*, *::before, *::after { box-sizing: border-box; }

/* ── Design tokens — same system as the rest of Little Explorers (see DESIGN-PATTERNS.md §1) ── */
:root {
  --nav-h: 56px;
  --bg-sky-cold: #dceffb;   /* early morning, cold light */
  --bg-sky-warm: #cfeaff;   /* midday blue that will warm toward amber at day's end (tinted via overlay, not by changing this value) */
  --panel: #ffffff;
  --text: #223a4f;
  --sub: #5b7085;
  --accent: #ff9f43;
  --ice-blue: #7fd3e8;
  --water-blue: #2fb8c6;
  --steam-gray: #aebac4;

  --font-display: 'Fredoka', system-ui, sans-serif;
  --font-body: 'Quicksand', system-ui, sans-serif;

  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 20px; --sp-6: 24px; --sp-7: 32px;

  --shadow-sm: 0 1px 2px rgba(34,58,79,.08);
  --shadow-md: 0 4px 12px rgba(34,58,79,.12);
  --shadow-lg: 0 10px 26px rgba(34,58,79,.18);

  --radius-md: 18px; --radius-lg: 26px;
}

html, body { margin: 0; padding: 0; font-family: var(--font-body); background: linear-gradient(to bottom, var(--bg-sky-cold), var(--bg-sky-warm)); color: var(--text); overflow-x: hidden; }

.top-bar {
  position: fixed; top: 0; left: 0; right: 0; height: var(--nav-h);
  display: flex; align-items: center; justify-content: space-between; padding: 0 10px;
  background: rgba(255,255,255,.9); backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(34,58,79,.08); box-shadow: var(--shadow-sm); z-index: 100; gap: 6px;
}
.home-btn {
  flex-shrink: 0; display: flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; font-size: 18px; border-radius: 50%;
  background: rgba(34,58,79,.06); text-decoration: none; transition: transform .15s;
}
.home-btn:hover { transform: scale(1.1) rotate(-8deg); }
.nav-left { display: flex; align-items: center; gap: 6px; min-width: 0; }
.logo { font-size: 22px; }
h1 { margin: 0; font-family: var(--font-display); font-size: 14px; line-height: 1.1; font-weight: 600; }
h1 small { display: block; font-size: 12px; color: var(--sub); font-weight: 600; font-family: var(--font-body); }
.sound-toggle { flex-shrink: 0; background: rgba(34,58,79,.06); border: none; color: var(--text); font-size: 16px; padding: 7px 10px; border-radius: 12px; cursor: pointer; transition: transform .12s; }
.sound-toggle:active { transform: scale(.9); }

.read-page-btn {
  flex-shrink: 0; width: 34px; height: 34px; border-radius: 50%;
  background: linear-gradient(135deg, #ffe29a, #ffd166); border: none; box-shadow: var(--shadow-sm);
  display: flex; align-items: center; justify-content: center; cursor: pointer; transition: transform .15s;
}
.read-page-btn:active { transform: scale(.9); }
.read-page-icon { font-size: 16px; }
.read-page-btn.reading { animation: read-page-pulse 1s ease-in-out infinite; }
@keyframes read-page-pulse { 0%,100% { box-shadow: var(--shadow-sm), 0 0 0 0 rgba(255,209,102,.5); } 50% { box-shadow: var(--shadow-sm), 0 0 0 8px rgba(255,209,102,0); } }

.nav-tabs { display: flex; gap: 4px; min-width: 0; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.nav-tabs::-webkit-scrollbar { display: none; }
.tab { background: transparent; border: none; color: var(--sub); padding: 8px 13px; cursor: pointer; font-family: var(--font-display); font-size: 13px; font-weight: 600; border-radius: 16px; flex-shrink: 0; white-space: nowrap; transition: background .15s; }
.tab.active { background: rgba(255,159,67,.25); color: #a35300; }

.view { display: none; padding-top: calc(var(--nav-h) + 10px); min-height: 100vh; }
.view.active { display: block; animation: view-in .3s ease both; }
@keyframes view-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.subtitle { text-align: center; font-size: 15px; font-weight: 700; color: var(--text); margin: 0 16px var(--sp-4); }

/* ── The Journey scene ─────────────────────────────────────── */
.cycle-view { padding-bottom: 30px; }
.scene {
  position: relative; height: min(64vh, 500px); margin: 0 auto; max-width: 480px;
  border-radius: 0 0 32px 32px; overflow: hidden; box-shadow: var(--shadow-md);
}
.scene-backdrop { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 0; }

/* Sun arcs across the day — same technique as Day & Night's Sunny (CSS keyframed left/top loop),
   scaled to this scene's shorter canvas. It "warms up" visually by growing slightly brighter/hotter in
   hue over the full cycle via a second, independent tint overlay below.
   BUGFIX 2026-08-29: this used to be two separate animations — one setting `top`/`left`
   percentages for position, one setting `transform: translate(-50%, ±N%) scale(...)` for the
   "bob"/glow. Neither actually worked: `top`/`left` are not valid on SVG elements (silently
   ignored — SVG <g> isn't a CSS layout box), and in SVG, percentages inside `transform` resolve
   against the whole viewBox (360x240 here), not the element's own size, so `-50%` was a constant
   -180,-120 unit offset every frame, not a centering trick. Net effect confirmed via a live
   headless screenshot: the sun never actually arced across the sky at all. Fixed by merging both
   into one animation driven entirely by `transform: translate(Xpx, Ypx) scale(S)` in the
   backdrop SVG's own 0-360 x 0-240 user-unit space (`viewBox="0 0 360 240"`) — for SVG elements,
   CSS transform px IS the local user unit, so these numbers plug in directly. */
@keyframes som-sun-arc {
  0%   { transform: translate(36px, 149px) scale(.9);   opacity: .9; }
  25%  { transform: translate(126px, 43px) scale(1.05); opacity: 1; }
  50%  { transform: translate(198px, 34px) scale(1);    opacity: 1; }
  65%  { transform: translate(259px, 29px) scale(1.08); opacity: 1; } /* highest/hottest moment of the whole loop — peak heat, when steam becomes possible later in Frosty's journey */
  82%  { transform: translate(317px, 72px) scale(.9);   opacity: .95; }
  100% { transform: translate(36px, 149px) scale(.9);   opacity: .9; }
}

/* transform-box: fill-box (both here and on the other transform-origin rules below) matters a
   lot once translate+scale are combined: Chromium's SVG default transform-box is `view-box`,
   meaning `transform-origin: center` resolves to the center of the WHOLE viewBox (not this
   element's own shape) unless overridden. Scaling around the wrong, far-away origin point drags
   the element toward that point as scale shrinks — exactly what was pulling Frosty off-canvas
   before this element also picked up an explicit `translate()+scale()` in the same property. */
#day-sun { animation: som-sun-arc 30s ease-in-out infinite; transform-origin: center; transform-box: fill-box; will-change: transform; }
.sun-core { fill: url(#sunGlow); animation: sun-pulse 3.2s ease-in-out infinite; }
@keyframes sun-pulse { 0%,100% { opacity: .95; } 50% { opacity: 1; } }
.sun-rays-mini { animation: sun-spin 24s linear infinite; transform-origin: center; transform-box: fill-box; } /* rays are drawn symmetric around their own local origin, so "center" of their own fill-box IS that origin -- the previous literal "0 0" meant the corner of the whole 360x240 canvas under the (default) view-box transform-box, not this group's own center */
@keyframes sun-spin { to { transform: rotate(360deg); } }

/* Warmth tint over the whole scene: cool early (mostly invisible), warms up mid-day toward amber,
   back down by end of loop. Independent of anything interactive — purely sets the "time of day" mood. */
.warm-tint { position: absolute; inset: 0; pointer-events: none; z-index: 1; background: #ffb703; mix-blend-mode: soft-light; animation: warm-cycle 30s ease-in-out infinite; }
@keyframes warm-cycle {
  0% { opacity: 0; } 20% { opacity: .08; } 55% { opacity: .28; } 75% { opacity: .12; } 100% { opacity: 0; }
}

/* Frosty's own independent arc across the same canvas: starts bottom-left (cold/ice) and travels
   rightward along a low-to-high path through water (center) up to steam (top-right-ish), then fades
   and restarts — deliberately offset from the sun's timing so the two never appear "stuck together." */
.frosty-traveller { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 4; pointer-events: none; }
/* Frosty himself is tappable, not just the ice/water/steam hotspots — a little bonus delight
   for kids who go straight for the character (added 2026-08-29). pointer-events stays off on
   the whole traveller SVG above so it never blocks taps on stations/background; re-enabled only
   on this one group, so only Frosty's own painted shape is clickable, never his empty bounding box. */
#frosty-pos { animation: frosty-journey 30s ease-in-out infinite; transform-origin: center; transform-box: fill-box; will-change: transform; pointer-events: auto; cursor: pointer; }
/* BUGFIX 2026-08-29: this previously drove position with CSS `top`/`left` percentages, which do
   NOT apply to SVG elements at all (silently ignored, not an error -- SVG <g> isn't a CSS layout
   box) — so Frosty never actually moved. It also stacked a `translate(-50%,-50%)` "centering"
   step copied from ordinary HTML/CSS onto every keyframe; in SVG, percentages inside `transform`
   resolve against the whole viewBox, not the element's own size, so that step shoved Frosty a
   constant, wrong ~50-unit offset (half the entire 0-100 viewBox) regardless of keyframe. Net
   effect, confirmed via a live headless screenshot: Frosty rendered as a giant, mostly-static
   snowflake in roughly one fixed spot instead of a small character traveling ice→water→steam.
   Fixed by driving position entirely through `transform: translate(Xpx, Ypx)` in the traveller
   SVG's own 0-100 user-unit space (matching its `viewBox="0 0 100 100"`) — for SVG elements, CSS
   transform px IS the local user unit, so these numbers line up directly with the viewBox. Scale
   values also shrunk (was up to 1.05x — a snowflake with a 48-unit arm-span at that scale filled
   nearly half the scene) so Frosty reads as a traveling character, not a screen-filling shape. */
@keyframes frosty-journey {
  /* cold start: resting near the ice station, lower on the scene */
  0%, 6%    { transform: translate(12px, 74px) scale(.26); opacity: 0; }
  10%       { opacity: 1; }
  8%, 34%   { transform: translate(22px, 70px) scale(.24); } /* lingering at Ice before moving on */
  /* melting into travel along the stream */
  46%       { transform: translate(48px, 56px) scale(.27); }
  54%, 58%  { transform: translate(56px, 52px) scale(.28); } /* passing through Water */
  /* warming up toward steam — rising as it goes */
  70%       { transform: translate(78px, 34px) scale(.23); }
  78%       { transform: translate(86px, 24px) scale(.18); opacity: .95; }
  88%       { transform: translate(90px, 18px) scale(.14); opacity: .5; }
  94%       { opacity: 0; }
  94.1%,100%{ transform: translate(12px, 74px) scale(.26); opacity: 0; }
}

.frosty-inner { animation: frosty-bob 4.4s ease-in-out infinite; transform-origin: center; transform-box: fill-box; }
@keyframes frosty-bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }
.flake-arms line { stroke-linecap: round; }
/* Face stays readable (doesn't spin) even while the arms do — only the flake arm group animates, so
   the face (sibling elements, not inside this group) stays put and upright the whole time. */
.flake-arms { transform-origin: center; transform-box: fill-box; animation: frosty-arm-spin 10s linear infinite; }
@keyframes frosty-arm-spin { to { transform: rotate(360deg); } }
.frosty-eye { fill: #2a3f5c; }
.frosty-smile { fill: none; stroke: #2a3f5c; stroke-width: 3; stroke-linecap: round; }

/* Station hotspots — same tappable-station pattern as Water Cycle/Day & Night. */
.station { position: absolute; cursor: pointer; transition: transform .15s ease; z-index: 6; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px; -webkit-tap-highlight-color: transparent; }
.station:active { transform: scale(.9); }
.station-active .som-icon { animation: station-pop .45s ease; }
@keyframes station-pop { 0% { transform: scale(1); } 45% { transform: scale(1.25); } 100% { transform: scale(1); } }

.som-icon { font-size: 30px; filter: drop-shadow(0 3px 4px rgba(0,0,0,.2)); line-height: 1; user-select: none; }
.station-label {
  font-family: var(--font-display); font-weight: 700; font-size: 12px; color: #fff; text-align: center;
  background: rgba(34,58,79,.55); border-radius: 10px; padding: 2px 10px; backdrop-filter: blur(2px);
}

/* Station placement mirrors Frosty's own journey endpoints so the visual story and the tappable
   hotspots land on the same spots instead of feeling randomly scattered across unrelated areas. */
.station-ice    { top: 66%; left: 10%; }
.station-water  { top: 50%; left: 50%; transform: translate(-50%, -50%); }
.station-steam  { top: 20%; right: 9%; }

/* Distinct little "props" under each station to sell what that state actually is — not just an emoji floating in sky. */
.som-ice-badge::before  { content: ""; position: absolute; bottom: -14px; width: 92px; height: 30px; background: linear-gradient(to bottom, #dceffb, #9fdcec); border-radius: 50%/60%; box-shadow: var(--shadow-sm); z-index: -1; }
.som-droplet::after     { content: ""; position: absolute; bottom: -18px; width: 74px; height: 12px; background: radial-gradient(ellipse at center, rgba(47,184,198,.55), transparent 75%); animation: water-shimmer 2.6s ease-in-out infinite; z-index: -1; }
@keyframes water-shimmer { 0%,100% { opacity: .6; transform: scaleX(1); } 50% { opacity: 1; transform: scaleX(1.08); } }
.som-steam-badge { position: relative; }
.som-steam-badge::before, .som-steam-badge::after { content: ""; position: absolute; top: -8px; width: 7px; height: 22px; border-radius: 50%; background: rgba(255,255,255,.7); filter: blur(2px); z-index: -1; animation: steam-rise 3s ease-in infinite; }
.som-steam-badge::before { left: -14px; animation-delay: 0s; }
.som-steam-badge::after  { left: 12px;  animation-delay: 1.4s; }
@keyframes steam-rise { 0% { transform: translateY(10px) scaleY(.6); opacity: 0; } 30% { opacity: .9; } 100% { transform: translateY(-26px) scaleY(1.3); opacity: 0; } }

.ground-ridge { position: absolute; left: 0; right: 0; bottom: 0; height: 26%; background: linear-gradient(to bottom, #bfe8f5 0%, #8fd0e6 100%); border-radius: 46% 46% 0 0 / 100% 100% 0 0; z-index: 2; box-shadow: inset 0 6px 12px rgba(255,255,255,.4); }

@media (prefers-reduced-motion: reduce) {
  #day-sun, .warm-tint, .sun-core, .sun-rays-mini, #frosty-pos, .flake-arms, .som-droplet::after, .som-steam-badge::before, .som-steam-badge::after, .frosty-spark { animation: none !important; opacity: 0; }
}

/* Little burst of sparkles when a kid taps Frosty directly. Independent, freshly-created
   elements (not a second animation stacked on Frosty's own already-animated groups) so this
   never fights the existing frosty-journey/frosty-bob transforms — see DESIGN-PATTERNS.md
   "SVG transform vs CSS animation conflict" gotcha for why that combo breaks. */
.frosty-spark {
  position: absolute; width: 9px; height: 9px; border-radius: 50%;
  background: radial-gradient(circle, #fff8dd 0%, #ffd166 70%, transparent 100%);
  pointer-events: none; z-index: 7; transform: translate(-50%, -50%);
  animation: frosty-giggle-spark .65s ease-out forwards;
}
@keyframes frosty-giggle-spark {
  0%   { transform: translate(-50%, -50%) scale(.3); opacity: 0; }
  30%  { opacity: 1; }
  100% { transform: translate(-50%, -160%) scale(1); opacity: 0; }
}

/* ── Station caption card ─────────────────────────────────── */
.station-caption { max-width: 480px; margin: var(--sp-4) auto 0; padding: var(--sp-5); background: var(--panel); border-radius: var(--radius-lg); box-shadow: var(--shadow-md); text-align: center; }
.caption-emoji { font-size: 34px; margin-bottom: var(--sp-2); }
#caption-text { font-family: var(--font-display); font-size: 17px; font-weight: 600; margin: 0 0 var(--sp-3); line-height: 1.4; color: var(--text); }

.read-aloud-btn { display: inline-flex; align-items: center; gap: 6px; background: linear-gradient(135deg, #ffe0b8, #ffc088); border: none; color: #7a4400; border-radius: 20px; padding: 10px 20px; font-family: var(--font-display); font-size: 14px; font-weight: 600; cursor: pointer; box-shadow: var(--shadow-sm); transition: transform .12s; }
.read-aloud-btn:active { transform: scale(.96); }
.read-aloud-btn.reading { animation: read-aloud-pulse 1s ease-in-out infinite; }
@keyframes read-aloud-pulse { 0%,100% { box-shadow: var(--shadow-sm), 0 0 0 0 rgba(255,159,67,.5); } 50% { box-shadow: var(--shadow-sm), 0 0 0 8px rgba(255,159,67,0); } }

/* ── Story Time — same layout as the other apps' story readers ─────────── */
.story-view h2 { text-align: center; margin: 0 0 4px; font-family: var(--font-display); font-size: 24px; font-weight: 600; }
.story-reader { max-width: 460px; margin: 0 auto; padding: 0 16px 30px; text-align: center; }
.story-art { background: var(--panel); border-radius: var(--radius-lg); padding: 20px; margin-bottom: var(--sp-4); box-shadow: var(--shadow-md); overflow: hidden; width: 100%; max-width: 320px; aspect-ratio: 1; display: grid; place-items: center; margin-left: auto; margin-right: auto; }
.story-scene { width: 100%; height: 100%; display: block; animation: scene-in .4s cubic-bezier(.2,.8,.3,1.1) both; }
@keyframes scene-in { from { opacity: 0; transform: scale(.92); } to { opacity: 1; transform: none; } }
.story-emoji { font-size: 72px; }

.scene-spark-mini { fill: #fff; animation: atmo-twinkle-alt 2.4s ease-in-out infinite; }
@keyframes atmo-twinkle-alt { 0%,100% { opacity: .25; } 50% { opacity: 1; } }
.scene-sun-rays-mini { animation: sun-spin 20s linear infinite; transform-origin: 100px 60px; }
.scene-loop { stroke-dasharray: 377; stroke-dashoffset: 377; animation: scene-loop-draw 2.4s ease-out .2s forwards; }
@keyframes scene-loop-draw { to { stroke-dashoffset: 0; } }

@media (prefers-reduced-motion: reduce) {
  .scene-spark-mini, .scene-sun-rays-mini, .scene-loop, .story-scene { animation: none !important; opacity: 1; stroke-dashoffset: 0; }
}

.story-title { font-family: var(--font-display); font-size: 21px; font-weight: 600; margin: 0 0 var(--sp-2); }
.story-script { font-size: 16px; line-height: 1.55; color: var(--text); background: var(--panel); border-radius: var(--radius-md); padding: var(--sp-4); margin-bottom: var(--sp-4); box-shadow: var(--shadow-sm); }
.play-btn { display: inline-flex; align-items: center; gap: 10px; background: linear-gradient(135deg, #ffe0b8, #ffc088); color: #7a4400; border: none; border-radius: 26px; padding: 15px 28px; font-family: var(--font-display); font-size: 17px; font-weight: 600; cursor: pointer; box-shadow: var(--shadow-md); margin-bottom: var(--sp-4); transition: transform .15s; }
.play-btn:active { transform: scale(.96); }

.story-nav { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); }
.nav-story-btn { background: var(--panel); border: none; border-radius: var(--radius-md); padding: var(--sp-3) var(--sp-4); font-family: var(--font-display); font-size: 14px; font-weight: 600; cursor: pointer; box-shadow: var(--shadow-sm); transition: transform .12s; }
.nav-story-btn:active:not(:disabled) { transform: scale(.95); }
.nav-story-btn:disabled { opacity: .35; cursor: default; box-shadow: none; }
.story-counter { font-size: 13px; font-weight: 700; color: var(--sub); }
.tiny-note { text-align: center; font-size: 12px; color: var(--sub); padding: 0 20px; }

@media (max-width: 430px) {
  h1 { font-size: 12px; } h1 small { display: none; }
  .tab { padding: 7px 10px; font-size: 12px; }
  .som-icon { font-size: 24px; }
  .station-label { font-size: 12px; padding: 1px 8px; }
}
@media (max-width: 340px) {
  .subtitle { font-size: 13px; }
  h1 { font-size: 0; }
  .tab { padding: 6px 8px; font-size: 12px; }
  .scene { border-radius: 0 0 22px 22px; height: min(58vh, 420px); }
}
