:root {
  --l0: #9aa1ab;
  --l1: #4c86c6;
  --l2: #2fa38a;
  --l3: #e0b42b;
  --l4: #ec7a23;
  --l5: #d6304a;

  --panel-bg: rgba(255, 255, 255, 0.94);
  --panel-fg: #1d232c;
  --muted: #5d6673;
  --line: rgba(20, 30, 45, 0.12);
  --accent: #1f5fae;
  --hover: rgba(31, 95, 174, 0.09);
  --shadow: 0 6px 24px rgba(10, 20, 35, 0.18), 0 1px 3px rgba(10, 20, 35, 0.14);
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --panel-bg: rgba(28, 32, 39, 0.94);
    --panel-fg: #e9edf2;
    --muted: #a3acb8;
    --line: rgba(255, 255, 255, 0.12);
    --accent: #7fb2f0;
    --hover: rgba(127, 178, 240, 0.12);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: #e8e4dc;
  font-family: var(--font);
  color: var(--panel-fg);
}

#map { position: fixed; inset: 0; }

/* ---------- panel ---------- */
.panel {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 2;
  width: 272px;
  max-height: calc(100% - 24px);
  overflow: visible;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  background: var(--panel-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  font-size: 14px;
}

.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.panel-head h1 { margin: 0; font-size: 16px; font-weight: 700; letter-spacing: -0.01em; }
.panel-head h1 span { color: var(--muted); font-weight: 500; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.icon-btn:hover { background: var(--hover); color: var(--panel-fg); }
.icon-btn svg { width: 16px; height: 16px; transition: transform 0.15s ease; }
.panel.collapsed .icon-btn svg { transform: rotate(180deg); }
.panel.collapsed .panel-body { display: none; }

.panel-body { display: flex; flex-direction: column; gap: 8px; overflow-y: auto; min-height: 0; }

/* ---------- search ---------- */
.search { position: relative; }
.search input {
  width: 100%;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: transparent;
  color: inherit;
  font: inherit;
  outline: none;
}
.search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--hover); }

.results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 5;
  margin: 0;
  padding: 4px;
  list-style: none;
  max-height: 320px;
  overflow-y: auto;
  background: var(--panel-bg);
  border-radius: 10px;
  box-shadow: var(--shadow);
}
.results li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 7px;
  cursor: pointer;
}
.results li[aria-selected="true"], .results li:hover { background: var(--hover); }
.results .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.results .num { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.results .empty { color: var(--muted); cursor: default; }
.results .empty:hover { background: none; }

/* ---------- controls ---------- */
.seg {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 3px;
  border-radius: 9px;
  background: var(--hover);
}
.seg button {
  height: 30px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.seg button.on { background: var(--panel-bg); color: var(--panel-fg); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15); }

.check { display: flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.check input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }

.dot, .legend i {
  display: inline-block;
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--c);
  box-shadow: 0 0 0 1.5px #fff, 0 0 0 2.5px rgba(0, 0, 0, 0.15);
}

.legend { margin-top: 4px; padding-top: 10px; border-top: 1px solid var(--line); }
.legend-title { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 6px; }
.legend ul { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; margin: 0; padding: 0; list-style: none; font-size: 13px; }
.legend li { display: flex; align-items: center; gap: 8px; }
.hint { margin: 8px 0 0; font-size: 12px; line-height: 1.4; color: var(--muted); }
.meta { margin: 0; font-size: 11px; color: var(--muted); }
.meta a { color: inherit; }

/* ---------- hover tip ---------- */
.tip {
  position: fixed;
  z-index: 3;
  pointer-events: none;
  padding: 6px 9px;
  border-radius: 8px;
  background: rgba(20, 24, 31, 0.92);
  color: #fff;
  font-size: 13px;
  line-height: 1.35;
  white-space: nowrap;
  transform: translate(12px, -50%);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}
.tip b { font-weight: 650; }
.tip .sub { color: #c4ccd6; font-size: 12px; font-variant-numeric: tabular-nums; }
.tip .warn { color: #ffc98a; font-size: 12px; }

/* ---------- touch popup ---------- */
.site-popup .maplibregl-popup-content { padding: 10px 28px 10px 12px; border-radius: 10px; font: 13px/1.4 var(--font); color: #1d232c; }
.site-popup .maplibregl-popup-close-button { font-size: 18px; width: 26px; height: 26px; }
.pop .sub { color: #5d6673; font-size: 12px; }
.pop .warn { color: #b25b00; font-size: 12px; }
.pop a { display: inline-block; margin-top: 6px; color: #1f5fae; font-weight: 600; text-decoration: none; }

.fatal {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 9;
  padding: 10px 14px; border-radius: 10px; background: #b3261e; color: #fff; font-size: 14px; box-shadow: var(--shadow);
}

/* ---------- maplibre tweaks ---------- */
.maplibregl-ctrl-attrib { font-size: 11px; }
.maplibregl-ctrl-group { border-radius: 9px !important; box-shadow: var(--shadow) !important; }

@media (max-width: 640px) {
  .panel {
    top: max(10px, env(safe-area-inset-top));
    left: 10px;
    right: 10px;
    width: auto;
    padding: 10px;
    max-height: 70%;
  }
  .panel-head h1 { font-size: 15px; }
}
