:root {
  --bg: #0b0f17;
  --panel: rgba(16, 22, 34, 0.92);
  --panel-border: rgba(80, 160, 220, 0.25);
  --accent: #2fe6a0;
  --accent-dim: #1f9d6e;
  --text: #e7eef7;
  --muted: #8da2bd;
  --radar-green: #28e07a;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ---------- Top bar ---------- */
#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 16px;
  /* Clear the iPhone status bar / notch when launched full-screen. */
  padding-top: calc(10px + env(safe-area-inset-top));
  padding-left: calc(16px + env(safe-area-inset-left));
  padding-right: calc(16px + env(safe-area-inset-right));
  background: linear-gradient(180deg, #0e1626, #0b0f17);
  border-bottom: 1px solid var(--panel-border);
  z-index: 1000;
}

.brand {
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.3px;
}
.brand .logo {
  color: var(--accent);
  margin-right: 6px;
}

.topbar-status {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--muted);
}
.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #777;
  display: inline-block;
}
.dot.live {
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
}
.dot.error {
  background: #ff5b6e;
  box-shadow: 0 0 8px #ff5b6e;
}
.count {
  background: rgba(47, 230, 160, 0.12);
  color: var(--accent);
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 600;
}

.topbar-search {
  display: flex;
  align-items: center;
  gap: 6px;
}
.topbar-search input {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  color: var(--text);
  padding: 6px 10px;
  font-size: 13px;
  width: 170px;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}
.topbar-search input::placeholder {
  color: var(--muted);
}
.topbar-search input:focus {
  border-color: var(--accent-dim);
  background: rgba(255, 255, 255, 0.1);
}

.topbar-actions button,
.modal button {
  background: rgba(47, 230, 160, 0.12);
  color: var(--accent);
  border: 1px solid var(--panel-border);
  padding: 7px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}
.topbar-actions button:hover,
.modal button:hover {
  background: rgba(47, 230, 160, 0.22);
}

main {
  position: relative;
  flex: 1;
}

#map {
  position: absolute;
  inset: 0;
  background: #0b0f17;
}

/* ---------- Floating panels ---------- */
.floating {
  position: absolute;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(6px);
  z-index: 800;
}

#radar-panel {
  bottom: 18px;
  left: 18px;
  padding: 10px;
}
.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  letter-spacing: 1.5px;
  color: var(--muted);
  margin-bottom: 6px;
  font-weight: 700;
}
.panel-hide {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
  letter-spacing: 0;
}
.panel-hide:hover {
  color: var(--text);
}
.topbar-actions button.active {
  background: rgba(47, 230, 160, 0.28);
  border-color: var(--accent);
}
#radar {
  display: block;
  border-radius: 50%;
}

/* ---------- Detail panel ---------- */
#detail-panel {
  top: 18px;
  right: 18px;
  width: 320px;
  max-width: calc(100vw - 36px);
  padding: 16px;
}
.close {
  position: absolute;
  top: 8px;
  right: 10px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 22px;
  cursor: pointer;
  line-height: 1;
}
.close:hover {
  color: var(--text);
}

.detail-callsign {
  font-size: 22px;
  font-weight: 700;
  color: var(--accent);
}
.detail-sub {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 12px;
}

.route {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 12px 0;
}
.route .ap {
  flex: 1;
  min-width: 0;
}
.route .code {
  font-size: 20px;
  font-weight: 700;
}
.route .name {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.route .arrow {
  color: var(--accent);
  font-size: 18px;
  flex: 0 0 auto;
}
.route .ap.dest {
  text-align: right;
}

.fit-route {
  width: 100%;
  margin-top: 4px;
  background: rgba(91, 200, 255, 0.12);
  color: #9ad0ff;
  border: 1px solid rgba(91, 200, 255, 0.35);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.fit-route:hover {
  background: rgba(91, 200, 255, 0.22);
}

/* Origin / destination pins on the map */
.airport-marker {
  display: inline-block;
  transform: translate(-50%, -50%);
  background: #0c121e;
  border: 1px solid #5bc8ff;
  color: #cfeaff;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 2px 6px;
  border-radius: 6px;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}
.airport-marker.destination {
  border-color: #ffe14d;
  color: #fff3b0;
}

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 12px;
  margin-top: 14px;
}
.stat {
  background: rgba(255, 255, 255, 0.04);
  border-radius: 8px;
  padding: 8px 10px;
}
.stat .label {
  font-size: 10px;
  letter-spacing: 0.5px;
  color: var(--muted);
  text-transform: uppercase;
}
.stat .value {
  font-size: 16px;
  font-weight: 700;
  margin-top: 2px;
}
.muted-note {
  font-size: 11px;
  color: var(--muted);
  margin-top: 12px;
}

/* ---------- Modal ---------- */
.modal {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}
.modal-card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 22px;
  width: 320px;
  max-width: calc(100vw - 32px);
}
.modal-card h2 {
  margin: 0 0 14px;
  font-size: 18px;
}
.modal-card label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 12px;
}
.modal-card input {
  width: 100%;
  margin-top: 5px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--panel-border);
  background: #0c121e;
  color: var(--text);
  font-size: 14px;
}
.modal-actions {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 8px;
}
.modal button.ghost {
  background: transparent;
}

/* ---------- Plane markers ---------- */
.plane-icon {
  width: 24px;
  height: 24px;
  line-height: 0;
  transition: transform 0.4s linear;
  filter: drop-shadow(0 0 3px rgba(0, 0, 0, 0.8));
  cursor: pointer;
}
.plane-icon svg {
  display: block;
}
.plane-icon.selected {
  filter: drop-shadow(0 0 6px var(--accent));
}
.home-icon {
  font-size: 24px;
}

.hidden {
  display: none !important;
}

/* ---------- Compact icon toggles ---------- */
#topbar {
  flex-wrap: wrap;
}
.icon-btn {
  min-width: 38px;
  padding: 7px 9px !important;
  font-size: 15px !important;
}
.topbar-actions {
  display: flex;
  gap: 8px;
}

/* ---------- Detail panel polish ---------- */
#detail-panel {
  max-height: calc(100vh - 36px);
  overflow-y: auto;
}
.detail-head {
  margin-bottom: 12px;
}
.detail-airline {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-top: 1px;
}
.detail-callsign {
  background: linear-gradient(90deg, var(--accent), #7dff8a);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* Aircraft photo */
.photo {
  display: block;
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  margin: 4px 0 12px;
  border: 1px solid var(--panel-border);
  line-height: 0;
}
.photo img {
  width: 100%;
  height: 150px;
  object-fit: cover;
  display: block;
}
.photo-credit {
  position: absolute;
  bottom: 0;
  right: 0;
  font-size: 9px;
  color: #dfe9f5;
  background: rgba(0, 0, 0, 0.55);
  padding: 2px 6px;
  border-top-left-radius: 6px;
  line-height: 1.4;
}

/* Route progress bar */
.progress {
  position: relative;
  height: 4px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.12);
  margin: 14px 0 6px;
}
.progress-fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--accent-dim), var(--accent));
  transition: width 0.6s ease;
}
.progress-plane {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%) rotate(90deg);
  font-size: 13px;
  color: #fff;
  text-shadow: 0 0 4px var(--accent);
  transition: left 0.6s ease;
}
.route-meta {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--muted);
}

/* Flight phase colors */
.value.phase-climbing { color: #7dff8a; }
.value.phase-descending { color: #ff9d3b; }
.value.phase-cruising { color: #5bc8ff; }
.value.phase-onground { color: var(--muted); }

/* Clickable airports in the route row */
.ap-zoom {
  cursor: pointer;
  transition: opacity 0.15s;
}
.ap-zoom:hover { opacity: 0.72; }
.ap-zoom:hover .code { text-decoration: underline; text-underline-offset: 3px; }

/* Schedule times (AeroDataBox) */
.sched {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 6px 0 2px;
  padding: 5px 10px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
}
.sched-times {
  display: flex;
  align-items: center;
  gap: 8px;
}
.sched-sep {
  color: var(--muted);
  font-size: 11px;
  font-weight: 400;
}
.sched-delay {
  font-size: 11px;
  font-weight: 600;
  color: #ff9d3b;
}

/* Altitude profile chart */
.alt-chart {
  margin: 12px 0 4px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid rgba(47, 230, 160, 0.15);
  background: rgba(47, 230, 160, 0.03);
}
.alt-axis {
  display: flex;
  justify-content: space-between;
  padding: 3px 8px 4px;
  font-size: 10px;
  color: var(--muted);
}
.alt-axis-title {
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ---------- Ceiling / projector mode (?ceiling) ---------- */
.ceiling-mode {
  /* Flip 180° so a face-up projector shows the right orientation on the ceiling */
  transform: rotate(180deg);
  transform-origin: center center;
}
/* Hide all interactive chrome — this is a passive ambient display */
.ceiling-mode #topbar,
.ceiling-mode #detail-panel,
.ceiling-mode #settings-modal { display: none !important; }

/* Radar: reposition to bottom-left in DOM = top-right visually after flip.
   Keep it visible but make it slightly smaller so the map breathes. */
.ceiling-mode #radar-panel {
  bottom: 24px;
  left: 24px;
  right: auto;
  top: auto;
  opacity: 0.85;
}
.ceiling-mode #radar { width: 220px; height: 220px; }

/* Always-visible flight labels */
.plane-label {
  display: none; /* hidden in normal mode */
}
.ceiling-mode .plane-label {
  display: block;
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-top: 3px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.4px;
  white-space: nowrap;
  text-shadow: 0 0 6px #000, 0 0 3px #000;
  pointer-events: none;
}
/* The wrap needs relative positioning for the label to anchor to */
.plane-icon-wrap { position: relative !important; overflow: visible !important; }

@media (max-width: 640px) {
  .topbar-search { display: none; }
  #detail-panel {
    top: auto;
    bottom: 18px;
    right: 18px;
    left: 18px;
    width: auto;
  }
  #radar-panel {
    transform: scale(0.8);
    transform-origin: bottom left;
  }
}
