/* ── Custom properties ── */
:root {
  --bg: #0a0e1a;
  --surface: #111827;
  --surface2: #1a2235;
  --border: #1e2d4a;
  --accent: #3b82f6;
  --accent-dim: rgba(59, 130, 246, 0.15);
  --green: #22c55e;
  --yellow: #eab308;
  --red: #ef4444;
  --text: #e2e8f0;
  --text-muted: #64748b;
  --text-dim: #94a3b8;
  --radius: 16px;
  --card-pad-h: 48px;
  --transition: 0.45s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, sans-serif;
  overflow: hidden;
}

/* ── Layout ── */
body {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* ── Header ── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 10;
}
.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}
.header-icon {
  font-size: 1.25rem;
}
.header-title {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--accent);
  text-transform: uppercase;
}
.header-right {
  display: flex;
  align-items: center;
  gap: 14px;
}
.header-clock {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.9rem;
  color: var(--text-dim);
  letter-spacing: 0.05em;
}

/* ── Icon buttons ── */
.icon-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  transition: color 0.2s, background 0.2s;
  line-height: 1;
}
.icon-btn:hover { color: var(--text); background: var(--surface2); }

/* ── Main ── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

/* ── State screens ── */
.state-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  text-align: center;
  padding: 20px;
}
.state-msg {
  font-size: 1rem;
  color: var(--text-dim);
  max-width: 300px;
}
.state-sub {
  font-size: 0.85rem;
  color: var(--text-muted);
}
.state-icon {
  font-size: 2.5rem;
  color: var(--yellow);
}

/* ── Spinner ── */
.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Empty GIF ── */
.empty-gif {
  width: min(280px, 80vw);
  border-radius: var(--radius);
  object-fit: cover;
}
.empty-caption {
  font-size: 1rem;
  color: var(--text-dim);
}

/* ── Primary button ── */
.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 10px 24px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
}
.btn-primary:hover { opacity: 0.85; }

/* ── Flights container ── */
.flights-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  min-height: 0;
}

/* ── Card viewport ── */
.card-viewport {
  flex: 1;
  position: relative;
  overflow: hidden;
  min-height: 0;
}

/* ── Flight card ── */
.flight-card {
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  padding: 0;
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform var(--transition);
  will-change: transform;
  overflow: hidden;
}
.flight-card.active {
  transform: translateX(0);
}
.flight-card.exit-left  { transform: translateX(-100%); }
.flight-card.exit-right { transform: translateX(100%); }

/* ── Card backdrop layers ── */
.card-bg {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  isolation: isolate; /* contain Leaflet's z-indexes so they don't beat .card-content */
}

/* Large airline logo — top-left corner, above the overlay, fades toward center */
.card-bg-logo { display: none; }

/* Sky gradient — set via JS based on time of day, bleeds from bottom-right */
.card-bg-sky {
  position: absolute;
  inset: 0;
}

/* Diagonal dark overlay: opaque top-left for text, transparent bottom-right for sky */
.card-bg-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    to bottom right,
    rgba(10, 14, 26, 0.96) 0%,
    rgba(10, 14, 26, 0.82) 30%,
    rgba(10, 14, 26, 0.50) 58%,
    rgba(10, 14, 26, 0.18) 100%
  );
}

/* ── Flight map (bottom-right backdrop) ── */
.card-map {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 55%;
  height: 55%;
  pointer-events: none;
  /* Anchor gradient at bottom-right corner; plane sits at 70.7% — solid stop at 80% */
  -webkit-mask-image: radial-gradient(ellipse 100% 100% at 100% 100%, black 0%, black 80%, transparent 100%);
  mask-image:         radial-gradient(ellipse 100% 100% at 100% 100%, black 0%, black 80%, transparent 100%);
}
/* Suppress Leaflet's default background flash */
.card-map .leaflet-container {
  width: 100%;
  height: 100%;
  background: transparent;
}
/* Strip Leaflet's default white-box background from our custom marker */
.leaflet-plane-marker {
  background: none !important;
  border: none !important;
}

/* ── Card content (sits above backdrop) ── */
.card-content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  padding: 40px var(--card-pad-h) 0;
}

/* Card header */
.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 4px;
}
.card-airline {
  display: flex;
  align-items: center;
  gap: 10px;
}
.airline-logo {
  width: 64px;
  height: 64px;
  object-fit: contain;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
  padding: 4px;
}
.airline-name {
  font-size: 2rem;
  font-weight: 500;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.country-flag {
  font-size: 2.2rem;
}
.card-callsign {
  font-family: 'JetBrains Mono', monospace;
  font-size: 7.2rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.02em;
  line-height: 1;
  text-shadow: 0 2px 16px rgba(0, 0, 0, 0.6);
}

/* Route row */
.card-route {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 16px 0 4px;
}
.route-airport {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.route-origin { align-items: flex-start; }
.route-dest   { align-items: flex-end; text-align: right; }
.route-iata {
  font-family: 'JetBrains Mono', monospace;
  font-size: 5.6rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.04em;
  line-height: 1;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.5);
}
.route-city {
  font-size: 1.7rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}
.route-line {
  flex: 1;
  position: relative;
  height: 2px;
  background: var(--border);
  min-width: 60px;
  margin: 0 10px;
  align-self: center;
}
/* Flown portion of the route */
.route-line::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: calc(var(--progress, 0.5) * 100%);
  background: var(--accent);
  transition: width 1s ease;
}
.route-plane {
  position: absolute;
  top: 50%;
  left: calc(var(--progress, 0.5) * 100%);
  transform: translate(-50%, -50%);
  font-size: 2rem;
  color: var(--accent);
  transition: left 1s ease;
  filter: drop-shadow(0 0 6px rgba(59,130,246,0.7));
}

/* Divider */
.card-divider {
  height: 1px;
  background: var(--border);
  margin: 16px 0;
}

/* Stats */
.card-stats {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
  min-height: 0;
}
.stat-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.stat-row-single {
  grid-template-columns: 1fr;
}
.stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stat-icon {
  font-size: 1.6rem;
  color: var(--text-muted);
  width: 2rem;
  display: inline-block;
}
.stat-label {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.stat-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 3rem;
  font-weight: 600;
  color: var(--text);
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.4);
}

/* Progress bar — bleeds to card edges, compensating for card-content padding */
.card-footer-bar {
  margin: auto calc(-1 * var(--card-pad-h)) 0;
  flex-shrink: 0;
}
.progress-track {
  height: 3px;
  background: var(--border);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 100%;
  background: var(--accent);
  transform-origin: left;
  transform: scaleX(1);
  transition: transform linear;
}

/* ── Carousel nav ── */
.carousel-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 14px 20px;
  flex-shrink: 0;
}
.nav-arrow {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 1.1rem;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.nav-arrow:hover {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}
.dot-track {
  display: flex;
  align-items: center;
  gap: 8px;
}
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border);
  cursor: pointer;
  transition: background 0.25s, transform 0.25s;
}
.dot.active {
  background: var(--accent);
  transform: scale(1.35);
}

/* ── Footer ── */
.footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 10px 20px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.footer-text {
  font-size: 0.78rem;
  color: var(--text-muted);
}
.footer-refresh {
  font-size: 1rem;
}

/* ── Settings overlay ── */
.settings-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: stretch;
  justify-content: flex-end;
  backdrop-filter: blur(4px);
}
.settings-panel {
  background: var(--surface);
  border-left: 1px solid var(--border);
  width: min(320px, 100vw);
  display: flex;
  flex-direction: column;
  animation: slide-in-right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
@keyframes slide-in-right {
  from { transform: translateX(100%); }
  to   { transform: translateX(0); }
}
.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}
.settings-body {
  flex: 1;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  overflow-y: auto;
}
.settings-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 10px;
  border: none;
  padding: 0;
}
.slider-row {
  display: flex;
  align-items: center;
  gap: 14px;
}
input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
  height: 4px;
  cursor: pointer;
}
.slider-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.9rem;
  color: var(--accent);
  min-width: 52px;
  text-align: right;
}
.settings-fieldset {
  border: none;
  padding: 0;
}
.radio-label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
  color: var(--text-dim);
  padding: 8px 0;
  cursor: pointer;
  transition: color 0.15s;
}
.radio-label:hover { color: var(--text); }
.radio-label input[type="radio"] { accent-color: var(--accent); width: 16px; height: 16px; }
.settings-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}
.settings-footer .btn-primary {
  width: 100%;
}

/* ── Utility ── */
.hidden { display: none !important; }

/* ── Responsive ── */
@media (max-width: 639px) {
  :root { --card-pad-h: 20px; }
  .header-title { font-size: 0.75rem; }
  .card-callsign { font-size: 4.8rem; }
  .route-iata { font-size: 3.6rem; }
  .stat-value { font-size: 2.2rem; }
  .stat-label { font-size: 1.1rem; }
  .airline-name { font-size: 1.4rem; }
  .route-city { font-size: 1.1rem; }
  .card-content { padding-top: 24px; }

  .airline-logo { width: 48px; height: 48px; }
  .carousel-nav { gap: 12px; padding: 10px; }
  .nav-arrow { width: 36px; height: 36px; }
}

@media (min-width: 640px) and (max-width: 1023px) {
  :root { --card-pad-h: 36px; }
  .card-callsign { font-size: 6rem; }
  .route-iata { font-size: 4.4rem; }
  .stat-value { font-size: 2.6rem; }
  .stat-label { font-size: 1.3rem; }
}

@media (min-width: 1024px) {
  :root { --card-pad-h: 64px; }
  .card-callsign { font-size: 9rem; }
  .route-iata { font-size: 6.4rem; }
  .stat-value { font-size: 3.4rem; }
  .stat-label { font-size: 1.6rem; }
  .route-city { font-size: 2rem; max-width: 280px; }
}
