/* Word Trains: the railway scene, the train, the depot and the home screen. */

#app { --n: 3; --u: min(calc(82vw / (var(--n) + 1.9)), 25vh);
  position: relative; height: 100%; overflow: hidden;
  background: linear-gradient(var(--sky-top), var(--sky-low) 70%); }

/* --- scenery --- */
.sun { position: absolute; top: 5%; right: 7%; width: calc(var(--u) * .6); aspect-ratio: 1; border-radius: 50%;
  background: var(--gold); box-shadow: 0 0 0 calc(var(--u) * .08) rgba(255, 201, 74, .35); }
.cloud { position: absolute; width: calc(var(--u) * 1.1); height: calc(var(--u) * .32); border-radius: 99px;
  background: #fff; opacity: .9; animation: drift 60s linear infinite; }
.cloud::before, .cloud::after { content: ""; position: absolute; background: #fff; border-radius: 50%; }
.cloud::before { width: 45%; aspect-ratio: 1; left: 14%; bottom: 30%; }
.cloud::after { width: 34%; aspect-ratio: 1; right: 16%; bottom: 35%; }
.cloud.c1 { top: 9%; left: 6%; }
.cloud.c2 { top: 30%; left: 62%; animation-duration: 85s; scale: .7; }
@keyframes drift { from { translate: -30vw 0; } to { translate: 110vw 0; } }
.hill { position: absolute; border-radius: 50%; background: var(--grass-dark); }
.hill.h1 { width: 70%; height: 34%; left: -15%; bottom: 8%; }
.hill.h2 { width: 80%; height: 30%; right: -22%; bottom: 9%; background: #6bb65d; }
.ground { position: absolute; left: 0; right: 0; bottom: 0; height: 21%; background: var(--grass); }
.track { position: absolute; left: 0; right: 0; bottom: calc(20% - var(--u) * .11); height: calc(var(--u) * .11);
  background: repeating-linear-gradient(90deg, var(--tie) 0 calc(var(--u) * .09), transparent 0 calc(var(--u) * .26));
  border-top: calc(var(--u) * .035) solid var(--rail); box-sizing: border-box; }

/* --- station sign --- */
#sign { position: absolute; top: max(3%, 10px); left: 50%; translate: -50% 0; display: flex; align-items: center;
  gap: calc(var(--u) * .16); padding: calc(var(--u) * .08) calc(var(--u) * .26);
  background: var(--paper); border: calc(var(--u) * .04) solid var(--ink); border-radius: calc(var(--u) * .2);
  box-shadow: 0 calc(var(--u) * .05) 0 var(--ink); white-space: nowrap; }
#sign .pic { font-size: calc(var(--u) * .62); line-height: 1.1; }
#sign .word { font-size: calc(var(--u) * .5); letter-spacing: .08em; }
#sign .word span.new { color: var(--engine); }
#sign.pop { animation: pop .45s; }
#sign.done { background: #dff7e8; }
/* Stars sit on the grass under the train, out of the sign's way. */
#stars { position: absolute; left: 0; right: 0; bottom: 5%; text-align: center; font-size: min(calc(var(--u) * .22), 6vh); line-height: 1; pointer-events: none; }

/* --- train --- */
#train { position: absolute; left: 0; right: 0; bottom: 20%; display: flex; justify-content: center;
  align-items: flex-end; gap: calc(var(--u) * .07); transition: transform 1.7s cubic-bezier(.2, .7, .3, 1); }
#train.off-left { transform: translateX(-130vw); transition: none; }
#train.off-right { transform: translateX(130vw); transition: transform 1.8s cubic-bezier(.6, 0, .9, .5); }
.car { position: relative; flex: none; width: calc(var(--u) * var(--w, 1)); height: calc(var(--u) * .78); margin-bottom: calc(var(--u) * .13);
  border-radius: calc(var(--u) * .14); background: var(--c, #ffd166); border: calc(var(--u) * .04) solid var(--ink);
  box-sizing: border-box; display: grid; place-items: center; font-size: calc(var(--u) * .6); line-height: 1; }
.car::before { content: ""; position: absolute; right: 100%; bottom: 12%; width: calc(var(--u) * .12);
  height: calc(var(--u) * .05); background: var(--ink); }
.car::after { content: ""; position: absolute; inset: 8% 8% auto; height: 10%; border-radius: 99px; background: rgba(255,255,255,.45); }
.car:first-child::before { display: none; }
.car .letter { position: relative; z-index: 1; }
.wheel { position: absolute; bottom: calc(var(--u) * -.2); width: calc(var(--u) * .26); aspect-ratio: 1; border-radius: 50%;
  background: conic-gradient(var(--ink) 0 25%, #6b6f8a 0 50%, var(--ink) 0 75%, #6b6f8a 0); border: calc(var(--u) * .03) solid var(--ink); box-sizing: border-box; }
.wheel.a { left: 12%; } .wheel.b { right: 12%; }
#train.moving .wheel, #train.moving .ewheel { animation: spin .6s linear infinite; }
.car.wiggle { animation: wiggle .4s; }
.car.hint { animation: hop 1s ease-in-out infinite; box-shadow: 0 0 0 calc(var(--u) * .05) var(--gold); }
.car.swap .letter { animation: drop .6s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes drop { from { translate: 0 calc(var(--u) * -1.2); scale: 1.6; opacity: 0; } }
.engine { position: relative; width: calc(var(--u) * 1.45); height: calc(var(--u) * 1.16); flex: none; }
/* The coupling between the last car and the engine. */
.engine::before { content: ""; position: absolute; left: calc(var(--u) * -.1); bottom: calc(var(--u) * .2); width: calc(var(--u) * .2);
  height: calc(var(--u) * .05); background: var(--ink); border-radius: 99px; }
.engine svg { display: block; width: 100%; height: 100%; overflow: visible; }
.ewheel { transform-box: fill-box; transform-origin: center; }
.puff { position: absolute; left: 68%; top: 2%; width: calc(var(--u) * .16); aspect-ratio: 1; border-radius: 50%;
  background: #fff; opacity: 0; animation: puff 2.4s ease-out infinite; }
.puff:nth-child(2) { animation-delay: .8s; } .puff:nth-child(3) { animation-delay: 1.6s; }
@keyframes puff { 0% { opacity: .9; scale: .5; translate: 0 0; } 100% { opacity: 0; scale: 2; translate: calc(var(--u) * -.5) calc(var(--u) * -.7); } }

/* --- cars in the build, missing-car and yard games --- */
.car.blank { background: rgba(255, 255, 255, .55); border-style: dashed; color: #8d90a8; }
.car.selected { translate: 0 calc(var(--u) * -.12); box-shadow: 0 0 0 calc(var(--u) * .05) var(--gold); }
#sign .word.sentence { letter-spacing: .02em; font-size: calc(var(--u) * .42); }
#sign .word.sentence span + span { margin-left: .35em; }
#sign .word.question { font-size: calc(var(--u) * .3); letter-spacing: 0; white-space: normal; max-width: 62vw; line-height: 1.15; text-align: left; }
/* --- train depot: a yard of sidings, one small word train on each --- */
#app.depot-mode #train, #app.depot-mode .track, #app.depot-mode #stars { display: none; }
#sidings { --du: min(calc(40vw / (var(--len, 3) + 2.6)), 11vh);
  position: absolute; z-index: 2; top: calc(max(3%, 10px) + var(--u) * 1.02); bottom: 3%;
  left: max(16px, env(safe-area-inset-left, 0px)); right: max(16px, env(safe-area-inset-right, 0px));
  display: grid; grid-template-rows: auto 1fr; gap: 8px; }
#lenTabs { display: flex; gap: 8px; justify-content: center; }
#lenTabs button { padding: 4px 14px; border-radius: 99px; background: var(--paper); border: 3px solid var(--ink); font-size: clamp(14px, 2.6vh, 20px); }
#lenTabs button[aria-pressed="true"] { background: var(--ink); color: #fff; }
#tracks { display: grid; grid-template-columns: 1fr 1fr; grid-auto-rows: 1fr; gap: 4px 18px; min-height: 0;
  background: #d9cfba; border: 4px solid var(--ink); border-radius: 22px; padding: 8px 16px; }
.siding { position: relative; display: flex; align-items: flex-end; justify-content: center; overflow: hidden; min-height: 0;
  padding-bottom: calc(var(--du) * .16);
  background: repeating-linear-gradient(90deg, var(--tie) 0 calc(var(--du) * .1), transparent 0 calc(var(--du) * .3)) left bottom / 100% calc(var(--du) * .12) no-repeat; }
.siding::after { content: ""; position: absolute; left: 0; right: 0; bottom: calc(var(--du) * .12); height: calc(var(--du) * .05); background: var(--rail); }
.minitrain { position: relative; z-index: 1; display: flex; align-items: flex-end; gap: calc(var(--du) * .08);
  transition: transform .9s cubic-bezier(.6, 0, .9, .5); animation: rollin .8s cubic-bezier(.2, .7, .3, 1); }
@keyframes rollin { from { transform: translateX(-60vw); } }
.minitrain.leaving { transform: translateX(110vw); }
.minitrain.wiggle { animation: wiggle .4s; }
.minitrain.glow .mcar { box-shadow: 0 0 0 calc(var(--du) * .08) var(--gold); }
.mcar { position: relative; width: calc(var(--du) * var(--w, 1)); height: calc(var(--du) * .8); margin-bottom: calc(var(--du) * .14);
  display: grid; place-items: center; box-sizing: border-box; font-size: calc(var(--du) * .58); line-height: 1;
  background: var(--c, #ffd166); border: calc(var(--du) * .05) solid var(--ink); border-radius: calc(var(--du) * .16); }
.mcar::after { content: ""; position: absolute; left: 8%; right: 8%; bottom: calc(var(--du) * -.2); height: calc(var(--du) * .24);
  background: radial-gradient(circle at 18% 50%, var(--ink) 0 calc(var(--du) * .11), transparent calc(var(--du) * .12)),
              radial-gradient(circle at 82% 50%, var(--ink) 0 calc(var(--du) * .11), transparent calc(var(--du) * .12)); }
.mengine { position: relative; width: calc(var(--du) * 1.3); flex: none; }
.mengine::before { content: ""; position: absolute; left: calc(var(--du) * -.12); bottom: calc(var(--du) * .22); width: calc(var(--du) * .2);
  height: calc(var(--du) * .06); background: var(--ink); border-radius: 99px; }
.mengine svg { display: block; width: 100%; height: auto; overflow: visible; }
@media (max-aspect-ratio: 1/1) {
  #sidings { --du: min(calc(80vw / (var(--len, 3) + 2.6)), 6.5vh); }
  #tracks { grid-template-columns: 1fr; }
}
/* --- themed engines --- */
.engine .deco { position: absolute; left: 12%; top: -24%; font-size: calc(var(--u) * .36); line-height: 1; }
.puff { background: var(--puff, #fff); }
.sparkle .car, .sparkle .mcar { animation: twinkle 1.6s ease-in-out infinite; }
.sparkle .car:nth-child(2n), .sparkle .mcar:nth-child(2n) { animation-delay: .8s; }
@keyframes twinkle { 50% { filter: brightness(1.18) saturate(1.2); } }
.livery .bar, #nextUnlock .bar { display: block; width: 100%; height: 12px; border: 2px solid var(--ink); border-radius: 99px; background: #fff; overflow: hidden; }
.livery .bar i, #nextUnlock .bar i { display: block; height: 100%; background: var(--go); }
#nextUnlock { display: grid; gap: 3px; justify-items: center; width: min(70vw, 300px); font-size: clamp(13px, 2.4vh, 17px); font-weight: 500; }
@media (prefers-reduced-motion: reduce) { .sparkle .car, .sparkle .mcar { animation: none; } }
#letters { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; }
#liveries { display: grid; grid-template-columns: repeat(auto-fit, minmax(128px, 1fr)); gap: 10px; overflow-y: auto; touch-action: pan-y; }
.livery { display: grid; justify-items: center; gap: 2px; padding: 10px 6px; background: #fff; border: 3px solid var(--guide);
  border-radius: 16px; font-size: 14px; font-weight: 500; }
.livery svg { width: 84px; height: auto; overflow: visible; }
.livery b { font-size: 16px; }
.livery.on { border-color: var(--ink); background: #fff3c9; }
.livery.locked svg, .livery.locked .cars { opacity: .45; filter: grayscale(.6); }
.livery:disabled { color: var(--ink); }
.livery .cars { display: flex; gap: 3px; }
.livery .cars i { width: 16px; height: 12px; border-radius: 3px; border: 2px solid var(--ink); }
.scroller { overflow-x: auto; touch-action: pan-x; border-radius: 16px; background: linear-gradient(var(--sky-low) 62%, var(--grass) 62%); }
#line { display: flex; align-items: flex-end; gap: 34px; padding: 26px 30px 0; width: max-content; min-width: 100%; box-sizing: border-box;
  height: 170px; background: repeating-linear-gradient(90deg, var(--tie) 0 8px, transparent 0 24px) left 0 bottom 30px / 100% 8px no-repeat,
  linear-gradient(var(--rail), var(--rail)) left 0 bottom 38px / 100% 4px no-repeat; }
.stop { font-size: 58px; line-height: 1; padding-bottom: 42px; }
.stop.engine-stop { padding-bottom: 38px; }
.stop.engine-stop svg { width: 110px; height: auto; display: block; overflow: visible; }

/* --- home screen --- */
#start { position: absolute; inset: 0; z-index: 6; display: grid; place-content: center; justify-items: center; gap: 1.4vh;
  background: linear-gradient(var(--sky-top), var(--sky-low)); text-align: center; padding-block: 8px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
#start h1 { margin: 0; font-size: clamp(24px, 6.5vh, 72px); line-height: 1; text-wrap: balance; }
#homeEngine svg { width: clamp(64px, 18vh, 190px); height: auto; overflow: visible; display: block; }
#homeStars { font-size: clamp(16px, 3.5vh, 28px); }
#homeStars:empty { display: none; }
#menu { display: grid; justify-items: center; gap: 1.6vh; }
#go { font-size: clamp(24px, 5vh, 44px); padding: .4em 1.3em; border-radius: 99px; background: var(--go); color: #fff;
  border: 5px solid var(--ink); box-shadow: 0 7px 0 var(--ink); }
#go:active { translate: 0 5px; box-shadow: 0 2px 0 var(--ink); }
.modes { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.modes button, .modes a { display: grid; justify-items: center; gap: 0; min-width: clamp(84px, 15vw, 132px); padding: 5px 10px;
  background: var(--paper); border: 4px solid var(--ink); border-radius: 18px; box-shadow: 0 5px 0 var(--ink);
  font-size: clamp(13px, 2.4vh, 18px); }
.modes button span, .modes a span { font-size: clamp(22px, 5.5vh, 46px); line-height: 1.1; }
.modes button.extra, .modes a.extra { background: #fff3c9; }
#parentsLink, #exit { color: var(--ink); font-weight: 500; font-size: 15px; }
#startMsg { margin: 0; font-weight: 500; font-size: 16px; max-width: 34ch; }
@media (prefers-reduced-motion: reduce) {
  .cloud, .puff, .car.hint, .confetti { animation: none; }
  #train, #train.off-right { transition-duration: .01s; }
}
#sendOff { background: var(--gold); animation: hop 1s ease-in-out infinite; }
#abcGrid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; overflow-y: auto; touch-action: pan-y; }
#abcGrid .choice.on { background: var(--gold); }
#abcTabs { display: flex; gap: 8px; justify-content: center; }
#abcTabs button { padding: 4px 16px; border-radius: 99px; background: var(--paper); border: 3px solid var(--ink); font-size: clamp(14px, 2.6vh, 20px); }
#abcTabs button[aria-pressed="true"] { background: var(--ink); color: #fff; }
.modes a { color: var(--ink); text-decoration: none; box-sizing: border-box; font-weight: 700; }
/* Home screen tiles: every game in one row across, with "All games" centred on its own row beneath.
   On a phone held upright there is no room for one row, so the tiles wrap and "All games" stays beneath. */
.modes.across { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: clamp(6px, 1vw, 12px); width: min(96vw, 1180px); }
.modes.across button { min-width: 0; padding: 5px 4px; line-height: 1.1; }
@media (max-width: 700px) {
  .modes.across { display: flex; flex-wrap: wrap; justify-content: center; width: auto; }
  .modes.across button { min-width: clamp(84px, 26vw, 120px); }
}
/* An upright phone: smaller heading and picture, three tiles to a row, so everything down to "All games" fits. */
@media (max-width: 700px) {
  #start { gap: 1vh; }
  #start h1 { font-size: min(6vh, 8vw); }
  #go { font-size: min(4.6vh, 7vw); white-space: nowrap; }
  #homeEngine svg { width: 12vh; }
  .modes.across button { min-width: 0; flex: 0 0 calc(33.3% - 8px); font-size: min(2vh, 3.3vw); }
  .modes.across button span { font-size: min(4vh, 8.5vw); }
}
