:root {
  color-scheme: dark;
  /* Whole-console zoom. Percentages scale type and spacing together (unlike a
     font-size change, which needs every px value re-tuned). */
  --ui-scale: 1.15;
  zoom: var(--ui-scale);
  --bg: #121417;
  --panel: #1b1f24;
  --panel-2: #20252b;
  --strip: #262b32;
  --strip-2: #2e343c;
  --line: #313840;
  --line-2: #3d454f;
  --ink: #e3e7ec;
  --ink-2: #b6bec8;
  --muted: #7d8794;
  --accent: #3fc1d6;
  --accent-2: #2a8fa0;
  --peq: #f2a93b;
  --thd: #b48cf2;
  --ok: #3fcf73;
  --warn: #f2b33b;
  --danger: #ef5350;
  --radius: 6px;
  --fader-h: 240px;
  --cap-h: 30px;
  --topbar-h: 64px;
  --mono: "Cascadia Mono", Consolas, "Courier New", monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { background: var(--bg); }

body {
  margin: 0;
  min-width: 0;
  /* Account for root zoom so the minimum height fits the actual viewport. */
  min-height: calc(100dvh / var(--ui-scale));
  display: flex;
  flex-direction: column;
  color: var(--ink);
  background: radial-gradient(1200px 500px at 50% -200px, #1d232a 0, transparent 70%), var(--bg);
  font: 13px/1.4 "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
}

body.has-overlay { overflow: hidden; }

button, input, select { font: inherit; color: inherit; }

button,
select,
input[type="text"],
input[type="number"] {
  min-height: 30px;
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  background: #16191d;
  color: var(--ink);
}

/* Segoe UI / YaHei glyphs sit ~1 px below the line-box center; the extra bottom
   padding lifts text so it reads as vertically centered in buttons and fields. */
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 12px 2px;
  line-height: 1;
  background: linear-gradient(#2c323a, #23282e);
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 120ms ease, background 120ms ease, color 120ms ease;
}

button:hover { border-color: #5a6470; }
button:active { transform: translateY(1px); }
button:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

button:disabled, input:disabled, select:disabled { cursor: not-allowed; opacity: 0.45; }

input[type="text"], input[type="number"], select { width: 100%; padding: 0 8px 1px; }
/* Number fields: no hidden spin-button gutter, value centered. Wheel and arrow keys still step. */
input[type="number"] { font-variant-numeric: tabular-nums; text-align: center; appearance: textfield; -moz-appearance: textfield; }
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
select { padding: 0 24px 2px 8px; line-height: 1; }
option { background: #1b1f24; color: var(--ink); }

input[type="checkbox"] { width: 15px; height: 15px; margin: 0; accent-color: var(--accent); }

.primary-action { border-color: var(--accent-2); background: linear-gradient(#2a7f8f, #1f6572); color: #f2fbfd; }
.primary-action:hover { border-color: var(--accent); }
.danger-action { border-color: #6b3434; color: #ffb3b0; }

.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  padding: 0 9px 1px;
  border: 1px solid var(--line-2);
  border-radius: 999px;
  background: #16191d;
  color: var(--ink-2);
  font-size: 12px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.status-idle { color: var(--ink-2); }
.status-ok { border-color: rgba(63, 207, 115, 0.5); color: #8ff0b2; background: rgba(63, 207, 115, 0.08); }
.status-warn { border-color: rgba(242, 179, 59, 0.5); color: #ffd58a; background: rgba(242, 179, 59, 0.08); }
.status-error { border-color: rgba(239, 83, 80, 0.6); color: #ffaaa8; background: rgba(239, 83, 80, 0.1); }

/* ----- Top bar ----- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 60;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 18px;
  padding: 9px 16px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(#20252b, #181b20);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
}

/* DSP and Scene pack left after the fixed-width brand; the variable-width status
   chips start the right-aligned group, so their text never moves the DSP switch. */
.brand { display: flex; align-items: center; gap: 10px; margin-right: 14px; }
.topbar-status { margin-left: auto; }
#sampleRateStatus { min-width: 104px; }
#dspGateStatus { min-width: 86px; }
#deviceSceneStatus { min-width: 108px; }
#flashStatus { min-width: 72px; }
#hidStatus { max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.brand-mark {
  padding: 4px 8px;
  border-radius: 4px;
  background: linear-gradient(135deg, var(--accent), #2d7fbf);
  color: #071318;
  font-weight: 800;
  letter-spacing: 0.04em;
}
.brand-meta { display: grid; line-height: 1.15; }
.brand-meta strong { font-size: 15px; }
.brand-meta small { color: var(--muted); font-size: 11px; }

.topbar-section { display: flex; align-items: center; gap: 8px; min-width: 0; }
.topbar-section select { width: auto; min-width: 118px; }
.section-label { color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: 0.08em; }
.topbar-status { flex-wrap: wrap; }
.icon-button { width: 30px; padding: 0; font-size: 16px; }
/* Crisp stroked glyph instead of the mismatched font arrow character. */
.icon-svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-button:hover .icon-svg { stroke: var(--accent); }

.segmented {
  display: inline-flex;
  padding: 2px;
  border: 1px solid var(--line-2);
  border-radius: 7px;
  background: #121519;
}
.segmented button {
  min-height: 26px;
  min-width: 48px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--ink-2);
  font-weight: 700;
}
.segmented button.is-active { background: linear-gradient(#3b434d, #2c323a); color: #fff; box-shadow: inset 0 0 0 1px #56606c; }
.dsp-function-control button[data-dsp-function="1"].is-active { color: var(--peq); }
.dsp-function-control button[data-dsp-function="2"].is-active { color: var(--thd); }

/* ----- Console layout ----- */

.console {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, max-content) minmax(0, max-content) minmax(260px, 320px);
  justify-content: center;
  /* Stretch the buses to the rack height (and vice versa) so all panel bottoms align. */
  align-items: stretch;
  align-content: start;
  gap: 12px;
  width: 100%;
  padding: 12px 16px 16px;
}

.bus, .rack-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(var(--panel-2), var(--panel));
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}

.bus-header {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
}
.bus-header h2, .rack-header h2 { margin: 0; font-size: 13px; letter-spacing: 0.12em; }
.bus-input .bus-header h2 { color: #8fd8ff; }
.bus-output .bus-header h2 { color: #ffc98a; }
.bus-meta, .rack-sub { color: var(--muted); font-size: 11px; }

.bus-body {
  display: flex;
  align-items: stretch;
  align-content: start;
  gap: 8px;
  padding: 10px;
  overflow-x: auto;
}

.bus-flow {
  align-self: center;
  width: 14px;
  height: 14px;
  flex: 0 0 auto;
  fill: none;
  stroke: var(--line-2);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.bus-input .bus-flow { transform: translateX(2px); }

.bus { display: flex; flex-direction: column; }
.bus-body { flex: 1; }
.strip-pair { display: flex; align-items: stretch; gap: 4px; }

/* ----- Channel strip ----- */

.strip {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  align-content: start;
  gap: 6px;
  width: 100px;
  flex: 0 0 auto;
  padding: 8px 6px;
  border: 1px solid var(--line-2);
  border-radius: 6px;
  background: linear-gradient(var(--strip-2), var(--strip));
}
.strip-input { box-shadow: inset 0 3px 0 #2e7ea6; }
.strip-output { box-shadow: inset 0 3px 0 #a8742c; }
.strip.is-follower .strip-head { opacity: 0.75; }

.strip-head { display: grid; justify-items: center; line-height: 1.15; }
.strip-name { font-weight: 800; font-size: 14px; letter-spacing: 0.04em; }
.strip-sub { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); font-size: 11px; }

.sync-led {
  display: inline-block;
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #3a424b;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.4);
}
.sync-led.led-ok { background: var(--ok); box-shadow: 0 0 6px rgba(63, 207, 115, 0.8); }
.sync-led.led-warn { background: var(--warn); box-shadow: 0 0 6px rgba(242, 179, 59, 0.7); }
.sync-led.led-off { background: transparent; box-shadow: inset 0 0 0 1px #4a525c; }

.strip-sum {
  padding: 3px 4px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #121519;
  color: var(--ink-2);
  font-size: 11px;
  font-weight: 700;
  text-align: center;
  font-variant-numeric: tabular-nums;
  cursor: help;
}
.strip-sum.is-boost { border-color: rgba(242, 179, 59, 0.55); color: #ffd58a; }
.strip-sum.is-muted { border-color: rgba(239, 83, 80, 0.6); color: #ffaaa8; }

/* Faders take the strip's spare height; --fader-h is the minimum travel. */
.strip-fader { flex: 1 0 auto; min-height: var(--fader-h); display: flex; justify-content: center; }
.strip-fader > .fader { width: 78px; height: auto; }

.strip-value { height: 28px; min-height: 28px; text-align: center; font-weight: 700; padding: 0 2px 1px; }
.strip-status, .usb-effective {
  display: block;
  min-height: 14px;
  color: var(--muted);
  font-size: 10px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.strip-button {
  position: relative;
  display: flex;
  justify-content: center;
  cursor: pointer;
}
.strip-button input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: inherit; }
.strip-button span {
  width: 100%;
  padding: 4px 0 6px;
  border: 1px solid var(--line-2);
  border-radius: 4px;
  background: linear-gradient(#323941, #282d34);
  color: var(--ink-2);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-align: center;
}
.strip-button input:checked + span { border-color: #b53a37; background: linear-gradient(#d64541, #a52f2c); color: #fff; box-shadow: 0 0 10px rgba(239, 83, 80, 0.45); }
.strip-button input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }
.strip-button input:disabled + span { opacity: 0.45; }
.strip-button:has(input:disabled) { cursor: not-allowed; }

.strip-knobs { display: flex; justify-content: center; gap: 4px; min-height: 76px; }

.strip-dsp { display: grid; gap: 9px; padding: 2px 1px 1px; }
.dsp-button {
  position: relative;
  display: grid;
  grid-template-columns: 1fr;
  justify-items: center;
  gap: 2px;
  min-height: 0;
  padding: 4px 4px 3px;
  border-color: var(--line-2);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--ink-2);
}
.mini-eq { display: block; width: 100%; height: 20px; opacity: 0.7; }
/* Glow palette lives on the base class so both the running (is-active) and the
   armed-but-idle (is-standby) states can light up with the same treatment. */
.peq-button {
  --glow: #f2a93b; --glow-text: #ffc067; --glow-bg-top: #3a2f22; --glow-bg: #2a241d;
  --glow-inset: rgba(242, 140, 59, 0.45); --glow-mid: rgba(242, 140, 59, 0.75); --glow-outer: rgba(242, 120, 50, 0.45);
}
.thd-button {
  --glow: #4da3ff; --glow-text: #9ccdff; --glow-bg-top: #1d2c3f; --glow-bg: #182230;
  --glow-inset: rgba(77, 163, 255, 0.45); --glow-mid: rgba(77, 163, 255, 0.75); --glow-outer: rgba(45, 130, 240, 0.45);
}
/* Lit state for both buttons: identical bloom, only the hue differs. */
.peq-button.is-active, .thd-button.is-active {
  border-color: var(--glow);
  color: var(--glow-text);
  background: linear-gradient(var(--glow-bg-top), var(--glow-bg));
  box-shadow: inset 0 0 0 1px var(--glow-inset), 0 0 6px var(--glow-mid), 0 0 14px var(--glow-outer);
}
.peq-button.is-active .mini-eq { opacity: 1; }
.thd-button.is-active .thd-glyph { filter: drop-shadow(0 0 4px var(--glow-mid)); }
/* Armed but idle (flat EQ / zero coefficients): dashed outline + the same glow,
   so "switched on, nothing to process" reads differently from "running". */
.peq-button.is-standby, .thd-button.is-standby {
  border-style: dashed;
  border-color: var(--glow);
  color: var(--glow-text);
  background: linear-gradient(var(--glow-bg-top), var(--glow-bg));
  box-shadow: inset 0 0 0 1px var(--glow-inset), 0 0 4px var(--glow-mid), 0 0 9px var(--glow-outer);
}
.thd-button.is-standby .thd-glyph { filter: drop-shadow(0 0 3px var(--glow-mid)); }
/* Rate bypass: genuinely not processing, so muted and unlit. */
.peq-button.is-bypass {
  border-style: dashed;
  border-color: rgba(242, 179, 59, 0.6);
  color: var(--warn);
  box-shadow: none;
}
.thd-glyph { display: flex; align-items: flex-end; gap: 4px; height: 20px; padding-bottom: 2px; }
.thd-glyph i { display: block; width: 4px; border-radius: 1px; background: currentColor; opacity: 0.55; }
.thd-glyph i:nth-child(1) { height: 14px; }
.thd-glyph i:nth-child(2) { height: 9px; }
.thd-glyph i:nth-child(3) { height: 5px; }
.thd-button.is-active .thd-glyph i { opacity: 1; }
.thd-button.is-standby { border-color: rgba(180, 140, 242, 0.4); color: #c3add9; }

.pair-link {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  flex: 0 0 auto;
  cursor: pointer;
}
.pair-link input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; margin: 0; }
.pair-link span {
  writing-mode: vertical-rl;
  padding: 10px 2px;
  border: 1px solid var(--line-2);
  border-radius: 11px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.2em;
}
.pair-link input:checked + span { border-color: var(--accent-2); background: rgba(63, 193, 214, 0.12); color: var(--accent); }
.pair-link input:focus-visible + span { outline: 2px solid var(--accent); }

.link-chip, .toggle-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}
.link-chip input, .toggle-chip input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; margin: 0; cursor: pointer; }
.link-chip span, .toggle-chip span {
  padding: 4px 8px;
  border: 1px solid var(--line-2);
  border-radius: 999px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  white-space: nowrap;
}
.link-chip input:checked + span { border-color: var(--accent-2); background: rgba(63, 193, 214, 0.12); color: var(--accent); }
.toggle-chip input:checked + span { border-color: rgba(63, 207, 115, 0.55); background: rgba(63, 207, 115, 0.12); color: #8ff0b2; }
.link-chip input:focus-visible + span, .toggle-chip input:focus-visible + span { outline: 2px solid var(--accent); }
.link-chip input:disabled + span, .toggle-chip input:disabled + span { opacity: 0.45; }

/* ----- USB volume group ----- */

.usb-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 0 0 auto;
  padding: 8px 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #1a1e23;
}
.usb-head { display: grid; justify-items: center; line-height: 1.15; }
.usb-head span { font-weight: 800; letter-spacing: 0.06em; }
.usb-head small { color: var(--muted); font-size: 10px; }
.usb-faders { display: flex; flex: 1; gap: 4px; }
.usb-channel { display: flex; flex-direction: column; gap: 6px; width: 64px; }
.usb-channel.is-master { padding-right: 4px; margin-right: 2px; border-right: 1px solid var(--line); }
.usb-channel .strip-fader > .fader { width: 58px; }
.usb-channel .strip-fader > .fader .fader-cap { width: 26px; }
.usb-name { color: var(--ink-2); font-size: 10px; font-weight: 800; text-align: center; letter-spacing: 0.06em; }
.usb-channel .strip-fader { min-height: calc(var(--fader-h) + 30px); }
.usb-channel.is-muted .usb-effective { color: #ffaaa8; }
.usb-foot { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-top: auto; }

/* ----- Fader ----- */

.fader {
  --t: 0;
  position: relative;
  display: grid;
  grid-template-columns: 24px 1fr;
  height: 100%;
  min-height: 110px;
  touch-action: none;
  user-select: none;
  outline: none;
  cursor: ns-resize;
}
.fader-scale { position: relative; }
.fader-scale span {
  position: absolute;
  right: 4px;
  bottom: calc(var(--tick) * (100% - var(--cap-h)) + var(--cap-h) / 2);
  transform: translateY(50%);
  color: var(--muted);
  font-size: 9px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.fader-scale span::after {
  content: "";
  position: absolute;
  top: 50%;
  right: -5px;
  width: 4px;
  border-top: 1px solid #4a525c;
}
.fader-track { position: relative; }
.fader-groove {
  position: absolute;
  top: calc(var(--cap-h) / 2);
  bottom: calc(var(--cap-h) / 2);
  left: 50%;
  width: 6px;
  transform: translateX(-50%);
  border-radius: 3px;
  background: #0b0d10;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.9), 0 0 0 1px #363d46;
}
.fader-fill {
  position: absolute;
  left: 50%;
  width: 4px;
  transform: translateX(-50%);
  border-radius: 2px;
  pointer-events: none;
}
.fader.is-level .fader-fill {
  bottom: calc(var(--cap-h) / 2);
  height: calc(var(--t) * (100% - var(--cap-h)));
  background: linear-gradient(to top, rgba(63, 193, 214, 0.15), rgba(63, 193, 214, 0.65));
}
.fader.is-bipolar .fader-fill {
  bottom: calc(var(--fill-lo, 0) * (100% - var(--cap-h)) + var(--cap-h) / 2);
  height: calc(var(--fill-span, 0) * (100% - var(--cap-h)));
  background: var(--fill-color, var(--peq));
}
.fader-cap {
  position: absolute;
  left: 50%;
  bottom: calc(var(--t) * (100% - var(--cap-h)));
  width: 34px;
  height: var(--cap-h);
  transform: translateX(-50%);
  border-radius: 4px;
  background: linear-gradient(#69727e, #424a54 42%, #2b3138 50%, #3f4750 58%, #565f6a);
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.7), inset 0 1px 0 rgba(255, 255, 255, 0.22);
  cursor: grab;
}
.fader-cap-line { position: absolute; top: 50%; left: 3px; right: 3px; height: 2px; margin-top: -1px; background: #f4f7fa; border-radius: 1px; }
.fader.is-dragging .fader-cap { cursor: grabbing; box-shadow: 0 0 0 2px rgba(63, 193, 214, 0.6), 0 3px 8px rgba(0, 0, 0, 0.8); }
.fader:focus-visible .fader-cap { outline: 2px solid var(--accent); outline-offset: 2px; }
.fader.is-disabled { opacity: 0.4; cursor: not-allowed; }
.fader.is-disabled .fader-cap { cursor: not-allowed; }

/* ----- Knob ----- */

.knob {
  display: grid;
  justify-items: center;
  align-content: start;
  gap: 1px;
  width: 44px;
  outline: none;
  user-select: none;
}
.knob-dial { width: 40px; height: 40px; cursor: ns-resize; touch-action: none; }
.knob-arc-bg { fill: none; stroke: #0d1013; stroke-width: 4; stroke-linecap: round; }
.knob-arc { fill: none; stroke: var(--knob-color, var(--accent)); stroke-width: 4; stroke-linecap: round; }
.knob.is-zero .knob-arc { stroke: transparent; }
.knob-body { fill: #3a414a; stroke: #5d6671; stroke-width: 1; }
.knob-pointer { stroke: #f2f5f8; stroke-width: 2.4; stroke-linecap: round; transform-box: view-box; transform-origin: 24px 24px; transform: rotate(var(--angle, -135deg)); }
.knob-readout {
  min-width: 44px;
  color: var(--ink);
  font-size: 10px;
  font-weight: 700;
  text-align: center;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.knob-caption { color: var(--muted); font-size: 9px; font-weight: 800; letter-spacing: 0.1em; }
.knob-input { width: 56px; min-height: 20px; height: 20px; padding: 0 3px; font-size: 11px; text-align: center; }
.knob:focus-visible .knob-body { stroke: var(--accent); stroke-width: 2; }
.knob.is-dragging .knob-body { stroke: var(--accent); }
.knob.is-disabled { opacity: 0.4; }
.knob.is-disabled .knob-dial { cursor: not-allowed; }
[data-pga-knob] { --knob-color: #8fd8ff; }
[data-gain-knob] { --knob-color: var(--warn); }
[data-mix-knob] { --knob-color: #c9a2ff; }

/* ----- Rack ----- */

.rack { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.rack > .rack-panel:last-child { flex: 1; }
.rack-panel { padding: 0 0 10px; }
.rack-header { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.rack-header .sync-led { margin-left: auto; }
.rack-note { margin: 8px 12px 0; color: var(--muted); font-size: 11px; line-height: 1.45; }
.rack-warn { color: #ffd58a; }

.mix-row {
  display: grid;
  grid-template-columns: 34px 1fr auto 1fr;
  align-items: center;
  justify-items: center;
  gap: 4px;
  padding: 10px 12px 0;
}
.mix-row-label { justify-self: start; color: var(--ink-2); font-weight: 800; font-size: 11px; letter-spacing: 0.08em; }
.mix-row .knob { width: 64px; }
.mix-row .knob-dial { width: 46px; height: 46px; }

.rack-field { display: grid; grid-template-columns: 40px 1fr; align-items: center; gap: 8px; padding: 10px 12px 0; }
.rack-field span { color: var(--ink-2); font-weight: 800; font-size: 11px; }
.rack-field select { min-width: 0; }

/* Fixed layout + nowrap: a longer value (e.g. -24.5 dB) can never wrap and change
   the row count, which would resize the DEVICE panel and the whole console. */
.sync-table { width: calc(100% - 24px); margin: 8px 12px 0; border-collapse: collapse; font-size: 11px; table-layout: fixed; }
.sync-table th, .sync-table td { padding: 4px 3px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sync-table th { color: var(--ink-2); font-weight: 700; width: 26%; }
.sync-value { color: var(--ink); font-variant-numeric: tabular-nums; }
.sync-bits { width: 46px; }
.bit { display: inline-block; width: 7px; height: 7px; margin-right: 2px; border-radius: 50%; background: #3a424b; }
.bit-ok { background: var(--ok); }
.bit-warn { background: var(--warn); }
.bit-pending { background: transparent; box-shadow: inset 0 0 0 1px var(--warn); }
.rack-actions { display: flex; gap: 8px; padding: 10px 12px 0; }
.rack-actions button { flex: 1; }

/* ----- Status bar ----- */

.statusbar {
  position: sticky;
  bottom: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 28px;
  padding: 4px 16px;
  border-top: 1px solid var(--line);
  background: #15181c;
  color: var(--ink-2);
  font-size: 12px;
}
#operationStatus { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.statusbar-hint { margin-left: auto; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.statusbar-version { color: #59636e; font-family: var(--mono); font-size: 11px; }
.statusbar-tools { display: flex; align-items: center; gap: 14px; margin-left: auto; flex-shrink: 0; }
.language-control { position: relative; }
.language-button {
  min-height: 28px;
  gap: 7px;
  padding: 0 10px;
  border-radius: 999px;
  background: linear-gradient(#252d34, #1b2127);
  color: var(--ink-2);
  font-size: 11px;
}
.language-button .globe-icon { width: 18px; height: 18px; stroke-width: 1.5; color: var(--accent); }
.language-button:hover, .language-button[aria-expanded="true"] { border-color: var(--accent-2); color: var(--ink); }
.language-menu {
  position: absolute;
  right: 0;
  bottom: calc(100% + 10px);
  width: 160px;
  padding: 6px;
  border: 1px solid var(--line-2);
  border-radius: 9px;
  background: linear-gradient(#262d35, #1b2026);
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.5);
}
.language-menu-title { display: block; padding: 5px 8px 8px; color: var(--muted); font-size: 10px; letter-spacing: 0.05em; }
.language-menu button { width: 100%; min-height: 34px; justify-content: flex-start; padding: 0 8px; border-color: transparent; background: transparent; }
.language-menu button small { color: var(--muted); font-size: 11px; }
.language-menu button:hover, .language-menu button:focus-visible { background: #303a44; }
.language-menu button[aria-checked="true"] { color: var(--accent); background: rgba(63, 193, 214, 0.08); }
.language-check { width: 14px; height: 14px; margin-left: auto; visibility: hidden; }
.language-menu button[aria-checked="true"] .language-check { visibility: visible; }

/* ----- Overlays (PEQ / THD) ----- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: calc(var(--topbar-h) + 14px) 16px 16px;
  overflow: auto;
  background: rgba(5, 7, 9, 0.72);
  backdrop-filter: blur(3px);
}
.overlay-window {
  display: flex;
  flex-direction: column;
  width: min(1240px, 100%);
  min-width: 0;
  border: 1px solid #47505b;
  border-radius: 10px;
  background: linear-gradient(#22272d, #1b1f24);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.65);
  outline: none;
}
.thd-window { width: min(1080px, 100%); }

.overlay-titlebar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}
.overlay-title { display: grid; line-height: 1.15; margin-right: auto; min-width: 0; }
.overlay-title h2 { margin: 0; font-size: 17px; }
.overlay-kicker { font-size: 10px; font-weight: 800; letter-spacing: 0.14em; }
.peq-kicker { color: var(--peq); }
.thd-kicker { color: var(--thd); }
.overlay-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
/* Status text in the overlay title bar matches the LINK/toggle chips beside it. */
.overlay-tools .chip { min-height: 0; padding: 4px 8px 5px; font-weight: 800; letter-spacing: 0.08em; }

.channel-tabs { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.channel-tabs button { min-width: 58px; font-weight: 800; color: var(--ink-2); }
.channel-tabs button.is-active { border-color: var(--peq); color: #ffd28c; background: linear-gradient(#3b342a, #2a2620); }
.thd-window .channel-tabs button.is-active { border-color: var(--thd); color: #dcc8ff; background: linear-gradient(#352e44, #262230); }
.tab-divider { width: 1px; height: 22px; margin: 0 6px; background: var(--line-2); }

.overlay-body { padding: 12px 14px; min-width: 0; }
.overlay-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 18px;
  padding: 10px 14px;
  border-top: 1px solid var(--line);
}
.footer-group { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.footer-group select { width: auto; }
.footer-progress { margin-left: auto; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

.graph-box { position: relative; min-width: 0; }
.graph-box canvas { display: block; width: 100%; border: 1px solid var(--line); border-radius: 6px; background: #101317; }
#responseCanvas { height: clamp(190px, 28vh, 300px); cursor: crosshair; touch-action: none; }
#responseCanvas.is-over-node { cursor: grab; }
#responseCanvas.is-dragging { cursor: grabbing; }
#responseCanvas.response-danger { border-color: rgba(239, 83, 80, 0.75); }
/* Borderless status text, on the same visual line as the graph legend. */
.graph-badge {
  position: absolute;
  top: 23px;
  right: 24px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
  text-shadow: 0 1px 2px rgba(6, 8, 10, 0.9);
  pointer-events: none;
}
.graph-badge.is-live { color: #8ff0b2; }
/* THD's label sits above its plot frame, so nudge it up to the same line. */
.thd-window .graph-badge { top: 12px; right: 28px; }
.response-warning {
  position: absolute;
  left: 50%;
  bottom: 36px;
  transform: translateX(-50%);
  padding: 4px 12px;
  border: 1px solid rgba(239, 83, 80, 0.7);
  border-radius: 999px;
  background: rgba(60, 16, 16, 0.92);
  color: #ffb3b0;
  font-weight: 700;
  font-size: 12px;
  pointer-events: none;
}

.peq-controls { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 12px; margin-top: 12px; align-items: start; }

.band-grid {
  display: grid;
  grid-template-columns: repeat(8, minmax(64px, 1fr));
  gap: 6px;
  min-width: 0;
  overflow-x: auto;
  padding-bottom: 2px;
}
.band-grid.is-locked { opacity: 0.6; }
.band-strip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-width: 64px;
  padding: 6px 4px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: linear-gradient(var(--strip-2), var(--strip));
  cursor: pointer;
  outline: none;
}
.band-strip:focus-visible { border-color: var(--accent); }
.band-strip.active { border-color: var(--peq); box-shadow: inset 0 0 0 1px rgba(242, 169, 59, 0.35); }
.band-strip.bypassed .band-type, .band-strip.bypassed .freq-label { color: #6c7682; }
.band-number { font-weight: 800; font-size: 13px; }
.band-type { color: var(--peq); font-size: 10px; font-weight: 800; letter-spacing: 0.06em; }
.freq-label { font-size: 11px; font-variant-numeric: tabular-nums; }
.q-readout, .gain-readout {
  min-width: 46px;
  padding: 1px 4px;
  border: 1px solid transparent;
  border-radius: 4px;
  color: var(--ink-2);
  font-size: 11px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  cursor: text;
}
.q-readout:hover, .gain-readout:hover { border-color: var(--line-2); }
.gain-readout { color: var(--ink); font-weight: 700; }
.band-strip.is-editing-gain .gain-readout { display: none; }
.q-readout[contenteditable="true"] { border-color: var(--accent); background: #101317; outline: none; }
.gain-inline-input { width: 56px; min-height: 22px; height: 22px; padding: 0 4px; font-size: 11px; text-align: center; }
.band-fader { width: 58px; height: clamp(135px, 21vh, 200px); }
.band-fader .fader-cap { width: 28px; }

.band-editor { padding: 10px; border: 1px solid var(--line); border-radius: 6px; background: #181b20; }
.band-editor-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.band-editor-head h3 { margin: 0; font-size: 13px; }
.editor-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.editor-field { display: grid; gap: 3px; min-width: 0; }
.editor-field span { color: var(--muted); font-size: 11px; }
.editor-wide { grid-column: 1 / -1; }
.field-disabled span { opacity: 0.5; }
.editor-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.editor-actions button { flex: 1; }

/* THD overlay */
.thd-body { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 14px; }
#thdCanvas { height: clamp(240px, 38vh, 380px); }
.thd-summary { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.thd-summary-item {
  display: grid;
  gap: 1px;
  min-width: 96px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #181b20;
}
.thd-summary-item > span { color: var(--muted); font-size: 10px; }
.thd-summary-item strong { font-size: 13px; font-variant-numeric: tabular-nums; }
.thd-reference-control { display: flex; align-items: center; gap: 4px; }
.thd-reference-control input { width: 72px; min-height: 24px; height: 24px; }
.thd-reference-control small { color: var(--muted); }
.thd-editor { display: flex; flex-direction: column; gap: 10px; padding: 10px; border: 1px solid var(--line); border-radius: 6px; background: #181b20; min-width: 0; }
.thd-bits-field { display: grid; grid-template-columns: auto 90px; align-items: center; justify-content: start; gap: 10px; }
.thd-bits-field span { color: var(--ink-2); font-weight: 700; }
.thd-terms { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.thd-term {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 4px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: linear-gradient(var(--strip-2), var(--strip));
  min-width: 0;
}
.thd-term > strong { font-size: 14px; color: var(--thd); }
.thd-term > span:not(.thd-ratio-readout) { color: var(--muted); font-size: 10px; }
.thd-fader { width: 84px; height: clamp(170px, 30vh, 260px); --fill-color: var(--thd); }
.thd-fader .fader-scale { grid-column: 1; }
.thd-fader { grid-template-columns: 36px 1fr; }
.thd-term input { height: 26px; min-height: 26px; text-align: center; padding: 0 2px 1px; }
.thd-ratio-readout { color: var(--ink-2); font-size: 11px; font-variant-numeric: tabular-nums; }
.thd-harmonic-readouts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 12px; color: var(--muted); font-size: 12px; }
.thd-harmonic-readouts strong { color: var(--ink); font-variant-numeric: tabular-nums; }
#thdOverlay.is-locked .thd-terms { opacity: 0.6; }

/* ----- Responsive ----- */

/* Breakpoints are viewport px; with the 115% root zoom each is the old value x 1.15. */
@media (max-width: 1610px) {
  .console { grid-template-columns: repeat(2, minmax(0, max-content)); }
  .rack { display: grid; grid-column: 1 / -1; grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: stretch; }
}

@media (max-width: 1265px) {
  .console { grid-template-columns: minmax(0, 1fr); }
  .rack { grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); }
  .bus-body { justify-content: flex-start; }
  .peq-controls { grid-template-columns: minmax(0, 1fr); }
  .thd-body { grid-template-columns: minmax(0, 1fr); }
}

@media (max-height: 1012px) { :root { --fader-h: 200px; } }
@media (max-height: 874px) { :root { --fader-h: 170px; } }

@media (max-width: 830px) {
  .topbar { gap: 8px 10px; padding: 8px 10px; }
  .brand { width: 100%; }
  .topbar-status .chip { font-size: 11px; }
  .topbar-connection { flex-wrap: wrap; }
  .console { padding: 10px 8px; }
  .overlay { padding: calc(var(--topbar-h) + 8px) 6px 8px; }
  .overlay-titlebar, .overlay-body, .overlay-footer { padding-left: 10px; padding-right: 10px; }
  .statusbar-hint { display: none; }
  .statusbar-version { display: none; }
  .thd-terms { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .thd-fader { width: 72px; grid-template-columns: 30px 1fr; }
  .editor-grid { grid-template-columns: minmax(0, 1fr); }
}
