/* Age of Flying — mobile-first. Works in both orientations; landscape breathes
   best but nothing cramps in portrait: the stick floats wherever the left
   thumb lands and the throttle rides the right edge with safe-area padding. */
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; background: #7fa8c8; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  color: #f4f1e8;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}
#gl { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }

/* ---------- loading / hangar ---------- */
#loading, #menu {
  position: fixed; inset: 0; z-index: 30;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; text-align: center;
  padding: env(safe-area-inset-top) 20px env(safe-area-inset-bottom);
}
#loading { background: linear-gradient(#8fbede, #c8dce8 65%, #93bf4e); }
#menu { background: rgba(20, 34, 24, 0.35); backdrop-filter: blur(3px); }
.brandmark {
  width: min(88vw, 460px); height: auto; display: block;
  filter: drop-shadow(0 8px 24px rgba(20, 40, 30, 0.35));
}
#loading .brandmark { animation: rise 0.7s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.tagline { font-size: 0.85rem; opacity: 0.85; text-shadow: 0 1px 6px rgba(0,0,0,0.4); }

/* Moo Labs + PhytoEngine credit, foot of the hangar menu */
#brand-footer {
  margin-top: 24px; display: flex; align-items: center; gap: 10px;
  flex-wrap: wrap; justify-content: center;
  font-size: 0.72rem; color: #eef4ee; opacity: 0.9;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.45);
}
#brand-footer a { color: inherit; text-decoration: none; display: inline-flex; align-items: center; gap: 7px; }
#brand-footer a:hover { text-decoration: underline; }
#brand-footer .moo img {
  width: 28px; height: 28px; border-radius: 7px;
  background: rgba(255, 255, 255, 0.92); padding: 2px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}
#brand-footer .dot { opacity: 0.5; }
#brand-footer .pwr a { color: #b6e2c6; font-weight: 600; }
#loading-status { margin-top: 18px; font-size: 0.95rem; color: #2e4020; }

#planes {
  display: flex; gap: 12px; margin-top: 18px; max-width: 100%;
  flex-wrap: wrap; justify-content: center;
}
.plane-card {
  display: flex; flex-direction: column; gap: 6px; text-align: left;
  width: min(78vw, 240px); padding: 14px 16px; border: 0; border-radius: 14px;
  background: rgba(18, 28, 18, 0.72); color: #f4f1e8; cursor: pointer;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
  transition: transform 0.12s;
}
.plane-card:active { transform: scale(0.97); }
.plane-card.locked { opacity: 0.55; cursor: default; }
.plane-year { font-size: 0.75rem; color: #d8b23a; font-weight: 700; letter-spacing: 0.1em; }
.plane-name { font-size: 1.15rem; font-weight: 700; }
.plane-blurb { font-size: 0.78rem; line-height: 1.35; opacity: 0.82; }

@media (orientation: landscape) {
  #planes { flex-wrap: nowrap; }
  .plane-card { width: min(30vw, 250px); }
}

/* ---------- touch controls ---------- */
#stick-zone {
  position: fixed; left: 0; top: 0; bottom: 0; width: 62%;
  z-index: 10; touch-action: none;
}
#stick-base, #stick-nub {
  position: fixed; z-index: 11; pointer-events: none; display: none; border-radius: 50%;
}
#stick-base {
  width: 120px; height: 120px;
  border: 2px solid rgba(255, 255, 255, 0.45);
  background: rgba(255, 255, 255, 0.08);
}
#stick-nub {
  width: 52px; height: 52px;
  background: rgba(255, 255, 255, 0.55);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

#throttle {
  position: fixed; z-index: 12;
  right: calc(10px + env(safe-area-inset-right));
  bottom: calc(16px + env(safe-area-inset-bottom));
  height: min(46vh, 300px); width: 58px;
  border-radius: 30px;
  background: rgba(14, 22, 14, 0.5);
  border: 1.5px solid rgba(255, 255, 255, 0.3);
  touch-action: none; overflow: hidden;
}
#throttle-fill {
  position: absolute; bottom: 0; left: 0; right: 0; height: 0%;
  background: linear-gradient(#f2c14e, #e07b39);
  opacity: 0.85;
}
#throttle-thumb {
  position: absolute; left: 4px; right: 4px; height: 28px; bottom: -14px;
  border-radius: 16px; background: #fffbe8;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}
#throttle-label {
  position: absolute; top: 8px; width: 100%; text-align: center;
  font-size: 0.62rem; font-weight: 700; letter-spacing: 0.12em; opacity: 0.8;
}

#btn-brake {
  position: fixed; z-index: 12;
  right: calc(84px + env(safe-area-inset-right));
  bottom: calc(24px + env(safe-area-inset-bottom));
  padding: 16px 22px; border: 0; border-radius: 40px;
  background: rgba(176, 48, 48, 0.85); color: #fff;
  font-size: 0.9rem; font-weight: 800; letter-spacing: 0.06em;
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.4);
  touch-action: none;
}

/* ---------- instruments / buttons ---------- */
#instruments {
  position: fixed; z-index: 9;
  top: calc(10px + env(safe-area-inset-top));
  left: calc(12px + env(safe-area-inset-left));
  display: flex; gap: 10px;
}
.inst {
  min-width: 64px; padding: 6px 10px; border-radius: 10px;
  background: rgba(14, 22, 14, 0.5); text-align: center;
}
.inst b { display: block; font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.inst span { font-size: 0.6rem; letter-spacing: 0.1em; opacity: 0.75; text-transform: uppercase; }

#mission {
  position: fixed; z-index: 9; left: 50%; transform: translateX(-50%);
  top: calc(12px + env(safe-area-inset-top));
  font-size: 0.75rem; letter-spacing: 0.04em; opacity: 0.9;
  background: rgba(14, 22, 14, 0.45); padding: 6px 14px; border-radius: 20px;
  white-space: nowrap; max-width: 46vw; overflow: hidden; text-overflow: ellipsis;
}
@media (max-width: 700px) { #mission { display: none; } }

#topbtns {
  position: fixed; z-index: 12;
  top: calc(10px + env(safe-area-inset-top));
  right: calc(12px + env(safe-area-inset-right));
  display: flex; gap: 8px;
}
.iconbtn {
  width: 44px; height: 44px; border: 0; border-radius: 12px;
  background: rgba(14, 22, 14, 0.5); color: #f4f1e8; font-size: 1.15rem;
  display: grid; place-items: center;
}
.iconbtn:active { background: rgba(14, 22, 14, 0.8); }

/* ---------- cues ---------- */
.cue {
  position: fixed; z-index: 9; left: 50%; transform: translateX(-50%);
  bottom: 30%; padding: 10px 26px; border-radius: 12px;
  font-size: 1.3rem; font-weight: 800; letter-spacing: 0.12em;
  background: rgba(38, 120, 60, 0.85); color: #fff;
  animation: pulse 0.8s infinite alternate;
}
.cue.stall { background: rgba(176, 48, 48, 0.9); }
@keyframes pulse { from { opacity: 0.75; } to { opacity: 1; } }

/* ---------- tree-line altimeter ---------- */
#treeline {
  position: fixed; z-index: 9;
  left: calc(12px + env(safe-area-inset-left));
  top: 50%; transform: translateY(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.tl-track {
  position: relative; width: 14px; height: min(30vh, 190px);
  border-radius: 8px; background: rgba(14, 22, 14, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.25);
}
#tl-wall {
  position: absolute; left: -5px; right: -5px; height: 2px;
  background: #d8b23a; box-shadow: 0 0 6px #d8b23a;
}
#tl-you {
  position: absolute; left: 2px; right: 2px; height: 8px; margin-bottom: -4px;
  border-radius: 4px; background: #e05d5d; transition: background 0.2s;
}
#tl-you.above { background: #55c46a; }
#tl-dist { font-size: 0.72rem; font-weight: 700; }
.tl-label { font-size: 0.55rem; letter-spacing: 0.1em; text-transform: uppercase; opacity: 0.7; }

/* ---------- distance flown (feet) ---------- */
#distance {
  position: fixed; z-index: 9; left: 50%; transform: translateX(-50%);
  top: calc(52px + env(safe-area-inset-top));
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
}
#dist-ft { font-size: 2.1rem; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1; }
#dist-unit { font-size: 0.7rem; letter-spacing: 0.14em; text-transform: uppercase; opacity: 0.8; }
#dist-target { font-size: 0.7rem; opacity: 0.75; margin-top: 1px; }
#dist-track {
  position: relative; width: min(60vw, 320px); height: 5px; margin-top: 4px;
  border-radius: 3px; background: rgba(14, 22, 14, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.2); overflow: visible;
}
#dist-you { position: absolute; left: 0; top: 0; bottom: 0; width: 0%;
  border-radius: 3px; background: linear-gradient(90deg, #55c46a, #d8b23a); }
.dist-stake {
  position: absolute; top: -3px; width: 2px; height: 11px; background: #f4f1e8;
  box-shadow: 0 0 4px rgba(0, 0, 0, 0.5); transform: translateX(-1px);
}
.dist-stake::after {
  content: attr(data-ft); position: absolute; top: -12px; left: 50%;
  transform: translateX(-50%); font-size: 0.5rem; opacity: 0.7; white-space: nowrap;
}

/* ---------- anemometer ---------- */
#anemometer {
  position: fixed; z-index: 9;
  right: calc(84px + env(safe-area-inset-right));
  bottom: calc(84px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  opacity: 1; transition: opacity 0.5s;
}
#anemometer.faded { opacity: 0.32; }
#anem-arrow { font-size: 1.1rem; line-height: 1; transition: transform 0.15s; }
#anem-bar {
  width: 46px; height: 7px; border-radius: 4px; overflow: hidden;
  background: rgba(14, 22, 14, 0.55); border: 1px solid rgba(255, 255, 255, 0.22);
}
#anem-fill { height: 100%; width: 0%; background: #8fd0ff; transition: width 0.1s, background 0.2s; }
#anem-fill.strong { background: #ffcf5d; }
#anem-fill.gale { background: #e05d5d; }
.anem-label { font-size: 0.5rem; letter-spacing: 0.12em; text-transform: uppercase; opacity: 0.7; }

/* ---------- wingtip clearance ---------- */
#wingtip {
  position: fixed; z-index: 9; left: 50%; transform: translateX(-50%);
  bottom: calc(16px + env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: 14px;
  font-variant-numeric: tabular-nums; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
}
.wt { font-size: 0.85rem; font-weight: 700; min-width: 46px; text-align: center; opacity: 0.9; }
.wt.tight { color: #ffcf5d; }
.wt.danger { color: #e05d5d; animation: pulse 0.5s infinite alternate; }
.wt-mid { font-size: 0.8rem; opacity: 0.5; }

.cue.release { background: rgba(38, 90, 150, 0.9); display: flex; flex-direction: column; align-items: center; }
.cue.release small { font-size: 0.6rem; font-weight: 500; letter-spacing: 0.04em; opacity: 0.85; }

/* ---------- banner / toast / endcard ---------- */
#banner {
  position: fixed; z-index: 20; left: 50%; top: 22%; transform: translateX(-50%);
  text-align: center; max-width: 84vw; padding: 16px 26px; border-radius: 16px;
  background: rgba(14, 22, 14, 0.72); backdrop-filter: blur(2px);
}
#banner h2 { font-size: 1.4rem; color: #fffbe8; }
#banner p { font-size: 0.85rem; margin-top: 6px; opacity: 0.85; line-height: 1.4; }

#toast {
  position: fixed; z-index: 20; left: 50%; bottom: 18%; transform: translateX(-50%);
  padding: 10px 20px; border-radius: 24px; white-space: nowrap; max-width: 90vw;
  overflow: hidden; text-overflow: ellipsis;
  background: rgba(14, 22, 14, 0.78); font-size: 0.9rem;
}
#toast.pop { animation: pop 0.25s; }
@keyframes pop { from { transform: translateX(-50%) scale(0.8); } }

#endcard {
  position: fixed; z-index: 25; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; text-align: center; padding: 24px;
  background: rgba(10, 16, 10, 0.55); backdrop-filter: blur(3px);
}
#endcard h2 { font-size: clamp(1.5rem, 6vw, 2.4rem); color: #fffbe8; }
#endcard p { max-width: 480px; font-size: 0.95rem; line-height: 1.45; opacity: 0.9; }
#end-buttons { display: flex; gap: 12px; margin-top: 14px; flex-wrap: wrap; justify-content: center; }
.btn.primary {
  padding: 14px 26px; border: 0; border-radius: 30px;
  background: #d8b23a; color: #2a2410; font-size: 1rem; font-weight: 800;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
}
.btn.primary:active { transform: scale(0.96); }
