:root {
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  /* Dark only. Monochrome UI (controls white); orange (--hl) only marks data: the selected range */
  --bg: #090909; --chrome: #131313; --panel: #131313; --panel-2: #1a1a1a; --border: #252525; --border-strong: #353535;
  --text: #ededed; --muted: #8a8a8a; --accent: #ededed; --accent-hover: #c9c9c9; --accent-text: #0a0a0a; --hl: #ee7a33;
  --ok: #22c55e; --warn: #f5b041; --bad: #f05252; --bad-fill: #c42b2b; --live: #e5484d;
  --trace: #e8e8e8; --grid: rgba(255, 255, 255, 0.07);
  --select: rgba(238, 122, 51, 0.1); --pop-shadow: 0 6px 16px rgba(0, 0, 0, 0.55), 0 1px 3px rgba(0, 0, 0, 0.4);
  /* Peak colours, in this order around the spectrum (checked for colour-vision deficiency as a cycle) */
  --pk-1: #3987e5; --pk-2: #e66767; --pk-3: #9085e9; --pk-4: #199e70; --pk-5: #c98500; --pk-6: #d55181; --pk-7: #008300;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text); font: 13px/1.45 var(--font);
  display: grid; grid-template-rows: auto minmax(0, 1fr) auto; grid-template-columns: minmax(0, 1fr);
  accent-color: var(--accent); caret-color: var(--text);
}
::selection { background: var(--select); color: var(--text); }
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.spacer { flex: 1; }
[hidden] { display: none !important; }
svg.i { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }

/* ---- controls ---- */
.btn {
  font: inherit; font-weight: 500; height: 32px; padding: 0 12px; border-radius: 8px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; white-space: nowrap;
  border: 1px solid var(--border-strong); background: var(--panel); color: var(--text);
  transition: background .15s ease-out, border-color .15s ease-out, color .15s ease-out;
}
a.btn { text-decoration: none; }
.btn:hover:not(:disabled) { border-color: var(--muted); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn .spin { display: none; width: 14px; height: 14px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .8s linear infinite; }
.btn.busy .spin { display: inline-block; }
.btn.busy .ico { display: none; }
.btn.busy:disabled { opacity: .8; cursor: progress; }
@keyframes spin { to { transform: rotate(360deg); } }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover:not(:disabled) { background: var(--panel-2); border-color: var(--border); }
.btn.icon { width: 32px; padding: 0; }
.btn.small { height: 28px; padding: 0 10px; font-size: 12px; }
.btn.small.icon { width: 28px; padding: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

input[type="number"], input[type="text"] {
  font: inherit; font-family: var(--font-mono); font-variant-numeric: tabular-nums; height: 30px; width: 76px;
  padding: 0 8px; text-align: right; border: 1px solid var(--border-strong); border-radius: 8px;
  background: var(--panel); color: var(--text);
}
.stepper { display: inline-flex; align-items: center; height: 32px; border: 1px solid var(--border-strong); border-radius: 8px; overflow: hidden; }
.stepper input { border: 0; border-radius: 0; height: 30px; width: 64px; background: transparent; }
.stepper .unit { padding-right: 8px; color: var(--muted); font-size: 12px; }
.stepper button {
  width: 30px; height: 30px; display: grid; place-items: center; border: 0; background: transparent; color: var(--text); cursor: pointer;
}
.stepper button:hover:not(:disabled) { background: var(--panel-2); }
.stepper button:disabled, .stepper input:disabled { opacity: .4; cursor: default; }
.stepper button:first-child { border-right: 1px solid var(--border); }
.stepper button:last-child { border-left: 1px solid var(--border); }

.seg { display: inline-flex; padding: 2px; border-radius: 8px; background: var(--panel-2); border: 1px solid var(--border); }
.seg button {
  font: inherit; font-weight: 500; border: 0; background: transparent; color: var(--muted);
  padding: 3px 14px; border-radius: 6px; cursor: pointer;
}
.seg button.on { background: var(--accent); color: var(--accent-text); }

.switch { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; user-select: none; white-space: nowrap; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch span {
  width: 30px; height: 18px; border-radius: 999px; background: var(--border-strong);
  position: relative; transition: background .15s ease-out; flex: none;
}
.switch span::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%;
  background: #fff; transition: transform .18s cubic-bezier(.2, .8, .2, 1); box-shadow: 0 1px 2px rgba(0,0,0,.25);
}
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(12px); background: var(--accent-text); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.label { font-size: 12px; color: var(--muted); }

/* ---- front panel (top bar) ---- */
.panel-bar {
  display: flex; align-items: center; gap: 14px; padding: 9px 16px; background: var(--chrome);
  border-bottom: 1px solid var(--border); flex-wrap: wrap; row-gap: 8px;
}
/* Three zones: the outer two share the leftover width, so the measuring controls sit in the middle */
.bar-zone { display: flex; align-items: center; gap: 12px; }
.bar-left, .bar-right { flex: 1 1 0; min-width: max-content; }
.bar-right { justify-content: flex-end; }
.bar-center { flex: none; gap: 14px; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 650; font-size: 14px; letter-spacing: -0.01em; margin-right: 6px; }
.brand svg.i { width: 20px; height: 20px; stroke-width: 2; }
.group { display: flex; align-items: center; gap: 8px; }
.vr { width: 1px; height: 24px; background: var(--border); }
/* Connection pill: grey "No device"; connected it turns green and carries its own disconnect button */
.conn {
  display: inline-flex; align-items: center; gap: 8px; height: 32px; padding: 0 12px; border-radius: 999px; white-space: nowrap;
  font-size: 12px; border: 1px solid var(--border); background: var(--panel-2);
  transition: border-color .2s ease-out, background .2s ease-out;
}
.conn.on { padding-right: 4px; border-color: color-mix(in srgb, var(--ok) 45%, var(--border)); background: color-mix(in srgb, var(--ok) 8%, var(--panel)); }
.conn-x {
  display: grid; place-items: center; width: 24px; height: 24px; padding: 0; border: 0; border-radius: 50%;
  background: transparent; color: var(--muted); cursor: pointer; transition: background .15s ease-out, color .15s ease-out;
}
.conn-x:hover { color: var(--bad); background: color-mix(in srgb, var(--bad) 16%, transparent); }
.conn-x svg.i { width: 14px; height: 14px; }
.led { width: 8px; height: 8px; border-radius: 50%; background: var(--border-strong); flex: none; }
.led.on { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 20%, transparent); }
.led.live { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }
#devInfo { color: var(--muted); }
.sim-badge { font-size: 10.5px; font-weight: 700; letter-spacing: .05em; padding: 3px 7px; border-radius: 6px; color: var(--hl); border: 1px solid var(--hl); }
.led.on + #devInfo { color: var(--text); }
/* Live: white "go" button with a green play mark; running, a clear red Stop that breathes */
.btn.live { min-width: 88px; }
.btn.live .i-stop { display: none; }
.btn.live.primary .i-play { color: #16a34a; }
.btn.live.stop { background: var(--live); border-color: var(--live); color: #fff; animation: live-ring 1.8s ease-out infinite; }
.btn.live.stop:hover:not(:disabled) { background: #ec5d61; border-color: #ec5d61; }
.btn.live.stop .i-stop { display: block; }
.btn.live.stop .i-play { display: none; }
@keyframes live-ring {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--live) 55%, transparent); }
  70%, 100% { box-shadow: 0 0 0 7px color-mix(in srgb, var(--live) 0%, transparent); }
}
@media (prefers-reduced-motion: reduce) { .btn.live.stop, .led.live { animation: none; } }
#scanInfo { font-size: 12px; color: var(--muted); white-space: nowrap; }

/* Exposure: stepper with a typed value; Auto is a plain switch next to it */
.expo { display: flex; align-items: center; gap: 10px; }
.expo-box {
  display: inline-flex; align-items: stretch; height: 32px; overflow: hidden;
  border: 1px solid var(--border-strong); border-radius: 8px; background: var(--panel);
  transition: border-color .2s ease-out, box-shadow .2s ease-out;
}
.expo-step { width: 30px; display: grid; place-items: center; border: 0; padding: 0; background: transparent; color: var(--text); cursor: pointer; }
.expo-step:hover { background: var(--panel-2); }
.expo-step svg.i { width: 14px; height: 14px; }
.expo-val { display: flex; align-items: center; gap: 4px; padding: 0 9px 0 4px; cursor: text; border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
.expo-val input {
  width: 46px; height: auto; padding: 0; border: 0; border-radius: 0; background: transparent;
  font: 600 13px var(--font-mono); font-variant-numeric: tabular-nums; text-align: right; color: var(--text);
}
.expo-val input:focus { outline: none; }
.expo-val:focus-within { background: var(--panel-2); }
.expo-val span { font-size: 12px; color: var(--muted); min-width: 16px; }
.expo-auto { padding: 0 12px 0 10px; border-left: 1px solid var(--border); }
.expo-auto:hover { background: var(--panel-2); }
/* Auto on: the value stays readable (it shows what Auto chose), the manual controls step back */
.expo-box.auto .expo-step { opacity: .3; cursor: default; }
.expo-box.auto .expo-step:hover { background: transparent; }
.expo-box.auto .expo-val { cursor: default; }
.expo-box.auto .expo-val input { color: var(--text); -webkit-text-fill-color: var(--text); opacity: 1; cursor: default; }
.expo.attn .expo-box { border-color: var(--bad); box-shadow: 0 0 0 3px color-mix(in srgb, var(--bad) 18%, transparent); }

/* Signal: strength bars and a word (Low · Fair · Good · High · Saturated) */
.sig { position: relative; display: flex; align-items: center; gap: 8px; cursor: default; border-radius: 6px; }
.sig:focus-visible { outline-offset: 4px; }
.sig-bars { display: inline-flex; align-items: flex-end; gap: 2px; height: 14px; }
.sig-bars i { width: 3px; border-radius: 1px; background: var(--border-strong); transition: background .2s ease-out; }
.sig-bars i:nth-child(1) { height: 4px; } .sig-bars i:nth-child(2) { height: 6.5px; } .sig-bars i:nth-child(3) { height: 9px; }
.sig-bars i:nth-child(4) { height: 11.5px; } .sig-bars i:nth-child(5) { height: 14px; }
.sig > b { font-weight: 600; font-size: 12.5px; color: var(--muted); }
.sig-pct { font-size: 12px; color: var(--muted); min-width: 34px; margin-left: -2px; }
.sig { --lvl: var(--text); }
.sig[data-level="low"], .sig[data-level="high"] { --lvl: var(--warn); }
.sig[data-level="good"] { --lvl: var(--ok); }
.sig[data-level="sat"] { --lvl: var(--bad); }
.sig[data-level] > b { color: var(--lvl); }
/* Hover card explaining the levels; the current one is highlighted */
.sig-tip {
  position: absolute; z-index: 20; top: calc(100% + 12px); left: -12px; width: 330px; padding: 12px 14px;
  background: var(--panel); color: var(--text); border: 1px solid var(--border-strong); border-radius: 12px; box-shadow: var(--pop-shadow);
  opacity: 0; transform: translateY(-3px); pointer-events: none; transition: opacity .15s ease-out, transform .15s ease-out;
}
.sig:hover .sig-tip, .sig:focus-visible .sig-tip { opacity: 1; transform: none; transition-delay: .12s; }
.sig-tip p { margin: 0 0 8px; font-size: 12px; color: var(--muted); }
.sig-tip ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.sig-tip li { display: grid; grid-template-columns: 10px 72px 1fr; align-items: center; gap: 8px; padding: 4px 6px; border-radius: 6px; font-size: 12px; }
.sig-tip li i { width: 8px; height: 8px; border-radius: 2px; background: var(--text); }
.sig-tip li[data-l="low"] i, .sig-tip li[data-l="high"] i { background: var(--warn); }
.sig-tip li[data-l="good"] i { background: var(--ok); }
.sig-tip li[data-l="sat"] i { background: var(--bad); }
.sig-tip li b { font-weight: 600; }
.sig-tip li span { color: var(--muted); }
.sig-tip li.cur { background: var(--panel-2); }
.sig-tip li.cur span { color: var(--text); }
.sig-bars i.on { background: var(--lvl); }

/* ---- workspace ---- */
.work { display: grid; min-height: 0; }
.plot-pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--panel); }
.pane-head {
  background: var(--chrome);
  display: flex; align-items: center; gap: 10px; height: 44px; padding: 0 12px 0 16px; flex: none;
  border-bottom: 1px solid var(--border);
}
#cursorRo { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.pane-head .seg button { padding: 2px 12px; }
.pane-head .vr { height: 20px; margin: 0 2px; }
.opt { display: inline-flex; align-items: center; gap: 6px; }

/* "?" next to an option: explains it on hover or keyboard focus */
.tip-btn {
  position: relative; display: grid; place-items: center; width: 22px; height: 22px; padding: 0;
  border: 0; border-radius: 50%; background: transparent; color: var(--muted); cursor: help;
}
.tip-btn:hover, .tip-btn:focus-visible { color: var(--text); background: var(--panel-2); }
.tip-btn svg.i { width: 15px; height: 15px; }
.tip-btn::after {
  content: attr(data-tip); position: absolute; z-index: 20; top: calc(100% + 8px); left: -8px; width: 280px;
  padding: 9px 11px; border-radius: 10px; font-size: 12px; line-height: 1.45; text-align: left; white-space: normal; cursor: default;
  background: var(--panel); color: var(--text); border: 1px solid var(--border-strong); box-shadow: var(--pop-shadow);
  opacity: 0; transform: translateY(-3px); pointer-events: none; transition: opacity .15s ease-out, transform .15s ease-out;
}
.tip-btn:hover::after, .tip-btn:focus-visible::after { opacity: 1; transform: none; transition-delay: .1s; }
.badge { font-size: 11px; font-weight: 700; letter-spacing: .04em; padding: 4px 9px; border-radius: 6px; color: #fff; background: var(--bad-fill); }
.sel-chip {
  display: inline-flex; align-items: center; gap: 2px; height: 28px; padding: 0 3px 0 11px; font-size: 12px;
  border-radius: 999px; border: 1px solid var(--hl); background: var(--select); color: var(--text);
}
.sel-chip button {
  display: grid; place-items: center; border: 0; background: transparent; color: var(--muted); cursor: pointer;
  width: 22px; height: 22px; border-radius: 50%;
}
.sel-chip button:hover { color: var(--text); background: var(--select); }
.sel-chip svg.i { width: 13px; height: 13px; }
.plot-wrap { flex: 1; min-height: 0; position: relative; padding: 6px 8px 4px 4px; }
.plot { position: absolute; inset: 6px 8px 4px 4px; }
.plot .u-select { background: var(--select); }
/* Zoomed in: the overview takes the strip under the plot */
.plot-wrap.zoomed .plot { bottom: 52px; }
.overview { position: absolute; bottom: 8px; height: 38px; }
.overview canvas { display: block; width: 100%; height: 100%; border: 1px solid var(--border); border-radius: 6px; background: var(--panel-2); cursor: grab; touch-action: none; }
.overview canvas.dragging { cursor: grabbing; }
.btn.hold.on { background: var(--panel-2); border-color: var(--border-strong); }
.btn.hold.on svg.i { fill: currentColor; }
.help-sub { margin-top: 14px !important; }
.plot .u-over { cursor: crosshair; touch-action: none; }
.plot-empty {
  position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; padding: 16px;
}
/* First-run guide: the three steps to a spectrum, the current one carries the action */
.guide {
  pointer-events: auto; width: min(440px, 100%); padding: 18px 20px 14px; border-radius: 14px;
  background: var(--panel); border: 1px solid var(--border); box-shadow: var(--pop-shadow);
}
.guide-head { display: flex; align-items: center; justify-content: space-between; margin: -4px -8px 8px 0; }
.guide-head b { font-size: 15px; }
.empty-note { margin: 0; padding: 16px 20px; text-align: center; color: var(--muted); }
.empty-note b { display: block; font-size: 15px; color: var(--text); margin-bottom: 4px; }
.guide ol { list-style: none; margin: 0; padding: 0; }
.guide li { display: grid; grid-template-columns: 22px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 10px 0; border-top: 1px solid var(--border); }
.gs-mark {
  width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center;
  border: 1.5px solid var(--border-strong); color: transparent;
}
.gs-mark svg.i { width: 13px; height: 13px; stroke-width: 2.4; }
.gs-text { font-weight: 550; color: var(--muted); }
.gs-text small { display: block; font-weight: 400; font-size: 12px; color: var(--muted); margin-top: 1px; }
.guide li.current .gs-mark { border-color: var(--accent); }
.guide li.current .gs-text { color: var(--text); }
.guide li.current .btn { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.guide li.done .gs-mark { background: var(--ok); border-color: var(--ok); color: #fff; }
.guide li.done .gs-text { color: var(--muted); }
.guide li.done .btn { display: none; }

/* One-time gesture hint over the plot */
.hint {
  position: absolute; bottom: 64px; left: 84px; width: fit-content; max-width: calc(100% - 108px);
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 16px; padding: 7px 8px 7px 14px; font-size: 12px; color: var(--muted);
  background: var(--panel); border: 1px solid var(--border-strong); border-radius: 10px; box-shadow: var(--pop-shadow);
}
.hint b { color: var(--text); font-weight: 600; }

/* ---- peaks rail: resizable from its left edge, collapsible to a strip ---- */
.work { grid-template-columns: minmax(0, 1fr) var(--rail-open, 380px); }
.work.rail-collapsed { grid-template-columns: minmax(0, 1fr) 44px; }
.rail { position: relative; display: flex; min-height: 0; min-width: 0; background: var(--chrome); border-left: 1px solid var(--border); container-type: inline-size; }
.rail-body { display: flex; flex-direction: column; flex: 1; min-width: 0; min-height: 0; }
.rail-resize { position: absolute; z-index: 5; top: 0; bottom: 0; left: -4px; width: 8px; cursor: col-resize; }
.rail-resize::after { content: ""; position: absolute; top: 0; bottom: 0; left: 3px; width: 2px; background: transparent; transition: background .15s ease-out; }
.rail-resize:hover::after, .work.resizing .rail-resize::after { background: var(--accent); }
.work.resizing { cursor: col-resize; user-select: none; }
.rail-strip { display: none; }
.work.rail-collapsed .rail-body, .work.rail-collapsed .rail-resize { display: none; }
.work.rail-collapsed .rail-strip {
  display: flex; flex-direction: column; align-items: center; gap: 10px; width: 100%; padding: 12px 0;
  border: 0; background: transparent; color: var(--text); cursor: pointer; font: inherit;
}
.rail-strip:hover { background: var(--panel-2); }
.strip-label { writing-mode: vertical-rl; font-weight: 600; font-size: 12px; letter-spacing: .02em; }
.rail .pane-head { padding: 0 8px 0 16px; gap: 8px; }
.rail .pane-head .switch { margin-right: 4px; }
.rail h2 { margin: 0; font-size: 13px; font-weight: 650; }
.count {
  min-width: 20px; padding: 0 6px; border-radius: 999px; font-size: 11px; text-align: center;
  background: var(--panel-2); border: 1px solid var(--border); color: var(--muted);
}
.scope { padding: 9px 12px 9px 16px; font-size: 12px; line-height: 20px; color: var(--muted); border-bottom: 1px solid var(--border); }
.scope b { color: var(--text); font-weight: 500; }
.scope .sel-tag { display: inline-flex; align-items: center; gap: 6px; padding: 2px 4px 2px 9px; border-radius: 999px; border: 1px solid var(--hl); background: var(--select); color: var(--text); }
.scope .sel-tag button { display: grid; place-items: center; width: 18px; height: 18px; border: 0; border-radius: 50%; background: transparent; color: var(--muted); cursor: pointer; }
.scope .sel-tag button:hover { color: var(--text); background: var(--select); }
.scope .sel-tag svg.i { width: 12px; height: 12px; }
.peak-wrap { overflow: auto; flex: 1; min-height: 0; }
.peak-wrap:has(tbody:empty) { display: none; }
.peak-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.peak-table th { position: sticky; top: 0; z-index: 1; background: var(--chrome); padding: 0; text-align: right; border-bottom: 1px solid var(--border); }
.peak-table th button {
  display: inline-flex; align-items: baseline; justify-content: flex-end; gap: 3px; width: 100%; padding: 9px 6px 7px;
  border: 0; background: transparent; font: 500 11.5px var(--font); color: var(--muted); white-space: nowrap; cursor: pointer;
}
.peak-table th button:hover { color: var(--text); }
.peak-table th button small { font-size: 10.5px; opacity: .8; }
.peak-table th[aria-sort] button { color: var(--text); }
.peak-table th[aria-sort="ascending"] button::after { content: "↑"; font-size: 10px; }
.peak-table th[aria-sort="descending"] button::after { content: "↓"; font-size: 10px; }
.peak-table td { padding: 7px 6px; text-align: right; font: 12px var(--font-mono); white-space: nowrap; border-bottom: 1px solid var(--border); }
.peak-table th:first-child button, .peak-table td:first-child { padding-left: 16px; justify-content: flex-start; text-align: left; }
.peak-table th:last-child button, .peak-table td:last-child { padding-right: 14px; }
.peak-table .c-pos button { justify-content: flex-start; }
.peak-table td.c-pos { font-size: 13px; font-weight: 600; text-align: left; }
.peak-table td.c-pos small { display: block; font-size: 11px; font-weight: 400; color: var(--muted); }
.peak-table td.c-n { color: var(--muted); }
.peak-table .pdot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 7px; vertical-align: -1px; }
.peak-table tr.max td.c-n { color: var(--text); font-weight: 650; }
/* Height relative to the strongest peak, as a bar in the peak's colour behind the value */
.peak-table td.c-h {
  background: linear-gradient(var(--pc), var(--pc)) no-repeat right 6px bottom 5px;
  background-size: calc(var(--rel) * (100% - 12px)) 2px;
}
.peak-table .c-ext { display: none; }
.peak-table tbody tr { cursor: pointer; transition: background .12s ease-out; }
.peak-table tbody tr:hover, .peak-table tbody tr.hl { background: var(--panel-2); }
.rail .peak-table tbody tr.focus { background: var(--panel); }
.peak-table tbody tr.focus { background: var(--panel-2); box-shadow: inset 3px 0 0 var(--pc); }
/* Wide panel: the second unit and the relative height get their own columns */
@container (min-width: 520px) {
  .peak-table .c-ext { display: table-cell; }
  .peak-table td.c-pos small { display: none; }
}
.rail-foot { margin: 0; padding: 8px 16px; font-size: 11.5px; color: var(--muted); border-top: 1px solid var(--border); }
.rail-empty { padding: 28px 22px; color: var(--muted); text-align: center; }
.rail-empty b { display: block; color: var(--text); font-weight: 600; margin-bottom: 4px; }

/* ---- signal chain (bottom bar) ---- */
.chain {
  display: flex; align-items: center; gap: 4px; padding: 6px 12px; background: var(--chrome);
  border-top: 1px solid var(--border); overflow-x: auto; white-space: nowrap;
}
.chain .label { margin: 0 8px 0 4px; }
.chain > svg.i { color: var(--border-strong); width: 14px; height: 14px; }
.stage {
  font: inherit; display: inline-flex; align-items: center; gap: 7px; height: 30px; padding: 0 8px 0 10px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--panel-2); color: var(--text); cursor: pointer;
  transition: border-color .15s ease-out, background .15s ease-out;
}
.stage:hover { border-color: var(--muted); }
.stage .caret { width: 13px; height: 13px; color: var(--muted); }
.stage.attn { border-color: var(--warn); background: color-mix(in srgb, var(--warn) 9%, var(--panel-2)); }
.stage.attn.bad { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 8%, var(--panel-2)); }
.chain-sum { font-size: 12px; color: var(--muted); padding-right: 4px; }
.chain > .vr { height: 18px; margin: 0 6px; }
.foot-link { display: inline-flex; align-items: center; gap: 6px; padding: 4px 6px; border-radius: 6px; font-size: 12px; color: var(--muted); text-decoration: none; }
.foot-link:hover { color: var(--text); background: var(--panel-2); }
.foot-link svg.i { width: 14px; height: 14px; }
.foot-small { font-size: 11px; opacity: .8; }
.stage[aria-expanded="true"] { background: var(--panel-2); border-color: var(--border-strong); }
.stage .k { color: var(--muted); }
.stage .v { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-weight: 500; }
.stage .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.stage .dot.ok { background: var(--ok); } .stage .dot.warn { background: var(--warn); } .stage .dot.bad { background: var(--bad); }

/* ---- popovers ---- */
[popover] {
  margin: 0; inset: auto; position: fixed; padding: 14px; min-width: 240px; color: var(--text);
  background: var(--panel); border: 1px solid var(--border-strong); border-radius: 12px; box-shadow: var(--pop-shadow);
  opacity: 0; transform: translateY(4px); transition: opacity .16s ease-out, transform .16s ease-out, display .16s allow-discrete, overlay .16s allow-discrete;
}
[popover]:popover-open { opacity: 1; transform: none; }
@starting-style { [popover]:popover-open { opacity: 0; transform: translateY(4px); } }
.pop h3 { margin: 0 0 10px; font-size: 13px; font-weight: 650; }
.pop p { margin: 8px 0 0; font-size: 12px; color: var(--muted); max-width: 270px; }
.pop .pop-lead { margin: 0 0 12px; }
.pop .pop-calc { color: var(--text); font-size: 11.5px; }
.pop .pop-calc:empty { display: none; }
.pop .row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.pop .row + .row, .pop p + .row { margin-top: 10px; }
.presets { display: flex; gap: 4px; margin-top: 10px; }
.presets button {
  font: inherit; font-size: 12px; font-family: var(--font-mono); height: 26px; min-width: 38px; padding: 0 8px;
  border: 1px solid var(--border); border-radius: 6px; background: var(--panel-2); color: var(--text); cursor: pointer;
}
.presets button:hover { border-color: var(--muted); }
.presets button.on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.status-line { font-size: 12px; font-weight: 600; margin-top: 10px; }
.status-line.ok { color: var(--ok); } .status-line.warn { color: var(--warn); } .status-line.bad { color: var(--bad); }
.menu { padding: 6px; min-width: 220px; }
.menu button {
  font: inherit; width: 100%; display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 0; border-radius: 8px;
  background: transparent; color: var(--text); cursor: pointer; text-align: left;
}
.menu button:hover:not(:disabled) { background: var(--panel-2); }
.menu button:disabled { opacity: .4; cursor: default; }
.menu button small { display: block; color: var(--muted); font-size: 11.5px; }
.help dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 12px; }
.help dt { font-weight: 600; white-space: nowrap; }
.help dd { margin: 0; color: var(--muted); }
.help-actions { display: flex; gap: 8px; margin-top: 14px; }

/* ---- dialog & toasts ---- */
dialog {
  border: 1px solid var(--border-strong); border-radius: 14px; background: var(--panel); color: var(--text);
  padding: 20px 22px; width: min(420px, calc(100vw - 32px)); box-shadow: var(--pop-shadow);
}
dialog::backdrop { background: rgba(0, 0, 0, .4); }
dialog:focus-visible { outline: none; }
dialog.env .env-list:has(+ .actions[hidden]) { margin-bottom: 0; }
dialog h3 { margin: 0 0 8px; font-size: 15px; }
dialog p { margin: 0 0 18px; color: var(--muted); }
dialog .actions { display: flex; justify-content: flex-end; gap: 8px; }
dialog.env { width: min(540px, calc(100vw - 32px)); }
/* ?diag page */
dialog.diag { width: min(900px, calc(100vw - 32px)); }
.diag canvas { display: block; width: 100%; height: 200px; margin: 6px 0 2px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel-2); }
.diag .diag-legend { margin: 0 0 8px; font: 11.5px var(--font-mono); }
.diag pre { margin: 0 0 14px; padding: 10px 12px; max-height: 240px; overflow: auto; font: 11.5px/1.5 var(--font-mono); color: var(--text); background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; white-space: pre-wrap; }
.env-system { margin: 0 0 14px; font-size: 12px; }
.env-system b { color: var(--text); font-weight: 600; }
.env-list { list-style: none; margin: 0 0 18px; padding: 0; display: grid; gap: 10px; }
.env-list > li { padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px; background: var(--panel-2); }
.env-list h4 { display: flex; align-items: center; gap: 8px; margin: 0 0 6px; font-size: 13px; }
.env-list h4::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--warn); flex: none; }
.env-list .env-block h4::before { background: var(--bad); }
.env-list .env-ready h4::before { background: var(--ok); }
.env-list p, .env-list ol { margin: 6px 0 0; color: var(--muted); font-size: 12.5px; }
.env-list ol { padding-left: 18px; }
.env-list li li + li { margin-top: 3px; }
.env-list a { color: var(--text); text-underline-offset: 2px; }
.env-list code, .env-list pre { font-family: var(--font-mono); font-size: 11.5px; background: var(--panel); border: 1px solid var(--border); border-radius: 5px; }
.env-list code { padding: 0 4px; color: var(--text); }
.env-list pre { margin: 8px 0 0; padding: 8px 10px; overflow-x: auto; color: var(--text); }
dialog .actions { align-items: center; }
/* Notifications: bottom centre, just above the processing bar, newest at the bottom */
#toasts {
  position: fixed; left: 50%; bottom: 58px; transform: translateX(-50%); z-index: 30;
  display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none;
}
.toast {
  width: max-content; max-width: min(520px, calc(100vw - 32px)); pointer-events: auto;
  display: flex; align-items: flex-start; gap: 10px; padding: 10px 14px; border-radius: 10px;
  background: var(--panel); color: var(--text); border: 1px solid var(--border-strong); box-shadow: var(--pop-shadow);
  transition: opacity .3s ease-out, transform .3s ease-out;
}
.toast::before { content: ""; width: 8px; height: 8px; margin-top: 5px; border-radius: 50%; background: var(--muted); flex: none; }
.toast.ok::before { background: var(--ok); }
.toast.bad::before { background: var(--bad); }
.toast.out { opacity: 0; transform: translateY(6px); }
@starting-style { .toast { opacity: 0; transform: translateY(8px); } }

@media (max-width: 1440px) {
  #devSerial { display: none; }
  .panel-bar { gap: 10px; }
}
@media (max-width: 1360px) {
  .sig-pct { display: none; }
}
@media (max-width: 1100px) {
  .brand span { display: none; }
}
/* Narrow desktop windows (phones use the compact layout below instead) */
@media (max-width: 900px) {
  html:not(.compact) body { height: auto; min-height: 100%; }
  html:not(.compact) .panel-bar { padding: 8px 16px; }
  html:not(.compact) .vr { display: none; }
  html:not(.compact) .work { grid-template-columns: minmax(0, 1fr); align-content: start; background: var(--panel); }
  html:not(.compact) #scanInfo { display: none; }
  html:not(.compact) .plot-pane { height: 440px; }
  html:not(.compact) .rail { border-left: 0; border-top: 1px solid var(--border); max-height: 420px; }
  html:not(.compact) .work.rail-collapsed { grid-template-columns: minmax(0, 1fr); }
  html:not(.compact) .rail-resize, html:not(.compact) #railCollapse, html:not(.compact) .work.rail-collapsed .rail-strip { display: none; }
  html:not(.compact) .work.rail-collapsed .rail-body { display: flex; }
  html:not(.compact) #cursorRo { display: none; }
  html:not(.compact) .sig-pct { display: none; }
  html:not(.compact) .hint { left: 16px; max-width: calc(100% - 32px); }
  html:not(.compact) #toasts { left: 16px; right: 16px; transform: none; }
}

/* ---- phones: compact landscape layout (class set by ui/mobile.js) ---- */
.fs-btn, .rotate { display: none; }
html.compact { touch-action: manipulation; }
html.compact body { height: 100dvh; overflow: hidden; padding: 0 env(safe-area-inset-right) 0 env(safe-area-inset-left); }
.compact .fs-btn { display: inline-flex; }
.compact .panel-bar { padding: 5px 8px; gap: 6px; flex-wrap: nowrap; }
.compact .sig-tip { left: auto; right: -40px; width: min(330px, 80vw); }
@media (max-width: 860px) { .compact .sig > b { display: none; } }
.compact .bar-zone { gap: 6px; }
.compact .bar-center { gap: 8px; }
.compact .brand span, .compact .panel-bar .label, .compact .lbl, .compact #devSerial, .compact .sig-pct,
.compact .sim-badge, .compact .panel-bar .vr { display: none; }
.compact .btn { height: 30px; padding: 0 10px; }
.compact .btn.icon, .compact #acqBtn, .compact #exportBtn, .compact .btn.hold { width: 32px; padding: 0; }
.compact .btn.live { min-width: 0; }
.compact .conn { height: 30px; padding: 0 10px; }
.compact .conn:not(.on) { display: none; } /* the Connect button says it */
.compact .conn.on { padding-right: 3px; }
.compact .expo-box { height: 30px; }
.compact .expo-val input { width: 40px; }
.compact .expo-auto { padding: 0 8px; }
.compact .sig { gap: 6px; }
.compact .pane-head { height: 38px; padding: 0 6px 0 8px; gap: 6px; }
.compact .pane-head .opt .tip-btn, .compact #cursorRo, .compact #scanInfo { display: none; }
.compact .plot-wrap { padding: 2px 4px 0 0; }
.compact .plot { inset: 2px 4px 0 0; }
.compact .hint { display: none; }
.compact .guide { padding: 12px 14px 8px; max-height: 100%; overflow: auto; }
.compact .guide li { padding: 6px 0; }
/* Processing moves to a strip on the left, mirroring the peaks strip on the right: the plot keeps the height */
html.compact body { grid-template-columns: 58px minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
.compact .panel-bar { grid-column: 1 / -1; }
.compact .work { grid-column: 2; grid-row: 2; }
.compact .chain {
  grid-column: 1; grid-row: 2; flex-direction: column; align-items: stretch; gap: 4px; padding: 6px 4px;
  border-top: 0; border-right: 1px solid var(--border); overflow-y: auto;
}
.compact .chain .label, .compact .chain-sum, .compact .chain > .vr, .compact .foot-link, .compact .chain .spacer { display: none; }
.compact .chain > svg.i { align-self: center; width: 12px; height: 12px; transform: rotate(90deg); }
/* Phone strip tiles: the full name written sideways (like the Peaks strip) and the value underneath */
.stage .st-short { display: none; }
.compact .chain > svg.i { display: none; }
.compact .stage { position: relative; flex: 1 1 auto; flex-direction: column; justify-content: center; gap: 6px; height: auto; padding: 8px 2px 7px; }
.compact .stage .v, .compact .stage .caret { display: none; }
.compact .stage .k { order: 1; writing-mode: vertical-rl; font-size: 11.5px; font-weight: 600; color: var(--text); letter-spacing: .02em; }
.compact .stage .st-short { order: 2; display: block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; font-size: 13px; font-weight: 650; color: var(--text); }
.compact .stage .dot { position: absolute; top: 5px; right: 5px; }
.compact #toasts { bottom: 10px; gap: 4px; }
.compact .toast { padding: 6px 11px; font-size: 12px; border-radius: 8px; gap: 8px; max-width: min(420px, calc(100vw - 32px)); }
.compact .toast::before { width: 6px; height: 6px; margin-top: 5px; }
.compact .plot-wrap.zoomed .plot { bottom: 32px; }
.compact .overview { bottom: 4px; height: 24px; }
/* Peaks: a strip at the right edge that opens as a drawer over the plot */
.compact .work, .compact .work.rail-collapsed { position: relative; grid-template-columns: minmax(0, 1fr) 40px; }
.compact .rail-resize { display: none; }
.compact .work:not(.rail-collapsed) .rail {
  position: absolute; z-index: 15; top: 0; right: 0; bottom: 0; width: min(440px, 64vw);
  box-shadow: -14px 0 28px rgba(0, 0, 0, .5);
}
.compact .rail .pane-head { padding: 0 6px 0 12px; }
.compact .peak-table th:first-child button, .compact .peak-table td:first-child { padding-left: 12px; }
.compact .rail-foot { display: none; }
/* Upright phone: only the turn-sideways screen (the bar would not fit and widen the page) */
.compact.portrait body > :not(.rotate):not(dialog) { display: none !important; }
.compact.portrait .rotate {
  display: grid; place-items: center; position: fixed; inset: 0; z-index: 100; padding: 24px; text-align: center;
  background: var(--bg);
}
.rotate b { display: block; font-size: 17px; margin: 14px 0 6px; }
.rotate p { margin: 0 0 20px; color: var(--muted); }
.rotate-icon { width: 44px; height: 44px; stroke-width: 1.5; color: var(--muted); animation: turn 2.4s ease-in-out infinite; }
@keyframes turn { 0%, 35% { transform: rotate(0); } 55%, 90% { transform: rotate(-90deg); } 100% { transform: rotate(0); } }
@media (prefers-reduced-motion: reduce) { .rotate-icon { animation: none; } }
