/* Tokens. Light is the default; dark follows the system unless the toggle says otherwise. */
:root {
  color-scheme: light;
  --page: #eef1f4;
  --surface: #fbfcfd;
  --ink: #14233b;
  --ink-2: #47566b;
  --muted: #6f7c8c;
  --line: #dde3ea;
  --line-strong: #bfc9d4;
  --accent: #c8470a;
  --on-accent: #ffffff;
  --up: #2a78d6;
  --up-text: #1c5cab;
  --down: #d03b3b;
  --down-text: #b02a2a;
  --context: #a9b4c1;
  --shadow: 0 6px 24px rgba(20, 35, 59, 0.16);

  --font: "Archivo", system-ui, -apple-system, "Segoe UI", sans-serif;
  --wide: "wdth" 118;
  --narrow: "wdth" 86;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d131a;
    --surface: #151d27;
    --ink: #e8edf3;
    --ink-2: #b6c1cd;
    --muted: #8793a1;
    --line: #243140;
    --line-strong: #35465a;
    --accent: #ff8a3d;
    --on-accent: #1d1206;
    --up: #3987e5;
    --up-text: #7fb2f0;
    --down: #e66767;
    --down-text: #f09a9a;
    --context: #4a5a6d;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d131a;
  --surface: #151d27;
  --ink: #e8edf3;
  --ink-2: #b6c1cd;
  --muted: #8793a1;
  --line: #243140;
  --line-strong: #35465a;
  --accent: #ff8a3d;
  --on-accent: #1d1206;
  --up: #3987e5;
  --up-text: #7fb2f0;
  --down: #e66767;
  --down-text: #f09a9a;
  --context: #4a5a6d;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
}

a { color: inherit; text-decoration-color: var(--line-strong); text-underline-offset: 3px; }
a:hover { text-decoration-color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 2px; }

.skip { position: absolute; left: -999px; }
.skip:focus { left: 16px; top: 8px; background: var(--surface); padding: 6px 10px; z-index: 10; }

/* ---------- frame ---------- */

.masthead, main, .footer { max-width: 1240px; margin: 0 auto; padding-left: 24px; padding-right: 24px; }

.masthead {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px 28px;
  padding-top: 18px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--ink);
}

.brand { display: flex; align-items: baseline; gap: 8px; text-decoration: none; }
.brand-mark {
  width: 14px; height: 14px; border-radius: 50%; align-self: center;
  background: linear-gradient(var(--page), var(--page)) center / 100% 1.5px no-repeat, var(--accent);
}
.brand-name { font-variation-settings: var(--wide); font-weight: 800; font-size: 18px; letter-spacing: -0.01em; }
.brand-sub { color: var(--ink-2); font-size: 14px; }

.nav { display: flex; flex-wrap: wrap; gap: 4px 20px; flex: 1; }
.nav a { text-decoration: none; font-weight: 600; color: var(--ink-2); padding: 4px 0; border-bottom: 3px solid transparent; }
.nav a:hover { color: var(--ink); }
.nav a[aria-current] { color: var(--ink); border-bottom-color: var(--accent); }

.theme-toggle, select, input[type="search"] {
  font: inherit; font-size: 14px; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: 6px; padding: 5px 10px;
}
.theme-toggle { cursor: pointer; }

main { padding-top: 28px; padding-bottom: 56px; min-height: 60vh; outline: none; }
main.busy { opacity: 0.55; }

.footer { padding-top: 16px; padding-bottom: 40px; border-top: 1px solid var(--line-strong); color: var(--ink-2); font-size: 13px; }
.footer p { margin: 0 0 4px; max-width: 76ch; }

.loading, .empty { color: var(--ink-2); }

/* ---------- headings and text ---------- */

h1 {
  font-variation-settings: var(--wide); font-weight: 800; font-size: clamp(1.8rem, 1.2rem + 2.4vw, 3rem);
  line-height: 1.05; letter-spacing: -0.02em; margin: 0 0 8px;
}
h1.with-logos { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
h2 { font-variation-settings: var(--wide); font-weight: 750; font-size: 1.35rem; line-height: 1.2; letter-spacing: -0.01em; margin: 0 0 6px; }
h3 { font-size: 0.93rem; font-weight: 700; margin: 0 0 6px; }

.intro { color: var(--ink-2); max-width: 74ch; margin: 0 0 12px; }
.crumb { margin: 0 0 10px; font-size: 14px; color: var(--ink-2); }
.count { color: var(--ink-2); margin: 0 0 6px; font-size: 14px; }

.view-head { display: flex; justify-content: space-between; align-items: flex-end; flex-wrap: wrap; gap: 12px 24px; margin-bottom: 10px; }
.block { margin-top: 44px; }
.method { margin: 18px 0 8px; padding: 14px 18px; border-left: 3px solid var(--accent); background: var(--surface); max-width: 86ch; }
.method h2 { font-size: 1rem; }
.method p { margin: 0; color: var(--ink-2); }

.picker { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--ink-2); }
.filters { display: flex; flex-wrap: wrap; gap: 10px 20px; margin: 6px 0 14px; }

.tag { font-size: 12px; color: var(--ink-2); border: 1px solid var(--line-strong); border-radius: 10px; padding: 0 7px; white-space: nowrap; }
.dim { color: var(--muted); }

/* ---------- week ribbon ---------- */

.ribbon { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0 22px; }
.ribbon a {
  min-width: 36px; text-align: center; padding: 4px 8px; text-decoration: none; font-weight: 600; font-size: 14px;
  font-variant-numeric: tabular-nums; color: var(--ink-2); background: var(--surface); border: 1px solid var(--line); border-radius: 4px;
}
.ribbon a:hover { border-color: var(--ink-2); color: var(--ink); }
.ribbon a[aria-current] { background: var(--ink); border-color: var(--ink); color: var(--surface); }

/* ---------- tables ---------- */

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
table.data { width: 100%; border-collapse: collapse; }
table.data caption { text-align: left; padding: 10px 12px; color: var(--ink-2); }
table.data th, table.data td { padding: 7px 12px; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--line); }
table.data tbody tr:last-child td, table.data tbody tr:last-child th { border-bottom: 0; }
table.data thead th { font-size: 13px; font-weight: 600; color: var(--ink-2); border-bottom-color: var(--line-strong); white-space: nowrap; vertical-align: bottom; }
table.data tbody th { font-weight: 500; }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tbody tr:hover { background: color-mix(in srgb, var(--ink) 4%, transparent); }
table.compact th, table.compact td { padding: 4px 10px; font-size: 13px; }

table.data thead th button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
table.data thead th button:hover { color: var(--ink); }
table.data thead th[aria-sort="ascending"] button::after { content: " \25B4"; color: var(--accent); }
table.data thead th[aria-sort="descending"] button::after { content: " \25BE"; color: var(--accent); }
table.data thead th[aria-sort="ascending"], table.data thead th[aria-sort="descending"] { color: var(--ink); }

td.rank, th.rank { width: 1%; text-align: right; }
td.rank { font-variation-settings: var(--wide); font-weight: 800; font-size: 21px; line-height: 1; font-variant-numeric: tabular-nums; }
table.ballot td.rank { font-size: 17px; }
.firsts { color: var(--ink-2); }

.team { display: inline-flex; align-items: center; gap: 9px; min-width: 0; }
.team a { text-decoration: none; }
.team a:hover { text-decoration: underline; text-decoration-color: var(--accent); }
.team-name { font-variation-settings: var(--narrow); font-weight: 650; font-size: 1.04em; white-space: nowrap; }
.logo { flex: none; object-fit: contain; }
.logo-none {
  display: inline-flex; align-items: center; justify-content: center; border-radius: 50%;
  background: var(--line); color: var(--ink-2); font-size: 11px; font-weight: 700;
}

.move { font-variant-numeric: tabular-nums; font-weight: 650; font-size: 13px; white-space: nowrap; }
.move-up { color: var(--up-text); }
.move-down { color: var(--down-text); }
.move-flat { color: var(--muted); }
.move-new { color: var(--ink-2); font-weight: 600; border: 1px solid var(--line-strong); border-radius: 3px; padding: 0 4px; font-size: 12px; }

/* ---------- the poll and its spread strips ---------- */

.split { display: grid; grid-template-columns: minmax(0, 1fr) 290px; gap: 28px; align-items: start; }
.others { margin: 14px 2px 0; color: var(--ink-2); font-size: 14px; max-width: 90ch; }
.others strong { color: var(--ink); }
.notice { margin: 0 0 14px; padding: 8px 12px; border-left: 3px solid var(--line-strong); background: var(--surface); color: var(--ink-2); font-size: 14px; max-width: 90ch; }

table.poll td { padding-top: 5px; padding-bottom: 5px; }
.strip-cell { width: 1%; padding-right: 4px; }
th.strip-cell { padding-bottom: 2px; }
.strip-title { display: block; }
.strip, .strip-axis { display: block; }
.strip { cursor: crosshair; }
.strip-base { stroke: var(--line-strong); stroke-width: 1; }
.strip-bar { fill: var(--ink); }
.strip-out { fill: var(--context); }
.strip-mark { fill: var(--accent); }
.strip-axis text { font-size: 9.5px; fill: var(--muted); font-family: var(--font); font-variant-numeric: tabular-nums; }

.side { display: grid; gap: 22px; }
.mini h3 { padding-bottom: 5px; border-bottom: 2px solid var(--ink); }
.mini ol { list-style: none; margin: 0; padding: 0; }
.mini li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 5px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.mini li:last-child { border-bottom: 0; }
.mini p { margin: 4px 0; font-size: 14px; color: var(--ink-2); }
.mini p strong { color: var(--ink); }
.mini-value { font-variant-numeric: tabular-nums; color: var(--ink-2); text-align: right; font-size: 13px; }
.bars li { display: grid; grid-template-columns: minmax(0, 1fr) 70px 26px; }
.bars-name { font-variation-settings: var(--narrow); font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.size { display: block; height: 8px; min-width: 60px; }
.size-fill { display: block; height: 100%; background: var(--ink-2); border-radius: 0 3px 3px 0; min-width: 1px; }

.lean { position: relative; display: block; height: 10px; min-width: 110px; }
.lean::before { content: ""; position: absolute; left: 50%; top: -3px; bottom: -3px; width: 1px; background: var(--line-strong); }
.lean-fill { position: absolute; top: 0; bottom: 0; min-width: 1px; }
.lean-up { background: var(--up); border-radius: 0 3px 3px 0; }
.lean-down { background: var(--down); border-radius: 3px 0 0 3px; }
.lean-cell { width: 150px; }
.lean-axis { display: flex; justify-content: space-between; font-weight: 500; color: var(--muted); font-size: 12px; }
.why { color: var(--ink-2); font-size: 14px; min-width: 200px; max-width: 520px; }
.quote { margin: 0 0 18px; padding: 10px 16px; border-left: 3px solid var(--accent); background: var(--surface); max-width: 86ch; white-space: pre-line; }

.trio { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 22px 32px; margin-top: 22px; }

.chips { list-style: none; margin: 0 0 20px; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 6px; }
.chip { display: flex; align-items: center; gap: 8px; padding: 5px 9px; text-decoration: none; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; font-size: 14px; }
.chip:hover { border-color: var(--ink-2); }
.chip-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip-gap { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; }

/* ---------- stat rows ---------- */

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 18px 28px; margin: 18px 0 26px; }
.stat { border-top: 2px solid var(--ink); padding-top: 8px; }
.stat-label { font-size: 13.5px; color: var(--ink-2); }
.stat-value { font-variation-settings: var(--wide); font-weight: 800; font-size: 2.1rem; line-height: 1.15; letter-spacing: -0.02em; }
.stat-note { font-size: 13px; color: var(--muted); }

/* ---------- charts ---------- */

.figure { margin: 10px 0 0; }
.scroll-x { overflow-x: auto; }
.grid { stroke: var(--line); stroke-width: 1; }
.axis { font-size: 11.5px; fill: var(--muted); font-family: var(--font); font-variant-numeric: tabular-nums; }

.legend, .bump-legend { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 18px; margin: 0 0 6px; font-size: 14px; color: var(--ink-2); min-height: 22px; }
.legend-item { display: inline-flex; align-items: center; gap: 7px; }
.key { display: inline-block; width: 16px; height: 0; border-top: 3px solid var(--context); border-radius: 2px; flex: none; }
.key-accent { border-top-color: var(--accent); }

.bump { display: block; min-width: 860px; width: 100%; height: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.bump-week text { font-size: 12px; font-weight: 600; fill: var(--ink-2); font-family: var(--font); }
.bump-week:hover text { fill: var(--accent); }
.bump-line { fill: none; stroke: var(--context); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.bump-lone { fill: var(--context); }
.bump-hit { fill: none; stroke: transparent; pointer-events: stroke; cursor: pointer; }
.bump-name { font-size: 12.5px; font-family: var(--font); font-variation-settings: var(--narrow); font-weight: 550; fill: var(--ink-2); cursor: pointer; white-space: pre; font-variant-numeric: tabular-nums; }
.bump.has-hot .bump-team:not(.hot) .bump-line { opacity: 0.4; }
.bump-team.hot .bump-line { stroke: var(--accent); stroke-width: 3; }
.bump-team.hot .bump-lone { fill: var(--accent); }
.bump-team.hot .bump-name { fill: var(--ink); font-weight: 800; }
.bump-dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; pointer-events: none; }
.bump-rank { font-size: 10px; font-weight: 800; fill: var(--on-accent); font-family: var(--font); pointer-events: none; }

.line-chart { display: block; width: 100%; max-width: 860px; height: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.series { fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.series.tone-accent { stroke: var(--accent); }
.series.tone-context { stroke: var(--context); stroke-width: 1.5; }
.series-dot.tone-accent, .series-end { fill: var(--accent); }
.series-dot.tone-context { fill: var(--context); }
.series-end { stroke: var(--surface); stroke-width: 2; }
.hair { stroke: var(--ink-2); stroke-width: 1; }

.numbers { margin-top: 8px; max-width: 860px; }
.numbers summary { cursor: pointer; color: var(--ink-2); font-size: 14px; }
.numbers .table-wrap { margin-top: 8px; max-height: 320px; overflow: auto; }

.multiples { display: grid; grid-template-columns: repeat(auto-fill, minmax(440px, 1fr)); gap: 18px 24px; }
.small-multiple h3 { margin-bottom: 2px; }

.heat { background: color-mix(in srgb, var(--up) calc(var(--heat, 0) * 46%), transparent); min-width: 34px; }
table.grid-table th, table.grid-table td { padding: 4px 8px; }
table.grid-table tbody th { position: sticky; left: 0; background: var(--surface); }

/* ---------- tooltip ---------- */

.tip {
  position: fixed; z-index: 20; pointer-events: none; max-width: 280px; padding: 8px 10px; font-size: 13px; line-height: 1.35;
  background: var(--surface); color: var(--ink); border: 1px solid var(--line-strong); border-radius: 6px; box-shadow: var(--shadow);
}
.tip[hidden] { display: none; }
.tip-row { display: flex; align-items: center; gap: 7px; }
.tip-row strong { font-variant-numeric: tabular-nums; }
.tip-row span:last-child { color: var(--ink-2); }
.tip-note { color: var(--muted); font-size: 12px; }

/* ---------- narrow screens ---------- */

@media (max-width: 980px) {
  .split { grid-template-columns: minmax(0, 1fr); }
  .side { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
}

@media (max-width: 640px) {
  .masthead, main, .footer { padding-left: 16px; padding-right: 16px; }
  table.data th, table.data td { padding: 6px 8px; }
  .stat-value { font-size: 1.7rem; }
}

@media (prefers-reduced-motion: no-preference) {
  .bump-line { transition: opacity 120ms ease, stroke 120ms ease; }
}
