:root {
  --bg: #f2f4fa;
  --bg-grad: radial-gradient(1200px 500px at 50% -200px, #dfe7ff 0%, transparent 70%);
  --card: #ffffff;
  --card-2: #f6f8fc;
  --text: #0b1020;
  --muted: #667085;
  --faint: #98a2b3;
  --line: #e7ebf3;
  --accent: #3366ff;
  --accent-soft: #e8eeff;
  --coal: #3b82f6;
  --opp: #f43f5e;
  --arab: #22c55e;
  --gold: #f5b014;
  --up: #12a150;
  --down: #e5484d;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 6px 24px -8px rgba(16, 24, 40, .10);
  --shadow-lg: 0 20px 60px -15px rgba(16, 24, 40, .35);
  --r: 20px;
  --num: 'Rubik', 'Heebo', system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #090d1a; --bg-grad: radial-gradient(1200px 500px at 50% -200px, #1a2550 0%, transparent 70%);
    --card: #121a2f; --card-2: #0f1628; --text: #eef2ff; --muted: #9aa4bf; --faint: #69738f; --line: #1e2843;
    --accent: #5b8cff; --accent-soft: #1a2650; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 30px -10px rgba(0,0,0,.6); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #090d1a; --bg-grad: radial-gradient(1200px 500px at 50% -200px, #1a2550 0%, transparent 70%);
  --card: #121a2f; --card-2: #0f1628; --text: #eef2ff; --muted: #9aa4bf; --faint: #69738f; --line: #1e2843;
  --accent: #5b8cff; --accent-soft: #1a2650; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 30px -10px rgba(0,0,0,.6); color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  font-family: 'Heebo', system-ui, -apple-system, sans-serif;
  background: var(--bg-grad), var(--bg);
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
.num { font-family: var(--num); font-variant-numeric: tabular-nums; }
.wrap { max-width: 540px; margin: 0 auto; padding: 14px 16px 110px; }

/* header */
.top { display: flex; align-items: center; gap: 12px; padding: 4px 2px 14px; }
.flag { width: 44px; height: 32px; border-radius: 7px; box-shadow: 0 2px 8px rgba(0,0,0,.12); flex: none; overflow: hidden; background: #fff; }
.top h1 { margin: 0; font-size: 22px; font-weight: 800; letter-spacing: -.3px; white-space: nowrap; }
.top .sub { color: var(--muted); font-size: 12.5px; margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .grow { flex: 1; min-width: 0; }
.pill { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 13px; border-radius: 999px; font-size: 13.5px; font-weight: 600; background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow); }
.pill svg { width: 16px; height: 16px; }
.live { color: #e11d48; background: color-mix(in srgb, #e11d48 9%, var(--card)); border-color: color-mix(in srgb, #e11d48 25%, transparent); }
.live .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; position: relative; }
.live .dot::after { content: ''; position: absolute; inset: -4px; border-radius: 50%; background: currentColor; opacity: .35; animation: ping 1.6s infinite; }
.live.off { color: var(--faint); background: var(--card); border-color: var(--line); }
.live.off .dot::after { display: none; }
@keyframes ping { 0% { transform: scale(.6); opacity: .5; } 100% { transform: scale(2.2); opacity: 0; } }

/* cards */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); }
.section { margin-top: 14px; }
.label { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.h2 { display: flex; align-items: baseline; justify-content: space-between; margin: 22px 4px 10px; font-weight: 700; font-size: 15px; }
.h2 small { color: var(--muted); font-weight: 500; font-size: 12px; }

/* hemicycle */
.hero { padding: 16px 14px 14px; position: relative; overflow: hidden; }
.hemi { width: 100%; display: block; }
.hemi-box { position: relative; }
.hemi-center { position: absolute; top: 2px; inset-inline: 0; text-align: center; color: var(--muted); font-size: 12px; line-height: 1.35; }
.hemi-center b { display: block; font-family: var(--num); font-size: 22px; color: var(--text); font-weight: 800; }
.score { display: grid; grid-template-columns: 1fr auto 1fr; align-items: start; margin-top: 14px; position: relative; padding: 0 6px; }
.score .side { text-align: center; }
.score .big { font-family: var(--num); font-weight: 900; font-size: 62px; line-height: .9; letter-spacing: -2px; }
.score .name { font-weight: 700; font-size: 15px; margin-top: 6px; }
.score .note { color: var(--muted); font-size: 12px; margin-top: 2px; }
.score .vs { color: var(--faint); font-weight: 800; font-size: 26px; padding-top: 12px; }
.coal { color: var(--coal); }
.oppc { color: var(--opp); }
.maj-tag { display: inline-flex; align-items: center; gap: 4px; margin-top: 6px; padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 700; background: color-mix(in srgb, currentColor 12%, transparent); }
.mode { position: absolute; top: 12px; inset-inline-start: 12px; display: flex; background: var(--card-2); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.mode button { font-size: 11.5px; padding: 4px 10px; border-radius: 999px; color: var(--muted); font-weight: 600; }
.mode button.on { background: var(--card); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,.12); }

/* stats */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { padding: 13px 12px 12px; }
.stat .v { font-family: var(--num); font-weight: 800; font-size: 23px; letter-spacing: -.5px; }
.stat .l { color: var(--muted); font-size: 12px; margin-top: 2px; }
.meter { height: 5px; border-radius: 9px; background: var(--line); margin-top: 9px; overflow: hidden; }
.meter i { display: block; height: 100%; border-radius: 9px; background: linear-gradient(90deg, #f472b6, #818cf8, #3b82f6); transition: width 1s cubic-bezier(.2,.8,.2,1); }

.blocbar { padding: 14px; }
.bar3 { display: flex; height: 14px; border-radius: 99px; overflow: hidden; position: relative; gap: 2px; background: var(--line); }
.bar3 span { transition: flex-grow .8s cubic-bezier(.2,.8,.2,1); }
.bar3 .mark { position: absolute; top: -3px; bottom: -3px; width: 3px; border-radius: 3px; background: var(--gold); box-shadow: 0 0 0 2px var(--card); }
.legend { display: flex; gap: 16px; margin-top: 10px; font-size: 13px; flex-wrap: wrap; }
.legend b { font-family: var(--num); }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-inline-end: 6px; }

/* last-update banner */
.changes { padding: 12px 14px; display: flex; gap: 10px; align-items: flex-start; }
.changes .ico { width: 34px; height: 34px; border-radius: 11px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); flex: none; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip { display: inline-flex; align-items: center; gap: 4px; font-size: 12.5px; font-weight: 600; padding: 3px 9px; border-radius: 999px; background: var(--card-2); border: 1px solid var(--line); }
.chip.up { color: var(--up); }
.chip.down { color: var(--down); }

/* tabs */
.tabs { position: sticky; top: 0; z-index: 20; margin: 18px -16px 0; padding: 10px 16px; background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); }
.seg { display: grid; grid-template-columns: repeat(4, 1fr); background: var(--card-2); border: 1px solid var(--line); border-radius: 16px; padding: 4px; position: relative; }
.seg button { position: relative; z-index: 1; padding: 9px 2px; font-size: 13.5px; font-weight: 600; color: var(--muted); border-radius: 12px; transition: color .2s; white-space: nowrap; }
.seg button.on { color: var(--text); }
.seg .thumb { position: absolute; top: 4px; bottom: 4px; border-radius: 12px; background: var(--card); box-shadow: 0 2px 8px rgba(0,0,0,.10); transition: inset-inline-start .35s cubic-bezier(.2,.8,.2,1); width: calc((100% - 8px) / 4); }
.pane { display: none; }
.pane.on { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } }

/* party rows */
.plist { display: grid; gap: 9px; margin-top: 12px; }
.prow { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center; padding: 12px 14px; text-align: start; width: 100%; transition: transform .15s; }
.prow:active { transform: scale(.985); }
.badge { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; font-weight: 800; font-size: 15px; letter-spacing: -.3px; flex: none; box-shadow: inset 0 -2px 0 rgba(0,0,0,.12); }
.prow .n { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 6px; }
.prow .m { color: var(--muted); font-size: 12.5px; margin-top: 1px; }
.prow .track { height: 6px; border-radius: 9px; background: var(--line); margin-top: 8px; overflow: hidden; }
.prow .track i { display: block; height: 100%; border-radius: 9px; transition: width 1s cubic-bezier(.2,.8,.2,1); }
.prow .s { font-family: var(--num); font-weight: 900; font-size: 30px; min-width: 44px; text-align: center; }
.delta { font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 6px; }
.delta.up { color: var(--up); background: color-mix(in srgb, var(--up) 12%, transparent); }
.delta.down { color: var(--down); background: color-mix(in srgb, var(--down) 12%, transparent); }
.thresh-head { display: flex; justify-content: space-between; margin: 20px 4px 8px; font-size: 13px; color: var(--muted); font-weight: 600; }
.thresh-head b { color: var(--gold); }
.prow.under .s { font-size: 17px; color: var(--down); }
.prow.under .track { position: relative; overflow: visible; }
.prow.under .track .tm { position: absolute; top: -4px; bottom: -4px; width: 3px; background: var(--gold); border-radius: 2px; }

/* coalition builder */
.builder { padding: 18px; text-align: center; }
.builder .total { font-family: var(--num); font-weight: 900; font-size: 64px; line-height: 1; letter-spacing: -2px; transition: color .3s; }
.builder .total.ok { color: var(--up); }
.builder .msg { color: var(--muted); font-size: 14px; margin-top: 6px; min-height: 20px; }
.stack { display: flex; height: 14px; border-radius: 99px; background: var(--line); overflow: hidden; margin-top: 14px; position: relative; }
.stack span { transition: width .4s cubic-bezier(.2,.8,.2,1); }
.stack .mark { position: absolute; top: 0; bottom: 0; width: 3px; background: var(--gold); }
.presets { display: flex; gap: 8px; overflow-x: auto; padding: 12px 2px 4px; scrollbar-width: none; }
.presets::-webkit-scrollbar { display: none; }
.presets button { white-space: nowrap; padding: 8px 14px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); font-size: 13px; font-weight: 600; box-shadow: var(--shadow); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 10px; }
.pick { display: flex; align-items: center; gap: 9px; padding: 9px 10px; border-radius: 16px; text-align: start; transition: all .2s; }
.pick .badge { width: 36px; height: 36px; border-radius: 11px; font-size: 12.5px; }
.pick .n { flex: 1; min-width: 0; font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pick .s { font-family: var(--num); font-weight: 800; font-size: 19px; }
.pick.on { border-color: var(--pc); background: color-mix(in srgb, var(--pc) 10%, var(--card)); box-shadow: 0 0 0 1.5px var(--pc) inset, var(--shadow); }
.pick .ck { width: 20px; height: 20px; border-radius: 7px; border: 1.5px solid var(--line); display: grid; place-items: center; flex: none; transition: all .2s; }
.pick.on .ck { background: var(--pc); border-color: var(--pc); color: #fff; }

/* night chart */
.vs { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 16px 10px; text-align: center; }
.vs .big { font-family: var(--num); font-weight: 900; font-size: 46px; line-height: 1; }
.vs .mid { color: var(--muted); font-size: 12px; }
.vs .mid b { display: block; color: var(--gold); font-size: 13.5px; margin-bottom: 2px; }
.chart { padding: 14px 8px 8px; }
.chart svg { width: 100%; display: block; overflow: visible; touch-action: pan-y; }
.chart .tip { font-size: 12px; text-align: center; color: var(--muted); min-height: 18px; }
.moments { display: grid; gap: 8px; }
.moment { display: flex; align-items: center; gap: 12px; padding: 11px 14px; font-size: 14px; }
.moment .p { font-family: var(--num); font-weight: 800; color: var(--muted); min-width: 52px; }
.moment .t { flex: 1; }
.moment .tm { color: var(--faint); font-size: 12px; }

/* cities */
.search { display: flex; align-items: center; gap: 8px; padding: 0 14px; height: 48px; margin-top: 12px; }
.search input { flex: 1; border: 0; outline: 0; background: none; font: inherit; font-size: 15px; color: var(--text); }
.search svg { color: var(--faint); }
.crow { display: flex; align-items: center; gap: 12px; padding: 11px 14px; width: 100%; text-align: start; }
.crow .n { flex: 1; font-weight: 600; }
.crow .w { font-size: 12.5px; font-weight: 600; padding: 3px 9px; border-radius: 999px; color: #fff; }
.crow .v { color: var(--faint); font-size: 12px; font-family: var(--num); }

/* sheet */
.scrim { position: fixed; inset: 0; background: rgba(5, 8, 20, .45); backdrop-filter: blur(3px); z-index: 50; opacity: 0; pointer-events: none; transition: opacity .3s; }
.scrim.on { opacity: 1; pointer-events: auto; }
.sheet { position: fixed; inset-inline: 0; bottom: 0; z-index: 51; max-width: 540px; margin: 0 auto; background: var(--card); border-radius: 26px 26px 0 0; padding: 8px 18px calc(22px + env(safe-area-inset-bottom)); transform: translateY(105%); transition: transform .4s cubic-bezier(.2,.9,.2,1); max-height: 88vh; overflow-y: auto; box-shadow: var(--shadow-lg); }
.sheet.on { transform: none; }
.grab { width: 40px; height: 5px; border-radius: 9px; background: var(--line); margin: 4px auto 10px; }
.sheet-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.sheet-head h3 { margin: 0; font-size: 20px; flex: 1; }
.xbtn { width: 36px; height: 36px; border-radius: 50%; background: var(--card-2); display: grid; place-items: center; border: 1px solid var(--line); }
.kv { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.kv > div { background: var(--card-2); border: 1px solid var(--line); border-radius: 16px; padding: 11px 12px; }
.kv .v { font-family: var(--num); font-weight: 800; font-size: 20px; }
.kv .v.num { direction: ltr; text-align: right; }
.kv .l { color: var(--muted); font-size: 12px; }
.spark { margin-top: 12px; padding: 12px; background: var(--card-2); border: 1px solid var(--line); border-radius: 16px; }
.full { color: var(--muted); font-size: 13px; margin: -6px 0 14px; }
.share-img { width: 100%; border-radius: 16px; border: 1px solid var(--line); display: block; background: var(--card-2); aspect-ratio: 4 / 5; object-fit: cover; }
.actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; margin-top: 10px; }
.actions button { padding: 12px 6px; border-radius: 16px; background: var(--card-2); border: 1px solid var(--line); font-size: 12.5px; font-weight: 600; display: grid; justify-items: center; gap: 6px; }
.actions svg { width: 22px; height: 22px; color: var(--accent); }
.primary { width: 100%; height: 54px; border-radius: 17px; background: linear-gradient(180deg, #4a7bff, #2f5fff); color: #fff; font-weight: 700; font-size: 16px; display: flex; align-items: center; justify-content: center; gap: 9px; box-shadow: 0 10px 24px -8px rgba(51, 102, 255, .7); }
.primary svg { width: 20px; height: 20px; }

/* floating share */
.fab { position: fixed; inset-inline: 0; bottom: 0; z-index: 30; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 40%); }
.fab .primary { max-width: 508px; margin: 0 auto; }

.toast { position: fixed; top: 12px; inset-inline: 0; margin: 0 auto; width: max-content; max-width: calc(100% - 32px); z-index: 60; background: #0b1020; color: #fff; padding: 11px 16px; border-radius: 14px; font-size: 14px; font-weight: 600; box-shadow: var(--shadow-lg); transform: translateY(-140%); transition: transform .45s cubic-bezier(.2,.9,.2,1); display: flex; align-items: center; gap: 8px; }
.toast.on { transform: none; }
.foot { color: var(--muted); font-size: 12px; text-align: center; margin-top: 26px; line-height: 1.7; }
.foot a { color: var(--accent); text-decoration: none; }

/* loading / error */
.skel { background: linear-gradient(90deg, var(--line) 25%, var(--card-2) 50%, var(--line) 75%); background-size: 200% 100%; animation: sk 1.3s infinite; border-radius: 14px; }
@keyframes sk { to { background-position: -200% 0; } }
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty .e-ico { width: 64px; height: 64px; border-radius: 20px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; margin: 0 auto 14px; }
.empty h3 { color: var(--text); margin: 0 0 6px; }
.empty button { margin-top: 16px; }

@media (max-width: 420px) {
  #shareTop span { display: none; }
  #shareTop { width: 34px; padding: 0; justify-content: center; }
  .legend { gap: 12px; font-size: 12.5px; }
}
@media (max-width: 380px) {
  .score .big { font-size: 52px; }
  .stat .v { font-size: 19px; }
  .seg button { font-size: 12.5px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* places search */
.ptypes { display: flex; gap: 6px; margin-top: 10px; overflow-x: auto; scrollbar-width: none; }
.ptypes::-webkit-scrollbar { display: none; }
.ptypes button { padding: 7px 14px; border-radius: 999px; font-size: 13px; font-weight: 600; color: var(--muted); background: var(--card); border: 1px solid var(--line); white-space: nowrap; }
.ptypes button.on { color: #fff; background: var(--accent); border-color: var(--accent); }
.crow .ptag { width: 34px; height: 34px; border-radius: 11px; background: var(--card-2); border: 1px solid var(--line); display: grid; place-items: center; font-size: 16px; flex: none; }
.crow .n small { display: block; font-weight: 500; font-size: 12px; color: var(--muted); margin-top: 1px; }
.crow .mstack { display: flex; width: 64px; height: 8px; border-radius: 4px; overflow: hidden; gap: 1px; flex: none; background: var(--line); }
.sheet-sub { display: block; font-size: 13px; font-weight: 500; color: var(--muted); margin-top: 2px; }
.search input::-webkit-search-cancel-button { display: none; }
