:root {
  --bg: #07090c;
  --panel: rgba(12, 15, 20, 0.86);
  --panel-solid: #0c0f14;
  --line: rgba(255, 255, 255, 0.09);
  --line-strong: rgba(255, 255, 255, 0.18);
  --text: #e6e9ee;
  --muted: #8a93a1;
  --faint: #5b6370;
  --accent: #ffd23f;
  --accent-ink: #1a1400;
  --live: #3ddc97;
  --warn: #ff8c1a;
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 14px/1.4 var(--sans); }
#map { position: fixed; inset: 0; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.mono, .num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

/* ---- HUD ---------------------------------------------------------------- */
.hud {
  position: fixed; top: 12px; left: 12px; z-index: 2;
  display: flex; align-items: center; gap: 4px;
  background: var(--panel); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 4px;
}
.brand { display: flex; align-items: center; gap: 6px; padding: 4px 10px 4px 6px; font-weight: 700; letter-spacing: 0.14em; font-size: 12px; }
.brand svg { width: 16px; height: 16px; fill: var(--accent); }
.hud-stat { display: flex; align-items: baseline; gap: 6px; padding: 4px 10px; border-left: 1px solid var(--line); font-size: 12px; color: var(--muted); white-space: nowrap; }
.hud-stat .num { color: var(--text); font-size: 13px; }
.hud-stat .unit { color: var(--faint); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); align-self: center; }
.dot.on { background: var(--live); box-shadow: 0 0 0 3px rgba(61, 220, 151, 0.18); }
.dot.off { background: var(--warn); }

/* ---- Panel -------------------------------------------------------------- */
.panel {
  position: fixed; top: 12px; right: 12px; bottom: 12px; z-index: 2; width: 320px;
  display: flex; flex-direction: column;
  background: var(--panel); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
}
.panel-toggle { display: none; }
.panel-body { overflow-y: auto; padding: 4px 16px 16px; scrollbar-width: thin; }
.panel section { padding: 14px 0; border-bottom: 1px solid var(--line); }
.panel section:last-of-type { border-bottom: 0; }
h2 { margin: 0 0 10px; font-size: 11px; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.section-head h2 { margin: 0; }
.link { background: none; border: 0; padding: 2px 4px; color: var(--muted); font-size: 12px; cursor: pointer; border-radius: 4px; }
.link:hover { color: var(--text); }

.seg { display: flex; background: rgba(255, 255, 255, 0.04); border: 1px solid var(--line); border-radius: 8px; padding: 2px; }
.seg button { flex: 1; background: none; border: 0; padding: 6px 0; border-radius: 6px; cursor: pointer; color: var(--muted); font-size: 12px; font-family: var(--mono); }
.seg button:hover { color: var(--text); }
.seg button[aria-checked="true"] { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.seg.small button { padding: 3px 7px; font-size: 11px; }

.legend { margin-top: 12px; }
.ramp { height: 6px; border-radius: 3px; background: linear-gradient(90deg, #ffffff 0%, #fff1a8 12%, #ffd23f 30%, #ff8c1a 55%, #d9481c 78%, #7a2a14 100%); }
.ramp-labels { display: flex; justify-content: space-between; margin-top: 4px; font: 10px var(--mono); color: var(--faint); }

/* ---- Bookmarks ---------------------------------------------------------- */
.bookmarks { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.bm { display: grid; grid-template-columns: 22px 1fr auto; align-items: center; gap: 8px; padding: 8px 8px 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: rgba(255, 255, 255, 0.02); }
.bm.active { border-color: rgba(255, 210, 63, 0.55); background: rgba(255, 210, 63, 0.06); }
.bm-idx { font: 11px var(--mono); color: var(--faint); text-align: center; border: 1px solid var(--line-strong); border-radius: 4px; line-height: 18px; }
.bm.active .bm-idx { color: var(--accent); border-color: var(--accent); }
.bm-go { background: none; border: 0; padding: 0; text-align: left; cursor: pointer; min-width: 0; }
.bm-name { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bm-sub { display: block; font: 11px var(--mono); color: var(--faint); }
.bm-empty .bm-name { color: var(--faint); font-style: italic; }
.bm-actions { display: flex; gap: 2px; }
.icon-btn { width: 28px; height: 28px; display: grid; place-items: center; background: none; border: 0; border-radius: 6px; color: var(--muted); cursor: pointer; }
.icon-btn:hover { background: rgba(255, 255, 255, 0.06); color: var(--text); }
.icon-btn svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---- Local view --------------------------------------------------------- */
.local-name { font-size: 13px; margin-bottom: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.local-grid { display: grid; grid-template-columns: 1fr 96px; align-items: center; gap: 8px; }
.big .num { display: block; font-size: 34px; line-height: 1; color: var(--text); }
.big .caption { font-size: 12px; color: var(--muted); }
.rose { width: 96px; height: 96px; }
.rose .ring { fill: none; stroke: var(--line-strong); stroke-width: 0.6; }
.rose .wedge { fill: var(--accent); opacity: 0.85; }
.rose text { font: 7px var(--mono); fill: var(--faint); text-anchor: middle; dominant-baseline: middle; }
.closest { margin: 10px 0 12px; font: 12px var(--mono); color: var(--muted); }
.closest b { color: var(--text); font-weight: 600; }
.histo { display: flex; align-items: flex-end; gap: 2px; height: 44px; }
.histo span { flex: 1; min-height: 1px; background: linear-gradient(180deg, var(--accent), #ff8c1a); border-radius: 2px 2px 0 0; opacity: 0.9; }
.histo span.zero { background: var(--line-strong); }
.histo-axis { display: flex; justify-content: space-between; margin-top: 4px; font: 10px var(--mono); color: var(--faint); }

/* ---- Sources ------------------------------------------------------------ */
.sources { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 12px; }
.sources li { display: grid; grid-template-columns: 8px 1fr auto; align-items: center; gap: 8px; }
.sources .ago { font-family: var(--mono); color: var(--faint); }
.sources .off-name { color: var(--faint); }
.disclaimer { margin: 12px 0 0; font-size: 11px; color: var(--faint); }

/* ---- Notice (API unreachable / origin not allowed) ----------------------- */
.notice { position: fixed; left: 12px; bottom: 40px; z-index: 3; max-width: min(420px, calc(100vw - 24px)); padding: 10px 12px; border-radius: 8px; background: var(--panel-solid); border: 1px solid var(--warn); color: var(--text); font-size: 12px; }

/* ---- Dialogs ------------------------------------------------------------ */
dialog { background: var(--panel-solid); color: var(--text); border: 1px solid var(--line-strong); border-radius: 12px; padding: 20px; width: min(360px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog h2 { font-size: 13px; color: var(--text); }
dialog p { margin: 0 0 12px; color: var(--muted); font-size: 13px; }
dialog input { width: 100%; padding: 9px 10px; border-radius: 8px; border: 1px solid var(--line-strong); background: #05070a; color: var(--text); font: 13px var(--mono); }
dialog menu { display: flex; justify-content: flex-end; gap: 8px; margin: 14px 0 0; padding: 0; }
dialog menu button { padding: 7px 14px; border-radius: 8px; border: 1px solid var(--line-strong); background: none; cursor: pointer; }
dialog menu .primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }

/* ---- MapLibre tweaks ---------------------------------------------------- */
.maplibregl-popup-content { background: var(--panel-solid); color: var(--text); border: 1px solid var(--line-strong); border-radius: 8px; padding: 10px 12px; font: 12px/1.5 var(--mono); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5); }
.maplibregl-popup-tip { border-top-color: var(--panel-solid) !important; border-bottom-color: var(--panel-solid) !important; }
.maplibregl-popup-close-button { color: var(--muted); }
.maplibregl-ctrl-attrib { background: rgba(7, 9, 12, 0.7) !important; }
.maplibregl-ctrl-attrib, .maplibregl-ctrl-attrib a { color: var(--muted) !important; }
.maplibregl-ctrl-group { background: var(--panel-solid); border: 1px solid var(--line); }
.maplibregl-ctrl-group button + button { border-top-color: var(--line); }
.maplibregl-ctrl-group button .maplibregl-ctrl-icon { filter: invert(0.9); }
.maplibregl-ctrl-top-right { right: 344px; }
.pop-title { color: var(--accent); font-weight: 600; margin-bottom: 2px; }
.pop-dim { color: var(--muted); }

/* ---- Small screens: panel becomes a bottom sheet ------------------------- */
@media (max-width: 720px) {
  .hud { left: 8px; right: 8px; top: 8px; justify-content: space-between; flex-wrap: wrap; }
  .hud-stat.mono { display: flex; flex-basis: 100%; justify-content: flex-end; border-left: 0; }
  .panel { top: auto; left: 8px; right: 8px; bottom: 8px; width: auto; max-height: 52vh; }
  .panel-toggle { display: flex; align-items: center; justify-content: space-between; width: 100%; padding: 10px 16px; background: none; border: 0; border-bottom: 1px solid var(--line); cursor: pointer; font-size: 12px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
  .panel-toggle svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; transition: transform 0.2s; }
  .panel.collapsed .panel-toggle svg { transform: rotate(180deg); }
  .panel.collapsed .panel-body { display: none; }
  .maplibregl-ctrl-top-right { right: 0; top: 52px; }
}
@media (min-width: 721px) { .maplibregl-ctrl-bottom-right { right: 344px; } }
