:root {
  --bg: #f6f6f4;
  --surface: #fcfcfb;
  --ink: #1b1c1e;
  --ink-2: #4a4d52;
  --muted: #7a7e85;
  --line: #e3e3df;
  --grid: #ececE8;
  --dem: #2f6fdb;
  --rep: #d6423a;
  --neutral: #a9adb4;
  --dem-soft: #2f6fdb38;
  --rep-soft: #d6423a38;
  --accent: #1b1c1e;
  --map-mid: #c4c3bc;
  --map-none: #efeee9;
  --map-stroke: #fcfcfb;
  --warn-bg: #fff4d6;
  --warn-ink: #6b4e00;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121211;
    --surface: #1a1a19;
    --ink: #ecece9;
    --ink-2: #b9bab6;
    --muted: #8b8d8a;
    --line: #2c2c2a;
    --grid: #262624;
    --dem: #4f86e8;
    --rep: #e0544a;
    --neutral: #6c6f74;
    --dem-soft: #4f86e840;
    --rep-soft: #e0544a40;
    --warn-bg: #3a2f10;
    --map-mid: #64645f;
    --map-none: #242423;
    --map-stroke: #1a1a19;
    --warn-ink: #f2d27a;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
}
h1 { font-size: 22px; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 15px; margin: 0; }
.sub, .meta { color: var(--muted); font-size: 13px; margin: 2px 0 0; }
.right { text-align: right; }
.tagline { margin: 4px 0 2px; color: var(--dem); font-weight: 600; font-size: 14px; }
.live { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--rep); vertical-align: middle; }
.mood { font-size: 14px; font-weight: 600; color: var(--ink-2); margin: 0 0 4px; }
.stat b.goal { color: var(--dem); }
.joint .cell.goal { border: 2px solid var(--dem); }
.joint .cell.goal .fill { background: var(--dem); opacity: .25; }
.pickup { font-size: 11px; font-weight: 700; margin-left: 6px; padding: 2px 6px; border-radius: 4px; background: var(--dem); color: #fff; }
.lost { font-size: 11px; font-weight: 600; margin-left: 6px; color: var(--muted); }
.pill.r { background: none; color: var(--ink-2); border-color: var(--rep); }
.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 20; max-width: min(360px, calc(100vw - 32px)); }
.toast {
  background: var(--dem); color: #fff; border-radius: 10px; padding: 12px 14px; font-size: 14px; font-weight: 600;
  box-shadow: 0 6px 24px #0003; animation: toast-in .35s ease-out;
}
.toast.tone-loss { background: var(--ink-2); color: var(--surface); }
.toast.tone-lead, .toast.tone-info { background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-left: 4px solid var(--dem); }
.toast.tone-big { font-size: 16px; padding: 16px 18px; }
.toast small { display: block; font-weight: 500; opacity: .9; margin-top: 2px; }
@keyframes toast-in { from { transform: translateY(12px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .toast, .live-dot { animation: none; } }

.top {
  display: flex; justify-content: space-between; align-items: end; gap: 16px;
  max-width: 1200px; margin: 0 auto; padding: 24px 16px 12px;
}
.live-dot {
  display: inline-block; width: 9px; height: 9px; border-radius: 50%;
  background: var(--rep); vertical-align: middle; margin: 0 2px 3px;
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: .25; } }

.banner {
  max-width: 1200px; margin: 0 auto 12px; padding: 8px 14px; border-radius: var(--radius);
  background: var(--warn-bg); color: var(--warn-ink); font-size: 13px; font-weight: 600;
  width: calc(100% - 32px);
}
main { max-width: 1200px; margin: 0 auto; padding: 0 16px 40px; display: grid; gap: 16px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; min-width: 0;
}
.chambers, .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid2 { grid-template-columns: 3fr 2fr; }
@media (max-width: 820px) { .chambers, .grid2 { grid-template-columns: 1fr; } .top { flex-direction: column; align-items: start; } .right { text-align: left; } }

/* Chamber card */
.chamber .head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.chamber .odds { font-size: 34px; font-weight: 700; letter-spacing: -0.02em; margin: 8px 0 2px; }
.chamber .odds small { font-size: 14px; font-weight: 500; color: var(--ink-2); margin-left: 6px; }
.oddsbar, .seatbar { display: flex; gap: 2px; height: 14px; margin: 10px 0 6px; position: relative; }
.oddsbar > div, .seatbar > div { height: 100%; min-width: 0; transition: flex-grow .6s ease; }
.oddsbar > div:first-child, .seatbar > div:first-child { border-radius: 4px 0 0 4px; }
.oddsbar > div:last-of-type, .seatbar > div:last-of-type { border-radius: 0 4px 4px 0; }
.seatbar { height: 22px; margin-top: 18px; }
.seg-d { background: var(--dem); }
.seg-r { background: var(--rep); }
.seg-dl { background: var(--dem-soft); }
.seg-rl { background: var(--rep-soft); }
.seg-n { background: var(--neutral); }
.majority {
  position: absolute; top: -6px; bottom: -6px; width: 2px; background: var(--ink);
}
.majority span {
  position: absolute; top: -18px; left: 50%; transform: translateX(-50%);
  font-size: 11px; color: var(--ink-2); white-space: nowrap;
}
.row { display: flex; justify-content: space-between; font-size: 13px; color: var(--ink-2); gap: 8px; flex-wrap: wrap; }
.key { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }
.stat { border-top: 1px solid var(--line); padding-top: 8px; }
.stat b { display: block; font-size: 18px; }
.stat span { font-size: 12px; color: var(--muted); }

/* Molly's Take */
.feed { list-style: none; margin: 12px 0 0; padding: 0; max-height: 340px; overflow-y: auto; display: grid; gap: 2px; }
.feed li { display: grid; grid-template-columns: 64px 1fr; gap: 12px; padding: 9px 10px; border-radius: 8px; border-left: 3px solid var(--line); }
.feed li.linked { cursor: pointer; }
.feed li.linked:hover { background: var(--bg); }
.feed li.empty { display: block; color: var(--muted); border: 0; }
.feed time { color: var(--muted); font-size: 12px; padding-top: 2px; white-space: nowrap; }
.feed p { margin: 0; font-size: 14px; }
.feed .tone-win { border-left-color: var(--dem); }
.feed .tone-big { border-left-color: var(--dem); background: var(--dem-soft); }
.feed .tone-big p { font-weight: 700; }
.feed .tone-loss { border-left-color: var(--rep); }
.feed .tone-lead { border-left-color: var(--neutral); }

/* Map */
.map { margin-top: 12px; }
.map svg { width: 100%; height: auto; display: block; max-height: 560px; }
.map path.state { stroke: var(--map-stroke); stroke-width: 1; stroke-linejoin: round; }
.map path.state.has { cursor: pointer; }
.map path.state.has:hover { stroke: var(--ink); stroke-width: 1.5; }
.map path.state.sel { stroke: var(--ink); stroke-width: 2.5; }
.map .st-label { font-size: 11px; font-weight: 600; text-anchor: middle; fill: var(--ink-2); pointer-events: none; }
.map .st-label.on-strong { fill: #fff; }
.map .empty { color: var(--muted); font-size: 13px; padding: 80px 0; text-align: center; }
.map-legend { display: flex; flex-wrap: wrap; gap: 8px 24px; align-items: center; font-size: 12px; color: var(--ink-2); margin-top: 8px; }
.map-legend .ramp { display: grid; grid-template-columns: repeat(3, auto); gap: 2px 0; align-items: center; }
.map-legend .ramp i { grid-column: 1 / -1; display: block; width: 220px; height: 10px; border-radius: 4px; }
.map-legend .ramp span:nth-of-type(2) { text-align: center; }
.map-legend .ramp span:nth-of-type(3) { text-align: right; }
.chip {
  font: inherit; font-size: 13px; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--ink);
  background: var(--ink); color: var(--surface); cursor: pointer;
}

/* Trend */
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--ink-2); margin: 10px 0 4px; }
.legend .sw { width: 14px; height: 2px; border-radius: 0; }
.legend .dash { background: none; border-top: 2px dashed var(--ink-2); }
.trend svg { width: 100%; height: 220px; display: block; overflow: visible; }
.trend text { fill: var(--muted); font-size: 11px; }
.trend .grid line { stroke: var(--grid); }
.trend .empty { color: var(--muted); font-size: 13px; padding: 60px 0; text-align: center; }

/* Joint */
.joint { display: grid; grid-template-columns: auto 1fr 1fr; gap: 6px; margin-top: 12px; font-size: 13px; }
.joint .lbl { color: var(--muted); align-self: center; }
.joint .lbl.col { text-align: center; }
.joint .cell {
  border-radius: 8px; padding: 14px 10px; text-align: center; border: 1px solid var(--line);
  position: relative; overflow: hidden;
}
.joint .cell b { font-size: 20px; display: block; position: relative; }
.joint .cell span { color: var(--ink-2); position: relative; }
.joint .cell .fill { position: absolute; inset: auto 0 0 0; background: var(--neutral); opacity: .22; }

/* Races */
.races-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.controls { display: flex; gap: 10px; flex-wrap: wrap; }
.tabs { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.tabs button {
  background: none; border: 0; padding: 6px 12px; font: inherit; font-size: 13px; color: var(--ink-2); cursor: pointer;
}
.tabs button[aria-selected="true"] { background: var(--ink); color: var(--surface); }
input[type="search"] {
  font: inherit; font-size: 13px; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg); color: var(--ink); min-width: 200px;
}
.table-wrap { overflow-x: auto; margin-top: 12px; }
table.races { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 760px; }
.races th { text-align: left; font-weight: 500; color: var(--muted); padding: 6px 8px; border-bottom: 1px solid var(--line); }
.races td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.races td.name b { display: block; }
.races td.name span { color: var(--muted); font-size: 12px; }
.cand b { font-weight: 600; }
.cand .who { color: var(--muted); font-size: 12px; display: block; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cand .tick { font-size: 11px; font-weight: 700; margin-left: 4px; }
.meter { height: 6px; border-radius: 3px; background: var(--grid); width: 90px; overflow: hidden; display: inline-block; vertical-align: middle; margin-right: 6px; }
.meter > i { display: block; height: 100%; background: var(--ink-2); border-radius: 3px; }
.prob { display: flex; align-items: center; gap: 8px; }
.prob .track { position: relative; width: 110px; height: 8px; background: var(--grid); border-radius: 4px; }
.prob .track::after { content: ""; position: absolute; left: 50%; top: -3px; bottom: -3px; width: 1px; background: var(--muted); }
.prob .track i { position: absolute; top: 0; bottom: 0; border-radius: 4px; }
.pill { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; white-space: nowrap; border: 1px solid var(--line); color: var(--ink-2); }
.pill.d { background: var(--dem); color: #fff; border-color: transparent; }
.pill.r { background: var(--rep); color: #fff; border-color: transparent; }
.pill.i { background: var(--ink-2); color: var(--surface); border-color: transparent; }
.flip { font-size: 11px; font-weight: 700; margin-left: 6px; color: var(--ink); }

.tooltip {
  position: fixed; pointer-events: none; z-index: 10; background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 12px;
  box-shadow: 0 4px 16px #0002; min-width: 150px;
}
.tooltip .t { color: var(--muted); margin-bottom: 4px; }
.tooltip .r { display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.footnote { color: var(--muted); font-size: 12px; max-width: 820px; }
