:root {
  --bg: #04060c; --bg-2: #070a14;
  --ink: #eef2f8; --muted: #7a859a; --muted-l: #a3aec2;
  --line: rgba(255,255,255,.08); --line-s: rgba(255,255,255,.16);
  --glass: rgba(255,255,255,.045);
  --right: #3f8ae0; --right-g: rgba(74,148,234,.45);
  --left: #ef5f5f; --left-g: rgba(239,95,95,.42);
  --swing: #2bb0c7; --swing-g: rgba(43,176,199,.42);
  --good: #34d29b; --warn: #f2b95a;
  --ease: cubic-bezier(.22,1,.36,1);
  --serif: 'Fraunces', Georgia, serif;
  --sans: 'Hanken Grotesk', -apple-system, 'Segoe UI', Roboto, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.4 var(--sans); }
body { min-height: 100dvh; padding-bottom: calc(76px + env(safe-area-inset-bottom)); overflow-x: hidden; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
.num, .serif { font-family: var(--serif); font-variant-numeric: tabular-nums; font-optical-sizing: auto; }
.tnum { font-variant-numeric: tabular-nums; }
.eyebrow { font-size: 10.5px; font-weight: 700; letter-spacing: .16em; text-transform: uppercase; color: var(--muted); }
.muted { color: var(--muted-l); }
.small { font-size: 12.5px; }

.aurora { position: fixed; inset: -20%; z-index: -1; pointer-events: none; filter: blur(40px); opacity: .55;
  background:
    radial-gradient(40% 30% at 15% 20%, var(--left-g), transparent 70%),
    radial-gradient(40% 30% at 85% 25%, var(--right-g), transparent 70%),
    radial-gradient(35% 25% at 50% 80%, rgba(43,165,62,.25), transparent 70%);
  animation: drift 38s ease-in-out infinite alternate; }
@keyframes drift { 0% { transform: translate3d(0,0,0) scale(1); } 50% { transform: translate3d(3%,-2%,0) scale(1.06); } 100% { transform: translate3d(-3%,2%,0) scale(1); } }

/* header */
.top { position: sticky; top: 0; z-index: 5; padding: calc(10px + env(safe-area-inset-top)) 16px 0;
  background: linear-gradient(var(--bg) 70%, rgba(4,6,12,.0)); }
.top-row { display: flex; justify-content: space-between; align-items: flex-end; }
.count { display: flex; align-items: baseline; gap: 6px; margin-top: 2px; }
.count .num { font-size: 34px; font-weight: 500; letter-spacing: -.02em; line-height: 1; }
.count-l { color: var(--muted-l); font-size: 13px; }
.live { white-space: nowrap; display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--muted-l); padding: 8px 12px; border-radius: 999px; background: var(--glass); border: 1px solid var(--line); min-height: 36px; }
.live .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); box-shadow: 0 0 10px var(--good); animation: pulse 1.6s ease infinite; }
.live.stale .dot { background: var(--warn); box-shadow: 0 0 10px var(--warn); }
.live.err .dot { background: var(--left); box-shadow: 0 0 10px var(--left); animation: none; }
@keyframes pulse { 50% { opacity: .35; } }
.pcbar { height: 3px; border-radius: 3px; background: var(--line); margin: 10px 0 0; overflow: hidden; }
.pcbar div { height: 100%; width: 0; background: linear-gradient(90deg, var(--swing), var(--good)); transition: width .8s var(--ease); }

main { padding: 12px 16px 24px; max-width: 560px; margin: 0 auto; }
section.card { position: relative; margin: 0 0 14px; padding: 16px; border-radius: 20px; background: var(--glass);
  border: 1px solid var(--line); box-shadow: 0 18px 50px -30px rgba(0,0,0,.9); }
.card h2 { margin: 0 0 10px; font: 600 11px/1 var(--sans); letter-spacing: .16em; text-transform: uppercase; color: var(--muted); display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.card h2 .r { letter-spacing: .04em; text-transform: none; font-weight: 500; color: var(--muted-l); font-size: 12px; }
.note { font-size: 12px; color: var(--muted); margin: 10px 0 0; line-height: 1.45; }

/* segmented control */
.seg { display: flex; background: rgba(255,255,255,.05); border: 1px solid var(--line); border-radius: 999px; padding: 3px; gap: 2px; margin-bottom: 12px; }
.seg button { flex: 1; min-height: 40px; border-radius: 999px; font-size: 13px; font-weight: 600; color: var(--muted-l); transition: background .3s var(--ease), color .3s; }
.seg button.on { background: rgba(255,255,255,.12); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line-s); }

/* hemicycle */
.hemi { width: 100%; display: block; }
.hemi-num { text-anchor: middle; fill: var(--ink); font-family: var(--serif); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 12px; margin-top: 8px; font-size: 12.5px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }

/* bloc bar */
.bloc { margin-top: 4px; }
.bloc-bar { position: relative; display: flex; height: 30px; border-radius: 10px; overflow: hidden; background: rgba(255,255,255,.04); }
.bloc-bar > div { height: 100%; transition: width .8s var(--ease); display: flex; align-items: center; justify-content: center; font: 600 13px var(--sans); color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.5); overflow: hidden; white-space: nowrap; }
.bloc-mid { position: absolute; left: 50%; top: -4px; bottom: -4px; width: 2px; background: var(--ink); border-radius: 2px; box-shadow: 0 0 8px rgba(255,255,255,.6); }
.bloc-lab { display: flex; justify-content: space-between; margin-top: 8px; font-size: 13px; }
.bloc-lab b { font-family: var(--serif); font-size: 22px; font-weight: 500; }

/* stat tiles */
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tile { padding: 12px 10px; border-radius: 16px; background: rgba(255,255,255,.035); border: 1px solid var(--line); }
.tile .num { font-size: 24px; font-weight: 500; display: block; margin-top: 4px; }
.tile .eyebrow { font-size: 9.5px; }

/* party table */
.ptable { width: 100%; border-collapse: collapse; font-size: 14px; }
.ptable th { font: 700 9.5px var(--sans); letter-spacing: .14em; text-transform: uppercase; color: var(--muted); text-align: right; padding: 0 4px 8px; }
.ptable th:first-child { text-align: left; }
.ptable td { padding: 9px 4px; border-top: 1px solid var(--line); text-align: right; font-variant-numeric: tabular-nums; }
.ptable td:first-child { text-align: left; }
.pname { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.pbar { height: 4px; border-radius: 4px; margin-top: 5px; opacity: .9; }
.chg { font-size: 11.5px; }
.up { color: var(--good); } .down { color: #f58585; }
.seatn { font-family: var(--serif); font-size: 18px; }
.ptable tr.more td { color: var(--muted-l); font-size: 13px; }
.linkbtn { color: var(--swing); font-weight: 600; font-size: 13px; min-height: 44px; padding: 0 4px; }

/* gov odds */
.odds { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.odd { position: relative; padding: 14px; border-radius: 18px; border: 1px solid var(--line); background: rgba(255,255,255,.035); overflow: hidden; }
.odd::before { content: ''; position: absolute; inset: -40% -40% auto auto; width: 140%; height: 140%; background: radial-gradient(closest-side, var(--g), transparent); opacity: .5; pointer-events: none; }
.odd .num { font-size: 38px; font-weight: 500; letter-spacing: -.02em; display: block; line-height: 1.05; margin-top: 4px; }
.odd .sub { font-size: 12px; color: var(--muted-l); }
.odd.R { --g: var(--right-g); } .odd.L { --g: var(--left-g); } .odd.S { --g: var(--swing-g); } .odd.N { --g: rgba(130,146,172,.3); }

/* bars / ranges */
.range { display: grid; grid-template-columns: 52px 1fr 64px; align-items: center; gap: 10px; padding: 7px 0; font-size: 13px; }
.range .track { position: relative; height: 22px; }
.range .track .ax { position: absolute; top: 10px; left: 0; right: 0; height: 2px; background: var(--line); }
.range .track .iv { position: absolute; top: 6px; height: 10px; border-radius: 6px; opacity: .55; }
.range .track .md { position: absolute; top: 2px; width: 4px; height: 18px; border-radius: 2px; margin-left: -2px; }
.range .v { text-align: right; font-variant-numeric: tabular-nums; }
.range .v b { font-family: var(--serif); font-size: 17px; font-weight: 500; }

.hist { display: flex; align-items: flex-end; gap: 1px; height: 110px; position: relative; }
.hist div { flex: 1; border-radius: 2px 2px 0 0; min-height: 1px; }
.hist-axis { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 6px; }

/* electorates */
.search { width: 100%; min-height: 46px; border-radius: 14px; border: 1px solid var(--line-s); background: rgba(255,255,255,.05); color: var(--ink); padding: 0 14px; font: 15px var(--sans); outline: none; }
.search:focus { border-color: rgba(255,255,255,.3); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 10px 0 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line-s); font-size: 13px; font-weight: 600; color: var(--muted-l); background: rgba(255,255,255,.03); }
.chip.on { color: var(--ink); background: rgba(255,255,255,.12); border-color: rgba(255,255,255,.28); }
.erow { display: grid; grid-template-columns: 6px 1fr auto; gap: 12px; align-items: center; width: 100%; text-align: left; padding: 12px 12px 12px 0; border-top: 1px solid var(--line); min-height: 64px; }
.erow:active { background: rgba(255,255,255,.04); }
.erow .stripe { width: 6px; align-self: stretch; border-radius: 3px; }
.erow .nm { font-weight: 650; font-size: 15px; }
.erow .ld { font-size: 12.5px; color: var(--muted-l); margin-top: 2px; }
.erow .rt { text-align: right; font-size: 12px; color: var(--muted-l); }
.erow .rt b { display: block; font-family: var(--serif); font-size: 17px; font-weight: 500; color: var(--ink); }
.prob { display: inline-block; padding: 2px 7px; border-radius: 999px; font-size: 11px; font-weight: 700; margin-top: 3px; }

/* candidate bars */
.cand { padding: 9px 0; border-top: 1px solid var(--line); }
.cand:first-child { border-top: 0; }
.cand .row1 { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; }
.cand .row1 b { font-weight: 650; }
.cand .bar { height: 8px; border-radius: 6px; background: rgba(255,255,255,.05); margin-top: 6px; overflow: hidden; }
.cand .bar div { height: 100%; border-radius: 6px; transition: width .6s var(--ease); }

/* sheet */
.sheet { position: fixed; inset: 0; z-index: 20; }
.sheet-back { position: absolute; inset: 0; background: rgba(0,0,0,.6); animation: fade .3s var(--ease); }
.sheet-card { position: absolute; left: 0; right: 0; bottom: 0; max-height: 88dvh; overflow-y: auto; padding: 20px 16px calc(24px + env(safe-area-inset-bottom));
  border-radius: 26px 26px 0 0; background: linear-gradient(#0c111d, #070a12); border-top: 1px solid var(--line-s);
  box-shadow: 0 -30px 100px -20px rgba(0,0,0,.9); animation: rise .45s var(--ease); max-width: 560px; margin: 0 auto; }
.sheet-x { position: absolute; top: 10px; right: 10px; width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; }
.sheet-x svg { width: 20px; height: 20px; stroke: var(--muted-l); stroke-width: 2; fill: none; stroke-linecap: round; }
.sheet h3 { font: 500 26px/1.15 var(--serif); margin: 4px 48px 4px 0; }
@keyframes rise { from { transform: translateY(40%); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

/* builder */
.pgrid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.ptoggle { display: flex; align-items: center; gap: 10px; min-height: 56px; padding: 8px 12px; border-radius: 16px; border: 1px solid var(--line-s); text-align: left; background: rgba(255,255,255,.03); transition: background .25s, border-color .25s, transform .15s; }
.ptoggle:active { transform: scale(.97); }
.ptoggle.on { background: color-mix(in srgb, var(--pc) 22%, transparent); border-color: var(--pc); }
.ptoggle .nm { font-weight: 650; font-size: 14px; }
.ptoggle .s { font-size: 12px; color: var(--muted-l); }
.ptoggle .ck { margin-left: auto; width: 22px; height: 22px; border-radius: 7px; border: 1.5px solid var(--line-s); display: grid; place-items: center; flex: none; }
.ptoggle.on .ck { background: var(--pc); border-color: var(--pc); }
.ptoggle .ck svg { width: 14px; height: 14px; stroke: #fff; stroke-width: 3; fill: none; opacity: 0; }
.ptoggle.on .ck svg { opacity: 1; }
.bigres { display: flex; align-items: baseline; gap: 10px; margin: 6px 0 10px; }
.bigres .num { font-size: 44px; font-weight: 500; letter-spacing: -.02em; }
.meter { position: relative; height: 14px; border-radius: 8px; background: rgba(255,255,255,.06); overflow: hidden; display: flex; }
.meter > div { height: 100%; transition: width .6s var(--ease); }
.meter .mk { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--ink); }
.blocrow { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 8px; padding: 6px 0; border-top: 1px solid var(--line); }
.blocpick { display: flex; gap: 4px; }
.blocpick button { min-width: 44px; min-height: 40px; border-radius: 10px; font-size: 12px; font-weight: 700; color: var(--muted-l); border: 1px solid var(--line); }
.blocpick button.on.R { background: var(--right); color: #fff; border-color: var(--right); }
.blocpick button.on.L { background: #d94a4a; color: #fff; border-color: #d94a4a; }
.blocpick button.on.S { background: #1f8fa3; color: #fff; border-color: #1f8fa3; }
.blocpick button.on.O { background: rgba(255,255,255,.14); color: var(--ink); }

/* trend chart */
.chart { width: 100%; display: block; overflow: visible; }
.chart text { fill: var(--muted); font: 10.5px var(--sans); }

/* tabs */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
  background: rgba(6,8,15,.88); border-top: 1px solid var(--line); backdrop-filter: blur(20px) saturate(1.3); -webkit-backdrop-filter: blur(20px) saturate(1.3); }
.tabs button { flex: 1; min-height: 56px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 11px; font-weight: 600; color: var(--muted); border-radius: 14px; }
.tabs svg { width: 22px; height: 22px; stroke: currentColor; stroke-width: 1.8; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.tabs button.on { color: var(--ink); background: rgba(255,255,255,.07); }
.tabs button:active { transform: scale(.95); }

.empty { text-align: center; color: var(--muted-l); padding: 40px 10px; }
.spin { width: 28px; height: 28px; border: 2px solid var(--line-s); border-top-color: var(--ink); border-radius: 50%; margin: 0 auto 12px; animation: sp 1s linear infinite; }
@keyframes sp { to { transform: rotate(1turn); } }
.flash { animation: flash 1.2s var(--ease); }
@keyframes flash { 0% { background: rgba(52,210,155,.18); } }

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

/* regions */
.reg { padding: 11px 0; border-top: 1px solid var(--line); }
.reg:first-of-type { border-top: 0; }
.reg1 { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 14.5px; }
.reg2 { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; margin-top: 8px; }
.regbar { display: flex; height: 6px; border-radius: 4px; overflow: hidden; margin-top: 8px; background: rgba(255,255,255,.05); gap: 1px; }
.regbar div { height: 100%; }
