:root {
  --bg: #fafaf8; --fg: #16181d; --muted: #6b7079; --line: #e3e3df; --card: #fff; --accent: #c8102e;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #111317; --fg: #eceef2; --muted: #9aa0aa; --line: #2a2e35; --card: #181b20; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
main, .top, footer { max-width: 960px; margin: 0 auto; padding: 0 16px; }
.top { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; padding-top: 20px; }
h1 { font-size: 1.1rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 40px 0 12px; }
h2 small, h3 small { margin-left: 6px; color: var(--muted); font-weight: 400; }
.status { color: var(--muted); margin: 0; font-size: .9rem; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); margin-right: 6px; }
.dot.live { background: var(--accent); animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { opacity: .3; } }

.hero { text-align: center; padding: 20px 0 4px; }
.hero-label { color: var(--muted); margin: 0; text-transform: uppercase; letter-spacing: .08em; font-size: .8rem; }
.hero-pair { display: flex; justify-content: center; align-items: flex-end; gap: clamp(20px, 7vw, 64px); margin-bottom: 10px; }
.hero-number { font-size: clamp(2rem, 9vw, 3.4rem); font-weight: 800; margin: 2px 0 0; font-variant-numeric: tabular-nums; letter-spacing: -.02em; line-height: 1.1; }
.hero-votes { font-size: clamp(1.5rem, 6.5vw, 2.5rem); }
.hero-sub { color: var(--muted); font-size: .8rem; margin: 8px 0 0; }
.hero-sub b { color: var(--fg); font-weight: 600; font-variant-numeric: tabular-nums; }
.updated { font-variant-numeric: tabular-nums; }
.progress { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; max-width: 560px; margin: 0 auto; }
#progress-bar { height: 100%; width: 0; background: var(--accent); }

.bar-wrap { position: relative; }
.seatbar { position: relative; display: flex; height: 28px; border-radius: 4px; background: var(--line); cursor: pointer; touch-action: manipulation; }
.seatbar:focus-visible { outline: 2px solid var(--fg); outline-offset: 4px; }
.seatbar > div { height: 100%; min-width: 0; box-shadow: inset -1px 0 0 var(--bg); transition: flex-basis .8s, opacity .15s, transform .15s, filter .15s; }
.seatbar > div:first-child { border-radius: 4px 0 0 4px; }
.seatbar > div:last-child { border-radius: 0 4px 4px 0; }
/* Same hover effect as the bloc bar: the picked party lifts and brightens, the rest dims. */
.seatbar.focus > div { opacity: .35; }
.seatbar.focus > div.on { opacity: 1; transform: scaleY(1.35); filter: brightness(1.12); position: relative; z-index: 1; border-radius: 3px; }
.seatbar::after { content: ""; position: absolute; left: 50%; top: -4px; bottom: -4px; border-left: 2px dashed var(--fg); }

table.parties { width: 100%; border-collapse: collapse; margin-top: 12px; font-variant-numeric: tabular-nums; }
.parties th, .parties td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; }
.parties th { color: var(--muted); font-weight: 500; font-size: .85rem; }
.num { text-align: right !important; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 8px; vertical-align: middle; }
.seats { font-weight: 800; }

#filter { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 6px; background: var(--card); color: var(--fg); font: inherit; }
.provinces { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; margin-top: 12px; }
.prov { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 12px; }
.prov h3 { margin: 0 0 4px; font-size: .95rem; display: flex; justify-content: space-between; }
.prov h3 span { color: var(--muted); font-weight: 400; }
.prov .meta { color: var(--muted); font-size: .8rem; margin: 0 0 8px; }
.prov ul { list-style: none; margin: 0; padding: 0; font-size: .88rem; font-variant-numeric: tabular-nums; }
.prov li { display: flex; justify-content: space-between; padding: 2px 0; }
footer { color: var(--muted); font-size: .8rem; padding-top: 32px; padding-bottom: 40px; }

.more-row { display: flex; justify-content: center; gap: 6px; margin-top: 10px; }
.more { padding: 4px 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--card); color: var(--muted); font: inherit; font-size: .78rem; cursor: pointer; }
.more:hover { color: var(--fg); }
.more:hover { border-color: var(--muted); }
.more[hidden] { display: none; }

/* Race for prime minister: two blocs pushing towards the 176 line from each end, decisivos in grey in between. */
.blocs { position: relative; margin-bottom: 18px; }
.bloc-heads { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 22px; }
.bloc-head { flex: 1 1 0; display: flex; align-items: center; gap: 10px; min-width: 0; }
.bloc-head.right { flex-direction: row-reverse; text-align: right; }
.bloc-head div { display: flex; flex-direction: column; line-height: 1.2; }
.bloc-head div span { color: var(--muted); font-size: .78rem; }
.bloc-total { font-size: 2rem; font-variant-numeric: tabular-nums; line-height: 1; }
.bloc-bar { position: relative; display: flex; height: 26px; background: var(--line); border-radius: 6px; cursor: pointer; touch-action: manipulation; }
.bloc-bar:focus-visible { outline: 2px solid var(--fg); outline-offset: 4px; }
.bloc-group { display: flex; height: 100%; min-width: 0; }
.bloc-group.left .bloc-seg:first-child { border-radius: 6px 0 0 6px; }
.bloc-group.right .bloc-seg:last-child { border-radius: 0 6px 6px 0; }
.bloc-gap { flex: 1; display: flex; justify-content: center; min-width: 0; }
.bloc-seg { height: 100%; min-width: 0; box-shadow: inset -1px 0 0 var(--bg); transition: opacity .15s, transform .15s, filter .15s; }
/* A slice picked for the popup lifts and brightens; the rest of the bar dims. */
.bloc-bar.focus .bloc-seg { opacity: .35; }
.bloc-bar.focus .bloc-seg.on { opacity: 1; transform: scaleY(1.35); filter: brightness(1.12); position: relative; z-index: 1; border-radius: 3px; }
.bloc-line { position: absolute; left: 50%; top: -5px; bottom: -5px; width: 2px; margin-left: -1px; background: var(--fg); }
.bloc-176 { position: absolute; left: 50%; top: -22px; transform: translateX(-50%); font-size: .72rem; font-weight: 700; }
.bloc-legend { display: grid; grid-template-columns: 1fr auto 1fr; gap: 12px; margin-top: 8px; font-size: .85rem; }
.bloc-legend > div { display: flex; flex-direction: column; min-width: 0; }
.bloc-legend { cursor: pointer; border-radius: 6px; }
.bloc-legend:focus-visible { outline: 2px solid var(--fg); outline-offset: 4px; }
.bloc-legend > div > span { text-decoration: underline dotted var(--muted); text-underline-offset: 3px; }
.bloc-legend > div { transition: opacity .15s; }
.bloc-legend.focus > div { opacity: .45; }
.bloc-legend.focus > div.on { opacity: 1; }
.bloc-legend .mid { text-align: center; }
.bloc-legend .right { text-align: right; }
.bloc-legend em { font-style: normal; font-weight: 700; color: var(--accent); text-transform: uppercase; font-size: .75rem; letter-spacing: .04em; }
.bloc-note { margin: 10px 0 0; padding: 6px 10px; border-left: 3px solid var(--accent); background: var(--card); font-size: .82rem; }
.bloc-note[hidden] { display: none; }
.bar-tip { position: absolute; z-index: 20; width: max-content; max-width: min(300px, 100%); padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--card); color: var(--fg); box-shadow: 0 8px 24px rgb(0 0 0 / .25); font-size: .8rem; line-height: 1.35;
  pointer-events: none; opacity: 0; visibility: hidden; transform: translateY(6px) scale(.98); transform-origin: var(--arrow, 50%) 100%;
  transition: opacity .15s ease-out, transform .15s ease-out, visibility 0s linear .15s; }
.bar-tip.show { opacity: 1; visibility: visible; transform: none; transition: opacity .15s ease-out, transform .15s ease-out; pointer-events: auto; }
.bar-tip::after { content: ''; position: absolute; top: 100%; left: var(--arrow, 50%); margin-left: -6px; border: 6px solid transparent; border-top-color: var(--card); }
.bar-tip.below { transform-origin: var(--arrow, 50%) 0; }
.bar-tip.below:not(.show) { transform: translateY(-6px) scale(.98); }
.bar-tip.below::after { top: auto; bottom: 100%; border-top-color: transparent; border-bottom-color: var(--card); }
.bar-tip p { margin: 0 0 4px; }
.bar-tip .bt-head { display: flex; align-items: center; gap: 2px; font-size: .9rem; }
.bar-tip .bt-seats { margin-left: auto; padding-left: 12px; font-weight: 700; white-space: nowrap; }
.bar-tip .bt-name { color: var(--muted); font-size: .75rem; }
.bar-tip .bt-side { margin-top: 6px; }
.bar-tip ul { margin: 6px 0 0; padding: 6px 0 0; list-style: none; border-top: 1px solid var(--line); color: var(--muted); }
.bar-tip li b { color: var(--fg); }
@media (prefers-reduced-motion: reduce) {
  .bloc-seg, .seatbar > div, .bar-tip, .bar-tip.show { transition: none; }
  .bar-tip { transform: none; }
  .bloc-bar.focus .bloc-seg.on, .seatbar.focus > div.on { transform: none; }
}
.pm-cands { margin-top: 16px; }
.pm-cands[hidden] { display: none; }
.pm-sub { font-size: .85rem; font-weight: 600; margin: 0 0 8px; color: var(--muted); }
.pm-rows { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.pm-card { font: inherit; color: inherit; cursor: pointer; transition: border-color .15s, box-shadow .15s, transform .15s; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 6px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); text-align: center; }
.pm-card.lead { border-color: var(--fg); }
/* Portrait popping out of a circle: the image is taller than the circle and bottom-aligned; the mask keeps the part
   inside the circle plus a circle-wide column above its centre, so the head rises over the top edge. */
.pm-pic { --s: 56px; --pop: 1.45; position: relative; display: block; flex: none; width: var(--s); height: var(--s);
  margin-top: calc(var(--s) * (var(--pop) - 1)); }
.pm-pic::before { content: ''; position: absolute; inset: 0; border-radius: 50%; background: var(--c);
  box-shadow: inset 0 -6px 12px rgb(0 0 0 / .25); }
.pm-pic img { position: absolute; left: 50%; bottom: 0; width: calc(var(--s) * var(--pop)); height: calc(var(--s) * var(--pop));
  transform: translateX(-50%); object-fit: cover;
  --m: radial-gradient(circle calc(var(--s) / 2) at 50% calc(100% - var(--s) / 2), #000 99%, transparent 100%),
       linear-gradient(#000 0 0) 50% 0 / var(--s) calc(100% - var(--s) / 2) no-repeat;
  -webkit-mask: var(--m); mask: var(--m); }
.bloc-head .pm-pic { --s: 60px; }
#pm-credits a { color: inherit; }
.pm-who { display: flex; flex-direction: column; align-items: center; line-height: 1.2; min-width: 0; }
.pm-who span { color: var(--muted); font-size: .75rem; }
.pm-who em { font-style: normal; font-size: .65rem; font-weight: 600; color: var(--accent); text-transform: uppercase; letter-spacing: .04em; }
.pm-num { display: flex; align-items: baseline; gap: 4px; }
.pm-seats { font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.pm-move { font-size: .75rem; font-weight: 700; }
.pm-move.up { color: #1a9a4b; }
.pm-move.down { color: var(--accent); }
.pm-wait { margin: 0 0 10px; font-size: .85rem; color: var(--muted); }
.pm-note { margin: 8px 0 0; font-size: .75rem; color: var(--muted); }
@media (max-width: 560px) {
  .pm-rows { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .bloc-total { font-size: 1.6rem; margin: 0 4px; }
  .bloc-head { gap: 8px; }
  .bloc-head div { display: none; }
  .bloc-head .pm-pic { --s: 46px; }
  .pm-card .pm-pic { --s: 46px; }
  .bloc-legend { grid-template-columns: 1fr 1fr; }
  .bloc-legend .mid { grid-column: 1 / -1; grid-row: 2; }
}
.map-tip li small { display: block; color: var(--muted); font-size: .72rem; margin-left: 18px; }
.map-tip li.tip-head { color: var(--muted); font-size: .75rem; margin-bottom: 2px; }

/* Map: provinces coloured by the leading party; lighter while the count is early. */
.map-wrap { position: relative; }
.map { position: relative; z-index: 1; width: 100%; height: auto; display: block; }
/* Municipios: a canvas under the SVG (and one above it for the outline of the one under the pointer). */
.map-canvas { position: absolute; left: 0; top: 0; width: 100%; height: 100%; pointer-events: none; }
.map-hl { z-index: 2; }
.map-prov.munis path { fill-opacity: 0; stroke-width: .6; }
.map-legend .map-note-li { color: var(--muted); font-size: .78rem; }
.map-prov path, .map-prov circle { fill: var(--fill, var(--line)); fill-opacity: var(--alpha, 1); stroke: var(--bg); stroke-width: .8; transition: fill .6s, fill-opacity .6s; cursor: pointer; }
.map-prov circle { stroke-width: 1.5; }
.map-prov:hover path, .map-prov.active path, .map-prov:focus path, .map-prov.active circle { stroke: var(--fg); stroke-width: 1.6; }
.map-prov:focus { outline: none; }
.map-frame { fill: none; stroke: var(--line); stroke-width: 1; }
.map-tip { position: absolute; left: 8px; top: 8px; min-width: 190px; max-width: 260px; padding: 8px 10px; background: var(--card); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 4px 16px rgb(0 0 0 / .15); font-size: .85rem; pointer-events: none; z-index: 3; }
.map-tip > span { color: var(--muted); font-size: .8rem; }
.map-tip p { margin: 2px 0 6px; color: var(--muted); font-size: .8rem; }
.map-tip ul { list-style: none; margin: 0; padding: 0; }
.map-tip li { display: flex; justify-content: space-between; gap: 8px; }
.map-legend { list-style: none; display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 8px 0 0; padding: 0; font-size: .85rem; }
.map-legend b { color: var(--muted); font-weight: 600; margin-left: 2px; }
.map-note { margin: 4px 0 0; font-size: .75rem; color: var(--muted); }

/* Live chat (placeholder look). Inline section on narrow screens, fixed sidebar on wide ones. */
.chat { max-width: 960px; margin: 40px auto 0; padding: 0 16px; display: flex; flex-direction: column; }
.chat header { display: flex; justify-content: space-between; align-items: baseline; }
.chat h2 { margin: 0 0 8px; }
.chat header small { color: var(--muted); font-size: .8rem; }
.chat-list { list-style: none; margin: 0; padding: 8px; height: 320px; overflow-y: auto; background: var(--card); border: 1px solid var(--line); border-radius: 8px; font-size: .9rem; overflow-wrap: anywhere; }
.chat-list li { padding: 3px 0; }
.chat-list time { color: var(--muted); font-size: .75rem; margin-right: 6px; font-variant-numeric: tabular-nums; }
.chat-list b { margin-right: 6px; }
.chat-form { display: grid; gap: 6px; margin-top: 8px; }
.chat-form input { padding: 9px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--card); color: var(--fg); font: inherit; min-width: 0; }
.chat-row { display: flex; gap: 6px; }
.chat-row input { flex: 1; }
.chat-form button { padding: 0 14px; border: 0; border-radius: 6px; background: var(--accent); color: #fff; font: inherit; font-weight: 600; cursor: pointer; }
.chat-form button:disabled { opacity: .6; }
.chat-form.closed button[type="submit"] { opacity: .5; }
.chat-note { margin: 0; min-height: 1.2em; font-size: .8rem; color: var(--accent); }
.chat-rules { margin: 0; font-size: .75rem; color: var(--muted); }
/* Emotes: inline in messages, and a picker under the input. */
.emote { height: 28px; width: auto; vertical-align: middle; margin: -4px 1px; }
.chat-form .emote-toggle { padding: 0 10px; background: var(--card); color: var(--fg); border: 1px solid var(--line); font-size: 1.1rem; }
.emote-picker { display: flex; flex-wrap: wrap; gap: 4px; max-height: 160px; overflow-y: auto; padding: 6px; background: var(--card); border: 1px solid var(--line); border-radius: 6px; }
.emote-picker[hidden] { display: none; }
.chat-form .emote-picker button { padding: 2px; background: none; border: 0; border-radius: 4px; cursor: pointer; }
.emote-picker button:hover, .emote-picker button:focus-visible { background: var(--line); }
.emote-picker img { height: 28px; width: auto; display: block; }
/* Superchats: paid messages, pinned on top for a while (longer for bigger amounts), plus the night's ranking. */
.chat-list li.paid, .chat-pins li { background: color-mix(in srgb, var(--accent) 10%, var(--card)); border-left: 3px solid var(--accent); padding: 4px 6px; margin: 3px 0; border-radius: 4px; }
.paid-tag { display: inline-block; font-size: .7rem; font-weight: 600; color: var(--accent); margin-right: 6px; white-space: nowrap; }
.chat-pins { list-style: none; margin: 0 0 6px; padding: 0; font-size: .9rem; overflow-wrap: anywhere; }
.chat-pins:empty { display: none; }
.chat-pins b { margin-right: 6px; }
.chat-top { margin-bottom: 6px; font-size: .8rem; }
.chat-top h3 { margin: 0 0 2px; font-size: .8rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.chat-top ol { margin: 0; padding-left: 1.4em; }
.chat-top li span { color: var(--muted); margin-left: 4px; font-variant-numeric: tabular-nums; }
.chat-super { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: .8rem; color: var(--muted); }
.chat-form .chat-super button { padding: 4px 10px; background: var(--card); color: var(--accent); border: 1px solid var(--accent); }
@media (min-width: 1320px) {
  body { padding-right: 340px; }
  .chat { position: fixed; top: 0; right: 0; bottom: 0; width: 340px; margin: 0; padding: 16px; border-left: 1px solid var(--line); background: var(--bg); }
  .chat-list { flex: 1; height: auto; }
}

/* Shown whenever results.json has "simulated": true (replays, mock feed). Never in live mode. */
.sim-banner { position: sticky; top: 0; z-index: 50; grid-column: 1 / -1; margin: 0; padding: 8px 16px; text-align: center;
  background: repeating-linear-gradient(-45deg, #ffd400 0 14px, #ffe14d 14px 28px); color: #16181d; font-size: .9rem; border-bottom: 2px solid #16181d; }
.sim-banner b { letter-spacing: .08em; }
.sim-banner[hidden] { display: none; }

/* Candidate cards double as map selectors. */
.pm-card:hover { border-color: var(--muted); }
.pm-card:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; }
.pm-card.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.pm-sub small { font-weight: 400; }
.map-scale { display: flex; align-items: center; gap: 6px; }
.map-ramp { display: inline-block; width: 120px; height: 10px; border-radius: 5px;
  background: linear-gradient(to right, color-mix(in srgb, var(--k) 15%, var(--bg)), var(--k)); }
.map-reset { padding: 3px 10px; border: 1px solid var(--line); border-radius: 999px; background: var(--card); color: var(--fg); font: inherit; font-size: .8rem; cursor: pointer; }
.map-reset:hover { border-color: var(--muted); }
.map-tip .tip-sel { color: var(--fg); margin: 0 0 6px; }
/* Explanations and credits, at the end of the page. */
.notes { margin: 8px 0 16px; padding-top: 12px; border-top: 1px solid var(--line); }
.notes h2 { font-size: .9rem; margin: 0 0 8px; }
.notes p { margin: 0 0 8px; font-size: .78rem; color: var(--muted); }
.notes a { color: inherit; }
@media (prefers-reduced-motion: reduce) { .pm-card { transition: none; } }

/* "Escaños en el Congreso" / "Por provincia" as tabs in one section. */
.tabbed { margin-top: 40px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs [role="tab"] { flex: none; padding: 10px 14px; border: 0; border-bottom: 3px solid transparent; margin-bottom: -1px; background: none;
  color: var(--muted); font: inherit; font-size: 1.05rem; font-weight: 700; cursor: pointer; transition: color .15s, border-color .15s; }
.tabs [role="tab"]:hover { color: var(--fg); }
.tabs [role="tab"][aria-selected="true"] { color: var(--fg); border-bottom-color: var(--accent); }
.tabs [role="tab"]:focus-visible, [role="tabpanel"]:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; }
[role="tabpanel"][hidden] { display: none; }
.tab-sub { margin: 0 0 10px; font-size: .85rem; color: var(--muted); }
@media (max-width: 420px) { .tabs [role="tab"] { padding: 10px 10px; font-size: .95rem; } }
@media (prefers-reduced-motion: reduce) { .tabs [role="tab"] { transition: none; } }

/* Popup lists (bloc legend). */
.bar-tip .bt-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2px 14px; margin: 6px 0 0; padding: 0; border: 0; color: var(--fg); }
.bar-tip .bt-list li { display: flex; align-items: center; gap: 2px; min-width: 0; }
.bar-tip .bt-list b { margin-left: auto; padding-left: 8px; }
/* Percentage and seats side by side (map popups, province cards), no separator: seats in bold. */
.ps { display: inline-flex; gap: 10px; }
.ps b { min-width: 1.4em; text-align: right; }
.sim-banner span { margin-left: 8px; }
