/* ==========================
 * Library — Shelf Page
 * ========================== */

.library-subtitle {
    font-family: var(--font-body);
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 2rem;
}

.book-shelf {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 24px;
    padding-bottom: 2rem;
}

.book-card {
    position: relative;
    background: var(--bg-card);
    border: 1px solid var(--purple-border);
    border-left: 4px solid var(--purple);
    border-radius: 2px 8px 8px 2px;
    padding: 24px 24px 24px 28px;
    cursor: pointer;
    transition: border-color 0.25s ease, transform 0.15s ease, box-shadow 0.25s ease;
}

.book-card:hover {
    border-color: var(--purple-border-strong);
    border-left-color: var(--purple-light);
    transform: translateY(-2px);
    box-shadow: 0 4px 20px var(--purple-border-light);
}

.book-card-title {
    font-family: var(--font-heading);
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-heading);
    margin: 0 0 8px;
    line-height: 1.3;
}

.book-card-author {
    font-family: var(--font-body);
    font-size: 0.8rem;
    color: var(--nav-text);
    margin-bottom: 12px;
}

.book-card-description {
    font-family: var(--font-body);
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.5;
    margin-bottom: 12px;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.book-card-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-top: 1px solid var(--purple-border-subtle);
    padding-top: 10px;
    margin-top: 4px;
}

.book-card-chapters {
    font-family: var(--font-heading);
    font-size: 0.75rem;
    color: var(--text-muted);
}

.book-card-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.book-tag {
    display: inline-block;
    padding: 2px 8px;
    background: var(--purple-bg);
    border: 1px solid var(--purple-border-input);
    border-radius: 3px;
    font-family: var(--font-heading);
    font-size: 0.7rem;
    color: var(--purple-light);
    text-decoration: none;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease;
}

.book-tag:hover {
    background: var(--purple-bg-hover);
    color: var(--purple-lighter);
}


/* ==========================
 * Library — Reader Layout
 * ========================== */

.reader-layout {
    display: flex;
    min-height: calc(100vh - 56px);
    margin-top: 56px;
}

/* Sidebar */
.reader-sidebar {
    width: 280px;
    min-width: 280px;
    background: rgba(5, 0, 10, 0.98);
    border-right: 1px solid var(--purple-border-light);
    padding: 20px 0;
    overflow-y: auto;
    position: sticky;
    top: 56px;
    height: calc(100vh - 56px);
    transition: transform 0.3s ease;
    z-index: 100;
}

.sidebar-close {
    display: none;
    position: absolute;
    top: 12px;
    right: 12px;
    background: none;
    border: none;
    color: var(--nav-text);
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
}

.sidebar-close:hover {
    color: var(--purple-lighter);
}

.sidebar-header {
    padding: 0 20px 16px;
    border-bottom: 1px solid var(--purple-bg);
    margin-bottom: 8px;
}

.sidebar-back {
    font-family: var(--font-body);
    font-size: 0.8rem;
    color: var(--nav-text);
    text-decoration: none;
    transition: color 0.2s;
}

.sidebar-back:hover {
    color: var(--purple-lighter);
}

.sidebar-book-title {
    font-family: var(--font-heading);
    font-size: 0.9rem;
    color: var(--text-heading);
    margin: 8px 0 0;
    line-height: 1.3;
}

/* Chapter navigation links */
.chapter-nav {
    padding: 0;
    margin: 0;
}

.chapter-nav-link {
    display: block;
    padding: 7px 20px;
    font-family: var(--font-body);
    font-size: 0.82rem;
    color: var(--nav-text);
    text-decoration: none;
    border-left: 3px solid transparent;
    transition: all 0.15s ease;
    line-height: 1.4;
}

.chapter-nav-link:hover {
    color: var(--purple-lighter);
    background: var(--purple-bg-subtle);
}

.chapter-nav-link.active {
    color: var(--text-heading);
    border-left-color: var(--purple);
    background: var(--purple-bg);
    font-weight: 500;
}

.chapter-nav-link .toc-number {
    font-family: var(--font-heading);
    font-size: 0.72rem;
    color: var(--text-muted-dim);
    margin-right: 6px;
}

.chapter-nav-link.active .toc-number {
    color: var(--purple-light);
}

/* Sidebar toggle (mobile only) */
.sidebar-toggle {
    display: none;
    align-items: center;
    gap: 6px;
    background: var(--purple-bg-light);
    border: 1px solid var(--purple-border);
    border-radius: 6px;
    color: var(--purple-light);
    padding: 8px 12px;
    cursor: pointer;
    margin-bottom: 20px;
    font-family: var(--font-body);
    font-size: 0.85rem;
    transition: all 0.2s;
}

.sidebar-toggle:hover {
    background: var(--purple-bg-hover);
    color: var(--purple-lighter);
}

/* Main reading area */
.reader-main {
    flex: 1;
    padding: 40px 48px 80px;
    max-width: 860px;
}

/* Reader content — extends markdown.css for a book feel */
.reader-content .md-content {
    line-height: 1.85;
}

.reader-content .md-content h1 {
    font-size: 1.6rem;
    margin-top: 0;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--purple-border-light);
}

.reader-content .md-content h2 {
    font-size: 1.3rem;
    margin-top: 2em;
}

.reader-content .md-content h3 {
    font-size: 1.1rem;
    margin-top: 1.5em;
}

/* Chapter pagination */
.chapter-pagination {
    display: flex;
    justify-content: space-between;
    align-items: stretch;
    gap: 12px;
    margin-top: 48px;
    padding-top: 24px;
    border-top: 1px solid var(--purple-border-light);
}

.chapter-nav-btn {
    font-family: var(--font-body);
    font-size: 0.85rem;
    color: var(--purple-light);
    text-decoration: none;
    padding: 10px 16px;
    border: 1px solid var(--purple-border-input);
    border-radius: 6px;
    transition: all 0.2s ease;
    line-height: 1.4;
}

.chapter-nav-btn:hover {
    background: var(--purple-bg);
    border-color: var(--purple-border-strong);
    color: var(--purple-lighter);
}

.chapter-nav-btn.prev {
    text-align: left;
    max-width: 40%;
}

.chapter-nav-btn.toc {
    font-family: var(--font-heading);
    font-size: 0.8rem;
    color: var(--text-muted);
    border-color: var(--purple-bg);
}

.chapter-nav-btn.next {
    text-align: right;
    max-width: 40%;
    margin-left: auto;
}


/* ==========================
 * Library — Book Landing (TOC)
 * ========================== */

.book-landing {
    max-width: 700px;
}

.book-landing-title {
    font-family: var(--font-heading);
    font-size: 1.8rem;
    color: var(--text-heading);
    margin-bottom: 8px;
    font-weight: 700;
}

.book-landing-author {
    font-family: var(--font-body);
    font-size: 0.9rem;
    color: var(--nav-text);
    margin-bottom: 16px;
}

.book-landing-description {
    font-family: var(--font-body);
    font-size: 0.95rem;
    color: #999;
    line-height: 1.7;
    margin-bottom: 20px;
}

.book-landing-source {
    font-family: var(--font-heading);
    font-size: 0.8rem;
    color: var(--blue-link);
    text-decoration: none;
    margin-bottom: 20px;
    display: inline-block;
}

.book-landing-source:hover {
    color: var(--blue-link-hover);
    text-decoration: underline;
}

.toc-heading {
    font-family: var(--font-heading);
    font-size: 1rem;
    color: var(--text-label);
    margin: 28px 0 12px;
    letter-spacing: 0.02em;
    font-weight: 600;
}

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

.toc-item {
    margin-bottom: 2px;
}

.toc-link {
    display: block;
    padding: 8px 16px;
    font-family: var(--font-body);
    font-size: 0.9rem;
    color: var(--text-body);
    text-decoration: none;
    border-left: 2px solid var(--purple-border-light);
    transition: all 0.2s;
}

.toc-link:hover {
    color: var(--purple-lighter);
    border-left-color: var(--purple);
    background: var(--purple-bg-faint);
}

.toc-link .toc-number {
    font-family: var(--font-heading);
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-right: 8px;
}


/* ==========================
 * Mobile Responsive
 * ========================== */

@media (max-width: 992px) {
    .reader-main {
        padding: 32px 32px 80px;
    }
}

@media (max-width: 768px) {
    .reader-sidebar {
        position: fixed;
        top: 56px;
        left: 0;
        width: 85%;
        max-width: 320px;
        transform: translateX(-100%);
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.5);
    }

    .reader-sidebar.open {
        transform: translateX(0);
    }

    .sidebar-close {
        display: block;
    }

    .sidebar-toggle {
        display: inline-flex;
    }

    .reader-main {
        padding: 24px 16px 80px;
        max-width: 100%;
    }

    .book-shelf {
        grid-template-columns: 1fr;
    }

    .chapter-pagination {
        flex-direction: column;
        gap: 8px;
    }

    .chapter-nav-btn.prev,
    .chapter-nav-btn.next {
        max-width: 100%;
    }

    .book-landing-title {
        font-size: 1.4rem;
    }
}

/* Sidebar overlay backdrop on mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 56px;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99;
}

.sidebar-overlay.active {
    display: block;
}
