/* The Sorcerer's Apprentice — a storybook drawn in code. */

@font-face {
  font-family: "Fraunces";
  src: url("../fonts/fraunces-latin-full-normal.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Caveat";
  src: url("../fonts/caveat-latin-wght-normal.woff2") format("woff2");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --paper: #f4ecdd;
  --paper-2: #ece0c8;
  --paper-3: #e1d2b4;
  --ink: #221d2e;
  --ink-2: #463f52;
  --ink-3: #6a6275;
  --indigo: #2e3160;
  --water: #3f82aa;
  --amber: #e2a03b;
  --rose: #b8475f;
  --rose-ink: #9c3550;
  --sage: #6f8f63;
  --accepted: #35592f;
  --conflicted: #8a4d14;
  --undecided: #2f4c61;
  --measure: 36rem;
  --gutter: clamp(1rem, 4vw, 2.5rem);
  --display: "Fraunces", Georgia, "Times New Roman", serif;
  --text: "Fraunces", Georgia, "Times New Roman", serif;
  --hand: "Caveat", "Segoe Print", "Bradley Hand", cursive;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --masthead: 3.4rem;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }

html {
  background: var(--paper);
  /* Clip on the root too: body's overflow is otherwise moved to the viewport, and a
     transient transform (a stamp landing) could widen the mobile layout viewport. */
  overflow-x: clip;
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--masthead) + 1rem);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    radial-gradient(ellipse at 20% 0%, rgba(226, 160, 59, 0.10), transparent 55%),
    radial-gradient(ellipse at 90% 40%, rgba(46, 49, 96, 0.06), transparent 50%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='260' height='260'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .32 0 0 0 0 .25 0 0 0 0 .16 0 0 0 .075 0'/%3E%3C/filter%3E%3Crect width='260' height='260' filter='url(%23n)'/%3E%3C/svg%3E");
  font-family: var(--text);
  font-size: clamp(1.06rem, 0.98rem + 0.32vw, 1.22rem);
  line-height: 1.62;
  font-optical-sizing: auto;
  font-variation-settings: "SOFT" 60, "WONK" 0;
  text-rendering: optimizeLegibility;
  overflow-x: clip;
}

img, svg { display: block; max-width: 100%; }
.kit { position: absolute; width: 0; height: 0; overflow: hidden; }

a { color: var(--rose-ink); text-underline-offset: 0.18em; text-decoration-thickness: 1px; }
a:hover { color: var(--ink); }
:focus-visible { outline: 3px solid var(--rose-ink); outline-offset: 3px; border-radius: 4px; }

em { font-style: oblique 9deg; font-variation-settings: "SOFT" 100, "WONK" 1; }
b, strong { font-weight: 640; }

.skip {
  position: absolute; left: 1rem; top: -4rem; z-index: 50;
  background: var(--ink); color: var(--paper); padding: .6rem 1rem; border-radius: 8px;
}
.skip:focus { top: 1rem; }

/* ---------- Masthead & contents ---------- */
.masthead {
  position: fixed; inset: 0 0 auto 0; z-index: 30;
  height: var(--masthead);
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0 var(--gutter);
  background: color-mix(in srgb, var(--paper) 86%, transparent);
  -webkit-backdrop-filter: blur(8px) saturate(1.1);
  backdrop-filter: blur(8px) saturate(1.1);
  border-bottom: 1px solid color-mix(in srgb, var(--ink) 12%, transparent);
}
.wordmark {
  display: inline-flex; align-items: center; gap: .3rem;
  font-family: var(--display); font-size: 1.35rem; font-weight: 640;
  font-variation-settings: "SOFT" 100, "WONK" 1, "opsz" 72;
  letter-spacing: -0.01em; color: var(--ink); text-decoration: none;
}
.wordmark svg { width: .72em; height: .72em; fill: var(--rose); transform: translateY(-.35em); }
.contents { position: relative; }
.contents-toggle {
  display: none;
  font: inherit; font-size: .95rem; color: var(--ink);
  background: transparent; border: 1.5px solid var(--ink); border-radius: 999px;
  padding: .3rem .95rem; cursor: pointer;
}
.toc { list-style: none; margin: 0; padding: 0; display: flex; gap: .15rem; }
.toc a {
  display: inline-flex; align-items: baseline; gap: .35rem;
  padding: .35rem .6rem; border-radius: 999px; white-space: nowrap;
  color: var(--ink-2); text-decoration: none; font-size: .9rem;
}
.toc a:hover { background: color-mix(in srgb, var(--ink) 7%, transparent); color: var(--ink); }
.toc a.is-current { background: var(--ink); color: var(--paper); }
.toc-n { font-variation-settings: "SOFT" 100, "WONK" 1; font-weight: 640; }
.toc-t { display: none; }
@media (min-width: 1440px) { .toc-t { display: inline; } .toc a { padding: .35rem .7rem; } }

@media (max-width: 760px) {
  .contents-toggle { display: inline-block; }
  .toc {
    position: absolute; right: 0; top: calc(100% + .6rem);
    flex-direction: column; gap: 0; min-width: 15rem;
    background: var(--paper); border: 1.5px solid var(--ink); border-radius: 14px;
    padding: .4rem; box-shadow: 0 18px 40px -18px rgba(34, 29, 46, .45);
    display: none;
  }
  .toc.is-open { display: flex; }
  .toc a { padding: .55rem .75rem; border-radius: 10px; font-size: 1rem; }
  .toc-t { display: inline; }
  .toc-n { min-width: 2.2rem; }
}

/* ---------- Layout primitives ---------- */
main { padding-top: var(--masthead); }
.prose { max-width: var(--measure); }
.prose--center { margin-inline: auto; padding-inline: var(--gutter); box-sizing: content-box; }
.prose p { margin: 0 0 1.05em; }

.chapter, .epilogue {
  padding: clamp(3rem, 7vw, 6rem) 0 clamp(2rem, 5vw, 4rem);
}
.chapter-head { text-align: center; padding-inline: var(--gutter); margin-bottom: clamp(1.6rem, 4vw, 2.8rem); }
.numeral {
  margin: 0 0 .35rem;
  font-size: .82rem; letter-spacing: .32em; text-transform: uppercase;
  color: var(--rose-ink); font-weight: 560;
}
.numeral::before, .numeral::after { content: "—"; margin: 0 .6em; opacity: .6; letter-spacing: 0; }
h1, h2, h3 {
  font-family: var(--display);
  font-variation-settings: "SOFT" 100, "WONK" 1;
  font-weight: 620; line-height: 1.04; letter-spacing: -0.015em;
  margin: 0;
  text-wrap: balance;
}
h2 { font-size: clamp(2.3rem, 1.6rem + 3.4vw, 4.4rem); }
h3 { font-size: clamp(1.35rem, 1.15rem + .8vw, 1.8rem); }

/* drop caps */
.opening::first-letter {
  float: left;
  font-family: var(--display);
  font-variation-settings: "SOFT" 100, "WONK" 1, "opsz" 144;
  font-weight: 700;
  font-size: 4.3em; line-height: .82;
  padding: .06em .12em 0 .02em; margin: .04em .1em 0 0;
  color: var(--rose);
  background: radial-gradient(circle at 42% 50%, rgba(226, 160, 59, .32) 0 42%, transparent 64%);
  text-shadow: 1px 1px 0 rgba(34, 29, 46, .18);
}

.moral {
  margin-top: 1.8em !important;
  padding: .9rem 1.1rem .95rem;
  border: 1.5px solid color-mix(in srgb, var(--ink) 70%, transparent);
  border-radius: 4px 14px 4px 14px;
  background: color-mix(in srgb, var(--paper-2) 80%, transparent);
  font-variation-settings: "SOFT" 100, "WONK" 1;
  font-size: 1.08em;
  box-shadow: 4px 4px 0 color-mix(in srgb, var(--ink) 12%, transparent);
}
.moral span {
  display: block;
  font-size: .72rem; letter-spacing: .26em; text-transform: uppercase;
  color: var(--rose-ink); font-weight: 600; margin-bottom: .2rem;
  font-variation-settings: "SOFT" 50, "WONK" 0;
}

.divider { width: min(260px, 60vw); height: auto; margin: 0 auto; opacity: .85; }

.plate { width: 100%; height: auto; overflow: visible; }
/* Illustrations are two stacked layers: a static, filtered background painted once,
   and an unfiltered foreground on its own compositor layer for everything that moves. */
.plate-stack { display: grid; }
.plate-stack > .plate { grid-area: 1 / 1; }
.plate-fg { will-change: transform; }
.plate-frame { margin: 0; }
.plate-frame--wide { max-width: 1100px; margin: clamp(1.5rem, 4vw, 3rem) auto; padding-inline: var(--gutter); }

/* ---------- Frontispiece ---------- */
.frontispiece {
  min-height: calc(100svh - var(--masthead));
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr);
  align-items: center; gap: clamp(1rem, 4vw, 4rem);
  padding: clamp(2rem, 5vw, 4rem) var(--gutter) clamp(2rem, 4vw, 3rem);
  max-width: 1320px; margin: 0 auto;
  position: relative;
}
.frontispiece::before {
  content: ""; position: absolute; inset: clamp(.6rem, 1.6vw, 1.4rem);
  border: 1.5px solid color-mix(in srgb, var(--ink) 55%, transparent);
  outline: 1px solid color-mix(in srgb, var(--ink) 25%, transparent);
  outline-offset: -8px;
  border-radius: 6px; pointer-events: none;
}
.kicker {
  margin: 0 0 1.2rem;
  font-size: .85rem; letter-spacing: .22em; text-transform: uppercase; color: var(--rose-ink); font-weight: 560;
}
.frontispiece h1 {
  font-size: clamp(3.1rem, 1.6rem + 6vw, 7.2rem);
  font-variation-settings: "SOFT" 100, "WONK" 1, "opsz" 144;
  font-weight: 700; line-height: .92; letter-spacing: -0.03em;
}
.t-the { display: block; font-size: .42em; font-weight: 500; letter-spacing: .02em; color: var(--ink-2); margin-bottom: .1em; }
.front-lede { font-size: clamp(1.12rem, 1rem + .5vw, 1.38rem); max-width: 30rem; margin: 1.6rem 0 2rem; color: var(--ink-2); }
.turn {
  display: inline-flex; gap: .5rem; align-items: center;
  font-family: var(--hand); font-size: 1.6rem; font-weight: 600; color: var(--ink); text-decoration: none;
  border-bottom: 2px solid var(--rose); padding-bottom: .1rem;
}
.turn span { display: inline-block; animation: nudge 2.4s ease-in-out infinite; }
.front-plate { margin: 0; }

@media (max-width: 860px) {
  .frontispiece { grid-template-columns: 1fr; text-align: center; min-height: auto; padding-top: 2.6rem; }
  .front-lede { margin-inline: auto; }
  .front-plate { max-width: 480px; margin: 0 auto; order: -1; }
}

/* ---------- Split chapters ---------- */
.split {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
  gap: clamp(1.5rem, 5vw, 5rem); align-items: center;
  max-width: 1180px; margin: 0 auto; padding-inline: var(--gutter);
}
@media (max-width: 860px) {
  .split { grid-template-columns: 1fr; }
  .split .plate-frame { order: -1; max-width: 520px; margin: 0 auto; width: 100%; }
}

/* ---------- The flood ---------- */
.flood {
  display: grid; grid-template-columns: minmax(0, .9fr) minmax(0, 1.1fr);
  gap: clamp(1.5rem, 4vw, 4rem);
  max-width: 1240px; margin: 0 auto; padding-inline: var(--gutter);
}
.flood-scene {
  grid-column: 2; grid-row: 1;
  position: sticky; top: calc(var(--masthead) + 5vh);
  height: min(78vh, 640px);
  border-radius: 18px; overflow: hidden;
  border: 2px solid var(--ink);
  box-shadow: 8px 8px 0 color-mix(in srgb, var(--ink) 14%, transparent);
  background: #ede2cb;
}
.flood-scene .plate { position: absolute; inset: 0; width: 100%; height: 100%; }
.flood-text { grid-column: 1; grid-row: 1; padding: 12vh 0 30vh; }
.flood-text > * { margin-bottom: 38vh !important; }
.flood-text > .moral { margin-bottom: 0 !important; }
.substitutions p { margin: 0 0 .5rem; }
.substitutions ul { margin: 0; padding-left: 1.2rem; }
.substitutions li { margin: .2rem 0; }
.substitutions li::marker { color: var(--rose); }

.flood-count {
  position: absolute; left: .8rem; top: .8rem; margin: 0;
  display: flex; flex-wrap: wrap; gap: .35rem;
  font-size: .78rem; letter-spacing: .04em;
}
.flood-count span {
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  border: 1.5px solid var(--ink); border-radius: 999px; padding: .15rem .6rem;
}
.flood-count b { font-variant-numeric: tabular-nums; font-weight: 700; }
.flood-count span:last-child { border-color: var(--rose-ink); color: var(--rose-ink); }

.tags { position: absolute; inset: 0; pointer-events: none; }
.float-tag {
  position: absolute; left: var(--x); top: var(--y);
  font-family: var(--hand); font-size: clamp(1.05rem, .8rem + .7vw, 1.45rem); font-weight: 600; line-height: 1;
  padding: .3rem .6rem .35rem; border-radius: 3px;
  background: #fbf5e7; border: 1.5px solid var(--ink);
  box-shadow: 3px 3px 0 rgba(34, 29, 46, .18);
  transform: translateY(1.2rem) rotate(var(--r)) scale(.9);
  opacity: 0;
  transition: opacity .6s ease, transform .9s cubic-bezier(.2, .8, .2, 1.2);
  white-space: nowrap;
}
.float-tag i { font-style: normal; color: var(--rose-ink); }
.float-tag.is-on { opacity: 1; transform: translateY(0) rotate(var(--r)) scale(1); }
.scene.is-playing .float-tag.is-on { animation: bob 3.2s ease-in-out infinite; }
.float-tag:nth-child(2n).is-on { animation-delay: -1.3s; }

@media (max-width: 860px) {
  .flood { display: block; }
  .flood-scene {
    top: calc(var(--masthead) + .5rem);
    height: 46svh; z-index: 2;
    margin-bottom: 1rem;
  }
  .flood-text { position: relative; z-index: 1; padding: 4vh 0 10vh; }
  .flood-text > * { margin-bottom: 42vh !important; }
  .float-tag { font-size: 1rem; }
  .flood-count { font-size: .7rem; left: .5rem; top: .5rem; }
}

/* ---------- Triptych ---------- */
.triptych {
  list-style: none; margin: clamp(1rem, 3vw, 2rem) auto clamp(1.5rem, 4vw, 3rem);
  padding: 0 var(--gutter);
  max-width: 1100px;
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: clamp(1rem, 3vw, 2.2rem);
}
.trip {
  background: color-mix(in srgb, #fbf6ea 88%, transparent);
  border: 1.5px solid var(--ink); border-radius: 18px 6px 18px 6px;
  padding: 1.2rem 1.3rem 1.3rem;
  box-shadow: 6px 6px 0 color-mix(in srgb, var(--ink) 12%, transparent);
}
.trip-art { width: 100%; max-width: 200px; height: auto; margin: 0 auto .6rem; }
.trip h3 { margin-bottom: .5rem; }
.trip p { margin: 0 0 .7rem; }
.gloss { font-size: .88rem; color: var(--ink-3); border-top: 1px dashed color-mix(in srgb, var(--ink) 35%, transparent); padding-top: .55rem; margin: 0 !important; }
@media (max-width: 860px) { .triptych { grid-template-columns: 1fr; max-width: 520px; } }

/* ---------- Emissaries ---------- */
.emissaries {
  list-style: none; padding: 0 var(--gutter); margin: 1.5rem auto 2.5rem;
  max-width: 1100px;
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: clamp(1rem, 3vw, 2rem);
  align-items: end;
}
.emissary { display: grid; grid-template-columns: 1fr; justify-items: center; }
.emissary-art { width: 120px; height: auto; }
.slip {
  position: relative;
  font-family: var(--hand); font-size: 1.32rem; line-height: 1.15;
  background: #fbf6e8;
  border: 1.5px solid var(--ink); border-radius: 2px;
  padding: 1.1rem 1rem .8rem;
  margin-top: -.4rem; width: 100%; max-width: 20rem;
  box-shadow: 4px 5px 0 rgba(34, 29, 46, .16);
  transform: rotate(-1.4deg);
}
.emissary:nth-child(2) .slip { transform: rotate(1.2deg); }
.emissary:nth-child(3) .slip { transform: rotate(-.6deg); }
.slip::before {
  content: ""; position: absolute; top: -9px; left: 50%; width: 16px; height: 16px; margin-left: -8px;
  border-radius: 50%; background: var(--rose); border: 1.5px solid var(--ink);
  box-shadow: inset -3px -3px 0 rgba(0, 0, 0, .2);
}
.slip p { margin: 0 0 .3rem; }
.slip b { font-family: var(--text); font-size: .7rem; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-3); font-weight: 600; margin-right: .3rem; }
.slip-status { margin-top: .55rem !important; padding-top: .45rem; border-top: 1px dashed color-mix(in srgb, var(--ink) 40%, transparent); font-weight: 700; }
.slip-status.is-waiting { color: #7a5410; }
.slip-status.is-sealed { color: var(--accepted); }
.slip-status.is-returned { color: var(--rose-ink); }
@media (max-width: 860px) {
  .emissaries { grid-template-columns: 1fr; max-width: 420px; gap: 2.2rem; }
}

/* ---------- The workshop / spell ---------- */
.motto {
  font-family: var(--display); text-align: center;
  font-size: clamp(1.4rem, 1.1rem + 1.2vw, 2rem); line-height: 1.2;
  font-variation-settings: "SOFT" 100, "WONK" 1; font-weight: 620;
  margin: 1.6rem 0 0 !important;
  color: var(--indigo);
}
.motto::before, .motto::after { content: "✦"; color: var(--rose); font-size: .6em; vertical-align: .35em; margin: 0 .55em; }

.spell {
  max-width: 1180px; margin: clamp(2rem, 5vw, 3.5rem) auto; padding-inline: var(--gutter);
  display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(0, 1fr); gap: clamp(1rem, 3vw, 2rem);
  align-items: start;
}
.spell-desk { contain: paint; }
.spell-desk, .ledger {
  background: #fbf6ea;
  border: 2px solid var(--ink); border-radius: 20px;
  padding: clamp(1.1rem, 3vw, 2rem);
  box-shadow: 8px 8px 0 color-mix(in srgb, var(--ink) 14%, transparent);
}
.spell-kicker { margin: 0 0 .2rem; font-family: var(--hand); font-size: 1.45rem; color: var(--rose-ink); font-weight: 700; }
.spell-desk h3 { font-size: clamp(1.8rem, 1.4rem + 1.4vw, 2.6rem); }
.spell-lede { margin: .5rem 0 1.2rem; color: var(--ink-2); }
.spell-form label { display: block; font-size: .8rem; letter-spacing: .14em; text-transform: uppercase; font-weight: 600; color: var(--ink-3); margin-bottom: .45rem; }
.spell-row { display: flex; gap: .6rem; flex-wrap: wrap; }
.spell-row input {
  flex: 1 1 16rem; min-width: 0;
  font: inherit; font-size: 1.08rem; color: var(--ink);
  background: var(--paper); border: 1.5px solid var(--ink); border-radius: 12px;
  padding: .7rem .9rem;
}
.spell-row input::placeholder { color: #8a8190; }
.spell-help { margin: .9rem 0 .5rem; font-size: .9rem; color: var(--ink-3); }
.chips { display: flex; flex-wrap: wrap; gap: .45rem; }
.chip {
  font: inherit; font-size: .9rem; color: var(--ink);
  background: transparent; border: 1.5px dashed color-mix(in srgb, var(--ink) 60%, transparent);
  border-radius: 999px; padding: .32rem .8rem; cursor: pointer;
}
.chip:hover { border-style: solid; background: color-mix(in srgb, var(--amber) 16%, transparent); }

.btn {
  font: inherit; font-size: 1rem; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .7rem 1.15rem; border-radius: 12px; cursor: pointer;
  border: 1.5px solid var(--ink);
  transition: transform .15s ease, background-color .2s ease, color .2s ease, box-shadow .15s ease;
}
.btn:active { transform: translateY(1px); }
.btn--ink { background: var(--ink); color: var(--paper); box-shadow: 3px 3px 0 color-mix(in srgb, var(--rose) 70%, transparent); }
.btn--ink:hover { background: var(--indigo); }
.btn--seal { background: var(--rose-ink); color: #fff8ee; border-color: var(--ink); box-shadow: 3px 3px 0 color-mix(in srgb, var(--ink) 30%, transparent); }
.btn--seal:hover { background: #7f2840; }
.btn--ghost { background: transparent; color: var(--ink); }
.btn--ghost:hover { background: color-mix(in srgb, var(--ink) 7%, transparent); }
.btn[disabled] { opacity: .45; cursor: not-allowed; }

.spell-stage { margin-top: 1.4rem; }
.spell-stage:empty { display: none; }
.honest { margin: 1.2rem 0 0; font-size: .84rem; color: var(--ink-3); border-left: 3px solid var(--amber); padding-left: .7rem; }

.arrival { display: flex; align-items: center; gap: .8rem; margin-bottom: .6rem; color: var(--ink-2); font-size: .95rem; }
.arrival svg { width: 44px; height: 44px; flex: none; }
.arrival.is-flying svg { animation: fly-in .9s cubic-bezier(.2, .8, .2, 1) both; }

.scroll {
  position: relative;
  background: linear-gradient(180deg, #fbf3df, #f6ebd2);
  border: 1.5px solid var(--ink);
  border-radius: 6px;
  padding: 1.5rem clamp(1rem, 3vw, 1.6rem) 1.3rem;
  margin: 1.2rem 0 .4rem;
  box-shadow: inset 0 0 40px rgba(163, 120, 60, .12);
  transform-origin: top center;
}
.scroll::before, .scroll::after {
  content: ""; position: absolute; left: -10px; right: -10px; height: 18px;
  background: linear-gradient(180deg, #e9d6ae, #d9bf8c 45%, #efe0bd 55%, #d2b784);
  border: 1.5px solid var(--ink); border-radius: 999px;
}
.scroll::before { top: -12px; }
.scroll::after { bottom: -12px; }
.scroll.is-unrolling { animation: unroll .7s cubic-bezier(.2, .8, .2, 1) both; }
.scroll-head { display: flex; justify-content: space-between; gap: 1rem; align-items: baseline; flex-wrap: wrap; }
.scroll h4 {
  margin: 0; font-family: var(--display); font-size: 1.35rem; font-weight: 640;
  font-variation-settings: "SOFT" 100, "WONK" 1;
}
.scroll-state { font-size: .72rem; letter-spacing: .18em; text-transform: uppercase; font-weight: 700; color: #7a5410; }
.scroll-meta { margin: .4rem 0 .8rem; font-size: .86rem; color: var(--ink-3); }
.scroll-words { margin: 0 0 1rem; font-family: var(--hand); font-size: 1.45rem; line-height: 1.2; color: var(--indigo); }
.scroll-words span { display: block; font-family: var(--text); font-size: .7rem; letter-spacing: .16em; text-transform: uppercase; color: var(--ink-3); font-weight: 600; margin-bottom: .15rem; }
.scroll-sec { margin: 0 0 .85rem; }
.scroll-sec h5 { margin: 0 0 .3rem; font-size: .72rem; letter-spacing: .16em; text-transform: uppercase; font-weight: 700; color: var(--rose-ink); }
.scroll-sec ul { margin: 0; padding-left: 1.1rem; }
.scroll-sec li { margin: .15rem 0; font-size: .98rem; }
.scroll-sec li::marker { color: var(--rose); }
/* "It would create" rows: a small tag in its own column, then what it is. */
.scroll-sec ul.kinds { list-style: none; padding-left: 0; }
.scroll-sec ul.kinds li { display: grid; grid-template-columns: 5.2rem minmax(0, 1fr); column-gap: .7rem; align-items: baseline; margin: .3rem 0; }
.kind {
  justify-self: start; display: inline-block; line-height: 1.5;
  padding: .05rem .45rem .08rem; border: 1px solid color-mix(in srgb, var(--ink) 35%, transparent); border-radius: 5px;
  background: color-mix(in srgb, var(--paper) 70%, transparent);
  font-size: .62rem; letter-spacing: .12em; text-transform: uppercase; font-weight: 700; color: var(--ink-3);
}
.scroll-seal {
  display: flex; align-items: center; gap: .8rem; margin-top: 1rem; padding-top: .9rem;
  border-top: 1px dashed color-mix(in srgb, var(--ink) 40%, transparent);
  font-size: .86rem; color: var(--ink-2);
}
.seal-text { flex: 1 1 auto; min-width: 0; margin: 0; }
.hash { font-family: var(--mono); font-size: .82rem; color: var(--rose-ink); word-break: break-all; }
.scroll-actions { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: 1.1rem; }
.return-note { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .8rem; width: 100%; }
.return-note label { width: 100%; font-size: .85rem; color: var(--ink-3); }
.return-note input { flex: 1 1 14rem; min-width: 0; font: inherit; font-size: 1rem; padding: .55rem .7rem; border: 1.5px solid var(--ink); border-radius: 10px; background: var(--paper); color: var(--ink); }
/* The stamp lands at the lower right, in the seal row: it may cross the dashed rule,
   but it takes its own space, so it never covers the title or any text. */
.stamp {
  flex: none; position: relative; margin: -1.3rem 0 -.5rem auto;
  width: 84px; height: 84px; pointer-events: none;
  animation: stamp .45s cubic-bezier(.2, .9, .3, 1.4) both;
}
.stamp--returned {
  width: auto; height: auto; margin: -.9rem .1rem -.3rem auto; padding: .3rem .65rem;
  font-family: var(--display); font-weight: 800; letter-spacing: .14em; font-size: 1rem; line-height: 1.2;
  color: var(--rose-ink); border: 3px solid var(--rose-ink); border-radius: 8px;
  transform: rotate(-8deg); background: rgba(251, 243, 223, .7); white-space: nowrap;
}
.outcome { margin: 1rem 0 0; padding: .8rem 1rem; border-radius: 12px; background: color-mix(in srgb, var(--sage) 16%, transparent); border: 1.5px solid color-mix(in srgb, var(--sage) 70%, var(--ink)); }
.outcome.is-returned { background: color-mix(in srgb, var(--rose) 10%, transparent); border-color: color-mix(in srgb, var(--rose) 70%, var(--ink)); }
.again { margin-top: .8rem; }

.ledger h3 { font-size: clamp(1.4rem, 1.2rem + .8vw, 1.9rem); }
.ledger-note { font-size: .9rem; color: var(--ink-3); margin: .5rem 0 1rem; }
.ledger-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .6rem; }
.ledger-empty { font-family: var(--hand); font-size: 1.3rem; color: var(--ink-3); padding: .8rem; border: 1.5px dashed color-mix(in srgb, var(--ink) 30%, transparent); border-radius: 12px; }
.entry {
  border: 1.5px solid var(--ink); border-radius: 12px; padding: .7rem .8rem;
  background: var(--paper);
  animation: pop .5s cubic-bezier(.2, .9, .3, 1.3) both;
}
.entry-top { display: flex; justify-content: space-between; gap: .6rem; align-items: baseline; }
.entry-n { font-family: var(--display); font-weight: 700; font-variation-settings: "SOFT" 100, "WONK" 1; }
.entry-verdict { font-size: .72rem; letter-spacing: .14em; text-transform: uppercase; font-weight: 700; }
.entry-verdict.is-sealed { color: var(--accepted); }
.entry-verdict.is-returned { color: var(--rose-ink); }
.entry-words { margin: .25rem 0 .35rem; font-size: .95rem; }
.entry-note { margin: 0 0 .35rem; font-size: .88rem; color: var(--ink-3); }
.entry dl { margin: 0; display: grid; grid-template-columns: auto minmax(0, 1fr); gap: .1rem .6rem; font-size: .78rem; }
.entry dt { color: var(--ink-3); }
.entry dd { margin: 0; }
.entry.is-broken { border-color: var(--rose-ink); background: color-mix(in srgb, var(--rose) 8%, var(--paper)); }
.entry.is-ok { border-color: var(--accepted); }
.ledger-tools { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1rem; }
.ledger-tools .btn { font-size: .9rem; padding: .5rem .8rem; }
.ledger-result { margin: .8rem 0 0; font-size: .95rem; min-height: 1.4em; }
.ledger-result.is-ok { color: var(--accepted); }
.ledger-result.is-bad { color: var(--rose-ink); }

@media (max-width: 960px) {
  .spell { grid-template-columns: 1fr; max-width: 680px; }
}

/* ---------- Library ---------- */
.plate-frame figcaption { max-width: 60rem; margin: 1.2rem auto 0; }
.caption-lede { text-align: center; color: var(--ink-2); margin: 0 auto 1rem; max-width: 42rem; font-size: 1rem; }
.verdicts { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; font-size: .95rem; }
.verdicts li { padding: .9rem 1rem; border-radius: 14px; background: color-mix(in srgb, #fbf6ea 85%, transparent); border: 1.5px solid color-mix(in srgb, var(--ink) 45%, transparent); }
.v { display: inline-block; font-weight: 700; font-size: .8rem; letter-spacing: .1em; text-transform: uppercase; padding: .15rem .55rem; border-radius: 6px; margin-bottom: .35rem; border: 1.5px solid currentColor; }
.v--accepted { color: var(--accepted); }
.v--conflicted { color: var(--conflicted); }
.v--undecided { color: var(--undecided); }
@media (max-width: 860px) { .verdicts { grid-template-columns: 1fr; } }
.pull { margin: 1.6rem 0; padding: 0; text-align: center; }
.pull p {
  font-family: var(--display); font-size: clamp(1.5rem, 1.2rem + 1.4vw, 2.3rem); line-height: 1.15; margin: 0;
  font-variation-settings: "SOFT" 100, "WONK" 1; font-weight: 600; color: var(--indigo);
}
.pull p::before { content: "“"; color: var(--rose); }
.pull p::after { content: "”"; color: var(--rose); }

/* ---------- Foundation ---------- */
.foundation {
  max-width: 1080px; margin: clamp(1.5rem, 4vw, 2.5rem) auto 1.5rem; padding-inline: var(--gutter);
  display: grid; justify-items: center; gap: 1rem;
}
.keystone { display: grid; justify-items: center; text-align: center; }
.keystone svg { width: 92px; height: 92px; }
.keystone p { margin: -.2rem 0 0; font-family: var(--display); font-weight: 640; font-variation-settings: "SOFT" 100, "WONK" 1; line-height: 1.1; }
.keystone span { font-family: var(--hand); font-size: 1.25rem; font-weight: 600; color: var(--rose-ink); }
.wall {
  width: 100%;
  display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 8px;
  padding: 12px; border-radius: 12px;
  background: #6c604f;
  border: 2px solid var(--ink);
  box-shadow: inset 0 0 0 4px rgba(0, 0, 0, .12), 8px 8px 0 color-mix(in srgb, var(--ink) 14%, transparent);
}
.stone {
  grid-column: span 2;
  font: inherit; font-family: var(--display); font-weight: 650;
  font-variation-settings: "SOFT" 20, "WONK" 0; font-size: clamp(.8rem, .7rem + .4vw, 1rem); line-height: 1.12;
  color: #3b3226;
  text-shadow: 0 1px 0 rgba(255, 255, 255, .45), 0 -1px 0 rgba(0, 0, 0, .25);
  min-height: 5.2rem; padding: .7rem .6rem;
  background:
    radial-gradient(ellipse at 30% 20%, rgba(255, 255, 255, .28), transparent 60%),
    linear-gradient(160deg, #d8ccb5, #bfb194 60%, #a99b7f);
  border: 1.5px solid #3b3226; border-radius: 10px 14px 9px 13px;
  cursor: pointer;
  transition: transform .18s ease, background-color .2s ease, box-shadow .2s ease;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, .12);
}
.stone:nth-child(5n+1) { border-radius: 14px 9px 12px 8px; }
.stone:nth-child(3n+2) { border-radius: 8px 13px 10px 15px; }
/* An uneven course of stones: 2+3+2+2+3 and 3+2+2+2+3 twelfths. */
.stone:nth-child(2), .stone:nth-child(5), .stone:nth-child(6), .stone:nth-child(10) { grid-column: span 3; }
.stone:hover { transform: translateY(-2px); }
.stone[aria-pressed="true"] {
  background: radial-gradient(ellipse at 50% 40%, rgba(255, 233, 170, .9), rgba(226, 160, 59, .55) 70%), #e0c28a;
  color: #2a1d10;
  box-shadow: 0 0 0 3px var(--amber), 0 0 22px rgba(226, 160, 59, .6);
}
.stone-caption {
  min-height: 3.6rem; max-width: 44rem; margin: .6rem auto 0; text-align: center; line-height: 1.45;
  font-size: clamp(1.05rem, .95rem + .4vw, 1.25rem);
}
.stone-caption b { display: block; font-family: var(--display); font-variation-settings: "SOFT" 100, "WONK" 1; font-size: 1.2em; margin-bottom: .2rem; }
.stone-caption-hint { color: var(--ink-3); font-size: .95rem; }
@media (max-width: 860px) {
  .wall { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stone, .stone:nth-child(n) { grid-column: auto; min-height: 4.2rem; }
}
.all-ten { max-width: var(--measure); margin: 0 auto 1.5rem; padding: 0 var(--gutter); box-sizing: content-box; }
.all-ten summary { cursor: pointer; font-weight: 600; color: var(--rose-ink); }
.all-ten ol { padding-left: 1.3rem; }
.all-ten li { margin: .45rem 0; }
.fine { font-size: .85rem; color: var(--ink-3); }
.status-note { font-size: .95rem; color: var(--ink-2); border: 1.5px dashed color-mix(in srgb, var(--ink) 40%, transparent); border-radius: 12px; padding: .85rem 1rem; }

/* ---------- Epilogue ---------- */
.rules { max-width: 860px; margin: 2rem auto 0; padding-inline: var(--gutter); }
.rules-title { text-align: center; margin-bottom: 1.2rem; font-size: clamp(1.3rem, 1.1rem + .8vw, 1.7rem); }
.rules-list { list-style: none; counter-reset: rule; margin: 0; padding: 0; display: grid; gap: .8rem; }
.rules-list li {
  counter-increment: rule;
  position: relative; padding: 1rem 1.1rem 1rem 3.6rem;
  background: #fbf6ea; border: 1.5px solid var(--ink); border-radius: 14px;
}
.rules-list li::before {
  content: counter(rule, upper-roman);
  position: absolute; left: .9rem; top: .9rem; width: 2rem; text-align: center;
  font-family: var(--display); font-weight: 700; font-variation-settings: "SOFT" 100, "WONK" 1;
  color: var(--rose);
}
.rules-list p { margin: 0; }
.stand { margin-top: .35rem !important; font-size: .86rem; color: var(--ink-3); }
.stand::before { content: "Where it stands: "; font-weight: 600; color: var(--ink-2); }

.cta {
  max-width: 980px; margin: clamp(2.5rem, 6vw, 4rem) auto 0; padding-inline: var(--gutter);
  display: grid; grid-template-columns: minmax(0, .8fr) minmax(0, 1.2fr); gap: clamp(1rem, 4vw, 3rem); align-items: center;
}
.cta-art { margin: 0; }
.cta-text h3 { font-size: clamp(1.8rem, 1.4rem + 1.6vw, 2.8rem); margin-bottom: .6rem; }
.cta-text p { margin: 0 0 1.1rem; }
.cta-note { margin-top: 1rem !important; padding: .85rem 1rem; border-radius: 12px; background: color-mix(in srgb, var(--amber) 16%, transparent); border: 1.5px solid color-mix(in srgb, var(--amber) 70%, var(--ink)); }
@media (max-width: 760px) { .cta { grid-template-columns: 1fr; text-align: center; } .cta-art { max-width: 320px; margin: 0 auto; } }

.colophon {
  text-align: center; padding: 3rem var(--gutter) 3.5rem; margin-top: 3rem;
  border-top: 1.5px solid color-mix(in srgb, var(--ink) 18%, transparent);
  color: var(--ink-2); font-size: .95rem;
}
.colophon p { margin: .3rem 0; }
.wordmark--foot { justify-content: center; font-size: 1.6rem; display: flex; }

/* ---------- Films ---------- */
.page-nav { display: flex; gap: .3rem; }
.page-nav a, .toc-film a {
  padding: .35rem .85rem; border-radius: 999px; color: var(--ink-2); text-decoration: none; font-size: .95rem;
}
.page-nav a:hover { background: color-mix(in srgb, var(--ink) 7%, transparent); color: var(--ink); }
.page-nav a[aria-current="page"] { background: var(--ink); color: var(--paper); }
.toc .toc-film a { border: 1.5px solid var(--rose-ink); color: var(--rose-ink); margin-left: .35rem; font-weight: 600; }
.toc .toc-film a:hover { background: var(--rose-ink); color: var(--paper); }
@media (max-width: 760px) { .toc .toc-film a { margin: .3rem 0 0; justify-content: center; } }
.watch-film {
  display: block; margin-top: 1rem; font-size: 1rem; color: var(--ink-2);
}
.watch-film a { color: var(--rose-ink); font-weight: 600; }
.film-hero { text-align: center; max-width: 52rem; margin: 0 auto; padding: clamp(2.5rem, 6vw, 4.5rem) var(--gutter) 0; }
.film-hero h1 {
  font-size: clamp(2.6rem, 1.5rem + 4.6vw, 5.4rem); font-weight: 700;
  font-variation-settings: "SOFT" 100, "WONK" 1, "opsz" 144; letter-spacing: -.025em;
}
.film-lede { font-size: clamp(1.1rem, 1rem + .4vw, 1.32rem); color: var(--ink-2); max-width: 40rem; margin: 1.2rem auto 0; }
.film-frame { max-width: 1100px; margin: clamp(1.5rem, 4vw, 2.5rem) auto 0; padding: 0 var(--gutter); }
.film-video, .loop-video {
  display: block; width: 100%; height: auto; aspect-ratio: 16 / 9;
  border-radius: 16px; border: 2px solid var(--ink); background: #2e3160;
  box-shadow: 8px 8px 0 color-mix(in srgb, var(--ink) 14%, transparent);
}
.film-frame figcaption { text-align: center; max-width: 44rem; margin: 1.1rem auto 0; color: var(--ink-2); font-size: .98rem; }
.film-frame figcaption p { margin: .3rem 0; }
.film-section { max-width: 46rem; margin: clamp(2.5rem, 6vw, 4rem) auto 0; padding: 0 var(--gutter); box-sizing: content-box; }
.film-section h2 { font-size: clamp(1.8rem, 1.3rem + 2vw, 2.8rem); margin-bottom: .9rem; }
.transcript { list-style: none; padding: 0; margin: 0; display: grid; gap: .5rem; }
.transcript li { display: grid; grid-template-columns: 3.4rem minmax(0, 1fr); gap: .6rem; }
.transcript .at { font-family: var(--mono); font-size: .85rem; color: var(--rose-ink); padding-top: .25rem; }
.loop-frame { position: relative; margin: 1.2rem 0 0; }
.video-toggle {
  position: absolute; right: .9rem; bottom: .9rem;
  font: inherit; font-size: .88rem; font-weight: 600; color: var(--paper);
  background: color-mix(in srgb, var(--ink) 82%, transparent); border: 1.5px solid var(--paper);
  border-radius: 999px; padding: .3rem .85rem; cursor: pointer;
}
.made { padding-left: 1.3rem; }
.made li { margin: .7rem 0; }
.made code, .witness code { font-family: var(--mono); font-size: .86em; color: var(--rose-ink); }
.witness-hash { font-size: .95rem; color: var(--ink-2); overflow-wrap: anywhere; }
.witness-table {
  display: block; overflow-x: auto; width: 100%; border-collapse: collapse; font-size: .86rem; margin-top: .8rem;
}
.witness-table th, .witness-table td {
  text-align: left; white-space: nowrap; padding: .45rem .7rem .45rem 0;
  border-bottom: 1px solid color-mix(in srgb, var(--ink) 18%, transparent);
}
.witness-table thead th { font-size: .72rem; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3); }
.film-back { text-align: center; margin: clamp(2.5rem, 6vw, 4rem) 0 0; }

.interlude {
  max-width: 1120px; margin: 0 auto; padding: clamp(2.5rem, 6vw, 4.5rem) var(--gutter);
  display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: clamp(1.2rem, 4vw, 3rem); align-items: center;
}
.interlude .loop-frame { margin: 0; }
.interlude h2 { font-size: clamp(2rem, 1.4rem + 2.2vw, 3.2rem); margin: .2rem 0 .8rem; }
.interlude p { margin: 0 0 1rem; }
.interlude .numeral { text-align: left; }
.interlude .numeral::before { content: none; }
.interlude .numeral::after { content: none; }
@media (max-width: 860px) { .interlude { grid-template-columns: 1fr; } }

/* ---------- Motion ---------- */
.reveal { opacity: 0; transform: translateY(18px); transition: opacity .7s ease, transform .8s cubic-bezier(.2, .8, .2, 1); }
.reveal.is-in { opacity: 1; transform: none; }
.no-js .reveal { opacity: 1; transform: none; }
.no-js .draw { stroke-dashoffset: 0; }

.hop { transform-box: fill-box; transform-origin: 50% 100%; animation: hop 1.05s ease-in-out infinite; animation-play-state: paused; }
.hop.slow { animation-duration: 2.6s; }
.hop.h2 { animation-delay: -.8s; }
.hop.h3 { animation-delay: -1.6s; }
.hop.h-ghost { animation-delay: -.3s; }
.twinkle { transform-box: fill-box; transform-origin: center; animation: twinkle 2.8s ease-in-out infinite; animation-play-state: paused; }
.twinkle.t2 { animation-delay: -.9s; } .twinkle.t3 { animation-delay: -1.7s; } .twinkle.t4 { animation-delay: -2.3s; }
.flame { transform-box: fill-box; transform-origin: 50% 100%; animation: flicker 1.6s ease-in-out infinite; animation-play-state: paused; }
.candle-glow { animation: glow 3.2s ease-in-out infinite; animation-play-state: paused; transform-box: fill-box; transform-origin: center; }
.drip { animation: drip 1.9s ease-in infinite; animation-play-state: paused; }
.drip.d2 { animation-delay: -.7s; } .drip.d3 { animation-delay: -1.3s; }
.cone { animation: cone 5s ease-in-out infinite; animation-play-state: paused; }
.cone.c2 { animation-delay: -1.6s; } .cone.c3 { animation-delay: -3.2s; }
.draw { stroke-dasharray: 1; stroke-dashoffset: 1; }
.scene.is-playing .hop, .scene.is-playing .twinkle, .scene.is-playing .flame,
.scene.is-playing .candle-glow, .scene.is-playing .drip, .scene.is-playing .cone,
.is-playing .hop, .is-playing .twinkle { animation-play-state: running; }
.is-in .draw, .scene.is-playing .draw { animation: draw 1.8s ease forwards .3s; }

@keyframes hop { 0%, 100% { transform: translateY(0) rotate(-4deg); } 50% { transform: translateY(-14px) rotate(3.5deg); } }
@keyframes twinkle { 0%, 100% { opacity: .35; transform: scale(.7) rotate(0deg); } 50% { opacity: 1; transform: scale(1.1) rotate(20deg); } }
@keyframes flicker { 0%, 100% { transform: scale(1, 1) rotate(-2deg); } 30% { transform: scale(.94, 1.08) rotate(2deg); } 60% { transform: scale(1.04, .95) rotate(-1deg); } }
@keyframes glow { 0%, 100% { opacity: .85; transform: scale(1); } 50% { opacity: 1; transform: scale(1.06); } }
@keyframes drip { 0% { transform: translateY(-6px); opacity: 0; } 20% { opacity: 1; } 100% { transform: translateY(70px); opacity: 0; } }
@keyframes cone { 0%, 100% { opacity: .8; } 50% { opacity: 1; } }
@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes bob { 0%, 100% { translate: 0 0; } 50% { translate: 0 -6px; } }
@keyframes nudge { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(5px); } }
@keyframes unroll { from { clip-path: inset(0 0 100% 0); opacity: .2; } to { clip-path: inset(0 0 -20px 0); opacity: 1; } }
@keyframes stamp { from { transform: scale(1.5) rotate(-14deg); opacity: 0; } to { transform: scale(1) rotate(-8deg); opacity: 1; } }
@keyframes pop { from { transform: scale(.94); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fly-in { from { transform: translate(-60px, -30px) rotate(-30deg); opacity: 0; } to { transform: none; opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
  .hop, .twinkle, .flame, .candle-glow, .drip, .cone, .float-tag.is-on { animation: none !important; }
  .reveal { opacity: 1; transform: none; }
  .draw { stroke-dashoffset: 0; }
  .turn span { animation: none; }
}
