/* s4tools, drawn like the S-4's own screen: flat grey cells on black (or white), IBM Plex Mono in light capitals,
   the selection inverted, every value a bar under its name, soft keys for buttons. The colours are in themes.css
   (Settings > Theme). IBM Plex Sans only for sentences. */
:root {
  --sans: 'IBM Plex Sans', ui-sans-serif, system-ui, 'Segoe UI', Roboto, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  --r: 3px;
  --r-sm: 3px;
}
/* waveform and lane colour: the ink, or the track's own inside a .tcN. The four tracks also carry the shapes
   of the S-4's track keys (triangle, square, hexagon, circle) */
:root, [data-theme] { --kc: var(--ink); }
.tc0 { --kc: var(--t1); --shape: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 4.5 20.5 19.5h-17z" fill="none" stroke="black" stroke-width="2.4" stroke-linejoin="round"/></svg>'); }
.tc1 { --kc: var(--t2); --shape: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><rect x="5" y="5" width="14" height="14" fill="none" stroke="black" stroke-width="2.4"/></svg>'); }
.tc2 { --kc: var(--t3); --shape: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M7.7 4.8h8.6l4.3 7.2-4.3 7.2H7.7L3.4 12z" fill="none" stroke="black" stroke-width="2.4" stroke-linejoin="round"/></svg>'); }
.tc3 { --kc: var(--t4); --shape: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><circle cx="12" cy="12" r="7.6" fill="none" stroke="black" stroke-width="2.4"/></svg>'); }
.lane-name::before, .tc0 .insp-title > .lbl::before, .tc1 .insp-title > .lbl::before, .tc2 .insp-title > .lbl::before, .tc3 .insp-title > .lbl::before {
  content: ''; display: inline-block; width: .78em; height: .78em; margin-right: .38em; vertical-align: -.04em;
  background: var(--kc); -webkit-mask: var(--shape) center / contain no-repeat; mask: var(--shape) center / contain no-repeat;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font: 300 13px/1.45 var(--mono); overflow: auto; -webkit-font-smoothing: antialiased; }
#app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; min-width: 0; min-height: 0; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
button:disabled { cursor: default; }
input, select { font: inherit; color: var(--ink); }
input:not([type="checkbox"], [type="radio"], [type="range"], [type="file"]) { border: 0; border-radius: var(--r-sm); background: var(--field); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--rule2); border-radius: 5px; border: 3px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }
:focus-visible { outline: 2px solid var(--learn); outline-offset: 1px; }

.num, .k-val, .k-input, .f-val, .f-input, .bpm-val, .tempo, .pad, .mk span, .tag, .mon-row, .proj-name, .mi-hint, .rb-txt, .count, .scn-no, .lib-dur { font-variant-numeric: tabular-nums; }
.sp { flex: 1; }
.dim { color: var(--mute); }
.small { font-size: 11px; }
.padded { padding: 12px; }
.lbl { font-size: 12px; color: var(--mute); font-weight: 500; white-space: nowrap; text-transform: uppercase; letter-spacing: .05em; }
.lbl.bright { color: var(--ink); font-weight: 400; }
.lbl.dimmer { color: var(--mute); }
/* sentences stay in Plex Sans, as they are written */
.note, .mo-desc, .lib-name, .lib-sub, .bl-name, .set-status > span, .insp-note, .report, .lib-empty, .lib-count { font-family: var(--sans); font-weight: 400; letter-spacing: 0; text-transform: none; }
.note { font-size: 12px; color: var(--mute); line-height: 1.5; }

/* ---------- icons ---------- */
.ico { display: inline-flex; align-items: center; justify-content: center; }
.ico svg { height: 16px; width: auto; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; overflow: visible; }

/* ---------- buttons: the S-4's soft keys, grey cells, the chosen one inverted ---------- */
.btn, .tb {
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 30px; padding: 0 12px; border: 0; border-radius: var(--r-sm);
  background: var(--card); color: var(--ink); font: 400 12px var(--mono); letter-spacing: .05em; text-transform: uppercase; white-space: nowrap;
  transition: background .1s, color .1s;
}
:is(.btn, .tb):hover:not(:disabled, .on, .primary, .recording, .armed) { background: var(--sel); }
.btn:disabled { opacity: .4; }
.btn.on, .tb.on, .btn.primary { background: var(--ink); color: var(--bg); }
.btn.sm, .tb.sm { height: 25px; padding: 0 9px; }
.btn.sm .ico svg { height: 13px; }
.btn.icon-only, .tb.icon-only { width: 32px; padding: 0; }
.btn.danger { color: var(--err); }
.btn.primary:hover:not(:disabled) { background: var(--ink2); }
a.btn { text-decoration: none; }
.tb.sq { width: 25px; height: 23px; padding: 0; }
.ib { display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 26px; border-radius: var(--r-sm); color: var(--mute); }
.ib:hover:not(:disabled) { color: var(--ink); background: var(--sel); }
.ib.on { color: var(--ink); background: var(--sel); }
.ib .ico svg { height: 15px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--faint); flex: none; }

/* segmented choice: a row of soft keys */
.seg { display: inline-flex; gap: 3px; }
.seg button { flex: 1; height: 27px; padding: 0 11px; border-radius: var(--r-sm); background: var(--card); color: var(--ink2); font: 400 12px var(--mono); letter-spacing: .05em; text-transform: uppercase; white-space: nowrap; }
.seg button:hover:not(:disabled):not(.on) { background: var(--sel); color: var(--ink); }
.seg button.on { background: var(--ink); color: var(--bg); }
.seg button:disabled { opacity: .4; }
.seg.mini button { height: 23px; padding: 0 8px; }
.seg.onoff { width: 120px; flex: none; }
.seg.wide { display: flex; }

/* ---------- header ---------- */
#hdr { height: 54px; flex: none; display: flex; align-items: center; gap: 10px; padding: 0 16px; background: var(--bg); }
.brand { display: flex; align-items: center; gap: 9px; margin-right: 18px; }
.brand .ico { width: 30px; height: 30px; border-radius: var(--r-sm); background: var(--ink); }
.brand .ico svg { height: 17px; }
.wordmark { font: 300 19px var(--mono); letter-spacing: .02em; }
.vtabs { display: flex; gap: 3px; align-self: center; }
.vtab { position: relative; height: 30px; padding: 0 16px; border-radius: var(--r-sm); background: var(--card); color: var(--ink2); font: 400 12.5px var(--mono); letter-spacing: .05em; text-transform: uppercase; }
.vtab:hover:not(.on) { background: var(--sel); color: var(--ink); }
.vtab.on { background: var(--ink); color: var(--bg); }
body[data-view="live"] .only-build, body[data-view="build"] .only-live { display: none !important; }
.count { font-size: 11px; color: var(--mute); }
.count:empty { display: none; }
.learn.on { background: var(--learn); color: var(--on-accent); }
.transport { display: flex; align-items: center; gap: 4px; padding: 0 4px 0 8px; margin-left: 4px; }
.transport .tb.on { background: var(--ink); color: var(--bg); }
.tb[data-target="btn.rec"] .dot { background: var(--rec); opacity: .5; }
.tb[data-target="btn.rec"].on { background: var(--rec); color: var(--on-accent); }
.tb[data-target="btn.rec"].on .dot { background: var(--on-accent); opacity: 1; }
.tb.trec .dot { background: var(--rec); opacity: .6; }
.tb.trec.on { background: var(--rec); color: var(--on-accent); }
.tb.trec.on .dot { background: var(--on-accent); opacity: 1; }
.tb.sq .ico svg { height: 12px; }
.tempo { min-width: 72px; padding: 0 6px; font-size: 13px; color: var(--mute); }
.gear { position: relative; }
.set-dot { position: absolute; top: 4px; right: 4px; width: 7px; height: 7px; background: var(--warn); box-shadow: 0 0 0 2px var(--card); }
.set-dot.ok { background: var(--ok); }

/* Build's own toolbar, under the header */
#subbar { height: 46px; flex: none; display: flex; align-items: center; gap: 8px; padding: 0 16px; background: var(--bg); }
.proj-name { width: 220px; height: 30px; padding: 0 9px; background: var(--field); border: 0; border-radius: var(--r-sm); font-size: 12.5px; letter-spacing: .04em; text-transform: uppercase; }
.proj-name:focus { outline: 2px solid var(--learn); outline-offset: -1px; }
.tbar-sep { width: 1px; height: 22px; background: var(--rule2); margin: 0 4px; }
.bpm { display: flex; align-items: center; gap: 2px; }
.bpm-val { min-width: 34px; text-align: center; font-weight: 600; font-size: 13px; cursor: ns-resize; }
.hw.on { background: var(--ok); color: var(--on-accent); }
.hw .dot { background: var(--faint); }
.hw.on .dot { background: var(--on-accent); }
.hw.on .lbl { color: var(--on-accent); }
.hw-where { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* learn bar */
#listenBar { flex: none; display: flex; align-items: center; gap: 10px; height: 38px; padding: 0 16px; background: var(--learn); color: var(--on-accent); }
#listenBar b { font-weight: 600; }
#listenBar .btn { background: color-mix(in srgb, var(--on-accent) 14%, transparent); color: var(--on-accent); }
#updateBar { flex: none; display: flex; align-items: center; gap: 10px; min-height: 38px; padding: 6px 16px; background: var(--ok); color: var(--on-accent); }
#updateBar b { font-weight: 600; }
#updateBar .btn { background: transparent; color: var(--on-accent); }
.lb-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--on-accent); animation: blink 1s steps(2) infinite; }
.lb-cur { opacity: .8; }

main { flex: 1; min-height: 0; display: flex; }
.view { flex: 1; min-width: 0; min-height: 0; display: flex; }

/* ---------- knob: a value as the S-4's pages show one, its name and value over a bar ---------- */
.knob { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "label val" "bar bar"; align-items: center; gap: 8px 6px; width: 100%; min-width: 0; padding: 9px 10px 10px; border-radius: var(--r-sm); background: var(--card); user-select: none; touch-action: none; cursor: ew-resize; outline: none; }
.knob:focus-visible { box-shadow: 0 0 0 2px var(--learn); }
.knob:hover:not(.disabled), .knob.drag { background: var(--sel); }
.k-label { grid-area: label; min-width: 0; max-width: 100%; font-size: 11.5px; font-weight: 500; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: .05em; text-transform: uppercase; text-align: left; }
/* a label with a mode chip: the chip on its own line above the name */
.k-label:has(.gridsel) { white-space: normal; line-height: 1.25; }
.k-label .gridsel { display: block; margin: 0 auto; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.k-bar { grid-area: bar; position: relative; height: 13px; border-radius: 2px; background: var(--rule2); }
.k-bfill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 2px; background: var(--ink); }
.k-bmark { display: none; position: absolute; top: 2px; bottom: 0; width: 2px; margin-left: -1px; background: var(--ink); }
.k-bmark::before { content: ''; position: absolute; top: -3px; left: -4px; border: 5px solid transparent; border-top-color: var(--ink); border-bottom-width: 0; }
.k-step { position: absolute; top: 0; bottom: 0; width: 1px; margin-left: -.5px; background: var(--bg); opacity: .7; }
.knob.bi .k-bfill { display: none; }
.knob.bi .k-bmark { display: block; }
/* dimmed while the S-4 has the value exactly (a project's, a default), full once a CC went out */
.knob.exact .k-bfill { background: color-mix(in srgb, var(--ink) 55%, transparent); }
.knob.exact .k-bmark, .knob.exact .k-bmark::before { opacity: .6; }
.k-val { grid-area: val; font-size: 11px; color: var(--mute); white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.k-val.k-edit { cursor: text; }
.k-val.k-edit:hover { text-decoration: underline dotted; }
.k-input { width: 64px; height: 18px; padding: 0 4px; font-size: 11px; text-align: center; background: var(--field); border: 0; border-radius: 2px; outline: none; }
.knob.disabled { opacity: .4; cursor: default; }
/* name, bar and value in a row: master, recorder */
.knob.k-inline { grid-template-columns: auto 64px auto; grid-template-areas: "label bar val"; gap: 8px; width: auto; padding: 4px 8px; }
.knob.k-inline .k-label { font-size: 11px; color: var(--mute); }
.knob.k-inline .k-bar { height: 9px; }
.knob.k-inline .k-val { min-width: 26px; text-align: left; }
.kgrid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; align-items: end; align-content: start; }
.gridsel { color: var(--ink); text-decoration: underline dotted; text-underline-offset: 2px; font-weight: 600; cursor: pointer; }

/* ---------- slider (modals and the recorder): the same bar ---------- */
.fader { position: relative; user-select: none; outline: none; cursor: ew-resize; touch-action: none; }
.fader.row { display: grid; grid-template-columns: 40px minmax(0, 1fr) 46px; grid-template-areas: "label bar val"; align-items: center; gap: 10px; height: 22px; }
.fader.stack { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "label val" "bar bar"; row-gap: 6px; padding: 3px 0 6px; }
.f-label { grid-area: label; color: var(--ink2); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: .05em; text-transform: uppercase; }
.f-val { grid-area: val; text-align: right; white-space: nowrap; font-size: 11.5px; }
.f-val.f-edit { cursor: text; }
.f-val.f-edit:hover { text-decoration: underline dotted; }
.f-input { grid-area: val; width: 84px; justify-self: end; height: 20px; padding: 0 5px; font-size: 11.5px; text-align: right; background: var(--field); border: 0; border-radius: var(--r-sm); outline: none; }
.f-bar { grid-area: bar; position: relative; height: 13px; border-radius: 2px; background: var(--rule2); }
.f-fill { position: absolute; top: 0; bottom: 0; border-radius: 2px; background: var(--ink); }
.fader.bi .f-fill { background: color-mix(in srgb, var(--ink) 55%, transparent); }
.f-tick { position: absolute; top: 50%; width: 2px; height: 17px; margin: -9.5px 0 0 -1px; background: var(--ink); border-radius: 1px; }
.f-step { position: absolute; top: 7px; width: 1px; height: 4px; background: var(--faint); }
.f-cc { display: none; }
.fader:focus-visible { outline: 2px solid var(--learn); outline-offset: 3px; border-radius: 3px; }
.fader.disabled { opacity: .4; cursor: default; }

/* ---------- learned controls & learning ---------- */
[data-target] { position: relative; }
[data-map]::after { content: ''; position: absolute; right: 1px; top: 1px; z-index: 3; width: 6px; height: 6px; border-radius: 50%; background: var(--learn); pointer-events: none; }
body.listening [data-map]::after { content: attr(data-map); width: auto; height: auto; right: -3px; top: -7px; padding: 0 4px; border-radius: 3px; font: 600 9.5px/14px var(--mono); color: var(--on-accent); }
body.listening [data-target] { box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--learn) 50%, transparent); border-radius: var(--r-sm); cursor: crosshair; }
body.listening .learn-sel { box-shadow: inset 0 0 0 2px var(--learn); background-color: color-mix(in srgb, var(--learn) 12%, transparent); }
body.listening .learn-wait { animation: blink .6s steps(2) infinite; }

/* ---------- Live ---------- */
/* --insp is the inspector's width (live.js); each side keeps its minimum whatever the window does */
.lv { --insp: 340px; flex: 1; min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr) 8px clamp(300px, var(--insp), calc(100% - 268px)); grid-template-rows: auto minmax(0, 1fr) auto; transition: grid-template-columns .22s ease; }
.lv.dragging { transition: none; cursor: col-resize; user-select: none; }
.lv-grip { grid-row: 2; grid-column: 2; position: relative; margin: 0 -3px 0 -1px; z-index: 2; cursor: col-resize; touch-action: none; outline: none; }
.lv-grip::after { content: ''; position: absolute; top: 50%; left: 50%; width: 4px; height: 44px; margin: -22px 0 0 -2px; border-radius: 2px; background: var(--rule2); transition: background .15s, height .15s, margin .15s; }
.lv-grip:hover::after, .lv-grip:focus-visible::after, .lv.dragging .lv-grip::after { height: 72px; margin-top: -36px; background: var(--mute); }
.lv-top { grid-column: 1 / -1; display: flex; align-items: center; gap: 10px; padding: 8px 16px 6px; }
.scn-box { display: flex; align-items: center; gap: 2px; padding: 2px; border-radius: var(--r-sm); background: var(--card); }
.scn-btn { display: flex; align-items: baseline; gap: 6px; height: 26px; padding: 0 10px; border-radius: var(--r-sm); letter-spacing: .05em; text-transform: uppercase; }
.scn-btn:hover { background: var(--sel); }
.scn-no { font-size: 18px; font-weight: 300; }
.lv-master { display: flex; align-items: center; gap: 8px; padding-left: 6px; }
.lv-lanes { container: lanes / size; min-height: 0; overflow-y: auto; padding: 6px 4px 8px 16px; display: flex; flex-direction: column; gap: 6px; }
/* a lane: a row of cells, as the S-4 lays out a page */
.lane { --lc: var(--kc); display: grid; grid-template-columns: 112px minmax(0, 1fr) 184px; gap: 4px; flex: 1 0 auto; max-height: 176px; }
.lane.muted .tiles, .lane.muted .lane-mix { opacity: .45; }
.lane-head, .bl-head, .lane-mix, .bl-mix, .bl-main { border-radius: var(--r-sm); background: var(--card); }
.lane-head { display: flex; flex-direction: column; justify-content: space-between; gap: 6px; padding: 10px 10px 10px 12px; }
.lane-name { font: 300 20px var(--mono); color: var(--ink); letter-spacing: .05em; text-transform: uppercase; }
.lane-btns { display: flex; flex-wrap: wrap; gap: 3px; }
:is(.lane-head, .bl-head) .tb { background: var(--sel); }
:is(.lane-head, .bl-head) .tb.on { background: var(--ink); }
:is(.lane-head, .bl-head) .tb.trec.on { background: var(--rec); }
.tiles { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 4px; }
.tile { display: flex; flex-direction: column; gap: 6px; min-width: 0; padding: 8px 9px 7px; border-radius: var(--r-sm); background: var(--card); text-align: left; }
.tile:hover:not(.sel) { background: var(--sel); }
.tile.sel { background: var(--ink); color: var(--bg); }
.tile.off { opacity: .45; }
.tile-slot { font-size: 10.5px; letter-spacing: .05em; text-transform: uppercase; color: var(--mute); }
.tile.sel .tile-slot { color: color-mix(in srgb, var(--bg) 75%, var(--ink)); }
.tile-dev { font-size: 13px; font-weight: 400; letter-spacing: .05em; text-transform: uppercase; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile-dev .tag-off { margin-left: 5px; font-size: 9.5px; font-weight: 600; color: var(--warn); }
.tile.sel .tile-dev .tag-off { color: var(--bg); }
.sky { display: flex; align-items: flex-end; gap: 2px; flex: 1; min-height: 26px; max-height: 72px; margin-top: auto; }
.sky i { flex: 1; min-width: 2px; max-width: 8px; background: var(--ink); opacity: .55; }
.tile.sel .sky i { background: var(--bg); opacity: .7; }
.sky-note { margin-top: auto; height: 26px; display: flex; align-items: flex-end; font-size: 10.5px; color: var(--mute); }
/* the mixer: three rows, as on the S-4's MIX page */
.lane-mix, .bl-mix { display: flex; flex-direction: column; justify-content: center; gap: 6px; padding: 8px 10px; }
:is(.lane-mix, .bl-mix) .knob { grid-template-columns: 34px minmax(0, 1fr) 46px; grid-template-areas: "label bar val"; gap: 8px; padding: 0; background: none; }
.bl-mix .knob { grid-template-columns: 34px minmax(0, 1fr) 40px; }
:is(.lane-mix, .bl-mix) .knob .k-bar { height: 9px; }
:is(.lane-mix, .bl-mix) .knob .k-val { text-align: right; }
:is(.lane-mix, .bl-mix) .knob .k-label { font-size: 10.5px; color: var(--mute); }
.lv-insp { container: insp / inline-size; grid-row: 2; grid-column: 3; min-height: 0; display: flex; flex-direction: column; background: var(--bg); }
.insp-head { display: flex; align-items: center; gap: 6px; padding: 12px 12px 10px; }
.insp-title { display: flex; flex-direction: column; min-width: 0; letter-spacing: .05em; text-transform: uppercase; }
.insp-title .lbl { font-size: 11px; color: var(--mute); }
.insp-dev { display: inline-flex; align-items: center; gap: 4px; font: 400 20px var(--mono); letter-spacing: .05em; text-transform: uppercase; }
.insp-dev .ico svg { height: 13px; }
.insp-tools { display: flex; gap: 2px; }
.insp-tabs { padding: 4px 10px 6px; }
.insp-note { margin: 4px 4px 10px; }
.insp-foot { margin: 18px 4px 0; font-size: 10.5px; color: var(--mute); letter-spacing: .05em; text-transform: uppercase; }
.insp-body { flex: 1; min-height: 0; overflow-y: auto; padding: 4px 10px 14px; }
.insp-body.off .kgrid { opacity: .45; }
.insp-sub { margin: 14px 2px 6px; font-size: 11px; font-weight: 600; color: var(--mute); letter-spacing: .05em; text-transform: uppercase; }
.macro-btns { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; padding: 0 4px; }
.lv-bottom { grid-column: 1 / -1; padding: 6px 16px 12px; }

/* short windows: the skylines give up their height first, so the four lanes still fit */
@container lanes (max-height: 560px) {
  .tile .sky { min-height: 14px; max-height: 22px; }
  .tile .sky-note { height: 14px; }
}
@container lanes (max-height: 420px) {
  .tile .sky, .tile .sky-note { display: none; }
}
/* the lanes go compact as the inspector takes the width */
@container lanes (max-width: 860px) {
  .lane { grid-template-columns: 76px minmax(0, 1fr) 150px; max-height: none; }
  .lane-head { padding: 8px 6px 8px 10px; }
  .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .tile { gap: 4px; }
  .tile .sky { min-height: 16px; max-height: 24px; }
  .tile .sky-note { height: 16px; }
}
@container lanes (max-width: 600px) {
  .lane { grid-template-columns: 70px minmax(0, 1fr); flex: none; }
  .lane-head { justify-content: flex-start; gap: 8px; }
  .lane-mix { grid-column: 1 / -1; flex-direction: row; gap: 10px; }
  .lane-mix .knob { grid-template-columns: auto minmax(20px, 1fr); grid-template-areas: "label val" "bar bar"; gap: 4px; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tile .sky, .tile .sky-note { display: none; }
}
/* the inspector's knobs: two to a row while it is narrow, four (an S-4 page) once it has the room, and bigger */
.lv-insp .kgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@container insp (min-width: 520px) {
  .lv-insp .kgrid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
  .lv-insp .knob { padding: 12px 12px 14px; gap: 10px 6px; }
  .lv-insp .knob .k-bar { height: 16px; }
  .lv-insp .knob :is(.k-label, .k-val) { font-size: 12.5px; }
}
@container insp (min-width: 860px) {
  .lv-insp .knob { padding: 16px 14px 18px; gap: 12px 6px; }
  .lv-insp .knob .k-bar { height: 20px; }
  .lv-insp .knob :is(.k-label, .k-val) { font-size: 13.5px; }
}

/* scene pads (Live popover and Build) */
.padgrid { display: grid; gap: 3px; }
.pad { position: relative; height: 26px; min-width: 0; border-radius: 2px; background: var(--card); font-size: 10px; color: var(--mute); }
.pad:hover { color: var(--ink); }
.pad.used { background: var(--sel); color: var(--ink); }
.pad.cur { background: var(--ink); color: var(--bg); }
.pad.playing { box-shadow: inset 0 0 0 2px var(--ok); color: var(--ink); }
.pad.cur.playing { box-shadow: inset 0 0 0 2px var(--ok); }
.pad.queued { animation: blink .5s steps(2) infinite; }
.scn-pop { padding: 10px; }
.scn-pop .padgrid { grid-template-columns: repeat(16, 30px); }
.scn-pop .pad { width: 30px; }

/* recorder bar */
.recbar { display: flex; align-items: center; gap: 12px; height: 52px; padding: 0 12px; background: var(--card); border-radius: var(--r); }
.recbar .btn { background: var(--sel); }
.recbar .btn.on { background: var(--ink); color: var(--bg); }
.rec-in { flex: 1; min-width: 130px; display: flex; flex-direction: column; gap: 4px; }
.rec-in-top { display: flex; align-items: center; gap: 6px; }
.rec-meter { position: relative; flex: 1; display: flex; flex-direction: column; gap: 3px; padding: 2px 0; }
.rec-ch { position: relative; height: 5px; background: var(--rule2); overflow: hidden; }
.rec-fill { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: var(--ink); }
.rec-fill.over { background: var(--warn); }
.rec-fill.clip { background: var(--err); }
.rec-thr { position: absolute; top: -2px; bottom: -2px; width: 2px; margin-left: -1px; background: var(--ink); }
.rec-meter:not(.on) .rec-thr { opacity: .35; }
.rec-status { font-size: 11px; color: var(--mute); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recbar .knob.k-inline { flex: none; background: none; }
.recbar .knob.k-inline .k-val { min-width: 54px; }
.rec-sep { width: 1px; height: 26px; flex: none; background: var(--rule2); }
.rec-pc { flex: none; }
.rec-pc .dot { background: var(--rec); opacity: .55; }
.rec-pc.recording { background: var(--rec); color: var(--on-accent); }
.rec-pc.recording .dot { background: var(--on-accent); opacity: 1; animation: blink 1s steps(2) infinite; }
.rec-tgt { flex: none; gap: 4px; }
.rec-tgt .ico svg { height: 12px; }
.rec-mon:empty { display: none; }
.rec-arm { flex: none; min-width: 84px; }
.rec-arm.armed { background: var(--warn); color: var(--on-accent); animation: blink 1.2s steps(2) infinite; }
.rec-arm.recording { background: var(--rec); color: var(--on-accent); }
.rec-arm.armed.beat1 { background: var(--ink); color: var(--bg); }
.rec-mode { flex: none; }
.rec-slot { display: contents; }
.rec-count { flex: none; width: 196px; justify-content: space-between; }
@media (max-width: 1500px) {
  .recbar { gap: 8px; }
  .rec-count { width: 168px; }
}

/* ---------- Build ---------- */
.bd { flex: 1; min-width: 0; display: grid; grid-template-columns: 250px minmax(0, 1fr) 380px; grid-template-rows: auto minmax(0, 1fr); }
.bd.lib-off { grid-template-columns: 44px minmax(0, 1fr) 380px; }
.bd-pads { grid-column: 1 / -1; padding: 8px 16px 10px; }
.pads-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.pads-head .lbl.bright { font-size: 13px; }
.bd-pads .padgrid { grid-template-columns: repeat(16, minmax(0, 1fr)); }
.bd-pads.short .pad:not(.inrow) { display: none; }
.bd-pads .pad { height: 30px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 0; }
.pad .bars { display: flex; gap: 2px; height: 4px; }
.pad .bars i { width: 5px; height: 4px; border-radius: 1px; background: var(--rule2); }
.pad .bars i.on0 { background: var(--t1); } .pad .bars i.on1 { background: var(--t2); } .pad .bars i.on2 { background: var(--t3); } .pad .bars i.on3 { background: var(--t4); }
.pad.cur .bars i:not([class^="on"]) { background: color-mix(in srgb, var(--bg) 30%, transparent); }
.pad .marks { position: absolute; top: 1px; right: 2px; display: flex; gap: 1px; }
.pad .marks .ico svg { height: 9px; }
.bd-lib { min-height: 0; display: flex; flex-direction: column; background: var(--bg); }
.lib-head { display: flex; align-items: center; gap: 6px; padding: 10px 10px 8px 12px; }
.lib-head .lbl.bright { font-size: 13px; }
.lib-search { display: flex; align-items: center; gap: 6px; margin: 0 10px 8px; padding: 0 8px; height: 30px; background: var(--field); border-radius: var(--r-sm); color: var(--mute); }
.lib-search input { flex: 1; min-width: 0; border: 0; outline: none; background: none; font-size: 12.5px; }
.lib-list { flex: 1; min-height: 0; overflow-y: auto; padding: 0 6px 10px; }
/* the picked row inverted, as in the S-4's lists */
.lib-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 6px; padding: 4px 8px; border-radius: 2px; cursor: grab; }
.lib-item:hover { background: var(--card); }
.lib-item.playing { background: var(--ink); color: var(--bg); }
.lib-item.playing :is(.lib-sub, .lib-dur) { color: color-mix(in srgb, var(--bg) 70%, var(--ink)); }
.lib-name { font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lib-sub { font-size: 10.5px; color: var(--mute); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lib-txt { min-width: 0; }
.lib-right { display: flex; align-items: center; }
.lib-dur { font-size: 10.5px; color: var(--mute); }
.lib-item:hover .lib-dur { display: none; }
.lib-count { padding: 2px 8px 6px; font-size: 11px; color: var(--mute); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lib-to { display: none; gap: 2px; }
.lib-item:hover .lib-to { display: flex; }
.lib-to button { width: 22px; height: 20px; border-radius: 3px; font: 600 10px var(--mono); color: var(--on-t); }
.lib-empty { padding: 14px; font-size: 12px; color: var(--mute); line-height: 1.55; }
.bd.lib-off .bd-lib > :not(.lib-head) { display: none; }
.bd.lib-off .lib-head { flex-direction: column; padding: 10px 0; }
.bd.lib-off .lib-head > :not(.lib-toggle) { display: none; }
.bd-lanes { min-height: 0; overflow-y: auto; padding: 6px 10px 10px; display: flex; flex-direction: column; gap: 6px; }
.blane { --lc: var(--kc); display: grid; grid-template-columns: 104px minmax(0, 1fr) 176px; gap: 4px; flex: 1 0 auto; max-height: 190px; }
.blane.drag { box-shadow: 0 0 0 2px var(--learn); }
.blane.muted .bl-wave, .blane.muted .bl-mix { opacity: .4; }
.bl-head { display: flex; flex-direction: column; gap: 6px; padding: 10px 8px 10px 12px; }
.blane.sel .bl-head { background: var(--ink); color: var(--bg); }
.blane.sel .bl-head .lane-name { color: var(--bg); }
.mat { display: inline-flex; align-items: center; gap: 3px; align-self: flex-start; padding: 2px 6px; border-radius: 2px; background: var(--sel); color: var(--ink); font-size: 11px; font-weight: 400; letter-spacing: .05em; text-transform: uppercase; }
.mat .ico svg { height: 11px; }
.bl-main { display: flex; flex-direction: column; gap: 6px; min-width: 0; padding: 8px 10px; }
.bl-wave { --kc: var(--ink); position: relative; flex: 1; min-height: 48px; border-radius: 2px; background: var(--bg); overflow: hidden; }
.bl-wave canvas, .ed-wave canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.bl-wave.empty { display: flex; align-items: center; justify-content: center; gap: 8px; border: 1px dashed var(--rule2); background: none; color: var(--mute); cursor: pointer; font-size: 12px; }
.bl-wave.empty:hover { color: var(--ink); }
.bl-wave.libref { color: var(--warn); }
.ph { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; display: none; pointer-events: none; background: var(--ink); }
.bl-info { display: flex; align-items: center; gap: 6px; min-width: 0; }
.bl-name { flex: 0 1 auto; min-width: 0; font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bl-name.missing { color: var(--err); }
.tag { padding: 1px 7px; border-radius: 2px; font-size: 11px; color: var(--ink2); white-space: nowrap; background: var(--sel); letter-spacing: .05em; text-transform: uppercase; }
.tag-btn { cursor: pointer; }
.tag.on-key { box-shadow: inset 0 0 0 1px var(--lc); }
.bd-insp { min-height: 0; display: flex; flex-direction: column; background: var(--bg); }
.itabs { display: flex; gap: 3px; padding: 8px 10px 4px; }
.itab { position: relative; flex: 1; height: 30px; border-radius: var(--r-sm); background: var(--card); color: var(--ink2); font: 400 12px var(--mono); letter-spacing: .05em; text-transform: uppercase; }
.itab:hover:not(.on) { background: var(--sel); color: var(--ink); }
.itab.on { background: var(--ink); color: var(--bg); }
.itab.lit::before { content: ''; position: absolute; right: 6px; top: 6px; width: 5px; height: 5px; border-radius: 50%; background: var(--ok); }
.ibody { flex: 1; min-height: 0; overflow-y: auto; padding: 8px 10px 16px; display: flex; flex-direction: column; gap: 10px; }
.ihead { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ibody > * { flex-shrink: 0; }
.isec { padding-top: 12px; margin-top: 2px; }
.ihead .lbl.bright { font-size: 13px; }
.keyrow { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.sw-row { display: flex; gap: 4px; flex-wrap: wrap; }
.ibody .kgrid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.ed { display: flex; flex-direction: column; gap: 8px; padding-top: 10px; }
.ed-wave { --kc: var(--ink); position: relative; height: 70px; background: var(--card); border-radius: var(--r-sm); overflow: hidden; }
.mk { position: absolute; top: 0; bottom: 0; width: 1px; margin-left: -.5px; background: var(--ink); cursor: ew-resize; touch-action: none; z-index: 2; }
.mk::before { content: ''; position: absolute; top: 0; bottom: 0; left: -6px; right: -6px; }
.mk span { position: absolute; padding: 0 4px; font-size: 10px; line-height: 14px; font-weight: 600; background: var(--ink); color: var(--bg); }
.mk-in span { top: 0; left: 0; border-radius: 0 0 3px 0; }
.mk-out span { bottom: 0; right: 0; border-radius: 3px 0 0 0; }
.ed-row { display: flex; align-items: center; gap: 10px; }
.bd-lanes.expand .blane { display: none; }
.big-ed { flex: 1; display: flex; flex-direction: column; gap: 8px; padding: 12px; background: var(--card); border-radius: var(--r); }
.big-ed .ed-wave { flex: 1; height: auto; }

/* ---------- menu: the picked row inverted ---------- */
.menu { position: fixed; z-index: 100; min-width: 190px; max-height: 70vh; overflow-y: auto; padding: 4px; background: var(--card); border: 1px solid var(--rule2); border-radius: 5px; box-shadow: var(--shadow); }
.menu-item { display: flex; align-items: center; gap: 8px; width: 100%; padding: 6px 10px 6px 6px; border-radius: 2px; text-align: left; color: var(--ink2); font: 400 12px var(--mono); letter-spacing: .05em; text-transform: uppercase; }
.menu-item:hover:not(:disabled) { background: var(--ink); color: var(--bg); }
.menu-item:hover :is(.mi-check, .mi-hint) { color: inherit; }
.menu-item.on { color: var(--ink); }
.menu-item.danger { color: var(--err); }
.menu-item:disabled { opacity: .4; }
.mi-check { width: 12px; font-size: 8px; color: var(--ink); }
.mi-hint { margin-left: auto; padding-left: 14px; font-size: 11px; color: var(--mute); }
.menu-head { padding: 7px 10px 3px 24px; font-size: 11px; font-weight: 400; color: var(--mute); letter-spacing: .05em; text-transform: uppercase; }
.menu-sep { height: 1px; margin: 4px 2px; background: var(--rule); }
.pop { position: fixed; z-index: 90; background: var(--card); border: 1px solid var(--rule2); border-radius: 5px; box-shadow: var(--shadow); }

/* ---------- modal ---------- */
.modal-back { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 60px 20px; overflow-y: auto; background: var(--scrim); }
.modal { width: 560px; max-width: 100%; background: var(--card); border: 1px solid var(--rule2); border-radius: 5px; box-shadow: var(--shadow); overflow: hidden; }
.modal.wide { width: 940px; }
.modal.mid { width: 760px; }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 14px 12px 10px 18px; }
.modal-head > .lbl { font: 400 15px var(--mono); color: var(--ink); letter-spacing: .05em; text-transform: uppercase; }
.modal-body { padding-bottom: 6px; }

/* control maps */
.map-presets { display: flex; align-items: center; gap: 10px; padding: 10px 20px; border-bottom: 1px solid var(--rule); }
.map-list { max-height: 46vh; overflow-y: auto; }
.map-row { display: grid; grid-template-columns: 170px 20px minmax(0, 1fr) auto 26px; align-items: center; gap: 10px; padding: 8px 20px; border-bottom: 1px solid var(--rule); }
.ms-main { color: var(--learn); font-weight: 600; }
.ms-dev { color: var(--mute); font-size: 11px; }
.map-arrow { color: var(--mute); }
.map-tgt { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.map-ctrls { display: flex; align-items: center; gap: 8px; }
.map-ctrls .btn.mode { min-width: 76px; }
.btn.inv.on { background: var(--learn); color: var(--on-accent); }
.rangebar { display: flex; align-items: center; gap: 8px; width: 150px; cursor: ew-resize; }
.rb-txt { width: 46px; font-size: 11px; color: var(--mute); }
.rb-bar { position: relative; flex: 1; height: 4px; border-radius: 2px; background: var(--rule2); touch-action: none; }
.rb-fill { position: absolute; top: 0; bottom: 0; border-radius: 2px; background: var(--learn); }
.map-empty { padding: 22px 20px; color: var(--mute); }
.map-opts { padding: 4px 20px 8px; }
.map-opts-head { display: flex; align-items: center; padding: 10px 0 8px; }
.map-opt { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 10px 0; border-top: 1px solid var(--rule); }
.mo-title { font-weight: 400; letter-spacing: .05em; text-transform: uppercase; }
.mo-desc { margin-top: 2px; color: var(--mute); font-size: 12px; }

/* reports */
.report { padding: 8px 20px 14px; line-height: 1.55; }
.report p { margin: 8px 0; }
.report .lbl { display: block; margin-top: 12px; }
.report ul { margin: 6px 0 0; padding-left: 18px; color: var(--mute); max-height: 34vh; overflow-y: auto; }
.report ul.missing { color: var(--warn); }
.choose { display: flex; flex-direction: column; padding: 6px; max-height: 60vh; overflow-y: auto; }

/* settings */
.settings { padding: 0 20px; }
.set-split { display: grid; grid-template-columns: 180px minmax(0, 1fr); gap: 20px; min-height: 380px; }
.set-nav { display: flex; flex-direction: column; gap: 3px; padding: 12px 16px 12px 0; }
.set-tab { height: 32px; padding: 0 10px; border-radius: var(--r-sm); background: var(--card); text-align: left; color: var(--ink2); font: 400 12px var(--mono); letter-spacing: .05em; text-transform: uppercase; }
.set-tab:hover:not(.on) { background: var(--sel); color: var(--ink); }
.set-tab.on { background: var(--ink); color: var(--bg); }
.set-panes { min-width: 0; }
.set-pane[hidden] { display: none; }
.set-pane .set-row:last-child { border-bottom: 0; }
.set-status { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--rule); }
.set-status > span { flex: 1; color: var(--ink2); }
.set-status.ok .dot { background: var(--ok); }
.set-status.warn .dot { background: var(--warn); }
.set-status.err .dot { background: var(--err); }
.set-status.err > span { color: var(--err); }
.settings .set-row { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 24px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--rule); }
.settings .set-ctl { display: flex; justify-content: flex-end; }
.settings .set-ctl .seg { width: 100%; }
select { width: 100%; height: 30px; padding: 0 8px; background: var(--field); border: 0; border-radius: var(--r-sm); font-weight: 400; }
/* theme swatches: each one carries its theme's data-theme, so its tokens are that theme's */
.themes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; width: 100%; }
.swatch { display: flex; border-radius: var(--r-sm); text-align: left; }
.swatch.on { box-shadow: 0 0 0 2px var(--ink); }
.sw-in { flex: 1; display: flex; flex-direction: column; align-items: flex-start; gap: 5px; padding: 7px 8px; border-radius: var(--r-sm); background: var(--bg); color: var(--ink); }
.sw-dots { display: flex; gap: 3px; }
.sw-dots i { width: 10px; height: 10px; border-radius: 3px; }
.sw-name { font-size: 11.5px; font-weight: 600; }
.ctrl-list { display: flex; flex-direction: column; gap: 6px; width: 100%; }
.chk { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.chk input { accent-color: var(--ink); }
.set-mon { padding: 12px 0 14px; }
.set-mon .mon-list { height: 320px; }
@media (max-width: 720px) {
  .set-split { grid-template-columns: minmax(0, 1fr); gap: 0; min-height: 0; }
  .set-nav { flex-direction: row; flex-wrap: wrap; padding: 10px 0; }
  .settings .set-row { grid-template-columns: minmax(0, 1fr); gap: 10px; }
}
.mon-list { height: 220px; overflow-y: auto; background: var(--card); border-radius: var(--r-sm); font-size: 11px; }
.mon-row { display: grid; grid-template-columns: 50px minmax(0, 1fr) auto; gap: 10px; padding: 3px 10px; border-bottom: 1px solid var(--rule); }
.mon-row.out .mon-dir { color: var(--ok); }
.mon-row.in .mon-dir { color: var(--learn); }
.mon-port { color: var(--mute); }

/* project settings and other panels */
.set-body { padding: 10px 20px 16px; }
.set-head { margin: 18px 0 6px; padding-bottom: 6px; border-bottom: 1px solid var(--rule); font-size: 13px; }
.set-body .set-row { display: grid; grid-template-columns: 180px 1fr; gap: 12px; align-items: center; min-height: 34px; }
.set-body .set-ctl { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-width: 0; }
.set-ctl .fader.row { flex: 1; max-width: 320px; }
.set-pair { display: inline-flex; align-items: center; gap: 4px; }
.set-names { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px 12px; }
.set-names label { display: flex; align-items: center; gap: 6px; }
.set-ctl .fader.row.qfree { width: 260px; flex: none; grid-template-columns: 0 minmax(0, 1fr) 70px; }
.set-name { flex: 1; min-width: 0; height: 27px; padding: 0 7px; background: var(--field); border: 0; border-radius: var(--r-sm); font: 500 12px var(--mono); text-transform: uppercase; }

/* modulators and routings */
.mod-ed { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.mod-top { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.mod-ed .kgrid { margin-top: 4px; }
.mod-routes { padding-top: 8px; }
.mod-rh { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.mod-route { display: grid; grid-template-columns: minmax(110px, 200px) minmax(110px, 1fr) auto auto; gap: 10px; align-items: center; min-height: 30px; }
.mod-route .mr-t { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mod-route .fader.row .f-label:empty { display: none; }
.perf-dest { display: grid; grid-template-columns: 40px 1fr; gap: 8px; align-items: start; padding: 4px 0; }
.perf-dest > .lbl { padding-top: 7px; }
.perf-dest .mod-routes { padding-top: 0; }
.mod-holder { min-width: 0; }
.ibody .mod-route { grid-template-columns: minmax(0, 1fr) 120px auto auto; }

/* toast */
#toast { position: fixed; left: 50%; bottom: 26px; z-index: 200; max-width: 80vw; padding: 10px 16px; border-radius: var(--r); background: var(--ink); color: var(--bg); font: 400 12px var(--mono); letter-spacing: .05em; text-transform: uppercase; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transform: translate(-50%, 14px); transition: opacity .2s, transform .2s; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.err { background: var(--err); color: var(--on-accent); }

@keyframes blink { 50% { opacity: .3; } }
