@import url('https://fonts.googleapis.com/css2?family=EB+Garamond:ital,wght@0,400;0,500;0,600;1,400;1,500&display=swap');

:root {
  --board: #1f3a3c;
  --mat: #efe3c9;
  --cream: #f8efdb;
  --ink: #3b2b1d;
  --ink-soft: #5b4632;
  --terracotta: #c8642d;
  --moss: #5f7f5b;
  --ochre: #d9a45b;
  --serif: 'EB Garamond', 'Iowan Old Style', 'Palatino Linotype', Palatino, Georgia, serif;
  --shade: rgba(58, 38, 18, .34);
  --edge: rgba(255, 250, 236, .5);
  --frame: clamp(10px, 1.6vw, 24px);
}

* { box-sizing: border-box; }
html { scrollbar-width: none; }
html::-webkit-scrollbar { display: none; }
body {
  margin: 0;
  background: var(--board);
  color: var(--ink);
  font-family: var(--serif);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
#scroll-space { width: 1px; }

/* ---------- the box ---------- */
.stage { position: fixed; inset: 0; overflow: hidden; background: #f1e4c8; }
#scenes { position: absolute; inset: 0; }
.scene { position: absolute; inset: 0; }
.layer { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform, opacity; pointer-events: none; }
.layer > svg { position: absolute; left: 0; top: 0; display: block; overflow: hidden; transform-origin: 0 0; }
.layer > svg.live { will-change: transform; }
.layer > svg.sprite { will-change: transform, opacity; }
.grain { fill: url(#grain); pointer-events: none; }
.grain.gm { display: none; } /* merged into its sheet's single grain path (see engine.js) */
/* paper shadows: silhouette copies of every cut-out (see sheet() in paper.js); --k is the layer's shadow depth */
.gsh { display: none; fill: #3a2612; }
/* blur: still pieces use an svg filter; moving ones fall back to two hard steps */
[data-shadow="blur"] .cut .gs .gsh:is(.s0, .s1) { display: inline; }
[data-shadow="blur"] .gsh.s0 { opacity: .15; transform: translate(0, 2.2px); }
[data-shadow="blur"] .gsh.s1 { opacity: .09; transform: translate(.5px, 4.6px); }
/* soft: ten copies spread like a gaussian around the blur's offset, plus the light rim */
[data-shadow="soft"] .cut .gsh { display: inline; opacity: .038; }
[data-shadow="soft"] .cut .gsh.r { opacity: .5; }
/* step: two hard steps scaled by depth, plus the light rim */
[data-shadow="step"] .cut .gsh:is(.r, .s0, .s1) { display: inline; }
[data-shadow="step"] .gsh.s0 { opacity: .15; transform: translate(0, calc(var(--k) * .55px)); }
[data-shadow="step"] .gsh.s1 { opacity: .09; transform: translate(calc(var(--k) * .12px), calc(var(--k) * 1.15px)); }
.vignette { position: absolute; inset: 0; pointer-events: none; box-shadow: inset 0 0 18vmin rgba(60, 36, 14, .22); }
.frame { position: absolute; inset: 0; z-index: 6; width: 100%; height: 100%; pointer-events: none; filter: drop-shadow(0 0 10px rgba(20, 20, 10, .35)); }
.defs { position: absolute; width: 0; height: 0; overflow: hidden; }

/* ---------- hanging tag ---------- */
.tag-wrap {
  position: fixed; top: 0; left: calc(var(--frame) + clamp(14px, 3.4vw, 60px)); z-index: 10;
  transform-origin: 50% 0; pointer-events: none;
  filter: drop-shadow(2px 10px 9px var(--shade));
}
.tag-wrap.swing { animation: swing 2.4s cubic-bezier(.3, .6, .3, 1); }
@keyframes swing {
  0% { transform: translateY(-110%); }
  30% { transform: translateY(4px) rotate(3.2deg); }
  52% { transform: rotate(-2deg); }
  72% { transform: rotate(1deg); }
  100% { transform: rotate(0); }
}
.tag-string { display: block; margin: 0 auto; width: 1px; height: clamp(20px, 4vh, 44px); background: linear-gradient(rgba(74, 54, 34, .2), rgba(74, 54, 34, .7)); }
.tag {
  position: relative; width: clamp(200px, 19vw, 270px); padding: 40px 20px 18px; text-align: center; background: var(--cream);
  clip-path: polygon(24% 0, 76% 0, 100% 15%, 100% 100%, 0 100%, 0 15%);
}
.tag::after { content: ''; position: absolute; inset: 7px; border: 1px dashed rgba(122, 78, 40, .35); clip-path: polygon(23% 0, 77% 0, 100% 14%, 100% 100%, 0 100%, 0 14%); pointer-events: none; }
.tag-hole {
  position: absolute; left: 50%; top: 12px; z-index: 1; width: 14px; height: 14px; margin-left: -7px; padding: 0; border: 0; border-radius: 50%;
  background: var(--board); box-shadow: 0 0 0 3px var(--ochre), 0 0 0 4px rgba(90, 56, 24, .35);
  cursor: pointer; pointer-events: auto; transition: box-shadow .25s, transform .3s cubic-bezier(.3, 1.6, .5, 1);
}
.tag-hole::before { content: ''; position: absolute; inset: -12px; border-radius: 50%; } /* a finger-sized target around the eyelet */
.tag-hole:hover { transform: scale(1.18); box-shadow: 0 0 0 3.5px var(--terracotta), 0 0 0 5px rgba(90, 56, 24, .35); }
.tag-hole:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--terracotta), 0 0 0 6px var(--cream), 0 0 0 7.5px var(--terracotta); }
.grain-fill { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.tag-title { position: relative; margin: 0; font-weight: 400; font-size: clamp(21px, 1.9vw, 28px); line-height: 1.05; }
.tag-ref { position: relative; margin: 8px 0 0; font-size: 14px; font-style: italic; color: var(--ink-soft); }
.parable-mark { display: none; color: var(--terracotta); }
.tag-wrap.parable .parable-mark { display: inline; }
.tag-wrap { transition: opacity .5s ease .35s, visibility 0s .35s; } /* it comes in a moment after the scene */
.tag-wrap.gone { opacity: 0; visibility: hidden; transition: opacity .4s ease, visibility 0s .4s; }
/* a small paper chip beside the eyelet: the same "back to the title page" as the eyelet, but spelled out */
.tag-back {
  position: absolute; left: calc(50% + 18px); top: calc(clamp(20px, 4vh, 44px) + 4px); z-index: 1;
  appearance: none; border: 0; padding: 4px 10px 5px; font: italic 13px/1 var(--serif); color: var(--ink); background: #efe3c7;
  cursor: pointer; pointer-events: auto;
  clip-path: polygon(3% 10%, 50% 0, 97% 8%, 100% 55%, 96% 96%, 50% 100%, 2% 92%, 0 45%);
  transition: transform .3s cubic-bezier(.3, 1.6, .5, 1), background-color .2s;
}
.tag-back::before { content: ''; position: absolute; inset: -8px; } /* a finger-sized target */
.tag-back:hover { transform: translateY(-1px) rotate(-2deg); background: #f6d9b8; }
.tag-back:focus-visible { outline: 2px dashed var(--terracotta); outline-offset: 2px; }

/* ---------- cover ---------- */
.cover {
  position: fixed; left: 50%; top: 42%; z-index: 9; width: min(560px, 84vw); margin: 0; padding: 34px 30px 30px;
  text-align: center; translate: -50% -50%; background: var(--cream);
  clip-path: polygon(1% 3%, 30% 0, 64% 2%, 99% 0, 100% 48%, 98% 97%, 62% 100%, 33% 98%, 0 100%, 1% 52%);
  pointer-events: none;
}
.cover-kicker { margin: 0 0 10px; font-size: 12px; letter-spacing: .26em; text-transform: uppercase; color: #9a5526; }
.cover h1 { margin: 0; font-weight: 400; font-size: clamp(38px, 5.4vw, 64px); line-height: .98; letter-spacing: -.01em; }
.cover h1 em { display: block; margin-top: 6px; font-size: .56em; color: var(--terracotta); }
.rule { display: block; width: 52px; height: 6px; margin: 16px auto 0; background: radial-gradient(circle, var(--moss) 1.5px, transparent 1.9px) 0 50% / 10px 6px repeat-x; }
.cover-sub { margin: 14px 0 0; font-size: clamp(16px, 1.6vw, 19px); line-height: 1.4; font-style: italic; color: var(--ink-soft); }

/* ---------- caption ---------- */
.caption {
  position: fixed; left: 50%; bottom: calc(var(--frame) + clamp(14px, 3vh, 34px)); z-index: 10;
  width: min(760px, calc(100vw - 2 * var(--frame) - 32px)); padding: 16px 26px 18px;
  translate: -50% 0; background: rgba(250, 243, 226, .96);
  clip-path: polygon(0 6%, 12% 1%, 40% 4%, 71% 0, 100% 5%, 99.4% 52%, 100% 95%, 74% 100%, 38% 96%, 9% 100%, .4% 94%, 0 48%);
  transition: opacity .5s ease, transform .5s ease;
}
.caption.off { opacity: 0; transform: translateY(20px); }
.caption.dim .cap-text { opacity: .55; }
.caption.flip { animation: capIn .6s cubic-bezier(.2, .8, .3, 1); }
@keyframes capIn { from { transform: translateY(10px) rotate(-.4deg); } to { transform: none; } }
.cap-ref { position: relative; margin: 0 0 4px; font-size: 11px; letter-spacing: .22em; text-transform: uppercase; color: #9a5526; }
.cap-text { position: relative; margin: 0; font-size: clamp(18px, 1.55vw, 24px); line-height: 1.38; transition: opacity .4s; text-wrap: pretty; }
.cap-text .w { display: inline-block; opacity: 0; will-change: opacity, transform; }
.cap-text .vn { margin-right: 3px; font-size: .58em; font-weight: 600; color: var(--terracotta); vertical-align: .55em; }
.cap-text .br { color: #9c8a73; }

/* ---------- progress thread ---------- */
.rail { position: fixed; right: calc(var(--frame) + clamp(10px, 1.6vw, 26px)); top: 16vh; bottom: 16vh; width: 18px; z-index: 11; }
.thread { position: absolute; left: 50%; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: rgba(74, 54, 34, .22); border-radius: 1px; overflow: hidden; }
.thread .fill { position: absolute; inset: 0; background: var(--terracotta); transform-origin: 0 0; transform: scaleY(0); }
.knot { position: absolute; left: 50%; width: 12px; height: 12px; margin: -6px 0 0 -6px; padding: 0; border: 0; border-radius: 50%; background: var(--cream); box-shadow: 0 0 0 1.5px rgba(74, 54, 34, .45), 0 2px 3px var(--shade); cursor: pointer; transition: background .3s, transform .2s; }
.knot.on { background: var(--terracotta); }
.knot:hover, .knot:focus-visible { transform: scale(1.35); outline: none; }
.knot .lbl { position: absolute; right: 22px; top: 50%; translate: 0 -50%; padding: 4px 10px; white-space: nowrap; font: italic 15px var(--serif); color: var(--ink); background: var(--cream); opacity: 0; pointer-events: none; transition: opacity .2s; box-shadow: 0 3px 6px var(--shade); }
.knot:hover .lbl, .knot:focus-visible .lbl { opacity: 1; }

/* ---------- hint & end ---------- */
.hint { position: fixed; left: 50%; bottom: calc(var(--frame) + 26px); z-index: 11; margin: 0; display: flex; align-items: center; gap: 10px; padding: 12px 24px; translate: -50% 0; font-size: 21px; font-style: italic; color: var(--cream); background: rgba(28, 55, 57, .82); clip-path: polygon(0 8%, 40% 0, 100% 6%, 99% 94%, 55% 100%, 1% 96%); transition: opacity .6s; }
.hint svg { width: 24px; height: 24px; animation: nudge 1.6s ease-in-out infinite; }
@keyframes nudge { 50% { transform: translateY(4px); } }
/* swipe mode (touch screens): nothing scrolls, the theatre moves one sentence per swipe */
.swipe, .swipe body { overflow: hidden; overscroll-behavior: none; }
.swipe .stage { touch-action: none; }
.swipe .hint svg { rotate: 180deg; }
.hint.gone { opacity: 0; pointer-events: none; visibility: hidden; transition: opacity .6s, visibility 0s .6s; }
.hint.gone svg { animation: none; }
.end {
  position: fixed; left: 50%; top: 40%; z-index: 12; width: min(520px, 86vw); padding: 26px 28px 24px; translate: -50% -50%;
  text-align: center; opacity: 0; pointer-events: none; transition: opacity 1s ease; color: var(--ink); background: var(--cream);
  clip-path: polygon(1% 4%, 32% 0, 66% 3%, 99% 0, 100% 50%, 98% 97%, 60% 100%, 30% 97%, 0 100%, 1% 50%);
}
.end.on { opacity: 1; pointer-events: auto; }
.end-kicker { margin: 0; font-size: 12px; letter-spacing: .28em; text-transform: uppercase; color: #9a5526; }
.end-q { margin: 8px 0 18px; font-size: clamp(26px, 3.4vw, 44px); line-height: 1.1; font-style: italic; }
.chip { appearance: none; border: 0; padding: 10px 20px; font: italic 17px var(--serif); color: var(--ink); background: #efe3c7; cursor: pointer; clip-path: polygon(2% 6%, 30% 0, 62% 4%, 99% 1%, 100% 52%, 98% 96%, 64% 100%, 34% 97%, 1% 100%, 0 48%); transition: transform .25s cubic-bezier(.3, 1.6, .5, 1); }
.chip:hover { transform: translateY(-2px) rotate(-1deg); }
.chip:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--terracotta); }

@media (max-width: 700px) {
  /* the tag turns into a slim one-line label, hung by its eyelet on the left */
  .tag-wrap { transform-origin: 19px 0; }
  .tag-string { margin: 0 0 0 18px; height: clamp(14px, 2.4vh, 24px); }
  .tag {
    display: flex; align-items: baseline; gap: 8px; width: auto; max-width: calc(100vw - 2 * var(--frame) - 112px);
    padding: 8px 14px 9px 34px; text-align: left; white-space: nowrap;
    clip-path: polygon(0 18%, 9px 0, 100% 0, 100% 100%, 9px 100%, 0 82%);
  }
  .tag::after { inset: 4px; clip-path: none; }
  .tag-hole { left: 12px; top: 50%; width: 12px; height: 12px; margin: -6px 0 0; }
  .tag-title { font-size: 17px; line-height: 1.2; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
  .tag-ref { flex: none; margin: 0; font-size: 13px; }
  .tag-back { left: calc(100% + 8px); top: calc(clamp(14px, 2.4vh, 24px) + 6px); padding: 6px 10px 7px; font-size: 14px; }
  .caption { padding: 12px 16px 14px; }
  /* on a tall screen the closing card hangs in the sky, above the scene, so the last sentence still has its picture */
  .end { top: 26%; padding: 20px 22px 20px; }
  .end-q { margin: 6px 0 14px; }
  .cap-ref { font-size: 12px; }
  .cap-text { font-size: 21px; line-height: 1.34; }
  .hint { font-size: 19px; padding: 11px 20px; }
  .rail { right: calc(var(--frame) + 4px); top: 24vh; bottom: 30vh; }
  .knot .lbl { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .tag-wrap.swing, .caption.flip, .hint svg { animation: none; }
}

/* ---------- page turn (jumping between sections) ---------- */
.turn {
  position: absolute; inset: -4% -2%; z-index: 5; display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: #f4ead4; pointer-events: none;
  clip-path: polygon(0 1%, 18% 0, 47% 1.5%, 76% 0, 100% 1%, 99% 50%, 100% 99%, 70% 100%, 38% 98.5%, 12% 100%, 0 99%, 1% 50%);
  transform: translateX(106%) rotate(1.2deg); transition: transform .42s cubic-bezier(.62, 0, .36, 1);
  filter: drop-shadow(-12px 0 16px rgba(58, 38, 18, .35));
}
.turn.on { transform: none; }
.turn.out { transform: translateX(-106%) rotate(-1.2deg); transition-duration: .52s; }
.turn.reset { transition: none; }
.turn-title { position: relative; margin: 0; font-size: clamp(30px, 4.4vw, 58px); font-style: italic; color: var(--ink); }
.turn-ref { position: relative; margin: 10px 0 0; font-size: 13px; letter-spacing: .26em; text-transform: uppercase; color: #9a5526; }

/* ---------- language picker: two paper flags on a little card ---------- */
.lang {
  transition: opacity .5s ease, transform .5s ease;
  position: fixed; top: calc(var(--frame) + 12px); right: calc(var(--frame) + 14px); z-index: 12;
  display: flex; gap: 4px; padding: 6px 7px; background: var(--cream);
  clip-path: polygon(3% 8%, 40% 0, 98% 6%, 100% 55%, 97% 96%, 55% 100%, 2% 94%, 0 45%);
  filter: drop-shadow(0 5px 6px var(--shade));
}
.flag {
  appearance: none; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 4px 6px 2px; border: 0;
  background: transparent; cursor: pointer; font: 600 10.5px var(--serif); letter-spacing: .18em; color: var(--ink-soft);
  opacity: .62; transition: opacity .25s, transform .3s cubic-bezier(.3, 1.6, .5, 1);
}
.flag svg { width: 34px; height: 22px; display: block; filter: drop-shadow(0 2px 2px rgba(58, 38, 18, .3)); }
.flag:hover { opacity: .9; transform: translateY(-2px) rotate(-2deg); }
.flag[aria-pressed="true"] { opacity: 1; transform: translateY(-1px); color: var(--terracotta); }
.flag[aria-pressed="true"]::after { content: ''; width: 5px; height: 5px; border-radius: 50%; background: var(--terracotta); }
.flag:focus-visible { outline: 2px dashed var(--terracotta); outline-offset: 2px; }

.stage { cursor: default; }

@media (max-width: 700px) {
  .lang { padding: 4px 5px; }
  .flag svg { width: 28px; height: 18px; }
}
@media (prefers-reduced-motion: reduce) { .turn { transition: none; } }

.turning .caption, .turning .end, .turning .hint, .turning .cover { opacity: 0 !important; transition: opacity .2s; }
.lang.gone { opacity: 0; transform: translateY(-12px); pointer-events: none; visibility: hidden; transition: opacity .5s ease, transform .5s ease, visibility 0s .5s; }

/* ---------- the chapter's title card ---------- */
.cover-ch { display: block; margin-bottom: 4px; font-size: 12px; font-style: normal; letter-spacing: .24em; text-transform: uppercase; color: #9a5526; }
.cover-toc { margin-top: 18px; pointer-events: auto; font-size: 16px; padding: 8px 18px; }
.end-actions { display: flex; gap: 10px; justify-content: center; }
.chip.next { font-style: normal; background: var(--terracotta); color: var(--cream); }

/* ---------- loading: nothing chapter-specific shows until the chapter is in ---------- */
.loading .cover, .loading .library, .loading .tag-wrap, .loading .hint, .loading .lang, .loading .rail, .loading .caption, .loading .end { visibility: hidden !important; }
/* until the script draws the deckled frame, a plain one in the same colours */
.loading .stage::after { content: ''; position: absolute; inset: calc(clamp(10px, 1.6vw, 24px) + 7px); z-index: 4; border-radius: 3.5vmin; box-shadow: 0 0 0 7px #efe3c9, 0 0 0 60px #1f3a3c; pointer-events: none; }
.loader { position: absolute; left: 50%; top: 50%; z-index: 5; display: flex; gap: 10px; transform: translate(-50%, -50%); opacity: 0; pointer-events: none; }
.loading .loader { animation: loader-in .3s ease-out .2s forwards; } /* a short delay, so a fast load never flashes it */
.loader i { width: 14px; height: 14px; border-radius: 46% 54% 50% 48%; background: var(--terracotta); box-shadow: 0 2px 2px rgba(58, 38, 18, .28), inset 0 -1px 0 rgba(58, 38, 18, .12); animation: loader-hop 1.1s ease-in-out infinite; }
.loader i:nth-child(2) { background: #8fae8b; animation-delay: .15s; }
.loader i:nth-child(3) { background: #e2b25c; animation-delay: .3s; }
.ready .cover { animation: cover-in .5s ease-out; }
@keyframes loader-in { to { opacity: 1; } }
@keyframes loader-hop { 0%, 60%, 100% { transform: translateY(0) rotate(0); } 30% { transform: translateY(-10px) rotate(-12deg); } }
@keyframes cover-in { from { opacity: 0; transform: translateY(12px); } }
@media (prefers-reduced-motion: reduce) { .loader i, .ready .cover { animation: none; } }

/* ---------- the library: the home page, books standing in front of the curtains ---------- */
.library {
  position: fixed; inset: var(--frame); z-index: 13; display: none; flex-direction: column; align-items: center;
  padding: 0 16px clamp(28px, 6vh, 64px); overflow-y: auto; overscroll-behavior: contain; scrollbar-width: none;
  border-radius: 3.5vmin; transition: background-color .5s ease;
}
.library::-webkit-scrollbar { display: none; }
.lib-on .library { display: flex; }
.library.unfolded { background: rgba(31, 42, 40, .28); }
/* while it is up, the chapter behind stands still: no scroll, no title card, no thread */
.lib-on #scroll-space, .lib-on .cover, .lib-on .hint, .lib-on .rail, .lib-on .tag-wrap { display: none; }
.lib-on .lang { z-index: 20; }
/* leaving for another chapter: the library steps away (the curtain is already closed behind it) */
.leaving .library { opacity: 0 !important; transition: opacity .3s ease; }
/* entering one: straight onto its first scene, no title card */
.entering .cover, .entering .hint { display: none; }

/* ---------- the stage curtain ---------- */
.drape { position: absolute; inset: 0; z-index: 4; pointer-events: none; visibility: hidden; }
.drape.on, .entering .drape { visibility: visible; }
.dr-half { position: absolute; top: 0; bottom: 0; width: calc(50% + 24px); background: #c9776b; transition: transform 1.35s cubic-bezier(.62, .02, .3, 1); will-change: transform; }
.dr-half svg, .dr-val svg { display: block; width: 100%; height: 100%; }
.dr-l { left: 0; transform-origin: 0 50%; box-shadow: 10px 0 22px rgba(58, 38, 18, .3); }
.dr-r { right: 0; transform-origin: 100% 50%; box-shadow: -10px 0 22px rgba(58, 38, 18, .3); }
.dr-val { position: absolute; left: 0; right: 0; top: 0; height: calc(min(90px, 10vh) + 50px); filter: drop-shadow(0 6px 6px rgba(58, 38, 18, .3)); transition: transform .9s cubic-bezier(.5, 0, .3, 1) .45s; }
/* drawn back to the wings: the halves slide off and gather a little as they go */
.drape.open .dr-l { transform: translateX(-104%) scaleX(.82); }
.drape.open .dr-r { transform: translateX(104%) scaleX(.82); }
.drape.open .dr-val { transform: translateY(-110%); }
.drape:not(.open) .dr-half { transition-duration: .85s; transition-timing-function: cubic-bezier(.45, 0, .3, 1); }
.drape:not(.open) .dr-val { transition-delay: 0s; transition-duration: .5s; }
.drape.snap .dr-half, .drape.snap .dr-val { transition: none; }
/* while it is closed the reading furniture steps back */
.drape-on .caption, .drape-on .tag-wrap, .drape-on .rail, .drape-on .end, .drape-on .hint, .drape-on .cover { opacity: 0 !important; pointer-events: none; transition: opacity .3s ease; }
@media (prefers-reduced-motion: reduce) { .dr-half, .dr-val { transition-duration: .01s !important; transition-delay: 0s !important; } }
@media (max-width: 759px) { .lib-book .lang { opacity: 0; visibility: hidden; transition: opacity .3s, visibility 0s .3s; } }

/* a paper banner hung on two strings */
.lib-head { position: relative; flex: none; display: flex; flex-direction: column; align-items: center; filter: drop-shadow(2px 9px 8px var(--shade)); transition: opacity .35s ease; }
.lib-strings { display: block; width: 62%; height: clamp(18px, 5vh, 52px); border: solid rgba(74, 54, 34, .6); border-width: 0 1px; }
.lib-banner {
  position: relative; padding: 16px clamp(26px, 4vw, 48px) 15px; text-align: center; background: var(--cream);
  clip-path: polygon(0 4%, 22% 0, 55% 3%, 100% 0, 99% 50%, 100% 97%, 64% 100%, 30% 97%, 1% 100%, .6% 50%);
}
.lib-kicker { position: relative; margin: 0; font-size: 12px; letter-spacing: .26em; text-transform: uppercase; color: #9a5526; }
.lib-title { position: relative; margin: 4px 0 0; font-weight: 400; font-size: clamp(38px, 4.4vw, 56px); line-height: 1; }
.lib-sub { position: relative; margin: 6px 0 0; font-size: clamp(16px, 1.4vw, 19px); font-style: italic; color: var(--ink-soft); }
.unfolded .lib-head { opacity: 0; }

/* the shelf of cards */
.shelves { flex: none; margin: auto 0; padding: clamp(22px, 5vh, 56px) 0 12px; transition: opacity .3s; }
.unfolded .shelves { opacity: 0; pointer-events: none; }
.shelf-name { margin: 0 0 14px; text-align: center; font-weight: 400; font-style: italic; font-size: 24px; color: var(--cream); }
.cards { --cw: clamp(180px, 16.4vw, 250px); display: grid; grid-template-columns: repeat(4, var(--cw)); gap: clamp(20px, 2.6vw, 44px); justify-content: center; }
.book-card, .bk-cover { position: relative; display: block; width: var(--cw); color: var(--ink); font: inherit; text-align: center; }
.book-card {
  appearance: none; margin: 0; padding: 0; border: 0; background: none; cursor: pointer;
  transform: rotate(var(--tilt)); filter: drop-shadow(0 10px 10px rgba(58, 38, 18, .36));
  transition: transform .4s cubic-bezier(.3, 1.5, .5, 1), filter .4s;
}
.book-card:hover { transform: translateY(-7px) rotate(calc(var(--tilt) * -.5)); filter: drop-shadow(0 18px 14px rgba(58, 38, 18, .32)); }
.book-card:active { transform: translateY(-2px) scale(.985); transition-duration: .12s; }
.book-card:focus-visible { outline: none; }
.book-card:focus-visible .bc-paper { box-shadow: inset 0 0 0 2px var(--accent); }
.book-card:disabled { cursor: default; opacity: .55; filter: grayscale(.6) drop-shadow(0 6px 6px rgba(58, 38, 18, .3)); transform: rotate(var(--tilt)); }
.bc-paper { position: relative; display: flex; flex-direction: column; align-items: center; padding: 10px 10px 18px; background: var(--cream); }
.bc-art { position: relative; display: block; width: 100%; }
.bc-art svg { display: block; width: 100%; height: auto; }
.bc-kicker { position: relative; margin-top: 13px; font-size: 10.5px; letter-spacing: .2em; text-transform: uppercase; color: var(--accent); }
.bc-name { position: relative; margin-top: 3px; font-size: clamp(28px, 2.4vw, 36px); line-height: 1; font-style: italic; }
.bc-count { position: relative; display: flex; flex-direction: column; align-items: center; margin-top: 10px; font-size: 14px; font-style: italic; color: var(--ink-soft); }
.bc-count::before { content: ''; width: 34px; height: 6px; margin-bottom: 6px; background: radial-gradient(circle, var(--moss) 1.4px, transparent 1.8px) 0 50% / 8.5px 6px repeat-x; }
/* a ribbon marks the book being read */
.bc-ribbon { position: absolute; top: -5px; right: 16%; width: 15px; height: 46px; background: var(--terracotta); clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 80%, 0 100%); filter: drop-shadow(0 2px 1px rgba(58, 38, 18, .3)); }

/* an open book: its cover, and the page of chapters unfolding from it */
.booklet { position: fixed; inset: var(--frame); z-index: 1; display: flex; align-items: center; justify-content: center; padding: 24px 16px; overflow-y: auto; scrollbar-width: none; pointer-events: none; }
.booklet[hidden] { display: none; }
.booklet > * { pointer-events: auto; }
.booklet { --cw: clamp(180px, 16.4vw, 250px); }
.bk-cover { flex: none; align-self: center; filter: drop-shadow(0 12px 12px rgba(58, 38, 18, .38)); z-index: 1; }
.bk-scroll { position: relative; display: flex; flex-direction: column; width: min(540px, 100%); height: min(660px, calc(100vh - 2 * var(--frame) - 48px)); margin-left: 22px; }
/* two turned wooden rods; the parchment hangs between them */
.rod {
  position: relative; z-index: 1; flex: none; height: 15px; margin: 0 -14px; border-radius: 8px;
  background: linear-gradient(#c49469, #a8764f 45%, #7a5134); box-shadow: 0 3px 5px rgba(58, 38, 18, .35);
}
.rod::before, .rod::after { content: ''; position: absolute; top: -3px; width: 12px; height: 21px; border-radius: 6px; background: linear-gradient(#b3805a, #6b4630); }
.rod::before { left: -9px; } .rod::after { right: -9px; }
.bk-sheet {
  position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; margin: -4px 0; background: #f7edd6;
  box-shadow: inset 0 10px 12px -8px rgba(58, 38, 18, .4), inset 0 -10px 12px -8px rgba(58, 38, 18, .4), inset 10px 0 14px -12px rgba(58, 38, 18, .3), inset -10px 0 14px -12px rgba(58, 38, 18, .3);
}
.bk-head { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 20px 22px 12px 28px; border-bottom: 1px dashed rgba(122, 78, 40, .35); }
.bk-kicker { margin: 0; font-size: 12px; letter-spacing: .2em; text-transform: uppercase; color: var(--accent); }
.bk-close { flex: none; padding: 7px 14px; font-size: 15px; }
.toc {
  position: relative; flex: 1; min-height: 0; margin: 0; padding: 8px 12px 20px; list-style: none; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: rgba(122, 78, 40, .35) transparent;
  -webkit-mask-image: linear-gradient(transparent, #000 12px, #000 calc(100% - 22px), transparent); mask-image: linear-gradient(transparent, #000 12px, #000 calc(100% - 22px), transparent);
}
.toc-row {
  position: relative; display: grid; grid-template-columns: 2.1em 1fr; gap: 14px; align-items: baseline; width: 100%; margin: 0; padding: 11px 14px 12px 6px;
  appearance: none; border: 0; background: transparent; color: var(--ink); font: inherit; text-align: left; cursor: pointer;
  clip-path: polygon(0 6%, 40% 0, 100% 5%, 99.5% 95%, 55% 100%, .5% 96%); transition: background-color .2s;
}
.toc li + li .toc-row::before { content: ''; position: absolute; left: 3.2em; right: 14px; top: 0; border-top: 1px dotted rgba(122, 78, 40, .22); }
.toc-row:hover, .toc-row:focus-visible { outline: none; background: #f1dfc2; }
.toc-row:hover::before, .toc-row:focus-visible::before, .toc-row:hover + *::before { opacity: 0; }
.toc-n { font-size: 30px; line-height: 1; text-align: right; color: var(--accent); font-variant-numeric: oldstyle-nums; transition: transform .3s cubic-bezier(.3, 1.6, .5, 1); }
.toc-row:hover .toc-n { transform: translateX(-2px) rotate(-4deg); }
.toc-t { display: block; min-width: 0; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.toc-line { display: block; min-height: 1.3em; font-size: 17.5px; line-height: 1.3; font-style: italic; text-wrap: pretty; }
.toc-row.here { background: #f3e1c3; }
.toc-row.here::after { content: ''; position: absolute; top: 0; right: 16px; width: 11px; height: 26px; background: var(--terracotta); clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 78%, 0 100%); }
.toc-row.picked { background: #edd2ad; }
.toc-row:disabled { cursor: default; opacity: .4; background: transparent; }

@media (max-width: 759px) {
  .library { padding: 0 12px 28px; }
  .lib-strings { height: clamp(58px, 9vh, 80px); width: 56%; }
  .lib-banner { padding: 12px 24px 12px; }
  .lib-title { font-size: 38px; }
  .lib-sub { font-size: 16px; }
  .shelves { padding-top: 22px; width: 100%; }
  .cards { --cw: 100%; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px 14px; max-width: 380px; margin: 0 auto; }
  .bc-paper { padding: 7px 7px 13px; }
  .bc-kicker { margin-top: 9px; font-size: 9px; letter-spacing: .14em; }
  .bc-name { font-size: 27px; }
  .bc-count { margin-top: 7px; font-size: 13px; }
  .booklet { --cw: min(118px, 32vw); flex-direction: column; justify-content: flex-start; padding: 12px 10px 16px; overflow: hidden; }
  .bk-cover .bc-kicker { display: none; }
  .bk-cover .bc-name { font-size: 22px; margin-top: 6px; }
  .bk-cover { align-self: center; }
  .bk-cover .bc-count { display: none; }
  .bk-scroll { width: calc(100% - 28px); max-width: 500px; height: auto; flex: 1; min-height: 0; margin: 12px 0 0; }
  .bk-head { padding: 16px 12px 10px 18px; }
  .toc { padding: 6px 6px 14px; }
  .toc-line { font-size: 17px; }
}
@media (prefers-reduced-motion: reduce) { .book-card, .toc-n { transition: none; } }
