/* ==========================================================
   economic.wiki — Dark Academia Scholarly Reading Experience
   Color Palette:
     Background:      #FAF6F0 (warm parchment cream)
     Primary Text:    #2C2420 (near-black walnut)
     Burgundy Accent: #7B2D3B (deep wine red)
     Margin Text:     #8C7B6B (warm taupe)
     Rule Lines:      #6B4C3B (medium brown, at 30% opacity)
     Diagram Stroke:  #3D2E24 (dark umber)
     Highlight:       #F0E4C8 (pale gold)
     Deep Background: #1E1A16 (espresso dark)
   ========================================================== */

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

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

body {
    background-color: #FAF6F0;
    color: #2C2420;
    font-family: 'Cormorant Garamond', 'Georgia', serif;
    font-size: 19px;
    line-height: 1.72;
    font-weight: 400;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ---- Chapter Navigation Sidebar ---- */
.chapter-nav {
    position: fixed;
    left: 0;
    top: 0;
    width: 48px;
    height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 24px;
    z-index: 100;
    background: transparent;
}

.chapter-link {
    font-family: 'Cormorant Garamond', serif;
    font-size: 16px;
    font-weight: 600;
    color: #8C7B6B;
    text-decoration: none;
    position: relative;
    transition: color 300ms ease;
    letter-spacing: 0.02em;
}

.chapter-link.active {
    color: #7B2D3B;
}

.chapter-link.active::after {
    content: '';
    position: absolute;
    bottom: -6px;
    left: 50%;
    transform: translateX(-50%);
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background-color: #7B2D3B;
    transition: opacity 300ms ease;
}

/* ---- Main Document Layout ---- */
.document {
    display: grid;
    grid-template-columns: 48px 1fr minmax(200px, 680px) minmax(180px, 28%) 1fr;
    min-height: 100vh;
}

.document-header,
.chapter,
.colophon {
    grid-column: 3 / 5;
}

/* ---- Document Header ---- */
.document-header {
    padding-top: 60px;
    padding-bottom: 20px;
    grid-column: 3 / 4;
}

.domain-name {
    font-family: 'Cormorant Garamond', serif;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.25em;
    text-transform: uppercase;
    color: #8C7B6B;
}

.title-rule {
    border: none;
    border-top: 1px solid rgba(107, 76, 59, 0.3);
    margin-top: 16px;
}

/* ---- Chapter Sections ---- */
.chapter {
    padding-top: 120px;
    padding-bottom: 0;
    grid-column: 3 / 5;
}

.chapter:first-of-type {
    padding-top: 40px;
}

.chapter-title {
    font-family: 'Cormorant Garamond', serif;
    font-size: 32px;
    font-weight: 600;
    color: #2C2420;
    letter-spacing: -0.01em;
    margin-bottom: 32px;
    line-height: 1.3;
}

.chapter-numeral {
    color: #8C7B6B;
    margin-right: 12px;
    font-weight: 400;
}

/* ---- Chapter Content & Marginalia Grid ---- */
.chapter-content {
    display: grid;
    grid-template-columns: minmax(200px, 680px) minmax(160px, 240px);
    gap: 40px;
}

.main-text {
    grid-column: 1 / 2;
    position: relative;
}

/* ---- Typography ---- */
p {
    margin-bottom: 20px;
    letter-spacing: 0;
}

em {
    font-style: italic;
}

strong {
    font-weight: 600;
}

code {
    font-family: 'JetBrains Mono', monospace;
    font-size: 15px;
    font-weight: 400;
    background-color: #F5F0E8;
    padding: 1px 4px;
    border-radius: 2px;
}

/* ---- Drop Caps ---- */
.drop-cap {
    float: left;
    font-family: 'Cormorant Garamond', serif;
    font-size: 72px;
    font-weight: 700;
    line-height: 0.8;
    color: #7B2D3B;
    margin-right: 8px;
    margin-top: 6px;
}

/* ---- Marginalia ---- */
.marginalia {
    position: relative;
    opacity: 0;
    transition: opacity 400ms ease;
    float: right;
    clear: right;
    width: 200px;
    margin-right: -240px;
    margin-bottom: 20px;
    padding-left: 16px;
}

.marginalia.visible {
    opacity: 1;
}

.margin-note {
    font-family: 'Source Serif 4', 'Georgia', serif;
    font-size: 14px;
    line-height: 1.55;
    color: #8C7B6B;
    font-weight: 400;
    margin-bottom: 8px;
}

.sparkline {
    display: block;
    width: 60px;
    height: 20px;
    margin-top: 8px;
}

/* ---- Definitions (Blockquotes with typewriter effect) ---- */
.definition {
    margin: 32px 0;
    padding: 20px 24px;
    border-left: 2px solid #7B2D3B;
    background: transparent;
    font-family: 'Cormorant Garamond', serif;
    font-size: 19px;
    line-height: 1.72;
    color: #2C2420;
    position: relative;
}

.definition .pilcrow {
    color: rgba(140, 123, 107, 0.6);
    margin-right: 4px;
}

.definition .typewriter-cursor {
    display: inline-block;
    width: 2px;
    height: 20px;
    background-color: #7B2D3B;
    vertical-align: text-bottom;
    animation: blink-cursor 0.6s step-end infinite;
}

.definition .typewriter-cursor.fade-out {
    animation: blink-cursor 0.6s step-end 3, fade-cursor 0.3s ease 1.8s forwards;
}

@keyframes blink-cursor {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

@keyframes fade-cursor {
    to { opacity: 0; }
}

/* ---- Pull Quotes ---- */
.pull-quote {
    margin: 40px 0;
    padding: 0 40px;
    border-left: 2px solid #7B2D3B;
    font-family: 'Cormorant Garamond', serif;
    font-style: italic;
    font-size: 24px;
    line-height: 1.55;
    color: #2C2420;
}

.pull-quote p {
    margin-bottom: 12px;
}

.pull-quote cite {
    display: block;
    font-family: 'Source Serif 4', serif;
    font-style: normal;
    font-variant: small-caps;
    font-size: 13px;
    color: #8C7B6B;
    letter-spacing: 0.03em;
}

/* ---- Footnotes ---- */
.footnote-ref {
    font-family: 'Source Serif 4', serif;
    font-size: 13px;
    color: #7B2D3B;
    cursor: pointer;
    text-decoration: none;
    position: relative;
    top: -2px;
    margin-left: 1px;
}

.footnote-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 400ms ease, padding 400ms ease;
    background-color: #F0E4C8;
    border-radius: 2px;
    margin-bottom: 20px;
    padding: 0 20px;
}

.footnote-content.expanded {
    max-height: 300px;
    padding: 16px 20px;
}

.footnote-content p {
    font-family: 'Source Serif 4', serif;
    font-size: 14px;
    line-height: 1.55;
    color: #2C2420;
    margin-bottom: 0;
}

/* ---- Chapter Dividers ---- */
.chapter-divider {
    text-align: center;
    padding: 120px 0 0;
    color: rgba(107, 76, 59, 0.4);
    font-size: 3px;
    letter-spacing: 16px;
    line-height: 1;
}

.diamond {
    font-size: 6px;
    margin: 0 8px;
    display: inline-block;
}

/* ---- SVG Diagrams ---- */
.diagram {
    margin: 40px 0;
    max-width: 100%;
}

.econ-diagram {
    width: 100%;
    max-width: 440px;
    height: auto;
    display: block;
}

.axis-label {
    font-family: 'Source Serif 4', serif;
    font-size: 12px;
    fill: #3D2E24;
    text-anchor: middle;
}

.curve-label,
.flow-label {
    font-family: 'Source Serif 4', serif;
    font-size: 14px;
    fill: #3D2E24;
    text-anchor: middle;
}

.diagram-label {
    font-family: 'Source Serif 4', serif;
    fill: #3D2E24;
}

.diagram-caption {
    font-family: 'Source Serif 4', serif;
    font-size: 13px;
    line-height: 1.5;
    color: #8C7B6B;
    margin-top: 12px;
    max-width: 440px;
}

/* Diagram animation: initially hidden paths */
.diagram-curve,
.eq-line {
    opacity: 1;
}

.diagram[data-animated="false"] .diagram-curve {
    stroke-dasharray: var(--path-length, 1000);
    stroke-dashoffset: var(--path-length, 1000);
}

.diagram[data-animated="true"] .diagram-curve {
    stroke-dashoffset: 0;
    transition: stroke-dashoffset 0.8s ease-out;
}

.diagram[data-animated="false"] .diagram-label,
.diagram[data-animated="false"] .curve-label,
.diagram[data-animated="false"] .flow-label,
.diagram[data-animated="false"] .equilibrium-point,
.diagram[data-animated="false"] .diagram-area {
    opacity: 0;
}

.diagram[data-animated="true"] .diagram-label,
.diagram[data-animated="true"] .curve-label,
.diagram[data-animated="true"] .flow-label,
.diagram[data-animated="true"] .equilibrium-point,
.diagram[data-animated="true"] .diagram-area {
    opacity: 1;
    transition: opacity 0.4s ease 0.8s;
}

/* Axes draw first */
.diagram[data-animated="true"] .diagram-axes line {
    stroke-dashoffset: 0;
    transition: stroke-dashoffset 0.3s ease-out;
}

/* ---- Colophon (Footer) ---- */
.colophon {
    background-color: #1E1A16;
    color: #8C7B6B;
    padding: 80px 0;
    margin-top: 120px;
    grid-column: 1 / -1;
}

.colophon-content {
    max-width: 680px;
    margin: 0 auto;
    padding: 0 24px;
}

.colophon-title {
    font-family: 'Cormorant Garamond', serif;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.25em;
    text-transform: uppercase;
    color: #F0E4C8;
    margin-bottom: 20px;
}

.colophon-text {
    font-family: 'Source Serif 4', serif;
    font-size: 14px;
    line-height: 1.65;
    color: #8C7B6B;
    margin-bottom: 12px;
}

.colophon-small {
    font-size: 12px;
    opacity: 0.7;
}

/* ---- Responsive: below 900px ---- */
@media (max-width: 900px) {
    .chapter-nav {
        display: none;
    }

    .document {
        display: block;
        padding: 0 20px;
    }

    .chapter-content {
        display: block;
    }

    .marginalia {
        float: none;
        width: 100%;
        margin-right: 0;
        margin-top: 12px;
        margin-bottom: 24px;
        padding: 12px 16px;
        background-color: rgba(240, 228, 200, 0.3);
        border-radius: 4px;
        opacity: 1;
    }

    .chapter-title {
        font-size: 26px;
    }

    .econ-diagram {
        max-width: 100%;
    }

    .pull-quote {
        padding: 0 20px;
        font-size: 20px;
    }

    .colophon {
        margin-left: -20px;
        margin-right: -20px;
        padding: 60px 20px;
    }
}

/* ---- Responsive: below 600px ---- */
@media (max-width: 600px) {
    body {
        font-size: 17px;
    }

    .document {
        padding: 0 16px;
    }

    .drop-cap {
        font-size: 54px;
    }

    .chapter {
        padding-top: 80px;
    }

    .chapter:first-of-type {
        padding-top: 24px;
    }

    .chapter-divider {
        padding-top: 80px;
    }

    .pull-quote {
        font-size: 18px;
        padding: 0 16px;
    }

    .definition {
        padding: 16px 18px;
        margin: 24px 0;
    }
}
