/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-family-sans);
    /* Default to sans-serif for UI */
    font-size: var(--font-size);
    font-weight: 300;
    line-height: 1.6;
    color: var(--text-color);
    background-color: var(--bg-color);
    /* transition: all 0.3s ease; */
    overflow-x: visible;
    /* Allow sidenotes to show */
}

/* Container */
.container {
    padding: 0 20px;
    /* Fixed padding */
}

/* Header */
.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: var(--header-bg);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-color);
    z-index: 1000;
    height: 60px;
    transition: top 0.3s ease-in-out;
}

.header.open {
    top: 0;
}

.header.closed {
    top: -60px;
}

.header .container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 100%;
    width: 100vw;
    position: relative;
}

/* Header layout: site-title | nav | [flex-grow] | menu-toggle | controls */
.header .site-title {
    flex-shrink: 0;
    order: 1;
}

.header .main-nav {
    flex-shrink: 0;
    order: 2;
    margin-left: 2rem;
}

.header #menu-toggle {
    flex-shrink: 0;
    order: 3;
    margin-left: 6px;
    margin-right: 1rem;
}

.header .controls {
    flex-shrink: 0;
    order: 4;
}

/* Mobile header adjustments */
@media (max-width: 768px) {
    .header .main-nav {
        display: none;
    }

    .header .container {
        padding: 0 15px;
    }

    .header #menu-toggle {
        margin-left: 6px;
        margin-right: 0;
    }

    .header .site-title a {
        font-size: 1rem;
    }
}

/* Very Small Mobile header adjustments */
@media (max-width: 375px) {
    .header .main-nav {
        display: none;
    }

    .header .container {
        padding: 0 10px;
    }

    .header #menu-toggle {
        margin-left: 6px;
        margin-right: 0;
    }

    .header .site-title a {
        font-size: 0.9rem;
    }
}

.book-title {
    font-size: 23px;
    /* Fixed size instead of var(--font-size-h5) */
    font-weight: 500;
    color: var(--primary-color);
    line-height: 1.2;
    /* Fixed line height */
}

.controls {
    display: flex;
    gap: 8px;
    /* Fixed gap instead of var(--spacing-xs) */
    align-items: center;
    min-width: 120px;
    /* Reserve space so theme toggle doesn't move when font controls are added */
    justify-content: flex-end;
}

.control-btn {
    background: var(--button-bg);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    padding: 8px 12px;
    /* Fixed padding instead of calc(var(--spacing-xs) / 1.3) var(--spacing-sm) */
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    /* Fixed font size instead of var(--font-size-small) */
    line-height: 1.2;
    /* Fixed line height */
    touch-action: manipulation;
}

#menu-toggle {
    padding: 0px 6px 4px 6px;
    font-size: 24px;
    border: none;
    background: none;
    margin-left: 6px;
}

.control-btn:hover {
    background: var(--button-hover-bg);
}

/* Sidebar */
.sidebar {
    position: fixed;
    top: 60px;
    left: 0;
    width: 300px;
    height: calc(100vh - 60px);
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    z-index: 100;
    transition: transform 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    will-change: transform;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    transform: translateX(-100%);
    /* Default hidden for all screens */
}

/* Show sidebar - same class for mobile AND desktop */
.sidebar.open {
    transform: translateX(0);
}

.sidebar-content {
    padding: 20px;
}

.sidebar-title {
    margin-bottom: 15px;
    color: var(--primary-color);
    font-size: 1.3rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 10px;
}

.sidebar h3 {
    margin-bottom: 15px;
    color: var(--primary-color);
    font-size: 1.1rem;
}

.chapter-list {
    list-style: none;
    margin-left: -12px;
    margin-right: -12px;
}

.chapter-list li {
    margin-bottom: 8px;
}

.chapter-list a {
    display: block;
    padding: 10px 15px;
    color: var(--text-color);
    text-decoration: none;
    border-radius: 6px;
    font-size: 0.95rem;
}

.chapter-list a:hover {
    background: var(--hover-bg);
    color: var(--primary-color);
}

.chapter-list a.active {
    background: var(--primary-color);
    color: white;
}

/* Chapter access level indicators */
.chapter-list a.chapter-auth {
    /* Slightly dimmed for auth-required chapters */
    opacity: 0.85;
}

.chapter-list a.chapter-premium {
    /* Special styling for premium chapters */
    opacity: 0.75;
    position: relative;
}

/* Main Content */
.main-content {
    margin-left: 0;
    margin-top: 60px;
    min-height: calc(100vh - 60px);
    width: 100%;
    overflow-x: visible;
    /* Allow sidenotes to show outside content area */
}

.chapter-content {
    min-height: 70vh;
    margin-bottom: 40px;
}

/* Chapter Navigation */
.chapter-nav {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    margin-top: 40px;
    padding-top: 20px;
    padding-bottom: 40px;
    border-top: 1px solid var(--border-color);
}

.nav-btn {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1rem;
    flex: 1;
    max-width: 200px;
}

.nav-btn:hover:not(:disabled) {
    background: var(--primary-hover);
}

.nav-btn:disabled {
    background: var(--disabled-bg);
    color: var(--disabled-text);
    cursor: not-allowed;
}

/* Responsive Design */
@media (max-width: 768px) {
    .sidebar {
        width: 280px;
        /* Slightly narrower on mobile */
    }

    .controls {
        gap: 5px;
        /* Fixed gap */
    }

    .control-btn {
        padding: 6px 8px;
        /* Fixed padding */
        font-size: 12px;
        /* Fixed font size */
    }

    .book-title {
        font-size: 20px;
        /* Fixed font size instead of 1.2rem */
    }

    .chapter-nav {
        flex-direction: column;
    }

    .nav-btn {
        max-width: none;
    }
}

@media (min-width: 769px) {
    /* Desktop styles - content is always full width */
}

/* Utility Classes */
.hidden {
    display: none !important;
}

.text-center {
    text-align: center;
}

.mb-20 {
    margin-bottom: 20px;
}

.mt-20 {
    margin-top: 20px;
}

.mb-100 {
    margin-bottom: 100px;
}