:root {
  color-scheme: light;
  --bg: #f7f6f2;
  --surface: #fcfcfb;
  --surface-2: #f0efea;
  --border: #e2e0d8;
  --grid: #e8e6df;
  --text: #121211;
  --text-2: #52514e;
  --text-3: #7a7973;
  --accent: #1c5cab;
  --accent-soft: #cde2fb;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #4a3aa7; --s8: #e34948;
  --seq-lo: #cde2fb; --seq-hi: #0d366b;
  --ord-lo: #86b6ef; --ord-hi: #0d366b;
  --shadow: 0 1px 2px rgba(20, 20, 18, .04), 0 4px 16px rgba(20, 20, 18, .05);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --border: #33332f; --grid: #2a2a27;
    --text: #f4f3ef; --text-2: #c3c2b7; --text-3: #8f8e86; --accent: #6da7ec; --accent-soft: #184f95;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
    --seq-lo: #1c2a3a; --seq-hi: #86b6ef;
    --ord-lo: #184f95; --ord-hi: #cde2fb;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --border: #33332f; --grid: #2a2a27;
  --text: #f4f3ef; --text-2: #c3c2b7; --text-3: #8f8e86; --accent: #6da7ec; --accent-soft: #184f95;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --seq-lo: #1c2a3a; --seq-hi: #86b6ef;
  --ord-lo: #184f95; --ord-hi: #cde2fb;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.55 "IBM Plex Sans", system-ui, -apple-system, sans-serif;
}
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
code, .mono { font-family: "IBM Plex Mono", ui-monospace, monospace; font-size: .9em; }

.top {
  border-bottom: 1px solid var(--border); background: var(--surface);
  position: sticky; top: 0; z-index: 10;
}
.top-inner { max-width: 1180px; margin: 0 auto; padding: 0 16px; display: flex; align-items: center; gap: 24px; min-height: 56px; }
.brand { font-weight: 600; letter-spacing: -.01em; color: var(--text); text-decoration: none; white-space: nowrap; display: flex; align-items: center; gap: 8px; }
.brand svg { flex: none; }
nav.pages { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; flex: 1; }
nav.pages::-webkit-scrollbar { display: none; }
nav.pages a { color: var(--text-2); text-decoration: none; padding: 6px 10px; border-radius: 6px; white-space: nowrap; font-size: 14px; }
nav.pages a:hover { background: var(--surface-2); color: var(--text); }
nav.pages a[aria-current="page"] { color: var(--text); background: var(--surface-2); font-weight: 500; }
.theme-btn { background: none; border: 1px solid var(--border); color: var(--text-2); border-radius: 6px; padding: 4px 8px; cursor: pointer; font: inherit; font-size: 13px; }

main { max-width: 1180px; margin: 0 auto; padding: 32px 16px 64px; }
h1 { font-size: clamp(26px, 4vw, 36px); line-height: 1.15; letter-spacing: -.02em; margin: 0 0 8px; font-weight: 600; }
h2 { font-size: 20px; letter-spacing: -.01em; margin: 0 0 4px; font-weight: 600; }
h3 { font-size: 15px; margin: 18px 0 6px; font-weight: 600; }
.lede { color: var(--text-2); font-size: 17px; max-width: 760px; margin: 0 0 28px; }
.asof { color: var(--text-3); font-size: 13px; margin-bottom: 20px; }
.note { color: var(--text-3); font-size: 13px; margin: 6px 0 0; }
p { max-width: 780px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin: 0 0 28px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .v { font-size: 28px; font-weight: 600; letter-spacing: -.02em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--text-2); font-size: 13px; margin-top: 4px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 20px; box-shadow: var(--shadow); margin-bottom: 20px; min-width: 0; }
.card > .sub { color: var(--text-2); font-size: 14px; margin: 0 0 14px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 460px), 1fr)); gap: 20px; }
.chart { width: 100%; overflow-x: auto; overflow-y: hidden; }
.chart svg { max-width: 100%; height: auto; }

.controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.controls label { color: var(--text-2); font-size: 13px; }
select, input[type="search"] {
  font: inherit; font-size: 14px; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px; min-width: 0;
}
input[type="search"] { width: min(320px, 100%); }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 7px; overflow: hidden; }
.seg button { font: inherit; font-size: 13px; padding: 5px 12px; border: 0; background: var(--surface); color: var(--text-2); cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--text); color: var(--surface); }

.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; color: var(--text-2); margin: 0 0 10px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

.tbl-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 10px; }
table { border-collapse: collapse; width: 100%; font-size: 14px; background: var(--surface); }
th, td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-weight: 500; color: var(--text-2); font-size: 13px; background: var(--surface-2); position: sticky; top: 0; cursor: pointer; white-space: nowrap; user-select: none; }
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
.pill { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 99px; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.count { color: var(--text-3); font-size: 13px; }
details.table-view { margin-top: 10px; }
details.table-view summary { cursor: pointer; color: var(--text-2); font-size: 13px; }

.callout { border-left: 3px solid var(--accent); background: var(--surface); padding: 12px 16px; border-radius: 0 8px 8px 0; margin: 0 0 20px; max-width: 820px; }
.findings { padding-left: 20px; max-width: 820px; }
.findings li { margin-bottom: 8px; }
.prose h2 { margin-top: 32px; }
.prose ul { max-width: 780px; }
footer { border-top: 1px solid var(--border); color: var(--text-3); font-size: 13px; }
footer .inner { max-width: 1180px; margin: 0 auto; padding: 20px 16px 40px; display: flex; flex-wrap: wrap; gap: 8px 24px; }
footer a { color: var(--text-2); }

/* Observable Plot tooltip + axes pick up theme tokens */
figure { margin: 0; }
[aria-label="tip"] { fill: var(--surface); stroke: var(--border); }
@media (max-width: 640px) {
  .top-inner { gap: 12px; }
  .brand span { display: none; }
  main { padding-top: 22px; }
  .kpi .v { font-size: 24px; }
}
