:root {
    --ink: #1c1c1a;
    --ink-2: #44443f;
    --muted: #6c6b65;
    --faint: #a3a29b;
    --rule: #e2e1dc;
    --rule-mid: #c9c8c1;
    --rule-strong: #1c1c1a;
    --bg: #ffffff;
    --tint: #f5f4f0;
    --hover: #f7f6f2;
    --accent: #a8151b;
    --focus: #1f4fbf;
    --sans: "Segoe UI Variable Text", "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
    --turnout: var(--ink);
    /* Candidate colours by ballot number (Okabe-Ito palette, colour-blind safe); party colours override. */
    --c1: #0072b2;
    --c2: #d55e00;
    --c3: #009e73;
    --c4: #cc79a7;
    --c5: #e69f00;
    --c6: #56b4e9;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--sans);
    font-size: 16px;
    line-height: 1.5;
    font-variant-numeric: tabular-nums lining-nums;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

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

h1, h2 { font-family: var(--sans); color: var(--ink); }
h2 {
    font-size: 1.15rem;
    font-weight: 650;
    letter-spacing: -.005em;
    margin: 0;
    padding-top: 10px;
    border-top: 2px solid var(--rule-strong);
}

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- Masthead ---------- */
.masthead { border-bottom: 1px solid var(--rule-mid); padding: 22px 0 18px; }
.masthead-inner { display: flex; justify-content: space-between; align-items: center; gap: 24px; }
.brand { display: flex; align-items: center; gap: 16px; min-width: 0; }
.brand-logo { width: auto; height: 58px; flex: 0 0 auto; }
.masthead h1 { margin: 0; font-size: clamp(1.15rem, 2.6vw, 1.45rem); font-weight: 650; line-height: 1.25; letter-spacing: -.01em; max-width: 34ch; }
.subtitle { margin: 3px 0 0; color: var(--muted); font-size: .9rem; }

.lang { display: inline-flex; align-items: center; gap: 2px; flex: 0 0 auto; font-size: .9rem; }
.lang button {
    appearance: none;
    border: 0;
    border-bottom: 2px solid transparent;
    background: none;
    color: var(--muted);
    font: 500 .9rem/1 var(--sans);
    padding: 6px 6px 5px;
    cursor: pointer;
}
.lang button + button::before { content: none; }
.lang button[aria-pressed="true"] { color: var(--ink); font-weight: 650; border-bottom-color: var(--accent); }
.lang button:not([aria-pressed="true"]):hover { color: var(--ink); }

/* ---------- Embed mode (?embed=1) ---------- */
.embed .masthead { display: none; }
.embed .tabs { margin-top: 4px; }
.embed .notes { margin-bottom: 16px; }
.embed .site-footer { display: none; }

/* ---------- Site footer ---------- */
.site-footer { margin-top: 8px; border-top: 1px solid var(--rule-mid); }
.site-footer p { margin: 0; padding: 16px 0 22px; color: var(--muted); font-size: .8rem; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 28px; margin: 18px 0 0; border-bottom: 1px solid var(--rule-mid); }
.tabs [role="tab"] {
    appearance: none;
    border: 0;
    border-bottom: 3px solid transparent;
    background: none;
    color: var(--muted);
    font: 600 1.02rem/1.2 var(--sans);
    padding: 10px 0 9px;
    margin-bottom: -1px;
    cursor: pointer;
    text-align: left;
}
.tabs [role="tab"][aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.tabs [role="tab"]:not([disabled]):not([aria-selected="true"]):hover { color: var(--ink); }
.tabs [role="tab"][disabled] { color: var(--faint); cursor: not-allowed; }
.tabs [role="tab"] small { display: block; font-size: .74rem; font-weight: 400; margin-top: 2px; color: var(--muted); }
.tabs [role="tab"][disabled] small { color: var(--faint); }

/* ---------- Election rounds (only once a second round exists) ---------- */
.rounds { display: inline-flex; margin: 18px 0 0; border: 1px solid var(--rule-mid); border-radius: 4px; overflow: hidden; }
.rounds[hidden] { display: none; }
.rounds button {
    appearance: none;
    border: 0;
    background: var(--bg);
    color: var(--muted);
    font: 600 .92rem/1.2 var(--sans);
    padding: 8px 18px;
    cursor: pointer;
    text-align: left;
}
.rounds button + button { border-left: 1px solid var(--rule-mid); }
.rounds button small { display: block; font-size: .74rem; font-weight: 400; margin-top: 2px; }
.rounds button[aria-pressed="true"] { background: var(--ink); color: #fff; }
.rounds button:not([aria-pressed="true"]):hover { background: var(--hover); color: var(--ink); }
.rounds button:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
@media (max-width: 420px) {
    .rounds { display: flex; }
    .rounds button { flex: 1; }
}
.updated-line { margin: 10px 0 0; color: var(--muted); font-size: .85rem; }
.updated-line time { color: var(--ink-2); }

/* ---------- Turnout summary ---------- */
.turnout-hero { margin: 26px 0 0; }
.hero-title {
    margin: 0;
    font-size: 1.15rem;
    font-weight: 650;
}
.hero-slot { color: var(--muted); font-weight: 400; }
.hero-body { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); gap: 40px; align-items: end; padding: 18px 0 4px; }
.gauge { min-width: 0; }
.gauge-figure { margin: 0; display: flex; align-items: baseline; line-height: .9; color: var(--ink); }
.gauge-int { font-size: clamp(4.2rem, 11vw, 6.4rem); font-weight: 600; letter-spacing: -.045em; }
.gauge-dec { font-size: clamp(1.9rem, 4.6vw, 2.8rem); font-weight: 500; letter-spacing: -.03em; color: var(--ink-2); }
.gauge-pct { font-size: clamp(1.9rem, 4.6vw, 2.8rem); font-weight: 400; margin-left: 4px; color: var(--muted); }

/* Turnout ring */
.gauge { display: flex; flex-direction: column; align-items: center; }
.ring { position: relative; width: min(280px, 100%); aspect-ratio: 1; }
.ring svg { display: block; width: 100%; height: 100%; overflow: visible; }
.ring-track { fill: none; stroke: #efece6; stroke-width: 21; }
.ring-seg { fill: none; stroke-width: 21; cursor: pointer; transition: stroke-dasharray .8s cubic-bezier(.2, .7, .2, 1), opacity .15s ease; outline: none; }
.ring-seg.is-latest { filter: drop-shadow(0 0 4px rgba(168, 21, 27, .45)); }
.ring-seg:hover, .ring-seg.is-picked { opacity: .78; }
.ring-label { font-size: 10.5px; fill: var(--muted); font-variant-numeric: tabular-nums; }
.ring-label.is-latest { fill: var(--accent); font-weight: 700; }
.ring-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; pointer-events: none; }
.ring .gauge-figure { margin: 0; display: flex; align-items: flex-start; line-height: .9; }
.ring .gauge-int { font-size: clamp(3.6rem, 13vw, 4.8rem); font-weight: 600; letter-spacing: -.045em; color: var(--ink); }
.ring .gauge-side { display: flex; flex-direction: column; margin: .35rem 0 0 .25rem; line-height: 1; }
.ring .gauge-dec { font-size: 1.15rem; font-weight: 500; letter-spacing: 0; color: var(--ink-2); }
.ring .gauge-pct { font-size: 1.7rem; font-weight: 500; margin: .2rem 0 0; color: var(--accent); }
.ring-sub { margin: 10px 0 0; color: var(--muted); font-size: .86rem; }
.ring-tip { min-height: 1.3em; margin: 6px 0 0; text-align: center; color: var(--ink-2); font-size: .82rem; }
.hero-stats { margin: 0; border-top: 1px solid var(--rule-mid); }
.hero-stats > div { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 16px; align-items: baseline; padding: 9px 0; border-bottom: 1px solid var(--rule); }
.hero-stats dt { color: var(--ink-2); font-size: .92rem; line-height: 1.35; }
.hero-stats dd { margin: 0; font-size: 1.05rem; font-weight: 600; white-space: nowrap; text-align: right; }
.hero-stats dd small { color: var(--muted); font-size: .8rem; font-weight: 400; margin-right: 6px; }

/* ---------- Turnout by time ---------- */
.turnout-overall { padding: 40px 0 0; }
.turnout-slots { list-style: none; margin: 12px 0 0; padding: 0; }
.turnout-slot {
    display: grid;
    grid-template-columns: 3.6rem minmax(0, 1fr) 5.4rem;
    grid-template-areas: "time bar pct" ". meta meta";
    column-gap: 18px;
    row-gap: 3px;
    align-items: center;
    padding: 10px 0 9px;
    border-bottom: 1px solid var(--rule);
}
.slot-time { grid-area: time; font-weight: 600; font-size: .98rem; }
.slot-bar { grid-area: bar; height: 6px; background: var(--tint); }
.slot-bar div { height: 100%; background: var(--ink-2); transition: width .8s ease; }
.turnout-slot.is-latest .slot-bar div { background: var(--accent); }
.slot-pct { grid-area: pct; justify-self: end; font-size: 1.12rem; font-weight: 600; }
.slot-meta { grid-area: meta; color: var(--muted); font-size: .82rem; }
.turnout-slot.is-empty .slot-time, .turnout-slot.is-empty .slot-pct { color: var(--faint); font-weight: 400; }
.turnout-slot.is-empty .slot-meta { color: var(--faint); }
.turnout-slots .empty { padding: 16px 0; color: var(--muted); }

.slot-picker { display: inline-flex; flex-wrap: wrap; margin: 14px 0 12px; border: 1px solid var(--rule-mid); }
.slot-picker button {
    appearance: none;
    border: 0;
    border-right: 1px solid var(--rule-mid);
    background: #fff;
    color: var(--ink-2);
    font: 500 .88rem/1 var(--sans);
    padding: 9px 13px;
    cursor: pointer;
    font-variant-numeric: tabular-nums;
}
.slot-picker button:last-child { border-right: 0; }
.slot-picker button:hover { background: var(--hover); color: var(--ink); }
.slot-picker button[aria-checked="true"] { background: var(--ink); color: #fff; }

/* ---------- Status ---------- */
.loading { color: var(--muted); padding: 40px 0; }
.loading.error { color: var(--accent); }

.status { padding: 22px 0 0; }
.status-line { margin: 0 0 8px; color: var(--ink-2); font-size: .92rem; display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: baseline; }
.status-line #reportedText { color: var(--ink); }
.status-sep { color: var(--muted); }
.stale { flex-basis: 100%; color: var(--accent); font-size: .85rem; }
.progress { height: 3px; background: var(--rule); overflow: hidden; }
.progress div { height: 100%; width: 0; background: var(--ink); transition: width .8s ease; }

/* ---------- Candidates ---------- */
.results { padding: 34px 0 0; }
.candidates { list-style: none; margin: 4px 0 0; padding: 0; }
.candidate {
    display: grid;
    grid-template-columns: 1.75rem 2.75rem minmax(0, 1fr) auto;
    grid-template-areas:
        "num mark name votes"
        "num mark bar  pct";
    column-gap: 14px;
    row-gap: 7px;
    align-items: center;
    padding: 15px 0 14px;
    border-bottom: 1px solid var(--rule);
}
/* Ballot number set like the box on a ballot paper, underlined in the candidate colour. */
.candidate-num {
    grid-area: num;
    align-self: start;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.75rem;
    height: 1.95rem;
    margin-top: 1px;
    border: 1px solid var(--rule-mid);
    border-bottom: 3px solid var(--cand, var(--ink-2));
    background: #fff;
    color: var(--ink);
    font-size: .95rem;
    font-weight: 650;
    line-height: 1;
}
.candidate-mark { grid-area: mark; align-self: start; width: 2.75rem; height: 2.75rem; display: flex; align-items: center; justify-content: center; }
.candidate-mark img { max-width: 100%; max-height: 100%; object-fit: contain; display: block; }
.candidate-swatch { width: 14px; height: 14px; background: var(--cand, var(--ink-2)); }
.candidate-name { grid-area: name; min-width: 0; }
.candidate-name strong { display: block; font-size: 1.04rem; font-weight: 650; line-height: 1.3; }
.candidate-name .coalition { display: block; color: var(--muted); font-size: .85rem; line-height: 1.4; margin-top: 1px; }
.candidate-name .coalition b { color: var(--ink-2); font-weight: 600; }
.leading {
    margin-left: 10px;
    color: var(--accent);
    font-size: .78rem;
    font-weight: 600;
    vertical-align: 1px;
}
.leading::before { content: "\25B2\00A0"; font-size: .62rem; vertical-align: 1px; }
.candidate-pct {
    grid-area: votes;
    justify-self: end;
    font-size: clamp(1.35rem, 3.6vw, 1.75rem);
    font-weight: 600;
    letter-spacing: -.02em;
    line-height: 1;
}
.candidate-bar { grid-area: bar; height: 6px; background: var(--tint); overflow: hidden; }
.candidate-bar div { height: 100%; width: 0; background: var(--cand, var(--ink-2)); transition: width .9s cubic-bezier(.2, .7, .2, 1); }
.candidate-votes { grid-area: pct; justify-self: end; color: var(--ink-2); font-size: .9rem; white-space: nowrap; min-width: 4.6rem; text-align: right; }
.mini-logo { width: 20px; height: 20px; object-fit: contain; vertical-align: -5px; margin-right: 8px; }

.cand-1 { --cand: var(--c1); }
.cand-2 { --cand: var(--c2); }
.cand-3 { --cand: var(--c3); }
.cand-4 { --cand: var(--c4); }
.cand-5 { --cand: var(--c5); }
.cand-6 { --cand: var(--c6); }

/* ---------- Summary figures ---------- */
.figures {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: 40px;
    margin: 30px 0 0;
    border-top: 2px solid var(--rule-strong);
}
.figure {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "label value" "sub sub";
    align-items: baseline;
    column-gap: 16px;
    padding: 10px 0 9px;
    border-bottom: 1px solid var(--rule);
}
.figure-label { grid-area: label; color: var(--ink-2); font-size: .92rem; line-height: 1.35; }
.figure b { grid-area: value; font-size: 1.12rem; font-weight: 600; white-space: nowrap; }
.figure small { grid-area: sub; color: var(--muted); font-size: .8rem; }
.figure small:empty { display: none; }

/* ---------- Stations ---------- */
.stations { padding: 40px 0 0; }
.section-hint { margin: 6px 0 12px; color: var(--muted); font-size: .88rem; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--rule); text-align: right; }
th:first-child, td:first-child { text-align: left; padding-left: 0; }
th:last-child, td:last-child { padding-right: 0; }
thead th {
    border-bottom: 1px solid var(--rule-strong);
    color: var(--muted);
    font-size: .8rem;
    font-weight: 500;
    vertical-align: bottom;
    white-space: nowrap;
}
.stations h2 + .table-wrap thead th, .stations .slot-picker + .table-wrap thead th { padding-top: 0; }
.station-row { cursor: pointer; }
.station-row:hover, .station-row:focus-visible { background: #f2f0ea; }
.station-row.is-open { background: var(--tint); }
.station-row.is-open td { border-bottom-color: transparent; }
.station-row .turnout-cell { font-weight: 600; }
/* "View results" cue: visible on every expandable row, darkens on hover, red while open. */
.cue-col { width: 1%; }
.row-cue { text-align: right; white-space: nowrap; padding-left: 4px; }
.cue { display: inline-flex; align-items: center; gap: 7px; padding: 5px 10px 5px 11px; border: 1px solid var(--rule-mid); border-radius: 4px; color: var(--ink-2); font-size: .8rem; font-weight: 600; line-height: 1.2; transition: background-color .12s ease, color .12s ease, border-color .12s ease; }
.cue-icon { width: 6px; height: 6px; border-right: 1.6px solid currentColor; border-bottom: 1.6px solid currentColor; transform: translateY(-2px) rotate(45deg); transition: transform .15s ease; }
.station-row:hover .cue, .station-row:focus-visible .cue { background: var(--ink); border-color: var(--ink); color: #fff; }
.station-row.is-open .cue { background: var(--accent); border-color: var(--accent); color: #fff; }
.station-row.is-open .cue-icon { transform: translateY(1px) rotate(-135deg); }
.station-number { display: inline-flex; align-items: center; gap: 9px; font-weight: 600; }
.station-name { display: block; margin-top: 2px; font-size: .78rem; font-weight: 400; color: var(--muted); line-height: 1.25; }
.station-chevron { display: inline-block; width: 0; height: 0; border-left: 5px solid var(--ink-2); border-top: 4px solid transparent; border-bottom: 4px solid transparent; transition: transform .15s ease; }
.station-row.is-open .station-chevron { transform: rotate(90deg); }
.station-pending td { color: var(--faint); }
.station-pending .station-number { font-weight: 400; color: var(--muted); }
.pending-dot { display: inline-block; width: 5px; height: 1px; margin: 0 1px; background: var(--faint); }
.pending-label { font-size: .82rem; white-space: nowrap; }
.turnout-table tbody td:last-child b { font-weight: 600; }
.station-detail-row { display: none; }
.station-detail-row.is-visible { display: table-row; }
.station-detail-row > td { padding: 0; background: var(--tint); text-align: left; }
/* contain: the opened detail must not widen the stations table; it takes the table's width instead. */
.station-detail { padding: 6px 14px 18px 18px; contain: inline-size; white-space: normal; }
.station-detail-summary { display: flex; flex-wrap: wrap; gap: 4px 22px; margin: 0 0 10px; color: var(--muted); font-size: .85rem; }
.station-detail-summary b { color: var(--ink); font-weight: 600; }
.detail-table { background: #fff; min-width: 560px; }
.detail-table th { border-bottom: 1px solid var(--rule-mid); background: #fff; padding-top: 8px; }
.detail-table td, .detail-table th { padding: 8px 10px; }
.detail-table td:first-child, .detail-table th:first-child { width: 44px; padding-left: 10px; color: var(--muted); }
.detail-table td:nth-child(2), .detail-table th:nth-child(2) { text-align: left; }
.detail-table td:last-child, .detail-table th:last-child { padding-right: 10px; }
.detail-table td b { font-weight: 600; }
.swatch { display: inline-block; width: 10px; height: 10px; background: var(--cand, var(--ink-2)); margin-right: 8px; vertical-align: 0; }
.detail-table small { display: block; color: var(--muted); font-size: .78rem; }
.empty { color: var(--muted); text-align: left; }

/* ---------- Notes ---------- */
.notes { margin: 30px 0 48px; padding-top: 12px; border-top: 1px solid var(--rule-mid); color: var(--muted); font-size: .8rem; line-height: 1.45; }
.notes p { margin: 0 0 3px; max-width: 80ch; }

/* ---------- Final markers ---------- */
.tabs [role="tab"] small.is-final { color: #1d6b3a; }
.final-mark { margin-left: 2px; color: #1d6b3a; font-weight: 600; font-size: .9em; }
/* Only in the admin preview: station counted with submitted, not yet verified figures. */
.unv-tag { margin-left: 4px; padding: 1px 6px; border-radius: 3px; background: #fff1d6; color: #8a5300; font-size: .68rem; font-weight: 700; white-space: nowrap; }

/* ---------- Station detail as cards on phones (no sideways scrolling) ---------- */
.detail-cards { display: none; list-style: none; margin: 0; padding: 0; background: #fff; border-top: 1px solid var(--rule-mid); }
.detail-card {
    display: grid;
    grid-template-columns: 1.35rem minmax(0, 1fr) auto;
    grid-template-areas: "num name votes" "num bar bar" "num meta meta";
    column-gap: 10px;
    row-gap: 5px;
    align-items: center;
    padding: 10px 10px 10px 8px;
    border-bottom: 1px solid var(--rule);
}
.detail-card:last-child { border-bottom: 0; }
.dc-num { grid-area: num; align-self: start; display: flex; align-items: center; justify-content: center; width: 1.35rem; height: 1.5rem; border: 1px solid var(--rule-mid); border-bottom: 2px solid var(--cand, var(--ink-2)); color: var(--ink); font-size: .78rem; font-weight: 650; line-height: 1; }
.dc-name { grid-area: name; font-weight: 600; font-size: .92rem; line-height: 1.3; overflow-wrap: anywhere; }
.dc-name .mini-logo { width: 18px; height: 18px; vertical-align: -4px; margin-right: 6px; }
.dc-votes { grid-area: votes; font-size: 1.02rem; font-weight: 600; }
.dc-bar { grid-area: bar; display: block; height: 4px; background: var(--tint); overflow: hidden; }
.dc-bar > span { display: block; height: 100%; background: var(--cand, var(--ink-2)); }
.dc-meta { grid-area: meta; color: var(--muted); font-size: .78rem; }

/* ---------- Small screens ---------- */
@media (max-width: 720px) {
    .wrap { padding: 0 16px; }
    .masthead { padding: 16px 0 14px; }
    .masthead-inner { align-items: flex-start; gap: 12px; }
    .brand { gap: 12px; }
    .brand-logo { height: 42px; }
    .tabs { gap: 22px; }
    .hero-body { grid-template-columns: 1fr; gap: 22px; }
    .figures { grid-template-columns: 1fr; }
    .turnout-slot { grid-template-columns: 3.1rem minmax(0, 1fr) 4.6rem; column-gap: 12px; }
    .slot-pct { font-size: 1rem; }
    .candidate { grid-template-columns: 1.5rem 2.2rem minmax(0, 1fr) auto; column-gap: 10px; }
    .candidate-mark { width: 2.2rem; height: 2.2rem; }
    .candidate-num { width: 1.5rem; height: 1.7rem; font-size: .85rem; }
    .stations-table th, .stations-table td { padding: 9px 6px; white-space: nowrap; }
    .station-detail { padding: 6px 10px 14px; }
    .station-detail .table-wrap { display: none; }
    .detail-cards { display: block; }
    .stations-table:not(.turnout-table) > thead > tr > th:nth-child(3),
    .stations-table:not(.turnout-table) > thead > tr > th:nth-child(4),
    .stations-table:not(.turnout-table) > tbody > tr > td:nth-child(3),
    .stations-table:not(.turnout-table) > tbody > tr > td:nth-child(4) { display: none; }
    .stations-table thead th { white-space: normal; font-size: .74rem; }
    .stations-table .pending-label { white-space: normal; line-height: 1.25; }
    .cue-text { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
    .cue { width: 28px; height: 28px; padding: 0; justify-content: center; border-radius: 50%; }
}

/* Narrow phones: tighter station tables so they fit the screen (long single-word headers cannot wrap). */
@media (max-width: 420px) {
    .masthead-inner { flex-direction: column; }
    .stations-table thead th { font-size: .66rem; padding: 8px 4px; }
    .stations-table > tbody > tr > td { padding: 9px 4px; font-size: .88rem; }
    .stations-table .station-number { gap: 6px; }
    .slot-picker button { padding: 8px 10px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; animation: none !important; }
}
