:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e222b;
  --panel-3: #262b36;
  --border: #2c3240;
  --text: #e8eaf0;
  --text-dim: #9aa3b5;
  --accent: #5b9dff;
  --accent-2: #3ddc97;
  --rec: #ff4d5e;
  --warn: #ffb84d;
  --playhead: #ff5a5a;
  --roll-bg: #14171d;
  --roll-row-white: #1a1e26;
  --roll-row-black: #151820;
  --roll-line: rgba(255, 255, 255, 0.10);
  --roll-line-faint: rgba(255, 255, 255, 0.04);
  --roll-line-strong: rgba(255, 255, 255, 0.22);
  --radius: 8px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  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: 13px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  user-select: none;
}
input, select, button { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { fill: currentColor; }
kbd {
  display: inline-block; min-width: 1.6em; padding: 1px 5px; margin: 0 1px;
  border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px;
  background: var(--panel-2); font: 11px ui-monospace, Consolas, monospace; text-align: center;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 16px; padding: 8px 14px;
  background: linear-gradient(#1b1f27, #151820); border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 200px; }
.logo svg { width: 34px; height: 34px; display: block; }
.titles { display: flex; flex-direction: column; }
.title-input, .composer-input {
  background: transparent; border: 1px solid transparent; border-radius: 5px; padding: 1px 5px; outline: none; width: 210px;
}
.title-input { font-size: 15px; font-weight: 650; }
.composer-input { font-size: 12px; color: var(--text-dim); }
.title-input:hover, .composer-input:hover { border-color: var(--border); }
.title-input:focus, .composer-input:focus { border-color: var(--accent); background: var(--panel); }

.transport { display: flex; align-items: center; gap: 6px; flex: 1; justify-content: center; flex-wrap: wrap; }
.tbtn {
  width: 38px; height: 34px; border-radius: 7px; border: 1px solid var(--border);
  background: var(--panel-2); display: grid; place-items: center; color: var(--text);
  transition: background .12s, transform .05s;
}
.tbtn svg { width: 18px; height: 18px; }
.tbtn:hover { background: var(--panel-3); }
.tbtn:active { transform: translateY(1px); }
.tbtn.play .i-pause { display: none; }
.tbtn.play.on { background: #1f3b2e; color: var(--accent-2); border-color: #2c6a4d; }
.tbtn.play.on .i-play { display: none; }
.tbtn.play.on .i-pause { display: block; }
.tbtn.rec { color: var(--rec); }
.tbtn.rec.on { background: var(--rec); color: #fff; border-color: var(--rec); animation: pulse 1s infinite; }
.tbtn.rec.counting { background: #5a2a14; color: var(--warn); border-color: var(--warn); }
@keyframes pulse { 50% { box-shadow: 0 0 0 5px rgba(255, 77, 94, 0.25); } }

.lcd {
  background: #0a0c10; border: 1px solid var(--border); border-radius: 7px; padding: 3px 10px; min-width: 96px;
  font-family: ui-monospace, Consolas, monospace; color: #9fe8ff; display: flex; flex-direction: column; align-items: center; justify-content: center; height: 38px;
}
.lcd-main { font-size: 16px; line-height: 1.1; letter-spacing: .5px; }
.lcd-sub { font-size: 10px; color: #6a8a96; letter-spacing: .5px; }
.lcd.tempo { flex-direction: row; gap: 6px; min-width: 0; }
.lcd-input { width: 48px; background: transparent; border: 0; color: #9fe8ff; font: 16px ui-monospace, Consolas, monospace; text-align: center; outline: none; }

.sel {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px; padding: 5px 8px; height: 32px; outline: none;
}
.sel:focus { border-color: var(--accent); }
.sel.wide { width: 100%; }
.toggle {
  height: 32px; min-width: 36px; padding: 0 9px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--panel-2); color: var(--text-dim); font-size: 11px; font-weight: 650; letter-spacing: .4px;
  display: inline-grid; place-items: center;
}
.toggle svg { width: 17px; height: 17px; }
.toggle.on { color: #fff; background: #1d3352; border-color: var(--accent); }
.toggle:hover { background: var(--panel-3); }
.toggle.on:hover { background: #24416a; }

.actions { display: flex; align-items: center; gap: 6px; }
.icon-btn {
  width: 32px; height: 32px; border-radius: 6px; border: 1px solid var(--border); background: var(--panel-2);
  display: grid; place-items: center; font-weight: 700;
}
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn:hover { background: var(--panel-3); }
.icon-btn:disabled { opacity: .35; cursor: default; }
.btn {
  height: 32px; padding: 0 12px; border-radius: 6px; border: 1px solid var(--border); background: var(--panel-2);
}
.btn:hover { background: var(--panel-3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.ghost { background: transparent; }
.btn.wide { width: 100%; }
.btn.big { height: 44px; padding: 0 26px; font-size: 15px; }
.mini {
  height: 26px; min-width: 26px; padding: 0 7px; border-radius: 5px; border: 1px solid var(--border);
  background: var(--panel-3); font-size: 11px; font-weight: 650;
}
.mini:hover { background: #313847; }

.menu { position: relative; }
.menu-pop {
  position: absolute; right: 0; top: 38px; z-index: 50; width: 290px; padding: 6px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 9px; box-shadow: var(--shadow);
}
.menu-pop button {
  display: flex; justify-content: space-between; align-items: center; width: 100%; text-align: left;
  background: none; border: 0; padding: 7px 10px; border-radius: 6px;
}
.menu-pop button:hover { background: var(--panel-3); }
.menu-pop hr { border: 0; border-top: 1px solid var(--border); margin: 5px 0; }
.menu-label { font-size: 10px; text-transform: uppercase; letter-spacing: .8px; color: var(--text-dim); padding: 4px 10px; }

/* ---------- Main ---------- */
.main { display: grid; grid-template-columns: 270px minmax(0, 1fr); min-height: 0; }
.sidebar {
  border-right: 1px solid var(--border); background: var(--panel); overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 10px;
}
.panel { background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; gap: 8px; }
.panel h2 { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-dim); margin: 0; font-weight: 700; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; }
.field > span { font-size: 11px; color: var(--text-dim); }
.hint { color: var(--text-dim); font-size: 12px; margin: 4px 0 6px; }
.status-pill { font-size: 10px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 150px; }
.status-pill.ok { color: var(--accent-2); }
.status-pill.busy { color: var(--warn); }
.load-bar { height: 4px; background: var(--panel-3); border-radius: 3px; overflow: hidden; margin: -2px 0 8px; }
.load-bar > div { height: 100%; width: 0; background: var(--accent); transition: width .15s; }
.knobs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; }
.slider { display: flex; flex-direction: column; gap: 2px; font-size: 11px; color: var(--text-dim); }
input[type=range] { width: 100%; accent-color: var(--accent); height: 16px; }

.led { width: 10px; height: 10px; border-radius: 50%; background: #333a47; box-shadow: inset 0 0 0 1px rgba(0,0,0,.4); }
.led.connected { background: #2b6b4c; }
.led.flash { background: var(--accent-2); box-shadow: 0 0 8px var(--accent-2); }

.track-list { display: flex; flex-direction: column; gap: 6px; }
.track {
  border: 1px solid var(--border); border-radius: 7px; padding: 7px 8px; background: var(--panel);
  display: grid; grid-template-columns: 8px 1fr auto; gap: 4px 8px; align-items: center; cursor: pointer;
}
.track.active { border-color: var(--accent); background: #18233a; }
.track .swatch { width: 8px; height: 30px; border-radius: 3px; grid-row: span 2; }
.track .name {
  background: transparent; border: 1px solid transparent; border-radius: 4px; padding: 0 3px; font-weight: 600; width: 100%; min-width: 0; outline: none;
}
.track .name:focus { border-color: var(--accent); background: var(--panel-2); }
.track .inst { font-size: 11px; color: var(--text-dim); padding-left: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.track .btns { display: flex; gap: 3px; grid-row: span 2; }
.track .btns button {
  width: 22px; height: 22px; border-radius: 4px; border: 1px solid var(--border); background: var(--panel-3); font-size: 10px; font-weight: 700; padding: 0; color: var(--text-dim);
}
.track .btns button.m.on { background: #6a4a10; color: #ffd27a; border-color: #a7761c; }
.track .btns button.s.on { background: #1e4f35; color: #8ff0bd; border-color: #2f8a5b; }
.track .btns button.x:hover { background: #5a1f27; color: #ffb3bb; }
.track .count { font-size: 10px; color: var(--text-dim); }

/* ---------- Workspace ---------- */
.workspace { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.work-head {
  display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 12px;
  border-bottom: 1px solid var(--border); background: var(--panel); flex-wrap: wrap;
}
.tabs { display: flex; gap: 2px; background: var(--panel-2); border-radius: 7px; padding: 3px; border: 1px solid var(--border); }
.tab { border: 0; background: none; padding: 5px 14px; border-radius: 5px; color: var(--text-dim); font-weight: 600; }
.tab.active { background: var(--panel-3); color: var(--text); }
.work-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline { display: flex; gap: 6px; align-items: center; color: var(--text-dim); font-size: 12px; }
.views { flex: 1; min-height: 0; position: relative; }
.view { position: absolute; inset: 0; }
.view[hidden] { display: none; }

.score-view { display: grid; grid-template-columns: 200px minmax(0, 1fr); }
.now-playing {
  border-right: 1px solid var(--border); background: var(--panel); padding: 12px; display: flex; flex-direction: column; gap: 6px; overflow: hidden;
}
.np-label { font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-dim); font-weight: 700; }
.chord-name { font-size: 30px; font-weight: 700; line-height: 1.1; min-height: 36px; color: #fff; word-break: break-word; }
.note-names { font-size: 12px; color: var(--text-dim); min-height: 18px; }
.live-staff { background: #fbfaf6; border-radius: 8px; padding: 4px; color: #111; }
.live-staff svg { display: block; }

.paper-wrap { overflow: auto; padding: 18px; position: relative; background: #2a2e37; }
.paper {
  background: #fbfaf6; color: #111; border-radius: 4px; min-height: calc(100% - 4px); padding: 18px 10px;
  box-shadow: 0 6px 24px rgba(0,0,0,.35); max-width: 1200px; margin: 0 auto;
}
.paper svg { display: block; }
.paper .abcjs-note, .paper .abcjs-rest { transition: fill .08s; }
.paper .hl, .paper .hl path { fill: #2f6fe0 !important; }
.paper .abcjs-staff-extra, .paper .abcjs-bar { cursor: pointer; }
.score-empty {
  position: absolute; left: 50%; top: 300px; transform: translateX(-50%); text-align: center; max-width: 440px; width: 80%;
  color: #555; pointer-events: none;
}
.score-empty h3 { margin: 0 0 6px; color: #222; }
.score-empty[hidden] { display: none; }

.roll-view { display: flex; flex-direction: column; }
.roll-view canvas { flex: 1; width: 100%; min-height: 0; display: block; outline: none; }
.roll-hint { font-size: 11px; color: var(--text-dim); padding: 4px 10px; border-top: 1px solid var(--border); background: var(--panel); }

/* ---------- Dock ---------- */
.dock { background: #0b0d11; border-top: 1px solid var(--border); }
.dock-bar { display: flex; align-items: center; gap: 14px; padding: 6px 12px; flex-wrap: wrap; }
.dock .group { display: flex; align-items: center; gap: 5px; }
.dock .grow { flex: 1; }
.g-label { font-size: 10px; text-transform: uppercase; letter-spacing: .8px; color: var(--text-dim); margin-right: 2px; }
.readout {
  font: 13px ui-monospace, Consolas, monospace; min-width: 34px; text-align: center; color: #9fe8ff;
  background: #050608; border: 1px solid var(--border); border-radius: 4px; padding: 2px 4px;
}
#btnSustain.on { background: #4b3a10; border-color: var(--warn); color: #ffe2a6; }
.meter { width: 110px; height: 8px; background: #1a1d24; border-radius: 4px; overflow: hidden; }
.meter > div { height: 100%; width: 0; background: linear-gradient(90deg, #3ddc97 0 70%, #ffd23d 70% 88%, #ff4d5e 88%); background-size: 110px 100%; }

.stage { position: relative; padding: 0 8px 8px; }
#viz { display: block; width: 100%; height: 110px; }
.piano {
  position: relative; height: 150px; border-radius: 0 0 6px 6px; touch-action: none;
  background: #000; box-shadow: inset 0 6px 8px -4px rgba(0,0,0,.9);
}
.key { position: absolute; top: 0; }
.key.white {
  height: 100%; background: linear-gradient(#f2f2f2, #fff 70%, #e9e9e9); border: 1px solid #222; border-top: 0;
  border-radius: 0 0 5px 5px; z-index: 1;
}
.key.black {
  height: 62%; background: linear-gradient(#2a2a2e, #0c0c0e 60%, #1c1c20); border-radius: 0 0 4px 4px; z-index: 2;
  box-shadow: 0 2px 3px rgba(0,0,0,.6), inset 0 -4px 0 rgba(255,255,255,.08);
}
.key.white.active { background: linear-gradient(var(--key-color), color-mix(in srgb, var(--key-color) 60%, #fff)); box-shadow: inset 0 4px 10px rgba(0,0,0,.25); }
.key.black.active { background: linear-gradient(color-mix(in srgb, var(--key-color) 70%, #000), var(--key-color)); box-shadow: 0 0 10px var(--key-color); }
.key-label {
  position: absolute; left: 0; right: 0; text-align: center; font: 600 10px ui-monospace, Consolas, monospace; pointer-events: none;
}
.key.white .key-label { bottom: 22px; color: #5b6170; }
.key.black .key-label { bottom: 6px; color: #b9c0cf; }
.key-name { position: absolute; bottom: 5px; left: 0; right: 0; text-align: center; font-size: 9px; color: #8a8f99; pointer-events: none; }
.piano.hide-labels .key-label { display: none; }

/* ---------- Overlays ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(5, 6, 9, 0.78); backdrop-filter: blur(4px);
  display: grid; place-items: center; z-index: 100;
}
.overlay[hidden] { display: none; }
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 28px 32px; max-width: 460px; text-align: center; box-shadow: var(--shadow);
}
.card h1 { margin: 0 0 8px; font-size: 26px; }
.card p { color: var(--text-dim); }
.dialog {
  background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: 12px; padding: 20px 24px; max-width: 900px; width: calc(100% - 32px);
  box-shadow: var(--shadow);
}
.dialog::backdrop { background: rgba(0,0,0,.6); }
.dialog h2 { margin-top: 0; }
.dialog h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .8px; color: var(--text-dim); }
.help-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 18px; }
.help-grid p { margin: 6px 0; }
.dialog form { text-align: right; margin-top: 10px; }

.toasts { position: fixed; bottom: 290px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; z-index: 200; align-items: center; pointer-events: none; }
.toast {
  background: #232835; border: 1px solid var(--border); padding: 8px 14px; border-radius: 8px; box-shadow: var(--shadow);
  animation: toast-in .2s ease-out;
}
.toast.err { border-color: var(--rec); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- Shared bits added for multitrack / songwriting ---------- */
.sel.small { height: 26px; padding: 2px 6px; font-size: 12px; }
.check { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text); margin: 4px 0; cursor: pointer; flex-wrap: wrap; }
.check input { accent-color: var(--accent); }
.menu-pop.narrow { width: 240px; padding: 10px; }
.menu-pop.up { top: auto; bottom: 34px; right: auto; left: 0; }
.dock .menu { position: relative; }
.add-btns { display: flex; gap: 3px; }
.meter.wide { width: 100%; margin: 4px 0 8px; }
.meter > div#micMeter { height: 100%; width: 0; background: linear-gradient(90deg, #3ddc97 0 70%, #ffd23d 70% 88%, #ff4d5e 88%); background-size: 240px 100%; }
.led.clip { background: var(--rec) !important; box-shadow: 0 0 8px var(--rec) !important; }
.load-bar.big { height: 8px; margin: 14px 0 6px; }
.load-bar.big > div { transition: width .2s; }
#busyOverlay .card { min-width: 320px; }
.track .btns button.a.on { background: #5a1f27; color: #ff8a95; border-color: #a8384a; }
.tab.write { color: #ffd27a; }
.tab.write.active { color: #ffe2a6; }

/* Toolbar items per view */
.score-only, .score-roll, .tracks-only { display: none !important; }
body[data-view="score"] .score-only, body[data-view="score"] .score-roll,
body[data-view="roll"] .score-roll, body[data-view="tracks"] .tracks-only { display: flex !important; }
body[data-view="score"] .btn.score-only, body[data-view="score"] .btn.score-roll, body[data-view="roll"] .btn.score-roll { display: inline-block !important; }
.arr-tools { gap: 6px; align-items: center; }

/* ---------- Tracks (arrangement) ---------- */
.tracks-view { display: flex; flex-direction: column; }
.arr-body { flex: 1; overflow-y: auto; overflow-x: hidden; background: var(--roll-bg); }
.arr-inner { display: grid; grid-template-columns: 230px minmax(0, 1fr); }
.arr-heads { background: var(--panel); border-right: 1px solid var(--border); }
.lane-ruler-spacer { background: var(--panel-2); border-bottom: 1px solid var(--border); }
#arrCanvas { width: 100%; display: block; }
.lane-head {
  border-bottom: 1px solid var(--border); padding: 6px 8px; display: flex; flex-direction: column; justify-content: center; gap: 5px; box-sizing: border-box;
}
.lane-head.active { background: #18233a; box-shadow: inset 3px 0 0 var(--accent); }
.lh-row { display: flex; align-items: center; gap: 5px; }
.lh-row .swatch { width: 8px; height: 18px; border-radius: 3px; flex: none; }
.lh-icon { font-size: 13px; }
.lh-name { flex: 1; min-width: 0; background: transparent; border: 1px solid transparent; border-radius: 4px; padding: 1px 4px; font-weight: 600; outline: none; }
.lh-name:focus { border-color: var(--accent); background: var(--panel-2); }
.lane-head button {
  width: 22px; height: 22px; border-radius: 4px; border: 1px solid var(--border); background: var(--panel-3); font-size: 10px; font-weight: 700; padding: 0; color: var(--text-dim); flex: none;
}
.lane-head button.arm.on { background: #5a1f27; color: #ff8a95; border-color: #a8384a; }
.lane-head button.m.on { background: #6a4a10; color: #ffd27a; border-color: #a7761c; }
.lane-head button.s.on { background: #1e4f35; color: #8ff0bd; border-color: #2f8a5b; }
.lh-knob { display: flex; flex-direction: column; font-size: 9px; color: var(--text-dim); flex: 1; min-width: 0; }
.lh-knob input { height: 12px; }

/* ---------- Beat maker ---------- */
.beats-view { display: flex; flex-direction: column; }
.bm-toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--border); background: var(--panel); }
.bm-title { font-size: 12px; color: var(--text-dim); margin-right: 6px; }
.bm-title b { color: var(--text); }
.bm-repeat { width: 64px; }
.bm-scroll { flex: 1; overflow: auto; padding: 12px; }
.bm-grid { display: grid; gap: 3px; min-width: max-content; }
.bm-corner { }
.bm-num { font-size: 10px; color: var(--text-dim); text-align: left; padding-left: 2px; }
.bm-num.now { color: #fff; }
.bm-name {
  text-align: left; border: 1px solid var(--border); background: var(--panel-2); border-radius: 5px; font-size: 12px; padding: 0 8px; height: 30px;
}
.bm-name:active { background: var(--accent); }
.bm-cell { height: 30px; border-radius: 5px; border: 1px solid #2a2f3a; background: #1b1f27; padding: 0; min-width: 18px; }
.bm-cell.alt { background: #222733; }
.bm-cell:hover { border-color: #4a5468; }
.bm-cell.on { background: var(--accent-2); border-color: #2cae76; box-shadow: 0 0 8px rgba(61,220,151,.35); }
.bm-cell.soft { background: #2b6b4c; border-color: #2b6b4c; }
.bm-cell.now { outline: 2px solid rgba(255,255,255,.6); outline-offset: -2px; }
.bm-empty { display: none; padding: 40px; text-align: center; color: var(--text-dim); }
.beats-view.no-track .bm-empty { display: block; }
.beats-view.no-track .bm-scroll, .beats-view.no-track .bm-toolbar > *:not(.bm-title) { display: none; }

/* ---------- Songwriter ---------- */
.write-view { display: flex; flex-direction: column; background: var(--bg); }
.sw-steps { display: flex; gap: 4px; padding: 8px 12px; border-bottom: 1px solid var(--border); background: var(--panel); overflow-x: auto; flex: none; }
.sw-step {
  display: flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--panel-2); color: var(--text-dim);
  border-radius: 999px; padding: 4px 12px 4px 4px; font-size: 12px; white-space: nowrap;
}
.sw-step span { width: 20px; height: 20px; border-radius: 50%; background: var(--panel-3); display: grid; place-items: center; font-size: 11px; font-weight: 700; }
.sw-step.done { color: var(--text); }
.sw-step.done span { background: #1e4f35; color: #8ff0bd; }
.sw-step.current { color: #fff; border-color: var(--accent); background: #1d3352; }
.sw-step.current span { background: var(--accent); color: #fff; }
.sw-cols {
  flex: 1; min-height: 0; overflow: auto; display: grid; gap: 10px; padding: 10px;
  grid-template-columns: minmax(250px, 1fr) minmax(300px, 1.25fr) minmax(260px, 1fr) minmax(300px, 1.15fr);
}
.sw-col { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; gap: 6px; min-width: 0; min-height: 0; overflow: auto; }
.sw-col h3 { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-dim); margin: 6px 0 2px; }
.sw-col textarea, .sw-input {
  width: 100%; background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px; padding: 8px; color: var(--text); resize: vertical; outline: none; font: inherit; user-select: text;
}
.sw-col textarea:focus, .sw-input:focus { border-color: var(--accent); }
.sw-grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 8px; }
.sw-row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.sw-drop { border: 1.5px dashed var(--border); border-radius: 8px; padding: 10px; font-size: 12px; color: var(--text-dim); }
.sw-drop.over { border-color: var(--accent); background: #18233a; }
.sw-ref { border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; background: var(--panel-2); font-size: 12px; }
.sw-ref-top { display: flex; justify-content: space-between; gap: 6px; }
.sw-ref-top b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sw-ref-stats { display: flex; gap: 12px; margin: 6px 0; }
.sw-ref-stats span, .sw-ref-line { display: flex; flex-direction: column; }
.sw-ref-line { flex-direction: row; gap: 6px; margin: 2px 0; }
.sw-ref i, .sw-ref-line i { font-style: normal; font-size: 10px; text-transform: uppercase; letter-spacing: .6px; color: var(--text-dim); min-width: 56px; }
.sw-arc { display: flex; align-items: flex-end; gap: 3px; height: 34px; margin: 6px 0; }
.sw-arc span { flex: 1; background: linear-gradient(var(--accent), #2a4f8f); border-radius: 2px; }
.sw-ref-actions { display: flex; gap: 4px; flex-wrap: wrap; }
.sw-section { border: 1px solid var(--border); border-radius: 8px; padding: 8px; background: var(--panel-2); display: flex; flex-direction: column; gap: 5px; }
.sw-sec-head { display: flex; gap: 5px; align-items: center; }
.sw-sec-name { flex: 1; min-width: 0; background: transparent; border: 1px solid transparent; border-radius: 4px; font-weight: 700; padding: 2px 4px; outline: none; }
.sw-sec-name:focus { border-color: var(--accent); }
.sw-sec-bars { font-size: 11px; color: var(--text-dim); display: flex; align-items: center; gap: 4px; }
.sw-sec-bars input { width: 46px; background: var(--panel); border: 1px solid var(--border); border-radius: 4px; padding: 2px 4px; }
.sw-sec-at { font-size: 10px; color: var(--text-dim); white-space: nowrap; }
.sw-sec-chords { width: 100%; background: var(--panel); border: 1px solid var(--border); border-radius: 5px; padding: 6px 8px; font: 13px ui-monospace, Consolas, monospace; outline: none; user-select: text; }
.sw-sec-chords:focus { border-color: var(--accent); }
.sw-sec-chords.invalid { border-color: var(--warn); }
.sw-roman { font: 11px ui-monospace, Consolas, monospace; color: #9fc4ff; min-height: 14px; }
.sw-idea { display: flex; align-items: center; gap: 6px; border: 1px solid var(--border); border-radius: 7px; padding: 6px 8px; background: var(--panel-2); }
.sw-idea > div { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.sw-idea span { font-size: 11px; color: var(--text-dim); }
.sw-idea .sel { height: 26px; font-size: 12px; max-width: 110px; }
.sw-arranger { display: flex; flex-direction: column; gap: 2px; }
.sw-arranger .sel { height: 26px; font-size: 12px; margin-left: auto; }
.sw-arranger .check { justify-content: flex-start; }
.sw-arranger .btn { margin-top: 6px; }
.sw-lyrics-wrap { display: grid; grid-template-columns: 44px 1fr; flex: 1; min-height: 280px; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.sw-gutter { background: #12151b; overflow: hidden; padding: 8px 0; font: 11px/20px ui-monospace, Consolas, monospace; color: var(--text-dim); }
.g-line { height: 20px; display: flex; gap: 3px; justify-content: flex-end; padding-right: 5px; white-space: nowrap; }
.g-line.head { color: #9fc4ff; }
.g-line b { color: var(--text); font-weight: 600; }
.rh { display: inline-block; min-width: 12px; text-align: center; border-radius: 3px; font-weight: 700; }
.rh-A { color: #5b9dff; } .rh-B { color: #ff8a3d; } .rh-C { color: #3ddc97; } .rh-D { color: #e45bff; } .rh-E { color: #ffd23d; } .rh-F { color: #3dd6ff; }
.sw-col textarea.sw-lyrics { border: 0; border-radius: 0; resize: none; font: 14px/20px system-ui, sans-serif; padding: 8px 10px; white-space: pre; overflow: auto; height: 100%; }
.sw-chat-col { gap: 8px; }
.sw-chat-head { display: flex; justify-content: space-between; align-items: center; }
.sw-chat { flex: 1; min-height: 220px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; padding-right: 2px; user-select: text; }
.sw-welcome { background: linear-gradient(135deg, #1d2a45, #1e222b); border: 1px solid var(--border); border-radius: 10px; padding: 12px; font-size: 13px; }
.sw-welcome p { margin: 6px 0 0; color: #c5cddc; }
.msg { border-radius: 10px; padding: 8px 11px; font-size: 13px; line-height: 1.5; max-width: 95%; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: #24416a; }
.msg.bot { align-self: flex-start; background: var(--panel-2); border: 1px solid var(--border); }
.msg ul { margin: 4px 0; padding-left: 18px; }
.msg code { background: #111; padding: 0 4px; border-radius: 3px; }
.tool { font-size: 11px; margin-top: 4px; padding: 3px 7px; border-radius: 5px; background: #12261c; color: #8ff0bd; }
.tool.run { background: #1a2335; color: #9fc4ff; }
.tool.bad { background: #3a1a1f; color: #ffb3bb; }
.typing { display: inline-flex; gap: 3px; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--text-dim); animation: blink 1s infinite; }
.typing i:nth-child(2) { animation-delay: .15s; } .typing i:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 50% { opacity: .2; } }
.sw-chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip { border: 1px solid #3a4a66; background: #172238; color: #bcd3ff; border-radius: 999px; padding: 4px 10px; font-size: 12px; }
.chip:hover { background: #1f3052; }
.sw-form { display: flex; flex-direction: column; gap: 6px; }
.sw-form-btns { display: flex; gap: 6px; justify-content: flex-end; }
.sw-stop { display: none; }
.agent-busy .sw-stop { display: inline-block; }
.sw-settings { font-size: 12px; border-top: 1px solid var(--border); padding-top: 6px; }
.sw-settings summary { cursor: pointer; color: var(--text-dim); }

/* ---------- Key mapping dialog ---------- */
.km-presets { display: flex; gap: 8px; margin: 6px 0 4px; }
.km-keys { position: relative; height: 130px; background: #000; border-radius: 6px; margin: 6px 0 10px; }
.km-key { position: absolute; top: 0; padding: 0; border: 1px solid #222; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; font: 600 11px ui-monospace, Consolas, monospace; }
.km-key.white { height: 100%; background: #eee; color: #222; border-radius: 0 0 5px 5px; z-index: 1; padding-bottom: 6px; }
.km-key.black { height: 60%; background: #1c1c20; color: #ddd; border-radius: 0 0 4px 4px; z-index: 2; padding-bottom: 4px; }
.km-key:hover { outline: 2px solid var(--accent); outline-offset: -2px; }
.km-key.listening, .km-bindbtn.listening { background: var(--accent) !important; color: #fff !important; animation: pulse 1s infinite; }
.km-bind { line-height: 1.2; text-align: center; }
.km-off { font-size: 9px; color: #888; font-weight: 400; }
.km-actions { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 4px 16px; max-height: 300px; overflow: auto; }
.km-row { display: grid; grid-template-columns: 1fr 80px 110px 24px; gap: 5px; align-items: center; font-size: 12px; }
.km-bindbtn { height: 26px; border-radius: 5px; border: 1px solid var(--border); background: var(--panel-2); font: 12px ui-monospace, Consolas, monospace; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.km-clear { height: 24px; border-radius: 4px; border: 1px solid var(--border); background: transparent; color: var(--text-dim); }
.dialog.wide { max-width: 1040px; }

/* ---------- Hum (voice) ---------- */
.tab.hum { color: #ff9fbf; }
.tab.hum.active { color: #ffc2d6; }
.hum-view { display: flex; flex-direction: column; }
.hum-top { display: flex; gap: 14px; padding: 14px; align-items: stretch; flex-wrap: wrap; background: var(--panel); border-bottom: 1px solid var(--border); }
.hum-mic {
  width: 150px; border-radius: 14px; border: 1px solid #6b2b45; background: #2a1720; color: #ffc2d6;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding: 12px; font-weight: 600;
}
.hum-mic .hm-icon { font-size: 34px; line-height: 1; }
.hum-mic.on { background: #d63c71; color: #fff; border-color: #ff8fb4; animation: pulse 1.4s infinite; }
.seg { display: flex; flex-direction: column; gap: 6px; }
.seg button {
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text-dim); border-radius: 10px; padding: 8px 14px; text-align: left; font-weight: 600;
}
.seg button small { display: block; font-weight: 400; font-size: 11px; }
.seg button.on { border-color: var(--accent); color: #fff; background: #1d3352; }
.tuner { flex: 1; min-width: 260px; background: #0a0c10; border: 1px solid var(--border); border-radius: 14px; padding: 10px 16px; text-align: center; opacity: .7; transition: opacity .2s; }
.tuner.live { opacity: 1; }
.tn-note { font-size: 52px; font-weight: 800; line-height: 1.05; color: #fff; font-variant-numeric: tabular-nums; }
.tn-sub { color: var(--text-dim); font-size: 12px; margin-bottom: 6px; }
.tn-meter { max-width: 360px; margin: 0 auto; }
.tn-scale { display: flex; justify-content: space-between; font-size: 10px; text-transform: uppercase; letter-spacing: .8px; color: var(--text-dim); }
.tn-bar { position: relative; height: 14px; border-radius: 7px; background: linear-gradient(90deg, #5a1f27, #4b3a10 30%, #1e4f35 44%, #1e4f35 56%, #4b3a10 70%, #5a1f27); margin-top: 3px; }
.tn-zone { position: absolute; left: 50%; top: -3px; bottom: -3px; width: 2px; background: #8ff0bd; transform: translateX(-1px); }
.tn-bar i { position: absolute; top: -5px; width: 6px; height: 24px; border-radius: 3px; background: #fff; transform: translateX(-3px); left: 50%; box-shadow: 0 0 8px rgba(255,255,255,.6); transition: left .06s linear; }
.tn-state { margin-top: 6px; font-weight: 700; font-size: 15px; min-height: 22px; }
.tn-state.good { color: #8ff0bd; }
.tn-state.near { color: #ffd27a; }
.tn-state.off { color: #ff8a95; }
.hum-key, .hum-beatinfo { min-width: 180px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 14px; padding: 12px 16px; display: flex; flex-direction: column; gap: 4px; }
.hum-key-name { font-size: 26px; font-weight: 800; color: #fff; }
#humTrail { flex: 1; width: 100%; min-height: 120px; display: block; }
.hum-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding: 8px 14px; background: var(--panel); border-top: 1px solid var(--border); }
.hum-controls .grow { flex: 1; }
.hum-rec { color: var(--rec); }
.hum-rec.on { background: var(--rec); color: #fff; border-color: var(--rec); }
.hum-train .mini { margin-left: 4px; }
.hum-view .beat-only { display: none; }
.hum-view.beat-mode .beat-only { display: flex; }
.hum-view.beat-mode .melody-only { display: none; }
span.beat-only, .hum-view.beat-mode span.beat-only { align-items: center; gap: 4px; }
.hum-toggle.on { background: #d63c71; border-color: #ff8fb4; color: #fff; }
.hum-readout { min-width: 72px; color: #ffc2d6; }

/* ---------- Stage mode (phones in landscape, or ⛶ STAGE) ---------- */
.stage-bar, .rotate-hint { display: none; }
body.stage { display: block; overflow: hidden; touch-action: none; }
body.stage .topbar, body.stage .main, body.stage .dock-bar { display: none; }
body.stage .dock { display: flex; flex-direction: column; height: 100vh; height: 100dvh; padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
body.stage .stage-bar {
  display: flex; align-items: center; gap: 6px; padding: 6px 10px; background: linear-gradient(#1b1f27, #151820); border-bottom: 1px solid var(--border); flex-wrap: nowrap; overflow-x: auto;
}
body.stage .stage .tbtn, body.stage .stage-bar .tbtn { width: 44px; height: 40px; }
body.stage .stage-bar .st-big { height: 36px; min-width: 36px; font-size: 14px; }
body.stage .stage-bar .toggle { height: 36px; }
body.stage .st-inst { max-width: 150px; height: 36px; }
body.stage .st-pos { min-width: 46px; }
body.stage .stage-bar .grow { flex: 1; }
body.stage .stage-bar .tbtn.rec.counting { background: #5a2a14; color: var(--warn); border-color: var(--warn); }
body.stage .stage { flex: 1; display: flex; flex-direction: column; min-height: 0; padding: 0 4px 4px; }
body.stage #viz { display: block; height: 16%; min-height: 24px; flex: none; }
body.stage .piano { flex: 1; height: auto; min-height: 0; }
body.stage .key-name { display: block; font-size: 11px; }
body.stage .key.white.active { box-shadow: inset 0 6px 14px rgba(0,0,0,.3); }
body.stage .toasts { bottom: auto; top: 60px; }
@media (pointer: coarse) and (orientation: portrait) and (max-width: 600px) {
  body:not(.stage) .rotate-hint { display: block; text-align: center; padding: 6px; font-size: 13px; color: #ffd27a; background: #2a2114; border-bottom: 1px solid #8a5a1c; }
}

/* ---------- Phones held upright: scrolling page, slim pinned keyboard ---------- */
@media (max-width: 600px) {
  body:not(.stage) { display: block; overflow: auto; }
  body:not(.stage) .topbar { gap: 8px; padding: 8px; }
  body:not(.stage) .brand { width: 100%; }
  body:not(.stage) .transport { justify-content: flex-start; }
  body:not(.stage) .main { display: flex; flex-direction: column; }
  body:not(.stage) .workspace { order: 1; min-height: 0; }
  body:not(.stage) .sidebar { order: 2; border-right: 0; border-top: 1px solid var(--border); overflow: visible; }
  body:not(.stage) .tabs { overflow-x: auto; max-width: 100%; }
  body:not(.stage) .tab { white-space: nowrap; padding: 6px 10px; }
  body:not(.stage) .views { flex: none; }
  body:not(.stage) .view { position: static; }
  body:not(.stage) .hum-mic { width: 100%; flex-direction: row; justify-content: center; padding: 10px; }
  body:not(.stage) .hum-mic .hm-icon { font-size: 26px; }
  body:not(.stage) .seg { flex-direction: row; width: 100%; }
  body:not(.stage) .seg button { flex: 1; }
  body:not(.stage) .tuner, body:not(.stage) .hum-key, body:not(.stage) .hum-beatinfo { width: 100%; min-width: 0; }
  body:not(.stage) #humTrail { height: 170px; flex: none; }
  body:not(.stage) .score-view { display: block; }
  body:not(.stage) .paper-wrap { max-height: 70vh; }
  body:not(.stage) .roll-view canvas { height: 60vh; flex: none; }
  body:not(.stage) .sw-cols { grid-template-columns: minmax(0, 1fr); }
  body:not(.stage) .dock { position: sticky; bottom: 0; z-index: 20; box-shadow: 0 -6px 18px rgba(0,0,0,.5); }
  body:not(.stage) .dock-bar { gap: 6px; padding: 4px 8px; flex-wrap: nowrap; overflow-x: auto; }
  body:not(.stage) .dock-bar .group:not(:has(#btnHum, #octDown, #btnSustain, #btnStage)) { display: none; }
  body:not(.stage) #kbSize, body:not(.stage) #btnLabels, body:not(.stage) #btnKeymap, body:not(.stage) .dock .g-label { display: none; }
  body:not(.stage) #viz { display: none; }
  body:not(.stage) .piano { height: 110px; }
  body:not(.stage) .toasts { bottom: 180px; }
}

/* ---------- Website: support ---------- */
.support-btn { border-color: #6b2b45; color: #ff9fbf; background: #2a1720; }
.support-btn:hover { background: #3a1d2b; }
.support-dialog { max-width: 520px; }
.support-dialog p { color: var(--text-dim); }
.support-options { display: flex; flex-direction: column; gap: 8px; margin: 14px 0; }
.support-opt {
  display: flex; flex-direction: column; gap: 2px; text-align: left; text-decoration: none; color: var(--text);
  border: 1px solid var(--border); background: var(--panel-2); border-radius: 10px; padding: 12px 14px; font: inherit; cursor: pointer;
}
.support-opt:hover { border-color: var(--accent); }
.support-opt.featured { border-color: #8a5a1c; background: #2a2114; }
.support-opt span { color: var(--text-dim); font-size: 12px; }
.support-opt[hidden] { display: none; }
.site-links { font-size: 12px; }
.site-links a { color: var(--text-dim); }
.support-toast { display: flex; align-items: center; gap: 8px; }

@media (max-width: 1440px) {
  .title-input, .composer-input { width: 150px; }
  .brand { min-width: 0; }
  .topbar { gap: 10px; }
  .transport { gap: 4px; }
  .lcd { min-width: 80px; padding: 3px 7px; }
}

/* ---------- Short screens (common laptops) ---------- */
@media (max-height: 860px) {
  #viz { height: 54px; }
  .piano { height: 118px; }
  .dock-bar { padding: 4px 12px; gap: 10px; }
}
@media (max-height: 720px) {
  #viz { display: none; }
  .piano { height: 96px; }
  .stage { padding-top: 4px; }
  .topbar { padding: 5px 12px; }
  .key-name { display: none; }
}

/* ---------- Narrow screens ---------- */
@media (max-width: 1500px) {
  .sw-cols { grid-template-columns: minmax(260px, 1fr) minmax(300px, 1.2fr); }
}
@media (max-width: 1100px) {
  .main { grid-template-columns: 230px minmax(0, 1fr); }
  .score-view { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .now-playing { flex-direction: row; align-items: center; border-right: 0; border-bottom: 1px solid var(--border); }
  .live-staff { display: none; }
  .chord-name { font-size: 22px; min-height: 0; }
}
@media (max-width: 760px) {
  body { overflow: auto; grid-template-rows: auto auto auto; }
  .main { grid-template-columns: minmax(0, 1fr); }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--border); }
  .workspace { min-height: 70vh; }
  .piano { height: 120px; }
}
