:root {
    --bg-primary: #0D1F0A;
    --bg-secondary: #132B0E;
    --bg-tertiary: #1A3A14;
    --text-primary: #C8D6C0;
    --text-secondary: #6B8F71;
    --accent-primary: #A8D08D;
    --accent-secondary: #D4E8A5;
    --accent-tertiary: #2D5016;
    --code-keyword: #7BC96F;
    --code-type: #B8C97A;
    --code-string: #8FAEB8;
    --font-primary: 'JetBrains Mono', monospace;
    --font-secondary: 'IBM Plex Mono', monospace;
    --font-display: 'Space Grotesk', sans-serif;
}

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

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

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-primary);
    font-size: 1rem;
    line-height: 1.85;
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
}

/* ============================================================
   Lambda Grid Background
   ============================================================ */
.lambda-grid {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
    opacity: 0.02;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120' viewBox='0 0 120 120'%3E%3Ctext x='15' y='35' font-family='serif' font-size='24' fill='%232D5016' transform='rotate(-8 15 35)'%3E%CE%BB%3C/text%3E%3Ctext x='75' y='25' font-family='serif' font-size='20' fill='%232D5016' transform='rotate(5 75 25)'%3E%CE%BB%3C/text%3E%3Ctext x='45' y='80' font-family='serif' font-size='22' fill='%232D5016' transform='rotate(-3 45 80)'%3E%CE%BB%3C/text%3E%3Ctext x='95' y='95' font-family='serif' font-size='18' fill='%232D5016' transform='rotate(12 95 95)'%3E%CE%BB%3C/text%3E%3Ctext x='10' y='105' font-family='serif' font-size='16' fill='%232D5016' transform='rotate(-15 10 105)'%3E%CE%BB%3C/text%3E%3C/svg%3E");
    background-repeat: repeat;
}

/* ============================================================
   Module Index (Left Sidebar Navigation)
   ============================================================ */
.module-index {
    position: fixed;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
    padding: 0.5rem;
    width: 24px;
}

.module-link {
    font-family: var(--font-secondary);
    font-size: 10px;
    color: var(--text-secondary);
    text-decoration: none;
    writing-mode: vertical-rl;
    transform: rotate(180deg);
    letter-spacing: 0.05em;
    transition: color 0.3s ease, border-left-color 0.3s ease;
    border-left: 2px solid transparent;
    padding-left: 4px;
    opacity: 0;
}

.module-link.loaded {
    opacity: 1;
    transition: opacity 0.4s ease, color 0.3s ease, border-left-color 0.3s ease;
}

.module-link.active {
    color: var(--accent-primary);
    border-left-color: var(--accent-primary);
}

/* ============================================================
   Main Column
   ============================================================ */
.column {
    max-width: 72ch;
    margin: 0 auto;
    padding: 0 2rem;
    position: relative;
    left: -4vw;
    z-index: 1;
}

/* ============================================================
   Sections
   ============================================================ */
.section {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 4rem 0;
}

/* ============================================================
   Hero
   ============================================================ */
.hero {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    min-height: 80vh;
    position: relative;
}

.hero-title {
    font-family: var(--font-display);
    font-weight: 500;
    font-size: clamp(2rem, 5vw, 3.5rem);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--accent-secondary);
    line-height: 1.3;
}

/* ============================================================
   Monad Unwrapping Animation (SVG)
   ============================================================ */
.monad-animation {
    width: 220px;
    height: 220px;
    margin-bottom: 3rem;
}

.monad-svg {
    width: 100%;
    height: 100%;
}

.monad-layer {
    fill: none;
    stroke-width: 2;
    transition: all 1.5s ease;
}

.monad-io {
    stroke: #2D5016;
    animation: monad-unwrap-io 12s ease-in-out infinite;
}

.monad-maybe {
    stroke: #1A3A14;
    animation: monad-unwrap-maybe 12s ease-in-out infinite;
}

.monad-either {
    stroke: #6B8F71;
    animation: monad-unwrap-either 12s ease-in-out infinite;
}

.monad-identity {
    stroke: var(--accent-primary);
    fill: rgba(26, 58, 20, 0.3);
    animation: monad-unwrap-identity 12s ease-in-out infinite;
}

.monad-label {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 11px;
    fill: var(--text-secondary);
}

.monad-label-io { animation: monad-label-fade-io 12s ease-in-out infinite; }
.monad-label-maybe { animation: monad-label-fade-maybe 12s ease-in-out infinite; }
.monad-label-either { animation: monad-label-fade-either 12s ease-in-out infinite; }
.monad-label-identity {
    font-size: 14px;
    fill: var(--accent-primary);
    animation: monad-label-fade-identity 12s ease-in-out infinite;
}

@keyframes monad-unwrap-io {
    0%, 10% { stroke-opacity: 0.8; fill: rgba(13, 31, 10, 0.2); stroke-width: 2; }
    20%, 30% { stroke-opacity: 0.2; fill: none; stroke-width: 1; }
    80%, 100% { stroke-opacity: 0.8; fill: rgba(13, 31, 10, 0.2); stroke-width: 2; }
}

@keyframes monad-unwrap-maybe {
    0%, 15% { stroke-opacity: 0.8; fill: rgba(19, 43, 14, 0.2); stroke-width: 2; }
    25%, 40% { stroke-opacity: 0.8; fill: none; stroke-width: 1; }
    35%, 50% { stroke-opacity: 0.2; fill: none; stroke-width: 1; }
    80%, 100% { stroke-opacity: 0.8; fill: rgba(19, 43, 14, 0.2); stroke-width: 2; }
}

@keyframes monad-unwrap-either {
    0%, 30% { stroke-opacity: 0.8; fill: rgba(26, 58, 20, 0.15); stroke-width: 2; }
    45%, 60% { stroke-opacity: 0.2; fill: none; stroke-width: 1; }
    80%, 100% { stroke-opacity: 0.8; fill: rgba(26, 58, 20, 0.15); stroke-width: 2; }
}

@keyframes monad-unwrap-identity {
    0%, 45% { stroke-opacity: 0.6; fill: rgba(26, 58, 20, 0.3); }
    55%, 70% { stroke-opacity: 1; fill: rgba(168, 208, 141, 0.1); }
    80%, 100% { stroke-opacity: 0.6; fill: rgba(26, 58, 20, 0.3); }
}

@keyframes monad-label-fade-io {
    0%, 10% { opacity: 0.7; }
    20%, 80% { opacity: 0.15; }
    90%, 100% { opacity: 0.7; }
}

@keyframes monad-label-fade-maybe {
    0%, 15% { opacity: 0.7; }
    30%, 80% { opacity: 0.15; }
    90%, 100% { opacity: 0.7; }
}

@keyframes monad-label-fade-either {
    0%, 30% { opacity: 0.7; }
    45%, 80% { opacity: 0.15; }
    90%, 100% { opacity: 0.7; }
}

@keyframes monad-label-fade-identity {
    0%, 45% { opacity: 0.5; }
    55%, 70% { opacity: 1; }
    80%, 100% { opacity: 0.5; }
}

/* ============================================================
   Section Headings
   ============================================================ */
.section-heading {
    font-family: var(--font-primary);
    font-weight: 700;
    font-size: clamp(1.5rem, 3vw, 2.8rem);
    color: var(--accent-primary);
    margin-bottom: 2rem;
}

/* ============================================================
   Body Text
   ============================================================ */
.body-text {
    font-family: var(--font-primary);
    font-size: 1rem;
    line-height: 1.85;
    color: var(--text-primary);
    margin-bottom: 3rem;
    max-width: 72ch;
}

/* ============================================================
   Annotations
   ============================================================ */
.annotation {
    font-family: var(--font-secondary);
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.7;
    margin-top: 2rem;
}

/* ============================================================
   Code Blocks
   ============================================================ */
.code-block {
    background-color: var(--bg-tertiary);
    padding: 1.5rem;
    padding-left: 1.5rem;
    border-left: 2px solid rgba(45, 80, 22, 0.4);
    margin: 2rem 0;
    overflow-x: auto;
}

.code-line {
    font-family: var(--font-primary);
    font-size: 0.9rem;
    line-height: 1.75;
    white-space: pre;
    opacity: 0;
}

.code-line.line-visible {
    opacity: 1;
    transition: opacity 0.4s ease;
}

.line-num {
    display: inline-block;
    width: 3ch;
    text-align: right;
    color: rgba(45, 80, 22, 0.5);
    margin-right: 1.5ch;
    user-select: none;
    font-variant-numeric: tabular-nums;
}

/* Syntax highlighting */
.kw { color: var(--code-keyword); font-weight: 700; }
.type { color: var(--code-type); }
.fn { color: var(--accent-primary); }
.op { color: var(--text-primary); }
.str { color: var(--code-string); }
.num { color: var(--code-string); }
.comment { color: var(--text-secondary); font-style: italic; opacity: 0.7; }

/* ============================================================
   Section Rules
   ============================================================ */
.section-rule {
    border: none;
    height: 1px;
    background-color: rgba(45, 80, 22, 0.3);
    margin-top: 4rem;
    transform: scaleX(0);
    transform-origin: left;
    transition: transform 0.8s cubic-bezier(0.25, 0.1, 0.25, 1.0);
}

.section-rule.visible {
    transform: scaleX(1);
}

/* ============================================================
   Spacers and Decorative Elements
   ============================================================ */
.spacer {
    min-height: 30vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.deco-symbol {
    font-family: var(--font-primary);
    font-size: 3rem;
    color: rgba(45, 80, 22, 0.15);
    user-select: none;
}

.deco-lambda {
    font-family: serif;
    font-size: 4rem;
    opacity: 0.8;
}

.deco-where {
    font-family: var(--font-secondary);
    font-size: 1.5rem;
    font-style: italic;
    animation: where-dissolve 8s ease-in-out infinite;
}

@keyframes where-dissolve {
    0%, 40% { opacity: 1; }
    60%, 80% { opacity: 0.3; }
    100% { opacity: 1; }
}

.deco-arrow {
    font-family: var(--font-primary);
    font-size: 2.5rem;
    letter-spacing: -0.15em;
}

/* ============================================================
   Type Arrow Trails
   ============================================================ */
.type-arrow-trail {
    width: 400px;
    height: 40px;
    max-width: 80vw;
}

.type-arrow-path {
    stroke-dasharray: 600;
    stroke-dashoffset: 600;
    transition: stroke-dashoffset 1.5s ease;
}

.type-arrow-head {
    opacity: 0;
    transition: opacity 0.4s ease 1.3s;
}

.type-arrow-trail.visible .type-arrow-path {
    stroke-dashoffset: 0;
}

.type-arrow-trail.visible .type-arrow-head {
    opacity: 1;
}

/* ============================================================
   Category Theory Diagrams
   ============================================================ */
.category-diagram {
    width: 240px;
    margin: 2rem 0;
}

.category-diagram-monad {
    width: 280px;
}

/* ============================================================
   Fade Reveal Animation
   ============================================================ */
.fade-reveal {
    opacity: 0;
    transform: translateY(12px);
    transition: opacity 0.6s cubic-bezier(0.25, 0.1, 0.25, 1.0),
                transform 0.6s cubic-bezier(0.25, 0.1, 0.25, 1.0);
}

.fade-reveal.visible {
    opacity: 1;
    transform: translateY(0);
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 768px) {
    .column {
        left: 0;
        padding: 0 1.5rem;
    }

    .module-index {
        display: none;
    }

    .hero-title {
        font-size: clamp(1.5rem, 6vw, 2.5rem);
    }

    .monad-animation {
        width: 170px;
        height: 170px;
    }

    .type-arrow-trail {
        width: 250px;
    }

    .category-diagram {
        width: 200px;
    }

    .category-diagram-monad {
        width: 240px;
    }
}

@media (max-width: 480px) {
    .code-block {
        padding: 1rem;
        font-size: 0.8rem;
    }

    .code-line {
        font-size: 0.78rem;
    }

    .body-text {
        font-size: 0.9rem;
    }

    .hero-title {
        font-size: clamp(1.2rem, 5vw, 2rem);
    }

    .monad-animation {
        width: 140px;
        height: 140px;
    }
}
