/* Bibb voter turnout — sister-site palette to bibbunited.com.
 * Light is "Community" mode (white canvas, navy + crimson). Dark is
 * "Urgent" mode (slate-900 canvas, lifted red). Both modes share one DOM;
 * tokens are the only thing that changes between them. */

:root {
  /* Light "Community" mode — mirrors bibbunited.com defaults. */
  --bg: #ffffff;
  --surface: #ffffff;
  --ink: #111827;
  --ink-soft: #4b5563;
  --ink-muted: #6b7280;
  --accent: #dc2626;
  --accent-soft: rgba(220, 38, 38, 0.08);
  --navy: #1b2a4a;
  --navy-soft: rgba(27, 42, 74, 0.08);
  /* Kicker is navy in light (civic-identity moment on white canvas), but
   * navy disappears on the slate-900 dark canvas — dark mode swaps to a
   * soft slate so the kicker stays legible without competing with the
   * crimson hero numeral. */
  --kicker-ink: var(--navy);
  --rule: #d1d5db;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 4px 12px rgba(15, 23, 42, 0.04);
  --radius: 12px;
  --max-w: 1080px;

  /* Chart palette — read by app.js via getComputedStyle so Chart.js options
   * stay theme-aware without duplicating the token table in JS. */
  --chart-grid: rgba(17, 24, 39, 0.06);
  --chart-tick: #4b5563;
  --chart-ring: #ffffff;
  /* "Remaining capacity" fill for meter-style charts (turnout pie). Tuned
   * to read as background, not data, so a tiny accent slice lands visually. */
  --chart-empty: rgba(17, 24, 39, 0.06);
}

/* Dark "Urgent" mode — mirrors bibbunited.com [data-mode="urgent"].
 * Slate-900 canvas, slate-800 surfaces, lifted Tailwind red-500 accent.
 * The accent is brighter than light mode for AA contrast on the dark
 * canvas while staying recognisably the brand red. */
:root[data-theme="dark"] {
  --bg: #0f172a;
  --surface: #1e293b;
  --ink: #f8fafc;
  --ink-soft: #cbd5e1;
  --ink-muted: #94a3b8;
  --accent: #ef4444;
  --accent-soft: rgba(239, 68, 68, 0.18);
  --navy: #1b2a4a;
  --navy-soft: rgba(255, 255, 255, 0.06);
  --kicker-ink: #cbd5e1;
  --rule: #334155;
  --shadow: none;
  --chart-grid: rgba(248, 250, 252, 0.06);
  --chart-tick: #94a3b8;
  --chart-ring: #1e293b;
  --chart-empty: rgba(248, 250, 252, 0.06);
}

/* OS-level dark preference, only when no explicit ?theme=… override is set.
 * The :not([data-theme]) guard lets the URL flag win without flash. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #0f172a;
    --surface: #1e293b;
    --ink: #f8fafc;
    --ink-soft: #cbd5e1;
    --ink-muted: #94a3b8;
    --accent: #ef4444;
    --accent-soft: rgba(239, 68, 68, 0.18);
    --navy: #1b2a4a;
    --navy-soft: rgba(255, 255, 255, 0.06);
    --kicker-ink: #cbd5e1;
    --rule: #334155;
    --shadow: none;
    --chart-grid: rgba(248, 250, 252, 0.06);
    --chart-tick: #94a3b8;
    --chart-ring: #1e293b;
    --chart-empty: rgba(248, 250, 252, 0.06);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Source Serif 4", Georgia, Cambria, "Times New Roman", Times, serif;
  font-feature-settings: "ss01", "tnum";
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Sister-site typography: Barlow Condensed display, Source Serif body.
 * h1/h2 uppercase mirrors bibbunited's Community-mode heading treatment. */
h1, h2 {
  font-family: "Barlow Condensed", "Helvetica Neue", Arial, sans-serif;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.005em;
}

h3, h4 {
  font-family: "Barlow Condensed", "Helvetica Neue", Arial, sans-serif;
  font-weight: 700;
}

.container {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 0 1.5rem;
}

.hero {
  padding: 4rem 0 3rem;
}

.kicker {
  margin: 0 0 0.5rem;
  font-family: "Barlow Condensed", "Helvetica Neue", Arial, sans-serif;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--kicker-ink);
}

/* The hero numeral keeps Barlow Condensed for that late-edition headline
 * weight. tabular-nums via font-feature-settings stays critical for the
 * count-up animation so digit widths don't reflow. */
.total {
  margin: 0;
  font-family: "Barlow Condensed", "Helvetica Neue", Arial, sans-serif;
  font-size: clamp(3.5rem, 12vw, 7rem);
  font-weight: 700;
  line-height: 0.95;
  letter-spacing: -0.02em;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  text-transform: none;
}

.subtitle {
  margin: 0.5rem 0 0;
  font-size: 1.1rem;
  color: var(--ink-soft);
}

.meta {
  margin: 1.25rem 0 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  font-size: 0.9rem;
}

.delta {
  display: inline-block;
  padding: 0.25rem 0.65rem;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 999px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.updated,
#last-checked {
  color: var(--ink-muted);
}

main {
  padding: 2rem 0 3rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

/* Section-heading rule: 2px accent underline scoped to the title text,
 * lifted directly from bibbunited.com's .section-heading-rule utility. */
.card h2 {
  margin: 0 0 0.25rem;
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  display: inline-block;
  padding-bottom: 0.4rem;
  border-bottom: 2px solid var(--accent);
}

.caption {
  margin: 0.75rem 0 1.25rem;
  color: var(--ink-muted);
  font-size: 0.95rem;
}

.grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
}

@media (min-width: 720px) {
  .grid { grid-template-columns: 1fr 1fr; }
}

.chart-wrap {
  position: relative;
  height: 280px;
}

.chart-wrap.small {
  height: 240px;
}

.placeholder {
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  gap: 0.35rem;
}

.placeholder-num {
  margin: 0;
  font-family: "Barlow Condensed", "Helvetica Neue", Arial, sans-serif;
  font-size: 3.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.placeholder-label {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.95rem;
}

.placeholder-note {
  margin: 0.5rem 0 0;
  color: var(--ink-muted);
  font-size: 0.85rem;
  font-style: italic;
}

/* Compound selector beats `.container { padding: 0 1.5rem }` so the page-end
 * runway below the byline actually lands. Vertical padding is the real intent
 * here; the inline gutter still inherits from .container. */
footer.container {
  padding-top: 2rem;
  padding-bottom: 8rem;
}

/* The source citation is true fine-print — narrower, smaller, and more muted
 * than body copy. It anchors the data, but the page's voice belongs to the
 * byline below it. */
.footnote {
  margin: 1.25rem auto 0;
  max-width: 58ch;
  color: var(--ink-muted);
  font-size: 0.78rem;
  line-height: 1.55;
}

.footnote a {
  color: inherit;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}
.footnote a:hover {
  color: var(--ink);
}

/* Editorial sign-off. A hairline rule + generous space mark the page-end,
 * then a kicker/name pair echoes the hero kicker pattern at the top of the
 * page — bookending the layout. The byline outweighs the citation through
 * type system (Barlow Condensed display family + scale + weight contrast),
 * not through reordering. */
.byline {
  margin: 2.75rem auto 0;
  padding-top: 1.5rem;
  max-width: 58ch;
  border-top: 1px solid var(--rule);
  text-align: center;
}

.byline-kicker {
  display: block;
  margin-bottom: 0.35rem;
  font-family: "Barlow Condensed", "Helvetica Neue", Arial, sans-serif;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.byline-name {
  display: inline-block;
  font-family: "Barlow Condensed", "Helvetica Neue", Arial, sans-serif;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--kicker-ink);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  transition: border-color 160ms cubic-bezier(0.16, 1, 0.3, 1);
}

.byline-name:hover,
.byline-name:focus-visible {
  border-bottom-color: var(--accent);
  outline: none;
}

.empty p {
  margin: 0;
  color: var(--ink-muted);
  text-align: center;
  padding: 2rem 0;
}

.hidden { display: none; }

/* Staleness signal. Tier 1 (overnight, >14h since cron heartbeat): the
 * "updated" line italicizes + drops to muted tone — sober, unobtrusive,
 * matches an expected nightly gap. Tier 2 (>24h, almost certainly a cron
 * failure): the headline numeral itself desaturates from accent red to
 * --ink-soft, withdrawing the brand's "live" signal until the page can
 * re-confirm. Both tiers compose so a stale page reads stale at every scale. */
.updated.is-overnight,
.updated.is-stale,
#last-checked.is-overnight,
#last-checked.is-stale {
  font-style: italic;
  color: var(--ink-muted);
}

.total.is-stale {
  color: var(--ink-soft);
  transition: color 400ms cubic-bezier(0.22, 1, 0.36, 1);
}

/* Visually-hidden utility for canvas chart text alternatives. Standard a11y
 * recipe — keeps the node in the accessibility tree without consuming layout. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Future-proofing for the count-up motion the design contract calls for —
 * also catches any third-party transitions Chart.js might add via plugins. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
