:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --ink: #16202a;
  --ink-soft: #5b6875;
  --line: #e5e8ec;
  --brand: #14563d;         /* deep evergreen */
  --brand-ink: #0d3a29;
  --agree-bg: #d7f0dc;
  --agree-ink: #14663a;
  --dissent-bg: #fbdcdc;
  --dissent-ink: #9e2a2a;
  --neutral-bg: #fef3d3;
  --neutral-ink: #8a6a1a;
  --na-bg: #f0f1f3;
  --shadow: 0 1px 2px rgba(16,32,42,.06), 0 8px 24px rgba(16,32,42,.05);
  --radius: 14px;
  --group-h: 30px;
  font-synthesis: none;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: 1180px; margin: 0 auto; padding: 0 20px; }

.masthead {
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-ink) 100%);
  color: #fff;
  padding: 34px 0 30px;
}
.masthead h1 { margin: 0; font-size: 2rem; font-weight: 750; letter-spacing: -0.02em; }
.tagline { margin: 6px 0 0; color: #cfe6da; font-weight: 500; }

main.wrap { padding-top: 22px; padding-bottom: 60px; }

.notice { padding: 40px; text-align: center; color: var(--ink-soft); }
.notice.error { color: var(--dissent-ink); }

.banner {
  background: var(--neutral-bg);
  color: var(--neutral-ink);
  border: 1px solid #f0dfa8;
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 18px;
  font-size: .92rem;
}
.banner code, .notice code { background: rgba(0,0,0,.06); padding: 1px 5px; border-radius: 5px; font-size: .9em; }

/* Control bar — view toggles that filter which source squares the cards show */
.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 24px;
  padding: 12px 16px;
  margin-bottom: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.toggle {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  cursor: pointer;
  user-select: none;
  font-size: .88rem;
  font-weight: 600;
  color: var(--ink);
}
.toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.toggle-track {
  position: relative;
  flex: none;
  width: 38px;
  height: 22px;
  border-radius: 999px;
  background: #cbd2d9;
  transition: background .15s ease;
}
.toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(16,32,42,.3);
  transition: transform .15s ease;
}
.toggle input:checked + .toggle-track { background: var(--brand); }
.toggle input:checked + .toggle-track .toggle-thumb { transform: translateX(16px); }
.toggle input:focus-visible + .toggle-track { outline: 2px solid var(--brand); outline-offset: 2px; }

.legend {
  display: flex;
  align-items: center;
  gap: 8px 14px;
  flex-wrap: wrap;
  font-size: .84rem;
  color: var(--ink-soft);
  margin-bottom: 14px;
}
.legend .swatch { width: 14px; height: 14px; border-radius: 4px; display: inline-block; margin-left: 6px; vertical-align: -2px; }
.legend .swatch:first-child { margin-left: 0; }
.swatch.agree { background: var(--agree-bg); }
.swatch.dissent { background: var(--dissent-bg); }
.swatch.neutral { background: var(--neutral-bg); }
.swatch.blank { background: var(--surface); border: 1px solid var(--line); }
.legend .meta { margin-left: auto; font-variant-numeric: tabular-nums; }

.table-scroll {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

table.grid {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  min-width: 900px;
  font-size: .875rem;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: #fbfcfd;
  color: var(--ink-soft);
  font-weight: 650;
  text-align: center;
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  white-space: normal;
  vertical-align: bottom;
  line-height: 1.2;
}
thead th:not(.race-col) {
  min-width: 82px;
  max-width: 100px;
}

/* Grouping band above the outlet names */
.group-head {
  top: 0;
  height: var(--group-h);
  box-sizing: border-box;
  padding: 0 8px;
  background: #edf1f3;
  color: var(--brand-ink);
  font-size: .66rem;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
  vertical-align: middle;
  border-left: 2px solid #fff;
  border-bottom: 1px solid var(--line);
  z-index: 3;
}
.group-head:first-of-type { border-left: none; }
.outlet-row th { top: var(--group-h); z-index: 3; }
.outlet-row th:not(:first-child) { border-left: 1px solid var(--line); }
thead th.race-col { z-index: 4; top: 0; }

/* Merged "To be released" column for outlets whose endorsements aren't out yet */
thead th.pending-head {
  top: 0;
  min-width: 132px;
  max-width: 150px;
  background: #e7eaed;
  border-left: 2px solid #fff;
  vertical-align: middle;
  padding: 8px 10px;
}
.pending-title {
  display: block;
  font-size: .78rem;
  font-weight: 700;
  color: var(--ink);
  text-transform: none;
  letter-spacing: 0;
}
.pending-names {
  display: block;
  margin-top: 4px;
  font-size: .64rem;
  font-weight: 500;
  line-height: 1.35;
  color: var(--ink-soft);
  text-transform: none;
  letter-spacing: 0;
}
td.pending-cell {
  background: #eef1f3;
  border-left: 1px solid var(--line);
  /* no inner row borders so the column reads as one continuous block */
}
thead th a { color: var(--brand); text-decoration: none; }
thead th a:hover { text-decoration: underline; }

th.race-col {
  position: sticky;
  left: 0;
  z-index: 2;
  background: #fbfcfd;
  text-align: left;
  min-width: 100px;
  max-width: 260px;
}
thead th.race-col { z-index: 4; }

tbody th.race-col { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.office { display: block; font-weight: 650; color: var(--ink); }
.district { display: block; font-size: .76rem; color: var(--ink-soft); font-weight: 500; margin-top: 1px; }

.section-row td {
  background: var(--brand);
  color: #fff;
  font-weight: 650;
  font-size: .78rem;
  letter-spacing: .06em;
  text-transform: uppercase;
  padding: 7px 14px;
  position: sticky;
  left: 0;
}

td.cell {
  text-align: center;
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  border-left: 1px solid var(--line);
  vertical-align: middle;
}
td.cell .cand { font-weight: 600; }
.cand-name { display: block; }
/* In a dual endorsement that meets consensus, the pick that is NOT part of the
   consensus is reddened and faded so it isn't read as agreement. */
.cand-name.against { color: var(--dissent-ink); opacity: .48; }

/* Dual endorsements: stacked names (no "/" separator) plus a badge, so they
   don't get confused with slash-containing names like "Yes / Approve". */
.cand.is-dual .cand-name + .cand-name { margin-top: 2px; }
.dual-badge {
  display: inline-block;
  margin-bottom: 3px;
  padding: 0 5px;
  border-radius: 5px;
  background: rgba(16, 32, 42, .10);
  color: #455360;
  font-size: .52rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  line-height: 1.55;
}

td.agree   { background: var(--agree-bg); color: var(--agree-ink); }
td.dissent { background: var(--dissent-bg); color: var(--dissent-ink); }
td.neutral { background: var(--neutral-bg); color: var(--neutral-ink); }
td.blank   { background: var(--surface); }
td.na      { background: var(--na-bg); color: #b3bac2; }

tbody tr:hover td.cell:not(.na) { filter: brightness(0.975); }

.foot { margin-top: 16px; color: var(--ink-soft); font-size: .8rem; }
.foot p { margin: 0; }

@media (max-width: 640px) {
  .masthead h1 { font-size: 1.55rem; }
  .legend .meta { margin-left: 0; width: 100%; }
  .wrap { padding: 0 14px; }
}

/* ============================================================
   Card view — the sole layout at every width. Mobile-first: cards
   stack vertically (info, then squares, then button). On wider
   screens (>= 641px) each card reflows horizontally — race info on
   the left, squares + "More info" on the right — for compact rows.
   ============================================================ */
.cards { margin-top: 2px; }

.m-section {
  margin: 16px 0 7px;
  font-size: .74rem;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--brand);
}
.m-section:first-child { margin-top: 6px; }

.race-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 11px 14px 10px;
  margin-bottom: 9px;
  cursor: pointer;
  transition: border-color .12s ease, box-shadow .12s ease, transform .12s ease;
}
.race-card:hover {
  border-color: rgba(20, 86, 61, .38);
  box-shadow: 0 2px 6px rgba(16,32,42,.10), 0 14px 30px rgba(16,32,42,.09);
}
.race-card:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.rc-head { text-align: center; }
.rc-office { display: block; font-weight: 700; font-size: 1rem; color: var(--ink); }
.rc-district { display: block; font-size: .78rem; color: var(--ink-soft); margin-top: 1px; }

.rc-consensus {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 1px;
  min-height: 36px;
  margin: 7px 0 9px;
}
.rc-pick-label {
  font-size: .58rem;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.rc-name {
  font-size: 1.35rem;
  font-weight: 750;
  line-height: 1.12;
  letter-spacing: -0.01em;
  color: var(--brand-ink);
  text-align: center;
}
.rc-badge {
  display: inline-block;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: .8rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
}
.rc-badge.split { background: var(--neutral-bg); color: var(--neutral-ink); }
.rc-badge.awaiting { background: var(--na-bg); color: var(--ink-soft); }

/* Squares clustered by outlet group, each cluster in a dotted enclosure */
.rc-squares {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.sq-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 9px 11px 10px;
  border: 1.5px dotted rgba(20, 86, 61, .32);
  border-radius: 16px;
}
.sq-group-label {
  font-size: .56rem;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--brand-ink);
  text-align: center;
}
.sq-group-items {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 7px 8px;
}
.sq-item {
  width: 52px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  text-align: center;
}
.sq {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  flex: none;
}
.sq.agree   { background: var(--agree-bg);   box-shadow: inset 0 0 0 1px rgba(20,102,58,.28); }
.sq.dissent { background: var(--dissent-bg); box-shadow: inset 0 0 0 1px rgba(158,42,42,.28); }
.sq.neutral { background: var(--neutral-bg); box-shadow: inset 0 0 0 1px rgba(138,106,26,.30); }
.sq.blank   { background: var(--surface);    box-shadow: inset 0 0 0 1px var(--line); }

/* Agree / dissent read as check / cross boxes */
.sq.agree, .swatch.agree, .sq.dissent, .swatch.dissent { position: relative; }
.sq.agree::after, .swatch.agree::after,
.sq.dissent::after, .swatch.dissent::after {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  line-height: 1;
}
.sq.agree::after,   .swatch.agree::after   { content: "✓"; color: var(--agree-ink); }
.sq.dissent::after, .swatch.dissent::after { content: "✕"; color: var(--dissent-ink); }
.sq.agree::after   { font-size: 12px; }
.sq.dissent::after { font-size: 11px; }
.swatch.agree::after   { font-size: 10px; }
.swatch.dissent::after { font-size: 9px; }
.sq-label {
  font-size: .58rem;
  line-height: 1.15;
  color: var(--ink-soft);
  font-weight: 500;
  word-break: break-word;
}

/* Non-interactive affordance — the whole card is the click target */
.rc-more-hint {
  display: block;
  margin-top: 10px;
  text-align: center;
  color: var(--brand);
  font-weight: 650;
  font-size: .85rem;
}
.rc-more-hint .chev { font-weight: 700; }
.race-card:hover .rc-more-hint { text-decoration: underline; }

/* Wide screens: reflow each card into a single compact row. */
@media (min-width: 641px) {
  .m-section { margin: 22px 0 8px; }

  .race-card {
    display: flex;
    align-items: center;
    gap: 22px;
    padding: 12px 20px;
  }

  .rc-main { flex: 0 0 250px; min-width: 0; }
  .rc-head { text-align: left; }
  .rc-consensus {
    justify-content: flex-start;
    align-items: flex-start;
    min-height: 0;
    margin: 5px 0 0;
  }
  .rc-name { text-align: left; font-size: 1.3rem; }

  .rc-side {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 20px;
  }
  .rc-squares {
    flex: 1 1 auto;
    justify-content: flex-start;
    gap: 8px 10px;
    padding-top: 0;
    border-top: none;
  }
  .rc-more-hint {
    flex: 0 0 auto;
    margin-top: 0;
    white-space: nowrap;
  }
}

/* ============================================================
   Race detail modal — one outlet per row (the endorsement matrix,
   stood up vertically for a single race).
   ============================================================ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(13, 24, 20, .55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}
.modal {
  position: relative;
  background: var(--surface);
  width: 100%;
  max-width: 560px;
  max-height: 92vh;
  overflow-y: auto;
  border-radius: 18px 18px 0 0;
  padding: 22px 18px 26px;
  box-shadow: 0 -10px 40px rgba(16,32,42,.28);
}
.modal-close {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 50%;
  background: var(--na-bg);
  color: var(--ink-soft);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}
.modal-close:hover { background: #e4e7ea; color: var(--ink); }
.modal-head { text-align: center; padding: 0 30px 12px; border-bottom: 1px solid var(--line); }
.modal-head .rc-office { font-size: 1.05rem; }

.modal-body { margin-top: 6px; }
.mrow-group {
  margin: 14px 0 6px;
  font-size: .64rem;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--brand);
}
.mrow {
  display: flex;
  align-items: stretch;
  gap: 10px;
  border-bottom: 1px solid var(--line);
}
.mrow-label {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  padding: 9px 0;
  font-size: .86rem;
  font-weight: 600;
  color: var(--ink);
}
.mrow-cell {
  flex: 0 0 44%;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 8px 10px;
  border-radius: 8px;
  margin: 4px 0;
  font-size: .84rem;
}
.mrow-cell.cell { border: none; }
.mrow-cell.agree   { background: var(--agree-bg);   color: var(--agree-ink); }
.mrow-cell.dissent { background: var(--dissent-bg); color: var(--dissent-ink); }
.mrow-cell.neutral { background: var(--neutral-bg); color: var(--neutral-ink); }
.mrow-cell.blank   { background: transparent; }
.mrow-cell.na      { background: var(--na-bg); color: #b3bac2; }
.mrow-empty { color: var(--ink-soft); opacity: .55; }
.mrow-names { flex-basis: 44%; background: var(--na-bg); color: var(--ink-soft); font-size: .74rem; }
.mrow.pending .mrow-label { color: var(--ink-soft); }
