:root {
  --bg: #ffffff;
  --panel: #f7f7f5;
  --fg: #1d1d1b;
  --muted: #6b6b66;
  --line: #e2e1dc;
  --accent: #2257c7;
  --chip: #ffffff;
  --chip-on: #1d1d1b;
  --chip-on-fg: #ffffff;
  --o: #1a9850; --g: #66bd63; --rcp: #3288bd; --nj: #9e9ac8;
  --ug: #bdbdbd; --rcm: #fdae61; --ri: #f46d43; --i: #c51b2a; --na: #8c8c8c;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161615; --panel: #1f1f1d; --fg: #ecebe6; --muted: #a09f98;
    --line: #34332f; --accent: #7aa2ff; --chip: #2a2a27; --chip-on: #ecebe6; --chip-on-fg: #161615;
  }
}
:root[data-theme="dark"] {
  --bg: #161615; --panel: #1f1f1d; --fg: #ecebe6; --muted: #a09f98;
  --line: #34332f; --accent: #7aa2ff; --chip: #2a2a27; --chip-on: #ecebe6; --chip-on-fg: #161615;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--fg); font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif; }
#app { display: flex; height: 100vh; height: 100dvh; }
#panel { width: 380px; flex: none; background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto; padding: 12px 16px; }
header { display: flex; align-items: center; justify-content: space-between; }
h1 { font-size: 18px; margin: 4px 0 8px; }
section { margin: 12px 0; }
.lbl { display: block; font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); margin-bottom: 6px; }
.row { display: flex; gap: 8px; align-items: center; margin: 6px 0; }
.small { font-size: 12px; }
.muted { color: var(--muted); }
input, select, button { font: inherit; color: var(--fg); }
input:not([type=range]), select { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; width: 100%; }
input[type=range] { flex: 1; accent-color: var(--accent); }
button { background: var(--chip); border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; cursor: pointer; }
#go { background: var(--accent); color: #fff; border-color: var(--accent); }
button.link { background: none; border: none; padding: 0; color: var(--accent); text-decoration: underline; }
.seg { display: flex; flex-wrap: wrap; gap: 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.seg button.on, .chips button.on { background: var(--chip-on); color: var(--chip-on-fg); border-color: var(--chip-on); }
.chips button { border-radius: 999px; padding: 4px 10px; font-size: 13px; }
.chips button .n { opacity: .6; font-size: 11px; margin-left: 4px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; border: 1px solid rgba(0,0,0,.2); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; }
details p { margin: 6px 0; }
#summary { font-weight: 600; margin: 14px 0 6px; padding-top: 10px; border-top: 1px solid var(--line); }
#list { list-style: none; padding: 0; margin: 0; }
#list li { padding: 8px 6px; border-bottom: 1px solid var(--line); cursor: pointer; border-radius: 4px; }
#list li:hover { background: var(--bg); }
#list .nm { font-weight: 600; }
#list .meta { font-size: 12px; color: var(--muted); }
#list .dist { float: right; font-size: 12px; color: var(--muted); }
.tag { display: inline-block; font-size: 11px; padding: 0 6px; border-radius: 4px; background: var(--chip-on); color: var(--chip-on-fg); margin-left: 4px; }
footer { margin-top: 16px; }
.maplibregl-popup-content { background: var(--bg); color: var(--fg); max-width: 320px; font-size: 13px; }
.maplibregl-popup-tip { border-top-color: var(--bg) !important; border-bottom-color: var(--bg) !important; }
.pop h3 { margin: 0 0 4px; font-size: 15px; }
.pop table { border-collapse: collapse; margin: 6px 0; width: 100%; }
.pop td { padding: 1px 4px 1px 0; vertical-align: top; }
.pop td:first-child { color: var(--muted); white-space: nowrap; }
.pop a { color: var(--accent); }
.lv { font-weight: 600; }
.lv5 { color: var(--o); } .lv4 { color: var(--g); } .lv3 { color: var(--rcp); } .lv2 { color: var(--rcm); } .lv1 { color: var(--i); }
.only-mobile { display: none; }
.picking #map { cursor: crosshair; }
.picking .maplibregl-canvas { cursor: crosshair; }

@media (max-width: 760px) {
  #app { flex-direction: column-reverse; }
  #panel { width: 100%; max-height: 55vh; border-right: none; border-top: 1px solid var(--line); padding: 8px 16px; }
  .only-mobile { display: inline-block; }
  #panel.collapsed #filters { display: none; }
}

/* v2: results, shortlist, legend */
.free { font-size: 11px; font-weight: 700; background: var(--o); color: #fff; border-radius: 4px; padding: 1px 6px; vertical-align: 3px; }
.grow { flex: 1; }
.val { font-weight: 600; min-width: 36px; text-align: right; }
input.full { width: 100%; accent-color: var(--accent); }
select.narrow { width: auto; padding: 3px 6px; }
.row.wrap { flex-wrap: wrap; }
.listbar { position: sticky; top: -12px; background: var(--panel); z-index: 2; padding-bottom: 4px; }
#legend { display: flex; flex-wrap: wrap; gap: 4px 10px; margin: 4px 0; }
.lg { white-space: nowrap; }
.chipbtn { border-radius: 999px; padding: 3px 10px; font-size: 12px; }
.chipbtn.on { background: var(--chip-on); color: var(--chip-on-fg); border-color: var(--chip-on); }
.star { float: right; background: none; border: none; padding: 0 0 0 8px; font-size: 18px; line-height: 1; color: var(--muted); }
.star.on { color: #e8a100; }
.rk { font-size: 11px; color: var(--muted); margin-right: 6px; }
.pophead { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.pophead .star { float: none; }
.results { margin-top: 8px; }
.results b { display: block; margin-top: 8px; }
table.res { font-size: 12px; }
table.res th { text-align: left; font-weight: 600; color: var(--muted); padding: 1px 6px 1px 0; }
table.res td { padding: 1px 6px 1px 0; color: var(--fg); }
table.res td:first-child { color: var(--fg); }

/* details card */
#mapwrap { flex: 1; position: relative; min-width: 0; }
#map { position: absolute; inset: 0; }
#card { position: absolute; top: 12px; right: 56px; bottom: 12px; width: 380px; overflow-y: auto; background: var(--bg); color: var(--fg);
  border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 6px 24px rgba(0,0,0,.18); padding: 14px 16px; z-index: 3; font-size: 13px; }
#card[hidden] { display: none; }
#cardClose { position: sticky; top: 0; float: right; margin: -6px -8px 0 8px; font-size: 20px; line-height: 1; padding: 2px 8px; background: var(--bg); }
@media (max-width: 760px) {
  #mapwrap { flex: 1; min-height: 45vh; }
  #card { position: fixed; left: 0; right: 0; top: 12vh; bottom: 0; width: auto; border-radius: 14px 14px 0 0; z-index: 10; }
}
