:root {
  color-scheme: light;
  --page: #f4f4f4;
  --surface: #fbfbfa;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --dem: #4a62f7;
  --rep: #cc4440;
  --dem-tint: #7183f8;
  --rep-tint: #de8381;
  --dem-soft: #c3cbfc;
  --rep-soft: #f0c7c6;
  --neutral: #f0efec;
  --critical: #d03b3b;
  --good: #006300;
  --warn-bg: #fff4dc;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}
main { max-width: 960px; margin: 0 auto; padding: 24px 16px 48px; }
header.page { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 16px; }
h1 { font-size: 22px; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 15px; margin: 0 0 12px; font-weight: 600; }
.sub { color: var(--text-2); font-size: 13px; }
.muted { color: var(--muted); }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
}
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 720px) { .grid2 { grid-template-columns: 1fr; } }
.live-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); margin-right: 6px; vertical-align: 1px; }
.live-dot.on { background: var(--good); }
.num { font-variant-numeric: tabular-nums; }

/* projections */
.cand-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.cand-row:last-of-type { border-bottom: 0; }
.cand-name { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.swatch { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.cand-votes { font-size: 22px; font-weight: 600; }
.cand-range { color: var(--text-2); font-size: 12px; text-align: right; }
.progress { height: 8px; border-radius: 4px; background: var(--neutral); overflow: hidden; margin: 6px 0 4px; }
.progress > div { height: 100%; background: var(--text-2); border-radius: 4px; }
svg text { fill: var(--text-2); font: 12px system-ui, -apple-system, "Segoe UI", sans-serif; }
svg .axis-label { fill: var(--muted); }

/* timeline + tooltip */
.chart { position: relative; }
.chart svg { width: 100%; height: auto; display: block; touch-action: pan-y; }
.tooltip {
  position: absolute; pointer-events: none; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; font-size: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,.12); white-space: nowrap; display: none;
}
.tooltip strong { font-size: 14px; }
.tooltip .key { display: inline-block; width: 12px; height: 2px; vertical-align: middle; margin-right: 6px; }

/* tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-weight: 600; color: var(--text-2); border-bottom: 1px solid var(--axis); padding: 6px 8px; white-space: nowrap; }
td { border-bottom: 1px solid var(--grid); padding: 6px 8px; vertical-align: middle; }
td.r, th.r { text-align: right; }
.bar-cell { min-width: 90px; }
.mini-bar { height: 6px; border-radius: 3px; background: var(--neutral); overflow: hidden; }
.mini-bar > div { height: 100%; background: var(--text-2); }
.range-cell svg { width: 180px; height: 18px; display: block; }
.net-cell { white-space: nowrap; }
.net-cell svg { width: 120px; height: 18px; display: inline-block; vertical-align: middle; margin-right: 8px; }
.net-cell .net-label { display: inline-block; min-width: 76px; font-variant-numeric: tabular-nums; }
footer { color: var(--muted); font-size: 12px; margin-top: 24px; }
footer a { color: var(--text-2); }

/* admin */
button, input, select, textarea { font: inherit; color: inherit; }
button {
  background: var(--surface); border: 1px solid var(--axis); border-radius: 8px; padding: 6px 12px; cursor: pointer;
}
button.primary { background: var(--text); color: var(--surface); border-color: var(--text); }
button.danger { color: var(--critical); }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea {
  background: var(--surface); border: 1px solid var(--axis); border-radius: 8px; padding: 6px 8px; width: 100%;
}
label { display: block; font-size: 13px; color: var(--text-2); }
label > input, label > select, label > textarea { margin-top: 4px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.form-grid .wide { grid-column: span 2; }
@media (max-width: 420px) { .form-grid .wide { grid-column: 1 / -1; } }
.flag { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 6px; background: var(--warn-bg); color: var(--text); margin: 1px 2px 1px 0; }
.flag::before { content: "⚠ "; }
.status-line { display: flex; flex-wrap: wrap; gap: 16px; font-size: 13px; }
.err { color: var(--critical); }
.checks { font-size: 13px; margin-top: 8px; }
tr.warned td { background: color-mix(in srgb, var(--warn-bg) 40%, transparent); }
tr.removed td { color: var(--muted); text-decoration: line-through; }
tr.removed td:last-child { text-decoration: none; }

/* ---------- public page ---------- */
body.public {
  --page: #fafafa;
  --surface: #fafafa;
  --text: #1a1a1a;
  --text-2: #555555;
  --muted: #8a8a8a;
  --grid: #e8e8e8;
  --axis: #c8c8c8;
  --rule: #dcdcdc;
  --dem: #4a62f7;
  --rep: #c9423e;
  --dem-tint: #8e9cf9;
  --rep-tint: #e08f8b;
  --dem-ink: #3047d6;         /* hatching lines, one step darker than the fill */
  --rep-ink: #a8332f;
  --sans: "Public Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  /* Type scale: one size per job. Weights are 400, and 500 for names and headings. */
  --fs-display: clamp(30px, 5.6vw, 44px);   /* the verdict sentence */
  --fs-heading: 24px;                       /* section headings */
  --fs-body: 17px;                          /* running text, captions; names at 500 */
  --fs-small: 14px;                         /* tables, tooltips */
  --fs-meta: 13px;                          /* status, legends, ranges, footer */
  --fs-chart: 12px;                         /* text inside charts and the map */
  background: var(--page);
  color: var(--text);
  font-family: var(--sans);
  font-size: var(--fs-body);
  line-height: 1.5;
}
body.public svg text { font-family: var(--sans); font-size: var(--fs-chart); font-variant-numeric: tabular-nums; }
body.public h2 { font-size: var(--fs-heading); font-weight: 500; margin: 0 0 14px; letter-spacing: -0.01em; }
.story { max-width: 920px; padding: 28px 20px 72px; }
/* Until the first render, show only the masthead: no flash of the empty results page. */
.story:not(.ready) > :not(.masthead) { visibility: hidden; }
.map-section { border-top: 1px solid var(--rule); padding-top: 28px; margin-bottom: 56px; }
.map svg { max-width: 640px; }
.map .county { fill: var(--neutral); stroke: var(--surface); stroke-width: 1; }
.map .county-group:hover .county, .map .county-group.active .county { fill: var(--grid); }
.map .bar { stroke: var(--surface); stroke-width: 1; transition: d .7s cubic-bezier(.2,.7,.2,1); }
.map .bar.dem { fill: var(--dem); }
.map .bar.rep { fill: var(--rep); }
.map .county-label { font-size: var(--fs-chart); fill: var(--text-2); paint-order: stroke; stroke: var(--surface); stroke-width: 3px; stroke-linejoin: round; pointer-events: none; }

.masthead {
  display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 6px 16px;
  border-bottom: 2px solid var(--text); padding-bottom: 10px; margin-bottom: 44px;
}
.masthead .title { font-size: var(--fs-body); font-weight: 500; }
.masthead .status { font-size: var(--fs-meta); color: var(--text-2); font-variant-numeric: tabular-nums; }
.live-dot { width: 7px; height: 7px; }
.live-dot.on { background: var(--rep); animation: pulse 2.4s ease-out infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--rep) 45%, transparent); } 70%, 100% { box-shadow: 0 0 0 7px transparent; } }

/* Counted and outstanding votes: one row per candidate, sideways bars on one shared scale. The
   gap between the two bars is constant, so the rows' total lengths compare directly. */
.tally { position: relative; margin: 8px 0 52px; --bar-h: 112px; }
.tally .cand { margin-bottom: 28px; }
.tally .name { font-size: var(--fs-body); font-weight: 500; margin: 0 0 10px; }
.tally .bars { display: flex; height: var(--bar-h); }
.tally .box { height: 100%; flex: none; transition: width .7s cubic-bezier(.2,.7,.2,1); outline-offset: 3px; }
.tally .box:focus-visible { outline: 2px solid var(--text); }
.tally .box.counted-dem { background: var(--dem); }
.tally .box.counted-rep { background: var(--rep); }
/* Outstanding ballots: hatched, to read as "not yet counted". */
.tally .box.out-dem { background: repeating-linear-gradient(135deg, color-mix(in srgb, var(--dem-ink) 55%, transparent) 0 1px, transparent 1px 6px), var(--dem-tint); }
.tally .box.out-rep { background: repeating-linear-gradient(135deg, color-mix(in srgb, var(--rep-ink) 55%, transparent) 0 1px, transparent 1px 6px), var(--rep-tint); }
.tally .captions { position: relative; height: 2.8em; margin-top: 8px; font-size: var(--fs-body); font-style: italic; font-variant-numeric: tabular-nums; }
.tally .captions.two-lines { height: 4.4em; }
.tally .range { display: block; font-size: var(--fs-meta); font-style: normal; color: var(--text-2); margin-top: 2px; }
.tally .caption { position: absolute; top: 0; margin: 0; white-space: nowrap; transition: left .7s cubic-bezier(.2,.7,.2,1); }

.verdict-block { border-top: 1px solid var(--rule); padding-top: 32px; margin: 8px 0 56px; }
.verdict { font-size: var(--fs-display); line-height: 1.2; letter-spacing: -0.022em; margin: 0 0 26px; max-width: 700px; font-weight: 400; }
.verdict span { white-space: nowrap; }
.verdict .dem { color: var(--dem); }
.verdict .rep { color: var(--rep); }
#margin-strip { width: 100%; max-width: 560px; height: auto; display: block; }
.narrative { font-size: var(--fs-body); line-height: 1.5; color: var(--text-2); max-width: 620px; margin: 24px 0 0; }
.narrative .dem { color: var(--dem); }
.narrative .rep { color: var(--rep); }

.charts-section, .counties-section { border-top: 1px solid var(--rule); padding-top: 28px; }
.section-note { color: var(--text-2); font-size: var(--fs-meta); margin: 0 0 16px; max-width: 620px; }
.legend { display: flex; flex-wrap: wrap; gap: 20px; font-size: var(--fs-meta); color: var(--text-2); margin-bottom: 14px; }
.legend span { display: inline-flex; align-items: center; gap: 7px; }
.multiples { display: grid; grid-template-columns: 1fr 1fr; gap: 32px; margin-bottom: 56px; }
.multiple h3 { font-size: var(--fs-body); font-weight: 500; margin: 0 0 6px; }
.multiple .chart svg { overflow: visible; }
body.public .tooltip { font-size: var(--fs-meta); background: var(--page); border-color: var(--axis); box-shadow: none; }

.counties-section table { font-size: var(--fs-small); }
body.public .tooltip strong { font-size: var(--fs-small); font-weight: 500; }
.counties-section th { color: var(--text-2); font-weight: 500; border-bottom-color: var(--text); }
.counties-section td { border-bottom-color: var(--grid); }
.counties-section .mini-bar { background: var(--grid); }
.counties-section td.vs-exp { white-space: nowrap; }
.vs.dem { color: var(--dem); }
.vs.rep { color: var(--rep); }
.vs.even { color: var(--text-2); }
.counties-section .mini-bar > div { background: var(--text-2); }
body.public footer { font-size: var(--fs-meta); line-height: 1.55; color: var(--text-2); border-top: 1px solid var(--rule); padding-top: 16px; margin-top: 40px; max-width: 640px; }
body.public footer .credit { margin: 8px 0 0; }

@media (max-width: 640px) {
  body.public { --fs-body: 16px; --fs-heading: 21px; }
  .tally { --bar-h: 72px; }
  .multiples { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  .tally .box, .tally .caption, .map .bar { transition: none; }
  .live-dot.on { animation: none; }
}
.tooltip .key.swatch { width: 10px; height: 10px; border-radius: 2px; vertical-align: -1px; }
