/* renai.monster — styles.css
   palette: deep-burgundy + parchment cream + honeyed sunlight
   layout: diagonal-sections with hand-drawn deckled edges
   typography: Fraunces (display) + Cormorant Garamond (body) + Caveat (script)
*/

:root {
  --burgundy-deep: #3A0A14;
  --burgundy-velvet: #6B1226;
  --burgundy-crimson: #A6263D;
  --parchment: #F4E9D8;
  --vellum: #EAD6B8;
  --sunlight: #F2A65A;
  --ink-black: #1F0509;
  --rail-width: 64px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  background-color: var(--parchment);
  color: var(--burgundy-deep);
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 18px;
  line-height: 1.55;
  overflow-x: hidden;
  position: relative;
  min-height: 100vh;
}

/* Paper grain background for whole body */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image:
    radial-gradient(ellipse at 20% 30%, rgba(58, 10, 20, 0.04) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 70%, rgba(107, 18, 38, 0.05) 0%, transparent 60%),
    repeating-linear-gradient(
      45deg,
      transparent 0px,
      transparent 3px,
      rgba(31, 5, 9, 0.012) 3px,
      rgba(31, 5, 9, 0.012) 4px
    );
  mix-blend-mode: multiply;
}

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

/* === Canvas particle layer === */
#particle-canvas {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

/* === Ripple SVG layer === */
#ripple-layer {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  width: 100vw;
  height: 100vh;
}

/* === Left rail: specimen numbers === */
.rail {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: var(--rail-width);
  z-index: 5;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 80px;
  padding-bottom: 80px;
}

.rail-line {
  position: absolute;
  left: 28px;
  top: 60px;
  bottom: 60px;
  width: 1px;
  background: linear-gradient(
    to bottom,
    transparent 0%,
    var(--burgundy-velvet) 8%,
    var(--burgundy-velvet) 92%,
    transparent 100%
  );
  opacity: 0.6;
  transform: rotate(0.3deg);
}

.rail-marks {
  list-style: none;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  padding-left: 4px;
  pointer-events: auto;
}

.rail-marks li {
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
  transition: opacity 400ms ease;
  opacity: 0.45;
}

.rail-marks li::before {
  content: '';
  position: absolute;
  left: 24px;
  top: 50%;
  width: 8px;
  height: 8px;
  background: var(--burgundy-deep);
  border-radius: 50%;
  transform: translate(-50%, -50%) rotate(2deg);
  filter: blur(0.4px);
}

.rail-marks li.active { opacity: 1; }
.rail-marks li.active::before {
  background: var(--burgundy-crimson);
  width: 12px;
  height: 12px;
  box-shadow: 0 0 0 3px var(--parchment), 0 0 0 4px var(--burgundy-velvet);
}

.rail-marks .numeral {
  font-family: 'Fraunces', serif;
  font-weight: 700;
  font-size: 14px;
  color: var(--burgundy-velvet);
  margin-left: 44px;
  letter-spacing: 0.02em;
}

.rail-marks .label {
  font-family: 'Caveat', cursive;
  font-size: 13px;
  color: var(--burgundy-velvet);
  opacity: 0;
  transform: translateX(-6px) rotate(-2deg);
  transition: opacity 400ms ease, transform 400ms ease;
  white-space: nowrap;
}

.rail-marks li:hover .label,
.rail-marks li.active .label {
  opacity: 0.85;
  transform: translateX(0) rotate(-2deg);
}

/* === Floating compass rose === */
.compass-rose {
  position: fixed;
  right: 28px;
  bottom: 28px;
  width: 64px;
  height: 64px;
  z-index: 8;
  border: none;
  background: var(--parchment);
  cursor: pointer;
  padding: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: transform 600ms cubic-bezier(0.34, 1.2, 0.64, 1);
  transform: rotate(-3deg);
  filter: drop-shadow(2px 3px 0 rgba(58, 10, 20, 0.15));
}
.compass-rose:hover {
  transform: rotate(8deg) scale(1.08);
}
.compass-svg {
  width: 44px;
  height: 44px;
  display: block;
  animation: compass-spin 60s linear infinite;
}
@keyframes compass-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}
.compass-label {
  font-family: 'Caveat', cursive;
  font-size: 11px;
  color: var(--burgundy-velvet);
  margin-top: -2px;
  display: block;
  transform: rotate(-2deg);
}

/* Compass index modal */
.compass-index {
  position: fixed;
  inset: 0;
  z-index: 12;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(58, 10, 20, 0.25);
  padding: 24px;
  animation: compass-fade 280ms ease;
}
.compass-index[hidden] { display: none; }
@keyframes compass-fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.compass-index-card {
  background: var(--parchment);
  padding: 36px 44px 32px;
  max-width: 480px;
  width: 100%;
  transform: rotate(-3deg);
  position: relative;
  clip-path: polygon(
    1% 2%, 12% 0%, 24% 3%, 38% 1%, 52% 2%, 68% 0%, 82% 2%, 95% 1%, 100% 4%,
    99% 18%, 100% 36%, 98% 54%, 100% 72%, 99% 88%, 100% 98%,
    88% 100%, 70% 99%, 50% 100%, 32% 98%, 14% 100%, 2% 99%,
    0% 84%, 2% 66%, 0% 48%, 2% 30%, 0% 12%
  );
  box-shadow: 4px 6px 0 rgba(58, 10, 20, 0.18);
}
.compass-index-title {
  font-family: 'Fraunces', serif;
  font-size: 28px;
  font-weight: 700;
  color: var(--burgundy-deep);
  transform: rotate(1deg);
  margin-bottom: 18px;
  font-style: italic;
}
.compass-index-list {
  list-style: none;
}
.compass-index-list li {
  margin: 8px 0;
  transform: rotate(calc(var(--n, 0) * 0.5deg));
}
.compass-index-list li:nth-child(1) { --n: -2; }
.compass-index-list li:nth-child(2) { --n: 1; }
.compass-index-list li:nth-child(3) { --n: -1; }
.compass-index-list li:nth-child(4) { --n: 2; }
.compass-index-list li:nth-child(5) { --n: -1; }
.compass-index-list li:nth-child(6) { --n: 1; }
.compass-index-list a {
  color: var(--burgundy-deep);
  text-decoration: none;
  font-family: 'Cormorant Garamond', serif;
  font-size: 19px;
  border-bottom: 1px solid rgba(166, 38, 61, 0.4);
  padding-bottom: 1px;
  transition: color 240ms ease, border-color 240ms ease;
}
.compass-index-list a:hover {
  color: var(--burgundy-crimson);
  border-color: var(--burgundy-crimson);
}
.compass-close {
  margin-top: 22px;
  border: 1.4px solid var(--burgundy-velvet);
  background: transparent;
  padding: 8px 18px;
  font-family: 'Caveat', cursive;
  font-size: 18px;
  color: var(--burgundy-velvet);
  cursor: pointer;
  border-radius: 2px;
  transform: rotate(-1.5deg);
  transition: background 240ms ease, color 240ms ease;
}
.compass-close:hover {
  background: var(--burgundy-velvet);
  color: var(--parchment);
}

/* === Manuscript article === */
.manuscript {
  position: relative;
  z-index: 3;
  padding-left: var(--rail-width);
  padding-right: 0;
  max-width: 100%;
}

/* === Panels: diagonal sections with deckled edges === */
.panel {
  position: relative;
  padding: 140px 6vw 160px;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
  isolation: isolate;
}

.panel-inner {
  position: relative;
  width: 100%;
  max-width: 1200px;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 32px;
  transform: rotate(calc(var(--tilt-deg, 0) * 0.4deg));
}

/* Tilt assignments (very subtle on inner content so text remains readable) */
.panel-prelude { --tilt-deg: -7; }
.panel-i { --tilt-deg: 9; }
.panel-ii { --tilt-deg: -10; }
.panel-iii { --tilt-deg: 7; }
.panel-iv { --tilt-deg: -8; }
.panel-coda { --tilt-deg: 6; }

/* Panel backgrounds with deckled hand-drawn edges via clip-path */
.panel-prelude {
  background: var(--parchment);
  clip-path: polygon(
    0% 4%, 8% 2%, 16% 5%, 24% 1%, 32% 4%, 40% 2%, 48% 5%, 56% 1%, 64% 3%, 72% 5%, 80% 1%, 88% 4%, 96% 2%, 100% 5%,
    100% 95%, 92% 98%, 84% 96%, 76% 99%, 68% 95%, 60% 98%, 52% 96%, 44% 99%, 36% 95%, 28% 98%, 20% 96%, 12% 99%, 4% 95%, 0% 98%
  );
}

.parchment-bright {
  background: var(--parchment);
}
.parchment-vellum {
  background: var(--vellum);
}
.deep-burgundy {
  background: var(--burgundy-deep);
  color: var(--parchment);
}

/* Generic deckled clip for all subsequent panels with slight variations */
.panel-i {
  clip-path: polygon(
    0% 6%, 7% 2%, 14% 5%, 21% 1%, 28% 4%, 35% 2%, 42% 5%, 49% 1%, 56% 3%, 63% 5%, 70% 1%, 77% 4%, 84% 2%, 91% 5%, 98% 2%, 100% 6%,
    100% 94%, 93% 98%, 86% 96%, 79% 99%, 72% 95%, 65% 98%, 58% 96%, 51% 99%, 44% 95%, 37% 98%, 30% 96%, 23% 99%, 16% 95%, 9% 98%, 2% 96%, 0% 94%
  );
}
.panel-ii {
  clip-path: polygon(
    0% 5%, 6% 2%, 13% 4%, 20% 1%, 27% 5%, 34% 2%, 41% 4%, 48% 1%, 55% 5%, 62% 2%, 69% 4%, 76% 1%, 83% 5%, 90% 2%, 97% 4%, 100% 5%,
    100% 96%, 94% 99%, 87% 95%, 80% 98%, 73% 96%, 66% 99%, 59% 95%, 52% 98%, 45% 96%, 38% 99%, 31% 95%, 24% 98%, 17% 96%, 10% 99%, 3% 95%, 0% 96%
  );
}
.panel-iii {
  clip-path: polygon(
    0% 7%, 8% 3%, 16% 6%, 24% 2%, 32% 5%, 40% 3%, 48% 6%, 56% 2%, 64% 5%, 72% 3%, 80% 6%, 88% 2%, 96% 5%, 100% 7%,
    100% 93%, 92% 97%, 84% 95%, 76% 98%, 68% 94%, 60% 97%, 52% 95%, 44% 98%, 36% 94%, 28% 97%, 20% 95%, 12% 98%, 4% 94%, 0% 93%
  );
}
.panel-iv {
  clip-path: polygon(
    0% 4%, 7% 2%, 14% 6%, 21% 2%, 28% 5%, 35% 1%, 42% 4%, 49% 2%, 56% 6%, 63% 1%, 70% 4%, 77% 2%, 84% 6%, 91% 1%, 98% 4%, 100% 5%,
    100% 95%, 92% 99%, 84% 95%, 76% 98%, 68% 95%, 60% 99%, 52% 95%, 44% 98%, 36% 95%, 28% 99%, 20% 95%, 12% 98%, 4% 95%, 0% 96%
  );
}
.panel-coda {
  clip-path: polygon(
    0% 6%, 8% 2%, 16% 5%, 24% 1%, 32% 4%, 40% 2%, 48% 5%, 56% 1%, 64% 3%, 72% 5%, 80% 1%, 88% 4%, 96% 2%, 100% 6%,
    100% 100%, 88% 100%, 76% 100%, 64% 100%, 52% 100%, 40% 100%, 28% 100%, 16% 100%, 4% 100%, 0% 100%
  );
}

/* Watermark layer on alternate panels */
.parchment-vellum::after,
.panel-coda::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    radial-gradient(circle at 25% 30%, rgba(58, 10, 20, 0.06) 0%, transparent 12%),
    radial-gradient(circle at 75% 60%, rgba(107, 18, 38, 0.05) 0%, transparent 14%),
    radial-gradient(circle at 50% 85%, rgba(58, 10, 20, 0.04) 0%, transparent 10%);
  opacity: 0.7;
}

/* Negative-margin overlap so panels appear to bleed into each other */
.panel + .panel {
  margin-top: -80px;
}

/* === PRELUDE styling === */
.panel-prelude .panel-inner {
  text-align: left;
  min-height: 70vh;
  position: relative;
}
.prelude-monogram {
  grid-column: 2 / 4;
  position: relative;
  width: 220px;
  height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
  transform: rotate(-4deg);
}
.monogram-svg {
  width: 100%;
  height: 100%;
  display: block;
  position: relative;
  z-index: 2;
  animation: monogram-drift 8s ease-in-out infinite;
}
.monogram-svg.small {
  width: 80px;
  height: 80px;
}
@keyframes monogram-drift {
  0%, 100% { transform: translateY(0) rotate(-1deg); }
  50% { transform: translateY(-6px) rotate(2deg); }
}

.ripple-pool {
  position: absolute;
  inset: -40px;
  z-index: 1;
}
.ripple-ring {
  position: absolute;
  inset: 0;
  border: 1.5px solid var(--burgundy-velvet);
  border-radius: 52% 48% 51% 49% / 49% 52% 48% 51%;
  opacity: 0;
  animation: prelude-ripple 4s ease-out infinite;
}
.ripple-ring.r1 { animation-delay: 0s; }
.ripple-ring.r2 { animation-delay: 1.3s; }
.ripple-ring.r3 { animation-delay: 2.7s; }
@keyframes prelude-ripple {
  0%   { transform: scale(0.4); opacity: 0; border-width: 2px; }
  20%  { opacity: 0.55; }
  100% { transform: scale(1.6); opacity: 0; border-width: 0.4px; }
}

.prelude-title {
  grid-column: 1 / 7;
  font-family: 'Fraunces', serif;
  font-weight: 900;
  font-variation-settings: "opsz" 144, "SOFT" 80, "WONK" 1;
  font-size: clamp(56px, 12vw, 168px);
  line-height: 0.9;
  color: var(--burgundy-deep);
  letter-spacing: -0.025em;
  transform: rotate(-2deg) translateX(-2vw);
  margin-top: 20px;
  margin-bottom: 24px;
  font-style: italic;
}
.prelude-sub {
  grid-column: 2 / 6;
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  font-size: clamp(18px, 2.4vw, 26px);
  color: var(--burgundy-velvet);
  transform: rotate(1.5deg);
  margin-bottom: 36px;
  line-height: 1.45;
}
.prelude-quote {
  grid-column: 1 / 5;
  font-family: 'Cormorant Garamond', serif;
  font-size: clamp(20px, 2.6vw, 30px);
  font-style: italic;
  color: var(--burgundy-deep);
  border-left: 2px solid var(--burgundy-crimson);
  padding-left: 22px;
  margin-top: 28px;
  transform: rotate(-1deg);
  line-height: 1.4;
  position: relative;
}

/* Illuminated capital */
.illuminated {
  font-family: 'Fraunces', serif;
  font-weight: 900;
  font-style: italic;
  font-size: 3.2em;
  float: left;
  line-height: 0.85;
  padding-right: 8px;
  padding-top: 6px;
  color: var(--burgundy-velvet);
  background: linear-gradient(135deg, var(--sunlight) 0%, var(--burgundy-velvet) 70%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-shadow: 0 0 0 transparent;
}
.illuminated-warm {
  background: linear-gradient(135deg, var(--sunlight) 0%, var(--parchment) 80%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* === Specimen sections === */
.specimen-header {
  grid-column: 1 / 7;
  position: relative;
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 14px;
  margin-bottom: 24px;
  transform: rotate(-1deg);
}
.specimen-header.on-dark { color: var(--parchment); }

.specimen-roman {
  font-family: 'Fraunces', serif;
  font-style: italic;
  font-weight: 700;
  font-size: clamp(48px, 7vw, 110px);
  color: var(--burgundy-crimson);
  letter-spacing: -0.03em;
  line-height: 1;
  text-shadow: 2px 3px 0 rgba(58, 10, 20, 0.12);
}
.specimen-header.on-dark .specimen-roman { color: var(--sunlight); }

.specimen-title {
  font-family: 'Fraunces', serif;
  font-style: italic;
  font-weight: 700;
  font-variation-settings: "opsz" 144, "SOFT" 50, "WONK" 1;
  font-size: clamp(34px, 5vw, 72px);
  color: var(--burgundy-deep);
  line-height: 0.95;
  letter-spacing: -0.02em;
  transform: rotate(2deg);
  flex: 1 1 auto;
  min-width: 280px;
}
.specimen-header.on-dark .specimen-title { color: var(--parchment); }

.specimen-aka {
  font-size: 22px;
  color: var(--burgundy-velvet);
  flex: 0 1 auto;
}
.specimen-header.on-dark .specimen-aka { color: var(--sunlight); }

.specimen-figure {
  position: relative;
  margin: 24px 0;
}
.figure-left  { grid-column: 1 / 4; transform: rotate(-3deg); }
.figure-right { grid-column: 4 / 7; transform: rotate(3deg); }
.figure-center{ grid-column: 2 / 6; transform: rotate(-1deg); }

.specimen-art {
  width: 100%;
  height: auto;
  max-height: 420px;
  display: block;
  filter: drop-shadow(2px 3px 0 rgba(58, 10, 20, 0.1));
}
.specimen-figure.on-dark .specimen-art {
  filter: drop-shadow(2px 3px 0 rgba(0, 0, 0, 0.4));
}
.specimen-figure.on-dark .specimen-art g[stroke="#1F0509"] {
  /* On dark background we use a CSS hack — actually we'll let the icon inherit. Drawn lines remain dark. */
}

.specimen-figure figcaption {
  text-align: center;
  margin-top: 12px;
  transform: rotate(-1deg);
  font-size: 18px;
  color: var(--burgundy-velvet);
}
.specimen-figure figcaption.on-dark { color: var(--sunlight); }

.creature-large { max-height: 520px; }

.specimen-prose {
  grid-column: 1 / 5;
  font-size: 19px;
  color: var(--burgundy-deep);
  transform: rotate(0.6deg);
  text-indent: 0;
}
.specimen-prose.on-dark { color: var(--parchment); }
.specimen-prose p {
  margin-bottom: 18px;
  text-indent: 1.2em;
}
.specimen-prose p:first-child {
  text-indent: 0;
}
.specimen-prose .aside-prose {
  font-style: italic;
  font-size: 17px;
  color: var(--burgundy-velvet);
  border-top: 1px dashed rgba(166, 38, 61, 0.4);
  padding-top: 12px;
  margin-top: 12px;
  text-indent: 0;
}
.specimen-prose.on-dark .aside-prose {
  color: var(--vellum);
  border-top-color: rgba(242, 166, 90, 0.35);
}

/* When figure is on right, prose takes left columns */
.panel-i .specimen-prose { grid-column: 4 / 7; transform: rotate(-0.8deg); }
.panel-ii .specimen-prose { grid-column: 1 / 4; }
.panel-iii .specimen-prose { grid-column: 1 / 7; margin-top: 8px; }
.panel-iv .specimen-prose { grid-column: 1 / 4; }

.specimen-quote {
  grid-column: 2 / 6;
  font-family: 'Fraunces', serif;
  font-style: italic;
  font-weight: 400;
  font-size: clamp(22px, 2.8vw, 32px);
  color: var(--burgundy-velvet);
  margin: 28px 0 12px;
  border-left: 2px solid var(--burgundy-crimson);
  padding-left: 22px;
  transform: rotate(-1.2deg);
  line-height: 1.32;
}

/* === Marginalia === */
.marginalia {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: 'Caveat', cursive;
  font-size: 22px;
  color: var(--burgundy-velvet);
  position: relative;
  margin: 12px 0;
}
.caveat-script {
  display: inline-block;
  transform: rotate(var(--rot, 0deg));
  font-family: 'Caveat', cursive;
  color: var(--burgundy-velvet);
}
.margin-1 { grid-column: 4 / 7; transform: rotate(3deg); margin-top: 12px; }
.margin-right { grid-column: 4 / 7; justify-content: flex-end; }
.margin-left { grid-column: 1 / 4; }
.margin-bottom { grid-column: 1 / 7; justify-content: center; margin-top: 28px; }

.marginalia.on-dark .caveat-script { color: var(--sunlight); }

.margin-arrow {
  width: 80px;
  height: 36px;
  display: inline-block;
  vertical-align: middle;
}

.inkblot-anchor {
  width: 36px;
  height: 36px;
  display: inline-block;
  flex-shrink: 0;
}
.inkblot-anchor.small { width: 24px; height: 24px; }

/* === Wax seal badges === */
.wax-badge {
  grid-column: 5 / 7;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 24px;
  transform: rotate(-4deg);
  justify-self: end;
  cursor: pointer;
  transition: transform 400ms cubic-bezier(0.34, 1.2, 0.64, 1);
}
.wax-badge:hover {
  transform: rotate(2deg) scale(1.06);
}
.wax-badge-dark { grid-column: 1 / 3; }
.wax-svg {
  width: 64px;
  height: 64px;
  display: block;
  flex-shrink: 0;
  filter: drop-shadow(2px 2px 0 rgba(0, 0, 0, 0.18));
}
.wax-text {
  font-size: 18px;
  color: var(--burgundy-velvet);
  white-space: nowrap;
}
.wax-badge-dark .wax-text { color: var(--sunlight); }

/* === Coda === */
.coda-header {
  grid-column: 1 / 7;
  margin-bottom: 24px;
  transform: rotate(-1deg);
}
.coda-header .caveat-script {
  display: block;
  font-size: 24px;
  margin-bottom: 8px;
  color: var(--burgundy-crimson);
}
.coda-title {
  font-family: 'Fraunces', serif;
  font-style: italic;
  font-weight: 800;
  font-size: clamp(40px, 6vw, 88px);
  color: var(--burgundy-deep);
  letter-spacing: -0.025em;
  line-height: 0.95;
  transform: rotate(1.5deg);
}
.coda-prose {
  grid-column: 1 / 5;
  font-size: 20px;
  color: var(--burgundy-deep);
  transform: rotate(-0.6deg);
}
.coda-prose p {
  margin-bottom: 16px;
  text-indent: 1.2em;
}
.coda-prose p:first-child { text-indent: 0; }
.coda-sign {
  font-family: 'Fraunces', serif;
  font-style: italic;
  font-size: 24px;
  color: var(--burgundy-velvet);
  margin-top: 22px;
  text-indent: 0;
}
.coda-monogram {
  grid-column: 5 / 7;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  transform: rotate(4deg);
  margin-top: 16px;
}
.coda-sign-name {
  font-size: 22px;
  color: var(--burgundy-velvet);
  text-align: center;
}

/* === Staggered letter animation === */
[data-stagger] {
  display: inline-block;
}
[data-stagger] .stagger-letter {
  display: inline-block;
  opacity: 0;
  transform: rotate(-15deg) translateY(20px);
  transition: opacity 600ms cubic-bezier(0.34, 1.2, 0.64, 1),
              transform 600ms cubic-bezier(0.34, 1.2, 0.64, 1);
}
[data-stagger].visible .stagger-letter {
  opacity: 1;
  transform: rotate(var(--letter-tilt, 0deg)) translateY(0);
}

/* === Paragraph fade-up on visible === */
.specimen-prose p,
.coda-prose p,
.specimen-quote,
.prelude-quote,
.prelude-sub,
.marginalia,
.specimen-figure,
.wax-badge,
.coda-monogram {
  opacity: 0;
  transform: translateY(28px) rotate(var(--enter-rot, 0deg));
  transition: opacity 900ms cubic-bezier(0.34, 1.2, 0.64, 1),
              transform 900ms cubic-bezier(0.34, 1.2, 0.64, 1);
}
.panel.visible .specimen-prose p,
.panel.visible .coda-prose p,
.panel.visible .specimen-quote,
.panel.visible .prelude-quote,
.panel.visible .prelude-sub,
.panel.visible .marginalia,
.panel.visible .specimen-figure,
.panel.visible .wax-badge,
.panel.visible .coda-monogram {
  opacity: 1;
  transform: translateY(0) rotate(var(--final-rot, 0deg));
  transition-delay: var(--enter-delay, 0ms);
}
/* preserve original rotations on visible state for elements that had transforms */
.panel.visible .specimen-figure.figure-left  { transform: translateY(0) rotate(-3deg); }
.panel.visible .specimen-figure.figure-right { transform: translateY(0) rotate(3deg); }
.panel.visible .specimen-figure.figure-center{ transform: translateY(0) rotate(-1deg); }
.panel.visible .prelude-quote { transform: translateY(0) rotate(-1deg); }
.panel.visible .prelude-sub { transform: translateY(0) rotate(1.5deg); }
.panel.visible .specimen-quote { transform: translateY(0) rotate(-1.2deg); }
.panel.visible .wax-badge { transform: translateY(0) rotate(-4deg); }
.panel.visible .wax-badge:hover { transform: translateY(0) rotate(2deg) scale(1.06); }
.panel.visible .coda-monogram { transform: translateY(0) rotate(4deg); }
.panel.visible .margin-1 { transform: translateY(0) rotate(3deg); }

/* === Responsive === */
@media (max-width: 900px) {
  :root { --rail-width: 0px; }
  .manuscript { padding-left: 0; }
  .rail {
    width: 100%;
    height: 48px;
    bottom: 0;
    top: auto;
    flex-direction: row;
    padding: 0 16px;
    background: linear-gradient(to top, rgba(244, 233, 216, 0.95), rgba(244, 233, 216, 0.6));
    backdrop-filter: blur(2px);
    transform: rotate(-1deg);
    transform-origin: center;
  }
  .rail-line {
    left: 16px; right: 16px; top: 50%; bottom: auto;
    width: auto; height: 1px;
    background: linear-gradient(to right, transparent, var(--burgundy-velvet), transparent);
  }
  .rail-marks {
    flex-direction: row;
    justify-content: space-between;
    width: 100%;
    height: 100%;
    padding: 0;
  }
  .rail-marks li::before { left: 50%; top: 50%; }
  .rail-marks .numeral { margin-left: 0; margin-bottom: 0; }
  .rail-marks .label { display: none; }

  .panel { padding: 100px 6vw 120px; }
  .panel-inner { grid-template-columns: 1fr; gap: 20px; }
  .prelude-monogram, .prelude-title, .prelude-sub, .prelude-quote,
  .specimen-header, .specimen-figure, .specimen-prose, .specimen-quote,
  .marginalia, .wax-badge, .coda-header, .coda-prose, .coda-monogram {
    grid-column: 1 / 2;
  }
  .prelude-monogram { width: 160px; height: 160px; margin: 0 auto; }
  .figure-left, .figure-right, .figure-center { transform: rotate(-1deg); }
  .wax-badge { justify-self: start; }
  .compass-rose { right: 14px; bottom: 64px; width: 52px; height: 52px; }
  .compass-svg { width: 36px; height: 36px; }
}

/* Reduced motion: kill all the motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .monogram-svg { animation: none; }
  .ripple-ring { animation: none; opacity: 0; }
  .compass-svg { animation: none; }
}
