:root {
    --bg-primary: #f7f2ea;
    --bg-secondary: #f0ebe1;
    --bg-tertiary: #e2dacb;
    --text-primary: #5c5347;
    --text-display: #7a6e5d;
    --text-tertiary: #a89b85;
    --accent-gold: #c4a35a;
    --accent-gold-light: #d4b96a;
    --border: #c4b8a0;
    --data-stroke: #b8977a;
    --descent-unit: 2.4rem;
    --h-margin: max(3rem, 8vw);
}

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

html {
    scroll-behavior: smooth;
}

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-family: 'Karla', sans-serif;
    font-weight: 400;
    font-size: clamp(1rem, 1.8vw, 1.25rem);
    line-height: 1.72;
    letter-spacing: 0.01em;
    overflow-x: hidden;
}

/* Noise texture overlay */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 100;
    opacity: 0.03;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='300' height='300' filter='url(%23n)' opacity='1'/%3E%3C/svg%3E");
}

/* Stratum sections */
.stratum {
    min-height: 100vh;
    display: grid;
    place-items: center;
    position: relative;
    padding: calc(var(--descent-unit) * 2.618) var(--h-margin);
}

.stratum-odd {
    background-color: var(--bg-primary);
}

.stratum-even {
    background-color: var(--bg-secondary);
}

/* 80px gradient transitions between sections */
.stratum-even::before {
    content: '';
    position: absolute;
    top: -40px;
    left: 0;
    right: 0;
    height: 80px;
    background: linear-gradient(to bottom, var(--bg-primary), var(--bg-secondary));
    z-index: 1;
}

.stratum-odd + .kintsugi-seam + .stratum-odd::before,
.stratum-even + .kintsugi-seam + .stratum-even::before {
    content: '';
    position: absolute;
    top: -40px;
    left: 0;
    right: 0;
    height: 80px;
    background: linear-gradient(to bottom, var(--bg-secondary), var(--bg-primary));
    z-index: 1;
}

.stratum-content {
    max-width: 72rem;
    width: 100%;
    transform: translateX(-4%);
}

/* Section numerals */
.section-numeral {
    position: absolute;
    top: calc(var(--descent-unit) * 1);
    left: var(--h-margin);
    font-family: 'Playfair Display', serif;
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--text-display);
    opacity: 0.2;
}

/* Marginal notes */
.marginal-note {
    position: absolute;
    left: calc(var(--h-margin) * 0.35);
    top: 50%;
    transform: rotate(-90deg) translateX(-50%);
    transform-origin: left center;
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 300;
    font-size: 0.7rem;
    color: var(--text-tertiary);
    letter-spacing: 0.06em;
    white-space: nowrap;
    opacity: 0.5;
}

.marginal-note::after {
    content: attr(data-label);
}

/* Opening section */
#opening {
    min-height: 100vh;
}

.opening-content {
    text-align: center;
    transform: translateX(0);
}

.hero-word {
    font-family: 'Playfair Display', serif;
    font-weight: 700;
    font-size: clamp(8rem, 18vw, 16rem);
    color: var(--text-display);
    letter-spacing: -0.03em;
    line-height: 0.92;
    text-shadow: 1px 1px 0 #f5f0e8, -1px -1px 2px rgba(90, 80, 65, 0.15);
    opacity: 0;
    transform: translateY(-12px);
    animation: lower-in 1.8s cubic-bezier(0.25, 0.1, 0.25, 1) 0.2s forwards;
}

.hero-subtitle {
    font-family: 'Karla', sans-serif;
    font-weight: 400;
    font-size: 1.2rem;
    letter-spacing: 0.35em;
    text-transform: uppercase;
    color: var(--text-tertiary);
    margin-top: calc(var(--descent-unit) * 0.5);
    opacity: 0;
    animation: fade-in 1s cubic-bezier(0.25, 0.1, 0.25, 1) 2.6s forwards;
}

@keyframes lower-in {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fade-in {
    to {
        opacity: 1;
    }
}

/* Section headings */
.section-heading {
    font-family: 'Playfair Display', serif;
    font-weight: 700;
    font-size: clamp(3.2rem, 10vw, 9rem);
    color: var(--text-display);
    letter-spacing: -0.03em;
    line-height: 0.92;
    margin-bottom: calc(var(--descent-unit) * 1.618);
}

/* Prose */
.section-prose {
    max-width: 42ch;
    color: var(--text-primary);
    margin-top: calc(var(--descent-unit) * 1.618);
}

/* Visualizations */
.viz {
    width: 100%;
    max-height: 300px;
    display: block;
}

.seed-descent {
    max-height: 400px;
    width: 60%;
}

/* Skeleton loading */
.skeleton-group {
    display: flex;
    flex-direction: column;
    gap: calc(var(--descent-unit) * 1);
}

.skeleton {
    background-color: var(--bg-tertiary);
    border-radius: 4px;
    animation: skeleton-pulse 2s ease-in-out infinite;
}

.skeleton-title {
    width: 60%;
    height: 3.5rem;
}

.skeleton-viz {
    width: 100%;
    height: 200px;
}

.skeleton-text {
    width: 42ch;
    max-width: 100%;
    height: 5rem;
}

@keyframes skeleton-pulse {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 0.7; }
}

/* Section reveal */
.section-actual {
    display: none;
}

.section-actual.visible {
    display: block;
    animation: content-in 600ms cubic-bezier(0.25, 0.1, 0.25, 1) forwards;
}

@keyframes content-in {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.skeleton-group.dissolving {
    animation: dissolve 400ms ease-out forwards;
}

@keyframes dissolve {
    to { opacity: 0; }
}

.skeleton-group.hidden {
    display: none;
}

/* Data path animation */
.data-path {
    stroke-dashoffset: var(--path-length, 2000);
    stroke-dasharray: var(--path-length, 2000);
    transition: stroke-dashoffset 2.5s cubic-bezier(0.25, 0.1, 0.25, 1);
}

.data-path.drawn {
    stroke-dashoffset: 0;
}

/* Kintsugi seams */
.kintsugi-seam {
    width: 60%;
    margin: 0 auto;
    padding: calc(var(--descent-unit) * 0.5) 0;
    position: relative;
    z-index: 2;
}

.kintsugi-seam svg {
    width: 100%;
    height: 20px;
    display: block;
}

.kintsugi-path {
    stroke-dasharray: 1600;
    stroke-dashoffset: 1600;
    transition: stroke-dashoffset 1.8s cubic-bezier(0.25, 0.1, 0.25, 1);
}

.kintsugi-path.drawn {
    stroke-dashoffset: 0;
}

.kintsugi-seam.glowing svg {
    filter: drop-shadow(0 0 6px rgba(196, 163, 90, 0.3));
    transition: filter 800ms ease-in;
}

/* Terminal stratum */
.terminal-stratum {
    min-height: 200vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    padding-bottom: calc(var(--descent-unit) * 2);
}

.terminal-content {
    text-align: center;
    transform: translateX(0);
    display: flex;
    flex-direction: column;
    align-items: center;
}

.terminal-text {
    font-family: 'Karla', sans-serif;
    font-weight: 300;
    font-size: 1rem;
    color: var(--text-tertiary);
    letter-spacing: 0.08em;
    margin-bottom: calc(var(--descent-unit) * 4.236);
}

.terminal-botanical {
    width: 80px;
    height: 120px;
    margin-bottom: calc(var(--descent-unit) * 4.236);
    opacity: 0.4;
}

.terminal-domain {
    font-family: 'Karla', sans-serif;
    font-weight: 300;
    font-size: 0.75rem;
    color: var(--text-tertiary);
    opacity: 0.4;
    letter-spacing: 0.04em;
}

/* Hairline section borders */
.stratum + .stratum::after,
.kintsugi-seam + .stratum::after {
    content: '';
    position: absolute;
    top: 0;
    left: 15%;
    right: 15%;
    height: 1px;
    background: repeating-linear-gradient(
        to right,
        var(--border) 0,
        var(--border) 20px,
        transparent 20px,
        transparent 28px
    );
    opacity: 0.5;
}

/* Scatter dots animation */
.scatter-dots circle {
    transform: scale(0);
    transform-origin: center;
    transform-box: fill-box;
}

.scatter-dots.animated circle {
    animation: dot-appear 400ms cubic-bezier(0.25, 0.1, 0.25, 1) forwards;
}

.scatter-dots.animated circle:nth-child(2) { animation-delay: 80ms; }
.scatter-dots.animated circle:nth-child(3) { animation-delay: 160ms; }
.scatter-dots.animated circle:nth-child(4) { animation-delay: 240ms; }
.scatter-dots.animated circle:nth-child(5) { animation-delay: 320ms; }
.scatter-dots.animated circle:nth-child(6) { animation-delay: 400ms; }
.scatter-dots.animated circle:nth-child(7) { animation-delay: 480ms; }
.scatter-dots.animated circle:nth-child(8) { animation-delay: 560ms; }
.scatter-dots.animated circle:nth-child(9) { animation-delay: 640ms; }
.scatter-dots.animated circle:nth-child(10) { animation-delay: 720ms; }
.scatter-dots.animated circle:nth-child(11) { animation-delay: 800ms; }
.scatter-dots.animated circle:nth-child(12) { animation-delay: 880ms; }
.scatter-dots.animated circle:nth-child(13) { animation-delay: 960ms; }
.scatter-dots.animated circle:nth-child(14) { animation-delay: 1040ms; }
.scatter-dots.animated circle:nth-child(15) { animation-delay: 1120ms; }
.scatter-dots.animated circle:nth-child(16) { animation-delay: 1200ms; }
.scatter-dots.animated circle:nth-child(17) { animation-delay: 1280ms; }
.scatter-dots.animated circle:nth-child(18) { animation-delay: 1360ms; }
.scatter-dots.animated circle:nth-child(19) { animation-delay: 1440ms; }
.scatter-dots.animated circle:nth-child(20) { animation-delay: 1520ms; }
.scatter-dots.animated circle:nth-child(21) { animation-delay: 1600ms; }
.scatter-dots.animated circle:nth-child(22) { animation-delay: 1680ms; }
.scatter-dots.animated circle:nth-child(23) { animation-delay: 1760ms; }
.scatter-dots.animated circle:nth-child(n+24) { animation-delay: 1840ms; }

@keyframes dot-appear {
    to {
        transform: scale(1);
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
