/* Tokens copied from votepredictor.com (its :root and [data-theme=dark] blocks), so the
   names line up with the site's Tailwind/shadcn theme when this is ported in. */
:root {
  --bg: #f6f6f8;
  --surface: #fff;
  --surface-2: #fafafb;
  --line: #e5e5ea;
  --line-2: #d4d4dc;
  --ink: #17181c;
  --ink-2: #5c5e68;
  --ink-3: #6e707b;
  --dem: #2f6aa6;
  --rep: #b0483d;
  --dem-soft: #e9f0f7;
  --rep-soft: #f9edeb;
  --track: #e9e9ee;
  --radius: 0.625rem;
  --map-none: #ececf0;
  --map-stroke: #ffffff;
  --shadow: 0 8px 28px rgba(23, 24, 28, 0.12);
  --font-sans: "Instrument Sans", ui-sans-serif, system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1014; --surface: #171920; --surface-2: #1c1f27; --line: #2a2d36; --line-2: #3a3e49;
    --ink: #eceef3; --ink-2: #a0a4b0; --ink-3: #828691; --dem: #6098d0; --rep: #d47b6f;
    --dem-soft: #16242f; --rep-soft: #2b1e1c; --track: #262931; --map-none: #23262e; --map-stroke: #0f1014;
    --shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
  }
}
.dark, :root[data-theme="dark"] {
  --bg: #0f1014; --surface: #171920; --surface-2: #1c1f27; --line: #2a2d36; --line-2: #3a3e49;
  --ink: #eceef3; --ink-2: #a0a4b0; --ink-3: #828691; --dem: #6098d0; --rep: #d47b6f;
  --dem-soft: #16242f; --rep-soft: #2b1e1c; --track: #262931; --map-none: #23262e; --map-stroke: #0f1014;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.5 var(--font-sans); font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: underline; text-decoration-color: var(--line-2); text-underline-offset: 3px; }
a:hover { text-decoration-color: currentColor; }
[hidden] { display: none !important; }
.mono { font-family: var(--font-mono); }
.d { color: var(--dem); } .r { color: var(--rep); }

/* ---------------------------------------------------------------- header */
.top { max-width: 1240px; margin: 0 auto; padding: 28px 24px 8px; display: flex; flex-wrap: wrap; gap: 16px 24px; align-items: end; justify-content: space-between; }
.eyebrow { font: 500 11px/1 var(--font-mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-3); margin: 0 0 8px; }
h1 { margin: 0; font-size: 26px; line-height: 1.2; font-weight: 600; letter-spacing: -0.01em; }
.sub { margin: 6px 0 0; color: var(--ink-2); }

.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--track); border-radius: 999px; }
.seg button {
  border: 0; background: none; color: var(--ink-2); font: 500 14px var(--font-sans);
  padding: 0 18px; min-height: 44px; border-radius: 999px; cursor: pointer;
}
.seg button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08); }

/* ---------------------------------------------------------------- controls */
.controls { max-width: 1240px; margin: 0 auto; padding: 12px 24px; display: flex; flex-wrap: wrap; gap: 12px; align-items: end; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font: 500 11px/1 var(--font-mono); letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-3); }
select, input[type="text"], input[type="number"] {
  font: 500 14px var(--font-sans); color: var(--ink); background-color: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); min-height: 44px; padding: 0 14px; min-width: 150px;
}
select:hover, input:hover { border-color: var(--line-2); }
select:focus-visible, input:focus-visible, button:focus-visible { outline: 2px solid var(--dem); outline-offset: 2px; }
/* Native select arrows sit flush against the edge; draw our own with room around it. */
select {
  appearance: none; -webkit-appearance: none; padding-right: 40px; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-2) 50%), linear-gradient(135deg, var(--ink-2) 50%, transparent 50%);
  background-position: right 19px center, right 14px center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
#n-feed { min-width: 280px; }
#n-turnout { min-width: 110px; width: 110px; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; font-weight: 500; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--ink); margin: 0; }
.asof { font: 12px var(--font-mono); color: var(--ink-3); padding-bottom: 14px; margin-left: auto; }

.btn {
  font: 600 14px var(--font-sans); min-height: 44px; min-width: 84px; padding: 0 16px; border-radius: 999px;
  border: 0; background: var(--ink); color: var(--bg); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn svg { width: 12px; height: 12px; fill: currentColor; }
.scrub { display: flex; gap: 14px; align-items: center; width: 100%; }
.scrub input[type="range"] { flex: 1; min-width: 0; height: 44px; accent-color: var(--ink); background: none; border: 0; padding: 0; margin: 0; }
.scrub .when { font: 12px var(--font-mono); color: var(--ink-2); min-width: 170px; text-align: right; }

/* ---------------------------------------------------------------- layout */
.layout { max-width: 1240px; margin: 0 auto; padding: 4px 24px 16px; display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 16px; align-items: start; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.map-card { padding: 12px 12px 8px; position: relative; }
.map-card .scrub { padding: 4px 4px 0; border-top: 1px solid var(--line); margin-top: 8px; }
#map { width: 100%; height: auto; display: block; touch-action: manipulation; }
#map path.unit { stroke: var(--map-stroke); stroke-width: 0.4; cursor: pointer; transition: fill 0.25s; }
#map path.unit:hover, #map path.unit.on { stroke: var(--ink); stroke-width: 1.3; }
#map path.states { fill: none; stroke: var(--map-stroke); stroke-width: 1.2; pointer-events: none; }
#map path.outline { fill: none; stroke: var(--ink-3); stroke-width: 0.8; pointer-events: none; }

.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; padding: 6px 4px 2px; font: 11px var(--font-mono); color: var(--ink-2); }
.legend .ramp { display: inline-flex; align-items: center; gap: 2px; }
.legend .ramp i { width: 22px; height: 10px; display: block; }
.legend .ramp i:first-child { border-radius: 3px 0 0 3px; } .legend .ramp i:last-child { border-radius: 0 3px 3px 0; }
.legend .note { color: var(--ink-3); }

/* ---------------------------------------------------------------- panel */
.panel { padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.panel h2 { margin: 0; font-size: 18px; line-height: 1.25; font-weight: 600; }
.panel .who { margin: 4px 0 0; color: var(--ink-2); font-size: 14px; }
.favored { font-size: 20px; font-weight: 600; line-height: 1.2; }
.stats { display: flex; gap: 24px; justify-content: flex-end; text-align: right; }
.stat b { display: block; font: 600 34px/1 var(--font-sans); letter-spacing: -0.02em; }
.stat span { font-size: 12px; color: var(--ink-2); }
.headline { display: flex; justify-content: space-between; align-items: end; gap: 12px; }

.pbar { height: 6px; border-radius: 99px; background: var(--rep); overflow: hidden; display: flex; }
.pbar i { display: block; height: 100%; background: var(--dem); }
.pbar.track { background: var(--track); }
.pbar.track i { background: var(--ink-2); }

.cands { display: flex; flex-direction: column; gap: 10px; }
.cand { display: grid; grid-template-columns: 6px 1fr auto; gap: 4px 10px; align-items: center; }
.cand .chip { grid-row: span 2; align-self: stretch; border-radius: 3px; }
.cand .chip.d { background: var(--dem); } .cand .chip.r { background: var(--rep); }
.cand .name { font-weight: 600; }
.cand .name small { font: 500 11px var(--font-mono); color: var(--ink-3); margin-left: 6px; letter-spacing: 0.04em; }
.cand .pct { font: 600 20px/1 var(--font-sans); text-align: right; }
.cand .votes { grid-column: 2 / 4; font: 12px var(--font-mono); color: var(--ink-2); display: flex; justify-content: space-between; }
.cand .bar { grid-column: 2 / 4; height: 6px; background: var(--track); border-radius: 99px; overflow: hidden; }
.cand .bar i { display: block; height: 100%; }

.box { background: var(--surface-2); border: 1px solid var(--line); border-radius: calc(var(--radius) * 0.8); padding: 12px 14px; }
.box .eyebrow { margin-bottom: 6px; }
.big { font: 600 30px/1 var(--font-sans); letter-spacing: -0.02em; }
.range { font: 12px var(--font-mono); color: var(--ink-2); margin-top: 6px; }

dl.kv { display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; margin: 0; font-size: 14px; }
dl.kv dt { color: var(--ink-2); }
dl.kv dd { margin: 0; font-family: var(--font-mono); font-size: 13px; text-align: right; }

.badge { display: inline-flex; align-items: center; gap: 6px; font: 500 11px var(--font-mono); letter-spacing: 0.04em; text-transform: uppercase; padding: 4px 8px; border-radius: 99px; background: var(--track); color: var(--ink-2); }
.badge.live::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--rep); animation: pulse 1.6s infinite; }
.badge.warn { background: #f6e7c8; color: #6a4a00; }
@keyframes pulse { 50% { opacity: 0.3; } }
@media (prefers-reduced-motion: reduce) { .badge.live::before { animation: none; } #map path.unit { transition: none; } }

table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl th { font: 500 10px var(--font-mono); letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-3); text-align: left; padding: 0 0 6px; border-bottom: 1px solid var(--line); }
table.tbl td { padding: 8px 0; border-bottom: 1px solid var(--line); font-family: var(--font-mono); font-size: 12px; }
table.tbl td:first-child { font-family: var(--font-sans); font-size: 13px; }
table.tbl th:not(:first-child), table.tbl td:not(:first-child) { text-align: right; }

.races { list-style: none; margin: 0; padding: 0; }
.races li { border-top: 1px solid var(--line); }
.races li:first-child { border-top: 0; }
.races a { display: grid; grid-template-columns: 1fr 70px 60px; gap: 10px; align-items: center; min-height: 44px; text-decoration: none; }
.races a:hover .st { text-decoration: underline; }
.races .m { font: 13px var(--font-mono); text-align: right; }
.note { margin: 0; font-size: 12px; color: var(--ink-2); line-height: 1.5; }

.spark { width: 100%; height: 70px; display: block; }
.spark .zero { stroke: var(--line-2); stroke-dasharray: 2 3; }
.spark .line { fill: none; stroke: var(--ink); stroke-width: 1.5; }
.spark .mark { fill: var(--surface); stroke: var(--ink); stroke-width: 2; }

/* ---------------------------------------------------------------- tooltip + mobile card */
.tooltip {
  position: fixed; pointer-events: none; z-index: 20; width: 250px; background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow); font-size: 13px;
}
.tt-head { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; margin-bottom: 8px; }
.tt-head small { font: 500 11px var(--font-mono); color: var(--ink-3); }
.tt-row { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; }
.tt-row span:first-child { color: var(--ink-2); }
.tt-row span:last-child { font-family: var(--font-mono); font-size: 12px; }
.tt-split { display: flex; height: 6px; border-radius: 99px; overflow: hidden; margin: 6px 0 8px; background: var(--track); }
.tt-split i:first-child { background: var(--dem); } .tt-split i:last-child { background: var(--rep); margin-left: auto; }
.tt-sub { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 6px; }

.sheet { display: none; }
@media (hover: none), (max-width: 767px) {
  .tooltip { display: none !important; }
  .sheet {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--surface); border-top: 1px solid var(--line);
    border-radius: 16px 16px 0 0; box-shadow: var(--shadow); padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
    max-height: 60vh; overflow-y: auto; transform: translateY(105%); transition: transform 0.2s ease-out; display: block;
  }
  .sheet.open { transform: none; }
  .sheet .close { position: absolute; top: 6px; right: 6px; width: 44px; height: 44px; border: 0; background: none; color: var(--ink-2); font-size: 22px; cursor: pointer; }
  .sheet .btn { width: 100%; margin-top: 12px; }
  .sheet .tt-head { padding-right: 44px; font-size: 16px; }
}

.foot { max-width: 1240px; margin: 0 auto; padding: 8px 24px 40px; color: var(--ink-3); font-size: 12px; }
.foot p { margin: 0 0 6px; max-width: 820px; }

/* ---------------------------------------------------------------- responsive */
@media (max-width: 1023px) {
  .layout { grid-template-columns: 1fr; }
}
@media (max-width: 767px) {
  body { font-size: 14px; }
  .top { padding: 20px 16px 4px; }
  h1 { font-size: 22px; }
  .seg { width: 100%; } .seg button { flex: 1; }
  .controls { padding: 10px 16px; display: grid; grid-template-columns: 1fr 1fr; }
  .controls .wide, .controls .scrub, .controls .asof { grid-column: 1 / -1; }
  .asof { margin-left: 0; padding-bottom: 0; }
  select, input[type="text"], input[type="number"], #n-feed, #n-turnout { min-width: 0; width: 100%; }
  .layout { padding: 4px 16px 16px; }
  .map-card { padding: 8px 6px 6px; }
  .scrub .when { min-width: 0; font-size: 11px; }
  .stat b { font-size: 28px; }
  .foot { padding: 8px 16px calc(32px + env(safe-area-inset-bottom)); }
}
