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

:root {
  --nav-h: 56px;
  --bg-sky: #bfe6ff;
  --bg-sky-deep: #ffd9a0;
  --bg-night: #1b2340;
  --panel: #ffffff;
  --text: #2a2440;
  --sub: #6b5f8a;
  --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(42,36,64,.08);
  --shadow-md: 0 4px 12px rgba(42,36,64,.12);
  --shadow-lg: 0 10px 26px rgba(42,36,64,.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(42,36,64,.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(42,36,64,.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(42,36,64,.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(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) 68%, #7cb342 68%, #5a8f34 100%);
}

.stars-layer { position: absolute; inset: 0 0 32% 0; pointer-events: none; z-index: 1; }
.dn-star {
  position: absolute; width: 3px; height: 3px; border-radius: 50%;
  background: #fff; opacity: 0; animation: dn-star-twinkle 3.6s ease-in-out infinite;
}
@keyframes dn-star-twinkle { 0%, 100% { opacity: 0; } 45% { opacity: .1; } 50% { opacity: .75; } 55% { opacity: .1; } }

.station { position: absolute; cursor: pointer; transition: transform .15s ease; z-index: 3; 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); } }
.dn-icon { font-size: 34px; filter: drop-shadow(0 3px 4px rgba(0,0,0,.2)); }

.station-morning { top: 58%; left: 8%; }
.station-noon { top: 8%; left: 50%; transform: translateX(-50%); }
.station-noon.station-active { animation: station-pop .45s ease; }
.station-evening { top: 58%; right: 8%; }
.station-night { top: 12%; right: 6%; }

.sunny { position: absolute; width: 72px; height: 72px; z-index: 4; animation: sunny-arc-loop 16s ease-in-out infinite; }
.sunny-rays { position: absolute; inset: -16px; 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); } }
.sunny-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.05); } }
.sunny-eye { position: absolute; top: 42%; width: 7px; height: 9px; border-radius: 50%; background: #7a4a00; }
.sunny-eye:first-of-type { left: 34%; } .sunny-eye:last-of-type { right: 34%; }
.sunny-smile { position: absolute; top: 55%; left: 50%; width: 22px; height: 11px; border: 3px solid #7a4a00; border-top: none; border-radius: 0 0 22px 22px; transform: translateX(-50%); }

@keyframes sunny-arc-loop {
  0%   { top: 60%; left: 10%; transform: translate(-50%,-50%) scale(.85); opacity: .95; }
  22%  { top: 12%; left: 50%; transform: translate(-50%,-50%) scale(1.1); opacity: 1; }
  45%  { top: 60%; left: 88%; transform: translate(-50%,-50%) scale(.85); opacity: .95; }
  58%  { top: 78%; left: 92%; transform: translate(-50%,-50%) scale(.4); opacity: 0; }
  85%  { top: 78%; left: 92%; transform: translate(-50%,-50%) scale(.4); opacity: 0; }
  92%  { top: 60%; left: 10%; transform: translate(-50%,-50%) scale(.6); opacity: .6; }
  100% { top: 60%; left: 10%; transform: translate(-50%,-50%) scale(.85); opacity: .95; }
}

.ground-hill { position: absolute; left: 0; right: 0; bottom: 0; height: 34%; background: radial-gradient(ellipse at 50% 100%, #8fc857 0%, #5a8f34 70%); border-radius: 50% 50% 0 0 / 100% 100% 0 0; z-index: 2; }

@media (prefers-reduced-motion: reduce) {
  .dn-star, .sunny, .sunny-rays, .sunny-face { 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-mini { fill: #fff; animation: atmo-twinkle-alt 2.4s ease-in-out infinite; }
@keyframes atmo-twinkle-alt { 0%,100% { opacity: .2; } 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; }
  .dn-icon { font-size: 26px; }
  .sunny { width: 56px; height: 56px; }
  .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; }
}
