:root {
    --bg: #000000;
    --text: rgba(255, 255, 255, 0.85);
    --text-muted: rgba(255, 255, 255, 0.5);
    --accent: #9a9a9a;
    --border: rgba(255, 255, 255, 0.1);
}

[data-theme="light"] {
    --bg: #f5f1e8;
    --text: rgba(0, 0, 0, 0.85);
    --text-muted: rgba(0, 0, 0, 0.5);
    --border: rgba(0, 0, 0, 0.1);
    --accent: #8b7355;
}

[data-theme="sepia"] {
    --bg: #f9f3e3;
    --text: #5c4b37;
    --text-muted: rgba(92, 75, 55, 0.6);
    --border: rgba(92, 75, 55, 0.15);
    --accent: #8b7355;
}

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

body {
    font-family: 'Crimson Text', serif;
    background: var(--bg);
    color: var(--text);
    transition: background 0.3s ease, color 0.3s ease;
}

/* Reader Controls */
.reader-controls {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.3s ease;
}

.back-link {
    font-family: 'Inter', sans-serif;
    font-size: 0.8rem;
    color: var(--text-muted);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: color 0.3s ease;
}

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

.back-link::before {
    content: '←';
}

.chapter-nav {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
}

.chapter-select {
    font-family: 'Inter', sans-serif;
    font-size: 0.8rem;
    font-weight: 400;
    color: var(--text-muted);
    letter-spacing: 0.05em;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    padding: 0.4rem 1.8rem 0.4rem 0.75rem;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23888' d='M6 8L2 4h8z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
    transition: all 0.2s ease;
}

.chapter-select:hover {
    color: var(--text);
    border-color: var(--text-muted);
}

.chapter-select:focus {
    outline: none;
    color: var(--text);
    border-color: var(--accent);
}

.chapter-select option {
    background: var(--bg);
    color: var(--text);
}

.controls-group {
    display: flex;
    gap: 1.5rem;
    align-items: center;
}

.theme-toggles {
    display: flex;
    gap: 0.5rem;
}

.theme-btn {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid var(--border);
    cursor: pointer;
    transition: transform 0.2s ease;
}

.theme-btn:hover {
    transform: scale(1.1);
}

.theme-btn.dark {
    background: #000;
}

.theme-btn.light {
    background: #f5f1e8;
}

.theme-btn.sepia {
    background: #f9f3e3;
}

.theme-btn.active {
    border-color: var(--accent);
}

.font-controls {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.font-btn {
    font-family: 'Inter', sans-serif;
    font-weight: 500;
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 0.25rem 0.6rem;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.font-btn:hover {
    border-color: var(--text-muted);
    color: var(--text);
}

.audio-toggle {
    font-family: 'Inter', sans-serif;
    font-size: 0.8rem;
    color: var(--text-muted);
    background: none;
    border: 1px solid var(--border);
    padding: 0.4rem 0.8rem;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.audio-toggle:hover {
    border-color: var(--text-muted);
    color: var(--text);
}

/* Vertical Progress Sidebar */
.progress-sidebar {
    position: fixed;
    right: 2rem;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    z-index: 50;
}

.page-indicator {
    font-family: 'Inter', sans-serif;
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
    text-align: center;
}

.page-indicator .current {
    color: var(--text);
    font-weight: 500;
}

/* Main Content Area */
.reader-page {
    max-width: 700px;
    margin: 0 auto;
    padding: 6rem 2rem 4rem;
}

.chapter-header {
    text-align: center;
    margin-bottom: 3rem;
    padding-bottom: 2rem;
    border-bottom: 1px solid var(--border);
}

.chapter-number {
    font-family: 'Inter', sans-serif;
    font-size: 0.75rem;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.chapter-title {
    font-family: 'Crimson Text', serif;
    font-size: 2rem;
    font-weight: 400;
    line-height: 1.3;
}

.citations-link {
    display: inline-block;
    font-family: 'Inter', sans-serif;
    font-size: 0.7rem;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    text-decoration: none;
    margin-top: 1rem;
    transition: all 0.2s ease;
    opacity: 0.7;
}

.citations-link:hover {
    opacity: 1;
    color: var(--text);
}

/* Chapter Content */
.chapter-content {
    font-size: var(--reader-font-size, 1.25rem);
    line-height: 1.5;
    letter-spacing: -0.015em;
    word-spacing: -0.05em;
}

.page-section {
    margin-bottom: 0;
}

.page-section p {
    margin-bottom: 0.35em;
    text-indent: 1.5em;
}

.page-section:first-child p:first-child {
    text-indent: 0;
}

.page-section:first-child p:first-child::first-letter {
    font-size: 3.5em;
    float: left;
    line-height: 0.8;
    padding-right: 0.1em;
    margin-top: 0.1em;
}

.chapter-content h3 {
    font-family: 'Crimson Text', serif;
    font-size: 1.1em;
    font-weight: 600;
    margin-top: 1.25em;
    margin-bottom: 1.25em;
    color: var(--text);
    text-align: center;
}

/* End of Chapter */
.chapter-end {
    text-align: center;
    padding: 4rem 0;
    margin-top: 2rem;
    border-top: 1px solid var(--border);
}

.end-marker {
    font-family: 'Inter', sans-serif;
    font-size: 0.7rem;
    letter-spacing: 0.3em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 2rem;
}

.chapter-nav {
    display: flex;
    justify-content: center;
    gap: 3rem;
    align-items: center;
}

.nav-btn {
    font-family: 'Crimson Text', serif;
    font-size: 1.1rem;
    font-style: italic;
    color: var(--text-muted);
    text-decoration: none;
    transition: color 0.3s ease;
}

.nav-btn:hover {
    color: var(--accent);
}

.nav-btn.next {
    font-style: normal;
    font-weight: 600;
    color: var(--text);
}

.nav-btn.next:hover {
    color: var(--accent);
}

/* Below Chapter: Citations & Questions */
.below-chapter-cue {
    text-align: center;
    padding: 3rem 0;
    color: var(--text-muted);
    font-family: 'Inter', sans-serif;
    font-size: 0.8rem;
    letter-spacing: 0.1em;
}

.below-chapter-cue span {
    display: block;
    margin-top: 0.5rem;
    font-size: 1.2rem;
}

.citations-section,
.questions-section {
    padding: 3rem 0;
    border-top: 1px solid var(--border);
}

.section-label {
    font-family: 'Inter', sans-serif;
    font-size: 0.75rem;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

.citation {
    font-size: 0.95rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
}

.citation strong {
    font-weight: 700;
    color: var(--text);
}

.citation a {
    color: var(--accent);
    text-decoration: none;
}

.citation a:hover {
    text-decoration: underline;
}

.question-item {
    font-size: 1.1rem;
    margin-bottom: 1rem;
    padding-left: 1.5rem;
    position: relative;
}

.question-item::before {
    content: '→';
    position: absolute;
    left: 0;
    color: var(--accent);
}

/* Chemical/Data Tables */
.chart-container {
    margin: 2rem 0;
    overflow-x: auto;
}

.chemical-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    line-height: 1.4;
}

.chemical-table th,
.chemical-table td {
    padding: 0.75rem 1rem;
    text-align: left;
    border: 1px solid var(--border);
    vertical-align: top;
}

.chemical-table th {
    background: rgba(255, 255, 255, 0.05);
    font-family: 'Inter', sans-serif;
    font-weight: 500;
    font-size: 0.8rem;
    letter-spacing: 0.02em;
    color: var(--text);
}

[data-theme="light"] .chemical-table th,
[data-theme="sepia"] .chemical-table th {
    background: rgba(0, 0, 0, 0.03);
}

.chemical-table td {
    color: var(--text-muted);
}

.chemical-table td:first-child {
    color: var(--text);
    white-space: nowrap;
}

.chemical-table td:last-child {
    color: var(--text);
}

.chemical-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.02);
}

[data-theme="light"] .chemical-table tbody tr:hover,
[data-theme="sepia"] .chemical-table tbody tr:hover {
    background: rgba(0, 0, 0, 0.02);
}

/* Causal Tree Diagram */
.causal-tree {
    margin: 2.5rem 0;
}

.tree-title {
    text-align: center;
    font-family: 'Inter', sans-serif;
    font-size: 1.3rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
    color: var(--text);
}

.tree-level {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.25rem;
    margin-bottom: 1rem;
}

.level-header {
    font-family: 'Inter', sans-serif;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    margin-bottom: 1rem;
}

.tree-items {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.tree-item {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.5rem 0.75rem;
    font-size: 0.85rem;
    line-height: 1.4;
}

[data-theme="light"] .tree-item,
[data-theme="sepia"] .tree-item {
    background: rgba(0, 0, 0, 0.03);
}

.item-letter, .item-number {
    display: inline-block;
    background: var(--accent);
    color: white;
    font-family: 'Inter', sans-serif;
    font-size: 0.7rem;
    font-weight: 600;
    width: 1.4em;
    height: 1.4em;
    line-height: 1.4em;
    text-align: center;
    border-radius: 3px;
    margin-right: 0.4rem;
}

.item-state {
    color: var(--text-muted);
    font-size: 0.8rem;
}

.item-refs {
    color: var(--text-muted);
    font-family: 'Inter', sans-serif;
    font-size: 0.7rem;
    margin-left: 0.25rem;
}

/* Disease Mapping List */
.disease-mapping {
    margin: 2rem 0;
}

.mapping-intro {
    margin-bottom: 0.75rem;
    text-indent: 0 !important;
}

.mapping-list {
    margin-bottom: 1.5rem;
    padding-left: 0;
}

.mapping-item {
    font-size: inherit;
    line-height: 1.8;
    text-indent: 0;
}

/* Book Footer */
.book-footer {
    margin-top: 4rem;
    padding: 3rem 0;
    border-top: 1px solid var(--border);
    font-family: 'Inter', sans-serif;
    font-size: 0.9rem;
    line-height: 1.8;
    color: var(--text-muted);
}

.book-footer .epigraph {
    font-family: 'Crimson Text', serif;
    font-style: italic;
    font-size: 1.1rem;
    color: var(--text);
    margin-bottom: 2rem;
}

.book-footer p {
    margin-bottom: 1rem;
}

.book-footer a {
    color: var(--accent);
    text-decoration: none;
}

.book-footer a:hover {
    text-decoration: underline;
}

.book-footer .term {
    font-weight: 500;
    color: var(--text);
}

.book-footer .attribution {
    margin-top: 2rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.book-footer .book-title {
    font-family: 'Crimson Text', serif;
    font-style: italic;
    font-size: 1rem;
    color: var(--text);
    margin-top: 1.5rem;
    margin-bottom: 0.5rem;
}

.book-footer .book-subtitle {
    font-size: 0.85rem;
    margin-bottom: 1rem;
}

/* Hide mobile indicator on desktop (will be shown via media query below) */
.mobile-page-indicator {
    display: none;
}

/* Mobile adjustments - switch to mobile layout at 900px */
@media (max-width: 900px) {
    .progress-sidebar {
        display: none;
    }

    .reader-page {
        padding: 6.5rem 1.5rem 3rem;
    }

    .reader-controls {
        padding: 0.75rem 1rem;
        flex-wrap: wrap;
    }

    /* Hide "Book" text, keep arrow */
    .back-link {
        font-size: 0;
    }
    .back-link::before {
        font-size: 1rem;
    }

    /* Remove absolute positioning on mobile */
    .chapter-nav {
        position: static;
        transform: none;
        margin-left: 0.75rem;
    }

    .controls-group {
        gap: 0.75rem;
        margin-left: auto;
    }

    /* Mobile page indicator bar - fixed at bottom */
    .mobile-page-indicator {
        display: block !important;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: var(--bg);
        text-align: center;
        font-family: 'Inter', sans-serif;
        font-size: 0.75rem;
        color: var(--text-muted);
        padding: 0.6rem 1rem;
        border-top: 1px solid var(--border);
        z-index: 100;
        transition: opacity 0.3s ease, transform 0.3s ease;
    }

    .mobile-page-indicator.hidden {
        opacity: 0;
        transform: translateY(100%);
        pointer-events: none;
    }

    .audio-toggle {
        display: none;
    }
}
