:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --wash: rgba(11, 11, 11, 0.04);
  --s1: #2a78d6;
  --s2: #eb6834;
  --s3: #1baf7a;
  --pos: #e34948;
  --neg: #2a78d6;
  --neutral: #c3c2b7;
  --good: #006300;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04), 0 4px 16px rgba(11, 11, 11, 0.04);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --wash: rgba(255, 255, 255, 0.06);
    --s1: #3987e5;
    --s2: #d95926;
    --s3: #199e70;
    --pos: #e66767;
    --neg: #3987e5;
    --neutral: #52514e;
    --good: #0ca30c;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --wash: rgba(255, 255, 255, 0.06);
  --s1: #3987e5;
  --s2: #d95926;
  --s3: #199e70;
  --pos: #e66767;
  --neg: #3987e5;
  --neutral: #52514e;
  --good: #0ca30c;
  --shadow: none;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 120px; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 16px; }
h1, h2, h3, p { margin: 0; }
h2 { font-size: 22px; font-weight: 650; letter-spacing: -0.01em; }
h3 { font-size: 15px; font-weight: 600; }
code { font-size: 0.92em; background: var(--wash); padding: 1px 5px; border-radius: 4px; }

/* ---------- Header ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; padding-top: 18px; }
.eyebrow { font-size: 12px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--s1); }
h1 { font-size: 24px; font-weight: 700; letter-spacing: -0.015em; margin-top: 2px; }
.subtitle { color: var(--ink-2); font-size: 14px; margin-top: 2px; }
.theme-toggle {
  display: inline-flex; align-items: center; gap: 6px; flex-shrink: 0;
  background: var(--surface); color: var(--ink-2);
  border: 1px solid var(--border); border-radius: 999px;
  padding: 7px 12px; font: inherit; font-size: 13px; cursor: pointer;
}
.theme-toggle:hover { color: var(--ink); background: var(--wash); }
.sectionnav { display: flex; gap: 4px; overflow-x: auto; padding-top: 10px; padding-bottom: 8px; scrollbar-width: none; }
.sectionnav::-webkit-scrollbar { display: none; }
.sectionnav a {
  flex-shrink: 0; color: var(--ink-2); text-decoration: none; font-size: 13.5px; font-weight: 500;
  padding: 6px 12px; border-radius: 999px;
}
.sectionnav a:hover { background: var(--wash); color: var(--ink); }
.sectionnav a.active { background: var(--ink); color: var(--page); }

/* ---------- Layout ---------- */
.section { padding-top: 36px; display: flex; flex-direction: column; gap: 16px; }
.section > h2 { margin-bottom: -8px; }
.section-lead { color: var(--ink-2); max-width: 760px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow); padding: 18px 18px 16px; min-width: 0;
}
figure.card { margin: 0; }
.chart-card { display: flex; flex-direction: column; gap: 12px; }
figcaption p { color: var(--ink-2); font-size: 13.5px; margin-top: 2px; }
.chart { width: 100%; position: relative; }
.chart svg { display: block; overflow: visible; }

/* ---------- Filter ---------- */
.filterbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.filter-label { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.filter-note { font-size: 12.5px; color: var(--muted); }
.segmented {
  display: inline-flex; background: var(--wash); border: 1px solid var(--border);
  border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap;
}
.segmented button {
  font: inherit; font-size: 13.5px; font-weight: 500; color: var(--ink-2);
  background: transparent; border: 0; border-radius: 7px; padding: 6px 14px; cursor: pointer;
}
.segmented button:hover { color: var(--ink); }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); font-weight: 600; }
.segmented.small button { font-size: 12.5px; padding: 5px 10px; }
.segmented { align-self: flex-start; }

/* ---------- Tiles ---------- */
.hero-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); gap: 16px; }
.hero { display: flex; flex-direction: column; justify-content: center; }
.hero-value { font-size: 64px; font-weight: 650; letter-spacing: -0.03em; line-height: 1.05; margin: 6px 0 6px; }
.tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.tiles-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); padding: 16px; min-width: 0; }
.thr-card .tile { box-shadow: none; background: var(--page); }
.tile-label { font-size: 13px; color: var(--ink-2); font-weight: 500; }
.tile-value { font-size: 28px; font-weight: 650; letter-spacing: -0.02em; margin-top: 4px; line-height: 1.15; }
.tile-sub { font-size: 12.5px; color: var(--muted); margin-top: 4px; }

/* ---------- Legend ---------- */
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; color: var(--ink-2); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.legend-line { width: 16px; height: 2px; border-radius: 1px; display: inline-block; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th { font-weight: 600; color: var(--ink-2); font-size: 12.5px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.best td { font-weight: 600; }
td .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
details.data-table { font-size: 13px; }
details.data-table summary, .details-card summary {
  cursor: pointer; color: var(--ink-2); font-size: 13px; font-weight: 500; list-style: none;
  display: inline-flex; align-items: center; gap: 6px;
}
details summary::-webkit-details-marker { display: none; }
details summary::before { content: ""; width: 6px; height: 6px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(-45deg); transition: transform .15s; }
details[open] > summary::before { transform: rotate(45deg); }
details.data-table[open] summary { margin-bottom: 8px; }
.details-card summary { font-size: 14px; color: var(--ink); font-weight: 600; }
.details-card[open] summary { margin-bottom: 12px; }
.badge { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--wash); color: var(--ink-2); }
.badge.good { color: var(--good); }

/* ---------- Confusion matrix ---------- */
.cm { display: grid; grid-template-columns: auto 1fr 1fr; gap: 4px; align-items: stretch; }
.cm .cm-head { font-size: 12.5px; color: var(--ink-2); font-weight: 600; text-align: center; padding: 4px; }
.cm .cm-row { font-size: 12.5px; color: var(--ink-2); font-weight: 600; display: flex; align-items: center; padding-right: 8px; }
.cm .cm-cell { border-radius: 8px; padding: 18px 10px; text-align: center; min-height: 84px; display: flex; flex-direction: column; justify-content: center; }
.cm .cm-val { font-size: 22px; font-weight: 650; }
.cm .cm-lbl { font-size: 12px; opacity: 0.85; }

/* ---------- Threshold ---------- */
.thr-card { display: flex; flex-direction: column; gap: 16px; }
.thr-control { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.thr-control label { font-weight: 600; font-size: 14px; }
.thr-control input[type="range"] { flex: 1; min-width: 180px; accent-color: var(--s1); }
.thr-control output { font-size: 22px; font-weight: 650; min-width: 56px; font-variant-numeric: tabular-nums; }

/* ---------- Insight ---------- */
.insight { display: flex; gap: 14px; }
.insight-num { flex-shrink: 0; width: 28px; height: 28px; border-radius: 50%; background: var(--wash); color: var(--ink); font-weight: 650; font-size: 13px; display: grid; place-items: center; }
.insight h3 { margin-bottom: 4px; }
.insight p { color: var(--ink-2); font-size: 14px; }

/* ---------- Tooltip ---------- */
.tooltip {
  position: fixed; z-index: 50; pointer-events: none;
  background: var(--surface); color: var(--ink); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 10px; font-size: 12.5px; min-width: 120px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.14);
}
.tooltip .tt-title { color: var(--ink-2); font-size: 12px; margin-bottom: 4px; }
.tooltip .tt-row { display: flex; align-items: center; gap: 8px; }
.tooltip .tt-key { width: 12px; height: 2px; border-radius: 1px; flex-shrink: 0; }
.tooltip .tt-val { font-weight: 650; font-variant-numeric: tabular-nums; }
.tooltip .tt-lbl { color: var(--ink-2); }

/* ---------- Chart marks ---------- */
.mark { transition: opacity .12s; }
.hit:hover + .mark, .hit:focus + .mark { opacity: 0.78; }
.hit { fill: transparent; cursor: default; outline: none; }
.hit:focus-visible { stroke: var(--ink); stroke-width: 1; }
.axis-text { fill: var(--muted); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.cat-text { fill: var(--ink-2); font-size: 12.5px; }
.val-text { fill: var(--ink-2); font-size: 12px; font-variant-numeric: tabular-nums; }

.footer { padding-top: 40px; padding-bottom: 40px; color: var(--muted); font-size: 12.5px; display: flex; flex-direction: column; gap: 4px; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .hero-grid { grid-template-columns: minmax(0, 1fr); }
  .tiles-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 560px) {
  h1 { font-size: 20px; }
  .hero-value { font-size: 52px; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tile-value { font-size: 22px; }
  .theme-toggle span { display: none; }
  .topbar .eyebrow, .topbar .subtitle { display: none; }
  .topbar-inner { padding-top: 12px; align-items: center; }
  .card { padding: 14px; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none !important; }
}
