/* ==========================================================================
   whitepapers.xyz - Scholarly Documentation Aesthetic
   Colors: #FAFAF9, #1A1A1A, #4F4F4F, #C5504A, #D0D0D0, #F5F1E8
   Fonts: Crimson Text, Inter, JetBrains Mono
   ========================================================================== */

/* --- Reset & Base --- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: 'Inter', sans-serif;
    font-weight: 400;
    line-height: 1.7;
    color: #1A1A1A;
    background-color: #FAFAF9;
    overflow-x: hidden;
}

/* --- Typography --- */
h1, h2, h3 {
    font-family: 'Crimson Text', serif;
    font-weight: 700;
    letter-spacing: -0.03em;
    color: #1A1A1A;
}

h2 {
    font-size: clamp(2rem, 5vw, 3.5rem);
    line-height: 1.15;
}

h3 {
    font-size: clamp(1.2rem, 3vw, 1.6rem);
    line-height: 1.3;
    margin-top: 2.5rem;
    margin-bottom: 1rem;
    color: #1A1A1A;
}

p {
    margin-bottom: 1.25rem;
    max-width: 70ch;
}

a {
    color: #C5504A;
    text-decoration: none;
    transition: background-color 0.2s ease;
}

a:hover {
    text-decoration: underline;
    background-color: rgba(197, 80, 74, 0.1);
}

/* --- Hero Section --- */
.hero {
    position: relative;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 4rem 2rem;
    background: linear-gradient(170deg, #FAFAF9 0%, #F5F1E8 40%, #FAFAF9 100%);
    overflow: hidden;
}

.hero-overlay {
    position: absolute;
    inset: 0;
    background-image:
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 39px,
            rgba(208, 208, 208, 0.25) 39px,
            rgba(208, 208, 208, 0.25) 40px
        );
    pointer-events: none;
    opacity: 0.5;
}

.hero-content {
    position: relative;
    z-index: 1;
    max-width: 720px;
    transition: transform 0.6s ease, opacity 0.6s ease;
}

.hero-label {
    display: inline-block;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
    color: #4F4F4F;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    margin-bottom: 2rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid #D0D0D0;
}

.hero-title {
    font-family: 'Crimson Text', serif;
    font-size: clamp(2.5rem, 7vw, 4.5rem);
    font-weight: 700;
    line-height: 1.1;
    letter-spacing: -0.03em;
    color: #1A1A1A;
    margin-bottom: 1.5rem;
}

.hero-subtitle {
    font-family: 'Inter', sans-serif;
    font-size: 1.125rem;
    line-height: 1.7;
    color: #4F4F4F;
    max-width: 560px;
    margin: 0 auto 2rem;
}

.hero-meta {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.75rem;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    color: #4F4F4F;
}

.hero-meta-divider {
    color: #D0D0D0;
}

.scroll-indicator {
    position: absolute;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.7rem;
    color: #4F4F4F;
    opacity: 1;
    transition: opacity 0.4s ease;
}

.scroll-indicator.hidden {
    opacity: 0;
    pointer-events: none;
}

.scroll-dot {
    animation: scrollBounce 2s ease-in-out infinite;
}

@keyframes scrollBounce {
    0%, 100% { transform: translateY(0); opacity: 1; }
    50% { transform: translateY(4px); opacity: 0.3; }
}

/* --- Table of Contents (Sticky Sidebar) --- */
.toc {
    position: fixed;
    right: 2rem;
    top: 50%;
    transform: translateY(-50%);
    z-index: 100;
    opacity: 0;
    transition: opacity 0.4s ease;
    pointer-events: none;
}

.toc.visible {
    opacity: 1;
    pointer-events: all;
}

.toc-inner {
    background-color: #FAFAF9;
    border-left: 2px solid #D0D0D0;
    padding: 1rem 1.25rem;
}

.toc-heading {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.7rem;
    color: #4F4F4F;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    display: block;
    margin-bottom: 0.75rem;
}

.toc-list {
    list-style: none;
}

.toc-list li {
    margin-bottom: 0.4rem;
}

.toc-link {
    font-family: 'Inter', sans-serif;
    font-size: 0.8rem;
    color: #4F4F4F;
    text-decoration: none;
    padding: 0.15rem 0;
    display: block;
    transition: color 0.2s ease, border-left 0.2s ease;
    border-left: 2px solid transparent;
    padding-left: 0.5rem;
    margin-left: -1.25rem;
    background: none;
}

.toc-link:hover {
    color: #1A1A1A;
    text-decoration: none;
    background: none;
}

.toc-link.active {
    color: #C5504A;
    border-left-color: #C5504A;
    background: none;
}

/* Mobile TOC Toggle */
.toc-toggle {
    display: none;
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 200;
    background-color: #FAFAF9;
    border: 1px solid #D0D0D0;
    padding: 0.5rem 0.8rem;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    color: #1A1A1A;
    cursor: pointer;
    align-items: center;
    gap: 0.4rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

/* --- Main Content --- */
.main-content {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 2rem 4rem;
    position: relative;
}

/* --- Chapter Sections --- */
.chapter {
    padding: 4rem 0;
}

.chapter-header {
    text-align: center;
    margin-bottom: 3rem;
}

.chapter-number {
    display: block;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    color: #C5504A;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    margin-bottom: 0.75rem;
}

.chapter-title {
    margin-bottom: 1.5rem;
}

.hairline {
    width: 60px;
    height: 1px;
    background-color: #D0D0D0;
    margin: 0 auto;
}

/* --- Chapter Body: Text + Sidebar Layout --- */
.chapter-body {
    display: grid;
    grid-template-columns: 1fr 220px;
    gap: 3rem;
    align-items: start;
}

.text-column {
    max-width: 70ch;
}

.lead-paragraph {
    font-size: 1.125rem;
    line-height: 1.8;
    color: #1A1A1A;
    margin-bottom: 1.5rem;
}

.lead-paragraph::first-letter {
    font-family: 'Crimson Text', serif;
    font-size: 3.5rem;
    float: left;
    line-height: 0.8;
    margin-right: 0.1em;
    margin-top: 0.1em;
    color: #C5504A;
}

/* --- Sidebar Notes (Marginalia) --- */
.sidebar-notes {
    position: sticky;
    top: 2rem;
}

.margin-note {
    margin-bottom: 1.5rem;
    padding: 0.75rem;
    background-color: #F5F1E8;
    border-left: 2px solid #D0D0D0;
}

.margin-note .note-marker {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.7rem;
    font-weight: 500;
    color: #C5504A;
    display: block;
    margin-bottom: 0.25rem;
}

.margin-note p {
    font-size: 0.8rem;
    line-height: 1.5;
    color: #4F4F4F;
    margin-bottom: 0;
}

/* --- Callout Boxes --- */
.callout {
    background-color: #F5F1E8;
    padding: 1.5rem;
    margin: 2rem 0;
    border-left: 3px solid #C5504A;
}

.callout-label {
    display: block;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.7rem;
    font-weight: 500;
    color: #C5504A;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 0.5rem;
}

.callout p {
    font-size: 0.95rem;
    line-height: 1.6;
    color: #1A1A1A;
    margin-bottom: 0;
}

/* --- Inline Citations --- */
.inline-citation {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    line-height: 1.5;
    color: #4F4F4F;
    padding: 1rem 0;
    margin: 1.5rem 0;
    border-top: 1px solid #D0D0D0;
    border-bottom: 1px solid #D0D0D0;
}

.citation-ref {
    color: #C5504A;
    font-weight: 500;
    margin-right: 0.5rem;
}

/* --- Diagram Breaks --- */
.diagram-break {
    padding: 3rem 0;
    text-align: center;
    max-width: 800px;
    margin: 0 auto;
}

.diagram-svg {
    width: 100%;
    max-width: 700px;
    height: auto;
}

/* --- References Section --- */
.references-list {
    max-width: 65ch;
}

.reference-item {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid rgba(208, 208, 208, 0.5);
}

.reference-number {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    color: #C5504A;
    flex-shrink: 0;
    padding-top: 0.15rem;
}

.reference-item p {
    font-size: 0.9rem;
    line-height: 1.5;
    color: #4F4F4F;
    margin-bottom: 0;
}

/* --- Footer --- */
.site-footer {
    padding: 3rem 0 2rem;
}

.footer-content {
    max-width: 1100px;
    margin: 0 auto;
}

.footer-grid {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 2rem 0 1.5rem;
}

.footer-brand {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
    color: #1A1A1A;
    display: block;
    margin-bottom: 0.25rem;
}

.footer-tagline {
    font-size: 0.85rem;
    color: #4F4F4F;
    margin-bottom: 0;
}

.footer-right {
    text-align: right;
}

.footer-meta {
    display: block;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    color: #4F4F4F;
    margin-bottom: 0.25rem;
}

.footer-license {
    font-size: 0.8rem;
    color: #D0D0D0;
    border-top: 1px solid #D0D0D0;
    padding-top: 1rem;
}

/* --- Footnote Tooltip --- */
.footnote-tooltip {
    position: fixed;
    z-index: 300;
    background-color: #F5F1E8;
    border: 1px solid #D0D0D0;
    padding: 0.75rem 1rem;
    font-size: 0.8rem;
    line-height: 1.5;
    color: #4F4F4F;
    max-width: 300px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.footnote-tooltip.visible {
    opacity: 1;
}

/* --- Marginalia Page Numbers --- */
.marginalia {
    position: fixed;
    right: 2rem;
    bottom: 2rem;
    z-index: 50;
    opacity: 0;
    transition: opacity 0.4s ease;
    pointer-events: none;
}

.marginalia.visible {
    opacity: 1;
}

.page-number {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    color: #4F4F4F;
}

/* --- Fade-in Animation --- */
.fade-section {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.6s ease-out, transform 0.6s ease-out;
}

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

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

    .toc.mobile-visible {
        display: block;
        position: fixed;
        right: 1rem;
        bottom: 4rem;
        top: auto;
        transform: none;
        background-color: #FAFAF9;
        border: 1px solid #D0D0D0;
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
        opacity: 1;
        pointer-events: all;
    }

    .toc-toggle {
        display: flex;
    }

    .chapter-body {
        grid-template-columns: 1fr;
        gap: 2rem;
    }

    .sidebar-notes {
        position: static;
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 1rem;
    }

    .marginalia {
        display: none;
    }

    .main-content {
        padding: 0 1.5rem 3rem;
    }

    .hero {
        padding: 3rem 1.5rem;
    }
}

@media (max-width: 600px) {
    .sidebar-notes {
        grid-template-columns: 1fr;
    }

    .hero-title {
        font-size: 2.2rem;
    }

    .footer-grid {
        flex-direction: column;
        gap: 1rem;
    }

    .footer-right {
        text-align: left;
    }

    .diagram-break {
        padding: 2rem 0;
    }
}
