:root {
  --bg: #0d1117;
  --panel: rgba(16, 20, 26, 0.86);
  --panel-solid: #101820;
  --line: #263140;
  --text: #e6edf3;
  --muted: #8b98a5;
  --accent: #4fc3f7;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font-family: -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif; color: var(--text); background: var(--bg); }
#map { position: absolute; inset: 0; }

/* Top bar */
#topbar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; gap: 12px;
  background: linear-gradient(180deg, rgba(8,11,15,0.85), rgba(8,11,15,0));
  pointer-events: none;
}
#topbar .title { font-weight: 600; letter-spacing: .2px; font-size: 15px; text-shadow: 0 1px 3px rgba(0,0,0,.6); }
#basemap { pointer-events: auto; display: flex; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
#basemap button {
  appearance: none; border: 0; background: transparent; color: var(--muted);
  padding: 6px 12px; font-size: 13px; cursor: pointer;
}
#basemap button.active { background: var(--accent); color: #06121a; font-weight: 600; }

/* Legend */
#legend {
  position: absolute; top: 56px; right: 12px; z-index: 5;
  width: 264px; max-width: 74vw;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; backdrop-filter: blur(6px);
  box-shadow: 0 8px 24px rgba(0,0,0,.35);
}
.legend-head { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 8px; }
.legend-row { display: flex; align-items: center; gap: 8px; padding: 4px 0; font-size: 13px; cursor: pointer; }
.legend-row input { accent-color: var(--accent); }
.legend-row .swatch { width: 12px; height: 12px; border-radius: 3px; flex: 0 0 auto; box-shadow: 0 0 0 1px rgba(0,0,0,.4) inset; }
.legend-row .name { flex: 1; min-width: 0; line-height: 1.25; }
.legend-row .status { font-size: 10px; color: var(--muted); font-style: italic; flex: 0 0 auto; white-space: nowrap; }
.legend-note { margin-top: 8px; font-size: 11px; color: var(--muted); line-height: 1.4; }
.legend-note code { color: #b6c2cf; }

/* Disclaimer */
#disclaimer {
  position: absolute; left: 12px; bottom: 10px; z-index: 5;
  max-width: min(560px, 70vw);
  font-size: 11px; line-height: 1.4; color: var(--text);
  background: rgba(8,11,15,0.7); border: 1px solid var(--line);
  padding: 6px 10px; border-radius: 8px;
}

/* Popups */
/* Above #legend (z-index 5): a popup is a direct response to a click and must
   never open underneath a panel. */
.maplibregl-popup { z-index: 6; }
.maplibregl-popup-content { background: var(--panel-solid); color: var(--text); border: 1px solid var(--line); border-radius: 8px; font-size: 12px; padding: 10px 12px; }
/* All four, not just top/bottom: a popup anchored left or right showed a white
   spike, because MapLibre colours the tip via whichever border faces the panel. */
.maplibregl-popup-tip {
  border-top-color: var(--panel-solid) !important; border-bottom-color: var(--panel-solid) !important;
  border-left-color: var(--panel-solid) !important; border-right-color: var(--panel-solid) !important;
}
/* The vendor sheet leaves this the UA default, i.e. near-black on a dark panel. */
.maplibregl-popup-close-button { color: var(--muted); font-size: 16px; padding: 0 6px; }
.maplibregl-popup-close-button:hover { color: var(--text); background: transparent; }

.pop { display: flex; flex-direction: column; max-height: min(52vh, 420px); }
.pop-kind { font-size: 10px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.pop-title { font-size: 13px; font-weight: 600; line-height: 1.3; margin: 2px 0 8px; padding-right: 14px; }
/* Only the middle scrolls, so the source link and the CC-BY credit can never be
   scrolled out of sight. */
.pop-note {
  font-size: 11px; line-height: 1.45; color: #ffca6b;
  background: rgba(255, 183, 77, .08); border-left: 2px solid #ffb74d;
  padding: 5px 7px; margin: 0 0 8px; border-radius: 0 4px 4px 0;
}
.pop-body { overflow-y: auto; min-height: 0; }
.pop-row { display: flex; gap: 8px; padding: 3px 0; border-top: 1px solid var(--line); }
.pop-k { flex: 0 0 84px; color: var(--muted); }
.pop-v { flex: 1; overflow-wrap: anywhere; }
.pop-foot { margin-top: 8px; padding-top: 6px; border-top: 1px solid var(--line); }
.pop-link { display: block; color: var(--accent); text-decoration: none; overflow-wrap: anywhere; margin-bottom: 2px; }
.pop-link:hover { text-decoration: underline; }
.pop-credit { margin-top: 4px; font-size: 10px; color: var(--muted); line-height: 1.4; }

/* Layers with no popup block fall back to a plain property list. */
.pop table { border-collapse: collapse; margin-top: 6px; width: 100%; }
.pop td { border-top: 1px solid var(--line); padding: 3px 6px; vertical-align: top; overflow-wrap: anywhere; }
.pop td:first-child { color: var(--muted); white-space: nowrap; }

.map-error {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  background: var(--panel-solid); border: 1px solid var(--line); color: var(--text);
  padding: 12px 16px; border-radius: 8px; font-size: 13px; max-width: 80%; text-align: center;
}

@media (max-width: 620px) {
  #legend { top: auto; bottom: 44px; right: 8px; width: 232px; }
  #disclaimer { max-width: 92vw; }
  .pop { max-height: min(42vh, 330px); }
  .pop-k { flex-basis: 72px; }
}
/* A phone held sideways has very little height to give a popup. */
@media (max-height: 480px) {
  .pop { max-height: 70vh; }
}
