/* Layout: sticky status bar → seat tally → grid of city cards */
:root {
  --bg: #f3f4f7; --surface: #ffffff; --fg: #14171f; --muted: #5d6475; --line: #dfe2ea;
  --kmt: #1f4fb8; --dpp: #1f8a4c; --tpp: #1a9aa8; --oth: #8a8f9c; --warn: #b8560f; --live: #d22d3d; --ok: #1f8a4c;
  --sans: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) { :root {
  --bg: #0f1218; --surface: #181c25; --fg: #eceef3; --muted: #9aa1b2; --line: #2a303d;
  --kmt: #5b8cff; --dpp: #3fc07a; --tpp: #3cc4d2; --oth: #8e94a3; --warn: #f0a050; --live: #ff5a68; --ok: #3fc07a; color-scheme: dark } }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font-family: var(--sans); font-size: 15px; line-height: 1.5;
  padding-bottom: env(safe-area-inset-bottom, 0px); }
[hidden] { display: none !important; }
.wrap { max-width: 1180px; margin: 0 auto; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.kmt { color: var(--kmt); } .dpp { color: var(--dpp); }

header { position: sticky; top: 0; z-index: 5; background: var(--surface); border-bottom: 1px solid var(--line); padding-top: env(safe-area-inset-top, 0px); }
header .wrap { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 20px; padding-block: 12px; }
h1 { font-size: 1.25rem; font-weight: 900; margin: 0; letter-spacing: .02em; text-wrap: balance; }
h1 small { font-weight: 500; color: var(--muted); font-size: .8rem; margin-left: 8px; letter-spacing: 0; }
.live { display: inline-flex; align-items: center; gap: 6px; font-size: .75rem; font-weight: 700; letter-spacing: .12em; color: var(--live); }
.live i { width: 8px; height: 8px; border-radius: 50%; background: var(--live); animation: pulse 1.4s infinite; }
.live.off { color: var(--muted); } .live.off i { background: var(--muted); animation: none; }
@keyframes pulse { 50% { opacity: .25; } }
.controls { margin-left: auto; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: .85rem; color: var(--muted); }
button, select, input { font: inherit; font-size: .85rem; color: var(--fg); background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 5px 10px; }
button { cursor: pointer; } button:hover { border-color: var(--muted); }
:focus-visible { outline: 2px solid var(--kmt); outline-offset: 2px; }

.notice { margin-top: 14px; padding: 10px 14px; border: 1px dashed var(--warn); color: var(--warn); border-radius: 6px; font-size: .85rem; }
.notice.ok { border-color: var(--ok); color: var(--ok); border-style: solid; }

.tally { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-top: 16px; }
.tally > div:not(.seatbar) { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; }
.tally .k { font-size: .75rem; color: var(--muted); letter-spacing: .08em; }
.tally .v { font-size: 1.6rem; font-weight: 600; }
.seatbar { grid-column: 1 / -1; display: flex; gap: 3px; height: 14px; }
.seatbar span { flex: 1; border-radius: 3px; background: var(--line); transition: background .4s, opacity .4s; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; margin-block: 16px 28px; }
@media (max-width: 420px) { .grid { grid-template-columns: 1fr; } }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 16px; min-width: 0; display: flex; flex-direction: column; gap: 12px; }
.card-head { display: flex; align-items: baseline; gap: 10px; }
.card-head h2 { margin: 0; font-size: 1.2rem; font-weight: 900; }
.pill { margin-left: auto; font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; letter-spacing: .06em; border: 1px solid currentColor; white-space: nowrap; }
.pill.counting { color: var(--muted); } .pill.lead { color: var(--warn); } .pill.won { color: #fff; border-color: transparent; }
.progress { font-size: .8rem; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.pbar { height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; }
.pbar b { display: block; height: 100%; background: var(--fg); transition: width .6s; }
.stack { display: flex; height: 22px; border-radius: 4px; overflow: hidden; background: var(--line); }
.stack span { transition: width .6s; }
.cands { display: flex; flex-direction: column; gap: 6px; }
.cand { display: grid; grid-template-columns: 10px 1fr auto auto; gap: 10px; align-items: center; font-size: .92rem; }
.cand .dot { width: 10px; height: 10px; border-radius: 2px; }
.cand .name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cand .name em { font-style: normal; color: var(--muted); font-size: .78rem; margin-left: 6px; }
.cand .name em:first-child { margin-left: 0; margin-right: 2px; }
.cand .votes { color: var(--muted); font-size: .85rem; }
.cand .pct { font-weight: 600; min-width: 4.2em; text-align: right; }
.cand.top .name { font-weight: 700; }
.cand.minor { font-size: .82rem; color: var(--muted); }
.margin { font-size: .8rem; color: var(--muted); border-top: 1px solid var(--line); padding-top: 8px; }
.flash { animation: flash .9s; }
@keyframes flash { from { color: var(--live); } }
footer { color: var(--muted); font-size: .78rem; padding-bottom: 28px; }
footer p { margin: 4px 0; }
@media (prefers-reduced-motion: reduce) { *, *::before { animation: none !important; transition: none !important; } }

header .races { display: flex; gap: 4px; padding-block: 0; border-top: 1px solid var(--line); }
.races button { border: 0; border-bottom: 3px solid transparent; border-radius: 0; background: none; padding: 8px 14px 9px; font-size: .95rem; font-weight: 700; color: var(--muted); }
.races button[aria-selected="true"] { color: var(--fg); border-bottom-color: var(--fg); }
.group { font-size: 1rem; font-weight: 900; margin: 22px 0 0; letter-spacing: .04em; }
.grid + .more, .more { display: block; width: 100%; margin: 0 0 20px; padding: 12px; font-weight: 700; background: var(--surface); border-style: dashed; }
.more[aria-expanded="true"] { margin-bottom: 0; }
#m-rest, #c-rest { margin-top: 16px; }
.hint { color: var(--muted); font-size: .85rem; margin: 12px 0 0; }
.tpp { color: var(--tpp); }

/* council */
.card.open { grid-column: 1 / -1; }
.parties { display: flex; flex-direction: column; gap: 5px; }
.prow { display: grid; grid-template-columns: 10px 1fr auto auto; gap: 10px; align-items: center; font-size: .9rem; }
.prow .dot { width: 10px; height: 10px; border-radius: 2px; }
.prow .pv { color: var(--muted); font-size: .85rem; }
.prow .pp { font-weight: 600; min-width: 4.2em; text-align: right; }
.prow.minor { color: var(--muted); font-size: .82rem; }
.toggle-d { align-self: flex-start; font-weight: 700; }
.lead-sum { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: .88rem; padding: 10px 12px; background: var(--bg); border-radius: 8px; }
.lead-sum b { font-family: var(--mono); }
.districts { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.dist { border: 1px solid var(--line); border-radius: 8px; padding: 12px; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.dist h3 { margin: 0; font-size: .98rem; display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.dist h3 small { font-weight: 500; color: var(--muted); font-size: .78rem; }
.dist .progress { font-size: .76rem; }
.crow { display: grid; grid-template-columns: 1.6em 10px 1fr auto auto; gap: 8px; align-items: center; font-size: .86rem; padding: 2px 0; }
.crow .rk { color: var(--muted); font-family: var(--mono); font-size: .76rem; text-align: right; }
.crow .dot { width: 9px; height: 9px; border-radius: 2px; }
.crow .name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crow .name em { font-style: normal; color: var(--muted); font-size: .74rem; margin-left: 5px; }
.crow .cv { color: var(--muted); font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: .8rem; }
.crow .cp { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: .8rem; min-width: 3.8em; text-align: right; }
.crow.in { font-weight: 700; }
.crow.in .rk { color: var(--fg); }
.cutline { border-top: 1px dashed var(--muted); margin: 3px 0; font-size: .7rem; color: var(--muted); text-align: right; line-height: 1.6; }
.loading { color: var(--muted); font-size: .85rem; }
@media (max-width: 420px) { .districts { grid-template-columns: 1fr; } }
.pill.likely { color: var(--ok); }
.pill.na { color: var(--muted); border-style: dashed; }
.seatbar { flex-wrap: wrap; }
.seatbar span { min-width: 10px; }
footer a { color: inherit; }

/* admin */
.admin-city { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; display: grid; gap: 8px; }
.admin-city h2 { margin: 0; font-size: 1.05rem; }
.admin-row { display: grid; grid-template-columns: 1fr 9em auto; gap: 8px; align-items: center; font-size: .9rem; }
.admin-row input[type=number] { width: 100%; font-family: var(--mono); }
.admin-row label.el { font-size: .8rem; color: var(--muted); display: flex; gap: 4px; align-items: center; white-space: nowrap; }
.admin-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-block: 16px; }
.primary { background: var(--fg); color: var(--bg); border-color: var(--fg); }
#status { font-size: .85rem; }

/* 手機：標題列不固定，避免佔掉太多畫面 */
@media (max-width: 600px) {
  header { position: static; }
  body::before { display: none; }
  .controls { margin-left: 0; }
}
