:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f3f2ee;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #6f6d68;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --focus: #2a78d6;

  /* party scales, light -> dark: tilt / lean / likely / safe (same in both themes: darker = surer) */
  --d-1: #c4dbf8; --d-2: #86b6ef; --d-3: #3f86dc; --d-4: #184f95;
  --r-1: #f9d0cb; --r-2: #f19a92; --r-3: #dc5650; --r-4: #9c2523;
  --i-1: #e0dbf8; --i-2: #b6adf0; --i-3: #7e70e0; --i-4: #3f3194;
  --d-bar: #3f86dc; --r-bar: #dc5650; --i-bar: #7e70e0;
  --norace: #ecebe6;
  --d-ink: #1c5cab; --r-ink: #b02f2d; --i-ink: #4a3aa7;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.12);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232322;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #a3a197;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --focus: #3987e5;
    --norace: #262625;
    --d-ink: #79b1f2; --r-ink: #f08a84; --i-ink: #a99ff0;
    --shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232322;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #a3a197;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --focus: #3987e5;
  --norace: #262625;
  --d-ink: #79b1f2; --r-ink: #f08a84; --i-ink: #a99ff0;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
}
a { color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }

.site-header { border-bottom: 1px solid var(--border); background: var(--surface); }
.header-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; padding-top: 20px; padding-bottom: 14px; flex-wrap: wrap; }
h1 { margin: 0; font-size: 26px; line-height: 1.15; letter-spacing: -0.01em; }
h2 { margin: 0; font-size: 17px; line-height: 1.3; }
.sub { margin: 4px 0 0; color: var(--ink-2); font-size: 13px; }
.top-nav { display: flex; gap: 14px; flex-wrap: wrap; font-size: 14px; }
.top-nav a { color: var(--ink-2); text-decoration: none; }
.top-nav a:hover { color: var(--ink); text-decoration: underline; }

/* hero */
.hero { padding: 24px 0 8px; }
.hero-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.hero-stat { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; }
.hero-label { font-size: 13px; color: var(--ink-2); }
.hero-num { font-size: 40px; font-weight: 700; line-height: 1.1; margin-top: 2px; }
.hero-stat[data-party="D"] .hero-num { color: var(--d-ink); }
.hero-stat[data-party="R"] .hero-num { color: var(--r-ink); }
.hero-stat[data-party="I"] .hero-num { color: var(--i-ink); }
.hero-note { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.control-bar { display: flex; height: 14px; border-radius: 4px; overflow: hidden; margin-top: 14px; gap: 2px; background: var(--surface); }
.control-bar span { display: block; height: 100%; transition: width .35s ease; }
.hero-foot { margin: 8px 0 0; font-size: 13px; color: var(--ink-2); }

/* controls */
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 28px; padding: 14px 16px; margin: 16px 0; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }
.control { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.control-label { font-size: 13px; color: var(--ink-2); display: inline-flex; align-items: center; gap: 6px; }
.control-val { font-size: 13px; font-variant-numeric: tabular-nums; min-width: 3.5em; color: var(--ink); }
.info { width: 18px; height: 18px; border-radius: 50%; border: 1px solid var(--axis); background: none; color: var(--ink-2); font-size: 11px; line-height: 1; cursor: help; padding: 0; }
.seg { display: inline-flex; border: 1px solid var(--axis); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: none; color: var(--ink-2); padding: 6px 12px; font: inherit; font-size: 13px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--axis); }
.seg button[aria-checked="true"] { background: var(--ink); color: var(--surface); }
.seg.small button { padding: 4px 10px; }
input[type="range"] { width: 160px; accent-color: var(--ink); }
.reset { margin-left: auto; font: inherit; font-size: 13px; background: none; border: 1px solid var(--axis); color: var(--ink-2); border-radius: 8px; padding: 6px 12px; cursor: pointer; }
.reset:hover { color: var(--ink); }

/* cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 16px; margin: 16px 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.card-sub { font-size: 13px; color: var(--ink-2); }
.card-intro { font-size: 13px; color: var(--ink-2); margin: 0 0 10px; max-width: 80ch; }
.hint { font-size: 12.5px; color: var(--muted); margin: 8px 0 0; }
.check { font-size: 13px; color: var(--ink-2); display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }
select { font: inherit; font-size: 13px; padding: 5px 8px; border-radius: 8px; border: 1px solid var(--axis); background: var(--surface); color: var(--ink); max-width: 100%; }

/* map */
.map-wrap { width: 100%; }
#map { width: 100%; height: auto; display: block; }
#map .state { stroke: var(--surface); stroke-width: 1; cursor: default; transition: fill .3s; }
#map .state.race { cursor: pointer; }
#map .state.race:hover, #map .state.race.hl { stroke: var(--ink); stroke-width: 2; }
#map .tile rect { stroke: var(--surface); stroke-width: 2; transition: fill .3s; }
#map .tile.race { cursor: pointer; }
#map .tile.race:hover rect, #map .tile.race.hl rect { stroke: var(--ink); }
#map text { pointer-events: none; font-size: 12px; font-weight: 600; text-anchor: middle; dominant-baseline: central; }
#map .lbl-dark { fill: #0b0b0b; }
#map .lbl-light { fill: #ffffff; }
#map .lbl-muted { fill: var(--muted); font-weight: 500; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12.5px; color: var(--ink-2); margin-top: 8px; align-items: center; }
.legend .sw { display: inline-block; width: 14px; height: 14px; border-radius: 3px; vertical-align: -2px; margin-right: 5px; }
.legend .grp { display: inline-flex; gap: 2px; align-items: center; margin-right: 4px; }
.legend .grp .sw { margin-right: 0; }

/* tooltip */
.tooltip { position: fixed; z-index: 30; pointer-events: none; background: var(--surface); color: var(--ink); border: 1px solid var(--border); box-shadow: var(--shadow); border-radius: 10px; padding: 12px 14px; width: 300px; max-width: calc(100vw - 24px); font-size: 13px; }
.tt-title { font-weight: 700; font-size: 15px; display: flex; justify-content: space-between; gap: 8px; }
.tt-rating { font-weight: 600; font-size: 12px; }
.tt-cands { margin: 8px 0 6px; display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; }
.tt-cands .pct { font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
.tt-bar { display: flex; height: 8px; border-radius: 3px; overflow: hidden; gap: 2px; margin: 4px 0 8px; }
.tt-row { display: flex; justify-content: space-between; gap: 10px; color: var(--ink-2); font-size: 12.5px; }
.tt-row b { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.tt-news { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border); color: var(--ink-2); font-size: 12px; }
.tt-foot { margin-top: 6px; color: var(--muted); font-size: 11.5px; }

/* tables */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
th { text-align: left; font-weight: 600; font-size: 12px; color: var(--ink-2); padding: 6px 8px; border-bottom: 1px solid var(--axis); white-space: nowrap; }
td { padding: 7px 8px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.race-table tbody tr { cursor: pointer; }
.race-table tbody tr:hover { background: var(--surface-2); }
.race-table td:first-child { font-weight: 600; white-space: nowrap; }
.matchup { white-space: nowrap; }
.matchup .vs { color: var(--muted); margin: 0 4px; }
.w-bar { min-width: 170px; }
.pbar { display: flex; height: 18px; border-radius: 4px; overflow: hidden; gap: 2px; position: relative; min-width: 150px; }
.pbar span { display: flex; align-items: center; font-size: 11.5px; font-weight: 700; padding: 0 5px; white-space: nowrap; overflow: hidden; }
.pbar .l { justify-content: flex-start; }
.pbar .r { justify-content: flex-end; }
.pill { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 1px 7px; border-radius: 10px; white-space: nowrap; border: 1px solid currentColor; }
.d-ink { color: var(--d-ink); } .r-ink { color: var(--r-ink); } .i-ink { color: var(--i-ink); } .t-ink { color: var(--ink-2); }
.latest-table tbody tr { cursor: pointer; }
.latest-table tbody tr:hover { background: var(--surface-2); }
.latest-table td { white-space: nowrap; }
.new-badge { font-size: 10.5px; font-weight: 700; color: var(--surface); background: var(--ink); border-radius: 4px; padding: 1px 5px; margin-left: 6px; }
.pollster-table th[data-k] { cursor: pointer; user-select: none; }
.pollster-table th[aria-sort="ascending"]::after { content: " ▲"; font-size: 9px; }
.pollster-table th[aria-sort="descending"]::after { content: " ▼"; font-size: 9px; }
.grade { font-weight: 700; }

/* charts */
.chart { width: 100%; position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .axis-line { stroke: var(--axis); }
.chart .tick-label { fill: var(--muted); font-size: 11px; }
.chart .annot { fill: var(--ink-2); font-size: 11.5px; }

/* dialog */
dialog { border: 0; padding: 0; border-radius: 12px; background: var(--surface); color: var(--ink); box-shadow: var(--shadow); width: min(920px, calc(100vw - 24px)); max-height: calc(100vh - 32px); }
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
.detail-inner { padding: 20px; position: relative; }
.close { position: absolute; top: 10px; right: 12px; width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--axis); background: var(--surface); color: var(--ink); font-size: 20px; line-height: 1; cursor: pointer; }
.d-head { padding-right: 40px; }
.d-head h2 { font-size: 22px; }
.d-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 14px; }
.d-box { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.d-box h3 { margin: 0 0 8px; font-size: 14px; }
.steps { width: 100%; font-size: 13px; }
.steps td { padding: 5px 6px; }
.steps td:last-child { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.steps tr.total td { border-top: 1px solid var(--axis); font-weight: 700; }
.steps .why { display: block; color: var(--muted); font-size: 11.5px; font-weight: 400; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 12px; border: 1px solid var(--border); border-radius: 8px; padding: 3px 8px; background: var(--surface-2); }
.chip b { font-weight: 600; }
.news-list { list-style: none; padding: 0; margin: 0; }
.news-list li { padding: 6px 0; border-bottom: 1px solid var(--grid); font-size: 13px; }
.news-list .src { color: var(--muted); font-size: 11.5px; display: block; }
.polls-table td, .polls-table th { padding: 5px 6px; font-size: 12.5px; }
.tag { font-size: 10.5px; color: var(--muted); border: 1px solid var(--axis); border-radius: 4px; padding: 0 3px; margin-left: 4px; }
.wbar { display: inline-block; height: 8px; background: var(--ink-2); border-radius: 2px; vertical-align: middle; margin-right: 6px; opacity: .7; }

.method { font-size: 14px; }
.method h3 { font-size: 15px; margin: 18px 0 6px; }
.method p, .method li { color: var(--ink-2); max-width: 82ch; }
.method .stat-row { display: flex; flex-wrap: wrap; gap: 10px; margin: 10px 0; }
.method .stat { border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; min-width: 140px; }
.method .stat .v { font-size: 20px; font-weight: 700; color: var(--ink); }
.method .stat .k { font-size: 12px; color: var(--muted); }

.site-footer { font-size: 12px; color: var(--muted); padding-top: 8px; padding-bottom: 32px; }

@media (max-width: 720px) {
  h1 { font-size: 22px; }
  .hero-grid { grid-template-columns: 1fr; }
  .hero-stat { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
  .hero-num { font-size: 30px; }
  .hero-note { width: 100%; }
  .reset { margin-left: 0; }
  .d-grid { grid-template-columns: 1fr; }
  input[type="range"] { width: 130px; }
  .detail-inner { padding: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}
