/* The reader: the scene on the left page, the words on the right, read
   aloud with each word lit as it is said. Also the hero on the home page. */

.reader-body { margin: 0; min-height: 100vh; min-height: 100dvh; background: var(--book-night, var(--night)); color: var(--paper); overflow: hidden; }

.reader { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; height: 100vh; height: 100dvh; gap: 12px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); }

.reader-bar { display: flex; align-items: center; gap: 14px; min-height: 52px; }
.reader-bar h1 { font-size: 1.25rem; margin-right: auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reader-bar .count { white-space: nowrap; font-variant-numeric: tabular-nums; color: rgb(253 248 238 / 0.75); font-size: 1rem; }
.round-button {
    flex: none; display: inline-flex; align-items: center; justify-content: center; width: 48px; height: 48px; border-radius: 50%;
    border: 0; background: rgb(255 255 255 / 0.1); color: var(--paper); text-decoration: none;
}
.round-button:hover { background: rgb(255 255 255 / 0.18); }
.round-button svg { width: 22px; height: 22px; }
.round-button[disabled] { opacity: 0.3; cursor: default; }

.reader-stage { position: relative; display: flex; align-items: center; justify-content: center; min-height: 0; }
.reader-stage .open-book { width: min(100%, calc((100dvh - 190px) * 1.5)); max-height: 100%; }

/* ─── The scene page ───────────────────────────────────────── */

.scene { position: relative; overflow: hidden; background: var(--book-night, var(--night)); }
.scene img, .scene video, .scene canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scene .still { animation: drift 16s ease-in-out infinite alternate; transform-origin: 50% 45%; }
.scene .fade-in { animation: scene-in 0.5s ease both; }
@keyframes drift { from { transform: scale(1.02) translate(0, 0); } to { transform: scale(1.09) translate(-1.2%, -1%); } }
@keyframes scene-in { from { opacity: 0; } to { opacity: 1; } }
.scene .scene-cover { filter: brightness(0.55) saturate(0.85); }

/* ─── The words page ───────────────────────────────────────── */

.words {
    position: relative; display: flex; flex-direction: column; justify-content: safe center; padding: 8% 10% 12% 12%;
    background: var(--paper); color: var(--ink); overflow-y: auto; min-height: 0;
    background-image: radial-gradient(circle at 70% 30%, rgb(255 255 255 / 0.7), transparent 60%);
}
.words .text { font-family: var(--text); font-size: clamp(1.125rem, 2.35vw, 2.125rem); line-height: 1.62; text-wrap: pretty; }
.words .folio { position: absolute; bottom: 5%; left: 0; right: 0; text-align: center; font-family: var(--title); font-size: 1rem; color: var(--ink-soft); }
.word { padding: 0; border: 0; background: transparent; color: inherit; font: inherit; text-align: inherit; border-radius: 0.24em; transition: background-color 0.12s ease, box-shadow 0.12s ease; cursor: pointer; }
.word:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; background: var(--moon); }
.word:hover { background: rgb(247 227 161 / 0.45); box-shadow: 0 0 0 0.08em rgb(247 227 161 / 0.45); }
.word.is-now { background: var(--moon); box-shadow: 0 0 0 0.12em var(--moon); }
.word.is-said { color: var(--ink); }
.reading .word:not(.is-said):not(.is-now) { color: #3b4155; }

.end, .paywall { display: grid; gap: 16px; align-content: center; justify-items: start; }
.end h2, .paywall h2 { font-size: clamp(1.75rem, 3.4vw, 2.75rem); }
.paywall p, .end p { color: var(--ink-soft); font-size: clamp(1rem, 1.6vw, 1.25rem); }
.paywall .actions { margin-top: 6px; }

/* ─── Controls ─────────────────────────────────────────────── */

.reader-controls { display: flex; align-items: center; justify-content: center; gap: 14px; flex-wrap: wrap; }
.play-button {
    display: inline-flex; align-items: center; gap: 12px; min-height: 60px; padding: 0 28px 0 22px; border-radius: 999px; border: 0;
    background: var(--moon); color: var(--night); font-weight: 700; font-size: 1.1875rem;
}
.play-button svg { width: 26px; height: 26px; }
.play-button:hover { background: #fbecbb; }
.turn-button { width: 60px; height: 60px; }
.toggle {
    display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 16px; border-radius: 999px;
    border: 2px solid rgb(253 248 238 / 0.3); background: transparent; color: var(--paper); font-weight: 700; font-size: 1rem;
}
.toggle[aria-pressed="true"] { border-color: var(--moon); color: var(--moon); }
.toggle svg { width: 18px; height: 18px; }
.reader-note { text-align: center; font-size: 0.9375rem; color: rgb(253 248 238 / 0.7); min-height: 1.4em; }

/* Big turn targets beside the book, for small hands */
.side-turn { position: absolute; top: 50%; transform: translateY(-50%); z-index: 3; }
.side-turn--prev { left: -8px; }
.side-turn--next { right: -8px; }
@media (max-width: 1100px) { .side-turn { display: none; } }

/* ─── Narrow and portrait screens: the scene above the page ─── */

@media (max-aspect-ratio: 1 / 1), (max-width: 640px) {
    .reader { overflow-y: auto; height: auto; min-height: 100dvh; }
    .reader-body { overflow: auto; }
    .reader-stage .open-book { width: 100%; grid-template-columns: 1fr; grid-template-rows: minmax(0, 0.95fr) auto; aspect-ratio: auto; height: auto; max-height: none; }
    .reader-stage .open-book::after { display: none; }
    .reader-stage .scene { aspect-ratio: 1 / 1; max-height: 56dvh; width: 100%; }
    .reader-stage .scene img, .reader-stage .scene video { object-position: 50% 72%; }
    .reader-stage .words { padding: 28px 24px 54px; }
    .reader-stage .words .text { font-size: clamp(1.25rem, 5.4vw, 1.75rem); }
}

/* ─── The hero version on the home page ────────────────────── */

.hero-reader .open-book { max-height: none; }
.hero-reader .words .text { font-size: clamp(1rem, 1.9vw, 1.75rem); }
.hero-reader .reader-controls { margin-top: 18px; }
.hero-reader .toggle, .hero-reader .round-button { color: var(--ink); border-color: var(--mist-line); background: var(--white); }
.hero-reader .reader-note { color: var(--ink-soft); }
@media (max-width: 640px) {
    .hero-reader .open-book { grid-template-columns: 1fr; aspect-ratio: auto; }
    .hero-reader .open-book::after { display: none; }
    .hero-reader .scene { aspect-ratio: 1 / 1; }
    .hero-reader .scene img, .hero-reader .scene video { object-position: 50% 72%; }
    .hero-reader .words { padding: 24px 22px 50px; }
}

@media (prefers-reduced-motion: reduce) {
    .scene .still, .scene .fade-in { animation: none; }
    .word { transition: none; }
}
.play-button:disabled { opacity: 0.45; cursor: default; }

@media (max-width: 640px) {
    .storybook-reader .open-book { grid-template-columns: 1fr; aspect-ratio: auto; }
    .storybook-reader .scene { aspect-ratio: 4 / 3; }
    .storybook-reader .words { padding: 24px; }
    .storybook-reader .words .text { font-size: 1.2rem; }
}

/* A real paper leaf, with an outgoing face and an incoming reverse. */
.open-book.is-turning { overflow: visible; isolation: isolate; }
.open-book.is-turning > .scene, .open-book.is-turning > .words { pointer-events: none; }
.page-turn { position: absolute; inset: 0; z-index: 8; perspective: 2400px; pointer-events: none; border-radius: inherit; }
.page-turn__rest { position: absolute; top: 0; bottom: 0; width: 50%; height: 100%; }
.page-turn--next .page-turn__rest { left: 0; }
.page-turn--prev .page-turn__rest { right: 0; }
.page-turn__leaf { position: absolute; top: 0; bottom: 0; width: 50%; transform-style: preserve-3d; will-change: transform; }
.page-turn--next .page-turn__leaf { right: 0; transform-origin: left center; }
.page-turn--prev .page-turn__leaf { left: 0; transform-origin: right center; }
.page-turn__face { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; overflow: hidden; background: var(--paper); border-radius: 4px 10px 10px 4px; box-shadow: 2px 0 8px rgb(57 43 23 / .1); }
.page-turn__face > .scene, .page-turn__face > .words { width: 100%; height: 100%; max-height: none; overflow: hidden; }
.page-turn__face::after { content: ''; position: absolute; inset: 0; pointer-events: none; background: linear-gradient(90deg, rgb(72 53 27 / .2), transparent 14%, rgb(255 255 255 / .12) 65%, rgb(72 53 27 / .08)); }
.page-turn__back { transform: rotateY(180deg); border-radius: 10px 4px 4px 10px; box-shadow: -14px 8px 24px rgb(43 35 20 / .18); }
.page-turn__back::after { background: linear-gradient(90deg, rgb(72 53 27 / .05), transparent 75%, rgb(72 53 27 / .2)); }
.page-turn--prev .page-turn__front { border-radius: 10px 4px 4px 10px; }
.page-turn--prev .page-turn__back { border-radius: 4px 10px 10px 4px; }
.page-turn--stacked { perspective: 1800px; }
.page-turn--stacked .page-turn__leaf { width: 100%; }
.page-turn--stacked .page-turn__front { display: grid; }
.page-turn--stacked .page-turn__face > .scene, .page-turn--stacked .page-turn__face > .words { min-height: 0; aspect-ratio: auto; }
.page-turn--stacked .page-turn__back { background: linear-gradient(90deg, #e3d9c0, #fffaed 18%, #f0e6d2); }
.page-turn .still, .page-turn .fade-in { animation: none; }
@media (prefers-reduced-motion: reduce) { .page-turn { display: none; } }
.page-turn__front { transform: rotateY(0deg) translateZ(.2px); }
.page-turn__back { transform: rotateY(180deg) translateZ(.2px); }
