:root {
  --awc-vfr: #16a34a;
  --awc-mvfr: #2563eb;
  --awc-ifr: #dc2626;
  --awc-lifr: #a21caf;
  --awc-unknown: #64748b;
  --awc-pirep: #f97316;
  --awc-sigmet: #ef4444;
  --awc-gairmet: #f59e0b;
}

* {
  box-sizing: border-box;
}

.topbar {
  border-bottom: 1px solid rgba(148, 163, 184, .32);
}

.brand::before {
  content: "◉";
  display: inline-grid;
  width: 28px;
  height: 28px;
  margin-right: 8px;
  place-items: center;
  border-radius: 8px;
  color: #fff;
  background: linear-gradient(135deg, #0f766e, #2563eb);
  font-size: 15px;
  vertical-align: 2px;
}

.page-panel {
  padding-bottom: 40px;
}

.page-card {
  min-height: 132px;
}

.source-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.source-card-header h2 {
  margin: 0;
}

.source-badge {
  flex: 0 0 auto;
  padding: 3px 7px;
  border-radius: 999px;
  color: #166534;
  background: #dcfce7;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.source-badge.stale {
  color: #92400e;
  background: #fef3c7;
}

.source-badge.error {
  color: #991b1b;
  background: #fee2e2;
}

.source-badge.loading {
  color: #334155;
  background: #e2e8f0;
}

.source-metric {
  margin: 12px 0 4px;
  color: #0f172a;
  font-size: 24px;
  font-weight: 800;
}

.source-detail {
  margin: 3px 0;
  color: #475569;
  font-size: 12px;
}

.aviation-legend {
  display: grid;
  gap: 5px;
  margin-top: 8px;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border: 1px solid rgba(15, 23, 42, .45);
  border-radius: 50%;
}

.legend-ring {
  width: 11px;
  height: 11px;
  border: 2px solid;
  border-radius: 50%;
  background: rgba(255, 255, 255, .55);
}

.flight-categories {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 3px;
}

.flight-category {
  padding: 3px 2px;
  border-radius: 4px;
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  text-align: center;
}

.flight-category.vfr { background: var(--awc-vfr); }
.flight-category.mvfr { background: var(--awc-mvfr); }
.flight-category.ifr { background: var(--awc-ifr); }
.flight-category.lifr { background: var(--awc-lifr); }

.drawer-section-title {
  margin: 8px 2px 4px;
  color: #475569;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.layer-count {
  float: right;
  padding-left: 8px;
  color: #64748b;
  font-size: 11px;
}

.awc-popup {
  min-width: 230px;
  color: #0f172a;
  line-height: 1.4;
}

.awc-popup h3 {
  margin: 0 0 4px;
  color: #0f766e;
  font-size: 15px;
}

.awc-popup .raw {
  margin-top: 7px;
  padding: 6px;
  border-radius: 5px;
  background: #f1f5f9;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 11px;
  overflow-wrap: anywhere;
}

.awc-popup .category {
  display: inline-block;
  margin-bottom: 5px;
  padding: 2px 6px;
  border-radius: 999px;
  color: #fff;
  font-size: 11px;
  font-weight: 800;
}

body.theme-dark .source-detail {
  color: #cbd5e1;
}

body.theme-dark .source-metric {
  color: #f8fafc;
}

body.theme-dark .source-badge {
  color: #bbf7d0;
  background: #14532d;
}

body.theme-dark .source-badge.stale {
  color: #fde68a;
  background: #78350f;
}

body.theme-dark .source-badge.error {
  color: #fecaca;
  background: #7f1d1d;
}

body.theme-dark .source-badge.loading {
  color: #e2e8f0;
  background: #334155;
}

@media (min-width: 721px) {
  .obs {
    width: clamp(360px, 48vw, 600px);
    height: auto;
    min-height: 78px;
    padding: 8px 12px 10px;
    overflow: hidden;
    border-right: 1px solid rgba(56, 189, 248, .55);
    border-bottom: 3px solid rgba(56, 189, 248, .9);
    border-bottom-right-radius: 12px;
    background: linear-gradient(135deg, rgba(15, 23, 42, .9), rgba(15, 118, 110, .76));
    box-shadow: 0 5px 16px rgba(2, 6, 23, .28);
  }

  .obs-title {
    font-size: clamp(24px, 2.2vw, 28px);
    line-height: 1.05;
  }

  .obs-sub {
    margin-top: 5px;
    font-size: 12px;
    line-height: 1.35;
  }

  .status {
    right: 58px;
    max-width: calc(100vw - 430px);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .rail {
    top: 84px;
  }

  .leaflet-control-zoom {
    margin-top: 152px !important;
  }

  .timeline {
    grid-template-columns: 54px 48px minmax(0, 1fr) minmax(260px, 300px);
  }

  .timeline .time {
    overflow: hidden;
    font-size: clamp(15px, 1.35vw, 18px);
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .page-grid {
    max-width: 1680px;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  }

  #settingsPage .page-grid {
    max-width: 720px;
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .topbar {
    height: calc(54px + env(safe-area-inset-top));
    gap: 3px;
    padding: env(safe-area-inset-top) 6px 0;
    overflow: hidden;
  }

  .brand {
    display: inline-flex;
    flex: 0 0 auto;
    min-width: 0;
    height: 44px;
    align-items: center;
    font-size: 0;
  }

  .brand::after {
    content: "Anchorita";
    font-size: 16px;
  }

  .brand::before {
    width: 24px;
    height: 24px;
    margin-right: 5px;
  }

  .top-link {
    flex: 0 0 auto;
    display: inline-flex;
    min-height: 44px;
    align-items: center;
    padding: 4px 6px;
    font-size: 11px;
    line-height: 1.1;
  }

  .top-link[data-page="sourcesPage"] {
    font-size: 0;
  }

  .top-link[data-page="sourcesPage"]::after {
    content: "Sources";
    font-size: 11px;
  }

  .obs {
    top: calc(54px + env(safe-area-inset-top));
    right: 0;
    width: auto;
    height: 88px;
    padding: 8px 10px;
  }

  .obs-title {
    font-size: 22px;
  }

  .obs-sub {
    margin-top: 5px;
    font-size: 11px;
  }

  .status {
    top: calc(142px + env(safe-area-inset-top));
    left: 0;
    right: 0;
    overflow: hidden;
    font-size: 11px;
    text-align: center;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .leaflet-control-zoom {
    margin-top: calc(176px + env(safe-area-inset-top)) !important;
  }

  .rail {
    top: auto;
    bottom: calc(120px + env(safe-area-inset-bottom));
    left: 8px;
    right: 8px;
    flex-direction: row;
    justify-content: center;
    gap: 6px;
    overflow-x: auto;
    overflow-y: hidden;
  }

  .rail button {
    flex: 0 0 44px;
    width: 44px;
    height: 44px;
    border-radius: 8px;
  }

  .drawer {
    top: calc(174px + env(safe-area-inset-top));
    bottom: calc(174px + env(safe-area-inset-bottom));
    left: 8px;
    right: 8px;
    width: auto;
    max-height: none;
    overflow-y: auto;
  }

  .drawer button,
  .drawer input,
  .settings-btn {
    min-height: 44px;
    font-size: 14px;
  }

  .legend {
    left: 8px;
    right: 8px;
    bottom: calc(174px + env(safe-area-inset-bottom));
    width: auto;
    max-height: min(220px, calc(100vh - 366px - env(safe-area-inset-top) - env(safe-area-inset-bottom)));
    overflow-y: auto;
  }

  .opacity {
    left: 8px;
    right: 8px;
    bottom: calc(174px + env(safe-area-inset-bottom));
    width: auto;
  }

  .timeline {
    height: calc(112px + env(safe-area-inset-bottom));
    grid-template-columns: 48px 96px minmax(0, 1fr);
    grid-template-rows: 55px 39px;
    gap: 4px 8px;
    padding: 6px 8px calc(4px + env(safe-area-inset-bottom));
  }

  .play {
    width: 44px;
    height: 44px;
  }

  .step {
    gap: 4px;
  }

  .step button {
    width: 44px;
    height: 44px;
  }

  .timeline .time {
    grid-column: 1 / -1;
    grid-row: 2;
    font-size: 14px;
  }

  .page-panel {
    top: calc(54px + env(safe-area-inset-top));
    padding: clamp(12px, 4vw, 18px);
    padding-bottom: calc(36px + env(safe-area-inset-bottom));
  }

  .page-grid {
    grid-template-columns: 1fr;
  }

  .page-card {
    min-width: 0;
    min-height: 0;
    overflow-wrap: anywhere;
  }

  .source-card-header {
    flex-wrap: wrap;
  }

  .leaflet-popup-content-wrapper,
  .leaflet-popup-tip-container {
    max-width: calc(100vw - 24px);
  }

  .awc-popup {
    min-width: 0;
    max-width: calc(100vw - 76px);
  }
}

@media (max-height: 620px) and (max-width: 720px) {
  .obs {
    height: 78px;
  }

  .obs-title {
    font-size: 20px;
  }

  .obs-sub {
    margin-top: 4px;
    font-size: 10px;
  }

  .status {
    top: calc(132px + env(safe-area-inset-top));
  }

  .leaflet-control-zoom {
    margin-top: calc(166px + env(safe-area-inset-top)) !important;
  }

  .drawer {
    top: calc(164px + env(safe-area-inset-top));
  }

  .legend {
    max-height: min(190px, calc(100vh - 346px - env(safe-area-inset-top) - env(safe-area-inset-bottom)));
  }
}

@media (max-width: 360px) {
  .brand::after {
    content: "Weather";
    font-size: 15px;
  }
}
