/* ===========================
   algoha.com - Styles
   Botanical Scholarship meets Speculative Futurism
   =========================== */

/* --- CSS Custom Properties --- */
:root {
    --vellum-cream: #F5EDE0;
    --aged-ivory: #EDE4D4;
    --ink-walnut: #3B2F2A;
    --foxing-sepia: #8C7A6B;
    --pressed-rose: #C4A882;
    --neon-chlorophyll: #39FF85;
    --neon-orchid: #D946EF;
    --phosphor-blue: #38BDF8;
    --deep-humus: #1C1512;

    --font-display: 'Cormorant Garamond', 'Georgia', serif;
    --font-body: 'Lora', 'Georgia', serif;
    --font-mono: 'JetBrains Mono', 'Courier New', monospace;

    --ease-organic: cubic-bezier(0.22, 1, 0.36, 1);
}

/* --- Reset & Base --- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    overflow-x: hidden;
}

body {
    background-color: var(--vellum-cream);
    color: var(--ink-walnut);
    font-family: var(--font-body);
    font-size: 1.125rem;
    font-weight: 400;
    line-height: 1.75;
    letter-spacing: 0.005em;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* --- Paper Grain Texture --- */
.paper-grain {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 100;
    opacity: 0.05;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='1'/%3E%3C/svg%3E");
    background-size: 200px 200px;
}

/* --- Typography --- */
.logotype {
    font-family: var(--font-display);
    font-weight: 300;
    font-size: clamp(3.5rem, 10vw, 8rem);
    letter-spacing: 0.04em;
    line-height: 1.0;
    color: var(--ink-walnut);
    text-align: center;
}

.section-heading {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: clamp(2rem, 5vw, 4rem);
    letter-spacing: 0.02em;
    line-height: 1.15;
    color: var(--ink-walnut);
    margin-bottom: 2rem;
}

.body-text {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: 1.125rem;
    line-height: 1.75;
    letter-spacing: 0.005em;
    color: var(--ink-walnut);
    margin-bottom: 1.5rem;
}

.subtitle {
    font-family: var(--font-body);
    font-weight: 400;
    font-style: italic;
    font-size: 1.125rem;
    line-height: 1.6;
    color: var(--foxing-sepia);
    text-align: center;
    max-width: 480px;
    margin: 1.5rem auto 0;
    opacity: 0;
    transform: translateY(12px);
    transition: opacity 0.8s var(--ease-organic), transform 0.8s var(--ease-organic);
}

.subtitle.visible {
    opacity: 1;
    transform: translateY(0);
}

.annotation-text {
    font-family: var(--font-mono);
    font-size: 0.625rem;
    font-weight: 400;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    fill: var(--foxing-sepia);
}

/* --- Navigation Rail --- */
.nav-rail {
    position: fixed;
    left: 48px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 50;
    display: flex;
    flex-direction: column;
    gap: 28px;
    align-items: center;
}

.nav-rail::before {
    content: '';
    position: absolute;
    left: 50%;
    top: -20px;
    bottom: -20px;
    width: 1px;
    background-color: var(--pressed-rose);
    opacity: 0.3;
    transform: translateX(-50%);
}

.nav-marker {
    position: relative;
    z-index: 1;
    color: var(--pressed-rose);
    opacity: 0.3;
    transition: opacity 2s ease-in-out;
    cursor: pointer;
}

.nav-marker.active {
    opacity: 0.8;
}

.nav-marker svg {
    display: block;
}

/* --- Chapters (General) --- */
.chapter {
    position: relative;
    min-height: 100vh;
    width: 100%;
    overflow: hidden;
}

/* --- Chapter 1: The Herbarium --- */
.chapter-herbarium {
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--vellum-cream);
    height: 100vh;
}

.bg-botanical {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    z-index: 0;
}

.bg-roots svg {
    width: 60vw;
    max-width: 800px;
    height: auto;
    animation: drift-right 120s linear infinite;
}

@keyframes drift-right {
    0% { transform: translateX(0); }
    100% { transform: translateX(60px); }
}

.herbarium-content {
    position: relative;
    z-index: 1;
    text-align: center;
    padding: 2rem;
}

.letter {
    display: inline-block;
    opacity: 0;
    transform: translateY(8px);
    animation: letter-fade-in 0.6s var(--ease-organic) forwards;
    animation-delay: calc(1s + var(--delay) * 120ms);
}

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

.subtitle {
    animation: subtitle-fade-in 0.8s var(--ease-organic) forwards;
    animation-delay: 1.8s;
}

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

/* Logotype glitch effect */
.logotype.glitch {
    animation: logotype-glitch 400ms steps(4) forwards;
}

@keyframes logotype-glitch {
    0% { transform: translateX(0); clip-path: inset(0 0 0 0); }
    25% { transform: translateX(3px); clip-path: inset(20% 0 40% 0); }
    50% { transform: translateX(-2px); clip-path: inset(60% 0 10% 0); }
    75% { transform: translateX(3px); clip-path: inset(30% 0 30% 0); }
    100% { transform: translateX(0); clip-path: inset(0 0 0 0); }
}

/* --- Section Dividers --- */
.section-divider {
    position: relative;
    height: 40px;
    margin: 0 auto;
    width: 60%;
    max-width: 800px;
}

.vine-divider {
    width: 100%;
    height: 100%;
}

.vine-path {
    stroke-dasharray: 1000;
    stroke-dashoffset: 1000;
    transition: stroke-dashoffset 1.5s var(--ease-organic);
}

.vine-path.animated {
    stroke-dashoffset: 0;
}

.vine-leaf {
    stroke-dasharray: 50;
    stroke-dashoffset: 50;
    transition: stroke-dashoffset 0.8s var(--ease-organic);
}

.vine-leaf.animated {
    stroke-dashoffset: 0;
}

.vine-leaf-1 { transition-delay: 0.6s; }
.vine-leaf-2 { transition-delay: 0.9s; }
.vine-leaf-3 { transition-delay: 1.2s; }

/* --- Chapter 2: Taxonomy --- */
.chapter-taxonomy {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    padding: 120px 0 120px 0;
    background-color: var(--vellum-cream);
    gap: 40px;
}

.taxonomy-text {
    max-width: 520px;
    margin-left: 15%;
    padding-top: 40px;
    flex-shrink: 0;
}

.specimen-cards-stack {
    position: relative;
    margin-left: auto;
    margin-right: 10%;
    display: flex;
    flex-direction: column;
    gap: 40px;
    padding-top: 20px;
}

.specimen-card {
    position: relative;
    max-width: 480px;
    width: 320px;
    padding: 30px 24px 40px;
    background-color: var(--aged-ivory);
    border: 1px solid var(--pressed-rose);
    box-shadow: inset 0 0 40px rgba(59, 47, 42, 0.04);
    opacity: 0;
    transform: translateX(30px);
    transition: opacity 0.6s var(--ease-organic), transform 0.6s var(--ease-organic), border-color 0.4s var(--ease-organic), box-shadow 0.4s var(--ease-organic);
}

.specimen-card.visible {
    opacity: 1;
    transform: translateX(0);
}

.specimen-card:nth-child(1) { transition-delay: 0ms; }
.specimen-card:nth-child(2) { transition-delay: 200ms; }
.specimen-card:nth-child(3) { transition-delay: 400ms; }

.specimen-card:hover {
    border-color: var(--neon-chlorophyll);
    box-shadow: inset 0 0 40px rgba(57, 255, 133, 0.04);
}

.specimen-label {
    display: block;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    font-weight: 400;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--foxing-sepia);
    margin-bottom: 16px;
}

.specimen-illustration {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 160px;
}

.specimen-svg {
    width: 140px;
    height: 140px;
}

.specimen-grid-pattern {
    position: absolute;
    bottom: 8px;
    right: 8px;
    width: 48px;
    height: 48px;
    background-image:
        linear-gradient(var(--foxing-sepia) 1px, transparent 1px),
        linear-gradient(90deg, var(--foxing-sepia) 1px, transparent 1px);
    background-size: 4px 4px;
    opacity: 0.08;
}

/* Neon glow for specimen card 2 */
.neon-glow-svg {
    filter: drop-shadow(0 0 4px var(--neon-chlorophyll)) drop-shadow(0 0 12px var(--neon-chlorophyll)) drop-shadow(0 0 24px var(--neon-chlorophyll));
    animation: neon-pulse 4s ease-in-out infinite;
}

@keyframes neon-pulse {
    0%, 100% { filter: drop-shadow(0 0 4px var(--neon-chlorophyll)) drop-shadow(0 0 8px var(--neon-chlorophyll)) drop-shadow(0 0 16px var(--neon-chlorophyll)); }
    50% { filter: drop-shadow(0 0 6px var(--neon-chlorophyll)) drop-shadow(0 0 16px var(--neon-chlorophyll)) drop-shadow(0 0 28px var(--neon-chlorophyll)); }
}

/* --- Chapter 3: Cross-Section --- */
.chapter-cross-section {
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--vellum-cream);
    height: 100vh;
    padding: 60px 20px;
}

.cross-section-container {
    position: relative;
    width: 100%;
    max-width: 600px;
    display: flex;
    justify-content: center;
}

.cross-section-svg {
    width: 100%;
    height: auto;
    max-height: 80vh;
}

/* Progressive neon illumination */
.pod-structure .ovule {
    transition: stroke 0.8s var(--ease-organic), filter 0.8s var(--ease-organic);
}

.cross-section-svg.phase-1 .ovule:nth-child(odd) {
    stroke: var(--neon-chlorophyll);
    filter: drop-shadow(0 0 4px var(--neon-chlorophyll));
}

.cross-section-svg.phase-1 .pod-outer {
    transition: stroke 0.8s var(--ease-organic);
}

/* Annotations reveal */
.cross-section-svg .annotations {
    transition: opacity 0.8s var(--ease-organic);
}

.cross-section-svg.phase-2 .annotations {
    opacity: 1;
}

.cross-section-svg .annotation-labels {
    transition: opacity 0.6s var(--ease-organic) 0.4s;
}

.cross-section-svg.phase-2 .annotation-labels {
    opacity: 1;
}

/* Annotation line draw animation */
.annotation-line {
    stroke-dasharray: 200;
    stroke-dashoffset: 200;
    transition: stroke-dashoffset 0.8s var(--ease-organic);
}

.cross-section-svg.phase-2 .annotation-line {
    stroke-dashoffset: 0;
}

/* Neon overlay */
.cross-section-svg .neon-overlay {
    transition: opacity 1s var(--ease-organic);
    mix-blend-mode: screen;
}

.cross-section-svg.phase-3 .neon-overlay {
    opacity: 0.7;
}

/* Glitch on cross-section */
.cross-section-svg.glitch-active {
    animation: svg-rgb-split 600ms steps(6) forwards;
}

@keyframes svg-rgb-split {
    0% { filter: none; transform: translate(0, 0); }
    16% { filter: drop-shadow(2px 0 0 rgba(57,255,133,0.5)) drop-shadow(-2px 0 0 rgba(217,70,239,0.5)); transform: translate(2px, 0); }
    33% { filter: drop-shadow(-3px 0 0 rgba(56,189,248,0.5)) drop-shadow(3px 0 0 rgba(217,70,239,0.5)); transform: translate(-1px, 0); }
    50% { filter: drop-shadow(4px 0 0 rgba(57,255,133,0.5)) drop-shadow(-2px 0 0 rgba(56,189,248,0.5)); transform: translate(3px, 0); }
    66% { filter: drop-shadow(-2px 0 0 rgba(217,70,239,0.5)) drop-shadow(2px 0 0 rgba(57,255,133,0.5)); transform: translate(-2px, 0); }
    83% { filter: drop-shadow(1px 0 0 rgba(56,189,248,0.5)); transform: translate(1px, 0); }
    100% { filter: none; transform: translate(0, 0); }
}

/* --- Chapter 4: Field Notes --- */
.chapter-field-notes {
    background-color: var(--aged-ivory);
    padding: 120px 20px 160px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.field-notes-heading {
    align-self: flex-start;
    margin-left: 15%;
    margin-bottom: 60px;
}

.field-note {
    max-width: 440px;
    padding-left: 20px;
    border-left: 1px solid var(--pressed-rose);
    margin-bottom: 60px;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.6s var(--ease-organic), transform 0.6s var(--ease-organic);
}

.field-note.visible {
    opacity: 1;
    transform: translateY(0);
}

.field-note-left {
    align-self: flex-start;
    margin-left: 15%;
}

.field-note-right {
    align-self: flex-start;
    margin-left: 55%;
}

.field-note-margin-sketch {
    align-self: center;
    margin: -20px 0 40px;
    opacity: 0;
    transition: opacity 0.6s var(--ease-organic);
}

.field-note-margin-sketch.visible {
    opacity: 1;
}

.margin-svg {
    width: 50px;
    height: 50px;
}

.margin-sketch-1 { margin-left: 35%; }
.margin-sketch-2 { margin-left: 70%; }
.margin-sketch-3 { margin-left: 25%; }

/* --- Chapter 5: The Algorithm --- */
.chapter-algorithm {
    background-color: var(--deep-humus);
    min-height: 100vh;
    padding: 120px 20px 160px;
    position: relative;
    overflow: hidden;
}

.algorithm-heading {
    color: var(--vellum-cream);
}

.algorithm-text {
    color: var(--vellum-cream);
    opacity: 0.9;
}

.data-stream {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    font-family: var(--font-mono);
    font-size: 0.7rem;
    letter-spacing: 0.08em;
    color: var(--vellum-cream);
    opacity: 0.03;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
    line-height: 1.8;
    white-space: pre-wrap;
    word-break: break-all;
}

.algorithm-content {
    position: relative;
    z-index: 2;
    max-width: 520px;
    margin-left: 15%;
    margin-bottom: 80px;
}

.neon-botanicals {
    position: relative;
    z-index: 1;
    display: flex;
    justify-content: center;
    gap: 60px;
    flex-wrap: wrap;
    padding: 0 20px;
}

.neon-botanical {
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 0.8s var(--ease-organic), transform 0.8s var(--ease-organic);
}

.neon-botanical.visible {
    opacity: 1;
    transform: translateY(0);
}

.neon-botanical-1 {
    transition-delay: 0ms;
}

.neon-botanical-2 {
    transition-delay: 300ms;
}

.neon-illustration {
    width: 250px;
    height: auto;
    filter: drop-shadow(0 0 4px rgba(57, 255, 133, 0.4)) drop-shadow(0 0 12px rgba(57, 255, 133, 0.2));
    animation: neon-breathe 4s ease-in-out infinite;
}

@keyframes neon-breathe {
    0%, 100% { filter: drop-shadow(0 0 4px rgba(57,255,133,0.3)) drop-shadow(0 0 8px rgba(217,70,239,0.2)); }
    50% { filter: drop-shadow(0 0 8px rgba(57,255,133,0.5)) drop-shadow(0 0 20px rgba(217,70,239,0.3)) drop-shadow(0 0 28px rgba(56,189,248,0.2)); }
}

/* --- Chapter 6: Synthesis --- */
.chapter-synthesis {
    background-color: var(--vellum-cream);
    min-height: 100vh;
    padding: 120px 20px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    overflow: hidden;
}

.synthesis-botanicals {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 60vw;
    max-width: 500px;
    pointer-events: none;
    z-index: 0;
}

.synthesis-bg-botanical,
.synthesis-neon-botanical {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: auto;
}

.synthesis-neon-botanical {
    mix-blend-mode: screen;
    filter: drop-shadow(0 0 6px rgba(57, 255, 133, 0.3));
    animation: neon-breathe 4s ease-in-out infinite;
}

.synthesis-content {
    position: relative;
    z-index: 1;
    max-width: 520px;
    text-align: center;
    margin-bottom: 80px;
}

.synthesis-heading {
    margin-bottom: 2rem;
}

.synthesis-text {
    color: var(--ink-walnut);
}

.closing-logotype {
    position: relative;
    z-index: 1;
    margin-top: 40px;
    text-align: center;
}

.closing-logo-text {
    font-family: var(--font-display);
    font-weight: 300;
    font-size: clamp(1.5rem, 4vw, 2.5rem);
    letter-spacing: 0.04em;
    color: var(--foxing-sepia);
}

.closing-space {
    height: 200px;
}

/* --- Glitch Effects --- */
.glitch-target.glitching,
.glitch-target-dark.glitching {
    animation: element-glitch 400ms steps(5) forwards;
}

@keyframes element-glitch {
    0% { transform: translateX(0); filter: none; }
    20% { transform: translateX(4px); filter: drop-shadow(2px 0 0 rgba(57,255,133,0.6)) drop-shadow(-2px 0 0 rgba(217,70,239,0.6)); }
    40% { transform: translateX(-3px); filter: drop-shadow(-3px 0 0 rgba(56,189,248,0.6)) drop-shadow(3px 0 0 rgba(217,70,239,0.6)); }
    60% { transform: translateX(5px); filter: drop-shadow(4px 0 0 rgba(57,255,133,0.6)) drop-shadow(-4px 0 0 rgba(56,189,248,0.6)); }
    80% { transform: translateX(-2px); filter: drop-shadow(2px 0 0 rgba(217,70,239,0.4)); }
    100% { transform: translateX(0); filter: none; }
}

/* Scan-line glitch for dark section (more aggressive) */
.glitch-target-dark.glitching {
    animation: element-glitch-dark 500ms steps(6) forwards;
}

@keyframes element-glitch-dark {
    0% { transform: translate(0, 0); filter: none; }
    16% { transform: translate(6px, 0); filter: drop-shadow(3px 0 0 rgba(57,255,133,0.8)) drop-shadow(-3px 0 0 rgba(217,70,239,0.8)); }
    33% { transform: translate(-5px, 1px); filter: drop-shadow(-4px 0 0 rgba(56,189,248,0.7)) drop-shadow(4px 0 0 rgba(217,70,239,0.7)); }
    50% { transform: translate(8px, -1px); filter: drop-shadow(5px 0 0 rgba(57,255,133,0.8)) drop-shadow(-3px 0 0 rgba(56,189,248,0.8)); }
    66% { transform: translate(-4px, 0); filter: drop-shadow(-3px 0 0 rgba(217,70,239,0.6)) drop-shadow(3px 0 0 rgba(57,255,133,0.6)); }
    83% { transform: translate(3px, 0); filter: drop-shadow(2px 0 0 rgba(56,189,248,0.5)); }
    100% { transform: translate(0, 0); filter: none; }
}

/* Flicker opacity animation */
@keyframes opacity-flicker {
    0% { opacity: 1; }
    20% { opacity: 0.4; }
    40% { opacity: 1; }
    60% { opacity: 0.5; }
    80% { opacity: 0.9; }
    100% { opacity: 1; }
}

.flickering {
    animation: opacity-flicker 300ms steps(5) forwards;
}

/* --- Responsive --- */
@media (max-width: 900px) {
    .nav-rail {
        left: 16px;
    }

    .chapter-taxonomy {
        flex-direction: column;
        align-items: center;
        padding: 80px 20px;
    }

    .taxonomy-text {
        margin-left: 0;
        max-width: 90%;
    }

    .specimen-cards-stack {
        margin-left: 0;
        margin-right: 0;
        align-items: center;
    }

    .field-note-left,
    .field-note-right {
        margin-left: 5%;
        max-width: 90%;
    }

    .field-notes-heading {
        margin-left: 5%;
    }

    .algorithm-content {
        margin-left: 5%;
        max-width: 90%;
    }

    .margin-sketch-1,
    .margin-sketch-2,
    .margin-sketch-3 {
        margin-left: auto;
        margin-right: auto;
    }
}

@media (max-width: 600px) {
    .nav-rail {
        display: none;
    }

    .specimen-card {
        width: 280px;
    }

    .neon-botanicals {
        flex-direction: column;
        align-items: center;
    }
}
