:root {
  --ink: #233456;
  --muted: #71809a;
  --sky: #7cc4f2;
  --sky-dark: #2d6fb4;
  --green: #3fb27f;
  --green-dark: #24724f;
  --yellow: #ffd23f;
  --orange: #f29545;
  --red: #e8574e;
  --panel: rgba(16, 24, 40, 0.78);
  --shadow: 0 20px 55px rgba(35, 52, 86, 0.14);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Nunito", sans-serif;
  background:
    radial-gradient(circle at 4% 10%, rgba(124, 196, 242, .3) 0 120px, transparent 121px),
    radial-gradient(circle at 97% 32%, rgba(63, 178, 127, .16) 0 180px, transparent 181px),
    linear-gradient(145deg, #f2f9ff, #f6fbf2 60%, #fff8ec);
  overflow-x: hidden;
}
button { color: inherit; font: inherit; }

.topbar {
  height: 72px;
  padding: 0 clamp(18px, 5vw, 72px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(35, 52, 86, .08);
  background: rgba(255, 253, 248, .86);
  backdrop-filter: blur(14px);
  position: relative;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark {
  width: 41px; height: 41px; display: grid; place-items: center;
  border-radius: 14px; color: white; background: var(--sky-dark); font-size: 21px;
  transform: rotate(-5deg); box-shadow: 0 7px 16px rgba(45, 111, 180, .27);
}
.brand-name { font: 800 22px/1 "Baloo 2", cursive; }
.brand-name small { display: block; color: var(--sky-dark); font: 800 9px/1.3 "Nunito", sans-serif; letter-spacing: 1.6px; }
.top-actions { display: flex; gap: 9px; }
.icon-btn {
  width: 41px; height: 41px; display: grid; place-items: center;
  border: 1px solid #e5e3dc; border-radius: 13px; background: white; color: var(--ink);
  text-decoration: none; cursor: pointer; box-shadow: 0 4px 12px rgba(35, 52, 86, .05);
  transition: .18s ease;
}
.icon-btn:hover { transform: translateY(-2px); }

main { width: min(1320px, calc(100% - 30px)); margin: 0 auto; padding: 28px 0 40px; }
.welcome { display: flex; justify-content: space-between; align-items: end; gap: 18px; margin-bottom: 16px; }
.eyebrow { margin: 0 0 3px; color: var(--sky-dark); font-size: 11px; font-weight: 900; letter-spacing: 1.8px; text-transform: uppercase; }
h1 { margin: 0; font: 800 clamp(30px, 4vw, 42px)/1.05 "Baloo 2", cursive; }
.welcome-copy { margin: 6px 0 0; color: var(--muted); font-size: 14px; }
.best-pill { flex: 0 0 auto; padding: 10px 15px; border: 1px solid #e8e4dc; border-radius: 15px; background: white; font-size: 12px; font-weight: 900; box-shadow: 0 8px 22px rgba(35, 52, 86, .05); }

.flight-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 250px;
  gap: 16px;
  align-items: start;
}

/* ---- Stage ---------------------------------------------------------------- */
.flight-stage {
  position: relative;
  aspect-ratio: 16 / 9;
  min-height: 440px;
  max-height: 80vh;
  width: 100%;
  overflow: hidden;
  border: 5px solid white;
  border-radius: 26px;
  background: linear-gradient(#8ccbf2, #d7ecf8);
  box-shadow: var(--shadow);
  user-select: none;
}
.flight-stage:fullscreen { aspect-ratio: auto; width: 100vw; height: 100vh; max-height: none; border: 0; border-radius: 0; }
#flightCanvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#flightCanvas:active { cursor: grabbing; }

/* ---- HUD -------------------------------------------------------------------- */
.hud { position: absolute; inset: 0; z-index: 3; pointer-events: none; color: white; }
.hud[hidden] { display: none; }
.hud-top { position: absolute; left: 14px; right: 14px; top: 12px; display: flex; justify-content: space-between; gap: 10px; }
.hud-chip {
  display: flex; align-items: center; gap: 8px; padding: 7px 12px;
  border-radius: 14px; background: var(--panel); font-size: 12px; font-weight: 800;
}
.hud-chip strong { font: 800 15px/1 "Baloo 2", cursive; }
.hud-chip span { padding: 3px 8px; border-radius: 10px; background: var(--green); font-size: 10px; letter-spacing: .6px; text-transform: uppercase; }
.hud-camera { font-size: 11px; color: #dbe7ff; }

.hud-warning {
  position: absolute; left: 50%; top: 58px; transform: translateX(-50%);
  padding: 8px 18px; border-radius: 14px; background: var(--red); color: white;
  font: 800 20px/1 "Baloo 2", cursive; letter-spacing: 1px;
  opacity: 0; transition: opacity .15s;
}
.hud-warning.show { opacity: 1; animation: flash .8s steps(2) infinite; }
@keyframes flash { 50% { background: #a62a22; } }
.hud-message {
  position: absolute; left: 50%; top: 104px; transform: translateX(-50%) translateY(-6px);
  max-width: 70%; padding: 8px 16px; border-radius: 14px; background: var(--panel);
  font-size: 14px; font-weight: 800; text-align: center;
  opacity: 0; transition: opacity .2s, transform .2s;
}
.hud-message.show { opacity: 1; transform: translateX(-50%); }
.hud-message[data-tone="good"] { background: rgba(36, 114, 79, .9); }
.hud-message[data-tone="warn"] { background: rgba(196, 98, 28, .92); }

.hud-nav {
  position: absolute; right: 14px; top: 56px; display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; border-radius: 14px; background: var(--panel);
}
.nav-arrow {
  width: 34px; height: 34px; display: grid; place-items: center; border-radius: 50%;
  background: var(--yellow); color: #3a2c00; font-size: 17px; transition: transform .2s linear;
}
.nav-copy { display: flex; flex-direction: column; font-size: 11px; font-weight: 700; color: #dbe7ff; }
.nav-copy strong { color: white; font: 800 15px/1.1 "Baloo 2", cursive; }
.nav-copy b { color: white; }

.pfd {
  position: absolute; left: 12px; bottom: 12px;
  width: clamp(250px, 30%, 360px); aspect-ratio: 1.45;
}

.systems {
  position: absolute; right: 12px; bottom: 12px; display: flex; gap: 10px;
  padding: 10px 12px; border-radius: 16px; background: var(--panel);
}
.throttle { display: flex; flex-direction: column; align-items: center; gap: 4px; width: 48px; }
.throttle small { color: #dbe7ff; font-size: 9px; font-weight: 900; letter-spacing: .5px; text-transform: uppercase; }
.throttle strong { font: 800 14px/1 "Baloo 2", cursive; }
.throttle-track { position: relative; width: 18px; height: 92px; overflow: hidden; border-radius: 9px; background: rgba(255, 255, 255, .15); }
.throttle-fill { position: absolute; left: 0; right: 0; bottom: 0; height: 0; border-radius: 9px; background: linear-gradient(var(--yellow), var(--green)); }
.sys-list { display: flex; flex-direction: column; gap: 3px; min-width: 132px; }
.sys-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 11px; font-weight: 800; color: #dbe7ff; }
.sys-row[hidden] { display: none; }
.sys-row strong { color: white; font-size: 12px; }
.sys-row strong[data-on="true"] { color: var(--yellow); }
.flap-track { height: 5px; overflow: hidden; border-radius: 3px; background: rgba(255, 255, 255, .15); }
.flap-fill { width: 0; height: 100%; background: #7fd0ff; }
.gear-lights { display: inline-flex; gap: 3px; }
.gear-lights i { width: 10px; height: 10px; border-radius: 50%; background: rgba(255, 255, 255, .18); }
.gear-lights i[data-state="down"] { background: #33e07a; box-shadow: 0 0 6px #33e07a; }
.gear-lights i[data-state="moving"] { background: #ff4a3d; box-shadow: 0 0 6px #ff4a3d; }

/* ---- Touch controls --------------------------------------------------------- */
/* One row between the instruments: stick, buttons, throttle. */
.touch-controls { display: none; }
.touch-controls.show {
  position: absolute; z-index: 4; left: calc(clamp(200px, 26%, 300px) + 24px); right: 232px; bottom: 14px;
  display: flex; align-items: flex-end; justify-content: center; gap: 14px; pointer-events: none;
}
.touch-mode .pfd { width: clamp(200px, 26%, 300px); }
.touch-stick {
  position: relative; flex: 0 0 120px; height: 120px; border-radius: 50%;
  background: rgba(16, 24, 40, .45); border: 3px solid rgba(255, 255, 255, .6);
  pointer-events: auto; touch-action: none;
}
.touch-knob {
  position: absolute; left: 30%; top: 30%; width: 40%; height: 40%; border-radius: 50%;
  background: rgba(255, 255, 255, .9); box-shadow: 0 4px 10px rgba(0, 0, 0, .25);
}
.touch-buttons { display: grid; grid-template-columns: repeat(2, 68px); gap: 6px; pointer-events: auto; }
.touch-buttons button {
  min-height: 38px; padding: 4px; border: 0; border-radius: 12px; background: rgba(255, 255, 255, .88);
  color: var(--ink); font-size: 11px; font-weight: 900; line-height: 1.1; touch-action: manipulation;
}
.touch-throttle {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  color: white; font-size: 9px; font-weight: 900; text-transform: uppercase; pointer-events: auto;
}
.touch-throttle input { writing-mode: vertical-lr; direction: rtl; width: 34px; height: 118px; }

/* ---- Overlays --------------------------------------------------------------- */
.flight-overlay {
  position: absolute; inset: 0; z-index: 8; display: grid; place-items: center; padding: 16px;
  background: rgba(22, 36, 64, .45); backdrop-filter: blur(4px);
  opacity: 0; pointer-events: none; transition: opacity .2s ease;
  overflow-y: auto;
}
.flight-overlay.show { opacity: 1; pointer-events: auto; }
.overlay-card { width: min(470px, 100%); padding: 24px; border-radius: 24px; background: white; box-shadow: 0 24px 65px rgba(20, 30, 55, .28); text-align: center; }
.overlay-icon { font-size: 48px; }
.overlay-card h2 { margin: 4px 0; font: 800 29px/1.08 "Baloo 2", cursive; }
.overlay-card p { margin: 7px auto 16px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.overlay-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.primary-btn, .secondary-btn {
  padding: 12px 20px; border: 0; border-radius: 14px; font-size: 13px; font-weight: 900; cursor: pointer;
  transition: transform .15s;
}
.primary-btn { background: var(--sky-dark); color: white; box-shadow: 0 8px 16px rgba(45, 111, 180, .28); }
.primary-btn:disabled { opacity: .55; cursor: wait; }
.secondary-btn { background: #eef3fa; color: var(--ink); }
.primary-btn:hover:not(:disabled), .secondary-btn:hover { transform: translateY(-1px); }
.toggle-row { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 0 0 16px; color: var(--muted); font-size: 12px; font-weight: 800; }

.report-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 4px 0 10px; }
.report-stats div { padding: 10px 6px; border-radius: 14px; background: #f1f6fb; }
.report-stats strong { display: block; font: 800 20px/1.1 "Baloo 2", cursive; }
.report-stats small { display: block; color: var(--muted); font-size: 9px; font-weight: 900; text-transform: uppercase; letter-spacing: .5px; }
.report-best { min-height: 18px; color: var(--green-dark) !important; font-weight: 900; }

/* ---- Hangar ----------------------------------------------------------------- */
#hangarOverlay { place-items: start center; }
.hangar-card {
  width: min(900px, 100%); margin: auto 0; padding: 20px 22px; border-radius: 24px; background: white;
  box-shadow: 0 24px 65px rgba(20, 30, 55, .28);
}
.hangar-head h2 { margin: 0; font: 800 28px/1.1 "Baloo 2", cursive; }
.hangar-head p { margin: 2px 0 6px; color: var(--muted); font-size: 13px; font-weight: 700; }
.hangar-section { margin-top: 12px; }
.hangar-section h3 { margin: 0 0 6px; font: 800 16px/1.1 "Baloo 2", cursive; }
.hangar-extras { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.choice-grid { display: grid; gap: 8px; }
.airline-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.aircraft-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.helper-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.small-grid { grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); }
.small-grid + .small-grid { margin-top: 8px; }
.choice {
  position: relative; min-height: 44px; padding: 9px 11px; border: 2px solid #e3e7ee; border-bottom-width: 4px;
  border-radius: 14px; background: white; text-align: left; cursor: pointer; transition: .14s;
}
.choice:hover { border-color: #9cc6ec; transform: translateY(-1px); }
.choice[aria-pressed="true"] { border-color: var(--sky-dark); background: #eef6ff; }
.choice strong { display: block; font: 800 15px/1.15 "Baloo 2", cursive; }
.choice small { display: block; margin-top: 2px; color: var(--muted); font-size: 11px; font-weight: 700; line-height: 1.35; }
.airline-choice { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px; }
.tail-art {
  position: relative; width: 70px; height: 46px;
}
.tail-art::before {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 14px; border-radius: 7px;
  background: linear-gradient(var(--fuselage) 50%, var(--belly) 50%); box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12);
}
.tail-art::after {
  content: ""; position: absolute; right: 6px; bottom: 10px; width: 30px; height: 36px;
  clip-path: polygon(30% 0, 70% 0, 100% 100%, 0 100%);
  background: linear-gradient(var(--tail) 40%, var(--stripe) 40% 55%, var(--tail) 55%);
}
.hangar-go { display: flex; align-items: center; justify-content: flex-end; gap: 12px; margin-top: 14px; }
.loading-note { margin: 0; color: var(--muted); font-size: 12px; font-weight: 800; }
.loading-note:empty { display: none; }
#flyBtn { font-size: 16px; padding: 13px 26px; }

/* ---- Side help -------------------------------------------------------------- */
.flight-help { display: flex; flex-direction: column; gap: 12px; }
.side-card { padding: 15px; border: 1px solid #e8e7e0; border-radius: 17px; background: white; box-shadow: 0 8px 22px rgba(35, 52, 86, .05); }
.side-card h3 { margin: 0 0 8px; font: 800 17px/1.1 "Baloo 2", cursive; }
.side-card p, .side-card li { margin: 0; color: var(--muted); font-size: 12px; font-weight: 800; line-height: 1.5; }
.key-list { margin: 0; padding: 0; list-style: none; display: grid; gap: 4px; }
kbd {
  display: inline-block; min-width: 22px; padding: 1px 5px; border: 1px solid #d5dbe5; border-bottom-width: 3px;
  border-radius: 6px; background: #f7f9fc; color: var(--ink); font: 900 11px/1.4 "Nunito", sans-serif; text-align: center;
}
.rotate-tip { margin-top: 8px !important; color: var(--green-dark) !important; }
.credits { margin: 14px 2px 0; color: var(--muted); font-size: 10px; font-weight: 700; line-height: 1.5; }

@media (max-width: 1100px) {
  .flight-shell { grid-template-columns: minmax(0, 1fr); }
  .flight-help { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .airline-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .aircraft-grid, .helper-grid, .hangar-extras { grid-template-columns: minmax(0, 1fr); }
  .flight-help { grid-template-columns: minmax(0, 1fr); }
  .flight-stage { aspect-ratio: auto; height: 78vh; min-height: 420px; }
  .pfd { width: 210px; }
  .systems { transform: scale(.85); transform-origin: bottom right; }
  .hud-nav { top: 52px; transform: scale(.9); transform-origin: top right; }
}
@media (max-width: 650px) {
  .topbar { padding: 0 13px; }
  .brand-name { font-size: 18px; }
  main { width: calc(100% - 16px); padding-top: 18px; }
  .welcome { align-items: start; }
  .welcome-copy { font-size: 12px; }
  .best-pill span { display: none; }
  .flight-stage { border-width: 3px; border-radius: 18px; }
  .touch-controls.show { left: 10px; right: 10px; bottom: 10px; justify-content: space-between; gap: 8px; }
  .touch-buttons { grid-template-columns: repeat(2, 64px); }
  .systems { display: none; }
  .hud-camera { display: none; }
  .hud-chip { font-size: 11px; }
  .hud-nav { top: 50px; right: 10px; padding: 6px 9px; }
  .pfd, .touch-mode .pfd { left: 50%; bottom: auto; top: 112px; width: min(300px, calc(100% - 20px)); transform: translateX(-50%); }
  .hud-message { top: 330px; max-width: 90%; }
  .hud-warning { top: 300px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; } }
