/* ---------- Reset & Base ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
  background: #0a0e17;
  color: #e0e6f0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* ---------- Loading Overlay ---------- */
#loading {
  position: fixed; inset: 0;
  z-index: 2000;
  display: flex; align-items: center; justify-content: center;
  background: #0a0e17;
  transition: opacity .4s;
}
#loading.fade-out { opacity: 0; pointer-events: none; }
.loader-content { text-align: center; }
.plane-icon {
  font-size: 3rem;
  animation: fly 1.5s ease-in-out infinite alternate;
}
@keyframes fly {
  0%   { transform: translateY(0) rotate(-5deg); }
  100% { transform: translateY(-18px) rotate(5deg); }
}
.loader-content p {
  margin-top: 1rem;
  font-size: .95rem;
  color: #8892a4;
}

/* ---------- App container ---------- */
#app {
  max-width: 420px;
  margin: 0 auto;
  padding: 0 1rem 2rem;
  min-height: 100vh;
}
#app.hidden { display: none; }

/* ---------- Header ---------- */
header {
  display: flex; align-items: center; justify-content: space-between;
  padding: .8rem 0;
}
header h1 {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: .03em;
  background: linear-gradient(135deg, #60a5fa, #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.header-actions {
  display: flex; gap: .5rem;
}
.header-actions button {
  width: 40px; height: 40px;
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 12px;
  background: rgba(255,255,255,.04);
  color: #8892a4;
  font-size: 1.1rem;
  cursor: pointer;
  transition: all .2s;
}
.header-actions button:active { background: rgba(255,255,255,.1); color: #e0e6f0; transform: scale(.95); }
#refresh-btn.spinning { animation: spin .6s linear; }
@keyframes spin { to { transform: rotate(360deg); } }
#ar-btn.active { background: rgba(96, 165, 250, .15); color: #60a5fa; border-color: rgba(96, 165, 250, .3); }

/* ---------- Empty state ---------- */
#empty { text-align: center; padding: 4rem 1rem; }
#empty.hidden { display: none; }
.empty-icon { font-size: 3.5rem; margin-bottom: 1rem; }
#empty p { font-size: 1.1rem; font-weight: 600; color: #e0e6f0; }
.empty-sub { font-size: .85rem; color: #64748b; font-weight: 400; margin-top: .3rem; }

/* ---------- Card ---------- */
#card {
  background: rgba(255,255,255,.04);
  border: 1px solid rgba(255,255,255,.06);
  border-radius: 16px;
  overflow: hidden;
  transition: opacity .3s;
}
#card.hidden { display: none; }
#card.updating { opacity: .6; }

/* ---------- Closest approach banner ---------- */
#overhead {
  display: flex; align-items: center; gap: .5rem;
  padding: .75rem 1rem;
  background: linear-gradient(135deg, rgba(52,211,153,.12), rgba(96,165,250,.12));
  border-bottom: 1px solid rgba(255,255,255,.06);
  font-size: .85rem;
  font-weight: 600;
}
#overhead-icon { font-size: 1rem; }
#overhead-text { color: #e0e6f0; }
#overhead.approaching #overhead-text { color: #34d399; }
#overhead.receding #overhead-text { color: #fbbf24; }
#overhead.away { display: none; }

/* ---------- Photo ---------- */
#photo-area {
  position: relative;
  width: 100%;
  height: 220px;
  background: rgba(255,255,255,.02);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
#aircraft-img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: none;
}
#aircraft-img.loaded { display: block; }
#no-photo { font-size: 4rem; opacity: .15; }
#no-photo.hidden { display: none; }
#photo-credit {
  position: absolute; bottom: .5rem; right: .6rem;
  font-size: .65rem;
  color: rgba(255,255,255,.5);
  background: rgba(0,0,0,.5);
  padding: 2px 8px;
  border-radius: 6px;
  display: none;
}
#photo-credit.visible { display: block; }

/* ---------- Card body ---------- */
#card-body { padding: 1.2rem 1.3rem 1.4rem; }
#callsign {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: .02em;
  margin-bottom: .1rem;
}
#type-info { font-size: .85rem; color: #8892a4; margin-bottom: .1rem; }
.registration {
  font-size: .8rem;
  color: #60a5fa;
  font-family: 'SF Mono', 'Fira Code', monospace;
  margin-bottom: 1.2rem;
}

/* ---------- Distance hero ---------- */
#distance-hero {
  display: flex; align-items: center; gap: .5rem;
  margin-bottom: 1.2rem;
  padding-bottom: 1.2rem;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
#distance {
  font-size: 2rem;
  font-weight: 800;
  background: linear-gradient(135deg, #34d399, #60a5fa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.distance-label {
  font-size: .9rem;
  color: #64748b;
  font-weight: 500;
}
.direction-badge {
  margin-left: auto;
  font-size: .75rem;
  font-weight: 600;
  color: #60a5fa;
  background: rgba(96,165,250,.1);
  padding: .2rem .6rem;
  border-radius: 6px;
}

/* ---------- Stats rows ---------- */
.stats-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .6rem;
  margin-bottom: .6rem;
}
.stat {
  background: rgba(255,255,255,.03);
  border-radius: 10px;
  padding: .6rem .75rem;
}
.stat-label {
  display: block;
  font-size: .65rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #64748b;
  margin-bottom: .15rem;
}
.stat-value { font-size: .95rem; font-weight: 600; }
.stat-value.mono {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: .8rem;
}

/* ---------- Map section ---------- */
#map-section { margin-top: 1rem; }
#map-section.hidden { display: none; }
#map-header {
  font-size: .8rem;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: .08em;
  margin-bottom: .5rem;
  padding-left: .2rem;
}
#map {
  width: 100%;
  height: 240px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.06);
}

/* ---------- Leaflet overrides ---------- */
.leaflet-control-attribution {
  background: rgba(10, 14, 23, .7) !important;
  color: #4a5568 !important;
  font-size: .6rem !important;
}
.leaflet-control-attribution a { color: #64748b !important; }
.leaflet-control-zoom a {
  background: rgba(10, 14, 23, .8) !important;
  color: #8892a4 !important;
  border-color: rgba(255,255,255,.08) !important;
}
.leaflet-control-zoom a:hover {
  background: rgba(10, 14, 23, .95) !important;
  color: #e0e6f0 !important;
}

/* ---------- Map marker styles ---------- */
.user-marker {
  width: 18px; height: 18px;
  border-radius: 50%;
  border: 3px solid #60a5fa;
  background: rgba(96, 165, 250, .3);
  box-shadow: 0 0 12px rgba(96, 165, 250, .4);
}
.plane-marker {
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
}
.plane-marker svg {
  width: 24px; height: 24px;
  filter: drop-shadow(0 1px 3px rgba(0,0,0,.6));
}
.approach-marker {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: #34d399;
  box-shadow: 0 0 8px rgba(52,211,153,.6);
}

/* ---------- AR Sky View ---------- */
#ar-view {
  position: fixed; inset: 0;
  z-index: 3000;
  background: #000;
}
#ar-view.hidden { display: none; }
#ar-camera {
  width: 100%; height: 100%;
  object-fit: cover;
}
#ar-overlay {
  position: absolute; inset: 0;
  pointer-events: none;
  overflow: hidden;
}
#ar-crosshair {
  position: absolute;
  top: 50%; left: 50%;
  width: 40px; height: 40px;
  transform: translate(-50%, -50%);
}
#ar-crosshair::before, #ar-crosshair::after {
  content: '';
  position: absolute;
  background: rgba(255, 255, 255, .4);
  border-radius: 1px;
}
#ar-crosshair::before {
  width: 1px; height: 100%;
  left: 50%; transform: translateX(-50%);
}
#ar-crosshair::after {
  height: 1px; width: 100%;
  top: 50%; transform: translateY(-50%);
}
#ar-compass {
  position: absolute;
  top: 1.2rem; left: 50%;
  transform: translateX(-50%);
  padding: .35rem 1rem;
  border-radius: 20px;
  background: rgba(0, 0, 0, .55);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: #e0e6f0;
  font-size: .85rem;
  font-weight: 600;
  letter-spacing: .05em;
  text-align: center;
  min-width: 80px;
}
#ar-close {
  position: absolute;
  bottom: 2rem; left: 50%;
  transform: translateX(-50%);
  width: 52px; height: 52px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,.25);
  background: rgba(0, 0, 0, .5);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: #fff;
  font-size: 1.3rem;
  cursor: pointer;
  pointer-events: auto;
  transition: all .2s;
  z-index: 10;
}
#ar-close:active { background: rgba(255,255,255,.15); transform: translateX(-50%) scale(.92); }

/* AR aircraft labels */
.ar-label {
  position: absolute;
  pointer-events: none;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  gap: .35rem;
  padding: .25rem .6rem .25rem .3rem;
  border-radius: 8px;
  background: rgba(0, 0, 0, .6);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 1px solid rgba(255, 255, 255, .12);
  white-space: nowrap;
  transition: opacity .15s;
}
.ar-icon {
  flex-shrink: 0;
  width: 20px; height: 20px;
  display: flex; align-items: center; justify-content: center;
}
.ar-icon svg {
  filter: drop-shadow(0 0 4px rgba(255,255,255,.3));
}
.ar-info {
  display: flex; flex-direction: column;
  line-height: 1.2;
}
.ar-callsign {
  font-size: .8rem;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0,0,0,.8);
}
.ar-details {
  font-size: .6rem;
  color: rgba(255,255,255,.65);
  text-shadow: 0 1px 2px rgba(0,0,0,.8);
}

/* ---------- Footer ---------- */
footer { text-align: center; padding: 1rem 0 .5rem; }
#updated { font-size: .75rem; color: #4a5568; }

/* ---------- Toast ---------- */
#toast {
  position: fixed;
  bottom: 1.5rem; left: 50%; transform: translateX(-50%);
  z-index: 1500;
  max-width: 90vw;
  padding: .6rem 1.2rem;
  border-radius: 10px;
  background: rgba(248, 113, 113, .9);
  backdrop-filter: blur(8px);
  font-size: .85rem;
  color: #fff;
  transition: opacity .3s;
}
#toast.hidden { opacity: 0; pointer-events: none; }

/* ---------- Mobile ---------- */
@media (max-width: 480px) {
  #app { padding: 0 .75rem 2rem; }
  #photo-area { height: 180px; }
  #callsign { font-size: 1.25rem; }
  #distance { font-size: 1.7rem; }
  #map { height: 200px; }
}
