/* ===== Train journey scene shell (js/scene.js) =====
   Vertical bands of the root: 0–20% sky + sign (no touch), 20–78% stage,
   78–88% track (decor), 88–97% nav row. Decor never receives pointer events. */

.scene {
  --scene-sky-top: #d8ecff;
  --scene-sky-bottom: #fff7e8;
  --scene-cloud: rgba(255, 255, 255, 0.95);
  --scene-cloud-far: rgba(255, 255, 255, 0.7);
  --scene-hill-far: #c5e1a5;
  --scene-hill-near: #9ccc65;
  --scene-ground-top: #8bc34a;
  --scene-ground-bottom: #7cb342;
  --scene-rail: #78909c;
  --scene-sleeper: #a1887f;
  --scene-post: #8d6e63;
  --scene-light-off: #eceff1;
  --scene-dot-off: rgba(255, 255, 255, 0.85);
  --scene-sign-bg: var(--color-primary, #5c6bc0);
  --scene-text: var(--color-text, #2f3a56);
  --scene-success: var(--color-success, #43a047);
  --scene-highlight: var(--color-highlight, #ffb300);
  --scene-snow: #ffffff;
  /* Season crossfade (opacity only; the gradients themselves never animate). */
  --scene-theme-ms: 900ms;

  position: relative;
  overflow: hidden;
}

/* The frame carries the layout, so rules on the root element (e.g. an #app grid) cannot break it. */
.scene__frame {
  position: absolute;
  inset: 0;
  overflow: hidden;
  display: grid;
  grid-template-columns: 100%;
  /* sky+sign | stage | track | nav | bottom gap (sums to 100%) */
  grid-template-rows: 20% 58% 10% 10% 2%;
  /* Size for the buttons the integration lane puts in navSlot (fits the 10% nav band). */
  --scene-nav-size: min(8.5vh, 9vmin);
  background: linear-gradient(180deg, var(--scene-sky-top) 0%, var(--scene-sky-bottom) 70%);
  font-family: var(--font-main, 'Nunito', 'Segoe UI', system-ui, sans-serif);
  color: var(--scene-text);
}

.scene[data-tone="calm"] {
  --scene-sky-top: #e6eef6;
  --scene-hill-near: #aed581;
}

/* ----- Decor (non-interactive) ----- */
.scene__sky,
.scene__weather,
.scene__sun,
.scene__layer,
.scene__ground,
.scene__track,
.scene__header {
  pointer-events: none;
}

.scene__sun {
  position: absolute;
  top: 3%;
  right: 4%;
  width: 11vh;
  height: 11vh;
  border-radius: 50%;
  background: radial-gradient(circle, #ffe082 0 55%, #ffd54f 56% 100%);
  box-shadow: 0 0 0 1.4vh rgba(255, 224, 130, 0.35), 0 0 0 3vh rgba(255, 224, 130, 0.18);
  transition: opacity var(--scene-theme-ms) ease-in-out;
}

/* Summer halo: a wide warm glow faded in over the sun. */
.scene__sun::after {
  content: "";
  position: absolute;
  inset: -70%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 236, 150, 0.6) 0, rgba(255, 236, 150, 0) 68%);
  opacity: 0;
  transition: opacity var(--scene-theme-ms) ease-in-out;
}

.scene[data-theme="summer"] .scene__sun::after {
  opacity: 1;
}

.scene[data-theme="winter"] .scene__sun {
  opacity: 0.45;
}

/* ===== Seasons =====
   Every painted surface (sky, both hill layers, ground) holds one tint child per season. A tint
   repaints the surface with its own palette and is faded in over the default look, so switching
   seasons is an opacity crossfade only. */
.scene__sky {
  position: absolute;
  inset: 0;
}

.scene__tint {
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity var(--scene-theme-ms) ease-in-out;
}

.scene__tint[data-tint="winter"] {
  --tint-sky-top: #9fb4c9;
  --tint-sky-bottom: #e6edf4;
  --tint-hill-far: #b3c3d4;
  --tint-hill-near: #d3dee9;
  --tint-ground-top: #ffffff;
  --tint-ground-bottom: #f0f4f8;
}

.scene__tint[data-tint="spring"] {
  --tint-sky-top: #cdeefc;
  --tint-sky-bottom: #ffe3ee;
  --tint-hill-far: #f7cadc;
  --tint-hill-near: #a9dc8c;
  --tint-ground-top: #9ad27a;
  --tint-ground-bottom: #80c35f;
}

.scene__tint[data-tint="summer"] {
  --tint-sky-top: #45aef5;
  --tint-sky-bottom: #c4e9ff;
  --tint-hill-far: #b8dd66;
  --tint-hill-near: #86c53a;
  --tint-ground-top: #8cc63f;
  --tint-ground-bottom: #6dab2e;
}

.scene__tint[data-tint="autumn"] {
  --tint-sky-top: #f1c491;
  --tint-sky-bottom: #fdecd8;
  --tint-hill-far: #e3a566;
  --tint-hill-near: #c8773a;
  --tint-ground-top: #b0743e;
  --tint-ground-bottom: #8b582d;
}

.scene__sky > .scene__tint {
  background: linear-gradient(180deg, var(--tint-sky-top) 0%, var(--tint-sky-bottom) 70%);
}

.scene__hills-far > .scene__tint,
.scene__hills-near > .scene__tint {
  background-repeat: repeat-x;
  background-size: var(--period) 100%;
}

.scene__hills-far > .scene__tint {
  background-image: radial-gradient(ellipse 51% 102% at 50% 100%, var(--tint-hill-far) 97%, transparent 100%);
}

.scene__hills-near > .scene__tint {
  background-image: radial-gradient(ellipse 51% 102% at 50% 100%, var(--tint-hill-near) 97%, transparent 100%);
}

.scene__ground > .scene__tint {
  background: linear-gradient(180deg, var(--tint-ground-top), var(--tint-ground-bottom));
}

.scene[data-theme="winter"] .scene__tint[data-tint="winter"],
.scene[data-theme="spring"] .scene__tint[data-tint="spring"],
.scene[data-theme="summer"] .scene__tint[data-tint="summer"],
.scene[data-theme="autumn"] .scene__tint[data-tint="autumn"] {
  opacity: 1;
}

/* Winter snow on the train roofs and along the rails. */
.scene__snow,
.scene__rails::before {
  opacity: 0;
  transition: opacity var(--scene-theme-ms) ease-in-out;
}

.scene[data-theme="winter"] .scene__snow,
.scene[data-theme="winter"] .scene__rails::before {
  opacity: 1;
}

/* ----- Weather particles (js/weather.js): above the sky, behind the track and the stage ----- */
.scene__weather {
  position: absolute;
  inset: 0;
  z-index: 1;
  overflow: hidden;
}

.weather__layer {
  position: absolute;
  inset: 0;
}

.weather__particle {
  position: absolute;
  top: 0;
  width: var(--size);
  height: var(--size);
  will-change: transform, opacity;
}

.weather__particle[data-kind="snow"] {
  border-radius: 50%;
  background: radial-gradient(circle, var(--scene-snow) 0 42%, rgba(255, 255, 255, 0) 72%);
}

.weather__particle[data-kind="petal"] {
  height: calc(var(--size) * 0.62);
  border-radius: 85% 0 85% 0;
  background: #f8bbd0;
}

.weather__particle[data-kind="petal"][data-variant="1"] { background: #f48fb1; }
.weather__particle[data-kind="petal"][data-variant="2"] { background: #fde4ee; }
.weather__particle[data-kind="petal"][data-variant="3"] { background: #f7a8c4; }

.weather__particle[data-kind="leaf"] {
  --leaf-color: #d9822b;
  height: calc(var(--size) * 0.66);
  border-radius: 0 85% 0 85%;
  background:
    linear-gradient(145deg, transparent 47%, rgba(80, 36, 10, 0.35) 48% 52%, transparent 53%),
    var(--leaf-color);
}

.weather__particle[data-kind="leaf"][data-variant="1"] { --leaf-color: #c0562f; }
.weather__particle[data-kind="leaf"][data-variant="2"] { --leaf-color: #e8b04a; }
.weather__particle[data-kind="leaf"][data-variant="3"] { --leaf-color: #9c5a2e; }

.weather__particle[data-kind="glint"] {
  border-radius: 50%;
  opacity: 0;
  background: radial-gradient(circle, rgba(255, 252, 228, 0.95) 0, rgba(255, 236, 150, 0.45) 32%, rgba(255, 236, 150, 0) 70%);
}

.weather__particle[data-kind="glint"][data-variant="1"] {
  background: radial-gradient(circle, rgba(255, 255, 255, 0.9) 0, rgba(255, 255, 255, 0.3) 30%, rgba(255, 255, 255, 0) 66%);
}

/* Parallax layers: a repeating tile of width --period; JS shifts them by whole periods while
   travelling, so the margin on each side must cover the largest shift (kept generous). */
.scene__layer {
  position: absolute;
  left: -140vw;
  width: calc(100% + 280vw);
  background-repeat: repeat-x;
  background-size: var(--period) 100%;
}

.scene__clouds-far {
  top: 1%;
  height: 10%;
  opacity: 0.8;
  background-image:
    radial-gradient(ellipse 14% 32% at 30% 60%, var(--scene-cloud-far) 96%, transparent 100%),
    radial-gradient(ellipse 10% 26% at 20% 70%, var(--scene-cloud-far) 96%, transparent 100%),
    radial-gradient(ellipse 11% 28% at 40% 70%, var(--scene-cloud-far) 96%, transparent 100%);
}

.scene__clouds-near {
  top: 6%;
  height: 13%;
  background-image:
    radial-gradient(ellipse 12% 36% at 70% 50%, var(--scene-cloud) 96%, transparent 100%),
    radial-gradient(ellipse 9% 28% at 61% 66%, var(--scene-cloud) 96%, transparent 100%),
    radial-gradient(ellipse 9% 28% at 79% 66%, var(--scene-cloud) 96%, transparent 100%);
}

.scene__hills-far {
  top: 66%;
  height: 20%;
  background-image: radial-gradient(ellipse 50% 100% at 50% 100%, var(--scene-hill-far) 97%, transparent 100%);
}

.scene__hills-near {
  top: 73%;
  height: 14%;
  background-image: radial-gradient(ellipse 50% 100% at 50% 100%, var(--scene-hill-near) 97%, transparent 100%);
}

.scene__ground {
  position: absolute;
  left: 0;
  right: 0;
  top: 85%;
  bottom: 0;
  background: linear-gradient(180deg, var(--scene-ground-top), var(--scene-ground-bottom));
}

/* ----- Top band: sign + instruction ----- */
.scene__header {
  grid-row: 1;
  grid-column: 1;
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 1.2vh;
  padding: 2vh 14vw 0;
  min-height: 0;
}

.scene__sign {
  position: relative;
  max-width: 100%;
  padding: 0.8vh 3.2vw;
  border-radius: 999px;
  background: var(--scene-sign-bg);
  color: #ffffff;
  box-shadow: 0 0.8vh 0 rgba(47, 58, 86, 0.18);
}

/* No title (cover): the empty pill must not show. */
.scene__sign.is-empty {
  visibility: hidden;
}

.scene__sign-title {
  display: block;
  font-size: clamp(26px, 6vh, 150px);
  font-weight: 900;
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.scene__instruction {
  margin: 0;
  max-width: 100%;
  font-size: clamp(16px, 3.4vh, 84px);
  font-weight: 800;
  line-height: 1.2;
  text-align: center;
  color: var(--scene-text);
}

.scene__instruction.is-celebrating {
  color: var(--scene-success);
}

/* ----- Stage + overlay ----- */
.scene__stage {
  grid-row: 2;
  grid-column: 1;
  position: relative;
  z-index: 3;
  min-height: 0;
  padding: 0 8vw;
}

.scene__overlay {
  grid-row: 2;
  grid-column: 1;
  position: relative;
  z-index: 5;
  display: flex;
  align-items: stretch;
  justify-content: stretch;
  padding: 2vh 12vw;
  /* Covers the whole stage band and catches every pointer, so nothing underneath reacts. */
  pointer-events: auto;
  touch-action: none;
}

.scene__overlay-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3vh;
  border-radius: 4vmin;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: 0 1.6vmin 3.2vmin rgba(47, 58, 86, 0.18);
  text-align: center;
}

.scene__overlay[hidden] {
  display: none;
}

.scene__overlay-title {
  margin: 0;
  padding: 0 3vw;
  font-size: clamp(32px, 8.5vh, 220px);
  font-weight: 900;
  line-height: 1.1;
  color: var(--scene-sign-bg);
}

.scene__overlay-subtitle {
  margin: 0;
  font-size: clamp(18px, 4vh, 100px);
  font-weight: 800;
}

.scene__overlay-button {
  width: clamp(120px, 24vmin, 460px);
  height: clamp(120px, 24vmin, 460px);
  padding: 2vmin;
  border: none;
  border-radius: 50%;
  background: var(--scene-success);
  color: #ffffff;
  font: inherit;
  font-size: clamp(20px, 4.4vmin, 90px);
  font-weight: 900;
  line-height: 1.1;
  box-shadow: 0 1vmin 0 rgba(47, 58, 86, 0.25);
  cursor: pointer;
  touch-action: manipulation;
  animation: scene-breathe 1.8s ease-in-out infinite;
}

.scene__overlay-button:active {
  animation: none;
  transform: translateY(0.6vmin) scale(0.97);
  box-shadow: 0 0.4vmin 0 rgba(47, 58, 86, 0.25);
}

/* ----- Cover: title above, actions in the lower middle of the stage band ----- */
.scene__overlay-card--cover {
  position: relative;
  justify-content: center;
  gap: 5vh;
}

/* School logo: a badge centered on the card's top edge, mostly in the sky band; it never moves the card's content. */
.scene__cover-logo {
  --cover-logo-size: 18vh;
  position: absolute;
  top: 0;
  left: 50%;
  height: var(--cover-logo-size);
  width: auto;
  transform: translate(-50%, -72%);
  filter: drop-shadow(0 0.6vmin 1.2vmin rgba(47, 58, 86, 0.2));
  pointer-events: none;
}

.scene__cover-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4vw;
}

/* Teacher's corner (spec §18.6): top left, outside the children's reach; filled only while the cover shows. */
/* Teacher corner: ⚙ (cover only) with the fullscreen toggle below it. */
.scene__teacher-corner {
  position: absolute;
  top: 1.5vh;
  left: 1.5vh;
  z-index: 6;
  display: flex;
  flex-direction: column;
  gap: 1.2vh;
}

.scene__settings-corner:empty {
  display: none;
}

/* Small, icon-only and muted, so children do not take it for a game button. */
.scene__cover-settings {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 6vh;
  height: 6vh;
  padding: 1.2vh;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.45);
  color: rgba(47, 58, 86, 0.45);
  cursor: pointer;
  touch-action: manipulation;
}

.scene__cover-settings:active {
  transform: scale(0.94);
}

.scene__cover-settings-icon {
  width: 100%;
  height: 100%;
}

/* ----- Finish: parade train, then the texts beside the restart button ----- */
.scene__overlay-card--finish {
  gap: 3vh;
}

.scene__finish-ending {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4vw;
}

.scene__finish-words {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5vh;
}

/* Hidden but keeping its place while the parade rolls in (the restart button cannot be tapped). */
.scene__finish-ending.is-pending {
  visibility: hidden;
}

/* One row that always fits: the unit (wagon width) shrinks with the wagon count; the locomotive is 1.26 units
   (its 126-wide crop against the wagon's 100). Cars overlap by 0.1 unit — the drawing's 90 pitch — so every
   coupler reaches the car in front at the same height. Row 1.36 + 0.9 n units wide. The top padding leaves
   room for the stickers above the roofs. */
.scene__parade-train {
  --parade-unit: min(12vh, calc(68vw / (var(--parade-count, 1) * 0.9 + 1.36)));
  display: flex;
  flex-direction: row-reverse;
  align-items: flex-end;
  flex: 0 0 auto;
  padding-top: calc(var(--parade-unit) * 0.5);
}

.scene__parade-loco {
  flex: 0 0 auto;
  width: calc(var(--parade-unit) * 1.26);
}

.scene__parade-car {
  position: relative;
  flex: 0 0 auto;
  width: var(--parade-unit);
  margin-left: calc(var(--parade-unit) * -0.1);
}

/* The drawing faces right; mirrored, the locomotive leads to the left as the train comes in from the right. */
.scene__parade-loco svg,
.scene__parade-car svg {
  display: block;
  width: 100%;
  height: auto;
  /* The locomotive is a crop of the whole drawing: the cars outside its viewBox must not show. */
  overflow: hidden;
  transform: scaleX(-1);
}

/* Sticker standing on the wagon roof (roof at 30% of the drawing height); the mirrored body is centred at 54%. */
.scene__parade-sticker {
  position: absolute;
  left: 16.5%;
  bottom: 70%;
  width: 75%;
  aspect-ratio: 1;
  object-fit: contain;
  object-position: center bottom;
}

@keyframes scene-breathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}

/* ----- Track band ----- */
.scene__track {
  position: absolute;
  inset: 0;
  z-index: 1;
}

/* Visible part of the rail. It spans the full height so lights, dots and puffs are never clipped;
   only a rail longer than the window (more than railVisibleStations) clips and fades at the edges. */
.scene__rail-window {
  position: absolute;
  left: 12%;
  right: 12%;
  top: 0;
  bottom: 0;
}

.scene__rail-window.is-scrollable {
  overflow: hidden;
  -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 3%, #000 97%, transparent 100%);
  mask-image: linear-gradient(90deg, transparent 0, #000 3%, #000 97%, transparent 100%);
}

/* The rail strip: width (share of the window) and --rail-x scroll are set by js/scene.js. */
.scene__rails {
  position: absolute;
  left: 0;
  width: 100%;
  bottom: 12.5%;
  height: 1.6%;
  border-radius: 999px;
  background:
    linear-gradient(180deg, var(--scene-rail) 0 35%, transparent 35%),
    repeating-linear-gradient(90deg, var(--scene-sleeper) 0 0.7vw, transparent 0.7vw 2.2vw);
  transform: var(--rail-x, none);
}

.scene__rails::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 30%;
  height: 1.3vh;
  border-radius: 999px;
  /* A soft drift: a solid base with low rounded heaps on top. */
  background:
    linear-gradient(0deg, var(--scene-snow) 0 45%, transparent 45%),
    radial-gradient(ellipse 50% 90% at 50% 100%, var(--scene-snow) 94%, transparent 100%) 0 0 / 3.4vw 100% repeat-x;
  filter: drop-shadow(0 0.2vh 0 rgba(120, 144, 156, 0.35));
}

.scene__station {
  position: absolute;
  bottom: 100%;
  display: flex;
  flex-direction: column-reverse;
  align-items: center;
  transform: translateX(-50%);
}

.scene__station-post {
  width: 0.5vw;
  height: 5.5vh;
  border-radius: 0.3vw 0.3vw 0 0;
  background: var(--scene-post);
}

.scene__station-light {
  width: 2.8vh;
  height: 2.8vh;
  border-radius: 50%;
  background: var(--scene-light-off);
  border: 0.45vh solid #ffffff;
  box-shadow: 0 0.3vh 0.8vh rgba(47, 58, 86, 0.25);
}

.scene__station.is-complete .scene__station-light {
  background: var(--scene-highlight);
  box-shadow: 0 0 0 0.8vh rgba(255, 179, 0, 0.3), 0 0 2vh rgba(255, 179, 0, 0.7);
}

/* The train wrapper spans the rails, so translateX(%) is a share of the rail length. */
.scene__train {
  position: absolute;
  left: 0;
  bottom: 90%;
  width: 100%;
  height: 0;
  transform: var(--train-x, none);
}

.scene__train-body {
  position: absolute;
  left: 0;
  bottom: 0;
  width: var(--train-width, 16%);
  transform: translateX(calc(-100% - 0.8vw));
}

.scene__train-body svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.scene__wheel {
  transform-box: fill-box;
  transform-origin: center;
}

/* Cargo on the wagon roofs (roof top at 30% of the drawing height). Car 1 spans x 0–80 and car 2 x 90–170
   of the 300-wide drawing; the front wagon (car 2, next to the locomotive) is filled first. */
.scene__cargo {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 70%;
  height: 0;
}

.scene__cargo-car {
  position: absolute;
  bottom: 0;
  width: 26.667%;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 1%;
}

.scene__cargo-car--front {
  left: 30%;
}

.scene__cargo-car--rear {
  left: 0;
}

/* Wagons coupled behind the drawing; js/scene.js sets each one's left and width (shares of the drawing). */
.scene__coupled {
  position: absolute;
  inset: 0;
}

.scene__wagon {
  position: absolute;
  bottom: 0;
}

.scene__wagon svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

/* A coupled wagon's own cargo slot: its body spans 6–86% of the wagon drawing, the roof is at 30% height. */
.scene__wagon > .scene__cargo-car {
  left: 6%;
  bottom: 70%;
  width: 80%;
}

.scene__sticker {
  flex: 0 0 auto;
  width: 32%;
  aspect-ratio: 1;
  object-fit: contain;
  object-position: center bottom;
  /* The travel sway pivots where the sticker stands on the roof. */
  transform-origin: center bottom;
}

/* The real cargo image waits under its flying copy. */
.scene__sticker.is-arriving {
  opacity: 0;
}

/* Flying sticker copies, above the stage and the overlay; never touchable. */
.scene__fly {
  position: absolute;
  inset: 0;
  z-index: 7;
  pointer-events: none;
}

.scene__fly-sticker {
  position: absolute;
  object-fit: contain;
  object-position: center bottom;
}

.scene__puff {
  position: absolute;
  left: 86%;
  top: 2%;
  width: 1.6vw;
  height: 1.6vw;
  border-radius: 50%;
  background: #ffffff;
  opacity: 0;
}

.scene__dots {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 1vh);
  display: flex;
  gap: 0.8vw;
  transform: translateX(-50%);
}

.scene__dot {
  width: 1.9vh;
  height: 1.9vh;
  border-radius: 50%;
  background: var(--scene-dot-off);
  border: 0.35vh solid var(--color-zone-default, #90a4d4);
}

.scene__dot.is-current {
  border-color: var(--scene-sign-bg);
  transform: scale(1.25);
}

.scene__dot.is-done {
  background: var(--scene-success);
  border-color: var(--scene-success);
}

/* ----- Nav row ----- */
.scene__nav {
  grid-row: 4;
  grid-column: 1;
  position: relative;
  z-index: 4;
  justify-self: center;
  align-self: stretch;
  min-height: 0;
  max-width: 76vw;
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: center;
  gap: 3vw;
}

/* Nav buttons are expected to use var(--scene-nav-size); it always fits the 10% nav band. */
.scene__nav > * {
  flex: 0 0 auto;
  max-height: 100%;
}

/* ----- Reduced motion ----- */
.scene--reduced .scene__overlay-button {
  animation: none;
}

.scene--reduced {
  --scene-theme-ms: 0ms;
}

@media (prefers-reduced-motion: reduce) {
  .scene__overlay-button {
    animation: none;
  }

  .scene {
    --scene-theme-ms: 0ms;
  }
}
