:root {
  color-scheme: light;
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #eef1f6;
  --text: #0f172a;
  --muted: #5b6475;
  --border: #e1e6ef;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --radar-bg: #ffffff;
  --ring: #d3dae6;
  --ring-faint: #e8ecf3;
  --alt-low: #e4572e;
  --alt-mid: #d68c00;
  --alt-high: #2f7de1;
  --alt-cruise: #7d8698;
  --danger: #c62828;
  --shadow: 0 10px 30px rgb(15 23 42 / 0.14), 0 2px 6px rgb(15 23 42 / 0.08);
  --radius: 14px;
  --drawer-w: 400px;
  font-family:
    system-ui,
    -apple-system,
    'Segoe UI',
    Roboto,
    sans-serif;
}

:root[data-theme='dark'] {
  color-scheme: dark;
  --bg: #0b1220;
  --surface: #121b2d;
  --surface-2: #1a2539;
  --text: #e7ecf5;
  --muted: #93a0b8;
  --border: #22304a;
  --accent: #5b9cff;
  --accent-text: #0b1220;
  --radar-bg: #0f1828;
  --ring: #2a3a57;
  --ring-faint: #1b2740;
  --alt-low: #ff7b54;
  --alt-mid: #f6b73c;
  --alt-high: #5fa2ff;
  --alt-cruise: #9aa5bb;
  --danger: #ff6b6b;
  --shadow: 0 10px 30px rgb(0 0 0 / 0.45), 0 2px 6px rgb(0 0 0 / 0.3);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
}

[hidden] {
  display: none !important;
}

[data-screen='setup'] .sky-only,
[data-screen='sky'] .setup-only {
  display: none !important;
}

h1,
h2,
h3,
p {
  margin: 0;
}

a {
  color: inherit;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

.muted {
  color: var(--muted);
  font-weight: 400;
}

button.link {
  padding: 4px 0;
  border: 0;
  background: none;
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
}

/* --- page frame --- */

.app {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px)
    env(safe-area-inset-left, 0px);
  transition: right 0.25s ease;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px 6px;
}

.logo {
  display: block;
  width: auto;
  height: 28px;
  color: var(--text);
}

.logo-accent,
.logo-plane {
  fill: var(--accent);
}

.top h1 {
  flex: none;
  font-size: 1.25rem;
  letter-spacing: -0.01em;
}

.top-right {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.theme-btn {
  flex: none;
}

.icon-sun,
[data-theme='dark'] .icon-moon {
  display: none;
}

[data-theme='dark'] .icon-sun {
  display: block;
}

.place {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-size: 0.9rem;
}

.place-label {
  overflow: hidden;
  color: var(--muted);
  white-space: nowrap;
  text-overflow: ellipsis;
}

.stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 0;
  padding: 4px 16px;
  overflow: auto;
}

/* --- setup --- */

.setup {
  display: grid;
  gap: 14px;
  width: 100%;
  max-width: 460px;
  padding: 22px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.setup h2 {
  font-size: 1.4rem;
}

button.primary {
  padding: 14px 16px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 650;
  cursor: pointer;
}

.search {
  display: grid;
  gap: 6px;
  margin-top: 6px;
}

.search label {
  color: var(--muted);
  font-size: 0.9rem;
}

.search-row {
  display: flex;
  gap: 8px;
}

.search-row input {
  flex: 1;
  min-width: 0;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
}

.search-row button {
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  font-weight: 600;
  cursor: pointer;
}

.results {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.results:empty,
.setup-status:empty {
  display: none;
}

.results button {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  text-align: left;
  cursor: pointer;
}

.results button:hover {
  border-color: var(--accent);
}

.setup-status {
  color: var(--muted);
  font-size: 0.9rem;
}

/* --- radar --- */

.radar {
  display: block;
  width: 100%;
  height: 100%;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.radar .radar-bg {
  fill: var(--radar-bg);
  stroke: var(--ring);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.radar .ring {
  fill: none;
  stroke: var(--ring);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.radar .ring.faint,
.radar .axis {
  fill: none;
  stroke: var(--ring-faint);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.radar .ring-label {
  fill: var(--muted);
  font-size: 11px;
}

.radar .cardinal {
  fill: var(--muted);
  font-size: 13px;
  font-weight: 700;
  text-anchor: middle;
  dominant-baseline: central;
}

.radar .radar-empty {
  fill: var(--muted);
  font-size: 13px;
  text-anchor: middle;
}

.radar .home {
  fill: var(--accent);
}

.radar .home-halo {
  fill: var(--accent);
  opacity: 0.18;
}

.radar .plane {
  cursor: pointer;
}

.radar .plane .hit {
  fill: transparent;
}

.radar .plane .glyph {
  fill: var(--band);
  stroke: var(--radar-bg);
  stroke-width: 0.7;
  stroke-linejoin: round;
}

.radar .plane .rotor {
  fill: none;
  stroke: var(--band);
  stroke-width: 1.2;
  stroke-linecap: round;
}

.radar .plane .halo {
  fill: var(--band);
  fill-opacity: 0.16;
  stroke: var(--band);
  stroke-width: 1;
  opacity: 0;
  transition: opacity 0.15s;
}

.radar .plane.active .halo {
  opacity: 1;
}

.radar .plane-label {
  fill: var(--text);
  font-size: 11px;
  font-weight: 650;
  text-anchor: middle;
  paint-order: stroke;
  stroke: var(--radar-bg);
  stroke-width: 3px;
  stroke-linejoin: round;
}

/* altitude bands, shared by radar, cards, tooltip and legend */

.band-low {
  --band: var(--alt-low);
}
.band-mid {
  --band: var(--alt-mid);
}
.band-high {
  --band: var(--alt-high);
}
.band-cruise {
  --band: var(--alt-cruise);
}

.swatch {
  display: inline-block;
  flex: none;
  width: 9px;
  height: 9px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--band);
  vertical-align: 1px;
}

/* --- bottom bar --- */

.hud {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 10px 16px;
  padding: 6px 16px 16px;
}

.hud-info {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 12px;
  margin: 0;
  padding: 0;
  color: var(--muted);
  font-size: 0.78rem;
  list-style: none;
}

.status {
  color: var(--muted);
  font-size: 0.85rem;
}

.status.error {
  color: var(--danger);
}

.hud-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.radius {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 0.85rem;
}

.radius select {
  padding: 8px 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
}

.list-toggle {
  position: relative;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
}

.list-toggle svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

.list-toggle svg circle {
  fill: currentColor;
  stroke: none;
}

/* plane count, as a badge on the corner of the list button */
.list-toggle .count {
  position: absolute;
  top: -7px;
  right: -7px;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border: 2px solid var(--bg);
  border-radius: 99px;
  background: var(--text);
  color: var(--bg);
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* --- tooltip --- */

.tip {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 10;
  width: min(330px, calc(100vw - 32px));
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
  pointer-events: none;
}

/* small screens: dock the details at the bottom, over the controls; tap to dismiss */
.tip-docked .hud {
  visibility: hidden;
}

.tip.docked {
  top: auto;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  left: 16px;
  width: auto;
  pointer-events: auto;
  cursor: pointer;
}

/* --- drawer --- */

.backdrop {
  position: fixed;
  inset: 0;
  z-index: 15;
  background: rgb(5 10 20 / 0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  width: min(var(--drawer-w), 100vw);
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) 0;
  border-left: 1px solid var(--border);
  background: var(--bg);
  transform: translateX(100%);
  transition:
    transform 0.25s ease,
    box-shadow 0.25s;
}

.drawer-open .drawer {
  transform: none;
  box-shadow: var(--shadow);
}

@media (max-width: 959px) {
  .drawer-open .backdrop {
    opacity: 1;
    pointer-events: auto;
  }
}

@media (min-width: 960px) {
  .drawer-open .app {
    right: var(--drawer-w);
  }
}

.drawer-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 16px 12px;
}

.drawer-head h2 {
  font-size: 1.15rem;
}

.drawer-head p {
  font-size: 0.85rem;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  cursor: pointer;
}

.icon-btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.list {
  display: grid;
  flex: 1;
  align-content: start;
  gap: 10px;
  margin: 0;
  padding: 0 16px 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
  list-style: none;
}

.empty {
  padding: 24px 16px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}

.card {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  scroll-margin: 12px;
}

.card.active {
  border-color: var(--band);
  box-shadow: inset 0 0 0 1px var(--band);
}

.card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.drawer-foot {
  display: grid;
  gap: 10px;
  padding: 12px 16px 16px;
  border-top: 1px solid var(--border);
}

.units {
  display: inline-flex;
  justify-self: start;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}

.units button {
  padding: 5px 10px;
  border: 0;
  border-radius: 7px;
  background: none;
  color: var(--muted);
  font-size: 0.85rem;
  cursor: pointer;
}

.units button[aria-pressed='true'] {
  background: var(--surface-2);
  color: var(--text);
  font-weight: 650;
}

.credits {
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.5;
}

/* --- plane details (shared by list cards and the tooltip) --- */

.d-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.d-title {
  min-width: 0;
}

.d-head h3 {
  font-size: 1.1rem;
  line-height: 1.25;
}

.d-head .arrow {
  color: var(--muted);
}

.code {
  padding: 1px 6px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 650;
  letter-spacing: 0.03em;
  vertical-align: 2px;
}

.sub {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.86rem;
}

.badges {
  display: flex;
  flex: none;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

.badge {
  padding: 3px 8px;
  border-radius: 99px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.badge.danger {
  background: var(--danger);
  color: #fff;
}

.look {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  font-size: 0.95rem;
  font-weight: 600;
}

.look-icon {
  flex: none;
  width: 16px;
  height: 16px;
  fill: var(--band);
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 10px 0 0;
}

.stats dt {
  color: var(--muted);
  font-size: 0.68rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.stats dd {
  margin: 1px 0 0;
  font-size: 0.95rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.type {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.84rem;
}

.nowrap {
  white-space: nowrap;
}
