:root {
  --ink: #0d1117;
  --panel: rgba(13, 17, 23, 0.88);
  --panel-solid: #0d1117;
  --line: rgba(255, 255, 255, 0.10);
  --text: #e6edf3;
  --dim: #8b949e;
  --dimmer: #6e7681;
  --accent: #39d3bb;
  --warn: #e3b341;
  --bad: #f85149;
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Inter, Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font-family: var(--sans);
  color: var(--text);
  background: #e9e4da;
  -webkit-font-smoothing: antialiased;
}
#map { position: absolute; inset: 0; }

.panel {
  position: absolute;
  background: var(--panel);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.28);
  z-index: 5;
}

/* ---------- brand / search ---------- */
#brand {
  top: 14px; left: 14px; width: 310px; padding: 13px 15px;
}
#brand h1 {
  margin: 0; font-size: 15px; letter-spacing: -0.01em; font-weight: 650;
}
#brand h1 .dot { color: var(--accent); }
#brand p {
  margin: 3px 0 0; font-size: 11.5px; color: var(--dim); line-height: 1.45;
}
#search {
  margin-top: 11px; width: 100%; padding: 8px 10px;
  background: rgba(255,255,255,0.05); border: 1px solid var(--line);
  border-radius: 7px; color: var(--text); font-size: 12.5px; font-family: var(--sans);
}
#search::placeholder { color: var(--dimmer); }
#search:focus { outline: none; border-color: rgba(57,211,187,0.5); }

#results { margin-top: 7px; max-height: 230px; overflow-y: auto; }
#results .hit {
  padding: 6px 8px; border-radius: 6px; cursor: pointer; font-size: 12px;
  display: flex; gap: 8px; align-items: center;
}
#results .hit:hover { background: rgba(255,255,255,0.07); }
#results .hit .k { color: var(--dimmer); font-size: 10px; font-family: var(--mono); text-transform: uppercase; }

/* ---------- status strip ---------- */
#status {
  top: 14px; left: 338px; padding: 9px 13px; display: flex; gap: 16px; align-items: center;
  font-family: var(--mono); font-size: 11px;
}
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat .v { font-size: 14px; font-weight: 600; line-height: 1; }
.stat .l { color: var(--dimmer); font-size: 9.5px; text-transform: uppercase; letter-spacing: 0.06em; }
.dot-live {
  width: 7px; height: 7px; border-radius: 50%; background: var(--accent);
  box-shadow: 0 0 0 0 rgba(57,211,187,0.6); animation: pulse 2.2s infinite;
}
.dot-live.bad { background: var(--bad); animation: none; }
.dot-live.warn { background: var(--warn); animation: none; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(57,211,187,0.55); }
  70% { box-shadow: 0 0 0 9px rgba(57,211,187,0); }
  100% { box-shadow: 0 0 0 0 rgba(57,211,187,0); }
}

/* ---------- layers ---------- */
/* The footer sits bottom-right at the same inset, so the panel must stop
   above it or the last layer in the list is unreadable behind it. With 14
   layers the list already scrolls; before this it simply ran underneath.
   14 top + 14 bottom inset + ~31 of footer + 10 of air. */
#layers {
  top: 14px; right: 14px; width: 280px; max-height: calc(100vh - 83px);
  display: flex; flex-direction: column;
}
#layers header {
  padding: 12px 15px 10px; border-bottom: 1px solid var(--line);
  font-size: 12px; font-weight: 600; display: flex; justify-content: space-between; align-items: center;
}
#layers header span.count { color: var(--dimmer); font-family: var(--mono); font-size: 10.5px; font-weight: 400; }
#layerlist { overflow-y: auto; padding: 6px; }
.lgroup { margin: 4px 0 10px; }
.lgroup > .gt {
  font-size: 9.5px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--dimmer); padding: 5px 9px 4px; font-family: var(--mono);
}
.layer {
  display: flex; align-items: flex-start; gap: 9px; padding: 7px 9px;
  border-radius: 7px; cursor: pointer; transition: background 0.12s;
}
.layer:hover { background: rgba(255,255,255,0.055); }
.layer .sw {
  width: 9px; height: 9px; border-radius: 2.5px; margin-top: 3px; flex: 0 0 auto;
  border: 1px solid rgba(255,255,255,0.22); background: transparent;
}
.layer.on .sw { background: var(--sc, var(--accent)); border-color: transparent; }
.layer .meta { flex: 1; min-width: 0; }
.layer .nm { font-size: 12.5px; line-height: 1.3; }
.layer.off .nm { color: var(--dim); }
.layer .src {
  font-size: 10px; color: var(--dimmer); font-family: var(--mono);
  margin-top: 2px; display: flex; gap: 5px; align-items: center;
}
.layer .src a { color: var(--dimmer); text-decoration: none; border-bottom: 1px dotted rgba(255,255,255,0.2); }
.layer .src a:hover { color: var(--accent); border-bottom-color: var(--accent); }
.layer .badge {
  font-size: 8.5px; padding: 1px 4px; border-radius: 3px; font-family: var(--mono);
  text-transform: uppercase; letter-spacing: 0.04em;
}
.badge.live { background: rgba(57,211,187,0.16); color: var(--accent); }
.badge.soon { background: rgba(139,148,158,0.14); color: var(--dimmer); }

/* ---------- detail ---------- */
#detail {
  bottom: 14px; left: 14px; width: 320px; padding: 0; display: none;
}
#detail.show { display: block; }
#detail .dh {
  padding: 12px 15px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 10px;
}
#detail .badge-line {
  font-family: var(--mono); font-weight: 700; font-size: 14px;
  padding: 3px 8px; border-radius: 5px; color: #06231f; background: var(--accent);
}
#detail .dh .t { flex: 1; min-width: 0; }
#detail .dh .t b { font-size: 13px; display: block; }
#detail .dh .t small { color: var(--dim); font-size: 11px; }
#detail .x { cursor: pointer; color: var(--dimmer); font-size: 17px; line-height: 1; padding: 0 2px; }
#detail .x:hover { color: var(--text); }
#detail dl { margin: 0; padding: 10px 15px 12px; font-size: 12px; }
#detail dl div { display: flex; justify-content: space-between; padding: 3.5px 0; gap: 12px; }
#detail dt { color: var(--dim); }
#detail dd { margin: 0; font-family: var(--mono); font-size: 11.5px; text-align: right; }
#detail .prov {
  padding: 9px 15px; border-top: 1px solid var(--line);
  font-size: 10px; color: var(--dimmer); font-family: var(--mono);
}
#detail .prov a { color: var(--dimmer); }

/* ---------- legend / footer ---------- */
#footer {
  bottom: 14px; right: 14px; padding: 8px 12px;
  font-size: 10px; color: var(--dimmer); font-family: var(--mono);
  display: flex; gap: 12px; align-items: center;
}
#footer a { color: var(--dim); text-decoration: none; }
#footer a:hover { color: var(--accent); }

.maplibregl-ctrl-group { background: var(--panel) !important; border: 1px solid var(--line) !important; }
.maplibregl-ctrl-group button { background: transparent !important; }
.maplibregl-ctrl-group button span { filter: invert(1) !important; }
.maplibregl-ctrl-attrib { display: none !important; }

@media (max-width: 820px) {
  #status { display: none; }
  #brand { width: calc(100vw - 28px); }
  #layers { top: auto; bottom: 14px; right: 14px; left: 14px; width: auto; max-height: 42vh; }
  #detail { bottom: auto; top: 120px; left: 14px; right: 14px; width: auto; }
  #footer { display: none; }
}

/* A caveat is a standing limit of the data, not a footnote: it stays visible
   in the layer list whether or not the layer is switched on. */
.layer .caveat {
  margin-top: 4px;
  font-size: 10.5px;
  line-height: 1.35;
  color: #c9a227;
  border-left: 2px solid rgba(201,162,39,0.5);
  padding-left: 6px;
}

/* hazard legend */
/* Bottom centre, not bottom left: the detail panel owns the left corner and
   the legend was rendering underneath it.
   Scoped to .legend, not to one id, because there is a key per layer now and
   more than one can be open at once. Styling these by id is how the swatches
   silently disappeared when the stack was introduced. */
.legend { width: 260px; padding: 11px 13px; }
.legend .lgt { font-size: 11px; font-weight: 600; line-height: 1.35; margin-bottom: 8px; }
.legend .lgscale { display: flex; height: 9px; border-radius: 3px; overflow: hidden; }
.legend .lgscale span { flex: 1; background: var(--c); }
.legend .lgends { display: flex; justify-content: space-between; font-size: 10px; opacity: .65; margin-top: 4px; }
.legend .lgnote { font-size: 10px; opacity: .55; margin-top: 7px; line-height: 1.35; }
@media (max-width: 820px) { #legend { display: none !important; } }

/* ---- transient notice. Deliberately not a toast in a corner: these carry
   the caveats that keep a layer honest, so it sits centred above the legend
   where the eye already is after switching a layer on. */
/* Legends stack upward from the bottom centre. More than one layer can be on
   at a time, so they must not occupy the same spot - which is what the single
   #legend did. */
#legends{
  position:absolute; left:50%; transform:translateX(-50%); bottom:14px;
  display:flex; flex-direction:column; gap:8px; align-items:center; z-index:6;
  pointer-events:none; max-width:min(620px,calc(100vw - 32px));
}
#legends .legend{ position:static; display:none; pointer-events:auto; }
#legends .legend.show{ display:block; }

#flash{
  max-width:min(560px,calc(100vw - 32px));
  background:rgba(13,17,23,.94); border:1px solid #30363d; border-radius:8px;
  color:#c9d1d9; font-size:12px; line-height:1.45; padding:9px 13px;
  box-shadow:0 8px 28px rgba(0,0,0,.5); z-index:7;
  pointer-events:none; text-align:center;
  display:none;
}
#flash.show{ display:block; }

/* Secondary text inside a detail row: units, scales, the "this is a rule of
   thumb" qualifiers. Dim, never hidden - a caveat set in display:none is a
   caveat we did not make. */
#detail .dim{color:#8b949e; font-weight:400}
#detail .warn{color:#f0883e; font-weight:600}
