.viz-root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface-1: #fcfcfb;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --neutral: #f0efec;
  --ink-dark: #0b0b0b;
  --ink-light: #ffffff;
  /* Sequential blue, near-zero recedes toward the surface. */
  --s0: #cde2fb; --s1: #9ec5f4; --s2: #6da7ec; --s3: #3987e5;
  --s4: #256abf; --s5: #184f95; --s6: #0d366b;
  --t0: var(--ink-dark); --t1: var(--ink-dark); --t2: var(--ink-dark); --t3: var(--ink-dark);
  --t4: var(--ink-light); --t5: var(--ink-light); --t6: var(--ink-light);
  --warning: #fab219; --serious: #ec835a; --critical: #d03b3b;
}
@media (prefers-color-scheme: dark) {
  .viz-root {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface-1: #1a1a19;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --series-1: #3987e5;
    --series-2: #d95926;
    --neutral: #383835;
    /* Same ramp, reversed so near-zero recedes into the dark surface. */
    --s0: #0d366b; --s1: #104281; --s2: #184f95; --s3: #256abf;
    --s4: #3987e5; --s5: #86b6ef; --s6: #cde2fb;
    --t0: var(--ink-light); --t1: var(--ink-light); --t2: var(--ink-light); --t3: var(--ink-light);
    --t4: var(--ink-dark); --t5: var(--ink-dark); --t6: var(--ink-dark);
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  padding: 24px clamp(12px, 3vw, 40px) 40px;
  background: var(--page);
  color: var(--text-primary);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h1 { font-size: 22px; margin: 0 0 4px; font-weight: 650; }
h2 { font-size: 16px; margin: 0; font-weight: 600; }
.sub, .hint, footer { color: var(--text-secondary); margin: 0; }
.hint { font-size: 12px; margin-top: 8px; }
footer { font-size: 12px; margin-top: 32px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.top { display: flex; flex-wrap: wrap; gap: 16px 32px; justify-content: space-between; align-items: flex-end; margin-bottom: 20px; }
.tiles { display: flex; gap: 12px; margin: 0; flex-wrap: wrap; }
.tile { background: var(--surface-1); border: 1px solid var(--border); border-radius: 8px; padding: 8px 14px; min-width: 112px; }
.tile dt { font-size: 12px; color: var(--text-secondary); }
.tile dd { margin: 2px 0 0; font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; }

.banner { background: var(--surface-1); border: 1px solid var(--critical); border-left-width: 4px; border-radius: 6px; padding: 8px 12px; margin-bottom: 16px; }

.controls { display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: center; margin-bottom: 12px; }
.controls label { color: var(--text-secondary); display: flex; gap: 6px; align-items: center; }
select, button { font: inherit; color: var(--text-primary); }
select { background: var(--surface-1); border: 1px solid var(--axis); border-radius: 6px; padding: 4px 8px; }
.seg { display: inline-flex; border: 1px solid var(--axis); border-radius: 8px; overflow: hidden; }
.seg button { background: var(--surface-1); border: 0; padding: 6px 12px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--axis); }
.seg button[aria-checked="true"] { background: var(--text-primary); color: var(--surface-1); }
button:focus-visible, select:focus-visible, td:focus-visible { outline: 2px solid var(--series-1); outline-offset: 2px; }
.ghost { background: none; border: 1px solid var(--axis); border-radius: 6px; padding: 4px 10px; cursor: pointer; }

.legend { display: flex; align-items: center; gap: 2px; font-size: 12px; color: var(--text-secondary); }
.legend .sw { display: inline-flex; flex-direction: column; align-items: center; gap: 2px; }
.legend .chip { width: 40px; height: 12px; border-radius: 3px; border: 1px solid var(--border); }
.legend .title { margin-right: 8px; }

.matrix-wrap { overflow: auto; background: var(--surface-1); border: 1px solid var(--border); border-radius: 8px; padding: 8px; max-height: 80vh; }
.matrix { border-collapse: separate; border-spacing: 2px; font-variant-numeric: tabular-nums; font-size: 12px; }
.matrix th { font-weight: 500; color: var(--text-secondary); white-space: nowrap; background: var(--surface-1); }
.matrix thead th { position: sticky; top: 0; z-index: 2; vertical-align: bottom; height: 96px; padding: 0 0 4px; }
.matrix thead th span { writing-mode: vertical-rl; transform: rotate(180deg); display: inline-block; }
.matrix tbody th { position: sticky; left: 0; z-index: 1; text-align: right; padding: 0 8px 0 0; }
.matrix thead th.corner { left: 0; z-index: 3; text-align: right; font-size: 11px; color: var(--text-muted); padding-right: 8px; }
.matrix td { min-width: 40px; height: 24px; text-align: center; border-radius: 4px; cursor: pointer; padding: 0 2px; }
.matrix td.self { color: var(--text-muted); cursor: default; background: none; }
.matrix td.na { color: var(--text-muted); background: var(--neutral); }
.matrix .area-start { box-shadow: inset 2px 0 0 var(--axis); }
.matrix tr.area-start th, .matrix tr.area-start td { box-shadow: inset 0 2px 0 var(--axis); }
.matrix th.hl { color: var(--text-primary); font-weight: 700; }
.matrix td.hover { outline: 2px solid var(--text-primary); outline-offset: -1px; }

.b0 { background: var(--s0); color: var(--t0); } .b1 { background: var(--s1); color: var(--t1); }
.b2 { background: var(--s2); color: var(--t2); } .b3 { background: var(--s3); color: var(--t3); }
.b4 { background: var(--s4); color: var(--t4); } .b5 { background: var(--s5); color: var(--t5); }
.b6 { background: var(--s6); color: var(--t6); }
.l0 { background: var(--neutral); color: var(--text-secondary); }
.l1 { background: var(--warning); color: var(--ink-dark); }
.l2 { background: var(--serious); color: var(--ink-dark); }
.l3 { background: var(--critical); color: var(--ink-light); }

.tooltip { position: fixed; z-index: 10; pointer-events: none; background: var(--surface-1); color: var(--text-primary); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; box-shadow: 0 4px 16px rgba(0,0,0,.18); font-size: 12px; max-width: 320px; }
.tooltip .tt-title { font-weight: 600; margin-bottom: 4px; }
.tooltip table { border-collapse: collapse; }
.tooltip td { padding: 1px 0; }
.tooltip td + td { padding-left: 12px; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.tooltip .key { display: inline-block; width: 10px; height: 2px; vertical-align: middle; margin-right: 6px; border-radius: 1px; }

.detail { margin-top: 20px; background: var(--surface-1); border: 1px solid var(--border); border-radius: 8px; padding: 16px; }
.detail-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.series-legend { display: flex; gap: 16px; font-size: 12px; color: var(--text-secondary); margin-bottom: 8px; }
.series-legend .key { display: inline-block; width: 16px; height: 2px; vertical-align: middle; margin-right: 6px; border-radius: 1px; }
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: 280px; overflow: visible; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .axis { stroke: var(--axis); stroke-width: 1; }
.chart text { fill: var(--text-muted); font-size: 11px; }
.chart text.end-label { fill: var(--text-secondary); font-size: 12px; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .crosshair { stroke: var(--axis); stroke-width: 1; }
.chart .dot { stroke: var(--surface-1); stroke-width: 2; }
.chart .hit { fill: transparent; }
