/* ============================================================
   The Storybook Translator
   Three acts: the blank page, the spell, the tale.
   Palette: midnight blue, aged parchment, antique gold.
   ============================================================ */

:root {
  --ink: #241a10;
  --ink-soft: #5b4a37;
  --ink-faint: #8b7963;

  --parchment: #f5e8ce;
  --parchment-deep: #e6d2ac;
  --parchment-shadow: #cbb187;

  --night: #0d1330;
  --night-deep: #05081a;

  --gold: #e8c375;
  --gold-bright: #ffe9b0;
  --gold-deep: #a97b2c;
  --gold-shadow: #6b4715;

  --radius: 8px;

  --font-title: 'Cinzel Decorative', 'Palatino Linotype', 'Book Antiqua', Palatino, serif;
  --font-body: 'Cormorant Garamond', Georgia, 'Times New Roman', serif;
  --font-mono: 'JetBrains Mono', 'SFMono-Regular', Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  font-family: var(--font-body);
  color: var(--parchment);
  background:
    radial-gradient(ellipse 120% 80% at 50% -10%, #23306b 0%, transparent 60%),
    radial-gradient(ellipse 90% 60% at 50% 110%, #1b1440 0%, transparent 65%),
    linear-gradient(180deg, var(--night) 0%, var(--night-deep) 100%);
  background-attachment: fixed;
  overflow-x: hidden;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

#motes {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
}

/* ============================================================
   SCENES — stacked in one grid cell so they can cross-fade
   ============================================================ */
.realm {
  position: relative;
  z-index: 1;
  display: grid;
  min-height: 100vh;
  perspective: 2000px;
}

.scene {
  grid-area: 1 / 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: clamp(2rem, 5vw, 3.5rem) 1.25rem;
  transform-style: preserve-3d;
}

.scene[hidden] {
  display: none;
}

/* Title plate --------------------------------------------------------- */
.titleplate {
  text-align: center;
  margin-bottom: clamp(1.5rem, 3.5vw, 2.4rem);
  transition: opacity 0.5s ease, transform 0.5s ease;
}

.titleplate.is-fading {
  opacity: 0;
  transform: translateY(-14px);
}

.eyebrow {
  margin: 0 0 0.7rem;
  font-size: 0.7rem;
  letter-spacing: 0.42em;
  text-transform: uppercase;
  color: var(--gold-deep);
}

.titleplate h1 {
  margin: 0;
  font-family: var(--font-title);
  font-weight: 900;
  font-size: clamp(2rem, 5.5vw, 3.7rem);
  line-height: 1.05;
  letter-spacing: 0.02em;
  background: linear-gradient(180deg, var(--gold-bright) 0%, var(--gold) 42%, var(--gold-deep) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 2px 12px rgba(232, 195, 117, 0.28));
}

.tale-title {
  font-size: clamp(1.7rem, 4vw, 2.7rem);
}

.subtitle {
  margin: 0.9rem auto 0;
  max-width: 34rem;
  font-size: clamp(1rem, 2vw, 1.18rem);
  font-style: italic;
  line-height: 1.6;
  color: #b9c0e0;
}

/* ============================================================
   THE LEAF — a single sheet of parchment
   ============================================================ */
.leaf {
  width: 100%;
  max-width: 44rem;
  transform-style: preserve-3d;
  will-change: transform, opacity;
}

.leaf--tale {
  max-width: 46rem;
}

.leaf__paper {
  position: relative;
  animation: paper-float 9s ease-in-out infinite;
  padding: clamp(1.6rem, 3.4vw, 2.6rem);
  border-radius: var(--radius);
  color: var(--ink);
  background:
    radial-gradient(ellipse at 50% 0%, rgba(255, 255, 255, 0.4), transparent 62%),
    linear-gradient(180deg, var(--parchment) 0%, var(--parchment-deep) 100%);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.5) inset,
    0 26px 55px -18px rgba(0, 0, 0, 0.8),
    0 0 80px -34px rgba(232, 195, 117, 0.6);
}

/* The parchment never sits perfectly still. */
@keyframes paper-float {
  0%,
  100% {
    transform: translateY(0) rotate(0deg);
  }
  50% {
    transform: translateY(-7px) rotate(-0.22deg);
  }
}

/* torn/aged edge + paper grain */
.leaf__paper::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  pointer-events: none;
  opacity: 0.55;
  background-image:
    radial-gradient(circle at 18% 26%, rgba(160, 130, 90, 0.12) 0 1px, transparent 1px),
    radial-gradient(circle at 72% 61%, rgba(160, 130, 90, 0.1) 0 1px, transparent 1px),
    radial-gradient(circle at 41% 83%, rgba(160, 130, 90, 0.1) 0 1px, transparent 1px);
  background-size: 90px 90px, 130px 130px, 70px 70px;
}

.leaf__heading {
  margin: 0 0 1.2rem;
  text-align: center;
  font-family: var(--font-title);
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--gold-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
}

.leaf__heading::before,
.leaf__heading::after {
  content: '';
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--parchment-shadow));
}

.leaf__heading::after {
  background: linear-gradient(90deg, var(--parchment-shadow), transparent);
}

.ornament {
  color: var(--gold-deep);
  font-size: 0.8rem;
}

/* Notes --------------------------------------------------------------- */
.notes-well {
  position: relative;
}

.notes {
  display: block;
  width: 100%;
  height: clamp(15rem, 34vh, 20rem);
  resize: none;
  border: 0;
  border-radius: 4px;
  padding: 0.9rem 1rem;
  font-family: var(--font-mono);
  font-size: 0.86rem;
  line-height: 1.85;
  color: var(--ink);
  background-color: rgba(255, 252, 240, 0.36);
  background-image: repeating-linear-gradient(
    180deg,
    transparent 0,
    transparent calc(1.85em - 1px),
    rgba(148, 118, 78, 0.22) calc(1.85em - 1px),
    rgba(148, 118, 78, 0.22) 1.85em
  );
  background-position: 0 0.55em;
  box-shadow: inset 0 1px 4px rgba(107, 71, 21, 0.16);
  outline: none;
  transition: box-shadow 0.25s ease, background-color 0.25s ease, opacity 0.35s ease;
}

.notes::placeholder {
  color: rgba(139, 121, 99, 0.85);
}

.notes:focus {
  background-color: rgba(255, 253, 245, 0.62);
  box-shadow:
    inset 0 1px 4px rgba(107, 71, 21, 0.16),
    0 0 0 2px rgba(169, 123, 44, 0.4);
}

/* When the words lift off the page, the real text goes invisible. */
.notes.is-emptied {
  color: transparent;
  caret-color: transparent;
}

.leaf__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 0.9rem;
}

.counter {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  color: var(--ink-faint);
  transition: color 0.25s ease;
}

.counter.is-near {
  color: #a3341c;
}

.counter.is-ticking {
  animation: counter-pop 0.28s ease;
}

@keyframes counter-pop {
  50% {
    transform: scale(1.22);
    color: var(--gold-deep);
  }
}

/* The example text materialises rather than blinking into place. */
.notes.is-conjured {
  animation: notes-conjure 0.9s ease;
}

@keyframes notes-conjure {
  0% {
    background-color: rgba(255, 240, 200, 0.95);
    box-shadow: inset 0 0 40px rgba(232, 195, 117, 0.9), 0 0 34px -6px rgba(232, 195, 117, 0.8);
  }
  100% {
    background-color: rgba(255, 252, 240, 0.36);
    box-shadow: inset 0 1px 4px rgba(107, 71, 21, 0.16);
  }
}

.ghost-btn {
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(169, 123, 44, 0.45);
  background: transparent;
  border-radius: 999px;
  padding: 0.4rem 1.05rem;
  font-family: var(--font-body);
  font-size: 0.92rem;
  font-style: italic;
  color: var(--gold-shadow);
  cursor: pointer;
  transition: background-color 0.25s ease, color 0.25s ease, border-color 0.25s ease,
    box-shadow 0.25s ease, transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* A little gold light sweeps through on hover. */
.ghost-btn::after {
  content: '';
  position: absolute;
  top: -50%;
  left: -60%;
  width: 40%;
  height: 200%;
  pointer-events: none;
  transform: rotate(18deg);
  background: linear-gradient(100deg, transparent, rgba(255, 233, 176, 0.55), transparent);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.ghost-btn:hover::after,
.ghost-btn:focus-visible::after {
  opacity: 1;
  animation: ghost-sweep 0.75s ease forwards;
}

@keyframes ghost-sweep {
  to {
    left: 130%;
  }
}

.ghost-btn:hover,
.ghost-btn:focus-visible {
  background: rgba(169, 123, 44, 0.14);
  border-color: var(--gold-deep);
  color: #4a3210;
  transform: translateY(-2px);
  box-shadow: 0 6px 16px -8px rgba(107, 71, 21, 0.7);
  outline: none;
}

.ghost-btn:active {
  transform: translateY(0) scale(0.97);
}

.ghost-btn--night {
  border-color: rgba(232, 195, 117, 0.35);
  color: var(--gold);
}

.ghost-btn--night:hover,
.ghost-btn--night:focus-visible {
  background: rgba(232, 195, 117, 0.12);
  border-color: var(--gold);
  color: var(--gold-bright);
  box-shadow: 0 0 22px -6px rgba(232, 195, 117, 0.7);
}

/* ============================================================
   THE TALE PAGE
   ============================================================ */
.leaf__paper--tale {
  overflow: hidden;
  padding: clamp(2.2rem, 4.5vw, 3.4rem);
  border: 1px solid rgba(169, 123, 44, 0.35);
}

/* The page arrives glowing, then cools. */
.leaf.is-entering .leaf__paper--tale {
  animation: paper-float 9s ease-in-out infinite, paper-kindle 1.6s ease-out;
}

@keyframes paper-kindle {
  0% {
    box-shadow:
      0 0 0 1px rgba(255, 233, 176, 0.9),
      0 0 90px 20px rgba(255, 233, 176, 0.85),
      0 26px 55px -18px rgba(0, 0, 0, 0.8);
    filter: brightness(1.3);
  }
  100% {
    box-shadow:
      0 1px 0 rgba(255, 255, 255, 0.5) inset,
      0 26px 55px -18px rgba(0, 0, 0, 0.8),
      0 0 80px -34px rgba(232, 195, 117, 0.6);
    filter: none;
  }
}

.ribbon {
  position: absolute;
  top: -0.4rem;
  right: 2.6rem;
  width: 1.5rem;
  height: 5.2rem;
  background: linear-gradient(180deg, #b0303a, #7d1c26);
  box-shadow: 0 4px 10px -2px rgba(0, 0, 0, 0.5);
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 78%, 0 100%);
  animation: ribbon-drop 0.9s cubic-bezier(0.22, 1, 0.36, 1) 0.35s backwards;
}

@keyframes ribbon-drop {
  from {
    transform: translateY(-100%);
  }
}

.corner {
  position: absolute;
  font-size: 1.15rem;
  color: var(--gold-deep);
  opacity: 0.55;
  animation: corner-twinkle 5s ease-in-out infinite;
}

@keyframes corner-twinkle {
  0%,
  100% {
    opacity: 0.3;
    transform: scale(0.9) rotate(0deg);
  }
  50% {
    opacity: 0.85;
    transform: scale(1.12) rotate(8deg);
  }
}

.corner--tl {
  top: 0.85rem;
  left: 1.1rem;
}
.corner--tr {
  top: 0.85rem;
  right: 1.1rem;
  animation-delay: 1.25s;
}
.corner--bl {
  bottom: 0.85rem;
  left: 1.1rem;
  animation-delay: 2.5s;
}
.corner--br {
  bottom: 0.85rem;
  right: 1.1rem;
  animation-delay: 3.75s;
}

/* A slow gold sheen drifting across the parchment */
.sheen {
  position: absolute;
  top: -50%;
  left: -60%;
  width: 45%;
  height: 200%;
  pointer-events: none;
  background: linear-gradient(
    100deg,
    transparent,
    rgba(255, 245, 210, 0.5),
    rgba(255, 233, 176, 0.15),
    transparent
  );
  transform: rotate(14deg);
  animation: sheen-drift 7s ease-in-out 1.2s infinite;
}

@keyframes sheen-drift {
  0%,
  55% {
    left: -60%;
  }
  100% {
    left: 130%;
  }
}

.story-text {
  position: relative;
  z-index: 1;
  font-size: clamp(1.08rem, 1.5vw, 1.28rem);
  line-height: 1.85;
  color: var(--ink);
}

.story-text p {
  margin: 0 0 1.15em;
  text-align: justify;
  hyphens: auto;
}

.story-text p:last-child {
  margin-bottom: 0;
}

/* Illuminated drop cap. Built as a real element rather than ::first-letter,
   because ::first-letter does not apply when the first child is an
   inline-block — and the words need to be inline-block to be transformed. */
.dropcap {
  float: left;
  font-family: var(--font-title);
  font-size: 3.7em;
  line-height: 0.82;
  padding: 0.06em 0.1em 0 0;
  color: var(--gold-deep);
  text-shadow: 1px 1px 0 rgba(255, 253, 245, 0.9);
  opacity: 0;
  animation: dropcap-strike 1.4s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

@keyframes dropcap-strike {
  0% {
    opacity: 0;
    transform: scale(2.4) rotate(-14deg);
    filter: blur(14px);
    color: #fffdf4;
    text-shadow: 0 0 40px rgba(255, 233, 176, 1);
  }
  45% {
    opacity: 1;
    transform: scale(1.16) rotate(3deg);
    filter: blur(1px);
    color: var(--gold-bright);
    text-shadow: 0 0 30px rgba(255, 233, 176, 0.95);
  }
  100% {
    opacity: 1;
    transform: none;
    filter: none;
    color: var(--gold-deep);
    text-shadow: 1px 1px 0 rgba(255, 253, 245, 0.9);
  }
}

/* Each word arrives as a golden ember out of thin air, then cools into ink. */
.story-text .word {
  display: inline-block;
  opacity: 0;
  animation: word-appear 1.1s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

@keyframes word-appear {
  0% {
    opacity: 0;
    filter: blur(9px);
    transform: translateY(9px) scale(1.35);
    color: #fffdf4;
    text-shadow: 0 0 20px rgba(255, 233, 176, 1), 0 0 42px rgba(232, 195, 117, 0.85);
  }
  35% {
    opacity: 1;
    filter: blur(2.5px);
    transform: translateY(2px) scale(1.1);
    color: var(--gold-bright);
    text-shadow: 0 0 16px rgba(255, 233, 176, 0.95), 0 0 34px rgba(232, 195, 117, 0.6);
  }
  65% {
    opacity: 1;
    filter: blur(0);
    color: var(--gold-deep);
    text-shadow: 0 0 10px rgba(232, 195, 117, 0.55);
  }
  100% {
    opacity: 1;
    filter: none;
    transform: none;
    color: var(--ink);
    text-shadow: none;
  }
}

/* An unseen quill: a soft gold light that travels down the page, staying
   just ahead of the words as they land. */
.scribe {
  position: absolute;
  left: -10%;
  width: 120%;
  height: 5rem;
  top: -6rem;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(
    ellipse 50% 50% at 50% 50%,
    rgba(255, 245, 214, 0.55) 0%,
    rgba(232, 195, 117, 0.22) 45%,
    transparent 72%
  );
  filter: blur(10px);
}

.scribe.is-writing {
  animation: scribe-run var(--reveal, 3s) ease-out forwards;
}

@keyframes scribe-run {
  0% {
    opacity: 0;
    top: -6rem;
  }
  12% {
    opacity: 1;
  }
  85% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    top: 100%;
  }
}

.fin {
  margin: 1.8rem 0 0;
  text-align: center;
  font-family: var(--font-title);
  font-size: 0.78rem;
  letter-spacing: 0.35em;
  text-transform: uppercase;
  color: var(--gold-deep);
  opacity: 0;
  animation: fade-up 0.9s ease forwards;
}

.fin[hidden] {
  display: none;
}

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 0.75;
    transform: none;
  }
}

.story-error {
  text-align: center;
  padding: 2.5rem 1rem;
}

.story-error[hidden] {
  display: none;
}

.error-mark {
  margin: 0 0 0.6rem;
  font-size: 2.2rem;
  color: #a3341c;
  opacity: 0.75;
}

.error-copy {
  margin: 0 auto;
  max-width: 24rem;
  font-size: 1.1rem;
  font-style: italic;
  color: #8a3a20;
}

.tale-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.7rem;
  margin-top: clamp(1.5rem, 3vw, 2.2rem);
  opacity: 0;
  animation: fade-up 0.7s ease 0.5s forwards;
}

/* ============================================================
   SCENE TRANSITIONS — the page turn
   ============================================================ */
.leaf.is-leaving {
  animation: leaf-out 0.75s cubic-bezier(0.55, 0, 0.85, 0.35) forwards;
}

@keyframes leaf-out {
  0% {
    transform: rotateY(0deg) translateZ(0) scale(1);
    opacity: 1;
  }
  100% {
    transform: rotateY(-92deg) translateZ(-160px) scale(0.82);
    opacity: 0;
  }
}

.leaf.is-entering {
  animation: leaf-in 0.95s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes leaf-in {
  0% {
    transform: rotateY(88deg) translateZ(-160px) scale(0.82);
    opacity: 0;
  }
  60% {
    opacity: 1;
  }
  100% {
    transform: rotateY(0deg) translateZ(0) scale(1);
    opacity: 1;
  }
}

/* `.tale-actions` and `.fin` fade themselves in (they start at opacity 0 and
   need `forwards`), so they must stay out of this backwards-filled rule. */
.scene.is-entering .titleplate,
.scene.is-entering .key-holder {
  animation: fade-up 0.8s ease 0.35s backwards;
}

/* ============================================================
   THE MAGIC BUTTON
   ============================================================ */
.key-holder {
  margin-top: clamp(1.8rem, 4vw, 2.8rem);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.85rem;
  transition: opacity 0.4s ease, transform 0.4s ease;
}

.key-holder.is-fading {
  opacity: 0;
  transform: translateY(12px) scale(0.94);
}

.magic-key {
  position: relative;
  border: 0;
  padding: 0;
  background: none;
  cursor: pointer;
  isolation: isolate;
  -webkit-tap-highlight-color: transparent;
}

.magic-key:disabled {
  cursor: wait;
}

.magic-key__halo {
  position: absolute;
  inset: -45%;
  z-index: -2;
  border-radius: 50%;
  background: radial-gradient(
    circle,
    rgba(232, 195, 117, 0.5) 0%,
    rgba(232, 195, 117, 0.15) 42%,
    transparent 70%
  );
  filter: blur(12px);
  animation: halo-pulse 3.6s ease-in-out infinite;
}

@keyframes halo-pulse {
  0%,
  100% {
    opacity: 0.55;
    transform: scale(0.94);
  }
  50% {
    opacity: 1;
    transform: scale(1.08);
  }
}

/* The ring hugs a pill-shaped button, so it breathes rather than spins —
   rotating a pill sweeps a wide oval well outside the button. */
.magic-key__ring {
  position: absolute;
  inset: -15px;
  z-index: -1;
  border-radius: 999px;
  border: 1px dashed rgba(232, 195, 117, 0.55);
  animation: ring-breathe 4.4s ease-in-out infinite;
}

.magic-key__ring::after {
  content: '';
  position: absolute;
  inset: 5px;
  border-radius: 999px;
  border: 1px solid rgba(232, 195, 117, 0.2);
}

@keyframes ring-breathe {
  0%,
  100% {
    transform: scale(1);
    opacity: 0.65;
  }
  50% {
    transform: scale(1.035);
    opacity: 1;
  }
}

@keyframes ring-spin {
  to {
    transform: rotate(360deg);
  }
}

.magic-key__face {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 1.05rem 2.9rem;
  border-radius: 999px;
  font-family: var(--font-title);
  font-size: clamp(1rem, 2.2vw, 1.35rem);
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #3d2708;
  background: linear-gradient(
    180deg,
    #fff3d0 0%,
    var(--gold-bright) 18%,
    var(--gold) 48%,
    var(--gold-deep) 88%,
    #8a5f1c 100%
  );
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.85),
    inset 0 -2px 6px rgba(107, 71, 21, 0.55),
    0 10px 26px -8px rgba(0, 0, 0, 0.75),
    0 0 34px -6px rgba(232, 195, 117, 0.6);
  transition: transform 0.16s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.22s ease;
}

.magic-key__star {
  font-size: 0.75em;
  opacity: 0.72;
  animation: star-twinkle 2.4s ease-in-out infinite;
}

.magic-key__star:last-child {
  animation-delay: 1.2s;
}

@keyframes star-twinkle {
  0%,
  100% {
    opacity: 0.4;
    transform: scale(0.9) rotate(0deg);
  }
  50% {
    opacity: 1;
    transform: scale(1.15) rotate(180deg);
  }
}

.magic-key__shimmer {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  overflow: hidden;
  pointer-events: none;
}

.magic-key__shimmer::before {
  content: '';
  position: absolute;
  top: -60%;
  left: -35%;
  width: 28%;
  height: 220%;
  background: linear-gradient(100deg, transparent, rgba(255, 255, 255, 0.85), transparent);
  transform: rotate(18deg);
  animation: shimmer-sweep 3.8s ease-in-out infinite;
}

@keyframes shimmer-sweep {
  0%,
  62% {
    left: -35%;
  }
  100% {
    left: 125%;
  }
}

.magic-key:hover .magic-key__face,
.magic-key:focus-visible .magic-key__face {
  transform: translateY(-3px) scale(1.035);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.95),
    inset 0 -2px 6px rgba(107, 71, 21, 0.5),
    0 16px 34px -10px rgba(0, 0, 0, 0.8),
    0 0 58px -4px rgba(255, 233, 176, 0.85);
}

.magic-key:focus-visible {
  outline: none;
}

.magic-key:focus-visible .magic-key__ring {
  border-color: var(--gold-bright);
}

.magic-key:active .magic-key__face {
  transform: translateY(1px) scale(0.985);
}

.magic-key.is-casting::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 999px;
  border: 2px solid rgba(255, 233, 176, 0.9);
  animation: shockwave 0.9s ease-out forwards;
  pointer-events: none;
}

@keyframes shockwave {
  from {
    opacity: 0.9;
    transform: scale(1);
  }
  to {
    opacity: 0;
    transform: scale(2.4);
  }
}

.key-hint {
  margin: 0;
  font-size: 0.9rem;
  font-style: italic;
  letter-spacing: 0.06em;
  color: rgba(185, 192, 224, 0.6);
}

/* ============================================================
   THE SPELL — full-screen interlude between the two pages
   ============================================================ */
.spell {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.55s ease;
  background: radial-gradient(circle at 50% 46%, rgba(20, 12, 45, 0.72) 0%, rgba(5, 8, 26, 0.94) 68%);
}

.spell[hidden] {
  display: none;
}

.spell.is-open {
  opacity: 1;
}

.spell__vortex {
  position: relative;
  width: min(26rem, 74vw);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
}

.vortex-core {
  position: absolute;
  width: 34%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(
    circle,
    #fffdf4 0%,
    var(--gold-bright) 22%,
    rgba(232, 195, 117, 0.45) 48%,
    transparent 72%
  );
  filter: blur(4px);
  animation: core-throb 2.1s ease-in-out infinite;
}

@keyframes core-throb {
  0%,
  100% {
    transform: scale(0.72);
    opacity: 0.7;
  }
  50% {
    transform: scale(1.05);
    opacity: 1;
  }
}

.vortex-ring {
  position: absolute;
  border-radius: 50%;
  border: 1px solid rgba(232, 195, 117, 0.5);
}

.vortex-ring--1 {
  width: 52%;
  aspect-ratio: 1;
  border-style: dashed;
  animation: ring-spin 6s linear infinite;
}

.vortex-ring--2 {
  width: 72%;
  aspect-ratio: 1;
  border-color: rgba(232, 195, 117, 0.28);
  border-top-color: var(--gold-bright);
  border-width: 2px;
  animation: ring-spin 9s linear infinite reverse;
}

.vortex-ring--3 {
  width: 92%;
  aspect-ratio: 1;
  border-style: dotted;
  border-color: rgba(232, 195, 117, 0.35);
  animation: ring-spin 16s linear infinite;
}

.vortex-runes {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  animation: ring-spin 24s linear infinite reverse;
}

.runetext {
  font-family: var(--font-title);
  font-size: 19px;
  letter-spacing: 0.42em;
  fill: rgba(232, 195, 117, 0.6);
}

/* Spiralling motes drawn into the vortex (populated by JS) */
.spell__swirl {
  position: fixed;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
}

.swirl-mote {
  position: absolute;
  width: 6px;
  height: 6px;
  margin: -3px 0 0 -3px;
  border-radius: 50%;
  background: radial-gradient(circle, #fffdf4 0%, var(--gold-bright) 45%, transparent 72%);
  will-change: transform, opacity;
}

.spell__status {
  position: absolute;
  bottom: clamp(4rem, 16vh, 9rem);
  margin: 0;
  padding: 0 1.5rem;
  text-align: center;
  font-size: clamp(1.05rem, 2.4vw, 1.45rem);
  font-style: italic;
  letter-spacing: 0.04em;
  color: var(--gold);
  text-shadow: 0 0 26px rgba(232, 195, 117, 0.55);
  animation: status-in 0.6s ease;
}

@keyframes status-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* Words lifting off the notes page ------------------------------------ */
.flyaway {
  position: fixed;
  inset: 0;
  z-index: 45;
  pointer-events: none;
}

.flyword {
  position: fixed;
  font-family: var(--font-mono);
  white-space: pre;
  color: var(--ink);
  will-change: transform, opacity;
}

/* Sparkle burst layer -------------------------------------------------- */
.sparkles {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 60;
}

.spark {
  position: fixed;
  border-radius: 50%;
  background: radial-gradient(circle, #fffdf4 0%, var(--gold-bright) 45%, transparent 72%);
  will-change: transform, opacity;
  animation: spark-fly 1s cubic-bezier(0.15, 0.6, 0.35, 1) forwards;
}

@keyframes spark-fly {
  from {
    opacity: 1;
    transform: translate(0, 0) scale(1);
  }
  to {
    opacity: 0;
    transform: translate(var(--dx), var(--dy)) scale(0.15);
  }
}

/* Gold flash at the moment of transformation --------------------------- */
.flash {
  position: fixed;
  inset: 0;
  z-index: 55;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(circle at 50% 46%, #fffdf4 0%, rgba(255, 233, 176, 0.75) 30%, transparent 70%);
}

.flash.is-firing {
  animation: flash-fire 0.7s ease-out forwards;
}

@keyframes flash-fire {
  0% {
    opacity: 0;
  }
  18% {
    opacity: 0.95;
  }
  100% {
    opacity: 0;
  }
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 640px) {
  .scene {
    justify-content: flex-start;
  }

  .notes {
    height: 13rem;
  }

  .story-text p {
    text-align: left;
  }

  .magic-key__face {
    padding: 0.95rem 2rem;
  }

  .ribbon {
    right: 1.6rem;
  }

  .tale-actions {
    flex-direction: column;
    width: 100%;
    max-width: 18rem;
  }
}

/* ============================================================
   Reduced motion — keep the story, drop the theatrics
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }

  .story-text .word,
  .dropcap {
    opacity: 1;
    color: inherit;
  }

  .dropcap {
    color: var(--gold-deep);
  }

  .fin,
  .tale-actions {
    opacity: 1;
  }
}
