/* ===== CSS VARIABLES ===== */
:root {
    --header-height: 60px;
    --toc-width: 280px;
    --font-size-base: 16px;
    --color-bg: #f4f4f4;
    --color-white: #ffffff;
    --color-text: #333333;
    --color-primary: #4a90e2;
    --color-primary-hover: #357abd;
    --color-highlight: #ffd700;
    --color-toc-hover: #f0f0f0;
    --color-section-header: #666;
    --shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    --transition: 0.3s ease;
}

/* ===== DARK MODE VARIABLES ===== */
body.dark-mode {
    --color-bg: #0f0f0f;
    --color-white: #1e1e1e;
    --color-text: #e8e8e8;
    --color-primary: #64b5f6;
    --color-primary-hover: #5ca9f0;
    --color-highlight: #ffd700;
    --color-toc-hover: #2a2a2a;
    --color-section-header: #a0a0a0;
    --shadow: 0 4px 8px rgba(0, 0, 0, 0.5);
}

/* ===== RESET & BASE ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    font-size: var(--font-size-base);
}

body {
    font-family: 'Georgia', 'Times New Roman', serif;
    background-color: var(--color-bg);
    color: var(--color-text);
    line-height: 1.7;
    padding-top: var(--header-height);
    padding-left: var(--toc-width);
}

/* ===== STICKY HEADER ===== */
.sticky-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: var(--color-white);
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    z-index: 1000;
}

.sticky-header h1 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--color-text);
    margin: 0;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    margin-left: calc(var(--toc-width) / 2);
}

.header-controls {
    display: flex;
    gap: 10px;
}

.btn-icon {
    background: var(--color-primary);
    color: white;
    border: none;
    padding: 8px 12px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: var(--transition);
}

.btn-icon:hover {
    background: var(--color-primary-hover);
    transform: translateY(-2px);
}

.hamburger {
    font-size: 1.5rem;
}

/* Hide TOC toggle on desktop (TOC always visible) */
#toc-toggle {
    display: none;
}

/* ===== TABLE OF CONTENTS ===== */
.table-of-contents {
    position: fixed;
    top: var(--header-height);
    left: 0;
    width: var(--toc-width);
    height: calc(100vh - var(--header-height));
    background: var(--color-white);
    box-shadow: var(--shadow);
    overflow-y: auto;
    padding: 20px;
    z-index: 900;
    transition: transform var(--transition);
}

.table-of-contents h2 {
    font-size: 1.2rem;
    margin-bottom: 15px;
    color: var(--color-primary);
}

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

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

.table-of-contents a {
    color: var(--color-text);
    text-decoration: none;
    display: block;
    padding: 5px 10px;
    border-radius: 5px;
    transition: var(--transition);
    font-size: 0.95rem;
}

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

.table-of-contents a.active {
    background: var(--color-primary);
    color: white;
    font-weight: bold;
}

/* Nested lists */
.table-of-contents ul ul {
    margin-left: 15px;
    margin-top: 5px;
}

.table-of-contents ul ul a {
    font-size: 0.9rem;
}

.table-of-contents ul ul ul a {
    font-size: 0.85rem;
}

/* ===== MAIN CONTENT CONTAINER ===== */
.container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    column-gap: 20px;
    row-gap: 5px;
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

/* Headers row spans both columns */
.headers-row {
    display: contents;
}

.header-cell {
    padding: 20px;
    background-color: var(--color-white);
    border-radius: 10px;
    box-shadow: var(--shadow);
}

.header-cell h2 {
    text-align: center;
    margin-bottom: 10px;
    font-size: 1.3rem;
}

.header-cell h2 strong {
    display: block;
    font-size: 75%;
    opacity: 0.75;
    font-weight: normal;
}

/* Section headers span both columns */
.section-header {
    grid-column: 1 / -1;
    padding: 20px;
    background-color: var(--color-white);
    border-radius: 10px;
    box-shadow: var(--shadow);
    margin-top: 20px;
    scroll-margin-top: calc(var(--header-height) + 20px);
}

.section-header h3 {
    margin: 10px 0;
    color: var(--color-primary);
}

.section-header h4 {
    margin: 8px 0;
    color: var(--color-section-header);
}

/* Each paragraph row */
.paragraph-row {
    display: contents;
}

/* Individual paragraph cells */
.para-cell {
    padding: 20px;
    background-color: var(--color-white);
    border-radius: 10px;
    box-shadow: var(--shadow);
    align-self: start;
}

/* ===== SENTENCE HIGHLIGHTING ===== */
.sentence {
    padding: 5px;
    cursor: pointer;
    border-radius: 5px;
    transition: var(--transition);
}

.sentence.highlight {
    background-color: transparent;
    outline: 3px solid var(--color-highlight);
    border-radius: 5px;
}

/* ===== RESPONSIVE DESIGN ===== */

/* Tablet (768px - 1200px) */
@media (max-width: 1200px) {
    :root {
        --toc-width: 250px;
    }

    .sticky-header h1 {
        font-size: 1.3rem;
    }

    .container {
        padding: 15px;
    }
}

/* Mobile & Tablet (< 992px) - Hide TOC by default, show with toggle */
@media (max-width: 992px) {
    body {
        padding-left: 0;
    }

    .sticky-header h1 {
        position: static;
        transform: none;
        margin-left: 0;
    }

    .table-of-contents {
        transform: translateX(-100%);
    }

    .table-of-contents.open {
        transform: translateX(0);
    }

    #toc-toggle {
        display: block;
    }
}

/* Mobile (< 768px) - Stack columns */
@media (max-width: 768px) {
    :root {
        --header-height: 50px;
        --toc-width: 250px;
    }

    .sticky-header {
        padding: 0 10px;
    }

    .sticky-header h1 {
        font-size: 1.1rem;
    }

    .btn-icon {
        padding: 6px 10px;
        font-size: 0.85rem;
    }

    .header-controls {
        gap: 5px;
    }

    /* Stack columns vertically */
    .container {
        grid-template-columns: 1fr;
        padding: 10px;
        gap: 15px;
    }

    .headers-row {
        display: grid;
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .para-cell {
        padding: 15px;
    }

    .section-header {
        margin-top: 15px;
        padding: 15px;
    }
}

/* Very small mobile (< 480px) */
@media (max-width: 480px) {
    :root {
        --font-size-base: 14px;
    }

    .sticky-header h1 {
        font-size: 1rem;
    }

    .table-of-contents {
        width: 100%;
    }

    .btn-icon {
        padding: 5px 8px;
    }
}

/* ===== PRINT STYLES ===== */
@media print {
    .sticky-header,
    .table-of-contents {
        display: none;
    }

    body {
        padding-left: 0;
        padding-top: 0;
    }

    .container {
        grid-template-columns: 1fr 1fr;
        max-width: 100%;
    }

    .section-header {
        page-break-after: avoid;
    }

    .para-cell {
        page-break-inside: avoid;
    }
}

/* ===== ACCESSIBILITY ===== */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

/* Focus styles for keyboard navigation */
a:focus,
button:focus {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

/* Smooth scrolling for anchor links */
html {
    scroll-padding-top: calc(var(--header-height) + 20px);
}
