:root {
  --bg: #0b0f14;
  --surface: rgba(16, 22, 30, 0.92);
  --surface-solid: #101620;
  --border: rgba(255, 255, 255, 0.11);
  --text: #e8edf4;
  --text-dim: #93a1b3;
  --accent: #4dd2ff;
  --accent-dim: rgba(77, 210, 255, 0.16);
  --warn: #ffb347;
  --bad: #ff5f6d;
  --good: #57d9a3;
  --radius: 10px;
  --shadow: 0 10px 34px rgba(0, 0, 0, 0.5);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

/* Author display rules must not defeat the hidden attribute. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

#map { position: absolute; inset: 0; background: var(--bg); }
.leaflet-container { background: #0a0e13; font-family: var(--font); outline: none; }

/* ------------------------------------------------------------------ topbar */

.topbar {
  position: absolute;
  z-index: 1000;
  top: 0; left: 0; right: 0;
  height: 52px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  background: linear-gradient(180deg, rgba(8, 11, 16, 0.94), rgba(8, 11, 16, 0.55) 70%, transparent);
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }

.brand {
  font-weight: 700;
  letter-spacing: 0.14em;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.8);
}
.brand-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent);
  animation: pulse 2.6s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  backdrop-filter: blur(8px);
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.icon-btn:hover { background: #1b2432; border-color: var(--accent); color: var(--accent); }
.icon-btn[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }

.search { position: relative; flex: 1; max-width: 420px; }
.search input {
  width: 100%;
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  backdrop-filter: blur(8px);
}
.search input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }
.search input::placeholder { color: var(--text-dim); }

.search-results {
  position: absolute;
  top: 38px; left: 0; right: 0;
  margin: 0; padding: 4px;
  list-style: none;
  max-height: 320px;
  overflow-y: auto;
  background: var(--surface-solid);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.search-results li {
  padding: 7px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12.5px;
  color: var(--text-dim);
  line-height: 1.35;
}
.search-results li:hover, .search-results li[aria-selected="true"] { background: #1b2432; color: var(--text); }
.search-results li b { color: var(--text); font-weight: 600; }

.topbar-right { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.clock {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
  padding: 0 6px;
  white-space: nowrap;
}

/* ------------------------------------------------------------------- panel */

.panel {
  position: absolute;
  z-index: 1001;
  top: 60px; left: 12px; bottom: 12px;
  width: 310px;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  transition: transform 0.22s ease, opacity 0.22s ease;
}
.panel.collapsed { transform: translateX(calc(-100% - 20px)); opacity: 0; pointer-events: none; }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.panel-head h1 { margin: 0; font-size: 12px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--text-dim); }
.panel-body { flex: 1; overflow-y: auto; padding: 4px 12px 12px; }
.panel-foot { border-top: 1px solid var(--border); padding: 8px 12px 10px; }

.group { margin-top: 14px; }
.group h2 {
  margin: 0 0 8px;
  font-size: 10.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.basemaps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.basemap-btn {
  padding: 7px 4px;
  font-size: 11px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.15s;
}
.basemap-btn:hover { color: var(--text); border-color: rgba(255, 255, 255, 0.28); }
.basemap-btn.active { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); }

.layer-list { display: flex; flex-direction: column; gap: 4px; }

.layer {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 6px 8px;
  transition: background 0.15s, border-color 0.15s;
}
.layer:hover { background: rgba(255, 255, 255, 0.035); }
.layer.on { background: rgba(77, 210, 255, 0.07); border-color: rgba(77, 210, 255, 0.25); }

.layer-row { display: flex; align-items: center; gap: 9px; cursor: pointer; }
.layer-icon { font-size: 15px; width: 20px; text-align: center; filter: saturate(1.2); }
.layer-name { flex: 1; font-size: 13px; }
.layer-count {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.06);
  border-radius: 999px;
  padding: 1px 7px;
  min-width: 30px;
  text-align: center;
}
.layer.on .layer-count { color: var(--accent); background: var(--accent-dim); }

.switch { position: relative; width: 32px; height: 18px; flex-shrink: 0; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch span {
  position: absolute; inset: 0;
  background: rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  transition: background 0.18s;
  pointer-events: none;
}
.switch span::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 14px; height: 14px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.18s;
}
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(14px); }

.layer-opts {
  display: none;
  padding: 8px 2px 2px 29px;
  gap: 6px;
  flex-direction: column;
}
.layer.on .layer-opts { display: flex; }
.layer-opts label { font-size: 11px; color: var(--text-dim); display: flex; align-items: center; gap: 8px; }
.layer-opts input[type="range"] { flex: 1; accent-color: var(--accent); height: 3px; }
.layer-opts select {
  flex: 1;
  background: #0d131c;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 6px;
  font-size: 11px;
}
.layer-note { font-size: 10.5px; color: var(--warn); line-height: 1.4; }

.feed-status { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 7px; }
.chip {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.04em;
  padding: 2px 6px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-dim);
  white-space: nowrap;
}
.chip.ok { color: var(--good); border-color: rgba(87, 217, 163, 0.4); }
.chip.warn { color: var(--warn); border-color: rgba(255, 179, 71, 0.4); }
.chip.bad { color: var(--bad); border-color: rgba(255, 95, 109, 0.4); }

.credits { margin: 0; font-size: 10px; line-height: 1.5; color: #64748b; }
.credits a { color: #7c8ea3; }

/* ----------------------------------------------------------------- details */

.details {
  position: absolute;
  z-index: 1001;
  top: 60px; right: 12px;
  width: 300px;
  max-height: calc(100% - 140px);
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  padding: 14px;
}
.details-close { position: absolute; top: 8px; right: 8px; }
.details h3 { margin: 0 0 2px; font-size: 16px; }
.details .subtitle { color: var(--text-dim); font-size: 12px; margin-bottom: 12px; }
.details .kv { display: grid; grid-template-columns: 96px 1fr; gap: 4px 10px; font-size: 12.5px; }
.details .kv dt { color: var(--text-dim); }
.details .kv dd { margin: 0; font-family: var(--mono); font-size: 12px; }
.details .tag {
  display: inline-block;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--accent-dim);
  color: var(--accent);
  margin-bottom: 10px;
}
.details a.ext { display: inline-block; margin-top: 12px; font-size: 12px; color: var(--accent); }

/* ---------------------------------------------------------------- timeline */

.timeline {
  position: absolute;
  z-index: 1001;
  bottom: 22px; left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  width: min(560px, calc(100% - 360px));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}
.timeline input[type="range"] { flex: 1; accent-color: var(--accent); }
.timeline-label { font-family: var(--mono); font-size: 11.5px; color: var(--text-dim); min-width: 118px; text-align: right; }

.legend {
  position: absolute;
  z-index: 1000;
  right: 12px; bottom: 22px;
  padding: 8px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  backdrop-filter: blur(14px);
  font-size: 11px;
  max-width: 190px;
}
.legend h4 { margin: 0 0 6px; font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--text-dim); }
.legend .row { display: flex; align-items: center; gap: 7px; margin-top: 3px; color: var(--text-dim); }
.legend .sw { width: 11px; height: 11px; border-radius: 3px; flex-shrink: 0; }
.legend .bar { height: 8px; border-radius: 4px; margin: 4px 0 3px; }
.legend .bar-labels { display: flex; justify-content: space-between; font-family: var(--mono); font-size: 9.5px; color: #64748b; }

.map-tooltip {
  position: absolute;
  z-index: 1002;
  pointer-events: none;
  padding: 4px 8px;
  background: rgba(8, 12, 18, 0.95);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: var(--mono);
  font-size: 11px;
  white-space: nowrap;
  transform: translate(12px, -50%);
}

.toast {
  position: absolute;
  z-index: 1003;
  bottom: 22px; left: 50%;
  transform: translateX(-50%);
  padding: 8px 16px;
  background: var(--surface-solid);
  border: 1px solid var(--accent);
  border-radius: 999px;
  font-size: 12.5px;
  box-shadow: var(--shadow);
}

/* Leaflet chrome restyled to match */
.leaflet-control-zoom a,
.leaflet-control-scale-line,
.leaflet-control-attribution {
  background: var(--surface) !important;
  color: var(--text-dim) !important;
  border-color: var(--border) !important;
  backdrop-filter: blur(8px);
}
.leaflet-control-zoom a { color: var(--text) !important; }
.leaflet-control-zoom a:hover { background: #1b2432 !important; color: var(--accent) !important; }
.leaflet-control-attribution { font-size: 10px; }
.leaflet-control-attribution a { color: #7c8ea3 !important; }
.leaflet-bar { border: 1px solid var(--border) !important; box-shadow: var(--shadow) !important; }
.leaflet-top.leaflet-left { margin-top: 56px; }
.velocity-overlay { background: var(--surface) !important; color: var(--text) !important; }

@media (max-width: 720px) {
  .panel { width: calc(100% - 24px); top: 58px; bottom: 90px; }
  .details { width: calc(100% - 24px); max-height: 46%; }
  .timeline { width: calc(100% - 24px); }
  .legend { display: none; }
  .brand { display: none; }
}
