:root {
    --bg-primary: #faf7f1;
    --bg-secondary: #f0ece4;
    --bg-sidebar: #f5f0e8;
    --text-primary: #3d3529;
    --text-body: #4a4238;
    --accent-primary: #6b7c5e;
    --accent-secondary: #a3b18a;
    --accent-tertiary: #c4956a;
    --border-rule: #ddd6cb;
    --caption-color: #8a8377;
    --marginalia-color: #a3967e;
    --grid-cream: #d5cfc5;
    --grid-parchment: #c9c3b9;
}

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

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Source Serif 4', Georgia, serif;
    color: var(--text-body);
    background: var(--bg-primary);
    line-height: 1.75;
    font-size: clamp(1rem, 1.1vw, 1.125rem);
    font-weight: 400;
}

/* Sidebar */
.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: 240px;
    height: 100vh;
    background: var(--bg-sidebar);
    display: flex;
    flex-direction: column;
    padding: 2.5rem 1.5rem;
    z-index: 10;
}

.wordmark {
    font-family: 'IBM Plex Sans', sans-serif;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-primary);
    letter-spacing: 0.02em;
    margin-bottom: 2.5rem;
    display: block;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.sidebar-link {
    font-family: 'IBM Plex Sans', sans-serif;
    font-size: 0.85rem;
    font-weight: 400;
    color: var(--accent-primary);
    text-decoration: none;
    letter-spacing: 0.04em;
    line-height: 2.2;
    position: relative;
    transition: color 400ms ease-out;
}

.sidebar-link:hover {
    color: var(--accent-secondary);
}

.sidebar-link.active {
    font-weight: 500;
    color: var(--text-primary);
}

.sidebar-link.active::before {
    content: '';
    position: absolute;
    left: -1.5rem;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 2px;
    background: var(--accent-primary);
    transition: top 800ms ease-out;
}

.sidebar-leaf {
    width: 60px;
    height: 90px;
    margin-top: auto;
    align-self: center;
    opacity: 0.6;
    transition: transform 600ms ease-out;
}

/* Reading Pane */
.reading-pane {
    margin-left: 240px;
}

.chapter {
    min-height: 100vh;
    position: relative;
    display: flex;
    padding: 6rem 3rem 6rem 4rem;
}

.chapter--cream {
    background-color: var(--bg-primary);
    background-image: url("data:image/svg+xml,%3Csvg width='32' height='32' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 16 H32 M16 0 V32' stroke='%23d5cfc5' stroke-width='0.5' opacity='0.03'/%3E%3C/svg%3E");
}

.chapter--parchment {
    background-color: var(--bg-secondary);
    background-image: url("data:image/svg+xml,%3Csvg width='32' height='32' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 16 H32 M16 0 V32' stroke='%23c9c3b9' stroke-width='0.5' opacity='0.03'/%3E%3C/svg%3E");
}

.chapter-content {
    max-width: 640px;
    flex: 1;
}

.chapter-title {
    font-family: 'Playfair Display', Georgia, serif;
    font-weight: 700;
    font-style: italic;
    font-size: clamp(2rem, 4vw, 3.5rem);
    color: var(--text-primary);
    letter-spacing: -0.01em;
    line-height: 1.2;
    margin-bottom: 1.5rem;
}

.chapter-body {
    margin-bottom: 1.5em;
}

.chapter-body--lead {
    font-size: clamp(1.1rem, 1.3vw, 1.25rem);
    font-weight: 600;
    line-height: 1.65;
}

/* Typewriter cursor */
.typewriter-cursor {
    display: inline-block;
    width: 2px;
    height: 0.85em;
    background: var(--accent-tertiary);
    margin-left: 4px;
    vertical-align: baseline;
    animation: blink 1.2s ease-in-out infinite;
    transition: opacity 3s ease-out;
}

.typewriter-cursor--hidden {
    opacity: 0;
}

@keyframes blink {
    0%, 100% { opacity: 0; }
    50% { opacity: 0.8; }
}

/* Divider rules */
.divider-rule {
    width: 100%;
    max-width: 400px;
    height: 4px;
    margin: 2rem 0;
    display: block;
}

/* Margin collage */
.margin-collage {
    position: sticky;
    top: 30vh;
    align-self: flex-start;
    width: 120px;
    margin-left: 3rem;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.margin-collage--mid {
    top: 40vh;
}

.margin-collage--low {
    top: 50vh;
}

.botanical-specimen {
    width: 80px;
    height: auto;
    opacity: 0.7;
    transition: transform 600ms ease-out, opacity 600ms ease-out;
}

.botanical-specimen.in-view {
    transform: scale(1.03);
    opacity: 0.85;
}

.marginalia {
    font-family: 'Caveat', cursive;
    font-size: 0.9rem;
    font-weight: 400;
    color: var(--marginalia-color);
    text-align: center;
    line-height: 1.4;
}

/* Responsive: sidebar collapses to top bar */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        width: 100%;
        height: auto;
        flex-direction: row;
        align-items: center;
        padding: 0.75rem 1.25rem;
        gap: 1.5rem;
        overflow-x: auto;
    }

    .wordmark {
        margin-bottom: 0;
        white-space: nowrap;
    }

    .sidebar-nav {
        flex-direction: row;
        gap: 1.25rem;
    }

    .sidebar-link {
        white-space: nowrap;
        line-height: 1.6;
    }

    .sidebar-link.active::before {
        left: 0;
        top: auto;
        bottom: -4px;
        width: 100%;
        height: 2px;
        transform: none;
    }

    .sidebar-leaf {
        display: none;
    }

    .reading-pane {
        margin-left: 0;
        margin-top: 52px;
    }

    .chapter {
        padding: 3rem 1.5rem;
        flex-direction: column;
    }

    .margin-collage {
        position: relative;
        top: auto;
        flex-direction: row;
        width: 100%;
        margin-left: 0;
        margin-top: 2rem;
        justify-content: center;
    }
}
