:root {
    --bg-carbon: #0B0E14;
    --bg-slate: #161B26;
    --neon-green: #39FF14;
    --neon-magenta: #FF2EAA;
    --neon-yellow: #CCFF00;
    --text-white: #E8ECF0;
    --text-muted: #7A8B9E;
    --accent-amber: #FF8C42;
    --font-display: 'Josefin Sans', sans-serif;
    --font-body: 'Nunito Sans', sans-serif;
    --font-mono: 'IBM Plex Mono', monospace;
    --neon-primary: #39FF14;
}

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

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    background-color: var(--bg-carbon);
    color: var(--text-white);
    font-family: var(--font-body);
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
}

/* ============================== */
/* SCANLINE OVERLAY */
/* ============================== */
.scanline-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: 100;
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 1px,
        rgba(0, 0, 0, 0.06) 1px,
        rgba(0, 0, 0, 0.06) 2px
    );
}

/* ============================== */
/* SCROLL INDICATOR */
/* ============================== */
.scroll-indicator {
    position: fixed;
    right: 0;
    top: 0;
    width: 2px;
    height: 0%;
    background-color: var(--neon-primary);
    z-index: 50;
    transition: background-color 1.2s ease;
    box-shadow: 0 0 6px var(--neon-primary), 0 0 12px var(--neon-primary);
}

.scroll-indicator.pulse-all {
    animation: pulseAllNeon 1.5s ease-out;
}

@keyframes pulseAllNeon {
    0% { box-shadow: 0 0 6px var(--neon-green), 0 0 12px var(--neon-green); background-color: var(--neon-green); }
    33% { box-shadow: 0 0 6px var(--neon-magenta), 0 0 12px var(--neon-magenta); background-color: var(--neon-magenta); }
    66% { box-shadow: 0 0 6px var(--neon-yellow), 0 0 12px var(--neon-yellow); background-color: var(--neon-yellow); }
    100% { box-shadow: 0 0 6px var(--neon-green), 0 0 12px var(--neon-green); background-color: var(--neon-green); }
}

/* ============================== */
/* VEIN NETWORK SVG */
/* ============================== */
.vein-network {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 1200px;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    opacity: 0.6;
}

/* ============================== */
/* LEAF FALL PARTICLES */
/* ============================== */
.leaf-particles {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 90vh;
    pointer-events: none;
    z-index: 2;
    overflow: hidden;
    opacity: 1;
    transition: opacity 0.5s ease;
}

.leaf-particles.hidden {
    opacity: 0;
}

.leaf-particle {
    position: absolute;
    top: -30px;
    left: var(--start-x);
    width: 20px;
    height: 28px;
    clip-path: polygon(50% 0%, 15% 30%, 5% 60%, 20% 85%, 50% 100%, 80% 85%, 95% 60%, 85% 30%);
    background-color: rgba(57, 255, 20, 0.2);
    animation: leafFall var(--fall-duration) var(--fall-delay) linear infinite;
}

@keyframes leafFall {
    0% {
        transform: translateX(0) rotate(var(--rotate-start));
        opacity: 0;
    }
    5% {
        opacity: 1;
    }
    85% {
        opacity: 1;
    }
    100% {
        transform: translateX(var(--drift)) translateY(90vh) rotate(var(--rotate-end));
        opacity: 0;
    }
}

/* ============================== */
/* GRID SECTIONS */
/* ============================== */
.grid-section {
    max-width: 1200px;
    margin: 0 auto;
    padding: 80px 2vw;
    position: relative;
    z-index: 1;
}

/* ============================== */
/* SECTION 1: HERO */
/* ============================== */
.hero-section {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    position: relative;
}

.leaf-wireframe {
    position: absolute;
    opacity: 0.5;
    animation: leafRotate 120s linear infinite;
}

.hero-leaf {
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

@keyframes leafRotate {
    from { transform: translate(-50%, -50%) rotate(0deg); }
    to { transform: translate(-50%, -50%) rotate(360deg); }
}

.hero-content {
    position: relative;
    z-index: 2;
    margin-bottom: 3rem;
}

.hero-title {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(2.5rem, 6vw + 0.5rem, 5.5rem);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    line-height: 1.1;
    margin-bottom: 1.5rem;
}

.text-green { color: var(--neon-green); }
.text-magenta { color: var(--neon-magenta); }

/* ============================== */
/* SPECIMEN LABELS */
/* ============================== */
.specimen-label {
    display: flex;
    gap: 1rem;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.hero-section .specimen-label {
    justify-content: center;
}

.label-code, .label-time, .label-desc {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: 0.2rem 0.5rem;
    border: 1px dashed var(--text-muted);
}

/* ============================== */
/* QED BLOCKS */
/* ============================== */
.qed-block {
    text-align: center;
    padding: 4rem 2rem;
    position: relative;
    z-index: 1;
    max-width: 1200px;
    margin: 0 auto;
}

.qed-text {
    font-family: var(--font-mono);
    font-size: clamp(0.9rem, 1.5vw, 1.2rem);
    color: var(--neon-yellow);
    letter-spacing: 0.06em;
}

/* ============================== */
/* SECTION 2: THESIS GRID */
/* ============================== */
.thesis-section {
    display: grid;
    grid-template-columns: 7fr 4fr;
    gap: 2vw;
    padding-top: 100px;
    padding-bottom: 100px;
}

.thesis-zone {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.annotation-zone {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    padding-left: 1rem;
    border-left: 1px solid rgba(57, 255, 20, 0.15);
}

/* ============================== */
/* GRID CELLS - THEOREM */
/* ============================== */
.theorem-cell {
    background-color: var(--bg-slate);
    border-radius: 4px;
    padding: 2.5rem;
    position: relative;
    overflow: hidden;
    will-change: transform;
    transform: perspective(1000px) rotateX(0deg) rotateY(0deg);
    transition: transform 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94), border-color 0.4s ease;
    border: 1px solid transparent;
}

.theorem-cell:hover {
    border-color: var(--neon-magenta);
}

.cell-wireframe {
    position: absolute;
    top: 0;
    right: 0;
    width: 200px;
    height: 200px;
    opacity: 0.5;
    pointer-events: none;
}

/* Different leaf wireframe background variants */
.leaf-bg-1 {
    background-image:
        repeating-linear-gradient(0deg, rgba(57,255,20,0.06) 0px, rgba(57,255,20,0.06) 1px, transparent 1px, transparent 20px),
        repeating-linear-gradient(90deg, rgba(57,255,20,0.06) 0px, rgba(57,255,20,0.06) 1px, transparent 1px, transparent 20px);
}

.leaf-bg-2 {
    background-image:
        repeating-linear-gradient(45deg, rgba(57,255,20,0.05) 0px, rgba(57,255,20,0.05) 1px, transparent 1px, transparent 14px);
}

.leaf-bg-3 {
    background-image:
        repeating-linear-gradient(135deg, rgba(57,255,20,0.05) 0px, rgba(57,255,20,0.05) 1px, transparent 1px, transparent 14px);
}

.leaf-bg-4 {
    background-image:
        repeating-linear-gradient(0deg, rgba(57,255,20,0.04) 0px, rgba(57,255,20,0.04) 1px, transparent 1px, transparent 25px),
        repeating-linear-gradient(60deg, rgba(57,255,20,0.04) 0px, rgba(57,255,20,0.04) 1px, transparent 1px, transparent 25px);
}

.leaf-bg-5 {
    background-image:
        radial-gradient(circle at 50% 50%, rgba(57,255,20,0.04) 1px, transparent 1px);
    background-size: 15px 15px;
}

.leaf-bg-6 {
    background-image:
        repeating-linear-gradient(90deg, rgba(57,255,20,0.05) 0px, rgba(57,255,20,0.05) 1px, transparent 1px, transparent 18px),
        repeating-linear-gradient(0deg, rgba(57,255,20,0.03) 0px, rgba(57,255,20,0.03) 1px, transparent 1px, transparent 18px);
}

.leaf-bg-7 {
    background-image:
        repeating-linear-gradient(30deg, rgba(255,46,170,0.04) 0px, rgba(255,46,170,0.04) 1px, transparent 1px, transparent 20px),
        repeating-linear-gradient(120deg, rgba(255,46,170,0.04) 0px, rgba(255,46,170,0.04) 1px, transparent 1px, transparent 20px);
}

.leaf-bg-8 {
    background-image:
        repeating-conic-gradient(rgba(255,46,170,0.03) 0deg 10deg, transparent 10deg 20deg);
    background-size: 40px 40px;
}

.leaf-bg-synthesis {
    width: 100%;
    height: 100%;
    background-image:
        repeating-linear-gradient(0deg, rgba(204,255,0,0.03) 0px, rgba(204,255,0,0.03) 1px, transparent 1px, transparent 30px),
        repeating-linear-gradient(90deg, rgba(204,255,0,0.03) 0px, rgba(204,255,0,0.03) 1px, transparent 1px, transparent 30px);
}

.cell-heading {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(1.5rem, 3vw, 2.5rem);
    color: var(--text-white);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    margin-bottom: 1rem;
}

.cell-body {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: clamp(0.95rem, 1.2vw + 0.4rem, 1.15rem);
    line-height: 1.72;
    color: var(--text-white);
    max-width: 60ch;
}

/* ============================== */
/* GRID CELLS - LEMMA */
/* ============================== */
.lemma-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

.lemma-cell {
    background-color: var(--bg-slate);
    border-radius: 4px;
    padding: 2rem;
    position: relative;
    overflow: hidden;
    aspect-ratio: 1 / 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    will-change: transform;
    transform: perspective(1000px) rotateX(0deg) rotateY(0deg);
    transition: transform 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94), border-color 0.4s ease;
    border: 1px solid transparent;
}

.lemma-cell:hover {
    border-color: var(--neon-magenta);
}

.cell-body-sm {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: clamp(0.9rem, 1.1vw, 1.05rem);
    line-height: 1.7;
    color: var(--text-muted);
}

/* ============================== */
/* GRID CELLS - COROLLARY */
/* ============================== */
.corollary-cell {
    background-color: var(--bg-slate);
    border: 1px solid rgba(57, 255, 20, 0.1);
    padding: 1.5rem;
    position: relative;
    will-change: transform;
    transform: perspective(1000px) rotateX(0deg) rotateY(0deg);
    transition: transform 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94), border-color 0.4s ease;
}

.corollary-cell:hover {
    border-color: var(--neon-magenta);
}

/* Scanline texture inside corollary cells */
.corollary-cell::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 2px,
        rgba(57, 255, 20, 0.015) 2px,
        rgba(57, 255, 20, 0.015) 3px
    );
    pointer-events: none;
}

.corollary-cell .label-code {
    display: block;
    margin-bottom: 0.75rem;
    border: none;
    padding: 0;
    color: var(--neon-green);
    opacity: 0.6;
}

.corollary-text {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: 0.9rem;
    line-height: 1.6;
    color: var(--text-muted);
}

/* ============================== */
/* SECTION 3: ANNOTATION DEEP-DIVE */
/* ============================== */
.annotation-section {
    display: grid;
    grid-template-columns: 5fr 6fr;
    gap: 2vw;
    padding-top: 100px;
    padding-bottom: 100px;
}

.thesis-zone-narrow {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.annotation-zone-wide {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    padding-left: 1rem;
    border-left: 1px solid rgba(255, 46, 170, 0.2);
}

.annotation-section .corollary-cell {
    border-color: rgba(255, 46, 170, 0.15);
}

.annotation-section .corollary-cell .label-code {
    color: var(--neon-magenta);
}

.annotation-section .corollary-cell::before {
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 2px,
        rgba(255, 46, 170, 0.015) 2px,
        rgba(255, 46, 170, 0.015) 3px
    );
}

.annotation-section .theorem-cell:hover {
    border-color: var(--neon-magenta);
}

.annotation-lemma {
    aspect-ratio: auto;
}

/* ============================== */
/* SECTION 4: SYNTHESIS */
/* ============================== */
.synthesis-section {
    display: grid;
    grid-template-columns: 10fr 2fr;
    gap: 2vw;
    padding-top: 100px;
    padding-bottom: 100px;
}

.synthesis-main {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.synthesis-cell {
    min-height: 500px;
}

.synthesis-tree {
    display: block;
    margin: 0 auto 2rem;
    max-width: 500px;
}

.synthesis-annotation {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    padding-left: 1rem;
    border-left: 1px solid rgba(204, 255, 0, 0.2);
}

.synthesis-section .corollary-cell {
    border-color: rgba(204, 255, 0, 0.15);
}

.synthesis-section .corollary-cell .label-code {
    color: var(--neon-yellow);
}

.synthesis-section .corollary-cell::before {
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 2px,
        rgba(204, 255, 0, 0.015) 2px,
        rgba(204, 255, 0, 0.015) 3px
    );
}

.synthesis-section .theorem-cell:hover {
    border-color: var(--neon-yellow);
}

/* ============================== */
/* SECTION 5: CODA */
/* ============================== */
.coda-section {
    min-height: 50vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 100px 2rem;
}

.coda-content {
    margin-bottom: 3rem;
}

.coda-title {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(2rem, 5vw, 4.5rem);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-white);
}

.coda-domain {
    display: inline-block;
    transition: opacity 2s ease-out;
}

.coda-domain.fading {
    opacity: 0;
}

.coda-qed {
    margin-top: 2rem;
}

.coda-symbol {
    font-family: var(--font-mono);
    font-size: clamp(1rem, 2vw, 1.5rem);
    color: var(--neon-yellow);
    letter-spacing: 0.1em;
    opacity: 0.8;
}

/* ============================== */
/* GRID CELL REVEAL ANIMATION */
/* ============================== */
.grid-cell-reveal {
    opacity: 0;
    transform: perspective(1000px) rotateY(-15deg) translateY(30px);
    transition: opacity 0.7s ease-out, transform 0.7s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.grid-cell-reveal.visible {
    opacity: 1;
    transform: perspective(1000px) rotateY(0deg) translateY(0);
}

/* Staggered entrance delay based on data-cell-index */
.grid-cell-reveal[data-cell-index="0"] { transition-delay: 0ms; }
.grid-cell-reveal[data-cell-index="1"] { transition-delay: 80ms; }
.grid-cell-reveal[data-cell-index="2"] { transition-delay: 160ms; }
.grid-cell-reveal[data-cell-index="3"] { transition-delay: 240ms; }
.grid-cell-reveal[data-cell-index="4"] { transition-delay: 320ms; }
.grid-cell-reveal[data-cell-index="5"] { transition-delay: 400ms; }
.grid-cell-reveal[data-cell-index="6"] { transition-delay: 480ms; }
.grid-cell-reveal[data-cell-index="7"] { transition-delay: 560ms; }
.grid-cell-reveal[data-cell-index="8"] { transition-delay: 640ms; }
.grid-cell-reveal[data-cell-index="9"] { transition-delay: 720ms; }
.grid-cell-reveal[data-cell-index="10"] { transition-delay: 0ms; }
.grid-cell-reveal[data-cell-index="11"] { transition-delay: 80ms; }
.grid-cell-reveal[data-cell-index="12"] { transition-delay: 0ms; }
.grid-cell-reveal[data-cell-index="13"] { transition-delay: 80ms; }
.grid-cell-reveal[data-cell-index="14"] { transition-delay: 160ms; }
.grid-cell-reveal[data-cell-index="15"] { transition-delay: 240ms; }
.grid-cell-reveal[data-cell-index="16"] { transition-delay: 320ms; }
.grid-cell-reveal[data-cell-index="17"] { transition-delay: 400ms; }
.grid-cell-reveal[data-cell-index="18"] { transition-delay: 0ms; }
.grid-cell-reveal[data-cell-index="19"] { transition-delay: 0ms; }
.grid-cell-reveal[data-cell-index="20"] { transition-delay: 80ms; }
.grid-cell-reveal[data-cell-index="21"] { transition-delay: 160ms; }
.grid-cell-reveal[data-cell-index="22"] { transition-delay: 240ms; }

/* ============================== */
/* NEON COLOR CYCLING */
/* ============================== */
body.neon-green {
    --neon-primary: #39FF14;
}

body.neon-magenta {
    --neon-primary: #FF2EAA;
}

body.neon-yellow {
    --neon-primary: #CCFF00;
}

/* ============================== */
/* RESPONSIVE */
/* ============================== */
@media (max-width: 768px) {
    .thesis-section,
    .annotation-section,
    .synthesis-section {
        grid-template-columns: 1fr;
    }

    .annotation-zone,
    .annotation-zone-wide,
    .synthesis-annotation {
        border-left: none;
        padding-left: 0;
        border-top: 1px solid rgba(57, 255, 20, 0.15);
        padding-top: 1.5rem;
    }

    .lemma-row {
        grid-template-columns: 1fr;
    }

    .lemma-cell {
        aspect-ratio: auto;
    }

    .grid-section {
        padding: 60px 1.5rem;
    }

    .hero-leaf svg {
        width: 250px;
        height: 325px;
    }

    .synthesis-cell {
        min-height: auto;
    }

    .leaf-particles {
        display: none;
    }
}

@media (max-width: 480px) {
    .cell-body {
        font-size: 0.95rem;
    }
    .theorem-cell {
        padding: 1.5rem;
    }
    .hero-title {
        font-size: clamp(2rem, 8vw, 3.5rem);
    }
}
