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

:root {
  --nav-h: 56px;
  --bg-sky: #fff2d6;
  --bg-sky-deep: #ffe4b0;
  --panel: #ffffff;
  --text: #4a3520;
  --sub: #8a6f52;
  --accent: #ff9f43;

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

.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(74,53,32,.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(74,53,32,.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(74,53,32,.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); }

.cycle-view { padding-bottom: 30px; }
.scene {
  position: relative; height: min(60vh, 460px); margin: 0 auto; max-width: 460px;
  border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow-md);
  background: radial-gradient(circle at 50% 40%, var(--bg-sky) 0%, var(--bg-sky-deep) 100%);
}
.sammy-svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.sammy-head { animation: sammy-breathe 3.6s ease-in-out infinite; transform-origin: 110px 120px; }
@keyframes sammy-breathe { 0%,100% { transform: scale(1); } 50% { transform: scale(1.015); } }
.sammy-ear { animation: sammy-breathe 3.6s ease-in-out infinite; }

.station { position: absolute; cursor: pointer; transition: transform .15s ease; display: flex; align-items: center; justify-content: center; }
.station:active { transform: scale(.9); }
.station.station-active { animation: station-pop .45s ease; }
@keyframes station-pop { 0% { transform: scale(1); } 45% { transform: scale(1.25); } 100% { transform: scale(1); } }

.station-eyes { top: 34%; left: 50%; transform: translate(-50%,-50%); width: 90px; height: 40px; gap: 22px; }
.sammy-eye { width: 20px; height: 20px; border-radius: 50%; background: #4a3520; animation: eye-blink 4s ease-in-out infinite; }
@keyframes eye-blink { 0%, 92%, 100% { transform: scaleY(1); } 95% { transform: scaleY(.1); } }

.station-ear-l { top: 40%; left: 10%; width: 50px; height: 50px; }
.station-ear-r { top: 40%; right: 10%; width: 50px; height: 50px; }

.station-nose { top: 48%; left: 50%; transform: translate(-50%,-50%); font-size: 26px; }
.station-mouth { top: 62%; left: 50%; transform: translate(-50%,-50%); width: 70px; height: 30px; }
.sammy-mouth { width: 56px; height: 22px; border: 4px solid #a35300; border-top: none; border-radius: 0 0 40px 40px; animation: mouth-talk 2.4s ease-in-out infinite; }
@keyframes mouth-talk { 0%,100% { height: 22px; } 50% { height: 14px; } }

.station-hand { bottom: 6%; right: 8%; font-size: 40px; animation: hand-wave 1.8s ease-in-out infinite; transform-origin: bottom center; }
@keyframes hand-wave { 0%,100% { transform: rotate(-8deg); } 50% { transform: rotate(12deg); } }

@media (prefers-reduced-motion: reduce) {
  .sammy-head, .sammy-ear, .sammy-eye, .sammy-mouth, .station-hand { animation: none !important; }
}

.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-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 { fill: #ffd166; animation: atmo-twinkle-alt 2s ease-in-out infinite; }
@keyframes atmo-twinkle-alt { 0%,100% { opacity: .3; } 50% { opacity: 1; } }
.scene-soundwave { animation: soundwave-pulse 1.2s ease-in-out infinite; opacity: .8; }
.scene-soundwave-2 { animation-delay: .3s; }
@keyframes soundwave-pulse { 0%,100% { opacity: .4; } 50% { opacity: 1; } }
.scene-scent { animation: scent-rise 2.4s ease-in-out infinite; opacity: .8; }
@keyframes scent-rise { 0%,100% { transform: translateY(0); opacity: .5; } 50% { transform: translateY(-6px); opacity: 1; } }
.scene-hand { animation: hand-wave 1.8s ease-in-out infinite; transform-origin: 160px 165px; display: inline-block; }
.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, .scene-soundwave, .scene-soundwave-2, .scene-scent, .scene-hand, .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; }
  .station-hand { font-size: 32px; }
  .sammy-eye { width: 16px; height: 16px; }
}
@media (max-width: 340px) {
  .subtitle { font-size: 13px; }
  h1 { font-size: 0; }
  .tab { padding: 6px 8px; font-size: 12px; }
}
