:root {
  --ink: #29364f;
  --purple: #684fa0;
  --paper: rgba(255, 255, 255, .95);
  --shadow: 0 16px 34px rgba(67, 43, 111, .2);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
body { min-height: 100vh; margin: 0; color: var(--ink); font-family: Fredoka, system-ui, sans-serif; background: linear-gradient(#e7dbff 0%, #faedff 55%, #c7e8ad 100%); }
button, a { font: inherit; }
button { cursor: pointer; border: 0; }
button:focus-visible, a:focus-visible { outline: 4px solid #29364f; outline-offset: 3px; }

.topbar { width: min(1100px, calc(100% - 32px)); margin: 14px auto 20px; display: grid; grid-template-columns: 58px minmax(0, 1fr) 58px; gap: 14px; align-items: center; }
.home, #sound { display: grid; width: 58px; height: 58px; place-items: center; border-radius: 18px; color: var(--ink); background: var(--paper); box-shadow: var(--shadow); text-decoration: none; font-size: 1.6rem; }
.topbar p { margin: 0; color: #725bb0; font-size: .78rem; font-weight: 700; letter-spacing: .08em; }
h1 { margin: 2px 0; font-size: clamp(1.85rem, 4vw, 2.8rem); line-height: 1; }
.topbar span { color: #64728a; font-weight: 600; }

.library { width: min(1100px, calc(100% - 32px)); margin: 0 auto 28px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.story-card { padding: 9px; border: 4px solid rgba(255, 255, 255, .9); border-radius: 24px; color: var(--ink); background: var(--paper); box-shadow: var(--shadow); text-align: left; }
.story-card:active { transform: scale(.98); }
.cover { width: 100%; aspect-ratio: 1 / .8; overflow: hidden; border-radius: 16px; background: #eadfff; }
.cover img { width: 100%; height: 100%; object-fit: cover; }
.story-card h2 { margin: 10px 4px 2px; font-size: clamp(1.15rem, 2.2vw, 1.45rem); }
.story-card p { margin: 0 4px 6px; color: #67758d; font-weight: 600; }

.player { position: fixed; inset: 0; z-index: 3; display: none; min-height: 100dvh; padding: max(14px, env(safe-area-inset-top)) clamp(18px, 3.5vw, 48px) max(18px, env(safe-area-inset-bottom)); background: linear-gradient(130deg, #d8c8fa, #fcedff); }
.player.active { display: flex; flex-direction: column; }
.reader-toolbar { width: min(1240px, 100%); min-height: 60px; margin: 0 auto clamp(8px, 1.6vw, 18px); display: grid; grid-template-columns: 58px minmax(0, 1fr) auto; gap: 14px; align-items: center; }
.close, .reader-sound { display: grid; width: 58px; height: 58px; place-items: center; border-radius: 18px; color: #5d4a8b; background: white; box-shadow: var(--shadow); font-size: 1.65rem; }
.reader-sound { justify-self: end; color: var(--ink); background: #fff7d9; }
.reader-controls { display: flex; align-items: center; justify-content: end; gap: 10px; }
.autoplay { min-height: 44px; padding: 8px 12px; border: 3px solid rgba(255, 255, 255, .86); border-radius: 16px; color: #5d4a8b; background: rgba(255, 255, 255, .92); box-shadow: var(--shadow); font-weight: 700; }
.autoplay[aria-pressed="false"] { color: #68758d; background: #edf0f5; }
.reader-heading { min-width: 0; text-align: center; }
.reader-heading p { margin: 0; overflow: hidden; color: #5c478e; font-size: clamp(1rem, 2vw, 1.25rem); font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.reader-heading span { color: #6a7790; font-size: .92rem; font-weight: 700; }

.reader-layout { width: min(1240px, 100%); min-height: 0; flex: 1; margin: 0 auto; display: grid; grid-template-columns: minmax(0, 1.8fr) minmax(270px, .88fr); gap: clamp(20px, 4vw, 54px); align-items: center; }
.reader-stage { position: relative; min-width: 0; display: grid; place-items: center; }
.scene { position: relative; width: 100%; aspect-ratio: 4 / 3; overflow: hidden; border: 5px solid white; border-radius: 28px; background: #f4edff; box-shadow: var(--shadow); touch-action: pan-y; }
.scene img, .scene video { display: block; width: 100%; height: 100%; object-fit: contain; }
.scene img { will-change: transform; }
.scene.motion-one img { animation: story-drift-one 14s ease-in-out both; }
.scene.motion-two img { animation: story-drift-two 14s ease-in-out both; }
.scene.motion-three img { animation: story-drift-three 14s ease-in-out both; }
.scene.video-active img { animation: none; }
.scene video { display: none; position: absolute; inset: 0; object-fit: cover; }
.scene.video-active video { display: block; }
.scene.turning { filter: brightness(.97); }
.page-turn { position: absolute; z-index: 1; top: 50%; width: 64px; height: 82px; transform: translateY(-50%); border-radius: 20px; color: white; background: rgba(82, 58, 133, .82); box-shadow: 0 8px 18px rgba(58, 39, 98, .25); font-size: 3rem; line-height: 1; transition: opacity .16s ease, transform .16s ease; }
.page-turn:active:not(:disabled) { transform: translateY(-50%) scale(.94); }
.page-turn.previous { left: 14px; }
.page-turn.next { right: 14px; }
.page-turn:disabled { opacity: .28; cursor: default; }

.copy { min-width: 0; padding: clamp(20px, 3vw, 32px); border-radius: 24px; background: var(--paper); box-shadow: var(--shadow); text-align: left; }
.reading-progress { width: 100%; height: 8px; overflow: hidden; border-radius: 999px; background: #e7ddf6; }
.reading-progress span { display: block; width: var(--progress, 8%); height: 100%; border-radius: inherit; background: linear-gradient(90deg, #8972c8, #d585c2); transition: width .2s ease; }
.copy h2 { margin: 18px 0 12px; font-size: clamp(1.55rem, 3.2vw, 2.25rem); line-height: 1.06; }
.copy #page-text { margin: 0; font-size: clamp(1.18rem, 2.25vw, 1.58rem); font-weight: 600; line-height: 1.38; }
.reader-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 24px; }
.reader-actions button { min-height: 54px; padding: 10px 15px; border-radius: 17px; color: white; background: var(--purple); box-shadow: 0 7px 14px rgba(95, 73, 150, .24); font-weight: 700; }
.swipe-cue { margin: 0; color: #76649b; font-size: .95rem; font-weight: 700; line-height: 1.15; text-align: right; }
.swipe-cue.hidden { visibility: hidden; }

@keyframes story-drift-one { from { transform: scale(1.015) translate3d(-.35%, -.15%, 0); } to { transform: scale(1.07) translate3d(.4%, .2%, 0); } }
@keyframes story-drift-two { from { transform: scale(1.07) translate3d(.35%, -.2%, 0); } to { transform: scale(1.015) translate3d(-.3%, .2%, 0); } }
@keyframes story-drift-three { from { transform: scale(1.025) translate3d(0, .35%, 0); } to { transform: scale(1.065) translate3d(0, -.25%, 0); } }

@media (max-width: 720px) {
  .topbar { width: min(100% - 20px, 1100px); grid-template-columns: 48px minmax(0, 1fr) 48px; gap: 10px; margin-top: 10px; }
  .home, #sound { width: 48px; height: 48px; border-radius: 15px; font-size: 1.3rem; }
  .library { width: min(100% - 20px, 1100px); grid-template-columns: 1fr; gap: 12px; }
  .story-card { display: grid; grid-template-columns: 40% 1fr; gap: 9px; align-items: center; }
  .story-card .cover { grid-row: 1 / 3; }
  .story-card h2 { margin: 0 4px; }
  .player { padding: max(10px, env(safe-area-inset-top)) 14px max(16px, env(safe-area-inset-bottom)); overflow-y: auto; }
  .reader-toolbar { grid-template-columns: 48px minmax(0, 1fr) auto; gap: 10px; }
  .close, .reader-sound { width: 48px; height: 48px; border-radius: 15px; font-size: 1.35rem; }
  .reader-controls { gap: 7px; }
  .autoplay { min-height: 40px; padding: 7px 9px; border-radius: 14px; font-size: .86rem; }
  .reader-layout { display: block; }
  .scene { border-radius: 20px; }
  .copy { margin-top: 14px; padding: 18px; border-radius: 20px; }
  .copy h2 { margin-top: 14px; }
  .page-turn { width: 56px; height: 70px; border-radius: 17px; font-size: 2.5rem; }
  .page-turn.previous { left: 10px; }
  .page-turn.next { right: 10px; }
}

@media (min-width: 721px) and (max-width: 1366px) and (orientation: landscape) {
  html, body { height: 100dvh; overflow: hidden; }
  .player { padding: max(10px, env(safe-area-inset-top)) 36px max(14px, env(safe-area-inset-bottom)); }
  .reader-toolbar { min-height: 52px; margin-bottom: 10px; }
  .close, .reader-sound { width: 50px; height: 50px; border-radius: 16px; }
  .autoplay { min-height: 42px; }
  .reader-layout { gap: 28px; grid-template-columns: minmax(0, 1.92fr) minmax(252px, .8fr); }
  .copy { padding: 20px; }
  .copy h2 { margin: 14px 0 10px; font-size: clamp(1.45rem, 3vw, 2rem); }
  .copy #page-text { font-size: 1.24rem; }
  .reader-actions { margin-top: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
