/* === RESET & BASE === */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #0a0a0a;
    --bg-alt: #0d120a;
    --neon-green: #39ff14;
    --neon-cyan: #00e5ff;
    --accent-amber: #c4a235;
    --text-primary: #d4d4d4;
    --text-muted: #7a8a6e;
    --grain-white: #f0f0e8;
    --text-pale-green: #b8f0b0;
}

html {
    scroll-behavior: smooth;
}

body {
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 300;
    font-size: 1.0625rem;
    line-height: 1.85;
    letter-spacing: 0.01em;
    overflow-x: hidden;
    cursor: crosshair;
}

/* === GRAIN CANVAS === */
#grain-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 1000;
    mix-blend-mode: overlay;
    opacity: 0.06;
    image-rendering: pixelated;
}

/* === SCANLINES === */
#scanlines {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 999;
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 2px,
        rgba(240, 240, 232, 0.02) 2px,
        rgba(240, 240, 232, 0.02) 3px
    );
}

/* === CURSOR GLOW === */
#cursor-glow {
    position: fixed;
    width: 240px;
    height: 240px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(57, 255, 20, 0.15) 0%, rgba(57, 255, 20, 0.05) 40%, transparent 70%);
    pointer-events: none;
    z-index: 998;
    transform: translate(-50%, -50%);
    transition: left 0.15s ease-out, top 0.15s ease-out;
    will-change: transform, left, top;
    opacity: 0;
}

body.cursor-active #cursor-glow {
    opacity: 1;
}

/* === LEAF CONTAINER === */
#leaf-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 5;
    overflow: hidden;
}

.leaf {
    position: absolute;
    pointer-events: none;
    transition: transform 0.8s ease-out;
    will-change: transform;
}

.leaf svg {
    width: 100%;
    height: 100%;
}

.leaf-green {
    color: rgba(57, 255, 20, 0.08);
}

.leaf-cyan {
    color: rgba(0, 229, 255, 0.05);
}

/* === GLITCH ANIMATION === */
@keyframes glitch-shift {
    0%, 95%, 100% { transform: translateX(0); }
    96% { transform: translateX(2px); }
    97% { transform: translateX(-1px); }
    98% { transform: translateX(1px); }
    99% { transform: translateX(-2px); }
}

@keyframes glitch-shift-2 {
    0%, 92%, 100% { transform: translateX(0); }
    93% { transform: translateX(-2px); }
    94% { transform: translateX(1px); }
    95% { transform: translateX(-1px); }
    96% { transform: translateX(2px); }
}

#grain-canvas {
    animation: glitch-shift 8s infinite, glitch-shift-2 13s infinite;
}

/* === SECTIONS === */
.section {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 10;
    padding: 12vh 1.5rem;
}

.section-inner {
    max-width: 640px;
    width: 100%;
    text-align: center;
}

/* === TITLE SPREAD === */
#title-spread {
    background: var(--bg-primary);
}

#title-spread .section-inner {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 3s ease-out, transform 3s ease-out;
}

#title-spread.revealed .section-inner {
    opacity: 1;
    transform: translateY(0);
}

.title-text {
    font-family: 'Caveat Brush', cursive;
    font-size: clamp(3rem, 8vw, 7rem);
    letter-spacing: 0.04em;
    color: var(--neon-green);
    text-shadow:
        0 0 20px rgba(57, 255, 20, 0.4),
        0 0 60px rgba(57, 255, 20, 0.15),
        0 0 120px rgba(57, 255, 20, 0.05);
    line-height: 1.1;
    margin-bottom: 2rem;
}

.title-line {
    display: block;
}

.subtitle {
    font-family: 'Kalam', cursive;
    font-size: 1rem;
    color: var(--text-pale-green);
    line-height: 1.6;
    margin-bottom: 3rem;
    opacity: 0.7;
}

.title-annotation {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    opacity: 0.5;
}

.annotation-marker {
    color: var(--accent-amber);
    font-size: 0.875rem;
}

.annotation-text {
    font-family: 'Kalam', cursive;
    font-weight: 400;
    font-size: 1rem;
    line-height: 1.6;
    color: var(--text-pale-green);
}

.annotation-text.small {
    font-size: 0.8125rem;
    color: var(--text-muted);
}

/* === SPECIMEN SECTIONS === */
.specimen-section {
    background: var(--bg-alt);
}

.specimen-section:nth-child(even) {
    background: var(--bg-primary);
}

.specimen-container {
    text-align: center;
}

.specimen-illustration {
    position: relative;
    width: 300px;
    height: 400px;
    margin: 0 auto 3rem;
}

.specimen-svg {
    width: 100%;
    height: 100%;
    overflow: visible;
}

.specimen-glow {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 320px;
    height: 420px;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    box-shadow: 0 0 80px rgba(57, 255, 20, 0.08);
    pointer-events: none;
    animation: glow-pulse 6s ease-in-out infinite;
}

@keyframes glow-pulse {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

/* Specimen animation states */
.specimen-stem {
    stroke-dasharray: 340;
    stroke-dashoffset: 340;
    transition: stroke-dashoffset 1s ease-out;
}

.specimen-frond {
    stroke-dasharray: 300;
    stroke-dashoffset: 300;
    transition: stroke-dashoffset 0.8s ease-out;
}

.specimen-vein {
    opacity: 0;
    transition: opacity 0.6s ease-out;
}

.specimen-section.revealed .specimen-stem {
    stroke-dashoffset: 0;
}

.specimen-section.revealed .specimen-frond {
    stroke-dashoffset: 0;
}

.specimen-section.revealed .specimen-vein {
    opacity: 0.6;
}

/* Staggered frond animations */
.specimen-section.revealed .frond-l1,
.specimen-section.revealed .frond-r1 { transition-delay: 0.8s; }
.specimen-section.revealed .frond-l2,
.specimen-section.revealed .frond-r2 { transition-delay: 1.0s; }
.specimen-section.revealed .frond-l3,
.specimen-section.revealed .frond-r3 { transition-delay: 1.2s; }
.specimen-section.revealed .frond-l4,
.specimen-section.revealed .frond-r4 { transition-delay: 1.4s; }
.specimen-section.revealed .frond-l5,
.specimen-section.revealed .frond-r5 { transition-delay: 1.6s; }
.specimen-section.revealed .frond-l6,
.specimen-section.revealed .frond-r6 { transition-delay: 1.8s; }
.specimen-section.revealed .frond-arc { transition-delay: 1.5s; }

/* Annotation lines */
.annotation-line {
    position: absolute;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    white-space: nowrap;
    opacity: 0;
    transition: opacity 0.8s ease-out;
}

.specimen-section.revealed .annotation-line {
    opacity: 1;
}

.ann-left {
    right: 55%;
    flex-direction: row-reverse;
    text-align: right;
}

.ann-right {
    left: 55%;
}

.ann-top {
    top: 15%;
    transition-delay: 1.5s !important;
}

.ann-mid {
    top: 45%;
    transition-delay: 1.8s !important;
}

.ann-bottom {
    top: 70%;
    transition-delay: 2.1s !important;
}

.specimen-section.revealed .ann-top { transition-delay: 1.5s; }
.specimen-section.revealed .ann-mid { transition-delay: 1.8s; }
.specimen-section.revealed .ann-bottom { transition-delay: 2.1s; }

.ann-dash {
    display: block;
    width: 40px;
    height: 0;
    border-top: 1px dashed var(--accent-amber);
    flex-shrink: 0;
}

.annotation-line .annotation-text {
    font-size: 0.75rem;
    color: var(--accent-amber);
    opacity: 0.8;
}

.specimen-title {
    font-family: 'Caveat Brush', cursive;
    font-size: clamp(1.5rem, 4vw, 2.5rem);
    letter-spacing: 0.04em;
    color: var(--neon-green);
    text-shadow:
        0 0 15px rgba(57, 255, 20, 0.3),
        0 0 40px rgba(57, 255, 20, 0.1);
    margin-bottom: 0.5rem;
}

.specimen-name {
    margin-bottom: 1.5rem;
    font-style: italic;
}

.specimen-body {
    color: var(--text-primary);
    max-width: 480px;
    margin: 0 auto;
    text-align: left;
}

.body-text {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 300;
    font-size: 1.0625rem;
    line-height: 1.85;
    letter-spacing: 0.01em;
    color: var(--text-primary);
}

/* === CLASSIFICATION INDEX === */
#classification-index {
    background: var(--bg-primary);
    min-height: auto;
    padding: 15vh 1.5rem;
}

.index-heading {
    font-family: 'Caveat Brush', cursive;
    font-size: clamp(2rem, 5vw, 3.5rem);
    letter-spacing: 0.04em;
    color: var(--neon-green);
    text-shadow:
        0 0 15px rgba(57, 255, 20, 0.3),
        0 0 40px rgba(57, 255, 20, 0.1);
    margin-bottom: 0.5rem;
}

.index-subheading {
    margin-bottom: 3rem;
    opacity: 0.6;
}

.index-entries {
    text-align: left;
}

.index-entry {
    display: flex;
    align-items: baseline;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    border-bottom: 1px solid rgba(122, 138, 110, 0.15);
    position: relative;
    transition: all 0.3s ease-out;
    filter: blur(2px);
    opacity: 0.4;
}

.index-entry.clear {
    filter: blur(0);
    opacity: 1;
}

.index-entry.clear::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    width: 100%;
    height: 1px;
    background: var(--neon-green);
    opacity: 0.3;
}

.index-code {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 500;
    font-size: 0.8125rem;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--neon-cyan);
    flex-shrink: 0;
    width: 50px;
}

.index-separator {
    color: var(--text-muted);
    opacity: 0.4;
    flex-shrink: 0;
}

.index-name {
    font-family: 'Kalam', cursive;
    font-size: 1rem;
    color: var(--text-pale-green);
    flex-grow: 1;
    font-style: italic;
}

.index-class {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 500;
    font-size: 0.6875rem;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--text-muted);
    flex-shrink: 0;
}

.index-status {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 500;
    font-size: 0.625rem;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--neon-green);
    opacity: 0.7;
    flex-shrink: 0;
    min-width: 65px;
    text-align: right;
}

.index-status.corrupted {
    color: var(--accent-amber);
    animation: status-flicker 4s ease-in-out infinite;
}

@keyframes status-flicker {
    0%, 90%, 100% { opacity: 0.7; }
    92% { opacity: 0.1; }
    94% { opacity: 0.6; }
    96% { opacity: 0.15; }
    98% { opacity: 0.7; }
}

/* === COLOPHON === */
#colophon {
    min-height: 50vh;
    background: var(--bg-alt);
    padding: 10vh 1.5rem;
}

#colophon .section-inner {
    opacity: 0;
    transition: opacity 2s ease-out;
}

#colophon.revealed .section-inner {
    opacity: 1;
}

.colophon-content {
    max-width: 480px;
    margin: 0 auto;
    text-align: left;
}

.colophon-text {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 1.5rem;
    line-height: 1.8;
}

.colophon-signature {
    margin-top: 3rem;
    text-align: center;
}

.colophon-signature .annotation-text {
    color: var(--text-muted);
    opacity: 0.5;
    font-size: 0.875rem;
}

.colophon-marker {
    margin-top: 4rem;
    text-align: center;
    opacity: 0.3;
}

/* === NOISE DISSOLVE MASK === */
.noise-mask {
    -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100%25' height='100%25'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100%25' height='100%25'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* === COLOPHON FADE === */
#colophon.fading .section-inner {
    opacity: 0;
    transition: opacity 10s ease-out;
}

/* === BREATHING GRAIN === */
@keyframes grain-breathe {
    0%, 100% { opacity: 0.04; }
    50% { opacity: 0.07; }
}

#grain-canvas {
    animation: grain-breathe 5s ease-in-out infinite, glitch-shift 8s infinite, glitch-shift-2 13s infinite;
}

/* === RESPONSIVE === */
@media (max-width: 768px) {
    .specimen-illustration {
        width: 220px;
        height: 300px;
    }

    .annotation-line {
        display: none;
    }

    .index-entry {
        flex-wrap: wrap;
        gap: 0.25rem 0.75rem;
    }

    .index-class {
        display: none;
    }

    .title-text {
        font-size: clamp(2.5rem, 10vw, 5rem);
    }
}

@media (max-width: 480px) {
    .index-entry {
        padding: 0.75rem 0.5rem;
    }

    .index-code {
        width: 40px;
        font-size: 0.6875rem;
    }

    .specimen-body {
        text-align: center;
    }
}
