:root {
  --bg: rgba(18, 20, 24, 0.92);
  --fg: #e8e8e8;
  --muted: #9aa0a6;
  --line: rgba(255, 255, 255, 0.12);
  --accent: #4cc9f0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
html, body { margin: 0; height: 100%; background: #0b0c0e; color: var(--fg); }
#map { position: absolute; inset: 0; }

#panel {
  position: absolute; top: 12px; left: 12px; width: 300px; max-height: calc(100% - 24px);
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  display: flex; flex-direction: column; box-shadow: 0 6px 24px rgba(0,0,0,.45); z-index: 2;
  font-size: 13px; backdrop-filter: blur(4px);
}
#panel header { display: flex; justify-content: space-between; align-items: flex-start; padding: 12px 14px 8px; border-bottom: 1px solid var(--line); }
#panel h1 { font-size: 15px; margin: 0; font-weight: 650; }
#panel .sub { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
#collapse { background: none; border: 1px solid var(--line); color: var(--fg); border-radius: 6px; width: 26px; height: 26px; cursor: pointer; font-size: 16px; line-height: 1; }
#panel.collapsed #panel-body { display: none; }
#panel.collapsed { width: auto; }
#panel-body { overflow-y: auto; padding: 4px 14px 12px; }
#panel section { padding: 10px 0; border-bottom: 1px solid var(--line); }
#panel h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 8px; font-weight: 600; }
#panel h2 label { cursor: pointer; }
select { width: 100%; background: #23262b; color: var(--fg); border: 1px solid var(--line); border-radius: 6px; padding: 5px 6px; font-size: 13px; }
.row { display: flex; align-items: center; gap: 8px; margin: 6px 0; }
.row > span { flex: 0 0 96px; color: var(--muted); }
.row > select, .row > input[type=range], .row > .seg { flex: 1; min-width: 0; }
input[type=range] { accent-color: var(--accent); }
.check { display: flex; align-items: center; gap: 6px; margin: 6px 0; cursor: pointer; }
.scale { color: var(--muted); font-size: 12px; margin: 6px 0 4px; }
.note { color: var(--muted); font-size: 11.5px; margin: 6px 0 0; line-height: 1.35; }
.note:empty { display: none; }

#legend .item, #elec-legend .item { display: flex; align-items: center; gap: 7px; padding: 2px 0; cursor: pointer; user-select: none; }
#legend .item .lt { min-width: 0; }
#legend .item.off { opacity: .35; }
.sw { width: 11px; height: 11px; border-radius: 50%; flex: 0 0 11px; }
.sq { width: 11px; height: 11px; border-radius: 2px; flex: 0 0 11px; }
#legend .actions { margin-top: 4px; font-size: 11.5px; }
#legend .actions a { color: var(--accent); cursor: pointer; margin-right: 10px; }
.ramp { height: 10px; border-radius: 3px; margin: 4px 0 2px; }
.ramp-labels { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; }

.seg { display: flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { flex: 1; background: #23262b; color: var(--fg); border: 0; padding: 6px 0; cursor: pointer; font-size: 12.5px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent); color: #0b0c0e; font-weight: 600; }
#panel footer { color: var(--muted); font-size: 11.5px; line-height: 1.4; padding-top: 10px; }

#info {
  position: absolute; right: 12px; bottom: 34px; width: 320px; max-height: 70%; overflow-y: auto;
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; z-index: 2;
  font-size: 12.5px; box-shadow: 0 6px 24px rgba(0,0,0,.45);
}
#info-close { position: absolute; top: 6px; right: 8px; background: none; border: 0; color: var(--muted); font-size: 18px; cursor: pointer; }
#info h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 10px 0 6px; }
#info h3:first-child { margin-top: 0; }
#info .place { font-weight: 600; font-size: 13.5px; margin-bottom: 2px; }
#info .bar { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; margin: 2px 0; }
#info .bar .lbl { display: flex; align-items: center; gap: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#info .bar .track { grid-column: 1 / 3; height: 4px; background: rgba(255,255,255,.08); border-radius: 2px; margin-top: -1px; }
#info .bar .fill { height: 100%; border-radius: 2px; }
#info .num { text-align: right; font-variant-numeric: tabular-nums; }
#info .muted { color: var(--muted); }
.maplibregl-ctrl-attrib { font-size: 10.5px; }
.seg4 button { font-size: 11.5px; padding: 6px 1px; }
#etype { margin-bottom: 4px; }
#elec-sec.off #elec-body { display: none; }
#elec-legend .item { cursor: default; }
#elec-legend .cols { columns: 2; column-gap: 10px; }
#info .sub2 { margin-top: 6px; }
.check.disabled { opacity: .45; cursor: default; }
.lab { color: var(--muted); margin: 8px 0 4px; }

/* "Figures for" summaries */
.focus-row { display: flex; align-items: center; gap: 8px; margin: 8px 0 4px; }
.focus-row > span { color: var(--muted); flex: 0 0 auto; }
.focus-row select { flex: 1; min-width: 0; padding: 3px 6px; font-size: 12.5px; }
.stack { display: flex; height: 22px; border-radius: 5px; overflow: hidden; margin: 4px 0 6px; background: rgba(255,255,255,.06); }
.stack > div { height: 100%; display: flex; align-items: center; justify-content: center; font-size: 10.5px; font-weight: 650;
  color: rgba(0,0,0,.78); overflow: hidden; white-space: nowrap; min-width: 0; }
.stack > div + div { box-shadow: inset 1px 0 0 rgba(0,0,0,.35); }
.chips { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 10px; font-size: 12px; }
.chips .chip { display: flex; align-items: center; gap: 6px; min-width: 0; }
.chips .chip .k { font-weight: 600; }
.chips .chip .v { margin-left: auto; font-variant-numeric: tabular-nums; }
.chg { font-size: 11px; font-variant-numeric: tabular-nums; margin-left: 4px; }
.chg.up { color: #8ce99a; }
.chg.down { color: #ffa8a8; }
.sumline { color: var(--muted); font-size: 11.5px; margin: 6px 0 2px; }
#legend .item .pc { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12px; }
#legend .item.off .pc { opacity: .6; }

/* click box: area vs province vs country */
#info table.cmp { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
#info table.cmp th { color: var(--muted); font-weight: 500; font-size: 11px; text-align: right; padding: 0 0 3px 6px; }
#info table.cmp td { padding: 2px 0 2px 6px; text-align: right; vertical-align: top; }
#info table.cmp td:first-child, #info table.cmp th:first-child { text-align: left; padding-left: 0; }
#info table.cmp td:first-child { display: flex; align-items: center; gap: 6px; }
#info table.cmp td.here { font-weight: 600; width: 56px; }
#info table.cmp td.other { color: var(--muted); width: 40px; }
#info .mini { height: 3px; background: rgba(255,255,255,.08); border-radius: 2px; margin-top: 2px; }
#info .mini i { display: block; height: 100%; border-radius: 2px; }
#info .cmpline { margin: 4px 0; }

/* sources dialog */
.linkbtn { display: block; margin-top: 8px; background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font-size: 12px; text-align: left; }
.linkbtn:hover { text-decoration: underline; }
#modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 10; display: flex; align-items: center; justify-content: center; }
#modal[hidden] { display: none; }
#modal .box { position: relative; width: min(760px, calc(100% - 40px)); max-height: calc(100% - 60px); overflow-y: auto;
  background: #16181c; border: 1px solid var(--line); border-radius: 12px; padding: 18px 24px 22px; font-size: 13px; line-height: 1.45;
  box-shadow: 0 10px 40px rgba(0,0,0,.6); }
#modal h2 { margin: 0 0 6px; font-size: 17px; }
#modal h3 { margin: 16px 0 4px; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
#modal ul { margin: 0; padding-left: 18px; }
#modal li { margin: 3px 0; }
#modal p { margin: 4px 0; color: var(--muted); }
#modal a { color: var(--accent); word-break: break-word; }
#modal-close { position: absolute; top: 8px; right: 12px; background: none; border: 0; color: var(--muted); font-size: 24px; cursor: pointer; }
#modal-close:hover { color: var(--fg); }
.row.wide > span { flex: 0 0 auto; }

/* values toggle and play button */
.valrow { display: flex; align-items: center; gap: 8px; padding: 8px 0 2px; }
.valrow > span { color: var(--muted); flex: 0 0 auto; }
.valrow .seg { flex: 1; }
.valrow .seg button { padding: 4px 0; font-size: 12px; }
.iconbtn { flex: 0 0 30px; height: 28px; background: #23262b; color: var(--fg); border: 1px solid var(--line); border-radius: 6px; cursor: pointer; font-size: 12px; }
.iconbtn.on { background: var(--accent); color: #0b0c0e; }
#info .sub, .chips .sub { color: var(--muted); font-size: 11px; font-weight: 400; }
#info .num { white-space: nowrap; }

/* search */
#search { position: absolute; top: 12px; left: 324px; width: 330px; z-index: 3; }
body.panel-closed #search { left: 12px; }
#panel header { position: relative; }
#search-input { width: 100%; box-sizing: border-box; background: var(--bg); color: var(--fg); border: 1px solid var(--line); border-radius: 8px;
  padding: 9px 12px; font-size: 14px; box-shadow: 0 6px 24px rgba(0,0,0,.45); backdrop-filter: blur(4px); outline: none; }
#search-input:focus { border-color: var(--accent); }
#search-results { list-style: none; margin: 4px 0 0; padding: 4px; background: #16181c; border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 8px 30px rgba(0,0,0,.55); max-height: 60vh; overflow-y: auto; }
#search-results li { padding: 7px 9px; border-radius: 6px; cursor: pointer; }
#search-results li.on, #search-results li:hover { background: rgba(76, 201, 240, .14); }
#search-results .nm { font-size: 13.5px; }
#search-results .via { color: var(--accent); font-size: 11.5px; margin-left: 4px; }
#search-results .ds { color: var(--muted); font-size: 11.5px; margin-top: 1px; }
.pulse { width: 18px; height: 18px; border-radius: 50%; background: rgba(76, 201, 240, .9); border: 2px solid #fff;
  box-shadow: 0 0 0 0 rgba(76, 201, 240, .7); animation: pulse 1.6s ease-out infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(76, 201, 240, .7); } 100% { box-shadow: 0 0 0 22px rgba(76, 201, 240, 0); } }

/* year shown while playing through the elections */
#badge { position: absolute; top: 60px; left: 50%; transform: translateX(-50%); z-index: 2; pointer-events: none; text-align: center;
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 6px 16px 8px; opacity: 0; transition: opacity .4s; }
#badge.on { opacity: 1; }
#badge b { display: block; font-size: 30px; line-height: 1.1; font-variant-numeric: tabular-nums; }
#badge span { color: var(--muted); font-size: 12px; }

#panel .hint { display: none; }
/* phones and narrow windows: the panel and the info box become sheets along the bottom */
@media (max-width: 700px) {
  :root { --bar: 62px; }
  #panel.collapsed header { height: var(--bar); box-sizing: border-box; align-items: center; }
  #panel.collapsed .hint { display: block; color: var(--muted); font-size: 12.5px; margin: 1px 0 0; }
  :root { font-size: 15px; }
  select, input, button { font-size: 16px; }        /* stops iOS zooming into form fields */
  #search { top: calc(8px + env(safe-area-inset-top)); left: 8px !important; right: 8px; width: auto; }
  #search-input { padding: 10px 12px; font-size: 16px; }
  #badge { top: calc(62px + env(safe-area-inset-top)); }
  #panel { top: auto; left: 0; right: 0; bottom: 0; width: auto; max-height: 72dvh; border-radius: 14px 14px 0 0; background: #121418;
    padding-bottom: env(safe-area-inset-bottom); font-size: 14px; }
  #panel header { cursor: pointer; padding: 10px 14px; }
  #panel header::before { content: ''; position: absolute; top: 5px; left: 50%; width: 38px; height: 4px; margin-left: -19px;
    border-radius: 2px; background: rgba(255,255,255,.25); }
  #panel h1 { font-size: 16px; }
  #panel.collapsed { width: auto; }
  #panel.collapsed .sub { display: none; }
  #collapse { width: 34px; height: 34px; font-size: 18px; }
  #panel-body { padding: 0 16px 16px; -webkit-overflow-scrolling: touch; }
  .row > span { flex-basis: 108px; }
  .seg button { padding: 8px 0; font-size: 14px; }
  .seg4 button { font-size: 12.5px; padding: 8px 1px; }
  .valrow .seg button { padding: 6px 0; font-size: 13px; }
  #legend .item { padding: 5px 0; }
  .check { margin: 9px 0; }
  .iconbtn { flex-basis: 40px; height: 36px; font-size: 14px; }
  #info { left: 0; right: 0; bottom: calc(var(--bar) + env(safe-area-inset-bottom)); width: auto; max-height: calc(64dvh - var(--bar)); border-radius: 14px 14px 0 0; z-index: 4; background: #121418;
    padding: 14px 16px 14px; font-size: 14px; box-sizing: border-box; box-shadow: 0 -6px 24px rgba(0,0,0,.5); }
  #info-close { font-size: 26px; top: 4px; right: 10px; }
  #info .place { font-size: 16px; padding-right: 28px; }
  #modal .box { width: calc(100% - 20px); max-height: calc(100% - 30px); padding: 16px; font-size: 14px; }
  .maplibregl-ctrl-bottom-left { bottom: 56px; }
  .maplibregl-ctrl-bottom-right { bottom: 56px; }
  .chips { font-size: 13px; }
}
.chips.one { grid-template-columns: 1fr; }
.chips .chip .v { white-space: nowrap; }
