:root {
  color-scheme: light;
  --page: #f6f5f1;
  --surface: #fcfcfb;
  --surface-2: #f1f0eb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e6e5df;
  --axis: #c3c2b7;
  --ring: rgba(11, 11, 11, 0.09);
  --shadow: 0 1px 2px rgba(20, 20, 10, 0.04), 0 8px 24px -12px rgba(20, 20, 10, 0.12);

  /* party ramps: deep / mid / light; neutral midpoint for toss-ups */
  --d-solid: #2a78d6; --r-solid: #e34948; --i-solid: #1baf7a;
  --d-deep: #184f95; --d-mid: #2a78d6; --d-light: #9ec5f4; --d-wash: rgba(42, 120, 214, 0.08);
  --r-deep: #a8282a; --r-mid: #e34948; --r-light: #f4aaa6; --r-wash: rgba(227, 73, 72, 0.08);
  --i-deep: #0d7a52; --i-mid: #1baf7a; --i-light: #96dcc1;
  --neutral: #dcdad2;
  --none: #ebeae4;

  --s1: #6250d6; /* Senate line */
  --s2: #eb6834; /* House line */
  --s3: #1baf7a; /* Governors line */
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0f0f0e;
    --surface: #1a1a19;
    --surface-2: #232321;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #8f8d86;
    --grid: #2c2c2a;
    --axis: #45453f;
    --ring: rgba(255, 255, 255, 0.09);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px -12px rgba(0, 0, 0, 0.6);
    --d-solid: #3987e5; --r-solid: #e66767; --i-solid: #199e70;
    --d-deep: #4a97f2; --d-mid: #2f6dbd; --d-light: #223f66; --d-wash: rgba(57, 135, 229, 0.12);
    --r-deep: #f2595a; --r-mid: #b8403f; --r-light: #66302e; --r-wash: rgba(230, 103, 103, 0.12);
    --i-deep: #2cc98f; --i-mid: #188a62; --i-light: #1a4d3b;
    --neutral: #45443f;
    --none: #262624;
    --s1: #9085e9; --s2: #d95926; --s3: #199e70;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0f0f0e;
  --surface: #1a1a19;
  --surface-2: #232321;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --muted: #8f8d86;
  --grid: #2c2c2a;
  --axis: #45453f;
  --ring: rgba(255, 255, 255, 0.09);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px -12px rgba(0, 0, 0, 0.6);
  --d-solid: #3987e5; --r-solid: #e66767; --i-solid: #199e70;
  --d-deep: #4a97f2; --d-mid: #2f6dbd; --d-light: #223f66; --d-wash: rgba(57, 135, 229, 0.12);
  --r-deep: #f2595a; --r-mid: #b8403f; --r-light: #66302e; --r-wash: rgba(230, 103, 103, 0.12);
  --i-deep: #2cc98f; --i-mid: #188a62; --i-light: #1a4d3b;
  --neutral: #45443f;
  --none: #262624;
  --s1: #9085e9; --s2: #d95926; --s3: #199e70;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.wrap { max-width: 1240px; margin: 0 auto; padding: 0 20px; }
@media (max-width: 600px) { .wrap { padding: 0 16px; } }
h2 { font-size: 17px; font-weight: 650; margin: 0; letter-spacing: -0.01em; }
h3 { font-size: 14px; font-weight: 650; margin: 0 0 4px; }
.sub { margin: 2px 0 0; color: var(--ink-2); font-size: 13.5px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.num { font-variant-numeric: tabular-nums; }
button { font: inherit; color: inherit; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--page) 86%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--ring);
}
.topbar-inner { display: flex; align-items: center; justify-content: space-between; height: 60px; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 30px; height: 30px; }
.brand-title { font-weight: 700; letter-spacing: -0.01em; }
.brand-sub { font-size: 12.5px; color: var(--ink-2); margin-top: -2px; }
.status { display: flex; align-items: center; gap: 12px; font-size: 13px; }
.pill {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 4px 10px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--ring);
  font-weight: 600; font-size: 12px; letter-spacing: 0.04em; text-transform: uppercase;
}
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.pill.live .dot { background: #d03b3b; animation: pulse 1.6s ease-out infinite; }
.pill.sim .dot { background: #eda100; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(208, 59, 59, 0.5); } 100% { box-shadow: 0 0 0 7px rgba(208, 59, 59, 0); } }
.viewers { display: inline-flex; align-items: center; gap: 5px; color: var(--ink-2); white-space: nowrap; }
.viewers strong { color: var(--ink); font-weight: 650; display: inline-block; transition: transform 250ms ease; }
.viewers strong.bump { transform: scale(1.25); }
@media (max-width: 420px) { .viewers-label { display: none; } }
.icon-btn {
  border: 1px solid var(--ring); background: var(--surface); border-radius: 8px;
  width: 32px; height: 32px; display: grid; place-items: center; cursor: pointer; color: var(--ink-2);
}
.icon-btn:hover { color: var(--ink); }
@media (max-width: 600px) { .brand-sub, #clock { display: none; } }

.simbar { background: color-mix(in srgb, #eda100 14%, var(--page)); border-bottom: 1px solid var(--ring); font-size: 13px; }
.simbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 8px; padding-bottom: 8px; flex-wrap: wrap; }
.sim-controls { display: flex; align-items: center; gap: 10px; }
.sim-controls select { font: inherit; padding: 3px 6px; border-radius: 6px; border: 1px solid var(--ring); background: var(--surface); color: var(--ink); }
.btn {
  border: 1px solid var(--ring); background: var(--surface); color: var(--ink);
  border-radius: 8px; padding: 5px 12px; cursor: pointer; font-weight: 550; font-size: 13px;
}
.btn:hover { background: var(--surface-2); }
.btn.ghost { background: transparent; }

.error { margin: 16px 0 0; padding: 10px 14px; border-radius: 10px; background: var(--r-wash); color: var(--ink); font-size: 13.5px; }

/* cards */
main { padding-top: 20px; padding-bottom: 60px; display: grid; gap: 16px; }
.card {
  background: var(--surface); border: 1px solid var(--ring); border-radius: 16px;
  box-shadow: var(--shadow); padding: 20px 22px; min-width: 0;
}
@media (max-width: 600px) { .card { padding: 16px; border-radius: 14px; } }
.card-head { margin-bottom: 14px; }
.card-head.row { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; }
.chambers { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 900px) { .grid-2, .chambers { grid-template-columns: 1fr; } }

/* chamber card */
.chamber { padding-bottom: 14px; }
.ch-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.ch-title { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; margin: 0; }
.ch-rule { font-size: 12.5px; color: var(--muted); }
.ch-body { display: grid; grid-template-columns: 220px 1fr; gap: 18px; align-items: center; margin-top: 8px; }
@media (max-width: 1100px) and (min-width: 901px), (max-width: 520px) { .ch-body { grid-template-columns: 1fr; } }
.dial { width: 100%; max-width: 240px; margin: 0 auto; display: block; }
.dial .needle { transition: transform 900ms cubic-bezier(.3, 1.3, .5, 1); transform-origin: 120px 120px; }
.headline { font-size: 15px; color: var(--ink-2); line-height: 1.35; }
.headline .big { display: block; font-size: 52px; line-height: 1.02; font-weight: 700; letter-spacing: -0.03em; color: var(--ink); margin-bottom: 2px; }
.headline .party-word { font-weight: 650; color: var(--ink); }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; vertical-align: baseline; margin-right: 6px; }
.split { display: flex; height: 10px; border-radius: 6px; overflow: hidden; gap: 2px; margin: 14px 0 6px; background: var(--surface); }
.split > span { transition: flex-grow 700ms ease; min-width: 2px; }
.split-labels { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--ink-2); }
.split-labels strong { color: var(--ink); font-variant-numeric: tabular-nums; }
.seats { margin-top: 14px; border-top: 1px solid var(--grid); padding-top: 12px; }
.seats-row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 13.5px; color: var(--ink-2); flex-wrap: wrap; }
.seats-row b { color: var(--ink); font-size: 18px; font-variant-numeric: tabular-nums; }
.hist { width: 100%; height: 92px; display: block; margin-top: 6px; }

/* timeline */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12.5px; color: var(--ink-2); margin-top: 8px; }
.legend .key { display: inline-block; width: 16px; height: 2px; border-radius: 2px; vertical-align: middle; margin-right: 6px; }

/* stat tiles */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile { background: var(--surface-2); border-radius: 12px; padding: 12px 14px; min-width: 0; }
.tile-label { font-size: 12.5px; color: var(--ink-2); }
.tile-value { font-size: 24px; font-weight: 650; letter-spacing: -0.02em; margin-top: 2px; }
.tile-note { font-size: 12px; color: var(--muted); margin-top: 1px; }
.meter { height: 6px; border-radius: 4px; background: var(--grid); margin-top: 8px; overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--ink-2); border-radius: 4px; transition: width 700ms ease; }
#gov-summary { margin-top: 12px; }
.gov { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: var(--surface-2); border-radius: 12px; padding: 12px 14px; }
.gov .tile-value { font-size: 20px; }

/* tile map */
.map-layout { display: grid; grid-template-columns: 1fr 170px; gap: 18px; align-items: start; }
@media (max-width: 700px) { .map-layout { grid-template-columns: 1fr; } }
.tilemap svg { width: 100%; height: auto; display: block; }
.tilemap .st { cursor: pointer; }
.tilemap .st rect { transition: fill 600ms ease; }
.tilemap .st:hover rect, .tilemap .st:focus rect { stroke: var(--ink); stroke-width: 2; }
.tilemap .st:focus { outline: none; }
.legend-col { font-size: 12.5px; color: var(--ink-2); display: grid; gap: 6px; }
.legend-col .lg-row { display: flex; align-items: center; gap: 8px; }
.legend-col .lg-sw { width: 18px; height: 14px; border-radius: 4px; flex: none; }
.legend-col .lg-title { font-weight: 600; color: var(--ink); margin-bottom: 2px; }

/* hemicycle */
.hemi { position: relative; }
.hemi svg { width: 100%; max-width: 860px; margin: 0 auto; display: block; height: auto; }
.hemi circle { transition: fill 600ms ease; cursor: pointer; }
.hemi circle:hover { stroke: var(--ink); stroke-width: 1.5; }

/* table */
.table-controls { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 5px 11px; border-radius: 8px; cursor: pointer; font-size: 13px; color: var(--ink-2); font-weight: 550; }
.seg button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08), 0 0 0 1px var(--ring); }
#search { font: inherit; font-size: 13px; padding: 6px 10px; border-radius: 9px; border: 1px solid var(--ring); background: var(--surface); color: var(--ink); width: 210px; max-width: 100%; }
.table-wrap { overflow-x: auto; margin: 0 -6px; }
table.races { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 680px; }
table.races th { text-align: left; font-weight: 550; color: var(--muted); font-size: 12px; padding: 6px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
table.races td { padding: 9px 6px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
table.races tbody tr { cursor: pointer; }
table.races tbody tr:hover td { background: var(--surface-2); }
.race-name { font-weight: 600; }
.race-meta { font-size: 12px; color: var(--muted); }
.count-main { font-variant-numeric: tabular-nums; }
.chip { white-space: nowrap; display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 650; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); }
.chip.called { color: #fff; }
.col-proj { width: 34%; }
.col-prob { width: 24%; }
.mbar { width: 100%; height: 26px; display: block; }
.pbar { display: flex; height: 8px; border-radius: 5px; overflow: hidden; gap: 2px; }
.pbar > span { min-width: 2px; }
.plabel { display: flex; justify-content: space-between; font-size: 12px; margin-top: 3px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.plabel strong { color: var(--ink); }
.more { display: block; margin: 12px auto 0; }

/* method */
.method-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; margin: 12px 0; }
@media (max-width: 900px) { .method-grid { grid-template-columns: 1fr 1fr; } }
@media (max-width: 560px) { .method-grid { grid-template-columns: 1fr; } }
.method p { margin: 0; font-size: 13.5px; color: var(--ink-2); }

/* tooltip */
.tooltip {
  position: fixed; z-index: 50; pointer-events: none;
  background: var(--surface); color: var(--ink); border: 1px solid var(--ring);
  box-shadow: 0 8px 28px -8px rgba(0, 0, 0, 0.25); border-radius: 10px;
  padding: 9px 11px; font-size: 12.5px; max-width: 280px;
}
.tooltip .tt-title { font-weight: 650; margin-bottom: 4px; }
.tooltip .tt-row { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.tooltip .tt-row .k { color: var(--ink-2); display: flex; align-items: center; gap: 6px; }
.tooltip .tt-row .v { font-weight: 650; font-variant-numeric: tabular-nums; }
.tooltip .line-key { width: 12px; height: 2px; border-radius: 2px; display: inline-block; }

/* drawer */
.drawer { position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, 0.32); display: none; }
.drawer.open { display: block; }
.drawer-panel {
  overflow-x: hidden;
  position: absolute; right: 0; top: 0; bottom: 0; width: min(460px, 100%);
  background: var(--surface); border-left: 1px solid var(--ring); padding: 22px; overflow-y: auto;
  box-shadow: -20px 0 50px -20px rgba(0, 0, 0, 0.35);
}
.drawer-close { position: absolute; top: 14px; right: 14px; }
.dr-title { font-size: 22px; font-weight: 700; margin: 0 40px 2px 0; letter-spacing: -0.02em; }
.dr-section { margin-top: 18px; }
.dr-section h3 { color: var(--ink-2); font-weight: 600; font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.05em; }
.cand { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; margin-top: 10px; }
.cand-name { font-weight: 600; }
.cand-votes { text-align: right; font-variant-numeric: tabular-nums; color: var(--ink-2); font-size: 13px; }
.cand-bar { grid-column: 1 / -1; height: 8px; background: var(--grid); border-radius: 4px; overflow: hidden; }
.cand-bar > span { display: block; height: 100%; border-radius: 4px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 13.5px; margin-top: 8px; }
.kv dt { color: var(--ink-2); }
.kv dd { margin: 0; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }

@media (forced-colors: active) {
  .split > span, .pbar > span { forced-color-adjust: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
@media (max-width: 600px) {
  table.races { min-width: 0; }
  table.races th:nth-child(3), table.races td:nth-child(3) { display: none; }
  .col-prob { width: 38%; }
}
