:root {
  --bg: #0b0d10;
  --panel: #14171c;
  --panel-2: #1b1f26;
  --text: #eef1f5;
  --text-dim: #9aa4b2;
  --border: #2a2f38;

  --section-federal: #b3261e;
  --section-chelan: #1e6b3c;
  --section-douglas: #1d5fa8;

  --party-D: #3b82f6;
  --party-R: #ef4444;
  --party-I: #a78bfa;
  --party-NP: #6b7280;
  --party-C: #14b8a6;

  --advance: #22c55e;
  --unofficial: #b45309;
  --certified: #15803d;
  --partial: #6d28d9;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f5f7;
    --panel: #ffffff;
    --panel-2: #f0f1f4;
    --text: #14171c;
    --text-dim: #565f6b;
    --border: #dfe2e7;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow-x: hidden;
}

body { max-width: 720px; margin: 0 auto; padding-bottom: 3rem; }

a { color: inherit; }

.banner {
  text-align: center;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 0.5rem;
  font-size: 0.85rem;
}
.banner.unofficial { background: var(--unofficial); color: #fff; }
.banner.certified { background: var(--certified); color: #fff; }
.banner.partial { background: var(--partial); color: #fff; }

header.masthead {
  padding: 1rem 1rem 0.5rem;
  text-align: center;
}
header.masthead h1 { margin: 0.25rem 0; font-size: 1.3rem; }
header.masthead .asof { color: var(--text-dim); font-size: 0.85rem; }
header.masthead .source { color: var(--text-dim); font-size: 0.75rem; margin-top: 0.25rem; }

.county-headers {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  padding: 0.5rem 1rem 1rem;
}
.county-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem;
  font-size: 0.8rem;
}
.county-card h3 { margin: 0 0 0.4rem; font-size: 0.85rem; }
.county-card .stat { display: flex; justify-content: space-between; margin: 0.15rem 0; }
.county-card .stat .label { color: var(--text-dim); }
.county-card .remaining { margin-top: 0.4rem; padding-top: 0.4rem; border-top: 1px dashed var(--border); }
.county-card .remaining .src { color: var(--text-dim); font-size: 0.7rem; }

section.group {
  margin-top: 1.25rem;
}
section.group > .group-label {
  padding: 0.4rem 1rem;
  font-weight: 700;
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #fff;
}
section.group[data-color="red"] > .group-label { background: var(--section-federal); }
section.group[data-color="green"] > .group-label { background: var(--section-chelan); }
section.group[data-color="blue"] > .group-label { background: var(--section-douglas); }

.race-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin: 0.6rem 1rem;
  padding: 0.75rem 0.85rem;
}

.race-head { margin-bottom: 0.5rem; }
.race-head .title-row { display: flex; align-items: baseline; gap: 0.4rem; flex-wrap: wrap; }
.race-head .title { font-weight: 700; font-size: 1rem; }
.race-head .badge {
  font-size: 0.65rem;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.05rem 0.5rem;
  white-space: nowrap;
}
.race-head .cert-badge {
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  border-radius: 999px;
  padding: 0.05rem 0.5rem;
  white-space: nowrap;
}
.race-head .cert-badge.unofficial { color: var(--unofficial); border: 1px solid var(--unofficial); }
.race-head .cert-badge.certified { background: var(--certified); color: #fff; }
.race-head .district { font-size: 0.75rem; color: var(--text-dim); }
.race-head .note { font-size: 0.75rem; color: var(--text-dim); margin-top: 0.1rem; }

.scope-toggle {
  display: flex;
  gap: 0.25rem;
  margin: 0.5rem 0 0.65rem;
  background: var(--panel-2);
  border-radius: 999px;
  padding: 0.2rem;
}
.scope-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.scope-toggle label {
  flex: 1;
  text-align: center;
  font-size: 0.72rem;
  padding: 0.3rem 0.4rem;
  border-radius: 999px;
  cursor: pointer;
  color: var(--text-dim);
}
.scope-toggle input:checked + label {
  background: var(--panel);
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 0 0 1px var(--border);
}
.scope-pane { display: none; }
.scope-pane.active { display: block; }

.candidate-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0;
  border-left: 3px solid transparent;
  padding-left: 0.5rem;
}
.candidate-row.top-two { border-left-color: var(--advance); }
.candidate-row .advance-mark {
  color: var(--advance);
  font-weight: 700;
  font-size: 0.75rem;
  width: 1rem;
  flex: none;
}
.candidate-row .name-block { flex: 1 1 auto; min-width: 0; }
.candidate-row .name-line { display: flex; align-items: center; gap: 0.35rem; flex-wrap: wrap; }
.candidate-row .cand-name { font-weight: 600; font-size: 0.92rem; }
.candidate-row .cand-note { color: var(--text-dim); font-size: 0.72rem; }
.candidate-row .bar-track {
  height: 4px;
  background: var(--panel-2);
  border-radius: 2px;
  margin-top: 0.3rem;
  overflow: hidden;
}
.candidate-row .bar-fill { height: 100%; background: var(--text-dim); border-radius: 2px; }
.candidate-row.top-two .bar-fill { background: var(--advance); }
.candidate-row .tallies { text-align: right; flex: none; font-variant-numeric: tabular-nums; }
.candidate-row .votes { font-weight: 700; font-size: 0.92rem; }
.candidate-row .pct { color: var(--text-dim); font-size: 0.72rem; }

.write-in-row { color: var(--text-dim); font-size: 0.78rem; padding: 0.25rem 0 0.25rem 1.75rem; }

.margin-note {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-top: 0.4rem;
  padding-top: 0.4rem;
  border-top: 1px dashed var(--border);
}

.rollup {
  margin-top: 0.6rem;
}
.rollup .bar {
  display: flex;
  height: 10px;
  border-radius: 5px;
  overflow: hidden;
  background: var(--panel-2);
}
.rollup .bar .seg.R { background: var(--party-R); }
.rollup .bar .seg.D { background: var(--party-D); }
.rollup .bar .seg.Other { background: var(--party-NP); }
.rollup .nums {
  display: flex;
  justify-content: space-between;
  font-size: 0.68rem;
  color: var(--text-dim);
  margin-top: 0.25rem;
}

.chip {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.02rem 0.35rem;
  border-radius: 4px;
  line-height: 1.5;
}
.chip.party-D { background: var(--party-D); color: #fff; }
.chip.party-R { background: var(--party-R); color: #fff; }
.chip.party-I { background: var(--party-I); color: #fff; }
.chip.party-NP, .chip.party-NPP { background: var(--party-NP); color: #fff; }
.chip.party-C { background: var(--party-C); color: #fff; }
.chip.tag {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
}

.legend {
  margin: 1.5rem 1rem 0;
  padding: 0.85rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 0.78rem;
}
.legend h4 { margin: 0 0 0.5rem; font-size: 0.8rem; }
.legend .row { display: flex; align-items: center; gap: 0.5rem; margin: 0.25rem 0; }
.legend .advance-sample { color: var(--advance); font-weight: 700; }

footer.disclaimer {
  margin: 1.5rem 1rem 0;
  color: var(--text-dim);
  font-size: 0.7rem;
  line-height: 1.4;
}
