:root {
    --book-header-offset: calc(var(--header-height, 96px) + 32px);
}

/* Book Container */
.book-container {
    position: relative;
    width: 100%;
    max-width: 780px;
    margin: 2rem auto;
    background: var(--book-surface, rgba(30, 15, 38, 0.9));
    color: var(--book-text-color, var(--text-dark));
    border-radius: var(--card-radius, 16px);
    padding: clamp(1.5rem, 4vw, 2.5rem);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    overflow: visible;
    box-sizing: border-box;
}

.light-mode .book-container {
    background: var(--book-surface-light, rgba(255, 255, 255, 0.92));
    color: var(--book-text-color-light, var(--text-dark));
}

.book-container--font-compact .book-section p {
    font-size: clamp(1rem, 1.02rem + 0.1vw, 1.05rem);
    line-height: 1.8;
}

.book-container--font-relaxed .book-section p {
    font-size: clamp(1.2rem, 1.25rem + 0.15vw, 1.35rem);
    line-height: 2.1;
}

/* Progress */
.book-progress {
    position: relative;
    height: 4px;
    background: rgba(191, 162, 219, 0.25);
    border-radius: 2px;
    margin-bottom: 1.5rem;
    overflow: hidden;
    width: 100%;
    border-radius: 999px;
}

.book-progress .progress-bar {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, var(--button-gradient-start), var(--button-gradient-end));
    transition: width 0.3s ease;
    border-radius: inherit;
}

/* Table of contents */
.book-toc {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.book-toc-item,
.book-toc-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.4);
    background: transparent;
    color: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
}

.book-toc-item:hover,
.book-toc-link:hover,
.book-toc-item.is-active {
    background: rgba(255, 255, 255, 0.2);
    color: var(--light-accent);
}

.light-mode .book-toc-item,
.light-mode .book-toc-link {
    border-color: rgba(59, 28, 74, 0.2);
}

.light-mode .book-toc-item:hover,
.light-mode .book-toc-link:hover,
.light-mode .book-toc-item.is-active {
    background: rgba(59, 28, 74, 0.08);
    color: var(--primary-dark);
}

.book-toc-item:focus-visible,
.book-toc-link:focus-visible {
    outline: 2px solid var(--light-accent);
    outline-offset: 2px;
}


.book-header {
    position: sticky;
    top: var(--book-header-offset);
    z-index: 8;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 1.25rem clamp(1rem, 3vw, 1.75rem);
    backdrop-filter: blur(12px);
    background: var(--book-surface-section, rgba(0, 0, 0, 0.18));
    border-radius: var(--card-radius, 16px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 12px 25px rgba(0, 0, 0, 0.18);
    width: 100%;
    box-sizing: border-box;
    color: inherit;
}

.light-mode .book-header {
    background: var(--book-surface-section-light, rgba(255, 255, 255, 0.9));
    border-color: rgba(59, 28, 74, 0.12);
}

.book-header .book-toc {
    margin-bottom: 0;
    justify-content: center;
}

.book-header .book-progress {
    margin-bottom: 0;
}
/* Sections */
.book-sections {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.book-section {
    position: relative;
    background: var(--book-surface-section, rgba(0, 0, 0, 0.08));
    border-radius: var(--card-radius, 16px);
    padding: 1.75rem;
    color: inherit;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05);
    scroll-margin-top: calc(var(--book-header-offset) + 32px);
    box-sizing: border-box;
}

.light-mode .book-section {
    background: var(--book-surface-section-light, rgba(255, 255, 255, 0.85));
    color: inherit;
    box-shadow: inset 0 0 0 1px rgba(59, 28, 74, 0.08);
}

.book-section p {
    font-size: clamp(1.08rem, 1.12rem + 0.22vw, 1.28rem);
    line-height: 1.98;
    letter-spacing: 0.01em;
    margin-bottom: 1.35rem;
    color: inherit;
}

.book-section p:last-child {
    margin-bottom: 0;
}

/* Responsive */
@media (max-width: 768px) {
    :root {
        --book-header-offset: calc(var(--mobile-header-height, 72px) + 28px);
    }

    .book-container {
        padding: clamp(1.1rem, 5vw, 1.5rem);
        margin: 1.2rem auto;
        border-radius: var(--card-radius, 16px);
    }

    .book-header {
        border-radius: var(--card-radius, 16px);
        padding: 1rem 1.25rem;
    }

    .book-section {
        padding: 1.35rem;
        scroll-margin-top: calc(var(--book-header-offset) + 24px);
    }

    .book-section p {
        font-size: clamp(1.05rem, 1.08rem + 0.18vw, 1.18rem);
        line-height: 1.92;
    }
}
