:root {
  --bg: #121316;
  --panel: #1b1c21;
  --panel-2: #24252c;
  --line: #31333b;
  --text: #ecebe6;
  --muted: #9c9aa8;
  --accent: #d6a24a;
  --accent-2: #e8b862;
  --accent-ink: #1a1408;
  --danger: #ff6b57;
  --rec: #ef4444;
  --radius: 12px;
  --f-display: 'Bricolage Grotesque', 'Avenir Next', 'Segoe UI', system-ui, sans-serif;
  --f-body: 'Instrument Sans', 'Helvetica Neue', 'Segoe UI', system-ui, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--f-body);
  display: grid;
  grid-template-columns: 300px 1fr;
}
button, input, select { font: inherit; color: inherit; }
h1, h2 { font-family: var(--f-display); letter-spacing: -.01em; }
h3 { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 22px 0 10px; }
.muted { color: var(--muted); }
.visually-hidden { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; pointer-events: none; }

/* sidebar */
#sidebar { background: var(--panel); border-right: 1px solid var(--line); padding: 20px; overflow-y: auto; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; font: 800 19px var(--f-display); margin-bottom: 20px; }
.brand img { border-radius: 8px; }
.drop {
  position: relative; display: flex; flex-direction: column; gap: 4px; padding: 18px; border: 1.5px dashed var(--line);
  border-radius: var(--radius); cursor: pointer; transition: .15s; text-align: center;
}
.drop span { color: var(--muted); font-size: 12px; }
.drop:hover, .drop.over { border-color: var(--accent); background: rgba(214, 162, 74, .08); }
.hint-touch { display: none; }
@media (hover: none) { .hint-touch { display: inline; } .hint-desktop { display: none; } }

#library { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 4px; }
#library li { padding: 10px 12px; border-radius: 10px; cursor: pointer; display: flex; flex-direction: column; gap: 2px; }
#library li:hover { background: var(--panel-2); }
#library li.active { background: rgba(214, 162, 74, .14); }
#library .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#library .meta { font-size: 12px; color: var(--muted); }
#library .mini-bar { height: 3px; background: var(--line); border-radius: 2px; overflow: hidden; margin-top: 4px; }
#library .mini-bar div { height: 100%; background: var(--accent); }

.cloud { margin-top: 16px; padding: 12px; background: var(--panel-2); border-radius: 10px; font-size: 12px; color: var(--muted); }
.cloud:empty { display: none; }
.cloud a { color: var(--accent-2); text-decoration: none; }
.cloud-links { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 4px 10px; }
.dot-ok, .dot-off, .dot-err, .dot-busy { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 8px; vertical-align: 1px; }
.dot-ok { background: #3fbf7f; } .dot-off { background: #555a6a; } .dot-err { background: var(--danger); }
.dot-busy { background: var(--accent); animation: pulse 1s infinite alternate; }
@keyframes pulse { to { opacity: .3; } }

/* main */
#main { height: 100vh; overflow-y: auto; padding: 28px 36px 80px; }
.empty, .gate { max-width: 560px; margin: 16vh auto 0; text-align: center; color: var(--muted); }
.empty h1, .gate h1 { color: var(--text); font-size: 34px; margin-bottom: 8px; }
.gate-or { margin-top: 26px; }
.gate-key { margin-top: 22px; font-size: 13px; }
.gate-key summary { cursor: pointer; }
.keyform { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.keyform input { flex: 1; min-width: 160px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; }

.track-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; }
.track-head h1 { margin: 0 0 8px; font-size: 28px; outline: none; border-radius: 6px; }
.track-head h1:focus { box-shadow: 0 0 0 2px var(--accent); }
.badges { display: flex; gap: 8px; flex-wrap: wrap; }
.badge { background: var(--panel-2); border: 1px solid var(--line); padding: 3px 10px; border-radius: 99px; font-size: 12px; color: var(--muted); }
.badge:empty { display: none; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn { background: var(--accent); color: var(--accent-ink); border: 0; padding: 9px 16px; border-radius: 10px; font-weight: 700; cursor: pointer; }
.btn:hover { background: var(--accent-2); }
.btn:disabled { opacity: .5; cursor: wait; }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
.btn.ghost:hover { border-color: var(--accent); }
.btn.danger:hover { border-color: var(--danger); color: var(--danger); background: transparent; }

.processing { margin-top: 40px; background: var(--panel); border-radius: var(--radius); padding: 24px; }
.proc-label { margin-bottom: 12px; }
.bar { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; }
.bar div { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), #f0c77c); transition: width .4s; }

.chord-now { display: flex; gap: 30px; align-items: flex-end; margin: 26px 0 10px; }
.chord-now small { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .08em; }
#chord-cur { font: 800 44px/1.1 var(--f-display); min-width: 120px; }
.chord-now .next div { font: 700 24px var(--f-display); color: var(--muted); }

canvas { display: block; width: 100%; border-radius: 10px; }
#chords { height: 64px; background: var(--panel); margin-bottom: 8px; cursor: pointer; }
#wave { height: 110px; background: var(--panel); cursor: pointer; }

.transport { display: flex; align-items: center; gap: 10px; margin: 16px 0; flex-wrap: wrap; }
.time { font-variant-numeric: tabular-nums; color: var(--muted); min-width: 42px; }
.icon { background: var(--panel-2); border: 1px solid var(--line); width: 36px; height: 36px; border-radius: 50%; cursor: pointer; }
.play { width: 52px; height: 52px; border-radius: 50%; border: 0; background: var(--text); color: var(--bg); font-size: 18px; cursor: pointer; }
.spacer { flex: 1; }
.toggle { background: var(--panel-2); border: 1px solid var(--line); padding: 7px 14px; border-radius: 99px; cursor: pointer; }
.toggle.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.toggle.rec { color: #ff8a80; }
.toggle.rec.on { background: var(--rec); border-color: var(--rec); color: #fff; }
.master { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
select { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; max-width: 100%; }
#meter { padding: 6px 8px; }
.link { background: none; border: 0; color: var(--accent-2); cursor: pointer; padding: 0; }
input[type=range] { accent-color: var(--accent); }

/* recording */
.rec-panel { background: var(--panel); border: 1px solid rgba(239, 68, 68, .35); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 14px; }
.rec-grid { display: flex; flex-wrap: wrap; gap: 10px 22px; align-items: center; }
.rec-grid label { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.rec-grid input[type=number] { width: 70px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px; }
.rec-actions { display: flex; align-items: center; gap: 14px; margin-top: 14px; flex-wrap: wrap; }
.rec-btn { background: var(--rec); color: #fff; }
.rec-btn:hover { background: #f87171; }
.rec-btn.recording { animation: pulse .8s infinite alternate; }
.chk { display: flex; align-items: center; gap: 8px; cursor: pointer; }

.controls { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.ctl { background: var(--panel); border-radius: var(--radius); padding: 16px 18px; }
.ctl-head { display: flex; justify-content: space-between; margin-bottom: 8px; }
.ctl-head b { font: 700 18px var(--f-display); }
.stepper { display: flex; align-items: center; gap: 10px; }
.stepper button { width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel-2); cursor: pointer; }
.stepper input { flex: 1; }
.ctl-sub { margin-top: 10px; color: var(--muted); font-size: 12px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.ctl-sub b { color: var(--text); }
#cents { width: 90px; }

/* mixer */
.mixer-title { margin-top: 26px; }
#mixer { display: flex; flex-direction: column; gap: 8px; }
.stem { display: grid; grid-template-columns: 170px 64px 1fr 130px 60px 64px; align-items: center; gap: 14px; background: var(--panel); border-radius: var(--radius); padding: 10px 14px; }
.stem .nm { display: flex; align-items: center; gap: 10px; font-weight: 600; min-width: 0; }
.stem .nm span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stem .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.stem .ms { display: flex; gap: 6px; }
.stem .ms button { width: 28px; height: 28px; border-radius: 7px; border: 1px solid var(--line); background: var(--panel-2); font-weight: 700; font-size: 12px; cursor: pointer; }
.stem .ms .m.on { background: var(--danger); border-color: var(--danger); }
.stem .ms .s.on { background: #f5c542; border-color: #f5c542; color: #111; }
.stem canvas { height: 36px; background: transparent; }
.stem.off canvas { opacity: .25; }
.stem .pan { width: 60px; }
.stem .acts { display: flex; gap: 6px; justify-content: flex-end; }
.stem .acts button { background: none; border: 0; color: var(--muted); font-size: 16px; cursor: pointer; padding: 2px 4px; }
.stem .acts button:hover { color: var(--text); }
.stem.take { border: 1px solid rgba(239, 68, 68, .25); }

/* dialogs */
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 16px; padding: 0; width: min(640px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); }
dialog::backdrop { background: rgba(0, 0, 0, .6); }
.dlg { padding: 22px 24px; display: flex; flex-direction: column; gap: 12px; }
.dlg h2 { margin: 0; font-size: 24px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.presets, .exp-tools { display: flex; flex-wrap: wrap; gap: 6px; }
.presets button, .exp-tools button { background: var(--panel-2); border: 1px solid var(--line); border-radius: 99px; padding: 5px 12px; cursor: pointer; font-size: 13px; }
.presets button:hover, .exp-tools button:hover { border-color: var(--accent); }
.stem-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.group { background: var(--panel-2); border-radius: 12px; padding: 10px 12px; }
.group > label { font-weight: 700; }
.group .subs { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 6px 0 0 24px; font-size: 13px; color: var(--muted); }
.group label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.group .tag { font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--accent); }
.note { font-size: 12px; color: var(--muted); margin: 0; }
.quality { display: flex; gap: 18px; flex-wrap: wrap; }
.quality label { display: flex; gap: 6px; align-items: center; cursor: pointer; }
.summary { font-size: 13px; margin: 0; }
.exp-stems { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 6px; }
.exp-stems label { display: flex; align-items: center; gap: 8px; background: var(--panel-2); border-radius: 8px; padding: 7px 10px; cursor: pointer; }
.exp-grid { display: flex; flex-direction: column; gap: 10px; }
.exp-grid > label:first-child { display: flex; gap: 10px; align-items: center; }
.radio-row { display: flex; gap: 18px; flex-wrap: wrap; }
.radio-row label { display: flex; gap: 6px; align-items: center; cursor: pointer; }
.acc { border-top: 1px solid var(--line); padding-top: 12px; }
.acc h4 { margin: 0 0 6px; font-size: 15px; }
.acc p { margin: 0 0 8px; font-size: 13px; }
.pair { display: flex; gap: 18px; align-items: center; margin-top: 12px; flex-wrap: wrap; }
.qr { background: #fff; padding: 8px; border-radius: 10px; line-height: 0; }
.qr svg, .qr img { width: 168px; height: 168px; }
.code { font: 800 28px var(--f-display); letter-spacing: .08em; }
.devices { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.devices li { display: flex; justify-content: space-between; align-items: center; gap: 10px; background: var(--panel-2); border-radius: 8px; padding: 8px 12px; font-size: 13px; }

#toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--panel-2); border: 1px solid var(--line); padding: 10px 16px; border-radius: 10px; z-index: 10; max-width: calc(100vw - 32px); }

body.locked #drop { display: none; }

@media (max-width: 900px) {
  html, body { height: auto; }
  body { display: block; }
  #sidebar { height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  #library { max-height: 240px; overflow-y: auto; }
  #main { height: auto; overflow: visible; padding: 20px 16px 80px; }
  .track-head { flex-direction: column; gap: 12px; }
  .track-head h1 { font-size: 22px; }
  #chord-cur { font-size: 36px; }
  .controls { grid-template-columns: 1fr; }
  .stem { grid-template-columns: 104px 64px 1fr 52px; gap: 10px; }
  .stem .vol, .stem .pan { display: none; }
  .master { width: 100%; }
  .master input { flex: 1; }
  .dlg { padding: 18px 16px; }
}
