/* The front door is a physical volume. All rules are scoped to that volume. */
.storybook-home {
  --book-ink: #39291e; --book-red: #763f31; --book-gold: #99733a;
  color: #ebd9b2; background: #211913; background-image: radial-gradient(ellipse at 48% 42%, #65503a22, #100d0bbf), url("scholars-desk.webp");
  background-size: cover; background-position: center; background-attachment: fixed;
  min-height: 100vh; margin: 0; font-family: "IM Fell English", Georgia, serif;
}
.storybook-home *, .storybook-home *::before, .storybook-home *::after { box-sizing: border-box; }
.storybook-home #main { padding: 0; outline: none; }
.storybook-world { min-height: calc(100svh - 44px); display: flex; flex-direction: column; justify-content: center; padding: 22px 32px 0; overflow: clip; }
.story-masthead { display: flex; align-items: baseline; justify-content: space-between; gap: 20px; width: min(1120px, calc(100% - 100px)); margin: 0 auto 32px; color: #d2b884; }
.story-masthead a { color: #eddbb6; text-decoration: none; font: 1.3rem "IM Fell English SC", Georgia, serif; letter-spacing: .11em; }
.story-masthead > span { font-size: .93rem; font-style: italic; color: #c4ae8a; }
.story-scene { perspective: 2200px; width: min(1170px, calc(100% - 128px)); margin: 0 auto; padding: 0 0 28px; position: relative; left: -30px; }
.story-volume { position: relative; isolation: isolate; color: var(--book-ink); transform: rotateX(5deg); transform-style: preserve-3d; margin: 0; }
.story-volume::after { content: ""; position: absolute; z-index: -3; inset: 17% 2% -36px; border-radius: 25%; background: #090705; opacity: .9; filter: blur(28px); transform: translateZ(-30px); pointer-events: none; }
.story-cover { position: absolute; z-index: -1; inset: -12px -16px -20px; border: 2px solid #9d733d; border-radius: 12px 16px 17px 12px; background: repeating-linear-gradient(15deg, #281c130f 0 2px, #76492e22 2px 4px), linear-gradient(90deg,#31241a, #633e2a 7%,#46291f 47%,#2c1b15 50%,#633e2a 53%,#472c20); box-shadow: inset 0 0 0 4px #321f16, inset 0 0 0 6px #936c38, inset 0 0 0 9px #382418, 0 5px 0 #20150f, 0 9px 0 #352316, 0 20px 30px #0008; }
.story-cover i { position: absolute; width: 33px; height: 33px; border: 2px solid #b6914d; background: #956f3680; }
.story-cover i:nth-child(1) { top: 4px; left: 4px; border-radius: 7px 0 22px 0; }
.story-cover i:nth-child(2) { top: 4px; right: 4px; border-radius: 0 7px 0 22px; }
.story-cover i:nth-child(3) { bottom: 4px; left: 4px; border-radius: 0 22px 0 7px; }
.story-cover i:nth-child(4) { bottom: 4px; right: 4px; border-radius: 22px 0 7px 0; }
.story-page-block { position: absolute; z-index: -1; inset: 8px -7px -10px; border-radius: 9px 11px 12px 8px; background: repeating-linear-gradient(0deg,#d2bc8d 0 1px,#88734e 1px 2px,#e6d5ae 2px 4px); box-shadow: 0 2px 0 #57472d, 0 4px 0 #b99b67; }
.story-spreads { position: relative; z-index: 2; border-radius: 7px 10px 10px 7px; }
.story-chapter { display: grid; grid-template-columns: 1fr 1fr; position: relative; width: 100%; min-height: 660px; aspect-ratio: 1.72; }
.story-chapter[hidden] { display: none !important; }
/* Composite each leaf's video and paper wash together, inside the 3D turn. */
.story-page { position: relative; isolation: isolate; min-width: 0; display: flex; flex-direction: column; overflow: hidden; background-color: var(--book-paper, #efd6ae); border-top: 1px solid #fff3d4; }
.story-page-art { border-radius: 6px 44% 0 8px / 8px 1.5% 0 6px; background-position: left; padding: 28px 30px 44px 30px; box-shadow: inset 4px 0 14px #80603720, inset -16px 0 22px #50381830; }
.story-page-text { border-radius: 44% 7px 8px 0 / 1.5% 7px 5px 0; padding: 28px 45px 65px 48px; box-shadow: inset 16px 0 23px #50381822, inset -2px 0 12px #80603717; }
.story-page::before { content: ""; position: absolute; inset: 0; background: linear-gradient(0deg,#a17b3e0a,transparent 7%,transparent 93%,#b0945808); pointer-events: none; z-index: 4; }
.story-running { color: #7b6141; text-align: center; font: .72rem "IM Fell English SC", Georgia, serif; letter-spacing: .13em; display: block; padding: 0 0 13px; border-bottom: 1px solid #92734440; margin: 0 16px; }
.story-illumination { position: relative; isolation: isolate; display: flex; flex: 1; flex-direction: column; justify-content: center; align-items: center; margin: 11px 0 0; min-height: 0; border: 0; outline: 0; box-shadow: none; }
/* The clips encode 768 x 1080 pixels with a 15:16 pixel aspect ratio,
   so their displayed frame is 2:3. Fit raw posters and captured frames to
   that same rectangle; contain would expose a wider poster behind the video.
   Keep the existing illustration height while correcting its displayed width. */
.story-media { position: relative; width: min(100%,calc(var(--art-width,347px) * .9375)); aspect-ratio: 2 / 3; flex-shrink: 0; overflow: hidden; mask-image: linear-gradient(90deg,transparent,#000 7%,#000 93%,transparent),linear-gradient(0deg,transparent,#000 5%,#000 95%,transparent); mask-composite: intersect; }
/* Keep the video surface clipped to its own frame when fullscreen resizes
   the tilted book. The soft paper mask remains inside this paint boundary. */
.story-media { contain: paint; isolation: isolate; clip-path: inset(0); }
.story-media img, .story-media video, .story-media canvas { display: block; width: 100%; height: 100%; object-fit: fill; }
.story-media video, .story-media canvas { position: absolute; inset: 0; }
.story-media video { opacity: 0; }
.story-media video.is-playing { opacity: 1; }
.story-motion { border: 0; padding: 5px 0; background: none; color: inherit; font: inherit; font-style: italic; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.story-motion[hidden] { display: none; }
@media print { .story-media video { display: none; } }

.story-illumination figcaption { flex-shrink: 0; text-align: center; color: #74583c; margin: 8px 0 0; font: italic .9rem/1.4 "IM Fell English",Georgia,serif; }
.story-writing { display: flex; flex-direction: column; justify-content: center; flex: 1; width: 100%; max-width: 370px; margin: 0 auto; padding: 21px 0 0; }
.story-chapter-number { margin: 0 0 12px; text-align: center; font: .85rem "IM Fell English SC", Georgia,serif; color: #846039; letter-spacing: .14em; }
.storybook-home .story-title { color: var(--book-red); text-align: center; font: 400 clamp(2.25rem,3.8vw,3.75rem)/1.08 "IM Fell English",Georgia,serif; margin: 0; letter-spacing: -.035em; text-wrap: balance; }
/* Keep the opening title's typography on the leaf itself so its animated
   clone retains the same font, wrapping, and spacing outside the chapter. */
.storybook-home h1.story-title { font-family: "IM Fell English SC",Georgia,serif; font-size: clamp(2.8rem,4.7vw,4.8rem); }
.story-flourish { text-align: center; color: #9b763b; font-size: 2rem; line-height: 1; margin: 17px 0 16px; }
.story-prose { color: #453121; font: 1.15rem/1.63 "IM Fell English",Georgia,serif; }
.story-prose p { margin: 0 0 15px; }
.story-prose p:first-child::first-letter { float: left; font-family: "IM Fell English SC",Georgia,serif; font-size: 4.05rem; color: #88472e; line-height: .91; padding: 7px 9px 0 0; }
.story-inscription { color: #71352c; display: block; align-self: center; text-align: center; font: italic 1.23rem/1.5 "IM Fell English",Georgia,serif; text-decoration-color: #8f624580; text-decoration-thickness: 1px; text-underline-offset: 5px; margin-top: 13px; padding: 3px 0; }
.story-inscription:hover { color: #a34c28; text-decoration-color: currentColor; }
.story-manicule { font-style: normal; display: inline-block; font-size: 1.6rem; vertical-align: -.04em; margin-right: 4px; }
.story-link-note { text-align: center; margin: 9px 0 0; font: italic .84rem/1.4 "IM Fell English",Georgia,serif; color: #7e6849; }
.story-folio { position: absolute; bottom: 22px; left: 0; right: 0; text-align: center; font: .8rem Georgia,serif; color: #87704d; }
.story-spine { position: absolute; pointer-events: none; z-index: 6; top: 0; bottom: 0; left: calc(50% - 24px); width: 48px; background: linear-gradient(90deg,transparent,#66442520 30%,#4d321642 48%,#3b240f66 50%,#edd2a130 53%,#fff3d137 68%,transparent); }
.story-ribbon { position: absolute; z-index: 1; width: 25px; height: 72px; bottom: -55px; left: 52%; background: linear-gradient(90deg,#52271d,#95533b 45%,#612c20); clip-path: polygon(0 0,100% 0,100% 100%,50% 82%,0 100%); box-shadow: 3px 5px 6px #0009; transform: rotate(-5deg); }
/* Unselected index slips emerge from below the fore-edge. Only the current
   slip lies over the open leaf; the nav must not create a stacking context. */
.story-tabs { position: absolute; right: -88px; top: 6%; width: 105px; height: 83%; display: flex; flex-direction: column; justify-content: space-between; pointer-events: none; }
.story-tab { --slip-wash: #92703c40; --slip-angle: -.8deg; position: relative; z-index: 1; min-height: 44px; width: 99px; padding: 10px 5px 9px 21px; display: flex; align-items: center; gap: 5px; text-decoration: none; color: #493321; font: italic .86rem/1.2 "IM Fell English",Georgia,serif; pointer-events: auto; }
.story-tab::before { content: ""; position: absolute; z-index: -1; inset: 5px 0; background-color: #d4bb8c; background-image: linear-gradient(var(--slip-wash),var(--slip-wash)), url("home-parchment.webp"); background-size: auto, 330px auto; background-position: center, 60% 45%; clip-path: polygon(0 7%,18% 4%,97% 0,100% 9%,98% 42%,100% 75%,96% 96%,1% 100%,4% 54%); box-shadow: inset 0 1px #f9e8bb80, inset 0 -2px #88643833; transform: rotate(var(--slip-angle)); }
.story-tab:nth-child(3n+2) { --slip-wash: #9b5a4536; --slip-angle: 1.1deg; }
.story-tab:nth-child(3n) { --slip-wash: #72744b36; --slip-angle: -.3deg; }
.story-tab:nth-child(4n) { --slip-angle: 1.5deg; }
.story-tab > span { transform: rotate(var(--slip-angle)); }
/* Hover changes ink only: avoid filtered paper repaints inside the 3D book. */
.story-tab:hover { color: #783b26; }
.story-tab[aria-current="page"] { z-index: 5; color: #713c29; }
.story-tab[aria-current="page"]::before { left: -18px; --slip-wash: #b1853920; }
.story-tab[aria-current="page"]::after { content: ""; position: absolute; left: 16px; top: 8px; bottom: 7px; width: 1px; background: #80613926; box-shadow: 1px 0 #ffedc85c; transform: rotate(var(--slip-angle)); pointer-events: none; }
.story-tab-number { font: .56rem Georgia,serif; width: 13px; opacity: .7; }
.story-page-turns { position: absolute; z-index: 8; inset: auto 24px 12px; display: flex; justify-content: space-between; pointer-events: none; }
.story-page-turns[hidden] { display: none; }
.story-page-turns button { pointer-events: auto; padding: 9px 10px; min-height: 44px; font: italic .87rem "IM Fell English",Georgia,serif; border: 0; background: none; color: #694a32; cursor: pointer; }
.story-page-turns button:hover { color: #9c452e; }
.story-page-turns button:disabled { opacity: 0; pointer-events: none; }
.story-page-turns button span { font-size: 1.2rem; font-style: normal; }
.story-page-turns button[data-book-next]::after { content: ""; position: absolute; right: -24px; bottom: -12px; width: 34px; height: 34px; background: linear-gradient(135deg,transparent 49%,#b8a07970 51%,#e5d1a5 58%,#fff1cf 83%); border-radius: 0 0 7px 0; transition: width .2s,height .2s; }
.story-page-turns button[data-book-next]:hover::after { width: 43px; height: 43px; }
.story-page-turns button:disabled::after { display: none; }
.story-turner { position: absolute; z-index: 7; left: 50%; top: 0; width: 50%; height: 100%; transform-origin: 0 50%; transform-style: preserve-3d; pointer-events: none; }
.story-turner[hidden] { display: none; }
.story-turner-front,.story-turner-back { position: absolute; inset: 0; backface-visibility: hidden; transform-style: preserve-3d; overflow: hidden; border-radius: 0 7px 8px 0; box-shadow: 14px 8px 25px #42270f36; }
.story-turner-back { transform: rotateY(180deg); border-radius: 7px 0 0 8px; }
.story-turner .story-page { width: 100%; height: 100%; }
/* The cloned page already carries its paper wash and gutter shading.
   Keep the turning faces untinted so they match the resting leaves. */
.story-colophon { width: min(1120px,calc(100% - 100px)); margin: 30px auto 5px; display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px 20px; color: #c3ad88; font: .82rem/1.5 "IM Fell English",Georgia,serif; }
.story-colophon a { color: #cfb88f; text-decoration: none; }
.story-colophon a:hover { color: #f6ddb0; text-decoration: underline; }
.story-hint { font-style: italic; }
.story-footer { min-height: 44px; display: flex; justify-content: center; gap: 15px; align-items: center; padding: 12px 20px; font: .73rem "IM Fell English",Georgia,serif; color: #c5af88; }
.story-footer a { color: inherit; text-decoration: none; }
.story-footer a:hover { text-decoration: underline; }
.storybook-home :is(a,button):focus-visible { outline: 2px solid #bd8b3a; outline-offset: 5px; border-radius: 2px; }
/* Without script, every spread is a readable chapter and the ribbons are anchors. */
.story-volume:not(.book-ready) .story-chapter + .story-chapter { margin-top: 36px; }
.story-volume:not(.book-ready) .story-chapter { scroll-margin-top: 15px; }
.story-volume:not(.book-ready) .story-tabs { height: 540px; top: 25px; }
.story-volume:not(.book-ready) .story-spine { display: none; }
/* Give the desktop index enough paper and ink to read at a glance. */
@media(min-width:1101px) {
  .story-scene { left: -48px; }
  .story-tabs { right: -122px; width: 139px; top: 5%; height: 86%; }
  .story-tab { width: 133px; min-height: 54px; padding: 12px 10px 12px 24px; gap: 7px; font-size: 1.08rem; color: #382719; }
  .story-tab::before { inset-block: 3px; }
  .story-tab-number { width: 16px; font-size: .68rem; opacity: .85; }
}
@media(min-width:1400px) and (min-height:900px) {
  .story-scene { width: min(1300px,calc(100% - 150px)); }
  .story-chapter { min-height: 720px; }
  .story-media { --art-width: 370px; }
  .story-writing { max-width: 405px; }
  .story-prose { font-size: 1.27rem; }
}
@media(max-width:1100px) and (min-width:701px) {
  .storybook-world { padding: 18px 20px 0; }
  .story-scene { width: calc(100% - 128px); left: -25px; }
  .story-chapter { min-height: 580px; aspect-ratio: auto; }
  .story-page-text { padding: 24px 26px 65px 31px; }
  .story-page-art { padding: 24px 21px 52px; }
  .story-prose { font-size: 1.03rem; line-height: 1.55; }
  .story-inscription { font-size: 1.06rem; }
  .story-running { font-size: .59rem; margin-inline: 0; }
  .story-media { --art-width: 280px; }
  .story-illumination figcaption { font-size: .78rem; }
  .story-link-note { font-size: .75rem; }
  .story-flourish { margin-block: 13px; }
  .story-tab[aria-current="page"]::before { left: -5px; }
}
/* On a phone the volume reads as one full-width illuminated leaf: text,
   then artwork. The index moves above it instead of stealing reading width. */
@media(max-width:700px) {
  .storybook-world { justify-content: flex-start; padding: 18px 18px 0; overflow: clip; }
  .story-masthead { width: 100%; margin: 0 auto 20px; justify-content: center; }
  .story-masthead a { font-size: 1.05rem; }
  .story-masthead > span { display: none; }
  .story-scene { width: 100%; margin: 0; padding-bottom: 16px; perspective: none; left: 0; }
  .story-volume { transform: none; scroll-margin-top: 12px; }
  .story-cover { inset: -7px -8px -15px; border-radius: 8px; }
  .story-page-block { inset: 6px -4px -8px; }
  .story-chapter { grid-template-columns: 1fr; min-height: 0; aspect-ratio: auto; }
  .story-page-text { order: -1; padding: 22px 25px 13px; border-radius: 6px 6px 0 0; box-shadow: inset 7px 0 16px #795d341a; }
  .story-running { font-size: .64rem; margin: 0; padding-bottom: 12px; }
  .story-writing { max-width: 460px; padding-top: 17px; }
  .story-chapter-number { font-size: .72rem; margin-bottom: 9px; }
  .storybook-home .story-title { font-size: clamp(2rem,7.5vw,2.8rem); }
  .storybook-home h1.story-title { font-size: clamp(2.6rem,9vw,3.5rem); }
  .story-prose { font-size: 1.1rem; line-height: 1.58; }
  .story-prose p { margin-bottom: 13px; }
  .story-prose p:first-child::first-letter { font-size: 3.7rem; padding-right: 7px; }
  .story-inscription { font-size: 1.15rem; margin-top: 8px; min-height: 44px; display: flex; align-items: center; justify-content: center; gap: 5px; }
  .story-manicule { font-size: 1.4rem; }
  .story-link-note { font-size: .8rem; margin-top: 3px; }
  .story-flourish { margin: 12px 0; font-size: 1.6rem; }
  .story-page-art { padding: 0 8px 72px; border-radius: 0 0 6px 6px; border-top: 0; box-shadow: inset 7px 0 16px #795d341a; }
  .story-page-art .story-running, .story-folio { display: none; }
  .story-illumination { margin: 0; }
  .story-media { width: min(100%,390px); }
  .story-illumination figcaption { font-size: .83rem; margin: 8px 12px 0; }
  .story-spine { display: none; }
  .story-tabs { position: relative; inset: auto; width: 100%; height: auto; display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 2px 3px; padding: 1px 3px 10px; }
  .story-tab { width: 100%; min-height: 44px; padding: 10px 3px; justify-content: center; font-size: .82rem; gap: 0; }
  .story-tab-number { display: none; }
  .story-tab::before { inset: 2px 0; }
  .story-tab[aria-current="page"] { color: #71352c; font-weight: bold; }
  .story-tab[aria-current="page"]::before { left: 0; background-color: #efd6ae; --slip-wash: #b185390d; }
  .story-tab[aria-current="page"]::after { inset: auto 22% 7px; height: 1px; width: auto; background: #8b492e; box-shadow: none; transform: none; }
  .story-page-turns { inset: auto 12px 12px; }
  .story-page-turns button { padding: 9px 6px; font-size: .88rem; }
  .story-page-turns button span { font-size: 1.1rem; }
  .story-page-turns button[data-book-next]::after { right: -12px; bottom: -12px; width: 28px; height: 28px; }
  .story-colophon { width: 100%; font-size: .76rem; margin-top: 25px; justify-content: center; text-align: center; gap: 7px 15px; }
  .story-colophon a { flex-basis: 100%; }
  .story-motion { min-height: 44px; padding: 10px 4px; }
  .story-ribbon { left: 65%; height: 50px; bottom: -40px; width: 20px; }
  .story-footer { font-size: .72rem; gap: 12px; padding-top: 18px; }
  .story-volume:not(.book-ready) .story-tabs { height: auto; top: auto; }
}
@media(max-width:360px) {
  .storybook-world { padding-inline: 14px; }
  .story-page-text { padding-inline: 20px; }
  .story-prose { font-size: 1.04rem; }
  .story-tab { font-size: .75rem; }
  .story-page-turns button { font-size: .8rem; }
}
@media(prefers-reduced-motion:reduce) {
  .story-volume { transform: none; }
  .story-tab, .story-page-turns button::after { transition: none; }
}
@media print {
  .storybook-home { background: white; }
  .story-cover,.story-page-block,.story-tabs,.story-spine,.story-page-turns,.story-ribbon,.story-colophon,.story-footer { display: none !important; }
  .story-scene { width: 100%; }
  .story-volume { transform: none; }
  .story-chapter,.story-chapter[hidden] { display: grid !important; break-after: page; }
}
