/* Retro arcade look: pixel boxes, an 8-bit display font, a terminal body font, CRT scanlines.
   Palette: Sweetie 16 by GrafxKid. Deliberately single (dark) theme. */
:root {
  color-scheme: dark;
  --ink: #1a1c2c;
  --purple: #5d275d;
  --red: #b13e53;
  --orange: #ef7d57;
  --yellow: #ffcd75;
  --lime: #a7f070;
  --green: #38b764;
  --teal: #257179;
  --navy: #29366f;
  --blue: #3b5dc9;
  --sky: #41a6f6;
  --cyan: #73eff7;
  --white: #f4f4f4;
  --grey: #94b0c2;
  --slate: #566c86;
  --dark: #333c57;

  --px: 4px;                                   /* one "pixel" of UI chrome */
  --font-pixel: "Press Start 2P", "Courier New", monospace;
  --font-term: "VT323", "Courier New", monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--ink);
  color: var(--white);
  font-family: var(--font-term);
  font-size: 22px;
  line-height: 1.15;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.hidden { display: none !important; }
button { font-family: var(--font-pixel); }
:focus-visible { outline: var(--px) solid var(--yellow); outline-offset: 2px; }

#sky { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }


/* Stepped-corner panel, like a game cartridge label: white rim, ink face */
.notch { background: var(--white); padding: var(--px); clip-path: polygon(0 8px, 4px 8px, 4px 4px, 8px 4px, 8px 0, calc(100% - 8px) 0, calc(100% - 8px) 4px, calc(100% - 4px) 4px, calc(100% - 4px) 8px, 100% 8px, 100% calc(100% - 8px), calc(100% - 4px) calc(100% - 8px), calc(100% - 4px) calc(100% - 4px), calc(100% - 8px) calc(100% - 4px), calc(100% - 8px) 100%, 8px 100%, 8px calc(100% - 4px), 4px calc(100% - 4px), 4px calc(100% - 8px), 0 calc(100% - 8px)); }
.notch > .notch-in { background: var(--ink); height: 100%; clip-path: polygon(0 4px, 4px 4px, 4px 0, calc(100% - 4px) 0, calc(100% - 4px) 4px, 100% 4px, 100% calc(100% - 4px), calc(100% - 4px) calc(100% - 4px), calc(100% - 4px) 100%, 4px 100%, 4px calc(100% - 4px), 0 calc(100% - 4px)); }

.pix-btn {
  font-size: 12px; letter-spacing: .04em; color: var(--ink); cursor: pointer;
  background: var(--orange); border: var(--px) solid var(--ink);
  box-shadow: inset calc(var(--px) * -1) calc(var(--px) * -1) 0 var(--red), inset var(--px) var(--px) 0 var(--yellow);
  padding: 10px 14px;
}
.pix-btn:hover { filter: brightness(1.08); }
.pix-btn:active { box-shadow: inset var(--px) var(--px) 0 var(--red); transform: translateY(2px); }
.pix-btn:disabled { background: var(--slate); box-shadow: inset calc(var(--px) * -1) calc(var(--px) * -1) 0 var(--dark); color: var(--dark); cursor: default; }
.pix-btn.big { width: 100%; font-size: 16px; padding: 16px; }
.pix-btn.ghost {
  width: 100%; margin-top: 10px; background: var(--ink); color: var(--grey);
  border-color: var(--slate); box-shadow: none;
}
.pix-btn.ghost:hover { color: var(--white); border-color: var(--grey); }

/* ───────── HUD ───────── */
#hud { position: fixed; inset: 0; pointer-events: none; }
#hud > * { pointer-events: auto; }

.hud-top {
  display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; align-items: start;
  padding: calc(10px + env(safe-area-inset-top, 0px)) max(12px, env(safe-area-inset-right, 0px)) 0 calc(56px + env(safe-area-inset-left, 0px));
  max-width: 760px; margin: 0 auto;
  font-family: var(--font-pixel);
  text-shadow: 2px 2px 0 var(--ink), -2px 0 0 var(--ink), 0 -2px 0 var(--ink);
}
.stat { display: flex; flex-direction: column; gap: 6px; }
.stat.center { align-items: center; text-align: center; }
.stat.right { align-items: flex-end; }
.stat-label { font-size: 9px; color: var(--orange); }
.stat-label.hot { color: var(--yellow); }
.stat-value { font-size: 16px; color: var(--white); font-variant-numeric: tabular-nums; }
.stat-sub { font-family: var(--font-term); font-size: 17px; color: var(--cyan); white-space: nowrap; }
.stat-value.lcd { font-size: 12px; color: var(--lime); background: #0d0e17; border: 2px solid var(--slate); padding: 4px 5px; text-shadow: none; }

#question-panel {
  margin: 12px max(10px, calc((100% - 640px) / 2)) 0 max(calc(52px + env(safe-area-inset-left, 0px)), calc((100% - 640px) / 2));
}
#question-panel > .notch-in { padding: 10px 12px; }
#question-panel { position: relative; z-index: 2; }
#question-panel.shake { animation: shake .3s steps(4); background: var(--red); }
#question-panel.sputter { background: var(--red); animation: alarm .4s steps(1) infinite; }
@keyframes shake {
  0%,100% { transform: translate(0,0); } 25% { transform: translate(-8px,0); }
  50% { transform: translate(8px,0); } 75% { transform: translate(-4px,0); }
}
@keyframes alarm { 50% { background: var(--yellow); } }
#question-panel.done #answer-form, #question-panel.done .fuel, #question-panel.done .icon-btn,
#question-panel.done .kit, #question-panel.done .mission-event, #question-panel.done .combo { display: none; }

.q-meta { display: flex; align-items: center; gap: 8px; }
.chip {
  font-family: var(--font-pixel); font-size: 7px; color: var(--ink);
  background: var(--yellow); padding: 4px 5px;
}
.q-count { font-size: 18px; color: var(--grey); flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  font-size: 9px; color: var(--grey); background: var(--ink); cursor: pointer;
  border: 2px solid var(--slate); height: 26px; min-width: 28px; padding: 0 4px; flex: none;
}
.icon-btn:hover { color: var(--white); border-color: var(--grey); }
#q-text { font-family: var(--font-term); font-weight: 400; font-size: clamp(26px, 6.4vw, 34px); line-height: 1; margin: 8px 0 10px; text-wrap: balance; color: var(--white); }

.chip { white-space: nowrap; }
/* Difficulty pips on the category chip: one, two or three filled squares */
.lv { display: inline-flex; gap: 2px; margin-left: 3px; vertical-align: 0; }
.lv i { width: 5px; height: 5px; background: rgba(26,28,44,0.25); }
.lv i.on { background: var(--ink); }
.chip.combo { background: var(--cyan); animation: blink .4s steps(1) 3; }
.mission-event {
  margin-top: 8px; font-family: var(--font-pixel); font-size: 9px; line-height: 1.6;
  color: var(--ink); background: var(--red); padding: 5px 8px;
}
.mission-event.calm { background: var(--cyan); }
.kit { display: flex; gap: 8px; margin-top: 10px; }
.kit-btn {
  flex: 1; font-size: 9px; color: var(--yellow); background: var(--ink); cursor: pointer;
  border: 2px solid var(--yellow); padding: 6px 4px;
}
.kit-btn:hover:not(:disabled) { background: var(--yellow); color: var(--ink); }
.kit-btn:disabled { color: var(--slate); border-color: var(--dark); cursor: default; text-decoration: line-through; }
#answer-form { display: flex; gap: 8px; align-items: stretch; }
.prompt { font-family: var(--font-pixel); color: var(--lime); font-size: 14px; display: flex; align-items: center; }
#answer-input {
  flex: 1; min-width: 0; font-family: var(--font-term); font-size: 26px; color: var(--lime);
  background: #0f1020; border: 2px solid var(--slate); padding: 4px 10px; outline: none; border-radius: 0;
  caret-color: var(--lime);
}
#answer-input::placeholder { color: var(--slate); }
#answer-input:focus { border-color: var(--lime); }
#answer-input:disabled { opacity: .5; }

/* Fuel tank gauge: ten cells between E and F */
.fuel { margin-top: 10px; display: flex; gap: 6px; align-items: center; font-family: var(--font-pixel); font-size: 8px; }
.fuel-e { color: var(--orange); }
.fuel-f { color: var(--lime); }
.fuel-cells { flex: 1; display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); gap: 3px; border: 2px solid var(--slate); padding: 3px; background: #0d0e17; }
.fuel-cells span { height: 10px; background: var(--dark); }
.fuel-cells span.on { background: var(--lime); }
.fuel-cells.mid span.on { background: var(--yellow); }
.fuel-cells.low span.on { background: var(--red); animation: blink .5s steps(1) infinite; }
#fuel-secs { color: var(--white); min-width: 50px; text-align: right; }
@keyframes blink { 50% { opacity: .35; } }

#feedback { min-height: 24px; margin-top: 8px; font-size: 20px; color: var(--grey); }
#feedback.bad { color: var(--red); }
#feedback.good { color: var(--lime); }
.fb-line { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: flex-end; }
/* Fuel-grade meter: five bars, lit up to the grade of the answer */
.meter { display: flex; gap: 3px; align-items: flex-end; height: 26px; flex: none; }
.meter span { width: 9px; background: var(--dark); }
.meter .m1 { height: 8px; } .meter .m2 { height: 12px; } .meter .m3 { height: 17px; } .meter .m4 { height: 22px; } .meter .m5 { height: 26px; }
.meter .m1.on { background: var(--grey); } .meter .m2.on { background: var(--sky); } .meter .m3.on { background: var(--lime); }
.meter .m4.on { background: var(--yellow); } .meter .m5.on { background: var(--orange); }
.meter .cur { box-shadow: 0 0 0 2px var(--white); }
.fb-grade { font-family: var(--font-pixel); font-size: 10px; line-height: 1.4; }
.fb-pts { color: var(--lime); }
.g-fumes { color: var(--grey); } .g-kerosene { color: var(--sky); } .g-hydrogen { color: var(--lime); }
.g-plasma { color: var(--yellow); } .g-antimatter { color: var(--orange); }
.fb-detail { color: var(--grey); font-size: 19px; }
.fb-detail b { color: var(--white); font-weight: 400; }
.tier { font-family: var(--font-pixel); font-size: 9px; padding: 4px 6px; color: var(--ink); }
.t-fumes { background: var(--grey); } .t-kerosene { background: var(--sky); }
.t-hydrogen { background: var(--lime); } .t-plasma { background: var(--yellow); }
.t-antimatter { background: var(--orange); box-shadow: 0 0 0 2px var(--red); }

/* Altitude tower: the look's signature. Bands are to scale (0 to 200 km). */
#tower {
  position: fixed; left: calc(10px + env(safe-area-inset-left, 0px));
  top: calc(70px + env(safe-area-inset-top, 0px)); bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  width: 26px; border: var(--px) solid var(--ink); box-shadow: 0 0 0 var(--px) var(--white);
  display: flex; flex-direction: column; pointer-events: none !important;
}
.tw-band { position: relative; }
.tw-space { flex: 50; background: #0d0e17; }
.tw-space i { position: absolute; width: 3px; height: 3px; background: var(--white); }
.tw-space i:nth-child(1) { left: 4px; top: 8%; } .tw-space i:nth-child(2) { left: 12px; top: 40%; } .tw-space i:nth-child(3) { left: 6px; top: 75%; background: var(--grey); }
.tw-thermo { flex: 7.5; background: var(--navy); border-top: var(--px) solid var(--cyan); }
.tw-meso { flex: 17.5; background: var(--blue); border-top: 2px solid var(--ink); }
.tw-strato { flex: 19; background: var(--sky); border-top: 2px solid var(--ink); }
.tw-tropo { flex: 6; background: var(--cyan); border-top: 2px solid var(--ink); }
.tw-label { position: absolute; left: calc(100% + 12px); font-family: var(--font-pixel); font-size: 7px; text-shadow: 1px 1px 0 var(--ink); }
.tw-l-orbit { top: 2px; color: var(--yellow); }
.tw-l-space { bottom: 50%; color: var(--cyan); }
.tw-marker {
  position: absolute; left: -8px; right: -8px; bottom: 0; height: 6px; transform: translateY(50%);
  background: var(--yellow); box-shadow: 0 0 0 2px var(--ink); transition: bottom .2s linear;
}
.tw-marker span {
  position: absolute; left: calc(100% + 6px); top: 50%; transform: translateY(-50%);
  font-family: var(--font-pixel); font-size: 7px; color: var(--ink); background: var(--yellow); padding: 3px 4px; white-space: nowrap;
}

/* Flight events: a hazard-stripe ribbon slides across the screen */
#ribbon {
  position: fixed; left: 0; right: 0; top: 52%; z-index: 6; pointer-events: none !important;
  transform: translate(-105%, -50%); transition: transform .25s steps(5);
}
#ribbon.show { transform: translate(0, -50%); }
#ribbon::before, #ribbon::after {
  content: ""; display: block; height: 12px;
  background: repeating-linear-gradient(45deg, var(--yellow) 0 10px, var(--ink) 10px 20px);
}
.rb-in { background: var(--ink); padding: 10px 16px 8px calc(56px + env(safe-area-inset-left, 0px)); display: flex; flex-direction: column; gap: 6px; }
.rb-title { font-family: var(--font-pixel); font-size: clamp(14px, 4.6vw, 22px); }
.rb-sub { font-family: var(--font-pixel); font-size: 8px; color: var(--white); line-height: 1.5; }

#banner {
  position: fixed; left: calc(50% + 23px); top: 64%; transform: translate(-50%, -50%);
  font-family: var(--font-pixel); font-size: clamp(20px, 6.5vw, 40px); text-align: center; line-height: 1.3;
  opacity: 0; pointer-events: none; z-index: 5; width: max-content; max-width: calc(100vw - 32px);
  text-shadow: 4px 4px 0 var(--ink), -2px -2px 0 var(--ink), 2px -2px 0 var(--ink), -2px 2px 0 var(--ink);
}
#banner.show { opacity: 1; animation: pop .3s steps(3); }
@keyframes pop { from { transform: translate(-50%, -50%) scale(.6); } to { transform: translate(-50%, -50%) scale(1); } }
#banner small { display: block; font-size: .38em; margin-top: 10px; }

/* ───────── Flight training tips: a speech bubble from the mission patch ───────── */
.tip { position: fixed; z-index: 20; display: flex; gap: 8px; align-items: flex-start; --arrow-x: 50%; }
.tip .patch { width: 44px; height: 44px; flex: none; }
.tip-bubble { flex: 1; min-width: 0; background: var(--white); color: var(--ink); padding: 10px 12px; box-shadow: 4px 4px 0 #0d0e17; }
.tip::before {
  content: ""; position: absolute; left: var(--arrow-x); top: -14px; transform: translateX(-50%);
  border: 8px solid transparent; border-bottom-color: var(--white);
}
.tip.above::before { top: auto; bottom: -14px; border-bottom-color: transparent; border-top-color: var(--white); transform: translate(-50%, 2px); }
.tip-step { margin: 0 0 8px; font-family: var(--font-pixel); font-size: 8px; color: var(--red); }
.tip-text { font-size: 21px; line-height: 1.1; color: var(--ink); }
.tip-text b { font-weight: 400; background: var(--lime); padding: 0 3px; }
.tip-text .tier { display: inline-block; margin: 2px 0; }
.tip-actions { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 10px; }
.tip-skip { background: none; border: 0; color: var(--slate); font-size: 7px; cursor: pointer; padding: 6px 0; text-decoration: underline; }
.tip-skip:hover { color: var(--ink); }
.tip-target { outline: var(--px) solid var(--yellow); outline-offset: 3px; animation: tipglow .6s steps(1) infinite; position: relative; z-index: 15; }
@keyframes tipglow { 50% { outline-color: var(--orange); } }

/* ───────── Screens ───────── */
.screen {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  padding: calc(20px + env(safe-area-inset-top, 0px)) max(20px, env(safe-area-inset-right, 0px)) calc(20px + env(safe-area-inset-bottom, 0px)) max(20px, env(safe-area-inset-left, 0px));
  overflow-y: auto; background: rgba(26, 28, 44, .35);
}
.card { width: 100%; max-width: 520px; margin: auto; }
.card > .notch-in { padding: 22px 20px; }
.card.small { max-width: 380px; text-align: center; }
.card.wide { max-width: 640px; }

.eyebrow { margin: 0; font-family: var(--font-pixel); font-size: 9px; color: var(--cyan); letter-spacing: .06em; }
.logo { margin: 14px 0 16px; display: flex; flex-direction: column; gap: 10px; font-family: var(--font-pixel); font-weight: 400; line-height: 1; }
.logo span {
  font-size: clamp(30px, 9.5vw, 50px); color: var(--yellow);
  text-shadow: 3px 3px 0 var(--orange), 6px 6px 0 var(--red), 9px 9px 0 var(--purple);
}
.logo span + span { color: var(--white); text-shadow: 3px 3px 0 var(--sky), 6px 6px 0 var(--blue), 9px 9px 0 var(--navy); }
.screen-title { font-family: var(--font-pixel); font-weight: 400; font-size: 20px; margin: 4px 0 12px; color: var(--yellow); text-shadow: 3px 3px 0 var(--red); }
.screen-title.huge { font-size: clamp(24px, 7vw, 38px); line-height: 1.2; text-wrap: balance; }
.screen-title.win { color: var(--lime); text-shadow: 3px 3px 0 var(--teal); }
.lead { color: var(--grey); margin: 0 0 14px; font-size: 22px; }
.lead em, .lead b { font-style: normal; font-weight: 400; color: var(--white); }

/* Title: logo on the sky, rocket on the pad (drawn by the canvas), payload panel at the bottom */
.screen.title { flex-direction: column; justify-content: space-between; align-items: stretch; gap: 16px; background: none; }
.title-top { display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; }
.title .logo { margin: 4px 0 0; }
.title .eyebrow { background: var(--ink); padding: 5px 7px; }
.title .logo span { font-size: clamp(32px, 11vw, 54px); }
.tagline { margin: 6px 0 0; font-size: 24px; color: var(--ink); background: var(--yellow); padding: 0 8px; }
.title-panel { width: 100%; max-width: 480px; margin: 0 auto; flex: none; }
.title-panel > .notch-in { padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.title-panel .difficulty { margin: 0; }
.title-panel .select-label { margin: 0; }
.diff svg { width: 24px; height: 24px; }
.title-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.link-btn { background: none; border: 0; color: var(--cyan); font-size: 8px; cursor: pointer; padding: 6px 0; text-decoration: underline; }
.link-btn:hover { color: var(--yellow); }

.select-label { font-family: var(--font-pixel); font-size: 9px; color: var(--grey); margin: 0 0 8px; }
.difficulty { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.diff {
  font-size: 11px; color: var(--grey); background: var(--ink); cursor: pointer;
  border: var(--px) solid var(--slate); padding: 10px 4px;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.diff small { font-family: var(--font-term); font-size: 17px; }
.diff.active { color: var(--ink); background: var(--cyan); border-color: var(--yellow); }

.title-scores { font-family: var(--font-pixel); font-size: 8px; color: var(--yellow); font-variant-numeric: tabular-nums; }

/* Results: octagonal mission patch over the report card */
#result-screen { flex-direction: column; justify-content: flex-start; }
#result-screen .card { margin: 0 auto; }
.result-patch {
  flex: none; width: 110px; height: 110px; margin: 0 auto -44px; position: relative; z-index: 2;
  background: var(--yellow); clip-path: polygon(30% 0, 70% 0, 100% 30%, 100% 70%, 70% 100%, 30% 100%, 0 70%, 0 30%); display: flex; align-items: center; justify-content: center;
}
.rp-in {
  width: 98px; height: 98px; background: var(--navy); clip-path: polygon(30% 0, 70% 0, 100% 30%, 100% 70%, 70% 100%, 30% 100%, 0 70%, 0 30%);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  font-family: var(--font-pixel); text-align: center;
}
.rp-top { font-size: 6px; color: var(--yellow); }
.rp-name { font-size: 8px; line-height: 1.4; color: var(--white); max-width: 84px; overflow-wrap: anywhere; }
.rp-stars { font-size: 8px; color: var(--lime); min-height: 8px; }
.result-patch.lost { background: var(--red); }
.result-patch.lost .rp-in { background: var(--ink); }
.result-card > .notch-in { padding-top: 52px; }
.score-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin-bottom: 16px; }
.score-cell { border: 2px solid var(--slate); padding: 8px 10px; }
.score-cell .k { font-family: var(--font-pixel); font-size: 7px; color: var(--grey); }
.score-cell .v { font-family: var(--font-pixel); font-size: 12px; margin-top: 8px; font-variant-numeric: tabular-nums; }
.score-cell.total { border-color: var(--yellow); }
.score-cell.total .v { color: var(--yellow); }

.section-title, #result-board h3 { font-family: var(--font-pixel); font-weight: 400; font-size: 10px; color: var(--red); margin: 6px 0 10px; }
.hiscore { margin-bottom: 14px; }
#hiscore-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font-family: var(--font-pixel); font-size: 11px; }
#hiscore-list li { display: grid; grid-template-columns: 40px 60px 1fr; gap: 8px; color: var(--grey); font-variant-numeric: tabular-nums; }
#hiscore-list li.me { color: var(--yellow); animation: blink .6s steps(1) 6; }
#initials-form { margin-bottom: 12px; }
#initials-form label { display: block; font-family: var(--font-pixel); font-size: 9px; color: var(--lime); margin-bottom: 8px; line-height: 1.6; }
.initials-row { display: flex; gap: 8px; }
#initials-input {
  width: 110px; font-family: var(--font-pixel); font-size: 20px; text-transform: uppercase; letter-spacing: .2em;
  color: var(--yellow); background: #0f1020; border: 2px solid var(--yellow); padding: 6px 8px; border-radius: 0;
}
.board-q { margin: 0 0 8px; color: var(--white); }
.board { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; max-height: 190px; overflow-y: auto; }
.pill { font-size: 18px; padding: 0 6px; border: 2px solid var(--slate); color: var(--grey); }
.pill b { font-weight: 400; color: var(--slate); margin-left: 4px; }
.pill.deep { border-color: var(--orange); color: var(--yellow); }

#flight-log { margin: 0 0 18px; padding-left: 26px; display: grid; gap: 4px; font-size: 19px; color: var(--grey); max-height: 220px; overflow-y: auto; }
#flight-log li b { color: var(--white); font-weight: 400; }
#flight-log .tier { font-size: 7px; padding: 2px 4px; margin: 0 4px; vertical-align: 2px; }

@media (max-width: 420px) {
  .stat-sub { font-size: 14px; }
  .stat-value { font-size: 14px; }
}
@media (max-height: 660px) {
  #q-text { margin: 4px 0 6px; font-size: 24px; }
  #question-panel > .notch-in { padding: 8px 10px; }
  .fuel { margin-top: 6px; }
}
@media (prefers-reduced-motion: reduce) {
  .tip-target { animation: none; }
  #ribbon { transition: none; }
  #question-panel.shake, #question-panel.sputter, .fuel-cells.low span.on, #banner.show, #hiscore-list li.me { animation: none; }
}
