:root {
  color-scheme: dark;
  --bg: #0d1117;
  --bg-elev: #161b22;
  --bg-elev-2: #1f2630;
  --border: #2d333b;
  --text: #e6edf3;
  --text-dim: #9aa4b1;
  --accent: #58a6ff;
  --error: #f85149;
  --gap: 8px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --footer-h: 32px;
  --wxbar-h: 44px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.4;
  height: 100%;
  overflow-x: hidden;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* =================================================================
   Cameras - primary content; each tile sized by the stream's aspect ratio
   ================================================================= */
.cams {
  display: grid;
  grid-template-columns: 1fr;
  /* Rows size to content so 16:9 tiles don't stretch and leave black space. */
  grid-auto-rows: max-content;
  align-content: start;
  gap: var(--gap);
  padding: var(--gap);
  padding-top: calc(var(--gap) + var(--safe-top));
  /* Reserve space at the bottom for the fixed footer. */
  padding-bottom: calc(var(--gap) + var(--footer-h) + var(--safe-bottom));
}

/* Phone landscape, small tablets: 2 columns */
@media (min-width: 700px) and (orientation: landscape),
       (min-width: 820px) {
  .cams { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Larger displays: 3 columns when there are enough cameras */
@media (min-width: 1500px) {
  .cams { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

.cam {
  margin: 0;
  background: #000;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
/* <video-stream> is the go2rtc MSE player wrapper; it injects a <video> child
   and sets its width/height to 100%, so the wrapper carries the aspect ratio. */
.cam video-stream {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
}
/* The <video> always lives inside <video-stream> now (MSE player), so a
   standalone .cam video selector is no longer needed. */
.cam video-stream video {
  width: 100%;
  height: 100%;
  display: block;
  background: #000;
  object-fit: contain;
}
.cam figcaption.cam-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 8px 4px 10px;
  background: rgba(0, 0, 0, 0.55);
  border-top: 1px solid var(--border);
}
.cam-name {
  color: var(--text-dim);
  font-size: 0.78rem;
  letter-spacing: 0.2px;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Availability overlay - covers the video (not the caption) while a stream is
   connecting or unavailable. Hidden once the tile is "live". */
.cam-view { position: relative; display: block; }
.cam-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px;
  text-align: center;
  background: rgba(13, 17, 23, 0.72);
  opacity: 1;
  transition: opacity 0.25s ease;
  pointer-events: none;
}
.cam-view[data-cam-state="live"] .cam-overlay {
  opacity: 0;
  visibility: hidden;
}
.cam-ov-spin {
  width: 26px;
  height: 26px;
  border: 3px solid rgba(255, 255, 255, 0.18);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: cam-spin 0.9s linear infinite;
}
@keyframes cam-spin { to { transform: rotate(360deg); } }
.cam-ov-text { color: var(--text); font-weight: 600; letter-spacing: 0.2px; }
.cam-ov-sub { color: var(--text-dim); font-size: 0.72rem; }
.cam-view[data-cam-state="offline"] .cam-ov-spin { border-top-color: var(--error); }
.cam-view[data-cam-state="offline"] .cam-ov-text { color: var(--error); }
@media (prefers-reduced-motion: reduce) {
  .cam-ov-spin { animation: none; }
}

.cams-empty {
  grid-column: 1 / -1;
  padding: 48px 12px;
  text-align: center;
  color: var(--text-dim);
}

/* =================================================================
   Quality selector - per-camera segmented control inside the caption bar
   ================================================================= */
.qsel {
  display: inline-flex;
  flex: 0 0 auto;
  gap: 2px;
  padding: 2px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 7px;
}
.qbtn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-dim);
  font: inherit;
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 5px;
  cursor: pointer;
  line-height: 1;
}
.qbtn:hover { background: rgba(255, 255, 255, 0.06); color: var(--text); }
.qbtn.active { background: var(--accent); color: #06101f; }
.qbtn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* =================================================================
   Debug overlay - opt-in diagnostics (?debug=1 / localStorage)
   ================================================================= */
.debug-overlay {
  position: fixed;
  left: 8px;
  /* Sits above the radio pill (also bottom-left) so the two never overlap. */
  bottom: calc(var(--footer-h) + var(--safe-bottom) + 56px);
  z-index: 40;
  max-width: min(92vw, 360px);
  padding: 8px 10px;
  background: rgba(0, 0, 0, 0.82);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.68rem;
  line-height: 1.5;
  color: var(--text-dim);
}
.debug-overlay[hidden] { display: none; }
.dbg-row { display: flex; gap: 8px; }
.dbg-k { color: var(--accent); min-width: 88px; flex: 0 0 auto; }
.dbg-v { color: var(--text); word-break: break-all; }

/* =================================================================
   CTAF radio - single shared audio player (fixed pill, bottom-left)
   ================================================================= */
.radiobar {
  position: fixed;
  left: 8px;
  bottom: calc(var(--footer-h) + var(--safe-bottom) + 8px);
  z-index: 30;
}
.radio-toggle {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 7px 14px 7px 11px;
  background: rgba(22, 27, 34, 0.92);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  text-align: left;
}
.radio-toggle:hover { background: rgba(31, 38, 48, 0.95); }
.radio-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.radio-icon {
  position: relative;
  width: 14px;
  height: 14px;
  flex: 0 0 auto;
}
/* idle / offline: play triangle (tap to start / retry) */
.radio-icon::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 52%;
  transform: translate(-50%, -50%);
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 6px 0 6px 10px;
  border-color: transparent transparent transparent var(--accent);
  border-radius: 1px;
}
#radiobar[data-state="offline"] .radio-icon::before { border-left-color: var(--error); }
/* loading: spinner */
#radiobar[data-state="loading"] .radio-icon::before {
  top: 0;
  left: 0;
  transform: none;
  width: 14px;
  height: 14px;
  box-sizing: border-box;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: radio-spin 0.8s linear infinite;
}
@keyframes radio-spin { to { transform: rotate(360deg); } }
/* playing: pulsing live dot */
#radiobar[data-state="playing"] .radio-icon::before {
  top: 2px;
  left: 2px;
  transform: none;
  width: 10px;
  height: 10px;
  border: 0;
  border-radius: 50%;
  background: var(--error);
  animation: radio-pulse 1.5s ease-in-out infinite;
}
@keyframes radio-pulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(248, 81, 73, 0.5); }
  50% { opacity: 0.55; box-shadow: 0 0 0 5px rgba(248, 81, 73, 0); }
}
@media (prefers-reduced-motion: reduce) {
  #radiobar[data-state="loading"] .radio-icon::before,
  #radiobar[data-state="playing"] .radio-icon::before { animation: none; }
}

.radio-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  min-width: 0;
}
.radio-title {
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.2px;
}
.radio-state {
  font-size: 0.6rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
#radiobar[data-state="playing"] .radio-state,
#radiobar[data-state="offline"] .radio-state { color: var(--error); }

/* Live audio-level meter: replaces the pulsing dot while playing, but only
   once main.js confirms the stream is CORS-readable (data-meter="on"). */
.radio-meter {
  display: none;
  align-items: flex-end;
  gap: 2px;
  width: 16px;
  height: 14px;
  flex: 0 0 auto;
}
.radio-meter i {
  display: block;
  flex: 1 1 0;
  height: 100%;
  background: var(--error);
  border-radius: 1px;
  transform: scaleY(0.12);
  transform-origin: bottom;
  transition: transform 0.09s linear;
}
#radiobar[data-state="playing"][data-meter="on"] .radio-meter { display: flex; }
#radiobar[data-state="playing"][data-meter="on"] .radio-icon { display: none; }
@media (prefers-reduced-motion: reduce) {
  /* Keep the (static) live dot instead of moving bars. */
  #radiobar[data-state="playing"][data-meter="on"] .radio-meter { display: none; }
  #radiobar[data-state="playing"][data-meter="on"] .radio-icon { display: block; }
}

/* =================================================================
   Weather bar - compact, tappable, expandable
   ================================================================= */
.wxbar {
  position: fixed;
  top: var(--safe-top);
  right: 8px;
  z-index: 30;
  max-width: calc(100vw - 16px);
  background: rgba(22, 27, 34, 0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  overflow: hidden;
  font-size: 0.82rem;
}

.wx-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  height: var(--wxbar-h);
  padding: 0 12px;
  background: transparent;
  color: var(--text);
  border: 0;
  cursor: pointer;
  font: inherit;
  text-align: left;
}
.wx-toggle:hover { background: rgba(255, 255, 255, 0.04); }

.wx-summary {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 75vw;
  font-variant-numeric: tabular-nums;
}
.wx-chev {
  margin-left: auto;
  color: var(--text-dim);
  font-size: 0.7rem;
  transform: rotate(180deg);
  transition: transform 0.18s ease;
}
.wxbar.open .wx-chev { transform: rotate(0deg); }

.wx-details {
  padding: 8px 12px 12px;
  border-top: 1px solid var(--border);
}
.wx-dl {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 16px;
  margin: 0;
}
.wx-dl > div { min-width: 0; }
.wx-dl dt {
  color: var(--text-dim);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 0;
}
.wx-dl dd {
  margin: 1px 0 0;
  color: var(--text);
  font-size: 0.92rem;
  font-variant-numeric: tabular-nums;
}
.metar-raw {
  margin: 8px 0 0;
  padding: 6px 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-dim);
  font-size: 0.7rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap;
  word-break: break-all;
}

/* On very narrow screens, anchor the bar full-width across the top. */
@media (max-width: 480px) {
  .wxbar {
    left: 8px;
    right: 8px;
    max-width: none;
  }
  .wx-summary { max-width: calc(100vw - 80px); }
  .wx-dl { grid-template-columns: 1fr 1fr; }
}

/* =================================================================
   Footer - thin info strip
   ================================================================= */
.site-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--footer-h);
  padding: 0 12px;
  padding-bottom: var(--safe-bottom);
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(13, 17, 23, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 0.72rem;
  overflow-x: auto;
  white-space: nowrap;
  z-index: 20;
}
.site-footer .sep { color: var(--border); }
.site-footer .viewers { font-variant-numeric: tabular-nums; }

/* Hide footer-only decorations on very narrow viewports. */
@media (max-width: 520px) {
  .site-footer { font-size: 0.68rem; gap: 6px; padding: 0 8px; }
}
