/* Styles every game shares: page basics, corner buttons, the tracing board, answer buttons, pop-up sheets. */
/* Layout: one full-screen railway scene. Station sign on top, the word train on the track, tracing board as an overlay. */
:root {
  --sky-top: #8fd3f4;
  --sky-low: #dff4fb;
  --grass: #7cc36a;
  --grass-dark: #5aa852;
  --ink: #2b2d42;
  --paper: #fffaf0;
  --rail: #5b4636;
  --tie: #a9825a;
  --engine: #e2483d;
  --engine-dark: #b5322a;
  --gold: #ffc94a;
  --go: #2fb573;
  --trace: #3d7bea;
  --guide: #e6dcc8;
  --font: "Fredoka", ui-rounded, "Arial Rounded MT Bold", "Trebuchet MS", system-ui, sans-serif;
  --eng: #e2483d;
  --eng-dark: #b5322a;
  color-scheme: light;
}
html, body { height: 100%; }
[hidden] { display: none !important; }
body {
  margin: 0; overflow: hidden; background: var(--sky-top); color: var(--ink);
  /* As a home-screen app the page runs under the status bar: keep content below it; the background colours the strip. */
  box-sizing: border-box; padding-top: env(safe-area-inset-top, 0px);
  font-family: var(--font); font-weight: 700;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent; touch-action: none; overscroll-behavior: none;
}
button { font: inherit; color: inherit; border: 0; background: none; padding: 0; cursor: pointer; touch-action: manipulation; }
button:focus-visible { outline: 4px solid var(--ink); outline-offset: 3px; }
@keyframes pop { 40% { scale: 1.12; } }

/* --- top corner buttons --- */
.corner { position: absolute; top: max(3%, 10px); display: flex; gap: 10px; align-items: center; }
#choices:not([hidden]) + #stars { display: none; }
.corner.right { right: max(16px, env(safe-area-inset-right, 0px)); }
.chip { min-width: 48px; height: 48px; padding: 0 12px; border-radius: 99px; background: var(--paper);
  border: 3px solid var(--ink); font-size: 22px; display: grid; place-items: center; }
@keyframes spin { to { rotate: 360deg; } }
@keyframes wiggle { 20% { rotate: -5deg; } 50% { rotate: 5deg; } 80% { rotate: -3deg; } }
@keyframes hop { 50% { translate: 0 calc(var(--u) * -.1); } }

/* --- tracing board --- */
#trace, .sheet { position: absolute; inset: 0; z-index: 5; display: grid; place-items: center;
  background: rgba(43, 45, 66, .55); padding-block: 12px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.board { position: relative; background: var(--paper); border: 5px solid var(--ink); border-radius: 28px;
  box-shadow: 0 8px 0 var(--ink); padding: 10px; animation: rise .3s cubic-bezier(.3, 1.4, .5, 1); }
@keyframes rise { from { scale: .7; opacity: 0; } }
.board .hd { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: clamp(18px, 3.4vh, 30px); padding: 0 4px; }
#pad { display: block; width: min(84vw, 60vh); aspect-ratio: 130 / 150; touch-action: none; }
#pad .guide { fill: none; stroke: var(--guide); stroke-width: 15; stroke-linecap: round; stroke-linejoin: round; }
#pad .ties { fill: none; stroke: #fff; stroke-width: 9; stroke-dasharray: 1.5 5; opacity: .9; }
#pad .fill { fill: none; stroke: var(--trace); stroke-width: 15; stroke-linecap: round; stroke-linejoin: round; }
#pad .ink { fill: none; stroke: var(--ink); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; opacity: .35; }
#pad .startdot { fill: var(--go); stroke: #fff; stroke-width: 2; }
#pad .num { font: 700 8px var(--font); fill: #fff; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
#pad .ghost { fill: #fff; stroke: var(--go); stroke-width: 2; }
#pad .cursor { fill: var(--gold); stroke: var(--ink); stroke-width: 2; }
#pad.done .fill { stroke: var(--go); transition: stroke .2s; }

#pad .rule { stroke: #cfe3f5; stroke-width: 1; stroke-dasharray: 3 3; }
#traceTitle span { margin-left: .06em; color: #b9b3a3; }
#traceTitle span.now { color: var(--trace); font-size: 1.25em; }
#traceTitle span.did { color: var(--go); }
.choice.dice { font-size: min(calc(var(--u) * .5), 11vh); background: var(--gold); animation: hop 1s ease-in-out infinite; }
.choice.dice.rolling { animation: spin .35s linear infinite; }
.choice.right { box-shadow: 0 0 0 calc(var(--u) * .05) var(--gold); }
#toast { position: absolute; z-index: 8; left: 50%; top: 30%; translate: -50% 0; padding: .5em 1em; white-space: nowrap;
  background: var(--gold); border: 4px solid var(--ink); border-radius: 99px; box-shadow: 0 5px 0 var(--ink);
  font-size: clamp(18px, 4vh, 32px); animation: rise .35s cubic-bezier(.3, 1.4, .5, 1); pointer-events: none; }
#choices { position: absolute; left: 0; right: 0; bottom: 2.5%; z-index: 2; display: flex; justify-content: center;
  gap: calc(var(--u) * .2); padding: 0 16px; }
.choice { min-width: calc(var(--u) * .8); height: min(calc(var(--u) * .62), 15vh); padding: 0 calc(var(--u) * .16);
  font-size: min(calc(var(--u) * .42), 10vh); background: var(--paper); border: calc(var(--u) * .035) solid var(--ink);
  border-radius: calc(var(--u) * .14); box-shadow: 0 calc(var(--u) * .04) 0 var(--ink); }
.choice.wiggle { animation: wiggle .4s; }
.choice.small { min-width: 0; width: 100%; height: auto; aspect-ratio: 1; padding: 0; font-size: clamp(18px, 4.4vh, 34px);
  border-width: 3px; border-radius: 14px; box-shadow: 0 3px 0 var(--ink); }

/* --- pop-up sheets: letter picker, engine shed, railway --- */
.sheet { z-index: 7; }
.sheet .board { width: min(92vw, 640px); max-height: 92%; display: grid; gap: 10px; overflow: hidden; box-sizing: border-box; }
#trialTag { font-size: 15px; background: var(--gold); }
.chip { text-decoration: none; box-sizing: border-box; }

.confetti { position: absolute; top: -8%; z-index: 4; font-size: calc(var(--u) * .3); pointer-events: none; animation: fall 2.2s ease-in forwards; }
@keyframes fall { to { translate: 0 120vh; rotate: 540deg; } }

/* Bonus rounds (shared by Math Rockets, Puzzle Ships and Physics Trucks) */
.bonus-dice, .bonus-choice { color: #2b2d42; background: #fffaf0; border: 4px solid #2b2d42; border-radius: 18px; box-shadow: 0 5px 0 #2b2d42;
  font-size: min(calc(var(--u) * .42), 9vh); min-width: calc(var(--u) * .8); height: min(calc(var(--u) * .66), 14vh); padding: 0 calc(var(--u) * .18); }
.bonus-dice { background: #ffc94a; font-size: min(calc(var(--u) * .5), 11vh); animation: hop 1s ease-in-out infinite; }
.bonus-dice.rolling { animation: spin .35s linear infinite; }
.bonus-choice.wiggle { animation: wiggle .4s; }
.bonus-choice.right { box-shadow: 0 0 0 6px #ffc94a; }
.bonus-stage { display: flex; align-items: center; justify-content: center; gap: calc(var(--u) * .16); flex-wrap: wrap; }
.bonus-pics { font-size: min(calc(var(--u) * .5), 10vh); line-height: 1.15; max-width: calc(var(--u) * 3.2); text-align: center; letter-spacing: .05em; }
.bonus-op { font-size: calc(var(--u) * .5); }

/* "Play again or all games?" after a level */
.again { position: absolute; inset: 0; z-index: 9; display: grid; place-items: center; background: rgba(43, 45, 66, .6); padding: 16px; }
.again-card { display: grid; gap: 2.4vh; justify-items: stretch; text-align: center; padding: 3vh 4vw; background: #fffaf0; color: #2b2d42;
  border: 5px solid #2b2d42; border-radius: 28px; box-shadow: 0 8px 0 #2b2d42; animation: rise .3s cubic-bezier(.3, 1.4, .5, 1); }
.again-card p { margin: 0; font-size: clamp(22px, 5vh, 40px); }
.again-card button { font-size: clamp(22px, 5vh, 40px); padding: .45em 1.2em; color: #2b2d42; background: #ffc94a; border: 4px solid #2b2d42; border-radius: 99px; box-shadow: 0 6px 0 #2b2d42; white-space: nowrap; }
.again-card button[data-again="again"] { background: #2fb573; color: #fff; }

/* The time gate's stop screen */
.gate { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 20px; background: linear-gradient(#1b2150, #3a2a6e); color: #fff; text-align: center; }
.gate-card { display: grid; gap: 2vh; justify-items: center; max-width: 520px; }
.gate-pic { font-size: clamp(70px, 20vh, 160px); line-height: 1; }
.gate h1 { margin: 0; font-size: clamp(28px, 6vh, 56px); line-height: 1.1; }
.gate p { margin: 0; font-size: clamp(18px, 3.4vh, 28px); font-weight: 500; }
.gate a { color: #fff; font-size: 16px; font-weight: 500; margin-top: 3vh; }
