:root {
  /* the day look; the evening look is chosen with the switch beside Home, or by the device */
  --bg: #eaf2fa;
  --bg2: #d4e2f0;
  --ink: #10202e;
  --inkDim: #43586c;
  --line: #9db3c8;
  --accent: #c8461c;
  --accentInk: #ffffff;
  --sel: #c6d8ea;
  --now: #b87300;
  --stageBg: #9cc8ee;
  --shade: rgba(234, 242, 250, 0.94);
  --toastBg: #10202e;
  --toastInk: #ffffff;
  --star: #b87300;
  --ready: #1f8a3a;
  --danger: #b42318;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16202c;
    --bg2: #233244;
    --ink: #e8f0f8;
    --inkDim: #9fb2c6;
    --line: #3a506a;
    --accent: #f2884e;
    --accentInk: #111a24;
    --sel: #33475e;
    --now: #ffd166;
    --stageBg: #6d8fb8;
    --shade: rgba(22, 32, 44, 0.92);
    --toastBg: #f6f9fc;
    --toastInk: #16202c;
    --star: #ffd166;
    --ready: #5fd07a;
    --danger: #ff8a80;
  }
}
:root[data-theme="dark"] {
  --bg: #16202c;
  --bg2: #233244;
  --ink: #e8f0f8;
  --inkDim: #9fb2c6;
  --line: #3a506a;
  --accent: #f2884e;
  --accentInk: #111a24;
  --sel: #33475e;
  --now: #ffd166;
  --stageBg: #6d8fb8;
  --shade: rgba(22, 32, 44, 0.92);
  --toastBg: #f6f9fc;
  --toastInk: #16202c;
  --star: #ffd166;
  --ready: #5fd07a;
  --danger: #ff8a80;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg2) 100%);
  color: var(--ink); user-select: none; -webkit-user-select: none; overflow: hidden;
}
#app { height: 100%; display: flex; flex-direction: column; max-width: min(100%, 1100px); margin: 0 auto; }

#hdr { display: flex; align-items: center; gap: 8px; padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top)); }
#hdr .pill { background: var(--bg2); border: 2px solid var(--line); border-radius: 999px; padding: 6px 11px; font-weight: 800; font-size: 15px; min-width: 44px; min-height: 44px; display: flex; align-items: center; cursor: pointer; justify-content: center; color: inherit; font-family: inherit; }
#hdrHome { border: none; background: var(--accent); color: var(--accentInk); font-size: 18px; }
#hdrStatus { flex: 1; min-width: 0; text-align: center; font-weight: 800; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--ink); }

.scr { flex: 1; display: none; flex-direction: column; overflow-y: auto; padding: 6px 14px 18px; gap: 10px; min-height: 0; }
.scr.on { display: flex; }
.scrTitle { color: var(--ink); font-size: 22px; text-align: center; }

#scr-menu { align-items: center; text-align: center; justify-content: center; }
#scr-menu h1 { font-size: clamp(30px, 9vw, 46px); color: var(--ink); }
#scr-menu .sub { color: var(--inkDim); font-weight: 600; }
.menuGrid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; width: 100%; }
button.big { width: 100%; border-radius: 16px; min-height: 56px; font-size: 19px; font-weight: 800; background: var(--bg2); color: var(--ink); border: 3px solid var(--line); cursor: pointer; font-family: inherit; padding: 6px 10px; }
button.big:active { transform: translateY(2px); }
button.big.primary { background: var(--accent); border-color: var(--accent); color: var(--accentInk); }
button.big.danger { border-color: var(--danger); color: var(--danger); }
button.big:disabled { opacity: 0.5; cursor: default; }
button.big[hidden] { display: none; }
#statsLine { color: var(--inkDim); font-weight: 700; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; width: 100%; }
.seg button { flex: 1; min-height: 44px; min-width: 56px; border-radius: 12px; border: 3px solid var(--line); background: var(--bg); color: var(--ink); font: 800 15px inherit; font-family: inherit; cursor: pointer; }
.seg button.sel { border-color: var(--accent); background: var(--sel); }

/* the flights */
#setGrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 8px; }
.tile { min-height: 76px; border-radius: 16px; border: 3px solid var(--line); background: var(--bg2); color: var(--ink); font-family: inherit; font-weight: 800; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
.tile b { font-size: 30px; }
.tile span { font-size: 13px; color: var(--inkDim); }
.tile.done span { color: var(--star); }
.tile.cur { border-color: var(--accent); }
.tile:disabled { opacity: 0.45; cursor: default; }

/* flying: the picture, then the goal row and 🛬 */
#scr-play { padding: 0 6px 6px; gap: 6px; }
#stageWrap { position: relative; flex: 1; min-height: 200px; border-radius: 14px; overflow: hidden; background: var(--stageBg); touch-action: none; }
#stage { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#arrow { position: absolute; left: -30px; top: -40px; width: 60px; height: 80px; pointer-events: none; transform-origin: 30px 40px; filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.35)); }
#arrow svg { display: block; width: 100%; height: 100%; }
#arrow path { fill: #ffc21a; stroke: #7a4a00; stroke-width: 3; stroke-linejoin: round; }
#arrow[hidden] { display: none; }
#stickBase { position: absolute; width: 120px; height: 120px; margin: -60px 0 0 -60px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, 0.75); background: rgba(16, 32, 46, 0.18); pointer-events: none; }
#stickBase[hidden] { display: none; }
#stickKnob { position: absolute; left: 34px; top: 34px; width: 52px; height: 52px; border-radius: 50%; background: rgba(255, 255, 255, 0.85); box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3); }
/* R16.2 the throttle lever, up the left of the picture */
#lever { position: absolute; left: 6px; top: 40px; bottom: 54px; width: 60px; touch-action: none; cursor: ns-resize; }
#lever[hidden] { display: none; }
#leverTxt { position: absolute; left: 0; right: 0; top: 0; text-align: center; font: 800 14px ui-monospace, monospace; color: #fff; background: rgba(16, 32, 46, 0.55); border-radius: 8px; padding: 2px 0; }
#leverTrack { position: absolute; left: 8px; right: 8px; top: 48px; bottom: 22px; border-radius: 22px; background: rgba(16, 32, 46, 0.35); border: 2px solid rgba(255, 255, 255, 0.7); }
#leverFill { position: absolute; left: 0; right: 0; bottom: 0; height: 0; border-radius: 20px; background: rgba(255, 194, 26, 0.55); }
#leverKnob { position: absolute; left: -8px; right: -8px; height: 44px; bottom: -22px; border-radius: 14px; background: rgba(255, 255, 255, 0.92); box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35); }
#slowChip { position: absolute; left: 50%; top: 10px; transform: translateX(-50%); background: #b3261e; color: #fff; font-weight: 800; font-size: 18px; padding: 6px 14px; border-radius: 12px; pointer-events: none; white-space: nowrap; }
#slowChip[hidden] { display: none; }
/* R16.6 the runway's four lights, read large in the corner on the way down */
#papiRow { position: absolute; right: 8px; top: 8px; display: flex; gap: 6px; padding: 6px 8px; border-radius: 12px; background: rgba(16, 32, 46, 0.6); pointer-events: none; }
#papiRow[hidden] { display: none; }
#papiRow i { width: 18px; height: 18px; border-radius: 50%; background: #e0261b; box-shadow: 0 0 6px rgba(224, 38, 27, 0.8); }
#papiRow i.w { background: #ffffff; box-shadow: 0 0 6px rgba(255, 255, 255, 0.9); }
#hint { position: absolute; left: 0; right: 0; bottom: 14px; text-align: center; font-size: 34px; pointer-events: none; }
#glFail { position: absolute; inset: 12px; display: flex; align-items: center; justify-content: center; text-align: center; background: var(--shade); color: var(--ink); border-radius: 14px; padding: 16px; font-weight: 700; }
#glFail[hidden] { display: none; }
#fpsNow { position: absolute; top: 6px; left: 8px; font: 700 12px ui-monospace, monospace; color: var(--ink); background: var(--shade); border-radius: 6px; padding: 2px 6px; pointer-events: none; }
#acts { display: flex; align-items: center; gap: 8px; padding-bottom: env(safe-area-inset-bottom); min-height: 76px; }
#goalRow { flex: 1; min-width: 0; display: flex; flex-wrap: wrap; gap: 2px 4px; align-items: center; font-size: 22px; }
.goal { opacity: 0.45; }
.goal.next { opacity: 1; transform: scale(1.25); }
.goal.got { opacity: 1; filter: grayscale(0.2); }
.act.land { flex: none; width: 76px; height: 76px; border-radius: 22px; border: 3px solid var(--line); background: var(--bg2); font-size: 40px; cursor: pointer; font-family: inherit; color: var(--ink); }
.act.land:disabled { opacity: 0.35; cursor: default; }
.act.land.ready { border-color: var(--ready); background: var(--ready); box-shadow: 0 0 0 4px var(--bg), 0 0 0 7px var(--ready); }

/* landed, help and settings */
#scr-landed { align-items: center; justify-content: center; }
#landedBig { font-size: 72px; text-align: center; color: var(--star); }
.card2 { background: var(--bg2); border: 2px solid var(--line); border-radius: 16px; padding: 12px 14px; line-height: 1.45; display: flex; flex-direction: column; gap: 8px; }
.card2 h2 { font-size: 19px; }
.setRow { display: flex; flex-direction: column; gap: 6px; }
.setNote { color: var(--inkDim); font-weight: 600; font-size: 14px; text-align: center; }

#toast { position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--toastBg); color: var(--toastInk); padding: 10px 16px; border-radius: 14px; font-weight: 800; opacity: 0; transition: opacity 0.2s; pointer-events: none; max-width: 90%; text-align: center; z-index: 10; font-size: 20px; }
#toast.on { opacity: 1; }
#footer { display: flex; justify-content: center; padding: 2px 0 calc(2px + env(safe-area-inset-bottom)); }
@media (prefers-reduced-motion: reduce) { button.big:active { transform: none; } .goal.next { transform: none; } }
