/* Whispering Wonders / Unikuiske - story website.
   Themes: paper (default), sepia, night. "auto" = night 19-07 or when the OS is dark (boot.js). */

@font-face { font-family: "Literata"; font-style: normal; font-weight: 200 900; font-display: swap;
  src: url(../fonts/literata-latin-opsz-normal.woff2) format("woff2"); }
@font-face { font-family: "Literata"; font-style: italic; font-weight: 200 900; font-display: swap;
  src: url(../fonts/literata-latin-opsz-italic.woff2) format("woff2"); }
@font-face { font-family: "Playfair Display"; font-style: normal; font-weight: 400 900; font-display: swap;
  src: url(../fonts/playfair-display-latin-wght-normal.woff2) format("woff2"); }
@font-face { font-family: "Atkinson Hyperlegible"; font-style: normal; font-weight: 400; font-display: swap;
  src: url(../fonts/atkinson-hyperlegible-latin-400-normal.woff2) format("woff2"); }
@font-face { font-family: "Atkinson Hyperlegible"; font-style: normal; font-weight: 700; font-display: swap;
  src: url(../fonts/atkinson-hyperlegible-latin-700-normal.woff2) format("woff2"); }

/* ---- BRAND TOKENS: the one place to change brand colours ------------------------------------
   Sampled from the channel logo (assets/logo/icon.svg: teal smiling moon, gold four-point star on
   the navy avatar tile) and the channel banners (navy -> violet -> plum night sky, white Playfair
   Display wordmark with a soft glow). After a logo change, run website/sync_brand.py and compare. */
:root {
  --brand-navy: #1d2941;       /* avatar tile */
  --brand-deep: #141c30;       /* logo contrast halo; night background */
  --brand-moon: #9accdb;       /* moon fill */
  --brand-moon-deep: #73b1c3;  /* moon outline */
  --brand-moon-ink: #2f6f82;   /* moon teal, darkened to stay readable on paper (AA) */
  --brand-star: #fcbc45;       /* star outer */
  --brand-star-deep: #e0a02a;  /* star inner */
  --brand-violet: #4a3f7d;     /* banner sky, middle */
  --brand-plum: #3b1f45;       /* banner sky, bottom */
  --brand-cream: #fff8ea;
  --brand-sky: linear-gradient(165deg, #1d2941 0%, #2c3766 38%, #4a3f7d 70%, #3b1f45 100%);
}

:root {
  --bg: #f5f0e6;
  --bg-2: #ebe4d6;
  --surface: #fffcf5;
  --ink: #1f2433;
  --ink-2: #5f6274;
  --line: rgba(29, 41, 65, .12);
  --accent: var(--brand-navy);
  --accent-ink: var(--brand-cream);
  --accent-text: var(--brand-moon-ink);
  --mark: rgba(252, 188, 69, .42);
  --glass: rgba(255, 252, 245, .74);
  --shadow: 0 1px 2px rgba(29, 41, 65, .06), 0 12px 32px -8px rgba(29, 41, 65, .2);
  --shadow-lg: 0 2px 4px rgba(29, 41, 65, .06), 0 30px 60px -18px rgba(29, 41, 65, .38);
  --img-filter: none;
  --glow: .36;
  --gutter: rgba(29, 41, 65, .10);

  --font-ui: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --font-display: "Playfair Display", "Iowan Old Style", Georgia, serif;
  --font-read: "Literata", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --scale: 1;
  --radius: 20px;
  --ease: cubic-bezier(.22, .8, .24, 1);
  color-scheme: light;
}
:root[data-theme="sepia"] {
  --bg: #eee1c8; --bg-2: #e5d5b8; --surface: #f8eedb; --ink: #33291f; --ink-2: #74624e;
  --line: rgba(80, 52, 22, .14); --accent: var(--brand-navy); --accent-ink: var(--brand-cream); --accent-text: #2b6475;
  --mark: rgba(224, 160, 42, .38); --glass: rgba(248, 238, 219, .74); --gutter: rgba(80, 52, 22, .14);
  --img-filter: sepia(.12) saturate(.95);
}
:root[data-theme="night"] {
  --bg: var(--brand-deep); --bg-2: #0f1526; --surface: var(--brand-navy); --ink: #f3ebdd; --ink-2: #a9adc2;
  --line: rgba(255, 255, 255, .09); --accent: var(--brand-star); --accent-ink: var(--brand-deep); --mark: rgba(252, 188, 69, .26);
  --accent-text: var(--brand-moon); --glass: rgba(29, 41, 65, .66); --gutter: rgba(0, 0, 0, .42);
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 14px 36px -10px rgba(0, 0, 0, .6);
  --shadow-lg: 0 2px 4px rgba(0, 0, 0, .3), 0 30px 70px -20px rgba(0, 0, 0, .8);
  --img-filter: brightness(.86) saturate(.94); --glow: .5;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --bg: var(--brand-deep); --bg-2: #0f1526; --surface: var(--brand-navy); --ink: #f3ebdd; --ink-2: #a9adc2;
    --line: rgba(255, 255, 255, .09); --accent: var(--brand-star); --accent-ink: var(--brand-deep); --mark: rgba(252, 188, 69, .26);
    --accent-text: var(--brand-moon); --glass: rgba(29, 41, 65, .66); --gutter: rgba(0, 0, 0, .42);
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 14px 36px -10px rgba(0, 0, 0, .6);
    --shadow-lg: 0 2px 4px rgba(0, 0, 0, .3), 0 30px 70px -20px rgba(0, 0, 0, .8);
    --img-filter: brightness(.86) saturate(.94); --glow: .5;
    color-scheme: dark;
  }
}
:root[data-font="easy"] { --font-read: "Atkinson Hyperlegible", var(--font-ui); }

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 400 1rem/1.55 var(--font-ui);
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
  transition: background-color .5s var(--ease), color .5s var(--ease);
}
img { display: block; max-width: 100%; height: auto; }
a { color: inherit; }
button { font: inherit; color: inherit; }
h1, h2, h3 { font-family: var(--font-display); font-weight: 560; letter-spacing: -.01em; margin: 0; text-wrap: balance; }
p { text-wrap: pretty; }
:focus-visible { outline: 2.5px solid var(--accent); outline-offset: 3px; border-radius: 10px; }
.skip { position: absolute; left: 12px; top: 12px; transform: translateY(-200%); z-index: 100; background: var(--surface); padding: 10px 16px; border-radius: 12px; box-shadow: var(--shadow); }
.skip:focus { transform: none; }
[hidden] { display: none !important; }
.ico { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.ico.fill { fill: currentColor; stroke: none; }

/* ---------------------------------------------------------------- shared controls */
.wrap { width: min(1180px, 100%); margin-inline: auto; padding-inline: 20px; }
@media (min-width: 700px) { .wrap { padding-inline: 32px; } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5em;
  min-height: 48px; padding: 0 1.4em; border-radius: 999px; border: 1px solid transparent;
  font-weight: 600; font-size: 1rem; letter-spacing: .01em; text-decoration: none; cursor: pointer;
  transition: transform .2s var(--ease), background-color .2s, box-shadow .2s, border-color .2s;
}
.btn:active { transform: scale(.97); }
.btn .ico { width: 18px; height: 18px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); box-shadow: 0 8px 22px -8px color-mix(in srgb, var(--accent) 70%, transparent); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: color-mix(in srgb, var(--surface) 55%, transparent); border-color: var(--line); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.btn.ghost:hover { border-color: color-mix(in srgb, var(--ink) 30%, transparent); }
.btn.wide { width: 100%; }
.actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 22px; }
.actions.center { justify-content: center; }

.icon-btn {
  display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--glass); color: var(--ink); cursor: pointer; text-decoration: none;
  backdrop-filter: blur(14px) saturate(1.3); -webkit-backdrop-filter: blur(14px) saturate(1.3);
  transition: transform .2s var(--ease), background-color .2s, opacity .3s;
}
.icon-btn:hover { background: color-mix(in srgb, var(--surface) 92%, transparent); }
.icon-btn:active { transform: scale(.94); }
.exit-btn { display: inline-flex; align-items: center; gap: 4px; height: 44px; padding: 0 16px 0 10px; border-radius: 999px; flex: none;
  border: 1px solid var(--line); background: var(--glass); color: var(--ink); text-decoration: none; font-weight: 650; font-size: .92rem;
  backdrop-filter: blur(14px) saturate(1.3); -webkit-backdrop-filter: blur(14px) saturate(1.3); transition: opacity .3s, background-color .2s, transform .2s var(--ease); }
.exit-btn:hover { background: color-mix(in srgb, var(--surface) 92%, transparent); opacity: 1; }
.exit-btn:active { transform: scale(.96); }
.reader[data-page="0"] .chrome.top .exit-btn { --glass: rgba(20, 28, 48, .38); --line: rgba(255, 255, 255, .2); color: #fff; }
.aa { font-family: var(--font-display); font-weight: 600; font-size: 1.05rem; letter-spacing: -.02em; }

.lang-switch { display: inline-flex; padding: 3px; border-radius: 999px; background: var(--glass); border: 1px solid var(--line); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); }
.lang-switch a { min-width: 40px; height: 36px; display: grid; place-items: center; padding: 0 10px; border-radius: 999px; text-decoration: none; font-weight: 650; font-size: .8rem; letter-spacing: .08em; color: var(--ink-2); transition: background-color .2s, color .2s; }
.lang-switch a[aria-current] { background: var(--ink); color: var(--bg); }
.lang-switch a:not([aria-current]):hover { color: var(--ink); }
.lang-switch.compact a { min-width: 34px; height: 36px; padding: 0 8px; }

.eyebrow { margin: 0 0 10px; font-size: .78rem; font-weight: 650; letter-spacing: .14em; text-transform: uppercase; color: var(--accent-text); }
.meta { margin: 10px 0 0; color: var(--ink-2); font-size: .92rem; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.badges { margin: 10px 0 0; display: flex; flex-wrap: wrap; gap: 6px; }
.badge { display: inline-flex; align-items: center; height: 24px; padding: 0 10px; border-radius: 999px; font-size: .74rem; font-weight: 650; letter-spacing: .02em; background: color-mix(in srgb, var(--brand-moon) 38%, transparent); color: var(--ink); }
.badge.soft { background: color-mix(in srgb, var(--ink) 7%, transparent); color: var(--ink-2); }

/* brand */
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; font-family: var(--font-display); font-weight: 600; font-size: 1.12rem; letter-spacing: 0; }
.brand-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 480px) { .topbar .brand { font-size: 1rem; } }
.brand-moon svg { width: 34px; height: 34px; display: block; }
.bm-sky { fill: var(--brand-navy); }
.bm-moon { fill: var(--brand-star); }
.bm-star { fill: var(--brand-cream); }
.brand-moon { flex: none; }
.brand-logo { width: 40px; height: 40px; flex: none; display: block; filter: drop-shadow(0 2px 6px rgba(20, 28, 48, .18)); }

/* ---------------------------------------------------------------- library */
.topbar { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: blur(16px) saturate(1.2); -webkit-backdrop-filter: blur(16px) saturate(1.2); border-bottom: 1px solid transparent; transition: border-color .3s; }
.topbar.scrolled { border-bottom-color: var(--line); }
.topbar-in { display: flex; align-items: center; justify-content: space-between; gap: 12px; height: 68px; }
.topbar-tools { display: flex; align-items: center; gap: 10px; }

.sky { position: relative; isolation: isolate; overflow: hidden; color: #fff; background: var(--brand-sky); }
.sky::before { content: ""; position: absolute; inset: 0; z-index: -1; opacity: .9;
  background-image:
    radial-gradient(1.2px 1.2px at 12% 22%, #fff 50%, transparent 51%), radial-gradient(1px 1px at 28% 64%, #fff 50%, transparent 51%),
    radial-gradient(1.6px 1.6px at 44% 18%, #ffe9b8 50%, transparent 51%), radial-gradient(1px 1px at 57% 46%, #fff 50%, transparent 51%),
    radial-gradient(1.3px 1.3px at 71% 26%, #fff 50%, transparent 51%), radial-gradient(1px 1px at 83% 70%, #cfe9f1 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 92% 14%, #fff 50%, transparent 51%), radial-gradient(1px 1px at 6% 80%, #fff 50%, transparent 51%),
    radial-gradient(1.1px 1.1px at 36% 86%, #ffe9b8 50%, transparent 51%), radial-gradient(1px 1px at 64% 84%, #fff 50%, transparent 51%);
  background-size: 360px 240px; animation: twinkle 7s ease-in-out infinite alternate; }
.sky::after { content: ""; position: absolute; inset: auto -10% -45% -10%; height: 90%; z-index: -1; pointer-events: none;
  background: radial-gradient(40% 55% at 15% 70%, rgba(214, 226, 245, .32), transparent 70%), radial-gradient(45% 60% at 88% 75%, rgba(232, 214, 240, .28), transparent 70%); filter: blur(8px); }
.intro { padding-top: clamp(40px, 7vw, 96px); padding-bottom: clamp(44px, 7vw, 96px); }
.display { font-size: clamp(2rem, 5.2vw, 3.8rem); line-height: 1.1; font-weight: 600; max-width: 18ch; letter-spacing: -.01em; text-shadow: 0 2px 24px rgba(0, 0, 0, .25), 0 0 40px rgba(252, 188, 69, .18); }
.intro-mark { width: clamp(64px, 9vw, 104px); height: auto; margin-bottom: 18px; filter: drop-shadow(0 6px 24px rgba(252, 188, 69, .25)); }
.topbar.on-sky { background: rgba(29, 41, 65, .96); color: #fff; --ink: #fff; --ink-2: rgba(255, 255, 255, .72); --glass: rgba(255, 255, 255, .1); --line: rgba(255, 255, 255, .2); --bg: var(--brand-navy); }
.topbar.on-sky .lang-switch a[aria-current] { background: #fff; color: var(--brand-navy); }
.hero { padding-top: clamp(32px, 5vw, 64px); }

.hero-card { display: grid; gap: 22px; align-items: center; }
.hero-art { display: block; border-radius: calc(var(--radius) + 8px); overflow: hidden; box-shadow: var(--shadow-lg); aspect-ratio: 16 / 9; background: var(--bg-2); }
.hero-art img { width: 100%; height: 100%; object-fit: cover; filter: var(--img-filter); transition: transform 1.2s var(--ease); }
.hero-card:hover .hero-art img { transform: scale(1.025); }
.hero-title { font-size: clamp(1.7rem, 3.4vw, 2.6rem); line-height: 1.08; }
.hero-title a { text-decoration: none; }
.hero-desc { color: var(--ink-2); font-size: 1.06rem; line-height: 1.6; margin: 14px 0 0; max-width: 46ch; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
@media (min-width: 900px) {
  .hero-card { grid-template-columns: 1.55fr 1fr; gap: 48px; }
}

.shelf { padding-top: clamp(48px, 7vw, 88px); }
.shelf-title { font-size: clamp(1.35rem, 2.4vw, 1.8rem); margin-bottom: 22px; display: flex; align-items: center; gap: 14px; }
.shelf-title::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.grid { display: grid; gap: 34px 26px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 290px), 1fr)); }
.card-link { display: block; text-decoration: none; border-radius: var(--radius); }
.card-art { position: relative; border-radius: var(--radius); overflow: hidden; aspect-ratio: 16 / 9; background: var(--bg-2); box-shadow: var(--shadow); transition: transform .45s var(--ease), box-shadow .45s var(--ease); }
.card-art img { width: 100%; height: 100%; object-fit: cover; filter: var(--img-filter); transition: transform .9s var(--ease); }
.card-link:hover .card-art { transform: translateY(-4px); box-shadow: var(--shadow-lg); }
.card-link:hover .card-art img { transform: scale(1.04); }
.card-progress { position: absolute; left: 12px; right: 12px; bottom: 12px; height: 4px; border-radius: 4px; background: rgba(255, 255, 255, .35); overflow: hidden; }
.card-progress::before { content: ""; position: absolute; inset: 0; width: var(--p, 0%); background: #fff; border-radius: inherit; }
.card-body { padding: 14px 4px 0; }
.card-title { font-size: 1.22rem; line-height: 1.2; }
.card .meta { margin-top: 6px; font-size: .88rem; }

.parents { padding-bottom: 24px; }
.pillars { display: grid; gap: 18px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); }
.pillar { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px 24px 26px; }
.pillar h3 { font-size: 1.15rem; margin-bottom: 8px; }
.pillar p { margin: 0; color: var(--ink-2); line-height: 1.6; }

.site-footer { margin-top: clamp(56px, 8vw, 100px); padding: 36px 0 calc(36px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); color: var(--ink-2); font-size: .92rem; }
.site-footer .wrap { display: grid; gap: 10px; }
.site-footer .brand { color: var(--ink); }
.site-footer p { margin: 0; max-width: 70ch; }

/* ---------------------------------------------------------------- language chooser */
.home { min-height: 100svh; display: grid; }
.choose { padding-block: clamp(32px, 7vw, 90px); display: grid; align-content: center; gap: 32px; }
.choose-head { display: grid; justify-items: center; gap: 10px; text-align: center; color: var(--ink-2); }
.choose-head .brand { color: var(--ink); font-size: 1.4rem; }
.choose-head p { margin: 0; }
.choose-grid { display: grid; gap: 22px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); }
.choose-card { position: relative; display: grid; border-radius: 28px; overflow: hidden; text-decoration: none; min-height: 340px; box-shadow: var(--shadow-lg); color: #fff; isolation: isolate; transition: transform .5s var(--ease); }
.choose-card:hover { transform: translateY(-4px); }
.choose-art, .choose-art img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; z-index: -2; }
.choose-art::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(29, 41, 65, 0) 25%, rgba(59, 31, 69, .55) 70%, rgba(20, 28, 48, .92)); }
.home { background: var(--brand-sky); color: #fff; --ink: #fff; --ink-2: rgba(255, 255, 255, .75); }
.choose-mark { width: 96px; height: auto; filter: drop-shadow(0 6px 24px rgba(252, 188, 69, .3)); }
.choose-body { align-self: end; display: grid; gap: 4px; padding: 26px 28px 28px; }
.choose-lang { font-size: .78rem; font-weight: 700; letter-spacing: .16em; text-transform: uppercase; color: var(--brand-star); }
.choose-name { font-family: var(--font-display); font-size: clamp(1.8rem, 3.5vw, 2.4rem); font-weight: 560; line-height: 1.05; }
.choose-tag { opacity: .85; max-width: 40ch; }

/* ---------------------------------------------------------------- reader */
.reader-body { overscroll-behavior: none; }
.js .reader-body { overflow: hidden; height: 100svh; height: 100dvh; }
.reader { position: relative; }

.book { outline: none; }
.js .book {
  display: flex; height: 100svh; height: 100dvh; overflow-x: auto; overflow-y: hidden;
  scroll-snap-type: x mandatory; overscroll-behavior: contain; scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.js .book::-webkit-scrollbar { display: none; }

.page { position: relative; min-height: 100svh; display: grid; grid-template-rows: auto 1fr; overflow: hidden; }
.js .page { flex: 0 0 100%; height: 100%; min-height: 0; scroll-snap-align: start; scroll-snap-stop: always; }
.page + .page { border-top: 1px solid var(--line); }
.js .page + .page { border-top: 0; }

/* the illustration */
.art { position: relative; margin: 0; padding: calc(68px + env(safe-area-inset-top)) 16px 0; display: grid; place-items: center; z-index: 1; }
.art-glow { position: absolute; inset: -10% -10% -60% -10%; z-index: -1; pointer-events: none; opacity: var(--glow);
  -webkit-mask-image: linear-gradient(180deg, #000 30%, transparent 85%); mask-image: linear-gradient(180deg, #000 30%, transparent 85%); }
.art-glow img { width: 100%; height: 100%; object-fit: cover; filter: blur(48px) saturate(1.15); transform: scale(1.1); }
.art-img { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 18px; box-shadow: var(--shadow-lg); filter: var(--img-filter); background: var(--bg-2); }

/* the text leaf */
.leaf { position: relative; display: flex; flex-direction: column; min-height: 0; overflow-y: auto; padding: clamp(22px, 5vw, 40px) clamp(24px, 7vw, 56px) calc(56px + env(safe-area-inset-bottom)); scrollbar-width: thin; }
.text { margin: min(5vh, 44px) auto auto; max-width: 34ch; width: 100%;
  font-family: var(--font-read); font-optical-sizing: auto; font-weight: 420;
  font-size: calc(clamp(1.24rem, 1.05rem + 1.1vw, 1.55rem) * var(--scale)); line-height: 1.62; letter-spacing: .003em;
  hyphens: auto; -webkit-hyphens: auto; hanging-punctuation: first; }
:root[data-font="easy"] .text { font-weight: 400; letter-spacing: .015em; line-height: 1.7; word-spacing: .06em; }
.text p { margin: 0 0 .7em; }
.text p:last-child { margin-bottom: 0; }
.text.first p:first-child::first-letter {
  font-family: var(--font-display); font-weight: 600;
  float: left; font-size: 3.35em; line-height: .82; margin: .06em .1em 0 -.02em; color: var(--accent-text);
}
.folio { margin: auto 0 0; padding-top: 18px; text-align: center; font-family: var(--font-display); font-style: italic; font-size: .9rem; color: var(--ink-2); opacity: .8; font-variant-numeric: oldstyle-nums; }

/* read-along word glow */
.w { border-radius: .22em; padding: .02em .06em; margin: -.02em -.06em; transition: background-color .28s var(--ease), box-shadow .28s var(--ease); -webkit-box-decoration-break: clone; box-decoration-break: clone; }
.w.on { background: var(--mark); box-shadow: 0 0 0 .08em var(--mark); }

/* two-page spread on landscape screens */
@media (min-aspect-ratio: 5/4) {
  .page:not(.cover):not(.end) { grid-template-rows: 1fr; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); }
  .page:not(.cover):not(.end) .art { padding: calc(64px + env(safe-area-inset-top)) clamp(16px, 3vw, 44px) 48px clamp(16px, 4vw, 64px); background: var(--bg); overflow: hidden; }
  .text { margin: auto; }
  .folio { margin-top: 0; }
  .leaf > .folio { position: absolute; left: 0; right: 0; bottom: 22px; }
  .art-glow { inset: 0; -webkit-mask-image: none; mask-image: none; }
  .art-img { max-height: calc(100dvh - 140px); width: auto; max-width: 100%; border-radius: 14px; }
  .leaf { background: var(--surface); padding: calc(64px + env(safe-area-inset-top)) clamp(24px, 4.5vw, 84px) 48px; box-shadow: inset 28px 0 36px -26px var(--gutter); }
  .leaf::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 1px; background: var(--line); }
  .text { font-size: calc(clamp(1.08rem, .55rem + 1.25vw, 1.75rem) * var(--scale)); max-width: 30ch; }
}
@media (min-aspect-ratio: 5/4) and (max-height: 520px) {
  .text { font-size: calc(clamp(1.08rem, .7rem + 1.6vh, 1.25rem) * var(--scale)); line-height: 1.5; }
  .folio { display: none; }
  .page:not(.cover):not(.end) .art { padding-top: calc(56px + env(safe-area-inset-top)); padding-bottom: 20px; }
  .art-img { max-height: calc(100dvh - 90px); }
  .leaf { padding-top: calc(58px + env(safe-area-inset-top)); padding-bottom: 24px; }
}

/* cover */
.page.cover { display: grid; grid-template-rows: 1fr; color: #fff; background: var(--brand-deep); }
.cover-art { position: absolute; inset: 0; }
.cover-art img { width: 100%; height: 100%; object-fit: cover; filter: var(--img-filter); animation: coverIn 2.4s var(--ease) both; }
.cover-art::after { content: ""; position: absolute; inset: 0; background:
  linear-gradient(90deg, rgba(20, 28, 48, .6) 0%, rgba(20, 28, 48, 0) 55%),
  linear-gradient(180deg, rgba(20, 28, 48, .45) 0%, rgba(20, 28, 48, 0) 22%, rgba(20, 28, 48, 0) 40%, rgba(58, 45, 92, .72) 74%, rgba(20, 28, 48, .94) 100%); }
.cover-body { position: relative; align-self: end; padding: 24px clamp(22px, 6vw, 80px) calc(clamp(36px, 7vh, 80px) + env(safe-area-inset-bottom)); max-width: 760px; animation: rise 1.1s .25s var(--ease) both; }
.cover .eyebrow { color: var(--brand-star); }
.cover-title { font-size: clamp(2.3rem, 6.4vw, 4.9rem); line-height: .98; font-weight: 540; letter-spacing: -.03em; text-shadow: 0 2px 30px rgba(0, 0, 0, .35), 0 0 42px rgba(252, 188, 69, .25); }
.cover-desc { margin: 16px 0 0; font-size: clamp(1rem, .9rem + .4vw, 1.15rem); line-height: 1.55; opacity: .9; max-width: 52ch; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.cover .meta { color: rgba(255, 255, 255, .78); }
.cover .btn.ghost { color: #fff; background: rgba(255, 255, 255, .12); border-color: rgba(255, 255, 255, .28); }
.cover .btn.primary { background: var(--brand-star); color: var(--brand-deep); box-shadow: 0 10px 30px -10px rgba(252, 188, 69, .6); }
.nojs-hint { margin: 18px 0 0; font-size: .9rem; opacity: .7; }
.js .nojs-hint { display: none; }
@keyframes coverIn { from { transform: scale(1.06); opacity: .4; } to { transform: none; opacity: 1; } }
@keyframes rise { from { transform: translateY(18px); opacity: 0; } to { transform: none; opacity: 1; } }

/* end */
.page.end { display: block; overflow-y: auto; background: radial-gradient(120% 70% at 50% 0%, color-mix(in srgb, var(--brand-violet) 26%, var(--bg)), var(--bg) 72%); }
.end-in { min-height: 100%; display: flex; flex-direction: column; align-items: center; text-align: center; padding: calc(80px + env(safe-area-inset-top)) 20px calc(60px + env(safe-area-inset-bottom)); max-width: 1000px; margin: 0 auto; }
.end-moon svg { width: 120px; height: 120px; overflow: visible; }
.em-halo { fill: var(--brand-star); fill-opacity: .16; animation: breathe 6s ease-in-out infinite; transform-origin: 60px 60px; }
.em-moon { fill: var(--brand-star); }
.em-star { fill: var(--brand-star); animation: twinkle 3.2s ease-in-out infinite; }
.em-star.s2 { animation-delay: 1.1s; } .em-star.s3 { animation-delay: 2s; }
.end-title { margin-top: 18px; font-size: clamp(2.6rem, 7vw, 4.4rem); font-weight: 480; letter-spacing: -.02em; }
.end-sleep { margin: 8px 0 0; font-family: var(--font-display); font-style: italic; font-size: 1.35rem; color: var(--accent-text); }
.end-sub { margin: 10px 0 0; color: var(--ink-2); max-width: 36ch; }
.end-more { width: 100%; margin-top: 56px; text-align: left; }
.end-more h3 { font-size: 1.2rem; margin-bottom: 18px; text-align: center; }
.end-more .grid.mini { grid-template-columns: repeat(auto-fit, minmax(220px, 290px)); justify-content: center; }
.grid.mini { grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr)); gap: 22px; }
.grid.mini .card-title { font-size: 1.05rem; }
@keyframes breathe { 0%, 100% { transform: scale(1); opacity: .85; } 50% { transform: scale(1.08); opacity: 1; } }
@keyframes twinkle { 0%, 100% { opacity: .25; } 50% { opacity: 1; } }

/* chrome */
.chrome { display: none; }
.js .chrome { display: flex; position: fixed; left: 0; right: 0; z-index: 30; transition: opacity .45s var(--ease), transform .45s var(--ease); }
.chrome.top { top: 0; align-items: center; gap: 10px; padding: calc(10px + env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 10px max(12px, env(safe-area-inset-left)); pointer-events: none; }
.chrome.top > * { pointer-events: auto; }
.chrome-title { flex: 1; min-width: 0; margin: 0; text-align: center; font-family: var(--font-display); font-weight: 560; font-size: .98rem; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: opacity .4s; }
.chrome-tools { display: flex; align-items: center; gap: 8px; }
.reader[data-page="0"] .chrome-title { opacity: 0; }
.reader[data-page="0"] .chrome.top .icon-btn, .reader[data-page="0"] .chrome.top .lang-switch { --glass: rgba(20, 28, 48, .38); --line: rgba(255, 255, 255, .2); --ink: #fff; --ink-2: rgba(255, 255, 255, .7); --bg: #fff; color: #fff; }
.reader[data-page="0"] .chrome.top .lang-switch a[aria-current] { color: var(--brand-deep); }
.play .i-pause { display: none; }
.reader.playing .play .i-pause { display: block; }
.reader.playing .play .i-play { display: none; }
.play { color: var(--accent-text); }
.reader.playing .play { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
@media (max-width: 420px) { .chrome-title { visibility: hidden; } }

.chrome.bottom { bottom: 0; height: calc(4px + env(safe-area-inset-bottom)); align-items: flex-start; pointer-events: none; }
.progress { position: relative; width: 100%; height: 3px; background: color-mix(in srgb, var(--ink) 8%, transparent); }
.progress-fill { position: absolute; inset: 0 auto 0 0; width: var(--progress, 0%); background: var(--accent); border-radius: 0 3px 3px 0; transition: width .6s var(--ease); }
.reader[data-page="0"] .progress { opacity: 0; }
.pageno { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.reader.immersive .chrome.top > *:not(.exit-btn), .reader.immersive .turn { opacity: 0; pointer-events: none; }
.reader.immersive .exit-btn { opacity: .6; }   /* the way out never disappears */

.turn { display: none; }
@media (hover: hover) and (pointer: fine) {
  .js .turn { display: grid; place-items: center; position: fixed; top: 50%; z-index: 25; width: 48px; height: 48px; margin-top: -24px; border-radius: 50%; border: 1px solid var(--line); background: var(--glass); color: var(--ink); cursor: pointer; opacity: 0; backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); transition: opacity .3s, transform .2s var(--ease); }
  .turn.prev { left: 14px; } .turn.next { right: 14px; }
  .reader:hover .turn:not([disabled]) { opacity: .75; }
  .reader .turn:hover:not([disabled]) { opacity: 1; transform: scale(1.06); }
  .turn[disabled] { opacity: 0 !important; pointer-events: none; }
}

/* settings sheet */
.sheet { position: fixed; z-index: 40; inset: auto 0 0 0; padding: 0 10px calc(10px + env(safe-area-inset-bottom)); animation: sheetUp .35s var(--ease) both; }
.sheet-in { background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 26px; box-shadow: var(--shadow-lg); padding: 18px 20px 20px; max-width: 420px; margin: 0 auto; display: grid; gap: 16px; }
@media (min-width: 700px) { .sheet { inset: calc(64px + env(safe-area-inset-top)) 14px auto auto; padding: 0; width: 360px; animation-name: pop; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { font-size: 1.15rem; }
.sheet-head .icon-btn { width: 36px; height: 36px; background: transparent; backdrop-filter: none; }
.seg-group { border: 0; margin: 0; padding: 0; display: grid; gap: 8px; }
.seg-group legend { padding: 0; margin-bottom: 8px; font-size: .74rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-2); }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; border-radius: 16px; background: color-mix(in srgb, var(--ink) 6%, transparent); }
.seg button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 0 4px; border: 0; border-radius: 12px; background: transparent; cursor: pointer; font-size: .88rem; font-weight: 600; color: var(--ink-2); transition: background-color .2s, color .2s, box-shadow .2s; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, .08), 0 4px 10px -4px rgba(0, 0, 0, .2); }
.sw { width: 12px; height: 12px; border-radius: 50%; border: 1px solid rgba(0, 0, 0, .18); flex: none; }
.sw-auto { background: linear-gradient(135deg, #fffcf5 50%, #1d2941 50%); }
.sw-paper { background: #fffcf5; } .sw-sepia { background: #f1dfbd; } .sw-night { background: #1d2941; border-color: rgba(255, 255, 255, .3); }
.f-classic { font-family: "Literata", serif; } .f-easy { font-family: "Atkinson Hyperlegible", sans-serif; }
.size-row { display: flex; align-items: center; gap: 12px; }
.size-row .icon-btn { width: 40px; height: 40px; flex: none; }
.a-small { font-family: var(--font-display); font-size: .85rem; font-weight: 600; } .a-big { font-family: var(--font-display); font-size: 1.3rem; font-weight: 600; }
input[type="range"] { flex: 1; accent-color: var(--accent); height: 28px; }
@keyframes sheetUp { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes pop { from { transform: translateY(-6px) scale(.98); opacity: 0; } to { transform: none; opacity: 1; } }

/* toast */
.toast { position: fixed; z-index: 35; left: 50%; bottom: calc(22px + env(safe-area-inset-bottom)); transform: translateX(-50%); display: flex; align-items: center; gap: 12px; padding: 8px 8px 8px 18px; border-radius: 999px; background: var(--ink); color: var(--bg); box-shadow: var(--shadow-lg); font-size: .92rem; white-space: nowrap; animation: rise .4s var(--ease) both; }
.toast button { border: 0; border-radius: 999px; min-height: 36px; padding: 0 14px; background: color-mix(in srgb, var(--bg) 18%, transparent); color: inherit; font-weight: 650; cursor: pointer; }

/* video */
.video-modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 20px; background: rgba(6, 8, 18, .86); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); animation: fade .3s both; }
.video-frame { width: min(1100px, 100%); aspect-ratio: 16 / 9; border-radius: 18px; overflow: hidden; background: #000; box-shadow: var(--shadow-lg); }
.video-frame iframe { width: 100%; height: 100%; border: 0; display: block; }
.video-close { position: absolute; top: calc(14px + env(safe-area-inset-top)); right: 14px; --glass: rgba(255, 255, 255, .12); --line: rgba(255, 255, 255, .25); color: #fff; }
@keyframes fade { from { opacity: 0; } }

/* page-turn depth: the picture drifts slower than the page, the text settles in */
@supports (animation-timeline: view()) {
  .js .page:not(.cover):not(.end) { view-timeline: --pg inline; }
  .js .page:not(.cover):not(.end) .art-img { animation: drift linear both; animation-timeline: --pg; }
  .js .page:not(.cover):not(.end) .text { animation: settle linear both; animation-timeline: --pg; }
  @keyframes drift { from { transform: translateX(14%) scale(.97); } 50% { transform: none; } to { transform: translateX(-14%) scale(.97); } }
  @keyframes settle { 0% { opacity: 0; transform: translateX(40px); } 40%, 60% { opacity: 1; transform: none; } 100% { opacity: 0; transform: translateX(-40px); } }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
@media print {
  .chrome, .turn, .sheet, .toast, .video-modal, .art-glow, .end-more { display: none !important; }
  .js .reader-body { overflow: visible; height: auto; }
  .js .book { display: block; height: auto; overflow: visible; }
  .js .page { height: auto; break-inside: avoid; page-break-inside: avoid; }
}
