:root {
  --bg: #070b14;
  --surface: #0d1424;
  --card: #101a2e;
  --card-edge: rgba(148, 180, 226, 0.10);
  --ink: #e8eefb;
  --ink2: #9db0cd;
  --muted: #5e7397;
  --accent: #f97316;
  --accent-soft: rgba(249, 115, 22, 0.14);
  --actual: #2196d9;
  --pred: #e05e0b;
  --good: #4ade80;
  --warn: #fbbf24;
  --bad: #f87171;
  --font: -apple-system, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }

body {
  font-family: var(--font);
  background:
    radial-gradient(1100px 500px at 75% -10%, rgba(249, 115, 22, 0.05), transparent 60%),
    radial-gradient(900px 600px at 15% 110%, rgba(33, 150, 217, 0.05), transparent 60%),
    var(--bg);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  user-select: none;
}

.card {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.015), rgba(255, 255, 255, 0)), var(--card);
  border: 1px solid var(--card-edge);
  border-radius: 12px;
}

/* ---------- Top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 22px;
  padding: 12px 16px 10px;
  flex: none;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { height: 24px; width: auto; display: block; }
.brand-name { font-weight: 700; letter-spacing: 0.22em; font-size: 14px; }
.brand-div { width: 1px; height: 18px; background: var(--card-edge); }
.brand-sub { letter-spacing: 0.26em; font-size: 11px; color: var(--ink2); font-weight: 600; }

.mode-area { display: flex; align-items: center; gap: 10px; row-gap: 7px; flex: 1; min-width: 0; flex-wrap: wrap; }
.mode-label { font-size: 9px; letter-spacing: 0.16em; color: var(--muted); font-weight: 700; }

.select-wrap { position: relative; }
.select-wrap::after {
  content: "";
  position: absolute; right: 11px; top: 50%;
  width: 6px; height: 6px;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
}
select {
  appearance: none;
  -webkit-appearance: none;
  font-family: var(--font);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--card-edge);
  border-radius: 999px;
  padding: 7px 30px 7px 14px;
  cursor: pointer;
  max-width: 420px;
}
select:hover { border-color: rgba(249, 115, 22, 0.45); }
select:focus { outline: none; border-color: var(--accent); }

.custom-inputs { display: flex; align-items: center; gap: 8px; row-gap: 7px; flex-wrap: wrap; }
.custom-inputs[hidden] { display: none; }
.icao {
  width: 74px;
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  text-align: center;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--card-edge);
  border-radius: 8px;
  padding: 6px 4px;
}
.icao:focus { outline: none; border-color: var(--accent); }
.route-arrow { color: var(--muted); font-size: 13px; }
.gen-btn {
  font-family: var(--font);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: #0b0f18;
  background: linear-gradient(180deg, #fb923c, var(--accent));
  border: none;
  border-radius: 999px;
  padding: 8px 18px;
  cursor: pointer;
}
.gen-btn:hover { filter: brightness(1.08); }
.gen-btn:active { transform: translateY(1px); }

.link-pill {
  display: flex; align-items: center; gap: 7px;
  font-size: 9.5px; font-weight: 700; letter-spacing: 0.14em;
  color: var(--ink2);
  border: 1px solid var(--card-edge);
  border-radius: 999px;
  padding: 6px 13px;
  white-space: nowrap;
}
.link-pill .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--good); box-shadow: 0 0 8px var(--good); }

/* ---------- Timeline ---------- */

.timeline {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 2px 16px 0;
  flex: none;
}

.play-btn {
  width: 34px; height: 34px; flex: none;
  display: grid; place-items: center;
  background: var(--card);
  border: 1px solid var(--card-edge);
  border-radius: 50%;
  cursor: pointer;
}
.play-btn svg { width: 15px; height: 15px; fill: var(--ink); }
.play-btn:hover { border-color: var(--accent); }

.time-readout {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink);
  display: flex; gap: 6px; align-items: baseline;
  min-width: 106px;
}
.time-total { color: var(--muted); font-size: 10.5px; }

.scrub { flex: 1 1 0; min-width: 0; height: 40px; cursor: pointer; }

.speed-wrap { flex: none; }
.speed-wrap select {
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 700;
  color: var(--ink2);
  padding: 5px 24px 5px 11px;
  max-width: none;
}
.speed-wrap select:hover { color: var(--ink); }

.jump-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 16px 8px 62px;
  flex: none;
}
.jump-label { font-size: 8.5px; font-weight: 700; letter-spacing: 0.18em; color: var(--muted); }
.jump-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.jump-chip {
  font-family: var(--font);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--ink2);
  background: transparent;
  border: 1px solid var(--card-edge);
  border-radius: 999px;
  padding: 4px 11px;
  cursor: pointer;
}
.jump-chip:hover { color: var(--ink); border-color: rgba(249, 115, 22, 0.5); }
.jump-chip.alert { color: var(--bad); border-color: rgba(248, 113, 113, 0.4); }

/* ---------- Main ---------- */

.main {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 236px;
  gap: 10px;
  padding: 0 16px 14px;
}

.hero { position: relative; overflow: hidden; }
.hero canvas { position: absolute; inset: 0; width: 100%; height: 100%; }

/* ---------- Cockpit layout: engine | EFIS | map over a full-width graph ---------- */

.cockpit {
  position: relative;
  min-height: 0;
  display: grid;
  grid-template-rows: 1fr clamp(150px, 26vh, 240px);
  gap: 10px;
}
.cpit-row {
  min-height: 0;
  display: grid;
  grid-template-columns: 0.82fr 1.12fr 1.3fr;
  gap: 10px;
}
/* twin-engine EMS needs two full gauge columns — take the room from the
   EFIS and aircraft tiles */
.cockpit.twin-ems .cpit-row { grid-template-columns: 1.35fr 1.02fr 1.05fr; }
.cpit-tile, .cpit-bottom { position: relative; overflow: hidden; }
.cpit-tile canvas, .cpit-bottom canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.cpit-tag {
  position: absolute;
  top: 8px; left: 10px;
  z-index: 810;
  font-size: 9px; font-weight: 700; letter-spacing: 0.2em;
  color: var(--ink2);
  background: rgba(7, 11, 20, 0.55);
  border: 1px solid var(--card-edge);
  border-radius: 6px;
  padding: 4px 8px;
  pointer-events: none;
  backdrop-filter: blur(4px);
}
.cpit-legend {
  position: absolute; top: 12px; right: 12px; z-index: 810;
  flex-direction: column; align-items: flex-end; gap: 5px;
}
.cpit-legend-bottom {
  position: absolute; left: 0; right: 0; bottom: 6px; z-index: 810;
  display: flex; justify-content: center; gap: 12px;
  pointer-events: none;
}
.cpit-legend-bottom:empty { display: none; }
.cpit-graph-tools {
  position: absolute;
  top: 8px; right: 10px;
  z-index: 810;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px 10px;
  max-width: 76%;
}

/* the Leaflet map lives in the lower half of the EFIS tile, under the HSI ring;
   the EFIS canvas draws above it but stays click-through so the map can pan */
#mapHero { position: absolute; top: 50%; left: 0; right: 0; bottom: 0; z-index: 1; }
#mapHero[hidden] { display: none; }
#efisTile canvas { z-index: 2; pointer-events: none; }
.leaflet-container { background: #0a0f1c; font-family: var(--font); }
/* lift the dark basemap: brighter with more contrast, still on-theme */
#mapHero .leaflet-tile-pane { filter: brightness(1.7) contrast(1.18) saturate(1.15); }
.leaflet-control-attribution {
  background: rgba(7, 11, 20, 0.72) !important;
  color: var(--muted) !important;
  font-size: 8.5px !important;
}
.leaflet-control-attribution a { color: var(--ink2) !important; }
.map-fix {
  font-family: var(--mono); font-size: 9px; font-weight: 700; letter-spacing: 0.08em;
  color: var(--ink2); background: rgba(7, 11, 20, 0.72);
  padding: 1px 5px; border-radius: 3px; white-space: nowrap;
}
.map-apt {
  font-family: var(--mono); font-size: 11px; font-weight: 700; letter-spacing: 0.1em;
  color: var(--ink); background: rgba(7, 11, 20, 0.78);
  border: 1px solid var(--card-edge);
  padding: 2px 7px; border-radius: 4px; white-space: nowrap;
}
.map-alert {
  font-family: var(--font); font-size: 9px; font-weight: 700; letter-spacing: 0.06em;
  color: var(--bad); background: rgba(7, 11, 20, 0.78);
  padding: 2px 6px; border-radius: 3px; white-space: nowrap;
}
.map-ac-inner { width: 26px; height: 26px; will-change: transform; }
.map-ac-inner svg { display: block; width: 100%; height: 100%; }

.hero-head {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 12px 14px;
  pointer-events: none;
  z-index: 800;
}
.hero-title {
  font-size: 10px; font-weight: 700; letter-spacing: 0.2em;
  color: var(--ink2);
  background: rgba(7, 11, 20, 0.55);
  border: 1px solid var(--card-edge);
  border-radius: 6px;
  padding: 5px 10px;
  backdrop-filter: blur(4px);
}
.hero-tools { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }

.legend { display: flex; gap: 12px; pointer-events: none; }
.legend:empty { display: none; }
.legend-item { display: flex; align-items: center; gap: 6px; font-size: 9.5px; font-weight: 700; letter-spacing: 0.12em; color: var(--ink2); }
.legend-item .swatch { width: 14px; height: 3px; border-radius: 2px; }

.metric-chips { display: flex; gap: 5px; pointer-events: auto; }
.metric-chips[hidden] { display: none; }
.metric-chip {
  font-family: var(--mono);
  font-size: 9.5px;
  font-weight: 700;
  color: var(--ink2);
  background: rgba(7, 11, 20, 0.55);
  border: 1px solid var(--card-edge);
  border-radius: 6px;
  padding: 5px 9px;
  cursor: pointer;
  backdrop-filter: blur(4px);
}
.metric-chip:hover { color: var(--ink); }
.metric-chip.active { color: var(--accent); border-color: rgba(249, 115, 22, 0.55); background: var(--accent-soft); }

/* generate overlay */
.gen-overlay {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  background: rgba(7, 11, 20, 0.72);
  backdrop-filter: blur(3px);
  z-index: 900;
}
.gen-overlay[hidden] { display: none; }
.gen-box { width: 300px; text-align: center; }
.gen-title { font-size: 11px; font-weight: 700; letter-spacing: 0.3em; color: var(--accent); margin-bottom: 10px; }
.gen-stage { font-size: 12.5px; color: var(--ink2); margin-bottom: 14px; min-height: 18px; }
.gen-bar { height: 3px; background: var(--card-edge); border-radius: 2px; overflow: hidden; }
.gen-fill { height: 100%; width: 0%; background: var(--accent); border-radius: 2px; transition: width 0.3s ease; }

/* ---------- Right rail ---------- */

.rail { display: flex; flex-direction: column; gap: 8px; min-height: 0; }

.stat {
  padding: 9px 13px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.stat .k { font-size: 8.5px; font-weight: 700; letter-spacing: 0.18em; color: var(--muted); }
.stat .v { font-size: 14px; font-weight: 700; letter-spacing: 0.04em; }
.stat .v.num { font-family: var(--mono); font-weight: 600; }

.metric-wrap { margin-top: 2px; }
.metric-wrap select {
  width: 100%;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  border-radius: 8px;
  padding: 5px 26px 5px 10px;
  max-width: none;
}

.status-v { display: flex; align-items: center; gap: 7px; }
.chan-dots { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 7px; }
.chan-dots[hidden] { display: none; }
.chan-dot {
  display: flex; align-items: center; gap: 5px;
  font-family: var(--mono); font-size: 8.5px; font-weight: 700;
  color: var(--ink2);
  background: transparent;
  border: 1px solid var(--card-edge);
  border-radius: 5px;
  padding: 2px 6px;
  cursor: pointer;
}
.chan-dot::before {
  content: ''; width: 6px; height: 6px; border-radius: 50%;
  background: var(--good);
}
.chan-dot.caution { color: var(--warn); }
.chan-dot.caution::before { background: var(--warn); box-shadow: 0 0 6px var(--warn); }
.chan-dot.alert { color: var(--bad); border-color: rgba(248, 113, 113, 0.45); }
.chan-dot.alert::before { background: var(--bad); box-shadow: 0 0 7px var(--bad); animation: pulse 0.9s ease-in-out infinite; }
.chan-dot.none { color: var(--muted); }
.chan-dot.none::before { background: var(--muted); box-shadow: none; }
.chan-dot.active { border-color: var(--accent); }
.chan-dot:hover { color: var(--ink); }
.status-v .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--good); box-shadow: 0 0 8px var(--good); }
#statusCard.normal .status-v { color: var(--good); }
#statusCard.caution .status-v { color: var(--warn); }
#statusCard.caution .status-v .dot { background: var(--warn); box-shadow: 0 0 8px var(--warn); }
#statusCard.alert .status-v { color: var(--bad); }
#statusCard.alert .status-v .dot { background: var(--bad); box-shadow: 0 0 10px var(--bad); animation: pulse 0.9s ease-in-out infinite; }
#statusCard.alert { border-color: rgba(248, 113, 113, 0.45); }
@keyframes pulse { 50% { opacity: 0.35; } }

.summary { flex: 1; min-height: 0; padding: 11px 13px; overflow: hidden; }
.summary .k { font-size: 8.5px; font-weight: 700; letter-spacing: 0.18em; color: var(--muted); margin-bottom: 8px; }
.summary-rows { display: flex; flex-direction: column; gap: 7px; }
.srow { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.srow .sk { font-size: 9px; font-weight: 600; letter-spacing: 0.1em; color: var(--ink2); }
.srow .sv { font-family: var(--mono); font-size: 11.5px; color: var(--ink); text-align: right; }
.srow .sv.hi { color: var(--accent); }
.srow .sv.bad { color: var(--bad); }

/* ---------- Filmstrip ---------- */

.filmstrip {
  flex: none;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  padding: 10px 16px 14px;
  height: 138px;
}

.tile {
  position: relative;
  overflow: hidden;
  cursor: pointer;
  padding: 0;
  font: inherit;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.015), rgba(255, 255, 255, 0)), var(--card);
  border: 1px solid var(--card-edge);
  border-radius: 10px;
  transition: border-color 0.15s ease;
}
.tile:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.tile:hover { border-color: rgba(249, 115, 22, 0.45); }
.tile.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), 0 0 18px rgba(249, 115, 22, 0.18); }
.tile canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.tile .tile-label {
  position: absolute;
  left: 8px; bottom: 6px;
  font-size: 8px; font-weight: 700; letter-spacing: 0.16em;
  color: var(--ink2);
  background: rgba(7, 11, 20, 0.6);
  border-radius: 4px;
  padding: 3px 6px;
  pointer-events: none;
}
.tile.active .tile-label { color: var(--accent); }

/* narrow presentation windows (e.g. shared over Meet) */
@media (max-width: 1180px) {
  .topbar { flex-wrap: wrap; row-gap: 8px; }
  .main { grid-template-columns: 1fr 208px; }
  .filmstrip { height: 112px; }
}

/* ---------- Auth gate ---------- */

.auth-gate {
  position: fixed; inset: 0; z-index: 2000;
  display: grid; place-items: center;
  background:
    radial-gradient(1100px 500px at 75% -10%, rgba(249, 115, 22, 0.06), transparent 60%),
    var(--bg);
}
.auth-gate[hidden] { display: none; }
.auth-card {
  width: 320px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.02), rgba(255, 255, 255, 0)), var(--card);
  border: 1px solid var(--card-edge);
  border-radius: 14px;
  padding: 28px 26px 24px;
  text-align: center;
}
.auth-mark { height: 34px; margin-bottom: 12px; }
.auth-title { font-weight: 700; letter-spacing: 0.22em; font-size: 15px; }
.auth-title span { color: var(--ink2); font-size: 11px; letter-spacing: 0.26em; }
.auth-sub {
  margin: 8px 0 20px;
  font-size: 8.5px; font-weight: 700; letter-spacing: 0.2em; color: var(--muted);
}
.auth-label {
  display: block; text-align: left; margin: 12px 2px 4px;
  font-size: 8.5px; font-weight: 700; letter-spacing: 0.18em; color: var(--muted);
}
.auth-card input {
  width: 100%;
  font-family: var(--mono); font-size: 13px;
  color: var(--ink); background: var(--bg);
  border: 1px solid var(--card-edge); border-radius: 8px;
  padding: 9px 10px;
}
.auth-card input:focus { outline: none; border-color: var(--accent); }
.auth-err { min-height: 16px; margin-top: 10px; font-size: 11px; color: var(--bad); }
.auth-submit { width: 100%; margin-top: 6px; }
.auth-note { font-size: 12px; line-height: 1.55; color: var(--ink2); margin-bottom: 14px; }

.signout-btn {
  font-family: var(--font); font-size: 9px; font-weight: 700; letter-spacing: 0.16em;
  color: var(--ink2); background: transparent;
  border: 1px solid var(--card-edge); border-radius: 999px;
  padding: 6px 13px; cursor: pointer; white-space: nowrap;
}
.signout-btn:hover { color: var(--ink); border-color: rgba(249, 115, 22, 0.5); }
