:root {
    --bg-color: #f9f9fb;
    --surface-color: #ffffff;
    --text-primary: #1a1a1a;
    --text-secondary: #666666;
    --accent-color: #2563eb;
    --border-color: #e5e7eb;
    --badge-free: #10b981;
    --badge-premium: #f59e0b;
    --font-family-reader: 'Georgia', serif;
    --font-size-reader: 18px;
}

body.dark-mode {
    --bg-color: #121212;
    --surface-color: #1e1e1e;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0a0;
    --border-color: #333333;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    transition: background-color 0.3s, color 0.3s;
}

.navbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    background-color: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 10;
}

.logo {
    font-weight: 700;
    font-size: 3rem;
    cursor: pointer;
    color: var(--accent-color);
}

.nav-links {
    display: flex;
    gap: 0.5rem;
}

.nav-btn {
    background: none;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    color: var(--text-secondary);
    cursor: pointer;
    font-weight: 500;
}

.nav-btn.active,
.nav-btn:hover {
    background-color: var(--accent-color);
    color: #ffffff;
}

.icon-btn {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
}

.container {
    max-width: 1000px;
    margin: 2rem auto;
    padding: 0 1rem;
}

.hidden {
    display: none !important;
}

.hero {
    text-align: center;
    margin-bottom: 2.5rem;
}

.hero h1 {
    font-size: 2.2rem;
    margin-bottom: 0.5rem;
}

.hero p {
    color: var(--text-secondary);
}

.books-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 1.5rem;
}

.book-card {
    width: 200px;
    /* Adjust grid item width */
    aspect-ratio: 2 / 3;
    /* Enforces a standard vertical book rectangle */
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    border-radius: 8px;
    overflow: hidden;
    background: #0d0d0d;
    padding: 10px;
    box-sizing: border-box;
}

.book-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.6);
}


.book-cover-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    /* Keeps 100% of the image details without cropping or stretching */
    display: block;
}

.card-badge {
    position: absolute;
    top: 12px;
    right: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 4px 8px;
    border-radius: 12px;
    color: #fff;
}

.card-badge.free {
    background-color: var(--badge-free);
}

.card-badge.premium {
    background-color: var(--badge-premium);
}

.cover-placeholder {
    height: 140px;
    background-color: var(--bg-color);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    margin-bottom: 1rem;
}

.book-card h3 {
    font-size: 1.1rem;
    margin-bottom: 0.3rem;
}

.author {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.category-tag {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--accent-color);
    font-weight: 600;
}

#reader-view {
    max-width: 680px;
}

.reader-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.btn-secondary,
.btn-sm {
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 0.4rem 0.8rem;
    border-radius: 6px;
    cursor: pointer;
}

.font-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
}

.reader-header {
    margin-bottom: 2rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 1rem;
}

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

.reader-header h2 {
    font-size: 1.2rem;
    color: var(--text-secondary);
    font-weight: 400;
}

.reader-body {
    font-family: var(--font-family-reader);
    font-size: var(--font-size-reader);
    line-height: 1.8;
    color: var(--text-primary);
}

.reader-body p {
    margin-bottom: 1.5rem;
}

.paywall-overlay {
    margin-top: 2rem;
    padding: 2rem;
    text-align: center;
    background: var(--surface-color);
    border: 2px dashed var(--badge-premium);
    border-radius: 12px;
}

.paywall-card h3 {
    margin-bottom: 0.5rem;
}

.paywall-card p {
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

.btn-primary {
    background: var(--accent-color);
    color: #fff;
    border: none;
    padding: 0.8rem 1.5rem;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
}

body.dark-mode #theme-toggle,
body.dark-mode #theme-toggle *,
body.dark-mode #theme-toggle svg,
body.dark-mode #theme-toggle svg path {
    color: #f1c40f !important;
    fill: #f1c40f !important;
    stroke: #f1c40f !important;
}

.section-title {
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 30px;
    font-size: 1.2rem;
    color: gray;
}

#reader-body {
    column-width: 100vw;
    column-gap: 20px;
    height: 75vh;

    overflow-x: hidden;
    overflow-y: hidden;
    padding: 20px 10px 0 10px;
    box-sizing: border-box;

    scrollbar-width: none;
    -ms-overflow-style: none;
}

#reader-body>* {
    break-inside: avoid-column;
    page-break-inside: avoid;
    margin-top: 0;
}

#reader-body::-webkit-scrollbar {
    display: none;
}

.resume-banner {
    background: #222;
    color: #fff;
    padding: 15px;
    margin-bottom: 20px;
    text-align: center;
    cursor: pointer;
    border-radius: 8px;
    border: 1px solid #444;
    transition: background 0.2s ease;
}

.resume-banner:hover {
    background: #333;
}

.novel-card {
    width: 150px;
    cursor: pointer;
    transition: transform 0.2s ease-in-out;
}

.novel-card:hover {
    transform: scale(1.05);
}

.novel-card img {
    width: 100%;
    border-radius: 6px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.subscribe-btn {
    background-color: #e50914;
    /* Or your accent color */
    color: #ffffff;
    border: none;
    padding: 10px 20px;
    font-size: 0.95rem;
    font-weight: 600;
    border-radius: 6px;
    cursor: pointer;
    margin-top: 10px;
    transition: background-color 0.2s ease, transform 0.2s ease;
}

.subscribe-btn:hover {
    background-color: #b80710;
    transform: translateY(-2px);
}

/* Modal Overlay Styling */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(4px);
    /* Modern glass blur effect */
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-overlay.hidden {
    display: none;
}

.modal-card {
    background-color: #1a1a1a;
    border: 1px solid #333;
    padding: 2rem;
    border-radius: 12px;
    max-width: 400px;
    width: 90%;
    text-align: center;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.8);
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 1.5rem;
}

.reader-body {
    user-select: none;
    /* Disables text highlighting/copying in the reader */
    -webkit-user-select: none;
}

/* Lines 411-417: Lock outer app shell to exact mobile viewport height */
html,
body,
#app {
    width: 100vw;
    height: 100dvh;
    margin: 0;
    padding: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
}

/* Lines 420-436: Middle reader box fills available screen space and enables vertical scroll */
.reader-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px;
    -webkit-overflow-scrolling: touch;
}

/* Lines 439-444: Clean paragraph styling (column/snap rules removed) */
.reader-container p {
    font-size: 1.05rem;
    line-height: 1.6;
    margin-bottom: 1rem;
}

/* Bottom navigation bar: Anchors left/right buttons to bottom edge */
.navigation-bar {
    /* Replace with your actual footer/button container class or ID */
    flex-shrink: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    background-color: #ffffff;
    border-top: 1px solid #eeeeee;
}

/* Lines 411-417: Lock outer app shell to exact mobile viewport height */
/* 1. RESTORE DASHBOARD SCROLLING */
html,
body {
    margin: 0;
    padding: 0;
    width: 100%;
    overflow-x: hidden;
    overflow-y: auto;
}

/* 2. FULLSCREEN READER OVERLAY (ACTIVE ONLY WHEN READING) */
#reader-view {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    background-color: inherit;
    color: inherit;
    z-index: 1000;
    box-sizing: border-box;
}

#reader-view.hidden {
    display: none !important;
    pointer-events: none !important;
}

#reader-body {
    height: 100%;
    width: 100%;
    overflow-x: auto;
    overflow-y: hidden;

    /* CSS Multi-Column Pagination */
    column-width: 100%;
    column-gap: 40px;
    column-fill: auto;

    box-sizing: border-box;
    scroll-behavior: smooth;

    /* PAGE SNAP (Snaps swipes directly to page columns) */
    scroll-snap-type: x mandatory;
    scroll-snap-stop: always;

    /* Hide scrollbars */
    scrollbar-width: none;
    -ms-overflow-style: none;
}

#reader-body::-webkit-scrollbar {
    display: none;
}

/* Enforce snap points and prevent paragraphs from breaking across pages */
#reader-body>* {
    scroll-snap-align: start;
    break-inside: avoid;
}

/* 4. FIXED BOTTOM NAVIGATION BAR */
.chapter-nav {
    flex-shrink: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    background-color: inherit;
    border-top: 1px solid rgba(128, 128, 128, 0.2);
    box-sizing: border-box;
}

/* 5. SMALL SCREEN FONT SCALING */
@media (max-height: 667px) {
    #reader-body p {
        font-size: 0.95rem;
        line-height: 1.5;
    }
}

/* 4. DARK MODE SUPPORT OVERRIDES */
body.dark-mode #reader-view,
body.dark,
[data-theme="dark"] #reader-view,
body.dark-mode .chapter-nav,
[data-theme="dark"] .chapter-nav {
    background-color: #121212 !important;
    /* Dark mode background */
    color: #ffffff !important;
    /* Dark mode text */
}

#reader-subscribe-btn {
    transition: transform 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease;
}

#reader-subscribe-btn:hover {
    background-color: #0056b3 !important;
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 123, 255, 0.4) !important;
}

#reader-subscribe-btn:active {
    transform: translateY(0);
}

.menu-toggle-btn {
    background: transparent;
    border: none;
    color: inherit;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 8px 12px;
    border-radius: 4px;
}

body.light-mode .menu-toggle-btn,
[data-theme="light"] .menu-toggle-btn {
    color: #121212;
}

/* Backdrop Overlay */
.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(2px);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    z-index: 998;
}

.sidebar-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* Side Drawer Styling */
.sidebar-drawer {
    position: fixed;
    top: 0;
    left: -290px;
    width: 280px;
    height: 100vh;
    background-color: #12121a;
    color: #ffffff;
    box-shadow: 4px 0 16px rgba(0, 0, 0, 0.6);
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 999;
    display: flex;
    flex-direction: column;
    padding: 1.5rem 1.2rem;
}

.sidebar-drawer.open {
    left: 0;
}

.drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    margin-bottom: 1.5rem;
}

.user-email-display {
    font-size: 0.9rem;
    font-weight: 600;
    color: #e0e0e0;
    word-break: break-all;
}

.close-drawer-btn {
    background: none;
    border: none;
    color: #888;
    font-size: 1.8rem;
    cursor: pointer;
    line-height: 1;
}

/* Default Blue Subscribe Button */
.drawer-sub-btn {
    width: 100%;
    padding: 14px 18px;
    font-size: 1rem;
    font-weight: 700;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    background-color: #007bff;
    /* Sleek Blue */
    color: #ffffff;
    transition: all 0.25s ease;
    box-shadow: 0 4px 12px rgba(0, 123, 255, 0.25);
}

.drawer-sub-btn:hover {
    background-color: #0056b3;
}

/* Gold Premium User State */
.drawer-sub-btn.premium-user {
    background: linear-gradient(135deg, #d4af37 0%, #f3e5ab 50%, #aa771c 100%);
    color: #111111;
    font-weight: 800;
    cursor: default;
    box-shadow: 0 0 14px rgba(212, 175, 55, 0.4);
}

.drawer-divider {
    border: none;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    margin: 1.5rem 0;
}

.drawer-menu {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.drawer-item {
    color: #bbbbbb;
    text-decoration: none;
    font-size: 0.95rem;
    padding: 10px 12px;
    border-radius: 6px;
    transition: background 0.2s ease, color 0.2s ease;
}

.drawer-item:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #ffffff;
}

/* Responsive Mobile Header Fix */
@media (max-width: 650px) {
    .navbar {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        justify-content: space-between;
        padding: 10px 14px;
    }

    /* Row 1 Layout */
    .menu-toggle-btn {
        flex-shrink: 0;
    }

    .logo {
        font-size: 3rem;
        margin-right: auto;
        /* Pushes Theme Toggle to far right */
        padding-left: 8px;
    }

    #theme-toggle {
        flex-shrink: 0;
        margin-left: auto;
        /* Ensures theme toggle stays pinned right */
    }

    /* Row 2: Category Bar with Horizontal Swipe */
    .nav-links {
        width: 100%;
        display: flex;
        overflow-x: auto;
        white-space: nowrap;
        gap: 8px;
        padding-top: 10px;
        margin-top: 6px;
        border-top: 1px solid rgba(255, 255, 255, 0.08);
        -webkit-overflow-scrolling: touch;
        /* Smooth iOS swipe */
        scrollbar-width: none;
        /* Hide Firefox scrollbar */
    }

    .nav-links::-webkit-scrollbar {
        display: none;
        /* Hide Chrome/Safari scrollbar */
    }

    .nav-btn {
        flex-shrink: 0;
        /* Prevents buttons from squishing */
        padding: 6px 14px;
        font-size: 0.85rem;
    }
}

/* Release Schedule End Card */
.chapter-end-card {
    margin: 3rem auto 2rem;
    padding: 1.8rem 1.5rem;
    background: linear-gradient(145deg, #181824 0%, #101018 100%);
    border: 1px solid rgba(212, 175, 55, 0.25);
    /* Subtle gold border */
    border-radius: 12px;
    text-align: center;
    max-width: 520px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.chapter-end-card .end-icon {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    display: block;
}

.chapter-end-card h3 {
    font-size: 1.2rem;
    color: #f3e5ab;
    /* Soft gold accent */
    margin-bottom: 0.4rem;
}

.chapter-end-card p {
    font-size: 0.95rem;
    color: #cccccc;
    line-height: 1.5;
    margin-bottom: 1rem;
}

.chapter-end-card .schedule-badge {
    display: inline-block;
    padding: 6px 14px;
    background: rgba(212, 175, 55, 0.12);
    color: #d4af37;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    letter-spacing: 0.5px;
}

/* Chapter Epigraph & Scene Break Styling */
.chapter-epigraph {
    font-style: italic;
    font-size: 1.05rem;
    color: #d4af37;
    /* Gold accent */
    border-left: 3px solid #d4af37;
    padding-left: 1rem;
    margin-bottom: 2rem;
    line-height: 1.6;
}

.chapter-divider {
    border: none;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(212, 175, 55, 0.4), transparent);
    margin: 2.5rem 0;
}

/* Chapter Boundary Markers */
.chapter-marker {
    display: flex;
    align-items: center;
    text-align: center;
    margin: 2.5rem 0;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 2.5px;
}

.chapter-marker::before,
.chapter-marker::after {
    content: '';
    flex: 1;
    border-bottom: 1px dashed rgba(212, 175, 55, 0.35);
    /* Subtle gold dashed line */
}

.chapter-marker::before {
    margin-right: 1.2rem;
}

.chapter-marker::after {
    margin-left: 1.2rem;
}

/* Start Marker Accent */
.chapter-marker.chapter-start {
    color: #d4af37;
    /* Soft gold text */
    margin-top: 1rem;
    margin-bottom: 2rem;
}

/* End Marker Accent */
.chapter-marker.chapter-end {
    color: #8a8a9e;
    /* Muted slate text */
    margin-top: 3.5rem;
    margin-bottom: 2rem;
}

.italics {
    font-style: italic;
}