/* =========================================================
   thesecond.world  -- watercolor atlas of an alternate Earth
   ========================================================= */

:root {
    /* Palette */
    --parchment: #F5EDE3;
    --burnt-umber: #2C1810;
    --warm-walnut: #4A3728;
    --raw-sienna: #C4956A;
    --umber-shadow: #6B3A2A;
    --muted-bronze: #8B7355;
    --amber-light: #D4A574;
    --indigo-depth: #2A2845;

    /* Membrane wash properties (driven by JS scroll progress) */
    --wash-progress: 0;
    --wash-temp: 30;          /* hue shift in degrees */
    --wash-saturation: 36%;
    --wash-lightness: 60%;
    --wash-opacity: 0.15;
    --wash-deep-opacity: 0.0;

    /* Terminal indigo bleed */
    --terminal-progress: 0;

    /* Glyph scroll-progress driver */
    --glyph-progress: 0;
}

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

html, body {
    background: var(--parchment);
    color: var(--warm-walnut);
    font-family: "Lora", Georgia, serif;
    font-size: clamp(1rem, 1.25vw, 1.2rem);
    line-height: 1.75;
    letter-spacing: 0.005em;
    overflow-x: hidden;
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    position: relative;
    min-height: 100vh;
    background:
        linear-gradient(
            180deg,
            var(--parchment) 0%,
            #F1E5D5 35%,
            #EFDFCA 60%,
            #EBD8BF 85%,
            color-mix(in oklab, var(--parchment) calc(100% - var(--terminal-progress) * 80%), var(--indigo-depth) calc(var(--terminal-progress) * 80%)) 100%
        );
    transition: background 0.4s linear;
}

/* =========================================================
   THE MEMBRANE LAYER  (z-index 0)
   Persistent watercolor wash behind everything.
   ========================================================= */
.membrane {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
    opacity: 0;
    animation: membraneBloom 1.5s ease-out 0.4s forwards;
}

@keyframes membraneBloom {
    from { opacity: 0; }
    to { opacity: 1; }
}

.wash {
    position: absolute;
    border-radius: 50%;
    mix-blend-mode: multiply;
    will-change: transform, opacity;
    filter: blur(60px);
}

/* Top warm raw-sienna -- biggest spread */
.wash-a {
    top: -20vh;
    left: -10vw;
    width: 80vw;
    height: 80vw;
    background: radial-gradient(
        circle at 50% 50%,
        rgba(196, 149, 106, calc(0.18 - var(--wash-progress) * 0.08)) 0%,
        rgba(196, 149, 106, calc(0.10 - var(--wash-progress) * 0.05)) 35%,
        rgba(196, 149, 106, 0) 70%
    );
    animation: driftA 42s ease-in-out infinite alternate;
}

/* Mid warm-amber -- medium spread, drifts to the right */
.wash-b {
    top: 30vh;
    right: -15vw;
    width: 60vw;
    height: 60vw;
    background: radial-gradient(
        circle at 50% 50%,
        rgba(212, 165, 116, calc(0.14 + var(--wash-progress) * 0.04)) 0%,
        rgba(212, 165, 116, calc(0.07 + var(--wash-progress) * 0.02)) 40%,
        rgba(212, 165, 116, 0) 75%
    );
    animation: driftB 50s ease-in-out infinite alternate;
}

/* Mid-low umber -- intensifies on scroll */
.wash-c {
    top: 60vh;
    left: 20vw;
    width: 70vw;
    height: 70vw;
    background: radial-gradient(
        circle at 50% 50%,
        rgba(107, 58, 42, calc(0.04 + var(--wash-progress) * 0.10)) 0%,
        rgba(107, 58, 42, calc(0.02 + var(--wash-progress) * 0.05)) 45%,
        rgba(107, 58, 42, 0) 80%
    );
    animation: driftC 56s ease-in-out infinite alternate;
}

/* Bottom indigo -- the second-world bleed-through, only at the end */
.wash-d {
    bottom: -10vh;
    right: 5vw;
    width: 50vw;
    height: 50vw;
    background: radial-gradient(
        circle at 50% 50%,
        rgba(42, 40, 69, calc(var(--terminal-progress) * 0.18)) 0%,
        rgba(42, 40, 69, calc(var(--terminal-progress) * 0.09)) 45%,
        rgba(42, 40, 69, 0) 80%
    );
    animation: driftD 48s ease-in-out infinite alternate;
}

@keyframes driftA {
    0%   { transform: translate3d(0, 0, 0) scale(1); }
    100% { transform: translate3d(6vw, 4vh, 0) scale(1.06); }
}
@keyframes driftB {
    0%   { transform: translate3d(0, 0, 0) scale(1); }
    100% { transform: translate3d(-7vw, 5vh, 0) scale(1.08); }
}
@keyframes driftC {
    0%   { transform: translate3d(0, 0, 0) scale(1); }
    100% { transform: translate3d(5vw, -4vh, 0) scale(1.05); }
}
@keyframes driftD {
    0%   { transform: translate3d(0, 0, 0) scale(1); }
    100% { transform: translate3d(-4vw, -3vh, 0) scale(1.07); }
}

/* Paper-grain noise overlay -- inline SVG via data URI to avoid extra request */
.paper-grain {
    position: absolute;
    inset: 0;
    pointer-events: none;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='220' height='220'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.17  0 0 0 0 0.09  0 0 0 0 0.06  0 0 0 0.6 0'/></filter><rect width='100%' height='100%' filter='url(%23n)' opacity='0.55'/></svg>");
    opacity: 0.05;
    mix-blend-mode: multiply;
}

/* =========================================================
   GHOST GLYPH at top of page
   ========================================================= */
.ghost-glyph {
    position: absolute;
    top: 14vh;
    left: 50%;
    transform: translateX(-50%);
    width: clamp(280px, 38vw, 460px);
    aspect-ratio: 5 / 3;
    pointer-events: none;
    z-index: 1;
    opacity: 0;
    animation: ghostFade 1.8s ease-out 1.0s forwards;
}

.ghost-glyph svg {
    width: 100%;
    height: 100%;
    display: block;
}

@keyframes ghostFade {
    from { opacity: 0; }
    to   { opacity: 0.15; }
}

/* =========================================================
   ATLAS  (main scrolling container)
   ========================================================= */
.atlas {
    position: relative;
    z-index: 2;
    width: 100%;
    overflow: hidden;
}

/* =========================================================
   OPENING SECTION
   ========================================================= */
.opening {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding: 18vh 8vw 12vh 12vw;
    position: relative;
}

.opening-inner {
    max-width: clamp(340px, 60vw, 760px);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    padding: 1.2rem 0;
}

.title {
    font-family: "Cormorant Garamond", "Cormorant", Georgia, serif;
    font-weight: 300;
    font-size: clamp(3rem, 7vw, 6rem);
    line-height: 1.05;
    letter-spacing: -0.02em;
    color: var(--burnt-umber);
    margin-bottom: 2.6rem;
    white-space: nowrap;
}

.title .ch {
    display: inline-block;
    opacity: 0;
    transform: translateY(14px);
    animation: charDrift 0.9s ease-out forwards;
    animation-delay: calc(0.6s + var(--i) * 40ms);
}

.title-frag { display: inline-block; }

.title-dot {
    display: inline-block;
    color: var(--indigo-depth);
    transform: translateY(-0.05em);
    margin: 0 0.04em;
    opacity: 0;
    animation: charDrift 1.1s ease-out forwards;
    animation-delay: 0.95s;
    text-shadow: 0 0 22px rgba(42, 40, 69, 0.18);
}

@keyframes charDrift {
    0%   { opacity: 0; transform: translateY(14px); }
    100% { opacity: 1; transform: translateY(0); }
}

.lede {
    font-family: "Lora", Georgia, serif;
    font-weight: 400;
    font-size: clamp(1.05rem, 1.4vw, 1.35rem);
    line-height: 1.7;
    color: var(--warm-walnut);
    max-width: 56ch;
    opacity: 0;
    transform: translateY(12px);
    animation: ledeRise 0.8s ease-out 1.6s forwards;
}

@keyframes ledeRise {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

.opening-meta {
    margin-top: 4rem;
    font-family: "Inter", "Helvetica Neue", sans-serif;
    font-weight: 300;
    font-size: clamp(0.7rem, 0.9vw, 0.85rem);
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--muted-bronze);
    opacity: 0;
    animation: ledeRise 0.8s ease-out 2.0s forwards;
}

/* =========================================================
   THRESHOLD SECTIONS
   60vh atmospheric breathing pauses, single SVG path-draw.
   ========================================================= */
.threshold {
    min-height: 60vh;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    padding: 4vh 0;
    overflow: hidden;
}

.threshold::before {
    /* localized intensification of wash */
    content: "";
    position: absolute;
    inset: -10% -10%;
    background: radial-gradient(
        ellipse at center,
        rgba(196, 149, 106, 0.10) 0%,
        rgba(196, 149, 106, 0.04) 40%,
        rgba(196, 149, 106, 0) 70%
    );
    pointer-events: none;
    z-index: -1;
}

.threshold-topo::before,
.threshold-spiral::before {
    background: radial-gradient(
        ellipse at center,
        rgba(107, 58, 42, 0.10) 0%,
        rgba(107, 58, 42, 0.04) 45%,
        rgba(107, 58, 42, 0) 75%
    );
}

.threshold-final-horizon::before {
    background: radial-gradient(
        ellipse at center,
        rgba(42, 40, 69, 0.10) 0%,
        rgba(42, 40, 69, 0.04) 45%,
        rgba(42, 40, 69, 0) 80%
    );
}

.contour-line {
    width: 100%;
    height: 100%;
    max-width: 1200px;
    max-height: 360px;
}

.contour-horizon, .contour-wave {
    width: 100%;
    height: 200px;
}

.contour-topo, .contour-spiral {
    width: clamp(260px, 40vw, 600px);
    height: clamp(220px, 32vw, 380px);
}

.contour-network {
    width: 100%;
    height: 280px;
}

/* When threshold is in view, contour paths animate */
.threshold.is-visible .contour-line path {
    animation: drawPath 2.5s ease-in-out forwards;
}

.threshold.is-visible .contour-line path:nth-child(2) { animation-delay: 0.4s; }
.threshold.is-visible .contour-line path:nth-child(3) { animation-delay: 0.8s; }
.threshold.is-visible .contour-line path:nth-child(4) { animation-delay: 1.2s; }
.threshold.is-visible .contour-line path:nth-child(5) { animation-delay: 1.6s; }

@keyframes drawPath {
    to { stroke-dashoffset: 0; }
}

/* =========================================================
   ISLANDS (asymmetric drift)
   ========================================================= */
.island {
    width: 100%;
    padding: 8vh 0;
    position: relative;
}

.island-body, .island-head, .meta {
    max-width: clamp(340px, 55vw, 680px);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}

.island-1 { padding-left: 12vw; padding-right: 8vw; }
.island-2 { padding-left: 28vw; padding-right: 6vw; }
.island-3 { padding-left: 8vw;  padding-right: 12vw; }
.island-4 { padding-left: 22vw; padding-right: 8vw; }

.island-head {
    margin-bottom: 1.6rem;
    opacity: 0;
    transform: translateY(20px);
}

.island.is-visible .island-head {
    animation: islandRise 0.6s ease-out 0s forwards;
}

.island h2 {
    font-family: "Cormorant Garamond", "Cormorant", Georgia, serif;
    font-weight: 400;
    font-size: clamp(2.4rem, 5.5vw, 5rem);
    line-height: 1.12;
    letter-spacing: -0.02em;
    color: var(--burnt-umber);
    margin-bottom: 0.5rem;
}

.rule {
    width: clamp(60px, 10vw, 120px);
    height: 12px;
    display: block;
}

.island.is-visible .rule path {
    animation: drawRule 1.0s ease-out 0.4s forwards;
}

@keyframes drawRule {
    to { stroke-dashoffset: 0; }
}

.island-body {
    opacity: 0;
    transform: translateY(20px);
}

.island.is-visible .island-body {
    animation: islandRise 0.7s ease-out 0.2s forwards;
}

.island-body p {
    margin-bottom: 1.2rem;
    color: var(--warm-walnut);
}

.island-body p:last-child { margin-bottom: 0; }

.dropcap {
    float: left;
    font-family: "Cormorant Garamond", "Cormorant", Georgia, serif;
    font-weight: 600;
    font-size: 3.5em;
    line-height: 0.8;
    margin-right: 0.08em;
    margin-top: 0.05em;
    color: var(--raw-sienna);
}

.meta {
    margin-top: 2rem;
    font-family: "Inter", "Helvetica Neue", sans-serif;
    font-weight: 300;
    font-size: clamp(0.7rem, 0.9vw, 0.85rem);
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--muted-bronze);
    opacity: 0;
    transform: translateY(20px);
}

.island.is-visible .meta {
    animation: islandRise 0.6s ease-out 0.35s forwards;
}

@keyframes islandRise {
    from { opacity: 0; transform: translateY(20px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Subtle background glyph drift in islands */
.island-2::after, .island-4::after {
    content: "";
    position: absolute;
    top: 50%;
    right: -6vw;
    width: 26vw;
    height: 26vw;
    background:
        radial-gradient(circle at 30% 50%, transparent 30%, rgba(139, 115, 85, 0.06) 31%, transparent 32%),
        radial-gradient(circle at 70% 50%, transparent 30%, rgba(139, 115, 85, 0.06) 31%, transparent 32%);
    transform: translateY(-50%);
    pointer-events: none;
    opacity: 0.7;
    z-index: -1;
}

.island-1::after, .island-3::after {
    content: "";
    position: absolute;
    top: 30%;
    left: -8vw;
    width: 22vw;
    height: 22vw;
    background: radial-gradient(circle at center, transparent 38%, rgba(196, 149, 106, 0.10) 39%, transparent 41%, rgba(196, 149, 106, 0.06) 60%, transparent 62%);
    pointer-events: none;
    z-index: -1;
}

/* =========================================================
   TERMINAL CONVERGENCE
   ========================================================= */
.terminal {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 14vh 6vw;
    position: relative;
}

.terminal-glyph {
    width: clamp(200px, 30vw, 400px);
    aspect-ratio: 5 / 3;
    margin-bottom: 4rem;
    opacity: 0;
    transform: scale(calc(0.9 + var(--glyph-progress) * 0.1));
    transition: opacity 1.4s ease-out;
    animation: terminalRotate 120s linear infinite;
}

.terminal.is-visible .terminal-glyph {
    opacity: 1;
}

.terminal-glyph svg {
    width: 100%;
    height: 100%;
    display: block;
}

@keyframes terminalRotate {
    from { transform: scale(calc(0.9 + var(--glyph-progress) * 0.1)) rotate(0deg); }
    to   { transform: scale(calc(0.9 + var(--glyph-progress) * 0.1)) rotate(360deg); }
}

.terminal-phrase {
    font-family: "Cormorant Garamond", "Cormorant", Georgia, serif;
    font-weight: 300;
    font-size: clamp(2rem, 4.5vw, 4rem);
    line-height: 1.25;
    letter-spacing: -0.015em;
    color: var(--burnt-umber);
    max-width: 22ch;
}

.terminal-phrase .line {
    display: block;
    opacity: 0;
    transform: translateY(20px);
}

.terminal.is-visible .line {
    animation: islandRise 1.1s ease-out forwards;
}

.terminal.is-visible .line:nth-child(1) { animation-delay: 0.2s; }
.terminal.is-visible .line:nth-child(2) { animation-delay: 0.7s; }
.terminal.is-visible .line:nth-child(3) { animation-delay: 1.2s; }

.terminal-meta {
    margin-top: 4rem;
    font-family: "Inter", "Helvetica Neue", sans-serif;
    font-weight: 300;
    font-size: clamp(0.7rem, 0.9vw, 0.85rem);
    letter-spacing: 0.22em;
    text-transform: uppercase;
    color: var(--muted-bronze);
    opacity: 0;
}

.terminal.is-visible .terminal-meta {
    animation: islandRise 1.0s ease-out 1.8s forwards;
}

/* =========================================================
   RESPONSIVE
   ========================================================= */
@media (max-width: 720px) {
    .opening { padding: 14vh 6vw 8vh 6vw; }
    .island-1, .island-2, .island-3, .island-4 {
        padding-left: 6vw;
        padding-right: 6vw;
    }
    .ghost-glyph { top: 10vh; width: 70vw; }
    .terminal { padding: 10vh 6vw; }
    .title { font-size: clamp(2.4rem, 12vw, 4rem); }
}

/* =========================================================
   REDUCED MOTION
   ========================================================= */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.001s !important;
        animation-delay: 0s !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001s !important;
    }
    .membrane { opacity: 1; }
    .ghost-glyph { opacity: 0.15; }
    .island .island-head,
    .island .island-body,
    .island .meta,
    .terminal .terminal-glyph,
    .terminal .line,
    .terminal .terminal-meta,
    .lede,
    .opening-meta,
    .title .ch,
    .title-dot { opacity: 1; transform: none; }
    .contour-line path { stroke-dashoffset: 0 !important; }
}
