/* Tokens: light palette on :root, dark palette for the OS setting and for an explicit data-theme. */
: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);
  --wash: rgba(11, 11, 11, 0.05);
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #6250d6;
  --series-8: #e34948;
  --series-other: #b4b2a9;
  --warning: #fab219;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface-1: #1a1a19;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --wash: rgba(255, 255, 255, 0.06);
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;
    --series-other: #5f5e5a;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface-1: #1a1a19;
  --text-primary: #f0efec;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --wash: rgba(255, 255, 255, 0.06);
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #9085e9;
  --series-8: #e66767;
  --series-other: #5f5e5a;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font: 15px/1.5 var(--font);
}

[hidden] { display: none !important; }

main, .page-header, footer {
  max-width: 1240px;
  margin-inline: auto;
  padding-inline: max(16px, env(safe-area-inset-left, 0px)) max(16px, env(safe-area-inset-right, 0px));
}

.page-header { padding-block: 40px 8px; }
.page-header h1 { margin: 0; font-size: clamp(1.6rem, 1.2rem + 1.6vw, 2.3rem); font-weight: 650; letter-spacing: -0.01em; }
.page-header p { margin: 6px 0 0; color: var(--text-secondary); max-width: 70ch; }
.page-header .updated { font-size: 0.85rem; color: var(--text-muted); }

a { color: inherit; text-underline-offset: 2px; }
code { font-size: 0.9em; }

/* KPI row */
.kpis {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-block: 24px 8px;
}
@media (min-width: 600px) { .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 980px) { .kpis { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
.tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  min-width: 0;
}
.tile.hero { grid-column: 1 / -1; display: flex; flex-direction: column; justify-content: center; }
@media (min-width: 980px) { .tile.hero { grid-column: span 2; grid-row: span 2; } }
.tile .label { color: var(--text-secondary); font-size: 0.85rem; }
.tile .value { font-size: 1.6rem; font-weight: 600; line-height: 1.25; margin-top: 2px; white-space: nowrap; }
.tile.hero .value { font-size: 3.4rem; line-height: 1.1; }
.tile .sub { color: var(--text-muted); font-size: 0.8rem; margin-top: 2px; }

/* Sections and cards */
section.block { margin-block: 36px; }
section.block > h2 { font-size: 1.25rem; font-weight: 600; margin: 0 0 4px; }
section.block { scroll-margin-top: 16px; }
.anchor { margin-left: 4px; color: var(--text-muted); font-weight: 400; text-decoration: none; opacity: 0; }
section.block > h2:hover .anchor, .anchor:focus-visible { opacity: 1; }
@media (hover: none) { .anchor { opacity: 0.6; } }
section.block > p.lede { margin: 0 0 14px; color: var(--text-secondary); max-width: 80ch; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 520px), 1fr));
  gap: 16px;
}

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 20px 14px;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.card.wide { grid-column: 1 / -1; }
.card-head { display: flex; align-items: flex-start; gap: 12px; }
.card-head .titles { flex: 1; min-width: 0; }
.card h3 { margin: 0; font-size: 1.05rem; font-weight: 600; }
.card .subtitle { margin: 2px 0 0; color: var(--text-secondary); font-size: 0.875rem; }

.toggle {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border-radius: 10px;
  background: var(--wash);
  flex: none;
}
.toggle button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  width: 32px;
  height: 28px;
  border-radius: 7px;
  display: grid;
  place-items: center;
  cursor: pointer;
}
.toggle button[aria-pressed="true"] { background: var(--surface-1); color: var(--text-primary); box-shadow: 0 0 0 1px var(--border); }
.toggle button:focus-visible { outline: 2px solid var(--series-1); outline-offset: 1px; }
.toggle svg { width: 18px; height: 18px; }

.plot { position: relative; height: 290px; margin-top: 14px; }
.plot canvas { display: block; }

.table-wrap { margin-top: 14px; max-height: 440px; overflow: auto; border-top: 1px solid var(--grid); }
.card.table-only .table-wrap { max-height: 520px; }
table { border-collapse: collapse; width: 100%; font-size: 0.85rem; }
th, td { padding: 6px 10px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--grid); }
th:first-child, td:first-child { text-align: left; }
td.text, th.text { text-align: left; }
thead th { position: sticky; top: 0; background: var(--surface-1); color: var(--text-secondary); font-weight: 600; }
td { font-variant-numeric: tabular-nums; }
tbody tr.group td { color: var(--text-muted); font-weight: 600; background: var(--wash); }

.legend {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 6px;
}
.legend button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: 0.85rem;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 3px 7px;
  border-radius: 6px;
  cursor: pointer;
}
.legend button:hover { background: var(--wash); }
.legend button:focus-visible { outline: 2px solid var(--series-1); }
.legend button[aria-pressed="false"] { opacity: 0.45; }
.key-line { width: 16px; height: 0; border-top: 2px solid; border-radius: 1px; }
.key-rect { width: 10px; height: 10px; border-radius: 2px; }
.key-blank { background: transparent; }

.note { margin: 8px 0 0; color: var(--text-muted); font-size: 0.8rem; }
.notice {
  border: 1px solid var(--border);
  border-left: 3px solid var(--warning);
  background: var(--surface-1);
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 14px;
  font-size: 0.9rem;
}

/* Tooltip */
.tip {
  position: absolute;
  z-index: 2;
  pointer-events: none;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  padding: 8px 10px;
  font-size: 0.8rem;
  min-width: 140px;
  max-width: 260px;
}
.tip-title { color: var(--text-muted); margin-bottom: 4px; }
.tip-row { display: flex; align-items: center; gap: 8px; line-height: 1.6; }
.tip-row strong { font-weight: 600; color: var(--text-primary); font-variant-numeric: tabular-nums; }
.tip-row span:last-child { color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tip .key-line { width: 12px; flex: none; }
.tip .key-rect { flex: none; }

/* Methodology */
.methodology { columns: 2 380px; column-gap: 40px; color: var(--text-secondary); font-size: 0.9rem; }
.methodology h3 { color: var(--text-primary); font-size: 0.95rem; margin: 0 0 4px; break-after: avoid; }
.methodology > div { break-inside: avoid; margin-bottom: 18px; }
.methodology p, .methodology ul { margin: 0 0 6px; }
.methodology ul { padding-left: 18px; }

footer { padding-block: 8px 48px; color: var(--text-muted); font-size: 0.8rem; }

.error { padding: 24px; color: var(--text-secondary); }

@media (max-width: 560px) {
  .card { padding: 14px 14px 10px; }
  .plot { height: 250px; }
  .tile.hero .value { font-size: 2.4rem; }
}

@media (forced-colors: active) {
  .toggle button[aria-pressed="true"] { outline: 2px solid CanvasText; }
}
