@font-face {
  font-family: "Archivo Narrow";
  src: url("fonts/archivo-narrow.woff2") format("woff2");
  font-weight: 400 700;
  font-display: swap;
}

:root {
  --bg: #f4f5f2;          /* counting-room paper grey */
  --ink: #1c1f24;         /* graphite */
  --muted: #555c66;
  --line: #d3d6d9;
  --line-strong: #8a9099;
  --field: #ffffff;
  --ballot: #f2e6c9;      /* manila ballot envelope */
  --ballot-line: #cdb98a;
  --ballot-ink: #3b3220;
  --btn: #1c1f24;
  --btn-ink: #ffffff;
  --blue: #1f4c9e;        /* 1st place ribbon */
  --red: #b3261e;         /* 2nd place ribbon */
  --white-rib: #ffffff;   /* 3rd place ribbon */
  --rib-ink: #ffffff;
  --ok: #1d6b3a;
  --ok-bg: #e3f1e7;
  --warn: #7a4d00;
  --warn-bg: #fbefd2;
  --bad: #a3221b;
  --bad-bg: #fbe3e0;
  --focus: #d97a00;
  --r-ctl: 6px;
  --r-card: 10px;
  --head: "Archivo Narrow", "Roboto Condensed", "Arial Narrow", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181b;
    --ink: #e9e7e1;
    --muted: #a7adb5;
    --line: #33373d;
    --line-strong: #6c737c;
    --field: #1f2226;
    --ballot: #2a2519;
    --ballot-line: #5c4f2e;
    --ballot-ink: #efe4c8;
    --btn: #e9e7e1;
    --btn-ink: #16181b;
    --blue: #7ea6f2;
    --red: #f08a80;
    --white-rib: #2a2d31;
    --rib-ink: #111317;
    --ok: #8fd3a5;
    --ok-bg: #1b3022;
    --warn: #f0c477;
    --warn-bg: #352a14;
    --bad: #f39a92;
    --bad-bg: #3a1d1a;
    --focus: #ffb347;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 17px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--blue); }
h1, h2, h3, .brand, .num, .rib, .badge, .pn, .val, .bj { font-family: var(--head); }
h1 { font-size: clamp(2.1rem, 6vw, 2.9rem); line-height: 1.05; margin: 0 0 10px; letter-spacing: -0.01em; }
h2 { font-size: 1.6rem; line-height: 1.15; margin: 0 0 10px; }
h3 { font-size: 1.2rem; margin: 0 0 6px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 0; background: var(--btn); color: var(--btn-ink); padding: 8px 12px; z-index: 5; }
.skip:focus { left: 8px; }
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); }

/* top bar */
.topbar { border-bottom: 2px solid var(--ink); }
.topbar-in { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 56px; }
.brand { display: flex; align-items: center; gap: 8px; color: var(--ink); text-decoration: none; font-size: 1.35rem; font-weight: 700; }
.topbar nav { display: flex; gap: 16px; font-size: 0.95rem; }
.topbar nav a { color: var(--ink); padding: 10px 0; }
@media (max-width: 420px) { .topbar nav a:first-child { display: none; } }

.hero { padding: 22px 0 8px; max-width: 720px; }
.lede { font-size: 1.1rem; margin: 0; color: var(--ink); }

/* tool layout */
.tool { margin-top: 14px; display: grid; gap: 0 32px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 1024px) {
  .tool { grid-template-columns: minmax(0, 1fr) 360px; align-items: start; }
  .results { position: sticky; top: 16px; max-height: calc(100vh - 32px); overflow: auto; }
}
.step { border-top: 2px solid var(--ink); padding: 14px 0 22px; }
.step h2 { display: flex; align-items: center; gap: 10px; }
.num { display: inline-grid; place-items: center; width: 30px; height: 30px; border: 2px solid var(--ink); border-radius: 4px; font-size: 1.05rem; }
h3.sub { font-size: 1.1rem; margin: 16px 0 6px; }
.hint { color: var(--muted); font-size: 0.95rem; margin: 0 0 10px; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 12px; }
.field { display: grid; gap: 4px; margin: 0 0 12px; max-width: 520px; }
.field.small { max-width: 220px; }
label { font-weight: 600; font-size: 0.95rem; }
input[type=text], input[type=number], select {
  font: inherit; font-size: 16px; color: var(--ink); background: var(--field);
  border: 1.5px solid var(--line-strong); border-radius: var(--r-ctl); padding: 10px 12px; min-height: 46px; width: 100%;
}
input::placeholder { color: var(--muted); opacity: 0.85; }
.switch { margin: 0 0 12px; }
.switch select { width: auto; max-width: 100%; min-width: 0; }
.check { display: flex; gap: 10px; align-items: center; font-weight: 500; min-height: 44px; }
.check input { width: 22px; height: 22px; accent-color: var(--blue); }
.score-opts { display: grid; gap: 0 16px; margin-top: 4px; }
@media (min-width: 640px) { .score-opts { grid-template-columns: 220px 1fr; } .score-opts .check { grid-column: 1 / -1; } }

/* segmented ballot type */
.seg { border: 0; padding: 0; margin: 4px 0 8px; display: grid; grid-template-columns: 1fr 1fr; max-width: 520px; }
.seg label { position: relative; font-weight: 600; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg span { display: flex; align-items: center; justify-content: center; text-align: center; min-height: 48px; padding: 8px 10px; border: 1.5px solid var(--ink); line-height: 1.2; }
.seg label:first-of-type span { border-radius: var(--r-ctl) 0 0 var(--r-ctl); }
.seg label:last-of-type span { border-radius: 0 var(--r-ctl) var(--r-ctl) 0; border-left: 0; }
.seg input:checked + span { background: var(--btn); color: var(--btn-ink); }
.seg input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }

/* speakers */
.speakers { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; max-width: 520px; }
.speakers li { display: grid; grid-template-columns: 32px 1fr 44px; align-items: center; gap: 6px; }
.sn, .pn { font-family: var(--head); font-weight: 700; color: var(--muted); text-align: center; }
.icon { width: 44px; height: 44px; border: 0; background: none; color: var(--muted); font-size: 1.6rem; line-height: 1; border-radius: var(--r-ctl); cursor: pointer; }
.icon:hover { color: var(--bad); }

/* buttons */
.btn {
  font: inherit; font-weight: 650; font-size: 1rem; min-height: 46px; padding: 10px 18px; border-radius: var(--r-ctl);
  border: 1.5px solid var(--ink); background: transparent; color: var(--ink); cursor: pointer;
}
.btn.primary { background: var(--btn); color: var(--btn-ink); }
.btn.ghost { border-color: var(--line-strong); }
.btn[aria-disabled="true"] { opacity: 0.45; }
.linkbtn { font: inherit; font-size: 0.95rem; background: none; border: 0; padding: 10px 4px; color: var(--blue); text-decoration: underline; cursor: pointer; min-height: 44px; }
.linkbtn.danger { color: var(--bad); }

/* ballot entry: the one manila "ballot" panel */
.entry { background: var(--ballot); border: 1.5px solid var(--ballot-line); border-radius: var(--r-card); padding: 14px 14px 12px; color: var(--ballot-ink); }
.entry.second { border-style: dashed; border-width: 2px; }
.entry h3 { font-size: 1.35rem; }
.entry .hint { color: var(--ballot-ink); opacity: 0.85; }
.pick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.pick {
  position: relative; display: flex; align-items: center; gap: 8px; text-align: left; min-height: 52px; padding: 8px 10px;
  font: inherit; font-weight: 600; color: var(--ink); background: var(--field); border: 1.5px solid var(--line-strong);
  border-radius: var(--r-ctl); cursor: pointer;
}
.pick .pname { flex: 1; overflow-wrap: anywhere; line-height: 1.2; }
.pick.on { border-width: 2.5px; }
.pick.p1 { border-color: var(--blue); }
.pick.p2 { border-color: var(--red); }
.pick.p3 { border-color: var(--ink); }
.pick.p4 { border-color: var(--line-strong); }
.pick.tbon { border-color: var(--ink); }
.pick.tbon .badge { background: var(--ink); color: var(--bg); }
.badge, .rib {
  display: inline-block; min-width: 38px; text-align: center; font-weight: 700; font-size: 0.95rem; padding: 2px 6px; border-radius: 3px;
  border: 1.5px solid transparent;
}
.badge { background: var(--muted); color: var(--bg); }
.p1 .badge, .rib.p1 { background: var(--blue); color: var(--rib-ink); }
.p2 .badge, .rib.p2 { background: var(--red); color: var(--rib-ink); }
.p3 .badge, .rib.p3 { background: var(--white-rib); color: var(--ink); border-color: var(--ink); }
.rib.p4 { background: transparent; color: var(--ink); border-color: var(--line-strong); }
.pick.dq .pname { text-decoration: line-through; text-decoration-color: var(--red); }
.score-grid { display: grid; gap: 8px; max-width: 420px; }
.score-row { display: grid; grid-template-columns: 26px 1fr 110px; align-items: center; gap: 8px; font-weight: 600; }
.score-row input { text-align: right; font-variant-numeric: tabular-nums; }
.mismatch p { margin: 0 0 8px; }
.mismatch .read { line-height: 1.7; }
.mismatch .read > span:first-child { display: block; font-weight: 600; }
.mismatch .rib { min-width: 32px; font-size: 0.8rem; padding: 0 4px; margin-right: 2px; }

/* saved ballots */
.ballot-list { list-style: none; margin: 14px 0 0; padding: 0; border-top: 1px solid var(--line); }
.ballot { display: grid; grid-template-columns: 70px 1fr auto; gap: 2px 10px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }
.bj { font-weight: 700; }
.bp { line-height: 1.6; }
.pk { white-space: nowrap; margin-right: 8px; }
@media (min-width: 700px) { .ballot { grid-template-columns: 70px 1fr auto auto; } .ba { grid-column: auto; } }
.bp .rib { min-width: 32px; font-size: 0.8rem; padding: 0 4px; margin-right: 2px; }
.bs { font-size: 0.85rem; font-weight: 600; white-space: nowrap; }
.s-ok { color: var(--ok); }
.s-bad { color: var(--bad); }
.s-pending, .s-aside { color: var(--muted); }
.ba { grid-column: 2 / -1; display: flex; flex-wrap: wrap; gap: 0 10px; }
.ba .linkbtn { padding: 4px 2px; min-height: 36px; }
.ballot.aside .bp { text-decoration: line-through; color: var(--muted); }
.flag { color: var(--bad); font-weight: 600; font-size: 0.9rem; }
.second-bar { margin-top: 10px; }
.second-bar p { margin: 0; }
/* phones and tablets: results sit below the steps, so offer a shortcut past the ballot list */
.jump { display: none; margin: 8px 0 0; }
.jump a { display: inline-flex; align-items: center; min-height: 44px; font-weight: 600; }
.jump a::after { content: "\2193"; margin-left: 6px; text-decoration: none; }
@media (max-width: 1023px) { .jump { display: block; } }
#h-results:focus { outline: none; }
.ok-line { margin: 0; color: var(--ok); font-weight: 600; }

/* rulings */
.rulings { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; max-width: 620px; }
.rulings li { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr); gap: 6px 10px; align-items: center; }
.rulings li.is-dq label { text-decoration: line-through; text-decoration-color: var(--red); }
.rulings .pen { grid-column: 2; display: grid; grid-template-columns: auto 100px; gap: 8px; align-items: center; justify-content: end; }
@media (max-width: 480px) { .rulings li { grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr); } .rulings .pen { grid-column: 1 / -1; justify-content: end; } }
@media (max-width: 340px) { .rulings li { grid-template-columns: 1fr; } }

/* tiebreak */
.need { margin: 0 0 10px; padding: 8px 10px; background: var(--bad-bg); color: var(--bad); border-left: 4px solid var(--bad); font-weight: 600; }
details.tb > summary { cursor: pointer; font-weight: 600; padding: 10px 0; }
details.tb .btn { margin-top: 10px; }

/* results: the one result card */
.results { border: 2px solid var(--ink); border-radius: var(--r-card); padding: 14px 16px; background: var(--field); margin: 6px 0 24px; scroll-margin-top: 12px; }
.results h2 { font-size: 1.5rem; }
.empty { color: var(--muted); }
.status { margin: 0 0 10px; padding: 6px 10px; font-weight: 600; border-radius: 4px; }
.status.s-ok { background: var(--ok-bg); color: var(--ok); }
.status.s-warn { background: var(--warn-bg); color: var(--warn); }
.status.s-bad { background: var(--bad-bg); color: var(--bad); }
.warns { margin: 0 0 12px; padding-left: 20px; font-size: 0.95rem; }
.warns li { margin-bottom: 4px; }
.warns .w-error { color: var(--bad); font-weight: 600; }
.places { list-style: none; margin: 0 0 8px; padding: 0; }
.pl { display: grid; grid-template-columns: 52px 1fr auto; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.pl .rib { font-size: 1.05rem; min-width: 46px; padding: 4px 6px; }
.pl .who b { font-size: 1.2rem; display: block; line-height: 1.2; }
.pl .note { display: block; font-size: 0.85rem; color: var(--muted); }
.pl .note.warn { color: var(--bad); font-weight: 600; }
.val { font-size: 1.15rem; font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
.dq-line { font-size: 0.95rem; margin: 8px 0; }
details.full summary { cursor: pointer; font-weight: 600; padding: 10px 0; }
.full-t, table.ex { border-collapse: collapse; width: 100%; font-size: 0.95rem; font-variant-numeric: tabular-nums; }
.full-t th, .full-t td, table.ex th, table.ex td { text-align: left; padding: 6px 8px 6px 0; border-bottom: 1px solid var(--line); }
.full-t .struck td { color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 4px; }
.reset { font-size: 0.9rem; margin: 10px 0 0; }

.toast {
  position: fixed; left: 50%; bottom: 16px; transform: translate(-50%, 140%); margin: 0; z-index: 10;
  background: var(--btn); color: var(--btn-ink); padding: 6px 8px 6px 14px; border-radius: var(--r-ctl);
  display: flex; align-items: center; gap: 8px; max-width: calc(100vw - 32px); width: max-content;
  transition: transform 0.2s ease; font-size: 0.95rem; visibility: hidden;
}
.toast.show { transform: translate(-50%, 0); visibility: visible; }
.toast .linkbtn { color: var(--btn-ink); font-weight: 700; }
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }

/* content */
.content { max-width: 720px; padding: 10px 0 30px; }
.content h2 { margin-top: 30px; }
.content p { margin: 0 0 14px; }
details.ref { border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 4px 0; margin: 16px 0; }
details.ref > summary { cursor: pointer; font-weight: 600; padding: 10px 0; }
.table-fit { max-width: 100%; }
table.ex td, table.ex th { padding-right: 6px; }
table.ex .tot th, table.ex .tot td { font-weight: 700; border-top: 2px solid var(--ink); }
.faq details { border-bottom: 1px solid var(--line); }
.faq summary { cursor: pointer; font-weight: 600; padding: 12px 0; min-height: 44px; }
.faq details p { margin: 0 0 14px; }
.sources { font-size: 0.92rem; color: var(--muted); margin-top: 26px; }
.sources a { color: inherit; }

footer { border-top: 2px solid var(--ink); padding: 18px 0 30px; font-size: 0.92rem; color: var(--muted); }
.sb-footer { display: grid; gap: 6px; }
.sb-footer p { margin: 0; line-height: 1.5; }
.sb-more a { display: inline-block; padding: 6px 0; }
.sb-footer a { color: var(--ink); }

/* 404 */
.nf { padding: 40px 0 60px; }
.nf .row a { text-decoration: none; display: inline-flex; align-items: center; }

/* ---------- print ---------- */
.print-sheet { display: none; }
@page { margin: 14mm 14mm 16mm; }
@media print {
  :root { --ink: #000; --muted: #444; --line: #999; }
  body { background: #fff; color: #000; font: 11pt/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
  .skip, .topbar, main, footer, .toast { display: none !important; }
  body:not([data-print="slip"]) #print-tally { display: block; }
  body[data-print="slip"] #print-slip { display: block; }
  .print-sheet .ptitle { font-family: var(--head); font-size: 20pt; font-weight: 700; line-height: 1.15; margin: 0 0 2pt; }
  .print-sheet .psub { font-family: var(--head); font-size: 13pt; font-weight: 700; margin: 14pt 0 4pt; break-after: avoid; }
  .ph p, .slip > p { margin: 0; }
  .pkind { font-family: var(--head); font-size: 10.5pt; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; }
  .pnote { margin: 6pt 0; font-size: 10pt; }
  .pnote.pflag { font-weight: 700; border: 1pt solid #000; padding: 4pt 6pt; }
  .tally { width: 99.6%; border-collapse: collapse; margin-top: 8pt; table-layout: fixed; font-variant-numeric: tabular-nums; }
  .tally th, .tally td { border: 0.75pt solid #000; padding: 5pt 4pt; text-align: center; font-size: 11pt; vertical-align: middle; overflow-wrap: break-word; hyphens: auto; }
  .tally thead th { font-family: var(--head); font-size: 10.5pt; line-height: 1.15; }
  .tally thead th .pn { display: block; color: #444; }
  .tally th[scope=row] { text-align: left; font-weight: 600; }
  .tally thead th:first-child { width: 15%; }
  .tally .chk { width: 9%; font-size: 9pt; }
  .tally tbody tr { height: 22pt; break-inside: avoid; }
  .tally tr.aside td, .tally tr.aside th { text-decoration: line-through; color: #555; }
  .tally tr.aside small { text-decoration: none; display: inline-block; }
  .tally tfoot tr { break-inside: avoid; }
  .tally tfoot th, .tally tfoot td { font-weight: 700; border-top-width: 1.5pt; }
  .tally .plc td { font-size: 10pt; }
  .tally .plc .why { display: block; font-size: 8.5pt; font-weight: 600; }
  .tally.tight .plc .why { font-size: 7.5pt; }
  .tally.tight th, .tally.tight td { font-size: 9.5pt; padding: 4pt 2pt; }
  .tally.tight thead th, .tally.tight .plc td { font-size: 8pt; padding-left: 1pt; padding-right: 1pt; }
  .tally.tight thead th:first-child { width: 11%; }
  .tally.tight .chk { width: 6.5%; }
  .tally tfoot { display: table-row-group; }
  .dropped { color: #555; }
  .ties { margin: 0; padding-left: 18pt; }
  .rank { margin: 0; padding: 0; list-style: none; }
  .rank.two { columns: 2; column-gap: 18pt; }
  .rank li { break-inside: avoid; }
  .pend { break-inside: avoid; }
  .tally s { text-decoration-thickness: 1.5pt; }
  .rank li { display: grid; grid-template-columns: 54pt 1fr; }
  .rank li > span:first-child { font-weight: 700; }
  .rank .v { color: #444; margin-left: 6pt; }
  .sigs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18pt; margin-top: 30pt; break-inside: avoid; }
  .sigs p { border-top: 0.75pt solid #000; padding-top: 3pt; font-size: 9.5pt; margin: 0; }
  .sigs.one { grid-template-columns: 1fr 1fr; margin-top: 26pt; }
  .slip { height: 112mm; padding: 4mm 2mm; break-inside: avoid; }
  .slip .ptitle { font-size: 18pt; margin-top: 4pt; }
  .slip .dqs { margin: 10pt 0 4pt; font-size: 11.5pt; }
  .slip .order { margin: 8pt 0 4pt; font-weight: 700; }
  .ann { border-collapse: collapse; width: 100%; }
  .ann th, .ann td { text-align: left; padding: 7pt 6pt; border-bottom: 0.75pt solid #000; font-size: 14pt; }
  .ann th { width: 36%; font-family: var(--head); }
  .ann td { font-weight: 700; }
  .cut { border-top: 1pt dashed #000; text-align: center; font-size: 8pt; color: #444; margin: 0 0 6mm; padding-top: 1mm; }
}
