:root {
    --bg-primary: #f5f0e6;
    --bg-secondary: #ede7d9;
    --text-primary: #4a3f32;
    --text-heading: #3b2f20;
    --accent-primary: #a0522d;
    --accent-secondary: #7a6540;
    --annotation: #a39882;
    --sim-lines: #5c4a32;
    --sim-fill: #c8b99a;
    --hover: #8b4513;
    --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

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

html {
    scroll-behavior: smooth;
}

body {
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: 'JetBrains Mono', monospace;
    font-weight: 400;
    font-size: clamp(0.875rem, 1.1vw, 1rem);
    line-height: 1.75;
}

/* Chapter Index Nav */
.chapter-index {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--bg-secondary);
    padding: 0.75rem 0;
    text-align: center;
}

.chapter-index ol {
    list-style: none;
    display: flex;
    justify-content: center;
    gap: 2.5rem;
}

.chapter-index a {
    font-family: 'Cormorant Garamond', serif;
    font-weight: 600;
    font-size: 1.25rem;
    color: var(--annotation);
    text-decoration: none;
    position: relative;
    padding-bottom: 4px;
    transition: color 400ms var(--ease);
}

.chapter-index a::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 50%;
    width: 0;
    height: 2px;
    background: var(--accent-primary);
    transition: width 400ms var(--ease), left 400ms var(--ease);
}

.chapter-index a.active {
    color: var(--text-heading);
}

.chapter-index a.active::after {
    width: 100%;
    left: 0;
}

.chapter-index a:hover {
    color: var(--hover);
}

/* Parchment Column */
.parchment-column {
    max-width: 680px;
    margin: 0 auto;
    padding: 0 clamp(1rem, 4vw, 2rem);
    position: relative;
}

/* Hero */
.hero-chapter {
    text-align: center;
    padding: 4rem 0 2rem;
    position: relative;
}

.hero-chapter h1 {
    font-family: 'Cormorant Garamond', serif;
    font-weight: 600;
    font-size: clamp(2.5rem, 5vw, 4rem);
    color: var(--text-heading);
    letter-spacing: 0.02em;
    line-height: 1.15;
    margin-top: 1.5rem;
}

.hero-chapter .subtitle {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 300;
    font-size: clamp(0.8rem, 1vw, 0.95rem);
    color: var(--annotation);
    letter-spacing: 0.05em;
    margin-top: 0.5rem;
}

.lorenz-attractor {
    display: block;
    margin: 0 auto;
    max-width: 100%;
    height: auto;
}

.lorenz-attractor path {
    fill: none;
    stroke: var(--sim-lines);
    stroke-width: 0.15;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.lorenz-attractor .lorenz-fill {
    fill: var(--sim-fill);
    opacity: 0.1;
    stroke: none;
}

/* Chapter Watermarks */
.chapter-watermark {
    position: absolute;
    top: -1rem;
    left: 50%;
    transform: translateX(-50%);
    font-family: 'Cormorant Garamond', serif;
    font-weight: 300;
    font-size: 15rem;
    color: var(--bg-secondary);
    pointer-events: none;
    user-select: none;
    z-index: 0;
    line-height: 1;
}

/* Chapters */
.chapter {
    position: relative;
    padding: 4rem 0 2rem;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 600ms var(--ease), transform 600ms var(--ease);
}

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

.chapter h2 {
    font-family: 'Cormorant Garamond', serif;
    font-weight: 600;
    font-size: clamp(2rem, 4vw, 3.25rem);
    color: var(--text-heading);
    letter-spacing: 0.02em;
    line-height: 1.15;
    margin-bottom: 1.5rem;
    position: relative;
    z-index: 1;
}

.chapter-numeral {
    font-weight: 300;
    color: var(--accent-primary);
    margin-right: 0.5rem;
}

.chapter-body {
    position: relative;
    z-index: 1;
}

.chapter-body p {
    margin-bottom: 1.25rem;
}

.chapter-body em {
    font-style: italic;
    color: var(--accent-secondary);
}

.annotation {
    font-weight: 300;
    font-size: clamp(0.8rem, 0.9vw, 0.9rem);
    color: var(--annotation);
    border-left: 2px solid var(--accent-primary);
    padding-left: 1rem;
    margin: 1.5rem 0;
}

.formula {
    font-family: 'Fira Code', monospace;
    font-weight: 500;
    color: var(--accent-secondary);
}

/* Margin Notes */
.margin-note {
    display: none;
}

@media (min-width: 1200px) {
    .margin-note {
        display: block;
        position: absolute;
        width: 180px;
        z-index: 2;
    }

    .margin-note-left {
        left: -210px;
    }

    .margin-note-right {
        right: -210px;
    }

    .margin-note p {
        font-family: 'JetBrains Mono', monospace;
        font-weight: 300;
        font-size: clamp(0.7rem, 0.8vw, 0.8rem);
        color: var(--annotation);
        letter-spacing: 0.01em;
        line-height: 1.5;
    }
}

.margin-diagram {
    display: block;
    margin-bottom: 0.5rem;
}

.greek-annotation {
    font-family: 'Cormorant Garamond', serif;
    font-style: italic;
    font-size: 1.2rem;
    color: var(--annotation);
    display: block;
    margin: 0.5rem 0;
}

/* Simulation Panels */
.simulation-panel {
    display: block;
    width: 100%;
    max-width: 680px;
    border-radius: 2px;
    border: 1px solid var(--bg-secondary);
    margin: 2rem 0 0.5rem;
    background: var(--bg-secondary);
    cursor: crosshair;
}

.sim-label {
    font-family: 'Fira Code', monospace;
    font-weight: 500;
    font-size: 0.75rem;
    color: var(--annotation);
    text-align: center;
    margin-bottom: 1rem;
}

/* Section Dividers */
.section-divider {
    display: block;
    margin: 1rem auto;
    max-width: 100%;
    height: auto;
}

.section-divider path {
    fill: none;
    stroke: var(--sim-lines);
    stroke-width: 1;
    stroke-linecap: round;
}

/* Colophon */
.colophon {
    border-top: 1px solid var(--bg-secondary);
    padding: 3rem 0 4rem;
    text-align: center;
}

.colophon p {
    font-family: 'Cormorant Garamond', serif;
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--text-heading);
    letter-spacing: 0.02em;
}

.colophon-note {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 300;
    font-size: 0.75rem;
    color: var(--annotation);
    margin-top: 0.5rem;
}

/* Path draw animation */
.section-divider path,
.lorenz-attractor path:not(.lorenz-fill) {
    transition: stroke-dashoffset 2s var(--ease);
}

.draw-ready path:not(.lorenz-fill) {
    stroke-dashoffset: var(--path-length);
    stroke-dasharray: var(--path-length);
}

.draw-active path:not(.lorenz-fill) {
    stroke-dashoffset: 0;
}
