:root {
  --yes: #3535ff;
  --no: #e3201b;
  --undecided: #9b9b9b;
  --state-mixed: #dcdcdc;
  --state-empty: #f0f0f0;
  --border: #ffffff;
  --text: #1b1b1b;
  --muted: #666;
  --bg: #ffffff;
  --panel: #f6f6f6;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 0 24px 24px;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
}

/* Header + map + charts. Pinned to the top on wide screens (body.pin), where
   the map and charts shrink to --viz-h as the page scrolls (see app.js). */
.pinned { padding-top: 24px; background: var(--bg); }
body.pin .pinned {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  padding: 16px 24px 12px;
}
body.pin .pinned.scrolled { box-shadow: 0 6px 16px rgba(0, 0, 0, 0.08); }

header { margin-bottom: 16px; }
.header-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 24px;
  flex-wrap: wrap;
}
h1 { margin: 0; font-size: 28px; }
.header-actions { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.save-custom { background: var(--text); border-color: var(--text); color: #fff; font-weight: 600; }
.save-custom:hover { background: #333; }
.save-custom:disabled { background: #fff; border-color: #ccc; color: var(--muted); cursor: default; font-weight: 400; }
.invisible { visibility: hidden; }
.sub, .hint { margin: 4px 0 0; color: var(--muted); font-size: 14px; }

/* Preset views: the bottom row of the header. */
.presets {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid #e4e4e4;
  font-size: 14px;
}
.presets span { color: var(--muted); }
.presets button[aria-pressed="true"] { background: var(--text); border-color: var(--text); color: #fff; }

button {
  font: inherit;
  font-size: 14px;
  padding: 6px 12px;
  border: 1px solid #bbb;
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
}
button:hover { background: #f0f0f0; }

/* The 12-column grid: map takes 8, counts take 4. */
.grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 24px;
  align-items: start;
}
.map { grid-column: span 8; }
.counts { grid-column: span 4; display: flex; flex-direction: column; gap: 24px; }

@media (max-width: 899px) {
  .map, .counts { grid-column: span 12; }
}

#map { width: 100%; height: auto; display: block; user-select: none; -webkit-user-select: none; }

body.pin .viz { height: var(--viz-h); }
body.pin .map, body.pin .counts { height: 100%; min-height: 0; }
body.pin #map { height: 100%; }
body.pin .counts { gap: 12px; }
body.pin .chamber { flex: 1 1 0; min-height: 0; display: flex; flex-direction: column; }
body.pin .hemicycle { flex: 1 1 0; min-height: 0; height: auto; }
/* Compact: Senate and House side by side, fewer words. */
.pinned.compact .counts { flex-direction: row; }
.pinned.compact .threshold { display: none; }
.pinned.compact .chamber figcaption { font-size: 14px; }
.pinned.compact .legend { font-size: 12px; gap: 2px 8px; margin-top: 4px; }
.state { cursor: pointer; stroke: var(--border); stroke-width: 1; transition: fill 120ms; }
.state:hover { stroke: #333; stroke-width: 1.5; }
.state.inert { cursor: default; fill: var(--state-empty); }
.state.inert:hover { stroke: var(--border); stroke-width: 1; }
.state-dots { pointer-events: none; }
/* States too small for their dots: dots show only while hovering the state. */
.state-dots g.overflow { display: none; }
.state-dots g.overflow.revealed { display: inline; }

.chamber { margin: 0; }
.chamber figcaption { font-weight: 600; font-size: 18px; margin-bottom: 4px; }
.hemicycle { width: 100%; height: auto; display: block; }
.hemicycle .yes-share { font-weight: 800; text-anchor: middle; }

.legend {
  list-style: none;
  padding: 0;
  margin: 8px 0 0;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  font-size: 14px;
}
.legend li { display: flex; align-items: center; gap: 6px; }
.swatch { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.swatch.vacant { border: 2px solid var(--undecided); background: transparent; }
.threshold { margin: 4px 0 0; font-size: 13px; color: var(--muted); }

/* State editor */
dialog {
  border: none;
  border-radius: 12px;
  padding: 0;
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 64px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.3); }
.dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px 8px;
  margin: 0;
}
.dialog-head h2 { margin: 0; font-size: 22px; }
.close { border: none; font-size: 24px; line-height: 1; padding: 4px 8px; }
.set-all { display: flex; align-items: center; gap: 8px; padding: 0 20px 12px; font-size: 14px; }
#dialog-body { padding: 0 20px 20px; overflow-y: auto; }
#dialog-body h3 { font-size: 14px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin: 16px 0 6px; }

/* Tables: one box per state, packed into columns. */
.tables { margin-top: 24px; }
.table { grid-column: span 12; }
/* Each table's heading sticks below the pinned map until its table ends, so
   "Senate" scrolls away as "House of Representatives" arrives. */
.table-head {
  position: sticky;
  top: var(--pinned-h, 0px);
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 16px;
  background: var(--bg);
  margin: 0 0 12px;
  padding: 12px 0 8px;
  border-bottom: 1px solid #e4e4e4;
}
.table h2 { font-size: 22px; margin: 0; }
.search { display: flex; align-items: center; gap: 8px; }
.search input {
  font: inherit;
  font-size: 14px;
  padding: 6px 10px;
  border: 1px solid #bbb;
  border-radius: 6px;
  width: 200px;
}
.table-title { display: flex; align-items: center; gap: 16px; }

/* "Undecided only": a checkbox drawn as a pill switch. */
.undecided-only { display: flex; align-items: center; gap: 8px; font-size: 14px; white-space: nowrap; cursor: pointer; }
.undecided-only input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.track {
  position: relative;
  width: 36px;
  height: 20px;
  border-radius: 999px;
  background: #ccc;
  transition: background 150ms;
  flex-shrink: 0;
}
.track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  transition: transform 150ms;
}
.undecided-only input:checked + .track { background: var(--text); }
.undecided-only input:checked + .track::after { transform: translateX(16px); }
.undecided-only input:focus-visible + .track { outline: 2px solid var(--yes); outline-offset: 2px; }
.no-match { color: var(--muted); font-size: 14px; }
[hidden] { display: none !important; }
.states { columns: 300px; column-gap: 16px; }
.state-box {
  break-inside: avoid;
  border: 1px solid #ddd;
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 16px;
}
.state-box h3 { margin: 0 0 4px; font-size: 15px; }

.cell {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  border-bottom: 1px solid #f0f0f0;
}
.cell:last-child { border-bottom: none; }
.who { flex: 1; min-width: 0; }
.who .name { font-size: 14px; }
.who .meta { color: var(--muted); font-size: 12px; }
.cell.vacant .name { color: var(--muted); font-style: italic; }

/* The three vote dots. Hollow until picked. */
.picker { display: inline-flex; gap: 4px; flex-shrink: 0; }
.dot, .hollow {
  width: 16px;
  height: 16px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid;
  background: #fff;
}
.dot:hover { background: #fff; transform: scale(1.15); }
.dot.yes { border-color: var(--yes); }
.dot.no { border-color: var(--no); }
.dot.undecided { border-color: var(--undecided); }
.dot.yes[aria-pressed="true"] { background: var(--yes); }
.dot.no[aria-pressed="true"] { background: var(--no); }
.dot.undecided[aria-pressed="true"] { background: var(--undecided); }
.hollow { display: inline-block; border-color: var(--undecided); margin-right: 40px; }

/* A seat that is up in 2026: its candidates, grouped. */
.race {
  border: 1px dashed #bbb;
  border-radius: 8px;
  padding: 6px 8px;
  margin: 6px 0;
  background: #fafafa;
}
.race-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 13px; }
.race-label { font-weight: 600; }
.badge { font-size: 11px; padding: 1px 6px; border-radius: 999px; background: #ececec; color: #444; }
.seat-result { margin-left: auto; font-size: 12px; color: var(--muted); }
.seat-result[data-vote="yes"] { color: var(--yes); }
.seat-result[data-vote="no"] { color: var(--no); }
.race-note { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.race .cell { border-bottom-color: #eee; }
.win {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 999px;
  color: var(--muted);
  flex-shrink: 0;
}
.win[aria-pressed="true"] { background: var(--text); border-color: var(--text); color: #fff; }
.poll { font-size: 13px; font-variant-numeric: tabular-nums; color: #444; min-width: 44px; text-align: right; cursor: help; }
.favorite { color: #d4a000; font-size: 13px; }
.candidate:not(.winner) .name { color: #555; }
.candidate.winner .name { font-weight: 600; }
