@property --ink {
  syntax: '<percentage>';
  inherits: false;
  initial-value: 0%;
}

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

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  padding: 0;
  background-color: #ede0c8;
  background-image:
    radial-gradient(ellipse at 20% 30%, rgba(160,120,60,0.1) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 15%, rgba(140,100,40,0.07) 0%, transparent 45%),
    radial-gradient(ellipse at 55% 60%, rgba(150,110,50,0.06) 0%, transparent 55%),
    radial-gradient(ellipse at 25% 80%, rgba(130,90,35,0.09) 0%, transparent 48%),
    radial-gradient(ellipse at 75% 72%, rgba(160,120,60,0.08) 0%, transparent 42%);
  font-family: 'Palatino Linotype', Palatino, 'Book Antiqua', Georgia, 'Times New Roman', serif;
  font-size: 1.1rem;
  line-height: 1.85;
  color: #2c1810;
  overflow-x: hidden;
}

body::after {
  content: '';
  position: fixed;
  inset: 0;
  box-shadow: inset 0 0 100px rgba(80, 50, 20, 0.1);
  pointer-events: none;
  z-index: 200;
}

.manuscript {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 2rem 12rem;
  position: relative;
}

/* --- Title --- */

.title-page {
  text-align: center;
  padding: 10vh 0 5rem;
}

.title-page .ornament {
  margin-bottom: 2rem;
  opacity: 0.7;
}

h1 {
  font-size: 2rem;
  font-weight: normal;
  color: #8b1a1a;
  line-height: 1.35;
  margin: 0 0 1.2rem;
  letter-spacing: 0.04em;
}

.subtitle {
  font-style: italic;
  color: #5a3a1a;
  font-size: 0.92rem;
  line-height: 1.7;
  margin: 0;
}

.scroll-hint-track {
  margin-top: 3.5rem;
  animation: hint-fade linear both;
  animation-timeline: scroll();
  animation-range: 0% 5%;
}

.scroll-hint {
  color: #a08050;
  font-size: 0.85rem;
  letter-spacing: 0.25em;
  margin: 0;
  animation: pulse 2.5s ease-in-out infinite;
}

/* --- Separators & Ornaments --- */

.sep {
  text-align: center;
  margin: 3rem 0;
  opacity: 0.55;
}

.ornament {
  display: block;
  margin: 0 auto;
}

/* --- Chapters --- */

.chapter {
  position: relative;
  margin-bottom: 3rem;
  padding: 1rem 0;
}

.chapter-title {
  font-size: 1.2rem;
  font-weight: normal;
  text-align: center;
  margin: 0 0 2.2rem;
  letter-spacing: 0.18em;
  color: #8b1a1a;
  background: linear-gradient(90deg, #8b1a1a var(--ink), transparent calc(var(--ink) + 3%));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: scribe linear both;
  animation-timeline: view();
  animation-range: entry 0% entry 100%;
}

/* --- Verses --- */

.verse {
  margin: 0 0 1.6em;
  animation: ink-appear linear both;
  animation-timeline: view();
  animation-range: entry 0% entry 80%;
}

.verse:last-child {
  margin-bottom: 0;
}

/* --- Drop Caps --- */

.drop-cap {
  float: left;
  font-size: 3.8em;
  line-height: 0.78;
  padding: 0.04em 0.14em 0.06em 0.08em;
  margin-right: 0.08em;
  margin-top: 0.06em;
  color: #c5a55a;
  background: #2e1a0e;
  border: 2px solid #c5a55a;
  font-weight: bold;
  box-shadow: 2px 2px 0 rgba(0,0,0,0.12);
}

.sc {
  font-variant: small-caps;
  letter-spacing: 0.06em;
}

/* --- Decrees --- */

.decree {
  border-left: 2.5px solid #8b1a1a;
  padding-left: 1.5em;
  margin-left: 1em;
  margin-right: 1em;
  font-style: italic;
}

/* --- The 404 --- */

.the-four-oh-four {
  text-align: center;
  padding: 1.5rem 0;
}

.four-oh-four-frame {
  display: inline-block;
  border: 3px double #c5a55a;
  padding: 1.2rem 2.8rem;
  position: relative;
  box-shadow: 0 0 25px rgba(197, 165, 90, 0.12);
}

.four-oh-four-frame::before,
.four-oh-four-frame::after {
  position: absolute;
  color: #c5a55a;
  font-size: 1.4rem;
  line-height: 1;
}

.four-oh-four-frame::before {
  content: '❧';
  top: -0.55em;
  left: 0.3em;
}

.four-oh-four-frame::after {
  content: '❧';
  bottom: -0.55em;
  right: 0.3em;
  display: inline-block;
  transform: rotate(180deg);
}

.four-oh-four-num {
  display: block;
  font-size: 4.5rem;
  font-weight: bold;
  line-height: 1;
  background: linear-gradient(180deg, #d4af37, #f0d060 35%, #c5a55a 65%, #9a7b2e);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.15));
}

.four-oh-four-msg {
  display: block;
  font-size: 1rem;
  color: #8b1a1a;
  margin-top: 0.4rem;
  font-variant: small-caps;
  letter-spacing: 0.22em;
}

/* --- Candle --- */

.candle-container {
  position: fixed;
  right: max(2rem, calc(50% - 420px));
  bottom: 22%;
  width: 50px;
  height: 160px;
  z-index: 50;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
}

.holder {
  flex-shrink: 0;
}

.wax {
  width: 14px;
  background: linear-gradient(to right, #e8dcc8, #faf3e3, #e8dcc8);
  border-radius: 2px 2px 0 0;
  position: relative;
  flex-shrink: 0;
  animation: melt linear both;
  animation-timeline: scroll();
}

.drip {
  position: absolute;
  width: 5px;
  height: 10px;
  background: #eee5d5;
  border-radius: 0 0 50% 50%;
  right: -2px;
  top: 28%;
}

.drip::after {
  content: '';
  position: absolute;
  width: 4px;
  height: 7px;
  background: #e8dcc8;
  border-radius: 0 0 50% 50%;
  left: -8px;
  top: 40%;
}

.flame-group {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  animation: flame-shrink linear both;
  animation-timeline: scroll();
}

.flame {
  width: 10px;
  height: 24px;
  position: relative;
  background: radial-gradient(ellipse at 50% 75%,
    #fff 0%,
    #ffc 8%,
    #ffcc00 22%,
    #ff9900 42%,
    #ff6600 62%,
    rgba(255,60,0,0.4) 82%,
    transparent 100%
  );
  border-radius: 50% 50% 50% 50% / 65% 65% 35% 35%;
  filter: blur(0.5px);
  animation: flicker 0.8s ease-in-out infinite;
}

.flame::after {
  content: '';
  position: absolute;
  width: 50px;
  height: 50px;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle, rgba(255,180,80,0.35) 0%, transparent 70%);
  border-radius: 50%;
  animation: glow-pulse 0.6s ease-in-out infinite alternate;
}

/* --- Light Overlays --- */

.candlelight {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 100;
  background: radial-gradient(ellipse at 88% 18%,
    rgba(255,200,120,0.12) 0%,
    rgba(255,180,80,0.06) 30%,
    transparent 65%
  );
  animation: dim-light linear both;
  animation-timeline: scroll();
}

.vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 99;
  animation: darken linear both;
  animation-timeline: scroll();
}

/* --- Quill --- */

.quill-container {
  position: fixed;
  left: min(calc(50% + 340px), calc(100vw - 50px));
  top: 42%;
  transform: rotate(-35deg);
  opacity: 0.45;
  pointer-events: none;
  z-index: 10;
  animation: quill-bob 1.8s ease-in-out infinite;
}

/* --- Marginal Notes --- */

.note-toggle {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.note-marker {
  position: absolute;
  right: -2.2rem;
  color: #8b1a1a;
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  transition: color 0.3s;
  user-select: none;
  z-index: 5;
}

.note-marker:hover {
  color: #c5a55a;
}

.note-body {
  position: absolute;
  right: -13.5rem;
  width: 10.5rem;
  font-size: 0.78rem;
  font-style: italic;
  color: #6b4423;
  line-height: 1.55;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.6s ease, opacity 0.6s ease;
  opacity: 0;
  z-index: 5;
}

.note-toggle:checked ~ .note-body {
  max-height: 10rem;
  opacity: 1;
}

.note-toggle:checked ~ .note-marker {
  color: #c5a55a;
}

/* --- Margin Doodle --- */

.margin-doodle {
  position: absolute;
  left: -3.5rem;
  top: 4em;
  opacity: 0.07;
  transition: opacity 1s ease;
  cursor: default;
}

.margin-doodle:hover {
  opacity: 0.85;
  transition: opacity 0.3s ease;
}

/* --- Prayer --- */

.prayer-mark {
  display: block;
  text-align: center;
  color: #c5a55a;
  font-size: 1.5rem;
  cursor: pointer;
  margin: 2.5rem 0 0.5rem;
  transition: color 0.4s, transform 0.4s;
  user-select: none;
}

.prayer-mark:hover {
  color: #8b1a1a;
  transform: scale(1.15);
}

.prayer-body {
  text-align: center;
  font-style: italic;
  color: #5a3a1a;
  font-size: 0.92rem;
  line-height: 1.9;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.8s ease, opacity 0.8s ease;
  opacity: 0;
}

.note-toggle:checked ~ .prayer-body {
  max-height: 15rem;
  opacity: 1;
}

.note-toggle:checked ~ .prayer-mark {
  color: #8b1a1a;
  transform: rotate(90deg);
}

/* --- Tired Hand --- */

.tired-wrapper {
  animation: tired-wobble 3s ease-in-out infinite;
}

.tired-hand {
  font-style: italic;
  letter-spacing: 0.02em;
}

/* --- Colophon --- */

.colophon-section {
  margin-top: 2rem;
}

.colophon-section::before {
  content: '';
  display: block;
  width: 7px;
  height: 7px;
  background: #2c1810;
  border-radius: 40% 55% 45% 50%;
  margin: 0 auto 2rem;
  opacity: 0.3;
}

.colophon-text {
  text-align: center;
  font-size: 0.95rem;
  color: #4a3a28;
}

.finis {
  text-align: center;
  font-size: 1.4rem;
  color: #c5a55a;
  letter-spacing: 0.35em;
  margin-top: 2.5rem !important;
}

/* --- Keyframes --- */

@keyframes scribe {
  to { --ink: 100%; }
}

@keyframes ink-appear {
  from {
    opacity: 0;
    filter: blur(1.5px);
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    filter: blur(0);
    transform: translateY(0);
  }
}

@keyframes pulse {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 0.7; }
}

@keyframes hint-fade {
  from { opacity: 1; }
  to { opacity: 0; }
}

@keyframes melt {
  from { height: 85px; }
  to { height: 5px; }
}

@keyframes flame-shrink {
  from { transform: translateX(-50%) scale(1); opacity: 1; }
  to { transform: translateX(-50%) scale(0.2); opacity: 0.1; }
}

@keyframes flicker {
  0%   { transform: scaleX(1)    scaleY(1)    rotate(0deg);    opacity: 1; }
  10%  { transform: scaleX(0.88) scaleY(1.05) rotate(-1.5deg); opacity: 0.94; }
  20%  { transform: scaleX(1.04) scaleY(0.95) rotate(1deg);    opacity: 1; }
  30%  { transform: scaleX(0.9)  scaleY(1.06) rotate(-0.5deg); opacity: 0.91; }
  40%  { transform: scaleX(1.02) scaleY(0.97) rotate(0.8deg);  opacity: 0.98; }
  50%  { transform: scaleX(0.86) scaleY(1.04) rotate(-2deg);   opacity: 0.89; }
  60%  { transform: scaleX(1.05) scaleY(0.96) rotate(1.2deg);  opacity: 0.96; }
  70%  { transform: scaleX(0.91) scaleY(1.03) rotate(-0.8deg); opacity: 0.93; }
  80%  { transform: scaleX(1.01) scaleY(0.98) rotate(0.3deg);  opacity: 1; }
  90%  { transform: scaleX(0.87) scaleY(1.05) rotate(1.5deg);  opacity: 0.9; }
  100% { transform: scaleX(0.95) scaleY(1.02) rotate(-1deg);   opacity: 0.96; }
}

@keyframes glow-pulse {
  from { opacity: 0.6; transform: translate(-50%, -50%) scale(0.9); }
  to   { opacity: 1;   transform: translate(-50%, -50%) scale(1.15); }
}

@keyframes dim-light {
  from { opacity: 1; }
  to   { opacity: 0; }
}

@keyframes darken {
  from { box-shadow: inset 0 0 80px rgba(30, 15, 5, 0); }
  to   { box-shadow: inset 0 0 250px rgba(30, 15, 5, 0.6); }
}

@keyframes quill-bob {
  0%, 100% { transform: rotate(-35deg) translateY(0); }
  30%      { transform: rotate(-33deg) translateY(-5px); }
  60%      { transform: rotate(-36deg) translateY(-2px); }
}

@keyframes tired-wobble {
  0%, 100% { transform: rotate(0deg); }
  25%      { transform: rotate(-0.3deg) translateX(-1px); }
  75%      { transform: rotate(0.3deg) translateX(1px); }
}
