/* ==========================================================================
   Signal bench — a measuring instrument for one strategy's result.

   World: CRT oscilloscope on a signal bench. Near-black instrument ground under
   a faint etched graticule; phosphor traces are the only saturated colour; every
   region is measured against the grid rather than floated inside a card.
   ========================================================================== */

:root {
  /* Ground and graticule: the glass and the etching on it. */
  --glass: #04090b;
  --bench: #080f12;
  --panel: #0b1418;
  --etched: #16383a;
  --etched-dim: #0e2124;
  --rule: #12292c;

  /* Trace inks. Only these carry saturation. */
  --ch1: #5df2a0;
  --ch1-dim: #1d6b48;
  --ch2: #4fd6ea;
  --ch2-dim: #1a5f6b;
  --ch3: #f0a63c;
  --ch3-dim: #6d4a18;
  /* Reference inks: desaturated so they are never mistaken for signal, but light
     enough to clear the 3:1 non-text floor on their own. They are drawn at full
     opacity -- compositing these over near-black was what made them unreadable. */
  --ref-a: #b7c3c9;
  --ref-b: #93a6b0;
  --ref-c: #7d949e;

  /* Readout ink. */
  --ink: #d8e8e8;
  --ink-mid: #93b0b1;
  --ink-dim: #6f8f91;

  --pos: #5df2a0;
  --neg: #f0776a;

  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, "Roboto Mono", monospace;
  --caps: "Helvetica Neue", -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;

  --hair: 1px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--glass);
  color: var(--ink);
  font: 14px/1.5 var(--mono);
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}

/* The glass itself: a faint graticule etched across the whole surface. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    linear-gradient(to right, var(--etched-dim) var(--hair), transparent var(--hair)),
    linear-gradient(to bottom, var(--etched-dim) var(--hair), transparent var(--hair));
  background-size: 48px 48px;
  opacity: .32;
}

.bench { position: relative; z-index: 1; max-width: 1500px; margin: 0 auto; padding: 0 20px 48px; }

/* ---- instrument chrome ---- */

.face {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 0 12px;
  border-bottom: var(--hair) solid var(--rule);
  margin-bottom: 6px;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: baseline; gap: 10px; }
.brand .mark {
  font: 700 13px/1 var(--caps);
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--ch1);
}
.brand .model { font-size: 12px; color: var(--ink-dim); letter-spacing: .04em; }

.face .plate {
  display: flex; gap: 18px; flex-wrap: wrap;
  font-size: 11px; letter-spacing: .07em; text-transform: uppercase; color: var(--ink-dim);
}
.face .plate b { color: var(--ink-mid); font-weight: 400; }

/* ---- bands: the display is a stack of horizon bands, dark to light ---- */

.band { border-top: var(--hair) solid var(--rule); }
.band:first-of-type { border-top: 0; }

.band-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 14px; flex-wrap: wrap;
  padding: 16px 0 8px;
}
.band-head h2 {
  margin: 0;
  font: 400 11px/1 var(--caps);
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--ink-mid);
}
.band-head .note { font-size: 11px; color: var(--ink-dim); }

/* ---- the scope face: display + channel strip ---- */

.scope { display: grid; grid-template-columns: minmax(0, 1fr) 220px; gap: 18px; }
/* the growth chart and the exposure band occupy the SAME grid column, so their
   plot areas line up exactly and the shared crosshair falls on the same bar */
.scope > .display { grid-column: 1; grid-row: 1; }
.scope > .exposure { grid-column: 1; grid-row: 2; min-width: 0; }
.scope > .channels { grid-column: 2; grid-row: 1 / span 2; }
/* Single column: release the explicit placement so source order applies. Source
   order is display, exposure, channels -- the exposure band stays directly under
   the chart it is read with, and the channels follow. `order: -1` was used to lift
   the channels above the chart, but that fights the grid placement this layout
   depends on for alignment, and it separated the two panels being compared. */
@media (max-width: 1100px) {
  .scope { grid-template-columns: 1fr; }
  .scope > .display, .scope > .exposure, .scope > .channels {
    grid-column: 1; grid-row: auto;
  }
}
@media (max-width: 820px) {
  .scope { gap: 12px; }
  .display svg { max-height: 52vh; }
  .readouts { grid-template-columns: repeat(auto-fit, minmax(116px, 1fr)); }
}

.display { position: relative; background: var(--bench); border: var(--hair) solid var(--rule); }
.display svg { display: block; width: 100%; height: auto; }

/* graticule */
.grat { stroke: var(--etched-dim); stroke-width: 1; }
.grat-major { stroke: var(--etched); stroke-width: 1; }
.grat-t { fill: var(--ink-dim); font: 11px var(--mono); letter-spacing: .02em; }

/* traces */
.trace { fill: none; stroke-linejoin: round; stroke-linecap: round; }
.trace.faint { opacity: .62; }
.trace.ref { stroke-dasharray: 6 4; }

/* crosshair */
.cursor { stroke: var(--ink-dim); stroke-width: 1; stroke-dasharray: 3 3; }
/* one rule spanning both stacked panels, so a state change can be read against
   whatever the growth chart is doing at the same bar */
.crosshair { stroke: var(--ink); stroke-width: 1; opacity: .38; pointer-events: none; }
.exp-crosshair { stroke-dasharray: 2 3; }
.exp-cross-label { font: 11px var(--mono); text-anchor: start; pointer-events: none; }

/* ---- channel strip: knobs and their skirts ---- */

.channels { display: flex; flex-direction: column; gap: 0; padding: 6px; border: var(--hair) solid var(--rule); background: var(--panel); }
.ch {
  display: grid; grid-template-columns: 34px minmax(0, 1fr);
  border-bottom: var(--hair) solid var(--rule);
}
.ch:last-child { border-bottom: 0; }
.ch .chnum {
  display: flex; align-items: flex-start; justify-content: center;
  padding-top: 10px;
  font-size: 11px; letter-spacing: .04em; color: var(--ink-dim);
  border-right: var(--hair) solid var(--rule);
  background: var(--bench);
}
.ch .chbody { padding: 7px 8px 8px; min-width: 0; }
.ch .chlabel {
  font: 400 11px/1.25 var(--caps); letter-spacing: .09em; text-transform: uppercase;
  color: var(--ink-dim); margin-bottom: 4px;
}
.ch.on .chnum { color: var(--ch1); }
.ch.on.c2 .chnum { color: var(--ch2); }
.ch.on.c3 .chnum  { color: var(--ch3); }

/* detents: discrete steps, never a smooth slider */
.detents { display: flex; flex-wrap: wrap; gap: 3px; }
.detents button {
  flex: 1 1 auto;
  min-width: 0;
  appearance: none;
  padding: 5px 7px;
  font: 400 11px/1.2 var(--mono);
  color: var(--ink-mid);
  background: var(--bench);
  border: var(--hair) solid var(--rule);
  border-radius: 1px;
  cursor: pointer;
  white-space: nowrap;
  transition: color .1s, border-color .1s, background .1s;
}
.detents button:hover { color: var(--ink); border-color: var(--etched); }
.detents button[aria-pressed="true"] {
  color: var(--glass);
  background: var(--ch1);
  border-color: var(--ch1);
  font-weight: 600;
}
.ch.c2 .detents button[aria-pressed="true"] { background: var(--ch2); border-color: var(--ch2); }
.ch.c3 .detents button[aria-pressed="true"] { background: var(--ch3); border-color: var(--ch3); }
.detents button:focus-visible { outline: 2px solid var(--ch2); outline-offset: 1px; }

/* trace key under each channel */
.trace-key { display: flex; flex-wrap: wrap; gap: 3px 12px; margin-top: 7px; }
.trace-key label {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; color: var(--ink-mid); cursor: pointer; user-select: none;
}
.trace-key input { accent-color: var(--ch1); margin: 0; width: 12px; height: 12px; }
.trace-key .swatch { width: 14px; height: 2px; display: inline-block; }

/* ---- readout strip: instrument measurement tabs ---- */

.readouts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  border: var(--hair) solid var(--rule);
  border-top: 0;
  background: var(--panel);
}
.ro { padding: 8px 10px 9px; border-right: var(--hair) solid var(--rule); min-width: 0; }
.ro:last-child { border-right: 0; }
.ro .k {
  font: 400 11px/1.25 var(--caps); letter-spacing: .08em; text-transform: uppercase;
  color: var(--ink-dim); min-height: 1.25em;
}
.ro .v { font-size: 18px; line-height: 1.25; font-weight: 600; letter-spacing: -.01em; }
.ro .s { font-size: 12px; color: var(--ink-dim); }
.ro.accent .v { color: var(--ch1); }
/* The lag spread carries the lag-2 channel ink, since that colour means "the
   spread" everywhere else on the surface. It gets no tab treatment of its own:
   an emphasised hero tab is the template this direction refuses. */
.ro.hero .v { color: var(--ch3); }
.ro .v.pos { color: var(--pos); }
.ro .v.neg { color: var(--neg); }
.ro .v.warn { color: var(--ch3); }

/* ---- exposure: the held instrument over time, one lane per instrument ---- */
.exposure { min-width: 0; }
.exp-head-row {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; margin: 2px 0 6px;
}
.exp-head-row h3 {
  font: 600 11px var(--mono); letter-spacing: .1em; text-transform: uppercase;
  color: var(--ink-mid); margin: 0;
}
.exp-head-row .note { font-size: 11px; color: var(--ink-dim); }
.exp-wrap { border: var(--hair) solid var(--rule); background: var(--panel); position: relative; }
.exp-wrap svg { display: block; width: 100%; height: auto; }
.exp-lane { stroke: none; }
.exp-lane:hover { opacity: .82; }
.exp-grid { stroke: var(--etched-dim); stroke-width: 1; }
.exp-label { font: 400 11px var(--mono); fill: var(--ink-mid); }
.exp-tick { fill: var(--ink-dim); font: 11px var(--mono); text-anchor: middle; }
.exp-head {
  display: flex; flex-wrap: wrap; gap: 4px 18px;
  padding: 8px 12px 9px; border-top: var(--hair) solid var(--rule);
  font-size: 11.5px; color: var(--ink-dim);
}
.exp-head b { color: var(--ink); font-weight: 600; }
.exp-head .sw { display: inline-block; width: 9px; height: 9px; margin-right: 5px; }
.exp-empty { padding: 22px 12px; text-align: center; color: var(--ink-dim); font-size: 12px; }

/* ---- states ---- */

.display { position: relative; }
body[data-loading="1"] .display::after {
  content: "acquiring…";
  position: absolute; right: 10px; bottom: 8px;
  font: 400 11px/1 var(--caps); letter-spacing: .12em; text-transform: uppercase;
  color: var(--ch3);
}
body[data-loading="1"] .display { opacity: .72; }

.fault {
  display: none;
  padding: 10px 12px;
  border: var(--hair) solid var(--neg);
  border-top: 0;
  background: var(--panel);
  color: var(--neg);
  font-size: 12px;
}
body[data-fault="1"] .fault { display: block; }
.empty-note {
  padding: 24px 12px; text-align: center;
  font-size: 12px; color: var(--ink-dim);
}

/* ---- band head control (the eligibility detents live with the timebase) ---- */
.band-ctl { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.band-ctl-label {
  font: 400 11px/1 var(--caps); letter-spacing: .1em; text-transform: uppercase;
  color: var(--ink-dim);
}
.band-ctl .detents { gap: 3px; }

/* ---- timebase: one cell per month, never shrunken ---- */

.timebase { border: var(--hair) solid var(--rule); background: var(--panel); padding: 10px 12px 12px; }
.tb-scroll { overflow-x: auto; padding-bottom: 4px; }
.tb-grid { display: flex; gap: 4px; min-width: min-content; }
.tb-year { display: flex; flex-direction: column; gap: 4px; }
.tb-year .yl {
  font-size: 12px; letter-spacing: .06em; color: var(--ink-dim);
  text-align: center; padding-bottom: 2px;
}
.tb-cell {
  width: 30px; height: 22px;
  border: var(--hair) solid transparent;
  border-radius: 1px;
  cursor: pointer;
  position: relative;
  transition: transform .08s ease-out;
}
.tb-cell:hover { transform: scale(1.14); z-index: 3; border-color: var(--ink); }
.tb-cell[aria-current="true"] {
  border-color: var(--ink);
  box-shadow: 0 0 0 2px var(--glass), 0 0 0 3px var(--ch1);
  z-index: 2;
}
.tb-cell.empty { background: var(--etched-dim); opacity: .25; cursor: default; }
.tb-cell.off { opacity: .22; }
.tb-cell:focus-visible { outline: 2px solid var(--ch2); outline-offset: 1px; }

/* ---- small multiples: distribution across start months ---- */

.multiples { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 940px) { .multiples { grid-template-columns: 1fr; } }
.mpanel { border: var(--hair) solid var(--rule); background: var(--panel); }
.mpanel svg { display: block; width: 100%; height: auto; }
.mfoot {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 6px 10px 7px; border-top: var(--hair) solid var(--rule);
  font-size: 11px; color: var(--ink-dim);
}

/* ---- drawer: the ranked table, out of the way ---- */

details.drawer { border: var(--hair) solid var(--rule); background: var(--panel); }
details.drawer summary {
  padding: 9px 12px; cursor: pointer;
  font: 400 11px/1 var(--caps); letter-spacing: .12em; text-transform: uppercase;
  color: var(--ink-mid);
}
details.drawer summary:hover { color: var(--ink); }
details.drawer summary::marker { color: var(--ink-dim); }
.table-wrap { max-height: 380px; overflow: auto; border-top: var(--hair) solid var(--rule); }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th, td { padding: 5px 10px; text-align: left; border-bottom: var(--hair) solid var(--rule); white-space: nowrap; }
th {
  position: sticky; top: 0; z-index: 1;
  background: var(--bench); color: var(--ink-dim);
  font: 400 11px/1.4 var(--caps); letter-spacing: .1em; text-transform: uppercase;
}
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--bench); }
tbody tr:has(td[aria-current="true"]) { background: color-mix(in srgb, var(--ch1) 10%, transparent); }
tbody tr:has(td[aria-current="true"]) td:first-child { box-shadow: inset 1px 0 0 var(--ch1); }

.pos { color: var(--pos); }
.neg { color: var(--neg); }
.dim { color: var(--ink-dim); }

/* ---- footer ---- */

footer {
  margin-top: 22px; padding-top: 12px;
  border-top: var(--hair) solid var(--rule);
  font-size: 11px; line-height: 1.7; color: var(--ink-dim);
}
footer code { color: var(--ink-mid); }

/* ---- tooltip: instrument annotation, not a floating card ---- */

.tip {
  position: fixed; z-index: 60; opacity: 0; pointer-events: none;
  transition: opacity .09s linear;
  background: rgba(4, 9, 11, .96);
  border: var(--hair) solid var(--etched);
  border-left: var(--hair) solid var(--ch1);
  padding: 7px 10px 8px;
  font-size: 11px; line-height: 1.6;
  max-width: 320px;
}
.tip.on { opacity: 1; }
.tip .tt { color: var(--ink); letter-spacing: .04em; margin-bottom: 3px; }
.tip .tr { display: flex; justify-content: space-between; gap: 14px; }
.tip .tr span:first-child { color: var(--ink-mid); }
.tip .tr span:last-child { color: var(--ink-mid); }
/* real-trade rows under a drawn exposure bar: a rule separates them from the
   bar's own facts, and the explanation sits dimmer than the numbers */
.tip .tr.sep { border-top: var(--hair) solid var(--rule); margin-top: 4px; padding-top: 3px; }
.tip .tr.sep span { color: var(--ink); }
.tip .tr.sub span { padding-left: 8px; font-size: 11px; }
.tip .tr.sub b { color: var(--ink); font-weight: 600; }
.tip .tr.sub i { font-style: normal; opacity: .72; }
.tip .tr.note { margin-top: 4px; padding-top: 3px; border-top: var(--hair) solid var(--rule); }
.tip .tr.note span { font-size: 10px; line-height: 1.35; opacity: .78; }
.tip .tr.note b { color: var(--ink); font-weight: 600; }

/* ---- browser surfaces: the parts nobody draws still carry the world ---- */

::selection { background: var(--ch1); color: var(--glass); }
:focus-visible { outline: 2px solid var(--ch2); outline-offset: 1px; }
* { scrollbar-width: thin; scrollbar-color: var(--etched) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bench); }
::-webkit-scrollbar-thumb { background: var(--etched); border: 2px solid var(--bench); }
::-webkit-scrollbar-thumb:hover { background: var(--ink-dim); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* Screen-reader-only: the document needs an h1 but the face already carries the name. */
.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
