:root {
  --bg: #0a0e14;
  --bg-card: #131922;
  --bg-card-2: #1a212d;
  --border: #232a36;
  --fg: #e8edf2;
  --fg-dim: #8a96a8;
  --fg-faint: #5a6678;
  --accent: #4ec3ff;
  --warn: #ffb347;
  --hot: #ff5b5b;
  --green: #6dd97a;
  --gold: #ffd24a;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Inter", sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100%;
  -webkit-overflow-scrolling: touch;
}
body {
  display: flex; flex-direction: column;
  height: 100vh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #131922, #0a0e14);
  flex-shrink: 0;
}
.brand { display: flex; align-items: baseline; gap: 14px; }
.brand .logo {
  width: 34px; height: 34px; display: inline-block; vertical-align: middle;
  filter: drop-shadow(0 1px 3px rgba(0,0,0,.6));
  margin-right: 8px; /* gap fallback */
}
.brand h1 {
  margin: 0 14px 0 0; /* gap fallback */
  font-size: 22px; font-weight: 600;
  letter-spacing: 0.5px;
}
.brand .subtitle {
  font-size: 13px; color: var(--fg-dim);
  font-weight: 400;
}
.meta {
  display: flex; align-items: center; gap: 12px;
  font-size: 13px; color: var(--fg-dim);
  font-variant-numeric: tabular-nums;
}
.meta .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
  animation: pulse 2s ease-in-out infinite;
}
.stats-btn {
  display: inline-block; text-decoration: none;
  background: var(--bg-card-2); border: 1px solid var(--accent);
  color: var(--accent); font-weight: 600; font-size: 13px;
  padding: 6px 14px; border-radius: 999px; white-space: nowrap;
  transition: background .15s, color .15s;
}
.stats-btn:hover, .stats-btn:active { background: var(--accent); color: #08121a; }
/* tab navigation bar */
.tabs {
  flex-shrink: 0; white-space: nowrap; overflow-x: auto;
  background: #0f141c; border-bottom: 1px solid var(--border); padding: 0 16px;
}
.tabs a {
  display: inline-block; padding: 9px 18px; font-size: 14px; font-weight: 600;
  color: var(--fg-dim); border-bottom: 2px solid transparent; text-decoration: none;
}
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); }
.tabs a:hover { color: var(--fg); }
@keyframes pulse {
  0%,100% { opacity: 1; }
  50% { opacity: 0.4; }
}

main {
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: 1fr 1fr 1fr;
  align-items: stretch; /* was: start — let cards stretch to equal column height */
  grid-gap: 12px; gap: 12px;
  padding: 12px 24px;
}

/* Card is itself a grid: photo + body. Body is a grid with locked rows.
   Grid track sizes are definite; child overflow does NOT push tracks (unlike flex). */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  display: grid;
  grid-template-rows: 150px 1fr; /* photo, then body fills */
  transition: border-color 0.4s ease;
  overflow: hidden; /* clip any rogue overflow rather than expand */
}
.card.fresh {
  animation: cardFresh 1s ease-in-out 3;
  border-color: var(--accent);
}
@keyframes cardFresh {
  0%, 100% {
    border-color: var(--border);
    box-shadow: 0 0 0 0 rgba(78,195,255,0);
  }
  50% {
    border-color: var(--accent);
    box-shadow: 0 0 22px 3px rgba(78,195,255,.6);
  }
}

.photo {
  position: relative;
  height: 150px; /* fixed across all cards — both real photos and SVG placeholders render at this height */
  background: #060a10 center/cover no-repeat;
  border-bottom: 1px solid var(--border);
  border-radius: 10px 10px 0 0;
  flex-shrink: 0;
  overflow: hidden;
}
.photo.photo-placeholder svg { width: 100%; height: 100%; display: block; }
.photo .photo-credit {
  position: absolute; bottom: 4px; right: 6px;
  font-size: 10px; color: rgba(255,255,255,.45);
  text-shadow: 0 0 4px black;
}
.photo .no-photo {
  display: flex; align-items: center; justify-content: center;
  height: 100%; color: var(--fg-faint); font-size: 14px;
}
.photo.photo-placeholder { background: #0a0e14; }

/* Photo overlay pills */
.cat-pill, .phase-pill {
  position: absolute;
  font-size: 10px; font-weight: 700; letter-spacing: 0.6px;
  padding: 3px 8px; border-radius: 999px;
  text-transform: uppercase;
  background: rgba(10,14,20,.78);
  border: 1px solid rgba(255,255,255,.14);
  color: var(--fg);
  text-shadow: 0 0 4px black;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.cat-pill { top: 6px; left: 6px; color: var(--fg-dim); }
.phase-pill { top: 6px; right: 6px; }
.phase-pill.phase-up { background: rgba(78,195,255,.22); border-color: rgba(78,195,255,.55); color: var(--accent); }
.phase-pill.phase-cruise { background: rgba(109,217,122,.18); border-color: rgba(109,217,122,.45); color: var(--green); }
.phase-pill.phase-down { background: rgba(255,179,71,.22); border-color: rgba(255,179,71,.55); color: var(--warn); }
.phase-pill.phase-ground { background: rgba(138,150,168,.2); border-color: rgba(138,150,168,.5); color: var(--fg-dim); }
/* Frontier tail mascot (curated). Bottom-left so it never collides with the
   bottom-right photo credit; clips with ellipsis on long animal names. */
.mascot-pill {
  position: absolute;
  bottom: 6px; left: 6px;
  max-width: calc(100% - 12px);
  font-size: 10px; font-weight: 700; letter-spacing: 0.4px;
  padding: 3px 8px; border-radius: 999px;
  background: rgba(10,30,18,.82);
  border: 1px solid rgba(109,217,122,.55);
  color: var(--green);
  text-shadow: 0 0 4px black;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

/* CSS Grid lock: every row is a definite track. iOS 14+ Grid + grid-gap is rock-solid.
   Rows: title(34) hero(130) route(84) progress(52) stats(120) navmodes(20) aircraft(20).
   gap=10px ×6 = 60. Plus padding 14+16 = 30. Body: 460 + 60 + 30 = 550. Card: 150+550 = 700. */
.card-body {
  padding: 14px 18px 16px;
  display: grid;
  grid-template-rows: 34px 130px 84px 52px 120px 20px 20px;
  grid-row-gap: 10px;
  gap: 10px;
  min-height: 0;
}
/* All direct children of card-body must clip, not expand, their grid track */
.card-body > * { min-height: 0; min-width: 0; overflow: hidden; }

.title-row {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: 12px;
  flex-wrap: nowrap;
  height: 34px;
  box-sizing: border-box;
}
.title-row .callsign, .title-row .airline-line { min-width: 0; }
.title-row .callsign { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.title-row .airline-line { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.callsign {
  font-size: 30px; font-weight: 700; letter-spacing: 1.5px;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.airline-line {
  font-size: 14px; color: var(--fg-dim);
  display: flex; align-items: baseline; gap: 8px;
  text-align: right;
}
.airline-line .airline { color: var(--fg); font-weight: 500; }
.airline-line .flag { font-size: 18px; }
.airline-line.empty .airline { color: var(--fg-faint); font-style: italic; font-weight: 400; }
.aircraft-row.empty { opacity: 0.55; font-style: italic; }
.aircraft-row .reg.empty { background: transparent; color: var(--fg-faint); }

/* AeroAPI-only enrichments */
.status-badge {
  font-size: 9px; font-weight: 700;
  padding: 2px 6px; border-radius: 999px;
  letter-spacing: 0.6px; text-transform: uppercase;
  border: 1px solid var(--border);
  white-space: nowrap;
}
.status-badge.status-warn { background: rgba(255,179,71,.18); border-color: rgba(255,179,71,.55); color: var(--warn); }
.status-badge.status-bad { background: rgba(255,91,91,.18); border-color: rgba(255,91,91,.55); color: var(--hot); }
.delay-tag {
  font-size: 11px; font-weight: 600;
  font-variant-numeric: tabular-nums;
  margin-left: 4px;
}
.delay-tag.delay-late { color: var(--warn); }
.delay-tag.delay-early { color: var(--green); }
.progress-eta .aloft { color: var(--fg-dim); font-weight: 400; margin-left: 2px; }

/* Headwind / tailwind tag in the hero-sub line */
.hero-sub .wind-comp {
  font-size: 13px; font-weight: 500;
  font-variant-numeric: tabular-nums;
  margin-left: 4px;
}
.hero-sub .wind-comp.wind-head { color: var(--warn); }
.hero-sub .wind-comp.wind-tail { color: var(--green); }

/* Nav-modes pill row sits in its own grid track below the stats table. */
.nav-modes {
  display: flex; flex-wrap: nowrap; gap: 4px;
  justify-content: center; align-items: center;
  height: 20px;
  overflow: hidden;
}
.nav-modes.filed {
  display: block; height: 20px; line-height: 20px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-size: 11px; color: var(--accent); text-align: center;
  font-variant-numeric: tabular-nums;
}
.wake-tag {
  font-size: 10px; font-weight: 700; letter-spacing: 0.5px;
  padding: 1px 6px; border-radius: 4px;
  background: rgba(255,179,71,.18); border: 1px solid rgba(255,179,71,.5); color: var(--warn);
}
.wake-tag.super { background: rgba(255,91,91,.18); border-color: rgba(255,91,91,.5); color: var(--hot); }
.filed-tag { font-size: 10px; color: var(--green); font-weight: 600; }
/* route source badge — where each route came from (debug/visibility) */
.src-tag {
  font-size: 9px; font-weight: 700; letter-spacing: .3px; flex-shrink: 0;
  padding: 1px 5px; border-radius: 4px;
  background: rgba(0,0,0,.35); border: 1px solid var(--border);
}
.src-tag.src-swim    { color: var(--green);  border-color: rgba(109,217,122,.55); background: rgba(10,30,18,.6); }
.src-tag.src-adsbdb  { color: var(--accent); border-color: rgba(78,195,255,.5); }
.src-tag.src-hexdb   { color: var(--fg-dim); }
.src-tag.src-aeroapi { color: var(--gold);   border-color: rgba(255,210,74,.55); }
/* IFR/VFR flight-rules badge */
.rules-tag { font-size: 9px; font-weight: 700; letter-spacing: .5px; padding: 1px 5px; border-radius: 4px; }
.rules-tag.rules-ifr { background: rgba(78,195,255,.15); border: 1px solid rgba(78,195,255,.5); color: var(--accent); }
.rules-tag.rules-vfr { background: rgba(109,217,122,.15); border: 1px solid rgba(109,217,122,.5); color: var(--green); }
.nav-modes .nav-mode {
  font-size: 9px; font-weight: 700;
  letter-spacing: 0.6px; text-transform: uppercase;
  padding: 2px 6px; border-radius: 999px;
  background: rgba(78,195,255,.12);
  border: 1px solid rgba(78,195,255,.4);
  color: var(--accent);
  white-space: nowrap;
}
.nav-modes .nav-mode.dim {
  background: transparent;
  border-color: var(--border);
  color: var(--fg-faint);
  font-style: italic;
  letter-spacing: 0.3px;
}

.hero {
  display: flex; align-items: center; gap: 18px;
  padding: 14px 6px;
  height: 130px;
  box-sizing: border-box;
}
.dir-arrow-big {
  width: 100px; height: 100px;
  transition: transform 0.6s cubic-bezier(.4,0,.2,1);
  filter: drop-shadow(0 0 8px rgba(255,210,74,.35));
  flex-shrink: 0;
}
.hero-stack {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; gap: 2px;
}
.hero-alt {
  display: flex; align-items: baseline; gap: 4px;
  line-height: 1;
}
.alt-num {
  font-size: 48px; font-weight: 800;
  color: var(--fg);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.5px;
  line-height: 1;
}
.alt-unit {
  font-size: 18px; font-weight: 500;
  color: var(--fg-dim);
  margin-left: 6px;
}
.hero-sub {
  display: flex; gap: 14px; align-items: baseline;
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
}
.dist-val {
  font-size: 22px; font-weight: 600;
  color: var(--gold);
}
.dist-val .unit { font-size: 13px; color: var(--fg-dim); margin-left: 2px; }
.hero-sub .vr {
  font-size: 16px; color: var(--fg-dim); font-weight: 500;
}
.hero-sub .vr.warn { color: var(--warn); }
.hero-sub .vr.hot { color: var(--hot); }

.cpa {
  margin-top: 6px;
  display: flex; align-items: baseline;
  gap: 6px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cpa .cpa-label { font-weight: 600; }
.cpa .cpa-sep { color: var(--fg-faint); }
.cpa .cpa-detail { color: var(--fg-dim); font-size: 12px; }
.cpa.cpa-future .cpa-label { color: var(--accent); }
.cpa.cpa-now .cpa-label {
  color: var(--gold);
  text-shadow: 0 0 8px rgba(255,210,74,.5);
  animation: cpaPulse 1.4s ease-in-out infinite;
}
.cpa.cpa-past .cpa-label { color: var(--fg-faint); }
@keyframes cpaPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

.route {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px;
  background: var(--bg-card-2);
  border-radius: 8px; border: 1px solid var(--border);
  height: 84px;
  box-sizing: border-box;
}
.route .city {
  flex: 1; min-width: 0;
}
.route .iata {
  font-size: 36px; font-weight: 800; letter-spacing: 2px;
  color: var(--fg);
  line-height: 1;
}
.route .city-name {
  font-size: 12px; color: var(--fg-dim);
  margin-top: 4px;
  display: flex; align-items: baseline; gap: 4px;
  min-width: 0;
}
.route .city-name .city-text {
  flex: 1 1 auto; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.route .city-name .delay-tag {
  flex: 0 0 auto;  /* don't shrink — protect delay from truncation */
  white-space: nowrap;
}
.route .city.dest .city-name { justify-content: flex-end; }
.route .city.dest { text-align: right; }
.route .arrow {
  color: var(--accent); font-size: 28px;
  flex-shrink: 0;
  filter: drop-shadow(0 0 4px rgba(78,195,255,.4));
}
.route .city-flag { font-size: 18px; vertical-align: middle; }
.route.empty { opacity: 0.35; }
.route.empty .iata, .route.empty .city-name, .route.empty .arrow { color: var(--fg-faint); }
.progress.empty { opacity: 0.35; }
.progress.empty .progress-bar { background: var(--bg-card-2); }
.progress .empty-line { color: var(--fg-faint); }

.progress {
  display: flex; flex-direction: column; gap: 4px;
  font-variant-numeric: tabular-nums;
  height: 52px;
  box-sizing: border-box;
}
.progress-bar {
  position: relative;
  height: 6px;
  background: var(--bg-card-2);
  border-radius: 4px;
  border: 1px solid var(--border);
  overflow: hidden;
}
.progress-fill {
  position: absolute; left: 0; top: 0; bottom: 0;
  background: linear-gradient(90deg, rgba(78,195,255,.55), var(--accent));
  border-radius: 4px;
  transition: width 0.6s ease;
}
.progress-tick {
  position: absolute; top: -3px; bottom: -3px;
  width: 2px;
  background: var(--gold);
  box-shadow: 0 0 6px rgba(255,210,74,.7);
  transform: translateX(-1px);
  transition: left 0.6s ease;
}
.progress-stats {
  display: flex; justify-content: space-between; gap: 8px;
  font-size: 11px;
  color: var(--fg-dim);
}
.progress-stats .prog-pct {
  color: var(--accent);
  font-weight: 600;
}
.progress-eta {
  font-size: 12px;
  color: var(--fg);
  font-weight: 500;
}
.progress-eta .eta-dur {
  color: var(--fg-dim); font-weight: 400; margin-left: 4px;
}

.stat-strip {
  width: 100%;
  height: 120px; /* match grid track; table-layout:fixed + explicit height = stable rows on iOS 14 */
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  table-layout: fixed;
}
.stat-strip td {
  padding: 4px 4px;
  border-bottom: 1px solid rgba(35,42,54,.6);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stat-strip tr:last-child td { border-bottom: 0; }
.stat-strip td.k {
  color: var(--fg-dim);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  text-align: right;
  width: 26%;
  font-weight: 500;
}
.stat-strip td.v {
  color: var(--fg);
  font-weight: 500;
  width: 24%;
  text-align: left;
}
.stat-strip td.v.dim { color: var(--fg-faint); }
.stat-strip td.v.warn { color: var(--warn); }
.stat-strip td.v.hot { color: var(--hot); font-weight: 700; }
.stat-strip .sq-note {
  font-size: 9px;
  color: var(--fg-dim);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-left: 4px;
}

.aircraft-row {
  font-size: 12px; color: var(--fg-dim);
  display: flex; gap: 8px;
  flex-wrap: nowrap;        /* was wrap — wrapping caused row-2 overflow drift */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  height: 20px; line-height: 20px;
}
.aircraft-row .reg {
  font-family: "SF Mono", Monaco, monospace;
  color: var(--fg);
  background: var(--bg-card-2);
  padding: 1px 6px; border-radius: 3px;
}
.aircraft-row .type { color: var(--fg); }
.aircraft-row .owner { font-style: italic; }
.aircraft-row .flag { font-size: 14px; }

.empty {
  display: flex; align-items: center; justify-content: center;
  height: 100%; color: var(--fg-faint); font-size: 14px;
  border: 1px dashed var(--border); border-radius: 10px;
}

.inbound-strip {
  flex-shrink: 0;
  display: flex; align-items: center; gap: 18px;
  padding: 7px 24px; border-top: 1px solid var(--border);
  background: linear-gradient(180deg, #10161f, #0a0e14);
  font-size: 13px; overflow-x: auto; white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.inbound-strip::-webkit-scrollbar { height: 0; }
.inbound-strip .lbl { color: var(--accent); font-weight: 700; letter-spacing: .5px; flex-shrink: 0; }
.inbound-strip .ib { color: var(--fg-dim); flex-shrink: 0; }
.inbound-strip .ib b { color: var(--fg); font-weight: 600; }
.inbound-strip .ib .ty { color: var(--fg-faint); }
.inbound-strip .ib .eta { color: var(--gold); font-weight: 700; }
.inbound-strip .ib .brg { color: var(--accent); }
.inbound-strip .none { color: var(--fg-faint); }
footer {
  padding: 8px 24px;
  font-size: 11px; color: var(--fg-faint);
  display: flex; justify-content: space-between; gap: 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
footer a { color: var(--fg-dim); text-decoration: none; }

@media (max-width: 600px) {
  main { grid-template-columns: 1fr; grid-gap: 8px; gap: 8px; padding: 8px 12px; }
}
