:root {
  --ledger-ink: #172033;
  --glacial-vellum: #F7F4EA;
  --protocol-cyan: #34D6D3;
  --futures-violet: #7B5CFF;
  --margin-coral: #FF6B5F;
  --soft-graphite: #7E8494;
  --deep-field: #0C111C;
  --ink-blue: #263A66;
  --pale-cyan: #DDF7F4;
  --soft-violet: #D8D1FF;
  --warm-note: #FFF0D9;
}

* { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  background: var(--deep-field);
}

body {
  margin: 0;
  font-family: "Noto Sans", Inter, system-ui, sans-serif;
  color: var(--ledger-ink);
  background: linear-gradient(135deg, #F7F4EA 0%, #DDF7F4 34%, #D8D1FF 68%, #FFF0D9 100%);
  overflow-x: hidden;
}

.grain {
  position: fixed;
  inset: 0;
  z-index: 80;
  pointer-events: none;
  opacity: .25;
  background-image:
    radial-gradient(circle at 18% 12%, rgba(23,32,51,.08) 0 1px, transparent 1px),
    radial-gradient(circle at 78% 62%, rgba(255,107,95,.08) 0 1px, transparent 1px),
    linear-gradient(90deg, rgba(23,32,51,.025) 1px, transparent 1px);
  background-size: 9px 9px, 13px 13px, 47px 47px;
  mix-blend-mode: multiply;
}

.page-index {
  position: fixed;
  right: 24px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 100;
  display: grid;
  gap: 12px;
}

.page-mark {
  width: 34px;
  height: 12px;
  border-top: 1px solid rgba(23,32,51,.55);
  border-bottom: 1px solid rgba(23,32,51,.18);
  text-decoration: none;
  color: var(--ledger-ink);
  transition: width .35s ease, border-color .35s ease, color .35s ease;
  position: relative;
}

.page-mark span {
  position: absolute;
  right: 42px;
  top: -9px;
  font: 400 11px "Noto Serif", serif;
  opacity: 0;
  transition: opacity .3s ease;
}

.page-mark.active {
  width: 54px;
  border-top-color: var(--margin-coral);
  color: var(--margin-coral);
}

.page-mark.active span { opacity: 1; }

.aperture {
  position: fixed;
  left: var(--aperture-x, 62%);
  top: var(--aperture-y, 48%);
  width: clamp(170px, 19vw, 310px);
  aspect-ratio: 1;
  z-index: 70;
  pointer-events: none;
  transform: translate(-50%, -50%) scale(var(--aperture-scale, .86));
  filter: drop-shadow(0 28px 58px rgba(38,58,102,.22));
  transition: left .75s cubic-bezier(.2,.8,.2,1), top .75s cubic-bezier(.2,.8,.2,1);
}

.aperture::before {
  content: "";
  position: absolute;
  inset: 12%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(247,244,234,.68), rgba(52,214,211,.13) 55%, rgba(123,92,255,.08));
  backdrop-filter: blur(1px) saturate(1.35);
}

.aperture svg { position: relative; width: 100%; height: 100%; }
.lens-rim { fill: none; stroke: url(#apertureGradient); stroke-width: 4; stroke-dasharray: 8 12; animation: spinDash 12s linear infinite; }
.lens-specimen, .lens-arrow { fill: none; stroke: var(--ledger-ink); stroke-width: 4; stroke-linecap: round; }
.lens-arrow { stroke: var(--protocol-cyan); }
.lens-arrow-head { fill: none; stroke: var(--protocol-cyan); stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; }
.lens-node { fill: rgba(247,244,234,.78); stroke: var(--ledger-ink); stroke-width: 3; }
.lens-label { font: 700 25px Caveat, cursive; fill: var(--margin-coral); }

.scene {
  position: relative;
  min-height: 100vh;
  isolation: isolate;
  overflow: hidden;
  padding: clamp(32px, 6vw, 86px);
}

.definition {
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #F7F4EA 0%, #DDF7F4 34%, #D8D1FF 68%, #FFF0D9 100%);
}

.field-lines, .ruled-scroll {
  position: absolute;
  inset: 0;
  opacity: .45;
  background-image: linear-gradient(rgba(126,132,148,.18) 1px, transparent 1px), linear-gradient(90deg, rgba(126,132,148,.1) 1px, transparent 1px);
  background-size: 100% 58px, 70px 100%;
  transform: rotate(-1deg) scale(1.05);
}

.diagram {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
}

.diagram path, .diagram circle, .diagram line {
  vector-effect: non-scaling-stroke;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.definition-diagram { opacity: .86; }
.wobble, .bracket, .network, .proof-bracket, .book-page, .spine, .final-line {
  fill: none;
  stroke: var(--ledger-ink);
  stroke-width: 3;
}
.wobble { stroke: rgba(23,32,51,.45); }
.bracket { stroke: var(--margin-coral); stroke-width: 4; }
.bracket.right { stroke: var(--protocol-cyan); }
.arrow-head { fill: none; stroke: var(--ledger-ink); stroke-width: 4; }
.arrow-head.left { stroke: var(--soft-graphite); }
.specimen circle { fill: rgba(247,244,234,.5); stroke: var(--ledger-ink); stroke-width: 4; }
.specimen path { fill: none; stroke: var(--protocol-cyan); stroke-width: 4; }

.title-island {
  width: min(900px, 82vw);
  transform: translateX(-5vw) rotate(-.35deg);
}

.citation {
  font: italic 400 clamp(14px, 1.3vw, 19px) "Noto Serif", serif;
  color: var(--soft-graphite);
  margin: 0 0 18px;
}

h1 {
  margin: 0;
  font-size: clamp(64px, 14vw, 204px);
  line-height: .82;
  letter-spacing: -.08em;
  font-weight: 700;
  color: var(--ledger-ink);
}

h2 {
  margin: 0 0 18px;
  font-size: clamp(34px, 5.6vw, 86px);
  line-height: .9;
  letter-spacing: -.055em;
  font-weight: 700;
}

p { font-size: clamp(17px, 1.55vw, 24px); line-height: 1.48; }
.definition-copy { max-width: 710px; margin: 24px 0 0 auto; color: var(--ink-blue); }

.hand-note, .svg-hand {
  font-family: Caveat, cursive;
  font-weight: 700;
  color: var(--margin-coral);
  fill: var(--margin-coral);
  font-size: clamp(25px, 3vw, 48px);
  position: absolute;
  z-index: 3;
}

.note-a { left: 8vw; bottom: 16vh; transform: rotate(-8deg); }
.note-b { right: 12vw; top: 18vh; transform: rotate(7deg); color: var(--protocol-cyan); }
.note-c { left: 11vw; top: 23vh; transform: rotate(-6deg); color: var(--protocol-cyan); }
.note-d { right: 12vw; bottom: 12vh; transform: rotate(5deg); color: var(--warm-note); }

.ledger {
  min-height: 120vh;
  background: linear-gradient(100deg, rgba(255,240,217,.98), rgba(247,244,234,.88) 45%, rgba(221,247,244,.92));
}

.ruled-scroll {
  background-size: 100% 52px, 120px 100%;
  animation: driftLines 16s ease-in-out infinite alternate;
}

.ledger-diagram { width: 150%; left: -16%; opacity: .72; }
.ledger-columns path { fill: none; stroke: rgba(126,132,148,.55); stroke-width: 2; }
.tabs path { fill: rgba(255,107,95,.1); stroke: var(--margin-coral); stroke-width: 3; }
.coral { stroke: var(--margin-coral); stroke-width: 5; fill: none; }
.tick { fill: none; stroke: var(--protocol-cyan); stroke-width: 6; }

.marginalia {
  position: relative;
  max-width: 520px;
  padding: 26px 28px 28px;
  background: rgba(247,244,234,.58);
  border-left: 2px solid var(--margin-coral);
  box-shadow: 0 22px 80px rgba(38,58,102,.1);
  backdrop-filter: blur(5px);
}

.ledger-copy { margin: 15vh 0 0 53vw; transform: rotate(.8deg); }
.ledger-copy.secondary { margin: 19vh 0 0 10vw; transform: rotate(-.9deg); border-left-color: var(--protocol-cyan); max-width: 430px; }
.marginalia p { color: var(--ink-blue); margin: 0; }
.cite-no {
  display: inline-block;
  font: 600 18px "Noto Serif", serif;
  color: var(--margin-coral);
  margin-bottom: 12px;
}
.marginalia::after, .final-statement::after {
  content: "";
  position: absolute;
  left: 24px;
  right: 30%;
  bottom: 18px;
  height: 2px;
  background: var(--margin-coral);
  transform: rotate(-.8deg);
}

.lens-scene {
  display: flex;
  align-items: flex-end;
  min-height: 115vh;
  background: radial-gradient(circle at 70% 20%, #263A66 0%, #172033 56%, #0C111C 100%);
  color: var(--glacial-vellum);
}

.lens-scene::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at var(--mouse-x, 58%) var(--mouse-y, 44%), rgba(52,214,211,.22), transparent 26%), linear-gradient(135deg, transparent, rgba(123,92,255,.22));
}

.blur-veil {
  position: absolute;
  inset: 0;
  backdrop-filter: blur(2px);
  background: rgba(12,17,28,.18);
}

.microscope-map { opacity: .78; filter: blur(.4px); }
.network { stroke: var(--protocol-cyan); stroke-width: 4; }
.network.thin { stroke: rgba(216,209,255,.55); stroke-width: 2; fill: none; }
.glyphs circle, .glyphs path { fill: rgba(52,214,211,.08); stroke: var(--warm-note); stroke-width: 3; }
.proof-bracket { stroke: var(--margin-coral); stroke-width: 3; }
.svg-serif { font: italic 26px "Noto Serif", serif; fill: var(--warm-note); }

.lens-copy {
  margin: 0 0 10vh 6vw;
  max-width: 650px;
  color: var(--glacial-vellum);
  background: rgba(12,17,28,.26);
  border-left-color: var(--protocol-cyan);
}
.lens-copy p { color: rgba(247,244,234,.82); }
.lens-copy .cite-no { color: var(--protocol-cyan); }

.stack {
  min-height: 125vh;
  background: linear-gradient(135deg, #F7F4EA 0%, #DDF7F4 38%, #D8D1FF 76%, #FFF0D9 100%);
  perspective: 1400px;
}

.stack-orbit {
  position: absolute;
  width: 72vw;
  height: 72vw;
  left: 8vw;
  top: 6vh;
  border: 1px dashed rgba(23,32,51,.18);
  border-radius: 50%;
  animation: slowTurn 32s linear infinite;
}

.page-stack {
  position: relative;
  width: min(930px, 76vw);
  height: 680px;
  margin: 8vh auto 0;
  transform-style: preserve-3d;
  transform: rotateX(58deg) rotateZ(-8deg) translateY(40px);
}

.page-plane {
  position: absolute;
  width: 460px;
  min-height: 250px;
  padding: 28px 32px;
  background: rgba(247,244,234,.76);
  border: 1px solid rgba(23,32,51,.16);
  box-shadow: 0 24px 70px rgba(38,58,102,.18);
  transform-style: preserve-3d;
}
.page-plane h2 { font-size: clamp(34px, 4.4vw, 64px); }
.page-plane p { margin: 0; color: var(--ink-blue); }
.plane-one { left: 40px; top: 32px; transform: translateZ(120px) rotateZ(-4deg); }
.plane-two { right: 30px; top: 105px; transform: translateZ(86px) rotateZ(5deg); }
.plane-three { left: 180px; top: 292px; transform: translateZ(50px) rotateZ(2deg); }
.plane-four { right: 142px; top: 440px; transform: translateZ(20px) rotateZ(-5deg); }

.book-map { opacity: .42; }
.book-page { stroke: var(--ledger-ink); stroke-width: 3; fill: rgba(255,240,217,.2); }
.spine { stroke: var(--margin-coral); stroke-width: 3; fill: none; }

.footnote {
  min-height: 105vh;
  display: grid;
  place-items: center;
  color: var(--glacial-vellum);
  background: radial-gradient(circle at 18% 20%, rgba(255,107,95,.55), transparent 26%), radial-gradient(circle at 72% 12%, #263A66 0%, #172033 44%, #0C111C 100%);
}

.final-orbits { opacity: .8; }
.orbit { fill: none; stroke-width: 2; stroke-dasharray: 7 16; transform-origin: 650px 420px; }
.orbit-one { stroke: rgba(52,214,211,.48); animation: slowTurn 24s linear infinite; }
.orbit-two { stroke: rgba(255,240,217,.25); animation: slowTurn 36s linear infinite reverse; }
.final-line { stroke: var(--protocol-cyan); stroke-width: 5; }
.final-node { fill: rgba(247,244,234,.15); stroke: var(--warm-note); stroke-width: 4; }
.orbiting-note { fill: rgba(255,240,217,.12); stroke: var(--margin-coral); stroke-width: 2; }
.orbiting-note text { stroke: none; fill: var(--warm-note); font: 700 26px Caveat, cursive; }
.n1 { transform: translate(360px, 188px) rotate(-9deg); }
.n2 { transform: translate(884px, 228px) rotate(8deg); }
.n3 { transform: translate(925px, 612px) rotate(-5deg); }
.n4 { transform: translate(292px, 590px) rotate(7deg); }

.final-statement {
  position: relative;
  width: min(900px, 82vw);
  padding: 34px 38px 48px;
  background: rgba(12,17,28,.22);
  border-left: 2px solid var(--margin-coral);
  transform: rotate(-.45deg);
  backdrop-filter: blur(4px);
}
.final-statement h2 { color: var(--glacial-vellum); }
.final-statement p:last-child { color: rgba(247,244,234,.78); max-width: 760px; }

.draw-path {
  stroke-dasharray: 1200;
  stroke-dashoffset: 1200;
  animation: drawIn 3.6s ease forwards, livingStroke 7s ease-in-out infinite alternate 3.7s;
}
.draw-path.delay { animation-delay: .45s, 4.15s; }
.draw-path.slow { animation-duration: 5s, 8s; }

body.scrolled .draw-path { animation-play-state: running; }

@keyframes drawIn { to { stroke-dashoffset: 0; } }
@keyframes livingStroke { from { stroke-dashoffset: 0; } to { stroke-dashoffset: -42; } }
@keyframes spinDash { to { stroke-dashoffset: -240; } }
@keyframes driftLines { from { transform: translateX(-2vw) rotate(-1.2deg) scale(1.05); } to { transform: translateX(4vw) rotate(.7deg) scale(1.05); } }
@keyframes slowTurn { to { transform: rotate(360deg); } }

@media (max-width: 760px) {
  .scene { padding: 28px; }
  .page-index { right: 12px; }
  .aperture { width: 155px; }
  .title-island { transform: none; width: 92vw; }
  .definition-copy { margin-left: 0; }
  .ledger-copy, .ledger-copy.secondary { margin: 16vh 0 0; }
  .page-stack { width: 100%; height: 900px; transform: none; }
  .page-plane { position: relative; left: auto; right: auto; top: auto; width: min(100%, 460px); margin: 18px auto; transform: rotate(var(--r, 0deg)); }
  .plane-one { --r: -2deg; } .plane-two { --r: 2deg; } .plane-three { --r: -1deg; } .plane-four { --r: 1deg; }
}
