/*
 * Knoww Books - Mobile First Responsive Styles
 * Library grid, Book TOC, Chapter Reader
 */

/* ==========================================================================
   CSS Custom Properties
   ========================================================================== */

:root {
    --books-primary: #4263eb;
    --books-primary-light: #5c7cfa;
    --books-primary-dark: #364fc7;
    --books-dark-text: #343a40;
    --books-muted-text: #6c757d;
    --books-light-bg: #f8f9fa;
    --books-border: #e9ecef;
    --books-card-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
    --books-card-shadow-hover: 0 8px 24px rgba(0, 0, 0, 0.12);
    --books-radius: 12px;
    --books-transition: 0.25s ease;
}

/* ==========================================================================
   Mobile Base Styles (320px+)
   ========================================================================== */

/* --- Hero / Page Header --- */

.books-hero {
    background: linear-gradient(135deg, #4263eb 0%, #7048e8 100%);
    color: #fff;
    padding: 3rem 1rem 2rem;
    text-align: center;
}

.books-hero h1 {
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: #fff;
}

.books-hero p {
    font-size: 1rem;
    opacity: 0.85;
    margin: 0;
    color: #fff;
}

/* --- Breadcrumb / Back Navigation --- */

.books-back {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 1rem;
    font-size: 0.9rem;
    color: var(--books-primary);
    text-decoration: none;
    font-weight: 500;
    transition: color var(--books-transition);
}

.books-back:hover {
    color: var(--books-primary-dark);
    text-decoration: none;
}

.books-breadcrumb {
    padding: 0.75rem 1rem;
    background: var(--books-light-bg);
    border-bottom: 1px solid var(--books-border);
}

.books-breadcrumb ol {
    list-style: none;
    display: flex;
    align-items: center;
    gap: 0.25rem;
    margin: 0;
    padding: 0;
    font-size: 0.85rem;
    flex-wrap: wrap;
}

.books-breadcrumb li {
    display: inline-flex;
    align-items: center;
    color: var(--books-muted-text);
}

.books-breadcrumb li + li::before {
    content: "\203A";
    margin-right: 0.4rem;
    color: #adb5bd;
}

.books-breadcrumb a {
    color: var(--books-primary);
    text-decoration: none;
}

.books-breadcrumb a:hover {
    text-decoration: underline;
}

/* --- Library Grid --- */

.books-library {
    padding: 1.5rem 1rem;
}

.books-library .section-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--books-dark-text);
    margin-bottom: 1.25rem;
}

.books-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

.book-card {
    background: #fff;
    border-radius: var(--books-radius);
    box-shadow: var(--books-card-shadow);
    overflow: hidden;
    transition: transform var(--books-transition), box-shadow var(--books-transition);
    text-decoration: none;
    color: inherit;
    display: flex;
    flex-direction: column;
}

.book-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--books-card-shadow-hover);
    text-decoration: none;
    color: inherit;
}

.book-card-cover {
    aspect-ratio: 3 / 4;
    background: linear-gradient(135deg, #4263eb 0%, #7048e8 50%, #9775fa 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    position: relative;
}

.book-card-cover .book-icon {
    font-size: 2.5rem;
    opacity: 0.9;
}

.book-card-cover .book-initials {
    font-size: 2rem;
    font-weight: 800;
    color: rgba(255, 255, 255, 0.9);
    text-transform: uppercase;
    letter-spacing: 2px;
}

.book-card-body {
    padding: 0.75rem;
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.book-card-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--books-dark-text);
    margin-bottom: 0.25rem;
    line-height: 1.3;
}

.book-card-meta {
    font-size: 0.75rem;
    color: var(--books-muted-text);
}

/* --- Empty State --- */

.books-empty {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--books-muted-text);
}

.books-empty .empty-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.books-empty h3 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--books-dark-text);
    margin-bottom: 0.5rem;
}

.books-empty p {
    font-size: 0.9rem;
}

/* --- Book TOC (Table of Contents) --- */

.books-toc {
    padding: 1.5rem 1rem;
}

.books-toc-header {
    margin-bottom: 1.5rem;
}

.books-toc-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--books-dark-text);
    margin-bottom: 0.25rem;
}

.books-toc-header .toc-meta {
    font-size: 0.9rem;
    color: var(--books-muted-text);
}

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

.chapter-item {
    border: 1px solid var(--books-border);
    border-radius: var(--books-radius);
    margin-bottom: 0.75rem;
    transition: border-color var(--books-transition), box-shadow var(--books-transition);
}

.chapter-item:hover {
    border-color: var(--books-primary-light);
    box-shadow: 0 2px 8px rgba(66, 99, 235, 0.1);
}

.chapter-link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
    text-decoration: none;
    color: inherit;
    gap: 0.75rem;
}

.chapter-link:hover {
    text-decoration: none;
    color: inherit;
}

.chapter-info {
    flex: 1;
    min-width: 0;
}

.chapter-number {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--books-primary);
    letter-spacing: 0.5px;
    margin-bottom: 0.15rem;
}

.chapter-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--books-dark-text);
    margin-bottom: 0.15rem;
    line-height: 1.3;
}

.chapter-read-time {
    font-size: 0.8rem;
    color: var(--books-muted-text);
}

.chapter-arrow {
    color: #adb5bd;
    font-size: 1.1rem;
    flex-shrink: 0;
    transition: transform var(--books-transition), color var(--books-transition);
}

.chapter-item:hover .chapter-arrow {
    color: var(--books-primary);
    transform: translateX(3px);
}

/* --- Chapter Reader --- */

.books-reader {
    padding: 2rem 1.25rem 3rem;
    background: #faf8f5;
    border-radius: var(--books-radius);
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.04);
}

.reader-header {
    margin-bottom: 1.75rem;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid #e0dbd4;
}

.reader-header .chapter-label {
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #7c6f5e;
    margin-bottom: 0.25rem;
}

.reader-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: #2c2418;
    margin-bottom: 0.35rem;
    line-height: 1.3;
}

.reader-header .reader-meta {
    font-size: 0.85rem;
    color: #8a7e6e;
}

/* Reader prose content */
.reader-content {
    max-width: 100%;
    margin: 0 auto;
}

.reader-content .markdown-content {
    font-family: Georgia, 'Times New Roman', serif;
    line-height: 1.85;
    color: #3d3425;
    font-size: 1rem;
}

.reader-content .markdown-content h1 {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 1.5rem;
    font-weight: 700;
    color: #2c2418;
    margin: 2.5rem 0 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid #e8e2d9;
}

.reader-content .markdown-content h2 {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 1.25rem;
    font-weight: 600;
    color: #4a3f30;
    margin: 2rem 0 0.75rem;
}

.reader-content .markdown-content h3 {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 1.1rem;
    font-weight: 600;
    color: #5a4e3c;
    margin: 1.75rem 0 0.6rem;
}

.reader-content .markdown-content p {
    margin-bottom: 1.3rem;
    font-size: 1rem;
    line-height: 1.85;
}

.reader-content .markdown-content blockquote {
    border-left: 3px solid #c4b8a5;
    padding: 0.75rem 1.25rem;
    margin: 1.5rem 0;
    background: #f3efe8;
    border-radius: 0 8px 8px 0;
    font-style: italic;
    color: #5a4e3c;
}

/* --- Chapter Navigation (Prev/Next) --- */

.chapter-nav {
    margin-top: 2.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid #e0dbd4;
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
}

.chapter-nav-btn {
    display: flex;
    flex-direction: column;
    padding: 0.75rem 1rem;
    border: 1px solid var(--books-border);
    border-radius: var(--books-radius);
    text-decoration: none;
    color: inherit;
    transition: border-color var(--books-transition), box-shadow var(--books-transition);
    flex: 1;
    min-width: 0;
}

.chapter-nav-btn:hover {
    border-color: var(--books-primary-light);
    box-shadow: 0 2px 8px rgba(66, 99, 235, 0.1);
    text-decoration: none;
    color: inherit;
}

.chapter-nav-btn.prev {
    text-align: left;
}

.chapter-nav-btn.next {
    text-align: right;
}

.chapter-nav-btn .nav-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--books-muted-text);
    letter-spacing: 0.5px;
    margin-bottom: 0.15rem;
}

.chapter-nav-btn .nav-title {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--books-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* --- 404 --- */

.books-notfound {
    text-align: center;
    padding: 4rem 1rem;
}

.books-notfound h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--books-dark-text);
    margin-bottom: 0.5rem;
}

.books-notfound p {
    color: var(--books-muted-text);
    margin-bottom: 1.5rem;
}

.books-notfound .btn-back {
    display: inline-block;
    padding: 0.6rem 1.5rem;
    background: var(--books-primary);
    color: #fff;
    border-radius: 25px;
    text-decoration: none;
    font-weight: 500;
    font-size: 0.9rem;
    transition: background var(--books-transition);
}

.books-notfound .btn-back:hover {
    background: var(--books-primary-dark);
    text-decoration: none;
    color: #fff;
}

/* ==========================================================================
   Small Tablet (576px+)
   ========================================================================== */

@media (min-width: 576px) {
    .books-hero {
        padding: 3.5rem 1.5rem 2.5rem;
    }

    .books-hero h1 {
        font-size: 2rem;
    }

    .books-library {
        padding: 2rem 1.5rem;
    }

    .books-grid {
        gap: 1.25rem;
    }

    .book-card-body {
        padding: 1rem;
    }

    .book-card-title {
        font-size: 0.95rem;
    }

    .books-toc,
    .books-reader {
        padding: 2rem 1.5rem 3rem;
    }

    .chapter-nav-btn .nav-title {
        font-size: 0.9rem;
    }
}

/* ==========================================================================
   Tablet (768px+)
   ========================================================================== */

@media (min-width: 768px) {
    .books-hero {
        padding: 4rem 2rem 3rem;
    }

    .books-hero h1 {
        font-size: 2.25rem;
    }

    .books-hero p {
        font-size: 1.125rem;
    }

    .books-library {
        padding: 2.5rem 2rem;
        max-width: 900px;
        margin: 0 auto;
    }

    .books-library .section-title {
        font-size: 1.5rem;
    }

    .books-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 1.5rem;
    }

    .book-card-cover .book-initials {
        font-size: 2.5rem;
    }

    .books-toc {
        padding: 2.5rem 2rem 3rem;
        max-width: 720px;
        margin: 0 auto;
    }

    .books-toc-header h1 {
        font-size: 1.75rem;
    }

    .chapter-link {
        padding: 1.25rem;
    }

    .chapter-title {
        font-size: 1.05rem;
    }

    .books-reader {
        padding: 2.5rem 2.5rem 4rem;
        max-width: 720px;
        margin: 0 auto;
    }

    .reader-header h1 {
        font-size: 1.75rem;
    }

    .reader-content .markdown-content p {
        font-size: 1.05rem;
    }

    .chapter-nav-btn {
        padding: 1rem 1.25rem;
    }

    .chapter-nav-btn .nav-title {
        font-size: 0.95rem;
    }
}

/* ==========================================================================
   Desktop (992px+)
   ========================================================================== */

@media (min-width: 992px) {
    .books-hero {
        padding: 5rem 2rem 3.5rem;
    }

    .books-hero h1 {
        font-size: 2.5rem;
    }

    .books-library {
        max-width: 1000px;
    }

    .books-grid {
        grid-template-columns: repeat(4, 1fr);
    }

    .book-card-cover .book-icon {
        font-size: 3rem;
    }

    .books-reader {
        max-width: 760px;
        padding: 3rem 3.5rem 4rem;
    }

    .reader-header h1 {
        font-size: 2rem;
    }

    .reader-content .markdown-content {
        font-size: 1.0625rem;
    }

    .reader-content .markdown-content p {
        font-size: 1.0625rem;
        line-height: 1.9;
    }

    .reader-content .markdown-content h1 {
        font-size: 1.75rem;
    }
}

/* ==========================================================================
   Large Desktop (1200px+)
   ========================================================================== */

@media (min-width: 1200px) {
    .books-library {
        max-width: 1100px;
    }

    .books-reader {
        max-width: 800px;
        padding: 3rem 4rem 4.5rem;
    }

    .reader-content .markdown-content {
        font-size: 1.125rem;
    }

    .reader-content .markdown-content p {
        font-size: 1.125rem;
        line-height: 1.95;
    }

    .reader-content .markdown-content h1 {
        font-size: 2rem;
    }

    .reader-content .markdown-content h2 {
        font-size: 1.5rem;
    }
}

/* ==========================================================================
   Dark Mode
   ========================================================================== */

@media (prefers-color-scheme: dark) {
    .book-card {
        background: #1e1e1e;
        box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
    }

    .book-card-title {
        color: #e9ecef;
    }

    .chapter-item {
        border-color: #333;
    }

    .books-reader {
        background: #1a1814;
        box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.2);
    }

    .reader-header {
        border-bottom-color: #33302a;
    }

    .reader-header h1 {
        color: #e8e2d6;
    }

    .reader-header .chapter-label,
    .reader-header .reader-meta {
        color: #9a8e7c;
    }

    .reader-content .markdown-content {
        color: #d4cdc0;
    }

    .reader-content .markdown-content h1,
    .reader-content .markdown-content h2,
    .reader-content .markdown-content h3 {
        color: #e8e2d6;
        border-bottom-color: #33302a;
    }

    .reader-content .markdown-content blockquote {
        background: #23201a;
        border-left-color: #5a4e3c;
        color: #b8ad9c;
    }
}

/* ==========================================================================
   Reduced Motion
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
    .book-card,
    .chapter-item,
    .chapter-arrow,
    .chapter-nav-btn {
        transition: none;
    }

    .book-card:hover {
        transform: none;
    }

    .chapter-item:hover .chapter-arrow {
        transform: none;
    }
}

/* ==========================================================================
   Print Styles
   ========================================================================== */

@media print {
    .books-hero,
    .books-breadcrumb,
    .books-back,
    .chapter-nav,
    .catalog-pagination {
        display: none;
    }

    .books-reader {
        padding: 0;
        max-width: 100%;
    }

    .reader-content .markdown-content {
        font-size: 12pt;
        line-height: 1.6;
        color: #000;
    }
}

/* ==========================================================================
   Catalog Browser
   ========================================================================== */

/* Cover image inside card */
.catalog-card-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    position: absolute;
    top: 0;
    left: 0;
}

/* Author + year line */
.catalog-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 0.5rem;
    font-size: 0.75rem;
    color: var(--books-muted-text);
    margin-bottom: 0.35rem;
    line-height: 1.3;
}

.catalog-author {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.catalog-year::before {
    content: "\00B7";
    margin-right: 0.5rem;
}

/* Genre pills */
.catalog-genres {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    margin-top: auto;
}

.catalog-genre-pill {
    display: inline-block;
    padding: 0.1rem 0.45rem;
    font-size: 0.65rem;
    border-radius: 9999px;
    background: var(--books-light-bg);
    color: var(--books-muted-text);
    border: 1px solid var(--books-border);
    white-space: nowrap;
    text-transform: capitalize;
}

/* Info bar */
.catalog-info {
    font-size: 0.85rem;
    color: var(--books-muted-text);
    margin-bottom: 1rem;
}

/* Pagination */
.catalog-pagination {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 0.35rem;
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--books-border);
}

.catalog-page-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2.2rem;
    padding: 0.4rem 0.7rem;
    font-size: 0.85rem;
    border: 1px solid var(--books-border);
    border-radius: 6px;
    text-decoration: none;
    color: var(--books-dark-text);
    background: #fff;
    transition: border-color var(--books-transition), background var(--books-transition);
}

.catalog-page-btn:hover {
    border-color: var(--books-primary-light);
    background: var(--books-light-bg);
    text-decoration: none;
    color: var(--books-primary);
}

.catalog-page-btn.active {
    background: var(--books-primary);
    border-color: var(--books-primary);
    color: #fff;
    font-weight: 600;
}

.catalog-page-btn.disabled {
    opacity: 0.4;
    pointer-events: none;
}

.catalog-page-ellipsis {
    padding: 0 0.25rem;
    color: var(--books-muted-text);
}

/* Dark mode additions */
@media (prefers-color-scheme: dark) {
    .catalog-genre-pill {
        background: #2a2a2a;
        border-color: #444;
        color: #adb5bd;
    }

    .catalog-page-btn {
        background: #1e1e1e;
        border-color: #333;
        color: #e0e0e0;
    }

    .catalog-page-btn.active {
        background: var(--books-primary);
        border-color: var(--books-primary);
        color: #fff;
    }
}

/* ==========================================================================
   Premium Book Reader
   ========================================================================== */

/* --- Light theme (default) --- */
.reader-page {
    --rdr-bg: #ffffff;
    --rdr-bg-elevated: #f8fafc;
    --rdr-text: #1e293b;
    --rdr-text-muted: #64748b;
    --rdr-heading: #0f172a;
    --rdr-border: #e2e8f0;
    --rdr-accent: #4f46e5;
    --rdr-accent-hover: #4338ca;
    --rdr-accent-subtle: #eef2ff;
    --rdr-code-bg: #f1f5f9;
    --rdr-code-text: #0f172a;
    --rdr-code-border: #e2e8f0;
    --rdr-quote-bg: #f8fafc;
    --rdr-quote-border: #a5b4fc;
    --rdr-quote-text: #475569;
    --rdr-link: #4f46e5;
    --rdr-link-hover: #4338ca;
    --rdr-hr: #e2e8f0;
    --rdr-table-stripe: #f8fafc;
    --rdr-table-border: #e2e8f0;
    --rdr-cover-grad: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
    --rdr-genre-bg: #f1f5f9;
    --rdr-genre-text: #475569;
    --rdr-genre-border: #e2e8f0;
    --rdr-nav-bg: #ffffff;
    --rdr-nav-border: #e2e8f0;
    --rdr-toggle-bg: #f1f5f9;
    --rdr-toggle-hover: #e2e8f0;
    --rdr-progress: #4f46e5;
    --rdr-shadow: 0 1px 3px rgba(0,0,0,0.06);
    --rdr-shadow-cover: 0 8px 30px rgba(0,0,0,0.12);
}

/* --- Dark theme --- */
.reader-page[data-theme="dark"] {
    --rdr-bg: #0d1117;
    --rdr-bg-elevated: #161b22;
    --rdr-text: #c9d1d9;
    --rdr-text-muted: #8b949e;
    --rdr-heading: #e6edf3;
    --rdr-border: #30363d;
    --rdr-accent: #818cf8;
    --rdr-accent-hover: #a5b4fc;
    --rdr-accent-subtle: rgba(129,140,248,0.08);
    --rdr-code-bg: #161b22;
    --rdr-code-text: #e6edf3;
    --rdr-code-border: #30363d;
    --rdr-quote-bg: #161b22;
    --rdr-quote-border: #6366f1;
    --rdr-quote-text: #8b949e;
    --rdr-link: #818cf8;
    --rdr-link-hover: #a5b4fc;
    --rdr-hr: #30363d;
    --rdr-table-stripe: #161b22;
    --rdr-table-border: #30363d;
    --rdr-cover-grad: linear-gradient(135deg, #312e81 0%, #4c1d95 100%);
    --rdr-genre-bg: #21262d;
    --rdr-genre-text: #8b949e;
    --rdr-genre-border: #30363d;
    --rdr-nav-bg: #161b22;
    --rdr-nav-border: #30363d;
    --rdr-toggle-bg: #21262d;
    --rdr-toggle-hover: #30363d;
    --rdr-progress: #818cf8;
    --rdr-shadow: 0 1px 3px rgba(0,0,0,0.3);
    --rdr-shadow-cover: 0 8px 30px rgba(0,0,0,0.4);
}

/* --- Page wrapper --- */
.reader-page {
    background: var(--rdr-bg);
    color: var(--rdr-text);
    min-height: 80vh;
    padding-top: 80px;
    transition: background-color 0.35s ease, color 0.35s ease;
}

/* --- Progress bar --- */
.rdr-progress {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 3px;
    z-index: 9999;
    background: transparent;
}

.rdr-progress-bar {
    height: 100%;
    width: 0;
    background: var(--rdr-progress);
    transition: width 0.1s linear;
    border-radius: 0 2px 2px 0;
}

/* --- Top navigation bar (hidden - toggle moved to main navbar) --- */
.rdr-nav {
    display: none;
}

.rdr-nav-inner {
    max-width: 800px;
    margin: 0 auto;
    padding: 0.65rem 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.rdr-back {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.925rem;
    font-weight: 500;
    color: var(--rdr-text-muted);
    text-decoration: none;
    transition: color 0.2s ease;
}

.rdr-back:hover {
    color: var(--rdr-accent);
    text-decoration: none;
}

.rdr-back svg {
    flex-shrink: 0;
}

.rdr-theme-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: none;
    background: var(--rdr-toggle-bg);
    color: var(--rdr-text-muted);
    cursor: pointer;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.rdr-theme-btn:hover {
    background: var(--rdr-toggle-hover);
    color: var(--rdr-heading);
}

/* Icon visibility: light mode shows moon, dark shows sun */
.reader-page .rdr-icon-sun { display: none; }
.reader-page .rdr-icon-moon { display: inline-block; }
.reader-page[data-theme="dark"] .rdr-icon-sun { display: inline-block; }
.reader-page[data-theme="dark"] .rdr-icon-moon { display: none; }

/* --- Book header --- */
.rdr-header {
    padding: 2rem 1.25rem;
    border-bottom: 1px solid var(--rdr-border);
    transition: border-color 0.35s ease;
}

.rdr-header-inner {
    max-width: 720px;
    margin: 0 auto;
    display: flex;
    gap: 1.25rem;
    align-items: flex-start;
}

.rdr-cover {
    width: 100px;
    flex-shrink: 0;
    aspect-ratio: 3 / 4;
    border-radius: 6px;
    overflow: hidden;
    box-shadow: var(--rdr-shadow-cover);
    position: relative;
    background: var(--rdr-cover-grad);
    display: flex;
    align-items: center;
    justify-content: center;
}

.rdr-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    position: absolute;
    top: 0;
    left: 0;
}

.rdr-cover-fallback {
    font-size: 1.5rem;
    font-weight: 800;
    color: rgba(255,255,255,0.85);
    text-transform: uppercase;
    letter-spacing: 2px;
}

.rdr-info {
    flex: 1;
    min-width: 0;
    padding-top: 0.15rem;
}

.rdr-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--rdr-heading);
    line-height: 1.3;
    margin: 0 0 0.3rem;
    transition: color 0.35s ease;
}

.rdr-author {
    font-size: 1rem;
    color: var(--rdr-text-muted);
    margin-bottom: 0.3rem;
    transition: color 0.35s ease;
}

.rdr-meta {
    font-size: 0.85rem;
    color: var(--rdr-text-muted);
    display: flex;
    flex-wrap: wrap;
    gap: 0;
    margin-bottom: 0.6rem;
    transition: color 0.35s ease;
}

.rdr-meta span + span::before {
    content: "\00B7";
    margin: 0 0.4rem;
}

.rdr-genres {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
}

.rdr-genre {
    display: inline-block;
    padding: 0.2rem 0.65rem;
    font-size: 0.775rem;
    font-weight: 500;
    border-radius: 9999px;
    background: var(--rdr-genre-bg);
    color: var(--rdr-genre-text);
    border: 1px solid var(--rdr-genre-border);
    text-transform: capitalize;
    transition: background-color 0.35s ease, color 0.35s ease, border-color 0.35s ease;
}

/* --- Article body --- */
.rdr-body {
    max-width: 720px;
    margin: 0 auto;
    padding: 2rem 1.25rem 3rem;
}

/* Empty state */
.rdr-empty {
    text-align: center;
    padding: 4rem 1rem;
    color: var(--rdr-text-muted);
}

.rdr-empty a {
    color: var(--rdr-accent);
    text-decoration: none;
    font-weight: 500;
}

/* -----------------------------------------------------------------------
   Prose: full markdown rendering
   ----------------------------------------------------------------------- */

.rdr-prose {
    font-family: 'Source Serif 4', source-serif-pro, Georgia, Cambria, 'Times New Roman', serif;
    font-size: 1.25rem;
    line-height: 1.58;
    color: var(--rdr-text);
    word-break: break-word;
    letter-spacing: -0.003em;
    font-optical-sizing: auto;
    -webkit-font-smoothing: antialiased;
    transition: color 0.35s ease;
}

/* Headings */
.rdr-prose h1 {
    font-family: sohne, 'Helvetica Neue', Helvetica, Arial, sans-serif;
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--rdr-heading);
    margin: 2.5rem 0 0.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--rdr-border);
    line-height: 1.22;
    letter-spacing: -0.022em;
    transition: color 0.35s ease, border-color 0.35s ease;
}

.rdr-prose h2 {
    font-family: sohne, 'Helvetica Neue', Helvetica, Arial, sans-serif;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--rdr-heading);
    margin: 2.25rem 0 0.5rem;
    line-height: 1.28;
    letter-spacing: -0.018em;
    transition: color 0.35s ease;
}

.rdr-prose h3 {
    font-family: sohne, 'Helvetica Neue', Helvetica, Arial, sans-serif;
    font-size: 1.375rem;
    font-weight: 700;
    color: var(--rdr-heading);
    margin: 2rem 0 0.4rem;
    line-height: 1.32;
    letter-spacing: -0.014em;
    transition: color 0.35s ease;
}

.rdr-prose h4,
.rdr-prose h5,
.rdr-prose h6 {
    font-family: sohne, 'Helvetica Neue', Helvetica, Arial, sans-serif;
    font-weight: 700;
    color: var(--rdr-heading);
    margin: 1.75rem 0 0.35rem;
    line-height: 1.36;
    transition: color 0.35s ease;
}

.rdr-prose h4 { font-size: 1.25rem; }
.rdr-prose h5 { font-size: 1.125rem; }
.rdr-prose h6 { font-size: 1rem; color: var(--rdr-text-muted); }

/* Paragraphs */
.rdr-prose p {
    margin: 0 0 2rem;
    line-height: 1.58;
}

/* Links */
.rdr-prose a {
    color: var(--rdr-link);
    text-decoration: underline;
    text-decoration-color: rgba(79,70,229,0.3);
    text-underline-offset: 2px;
    transition: color 0.2s ease, text-decoration-color 0.2s ease;
}

.rdr-prose a:hover {
    color: var(--rdr-link-hover);
    text-decoration-color: currentColor;
}

.reader-page[data-theme="dark"] .rdr-prose a {
    text-decoration-color: rgba(129,140,248,0.3);
}

/* Bold & italic */
.rdr-prose strong { font-weight: 700; color: var(--rdr-heading); }
.rdr-prose em { font-style: italic; }

/* Lists */
.rdr-prose ul,
.rdr-prose ol {
    margin: 0 0 1.35rem;
    padding-left: 1.75rem;
}

.rdr-prose li {
    margin-bottom: 0.4rem;
    line-height: 1.8;
}

.rdr-prose li > ul,
.rdr-prose li > ol {
    margin-top: 0.4rem;
    margin-bottom: 0;
}

.rdr-prose ul { list-style-type: disc; }
.rdr-prose ol { list-style-type: decimal; }
.rdr-prose ul ul { list-style-type: circle; }

/* Blockquote */
.rdr-prose blockquote {
    margin: 1.75rem 0;
    padding: 1rem 1.25rem;
    border-left: 3px solid var(--rdr-quote-border);
    background: var(--rdr-quote-bg);
    border-radius: 0 8px 8px 0;
    color: var(--rdr-quote-text);
    font-style: italic;
    transition: background-color 0.35s ease, border-color 0.35s ease, color 0.35s ease;
}

.rdr-prose blockquote p:last-child { margin-bottom: 0; }

/* Inline code */
.rdr-prose code {
    font-family: 'SF Mono', 'Cascadia Code', 'Fira Code', Consolas, monospace;
    font-size: 0.875em;
    padding: 0.15em 0.4em;
    background: var(--rdr-code-bg);
    color: var(--rdr-code-text);
    border-radius: 4px;
    border: 1px solid var(--rdr-code-border);
    transition: background-color 0.35s ease, color 0.35s ease, border-color 0.35s ease;
}

/* Code blocks */
.rdr-prose pre {
    margin: 1.75rem 0;
    padding: 1.25rem;
    background: var(--rdr-code-bg);
    border: 1px solid var(--rdr-code-border);
    border-radius: 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    transition: background-color 0.35s ease, border-color 0.35s ease;
}

.rdr-prose pre code {
    font-size: 0.85rem;
    padding: 0;
    background: none;
    border: none;
    border-radius: 0;
    line-height: 1.6;
    color: var(--rdr-code-text);
}

/* Horizontal rule */
.rdr-prose hr {
    margin: 2.5rem 0;
    border: none;
    height: 1px;
    background: var(--rdr-hr);
    transition: background-color 0.35s ease;
}

/* Tables */
.rdr-prose table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.75rem 0;
    font-size: 0.9em;
}

.rdr-prose th,
.rdr-prose td {
    text-align: left;
    padding: 0.6rem 0.8rem;
    border: 1px solid var(--rdr-table-border);
    transition: border-color 0.35s ease;
}

.rdr-prose th {
    font-weight: 600;
    background: var(--rdr-bg-elevated);
    color: var(--rdr-heading);
}

.rdr-prose tr:nth-child(even) {
    background: var(--rdr-table-stripe);
}

/* Images */
.rdr-prose img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 1.5rem 0;
}

/* --- Reader footer --- */
.rdr-footer {
    border-top: 1px solid var(--rdr-border);
    transition: border-color 0.35s ease;
}

.rdr-footer-inner {
    max-width: 680px;
    margin: 0 auto;
    padding: 1.5rem 1.25rem 2.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.rdr-footer-back {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--rdr-text-muted);
    text-decoration: none;
    transition: color 0.2s ease;
}

.rdr-footer-back:hover {
    color: var(--rdr-accent);
    text-decoration: none;
}

.rdr-footer-copy {
    font-size: 0.8rem;
    color: var(--rdr-text-muted);
    opacity: 0.6;
}

/* --- Reader responsive: 576px+ --- */
@media (min-width: 576px) {
    .rdr-header { padding: 2.5rem 1.5rem; }
    .rdr-header-inner { gap: 1.5rem; }
    .rdr-cover { width: 120px; }
    .rdr-title { font-size: 1.6rem; }
    .rdr-body { padding: 2.5rem 1.5rem 3.5rem; }
    .rdr-prose { font-size: 1.25rem; }
}

/* --- Reader responsive: 768px+ --- */
@media (min-width: 768px) {
    .rdr-nav-inner { padding: 0.75rem 2rem; }
    .rdr-header { padding: 3rem 2rem; }
    .rdr-header-inner { gap: 2rem; }
    .rdr-cover { width: 150px; border-radius: 8px; }
    .rdr-cover-fallback { font-size: 2rem; }
    .rdr-title { font-size: 1.85rem; }
    .rdr-author { font-size: 1.05rem; }
    .rdr-meta { font-size: 0.875rem; }
    .rdr-genre { font-size: 0.8rem; padding: 0.2rem 0.7rem; }
    .rdr-body { padding: 3rem 2rem 4rem; }
    .rdr-prose { font-size: 1.3125rem; }
    .rdr-prose h1 { font-size: 2rem; }
    .rdr-prose h2 { font-size: 1.5rem; }
    .rdr-prose h3 { font-size: 1.25rem; }
    .rdr-prose p { line-height: 1.58; }
    .rdr-footer-inner { padding: 2rem; }
}

/* --- Reader responsive: 992px+ --- */
@media (min-width: 992px) {
    .rdr-cover { width: 170px; }
    .rdr-title { font-size: 2rem; }
    .rdr-body { padding: 3rem 2rem 4.5rem; }
    .rdr-prose { font-size: 1.3125rem; }
    .rdr-prose h1 { font-size: 2.125rem; }
    .rdr-prose h2 { font-size: 1.625rem; }
    .rdr-prose h3 { font-size: 1.3rem; }
    .rdr-prose p { line-height: 1.58; }
}

/* --- Reader responsive: 1200px+ --- */
@media (min-width: 1200px) {
    .rdr-body { max-width: 680px; }
    .rdr-header-inner { max-width: 680px; }
    .rdr-footer-inner { max-width: 680px; }
    .rdr-prose { font-size: 1.3125rem; }
    .rdr-prose p { line-height: 1.58; }
    .rdr-prose h1 { font-size: 2.25rem; }
    .rdr-prose h2 { font-size: 1.75rem; }
}

/* --- Reader print --- */
@media print {
    .rdr-nav,
    .rdr-progress,
    .rdr-footer { display: none; }
    .reader-page { background: #fff; color: #000; }
    .rdr-prose { font-size: 11pt; line-height: 1.6; color: #000; }
    .rdr-prose h1, .rdr-prose h2, .rdr-prose h3 { color: #000; }
    .rdr-cover { box-shadow: none; }
}

/* -----------------------------------------------------------------------
   Reader dark mode: Crafto template overrides
   body[data-reader-theme="dark"] is set by JS alongside .reader-page
   ----------------------------------------------------------------------- */

html[data-reader-theme="dark"],
body[data-reader-theme="dark"] {
    background-color: #0d1117 !important;
}

/* Navbar background — override Crafto sticky + data-header-hover=light */
body[data-reader-theme="dark"] > header,
body[data-reader-theme="dark"] > header nav.navbar,
body[data-reader-theme="dark"] header.sticky.sticky-active [data-header-hover="light"] {
    background-color: #161b22 !important;
    box-shadow: 0 1px 0 #30363d !important;
}

/* Nav link text */
body[data-reader-theme="dark"] > header .nav-link,
body[data-reader-theme="dark"] > header .widget-text,
body[data-reader-theme="dark"] > header .widget-text a,
body[data-reader-theme="dark"] header.sticky.sticky-active [data-header-hover="light"] .nav-link,
body[data-reader-theme="dark"] header.sticky.sticky-active [data-header-hover="light"] .widget-text a {
    color: #c9d1d9 !important;
}

/* Swap logo: hide black logo, show white logo */
body[data-reader-theme="dark"] > header .navbar-brand .alt-logo,
body[data-reader-theme="dark"] > header .navbar-brand .mobile-logo {
    filter: invert(1) brightness(1.8);
}

/* Dropdown menus */
body[data-reader-theme="dark"] > header .dropdown-menu {
    background-color: #161b22 !important;
    border-color: #30363d !important;
}

body[data-reader-theme="dark"] > header .dropdown-menu a {
    color: #c9d1d9 !important;
}

body[data-reader-theme="dark"] > header .dropdown-menu a:hover {
    background-color: #21262d !important;
    color: #e6edf3 !important;
}

/* Footer */
body[data-reader-theme="dark"] > footer {
    background: #0d1117 !important;
}

body[data-reader-theme="dark"] > footer a,
body[data-reader-theme="dark"] > footer p,
body[data-reader-theme="dark"] > footer span,
body[data-reader-theme="dark"] > footer li {
    color: #8b949e !important;
}

body[data-reader-theme="dark"] > footer a:hover {
    color: #c9d1d9 !important;
}

body[data-reader-theme="dark"] > footer .border-top {
    border-color: #30363d !important;
}

/* Scroll progress dot */
body[data-reader-theme="dark"] .scroll-progress .scroll-top {
    background-color: #161b22 !important;
    border-color: #30363d !important;
}

body[data-reader-theme="dark"] .scroll-progress .scroll-text {
    color: #8b949e !important;
}

/* --- Mobile nav overrides for reader pages --- */
body[data-reader-theme="dark"] .navbar-modern-inner,
body[data-reader-theme="dark"] [data-mobile-nav-style=modern] .navbar-modern-inner {
    background-color: #161b22 !important;
}

body[data-reader-theme="dark"] .navbar-modern-inner .navbar-nav .nav-link {
    color: #e6edf3 !important;
}

body[data-reader-theme="dark"] .navbar-modern-inner .navbar-toggler-line {
    background-color: #c9d1d9 !important;
}

body[data-reader-theme="light"] .navbar-modern-inner,
body[data-reader-theme="light"] [data-mobile-nav-style=modern] .navbar-modern-inner {
    background-color: #ffffff !important;
}

body[data-reader-theme="light"] .navbar-modern-inner .navbar-nav .nav-link {
    color: #1a1a1a !important;
}

body[data-reader-theme="light"] .navbar-modern-inner .navbar-toggler-line {
    background-color: #333 !important;
}

/* ==========================================================================
   Knoww Theme: Grid/Catalog dark mode overrides
   ========================================================================== */

/* Page background */
body[data-reader-theme="dark"] .knoww-themed-page {
    background-color: #0d1117 !important;
    color: #e6edf3;
}

body[data-reader-theme="dark"] .knoww-themed-page section,
body[data-reader-theme="dark"] .knoww-themed-page nav.books-breadcrumb {
    background-color: transparent !important;
}

/* Hero */
body[data-reader-theme="dark"] .books-hero {
    background: linear-gradient(135deg, #1a1f36 0%, #2d1b4e 100%) !important;
}

/* Breadcrumb */
body[data-reader-theme="dark"] .books-breadcrumb {
    background: #0d1117;
    border-color: #30363d;
}

body[data-reader-theme="dark"] .books-breadcrumb li + li::before {
    color: #484f58;
}

body[data-reader-theme="dark"] .books-breadcrumb li {
    color: #8b949e;
}

body[data-reader-theme="dark"] .books-breadcrumb a {
    color: #8b949e;
}

body[data-reader-theme="dark"] .books-breadcrumb a:hover {
    color: #e6edf3;
}

/* Search bar */
body[data-reader-theme="dark"] #bookSearchInput {
    background: #161b22 !important;
    border-color: #30363d !important;
    color: #e6edf3 !important;
}

body[data-reader-theme="dark"] #bookSearchInput::placeholder {
    color: #6e7681 !important;
}

/* Catalog info text */
body[data-reader-theme="dark"] .catalog-info {
    color: #8b949e;
}

/* Book cards */
body[data-reader-theme="dark"] .book-card {
    background: #161b22;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
}

body[data-reader-theme="dark"] .book-card:hover {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

body[data-reader-theme="dark"] .book-card-title {
    color: #e6edf3;
}

body[data-reader-theme="dark"] .book-card-meta {
    color: #8b949e;
}

body[data-reader-theme="dark"] .catalog-author {
    color: #8b949e;
}

body[data-reader-theme="dark"] .catalog-year {
    color: #6e7681;
}

body[data-reader-theme="dark"] .catalog-year::before {
    color: #6e7681;
}

/* Genre pills */
body[data-reader-theme="dark"] .catalog-genre-pill {
    background: #21262d;
    border-color: #30363d;
    color: #8b949e;
}

/* Pagination */
body[data-reader-theme="dark"] .catalog-pagination {
    border-top-color: #30363d;
}

body[data-reader-theme="dark"] .catalog-page-btn {
    background: #161b22;
    border-color: #30363d;
    color: #c9d1d9;
}

body[data-reader-theme="dark"] .catalog-page-btn:hover {
    border-color: #58a6ff;
    background: #21262d;
    color: #58a6ff;
}

body[data-reader-theme="dark"] .catalog-page-btn.active {
    background: #4263eb;
    border-color: #4263eb;
    color: #fff;
}

body[data-reader-theme="dark"] .catalog-page-ellipsis {
    color: #6e7681;
}

/* Books library section */
body[data-reader-theme="dark"] .books-library {
    background: #0d1117;
}

body[data-reader-theme="dark"] .books-library .section-title {
    color: #e6edf3;
}

/* Search section */
body[data-reader-theme="dark"] .books-search-section {
    background: transparent;
}

/* Theme footer */
body[data-reader-theme="dark"] .knoww-theme-footer {
    border-top-color: #30363d !important;
}

body[data-reader-theme="dark"] .knoww-theme-footer a,
body[data-reader-theme="dark"] .knoww-theme-footer span {
    color: #8b949e !important;
}

/* Light mode: ensure themed page is white */
body[data-reader-theme="light"] .knoww-themed-page {
    background-color: #fff;
    color: #343a40;
}
