/* ---------- tokens ---------- */
:root {
  --bg: #E9E5DC;
  --surface: #F7F4EE;
  --text: #211E19;
  --muted: #6E675C;
  --border: #CFC9BC;
  --accent: #D5232E;          /* DSA red */
  --accent-strong: #B31B24;
  --accent-ink: #FFFFFF;
  --focus: #1A56C4;
  /* the ballot is a physical object: paper stays paper in both themes */
  --paper: #FEFDFA;
  --ink: #17150F;
  --ink-muted: #5C5952;
  --rule: #17150F;
  --paper-dim: #F1EEE6;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #191714;
    --surface: #23201C;
    --text: #F0ECE3;
    --muted: #A39B8D;
    --border: #3B372F;
    --accent: #E4353F;
    --accent-strong: #F0555C;
    --focus: #7FA7F2;
    --paper: #F4F1E9;
    --paper-dim: #E9E5DA;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
.phone {
  max-width: 430px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}
a { color: var(--accent-strong); }
button { font: inherit; cursor: pointer; }
:is(button, a, input, summary):focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 2px;
}

/* ---------- app chrome ---------- */
.masthead {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 20px 12px;
  border-bottom: 3px solid var(--text);
}
.masthead .rose { font-size: 20px; line-height: 1; }
.masthead .wordmark {
  font-weight: 800;
  letter-spacing: .14em;
  text-transform: uppercase;
  font-size: 14px;
}
.masthead .proto {
  margin-left: auto;
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}

.screen { display: none; flex: 1; flex-direction: column; }
.screen.active { display: flex; }

/* Available to screen readers, absent from the layout. Used for per-screen
   headings that would be redundant on screen but give assistive tech a
   landing point and a sane heading order. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* Headings receive focus programmatically on screen change; they aren't in
   the tab order, so a persistent ring would only ever be confusing. */
[tabindex="-1"]:focus { outline: none; }

/* ---------- landing ---------- */
.landing { padding: 36px 20px 28px; gap: 22px; }
.landing h1 {
  margin: 0;
  font-size: clamp(30px, 8.5vw, 38px);
  line-height: 1.06;
  font-weight: 900;
  letter-spacing: -0.015em;
  text-wrap: balance;
}
.landing h1 .red { color: var(--accent); }
.landing .sub { margin: 0; color: var(--muted); font-size: 16px; max-width: 34ch; }

.btn-primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 17px 20px;
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: .02em;
}
.btn-primary:active { background: var(--accent-strong); }
.btn-primary svg { flex: none; }

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: .12em;
  text-transform: uppercase;
}
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

.lookup-form {
  display: grid;
  grid-template-columns: 5.4rem 1fr 4rem;
  gap: 12px 10px;
}
.lookup-form .f-street { grid-column: 1 / -1; }
.lookup-form button { grid-column: 1 / -1; }
.lookup-form label {
  display: block;
  margin-bottom: 5px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}
.lookup-form .f-state input { text-transform: uppercase; text-align: center; padding-inline: 4px; }
.lookup-form .f-zip input { text-align: center; padding-inline: 4px; }
.lookup-form input {
  min-width: 0;
  width: 100%;
  padding: 15px 14px;
  font-size: 17px;
  letter-spacing: .05em;
  border: 2px solid var(--text);
  background: var(--surface);
  color: var(--text);
  border-radius: 0;
}
.lookup-form input.invalid { border-color: var(--accent-strong); }
.lookup-form button {
  padding: 15px 20px;
  background: var(--text);
  color: var(--bg);
  border: none;
  font-weight: 700;
  font-size: 16px;
}
.field-error { color: var(--accent-strong); font-size: 14px; margin: -12px 0 0; display: none; }
.field-error.show { display: block; }
.why-address { margin: -8px 0 0; color: var(--muted); font-size: 13px; max-width: 42ch; }

.privacy {
  margin-top: auto;
  padding-top: 24px;
  color: var(--muted);
  font-size: 13px;
  max-width: 40ch;
}

/* ---------- locating ---------- */
.locating { align-items: center; justify-content: center; gap: 18px; padding: 40px 24px; text-align: center; }
.spinner {
  width: 44px; height: 44px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.locating p { margin: 0; font-weight: 700; font-size: 17px; }
.locating .fine { font-weight: 400; color: var(--muted); font-size: 14px; }

/* ---------- results ---------- */
.results { padding-bottom: 40px; }
.locbar {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.locbar .where { font-weight: 700; }
.locbar button {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--accent-strong);
  font-weight: 700;
  font-size: 14px;
  text-decoration: underline;
  padding: 2px;
}

.offline-note {
  margin: 0;
  padding: 11px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: 13.5px;
}
.offline-note strong { color: var(--text); }

/* ---------- the ballot ---------- */
.ballot {
  margin: 16px 12px 0;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--rule);
  box-shadow: 0 1px 0 var(--border), 0 6px 18px rgba(0,0,0,.12);
}
.ballot-mast {
  padding: 14px 16px 12px;
  border-bottom: 4px double var(--rule);
  text-align: center;
}
.ballot-mast .kicker {
  font-size: 11px;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--ink-muted);
}
.ballot-mast h2 {
  margin: 4px 0 2px;
  font-family: "Arial Narrow", "Helvetica Neue", Arial, sans-serif;
  font-size: 22px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .01em;
}
.ballot-mast .when { font-size: 13px; color: var(--ink-muted); }
.ballot-mast .party-note {
  margin: 8px auto 0;
  max-width: 46ch;
  font-size: 12.5px;
  font-style: italic;
  color: var(--ink-muted);
}

.etabs { display: flex; border-bottom: 1.5px solid var(--rule); }
.etabs button {
  flex: 1;
  padding: 9px 8px;
  background: var(--paper-dim);
  color: var(--ink);
  border: none;
  border-left: 1px solid var(--rule);
  font-size: 12.5px;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
}
.etabs button:first-child { border-left: none; }
.etabs button.on { background: var(--ink); color: var(--paper); }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  padding: 10px 16px;
  border-bottom: 1.5px solid var(--rule);
  font-size: 12.5px;
  background: var(--paper-dim);
}
.legend span { display: inline-flex; align-items: center; gap: 7px; }

.oval {
  flex: none;
  width: 24px; height: 13px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: transparent;
  display: inline-block;
}
.oval.filled { background: var(--accent); border-color: var(--accent); }
.oval.rec { border-color: var(--accent); }

.race { border-bottom: 1.5px solid var(--rule); }
.race:last-child { border-bottom: none; }
.race-head {
  background: var(--ink);
  color: var(--paper);
  padding: 7px 16px 6px;
}
.race-head h3 {
  margin: 0;
  font-family: "Arial Narrow", "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.race-head .instr { font-size: 11.5px; font-style: italic; opacity: .85; }

.cand { border-top: 1px solid color-mix(in srgb, var(--ink) 25%, transparent); }
.cand:first-of-type { border-top: none; }
.cand-row {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 12px 16px;
}
.cand-row .who { min-width: 0; }
.cand-row .name { font-weight: 700; font-size: 16.5px; }
.cand-row .party { font-size: 12.5px; color: var(--ink-muted); }
.cand.other .name { font-weight: 400; color: var(--ink-muted); }

.chip {
  margin-left: auto;
  flex: none;
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: .1em;
  text-transform: uppercase;
  padding: 4px 8px 3px;
}
.chip.endorsed { background: var(--accent); color: #fff; }
.chip.rec { background: transparent; color: var(--accent-strong); border: 1.5px solid var(--accent); }

/* Built from a button rather than <details>/<summary>: Safari strips the
   summary's semantics once its list-item display is overridden, and
   VoiceOver then treats the control as plain text — unreadable and
   unclickable. An explicit button keeps the semantics under our control. */
.why { padding: 0 16px 10px 53px; }
.why-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  /* Padding, not size: clears the 44px target without looking bigger. */
  padding: 11px 4px;
  margin-left: -4px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--accent-strong);
  text-align: left;
}
/* Drawn, not written — a text arrow would be read aloud as "right arrow". */
.why-toggle::before {
  content: "";
  flex: none;
  width: 0;
  height: 0;
  border: 5px solid transparent;
  border-left-color: currentColor;
  transition: transform .15s ease;
}
.why-toggle[aria-expanded="true"]::before { transform: rotate(90deg) translateX(2px); }
.why-body p { margin: 0 0 4px; font-size: 14px; color: var(--ink-muted); max-width: 60ch; }

@media (prefers-reduced-motion: reduce) {
  .why-toggle::before { transition: none; }
}

.no-pick { padding: 11px 16px; font-size: 13.5px; color: var(--ink-muted); font-style: italic; }

.section-note {
  margin: 0;
  padding: 10px 16px;
  background: var(--paper-dim);
  border-top: 1.5px solid var(--rule);
  border-bottom: 1.5px solid var(--rule);
  font-size: 12.5px;
  font-style: italic;
  color: var(--ink-muted);
}
.race + .section-note { border-top: none; }

.results .foot {
  padding: 18px 20px 0;
  font-size: 12.5px;
  color: var(--muted);
  max-width: 46ch;
}

@media (prefers-reduced-motion: reduce) {
  .spinner { animation: none; border-top-color: var(--border); }
}
