/* Grandpa Fairy and the Old Oak -- book styles.
   Type sizes use cqw so the words scale with the page, like print. */

@font-face { font-family: "Alegreya"; src: url("fonts/alegreya-400.woff2") format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "Alegreya"; src: url("fonts/alegreya-400-italic.woff2") format("woff2"); font-weight: 400; font-style: italic; font-display: swap; }
@font-face { font-family: "Alegreya"; src: url("fonts/alegreya-700.woff2") format("woff2"); font-weight: 700; font-style: normal; font-display: swap; }
@font-face { font-family: "Alegreya"; src: url("fonts/alegreya-700-italic.woff2") format("woff2"); font-weight: 700; font-style: italic; font-display: swap; }
@font-face { font-family: "Fraunces"; src: url("fonts/fraunces-600.woff2") format("woff2"); font-weight: 600; font-style: normal; font-display: swap; }
@font-face { font-family: "Fraunces"; src: url("fonts/fraunces-400-italic.woff2") format("woff2"); font-weight: 400; font-style: italic; font-display: swap; }

:root {
  --page: min(46vw, calc(100vh - 8.5rem));
  --turn: 1.2s;
  --body: "Alegreya", Georgia, "Times New Roman", serif;
  --display: "Fraunces", "Alegreya", Georgia, serif;
  --moss: #55693a;
  --cover: #4d5f38;
  --cover-ink: #f3e7c4;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  background: radial-gradient(ellipse at 50% 35%, #46553a 0%, #2c3626 60%, #1f271b 100%);
  color: #f3e7c4;
  font-family: var(--body);
  overflow-x: hidden;
}

/* ---------- Stage and book ---------- */

.stage {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 1.5rem 1rem 5rem;
}

.book {
  position: relative;
  width: calc(var(--page) * 2);
  height: var(--page);
  perspective: 2600px;
  transition: transform var(--turn) ease;
  -webkit-user-select: none;
  user-select: none;
  touch-action: pan-y;
}
.book[data-state="closed-front"] { transform: translateX(-25%); }
.book[data-state="closed-back"] { transform: translateX(25%); }

/* One shadow for the whole book, so 25 leaves do not stack 25 shadows. */
.book:not(.stack)::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 0.5rem;
  box-shadow: 0 0.9rem 2.4rem rgba(0, 0, 0, 0.45);
  transition: left var(--turn) ease, right var(--turn) ease;
}
.book[data-state="closed-front"]::before { left: 50%; }
.book[data-state="closed-back"]::before { right: 50%; }

.leaf {
  position: absolute;
  top: 0;
  left: 50%;
  width: 50%;
  height: 100%;
  transform-origin: left center;
  transform-style: preserve-3d;
  transition: transform var(--turn) cubic-bezier(0.45, 0.05, 0.2, 1);
  cursor: pointer;
}
.leaf.flipped { transform: rotateY(-180deg); }
.leaf.instant { transition: none; }

/* The bending turn: bend.js copies the turning leaf into a chain of strips. */
.bend {
  position: absolute;
  top: 0;
  left: 50%;
  width: 50%;
  height: 100%;
  z-index: 60;
  transform-style: preserve-3d;
  pointer-events: none;
}
.strip {
  position: absolute;
  top: 0;
  height: 100%;
  transform-origin: left center;
  transform-style: preserve-3d;
}
.strip-face {
  position: absolute;
  inset: 0;
  overflow: hidden;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background: #fbfaf5;
}
.strip-back { transform: rotateY(180deg); }
.strip-page { position: absolute; top: 0; }
.strip-shade { position: absolute; inset: 0; background: #2a1c10; opacity: var(--shade, 0); }
.strip-edge > .strip-front { border-radius: 0 0.5rem 0.5rem 0; }
.strip-edge > .strip-back { border-radius: 0.5rem 0 0 0.5rem; }

/* The soft shadow the lifted page throws on the pages under it. */
.bend-cast {
  position: absolute;
  inset: 0;
  z-index: 55;
  opacity: 0;
  pointer-events: none;
  border-radius: 0.5rem;
  background: linear-gradient(90deg,
    transparent calc(var(--reach, 50%) - 24%),
    rgba(40, 25, 10, 0.9) var(--reach, 50%),
    transparent calc(var(--reach, 50%) + 24%));
}

.face {
  position: absolute;
  inset: 0;
  overflow: hidden;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background: #fbfaf5;
}
.face.front { border-radius: 0 0.5rem 0.5rem 0; }
.face.back { transform: rotateY(180deg); border-radius: 0.5rem 0 0 0.5rem; }

/* The shadow that falls into the spine. */
.face::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.face.front::after { background: linear-gradient(90deg, rgba(60, 40, 20, 0.22) 0%, rgba(60, 40, 20, 0.06) 5%, transparent 13%); }
.face.back::after { background: linear-gradient(270deg, rgba(60, 40, 20, 0.22) 0%, rgba(60, 40, 20, 0.06) 5%, transparent 13%); }

/* ---------- Pages ---------- */

.page {
  position: absolute;
  inset: 0;
  margin: 0;
  container-type: size;
}

.picture img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Scene palettes: the paper takes the weather of the picture beside it. */
.words {
  --paper: #faf6e9;
  --ink: #3a2e24;
  --muted: #8b7d6b;
  --grandpa: #55693a;
  --wren: #a8516f;
  --gold: #a9781c;
  --glow: rgba(244, 204, 96, 0.5);
  background: var(--paper);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 9% 10% 12% 12%;
}
.words[data-scene="spring"] { --paper: radial-gradient(ellipse at 30% 20%, #fdfbee 0%, #f7f3e2 70%, #f1eed9 100%); }
.words[data-scene="seasons"] { --paper: linear-gradient(90deg, #f4f5e3 0%, #f9eed6 50%, #f1f3f4 100%); }
.words[data-scene="hearth"] { --paper: radial-gradient(ellipse at 25% 85%, #fde9d6 0%, #fbeee6 55%, #f8ebe4 100%); }
.words[data-scene="summer"] { --paper: radial-gradient(ellipse at 70% 15%, #fffbe0 0%, #f9f3d8 75%); }
.words[data-scene="light"] { --paper: radial-gradient(ellipse at 50% -10%, #fffbe2 0%, #f9f0d2 55%, #f1ead0 100%); }
.words[data-scene="sunset"] { --paper: linear-gradient(180deg, #fbe2d5 0%, #fbecd9 60%, #fbf3df 100%); }
.words[data-scene="autumn"] { --paper: radial-gradient(ellipse at 30% 20%, #fbf0d6 0%, #f6e7c8 70%, #f0dfbb 100%); --grandpa: #5d6431; }
.words[data-scene="storm"] {
  --paper: linear-gradient(180deg, #2f3a54 0%, #435070 58%, #6f7590 82%, #c9b48f 100%);
  --ink: #f4eedf;
  --muted: #b9c1d6;
  --grandpa: #f3d98f;
  --wren: #f5bccb;
  --glow: rgba(255, 236, 170, 0.26);
  padding-bottom: 24%;
}
.words[data-scene="dusk"] {
  --paper: linear-gradient(180deg, #3a3f66 0%, #555786 55%, #b98782 88%, #efbf8d 100%);
  --ink: #f6f0e3;
  --muted: #c6c7df;
  --grandpa: #f3d98f;
  --wren: #ffd3c4;
  --glow: rgba(255, 236, 170, 0.26);
  padding-bottom: 24%;
}

/* ---------- Words ---------- */

.text {
  font-size: var(--fs, 4cqw);
  line-height: 1.42;
  font-kerning: normal;
  font-variant-ligatures: common-ligatures;
  hanging-punctuation: first;
  text-wrap: pretty;
}
/* cqw measures the page inside its margins, so 6.2cqw is about 4.8% of the full page width. */
.words[data-size="s"] { --fs: 5.3cqw; }
.words[data-size="m"] { --fs: 6.2cqw; }
.words[data-size="l"] { --fs: 7.4cqw; }
.words[data-align="centre"] .text { text-align: center; text-wrap: balance; }

.text p { margin: 0 0 0.85em; }
.text p:last-child { margin-bottom: 0; }
.text em { font-style: italic; }

.folio {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 4.5%;
  text-align: center;
  font-size: 3.3cqw;
  letter-spacing: 0.12em;
  color: var(--muted);
}
.words[data-scene="storm"] .folio,
.words[data-scene="dusk"] .folio { color: #4a4458; }

/* Opening words. */
.lead { font-variant-caps: small-caps; letter-spacing: 0.04em; }
.dropcap::first-letter {
  font-family: var(--display);
  font-weight: 600;
  float: left;
  font-size: 3.5em;
  line-height: 0.8;
  padding: 0.06em 0.09em 0 0;
  color: var(--grandpa);
}

/* Voices. Grandpa speaks in moss green, Wren in foxglove pink. */
.grandpa { font-style: italic; color: var(--grandpa); }
.wren { font-style: italic; color: var(--wren); }
.said { font-style: normal; color: var(--ink); font-size: 0.8em; }
.name { color: var(--wren); font-weight: 700; }
.grandpa-name { color: var(--grandpa); font-size: 1.12em; }
.big { font-size: 1.18em; line-height: 1.32; }
.huge { font-family: var(--display); font-size: 1.55em; line-height: 1.2; }
.huge .said { font-family: var(--body); font-size: 0.55em; }

/* Quiet lines. */
.aside { font-style: italic; color: var(--muted); font-size: 0.86em; }
.hush {
  margin-top: 2.2em !important;
  font-size: 0.8em;
  letter-spacing: 0.05em;
  color: var(--muted);
  text-align: right;
}
.after-silence { margin-top: 2.6em !important; font-style: italic; }
.refrain { font-style: italic; }
.slow { display: block; white-space: nowrap; letter-spacing: 0.2em; font-style: italic; margin: 0.15em 0; }

/* Loud lines. */
.shout { font-style: italic; font-weight: 700; color: #8d4a2c; line-height: 1; }
.shout-1 { font-size: 1.25em; }
.shout-2 { font-size: 1.6em; }
.shout-3 { font-size: 2.05em; }
.rumble { font-weight: 700; font-size: 1.22em; letter-spacing: 0.1em; }

/* Lines that act out what they say. */
.wander { margin-bottom: 0.5em !important; }
.step-1 { padding-left: 1.3em; }
.step-2 { padding-left: 2.6em; }
.step-3 { padding-left: 3.9em; }
.droop { margin-top: 1.3em !important; color: var(--muted); font-size: 0.92em; line-height: 1.5; }
.droop-2 { font-size: 0.92em; padding-left: 0.9em; }
.droop-3 { font-size: 0.84em; padding-left: 1.8em; }
.falling { display: flex; justify-content: center; gap: 0.5em; font-style: italic; color: var(--gold); margin: 0.2em 0 1.5em !important; }
.falling > span:nth-child(2) { transform: translateY(0.75em) rotate(4deg); }
.falling > span:nth-child(3) { transform: translateY(1.5em) rotate(-5deg); }

/* The word the narrator is saying right now. */
.w { border-radius: 0.18em; transition: background-color 0.12s ease, box-shadow 0.12s ease; }
.w.speaking { background-color: var(--glow); box-shadow: 0 0 0 0.14em var(--glow); }
.shimmer { color: var(--gold); font-style: italic; }
.keepsake { text-align: center; font-family: var(--display); font-style: italic; margin: 1em 0 !important; }
.sprout { color: var(--grandpa); font-style: italic; font-size: 1.15em; }

.the-end {
  margin-top: 2.4em !important;
  font-family: var(--display);
  font-style: italic;
  font-size: 0.9em;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.the-end svg { display: block; width: 0.9em; height: 1.2em; margin: 0 auto 0.5em; color: var(--grandpa); }

/* ---------- Covers ---------- */

.cover {
  background:
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.035) 0 1px, transparent 1px 3px),
    repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.05) 0 1px, transparent 1px 3px),
    radial-gradient(ellipse at 50% 30%, #5d7145 0%, var(--cover) 60%, #3f4f2e 100%);
  color: var(--cover-ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 8%;
}
.cover::before {
  content: "";
  position: absolute;
  inset: 3.5%;
  border: 0.35cqw solid rgba(243, 231, 196, 0.55);
  border-radius: 1.2cqw;
  pointer-events: none;
}
.cover-kicker { margin: 0; font-style: italic; font-size: 3.3cqw; letter-spacing: 0.03em; opacity: 0.85; }
.cover-title { margin: 0.25em 0 0.45em; font-family: var(--display); font-weight: 600; font-size: 10cqw; line-height: 1.02; }
.cover-title span { display: block; font-style: italic; font-weight: 400; font-size: 0.42em; margin: 0.2em 0 0.15em; }
.cover-plate {
  width: 46%;
  aspect-ratio: 4 / 5;
  overflow: hidden;
  border-radius: 50% 50% 4% 4% / 40% 40% 3% 3%;
  border: 0.9cqw solid var(--cover-ink);
  box-shadow: 0 0.8cqw 2cqw rgba(0, 0, 0, 0.35);
}
.cover-plate img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 42%; display: block; }
.cover-acorn { width: 4.5cqw; height: 6cqw; margin-top: 3.5cqw; opacity: 0.8; }
.cover-actions { display: flex; gap: 2.4cqw; margin-top: 4cqw; }
.cover-actions button {
  font-family: var(--body);
  font-size: 3.5cqw;
  padding: 1.3cqw 3.4cqw;
  border-radius: 99cqw;
  border: 0.3cqw solid var(--cover-ink);
  background: var(--cover-ink);
  color: #3f4f2e;
  cursor: pointer;
}
.cover-actions button.plain { background: transparent; color: var(--cover-ink); font-style: italic; }
.cover-actions button:hover { filter: brightness(1.08); }
.cover-actions button:focus-visible { outline: 0.4cqw solid #fff; outline-offset: 0.5cqw; }
.back-cover .cover-acorn { width: 9cqw; height: 12cqw; margin: 0 0 5cqw; }
.back-cover .cover-kicker { max-width: 60%; font-size: 4cqw; line-height: 1.4; }

/* ---------- Controls ---------- */

.controls {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 1.6rem 0 1.1rem;
  background: linear-gradient(180deg, rgba(31, 39, 27, 0) 0%, rgba(31, 39, 27, 0.94) 45%);
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1.1rem;
  font-size: 1.05rem;
  letter-spacing: 0.04em;
}
.controls button {
  width: 2.6rem;
  height: 2.6rem;
  border-radius: 50%;
  border: 1px solid rgba(243, 231, 196, 0.5);
  background: rgba(243, 231, 196, 0.08);
  color: inherit;
  font: inherit;
  font-size: 1.7rem;
  line-height: 1;
  cursor: pointer;
}
.controls button:hover:not(:disabled) { background: rgba(243, 231, 196, 0.2); }
.controls button:focus-visible { outline: 2px solid #f3e7c4; outline-offset: 3px; }
.controls button:disabled { opacity: 0.3; cursor: default; }
#place { min-width: 8.5rem; text-align: center; font-style: italic; }
.controls { flex-wrap: wrap; row-gap: 0.5rem; }
.controls button.pill {
  width: auto;
  height: 2.6rem;
  padding: 0 1.1rem;
  border-radius: 99rem;
  font-size: 1rem;
  font-style: italic;
  letter-spacing: 0.03em;
}
.controls button.pill[aria-pressed="true"]:not(.quiet) { background: #f3e7c4; color: #2c3626; }
.controls button.pill.quiet { border-color: rgba(243, 231, 196, 0.28); opacity: 0.85; }
.controls button[hidden] { display: none; }
.back-cover .cover-actions { margin-top: 6cqw; }

/* ---------- Narrow screens: one page at a time, picture above words ---------- */

.book.stack {
  width: min(94vw, 34rem);
  height: auto;
  perspective: none;
  transform: none;
}
.stack .card { display: none; border-radius: 0.5rem; overflow: hidden; box-shadow: 0 0.6rem 1.8rem rgba(0, 0, 0, 0.35); }
.stack .card.current { display: block; animation: arrive 0.45s ease; }
.stack .page { position: relative; inset: auto; aspect-ratio: 1; }
.stack .words { aspect-ratio: auto; min-height: 62vw; container-type: inline-size; }
.stack .folio { position: static; margin-top: 1.5em; }

@keyframes arrive {
  from { opacity: 0; transform: translateY(0.6rem); }
  to { opacity: 1; transform: none; }
}

/* ---------- Movement drawn over a picture (pages marked data-motion) ---------- */

/* The layers fade in once the page has landed (the 1.2s is TURN_MS) and are left
   out of the bending copies, which would otherwise each run their own. */
.motion {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.5s;
}
.motion.showing { opacity: 1; transition: opacity 1.5s 1.2s; }
.bend .motion { display: none; }
.motion i { position: absolute; }

/* Rain: two sheets of streaks, near and far, each sliding one tile along the slant
   of the painted rain. --dry is the part of the picture the rain must not cross. */
.motion .rain { inset: 0; -webkit-mask-image: var(--dry); mask-image: var(--dry); }
.motion .rain::before, .motion .rain::after {
  content: "";
  position: absolute;
  inset: calc(-1 * var(--fall)) calc(-1 * var(--lean)) 0 0;
  background-size: var(--lean) var(--fall);
  animation: rain var(--time) linear infinite;
}
.motion .rain::before {
  --lean: 26cqw; --fall: 65cqw; --time: 0.95s;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 250'%3E%3Cg stroke='%23e4ecff' stroke-linecap='round' stroke-width='0.9'%3E%3Cpath d='M28 10l-11 28' opacity='.55'/%3E%3Cpath d='M72 58l-11 28' opacity='.4'/%3E%3Cpath d='M48 120l-11 28' opacity='.6'/%3E%3Cpath d='M92 170l-11 28' opacity='.45'/%3E%3Cpath d='M20 196l-11 28' opacity='.5'/%3E%3C/g%3E%3C/svg%3E");
}
.motion .rain::after {
  --lean: 18cqw; --fall: 45cqw; --time: 1.25s;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 250'%3E%3Cg stroke='%23d5e0fa' stroke-linecap='round' stroke-width='0.8'%3E%3Cpath d='M18 30l-8 20' opacity='.35'/%3E%3Cpath d='M60 8l-8 20' opacity='.3'/%3E%3Cpath d='M85 92l-8 20' opacity='.4'/%3E%3Cpath d='M40 140l-8 20' opacity='.3'/%3E%3Cpath d='M70 200l-8 20' opacity='.35'/%3E%3Cpath d='M25 215l-8 20' opacity='.25'/%3E%3C/g%3E%3C/svg%3E");
}

@keyframes rain {
  to { transform: translate(calc(-1 * var(--lean)), var(--fall)); }
}

/* Glow: warm lamplight that wavers. --lamp is where the lamp is in the picture. */
.motion .glow {
  left: var(--lamp-x);
  top: var(--lamp-y);
  width: 36cqw;
  height: 36cqw;
  translate: -50% -50%;
  background: radial-gradient(closest-side, rgba(255, 200, 104, 0.5), rgba(255, 190, 90, 0.16) 45%, transparent);
  animation: glow 6s ease-in-out infinite;
}

@keyframes glow {
  0%, 100% { opacity: 0.55; }
  9% { opacity: 0.85; }
  15% { opacity: 0.5; }
  27% { opacity: 0.8; }
  44% { opacity: 0.6; }
  52% { opacity: 0.95; }
  61% { opacity: 0.55; }
  78% { opacity: 0.8; }
  88% { opacity: 0.65; }
}

/* Flash: lightning. Dark for most of 11 seconds, then two quick pulses and a fade.
   Kept soft, and two pulses only, for readers who are sensitive to flashing.
   --bolt is where the painted lightning is. */
.motion .flash {
  inset: 0;
  background:
    radial-gradient(ellipse 55% 65% at var(--bolt-x) var(--bolt-y), rgba(240, 236, 255, 0.55), rgba(206, 208, 255, 0.26) 45%, transparent 80%),
    rgba(214, 220, 255, 0.1);
  opacity: 0;
  animation: flash 11s linear infinite;
}

@keyframes flash {
  0%, 86% { opacity: 0; }
  87% { opacity: 0.85; }
  88.5% { opacity: 0.2; }
  90% { opacity: 1; }
  96%, 100% { opacity: 0; }
}

/* Leaves, snow and sparkles are made of parts, eight to a layer. These are the
   numbers that make each part differ from the next; a page can hide some. */
.motion b { position: absolute; display: none; }
.motion b:nth-child(1) { --at: 0.08; --row: 0.6; --time: 15s; --wait: -2s; --swing: 2.3s; --size: 4.2cqw; }
.motion b:nth-child(2) { --at: 0.62; --row: 0.1; --time: 18s; --wait: -9s; --swing: 2.9s; --size: 3.4cqw; }
.motion b:nth-child(3) { --at: 0.34; --row: 0.9; --time: 13s; --wait: -5s; --swing: 2.1s; --size: 3.8cqw; }
.motion b:nth-child(4) { --at: 0.88; --row: 0.3; --time: 16s; --wait: -12s; --swing: 2.6s; --size: 4.4cqw; }
.motion b:nth-child(5) { --at: 0.21; --row: 0; --time: 19s; --wait: -15s; --swing: 3.1s; --size: 3.2cqw; }
.motion b:nth-child(6) { --at: 0.74; --row: 0.75; --time: 14s; --wait: -7s; --swing: 2.4s; --size: 3.6cqw; }
.motion b:nth-child(7) { --at: 0.48; --row: 0.45; --time: 17s; --wait: -3.5s; --swing: 2.7s; --size: 4cqw; }
.motion b:nth-child(8) { --at: 0.96; --row: 0.55; --time: 20s; --wait: -17s; --swing: 3.3s; --size: 3cqw; }

/* Leaves and snow: each part starts somewhere in a box (--left, --top, --width,
   --height), travels --drift across and --drop down while it sways, fades out,
   waits, and starts again. --clear is the part of the picture it passes behind. */
.motion :is(.leaves, .snow) {
  inset: 0;
  -webkit-mask-image: var(--clear, none);
  mask-image: var(--clear, none);
}
.motion :is(.leaves, .snow) b {
  display: block;
  left: calc(var(--left) + var(--at) * var(--width));
  top: calc(var(--top) + var(--row) * var(--height));
  width: calc(var(--size) * var(--scale, 1));
  height: calc(var(--size) * var(--scale, 1));
  background: var(--look) center / contain no-repeat;
  opacity: 0;
  animation:
    fall calc(var(--pace, 1) * var(--time)) linear var(--wait) infinite,
    sway var(--swing) ease-in-out infinite alternate;
}

@keyframes fall {
  0% { translate: 0 0; opacity: 0; }
  7%, 60% { opacity: 0.9; }
  70%, 100% { translate: var(--drift, 3cqw) var(--drop); opacity: 0; }
}

@keyframes sway {
  from { transform: translateX(-1.6cqw) rotate(-28deg); }
  to { transform: translateX(1.6cqw) rotate(32deg); }
}

.motion .leaves b { --look: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2c5 4 7 10 0 20C5 12 7 6 12 2z' fill='%23e0a12f' stroke='%238a5a22' stroke-width='1.2' stroke-linejoin='round'/%3E%3Cpath d='M12 5v14' stroke='%238a5a22' stroke-width='.8' fill='none'/%3E%3C/svg%3E"); }
.motion .leaves b:nth-child(3n) { --look: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2c5 4 7 10 0 20C5 12 7 6 12 2z' fill='%23d9822b' stroke='%23874a1c' stroke-width='1.2' stroke-linejoin='round'/%3E%3Cpath d='M12 5v14' stroke='%23874a1c' stroke-width='.8' fill='none'/%3E%3C/svg%3E"); }
.motion .leaves b:nth-child(3n + 1) { --look: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2c5 4 7 10 0 20C5 12 7 6 12 2z' fill='%23c9702b' stroke='%237a3f1a' stroke-width='1.2' stroke-linejoin='round'/%3E%3Cpath d='M12 5v14' stroke='%237a3f1a' stroke-width='.8' fill='none'/%3E%3C/svg%3E"); }
.motion .snow { --scale: 0.32; }
.motion .snow b { --look: radial-gradient(circle, #fff 0 35%, rgba(255, 255, 255, 0) 70%); }

/* Sparkles: small stars that light and fade in turn. Each page says where they sit. */
.motion .sparkle { inset: 0; }
.motion .sparkle b {
  display: block;
  width: calc(var(--size) * 0.6);
  height: calc(var(--size) * 0.6);
  translate: -50% -50%;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 0c1 7 5 11 12 12-7 1-11 5-12 12-1-7-5-11-12-12 7-1 11-5 12-12z' fill='%23fff8dc'/%3E%3C/svg%3E") center / contain no-repeat;
  filter: drop-shadow(0 0 0.4cqw rgba(255, 232, 160, 0.9));
  opacity: 0;
  animation: twinkle calc(var(--swing) * 2) ease-in-out var(--wait) infinite;
}

@keyframes twinkle {
  0%, 60%, 100% { opacity: 0; scale: 0.4; }
  30% { opacity: 1; scale: 1; }
}

/* Page 10: leaves come off the autumn branch and snow falls in the winter corner.
   Both pass behind the two on the branch. */
.motion[data-page="10"] { --clear: radial-gradient(ellipse 11% 12% at 68% 37%, transparent 75%, #000 100%); }
.motion[data-page="10"] .leaves { --left: 55%; --width: 30%; --top: 16%; --height: 8%; --drop: 42cqw; --drift: -3cqw; --pace: 0.75; }
.motion[data-page="10"] .leaves b:nth-child(n + 5) { display: none; }
.motion[data-page="10"] .snow { --left: 76%; --width: 22%; --top: -4%; --height: 10%; --drop: 64cqw; --drift: -2cqw; }

/* Page 16: his wings sparkle, and a few leaves fall at the right edge. */
.motion[data-page="16"] .leaves { --left: 84%; --width: 11%; --top: -6%; --height: 10%; --drop: 110cqw; --drift: -4cqw; }
.motion[data-page="16"] .leaves b:nth-child(n + 4) { display: none; }
.motion[data-page="16"] .sparkle b:nth-child(1) { left: 16%; top: 36%; }
.motion[data-page="16"] .sparkle b:nth-child(2) { left: 22%; top: 41%; }
.motion[data-page="16"] .sparkle b:nth-child(3) { left: 28%; top: 47%; }
.motion[data-page="16"] .sparkle b:nth-child(4) { left: 19%; top: 50%; }
.motion[data-page="16"] .sparkle b:nth-child(5) { left: 25%; top: 54%; }
.motion[data-page="16"] .sparkle b:nth-child(6) { left: 14%; top: 43%; }
.motion[data-page="16"] .sparkle b:nth-child(7) { left: 46%; top: 33%; }
.motion[data-page="16"] .sparkle b:nth-child(8) { left: 48%; top: 40%; }

/* Page 17: leaves drift down across the whole sky and pass behind the two watching. */
.motion[data-page="17"] { --clear: radial-gradient(ellipse 31% 31% at 56% 62%, transparent 78%, #000 100%); }
.motion[data-page="17"] .leaves { --left: 3%; --width: 92%; --top: -8%; --height: 14%; --drop: 114cqw; --drift: 5cqw; }
.motion[data-page="17"] .leaves b:nth-child(n + 7) { display: none; }

/* Page 20: the swirl sparkles, and leaves blow up and away along it, behind Wren. */
.motion[data-page="20"] { --clear: radial-gradient(ellipse 19% 38% at 70% 60%, transparent 78%, #000 100%); }
.motion[data-page="20"] .leaves { --left: 22%; --width: 30%; --top: 30%; --height: 22%; --drop: -24cqw; --drift: 42cqw; --pace: 0.5; }
.motion[data-page="20"] .sparkle b:nth-child(1) { left: 33%; top: 37%; }
.motion[data-page="20"] .sparkle b:nth-child(2) { left: 29%; top: 45%; }
.motion[data-page="20"] .sparkle b:nth-child(3) { left: 36%; top: 52%; }
.motion[data-page="20"] .sparkle b:nth-child(4) { left: 45%; top: 49%; }
.motion[data-page="20"] .sparkle b:nth-child(5) { left: 43%; top: 38%; }
.motion[data-page="20"] .sparkle b:nth-child(6) { left: 52%; top: 27%; }
.motion[data-page="20"] .sparkle b:nth-child(7) { left: 63%; top: 21%; }
.motion[data-page="20"] .sparkle b:nth-child(8) { left: 74%; top: 15%; }

/* Page 11: the hollow stays dry, the acorn lantern hangs at its mouth,
   and the lightning is in the sky on the left. */
.motion[data-page="11"] {
  --dry: radial-gradient(ellipse 32% 34% at 60% 62%, transparent 70%, #000 100%);
  --lamp-x: 48%;
  --lamp-y: 43%;
  --bolt-x: 21%;
  --bolt-y: 30%;
}

@media (prefers-reduced-motion: reduce) {
  .leaf, .book { transition: none; }
  .stack .card.current { animation: none; }
  .motion { display: none; }
}
