/* SparkReach results page. Tokens first; dark mode follows the system unless the
   reader picks a theme (data-theme on <html>). */
:root {
  --brand-orange: #FF914D;
  --brand-navy: #0E5792;
  --link: #2563EB;
  --cta: #F59E0B;
  --cta-ink: #1E293B;

  --bg: #F8FAFC;
  --surface: #FFFFFF;
  --surface-2: #F1F5F9;
  --border: #E2E8F0;
  --ink: #1E293B;
  --muted: #475569;
  --faint: #94A3B8;

  --dem: #2563EB;
  --rep: #DC2626;
  --other: #A8A29E;
  --lead: #7C3AED;
  --second: #94A3B8;
  --yes: #0F766E;
  --no: #B45309;
  --empty: #E2E8F0;

  --ok-bg: #DCFCE7; --ok-ink: #166534;
  --warn-bg: #FEF3C7; --warn-ink: #92400E;
  --info-bg: #E0F2FE; --info-ink: #075985;
  --neutral-bg: #F1F5F9; --neutral-ink: #475569;

  --radius: 10px;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --link: #60A5FA; --brand-navy: #7DB4E6;
    --bg: #0B1220; --surface: #111A2B; --surface-2: #17223A; --border: #24324D;
    --ink: #E2E8F0; --muted: #A3B1C6; --faint: #64748B;
    --dem: #3B82F6; --rep: #EF4444; --other: #78716C; --lead: #8B5CF6; --second: #64748B;
    --yes: #14B8A6; --no: #F59E0B; --empty: #24324D;
    --ok-bg: #14532D; --ok-ink: #BBF7D0; --warn-bg: #713F12; --warn-ink: #FDE68A;
    --info-bg: #0C4A6E; --info-ink: #BAE6FD; --neutral-bg: #1E293B; --neutral-ink: #CBD5E1;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --link: #60A5FA; --brand-navy: #7DB4E6;
  --bg: #0B1220; --surface: #111A2B; --surface-2: #17223A; --border: #24324D;
  --ink: #E2E8F0; --muted: #A3B1C6; --faint: #64748B;
  --dem: #3B82F6; --rep: #EF4444; --other: #78716C; --lead: #8B5CF6; --second: #64748B;
  --yes: #14B8A6; --no: #F59E0B; --empty: #24324D;
  --ok-bg: #14532D; --ok-ink: #BBF7D0; --warn-bg: #713F12; --warn-ink: #FDE68A;
  --info-bg: #0C4A6E; --info-ink: #BAE6FD; --neutral-bg: #1E293B; --neutral-ink: #CBD5E1;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 15px; line-height: 1.4; }
a { color: var(--link); }
h1, h2, h3 { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
[hidden] { display: none !important; }

.wrap { max-width: 1200px; margin: 0 auto; padding: 0 16px; }

/* Header */
.site-header { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.header-row { display: flex; align-items: center; justify-content: space-between; height: 52px; }
.logo img { display: block; height: 26px; width: auto; }
.logo-dark { display: none !important; }
:root[data-theme="dark"] .logo-light { display: none !important; }
:root[data-theme="dark"] .logo-dark { display: block !important; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .logo-light { display: none !important; }
  :root:not([data-theme="light"]) .logo-dark { display: block !important; }
}
.header-actions { display: flex; gap: 4px; }
.icon-button { display: inline-flex; align-items: center; gap: 6px; border: 1px solid transparent; background: none; color: var(--muted); padding: 6px 8px; border-radius: 8px; font: inherit; font-size: 13px; cursor: pointer; transition: background .15s, color .15s; }
.icon-button:hover { background: var(--surface-2); color: var(--ink); }
.icon-button:focus-visible, .link-button:focus-visible, .race-title:focus-visible, summary:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }

.banner { padding: 8px 16px; text-align: center; font-size: 13px; font-weight: 600; }
.banner-preview { background: var(--warn-bg); color: var(--warn-ink); }
.banner-archived { background: var(--info-bg); color: var(--info-ink); }

/* Title */
.title-block { padding: 16px 0 8px; }
h1 { font-size: 19px; line-height: 1.25; letter-spacing: -0.01em; }
.updated { margin: 6px 0 0; font-size: 13px; display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; }
#updated-at { font-weight: 600; }
.link-button { background: none; border: 0; padding: 0; color: var(--link); font: inherit; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.warning { margin: 8px 0 0; padding: 8px 10px; border-radius: 8px; background: var(--warn-bg); color: var(--warn-ink); font-size: 13px; }

/* Section nav (mobile jump chips) */
.section-nav { display: flex; gap: 6px; overflow-x: auto; padding: 4px 0 10px; scrollbar-width: none; position: sticky; top: 52px; z-index: 5; background: var(--bg); }
.section-nav::-webkit-scrollbar { display: none; }
.section-nav a { flex: none; font-size: 12px; font-weight: 600; text-decoration: none; color: var(--muted); background: var(--surface); border: 1px solid var(--border); padding: 4px 10px; border-radius: 999px; }
.section-nav a:hover { color: var(--ink); border-color: var(--faint); }

/* Sections */
.group { margin: 8px 0 18px; scroll-margin-top: 112px; } /* clear the sticky header and section chips */
.group-note { margin: 0 0 8px; font-size: 13px; color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.group > summary { list-style: none; cursor: pointer; display: flex; align-items: baseline; gap: 8px; padding: 6px 0; font-size: 15px; font-weight: 700;  }
.group > summary::-webkit-details-marker { display: none; }
.group > summary::before { content: "▸"; color: var(--faint); transition: transform .15s; display: inline-block; }
.group[open] > summary::before { transform: rotate(90deg); }
.group-count { font-size: 12px; font-weight: 500; color: var(--muted); }
.featured-heading { font-size: 15px; font-weight: 700; padding: 6px 0; }

.race-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }

/* Race card */
.race { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; transition: border-color .15s, box-shadow .15s; }
.race:hover { border-color: var(--faint); }
.race.updated-flash { animation: flash 1.2s ease-out; }
@keyframes flash { from { box-shadow: 0 0 0 3px color-mix(in srgb, var(--link) 35%, transparent); } to { box-shadow: 0 0 0 0 transparent; } }
@media (prefers-reduced-motion: reduce) { .race.updated-flash { animation: none; } }

.race-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.race-head h3 { min-width: 0; font-size: inherit; }
.race-title { overflow-wrap: anywhere; display: inline; background: none; border: 0; padding: 0; margin: 0; color: var(--ink); font: inherit; font-size: 15px; font-weight: 700; text-align: left; cursor: pointer; }
.race-title:hover .chevron { color: var(--ink); }
.chevron { display: inline-block; margin-left: 4px; font-size: 11px; color: var(--faint); transition: transform .15s; }
.race-title[aria-expanded="true"] .chevron { transform: rotate(180deg); }
a.chip { text-decoration: none; }
a.chip:hover { filter: brightness(0.97); text-decoration: underline; }
.race-label { font-size: 12px; font-weight: 500; color: var(--muted); margin-left: 6px; white-space: nowrap; }
.chip { flex: none; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--neutral-bg); color: var(--neutral-ink); white-space: nowrap; }
.chip.counting { background: var(--warn-bg); color: var(--warn-ink); }
.chip.called, .chip.final_unofficial, .chip.certified { background: var(--ok-bg); color: var(--ok-ink); }
.chip.warn { background: var(--warn-bg); color: var(--warn-ink); }

.bar { position: relative; display: flex; height: 22px; margin: 8px 0 6px; border-radius: 6px; overflow: hidden; background: var(--empty); }
.seg { display: flex; align-items: center; min-width: 0; color: #fff; font-size: 12px; font-weight: 700; padding: 0 6px; transition: flex-basis .6s ease; white-space: nowrap; overflow: hidden; }
.seg:last-child { justify-content: flex-end; }
.seg.d { background: var(--dem); } .seg.r { background: var(--rep); }
.seg.other { background: var(--other); padding: 0; }
.seg.lead { background: var(--lead); } .seg.second { background: var(--second); }
.seg.yes { background: var(--yes); } .seg.no { background: var(--no); }
.seg.winner::after { content: " ✓"; }
.bar-empty { display: flex; align-items: center; padding: 0 8px; font-size: 12px; color: var(--muted); }

.race-meta { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 12px; color: var(--muted); }
.meta-left { display: flex; flex-wrap: wrap; gap: 0 6px; min-width: 0; }
.meta-left > span + span::before { content: "·"; margin-right: 6px; color: var(--faint); }
.gain { color: var(--ink); font-weight: 600; }
.source-link { flex: none; color: var(--link); text-decoration: none; font-weight: 600; white-space: nowrap; }
.source-link:hover { text-decoration: underline; }
.note { font-size: 12px; color: var(--muted); font-style: italic; }
.card-note { margin-top: 6px; font-size: 12px; color: var(--muted); }
.stale-note { margin-top: 6px; font-size: 12px; color: var(--warn-ink); background: var(--warn-bg); border-radius: 6px; padding: 4px 8px; }
.call-line { margin-top: 6px; font-size: 12px; color: var(--ok-ink); font-weight: 600; }
.call-line a { color: inherit; }
.call-line.retracted { color: var(--muted); text-decoration: line-through; font-weight: 500; }

.race-details { margin-top: 8px; border-top: 1px solid var(--border); padding-top: 8px; font-size: 13px; }
.race-details table { width: 100%; border-collapse: collapse; }
.race-details td, .race-details th { padding: 3px 0; text-align: left; }
.race-details th { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.race-details td.num, .race-details th.num { text-align: right; font-variant-numeric: tabular-nums; }
.race-details .party { color: var(--muted); font-size: 12px; }
.race-details dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin: 8px 0 0; font-size: 12px; }
.race-details dt { color: var(--muted); }
.race-details dd { margin: 0; }

/* Balance of power strip */
.chambers { display: grid; grid-template-columns: 1fr; gap: 6px; margin: 4px 0 12px; }
.chamber-group-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-top: 2px; }
.chamber { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 10px; }
.chamber-head { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; font-size: 12px; }
.chamber-name { font-weight: 700; }
.chamber-counts { font-variant-numeric: tabular-nums; color: var(--muted); }
.chamber-counts .d { color: var(--dem); font-weight: 700; }
.chamber-counts .r { color: var(--rep); font-weight: 700; }
.chamber-bar { position: relative; display: flex; height: 8px; margin: 6px 0 4px; border-radius: 4px; background: var(--empty); overflow: visible; }
.chamber-bar .cd { background: var(--dem); border-radius: 4px 0 0 4px; }
.chamber-bar .cr { background: var(--rep); border-radius: 0 4px 4px 0; margin-left: auto; }
.chamber-bar .tick { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--ink); }
.chamber-bar .tick.super { background: var(--muted); }
.chamber-foot { display: flex; justify-content: space-between; gap: 6px; font-size: 11px; color: var(--muted); }

/* Footer + CTA */
.site-footer { margin: 28px 0 40px; display: grid; gap: 16px; }
.methodology { font-size: 13px; color: var(--muted); }
.methodology h2 { font-size: 14px; color: var(--ink); margin-bottom: 6px; }
.methodology p { margin: 0 0 8px; }
.cta { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; display: grid; gap: 8px; justify-items: start; }
.cta img { height: 22px; width: auto; }
.cta p { margin: 0; font-size: 14px; }
.cta-button { display: inline-block; background: var(--cta); color: var(--cta-ink); font-weight: 700; text-decoration: none; padding: 9px 16px; border-radius: 8px; transition: transform .1s, filter .15s; }
.cta-button:hover { filter: brightness(1.05); transform: translateY(-1px); }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 8px 14px; border-radius: 8px; font-size: 13px; z-index: 20; }

.skeleton { height: 92px; border-radius: var(--radius); background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 50%, var(--surface) 75%); background-size: 200% 100%; animation: shimmer 1.4s infinite; margin-bottom: 8px; border: 1px solid var(--border); }
@keyframes shimmer { to { background-position: -200% 0; } }

.offline-message { text-align: center; padding: 48px 16px; }
.offline-message h2 { font-size: 18px; margin-bottom: 8px; }

/* Desktop */
@media (min-width: 768px) {
  body { font-size: 15px; }
  h1 { font-size: 24px; }
  .icon-button-label { display: inline; }
  .section-nav { position: static; }
  .group { scroll-margin-top: 64px; }
  .race-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .chambers { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
  .chamber-group-label { display: none; }
  .site-footer { grid-template-columns: 3fr 2fr; align-items: start; }
}
@media (min-width: 1280px) {
  .race-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 767px) {
  .icon-button-label { display: none; }
}
