:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #15181d;
  --muted: #5f6672;
  --line: #e3e6eb;
  --track: #e9ecf0;
  --map-empty: #dfe3e8;
  --map-stroke: #ffffff;
  --accent: #1f2937;
  --stale: #b45309;
  --stale-bg: #fef3c7;
  /* Candidate colors are set from app.js (CONFIG.candidates). */
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --panel: #171b21;
    --text: #e8eaee;
    --muted: #9aa3af;
    --line: #2a3039;
    --track: #262c35;
    --map-empty: #2f3640;
    --map-stroke: #171b21;
    --accent: #e8eaee;
    --stale: #fbbf24;
    --stale-bg: #3b2f12;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
}
main, .top, footer { max-width: 1200px; margin: 0 auto; padding: 0 16px; }
h1 { font-size: 1.5rem; margin: 0; }
h2 { font-size: 1rem; margin: 0 0 12px; }
a { color: inherit; }

.top {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding-top: 20px; padding-bottom: 16px; flex-wrap: wrap;
}
.meta { margin: 4px 0 0; color: var(--muted); font-size: .9rem; }
.dot { margin: 0 6px; }
button {
  font: inherit; cursor: pointer; border-radius: 8px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
  padding: 8px 14px;
}
button:disabled { opacity: .5; cursor: default; }

.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 16px; margin-bottom: 16px;
}
.layout { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 16px; align-items: start; }
@media (max-width: 860px) { .layout { grid-template-columns: 1fr; } }
.map-panel { position: sticky; top: 12px; }
@media (max-width: 860px) { .map-panel { position: static; } }

/* National */
.nat-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: baseline; }
.nat-names { display: flex; justify-content: space-between; margin: 12px 0 6px; gap: 12px; }
.nat-names .c { display: flex; flex-direction: column; }
.nat-names .c.right { text-align: right; align-items: flex-end; }
.nat-names .name { font-weight: 700; font-size: 1.05rem; }
.nat-names .pct { font-size: 2rem; font-weight: 800; line-height: 1.1; }
.nat-names .votes { color: var(--muted); font-size: .85rem; }
.elected { font-size: .7rem; font-weight: 700; letter-spacing: .04em; padding: 2px 6px; border-radius: 4px; color: #fff; margin-left: 6px; vertical-align: middle; }

/* Split bar */
.split { position: relative; display: flex; height: 12px; border-radius: 6px; overflow: hidden; background: var(--track); }
.split.big { height: 22px; }
.split > span { display: block; height: 100%; transition: width .4s ease; }
.split::after { content: ""; position: absolute; left: 50%; top: -2px; bottom: -2px; width: 2px; background: var(--panel); }
.counted { color: var(--muted); font-size: .85rem; }

/* Toggle */
.list-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.list-head h2 { margin: 0; }
.toggle { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.toggle button { border: 0; border-radius: 0; padding: 6px 12px; background: transparent; color: var(--muted); }
.toggle button[aria-selected="true"] { background: var(--accent); color: var(--bg); }

/* Rows */
.row {
  display: grid; grid-template-columns: minmax(140px, 2.2fr) minmax(0, 5fr); gap: 4px 14px;
  padding: 10px 4px; border-bottom: 1px solid var(--line); align-items: center;
  scroll-margin-top: 12px;
}
.row.flash { animation: flash 1.2s ease; }
@keyframes flash { from { background: var(--track); } to { background: transparent; } }
.row .label { display: flex; flex-direction: column; min-width: 0; }
.row .label strong { overflow-wrap: anywhere; }
.row .sub { color: var(--muted); font-size: .78rem; }
.row .nums { display: flex; justify-content: space-between; font-size: .85rem; margin-bottom: 4px; gap: 8px; }
.row .nums b { font-weight: 700; }
.row .nums small { color: var(--muted); }
.region-row { background: var(--track); border-radius: 8px; border-bottom: 0; margin-top: 12px; padding: 10px 10px; }
.region-row:first-child { margin-top: 0; }
.region-row .label strong { font-size: 1rem; }
.state-row { padding-left: 14px; }
.region-row.expandable { cursor: pointer; user-select: none; }
.region-row.expandable:hover { filter: brightness(.97); }
.region-row.expandable:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.chevron { display: inline-block; width: 1.1em; color: var(--muted); transition: transform .15s ease; }
.region-row.open .chevron { transform: rotate(90deg); }
.region-states { margin: 2px 0 4px; }
.rank { display: inline-block; min-width: 1.8em; color: var(--muted); font-weight: 400; }
.badge { font-size: .7rem; font-weight: 700; padding: 1px 6px; border-radius: 4px; margin-left: 4px; }
.badge.stale { color: var(--stale); background: var(--stale-bg); }
.badge.done { color: var(--muted); border: 1px solid var(--line); }
.pending { color: var(--muted); font-size: .85rem; }

/* Map */
#map { width: 100%; height: auto; display: block; }
#map path { stroke: var(--map-stroke); stroke-width: 1.2; fill: var(--map-empty); cursor: pointer; transition: fill .4s ease; }
#map path:hover { stroke: var(--text); stroke-width: 2; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: .82rem; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -1px; margin-right: 5px; }

#tooltip {
  position: fixed; pointer-events: none; z-index: 10;
  background: var(--panel); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; font-size: .85rem; box-shadow: 0 6px 20px rgba(0,0,0,.18);
}

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