/* Layout: a tabletop scoreboard — seat strip on top, a tray of dice below, the batch ledger last. */
:root {
  --bg: #eceff3;
  --surface: #ffffff;
  --ink: #16202b;
  --muted: #5a6677;
  --line: #d3d9e1;
  --dem: #2256c4;
  --dem-soft: #dbe5fa;
  --rep: #c3342e;
  --rep-soft: #f8dcda;
  --dem-edge: #173c8c;
  --rep-edge: #8e211d;
  --die: #fbf6e8;
  --die-ink: #221d12;
  --die-edge: #c9b88e;
  --accent: #7a5a10;
  --font-display: "Archivo", "Arial Narrow", system-ui, sans-serif;
  --font-body: "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f141b; --surface: #18202a; --ink: #e5eaf0; --muted: #95a1b2; --line: #2a3441;
    --dem: #7aa3ff; --dem-soft: #1c2a47; --rep: #ff736b; --rep-soft: #3d1f1f; --dem-edge: #3f64b8; --rep-edge: #b8433d;
    --die: #efe6cc; --die-ink: #1d180d; --die-edge: #8c7a4c; --accent: #d9b458;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f141b; --surface: #18202a; --ink: #e5eaf0; --muted: #95a1b2; --line: #2a3441;
  --dem: #7aa3ff; --dem-soft: #1c2a47; --rep: #ff736b; --rep-soft: #3d1f1f; --dem-edge: #3f64b8; --rep-edge: #b8433d;
  --die: #efe6cc; --die-ink: #1d180d; --die-edge: #8c7a4c; --accent: #d9b458;
  color-scheme: dark;
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.5 var(--font-body);
}
.wrap { max-width: 1120px; margin: 0 auto; padding: 24px 16px 48px; display: grid; gap: 28px; }
h1, h2, h3 { font-family: var(--font-display); margin: 0; text-wrap: balance; }
h1 { font-weight: 800; font-stretch: 75%; font-size: 2.4rem; letter-spacing: -0.01em; line-height: 1; text-transform: uppercase; }
h2 { font-weight: 800; font-stretch: 80%; font-size: 1.35rem; text-transform: uppercase; letter-spacing: 0.02em; }
h3 { font-weight: 500; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.sub { margin: 6px 0 0; color: var(--muted); font-size: 0.9rem; }

/* header */
.top { display: flex; flex-wrap: wrap; align-items: end; gap: 16px 24px; }
.brand { flex: 1 1 220px; min-width: 0; }
.chamber { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; padding: 3px; background: var(--surface); }
.tab {
  font: 700 0.9rem var(--font-body); border: 0; background: none; color: var(--muted);
  padding: 7px 16px; border-radius: 6px; cursor: pointer;
}
.tab[aria-pressed="true"] { background: var(--ink); color: var(--bg); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.btn {
  font: 700 0.92rem var(--font-body); border-radius: 8px; padding: 9px 16px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--bg); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: none; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.rules { margin: -12px 0 0; color: var(--muted); max-width: 70ch; }
.rules b { color: var(--ink); }

/* scoreboard */
.board { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 20px; display: grid; gap: 14px; }
.tally { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 16px; }
.count { display: grid; }
.count .lbl { font: 700 0.75rem var(--font-body); text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); }
.count .num { font: 800 3.2rem/1 var(--font-display); font-stretch: 70%; font-variant-numeric: tabular-nums; }
.count.d .num { color: var(--dem); }
.count.r { text-align: right; }
.count.r .num { color: var(--rep); }
.verdict { text-align: center; font: 800 1.2rem/1.2 var(--font-display); font-stretch: 85%; text-transform: uppercase; text-wrap: balance; }
.verdict.d { color: var(--dem); }
.verdict.r { color: var(--rep); }
.verdict small { display: block; font: 400 0.85rem var(--font-body); text-transform: none; color: var(--muted); margin-top: 4px; }
.strip { display: grid; gap: 2px; position: relative; }
.strip.senate { grid-template-columns: repeat(50, 1fr); }
.strip.house { grid-template-columns: repeat(87, 1fr); gap: 1px; }
.seat { aspect-ratio: 1; border-radius: 2px; background: var(--line); }
.seat.d { background: var(--dem); }
.seat.r { background: var(--rep); }
.seat.up { opacity: 1; }
.seat.held { opacity: 0.4; }
.strip-note { margin: 0; font-size: 0.82rem; color: var(--muted); }

/* tray */
.sec-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px 16px; margin-bottom: 12px; }
.hint, .run-tag { color: var(--muted); font-size: 0.85rem; }
.run-tag { font-family: var(--font-mono); background: var(--surface); border: 1px solid var(--line); padding: 2px 8px; border-radius: 99px; }
.tray { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.race {
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 14px;
  display: grid; grid-template-columns: 1fr; gap: 8px; align-items: start; min-width: 0;
}
.race .who { min-width: 0; }
.race .st { font: 800 1.6rem/1 var(--font-display); font-stretch: 75%; }
.race .nm { font-size: 0.8rem; line-height: 1.35; color: var(--muted); margin-top: 2px; }
.race .head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.race .head .chip { margin-top: 0; }
.chip {
  display: inline-block; font: 700 0.7rem var(--font-body); text-transform: uppercase; letter-spacing: 0.06em;
  padding: 2px 7px; border-radius: 4px; margin-top: 6px; border: 1px solid var(--line); color: var(--muted);
}
.chip.d { background: var(--dem-soft); color: var(--dem); border-color: transparent; }
.chip.r { background: var(--rep-soft); color: var(--rep); border-color: transparent; }
.die {
  width: 58px; height: 58px; border-radius: 12px; background: var(--die); color: var(--die-ink);
  border: 2px solid var(--die-edge); box-shadow: inset 0 -4px 0 var(--die-edge);
  display: grid; place-items: center; font: 700 1.5rem var(--font-mono); font-variant-numeric: tabular-nums;
}
.die.d { background: var(--dem); color: var(--surface); border-color: var(--dem-edge); box-shadow: inset 0 -4px 0 var(--dem-edge); }
.die.r { background: var(--rep); color: var(--surface); border-color: var(--rep-edge); box-shadow: inset 0 -4px 0 var(--rep-edge); }
.eqs-box { display: grid; gap: 6px; }
.eq {
  display: grid; grid-template-columns: 2.4em 34px 1fr auto 2.2em; align-items: center; gap: 8px;
  padding: 4px 8px; border-radius: 8px; border: 1px solid transparent;
}
.eq.win.d { background: var(--dem-soft); }
.eq.win.r { background: var(--rep-soft); }
.eq:not(.win) { opacity: 0.55; }
.eq .party { font: 700 0.7rem var(--font-body); text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.die.sm { width: 34px; height: 34px; border-radius: 7px; font-size: 0.95rem; border-width: 1px; box-shadow: inset 0 -3px 0 var(--dem-edge); }
.die.sm.r { box-shadow: inset 0 -3px 0 var(--rep-edge); }
.adds { display: flex; flex-wrap: wrap; gap: 2px 8px; font: 700 0.9rem var(--font-mono); font-variant-numeric: tabular-nums; min-width: 0; }
.adds small { font: 400 0.72rem var(--font-body); color: var(--muted); }
.adds .none { font-style: italic; }
.eqs { font: 700 1rem var(--font-mono); color: var(--muted); }
.total { font: 800 1.9rem/1 var(--font-display); font-stretch: 75%; font-variant-numeric: tabular-nums; text-align: right; }
.eq.d .total { color: var(--dem); }
.eq.r .total { color: var(--rep); }
.tray.rolling .total { visibility: hidden; }
.tray.rolling .eq { opacity: 1; background: none; }
.math { grid-column: 1 / -1; font: 500 0.8rem var(--font-mono); color: var(--muted); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.result {
  grid-column: 1 / -1; font: 800 0.95rem var(--font-display); font-stretch: 85%; text-transform: uppercase;
  letter-spacing: 0.03em; padding: 6px 10px; border-radius: 6px; display: flex; justify-content: space-between; gap: 8px;
}
.result.d { background: var(--dem); color: var(--surface); }
.result.r { background: var(--rep); color: var(--surface); }
.result .flip { font: 700 0.72rem var(--font-body); letter-spacing: 0.08em; }
.solid-note { margin: 12px 0 0; font-size: 0.85rem; color: var(--muted); }
.solid-note b { color: var(--ink); }

/* house groups */
.group { grid-column: 1 / -1; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 14px; display: grid; gap: 10px; }
.group-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; align-items: baseline; }
.group-head b { font: 800 1.15rem var(--font-display); font-stretch: 80%; text-transform: uppercase; }
.group-head span { font: 500 0.85rem var(--font-mono); color: var(--muted); }
.mini { display: flex; flex-wrap: wrap; gap: 4px; }
.mini i {
  font: 700 0.68rem/1 var(--font-mono); font-style: normal; min-width: 44px; height: 26px; padding: 0 4px; border-radius: 5px;
  display: grid; place-items: center; color: var(--surface);
}
.mini i.d { background: var(--dem); }
.mini i.r { background: var(--rep); }

/* batch */
.runs-summary { display: flex; flex-wrap: wrap; gap: 10px 28px; margin-bottom: 16px; }
.stat { display: grid; }
.stat .v { font: 800 2rem/1 var(--font-display); font-stretch: 75%; font-variant-numeric: tabular-nums; }
.stat .v.d { color: var(--dem); }
.stat .v.r { color: var(--rep); }
.stat .k { font-size: 0.8rem; color: var(--muted); }
.runs-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 12px; margin-bottom: 16px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 14px; display: grid; gap: 12px; min-width: 0; align-content: start; }
.hist { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; align-items: end; gap: 3px; height: 170px; position: relative; padding-bottom: 20px; }
.bar { position: relative; height: 100%; display: flex; flex-direction: column; justify-content: end; }
.bar .fill { border-radius: 3px 3px 0 0; min-height: 0; }
.bar .fill.d { background: var(--dem); }
.bar .fill.r { background: var(--rep); }
.bar .n { font: 500 0.65rem var(--font-mono); text-align: center; color: var(--muted); }
.bar .x { position: absolute; bottom: -18px; left: 50%; transform: translateX(-50%); font: 500 0.65rem var(--font-mono); color: var(--muted); white-space: nowrap; }
.odds { display: grid; gap: 6px; }
.orow { display: grid; grid-template-columns: 34px 1fr 42px; gap: 8px; align-items: center; font: 500 0.8rem var(--font-mono); }
.orow .track { height: 12px; background: var(--rep); border-radius: 3px; position: relative; overflow: hidden; }
.orow .track .fill { position: absolute; inset: 0 auto 0 0; background: var(--dem); }
.orow .track .exp { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--ink); }
.orow .pct { text-align: right; font-variant-numeric: tabular-nums; }
.odds-key { font-size: 0.75rem; color: var(--muted); }
.tiles { display: grid; grid-template-columns: repeat(10, 1fr); gap: 4px; }
.tile {
  border: 0; border-radius: 5px; padding: 8px 0; cursor: pointer; color: var(--surface);
  font: 700 0.85rem var(--font-mono); font-variant-numeric: tabular-nums;
}
.tile.d { background: var(--dem); }
.tile.r { background: var(--rep); }
.tile[aria-current="true"] { outline: 3px solid var(--accent); outline-offset: 1px; }
.foot { font-size: 0.8rem; color: var(--muted); border-top: 1px solid var(--line); padding-top: 16px; }

/* settings */
dialog {
  border: 1px solid var(--line); border-radius: 14px; padding: 0; background: var(--surface); color: var(--ink);
  width: min(620px, calc(100% - 32px)); max-height: calc(100% - 32px);
}
dialog::backdrop { background: rgb(0 0 0 / 0.45); }
.set { padding: 20px; display: grid; gap: 18px; }
.set-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; position: sticky; top: -20px; background: var(--surface); padding-block: 8px; z-index: 1; }
fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin: 0; display: grid; gap: 10px; min-width: 0; }
legend { font: 800 0.95rem var(--font-display); text-transform: uppercase; letter-spacing: 0.04em; padding: 0 6px; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.row.check { justify-content: start; }
input[type="number"], select {
  font: 500 0.95rem var(--font-mono); padding: 6px 8px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--bg); color: var(--ink); width: 110px;
}
input[type="range"] { flex: 1 1 200px; accent-color: var(--accent); }
input[type="checkbox"] { accent-color: var(--accent); width: 18px; height: 18px; }
#shift-label { font: 700 1rem var(--font-mono); min-width: 5ch; }
.shift-ends { display: flex; justify-content: space-between; font-size: 0.75rem; }
.shift-ends .d { color: var(--dem); }
.shift-ends .r { color: var(--rep); }
.help { margin: 0; font-size: 0.82rem; color: var(--muted); }
.odds-table { overflow-x: auto; }
.odds-table table { border-collapse: collapse; width: 100%; font: 500 0.82rem var(--font-mono); font-variant-numeric: tabular-nums; }
.odds-table th, .odds-table td { padding: 4px 6px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
.odds-table td.d { color: var(--dem); }
.odds-table td.r { color: var(--rep); }
.odds-table th:first-child, .odds-table td:first-child { text-align: left; }
.ratings { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 6px 12px; }
.ratings label { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 0.85rem; }
.ratings select { width: 100px; font-size: 0.8rem; padding: 4px 6px; }
.set-foot { display: flex; justify-content: end; }

@media (max-width: 560px) {
  h1 { font-size: 2rem; }
  .count .num { font-size: 2.4rem; }
  .tally { grid-template-columns: auto auto; }
  .verdict { grid-column: 1 / -1; grid-row: 2; }
  .strip.house { grid-template-columns: repeat(58, 1fr); }
  .tiles { grid-template-columns: repeat(5, 1fr); }
  .actions { width: 100%; }
  .actions .btn { flex: 1 1 auto; }
}
@media (prefers-reduced-motion: reduce) {
  .die.spin { animation: none; }
}
