/* ==========================================================================
   CODEX CDIV — Illuminated Medieval Manuscript (Pure HTML + CSS)
   No JavaScript, no canvas, no external font or image files.
   ========================================================================== */

:root {
  --vellum-base: #f2e4c4;
  --vellum-edge: #dec79b;
  --vellum-shadow: #c2a470;
  --ink-dark: #231812;
  --ink-soft: #4e3b2c;
  --rubric: #9e2a2b;
  --rubric-bright: #b83330;
  --lapis: #1e436d;
  --gold: #d4a438;
  --gold-light: #f6de8c;
  --emerald: #3a6b4c;

  --font-serif: "Palatino Linotype", "Book Antiqua", Palatino, "Hoefler Text", Georgia, serif;
  --font-mono: "SF Mono", Menlo, Consolas, "Courier New", monospace;
}

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

html {
  scroll-behavior: smooth;
  font-size: 16px;
  overflow-x: clip;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-serif);
  color: var(--ink-dark);
  background-color: #202833;
  overflow-x: clip;
  line-height: 1.65;
}

svg {
  max-width: 100%;
  height: auto;
}

.svg-defs {
  position: absolute;
  width: 0;
  height: 0;
  pointer-events: none;
}

.sr-toggle,
.sr-dropcap {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ==========================================================================
   1. SCROLL-DRIVEN SCRIPTORIUM LIGHTING (Matins -> Sext -> Vespers -> Compline)
   ========================================================================== */

.room-backdrop,
.room-sunbeam,
.room-nightfall,
.candle-ambient-glow {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

.room-backdrop {
  z-index: 0;
  background: radial-gradient(circle at 30% 20%, #44586c 0%, #24303e 55%, #161c24 100%);
  animation: backdrop-shift linear both;
  animation-timeline: scroll(root block);
}

.room-sunbeam {
  inset: -24%;
  z-index: 1;
  background: linear-gradient(
    125deg,
    rgba(210, 232, 255, 0.24) 0%,
    rgba(255, 236, 195, 0.1) 36%,
    transparent 64%
  );
  animation: sunbeam-shift linear both;
  animation-timeline: scroll(root block);
}

.room-nightfall {
  z-index: 4;
  background: radial-gradient(
    ellipse at 54% 48%,
    rgba(12, 8, 6, 0.05) 18%,
    rgba(10, 7, 5, 0.72) 72%,
    rgba(6, 4, 3, 0.92) 100%
  );
  opacity: 0;
  animation: nightfall-creep linear both;
  animation-timeline: scroll(root block);
}

.candle-ambient-glow {
  z-index: 5;
  background: radial-gradient(
    circle at 86% 52%,
    rgba(255, 174, 66, 0.34) 0%,
    rgba(235, 130, 42, 0.16) 28%,
    rgba(160, 78, 22, 0.05) 54%,
    transparent 76%
  );
  opacity: 0.18;
  animation: candle-glow-grow linear both;
  animation-timeline: scroll(root block);
}

@keyframes backdrop-shift {
  0% {
    filter: hue-rotate(0deg) brightness(1);
  }
  35% {
    filter: sepia(0.32) hue-rotate(-14deg) brightness(1.08);
  }
  70% {
    filter: sepia(0.55) hue-rotate(-25deg) brightness(0.68);
  }
  100% {
    filter: sepia(0.75) hue-rotate(-28deg) brightness(0.32);
  }
}

@keyframes sunbeam-shift {
  0% {
    opacity: 0.85;
    transform: translateX(-4%) translateY(-2%);
  }
  38% {
    opacity: 0.75;
    filter: sepia(0.8);
    transform: translateX(6%) translateY(0%);
  }
  72% {
    opacity: 0.28;
    filter: sepia(1) saturate(1.4);
    transform: translateX(14%) translateY(4%);
  }
  100% {
    opacity: 0;
    transform: translateX(20%) translateY(8%);
  }
}

@keyframes nightfall-creep {
  0% { opacity: 0; }
  35% { opacity: 0.04; }
  68% { opacity: 0.42; }
  100% { opacity: 0.84; }
}

@keyframes candle-glow-grow {
  0% { opacity: 0.14; }
  45% { opacity: 0.25; }
  78% { opacity: 0.65; }
  100% { opacity: 1; }
}

/* ==========================================================================
   2. LEFT COMPANION: CANONICAL HOURS WHEEL & SCROLL RIBBON
   ========================================================================== */

.hours-companion {
  position: fixed;
  left: max(1.25rem, calc(50% - 545px));
  top: 50%;
  transform: translateY(-50%);
  z-index: 12;
  pointer-events: none;
}

.hours-wheel {
  position: relative;
  padding: 1rem 1.05rem 1rem 1.25rem;
  background: rgba(242, 228, 196, 0.9);
  border: 1px solid rgba(158, 42, 43, 0.45);
  border-radius: 4px;
  box-shadow: 0 8px 24px rgba(10, 7, 5, 0.35);
}

.hours-title {
  display: block;
  font-size: 0.68rem;
  letter-spacing: 0.22em;
  color: var(--rubric);
  font-weight: 700;
  margin-bottom: 0.55rem;
  text-align: center;
}

.hours-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.hour-item {
  display: flex;
  align-items: center;
  gap: 0.48rem;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  color: rgba(35, 24, 18, 0.42);
  font-weight: 600;
  animation-timing-function: linear;
  animation-fill-mode: both;
  animation-timeline: scroll(root block);
}

.hour-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  border: 1.5px solid currentColor;
  background: transparent;
  flex-shrink: 0;
}

.hour-matins { animation-name: hl-matins; }
.hour-prime  { animation-name: hl-prime; }
.hour-sext   { animation-name: hl-sext; }
.hour-vespers { animation-name: hl-vespers; }
.hour-compline { animation-name: hl-compline; }

@keyframes hl-matins {
  0%, 16% { color: var(--rubric); transform: translateX(2px); }
  26%, 100% { color: rgba(35, 24, 18, 0.42); transform: translateX(0); }
}
@keyframes hl-prime {
  0%, 16% { color: rgba(35, 24, 18, 0.42); }
  22%, 38% { color: var(--rubric); transform: translateX(2px); }
  48%, 100% { color: rgba(35, 24, 18, 0.42); transform: translateX(0); }
}
@keyframes hl-sext {
  0%, 38% { color: rgba(35, 24, 18, 0.42); }
  45%, 62% { color: var(--rubric); transform: translateX(2px); }
  72%, 100% { color: rgba(35, 24, 18, 0.42); transform: translateX(0); }
}
@keyframes hl-vespers {
  0%, 62% { color: rgba(35, 24, 18, 0.42); }
  68%, 84% { color: var(--rubric); transform: translateX(2px); }
  92%, 100% { color: rgba(35, 24, 18, 0.42); transform: translateX(0); }
}
@keyframes hl-compline {
  0%, 84% { color: rgba(35, 24, 18, 0.42); }
  90%, 100% { color: var(--rubric); transform: translateX(2px); }
}

.scroll-ribbon-track {
  position: absolute;
  left: 0.45rem;
  top: 2.3rem;
  bottom: 0.95rem;
  width: 3px;
  background: rgba(158, 42, 43, 0.16);
  border-radius: 2px;
  overflow: hidden;
}

.scroll-ribbon-fill {
  width: 100%;
  height: 100%;
  background: linear-gradient(180deg, var(--rubric), var(--gold));
  transform-origin: top center;
  animation: ribbon-progress linear both;
  animation-timeline: scroll(root block);
}

@keyframes ribbon-progress {
  from { transform: scaleY(0.05); }
  to { transform: scaleY(1); }
}

/* ==========================================================================
   3. RIGHT COMPANION: BURNING CANDLE & LIVING GOOSE QUILL
   ========================================================================== */

.desk-companion {
  position: fixed;
  right: max(1.25rem, calc(50% - 545px));
  bottom: 2.4rem;
  z-index: 12;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
  pointer-events: none;
}

.candlestick-stage {
  position: relative;
  width: 96px;
  height: 270px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
}

/* Flame carriage drops smoothly as the candle shrinks */
.flame-carriage {
  position: absolute;
  top: 24px;
  left: 50%;
  width: 34px;
  height: 44px;
  margin-left: -17px;
  z-index: 3;
  animation: flame-descend linear both;
  animation-timeline: scroll(root block);
}

@keyframes flame-descend {
  from { transform: translateY(0px); }
  to { transform: translateY(138px); }
}

.wick {
  position: absolute;
  bottom: 0;
  left: 50%;
  width: 2px;
  height: 10px;
  margin-left: -1px;
  background: linear-gradient(180deg, #ff9933 0%, #241914 60%);
  border-radius: 1px;
}

.flame-aura {
  position: absolute;
  bottom: 4px;
  left: 50%;
  width: 68px;
  height: 68px;
  margin-left: -34px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 195, 85, 0.55) 0%, rgba(255, 130, 35, 0.16) 50%, transparent 72%);
  animation: aura-flicker 2.4s ease-in-out infinite alternate;
}

.flame-outer {
  position: absolute;
  bottom: 8px;
  left: 50%;
  width: 18px;
  height: 30px;
  margin-left: -9px;
  background: radial-gradient(ellipse at 50% 72%, #ffb32c 10%, #e86b1a 68%, rgba(210, 62, 16, 0.1) 100%);
  border-radius: 50% 50% 48% 48% / 68% 68% 32% 32%;
  transform-origin: bottom center;
  animation: flame-dance 1.35s ease-in-out infinite;
}

.flame-mid {
  position: absolute;
  bottom: 9px;
  left: 50%;
  width: 11px;
  height: 21px;
  margin-left: -5.5px;
  background: radial-gradient(ellipse at 50% 78%, #fff6be 10%, #ffca45 70%, transparent 100%);
  border-radius: 50% 50% 45% 45% / 70% 70% 30% 30%;
  transform-origin: bottom center;
  animation: flame-dance 0.95s ease-in-out infinite reverse;
}

.flame-core {
  position: absolute;
  bottom: 10px;
  left: 50%;
  width: 5px;
  height: 11px;
  margin-left: -2.5px;
  background: #fffef5;
  border-radius: 50%;
  box-shadow: 0 0 8px #ffe488;
}

.flame-spark {
  position: absolute;
  bottom: 32px;
  left: 50%;
  width: 2.5px;
  height: 2.5px;
  border-radius: 50%;
  background: #ffd166;
  opacity: 0;
  animation: spark-rise 2.6s ease-out infinite;
}

@keyframes flame-dance {
  0%   { transform: scaleX(1) scaleY(1) skewX(0deg); }
  25%  { transform: scaleX(0.92) scaleY(1.07) skewX(-4deg); }
  50%  { transform: scaleX(1.04) scaleY(0.95) skewX(3deg); }
  75%  { transform: scaleX(0.95) scaleY(1.09) skewX(-2deg); }
  100% { transform: scaleX(1) scaleY(1) skewX(1deg); }
}

@keyframes aura-flicker {
  0%   { transform: scale(0.94); opacity: 0.78; }
  50%  { transform: scale(1.08); opacity: 0.98; }
  100% { transform: scale(0.98); opacity: 0.85; }
}

@keyframes spark-rise {
  0%   { transform: translate(0, 0) scale(1); opacity: 0; }
  20%  { opacity: 0.9; }
  100% { transform: translate(-4px, -22px) scale(0.2); opacity: 0; }
}

/* Wax pillar shrinks from 164px to 26px */
.wax-pillar-frame {
  width: 30px;
  height: 164px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
}

.wax-pillar {
  position: relative;
  width: 28px;
  height: 164px;
  background: linear-gradient(90deg, #e9d4a2 0%, #fbf0d3 38%, #dec084 80%, #b99557 100%);
  border-radius: 4px 4px 2px 2px;
  box-shadow: inset 0 5px 8px rgba(255, 224, 130, 0.55), 0 2px 8px rgba(0, 0, 0, 0.35);
  animation: candle-melt linear both;
  animation-timeline: scroll(root block);
}

@keyframes candle-melt {
  from { height: 164px; }
  to { height: 26px; }
}

.wax-drip {
  position: absolute;
  top: 2px;
  width: 5px;
  border-radius: 0 0 4px 4px;
  background: linear-gradient(180deg, #fff4d8, #e1c182);
  box-shadow: 0 1px 2px rgba(72, 48, 22, 0.28);
}

.wax-drip-1 {
  left: 4px;
  height: 8px;
  animation: drip-grow-1 linear both;
  animation-timeline: scroll(root block);
}

.wax-drip-2 {
  right: 5px;
  width: 4px;
  height: 4px;
  animation: drip-grow-2 linear both;
  animation-timeline: scroll(root block);
}

@keyframes drip-grow-1 {
  0% { height: 6px; }
  55% { height: 34px; }
  100% { height: 18px; }
}

@keyframes drip-grow-2 {
  0% { height: 4px; }
  70% { height: 22px; }
  100% { height: 14px; }
}

/* Brass Candlestick */
.brass-bobeche {
  width: 52px;
  height: 8px;
  border-radius: 4px 4px 10px 10px;
  background: linear-gradient(90deg, #745521, #d7ae53 45%, #8f6928 85%, #5b4016);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.45);
}

.brass-stem {
  width: 12px;
  height: 22px;
  background: linear-gradient(90deg, #694b1c, #cca34a 50%, #5c4016);
}

.brass-base {
  width: 64px;
  height: 11px;
  border-radius: 12px 12px 3px 3px;
  background: linear-gradient(90deg, #62461a, #d4aa4f 42%, #7d5b22 86%, #4b3412);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.55);
}

/* Working Goose Quill & Inkhorn */
.writing-desk-tools {
  position: relative;
  width: 90px;
  height: 92px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
}

.quill-rig {
  position: absolute;
  top: -12px;
  right: 6px;
  transform-origin: 18% 92%;
  animation: quill-scribe 4.8s ease-in-out infinite;
}

.nib-inkdrop {
  animation: nib-pulse 2.4s ease-in-out infinite;
}

@keyframes quill-scribe {
  0%   { transform: translate(0, 0) rotate(0deg); }
  12%  { transform: translate(-5px, 2px) rotate(-6deg); }
  22%  { transform: translate(-1px, -1px) rotate(3deg); }
  34%  { transform: translate(-7px, 3px) rotate(-7deg); }
  46%  { transform: translate(1px, 0) rotate(2deg); }
  58%  { transform: translate(-4px, 2px) rotate(-5deg); }
  72%  { transform: translate(-2px, 12px) rotate(-14deg); } /* dip into inkhorn */
  82%  { transform: translate(-2px, 12px) rotate(-14deg); }
  100% { transform: translate(0, 0) rotate(0deg); }
}

@keyframes nib-pulse {
  0%, 100% { opacity: 0.7; transform: scale(0.9); }
  75% { opacity: 1; transform: scale(1.2); }
}

.inkhorn {
  position: relative;
  width: 44px;
  height: 28px;
  border-radius: 10px 10px 14px 14px;
  background: linear-gradient(90deg, #2b211a, #544234 45%, #201813);
  border: 2px solid #8a6d43;
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
}

.ink-pool {
  width: 26px;
  height: 7px;
  margin-top: -3px;
  border-radius: 50%;
  background: radial-gradient(circle, #33251d 20%, #0d0907 85%);
  border: 1.5px solid #9c7b4c;
}

/* ==========================================================================
   4. MAIN CODEX FOLIO (Parchment Sheet & Borders)
   ========================================================================== */

.scriptorium-desk {
  position: relative;
  z-index: 6;
  padding: 3.5rem 1.25rem 22vh;
  display: flex;
  justify-content: center;
}

.codex-folio {
  position: relative;
  width: 100%;
  min-width: 0;
  max-width: 740px;
  overflow-wrap: break-word;
  padding: 3.2rem 3.4rem 3.8rem;
  background:
    radial-gradient(circle at 18% 12%, rgba(255, 249, 232, 0.55) 0%, transparent 45%),
    radial-gradient(circle at 85% 88%, rgba(196, 162, 106, 0.32) 0%, transparent 48%),
    linear-gradient(180deg, #f5e9ce 0%, #efdfb9 52%, #e6d1a3 100%);
  border-radius: 3px;
  box-shadow:
    0 24px 60px rgba(6, 4, 3, 0.68),
    inset 0 0 42px rgba(138, 102, 54, 0.35),
    inset 0 0 0 1px rgba(120, 86, 44, 0.45);
}

/* Warm candlelight wash across the parchment as Compline falls */
.codex-folio::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: inherit;
  z-index: 9;
  background: radial-gradient(
    ellipse at 92% 72%,
    rgba(255, 192, 92, 0.14) 0%,
    rgba(232, 146, 52, 0.08) 42%,
    rgba(32, 18, 10, 0.24) 100%
  );
  opacity: 0;
  animation: folio-candlelight linear both;
  animation-timeline: scroll(root block);
}

@keyframes folio-candlelight {
  0%   { opacity: 0; }
  45%  { opacity: 0.1; }
  75%  { opacity: 0.52; }
  100% { opacity: 0.92; }
}

.vellum-texture {
  position: absolute;
  inset: 0;
  pointer-events: none;
  filter: url(#vellum-grain);
  opacity: 0.7;
  border-radius: inherit;
}

/* Double Rubricated Manuscript Rules */
.folio-rule-outer {
  position: absolute;
  inset: 14px;
  border: 1.5px solid rgba(158, 42, 43, 0.42);
  pointer-events: none;
}

.folio-rule-inner {
  position: absolute;
  inset: 20px;
  border: 1px solid rgba(158, 42, 43, 0.24);
  pointer-events: none;
}

/* Running Header */
.folio-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.74rem;
  letter-spacing: 0.16em;
  color: var(--rubric);
  border-bottom: 1px solid rgba(158, 42, 43, 0.28);
  padding-bottom: 0.6rem;
  margin-bottom: 2.1rem;
  font-weight: 700;
}

.running-ornament {
  font-size: 1rem;
  color: var(--gold);
}

/* Title Illumination */
.title-block {
  text-align: center;
  margin-bottom: 2.6rem;
}

.title-seal-row {
  margin-bottom: 0.5rem;
}

.vine-flourish {
  max-width: 100%;
  height: auto;
}

.rubric-super {
  margin: 0 0 0.45rem;
  font-size: 0.78rem;
  letter-spacing: 0.2em;
  color: var(--rubric);
  font-weight: 700;
}

.manuscript-title {
  margin: 0 0 0.75rem;
  font-size: clamp(2rem, 4.4vw, 2.85rem);
  line-height: 1.15;
  font-weight: 700;
  color: var(--ink-dark);
  letter-spacing: 0.02em;
}

.numeral-404 {
  color: var(--rubric);
  text-shadow: 1px 1px 0 rgba(212, 164, 56, 0.45);
}

.manuscript-subtitle {
  margin: 0 auto;
  max-width: 520px;
  font-size: 1.06rem;
  font-style: italic;
  color: var(--ink-soft);
}

/* Chapters & Illuminated Headings */
.folio-chapter {
  position: relative;
  margin-bottom: 2.4rem;
}

.chapter-rubric {
  margin: 0 0 1.15rem;
  font-size: 1.24rem;
  letter-spacing: 0.04em;
  color: var(--rubric);
  font-weight: 700;
}

.pilcrow {
  color: var(--lapis);
  margin-right: 0.3rem;
}

.dropcap-lead {
  display: flex;
  gap: 0.9rem;
  align-items: flex-start;
  margin-bottom: 0.85rem;
}

.dropcap-next {
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--rubric);
}

.illuminated-initial {
  flex-shrink: 0;
  filter: drop-shadow(0 3px 5px rgba(56, 36, 16, 0.28));
  animation: gold-glint 6s ease-in-out infinite;
}

@keyframes gold-glint {
  0%, 100% { filter: drop-shadow(0 3px 5px rgba(56, 36, 16, 0.28)) brightness(1); }
  50% { filter: drop-shadow(0 3px 8px rgba(212, 164, 56, 0.45)) brightness(1.06); }
}

/* ==========================================================================
   5. SCROLL-DRIVEN LINE INKING (Faint Dry-Point -> Wet Iron-Gall Ink)
   ========================================================================== */

.verse-stanza {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  margin-bottom: 1.1rem;
}

.verse-line {
  margin: 0;
  font-size: 1.08rem;
  line-height: 1.7;
  padding-bottom: 0.16rem;
  /* Faint ruled plummet guideline underneath each line */
  border-bottom: 1px solid rgba(118, 86, 52, 0.14);
}

.rubric {
  color: var(--rubric);
  font-weight: 700;
}

.rune {
  font-family: var(--font-mono);
  font-size: 0.88em;
  color: var(--lapis);
  font-weight: 600;
  letter-spacing: -0.02em;
}

@supports (animation-timeline: view()) {
  .verse-line {
    -webkit-mask-image: linear-gradient(90deg, #000 42%, rgba(0, 0, 0, 0.17) 56%);
    mask-image: linear-gradient(90deg, #000 42%, rgba(0, 0, 0, 0.17) 56%);
    -webkit-mask-size: 240% 100%;
    mask-size: 240% 100%;
    -webkit-mask-position: 100% 0;
    mask-position: 100% 0;
    animation: ink-sweep linear both;
    animation-timeline: view();
    animation-range: entry 0% cover 22%;
  }

  @keyframes ink-sweep {
    from {
      -webkit-mask-position: 100% 0;
      mask-position: 100% 0;
    }
    to {
      -webkit-mask-position: 0% 0;
      mask-position: 0% 0;
    }
  }
}

/* ==========================================================================
   6. INTERACTION 1: EXPANDABLE MARGINAL GLOSSES (<details>)
   ========================================================================== */

.marginal-gloss {
  margin: 1rem 0 0.5rem 1.2rem;
  border-left: 2px solid rgba(158, 42, 43, 0.45);
  padding-left: 0.85rem;
}

.gloss-trigger {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  cursor: pointer;
  list-style: none;
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--rubric);
  padding: 0.22rem 0.55rem;
  border-radius: 3px;
  background: rgba(158, 42, 43, 0.07);
  border: 1px dashed rgba(158, 42, 43, 0.38);
  transition: background-color 0.2s ease, transform 0.2s ease;
  user-select: none;
}

.gloss-trigger::-webkit-details-marker {
  display: none;
}

.gloss-trigger:hover {
  background: rgba(158, 42, 43, 0.15);
  transform: translateX(2px);
}

.manicule {
  font-size: 1.15rem;
  transition: transform 0.25s ease;
}

.marginal-gloss[open] .manicule {
  transform: rotate(90deg);
}

.gloss-card {
  margin-top: 0.55rem;
  padding: 0.75rem 1rem;
  background: rgba(252, 244, 223, 0.78);
  border: 1px solid rgba(138, 102, 54, 0.35);
  border-radius: 3px;
  font-size: 0.95rem;
  color: var(--ink-soft);
  box-shadow: 0 3px 10px rgba(72, 48, 22, 0.12);
}

.marginal-gloss[open] .gloss-card {
  animation: gloss-unfold 0.3s ease-out;
}

.gloss-card p {
  margin: 0;
}

@keyframes gloss-unfold {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ==========================================================================
   7. ILLUMINATED 404 PLAQUE & INTERACTION 2: CANDLELIGHT PALIMPSEST
   ========================================================================== */

.cipher-404-plaque {
  margin: 1.5rem auto;
  padding: 1.1rem 1.5rem;
  max-width: 460px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  background: linear-gradient(135deg, rgba(30, 67, 109, 0.1), rgba(212, 164, 56, 0.16));
  border: 2px double var(--rubric);
  position: relative;
}

.cipher-digits {
  font-size: 3.1rem;
  line-height: 1;
  font-weight: 700;
  color: var(--rubric);
  letter-spacing: 0.12em;
  text-shadow: 1px 1px 0 var(--gold-light);
}

.cipher-latin {
  margin-top: 0.35rem;
  font-size: 0.78rem;
  letter-spacing: 0.2em;
  color: var(--lapis);
  font-weight: 700;
}

.cipher-corner {
  position: absolute;
  color: var(--gold);
  font-size: 1rem;
}
.cipher-corner:first-child { top: 4px; left: 7px; }
.cipher-corner:last-child  { bottom: 4px; right: 7px; }

.palimpsest-box {
  margin: 1.35rem 0 1.1rem;
}

.vellum-seal-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  padding: 0.45rem 0.95rem;
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #fdf2d4;
  background: linear-gradient(180deg, #a83230 0%, #832122 100%);
  border: 1.5px solid var(--gold);
  border-radius: 3px;
  box-shadow: 0 3px 8px rgba(45, 22, 12, 0.28);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  user-select: none;
}

.vellum-seal-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 5px 12px rgba(45, 22, 12, 0.36);
}

.vellum-seal-btn .label-on {
  display: none;
}

#palimpsest-toggle:checked + .vellum-seal-btn .label-off,
#turn-leaf:checked + .vellum-seal-btn .label-off {
  display: none;
}

#palimpsest-toggle:checked + .vellum-seal-btn .label-on,
#turn-leaf:checked + .vellum-seal-btn .label-on {
  display: inline;
}

.palimpsest-window {
  position: relative;
  margin-top: 0.8rem;
  padding: 1.35rem 1.4rem;
  min-height: 158px;
  border: 1.5px solid rgba(122, 88, 44, 0.45);
  border-radius: 3px;
  background: #f5ead0;
  overflow: hidden;
  box-shadow: inset 0 0 22px rgba(154, 118, 66, 0.25);
  transition: background-color 0.5s ease, box-shadow 0.5s ease;
}

.palimpsest-backlight {
  position: absolute;
  inset: 0;
  opacity: 0;
  background: radial-gradient(circle at 50% 50%, rgba(255, 200, 92, 0.88) 0%, rgba(235, 145, 45, 0.42) 55%, rgba(168, 92, 26, 0.25) 100%);
  transition: opacity 0.55s ease;
  pointer-events: none;
}

.palimpsest-surface {
  position: relative;
  z-index: 2;
}

.palimpsest-visible-note {
  margin: 2.3rem 0 0;
  text-align: center;
  font-style: italic;
  color: rgba(78, 59, 44, 0.5);
  transition: opacity 0.35s ease;
}

.palimpsest-ghosts {
  position: absolute;
  inset: 0;
  opacity: 0.04;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: #5c2c0e;
  transition: opacity 0.6s ease;
  pointer-events: none;
}

.ghost-line {
  margin: 0 0 0.42rem;
}

.ghost-pawprint {
  position: absolute;
  right: 8px;
  bottom: -4px;
  color: #6b3010;
  transform: rotate(-18deg);
}

#palimpsest-toggle:checked ~ .palimpsest-window {
  box-shadow: inset 0 0 36px rgba(255, 164, 48, 0.65), 0 0 24px rgba(255, 168, 56, 0.35);
}

#palimpsest-toggle:checked ~ .palimpsest-window .palimpsest-backlight {
  opacity: 1;
}

#palimpsest-toggle:checked ~ .palimpsest-window .palimpsest-visible-note {
  opacity: 0;
}

#palimpsest-toggle:checked ~ .palimpsest-window .palimpsest-ghosts {
  opacity: 0.88;
}

/* ==========================================================================
   8. INTERACTION 3: 3D TURNING ILLUMINATED LEAF (Recto <-> Verso)
   ========================================================================== */

.turning-leaf-wrapper {
  margin: 1.5rem 0 1rem;
}

.leaf-perspective {
  margin-top: 0.9rem;
  perspective: 1400px;
}

.leaf-card {
  position: relative;
  width: 100%;
  min-height: 270px;
  transform-style: preserve-3d;
  transform-origin: center center;
  transition: transform 0.95s cubic-bezier(0.32, 0.08, 0.24, 1);
}

#turn-leaf:checked ~ .leaf-perspective .leaf-card {
  transform: rotateY(-180deg);
}

.leaf-face {
  position: relative;
  width: 100%;
  min-height: 270px;
  backface-visibility: hidden;
  background: linear-gradient(135deg, #f8eed4 0%, #ead6ab 100%);
  border: 1.5px solid #8a642e;
  border-radius: 4px;
  padding: 1rem;
  box-shadow: 0 10px 24px rgba(34, 20, 10, 0.22);
}

.leaf-verso {
  position: absolute;
  inset: 0;
  transform: rotateY(180deg);
  background: linear-gradient(135deg, #efe0bd 0%, #e4cd9b 100%);
}

.miniature-frame {
  height: 100%;
  min-height: 236px;
  border: 2px solid var(--lapis);
  outline: 1px solid var(--gold);
  outline-offset: -5px;
  padding: 1rem 1.2rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  text-align: center;
}

.miniature-tag {
  font-size: 0.7rem;
  letter-spacing: 0.18em;
  color: var(--rubric);
  font-weight: 700;
}

.recto-emblem {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
}

.recto-roman {
  font-size: 2.35rem;
  font-weight: 700;
  color: var(--lapis);
  letter-spacing: 0.16em;
  border-bottom: 2px solid var(--gold);
  padding-bottom: 0.15rem;
}

.recto-title {
  font-size: 1.1rem;
  font-style: italic;
  color: var(--ink-dark);
}

.recto-caption {
  margin: 0;
  max-width: 440px;
  font-size: 0.96rem;
  color: var(--ink-soft);
}

.recto-ornaments {
  display: flex;
  gap: 1.1rem;
  color: var(--rubric);
  font-size: 1.05rem;
}

/* Verso Rough Sketch */
.verso-frame {
  border-color: var(--rubric);
}

.verso-wireframe {
  width: 100%;
  max-width: 470px;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  color: var(--ink-dark);
}

.wire-header,
.wire-nav,
.wire-main,
.wire-footer {
  border: 1.5px dashed rgba(35, 24, 18, 0.65);
  padding: 0.42rem 0.6rem;
  background: rgba(255, 250, 238, 0.45);
}

.wire-row {
  display: flex;
  gap: 0.45rem;
}

.wire-nav {
  width: 34%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--lapis);
}

.wire-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  align-items: center;
}

.wire-marquee {
  color: var(--rubric);
  font-weight: 700;
  animation: mini-marquee 3.8s linear infinite;
}

@keyframes mini-marquee {
  0% { transform: translateX(8px); }
  50% { transform: translateX(-8px); }
  100% { transform: translateX(8px); }
}

.wire-turnip-btn {
  padding: 0.25rem 0.7rem;
  border-radius: 14px;
  border: 1.5px solid var(--emerald);
  background: rgba(58, 107, 76, 0.14);
  color: var(--emerald);
  font-weight: 700;
}

.verso-note {
  margin: 0;
  font-size: 0.88rem;
  color: var(--ink-soft);
}

/* ==========================================================================
   9. LIVING & MISBEHAVING MARGINALIA (Snail, Hare, Pangur Cat, Ink-Spider)
   ========================================================================== */

.divider-vine {
  position: relative;
  display: flex;
  justify-content: center;
  margin: 1.8rem 0 1.4rem;
}

.marginalia-lane-left {
  position: absolute;
  left: -42px;
  top: 430px;
  width: 60px;
  height: 220px;
  pointer-events: auto;
  z-index: 8;
}

.snail-drolerie {
  position: absolute;
  left: 0;
  bottom: 0;
  animation: snail-patrol 14s ease-in-out infinite alternate;
}

.snail-antennae {
  transform-origin: 50px 23px;
  animation: antennae-wiggle 2.4s ease-in-out infinite;
}

.hare-drolerie {
  position: absolute;
  left: 4px;
  top: 0;
  animation: hare-nervous 2.8s ease-in-out infinite;
}

.hare-drolerie:hover {
  animation-duration: 0.6s;
}

@keyframes snail-patrol {
  0%   { transform: translateY(0px) rotate(-90deg); }
  50%  { transform: translateY(-64px) rotate(-86deg); }
  100% { transform: translateY(-108px) rotate(-92deg); }
}

@keyframes antennae-wiggle {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(8deg); }
}

@keyframes hare-nervous {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  35% { transform: translateY(-5px) rotate(-3deg); }
  70% { transform: translateY(0) rotate(2deg); }
}

/* Pangur the Abbey Cat on the right margin */
.marginalia-cat-stage {
  position: absolute;
  right: -28px;
  top: 56%;
  z-index: 8;
}

.cat-drolerie {
  transition: transform 0.25s ease;
}

.cat-drolerie:hover {
  transform: scale(1.08) rotate(-3deg);
}

.cat-tail {
  transform-origin: 22px 60px;
  animation: tail-swish 3.2s ease-in-out infinite;
}

.cat-eye {
  transform-origin: center;
  animation: cat-blink 5.5s ease-in-out infinite;
}

.cat-paw {
  transform-origin: 52px 46px;
  animation: paw-bat 2.6s ease-in-out infinite;
}

.dangling-seal {
  transform-origin: 74px 4px;
  animation: seal-swing 2.6s ease-in-out infinite;
}

@keyframes tail-swish {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(16deg); }
}

@keyframes cat-blink {
  0%, 44%, 48%, 100% { transform: scaleY(1); }
  46% { transform: scaleY(0.1); }
}

@keyframes paw-bat {
  0%, 60%, 100% { transform: rotate(0deg); }
  74% { transform: rotate(-16deg); }
  84% { transform: rotate(4deg); }
}

@keyframes seal-swing {
  0%, 60%, 100% { transform: rotate(0deg); }
  78% { transform: rotate(22deg); }
  90% { transform: rotate(-10deg); }
}

/* Tiny Ink-Spider descending from divider */
.spider-thread {
  position: absolute;
  right: 18%;
  top: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.spider-web-line {
  width: 1px;
  height: 36px;
  background: rgba(35, 24, 18, 0.38);
  transform-origin: top center;
  animation: spider-web-stretch 7s ease-in-out infinite;
}

.tiny-spider {
  margin-top: -3px;
  animation: spider-drop 7s ease-in-out infinite;
}

@keyframes spider-web-stretch {
  0%, 100% { transform: scaleY(0.32); opacity: 0.65; }
  45% { transform: scaleY(1); opacity: 1; }
  65% { transform: scaleY(0.85); opacity: 1; }
}

@keyframes spider-drop {
  0%, 100% { transform: translateY(-24px); opacity: 0.75; }
  45% { transform: translateY(0px); opacity: 1; }
  65% { transform: translateY(-5px); opacity: 1; }
}

/* ==========================================================================
   10. COLOPHON & RETURN HOME SEAL
   ========================================================================== */

.colophon {
  margin-top: 2.6rem;
  padding-top: 1.6rem;
  border-top: 1.5px solid rgba(158, 42, 43, 0.35);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.9rem;
}

.colophon-text {
  margin: 0;
  font-size: 0.94rem;
  color: var(--ink-soft);
}

.return-home-link {
  display: inline-block;
  margin-top: 0.3rem;
  padding: 0.45rem 1.05rem;
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--rubric);
  border: 1.5px solid var(--rubric);
  border-radius: 999px;
  background: rgba(158, 42, 43, 0.06);
  transition: background-color 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.return-home-link:hover {
  background: var(--rubric);
  color: #fdf2d4;
  transform: translateY(-1px);
}

/* ==========================================================================
   11. RESPONSIVE ADAPTATIONS & ACCESSIBILITY
   ========================================================================== */

@media (max-width: 1120px) {
  .hours-companion {
    display: none;
  }

  .desk-companion {
    right: 0.85rem;
    bottom: 1rem;
    transform: scale(0.76);
    transform-origin: bottom right;
    opacity: 0.94;
  }

  .marginalia-lane-left {
    left: -18px;
    transform: scale(0.82);
  }

  .marginalia-cat-stage {
    right: -12px;
    transform: scale(0.84);
  }
}

@media (max-width: 680px) {
  .scriptorium-desk {
    padding: 1.5rem 0.65rem 22vh;
  }

  .codex-folio {
    padding: 2.1rem 1.35rem 2.6rem;
  }

  .folio-rule-outer {
    inset: 8px;
  }

  .folio-rule-inner {
    inset: 12px;
  }

  .dropcap-lead {
    flex-direction: column;
    gap: 0.65rem;
  }

  .wire-row {
    flex-direction: column;
  }

  .wire-nav {
    width: 100%;
  }

  .marginalia-lane-left,
  .marginalia-cat-stage {
    display: none;
  }

  .desk-companion {
    top: auto;
    bottom: 0.65rem;
    right: 0.3rem;
    transform: scale(0.55);
    transform-origin: bottom right;
  }

  .writing-desk-tools {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .flame-outer,
  .flame-mid,
  .flame-aura,
  .flame-spark,
  .quill-rig,
  .nib-inkdrop,
  .snail-drolerie,
  .snail-antennae,
  .hare-drolerie,
  .cat-tail,
  .cat-eye,
  .cat-paw,
  .dangling-seal,
  .spider-web-line,
  .tiny-spider,
  .wire-marquee,
  .illuminated-initial {
    animation: none !important;
  }

  .verse-line {
    -webkit-mask-image: none !important;
    mask-image: none !important;
    animation: none !important;
  }
}
