:root {
    /* Interaction (3% batch IntersectionObserver handles scroll-linked (no listeners IntersectionObserver` triggers. force-directed uses simple spring-force simulation vanilla JavaScript (~50 IntersectionObserver` `threshold: [0.1 0.1 (400 (Google (400i 400i */
    --deep-ocean: #0b1d2e;
    --tidal-slate: #2b3a4e;
    --coast-teal: #4a8b9c;
    --shore-mist: #c5cdd8;
    --driftwood: #e8dcc8;
    --shell-white: #f5f0e8;
    --foam: #7ec8d4;
    --kelp: #1a5c5e;
}

* { box-sizing: border-box; }

html {
    scroll-behavior: smooth;
    scroll-snap-type: y proximity;
    background: var(--shell-white);
}

body {
    margin: 0;
    overflow-x: hidden;
    font-family: "Cormorant Garamond", Georgia, serif;
    color: var(--tidal-slate);
    background: var(--shell-white);
    opacity: 0;
    transition: opacity 700ms ease;
}

body.fonts-ready { opacity: 1; }
body.no-font-api { opacity: 1; }

.scroll-story { width: 100%; }

.spread {
    min-height: 100vh;
    width: 100%;
    position: relative;
    overflow: hidden;
    scroll-snap-align: start;
    display: flex;
    padding: clamp(2rem, 5vw, 6rem);
    isolation: isolate;
}

.spread.light { background: var(--shell-white); color: var(--tidal-slate); }
.spread.dark { background: var(--deep-ocean); color: var(--shore-mist); }
.spread::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: -1px;
    height: 5vh;
    pointer-events: none;
    z-index: 3;
}
.spread.light::after { background: linear-gradient(to bottom, rgba(245,240,232,0), rgba(11,29,46,0.18)); }
.spread.dark::after { background: linear-gradient(to bottom, rgba(11,29,46,0), rgba(245,240,232,0.12)); }

.progress-track {
    position: fixed;
    top: 0;
    right: 0;
    width: 1px;
    height: 100vh;
    background: rgba(74, 139, 156, 0.26);
    z-index: 100;
}

.progress-fill {
    width: 1px;
    height: 0;
    background: var(--coast-teal);
    transition: height 120ms linear;
}

.progress-markers {
    position: fixed;
    top: 0;
    right: 10px;
    height: 100vh;
    z-index: 101;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 6vh 0;
}

.marker {
    width: 9px;
    height: 9px;
    padding: 0;
    border: 1px solid var(--coast-teal);
    background: var(--deep-ocean);
    transform: rotate(45deg);
    opacity: 0.42;
    cursor: pointer;
    transition: opacity 350ms ease, background 350ms ease, transform 350ms ease;
}

.marker.active {
    opacity: 1;
    background: var(--foam);
    transform: rotate(45deg) scale(1.25);
}

.grid-whisper {
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(90deg, rgba(197,205,216,0.15) 0.5px, transparent 0.5px),
        linear-gradient(0deg, rgba(197,205,216,0.15) 0.5px, transparent 0.5px);
    background-size: 61.8vw 61.8vh, 38.2vw 38.2vh;
    opacity: 0.55;
    pointer-events: none;
    z-index: -2;
}

.spread-left, .spread-right {
    position: relative;
    min-height: calc(100vh - clamp(4rem, 10vw, 12rem));
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.wide { flex: 0 0 55%; }
.narrow { flex: 0 0 45%; }
.half { flex: 0 0 50%; }

.text-pane {
    align-items: flex-start;
    padding-inline: clamp(2rem, 5vw, 6rem) clamp(1rem, 3vw, 4rem);
}

.text-pane p {
    max-width: 38ch;
    font-size: clamp(1.05rem, 1.4vw, 1.35rem);
    line-height: 1.85;
    margin: 0 0 1.8rem;
    color: var(--tidal-slate);
}

.dark .text-pane p { color: var(--shore-mist); }

h1, h2 {
    font-family: "Playfair Display", Didot, serif;
    font-weight: 900;
    letter-spacing: -0.03em;
    line-height: 0.95;
    margin: 0;
}

.text-pane h2 {
    max-width: 7.5ch;
    font-size: clamp(4rem, 12vw, 10rem);
    color: var(--deep-ocean);
    margin-bottom: 2.5rem;
}

.dark .text-pane h2 { color: var(--driftwood); }

.kicker {
    font-family: "JetBrains Mono", ui-monospace, monospace !important;
    color: var(--coast-teal) !important;
    letter-spacing: 0.28em;
    text-transform: uppercase;
    font-size: 0.78rem !important;
    line-height: 1 !important;
    margin-bottom: 2rem !important;
    border-left: 2px solid var(--coast-teal);
    padding-left: 1rem;
}

blockquote {
    font-family: "Playfair Display", Didot, serif;
    font-style: italic;
    font-size: clamp(1.6rem, 3vw, 2.4rem);
    line-height: 1.12;
    color: var(--coast-teal);
    max-width: 13ch;
    margin: 2.5rem 0 2.8rem -3vw;
}

.focus-element {
    opacity: 0.7;
    transform: scale(0.85);
    transition: transform 1200ms ease-out, opacity 1200ms ease-out;
}

.focus-element.in-focus {
    opacity: 1;
    transform: scale(1);
}

.blob {
    position: absolute;
    border-radius: 30% 70% 70% 30% / 30% 30% 70% 70%;
    background: linear-gradient(135deg, var(--coast-teal), var(--foam));
    animation: blobMorph 10s ease-in-out infinite, drift 18s ease-in-out infinite;
    will-change: border-radius, transform;
}

@keyframes blobMorph {
    0% { border-radius: 30% 70% 70% 30% / 30% 30% 70% 70%; }
    25% { border-radius: 58% 42% 55% 45% / 45% 60% 40% 55%; }
    50% { border-radius: 40% 60% 35% 65% / 55% 35% 65% 45%; }
    75% { border-radius: 65% 35% 50% 50% / 40% 55% 45% 60%; }
    100% { border-radius: 30% 70% 70% 30% / 30% 30% 70% 70%; }
}

@keyframes drift {
    0%, 100% { translate: 0 0; }
    50% { translate: 1.5rem -2rem; }
}

.ambient-blob {
    width: clamp(20rem, 36vw, 42rem);
    height: clamp(16rem, 31vw, 36rem);
    opacity: 0.08;
    z-index: -1;
}
.ghost-a { left: -11vw; bottom: -11vh; animation-duration: 12s, 24s; }
.ghost-b { right: -10vw; top: 7vh; opacity: 0.1; animation-duration: 9s, 20s; }

.spread-cover {
    align-items: flex-end;
    justify-content: flex-start;
    background:
        radial-gradient(circle at 78% 20%, rgba(126,200,212,0.32), transparent 34%),
        linear-gradient(135deg, var(--shell-white) 0%, var(--driftwood) 55%, rgba(126,200,212,0.52) 100%);
}

.cover-title {
    font-size: clamp(6rem, 14vw, 12rem);
    color: var(--deep-ocean);
    margin: 0 0 8vh 2vw;
    z-index: 2;
}

.cover-blob {
    width: clamp(14rem, 28vw, 34rem);
    height: clamp(12rem, 24vw, 28rem);
    top: 8vh;
    right: 10vw;
    opacity: 0.88;
    box-shadow: inset 0 0 4rem rgba(245,240,232,0.22);
}

.cover-blob span {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    font-family: "Playfair Display", serif;
    font-size: clamp(4rem, 9vw, 9rem);
    color: rgba(11,29,46,0.08);
    animation: lambdaGlimmer 10s ease-in-out infinite;
}

@keyframes lambdaGlimmer { 0%, 42%, 100% { opacity: 0; } 56% { opacity: 1; } }

.visual-pane { align-items: center; }

.expression-tree, .composition-flow, .history-line, .concept-graph {
    width: min(100%, 820px);
    height: auto;
    overflow: visible;
}

.tree-edge {
    fill: none;
    stroke: var(--coast-teal);
    stroke-width: 1.5;
    opacity: 0.58;
    stroke-dasharray: 9 12;
    animation: dashTide 12s linear infinite;
}

@keyframes dashTide { to { stroke-dashoffset: -160; } }

.dag-node { transform: translate(var(--x), var(--y)); transform-origin: center; animation: nodePulse 7s ease-in-out infinite; }
.dag-node ellipse { stroke: rgba(232,220,200,0.42); stroke-width: 1; }
.dag-node text { text-anchor: middle; dominant-baseline: central; font-family: "JetBrains Mono", monospace; font-size: 18px; fill: var(--deep-ocean); }
.dag-node.functor ellipse { fill: var(--coast-teal); }
.dag-node.monad ellipse { fill: var(--kelp); }
.dag-node.monad text { fill: var(--driftwood); }
.dag-node.base ellipse { fill: var(--shore-mist); }

@keyframes nodePulse { 0%,100% { scale: 1; opacity: 0.9; } 50% { scale: 1.045; opacity: 1; } }

.code-poem { gap: 1.1rem; align-items: flex-start; padding-left: clamp(1rem, 4vw, 5rem); }
.sig {
    display: block;
    font-family: "JetBrains Mono", ui-monospace, monospace;
    color: var(--coast-teal);
    border-left: 2px solid var(--coast-teal);
    padding-left: 1rem;
    font-size: clamp(0.78rem, 1.1vw, 1rem);
    letter-spacing: 0.01em;
    white-space: nowrap;
    transform-origin: left center;
}
.primary-sig { opacity: 1; scale: 1.18; color: var(--kelp); border-color: var(--kelp); margin: 0.8rem 0; }
.recede-1 { opacity: 0.72; scale: 0.94; }
.recede-2 { opacity: 0.46; scale: 0.86; }
.recede-3 { opacity: 0.26; scale: 0.78; }

.composition-flow path {
    fill: none;
    stroke: var(--coast-teal);
    stroke-width: 1.5;
    stroke-linecap: round;
    stroke-dasharray: 820;
    stroke-dashoffset: 820;
}
.composition-flow circle { fill: var(--foam); opacity: 0.9; }
.composition-flow .kelp { stroke: var(--kelp); }
.spread-purity.in-view .composition-flow path { animation: drawFlow 3s ease forwards; }
.spread-purity.in-view .delay-1 { animation-delay: 250ms; }
.spread-purity.in-view .delay-2 { animation-delay: 500ms; }
@keyframes drawFlow { to { stroke-dashoffset: 0; } }

.spread-composition { padding: 0; align-items: center; justify-content: center; }
.graph-stage { width: 100%; height: 100vh; position: relative; display: grid; place-items: center; }
.concept-graph { width: min(96vw, 1320px); height: min(76vh, 820px); }
.graph-edge { stroke: rgba(197,205,216,0.3); stroke-width: 1.2; fill: none; }
.graph-node { cursor: pointer; transition: opacity 300ms ease; }
.graph-node ellipse { fill: url(#unused); stroke: rgba(126,200,212,0.35); stroke-width: 1; }
.graph-node text { font-family: "JetBrains Mono", monospace; font-size: 15px; text-anchor: middle; dominant-baseline: central; fill: var(--driftwood); pointer-events: none; }
.graph-node:hover ellipse, .graph-node.active ellipse { fill: var(--foam); }
.graph-node:hover text, .graph-node.active text { fill: var(--deep-ocean); }
.central-lambda text { font-family: "Playfair Display", serif; font-size: 48px; }

.concept-card {
    position: absolute;
    right: clamp(2rem, 7vw, 8rem);
    bottom: clamp(2rem, 7vw, 6rem);
    width: min(22rem, 34vw);
    color: var(--shore-mist);
    font-size: clamp(1.05rem, 1.4vw, 1.25rem);
    line-height: 1.7;
}
.concept-name { font-family: "Playfair Display", serif; font-size: clamp(2.2rem, 5vw, 5rem); color: var(--driftwood); line-height: 1; }
.concept-card p { margin: 0.6rem 0 0; }

.history-line { width: min(100%, 520px); }
.time-spine, .time-branch {
    fill: none;
    stroke: var(--coast-teal);
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-dasharray: 900;
    stroke-dashoffset: 900;
}
.time-branch { stroke: var(--kelp); opacity: 0.72; }
.spread-monadic.in-view .time-spine, .spread-monadic.in-view .time-branch { animation: drawFlow 2.7s ease forwards; }
.time-node ellipse { fill: var(--driftwood); stroke: var(--coast-teal); stroke-width: 1; }
.time-node text { text-anchor: middle; dominant-baseline: central; font-family: "JetBrains Mono", monospace; font-size: 13px; fill: var(--deep-ocean); }
.spread-monadic .text-pane h2 { font-size: clamp(3.2rem, 8vw, 7rem); max-width: 8ch; }

.spread-coda {
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--deep-ocean), var(--coast-teal), var(--kelp));
    background-size: 300% 300%;
    animation: codaSea 30s ease-in-out infinite;
}
@keyframes codaSea { 0%,100% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } }
.lambda-watermark {
    position: absolute;
    font-family: "Playfair Display", serif;
    font-size: min(64vw, 44rem);
    color: var(--driftwood);
    opacity: 0.03;
    line-height: 1;
}
.coda-copy { text-align: center; }
.coda-copy h2 {
    font-family: "JetBrains Mono", ui-monospace, monospace;
    font-weight: 400;
    font-size: 1.2rem;
    letter-spacing: 0.4em;
    color: var(--driftwood);
    text-transform: lowercase;
}
.coda-copy p {
    font-family: "Playfair Display", serif;
    font-style: italic;
    font-size: clamp(1.25rem, 2vw, 1.8rem);
    color: var(--driftwood);
    margin-top: 1.4rem;
}

@media (max-width: 820px) {
    .spread { flex-direction: column; padding: 2rem; }
    .spread-left, .spread-right, .wide, .narrow, .half { flex: 1 1 auto; width: 100%; min-height: 42vh; }
    .text-pane { padding: 2rem 0; }
    .text-pane h2 { font-size: clamp(3rem, 17vw, 6rem); }
    .sig { white-space: normal; }
    .concept-card { width: auto; left: 2rem; right: 2rem; bottom: 2rem; }
    .cover-title { margin-left: 0; }
}
