:root {
  color-scheme: dark;
  --space: #141a33;
  --deep: #0c1024;
  --panel: #1e2648;
  --line: #34407a;
  --ink: #eef0fb;
  --muted: #a9b1d6;
  --amber: #ffb84d;
  --teal: #4fd6c4;
  --coral: #ff7a6b;
  --display: "Chakra Petch", "Trebuchet MS", sans-serif;
  --body: "Atkinson Hyperlegible", system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; background: var(--space); color: var(--ink); font: 17px/1.45 var(--body); overscroll-behavior: none; }
body { touch-action: manipulation; user-select: none; -webkit-user-select: none; }
#app { position: fixed; inset: 0; height: 100dvh; }
h1, h2, h3 { font-family: var(--display); margin: 0; line-height: 1.15; text-wrap: balance; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
[hidden] { display: none !important; }

.screen { position: absolute; inset: 0; display: none; flex-direction: column; align-items: center; gap: 18px;
  padding: calc(20px + env(safe-area-inset-top)) calc(18px + env(safe-area-inset-right)) calc(20px + env(safe-area-inset-bottom)) calc(18px + env(safe-area-inset-left));
  overflow-y: auto; }
.screen.active { display: flex; }
.logo { font-size: clamp(2.2rem, 9vw, 4rem); letter-spacing: .04em; margin-top: 4vh; }
.logo span { color: var(--amber); }
.hint { color: var(--muted); font-size: .9rem; margin: 0; text-align: center; }

.btn { font: 700 1.05rem var(--display); color: var(--ink); background: var(--panel); border: 2px solid var(--line); border-radius: 12px;
  padding: 14px 22px; min-height: 52px; cursor: pointer; }
.btn.primary { background: var(--amber); border-color: var(--amber); color: var(--deep); }
.btn.ghost { background: transparent; }
.btn.small { padding: 8px 14px; min-height: 44px; font-size: .95rem; }
.btn.danger { border-color: var(--coral); color: var(--coral); background: transparent; }
.btn:active { transform: scale(.97); }
:focus-visible { outline: 3px solid var(--teal); outline-offset: 2px; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 22px; display: flex; flex-direction: column; gap: 14px; width: min(100%, 460px); }
.panel.center { align-items: center; text-align: center; margin: auto; }
.row { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
label, .label { font-family: var(--display); color: var(--muted); font-size: .9rem; text-transform: uppercase; letter-spacing: .06em; }
input[type=text] { font: 700 1.3rem var(--display); color: var(--ink); background: var(--deep); border: 2px solid var(--line); border-radius: 10px; padding: 12px 14px; width: 100%; user-select: text; -webkit-user-select: text; }

/* pilots */
.pilot-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; width: min(100%, 680px); }
.pilot { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 18px 12px; min-height: 150px; }
.pilot svg { width: 56px; height: 56px; }
.pilot .name { font-size: 1.25rem; overflow-wrap: anywhere; }
.pilot .sub { font: 400 .85rem var(--body); color: var(--muted); }
.pilot.add { border-style: dashed; justify-content: center; color: var(--muted); }
.swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch { width: 52px; height: 52px; border-radius: 12px; border: 3px solid transparent; background: var(--deep); cursor: pointer; padding: 6px; }
.swatch[aria-pressed=true] { border-color: var(--ink); }

/* map */
.bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: min(100%, 680px); }
.who { display: flex; align-items: center; gap: 10px; font-family: var(--display); min-width: 0; }
.who svg { width: 36px; height: 36px; flex: none; }
.who .sub { font: 400 .85rem var(--body); color: var(--muted); }
.gear { position: relative; width: 48px; height: 48px; border-radius: 50%; border: 2px solid var(--line); background: transparent; color: var(--muted); display: grid; place-items: center; cursor: pointer; touch-action: none; }
.gear::after { content: ""; position: absolute; inset: -4px; border-radius: 50%; border: 4px solid var(--teal); clip-path: inset(100% 0 0 0); }
.gear.holding::after { clip-path: inset(0 0 0 0); transition: clip-path 2s linear; }
.mission-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; width: min(100%, 680px); }
.mission { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left; padding: 14px 16px; min-height: 104px; }
.mission .num { font: 700 .8rem var(--display); color: var(--op, var(--teal)); letter-spacing: .08em; }
.mission .facts { font: 400 .95rem var(--body); color: var(--muted); }
.mission .stars { font-size: 1.3rem; letter-spacing: 3px; margin-top: auto; }
.mission.next { border-color: var(--op, var(--amber)); box-shadow: 0 0 0 3px color-mix(in srgb, var(--op, var(--amber)) 30%, transparent); }
.mission:disabled { opacity: .45; cursor: default; }
.star-on { color: var(--amber); }
.star-off { color: var(--line); }

/* play */
#s-play { padding: 0; gap: 0; overflow: hidden; background: var(--deep); }
.hud { display: flex; align-items: center; gap: 12px; width: 100%; padding: calc(8px + env(safe-area-inset-top)) 12px 8px; font-family: var(--display); font-weight: 700; }
.hud-item { color: var(--muted); font-size: .9rem; white-space: nowrap; }
.hud-score { flex: 1; text-align: center; font-size: 1.5rem; color: var(--amber); font-variant-numeric: tabular-nums; }
.hud-mult { min-width: 2.4em; color: var(--teal); font-size: 1.1rem; }
.hud-shields { display: flex; gap: 4px; }
.hud-shields svg { width: 24px; height: 26px; }
.stage { position: relative; flex: 1; min-height: 0; width: 100%; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }
.console { width: 100%; text-align: center; font: 700 clamp(2rem, 8vw, 3.2rem) var(--display); padding: 10px 12px calc(12px + env(safe-area-inset-bottom));
  background: var(--panel); border-top: 2px solid var(--line); font-variant-numeric: tabular-nums; min-height: 1.9em; }
.console.good { color: var(--teal); }
.console.bad { color: var(--ink); border-top-color: var(--coral); }
.console .ans { color: var(--deep); background: var(--teal); border-radius: 10px; padding: 0 .3em; }
#s-play.bonus .console { border-top-color: var(--amber); }
#s-play.bonus .console::before { content: "★ BONUS: answer fast to count double"; display: block; font-size: .95rem; letter-spacing: .05em; color: var(--amber); }
.overlay { position: absolute; inset: 0; background: rgba(12, 16, 36, .85); display: flex; padding: 20px; }

/* result */
.result .big { font: 700 2.6rem var(--display); color: var(--amber); font-variant-numeric: tabular-nums; }
.result .stars { font-size: 2.6rem; letter-spacing: 6px; }
.result .rankup { color: var(--teal); font-family: var(--display); font-weight: 700; }
.missed { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.missed li { background: var(--deep); border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; font: 700 1.15rem var(--display); }
.muted { color: var(--muted); margin: 0; }

/* settings */
.settings { display: flex; flex-direction: column; gap: 22px; width: min(100%, 680px); }
.settings section { display: flex; flex-direction: column; gap: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { font: 700 1rem var(--display); min-width: 48px; min-height: 44px; border-radius: 10px; border: 2px solid var(--line); background: transparent; color: var(--muted); cursor: pointer; padding: 6px 14px; }
.chip[aria-pressed=true] { background: var(--teal); border-color: var(--teal); color: var(--deep); }
.gridwrap { overflow-x: auto; }
.factgrid { border-collapse: separate; border-spacing: 3px; font: 700 .8rem var(--display); }
.factgrid th { color: var(--muted); width: 30px; height: 30px; }
.factgrid td { width: 30px; height: 30px; border-radius: 5px; text-align: center; color: var(--deep); }
.c-new { background: var(--line); }
.c-fast { background: var(--teal); }
.c-slow { background: var(--amber); }
.c-missed { background: var(--coral); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; color: var(--muted); font-size: .9rem; }
.legend i { display: inline-block; width: 14px; height: 14px; border-radius: 3px; vertical-align: -2px; margin-right: 6px; }

@media (prefers-reduced-motion: reduce) { .btn:active { transform: none; } }

/* map choices */
.chips.center { justify-content: center; width: min(100%, 680px); }
.chips:empty { display: none; }
.chip small { display: block; font: 400 .78rem var(--body); opacity: .8; }
.mission.free { border-style: dashed; }
.mission.free .num { color: var(--amber); }
.btn:disabled { opacity: .45; cursor: default; }
.settings .chips + .chips { margin-top: 4px; }
.factgrid { margin-bottom: 10px; }

/* Fuel-Up: keypad under the scene, or beside it on wide screens */
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; width: 100%; padding: 10px 12px calc(12px + env(safe-area-inset-bottom)); background: var(--panel); }
.key { font: 700 1.7rem var(--display); color: var(--ink); background: var(--deep); border: 2px solid var(--line); border-radius: 12px; min-height: 54px; cursor: pointer; touch-action: none; }
.key:active { background: var(--amber); color: var(--deep); border-color: var(--amber); }
.key.fn { color: var(--muted); }
#s-play.fuel .console { padding-bottom: 10px; border-bottom: 0; }
@media (min-aspect-ratio: 5/4) {
  #s-play.fuel.active { display: grid; align-items: stretch; grid-template: "hud hud" auto "stage keypad" 1fr "console keypad" auto / 1fr minmax(240px, 34%); }
  #s-play.fuel .hud { grid-area: hud; }
  #s-play.fuel .stage { grid-area: stage; }
  #s-play.fuel .console { grid-area: console; padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  #s-play.fuel .keypad { grid-area: keypad; height: 100%; grid-auto-rows: 1fr; border-left: 2px solid var(--line); }
}

/* map title changes with the game and the kind of fact */
.map-title { text-align: center; }
.map-title span { color: var(--op, var(--amber)); }
#s-map .chip[data-act=set-op][aria-pressed=true] { background: var(--op); border-color: var(--op); }

/* Tock the robot */
.buddy { position: absolute; left: 8px; bottom: 6px; width: clamp(48px, 13vw, 84px); pointer-events: none; }
.buddy svg { display: block; width: 100%; height: auto; }
.buddy.big { position: static; width: 110px; }
.buddy[data-mood=cheer] { animation: hop .35s ease-out; }
.buddy[data-mood=oops] { animation: wobble .4s ease-in-out; }
@keyframes hop { 40% { transform: translateY(-12px); } }
@keyframes wobble { 25% { transform: rotate(-8deg); } 75% { transform: rotate(8deg); } }

/* streak flames: the multiplier heats up */
/* only transform is animated: animating the glow itself forces a repaint every frame */
#s-play.flames .hud-mult.hot { color: var(--amber); text-shadow: 0 0 10px var(--coral), 0 -3px 14px var(--amber); animation: flicker .5s infinite alternate; will-change: transform; }
@keyframes flicker { to { transform: scale(1.14); } }

/* star-chart mission map */
.mission-list.chartmode { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.chart { width: min(100%, 460px); height: auto; font-family: var(--display); }
.chart .planet:not(.locked) { cursor: pointer; }
.chart .planet:focus-visible { outline: 3px solid var(--teal); outline-offset: 4px; }
/* the pulsing ring is a separate layer over the chart, so the big drawing underneath is painted once */
.chartwrap { position: relative; }
.ring { position: absolute; width: 20%; height: 0; padding-bottom: 20%; margin: -10% 0 0 -10%; border-radius: 50%; box-shadow: 0 0 0 4px var(--op, var(--amber)); pointer-events: none; animation: pulse 1.4s ease-in-out infinite; will-change: transform, opacity; }
@keyframes pulse { 50% { transform: scale(1.16); opacity: .35; } }

/* grown-up screen: tabs, progress, mission log */
.tabs { width: min(100%, 680px); }
.tabs .chip { flex: 1; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.pager strong { font-family: var(--display); text-align: center; }
.summary { margin: 0; font-size: 1.05rem; }
.summary b { color: var(--amber); }
.grids { display: flex; flex-wrap: wrap; gap: 8px 28px; }
.factgrid caption { text-align: left; font: 700 .9rem var(--display); color: var(--muted); padding: 0 0 4px 3px; }
.settings label { text-transform: none; letter-spacing: 0; font: 400 1rem var(--body); }
.log h3 { margin-top: 10px; }
.logrow { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; display: flex; flex-direction: column; gap: 2px; }
.logrow .muted { font-size: .92rem; }
.logrow .bad { color: var(--coral); }
.logrow .star-on, .logrow .star-off { letter-spacing: 2px; }

@media (prefers-reduced-motion: reduce) { .buddy, .ring, #s-play.flames .hud-mult.hot { animation: none !important; } }

/* the star chart lives in a fixed window that scrolls on its own */
.chartbox { width: min(100%, 460px); height: min(52vh, 480px); height: min(52dvh, 480px); overflow-y: auto; overscroll-behavior: contain; background: var(--deep); border: 2px solid var(--line); border-radius: 16px; }
.chartbox .chart { width: 100%; display: block; }
