/* ============================================================
   Story Mode — animated flip-book that teaches a note as a story.
   ============================================================ */

body.story-open { overflow: hidden; }

.story-stage {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at 50% 20%, #3a2f5a 0%, #1a1530 55%, #0d0a1a 100%);
  opacity: 0;
  transition: opacity 300ms var(--ease-out, ease);
}
.story-stage.is-open { opacity: 1; }

.story-close {
  position: absolute;
  top: 18px; right: 18px;
  display: grid; place-items: center;
  width: 40px; height: 40px;
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 50%;
  cursor: pointer;
  transition: background 150ms ease;
  z-index: 3;
}
.story-close:hover { background: rgba(255, 255, 255, 0.25); }

.story-subject {
  position: absolute;
  top: 24px; left: 24px;
  color: rgba(255, 255, 255, 0.7);
  font-size: var(--font-size-sm);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.story-book-wrap {
  width: 100%;
  max-width: 620px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ── Loading ─────────────────────────────────────────────── */
.story-loading { text-align: center; color: #f3eefb; }
.story-loading__book {
  position: relative;
  width: 80px; height: 60px;
  margin: 0 auto 22px;
}
.story-loading__page {
  position: absolute; left: 50%; top: 0;
  width: 40px; height: 56px;
  background: #f7f2e6;
  border-radius: 3px 6px 6px 3px;
  transform-origin: left center;
  animation: story-flip-loop 1.6s infinite ease-in-out;
}
.story-loading__page:nth-child(2) { animation-delay: 0.25s; }
.story-loading__page:nth-child(3) { animation-delay: 0.5s; }
@keyframes story-flip-loop {
  0%, 100% { transform: rotateY(0deg); }
  50% { transform: rotateY(-150deg); }
}
.story-loading h2 { margin: 0 0 6px; }
.story-loading p { margin: 0; color: rgba(255, 255, 255, 0.7); }
.story-loading__icon { font-size: 48px; margin-bottom: 12px; }
.story-error-actions { display: flex; gap: 10px; justify-content: center; margin-top: 20px; }

/* ── Book ────────────────────────────────────────────────── */
.story-book {
  position: relative;
  width: min(560px, 92vw);
  height: min(660px, 74vh);
  perspective: 2200px;
}
.story-book__base {
  position: absolute;
  inset: 0;
  background: #ece3d0;
  border-radius: 6px 10px 10px 6px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
  transform: translateZ(-6px);
}

/* Cover */
.story-cover {
  position: absolute;
  inset: 0;
  z-index: 500;
  transform-origin: left center;
  transition: transform 900ms cubic-bezier(0.4, 0.1, 0.2, 1);
  border-radius: 6px 10px 10px 6px;
  overflow: hidden;
  backface-visibility: hidden;
  background: linear-gradient(135deg, #6a3d8f 0%, #4a2b6b 55%, #2f1a4a 100%);
  color: #fff;
  cursor: default;
}
.story-book.is-open .story-cover { transform: rotateY(-180deg); }
.story-cover__spine {
  position: absolute; left: 0; top: 0; bottom: 0; width: 14px;
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.4), transparent);
}
.story-cover__inner {
  height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center;
  padding: 40px 34px;
  gap: 12px;
}
.story-cover__genre {
  font-size: var(--font-size-xs);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: #e8d4ff;
}
.story-cover__title {
  margin: 4px 0;
  font-family: Georgia, 'Times New Roman', serif;
  font-size: clamp(24px, 5vw, 34px);
  line-height: 1.25;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
}
.story-cover__hero { margin: 0; font-style: italic; color: #d9c4f5; }
.story-cover__scene {
  width: 200px; height: 130px; margin: 10px 0;
  border-radius: 10px; overflow: hidden;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  border: 3px solid rgba(255, 255, 255, 0.4);
}
.story-cover__scene svg { width: 100%; height: 100%; display: block; }
.story-cover__open {
  margin-top: 14px;
  padding: 11px 24px;
  font-size: var(--font-size-md);
  font-weight: 600;
  color: #3a2b5a;
  background: #f5d76b;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3);
  transition: transform 150ms ease, box-shadow 150ms ease;
}
.story-cover__open:hover { transform: translateY(-2px); box-shadow: 0 10px 24px rgba(0, 0, 0, 0.4); }

/* Leaves — single-faced pages that turn over on flip.
   `perspective` (not preserve-3d) keeps z-index stacking working while still
   giving each page turn real 3D depth. z-index keeps pages above the base
   (the base is last in DOM and would otherwise paint over the pages). */
.story-leaves { position: absolute; inset: 0; perspective: 2200px; z-index: 1; }
.story-leaf {
  position: absolute;
  inset: 0;
  transform-origin: left center;
  transition: transform 850ms cubic-bezier(0.4, 0.1, 0.2, 1);
  backface-visibility: hidden;
  border-radius: 6px 10px 10px 6px;
  overflow: hidden;
}
.story-leaf.is-flipped { transform: rotateY(-180deg); }

/* Page surface */
.story-page {
  position: relative;
  height: 100%;
  display: flex; flex-direction: column;
  padding: 26px 30px 40px;
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.06), transparent 8%),
    repeating-linear-gradient(0deg, transparent, transparent 27px, rgba(120, 90, 60, 0.05) 28px),
    #fbf6ea;
  box-shadow: inset 14px 0 24px -14px rgba(90, 60, 30, 0.4);
  overflow-y: auto;
}
.story-page__art {
  position: relative;
  width: 100%; height: 200px;
  border-radius: 12px; overflow: hidden;
  margin-bottom: 18px;
  box-shadow: 0 8px 22px rgba(90, 60, 30, 0.28), inset 0 0 0 1px rgba(255, 255, 255, 0.35);
  flex-shrink: 0;
}
.story-page__art svg { width: 100%; height: 100%; display: block; }
.story-page__art::after {
  content: ""; position: absolute; inset: 0;
  border-radius: 12px;
  box-shadow: inset 0 0 0 3px rgba(120, 80, 40, 0.12);
  pointer-events: none;
}
.story-page__emoji {
  position: absolute; right: 12px; bottom: 8px;
  font-size: 30px;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.4));
  animation: story-emoji-pop 500ms 200ms both;
}
@keyframes story-emoji-pop { from { transform: scale(0) rotate(-20deg); } to { transform: scale(1) rotate(0); } }

.story-page__heading {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 1.16rem;
  font-weight: 700;
  color: #6a3f8f;
  margin: 0 0 10px;
  padding-bottom: 8px;
  border-bottom: 2px solid rgba(138, 77, 181, 0.2);
  letter-spacing: 0.01em;
}
.story-page__text { color: #33281c; }
.story-para {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 1.02rem;
  line-height: 1.72;
  margin: 0 0 12px;
  text-align: justify;
}
.story-page__takeaway {
  margin: 4px 0 14px;
  padding: 12px 14px 12px 16px;
  background: linear-gradient(90deg, rgba(138, 77, 181, 0.1), rgba(138, 77, 181, 0.03));
  border-left: 4px solid #8a4db5;
  border-radius: 8px;
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 0.98rem;
  line-height: 1.55;
  color: #2e2340;
}
.story-page__takeaway-label {
  display: inline-block;
  font-family: var(--font-family, system-ui);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #8a4db5;
  margin-right: 6px;
  vertical-align: 1px;
}
.story-para--first::first-letter {
  float: left;
  font-size: 3.1rem;
  line-height: 0.82;
  padding: 6px 8px 0 0;
  font-weight: 700;
  color: #8a4db5;
  font-family: Georgia, serif;
}
.story-page__folio {
  position: absolute; bottom: 12px; left: 0; right: 0;
  text-align: center;
  font-size: var(--font-size-xs);
  color: #a08a6a;
  font-style: italic;
}

/* In-story question */
.story-q {
  margin-top: 8px;
  padding: 16px;
  background: #fff;
  border: 1px solid #e6d9bf;
  border-radius: 12px;
  box-shadow: 0 4px 14px rgba(90, 60, 30, 0.12);
  animation: story-q-in 400ms both;
}
@keyframes story-q-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.story-q__prompt {
  margin: 0 0 12px;
  font-weight: 600;
  color: #3a2b1c;
  font-family: var(--font-family-base, system-ui);
}
.story-q__badge { margin-right: 4px; }
.story-q__options { display: flex; flex-direction: column; gap: 8px; }
.story-q__opt {
  text-align: left;
  padding: 10px 14px;
  font-size: var(--font-size-sm);
  color: #3a2b1c;
  background: #faf6ec;
  border: 1.5px solid #e6d9bf;
  border-radius: 8px;
  cursor: pointer;
  transition: all 140ms ease;
}
.story-q__opt:hover:not(:disabled) { border-color: #8a4db5; background: #f3e9ff; }
.story-q__opt:disabled { cursor: default; }
.story-q__opt.is-correct { border-color: #1a7f4b; background: #e3f6ec; color: #12603a; font-weight: 600; }
.story-q__opt.is-wrong { border-color: #c0392b; background: #fdecea; color: #a02b1e; }
.story-q__result {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: var(--font-size-sm);
}
.story-q__result.is-correct { background: #e3f6ec; color: #12603a; }
.story-q__result.is-wrong { background: #fdecea; color: #a02b1e; }
.story-q__result strong { display: block; margin-bottom: 4px; }
.story-q__result p { margin: 0; line-height: 1.5; }

/* End page */
.story-page--end {
  align-items: center; justify-content: center; text-align: center;
  gap: 14px;
  background: radial-gradient(circle at 50% 30%, #fff6e0, #f3ead0);
}
.story-end__seal {
  width: 60px; height: 60px;
  display: grid; place-items: center;
  font-size: 28px;
  color: #fff;
  background: linear-gradient(135deg, #8a4db5, #5a2b8f);
  border-radius: 50%;
  box-shadow: 0 6px 18px rgba(90, 40, 130, 0.4);
  animation: story-seal 2.4s ease-in-out infinite;
}
@keyframes story-seal { 0%, 100% { transform: rotate(-6deg); } 50% { transform: rotate(6deg); } }
.story-end__title { margin: 0; font-family: Georgia, serif; font-size: 30px; color: #4a2b6b; }
.story-end__moral {
  margin: 0; max-width: 340px;
  font-family: Georgia, serif; font-style: italic; font-size: 1.05rem;
  line-height: 1.6; color: #5a4630;
}
.story-end__actions { display: flex; gap: 10px; margin-top: 10px; }

/* ── Controls ────────────────────────────────────────────── */
.story-controls {
  display: flex; align-items: center; gap: 14px;
  margin-top: 22px;
  width: min(560px, 92vw);
}
.story-nav {
  flex-shrink: 0;
  width: 44px; height: 44px;
  display: grid; place-items: center;
  font-size: 24px; line-height: 1;
  color: #fff;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  cursor: pointer;
  transition: background 150ms ease;
}
.story-nav:hover:not(:disabled) { background: rgba(255, 255, 255, 0.3); }
.story-nav:disabled { opacity: 0.35; cursor: default; }
.story-progress {
  flex: 1; height: 6px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 999px; overflow: hidden;
}
.story-progress__fill {
  height: 100%; width: 0;
  background: linear-gradient(90deg, #f5d76b, #ff9f52);
  border-radius: 999px;
  transition: width 400ms ease;
}
.story-page-num {
  flex-shrink: 0;
  min-width: 92px; text-align: center;
  color: rgba(255, 255, 255, 0.85);
  font-size: var(--font-size-sm);
}

/* ── Scene animations (SVG element classes) ──────────────── */
.sc-float { animation: sc-float 5s ease-in-out infinite; }
@keyframes sc-float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
.sc-pulse { animation: sc-pulse 4s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes sc-pulse { 0%, 100% { opacity: 0.85; transform: scale(1); } 50% { opacity: 1; transform: scale(1.08); } }
.sc-drift { animation: sc-drift 14s linear infinite; }
.sc-drift2 { animation: sc-drift 20s linear infinite reverse; }
@keyframes sc-drift { from { transform: translateX(-24px); } to { transform: translateX(24px); } }
.sc-flow { animation: sc-flow 3s ease-in-out infinite; }
.sc-flow2 { animation: sc-flow 3.6s ease-in-out infinite reverse; }
@keyframes sc-flow { 0%, 100% { opacity: 0.85; } 50% { opacity: 1; transform: translateX(4px); } }
.sc-shimmer { animation: sc-shimmer 3.5s ease-in-out infinite; }
@keyframes sc-shimmer { 0%, 100% { opacity: 0.15; transform: translateX(0); } 50% { opacity: 0.5; transform: translateX(-8px); } }
.sc-flag { animation: sc-flag 2.5s ease-in-out infinite; transform-box: fill-box; transform-origin: left center; }
@keyframes sc-flag { 0%, 100% { transform: skewY(0deg) scaleX(1); } 50% { transform: skewY(-4deg) scaleX(0.94); } }
.sc-wave { animation: sc-wave 5s ease-in-out infinite; }
.sc-wave2 { animation: sc-wave 6s ease-in-out infinite reverse; }
@keyframes sc-wave { 0%, 100% { transform: translateX(0); } 50% { transform: translateX(-18px); } }
.sc-sway { animation: sc-sway 4s ease-in-out infinite; }
@keyframes sc-sway { 0%, 100% { transform: rotate(-3deg); } 50% { transform: rotate(3deg); } }
.sc-twinkle { animation: sc-twinkle 2.4s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes sc-twinkle { 0%, 100% { opacity: 0.3; } 50% { opacity: 1; } }
.sc-spin { animation: sc-spin 18s linear infinite; transform-box: fill-box; transform-origin: center; }
.sc-spin-rev { animation: sc-spin 14s linear infinite reverse; transform-box: fill-box; transform-origin: center; }
@keyframes sc-spin { to { transform: rotate(360deg); } }
.sc-orbit { animation: sc-orbit 6s linear infinite; transform-box: fill-box; transform-origin: 80px 0; }
@keyframes sc-orbit { to { transform: rotate(360deg); } }
.sc-blink { animation: sc-twinkle 3s ease-in-out infinite; }
.sc-tilt { animation: sc-tilt 5s ease-in-out infinite; }
@keyframes sc-tilt { 0%, 100% { transform: rotate(-4deg); } 50% { transform: rotate(4deg); } }
.sc-dash { stroke-dashoffset: 200; animation: sc-dash 3s ease-out forwards; }
@keyframes sc-dash { to { stroke-dashoffset: 0; } }
.sc-fill { animation: sc-pulse 3s ease-in-out infinite; }
.sc-bubble { animation: sc-bubble 2.6s ease-in infinite; transform-box: fill-box; }
@keyframes sc-bubble { 0% { transform: translateY(0); opacity: 0.8; } 100% { transform: translateY(-40px); opacity: 0; } }
.sc-rain { animation: sc-rain 1.2s linear infinite; }
@keyframes sc-rain { from { transform: translateY(-6px); opacity: 0.4; } to { transform: translateY(14px); opacity: 1; } }
.sc-grow { animation: sc-grow 900ms ease-out both; }
@keyframes sc-grow { from { transform: scaleY(0); } to { transform: scaleY(1); } }
.sc-boat { animation: sc-boat 4s ease-in-out infinite; transform-box: fill-box; }
@keyframes sc-boat { 0%, 100% { transform: translateY(0) rotate(-1deg); } 50% { transform: translateY(-5px) rotate(1deg); } }
.sc-train { animation: sc-train 6s linear infinite; transform-box: fill-box; }
@keyframes sc-train { from { transform: translateX(-40px); } to { transform: translateX(260px); } }
.sc-wheel { animation: sc-spin 1.4s linear infinite; transform-box: fill-box; transform-origin: center; }
.sc-smoke { animation: sc-smoke 3s ease-out infinite; transform-box: fill-box; }
@keyframes sc-smoke { 0% { opacity: 0.7; transform: translateY(0); } 100% { opacity: 0; transform: translateY(-16px); } }
.sc-rise { animation: sc-rise 5s ease-in-out infinite; transform-box: fill-box; }
@keyframes sc-rise { 0%, 100% { transform: translateY(6px); } 50% { transform: translateY(-6px); } }
.sc-step { animation: sc-step 1.4s ease-in-out infinite; transform-box: fill-box; }
@keyframes sc-step { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 560px) {
  .story-stage { padding: 12px; }
  .story-page { padding: 20px 20px 36px; }
  .story-para { font-size: 0.98rem; }
  .story-subject { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .story-cover, .story-leaf { transition: none; }
  .story-book-wrap [class^="sc-"], .story-book-wrap [class*=" sc-"] { animation: none; }
}
