/* Editorial layout. Colour roles (light + dark are each selected, not flipped). */
.viz-root {
  color-scheme: light;
  --surface-0: #ffffff;
  --surface-1: #ffffff;
  --map-bg: #f3f3f1;
  --hairline: #e2e2df;
  --text-primary: #121212;
  --text-secondary: #4d4d4b;
  --text-muted: #757571;
  --nda: #eb6834;
  --india: #2a78d6;
  --oth: #1baf7a;
  --nodata: #e4e4e1;
  --mid: #f0efec;
  --focus: #121212;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.08);
  --sans: "Libre Franklin", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --serif: "Source Serif 4", Georgia, "Times New Roman", serif;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .viz-root {
    color-scheme: dark;
    --surface-0: #121211; --surface-1: #1a1a19; --map-bg: #161615; --hairline: #2f2f2c;
    --text-primary: #f0efec; --text-secondary: #c3c2b7; --text-muted: #8f8e86;
    --nda: #d95926; --india: #3987e5; --oth: #199e70; --nodata: #2a2a27; --mid: #383835; --focus: #f0efec;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 20px rgba(0,0,0,.45);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--surface-0); color: var(--text-primary); font: 16px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* headline block */
.hed { max-width: 760px; margin: 0 auto; padding: 48px 20px 12px; text-align: center; }
.kicker { font: 700 12px/1 var(--sans); letter-spacing: .14em; text-transform: uppercase; color: var(--text-secondary); margin: 0 0 14px; }
.hed h1 { font: 700 clamp(30px, 5vw, 48px)/1.08 var(--serif); letter-spacing: -0.015em; margin: 0 0 16px; }
.dek { font: 400 clamp(17px, 2.2vw, 20px)/1.45 var(--serif); color: var(--text-secondary); margin: 0 auto 14px; max-width: 640px; }
.byline { font: 500 13px/1.4 var(--sans); color: var(--text-muted); margin: 0; }

/* seat tally */
.topline { max-width: 760px; margin: 22px auto 26px; padding: 0 20px; }
.seatbar .labels { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 6px; }
.seatbar .side { font: 600 13px/1.2 var(--sans); }
.seatbar .side b { display: block; font: 800 26px/1 var(--sans); letter-spacing: -0.01em; }
.seatbar .side.r { text-align: right; }
.seatbar .side .nm { color: var(--text-secondary); font-weight: 600; }
.seatbar .track { position: relative; display: flex; height: 14px; gap: 2px; }
.seatbar .track span { display: block; height: 100%; }
.seatbar .track span:first-child { border-radius: 3px 0 0 3px; }
.seatbar .track span:last-child { border-radius: 0 3px 3px 0; }
.seatbar .maj { position: absolute; top: -5px; bottom: -5px; width: 2px; background: var(--text-primary); }
.seatbar .majlbl { position: absolute; top: 22px; transform: translateX(-50%); font: 600 11px/1 var(--sans); color: var(--text-secondary); white-space: nowrap; }
.seatbar .oth { text-align: center; font: 500 12px/1 var(--sans); color: var(--text-muted); margin-top: 26px; }

/* map */
.map-section { margin: 0 auto; max-width: 1600px; padding: 0 12px; }
.map-wrap { position: relative; height: min(86vh, 920px); min-height: 520px; background: var(--map-bg); border-radius: 4px; overflow: hidden; }
#map { position: absolute; inset: 0; }
.map-note { text-align: center; font: 500 12px/1.4 var(--sans); color: var(--text-muted); margin: 10px 0 0; }
.overlay { position: absolute; z-index: 3; }
.overlay-tl { top: 14px; left: 14px; display: flex; flex-direction: column; gap: 8px; width: 270px; }
.overlay-tr { top: 14px; right: 56px; max-width: 360px; }
.overlay-r { top: 14px; right: 14px; bottom: 14px; width: 340px; overflow: auto; z-index: 4; }
.overlay-bl { bottom: 14px; left: 14px; }
.search { display: flex; align-items: center; gap: 8px; background: var(--surface-1); border-radius: 4px; padding: 0 10px; box-shadow: var(--shadow); color: var(--text-muted); }
.search input { flex: 1; border: 0; background: transparent; font: 500 14px/1 var(--sans); color: var(--text-primary); padding: 11px 0; outline: none; min-width: 0; }
.seg { display: flex; background: var(--surface-1); border-radius: 4px; box-shadow: var(--shadow); padding: 3px; }
.seg button { flex: 1; border: 0; background: transparent; font: 600 12px/1 var(--sans); color: var(--text-secondary); padding: 8px 4px; border-radius: 3px; cursor: pointer; }
.seg button[aria-selected="true"] { background: var(--text-primary); color: var(--surface-1); }
.ctl-inline { display: flex; align-items: center; gap: 8px; background: var(--surface-1); border-radius: 4px; box-shadow: var(--shadow); padding: 0 0 0 10px; }
.ctl-inline label { font: 700 10px/1 var(--sans); letter-spacing: .08em; text-transform: uppercase; color: var(--text-muted); white-space: nowrap; }
.ctl-inline select { flex: 1; min-width: 0; appearance: none; -webkit-appearance: none; border: 0; background: transparent url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23757571' stroke-width='1.6'/%3E%3C/svg%3E") no-repeat right 10px center; font: 600 13px/1 var(--sans); color: var(--text-primary); padding: 10px 26px 10px 0; cursor: pointer; text-overflow: ellipsis; }
.btn { font: 600 12px/1 var(--sans); color: var(--text-primary); background: var(--surface-1); border: 0; border-radius: 4px; padding: 9px 12px; box-shadow: var(--shadow); cursor: pointer; }
.maplibregl-ctrl-group { box-shadow: var(--shadow) !important; border-radius: 4px !important; }
.maplibregl-ctrl-attrib { font: 400 10px/1.4 var(--sans); }

/* legend */
.legend { background: color-mix(in srgb, var(--surface-1) 94%, transparent); border-radius: 4px; box-shadow: var(--shadow); padding: 10px 12px; font: 500 12px/1.3 var(--sans); color: var(--text-secondary); display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; }
.legend .title { font: 700 12px/1.2 var(--sans); color: var(--text-primary); width: 100%; }
.legend .sw { display: inline-block; width: 11px; height: 11px; border-radius: 2px; vertical-align: -1px; margin-right: 5px; }
.legend .ramp { display: flex; align-items: center; gap: 7px; }
.legend .ramp .bar { width: 160px; height: 9px; border-radius: 2px; }
.legend .ramp .bar.split { display: flex; gap: 1px; width: 72px !important; }
.legend .ramp .bar.split span { flex: 1; }
.legend .muted { width: 100%; font-size: 11px; color: var(--text-muted); }
.legend.inline { background: none; box-shadow: none; padding: 6px 0 0; }

/* tooltip */
.tooltip { position: absolute; top: 0; left: 0; z-index: 6; pointer-events: none; width: 290px; background: var(--surface-1); color: var(--text-primary); border-radius: 4px; box-shadow: 0 2px 4px rgba(0,0,0,.08), 0 10px 30px rgba(0,0,0,.18); padding: 12px 14px; font: 400 13px/1.35 var(--sans); }
.tooltip h3 { margin: 0 0 2px; font: 700 15px/1.2 var(--sans); }
.tooltip .sub { color: var(--text-muted); font-size: 12px; margin-bottom: 8px; }
.tooltip .note { color: var(--text-muted); font-size: 11px; margin-top: 8px; }

/* candidate rows */
.cands { width: 100%; border-collapse: collapse; }
.cands td { padding: 4px 0; vertical-align: middle; }
.cands td.v { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; padding-left: 10px; }
.cands td.p { text-align: right; font-variant-numeric: tabular-nums; color: var(--text-secondary); width: 50px; }
.cands .nm { display: flex; align-items: center; gap: 7px; }
.cands .key { width: 3px; height: 14px; border-radius: 1px; flex: none; }
.cands .cname { font-weight: 500; }
.cands .party { color: var(--text-muted); font-size: 11px; font-weight: 600; letter-spacing: .02em; }
.cands .barwrap { height: 4px; background: var(--hairline); border-radius: 2px; margin: 4px 0 0 10px; }
.cands .barfill { height: 4px; border-radius: 2px; }
.cands tr.win .cname { font-weight: 700; }

/* selected-area card */
.card { background: var(--surface-1); border-radius: 4px; box-shadow: var(--shadow); padding: 16px 18px; }
.seat h2 { font: 700 20px/1.2 var(--serif); margin: 0 26px 4px 0; }
.seat .close { position: absolute; top: 10px; right: 10px; width: 28px; height: 28px; border: 0; background: transparent; font: 400 22px/1 var(--sans); color: var(--text-muted); cursor: pointer; border-radius: 50%; }
.seat .close:hover { background: var(--map-bg); }
.muted { color: var(--text-muted); }
.small { font-size: 12px; }
#seat-sub { font-size: 13px; margin: 0 0 12px; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 3px 12px; font-size: 13px; margin-top: 12px; }
.kv .k { color: var(--text-secondary); }
.kv .v { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.kv .grp, .booths .grp { grid-column: 1 / -1; font: 700 10px/1.2 var(--sans); text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--hairline); }
.booths { margin-top: 6px; }
.bwrap { max-height: 300px; overflow: auto; border: 1px solid var(--hairline); border-radius: 4px; margin-top: 6px; }
.btable { width: 100%; border-collapse: collapse; font-size: 12px; font-variant-numeric: tabular-nums; }
.btable th { position: sticky; top: 0; background: var(--surface-1); text-align: left; font-weight: 700; color: var(--text-secondary); padding: 6px 8px; border-bottom: 1px solid var(--hairline); }
.btable td { padding: 4px 8px; border-bottom: 1px solid var(--hairline); }
.btable td:nth-child(3), .btable td:nth-child(4), .btable th:nth-child(3), .btable th:nth-child(4) { text-align: right; }
.btable .key { display: inline-block; width: 3px; height: 11px; border-radius: 1px; vertical-align: -1px; }

/* story */
.story { max-width: 720px; margin: 56px auto 0; padding: 0 20px 72px; }
.story h2 { font: 700 28px/1.2 var(--serif); margin: 0 0 12px; }
.story > p { font: 400 19px/1.55 var(--serif); margin: 0 0 24px; }
.figure { margin: 28px 0 40px; }
.figure h3 { font: 700 17px/1.3 var(--sans); margin: 0 0 4px; }
.fig-controls { display: flex; gap: 10px; flex-wrap: wrap; }
.fig-controls .ctl-inline { box-shadow: none; border: 1px solid var(--hairline); flex: 1; min-width: 240px; }
.stat { margin: 12px 0 4px; font-size: 14px; color: var(--text-secondary); }
.stat b { color: var(--text-primary); font-variant-numeric: tabular-nums; }
#scatter { width: 100%; height: 380px; display: block; }
#scatter .dot { stroke: var(--surface-0); stroke-width: .8; }
#scatter .dot.hl { stroke: var(--focus); stroke-width: 2; }
#scatter .axis text { fill: var(--text-muted); font: 500 11px var(--sans); }
#scatter .axis path, #scatter .axis line { stroke: var(--hairline); }
#scatter .grid line { stroke: var(--hairline); }
#scatter .fit { stroke: var(--text-primary); stroke-width: 1.5; stroke-dasharray: 4 4; fill: none; opacity: .7; }
#scatter .lbl { fill: var(--text-secondary); font: 600 12px var(--sans); }
#rank .r { display: grid; grid-template-columns: 1fr 160px 48px; align-items: center; gap: 12px; font-size: 14px; padding: 7px 4px; border-bottom: 1px solid var(--hairline); cursor: pointer; }
#rank .r:hover { background: var(--map-bg); }
#rank .r .lbl small { color: var(--text-muted); font-size: 11px; }
#rank .r .track { position: relative; height: 10px; }
#rank .r .track::before { content: ""; position: absolute; left: 50%; top: -3px; bottom: -3px; width: 1px; background: var(--text-muted); }
#rank .r .b { position: absolute; top: 0; height: 10px; border-radius: 2px; }
#rank .r .val { text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; }
.notes { margin-top: 48px; padding-top: 20px; border-top: 1px solid var(--hairline); color: var(--text-secondary); font-size: 13px; line-height: 1.55; }
.notes h3 { font: 700 13px/1 var(--sans); text-transform: uppercase; letter-spacing: .08em; color: var(--text-primary); margin: 0 0 10px; }
.notes ul { padding-left: 18px; margin: 0; }
.notes li { margin: 6px 0; }

/* small screens */
@media (max-width: 820px) {
  .hed { padding-top: 28px; text-align: left; }
  .map-wrap { height: 72vh; }
  .overlay-tl { right: 14px; width: auto; }
  .overlay-tl .ctl-inline ~ .ctl-inline { display: none; }
  .overlay-tr { top: auto; bottom: 14px; right: 14px; left: 120px; }
  .overlay-r { position: fixed; left: 0; right: 0; bottom: 0; top: auto; width: auto; max-height: 60vh; border-radius: 12px 12px 0 0; }
}
/* keep the legend clear of the detail card while it is open */
.map-wrap:has(#seat-card:not([hidden])) .overlay-tr { right: 368px; }
.map-wrap:has(#seat-card:not([hidden])) .maplibregl-ctrl-top-right { right: 354px; }
@media (max-width: 820px) { .map-wrap:has(#seat-card:not([hidden])) .overlay-tr { right: 14px; } .map-wrap:has(#seat-card:not([hidden])) .maplibregl-ctrl-top-right { right: 0; } }
