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

:root {
  --nav-h: 56px;
  --bg-sky: #bfe8ff;
  --bg-sky-deep: #7fcdf5;
  --bg-water: #1f8fc4;
  --bg-water-deep: #115d8c;
  --panel: #ffffff;
  --text: #16324a;
  --sub: #4d6f8a;
  --accent: #ffd166;

  --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(22,50,74,.08);
  --shadow-md: 0 4px 12px rgba(22,50,74,.12);
  --shadow-lg: 0 10px 26px rgba(22,50,74,.18);

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

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

/* ── NAV ─────────────────────────────────────── */
.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(22,50,74,.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(22,50,74,.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(22,50,74,.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); }

.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,209,102,.5); color: #7a5200; }

/* ── VIEWS ───────────────────────────────────── */
.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); }

/* ── Cycle 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);
  background: linear-gradient(to bottom, var(--bg-sky) 0%, var(--bg-sky-deep) 60%, var(--bg-water) 60%, var(--bg-water-deep) 100%);
}

.station { position: absolute; cursor: pointer; transition: transform .15s ease; }
.station:active { transform: scale(.92); }
.station.station-active { animation: station-pop .45s ease; }
@keyframes station-pop { 0% { transform: scale(1); } 45% { transform: scale(1.18); } 100% { transform: scale(1); } }

/* Sun: radial gradient disc + a ring of rays that slowly rotates, plus a tiny
   friendly face -- a flat emoji reads much flatter than this at large sizes. */
.station-sun { top: 6%; right: 9%; width: 84px; height: 84px; }
.sun-rays {
  position: absolute; inset: -18px;
  background: repeating-conic-gradient(from 0deg, #ffd166 0deg 8deg, transparent 8deg 24deg);
  border-radius: 50%;
  opacity: .55;
  animation: sun-spin 24s linear infinite;
  mask: radial-gradient(circle, transparent 56%, #000 58%);
  -webkit-mask: radial-gradient(circle, transparent 56%, #000 58%);
}
@keyframes sun-spin { to { transform: rotate(360deg); } }
.sun-face {
  position: absolute; inset: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff6cf, #ffd166 65%, #ffb703 100%);
  box-shadow: var(--shadow-md);
  animation: sun-pulse 3.2s ease-in-out infinite;
}
@keyframes sun-pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.04); } }
.sun-eye { position: absolute; top: 42%; width: 6px; height: 8px; border-radius: 50%; background: #7a4a00; }
.sun-eye-l { left: 35%; } .sun-eye-r { right: 35%; }
.sun-smile { position: absolute; top: 54%; left: 50%; width: 20px; height: 10px; border: 3px solid #7a4a00; border-top: none; border-radius: 0 0 20px 20px; transform: translateX(-50%); }

/* Cloud: four overlapping rounded "puffs" instead of a single emoji glyph. */
.station-cloud { top: 16%; left: 8%; width: 96px; height: 56px; }
.cloud-shape { position: absolute; inset: 0; animation: cloud-float 5s ease-in-out infinite; }
@keyframes cloud-float { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
.puff { position: absolute; background: #fff; border-radius: 50%; box-shadow: var(--shadow-sm); }
.puff-1 { width: 46px; height: 46px; left: 4px; bottom: 0; }
.puff-2 { width: 58px; height: 58px; left: 30px; bottom: 4px; }
.puff-3 { width: 40px; height: 40px; left: 58px; bottom: 0; }
.puff-4 { width: 60px; height: 26px; left: 10px; bottom: 0; border-radius: 30px; }

.rain-drops { position: absolute; top: 34%; left: 12%; width: 60%; height: 24%; pointer-events: none; }
.rain-drops::before, .rain-drops::after {
  content: ""; position: absolute; width: 6px; height: 14px;
  background: #eaf7ff; border-radius: 50% 50% 50% 0; transform: rotate(45deg);
  opacity: 0; animation: rain-fall 2.4s linear infinite;
}
.rain-drops::before { left: 24%; animation-delay: 0s; }
.rain-drops::after { left: 66%; animation-delay: 1.2s; }
@keyframes rain-fall { 0% { top: -10%; opacity: 0; } 10% { opacity: .9; } 88% { opacity: .9; } 100% { top: 100%; opacity: 0; } }

.station-rain-label { top: 42%; left: 50%; transform: translateX(-50%); z-index: 3; }
.rain-icon { font-size: 42px; filter: drop-shadow(0 3px 4px rgba(22,50,74,.2)); }

/* Ocean: gradient body with two animated wave-crest SVGs layered for depth. */
.water-layer { position: absolute; inset: 60% 0 0 0; }
.station-ocean { position: absolute; inset: 0; }
.wave { position: absolute; top: -14px; left: 0; width: 200%; height: 24px; }
.wave path { fill: var(--bg-water); }
.wave-front path { fill: var(--bg-water-deep); opacity: .55; }
.wave-back { animation: wave-scroll 9s linear infinite; }
.wave-front { animation: wave-scroll 6s linear infinite reverse; top: -8px; }
@keyframes wave-scroll { from { transform: translateX(0); } to { transform: translateX(-50%); } }

/* Drippy: custom SVG character (teardrop + face), animated along the cycle
   loop. Percentage-based keyframe positions scale with the scene container
   across viewport widths rather than fixed pixels. */
.drippy { position: absolute; width: 46px; height: 55px; z-index: 5; animation: drippy-loop 11s ease-in-out infinite; }
.drippy-svg { width: 100%; height: 100%; filter: drop-shadow(0 4px 6px rgba(22,50,74,.25)); }
.drippy-body { fill: #4fc3e8; }
.drippy-shine { fill: rgba(255,255,255,.55); }
.drippy-eye { fill: #16324a; }
.drippy-smile { fill: none; stroke: #16324a; stroke-width: 3.5; stroke-linecap: round; }

@keyframes drippy-loop {
  0%   { top: 70%; left: 50%; transform: translate(-50%,-50%) scale(1) rotate(0deg); }
  20%  { top: 24%; left: 66%; transform: translate(-50%,-50%) scale(.72) rotate(-10deg); }
  40%  { top: 20%; left: 26%; transform: translate(-50%,-50%) scale(.86) rotate(6deg); }
  55%  { top: 20%; left: 26%; transform: translate(-50%,-50%) scale(1) rotate(0deg); }
  75%  { top: 48%; left: 46%; transform: translate(-50%,-50%) scale(1.05) rotate(4deg); }
  100% { top: 70%; left: 50%; transform: translate(-50%,-50%) scale(1) rotate(0deg); }
}

@media (prefers-reduced-motion: reduce) {
  .sun-rays, .sun-face, .cloud-shape, .rain-drops::before, .rain-drops::after,
  .wave-back, .wave-front, .drippy { animation: none !important; }
}

.station-caption {
  max-width: 480px;
  margin: var(--sp-4) auto 0;
  padding: var(--sp-5) 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 button ───────────────────────── */
.read-aloud-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: linear-gradient(135deg, #ffe29a, #ffd166);
  border: none;
  color: #6b4700;
  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,209,102,.5); }
  50% { box-shadow: var(--shadow-sm), 0 0 0 8px rgba(255,209,102,0); }
}

/* ── Story reader ─────────────────────────────── */
.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; }
.story-emoji { font-size: 72px; }

/* Per-page illustrated scenes (see STORY_SCENES in app.js) -- replaces the
   plain emoji-only illustration Ryan flagged 2026-08-22 ("just has an emoji,
   no pictures"). Reuses the same Drippy mark, sun/cloud/wave shapes as the
   Cycle view so the mascot and world are visually consistent everywhere. */
.story-scene { width: 100%; max-width: 260px; display: block; margin: 0 auto; border-radius: 20px; 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-drippy-body { fill: #4fc3e8; }
.story-drippy-shine { fill: rgba(255,255,255,.55); }
.story-drippy-eye { fill: #16324a; }
.story-drippy-smile { fill: none; stroke: #16324a; stroke-width: 3.5; stroke-linecap: round; }

.scene-spark { fill: #ffd166; animation: atmo-twinkle-alt 2s ease-in-out infinite; }
@keyframes atmo-twinkle-alt { 0%, 100% { opacity: .3; } 50% { opacity: 1; } }
.scene-sun-rays { animation: sun-spin 20s linear infinite; transform-origin: 140px 55px; }
.scene-motion-line { fill: none; stroke: #bfe8ff; stroke-width: 4; stroke-linecap: round; opacity: .8; }
.scene-raindrop { fill: #7fcdf5; animation: scene-rain-fall 1.6s ease-in infinite; }
.scene-raindrop-2 { animation-delay: .6s; }
@keyframes scene-rain-fall { 0% { transform: translateY(0); opacity: 0; } 15% { opacity: 1; } 90% { opacity: 1; } 100% { transform: translateY(50px); opacity: 0; } }
.scene-loop { stroke-dasharray: 377; stroke-dashoffset: 377; animation: scene-loop-draw 2.4s ease-out .2s forwards; } /* 2*pi*60, matches the circle's real r=60 exactly */
@keyframes scene-loop-draw { to { stroke-dashoffset: 0; } }

@media (prefers-reduced-motion: reduce) {
  .scene-spark, .scene-sun-rays, .scene-raindrop, .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, #ffe29a, #ffd166);
  color: #6b4700;
  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; }

/* ── Narrow screens / Fold-7 cover width ─────── */
@media (max-width: 430px) {
  h1 { font-size: 12px; }
  h1 small { display: none; }
  .tab { padding: 7px 10px; font-size: 12px; }
  .station-sun { width: 68px; height: 68px; }
  .station-cloud { width: 76px; height: 44px; }
  .puff-1 { width: 36px; height: 36px; }
  .puff-2 { width: 46px; height: 46px; left: 24px; }
  .puff-3 { width: 32px; height: 32px; left: 46px; }
  .puff-4 { width: 48px; height: 20px; left: 8px; }
  .rain-icon { font-size: 34px; }
  .drippy { width: 38px; height: 45px; }
  .scene { border-radius: 0 0 22px 22px; }
}
@media (max-width: 340px) {
  .subtitle { font-size: 13px; }
  h1 { font-size: 0; }
  .tab { padding: 6px 8px; font-size: 12px; }
}

/* ── "Read this page" button, lives IN THE NAV BAR ───────────────────────
   Was a fixed bottom-right floating button -- found as a real bug 2026-08-22:
   it physically overlapped whatever content a view happened to render near
   the bottom of the CURRENT VIEWPORT (confirmed blocking Story's "Next"
   button via getBoundingClientRect). Padding-bottom on the view container
   does NOT fix this -- it only adds scrollable space AFTER existing content,
   it never moves already-flowed content up off a fixed-position overlay.
   The nav bar is a protected zone I fully control and nothing else ever
   renders into, so a button placed there can never collide with per-view
   content, at the cost of being a bit smaller than a floating FAB. */
.read-page-btn {
  flex-shrink: 0;
  width: 36px; height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #ffe29a, #ffb347);
  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: 17px; }
.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,179,71,.5); }
  50% { box-shadow: var(--shadow-sm), 0 0 0 8px rgba(255,179,71,0); }
}
@media (prefers-reduced-motion: reduce) { .read-page-btn.reading { animation: none; } }
