/* kids-arcade-b.css: owned by area A2 of the fun and navigation round (tools/kids/FUN.md sections 4 and 5; tools/kids/CONTRACT.md section 16f). Class prefix kb-.
 * Word Train (platform/kids/js/58-arcade-b.js: the station) and Lantern Memory (the night): objects only (an engine, wagons, crates, lanterns, a string of lights: no face, no animal),
 * big targets (the band's --kids-target at least, 64 px in a class), light only, no sound anywhere. Every loop turns in 2 seconds or more and nothing blinks; under
 * prefers-reduced-motion nothing moves (the script fades, the keyframes below are switched off). Text never sits straight on a scene: a letter is always on a card of its own.
 * Arabic is one element each, in the mushaf face (a lone Yaa in Amiri Quran: .ar-dots). A letter's face is as tall as the tallest mark needs (a kasrah under a jim, a Yaa's two dots):
 * the glyph-fit check of tools/smoke_kids_arcade_b.js draws every letter, syllable and word cluster of the course and fails on any ink the face would cut.
 * Layout: the station sign is IN the stage's flow (.kb-signspace holds it, right above the crates, so the crates can never cover it); the script lifts it onto the scene's own board
 * only when that leaves it clear of the crates and the bar (--kb-lift, .is-onboard). Sizes are layout pixels: the stage's own height is divided by the Aa zoom (--content-zoom),
 * as kids.css does for its other screens, so the text size a phone allows never pushes the train off the first screen. A phone on its side (a short, wide window) lays the
 * station out as a grid so the sign, the crates and the train are all on the first screen. */

.kb-game { --kb-crate: 96px; --kb-lant: 120px; display: block; width: 100%; max-width: 46rem; margin-inline: auto; box-sizing: border-box; }
.kb-game[data-band="little"] { --kb-crate: 116px; --kb-lant: 136px; }
.kb-game[data-band="big"] { --kb-crate: 88px; --kb-lant: 108px; }
/* a class board puts the game in a shrink-to-fit grid: it needs a width of its own, or it collapses to a narrow column */
.kb-game[data-class="1"] { --kb-crate: 124px; --kb-lant: 136px; width: min(56rem, 94vw); max-width: 56rem; }
.kb-game [hidden] { display: none !important; }

/* ---- the stage: a scene behind everything, the bar on top ---- */
.kb-stage {
  --kb-s: .9;
  display: flex; flex-direction: column; align-items: stretch; gap: 10px; box-sizing: border-box;
  min-height: clamp(360px, calc(72vh / var(--content-zoom, 1)), 640px); padding: 10px 12px 0;
  container: kbstage / inline-size;                         /* its rules below ask the stage's own width in layout pixels (the Aa zoom shrinks it) */
}
@supports (height: 1dvh) { .kb-stage { min-height: clamp(360px, calc(72dvh / var(--content-zoom, 1)), 640px); } }
.kb-bar { position: relative; z-index: 3; display: flex; align-items: center; gap: 10px; min-height: 56px; }
/* a long press on a crate, a lantern or the sign never selects its letters or opens a callout */
.kb-crate, .kb-lantern, .kb-sign { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.kb-howkey, .kb-watchkey { flex: none; min-width: var(--kids-target, 56px); min-height: var(--kids-target, 56px); padding: 0; justify-content: center; }
.kb-bar .kx-meter { flex: 1 1 0; width: auto; min-width: 0; max-width: none; margin: 0; --kx-m-art: 40px; }
html[data-band="little"] .kb-bar .kx-meter { --kx-m-art: 48px; }
/* the three-in-a-row mark: a deep ring round the pill, so it shows on the sun, a cloud or the sky alike (the pill's own tint is as pale as they are) */
.kb-streakbox { position: absolute; z-index: 3; right: 14px; top: 74px; pointer-events: none; }
.kb-streakbox .kx-streak { min-width: 0; }
.kb-streakbox .kx-streak:not([data-level="0"]) { box-shadow: inset 0 0 0 2px var(--kx-c), 0 0 0 3px var(--kx-amber-deep); }

/* ---- Arabic on a card: one element, never wrapped ---- */
.kb-ar { display: block; margin: 0; direction: rtl; line-height: 1.55; padding-block: .06em; white-space: nowrap; word-break: keep-all; overflow-wrap: normal; text-align: center; color: var(--ink); }
.kb-ar.ar-dots { padding-block: 0 .12em; }
/* the letters already on the train are lit on the sign: blue against the ink (3.2:1; dark green against near-black was 2:1 and vanished for a colour-blind child) */
.kb-lit { color: #2563EB; }

/* ================================================================ Word Train: the station */
/* the sign's room: a little above it (the chains it hangs by are 24 px: 10 of the stage's gap and 14 here), a gap above the crates, and the whole of the sign (a word is taller than a
   speaker: --kb-signh is its height, kept from the start in a game that has a word) so the crates can never cover it */
.kb-g-train { --kb-signh: 110px; }
.kb-signspace { flex: 1 1 auto; display: flex; align-items: flex-end; justify-content: center; box-sizing: border-box; padding: 14px 0 12px; min-height: calc(14px + 78px + 12px); }
.kb-g-train[data-words="1"] .kb-signspace { min-height: calc(14px + 12px + var(--kb-signh)); }
.kb-sign {
  appearance: none; position: relative; z-index: 2; flex: 0 1 auto; padding: 0; border: 0; background: none; color: var(--ink); cursor: pointer;
  translate: 0 calc(-1 * var(--kb-lift, 0px)); max-width: 100%;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.kb-sign__board {
  position: relative; display: grid; place-items: center; min-width: max(172px, calc(var(--kb-s) * 178px)); min-height: 78px; padding: 4px 26px; box-sizing: border-box; border-radius: 14px;
  background: #FFF8E6; border: 5px solid #8A6F5A; box-shadow: 0 6px 0 rgba(138, 111, 90, .4); max-width: 100%;
}
/* the chains it hangs by, drawn only while it hangs on the scene's own roof */
.kb-sign__board::before, .kb-sign__board::after { content: ''; position: absolute; top: -24px; width: 5px; height: 20px; border-radius: 3px; background: #8A6F5A; display: none; }
.kb-sign__board::before { left: 22%; }
.kb-sign__board::after { right: 22%; }
.kb-g-train.is-onboard .kb-sign__board::before, .kb-g-train.is-onboard .kb-sign__board::after { display: block; }
.kb-sign__ar { font-size: clamp(2.4rem, 12vw, 3.6rem); line-height: 1.6; }
.kb-sign .icon { width: 46px; height: 46px; stroke: var(--kx-violet-deep); }
@media (hover: hover) { .kb-sign:hover .kb-sign__board { background: #FFFDF3; } }
.kb-sign:focus-visible { outline: none; }
.kb-sign:focus-visible .kb-sign__board { outline: 3px solid var(--lapis); outline-offset: 3px; }
.kb-game[data-band="little"] .kb-sign .icon { width: 56px; height: 56px; }
/* the scene draws a blank board and its chains where the sign hangs; the sign is its own board, so the drawn one never shows (it would peek out wherever the sign stands elsewhere) */
.kb-g-train .kx-scene--station rect[x="320"][y="184"], .kb-g-train .kx-scene--station path[d^="M350 162"] { display: none; }

.kb-crates {
  position: relative; z-index: 2; display: flex; justify-content: center; align-items: flex-end; flex-wrap: wrap; gap: 8px 8px; padding-inline: 2px;
  min-height: calc(var(--kb-crate) * .92);
}
.kb-crate {
  appearance: none; position: relative; flex: 1 1 0; max-width: var(--kb-crate); min-width: min(max(var(--kids-target, 56px), 48px), calc((100% - 16px) / 3)); aspect-ratio: 1 / .92; padding: 0; border: 0; background: none;
  cursor: pointer; container-type: inline-size; touch-action: manipulation; -webkit-tap-highlight-color: transparent; color: var(--ink);
}
.kb-game[data-class="1"] .kb-crate, .kb-game[data-band="little"] .kb-crate { min-width: min(64px, calc((100% - 16px) / 3)); }       /* three always share a row, even at the biggest text size */
.kb-crate::before {
  content: ''; position: absolute; inset: 0; border-radius: 12px; box-shadow: inset 0 0 0 3px var(--kx-amber-deep), 0 5px 0 rgba(111, 67, 0, .38);
  background:
    linear-gradient(var(--kx-amber-deep), var(--kx-amber-deep)) top / 100% 14% no-repeat,
    linear-gradient(var(--kx-amber-deep), var(--kx-amber-deep)) bottom / 100% 14% no-repeat,
    repeating-linear-gradient(90deg, var(--kx-amber) 0 23%, #E9A92A 23% 25%);
}
/* the face is cream, clipped to its own rounded corners; it is tall enough for the tallest letter (a jim with a kasrah under it, a Yaa and its dots): nothing the child must read is ever cut */
.kb-crate__face {
  position: absolute; inset: 15% 11%; display: grid; place-items: center; overflow: hidden; border-radius: 9px; background: #FFF8E6; box-shadow: inset 0 0 0 2.5px var(--kx-amber-deep);
}
.kb-crate__ar { font-size: calc(var(--kb-crate) * .32); font-size: 32cqw; line-height: 1.35; }
.kb-crate__ar.ar-dots { font-size: 27cqw; line-height: 1.5; padding-block: 0 .12em; }
@media (hover: hover) { .kb-crate:not(:disabled):hover .kb-crate__face { background: #FFFDF3; } }
.kb-crate:focus-visible { outline: 3px solid var(--lapis); outline-offset: 4px; border-radius: 12px; }
.kb-crate.is-off { opacity: .32; filter: grayscale(.55); pointer-events: none; }
.kb-crate.is-gone { visibility: hidden; }
/* six crates (a six-letter word, Big readers) fit one row on a small phone, or sit three and three: never five and a lone one (the stage's own width, in layout pixels) */
@container kbstage (max-width: 400px) { .kb-crates { gap: 6px; } }
@container kbstage (max-width: 345px) { .kb-crates[data-n="6"] { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); justify-items: center; } .kb-crates[data-n="6"] .kb-crate { width: 100%; } }

.kb-rail { position: relative; z-index: 2; display: flex; justify-content: center; align-items: flex-end; box-sizing: border-box; padding-bottom: calc(38 * var(--kb-s) * 1px); min-height: 96px; }
.kb-train { display: flex; align-items: flex-end; justify-content: center; gap: 3px; width: 100%; max-width: 660px; }
.kb-engine { position: relative; flex: 0 1 124px; min-width: 0; translate: 0 7%; }
.kb-engine .kx-art { display: block; width: 100%; height: auto; }
.kb-puff { position: absolute; left: 12%; top: -6%; width: 34%; pointer-events: none; z-index: 3; }
.kb-puff .kx-art { width: 100%; height: auto; }
.kb-car { position: relative; flex: 0 1 94px; min-width: 0; aspect-ratio: 100 / 60; }
.kb-car > .kx-art { position: absolute; inset: 0; width: 100%; height: 100%; }
.kb-car__front { z-index: 2; pointer-events: none; }
.kb-slot { position: absolute; z-index: 1; left: 7%; right: 7%; bottom: 50%; aspect-ratio: 1 / .96; }       /* the crate in a wagon is as wide as the wagon lets it: the letter is read there */
.kb-load { display: block; position: relative; width: 100%; height: 100%; opacity: 0; transition: opacity .2s; container-type: inline-size; border-radius: 6px; box-shadow: inset 0 0 0 2px var(--kx-amber-deep); background: repeating-linear-gradient(90deg, var(--kx-amber) 0 23%, #E9A92A 23% 25%); }
.kb-slot[data-in="1"] .kb-load { opacity: 1; }
.kb-load__face { position: absolute; inset: 10% 11%; display: grid; place-items: center; overflow: hidden; border-radius: 4px; background: #FFF8E6; }
.kb-load__ar { font-size: 38cqw; line-height: 1.35; }
.kb-load__ar.ar-dots { font-size: 32cqw; line-height: 1.5; padding-block: 0 .1em; }
/* the wagon that asks: a dashed place for the crate and a small arrow that nods (a fade under reduced motion) */
.kb-car[data-state="ask"] .kb-slot::before { content: ''; position: absolute; inset: 0; border: 3px dashed var(--kx-amber-deep); border-radius: 8px; background: rgba(255, 255, 255, .6); animation: kb-ask 2.4s ease-in-out infinite alternate; }
.kb-car[data-state="ask"] .kb-slot::after { content: ''; position: absolute; left: 50%; top: -16px; translate: -50% 0; border: 8px solid transparent; border-top: 10px solid var(--kx-amber-deep); border-bottom: 0; animation: kb-nudge 2.4s ease-in-out infinite alternate; }
@keyframes kb-ask { from { opacity: .55; } to { opacity: 1; } }
@keyframes kb-nudge { from { translate: -50% -3px; } to { translate: -50% 3px; } }

/* ================================================================ Lantern Memory: the evening street */
.kb-g-lanterns .kb-stage { min-height: clamp(360px, calc(62vh / var(--content-zoom, 1)), 560px); }
.kb-g-lanterns[data-rows="2"] .kb-stage, .kb-g-lanterns[data-rows="3"] .kb-stage { min-height: clamp(480px, calc(80vh / var(--content-zoom, 1)), 680px); }
@supports (height: 1dvh) { .kb-g-lanterns .kb-stage { min-height: clamp(360px, calc(62dvh / var(--content-zoom, 1)), 560px); } .kb-g-lanterns[data-rows="2"] .kb-stage, .kb-g-lanterns[data-rows="3"] .kb-stage { min-height: clamp(480px, calc(80dvh / var(--content-zoom, 1)), 680px); } }
.kb-stage::after { content: ''; position: absolute; inset: 0; z-index: 1; pointer-events: none; background: rgba(28, 22, 92, .36); opacity: 0; transition: opacity .35s; }
.kb-stage.is-watching::after { opacity: 1; }
.kb-hang { --kb-swag: 40px; position: relative; z-index: 2; display: flex; flex-direction: column; gap: 10px; margin-block: auto 0; padding-top: 6px; --kb-glow: 0; }
.kb-g-lanterns[data-rows="2"] .kb-hang, .kb-g-lanterns[data-rows="3"] .kb-hang { --kb-swag: 32px; gap: 14px; }
.kb-rowbox { position: relative; padding-top: 4px; }
.kb-string { position: absolute; left: 0; right: 0; top: 4px; width: 100%; height: var(--kb-swag); overflow: visible; pointer-events: none; }
.kb-string path { fill: none; stroke: #F3D88B; stroke-width: 3; stroke-linecap: round; }
.kb-row { position: relative; display: grid; grid-template-columns: repeat(calc(var(--kb-cols, 4) * 2), minmax(0, 1fr)); gap: 0 4px; align-items: start; }
.kb-lantern {
  --kx-c: #CFC8F7; --kx-c-tint: #F1EEFF; --kx-c-deep: #2F2A86;
  appearance: none; position: relative; grid-column: span 2; justify-self: center; width: min(100%, var(--kb-lant)); min-width: var(--kids-target, 56px); aspect-ratio: 100 / 130; padding: 0; border: 0; background: none;
  margin-top: calc(var(--kb-sag, 0) * var(--kb-swag) - 4px); transform-origin: 50% 0; cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent;
  animation: kb-swing 4.6s ease-in-out infinite alternate; animation-delay: var(--kx-d, 0s);
}
.kb-game[data-class="1"] .kb-lantern { min-width: 64px; }
.kb-lantern__art { position: absolute; inset: 0; width: 100%; height: 100%; }
.kb-lantern__halo {
  position: absolute; left: -40%; right: -40%; top: 2%; aspect-ratio: 1; border-radius: 50%; pointer-events: none;
  background: radial-gradient(circle, rgba(255, 226, 122, .95) 0, rgba(255, 226, 122, .55) 36%, rgba(255, 226, 122, 0) 68%);
  opacity: calc(var(--kb-glow, 0) * .3); transition: opacity .2s ease, scale .2s ease;
}
.kb-lantern__glass {
  position: absolute; left: 24%; right: 24%; top: 34%; height: 39%; display: grid; place-items: center; overflow: visible; border-radius: 7px;
  background: #FFF4DA; box-shadow: inset 0 0 0 2px rgba(47, 42, 134, .55); transition: background-color .2s ease, box-shadow .2s ease; container-type: inline-size;
}
.kb-lantern__ar { font-size: calc(var(--kb-lant) * .24); font-size: 56cqw; line-height: 1.25; padding-block: 0; }
/* a lone Yaa (Amiri Quran) carries its dots low: lift it so it sits in the middle of the glass */
.kb-lantern__ar.ar-dots { font-size: 48cqw; line-height: 1.3; padding-block: 0 .1em; translate: 0 -.12em; }
.kb-lantern.is-lit { --kx-c: var(--kx-amber); --kx-c-tint: var(--kx-amber-tint); --kx-c-deep: var(--kx-amber-deep); }
.kb-lantern.is-lit .kb-lantern__halo { opacity: 1; scale: 1.08; }
.kb-lantern.is-lit .kb-lantern__glass { background: #FFF8B8; box-shadow: inset 0 0 0 2px #B07B14, 0 0 16px 6px rgba(255, 214, 102, .95); }
.kb-lantern:focus-visible { outline: 3px solid #fff; outline-offset: 2px; border-radius: 14px; }
.kb-lantern[aria-disabled="true"] { cursor: default; }
.kb-lantern.is-hint::after { content: ''; position: absolute; inset: -2px -8px; border-radius: 20px; box-shadow: 0 0 0 4px rgba(255, 244, 190, .95); animation: kb-hint 2.4s ease-in-out infinite alternate; pointer-events: none; }
.kb-steps { position: relative; z-index: 2; display: flex; justify-content: center; align-items: center; gap: 10px; min-height: 26px; margin: 14px 0 auto; }
.kb-step { width: 20px; height: 20px; border-radius: 50%; box-sizing: border-box; background: rgba(255, 255, 255, .28); box-shadow: inset 0 0 0 3px #F3D88B; transition: background-color .2s; }
.kb-step.is-on { background: #FFC247; box-shadow: inset 0 0 0 3px #FFF1D0; }
.kb-g-lanterns.is-finale .kb-lantern__halo { opacity: .55; }
@keyframes kb-swing { from { rotate: -2.2deg; } to { rotate: 2.2deg; } }
@keyframes kb-hint { from { opacity: .25; } to { opacity: 1; } }

/* ---- a short window (a phone on its side, or a laptop's small browser) gives up its decoration, a step at a time ---- */
@media (max-height: 700px) {
  .kb-g-train { --kb-signh: 96px; }
  .kb-sign__ar { font-size: clamp(2.4rem, 12vw, 3rem); }
}
@media (max-height: 520px) {
  .kb-stage, .kb-g-lanterns .kb-stage, .kb-g-lanterns[data-rows="2"] .kb-stage, .kb-g-lanterns[data-rows="3"] .kb-stage { min-height: 0; }
  .kb-stage { gap: 4px; padding-top: 4px; }
  .kb-bar { min-height: 48px; }
  .kb-bar .kx-meter, html[data-band="little"] .kb-bar .kx-meter { --kx-m-art: 32px; }
  .kb-game, .kb-game[data-band="little"], .kb-game[data-band="big"] { --kb-crate: 72px; --kb-lant: 92px; }
  .kb-game[data-band="little"] { --kb-crate: 80px; --kb-lant: 92px; }
  .kb-game[data-band="big"] { --kb-crate: 68px; --kb-lant: 84px; }
  .kb-engine { flex-basis: 84px; }
  .kb-car { flex-basis: 62px; }
  .kb-rail { min-height: 70px; }
  .kb-hang { margin-top: 8px; --kb-swag: 24px; }
  .kb-sign__board { min-height: 54px; padding-block: 0; border-width: 4px; }
  .kb-sign__ar { font-size: 2.4rem; line-height: 1.5; }
  .kb-sign .icon, .kb-game[data-band="little"] .kb-sign .icon { width: 38px; height: 38px; }
  .kb-steps { margin-top: 6px; min-height: 22px; }
  .kb-signspace { padding-top: 4px; min-height: 0; }
  .kb-g-train[data-words="1"] .kb-signspace { min-height: 0; }
}
/* wide and short (a phone on its side): the station is a grid, [meter] over [how-to key, sign, crates] over [the train], so all of it is on the first screen.
   The scene's roof and posts stay behind it; the sign is a board of its own. */
@media (max-height: 520px) and (min-width: 540px) {
  .kb-g-train .kb-stage { display: grid; grid-template-columns: auto auto minmax(0, 1fr); grid-template-areas: "meter meter meter" "how sign crates" "rail rail rail"; align-items: end; column-gap: 8px; row-gap: 4px; padding: 4px 10px 0; }
  .kb-g-train .kb-bar { display: contents; }
  .kb-g-train .kb-bar .kx-meter { grid-area: meter; }
  .kb-g-train .kb-howkey { grid-area: how; align-self: end; }
  .kb-g-train .kb-signspace { display: contents; }
  .kb-g-train .kb-sign { grid-area: sign; align-self: end; translate: none; margin-bottom: 4px; max-width: 46vw; }
  .kb-g-train .kb-crates { grid-area: crates; min-height: 0; justify-content: flex-start; }
  .kb-g-train .kb-rail { grid-area: rail; }
  .kb-g-train .kb-streakbox { top: 40px; right: 12px; }
}
@media (max-height: 400px) {
  .kb-game, .kb-game[data-band="little"] { --kb-crate: 72px; --kb-lant: 76px; }
  .kb-game[data-band="big"] { --kb-crate: 60px; --kb-lant: 72px; }
  .kb-bar { min-height: 40px; }
  .kb-engine { flex-basis: 70px; }
  .kb-car { flex-basis: 52px; }
  .kb-rail { min-height: 58px; }
  .kb-hang { --kb-swag: 18px; margin-top: 4px; }
  .kb-sign__board { min-height: 46px; }
  .kb-sign__ar { font-size: 2rem; }
  .kb-steps { margin-top: 2px; min-height: 18px; }
  .kb-step { width: 16px; height: 16px; }
}

/* a very short window (568 x 320, the smallest phone on its side: the page's own heading takes the room the readers' band has no words for) shrinks the rest, never below the tap targets */
@media (max-height: 340px) {
  .kb-game, .kb-game[data-band="little"] { --kb-crate: 72px; --kb-lant: 66px; }
  .kb-game[data-band="big"] { --kb-crate: 58px; --kb-lant: 62px; }
  .kb-stage { padding-top: 2px; gap: 2px; }
  .kb-engine { flex-basis: 62px; }
  .kb-car { flex-basis: 46px; }
  .kb-rail { min-height: 50px; }
  .kb-hang { --kb-swag: 14px; margin-top: 2px; }
  .kb-steps { min-height: 14px; margin-top: 0; }
  .kb-step { width: 14px; height: 14px; }
}

/* ---- reduced motion: nothing moves; the script fades; the game stays fully playable ---- */
@media (prefers-reduced-motion: reduce) {
  .kb-lantern, .kb-car[data-state="ask"] .kb-slot::before, .kb-car[data-state="ask"] .kb-slot::after, .kb-lantern.is-hint::after { animation: none; }
  .kb-lantern.is-lit .kb-lantern__halo { scale: 1; }
  .kb-lantern__halo, .kb-lantern__glass, .kb-stage::after, .kb-step, .kb-load { transition: none; }
}
