:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --ink: #16181d;
  --muted: #6b7280;
  --line: #e3e6ea;
  --ocean: #dfe9f1;
  --land: #d4d8cc;
  --land-border: #ffffff;
  --hover: #bfc6b4;
  --accent: #2b59c3;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121419;
    --panel: #1a1d24;
    --ink: #eceef2;
    --muted: #9aa1ad;
    --line: #2a2f39;
    --ocean: #161c24;
    --land: #3a4049;
    --land-border: #20252d;
    --hover: #4b525d;
    --accent: #7aa2ff;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
button { font: inherit; color: inherit; }

.app {
  display: grid;
  grid-template-columns: 1fr 380px;
  height: 100vh;
}

/* ---------- Map pane ---------- */
.app.sb-hidden { grid-template-columns: 1fr; }
.app.sb-hidden .sidebar { display: none; }

/* The map sits in a frame: a margin in the page colour around a rounded, bordered sea. */
.map-pane {
  position: relative; overflow: hidden; background: var(--ocean);
  margin: 10px; border: 1px solid var(--line); border-radius: 14px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.04), var(--shadow);
}

.topbar {
  position: absolute; top: 12px; left: 12px; right: 12px; z-index: 3;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.topbar h1 {
  margin: 0; font-size: 18px; font-weight: 700;
  background: var(--panel); padding: 8px 14px; border-radius: 10px; box-shadow: var(--shadow);
}
.controls { display: flex; gap: 8px; flex-wrap: wrap; }
.btn, .seg {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow);
}
.btn { padding: 7px 12px; cursor: pointer; }
.btn:hover { border-color: var(--muted); }
.seg { display: flex; padding: 3px; }
.seg button { border: 0; background: none; padding: 5px 10px; border-radius: 7px; cursor: pointer; color: var(--muted); }
.seg button.on { background: var(--accent); color: #fff; }

.map { position: absolute; inset: 0; }
.map svg { width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
.map.dragging svg { cursor: grabbing; }

#map .region {
  fill: var(--land);
  stroke: var(--land-border);
  stroke-width: .8px;
  vector-effect: non-scaling-stroke;
  cursor: pointer;
  transition: fill .15s;
}
#map .micro {
  fill: var(--land);
  stroke: var(--muted);
  stroke-width: 1px;
  vector-effect: non-scaling-stroke;
  cursor: pointer;
}
#map .region:hover, #map .micro:hover { filter: brightness(.9); }
#map .region:not(.picked):hover, #map .micro:not(.picked):hover { fill: var(--hover); filter: none; }
#map .active { stroke: var(--ink); stroke-width: 2px; }

.zoom {
  position: absolute; right: 12px; bottom: 12px; z-index: 3;
  display: flex; flex-direction: column; background: var(--panel);
  border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); overflow: hidden;
}
.zoom button { width: 36px; height: 34px; border: 0; background: none; cursor: pointer; font-size: 18px; }
.zoom button + button { border-top: 1px solid var(--line); }
.zoom button:hover { background: var(--bg); }

.legend {
  position: absolute; left: 12px; bottom: 12px; z-index: 3; max-width: calc(100% - 80px);
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow);
  padding: 10px 12px;
}
.legend h3 { margin: 0 0 6px; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.legend ul { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(2, auto); gap: 3px 16px; }
.legend li { display: flex; align-items: center; gap: 6px; font-size: 12.5px; white-space: nowrap; }
.legend li.zero { opacity: .4; }
.legend .sw { width: 11px; height: 11px; border-radius: 3px; flex: none; }
.legend .n { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 600; padding-left: 8px; }

.tip {
  position: fixed; z-index: 10; pointer-events: none;
  background: var(--ink); color: var(--panel); padding: 5px 9px; border-radius: 7px; font-size: 12.5px;
  white-space: nowrap; transform: translate(12px, 12px);
}
.tip small { opacity: .75; }

/* ---------- Sidebar ---------- */
.sidebar {
  background: var(--panel); border-left: 1px solid var(--line);
  overflow-y: auto; display: flex; flex-direction: column;
}
.sb-head { padding: 20px 20px 14px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); z-index: 1; }
.sb-kicker { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; min-height: 1em; }
.sb-head h2 { margin: 2px 0 8px; font-size: 22px; }
.sb-pick { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.sb-pick .dot { width: 10px; height: 10px; border-radius: 50%; }
.sb-pick button { margin-left: auto; border: 1px solid var(--line); background: none; border-radius: 7px; padding: 3px 9px; cursor: pointer; font-size: 12.5px; }

.party-list { padding: 14px; display: flex; flex-direction: column; gap: 8px; }

.party {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 10px 12px; text-align: left; cursor: pointer;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  border-left: 5px solid var(--pc);
  transition: border-color .12s, box-shadow .12s, background .12s;
}
.party:hover { box-shadow: var(--shadow); border-color: var(--muted); border-left-color: var(--pc); }
.party.selected {
  border-color: var(--pc); box-shadow: 0 0 0 2px var(--pc) inset;
  background: color-mix(in srgb, var(--pc) 9%, var(--panel));
}

.logo {
  width: 52px; height: 52px; flex: none; border-radius: 12px; overflow: hidden;
  display: grid; place-items: center; background: var(--pc);
  font-weight: 800; letter-spacing: -.02em;
}
.logo.has-img { background: #fff; border: 1px solid var(--line); }
.logo.has-img.on-colour { background: var(--pc); }
.logo img { width: 100%; height: 100%; object-fit: contain; padding: 4px; }

.ptext { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.pname { font-weight: 600; font-size: 14.5px; line-height: 1.25; }
.pabbr { color: var(--muted); font-size: 12.5px; margin-top: 2px; }

.party:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.wiki {
  flex: none; width: 30px; height: 30px; border-radius: 8px;
  display: grid; place-items: center;
  font: 700 15px/1 Georgia, "Times New Roman", serif; color: var(--muted);
  border: 1px solid var(--line); text-decoration: none;
}
.wiki:hover, .wiki:focus-visible { color: var(--ink); border-color: var(--muted); background: var(--bg); }
.ep {
  width: 44px; height: 44px; flex: none; border-radius: 50%;
  display: grid; place-items: center; overflow: hidden;
  background: var(--ec); font-size: 11px; font-weight: 800; text-align: center; line-height: 1;
}
.ep.has-img { background: #fff; box-shadow: 0 0 0 2px var(--ec); }
.ep img { width: 100%; height: 100%; object-fit: contain; padding: 5px; }

.empty { padding: 28px 22px; color: var(--muted); }
.empty h2 { color: var(--ink); margin: 0 0 8px; font-size: 20px; }
.empty code { background: var(--bg); padding: 1px 5px; border-radius: 4px; color: var(--ink); }

.sb-foot { margin-top: auto; padding: 12px 20px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 62vh auto; height: auto; }
  .sidebar { border-left: 0; border-top: 1px solid var(--line); }
  .topbar h1 { font-size: 15px; }
  .legend { display: none; }
}
