:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --ink: #101828;
  --muted: #5b6575;
  --line: #e3e7ee;
  --chip: #eef1f6;
  --unl: #0f9f6e;
  --seven: #3b5bdb;
  --bonus: #c2410c;
  --none: #98a2b3;
  --accent: #0f9f6e;
  --shadow: 0 6px 24px rgba(16, 24, 40, .12);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1020;
    --panel: #121a2e;
    --ink: #eef2f8;
    --muted: #9aa6bb;
    --line: #23304a;
    --chip: #1b2640;
    --unl: #2fd39a;
    --seven: #7b93ff;
    --bonus: #fb923c;
    --none: #667085;
    --accent: #2fd39a;
    --shadow: 0 6px 24px rgba(0, 0, 0, .45);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1020; --panel: #121a2e; --ink: #eef2f8; --muted: #9aa6bb; --line: #23304a; --chip: #1b2640;
  --unl: #2fd39a; --seven: #7b93ff; --bonus: #fb923c; --none: #667085; --accent: #2fd39a;
  --shadow: 0 6px 24px rgba(0, 0, 0, .45); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  display: flex; flex-direction: column;
}
a { color: var(--accent); }

.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand svg { width: 34px; height: 34px; flex: none; }
.brand h1 { margin: 0; font-size: 18px; font-weight: 800; letter-spacing: -.01em; }
.brand p { margin: 0; color: var(--muted); font-size: 12.5px; }

.seg { display: inline-flex; background: var(--chip); border-radius: 999px; padding: 3px; }
.seg button {
  border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 600;
  padding: 6px 14px; border-radius: 999px; cursor: pointer;
}
.seg button[aria-selected="true"] { background: var(--panel); color: var(--ink); box-shadow: 0 1px 4px rgba(0,0,0,.12); }

.layout { flex: 1; display: grid; grid-template-columns: 1fr 400px; min-height: 0; }
.mapwrap { position: relative; min-height: 0; }
#map { position: absolute; inset: 0; background: var(--bg); }

.legend {
  position: absolute; left: 12px; bottom: 22px; z-index: 500;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
  padding: 8px 12px; font-size: 12.5px; display: grid; gap: 4px;
}
.legend .row { display: flex; align-items: center; gap: 8px; }
.legend .note { color: var(--muted); font-size: 11.5px; }
.dot { width: 11px; height: 11px; border-radius: 50%; flex: none; display: inline-block; border: 2px solid rgba(255,255,255,.85); box-shadow: 0 0 0 1px rgba(0,0,0,.15); }

.surprise {
  position: absolute; right: 12px; top: 12px; z-index: 500;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  font: inherit; font-weight: 600; padding: 8px 12px; border-radius: 999px; cursor: pointer; box-shadow: var(--shadow);
}
.surprise:hover { border-color: var(--accent); }

.panel { background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; padding: 14px 16px 24px; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.stat { background: var(--chip); border-radius: 12px; padding: 10px; }
.stat b { display: block; font-size: 22px; font-weight: 800; line-height: 1.1; }
.stat span { color: var(--muted); font-size: 12px; }

.block { border: 1px solid var(--line); border-radius: 12px; padding: 0 12px; margin-bottom: 12px; }
.block summary { cursor: pointer; font-weight: 700; padding: 10px 0; display: flex; align-items: center; gap: 8px; list-style: none; }
.block summary::-webkit-details-marker { display: none; }
.block summary::after { content: "▾"; margin-left: auto; color: var(--muted); transition: transform .15s; }
.block:not([open]) summary::after { transform: rotate(-90deg); }
.block > :last-child { margin-bottom: 12px; }
.hint { color: var(--muted); font-size: 12.5px; margin: 0 0 8px; }
.pill { background: var(--chip); color: var(--muted); font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; }

.supers { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.super {
  text-align: left; border: 1px solid var(--line); background: transparent; color: var(--ink);
  border-radius: 10px; padding: 8px 10px; font: inherit; cursor: pointer;
}
.super:hover { border-color: var(--accent); }
.super small { display: block; color: var(--muted); font-size: 11.5px; }
.super b { display: block; font-size: 13.5px; }
.super span { font-size: 12.5px; color: var(--muted); }

.controls { position: sticky; top: -14px; background: var(--panel); padding: 8px 0; z-index: 2; display: grid; gap: 8px; }
#q {
  width: 100%; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--ink); font: inherit;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: transparent;
  color: var(--ink); font: inherit; font-size: 12.5px; font-weight: 600; padding: 5px 10px; border-radius: 999px; cursor: pointer;
}
.chip[aria-pressed="false"] { opacity: .45; }
.sort { color: var(--muted); font-size: 12.5px; display: flex; align-items: center; gap: 6px; }
.sort select { font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 3px 6px; }

.list { list-style: none; margin: 4px 0 12px; padding: 0; }
.item { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; padding: 9px 4px; border-bottom: 1px solid var(--line); }
.item .main { cursor: pointer; min-width: 0; }
.item .name { font-weight: 600; display: flex; align-items: center; gap: 7px; }
.item .meta { color: var(--muted); font-size: 12px; }
.tag { font-size: 10.5px; font-weight: 700; padding: 1px 6px; border-radius: 6px; background: var(--chip); color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.tag.new { background: var(--accent); color: #fff; }
.access { font-size: 12px; font-weight: 700; white-space: nowrap; }
.step { display: inline-flex; align-items: center; gap: 4px; }
.step button {
  width: 24px; height: 24px; border-radius: 7px; border: 1px solid var(--line); background: var(--bg); color: var(--ink);
  font: inherit; font-weight: 700; cursor: pointer; line-height: 1;
}
.step output { min-width: 16px; text-align: center; font-weight: 700; font-size: 12.5px; }
.right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }

.plan-row { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; padding: 4px 0; border-bottom: 1px dashed var(--line); }
.plan-row.over { color: var(--bonus); font-weight: 600; }
.plan-empty { color: var(--muted); font-size: 12.5px; }
.plan-clear { margin-top: 8px; border: 1px solid var(--line); background: transparent; color: var(--muted); font: inherit; font-size: 12px; padding: 4px 10px; border-radius: 8px; cursor: pointer; }

.about p { color: var(--muted); font-size: 12.5px; margin: 0 0 8px; }
.src { margin: 0; padding-left: 18px; font-size: 12.5px; }

.tiles { filter: saturate(.75) contrast(.95); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .tiles { filter: invert(1) hue-rotate(180deg) brightness(.85) contrast(.9) saturate(.6); }
}

/* Leaflet popup */
.leaflet-popup-content-wrapper { background: var(--panel); color: var(--ink); border-radius: 14px; box-shadow: var(--shadow); }
.leaflet-popup-tip { background: var(--panel); }
.leaflet-popup-content { margin: 12px 14px; font: 13px/1.45 Inter, system-ui, sans-serif; min-width: 230px; }
.leaflet-container a.leaflet-popup-close-button { color: var(--muted); }
.pop h3 { margin: 0 0 2px; font-size: 16px; font-weight: 800; }
.pop .where { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.pop .badge { display: inline-block; color: #fff; font-weight: 700; font-size: 12px; padding: 3px 9px; border-radius: 999px; margin: 0 4px 4px 0; }
.pop .badge.ghost { background: var(--chip); color: var(--ink); }
.pop .grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 8px 0; }
.pop .grid div { background: var(--chip); border-radius: 8px; padding: 5px 6px; text-align: center; }
.pop .grid b { display: block; font-size: 13px; }
.pop .grid span { font-size: 10.5px; color: var(--muted); }
.pop .fact { margin: 6px 0 0; }
.pop .share { color: var(--muted); font-size: 12px; margin-top: 4px; }
.leaflet-control-attribution { font-size: 10px; }
.leaflet-tooltip.lbl { background: var(--panel); color: var(--ink); border: 1px solid var(--line); font: 600 12px Inter, sans-serif; box-shadow: var(--shadow); }

@media (max-width: 860px) {
  body { display: block; height: auto; }
  .layout { display: block; }
  .mapwrap { height: 62vh; min-height: 360px; }
  .panel { border-left: 0; border-top: 1px solid var(--line); overflow: visible; }
  .controls { top: 0; }
  .legend { bottom: 16px; left: 8px; }
  .brand p { display: none; }
}
@media (max-width: 420px) {
  .stats { grid-template-columns: repeat(3, 1fr); }
  .stat b { font-size: 19px; }
  .supers { grid-template-columns: 1fr; }
  .pop .grid { grid-template-columns: repeat(2, 1fr); }
}
