/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Color scheme variables */
:root {
    /* Light mode colors */
    --bg-primary: #fefefe;
    --bg-sidebar-left: #f8f8f8;
    --bg-sidebar-right: #f9f9f9;
    --bg-controls: #eeeeee;
    --bg-footnote: white;
    --bg-footnote-highlight: #fff3cd;
    --text-primary: #333;
    --text-secondary: #555;
    --text-muted: #666;
    --text-placeholder: #999;
    --border-primary: #ddd;
    --border-secondary: #e0e0e0;
    --border-highlight: #ffeaa7;
    --slider-inactive: #ddd;
    --accent-blue: #3498db;
    --accent-hover: #e8e8e8;
    --accent-hover-footnote: #e3f2fd;
}

body.dark-mode {
    /* Dark mode colors */
    --bg-primary: #1a1a1a;
    --bg-sidebar-left: #2d2d2d;
    --bg-sidebar-right: #2a2a2a;
    --bg-controls: #3a3a3a;
    --bg-footnote: #2d2d2d;
    --bg-footnote-highlight: #4a3800;
    --text-primary: #e0e0e0;
    --text-secondary: #b0b0b0;
    --text-muted: #888;
    --text-placeholder: #666;
    --border-primary: #444;
    --border-secondary: #333;
    --border-highlight: #6b5b00;
    --slider-inactive: #777;
    --accent-blue: #4a9eff;
    --accent-hover: #3a3a3a;
    --accent-hover-footnote: #1a3a5a;
}

body {
    font-family: Georgia, 'Times New Roman', serif;
    line-height: 1.6;
    color: var(--text-primary);
    background-color: var(--bg-primary);
    transition: background-color 0.3s ease, color 0.3s ease;
    hyphens: auto;
    hyphenate-character: "⸗";
}

body {
    display: grid;
    grid-template-columns: 1fr 280px minmax(0, 1000px) 320px 1fr;
    height: 100vh;
}

#title-link {
    color: var(--text-primary);
    text-decoration: none;
    cursor: pointer;
}

.sidebar-left-bg {
    grid-column: 1;
    background-color: var(--bg-sidebar-left);
    transition: background-color 0.3s ease;
}

.sidebar-right-bg {
    grid-column: 5;
    background-color: var(--bg-sidebar-right);
    transition: background-color 0.3s ease;
}

/* Sidebar styles */
.sidebar {
    grid-column: 2;
    background-color: var(--bg-sidebar-left);
    border-right: 1px solid var(--border-primary);
    padding: 2rem 1.5rem;
    overflow-y: auto;
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.sidebar h1 {
    font-size: 1.8rem;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
    font-weight: normal;
    transition: color 0.3s ease;
}

.subtitle {
    font-style: italic;
    color: var(--text-muted);
    margin-bottom: 2rem;
    font-size: 0.9rem;
    transition: color 0.3s ease;
}

/* Style controls */
.style-controls {
    margin: 2rem 0;
    padding: 1rem;
    max-width: 250px;
    background-color: var(--bg-controls);
    border-radius: 6px;
    border: 1px solid var(--border-primary);
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.style-controls h3 {
    margin: 0 0 1rem 0;
    font-size: 1rem;
    color: var(--text-primary);
    font-weight: normal;
    transition: color 0.3s ease;
}

.toggle-control {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    margin-top: 4px;
    font-size: 0.9rem;
}

.toggle-control label {
    color: var(--text-secondary);
    white-space: nowrap;
    transition: color 0.3s ease;
}

/* Toggle switch styling - vertical */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 12px;
    min-width: 12px;
    height: 31px;
    margin-left: auto;
    cursor: pointer;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--slider-inactive);
    border-radius: 24px;
    transition: 0.4s;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: -3px;
    top: 0;
    background-color: white;
    border-radius: 50%;
    transition: 0.4s;
}

input:checked + .slider {
    background-color: var(--accent-blue);
}

input:checked + .slider:before {
    transform: translateY(14px);
}

.toggle-labels {
    display: flex;
    flex-direction: column;
    font-size: 0.8rem;
    color: var(--text-muted);
    line-height: 1.2;
    margin-left: 0.5rem;
    transition: color 0.3s ease;
}

.toggle-off, .toggle-on {
    white-space: nowrap;
}

/* Footnote popup modal */
.footnote-popup {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.footnote-popup.show {
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 1;
}

.footnote-popup-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    cursor: pointer;
}

.footnote-popup-content {
    position: relative;
    background: var(--bg-footnote);
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    max-width: 90vw;
    min-width: 50vw;
    max-height: 80vh;
    margin: 20px;
    overflow: hidden;
    z-index: 1001;
    transition: background-color 0.3s ease;
}

.footnote-popup-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-secondary);
    background-color: var(--bg-controls);
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.footnote-popup-header h4 {
    margin: 0;
    font-size: 1.1rem;
    color: var(--text-primary);
    font-weight: normal;
    transition: color 0.3s ease;
}

.footnote-popup-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0;
    margin-left: 8px;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
}

.footnote-popup-close:hover {
    background-color: var(--accent-hover);
    color: var(--text-primary);
}

.footnote-popup-body {
    padding: 1.5rem;
    overflow-y: auto;
    max-height: 60vh;
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 0.95rem;
    line-height: 1.6;
    color: var(--text-primary);
    transition: color 0.3s ease;
    text-align: justify;
}

.footnote-popup-body .footnote-label {
    font-weight: bold;
    color: var(--accent-blue);
    margin-right: 0.5rem;
    transition: color 0.3s ease;
}


.table-of-contents ul {
    list-style: none;
}

.table-of-contents li {
    /* margin-bottom: 0.5rem; */
}

.table-of-contents a {
    display: block;
    padding: 0.1rem;
    text-decoration: none;
    color: var(--text-secondary);
    border-radius: 4px;
    transition: all 0.2s ease;
    font-size: 0.95rem;
}

.table-of-contents a:hover {
    background-color: var(--accent-hover);
    color: var(--text-primary);
}

.table-of-contents a.active {
    background-color: var(--accent-blue);
    color: white;
}

/* Main content styles */
.main-content {
    grid-column: 3;
    padding: 3rem;
    overflow-y: auto;
    border-right: 1px solid var(--border-primary);
    transition: border-color 0.3s ease;
}

a {
    color: var(--accent-blue);
}

#chapter-title {
    font-size: 2.2rem;
    margin-bottom: 2rem;
    color: var(--text-primary);
    font-weight: normal;
    line-height: 1.3;
    transition: color 0.3s ease;
}

#chapter-text {
    font-size: 1.15rem;
    line-height: 1.7;
    max-width: 65ch;
    text-align: justify;
}

#chapter-text p {
    text-indent: 1.5em;
    line-height: 1.4;
    clear: left;
}

.drop-cap-letter {
    float: left;
    font-size: 4.8em;
    line-height: 1em;
    margin-right: 0.1em;
    margin-top: -0.05em;
    margin-bottom: -0.1em;
}

.drop-cap-letter.short {
    margin-bottom: -0.4em;
}

.drop-cap-rest {
    font-variant: small-caps;
    margin-left: -0.35em;
}

.drop-cap-rest.separate {
    margin-left: 0;
}

/* Remove text-indent from paragraphs with drop caps */
#chapter-text p:has(.drop-cap-letter) {
    text-indent: 0;
}

#chapter-text h2, #chapter-text h3 {
    margin: 2rem 0 1rem 0;
    color: var(--text-primary);
    font-weight: normal;
    transition: color 0.3s ease;
}

#chapter-text blockquote {
    margin: 1.5rem 0;
    padding-left: calc(1.5em - 3px);
    border-left: 3px solid var(--border-primary);
    /* font-style: italic; */
    color: var(--text-muted);
    transition: border-color 0.3s ease, color 0.3s ease;
}

#chapter-text pre {
    font-size: 90%;
    font-family: 'Courier', monospace;
    text-wrap-mode: wrap;
    background-color: var(--bg-sidebar-left);
    padding: 1em;
    margin: 1.5rem 0;
}

/* Subtle note showing words since last marker */
.words-since-marker {
    color: #bfbfbf;
    font-size: 0.95rem;
    margin-top: 1.25rem;
    text-align: right;
}

body.dark-mode .words-since-marker {
    color: #777;
}

#chapter-text em {
    font-style: italic;
}

#chapter-text strong {
    font-weight: bold;
}

/* Section separator styling */
.section-separator {
    text-align: center;
    margin: 1rem 25% 1rem 25%;
    font-size: 1.2rem;
    color: var(--text-muted);
    letter-spacing: 0.4rem;
    transition: color 0.3s ease;
}

/* Author attribution styles */
.author-note {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-style: italic;
    margin: 1rem 0;
    padding: 0.5rem 0;
    border-top: 1px solid var(--border-secondary);
    transition: color 0.3s ease, border-color 0.3s ease;
}

.footnote-ref, .annotation-ref {
    font-size: 0.8em;
    vertical-align: top;
    top: -0.2em;
    position: relative;
    text-decoration: none;
    cursor: pointer;
    padding: 0 2px;
    transition: color 0.3s ease;
}

.footnote-ref {
    color: var(--accent-blue);
}

.footnote-ref:hover {
    background-color: var(--accent-hover-footnote);
    border-radius: 2px;
}

.annotation-ref {
    color: #dc3545;
    display: none; /* Hidden by default */
}

.annotation-ref.visible {
    display: inline; /* Show when annotations are enabled */
}

.annotation-ref:hover {
    background-color: rgba(220, 53, 69, 0.1);
    border-radius: 2px;
}

/* Footnotes panel styles */
.footnotes-panel {
    grid-column: 4;
    background-color: var(--bg-sidebar-right);
    padding: 2rem 1.5rem;
    overflow-y: auto;
    transition: background-color 0.3s ease;
}

.footnotes-panel h3 {
    font-size: 1.3rem;
    margin-bottom: 1.5rem;
    color: var(--text-primary);
    font-weight: normal;
    transition: color 0.3s ease;
}

.footnotes-placeholder {
    color: var(--text-placeholder);
    font-style: italic;
    font-size: 0.9rem;
    transition: color 0.3s ease;
}

.footnote {
    margin-bottom: 1rem;
    padding: 0.75rem;
    border-radius: 4px;
    background-color: var(--bg-footnote);
    border: 1px solid var(--border-secondary);
    font-size: 0.9rem;
    line-height: 1.5;
    transition: all 0.3s ease;
    text-align: justify;
}

.footnote.highlighted {
    background-color: var(--bg-footnote-highlight);
    border-color: var(--border-highlight);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.footnote-label {
    font-weight: bold;
    color: var(--accent-blue);
    margin-right: 0.5rem;
    transition: color 0.3s ease;
}

/* Utterances comments section */
#utterances-comments {
    margin-top: 3rem;
    padding-top: 2rem;
    border-top: 2px solid var(--border-primary);
    transition: border-color 0.3s ease;
}

/* Responsive design */
@media (max-width: 1200px) {
    body {
        grid-template-columns: 1fr 250px minmax(0, 900px) 280px 1fr;
    }

    .main-content {
        padding: 2rem;
    }

    #chapter-text {
        font-size: 1.1rem;
    }
}

@media (max-width: 900px) {
    body {
        display: block;
        height: auto;
        min-height: 100vh;
    }

    .container {
        display: grid;
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr auto;
        height: auto;
        min-height: 100vh;
    }

    .sidebar {
        grid-column: 1;
        border-right: none;
        border-bottom: 1px solid var(--border-primary);
        padding: 1rem;
    }

    .sidebar h1 {
        font-size: 1.5rem;
    }

    .style-controls {
        margin: 1rem 0;
        padding: 0.75rem;
    }

    .toggle-control {
        flex-wrap: wrap;
        gap: 0.25rem;
    }

    .table-of-contents {
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .table-of-contents li {
        margin-bottom: 0;
    }

    .table-of-contents a {
        padding: 0.4rem 0.6rem;
        font-size: 0.85rem;
    }

    .main-content {
        grid-column: 1;
        padding: 1.5rem;
        border-right: none;
        border-bottom: 1px solid var(--border-primary);
    }

    .footnotes-panel {
        grid-column: 1;
        padding: 1.5rem;
        max-height: 300px;
    }

    #chapter-title {
        font-size: 1.8rem;
    }

    #chapter-text {
        font-size: 1rem;
    }
}

@media (max-width: 600px) {
    .main-content {
        padding: 1rem;
    }

    .footnotes-panel {
        padding: 1rem;
    }

    #chapter-title {
        font-size: 1.5rem;
    }
}
