:root {
  --bg: #f6f5f1; --panel: #ffffff; --ink: #1d2328; --dim: #66707a; --line: #e2e2dc;
  --accent: #2b6a8f; --accent-ink: #fff; --found: #1f9d55; --miss: #d64545; --warn: #b7791f;
  --chip: #eef1f3; --shadow: 0 6px 24px rgba(20, 30, 40, .14);
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12171c; --panel: #192028; --ink: #e6eaee; --dim: #93a0ac; --line: #2a333d;
    --accent: #5fa8d3; --accent-ink: #0d1318; --found: #3ecf7a; --miss: #ff6b6b; --warn: #e0a84a;
    --chip: #222b35; --shadow: 0 6px 24px rgba(0, 0, 0, .45);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex; flex-direction: column; overflow: hidden;
}
a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }
small, .small { font-size: 12.5px; }
.dim { color: var(--dim); }

/* ---------- header ---------- */
.top {
  display: flex; align-items: center; gap: 12px; padding: 8px 12px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: var(--panel); border-bottom: 1px solid var(--line); z-index: 3;
}
.brand { display: flex; align-items: center; gap: 8px; min-width: 0; }
.brand b { display: block; font-size: 15px; }
.brand small { display: block; color: var(--dim); font-size: 11.5px; white-space: nowrap; }
.modes { display: flex; gap: 2px; margin-left: auto; background: var(--chip); border-radius: 9px; padding: 3px; }
.modes button {
  border: 0; background: transparent; padding: 6px 14px; border-radius: 7px; cursor: pointer; font-weight: 550;
}
.modes button[aria-selected="true"] { background: var(--panel); box-shadow: 0 1px 3px rgba(0,0,0,.15); color: var(--accent); }
.icon-btn {
  width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line); background: var(--panel);
  display: grid; place-items: center; cursor: pointer; font-weight: 700; flex: none;
}

/* ---------- layout ---------- */
main { flex: 1; position: relative; display: flex; min-height: 0; }
#map { flex: 1; min-width: 0; }
.panel {
  width: 380px; flex: none; background: var(--panel); border-left: 1px solid var(--line);
  overflow-y: auto; padding: 14px 16px 24px; z-index: 2;
}
.grip { display: none; }
.mode { display: none; }
.mode.on { display: block; }
.row { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--dim); margin: 18px 0 8px; }

select, input[type="text"], input[type="search"] {
  border: 1px solid var(--line); background: var(--bg); border-radius: 8px; padding: 8px 10px; min-width: 0;
}
select.scope { flex: 1; }
.filters select { flex: 1; }
input[type="search"] { width: 100%; }

.btn {
  border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink);
  padding: 8px 12px; border-radius: 8px; cursor: pointer; font-weight: 550;
}
.btn.ghost { background: transparent; color: var(--accent); }
.btn.ok { background: var(--found); border-color: var(--found); }
.btn:disabled { opacity: .5; cursor: default; }
.chk { display: flex; align-items: center; gap: 6px; font-size: 13.5px; cursor: pointer; user-select: none; }
.tools { flex-direction: column; align-items: flex-start; gap: 4px; }

.seg { display: flex; background: var(--chip); border-radius: 8px; padding: 3px; gap: 2px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 6px 8px; border-radius: 6px; cursor: pointer; font-size: 13.5px; white-space: nowrap; }
.seg button.on { background: var(--panel); color: var(--accent); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.15); }
.seg.wide { margin-bottom: 12px; }

/* ---------- quiz ---------- */
.answer { position: relative; margin-bottom: 10px; }
.answer input { width: 100%; font-size: 19px; padding: 11px 13px; border-width: 2px; }
.answer input:focus { outline: none; border-color: var(--accent); }
.answer input.good { border-color: var(--found); }
.answer input.bad { animation: shake .3s; border-color: var(--miss); }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
.msg { min-height: 20px; font-size: 13.5px; margin-top: 5px; color: var(--dim); }
.msg.good { color: var(--found); } .msg.bad { color: var(--miss); } .msg.warn { color: var(--warn); }
.score { display: flex; align-items: flex-end; justify-content: space-between; gap: 10px; }
.score .big { font-size: 34px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.score .of { font-size: 18px; color: var(--dim); font-weight: 500; }
.score .meta { text-align: right; font-size: 13px; color: var(--dim); }
.timer { font-variant-numeric: tabular-nums; font-size: 15px; color: var(--ink); }
.bar { height: 6px; background: var(--chip); border-radius: 3px; overflow: hidden; margin: 8px 0 12px; }
.bar i { display: block; height: 100%; width: 0; background: var(--found); transition: width .3s; }
.btns .btn { flex: 1; }

.regions { display: grid; gap: 6px; }
.region { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; font-size: 13.5px; cursor: pointer; }
.region .bar { grid-column: 1 / -1; margin: 0; height: 4px; }
.region span:last-of-type { color: var(--dim); font-variant-numeric: tabular-nums; }
.region:hover b { color: var(--accent); }
.region b { font-weight: 500; }

.clist { list-style: none; margin: 0; padding: 0; }
.clist li {
  display: grid; grid-template-columns: 50px 1fr auto; align-items: baseline; gap: 6px;
  padding: 6px 4px; border-bottom: 1px solid var(--line); cursor: pointer; font-size: 14px;
}
.clist li:hover { background: var(--chip); }
.clist li .rk { color: var(--dim); font-size: 12px; text-align: right; font-variant-numeric: tabular-nums; }
.clist li .nm small { color: var(--dim); }
.clist li .pp { font-variant-numeric: tabular-nums; color: var(--dim); font-size: 13px; }
.clist li.miss .nm { color: var(--miss); }
.clist li.found .rk::after { content: " ✓"; color: var(--found); }
.clist li.sel { background: var(--chip); }

/* ---------- practice ---------- */
.card { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; background: var(--bg); }
.card .q { font-size: 17px; font-weight: 600; margin-bottom: 10px; }
.card .q small { display: block; font-weight: 400; color: var(--dim); font-size: 13px; margin-top: 2px; }
.card input { width: 100%; font-size: 18px; padding: 9px 11px; border-width: 2px; margin-bottom: 8px; }
.card .row { margin: 0; }
.card .result { margin-top: 10px; font-size: 14px; }
.card .result .nm { font-size: 18px; font-weight: 650; }
.card .result.good .verdict { color: var(--found); font-weight: 650; }
.card .result.bad .verdict { color: var(--miss); font-weight: 650; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.pair button {
  border: 2px solid var(--line); background: var(--panel); border-radius: var(--radius); padding: 12px 8px; cursor: pointer; text-align: center;
}
.pair button b { display: block; font-size: 16px; }
.pair button small { color: var(--dim); }
.pair button.right { border-color: var(--found); }
.pair button.wrong { border-color: var(--miss); }
.pair button .pv { display: block; font-size: 15px; margin-top: 4px; font-weight: 600; }
.known .bar { margin: 4px 0; }

/* ---------- atlas ---------- */
.detail { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 4px 0 12px; background: var(--bg); position: relative; }
.detail h2 { margin: 0 30px 2px 0; font-size: 21px; }
.detail .sub { color: var(--dim); font-size: 13.5px; }
.detail .close { position: absolute; top: 10px; right: 10px; width: 28px; height: 28px; }
.facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.facts div { background: var(--panel); border-radius: 8px; padding: 7px 8px; }
.facts b { display: block; font-size: 16px; font-variant-numeric: tabular-nums; }
.facts small { color: var(--dim); }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0 8px; }
.chips span { background: var(--chip); border-radius: 12px; padding: 2px 8px; font-size: 12.5px; }
.chips span small { color: var(--dim); }
.badge { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 9px; background: var(--chip); color: var(--dim); vertical-align: middle; margin-left: 4px; font-weight: 500; }
.badge.cap { background: #ffcc4d33; color: var(--warn); }
.badge.low { background: #d6454522; color: var(--miss); }
.spark { width: 100%; height: 64px; display: block; margin: 6px 0 2px; }
.spark .ln { fill: none; stroke: var(--accent); stroke-width: 2; }
.spark .ar { fill: var(--accent); opacity: .12; }
.spark .proj { stroke-dasharray: 4 3; }
.spark text { fill: var(--dim); font-size: 10px; }
.spark .now { fill: var(--accent); }
.note { font-size: 13px; color: var(--dim); border-left: 3px solid var(--line); padding-left: 8px; margin: 8px 0; }
.dh { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--dim); margin-top: 10px; }

/* ---------- layers popover ---------- */
.layers { position: absolute; top: 10px; left: 10px; z-index: 2; }
.layers-btn { width: 40px; height: 40px; box-shadow: var(--shadow); }
.layers-pop {
  margin-top: 8px; background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 12px; width: 290px; display: flex; flex-direction: column; gap: 6px; font-size: 14px;
}
.layers-pop label { display: flex; gap: 8px; align-items: center; cursor: pointer; }
.layers-pop small { color: var(--dim); }
.lp-title { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--dim); margin-top: 4px; }

/* ---------- map bits ---------- */
.maplibregl-ctrl-attrib { font-size: 10px; }
.toast {
  position: absolute; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--panel); color: var(--ink);
  padding: 8px 14px; border-radius: 20px; box-shadow: var(--shadow); font-size: 14px; z-index: 3; pointer-events: none;
  opacity: 0; transition: opacity .2s;
}
.toast.on { opacity: 1; }
.maplibregl-popup-content { background: var(--panel); color: var(--ink); border-radius: 8px; padding: 8px 10px; font-size: 13.5px; }
.maplibregl-popup-tip { border-top-color: var(--panel) !important; border-bottom-color: var(--panel) !important; }

dialog#about {
  max-width: 640px; width: calc(100% - 32px); border: 0; border-radius: 14px; padding: 20px 22px; background: var(--panel); color: var(--ink);
  box-shadow: var(--shadow); line-height: 1.5;
}
dialog#about h2 { margin-top: 0; }
dialog#about .close { position: absolute; right: 14px; top: 14px; }
dialog::backdrop { background: rgba(0,0,0,.4); }

/* ---------- phone ---------- */
@media (max-width: 760px) {
  .brand small { display: none; }
  .brand b { font-size: 14px; }
  .modes button { padding: 6px 10px; }
  main { flex-direction: column; }
  .panel {
    width: auto; height: 46%; border-left: 0; border-top: 1px solid var(--line);
    padding: 6px 16px 20px; border-radius: 14px 14px 0 0; margin-top: -12px; box-shadow: 0 -4px 16px rgba(0,0,0,.1);
    transition: height .2s;
  }
  .panel.tall { height: 82%; }
  .panel.short { height: 150px; }
  .grip { display: block; width: 44px; height: 5px; border-radius: 3px; background: var(--line); margin: 2px auto 10px; cursor: grab; }
  .layers-pop { width: min(290px, calc(100vw - 20px)); }
  .score .big { font-size: 28px; }
  .facts { grid-template-columns: repeat(3, 1fr); }
}
[hidden] { display: none !important; }
