/* Reloading section styles */

.ch-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 0;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--color-border);
    font-size: 0.9rem;
}

.ch-nav + .chapter-content + .ch-nav {
    border-bottom: none;
    border-top: 1px solid var(--color-border);
    margin-top: 2rem;
    margin-bottom: 0;
}

.ch-nav a {
    color: var(--color-accent);
    font-weight: 500;
    border-bottom: none;
}

.ch-nav a:hover {
    color: var(--color-accent-light);
}

.ch-nav-prev, .ch-nav-next {
    min-width: 120px;
}

.ch-nav-prev { text-align: left; }
.ch-nav-next { text-align: right; }
.ch-nav-home { font-weight: 600; }

/* Chapter content */
.chapter-content {
    max-width: 100%;
}

.chapter-content a {
    text-decoration: underline;
    color: var(--color-accent);
}

.chapter-content a:hover {
    color: var(--color-accent-light);
}

.chapter-content h1 {
    font-size: 1.6rem;
    margin-top: 0;
}

.chapter-content h2 {
    cursor: pointer;
    user-select: none;
    position: relative;
    padding-right: 1.5rem;
}

.chapter-content h2::after {
    content: "\25B2";
    position: absolute;
    right: 0;
    font-size: 0.6em;
    color: var(--color-text-light);
    transition: transform 0.3s;
}

.chapter-content h2.collapsed::after {
    transform: rotate(180deg);
}

.chapter-section {
    overflow: hidden;
    transition: max-height 0.4s ease, opacity 0.3s ease;
    max-height: 5000px;
    opacity: 1;
}

.chapter-section.hidden {
    max-height: 0;
    opacity: 0;
}

/* Floating ToC */
.ch-toc {
    display: none;
}

@media (min-width: 1280px) {
    .ch-toc {
        display: block;
        position: fixed;
        right: 20px;
        top: 120px;
        width: 220px;
        max-height: calc(100vh - 160px);
        overflow-y: auto;
        font-size: 0.8rem;
        line-height: 1.4;
        padding: 1rem;
        background: var(--color-surface);
        border: 1px solid var(--color-border);
        border-radius: var(--radius);
        box-shadow: var(--shadow);
    }

    /* On very wide screens, ensure ToC does not overlap with the new forum sidebar */
    @media (min-width: 1560px) {
        .ch-toc {
            top: 22rem; /* Increased to leave room for the profile block when logged in */
            width: 220px;
            max-height: calc(100vh - 24rem); /* Adjusted to match new top offset */
        }
    }

    .ch-toc h4 {
        margin: 0 0 0.5rem;
        font-size: 0.75rem;
        text-transform: uppercase;
        letter-spacing: 0.08em;
        color: var(--color-text-light);
        border: none;
        padding: 0;
    }

    .ch-toc ul {
        list-style: none;
        padding: 0;
        margin: 0;
    }

    .ch-toc li {
        margin-bottom: 0.3rem;
    }

    .ch-toc li.toc-h3 {
        padding-left: 0.8rem;
        font-size: 0.75rem;
    }

    .ch-toc a {
        color: var(--color-text-light);
        border-bottom: none;
        transition: color 0.2s;
    }

    .ch-toc a:hover,
    .ch-toc a.active {
        color: var(--color-accent);
    }
}

/* Reading progress */
.reading-progress {
    position: fixed;
    top: 0;
    left: 0;
    height: 3px;
    background: var(--color-accent);
    z-index: 9999;
    transition: width 0.1s linear;
    width: 0;
}

/* Index cards */
.reloading-intro {
    font-size: 1.05rem;
    line-height: 1.7;
    margin-bottom: 2rem;
    color: var(--color-text);
}

.reloading-intro .pdf-link {
    display: inline-block;
    margin-top: 0.75rem;
    padding: 0.4rem 1rem;
    background: var(--color-accent);
    color: #fff !important;
    border-radius: var(--radius);
    font-size: 0.85rem;
    font-weight: 600;
    border-bottom: none !important;
    transition: background-color 0.2s;
}

.reloading-intro .pdf-link:hover {
    background: var(--color-accent-light);
    color: #fff !important;
    border-bottom: none !important;
}

.chapter-cards {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.75rem;
    margin-bottom: 2rem;
}

.chapter-card {
    display: flex;
    align-items: baseline;
    gap: 1rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-left: 4px solid var(--color-accent);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    text-decoration: none;
    color: var(--color-text);
    transition: box-shadow 0.2s, transform 0.15s;
}

.chapter-card:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-1px);
    border-bottom: none;
}

.chapter-card .ch-num {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--color-accent);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
    min-width: 60px;
}

.chapter-card .ch-title {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--color-text);
}

.chapter-card:hover .ch-title {
    color: var(--color-accent);
}

.chapter-card .ch-desc {
    font-size: 0.85rem;
    color: var(--color-text-light);
    margin-top: 0.15rem;
}

.section-divider {
    margin: 2rem 0 1rem;
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--color-text-light);
    border-bottom: 2px solid var(--color-border);
    padding-bottom: 0.3rem;
}

/* Warning box */
.warning-box {
    background: #fff8e1;
    border: 1px solid #e6c84c;
    border-left: 4px solid #e6a817;
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    margin: 1.25rem 0;
    font-size: 0.92rem;
}

.warning-box strong {
    color: #8a6d00;
}

/* Formulas */
.formula {
    background: var(--color-code-bg, #f5f7fa);
    border: 1px solid var(--color-border, #ddd);
    border-radius: var(--radius, 4px);
    padding: 0.75rem 1.25rem;
    margin: 1rem 0;
    font-family: 'Georgia', 'Times New Roman', serif;
    font-size: 1.05rem;
    text-align: center;
    overflow-x: auto;
}

/* Info box */
.info-box {
    background: var(--color-code-bg);
    border: 1px solid var(--color-border);
    border-left: 4px solid var(--color-accent);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    margin: 1.25rem 0;
    font-size: 0.92rem;
    font-style: italic;
    color: var(--color-text-light);
}

/* Responsive tables */
.table-wrapper {
    overflow-x: auto;
    margin: 1rem 0;
}

.table-wrapper table {
    min-width: 500px;
}

/* Interactive chart */
.chart-container {
    max-width: 600px;
    margin: 1.5rem auto;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1rem;
}

.chart-container canvas {
    width: 100%;
    height: auto;
}

@media (max-width: 768px) {
    .chapter-card {
        flex-direction: column;
        gap: 0.25rem;
    }

    .chapter-card .ch-num {
        min-width: 0;
    }

    .ch-nav {
        font-size: 0.82rem;
    }

    .ch-nav-prev, .ch-nav-next {
        min-width: 80px;
    }
}
