:root {
  --bg: #0E1116;
  --surface: #161B22;
  --surface-2: #1F2630;
  --surface-3: #262E3A;
  --code-bg: #0B0F14;
  --code-fg: #D7F5DD;
  --fg: #E6EDF3;
  --fg-muted: #9AA7B4;
  --outline: #3A4452;
  --primary: #7CC4FF;
  --selected: #1E3A55;
  --warn: #FFB86B;
  --error-bg: #3A1D22;
  --error-fg: #FFB4B4;
  --radius: 14px;
  --panel-w: 420px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "Cascadia Mono", Menlo, Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.4 var(--font);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; }

#map { position: fixed; inset: 0; background: var(--bg); }
.maplibregl-map { font: inherit; }
.maplibregl-ctrl-bottom-right { z-index: 3; }
.maplibregl-ctrl-attrib, .maplibregl-ctrl-attrib.maplibregl-compact {
  background: color-mix(in srgb, var(--surface) 80%, transparent) !important;
  color: var(--fg-muted);
  font-size: 10px;
}
.maplibregl-ctrl-attrib a { color: var(--fg-muted); }
.maplibregl-ctrl-attrib-button { filter: invert(0.85); }
.maplibregl-ctrl-group { background: var(--surface) !important; }
.maplibregl-ctrl-group button + button { border-top-color: var(--outline) !important; }
.maplibregl-ctrl-group button .maplibregl-ctrl-icon { filter: invert(0.9); }
.maplibregl-ctrl-bottom-right { bottom: env(safe-area-inset-bottom); }

.station-canvas { position: absolute; inset: 0; pointer-events: none; z-index: 2; }

/* ---------------------------------------------------------------- top bar */
.topbar {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 12px);
  left: 12px;
  width: min(440px, calc(100vw - 24px));
  z-index: 1000;
}
.search {
  display: flex; align-items: center; gap: 4px;
  height: 52px; padding: 0 4px 0 16px;
  border-radius: 28px;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  box-shadow: 0 4px 18px #0008;
  backdrop-filter: blur(6px);
}
.search .icon { width: 22px; height: 22px; fill: var(--fg-muted); flex: none; margin-right: 8px; }
.search input {
  flex: 1; min-width: 0;
  background: none; border: none; outline: none;
  color: var(--fg); font-size: 16px; font-weight: 500;
  text-transform: uppercase;
}
.search input::placeholder { color: var(--fg-muted); text-transform: none; font-weight: 400; }
.icon-btn {
  display: grid; place-items: center;
  width: 44px; height: 44px; flex: none;
  border: none; border-radius: 50%;
  background: none; cursor: pointer;
}
.icon-btn svg { width: 22px; height: 22px; fill: var(--fg); }
.icon-btn:hover { background: #ffffff12; }
.icon-btn:focus-visible, .tabs button:focus-visible, .segmented button:focus-visible, .legend:focus-visible {
  outline: 2px solid var(--primary); outline-offset: 2px;
}
#refresh.spinning svg { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.progress {
  height: 2px; margin: 6px 24px 0; border-radius: 2px; overflow: hidden;
  position: relative;
}
.progress::after {
  content: ""; position: absolute; inset: 0 auto 0 0; width: 40%;
  background: var(--primary); border-radius: 2px;
  animation: slide 1.1s ease-in-out infinite;
}
@keyframes slide { from { left: -40%; } to { left: 100%; } }

.feed-banner {
  margin-top: 8px; padding: 8px 14px; border-radius: 12px;
  background: #3A2E14; color: var(--warn); font-size: 13px;
  box-shadow: 0 2px 10px #0006;
}

/* ---------------------------------------------------------------- layers menu */
.layers-panel {
  margin-top: 8px; padding: 12px 14px; border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  box-shadow: 0 4px 18px #0008;
  max-height: calc(100vh - 160px); overflow-y: auto;
}
.layers-panel h2 { margin: 0 0 6px; font-size: 14px; }
.layer-row { display: flex; gap: 10px; align-items: flex-start; padding: 6px 0; cursor: pointer; }
.layer-row input { margin-top: 3px; accent-color: var(--primary); width: 16px; height: 16px; flex: none; }
.layer-text { display: flex; flex-direction: column; }
.layer-name { font-weight: 600; font-size: 14px; }
.layer-count { color: var(--fg-muted); font-weight: 400; font-size: 12px; }
.layer-note { color: var(--fg-muted); font-size: 12px; margin: 0; }
.radar-scale { display: flex; height: 8px; border-radius: 4px; overflow: hidden; margin-top: 10px; }
.radar-scale span { flex: 1; }
.radar-scale-labels { display: flex; justify-content: space-between; font-size: 11px; color: var(--fg-muted); margin: 2px 0 8px; }
.radar-time {
  display: inline-block; margin: 8px 0 0 8px; padding: 2px 10px; border-radius: 999px;
  background: color-mix(in srgb, var(--surface) 90%, transparent); color: var(--fg-muted); font-size: 12px;
}
.maplibregl-popup { z-index: 3; } /* above the station-dot canvas */
.hazard-popup .maplibregl-popup-content {
  background: var(--surface); color: var(--fg); border-radius: 10px; font-size: 13px; padding: 10px 28px 10px 12px;
}
.hazard-popup pre { white-space: pre-wrap; font: 11px/1.4 var(--mono); color: var(--fg-muted); margin: 6px 0 0; max-height: 200px; overflow: auto; }
.hazard-popup .maplibregl-popup-tip { border-top-color: var(--surface); border-bottom-color: var(--surface); }
.hazard-popup .maplibregl-popup-close-button { color: var(--fg-muted); font-size: 18px; }

/* ---------------------------------------------------------------- no-map fallback */
.map-fallback {
  position: fixed; z-index: 900;
  top: calc(env(safe-area-inset-top) + 84px); left: 12px;
  width: min(440px, calc(100vw - 24px));
  max-height: calc(100vh - 160px);
  display: flex; flex-direction: column;
  background: var(--surface); border-radius: var(--radius);
  box-shadow: 0 4px 18px #0008;
  padding: 16px 16px 8px;
}
.map-fallback h2 { margin: 0 0 6px; font-size: 16px; }
.map-fallback p { margin: 0 0 12px; color: var(--fg-muted); font-size: 13px; }
.fallback-list { overflow-y: auto; margin: 0 -8px; }
.fallback-item {
  display: grid; grid-template-columns: 9px 48px 1fr auto; gap: 10px; align-items: center;
  width: 100%; padding: 8px; border: none; border-radius: 10px;
  background: none; cursor: pointer; text-align: left;
}
.fallback-item:hover, .fallback-item:focus-visible { background: var(--surface-2); outline: none; }
.fb-icao { font-weight: 600; font-family: var(--mono); font-size: 13px; }
.fb-name { color: var(--fg-muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fb-cat { font-size: 12px; font-weight: 700; }

/* ---------------------------------------------------------------- bottom left */
.bottom-left {
  position: fixed; left: 12px;
  bottom: calc(env(safe-area-inset-bottom) + 12px);
  z-index: 1000;
  display: flex; flex-direction: column; align-items: flex-start; gap: 8px;
  max-width: calc(100vw - 24px);
}
.toast {
  background: var(--error-bg); color: var(--error-fg);
  padding: 8px 12px; border-radius: 12px; font-size: 13px; cursor: pointer;
  box-shadow: 0 2px 10px #0006;
}
.legend {
  display: flex; flex-direction: column; gap: 4px; align-items: flex-start;
  padding: 8px 12px; border: none; border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  cursor: pointer; text-align: left;
}
.legend .row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.legend .item { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; }
.legend .desc { font-size: 11px; color: var(--fg-muted); font-weight: 400; margin-left: 4px; }
.legend .hint { font-size: 11px; color: var(--fg-muted); margin-top: 2px; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }

.site-links { display: flex; gap: 12px; padding: 0 4px; font-size: 11px; }
.site-links a { color: var(--fg-muted); text-decoration: none; }
.site-links a:hover, .site-links a:focus-visible { color: var(--fg); text-decoration: underline; }

.notice {
  width: min(400px, calc(100vw - 24px));
  background: #3A2E14; color: #FFE2B0;
  border-radius: var(--radius); padding: 12px 14px;
  box-shadow: 0 4px 18px #0008;
  font-size: 13px;
}
.notice p { margin: 0 0 10px; }
.notice strong { color: #FFF0D6; }
.notice-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.notice-actions a { color: #FFD089; }
.notice-actions button {
  border: none; border-radius: 999px; padding: 7px 14px; cursor: pointer;
  background: #FFD089; color: #2A1E05; font-weight: 600;
}
.notice-actions button:focus-visible, .notice-actions a:focus-visible { outline: 2px solid #FFF0D6; outline-offset: 2px; }

/* ---------------------------------------------------------------- station panel */
.panel {
  position: fixed; z-index: 1100;
  background: var(--surface);
  display: flex; flex-direction: column;
  box-shadow: 0 0 30px #000a;
  /* Fully hidden once closed (no shadow peeking, no tabbing into its buttons); visibility flips
     after the slide-out finishes and immediately on opening. */
  visibility: hidden;
  transition: transform 220ms cubic-bezier(.2,.8,.2,1), visibility 0s 220ms;
}
.panel.open { visibility: visible; transition: transform 220ms cubic-bezier(.2,.8,.2,1); }
/* Wide screens: right-hand side panel. */
@media (min-width: 760px) {
  .panel {
    top: 0; right: 0; bottom: 0; width: var(--panel-w);
    transform: translateX(105%);
    padding-top: env(safe-area-inset-top);
  }
  .panel.open { transform: none; }
  .panel .panel-grip { display: none; }
}
/* Phones: bottom sheet that can be dragged taller. */
@media (max-width: 759.98px) {
  .panel {
    left: 0; right: 0; bottom: 0;
    height: 58vh; max-height: calc(100vh - 24px);
    border-radius: 24px 24px 0 0;
    transform: translateY(105%);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .panel.open { transform: none; }
  .panel.expanded { height: 92vh; }
  .panel.dragging { transition: none; }
}
.panel-grip { display: grid; place-items: center; height: 22px; cursor: grab; touch-action: none; flex: none; }
.panel-grip span { width: 36px; height: 4px; border-radius: 2px; background: var(--fg-muted); opacity: 0.7; }
.panel-close { position: absolute; top: calc(env(safe-area-inset-top) + 10px); right: 10px; }
@media (max-width: 759.98px) { .panel-close { top: 16px; } }

.panel-head { padding: 14px 20px 0; flex: none; }
.title-row { display: flex; align-items: center; gap: 10px; }
.panel h1 { margin: 0; font-size: 28px; font-weight: 700; letter-spacing: 0.5px; }
.pill {
  display: inline-block; padding: 1px 8px; border-radius: 8px;
  font-weight: 700; font-size: 13px; border: 1px solid;
}
.ltg-badge {
  display: inline-block; margin: 6px 0 2px; padding: 2px 10px; border-radius: 999px;
  background: #3A3410; color: #FFE27A; font-size: 12px; font-weight: 600;
}
.ltg-dot { background: radial-gradient(circle, #ECF2FF 0 35%, #8FB4FF 60%, transparent 75%); box-shadow: 0 0 6px #BFD3FF; }
.sub { color: var(--fg-muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-right: 40px; }
.age { color: var(--fg-muted); font-size: 12px; margin-top: 2px; }
.age.stale { color: var(--warn); }

.stats {
  display: flex; gap: 8px; overflow-x: auto; flex: none;
  padding: 12px 20px; scrollbar-width: none;
}
.stats::-webkit-scrollbar { display: none; }
.stat { background: var(--surface-2); border-radius: 12px; padding: 8px 12px; flex: none; }
.stat .k { font-size: 10px; letter-spacing: 0.8px; color: var(--fg-muted); text-transform: uppercase; }
.stat .v { font-size: 15px; font-weight: 600; white-space: nowrap; }

.tabs { display: flex; flex: none; margin-top: 4px; }
.tabs button {
  flex: 1; padding: 12px 0; border: none; background: none; cursor: pointer;
  color: var(--primary); font-weight: 600; font-size: 15px; letter-spacing: 0.3px;
  position: relative; opacity: 0.75;
}
.tabs button[aria-selected="true"] { opacity: 1; }
.tabs button[aria-selected="true"]::after {
  content: ""; position: absolute; left: 50%; bottom: 0; width: 48px; height: 3px;
  transform: translateX(-50%); background: var(--primary); border-radius: 3px 3px 0 0;
}

.segmented {
  display: flex; flex: none; margin: 12px auto; width: min(320px, calc(100% - 40px));
  border: 1px solid var(--outline); border-radius: 999px; overflow: hidden;
}
.segmented button {
  flex: 1; padding: 8px 0; border: none; background: none; cursor: pointer; font-weight: 500;
}
.segmented button + button { border-left: 1px solid var(--outline); }
.segmented button[aria-checked="true"] { background: var(--selected); color: #D3E8FF; }
.segmented button[aria-checked="true"]::before { content: "✓ "; }

.panel-body { flex: 1; overflow-y: auto; padding: 0 20px 24px; overscroll-behavior: contain; }

.code {
  background: var(--code-bg); color: var(--code-fg);
  border-radius: var(--radius); padding: 16px;
  font: 14px/1.6 var(--mono); white-space: pre-wrap; word-break: break-word;
  margin: 0; user-select: text;
}
.fields { background: var(--surface-2); border-radius: var(--radius); padding: 6px 16px; }
.field { display: grid; grid-template-columns: 128px 1fr; gap: 8px; padding: 6px 0; }
.field .k { color: var(--fg-muted); font-size: 13px; }
.field .v { white-space: pre-line; }
.period .field { grid-template-columns: 96px 1fr; padding: 3px 0; }

.section-title {
  margin: 20px 0 8px; font-size: 11px; letter-spacing: 1px; font-weight: 600;
  color: var(--fg-muted); text-transform: uppercase;
}
.valid { color: var(--fg-muted); font-size: 12px; margin-bottom: 8px; }
.periods { display: flex; flex-direction: column; gap: 10px; }
.period {
  background: var(--surface-2); border-radius: var(--radius); padding: 14px 14px 14px 18px;
  border-left: 4px solid var(--cat);
}
.period-head { display: flex; align-items: center; gap: 8px; }
.period-head .t { flex: 1; font-weight: 600; font-size: 15px; }
.period .range { color: var(--fg-muted); font-size: 12px; margin-bottom: 8px; }

.history { display: flex; flex-direction: column; gap: 6px; }
.hist { display: flex; gap: 10px; align-items: flex-start; }
.hist .bar { width: 4px; height: 28px; margin-top: 4px; border-radius: 2px; flex: none; }
.hist .txt { font-size: 13px; line-height: 1.4; color: #E6EDF3D9; }
.hist .txt.mono { font: 12px/1.45 var(--mono); }
.link-btn { background: none; border: none; color: var(--primary); cursor: pointer; padding: 8px 0; font-weight: 500; }
.msg { color: var(--fg-muted); padding: 8px 0; }
.panel-note { margin: 24px 0 0; color: var(--fg-muted); font-size: 12px; }
.panel-note a { color: var(--fg-muted); }
.spinner {
  width: 24px; height: 24px; margin: 24px auto; border-radius: 50%;
  border: 2px solid var(--outline); border-top-color: var(--primary);
  animation: spin 0.8s linear infinite;
}

@media (max-width: 420px) {
  .field { grid-template-columns: 108px 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
