/* VibeField DJ
 * Colour encodes origin: everything from deck A is cobalt, everything from
 * deck B is marigold. Where they meet – the Field – the colours mix.
 * Fonts are system stacks on purpose: the app must run offline from a stick. */

:root {
  --ink: #19152b;
  --plate: #231e3a;
  --plate-2: #2c2648;
  --plate-3: #383157;
  --line: #3a3358;
  --text: #eae6f5;
  --muted: #9c95b8;
  --deck-a: #4f8bff;
  --deck-a-deep: #2449b8;
  --deck-a-soft: #bfd3ff;
  --deck-b: #ffb23e;
  --deck-b-deep: #b86a0a;
  --deck-b-soft: #ffe3b0;
  --clip: #ff4d6d;
  --ok: #3ddc97;
  --hc1: #ff5c8a; --hc2: #3ddc97; --hc3: #b48cff; --hc4: #4fd1e8;
  --hc5: #ff8a3d; --hc6: #e8e05a; --hc7: #ff6fd8; --hc8: #8ae04f;
  --hot: #ff5c8a, #3ddc97, #b48cff, #4fd1e8, #ff8a3d, #e8e05a, #ff6fd8, #8ae04f;
  --font: "Bahnschrift", "DIN Alternate", "DIN 2014", "Barlow Semi Condensed", "Roboto Condensed", "Ubuntu Condensed", "Arial Narrow", system-ui, sans-serif;
  --r-pad: 6px;
  --gap: 12px;
  --ws-width: 380px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
/* the hidden attribute must win over any display rule below */
[hidden] { display: none !important; }

/* An instrument, not a document: dragging a fader or double-clicking a knob
   must never select text, drag images or flash touch highlights. Only real
   text inputs (and anything marked .selectable) stay selectable. */
html {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
input, textarea, select, [contenteditable], .selectable {
  -webkit-user-select: text;
  user-select: text;
}
canvas, img, svg { -webkit-user-drag: none; }
html, body { height: 100%; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--ink);
  color: var(--text);
  font: 400 14px/1.4 var(--font);
  font-stretch: semi-condensed;
  -webkit-font-smoothing: antialiased;
  /* Nothing gets cut off: when the screen is too small for the layout, the
     page scrolls (on a normal screen everything fits and nothing scrolls). */
  overflow-x: hidden;
  overflow-y: auto;
  /* notches and rounded corners (viewport-fit=cover) */
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
button, input, select, textarea { font: inherit; color: inherit; }
/* no double-tap zoom delay on buttons */
button, select, a { touch-action: manipulation; }
.num { font-variant-numeric: tabular-nums; }
:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }

/* ------------------------------------------------------------ layout */
/* one column of exactly the window width (the top bar wraps instead of
   pushing the page wider) */
body { display: grid; grid-template-rows: auto 1fr; grid-template-columns: minmax(0, 1fr); }
.app {
  display: grid;
  grid-template-rows: clamp(110px, 17vh, 170px) auto minmax(140px, 1fr);
  gap: var(--gap);
  padding: 0 var(--gap) var(--gap);
  min-height: 0;
  transition: margin-right .2s ease;
}
body.ws-open .app { margin-right: var(--ws-width); }
.waves-wrap { position: relative; min-height: 0; }
.zoom-btn {
  position: absolute; top: 6px; right: 8px;
  background: color-mix(in srgb, var(--ink) 75%, transparent); color: var(--muted);
}
body.browse .zoom-btn { top: 4px; padding: 1px 8px; font-size: 11.5px; }
.waves {
  width: 100%; height: 100%;
  display: block;
  background: var(--plate);
  border-radius: 10px;
  touch-action: none;
}
.waves.grabbable { cursor: grab; }
.waves.scratching { cursor: grabbing; }
/* browse view (Space): the track list takes the screen */
.dropzones { display: none; grid-template-columns: 1fr 1fr; gap: var(--gap); }
body.browse .app { grid-template-rows: 64px auto minmax(0, 1fr); }
body.browse .stage { display: none; }
body.browse .dropzones { display: grid; }
.dropzone {
  --accent: var(--deck-a);
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 12px;
  padding: 8px 14px; text-align: left; cursor: pointer;
  background: var(--plate); color: var(--text);
  border: 2px dashed color-mix(in srgb, var(--accent) 45%, transparent); border-radius: 10px;
}
.dropzone.dz-b { --accent: var(--deck-b); }
.dropzone:hover { background: var(--plate-2); }
.dropzone.drop { border-style: solid; border-color: var(--accent); background: color-mix(in srgb, var(--accent) 16%, var(--plate)); }
.dropzone.playing { border-style: solid; border-color: color-mix(in srgb, var(--accent) 70%, transparent); }
.dz-text { display: grid; min-width: 0; }
.dz-title { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dz-sub { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dz-time { font-size: 18px; color: var(--accent); }

.stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(330px, 380px) minmax(0, 1fr);
  gap: var(--gap);
}

/* ------------------------------------------------------------ topbar */
.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: 0 var(--gap);
  min-width: 0; min-height: 46px;
}
.brand { display: flex; align-items: center; gap: 8px; font-size: 17px; font-weight: 600; letter-spacing: .01em; margin-right: 8px; white-space: nowrap; }
.brand-mark {
  width: 18px; height: 18px; border-radius: 5px;
  background: linear-gradient(90deg, var(--deck-a) 0 50%, var(--deck-b) 50% 100%);
}
.chip {
  border: 1px solid var(--line); background: transparent; border-radius: 999px;
  padding: 3px 10px; font-size: 12.5px; color: var(--muted); cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 32ch;
}
.chip:hover { color: var(--text); border-color: var(--muted); }
.chip.static { cursor: default; }
.chip.quiet { border-color: transparent; }
.rec-slot { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.chip.fs-btn { display: inline-grid; place-items: center; padding: 3px 8px; color: var(--muted); }
.chip.fs-btn svg { display: block; }
.rec-time { color: var(--clip); min-width: 4ch; }
.rec-after { display: flex; gap: 6px; }

/* ----------------------------------------------------------- buttons */
.btn {
  border: 1px solid var(--line); background: var(--plate-2); border-radius: var(--r-pad);
  padding: 5px 12px; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--plate-3); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.primary { background: var(--text); color: var(--ink); border-color: var(--text); font-weight: 600; }
.btn.primary:hover { background: #fff; }
.btn.quiet { background: transparent; border-color: transparent; color: var(--muted); }
.btn.tiny { padding: 1px 7px; font-size: 12px; }
.btn.big { padding: 10px 26px; font-size: 17px; }
.btn.deck-a { border-color: var(--deck-a-deep); }
.btn.deck-b { border-color: var(--deck-b-deep); }

.pad {
  border: 1px solid var(--line); background: var(--plate-2); color: var(--text);
  border-radius: var(--r-pad); padding: 0 8px; min-height: 36px; cursor: pointer;
  touch-action: none; user-select: none; transition: background .06s;
}
.pad:hover { background: var(--plate-3); }
.pad.pressed { background: var(--text); color: var(--ink); }
.pad.tiny { min-height: 26px; padding: 0 6px; font-size: 12px; }

/* -------------------------------------------------------------- decks */
.deck { --accent: var(--deck-a); --accent-deep: var(--deck-a-deep); }
.deck-b { --accent: var(--deck-b); --accent-deep: var(--deck-b-deep); }
.deck {
  background: var(--plate); border-radius: 10px; padding: 12px;
  display: flex; flex-direction: column; gap: 8px; min-width: 0;
  border-top: 3px solid var(--accent);
}
.deck.drop { outline: 2px dashed var(--accent); outline-offset: -4px; }
.deck-head { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; }
.deck-letter {
  width: 34px; height: 34px; border-radius: 8px; display: grid; place-items: center;
  background: var(--accent); color: var(--ink); font-weight: 700; font-size: 19px;
}
.deck-meta { min-width: 0; }
.deck-title { margin: 0; font-size: 18px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.deck-artist { margin: 0; color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.deck-tempo { text-align: right; line-height: 1; }
.deck-right { display: flex; align-items: center; gap: 10px; }
.deck-key {
  padding: 3px 8px; border: 1px solid var(--line); border-radius: 6px;
  font-size: 15px; font-weight: 600; line-height: 1.2; color: var(--text); white-space: nowrap;
}
.deck-key.shifted { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 60%, transparent); }
.deck-key.unsure { opacity: .6; }
/* loading: the name is there at once, the rest waits greyed out */
.deck .overview, .deck .deck-body, .deck .deck-times, .deck .bpm { transition: opacity .15s, filter .15s; }
.deck.loading .overview, .deck.loading .deck-body, .deck.loading .deck-times { opacity: .42; filter: grayscale(.85); }
.deck.loading .bpm { opacity: .6; }
.deck.loading .bpm-sub { color: var(--accent); }
.deck.loading .load-bar {
  background: repeating-linear-gradient(90deg, transparent 0 10px, color-mix(in srgb, var(--accent) 60%, transparent) 10px 20px);
  background-size: 40px 100%; animation: vf-loading .7s linear infinite;
}
@keyframes vf-loading { to { background-position: 40px 0; } }
.dropzone.loading { border-style: solid; }
.dropzone.loading .dz-sub { color: var(--accent); }
.bpm { display: block; font-size: 34px; font-weight: 600; letter-spacing: -.01em; color: var(--accent); }
.bpm-sub { display: block; font-size: 12px; color: var(--muted); margin-top: 3px; }
.deck-times { display: flex; align-items: center; justify-content: space-between; font-size: 15px; }
.remain { color: var(--muted); }
.phase { display: flex; gap: 4px; }
.phase span { width: 18px; height: 5px; border-radius: 2px; background: var(--line); }
.phase span.on { background: var(--accent); box-shadow: 0 0 8px 1px color-mix(in srgb, var(--accent) 70%, transparent); }
.overview { width: 100%; height: 44px; display: block; cursor: pointer; border-radius: 4px; background: var(--ink); }
.load-bar { height: 2px; margin-top: -6px; }
.load-bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .1s linear; }

.deck-body { display: flex; gap: 10px; min-height: 0; flex: 1; }
.deck-main { flex: 1; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.transport { display: grid; grid-template-columns: 1fr 1.4fr 1fr; gap: 8px; }
.transport .pad { min-height: 52px; font-size: 16px; font-weight: 600; }
.pad.cue { border-color: var(--accent-deep); }
.hotcues { display: grid; grid-template-columns: repeat(8, 1fr); gap: 5px; }
.pad.hot { min-height: 34px; border-color: color-mix(in srgb, var(--hc) 55%, var(--line)); }
.loops { display: flex; flex-wrap: wrap; gap: 5px; }
.loops .pad { min-height: 30px; font-size: 13px; padding: 0 8px; white-space: nowrap; flex: 1 0 auto; }

.pitch-col { display: flex; flex-direction: column; align-items: center; gap: 6px; width: 56px; }
.grid-row {
  display: flex; flex-wrap: wrap; align-items: center; gap: 5px;
  padding: 6px 8px; border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--line)); border-radius: var(--r-pad);
}
.grid-row .pad { min-height: 28px; font-size: 13px; padding: 0 8px; }
.grid-label { color: var(--accent); font-weight: 600; margin-right: 2px; }
.grid-bpm { min-width: 9ch; text-align: center; font-size: 13px; }
.pitch-val { font-size: 11px; color: var(--muted); text-align: center; white-space: nowrap; }
.nudge { display: flex; gap: 4px; }

/* ------------------------------------------------------------- knobs */
.knob-wrap { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.knob {
  --size: 38px;
  width: var(--size); height: var(--size); border-radius: 50%;
  background: conic-gradient(from 225deg, var(--accent, var(--text)) calc(var(--v, .5) * 270deg), var(--line) 0 270deg, transparent 0);
  display: grid; place-items: center; cursor: ns-resize; touch-action: none;
}
.knob-cap {
  width: calc(var(--size) - 8px); height: calc(var(--size) - 8px); border-radius: 50%;
  background: var(--plate-2); position: relative;
  transform: rotate(calc(-135deg + var(--v, .5) * 270deg));
}
.knob-cap::after {
  content: ""; position: absolute; left: 50%; top: 3px; width: 2px; height: 9px; margin-left: -1px;
  background: var(--text); border-radius: 1px;
}
.knob.active .knob-cap { background: var(--plate-3); }
/* fine mode (Shift while dragging): a dashed ring around the control */
.knob.fine, .fader.fine { outline: 1px dashed color-mix(in srgb, var(--accent, var(--text)) 75%, transparent); outline-offset: 3px; }
.knob-label { font-size: 11px; color: var(--muted); }
.knob-wrap.small .knob { --size: 30px; }
.knob-wrap.filter .knob { --accent: var(--text); }

/* ------------------------------------------------------------ faders */
.fader { position: relative; touch-action: none; cursor: pointer; }
.fader.v { width: 34px; flex: 1; min-height: 110px; }
.fader.v::before { content: ""; position: absolute; left: 50%; top: 0; bottom: 0; width: 4px; margin-left: -2px; background: var(--ink); border-radius: 2px; }
.fader .thumb { position: absolute; left: 0; right: 0; height: 18px; border-radius: 4px; background: var(--text); box-shadow: 0 0 0 3px var(--plate); }
.fader.v .thumb { bottom: calc(var(--v, .5) * (100% - 18px)); }
.fader.v[data-invert] .thumb { bottom: auto; top: calc(var(--v, .5) * (100% - 18px)); }
.fader.v.pitch .thumb { background: var(--accent); }
.fader.v.pitch::after { content: ""; position: absolute; left: 4px; right: 4px; top: 50%; height: 1px; background: var(--muted); }
.fader.h { height: 34px; width: 100%; }
.fader.h::before { content: ""; position: absolute; top: 50%; left: 0; right: 0; height: 4px; margin-top: -2px; background: var(--ink); border-radius: 2px; }
.fader.h .thumb { top: 0; bottom: 0; width: 22px; height: auto; left: calc(var(--v, .5) * (100% - 22px)); right: auto; }

/* ------------------------------------------------------------- mixer */
.mixer { background: var(--plate); border-radius: 10px; padding: 12px; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.mixer-top { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; flex: 1 0 auto; }
.channel { --accent: var(--deck-a); display: grid; grid-template-columns: auto auto; justify-content: center; gap: 10px; }
.channel.ch-b { --accent: var(--deck-b); }
.channel.ch-b .knobs { order: 2; }
.knobs { display: flex; flex-direction: column; gap: 4px; }
.knobs .knob { --size: 32px; }
.strip { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.cue-btn { min-height: 26px; font-size: 12px; width: 100%; }
.fader-row { display: flex; gap: 6px; flex: 1; min-height: 120px; justify-content: center; }
.master-col { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 0 4px; border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
.master-col { --accent: var(--text); }
.master-meters { display: flex; gap: 4px; flex: 1; min-height: 60px; }

.meter { width: 7px; background: var(--ink); border-radius: 2px; position: relative; overflow: hidden; }
.meter span {
  position: absolute; inset: 0;
  background: linear-gradient(to top, var(--ok) 0 70%, var(--deck-b) 70% 90%, var(--clip) 90%);
  transform-origin: bottom; transform: scaleY(var(--m, 0));
}
.meter.clip { box-shadow: 0 0 0 1px var(--clip); }
.limiter { font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; }
.eq-mode { width: 100%; letter-spacing: .02em; }

/* the Field */
.xfade { display: flex; flex-direction: column; gap: 6px; }
.field { width: 100%; height: 54px; display: block; border-radius: 6px; background: var(--ink); }
.field-label { margin: 0; font-size: 12px; color: var(--muted); min-height: 1.4em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.xfade-opts { display: flex; align-items: center; gap: 8px; justify-content: space-between; flex-wrap: wrap; }
.modes { display: flex; border: 1px solid var(--line); border-radius: var(--r-pad); overflow: hidden; }
.seg { border: 0; background: transparent; padding: 4px 10px; cursor: pointer; color: var(--muted); }
.seg + .seg { border-left: 1px solid var(--line); }
.seg[aria-checked="true"] {
  background: linear-gradient(90deg, var(--deck-a), var(--deck-b)); color: var(--ink); font-weight: 600;
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / .28), inset 0 0 14px rgb(255 255 255 / .3);
}
/* sweep direction: spectrum icon (bass left, like the Field above), amber =
   the bars deck B takes first, arrow = the way the handover travels */
.sweep-dir { display: inline-flex; align-items: center; justify-content: center; padding: 1px 8px; min-height: 30px; transition: opacity .15s; }
.sweep-dir.on { background: var(--plate-2); }
.sweep-dir:hover { background: var(--plate-3); }
.sweep-dir.idle { opacity: .55; }
.sweep-icon { display: block; overflow: visible; }
.sweep-icon rect { transition: fill .18s; }
.sweep-dir[data-dir="0"] .lo, .sweep-dir[data-dir="1"] .hi { fill: var(--deck-b); }
.sweep-dir[data-dir="0"] .hi, .sweep-dir[data-dir="1"] .lo { fill: var(--deck-a); }
.sweep-icon .arrow path { stroke: var(--text); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.sweep-icon .arrow { transition: transform .18s; transform-origin: 22px 19px; }
.sweep-dir[data-dir="1"] .arrow { transform: scaleX(-1); }

/* ----------------------------------------------------------- library */
.library { background: var(--plate); border-radius: 10px; display: flex; flex-direction: column; min-height: 0; position: relative; container: lib / inline-size; }
/* sources on the left (library, playlists), the list on the right; a row of
   chips above the list when the panel is narrow */
.lib-wrap {
  flex: 1; min-height: 0; display: grid;
  grid-template-columns: minmax(140px, 180px) minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas: "side bar" "side list";
}
.lib-side {
  grid-area: side; display: flex; flex-direction: column; gap: 2px; min-height: 0; overflow-y: auto;
  padding: 8px 6px; border-right: 1px solid var(--line);
}
.lib-src, .pl-item {
  display: flex; align-items: center; gap: 8px; width: 100%; min-width: 0; text-align: left;
  padding: 5px 8px; border: 0; border-radius: var(--r-pad); background: transparent; color: var(--text); cursor: pointer;
}
.lib-src:hover, .pl-item:hover { background: var(--plate-2); }
.lib-src.active, .pl-item.active { background: var(--plate-3); box-shadow: inset 3px 0 var(--text); }
.lib-src .n, .pl-item .n { margin-left: auto; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.lib-src > span:first-child { font-weight: 600; }
.pl-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pl-item.drop { outline: 2px dashed var(--text); outline-offset: -2px; background: var(--plate-2); }
.pl-head { display: flex; align-items: center; gap: 2px; margin: 12px 0 2px; padding: 0 2px 0 8px; color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; }
.pl-head > span { margin-right: auto; }
.pl-head .btn.tiny { min-width: 26px; padding: 0 6px; font-size: 15px; line-height: 1; text-transform: none; }
.pl-list { display: flex; flex-direction: column; gap: 2px; }
.pl-empty { margin: 4px 8px; color: var(--muted); font-size: 12px; line-height: 1.35; }
.lib-restore { align-self: flex-start; margin: 0 0 0 8px; padding: 0; border: 0; background: none; color: var(--muted); font-size: 12px; text-decoration: underline; cursor: pointer; }
.lib-restore:hover { color: var(--text); }
.pl-rename { width: 100%; background: var(--ink); border: 1px solid var(--text); border-radius: var(--r-pad); padding: 4px 8px; }
.pl-bar { display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pl-sort { background: var(--ink); border: 1px solid var(--line); border-radius: var(--r-pad); padding: 5px 6px; max-width: 16em; }
.pl-more { min-width: 34px; font-size: 16px; line-height: 1; }
.library.drop { outline: 2px dashed var(--text); outline-offset: -4px; }
.lib-bar { grid-area: bar; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.lib-bar input[type="search"] { flex: 1; max-width: 420px; background: var(--ink); border: 1px solid var(--line); border-radius: var(--r-pad); padding: 5px 10px; }
.lib-count { color: var(--muted); font-size: 12.5px; margin-left: auto; }
.lib-scroll { grid-area: list; overflow: auto; min-height: 0; }
.lib-table { width: 100%; border-collapse: collapse; }
.lib-table th { position: sticky; top: 0; background: var(--plate); text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 6px 12px; }
.lib-table td { padding: 5px 12px; border-top: 1px solid color-mix(in srgb, var(--line) 50%, transparent); white-space: nowrap; }
.lib-table .num { text-align: right; }
.lib-table tr { cursor: default; }
.lib-table tbody tr:hover { background: var(--plate-2); }
.lib-table tr.marked { background: color-mix(in srgb, var(--plate-3) 85%, var(--text) 7%); }
.lib-table tr.selected { background: var(--plate-3); outline: 1px solid color-mix(in srgb, var(--text) 32%, transparent); outline-offset: -1px; }
.lib-table tr.marked.selected { background: color-mix(in srgb, var(--plate-3) 85%, var(--text) 7%); }
.lib-table tr.missing td { color: var(--muted); }
.lib-table tr.missing .c-status { font-style: italic; }
.lib-table tr.drop-before td { box-shadow: inset 0 2px 0 var(--text); }
.lib-table tr.drop-after td { box-shadow: inset 0 -2px 0 var(--text); }
.lib-table th.sortable { padding: 0; }
.th-btn { padding: 6px 12px; border: 0; background: none; color: inherit; font: inherit; cursor: pointer; white-space: nowrap; }
.th-btn:hover { color: var(--text); }
th.sorted .th-btn { color: var(--text); }
.sort-arrow { margin-left: 4px; font-size: 9px; vertical-align: 1px; }
th.h-key { white-space: nowrap; }
.th-btn.key-fmt { margin: 0 6px 0 -8px; padding: 0 5px; border: 1px solid var(--line); border-radius: 4px; font-size: 10.5px; line-height: 16px; vertical-align: 1px; }
.lib-table .c-pos { color: var(--muted); width: 1%; padding-right: 0; }
.lib-table th.c-pos { padding: 6px 0 6px 12px; }
.c-key { width: 1%; }
.c-key.unsure { opacity: .5; }
.drag-ghost { position: fixed; top: -100px; left: 0; padding: 6px 12px; border-radius: 6px; background: var(--plate-3); color: var(--text); font-size: 13px; }
.lib-table tr.on-a .c-title { box-shadow: inset 3px 0 var(--deck-a); }
.lib-table tr.on-b .c-title { box-shadow: inset 3px 0 var(--deck-b); }
.lib-table tr.on-a.on-b .c-title { box-shadow: inset 3px 0 var(--deck-a), inset 6px 0 var(--deck-b); }
.c-title { max-width: 0; width: 60%; overflow: hidden; text-overflow: ellipsis; }
.c-title .t { margin-right: 8px; }
.c-title .a { color: var(--muted); }
.c-status { color: var(--muted); font-size: 12px; }
.c-load { display: flex; gap: 4px; }
.lib-empty { display: none; padding: 24px; color: var(--muted); }
.lib-note { font-size: 13px; }
.legal { display: flex; gap: 12px; margin-left: 4px; font-size: 12.5px; white-space: nowrap; }
.legal a { color: var(--muted); text-decoration: none; }
.legal a:hover { color: var(--text); text-decoration: underline; }
.gate-warn { color: var(--deck-b); }
.library.empty .lib-empty { display: block; }
@container lib (max-width: 620px) {
  .lib-wrap { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto minmax(0, 1fr); grid-template-areas: "side" "bar" "list"; }
  .lib-side { flex-direction: row; align-items: center; gap: 4px; overflow-x: auto; overflow-y: hidden; scrollbar-width: thin; padding: 6px 8px; border-right: 0; border-bottom: 1px solid var(--line); }
  .lib-src, .pl-item { width: auto; flex: none; max-width: 16em; }
  .pl-list { flex-direction: row; gap: 4px; }
  .pl-head { margin: 0 2px; padding: 0; }
  .pl-head > span, .pl-empty { display: none; }
  .lib-restore { flex: none; margin: 0 4px; white-space: nowrap; }
  .pl-rename { width: 12em; flex: none; }
}
@container lib (max-width: 460px) {
  .h-len, .c-len, .h-status, .c-status { display: none; }
}
.library.empty .lib-table { display: none; }

/* --------------------------------------------------------- effects */
/* the chains (A cobalt, master neutral, B marigold) get a column right of
   the library; a slot's settings open in a drawer on the right like the
   workshop */
:root { --fxe-width: 380px; }
/* open: the library stays where it was (left), the chains get a column on
   the right of it – nothing new users would have to look for */
body.fx-open .app {
  grid-template-columns: minmax(0, 1fr) minmax(360px, 38%);
  grid-template-rows: clamp(110px, 17vh, 170px) auto minmax(0, 1fr);
  grid-template-areas: "waves waves" "stage stage" "lib fx";
}
body.fx-open .waves-wrap { grid-area: waves; }
body.fx-open .stage { grid-area: stage; }
body.fx-open .library { grid-area: lib; }
body.fx-open .fxpanel { grid-area: fx; }
body.fxe-open .app { margin-right: var(--fxe-width); }
body.fxe-open.ws-open .app { margin-right: calc(var(--ws-width) + var(--fxe-width)); }
body.browse .fxpanel { display: none; }
.fxpanel {
  background: var(--plate); border-radius: 10px; padding: 5px 10px; min-width: 0; min-height: 0;
  overflow-y: auto; container: fxp / size;
}
/* The chains one below the other, their slots 2 × 2 when the column is
   wide enough. When it is too low for all three, tabs (A · B · Master, with
   a LED when something runs there) show one chain at a time. */
.fx-chains { display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; }
.fx-tabs { display: none; align-items: center; gap: 4px; margin-bottom: 4px; }
.fx-tool { display: none; align-items: center; gap: 6px; margin-left: 4px; }
.fx-tool.tab-active { display: flex; }
.fx-tool .knob-wrap { flex-direction: row; gap: 4px; }
/* the small buttons in the chain rows stay as low as the rows themselves */
.fx-slot .pad.tiny, .fx-head .pad.tiny, .fx-tool .pad.tiny { min-height: 22px; }
.fx-tab {
  flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-width: 0;
  border: 1px solid var(--line); border-radius: var(--r-pad); background: transparent; color: var(--muted);
  padding: 1px 8px; cursor: pointer; white-space: nowrap; font-size: 13px;
}
.fx-tab:hover { color: var(--text); background: var(--plate-2); }
.fx-tab[aria-selected="true"] { color: var(--text); background: var(--plate-2); border-color: var(--accent); box-shadow: inset 0 -2px 0 var(--accent); }
.fx-tab .fx-letter { width: 18px; height: 18px; font-size: 11px; }
.fx-tab-led { width: 7px; height: 7px; border-radius: 50%; background: var(--line); }
.fx-tab-led.on { background: var(--accent); box-shadow: 0 0 6px 1px color-mix(in srgb, var(--accent) 70%, transparent); }
/* tab mode: too low for all three chains (2 × 2 needs ≈ 300 px, one slot
   per row ≈ 430 px); the chain's header row moves into the tab bar */
@container fxp (min-width: 620px) and (max-height: 300px) {
  .fx-tabs { display: flex; }
  .fx-chain:not(.tab-active), .fx-chain .fx-head { display: none; }
}
@container fxp (max-width: 619px) and (max-height: 430px) {
  .fx-tabs { display: flex; }
  .fx-chain:not(.tab-active), .fx-chain .fx-head { display: none; }
}
.fx-a { --accent: var(--deck-a); --accent-deep: var(--deck-a-deep); }
.fx-b { --accent: var(--deck-b); --accent-deep: var(--deck-b-deep); }
.fx-m { --accent: var(--text); --accent-deep: var(--muted); }
.fx-chain { min-width: 0; }
.fx-head { display: flex; align-items: center; gap: 8px; min-height: 24px; border-bottom: 2px solid var(--accent); padding-bottom: 2px; }
.fx-letter {
  width: 20px; height: 20px; border-radius: 5px; display: grid; place-items: center; flex: none;
  background: var(--accent); color: var(--ink); font-weight: 700; font-size: 12px;
}
.fx-title { font-weight: 600; margin-right: auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fx-chain-on { min-width: 34px; min-height: 22px; font-weight: 600; letter-spacing: .03em; }
.fx-head .knob-wrap { flex-direction: row; gap: 4px; }
.knob-wrap.tiny .knob { --size: 22px; }
.knob-wrap.tiny .knob-cap::after { top: 2px; height: 5px; }
.knob-val { font-size: 11px; color: var(--text); min-width: 5ch; text-align: center; white-space: nowrap; }
.fx-slots { list-style: none; margin: 2px 0 0; padding: 0; display: grid; gap: 1px; }
/* 2 × 2 only where even "Multiband-Kompressor" fits in the menu */
@container fxp (min-width: 620px) {
  .fx-slots { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); column-gap: 10px; }
}
.fx-slot {
  display: grid; grid-template-columns: 12px auto minmax(0, 1fr) auto auto 8px; align-items: center; gap: 4px;
  padding: 0 4px; border-radius: var(--r-pad); border: 1px solid transparent; cursor: pointer;
}
.fx-slot:hover { background: var(--plate-2); }
.fx-slot.selected { background: var(--plate-2); border-color: color-mix(in srgb, var(--accent) 55%, var(--line)); }
.fx-num { color: var(--muted); font-size: 11.5px; text-align: right; }
.fx-on { min-height: 22px; width: 26px; padding: 0; font-size: 12px; }
.fx-edit { min-height: 22px; width: 26px; padding: 0; font-size: 12px; color: var(--muted); }
.fx-slot.empty .fx-edit { visibility: hidden; }
.fx-kind {
  min-width: 0; width: 100%; height: 21px; background: var(--ink); border: 1px solid var(--line); border-radius: var(--r-pad);
  padding: 0 6px; font-size: 13px; color: var(--text);
}
.fx-slot.empty .fx-kind { color: var(--muted); }
.knob.fx-meta { --size: 22px; }
.knob.fx-meta .knob-cap::after { top: 2px; height: 5px; }
.knob.fx-meta.off { opacity: .25; pointer-events: none; }
.fx-live { width: 8px; height: 8px; border-radius: 50%; background: transparent; }
.fx-live[data-live="on"] { background: var(--accent); box-shadow: 0 0 6px var(--accent); }
.fx-live[data-live="tail"] { background: color-mix(in srgb, var(--accent) 45%, transparent); }

/* drawer */
.fx-drawer {
  position: fixed; top: 46px; right: 0; bottom: 0; width: var(--fxe-width); z-index: 19;
  background: var(--plate); border-left: 3px solid var(--accent, var(--line)); overflow: auto;
}
body.ws-open .fx-drawer { right: var(--ws-width); }
.fx-editor { display: flex; flex-direction: column; gap: 10px; padding: 12px 14px 16px; }
.fx-ed-title { display: flex; align-items: center; gap: 8px; }
.fx-ed-title h2 { margin: 0 auto 0 0; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fx-editor > .fx-kind { height: 30px; font-size: 15px; font-weight: 600; }
.fx-ed-info { margin: 0; color: var(--muted); font-size: 12.5px; line-height: 1.35; }
.fx-ed-empty { margin: 0; color: var(--muted); }
.fx-ed-head { display: flex; align-items: center; gap: 10px; }
.fx-ed-head .knob-wrap { flex-direction: row; gap: 6px; }
.fx-ed-head .fx-on { width: auto; padding: 0 10px; min-height: 26px; }
.fx-ed-body { display: flex; flex-direction: column; gap: 10px; }
.fx-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px 4px; align-items: start; }
.fx-knob { min-width: 0; }
.fx-knob .knob-label { text-align: center; line-height: 1.15; }
.fx-ctl { display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; }
.fx-ctl-toggle { justify-content: center; align-self: center; }
.fx-ctl-seg { grid-column: span 2; }
.fx-toggle { min-height: 28px; }
.fx-seg .seg { padding: 3px 7px; font-size: 12.5px; white-space: nowrap; }
.fx-group { display: flex; flex-direction: column; gap: 4px; padding: 4px 6px 6px; border: 1px solid var(--line); border-radius: 8px; }
.fx-group-title { font-size: 11.5px; color: var(--accent); font-weight: 600; letter-spacing: .02em; }
.fx-group-body { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px 2px; }
.fx-bandgrid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.fx-band .fx-group-body { grid-template-columns: 1fr; }
.fx-bands { width: 100%; height: 120px; display: block; background: var(--ink); border-radius: 6px; touch-action: none; cursor: ns-resize; }
.fx-graphic { display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); gap: 2px; }
.fx-gfader { display: flex; flex-direction: column; align-items: center; gap: 3px; min-width: 0; }
.fx-gfader .knob-val { min-width: 0; font-size: 10px; }
.fx-gfader .fader.v { min-height: 120px; height: 120px; flex: none; width: 26px; }
.fx-gfader .fader.v::after { content: ""; position: absolute; left: 4px; right: 4px; top: 50%; height: 1px; background: var(--muted); }
.fx-gfader .fader .thumb { background: var(--accent); }
.fx-graphic + .fx-knob { align-self: flex-start; }
.fx-grbox { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px; }
.fx-gr { height: 8px; background: var(--ink); border-radius: 3px; overflow: hidden; }
.fx-gr span { display: block; height: 100%; background: var(--clip); transform-origin: left; transform: scaleX(var(--m, 0)); }
.fx-gr-val { font-size: 12px; min-width: 7ch; text-align: right; }
.fx-lfo { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); opacity: .2; margin-left: auto; }

/* ------------------------------------------------ lit buttons (LEDs) */
/* Switches look like the buttons of a controller. Off: dark, with a faint
   ring in their colour (so you can tell it is a switch). On: filled with that
   colour, dark bold text and a glow around it like a lit LED. --lit is the
   colour: the deck's or channel's accent (white on the master), the cue
   colour for hot cues, red for recording and the limiter lamp. */
.pad.play, .pad.loop, .pad.key, .pad.grid-toggle, .cue-btn, .eq-mode, .fx-on, .fx-chain-on, .fx-toggle, .btn, .seg {
  --lit: var(--accent, var(--text));
}
.pad.hot { --lit: var(--hc); }
.btn.rec, .limiter { --lit: var(--clip); }
.pad.play, .pad.loop, .pad.key, .pad.grid-toggle, .cue-btn, .eq-mode, .fx-on, .fx-chain-on, .fx-toggle {
  border-color: color-mix(in srgb, var(--lit) 42%, var(--line));
}
.pad, .btn, .chip, .seg, .limiter {
  transition: background .08s, color .08s, border-color .1s, box-shadow .18s, filter .08s;
}
:is(.pad.play, .pad.loop, .pad.key, .pad.grid-toggle, .cue-btn, .eq-mode, .fx-on, .fx-chain-on).on,
.pad.hot.set,
:is(.fx-toggle, .btn)[aria-pressed="true"],
.limiter.on {
  background: var(--lit);
  color: var(--ink);
  border-color: var(--lit);
  font-weight: 600;
  box-shadow:
    0 0 0 1px var(--lit),
    0 0 10px 1px color-mix(in srgb, var(--lit) 55%, transparent),
    0 0 26px 4px color-mix(in srgb, var(--lit) 22%, transparent),
    inset 0 1px 0 rgb(255 255 255 / .35);
}
:is(.pad.play, .pad.loop, .pad.key, .pad.grid-toggle, .cue-btn, .eq-mode, .fx-on, .fx-chain-on).on:hover,
.pad.hot.set:hover, :is(.fx-toggle, .btn)[aria-pressed="true"]:hover { filter: brightness(1.1); }
:is(.pad.play, .pad.loop, .pad.key, .pad.grid-toggle, .cue-btn, .eq-mode, .fx-on, .fx-chain-on).on.pressed,
.pad.hot.set.pressed { filter: brightness(.85); }
/* hot cues that are set glow in their colour, a little softer */
.pad.hot.set {
  box-shadow: 0 0 0 1px var(--lit), 0 0 9px 0 color-mix(in srgb, var(--lit) 50%, transparent), inset 0 1px 0 rgb(255 255 255 / .3);
}
/* recording: the red lamp breathes */
.btn.rec[aria-pressed="true"] { animation: rec-glow 1.6s ease-in-out infinite; }
@keyframes rec-glow {
  50% { box-shadow: 0 0 0 1px var(--lit), 0 0 16px 3px color-mix(in srgb, var(--lit) 70%, transparent), 0 0 34px 8px color-mix(in srgb, var(--lit) 30%, transparent), inset 0 1px 0 rgb(255 255 255 / .35); }
}
/* segments sit in a clipped group: the glow goes inwards */
.fx-seg .seg[aria-checked="true"] {
  background: var(--lit); color: var(--ink); font-weight: 600;
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / .28), inset 0 0 12px rgb(255 255 255 / .3);
}
/* chips (top bar, set editor lanes): on = bright outline with a soft glow */
.chip[aria-pressed="true"], .se-lanes .chip.on {
  opacity: 1; color: var(--text); background: var(--plate-3); border-color: var(--text);
  box-shadow: 0 0 0 1px rgb(255 255 255 / .2), 0 0 12px -2px rgb(255 255 255 / .45);
}
/* effects running: a green LED in the chip */
.chip.fx-chip.live { color: var(--text); }
.chip.fx-chip.live::before {
  content: ""; display: inline-block; width: 7px; height: 7px; margin-right: 6px; border-radius: 50%; vertical-align: 1px;
  background: var(--ok); box-shadow: 0 0 6px 1px color-mix(in srgb, var(--ok) 70%, transparent);
}

/* ------------------------------------------------------- workshop */
.workshop {
  position: fixed; top: 46px; right: 0; bottom: 0; width: var(--ws-width);
  background: var(--plate); border-left: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 10px; padding: 14px; overflow: auto; z-index: 20;
}
.ws-head { display: flex; align-items: center; justify-content: space-between; }
.ws-head h2 { margin: 0; font-size: 18px; }
.ws-close { background: none; border: 0; font-size: 18px; cursor: pointer; color: var(--muted); }
.ws-port { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 12px; }
.ws-port select, .ws-form input, .workshop textarea {
  background: var(--ink); border: 1px solid var(--line); border-radius: var(--r-pad); padding: 6px 8px; color: var(--text);
}
.ws-monitor { margin: 0; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.ws-tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); }
.ws-tab { background: none; border: 0; padding: 6px 7px; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; font-size: 13px; }
.ws-tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--text); }
.ws-body { display: flex; flex-direction: column; gap: 10px; }
.ws-instruction { font-size: 18px; line-height: 1.35; margin: 4px 0; }
.ws-count, .ws-existing { margin: 0; color: var(--muted); font-size: 12px; }
.ws-status { min-height: 2.6em; margin: 0; }
.ws-status[data-kind="ok"] { color: var(--ok); }
.ws-status[data-kind="hint"] { color: var(--deck-b); }
.ws-row { display: flex; gap: 6px; flex-wrap: wrap; }
.ws-progress { height: 4px; background: var(--ink); border-radius: 2px; overflow: hidden; }
.ws-progress span { display: block; height: 100%; width: calc(var(--p) * 100%); background: linear-gradient(90deg, var(--deck-a), var(--deck-b)); }
.ws-empty { color: var(--muted); }
.ws-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.ws-table th { text-align: left; color: var(--muted); font-weight: 500; padding: 4px; }
.ws-table td { padding: 4px; border-top: 1px solid var(--line); vertical-align: top; }
.ws-table td:last-child { display: flex; gap: 4px; flex-wrap: wrap; }
.ws-form { display: grid; gap: 8px; }
.ws-form label { display: grid; gap: 3px; font-size: 12px; color: var(--muted); }
.ws-form .ws-check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 14px; }
.workshop h3 { margin: 10px 0 0; font-size: 14px; }
.ws-file { font-size: 12px; color: var(--muted); display: grid; gap: 4px; }

/* the control the workshop is waiting for */
.learn-target { outline: 2px solid var(--text) !important; outline-offset: 3px; animation: learn 1s ease-in-out infinite alternate; }
@keyframes learn { from { outline-color: var(--text); } to { outline-color: transparent; } }
body.learning .ctl { cursor: crosshair; }
body.learning .ctl:hover { outline: 1px dashed var(--muted); outline-offset: 2px; }

/* --------------------------------------------------- overlays, toasts */
.gate {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  background: color-mix(in srgb, var(--ink) 88%, transparent);
}
.gate-inner { max-width: 44ch; text-align: center; display: grid; gap: 14px; justify-items: center; }
.gate-title {
  margin: 0; font-size: 44px; font-weight: 700; letter-spacing: -.01em;
  background: linear-gradient(90deg, var(--deck-a), var(--deck-b));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.toasts { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); display: grid; gap: 6px; z-index: 60; pointer-events: none; }
.toast {
  background: var(--plate-3); border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px;
  max-width: min(64ch, calc(100vw - 24px)); box-shadow: 0 6px 24px rgba(0, 0, 0, .35); transition: opacity .3s;
}
.toast.error { border-color: var(--clip); }
.toast.action { border-color: var(--deck-b); }
.toast.out { opacity: 0; }
.toast.with-action { pointer-events: auto; display: flex; align-items: center; gap: 14px; }
.toast-btn { flex: none; }
.ctx-menu {
  position: fixed; z-index: 70; min-width: 210px; max-width: min(320px, calc(100vw - 8px)); max-height: calc(100vh - 8px); overflow-y: auto;
  padding: 4px; background: var(--plate-2); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 10px 30px rgba(0, 0, 0, .45);
}
.ctx-item {
  display: flex; align-items: center; gap: 16px; width: 100%; padding: 6px 10px; text-align: left;
  border: 0; border-radius: 5px; background: none; color: var(--text); cursor: pointer;
}
.ctx-item > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ctx-item:hover, .ctx-item:focus-visible { background: var(--plate-3); outline: none; }
.ctx-item:disabled { color: var(--muted); cursor: default; background: none; }
.ctx-item kbd { margin-left: auto; color: var(--muted); font: inherit; font-size: 11.5px; }
.ctx-head { padding: 6px 10px 2px; color: var(--muted); font-size: 11.5px; }
.ctx-sep { height: 1px; margin: 4px 6px; background: var(--line); }
.dlg { background: var(--plate); color: var(--text); border: 1px solid var(--line); border-radius: 12px; padding: 18px; max-width: min(520px, calc(100vw - 24px)); }
.dlg::backdrop { background: rgba(10, 8, 20, .6); }
.dlg h2 { margin: 0 0 12px; font-size: 18px; }
.dlg-row { display: flex; align-items: center; gap: 8px; margin: 8px 0; }
.dlg-row select { flex: 1; background: var(--ink); border: 1px solid var(--line); border-radius: var(--r-pad); padding: 5px; }
.dlg-row.check { align-items: flex-start; }
.dlg-note { color: var(--muted); font-size: 13px; }
.dlg-group { border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px 4px; margin: 10px 0; display: flex; flex-direction: column; gap: 6px; }
.dlg-group legend { padding: 0 4px; font-size: 13px; color: var(--text); }
.dlg-group .btn { align-self: flex-start; }
.phones-status { color: var(--text); }
.route-row { display: grid; grid-template-columns: 6.5em 1fr auto; align-items: center; gap: 8px; }
.route-row select { min-width: 0; }
.dlg-group details summary { cursor: pointer; color: var(--text); }
.dlg-group details p { margin: 6px 0 0; }
.dlg-actions { display: flex; justify-content: flex-end; margin-top: 14px; }
.keys th { text-align: left; padding: 3px 14px 3px 0; font-weight: 600; white-space: nowrap; }
.keys td { color: var(--muted); }

/* --------------------------------------------------------- responsive */
/* Laptops (768–860 px high): a bit more compact, so the decks and the whole
   mixer fit without scrolling. */
@media (max-height: 860px) {
  .app { grid-template-rows: clamp(84px, 13vh, 110px) auto minmax(120px, 1fr); }
  body.fx-open .app { grid-template-rows: clamp(52px, 8vh, 96px) auto minmax(0, 1fr); }
  .deck { padding: 10px; gap: 6px; }
  .transport .pad { min-height: 44px; }
  .overview { height: 36px; }
  .mixer { padding: 10px; gap: 8px; }
  .knobs { gap: 1px; }
  .knobs .knob { --size: 27px; }
  .knobs .knob-label { font-size: 10.5px; line-height: 1.25; }
  .master-col { gap: 5px; }
  .master-col .knob { --size: 30px; }
  .master-meters { min-height: 40px; }
  .fader-row { min-height: 96px; }
  .field { height: 40px; }
}
/* Tablets and small windows: decks side by side, the mixer below them in
   one row (channels and master left, crossfader right). The page scrolls. */
@media (max-width: 1180px) {
  .app { grid-template-rows: clamp(84px, 13vh, 140px) auto minmax(300px, 1fr); }
  body.fx-open .app { grid-template-rows: clamp(84px, 13vh, 140px) auto minmax(300px, 1fr); }
  .stage { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .mixer { grid-column: 1 / -1; order: 3; flex-direction: row; align-items: stretch; gap: 14px; }
  .mixer-top { flex: none; }
  .xfade { flex: 1; min-width: 0; justify-content: center; }
  body.ws-open .app { margin-right: 0; }
  .workshop { width: min(var(--ws-width), 100%); }
  body.fxe-open .app, body.fxe-open.ws-open .app { margin-right: 0; }
  .fx-drawer { width: min(var(--fxe-width), 100%); }
  body.ws-open .fx-drawer { right: 0; }
}
/* Phones: one column – waveforms, deck A, mixer, deck B, effects, library. */
@media (max-width: 760px) {
  :root { --gap: 8px; }
  /* top bar in two rows: logo · language · fullscreen, then the rest */
  .topbar { flex-wrap: wrap; row-gap: 6px; padding-block: 6px; }
  .topbar > * { order: 2; }
  .topbar > .brand { order: 0; margin-right: auto; }
  .topbar > .lang, .topbar > .fs-btn { order: 1; }
  .topbar .chip { max-width: 20ch; }
  .topbar .chip.static, .legal { display: none; }
  .rec-slot { margin-left: 0; }
  .app { grid-template-rows: 96px auto auto auto; }
  body.fx-open .app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 96px auto auto auto;
    grid-template-areas: "waves" "stage" "fx" "lib";
  }
  /* in the page flow on phones: as tall as its content, never tabs */
  .fxpanel { overflow: visible; min-height: auto; container: fxp / inline-size; }
  .stage { grid-template-columns: minmax(0, 1fr); }
  .mixer { order: 0; flex-direction: column; padding: 10px; }
  .mixer-top { gap: 6px; }
  .channel { gap: 6px; }
  .master-col { padding: 0 2px; }
  .library { height: 75vh; height: 75dvh; }
  /* side panels take the whole screen (the top bar may wrap to two rows) */
  .fx-drawer, .workshop { width: 100%; top: 0; z-index: 30; }
  .hotcues { grid-template-columns: repeat(4, 1fr); }
  .deck-tempo .bpm { font-size: 28px; }
  .dropzones { grid-template-columns: minmax(0, 1fr); }
  body.browse .app { grid-template-rows: auto auto minmax(60vh, 1fr); }
}
/* Touch only (no keyboard to speak of): no keyboard help */
@media (hover: none) and (pointer: coarse) {
  .keys-chip { display: none; }
}
/* Fingers instead of a mouse: bigger targets. */
@media (pointer: coarse) {
  .pad { min-height: 40px; }
  .pad.tiny { min-height: 34px; min-width: 34px; }
  .pad.hot { min-height: 42px; }
  .loops .pad, .grid-row .pad { min-height: 38px; }
  .chip { padding: 6px 12px; }
  .fx-on, .fx-edit { min-height: 34px; width: 36px; }
  .fx-slot .pad.tiny, .fx-head .pad.tiny, .fx-tool .pad.tiny { min-height: 34px; }
  .fx-kind { height: 34px; }
  .knob.fx-meta, .knob-wrap.tiny .knob { --size: 30px; }
  .fader.h { height: 44px; }
  .fader.h .thumb { width: 30px; left: calc(var(--v, .5) * (100% - 30px)); }
  .seg { padding: 8px 12px; }
}
@media (prefers-reduced-motion: reduce) {
  .learn-target, .btn.rec[aria-pressed="true"] { animation: none; }
  .app, .load-bar span, .toast { transition: none; }
  .deck.loading .load-bar { animation: none; }
}

/* ------------------------------------------------------------ set editor */
.se-overlay {
  position: fixed; inset: 0; z-index: 40;
  display: grid; grid-template-rows: auto auto minmax(0, 1fr) 34px auto;
  gap: 8px; padding: 12px 16px;
  background: var(--ink); color: var(--text);
}
.se-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.se-head h2 { margin: 0; font-size: 18px; }
.se-info { color: var(--muted); font-size: 13px; }
.se-status { color: var(--muted); font-size: 13px; flex: 1; min-width: 12em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.se-status.error { color: var(--clip); }
.se-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.se-toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; min-height: 32px; font-size: 13px; }
.se-selinfo { color: var(--text); }
.se-seltools { display: flex; gap: 4px; flex-wrap: wrap; }
.se-seltools[hidden] { display: none; }
.se-kinds { display: flex; align-items: center; gap: 10px; color: var(--muted); margin-left: auto; }
.se-check { display: inline-flex; align-items: center; gap: 4px; color: var(--text); cursor: pointer; }
.se-scroll { position: relative; overflow-y: auto; overflow-x: hidden; border-radius: 10px; background: var(--plate); }
.se-canvas { display: block; width: 100%; touch-action: none; }
.se-mini { display: block; width: 100%; height: 34px; border-radius: 6px; cursor: pointer; touch-action: none; }
.se-tip {
  position: absolute; pointer-events: none; z-index: 2;
  background: var(--plate-3); color: var(--text); border: 1px solid var(--line);
  border-radius: 6px; padding: 3px 8px; font-size: 12px; white-space: nowrap;
}
.se-foot { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.se-lanes { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.se-lanes .chip { font-size: 11.5px; padding: 1px 8px; opacity: 0.55; }
.se-hint { margin-left: auto; }
body.set-editing { overflow: hidden; }

/* ---------------------------------------------------------- languages */
.lang { position: relative; flex: none; }
.lang-btn { display: inline-flex; align-items: center; gap: 6px; max-width: none; overflow: visible; }
.lang-btn[aria-expanded="true"] { color: var(--text); border-color: var(--muted); }
.lang-code { font-size: 11.5px; font-weight: 600; letter-spacing: .06em; }
.lang-chevron {
  width: 6px; height: 6px; margin: 0 1px 2px 1px;
  border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg); transition: transform .15s;
}
.lang-btn[aria-expanded="true"] .lang-chevron { transform: rotate(-135deg); margin: 2px 1px 0 1px; }
.flag {
  display: inline-block; flex: none; width: 20px; height: 14px; border-radius: 3px; overflow: hidden;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .14);
}
.flag svg { display: block; width: 100%; height: 100%; }
.lang-menu {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 60;
  display: grid; grid-template-columns: repeat(3, minmax(150px, 1fr)); gap: 2px;
  padding: 8px; border-radius: 12px; border: 1px solid var(--line);
  background: color-mix(in srgb, var(--plate) 92%, black);
  box-shadow: 0 18px 50px rgba(0, 0, 0, .55);
}
.lang-menu[hidden] { display: none; }
.lang-item {
  direction: ltr; /* same row layout in every language, also in fa/he */
  display: flex; align-items: center; gap: 10px; min-width: 0;
  padding: 7px 10px; border: 0; border-radius: 8px; background: transparent;
  color: var(--text); font: inherit; font-size: 13.5px; text-align: start; cursor: pointer;
}
.lang-item span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lang-item:hover, .lang-item:focus-visible { background: var(--plate-3); outline: none; }
.lang-item[aria-checked="true"] { background: color-mix(in srgb, var(--deck-a) 22%, var(--plate-2)); font-weight: 600; }
@media (max-width: 720px) {
  .lang-menu { grid-template-columns: repeat(2, minmax(130px, 1fr)); }
}
.gate-lang { position: absolute; top: 14px; right: 18px; }
.gate-lang .lang-menu { max-height: calc(100vh - 80px); overflow: auto; }

/* Persian and Hebrew: the DJ layout stays as on hardware (deck A left),
   but every text runs in its own direction */
:root[data-rtl] :is(p, li, label, legend, summary, h1, h2, h3, td, th, button, option, .toast, .chip, .field-label, .se-status, .se-hint, .se-selinfo, .ws-instruction, .dz-sub, .deck-artist) {
  unicode-bidi: plaintext;
}
:root[data-rtl] :is(p, li, label, legend, summary, h1, h2, h3, td, th, .toast, .ws-instruction, .se-hint) { text-align: start; }
:root[data-rtl] .gate-inner p { text-align: center; }

/* ------------------------------------------------------- phones */
/* Shown only where needed: the library chip (phones) and the hint to turn
   the phone (upright phones). */
.lib-chip, .rotate-hint { display: none; }
@media (max-width: 760px) {
  .lib-chip { display: inline-block; }
}
@media (orientation: portrait) and (max-width: 760px) and (pointer: coarse) {
  .rotate-hint {
    display: flex; align-items: center; gap: 10px; position: fixed; left: 8px; right: 8px; bottom: calc(8px + env(safe-area-inset-bottom));
    z-index: 55; padding: 8px 10px 8px 14px; border-radius: 10px; font-size: 13px;
    background: var(--plate-3); border: 1px solid var(--line); box-shadow: 0 6px 24px rgba(0, 0, 0, .4);
  }
  .rotate-hint span { flex: 1; }
}

/* Phones held sideways (≈ 340–540 px high): one screen, no scrolling –
   flat waveforms, deck A | mixer | deck B in one row. The library opens big
   from the top bar ("Library"), the effects as a sheet over the decks. */
@media (orientation: landscape) and (max-height: 540px) {
  :root { --gap: 6px; }
  body { height: 100vh; height: 100dvh; grid-template-rows: auto minmax(0, 1fr); }
  .topbar {
    flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; scrollbar-width: none;
    min-height: 34px; padding-block: 3px; gap: 6px;
  }
  .topbar::-webkit-scrollbar { display: none; }
  .topbar > * { flex: none; }
  .brand { font-size: 14px; margin-right: 0; }
  .topbar .chip { max-width: 22ch; padding: 4px 10px; }
  .topbar .chip.static, .legal, .keys-chip { display: none; }
  .lib-chip { display: inline-block; }
  .lib-chip[aria-pressed="true"] { color: var(--ink); background: var(--text); border-color: var(--text); }
  .rec-slot { margin-left: 0; }

  .app, body.fx-open .app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 50px minmax(0, 1fr);
    grid-template-areas: none;
    gap: var(--gap); padding: 0 var(--gap) var(--gap); min-height: 0;
  }
  body.fx-open .waves-wrap, body.fx-open .stage { grid-area: auto; }
  .zoom-btn { display: none; }
  .library { display: none; }
  body.browse .app { grid-template-rows: 40px auto minmax(0, 1fr); }
  body.browse .library { display: flex; height: auto; }
  .dropzone { padding: 4px 10px; }
  .dz-title { font-size: 14px; }

  /* effects: a sheet over the decks */
  body.fx-open .fxpanel {
    position: fixed; left: var(--gap); right: var(--gap); bottom: var(--gap); z-index: 25;
    height: min(72dvh, 300px); box-shadow: 0 -8px 30px rgba(0, 0, 0, .5); border: 1px solid var(--line);
  }

  .stage { grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: var(--gap); min-height: 0; }

  /* decks */
  .deck { padding: 6px 8px; gap: 4px; border-top-width: 2px; min-height: 0; overflow: hidden; }
  .deck-head { gap: 6px; }
  .deck-letter { width: 22px; height: 22px; font-size: 13px; border-radius: 5px; }
  .deck-title { font-size: 13px; }
  .deck-artist { display: none; }
  .deck-right { gap: 6px; }
  .bpm { font-size: 18px; }
  .bpm-sub { font-size: 10px; margin-top: 1px; }
  .deck-key { font-size: 11px; padding: 1px 5px; }
  .deck-times { font-size: 11px; }
  .phase span { width: 12px; height: 4px; }
  .overview { height: 20px; }
  .load-bar { margin-top: -4px; }
  .deck-body { gap: 6px; }
  .deck-main { gap: 4px; }
  .transport { gap: 4px; }
  /* the main buttons grow with the room there is (fullscreen, taller phones) */
  .transport .pad { min-height: clamp(30px, 10.5dvh, 46px); font-size: 13px; }
  .hotcues { grid-template-columns: repeat(8, 1fr); gap: 3px; }
  .pad.hot { min-height: clamp(26px, 8dvh, 36px); font-size: 12px; padding: 0; }
  .loops { gap: 3px; }
  .loops .pad, .grid-row .pad { min-height: 24px; font-size: 11.5px; padding: 0 5px; }
  .grid-row { padding: 3px 4px; gap: 3px; }
  .pitch-col { width: 38px; gap: 3px; }
  .pitch-col .pad.tiny { min-height: 22px; min-width: 0; width: 34px; padding: 0; font-size: 11px; }
  .fader.v.pitch { width: 26px; min-height: 50px; }
  .pitch-val { font-size: 9px; }
  .nudge { gap: 2px; }
  .nudge .pad.tiny { width: 16px; }

  /* mixer */
  .mixer { grid-column: auto; order: 0; flex-direction: column; align-items: stretch; padding: 6px 8px; gap: 5px; min-height: 0; }
  .mixer-top { gap: 6px; flex: 1 1 auto; min-height: 0; }
  .channel { gap: 4px; }
  .knobs { gap: 0; }
  .knobs .knob, .master-col .knob { --size: 24px; }
  .knob-label, .knobs .knob-label { font-size: 9px; line-height: 1.15; }
  .knob-cap::after { top: 2px; height: 6px; }
  .strip { gap: 4px; }
  .strip .pad { min-height: 24px; font-size: 11px; padding: 0 6px; }
  .fader-row { min-height: 0; gap: 4px; }
  .fader.v.vol { width: 26px; min-height: 60px; }
  .master-col { gap: 3px; padding: 0 3px; }
  .master-meters { min-height: 24px; }
  .limiter { font-size: 9px; }
  .eq-mode, .master-col .pad.tiny { min-height: 22px; min-width: 0; font-size: 10px; padding: 0 5px; }
  .field, .field-label { display: none; }
  .xfade { gap: 4px; flex: none; }
  .fader.h { height: 26px; }
  .fader.h .thumb { width: 22px; left: calc(var(--v, .5) * (100% - 22px)); }
  .xfade-opts { gap: 4px; flex-wrap: nowrap; }
  .seg { padding: 3px 7px; font-size: 11.5px; }
  .sweep-dir { min-height: 24px; padding: 0 4px; }
  .xfade-opts .knob-wrap { flex-direction: row; gap: 3px; }
  .xfade-opts .knob { --size: 22px; }
}
@media (orientation: landscape) and (max-height: 540px) {
  .dropzones { grid-template-columns: 1fr 1fr; }
  .dz-sub { font-size: 11px; }
}
/* small phones with the address bar showing (≈ 340 px): a bit tighter still */
@media (orientation: landscape) and (max-height: 380px) {
  .app, body.fx-open .app { grid-template-rows: 42px minmax(0, 1fr); }
  .knobs .knob, .master-col .knob { --size: 21px; }
  .knob-label, .knobs .knob-label { font-size: 8.5px; }
  .master-col { gap: 2px; }
  .master-meters { min-height: 14px; }
  .limiter { font-size: 8px; padding: 0 3px; }
  .eq-mode, .master-col .pad.tiny { min-height: 20px; }
  .strip .pad { min-height: 22px; }
  .fader.h { height: 22px; }
  .seg { padding: 2px 6px; }
  .sweep-dir { min-height: 22px; }
}
/* narrow phones sideways: a slimmer mixer, and decks that get narrow put
   their hot cues in two rows */
@media (orientation: landscape) and (max-height: 540px) {
  .deck { container: deck / inline-size; }
}
@media (orientation: landscape) and (max-height: 540px) and (max-width: 820px) {
  .seg { padding: 2px 5px; font-size: 10.5px; }
  .sweep-icon { width: 32px; height: 18px; }
  .sweep-dir { padding: 0 2px; }
  .xfade-opts .knob-label { display: none; }
  .transport .pad { font-size: 12px; padding: 0 3px; }
}
@container deck (max-width: 250px) {
  .hotcues { grid-template-columns: repeat(4, 1fr); }
  .pad.hot { min-height: clamp(22px, 6.5dvh, 32px); }
  .transport { grid-template-columns: 1fr 1.2fr 1fr; }
  .loops .pad, .grid-row .pad { min-height: 22px; font-size: 11px; padding: 0 4px; }
}
