/* Reset and Normalization */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: auto;
}

body {
    font-family: 'Roboto Slab', serif;
    font-size: 18px;
    line-height: 1.75;
    color: #E8E4DF;
    background-color: #0D1F15;
    overflow-x: hidden;
}

/* Color Palette */
:root {
    --deep-forest: #0D1F15;
    --canopy: #1B3A2D;
    --moss: #4A7C59;
    --lichen: #8FBC8F;
    --concrete: #E8E4DF;
    --marble: #F5F2EE;
    --vein: #B5C4B1;
    --iron: #0A1610;
    --grid-line: #2D5A3D;
}

/* Navigation Bar */
.nav-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 48px;
    background-color: var(--canopy);
    border-bottom: 2px solid var(--canopy);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 32px;
    z-index: 999;
}

.nav-brand {
    font-family: 'Zilla Slab', serif;
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 0.2em;
    color: var(--marble);
    text-transform: uppercase;
}

.nav-contents {
    font-family: 'Zilla Slab', serif;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.2em;
    color: var(--moss);
    background: none;
    border: 1px solid var(--moss);
    padding: 6px 12px;
    cursor: pointer;
    text-transform: uppercase;
}

.nav-contents:hover {
    color: var(--marble);
    border-color: var(--marble);
    background-color: transparent;
}

/* Grid Overlay */
.grid-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: repepeating-linear-gradient(
        to right,
        transparent 0,
        transparent calc((100% - 32px) / 12 * 11 + 32px),
        var(--grid-line) calc((100% - 32px) / 12 * 11 + 32px),
        var(--grid-line) calc((100% - 32px) / 12 * 11 + 34px),
        transparent calc((100% - 32px) / 12 * 11 + 34px)
    );
    opacity: 0.15;
    pointer-events: none;
    z-index: 1;
}

/* Grid using SVG approach via pseudo-elements */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image:
        repeating-linear-gradient(
            90deg,
            transparent,
            transparent calc((100vw - 64px) / 12),
            var(--grid-line) calc((100vw - 64px) / 12),
            var(--grid-line) calc((100vw - 64px) / 12 + 1px)
        );
    margin-left: 32px;
    pointer-events: none;
    z-index: 1;
    opacity: 0.15;
}

/* Contents Overlay (Table of Contents) */
.toc-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(10, 22, 16, 0.98);
    z-index: 1001;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.toc-overlay.active {
    opacity: 1;
    visibility: visible;
}

.toc-list {
    list-style: none;
    font-family: 'Zilla Slab', serif;
    font-size: 24px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-align: left;
}

.toc-link {
    color: var(--moss);
    text-decoration: none;
    display: block;
    margin: 24px 0;
    transition: color 0s;
}

.toc-link:hover {
    color: var(--lichen);
}

/* Slab Sections */
.slab {
    min-height: 100vh;
    background-color: var(--deep-forest);
    border-bottom: 4px solid var(--canopy);
    padding-top: 48px;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    padding-left: 32px;
    padding-right: 32px;
    padding-bottom: 32px;
}

.slab:first-of-type {
    padding-top: 48px;
    justify-content: center;
}

.slab-content {
    max-width: 100%;
    width: 100%;
    position: relative;
}

.slab-title {
    font-family: 'Zilla Slab', serif;
    font-size: clamp(72px, 8vw, 128px);
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--marble);
    margin-bottom: 32px;
    line-height: 1.1;
    text-align: left;
}

/* Text Block Styling */
.text-block {
    max-width: 55ch;
    margin-left: calc((100vw - 64px) / 12 * 1);
}

.text-block p {
    margin-bottom: 1.5em;
    text-align: left;
    color: var(--concrete);
    font-family: 'Roboto Slab', serif;
    font-weight: 400;
    font-size: 18px;
    line-height: 1.75;
}

.text-block p:last-child {
    margin-bottom: 0;
}

/* Code Styling */
code {
    font-family: 'Roboto Mono', monospace;
    font-size: 14px;
    background-color: var(--canopy);
    color: var(--lichen);
    padding: 2px 6px;
    border-radius: 0;
}

pre {
    margin: 24px 0;
}

pre code {
    display: block;
    font-size: 16px;
    line-height: 1.6;
    padding: 24px;
    background-color: var(--deep-forest);
    color: var(--lichen);
    border-left: 3px solid var(--moss);
    overflow-x: auto;
}

/* Marble Panel */
.marble-panel {
    position: relative;
    background-color: var(--deep-forest);
    border: 2px solid var(--vein);
    padding: 24px;
    margin: 32px 0;
    max-width: 600px;
}

.panel-corner {
    position: absolute;
    width: 16px;
    height: 16px;
    border: 1px solid var(--vein);
}

.corner-tl {
    top: 8px;
    left: 8px;
    border-right: none;
    border-bottom: none;
}

.corner-tr {
    top: 8px;
    right: 8px;
    border-left: none;
    border-bottom: none;
}

.corner-bl {
    bottom: 8px;
    left: 8px;
    border-right: none;
    border-top: none;
}

.corner-br {
    bottom: 8px;
    right: 8px;
    border-left: none;
    border-top: none;
}

.marble-panel pre code {
    background-color: var(--deep-forest);
    padding: 16px;
    border-left: 3px solid var(--moss);
}

/* SVG Diagrams */
.lambda-svg,
.type-diagram,
.tree-diagram,
.proof-diagram {
    visibility: hidden;
    max-width: 100%;
    height: auto;
    margin: 32px 0;
}

.lambda-svg.drawn,
.type-diagram.drawn,
.tree-diagram.drawn,
.proof-diagram.drawn {
    visibility: visible;
}

/* Lambda Path Animation */
.lambda-path {
    stroke-dasharray: 1000;
    stroke-dashoffset: 1000;
    transition: stroke-dashoffset 2.5s ease-in-out;
}

.lambda-svg.drawn .lambda-path {
    stroke-dashoffset: 0;
}

/* Type Diagram Animations */
.type-arrow-1 {
    stroke-dasharray: 40;
    stroke-dashoffset: 40;
    transition: stroke-dashoffset 1.5s ease-in-out;
}

.type-arrow-2 {
    stroke-dasharray: 40;
    stroke-dashoffset: 40;
    transition: stroke-dashoffset 1.5s ease-in-out;
    transition-delay: 0.3s;
}

.type-diagram.drawn .type-arrow-1 {
    stroke-dashoffset: 0;
}

.type-diagram.drawn .type-arrow-2 {
    stroke-dashoffset: 0;
}

/* Proof Diagram Animations */
.proof-box-1,
.proof-box-2,
.proof-box-3 {
    stroke-dasharray: 360;
    stroke-dashoffset: 360;
    transition: stroke-dashoffset 1.2s ease-in-out;
}

.proof-arrow-1 {
    stroke-dasharray: 50;
    stroke-dashoffset: 50;
    transition: stroke-dashoffset 1.2s ease-in-out;
    transition-delay: 0.2s;
}

.proof-arrow-2 {
    stroke-dasharray: 50;
    stroke-dashoffset: 50;
    transition: stroke-dashoffset 1.2s ease-in-out;
    transition-delay: 0.4s;
}

.proof-diagram.drawn .proof-box-1 {
    stroke-dashoffset: 0;
}

.proof-diagram.drawn .proof-box-2 {
    stroke-dashoffset: 0;
}

.proof-diagram.drawn .proof-box-3 {
    stroke-dashoffset: 0;
}

.proof-diagram.drawn .proof-arrow-1 {
    stroke-dashoffset: 0;
}

.proof-diagram.drawn .proof-arrow-2 {
    stroke-dashoffset: 0;
}

/* Terminus Section */
.terminus-block {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: flex-start;
    height: calc(100vh - 80px);
    padding-top: 48px;
}

.terminus-period {
    font-family: 'Zilla Slab', serif;
    font-size: clamp(128px, 20vw, 256px);
    font-weight: 700;
    color: var(--marble);
    line-height: 0.8;
    margin-bottom: 32px;
}

.terminus-text {
    font-family: 'Zilla Slab', serif;
    font-size: clamp(36px, 6vw, 72px);
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--concrete);
}

/* Responsive Design */
@media (max-width: 768px) {
    .nav-bar {
        padding: 0 16px;
    }

    .slab {
        padding-left: 16px;
        padding-right: 16px;
    }

    .slab-title {
        font-size: clamp(48px, 6vw, 96px);
    }

    .text-block {
        max-width: 100%;
    }

    .marble-panel {
        margin: 16px 0;
    }

    .toc-list {
        font-size: 18px;
    }

    .toc-link {
        margin: 16px 0;
    }

    .grid-overlay::before {
        opacity: 0.08;
    }
}

@media (max-width: 480px) {
    .nav-bar {
        height: 40px;
        padding: 0 12px;
    }

    .nav-brand {
        font-size: 12px;
    }

    .nav-contents {
        font-size: 10px;
        padding: 4px 8px;
    }

    .slab {
        padding-left: 12px;
        padding-right: 12px;
        padding-bottom: 16px;
    }

    .slab-title {
        font-size: clamp(32px, 5vw, 72px);
        margin-bottom: 16px;
    }

    .text-block p {
        font-size: 16px;
    }

    pre code {
        font-size: 12px;
        padding: 12px;
    }
}
