        /* Base theme variables */
        body {
            font-family: 'Inter', sans-serif;
            transition: background-color 0.3s ease, color 0.3s ease;
        }

        .serif,
        .font-serif {
            font-family: 'Playfair Display', serif;
        }

        /* Theme classes */
        body.theme-dark {
            background-color: #0f172a;
            color: #f8fafc;
        }

        body.theme-light {
            background-color: #fdfbf7;
            color: #1f2937;
        }

        body.theme-sepia {
            background-color: #f4ecd8;
            color: #433422;
        }

        /* Sidebar theming */
        body.theme-dark #sidebar {
            background-color: #0f172a;
            border-right: 1px solid rgba(255, 255, 255, 0.1);
        }

        body.theme-light #sidebar {
            background-color: #fdfbf7;
            border-right: 1px solid rgba(0, 0, 0, 0.1);
        }

        body.theme-sepia #sidebar {
            background-color: #f4ecd8;
            border-right: 1px solid rgba(0, 0, 0, 0.1);
        }

        /* Top navigation theming */
        body.theme-dark header {
            background-color: rgba(15, 23, 42, 0.9);
            border-bottom-color: rgba(255, 255, 255, 0.1);
        }

        body.theme-light header {
            background-color: rgba(253, 251, 247, 0.9);
            border-bottom-color: rgba(0, 0, 0, 0.1);
        }

        body.theme-sepia header {
            background-color: rgba(244, 236, 216, 0.9);
            border-bottom-color: rgba(0, 0, 0, 0.1);
        }

        /* Text content theming */
        body.theme-dark #chapter-content {
            color: #e2e8f0;
        }

        body.theme-light #chapter-content {
            color: #1f2937;
        }

        body.theme-sepia #chapter-content {
            color: #433422;
        }

        /* Drop cap (same amber for all themes) */
        #chapter-content.is-chapter p:first-of-type::first-letter {
            float: left;
            font-family: 'Playfair Display', serif;
            font-size: 4em;
            line-height: 0.8;
            padding-top: 0.1em;
            padding-right: 0.1em;
            font-weight: bold;
            color: #d4af37;
        }

        /* Paragraph styling */
        #chapter-content p {
            text-align: justify;
            text-indent: 1.5em;
            margin-bottom: 1em;
        }

        /* Force center alignment for all content inside the end page */
        #chapter-content .end-page-content,
        #chapter-content .end-page-content * {
            text-align: center !important;
        }

        /* Remove indentation from paragraphs on the end page */
        #chapter-content .end-page-content p {
            text-indent: 0 !important;
            margin-left: auto !important;
            margin-right: auto !important;
        }

        #chapter-content.is-chapter p:first-of-type {
            text-indent: 0;
        }

        /* Custom scrollbar */
        ::-webkit-scrollbar {
            width: 8px;
        }

        body.theme-dark ::-webkit-scrollbar-track {
            background: #1e293b;
        }

        body.theme-dark ::-webkit-scrollbar-thumb {
            background: #475569;
        }

        body.theme-dark ::-webkit-scrollbar-thumb:hover {
            background: #d4af37;
        }

        body.theme-light ::-webkit-scrollbar-track {
            background: #e5e7eb;
        }

        body.theme-light ::-webkit-scrollbar-thumb {
            background: #9ca3af;
        }

        body.theme-light ::-webkit-scrollbar-thumb:hover {
            background: #d4af37;
        }

        body.theme-sepia ::-webkit-scrollbar-track {
            background: #d1c5a9;
        }

        body.theme-sepia ::-webkit-scrollbar-thumb {
            background: #b89a6e;
        }

        body.theme-sepia ::-webkit-scrollbar-thumb:hover {
            background: #d4af37;
        }

        /* Progress bar */
        #progress-bar {
            background-color: #d4af37;
        }

        /* TOC items */
        .toc-item:hover {
            background-color: rgba(212, 175, 55, 0.1);
        }

        /* Mobile sidebar transition */
        #sidebar {
            transition: transform 0.3s ease-in-out;
        }

        @media (max-width: 768px) {
            #sidebar {
                transform: translateX(-100%);
            }

            #sidebar.open {
                transform: translateX(0);
            }

            body {
                overflow-x: hidden;
            }

            header {
                min-height: 52px;
            }

            header > div:nth-child(2) {
                flex-wrap: nowrap;
                align-items: center;
                min-height: 52px;
                height: 52px;
                padding-top: 0.25rem;
                padding-bottom: 0.25rem;
                gap: 0.25rem;
                overflow: visible;
            }

            header > div:nth-child(2) > div:first-child,
            header > div:nth-child(2) > div:last-child {
                min-width: 0;
                width: auto;
                flex-wrap: nowrap;
                align-items: center;
                gap: 0.25rem;
            }

            header > div:nth-child(2) > div:first-child {
                flex: 0 0 auto;
                max-width: 30px;
            }

            header > div:nth-child(2) > div:first-child a {
                gap: 0.15rem;
                padding: 0.25rem;
                max-width: 24px;
                overflow: hidden;
            }

            header > div:nth-child(2) > div:first-child a span {
                display: none;
            }

            header > div:nth-child(2) > div:last-child {
                justify-content: flex-end;
                gap: 0.1rem;
                flex: 1 1 auto;
                min-width: 0;
            }

            #book-title {
                max-width: 88px;
                min-width: 0;
                font-size: 0.82rem;
                line-height: 1.2;
                white-space: nowrap;
                overflow: hidden;
                text-overflow: ellipsis;
                flex-shrink: 1;
            }

            #open-sidebar {
                margin-right: 0;
                padding: 0.25rem;
            }

            button[aria-label="Share on WhatsApp"],
            button[aria-label="Bookmark this chapter"],
            #settings-btn {
                padding: 0.25rem 0.35rem;
                min-width: 0;
                display: inline-flex;
                align-items: center;
                justify-content: center;
            }

            button[aria-label="Share on WhatsApp"] span,
            button[aria-label="Bookmark this chapter"] span {
                display: none;
            }

            .settings-dropdown {
                right: 0;
                left: auto;
                width: min(90vw, 18rem);
            }

            article {
                padding-left: 1rem;
                padding-right: 1rem;
            }

            footer > div {
                flex-direction: column;
                align-items: stretch;
            }

            footer > div > * {
                width: 100%;
            }

            footer > div .flex.items-center.gap-4 {
                justify-content: center;
                flex-wrap: wrap;
            }
        }

        /* Settings dropdown */
        header {
            position: relative;
            z-index: 40;
            overflow: visible;
        }

        main {
            position: relative;
            z-index: 1;
            isolation: isolate;
            overflow: visible;
        }

        article {
            position: relative;
            z-index: 10;
        }

        #settings-btn {
            position: relative;
            z-index: 60;
        }

        #settings-menu.settings-dropdown {
            position: fixed !important;
            top: 4.5rem !important;
            right: 1rem !important;
            left: auto !important;
            z-index: 99999 !important;
            display: none;
            width: min(90vw, 18rem);
            max-height: calc(100vh - 5.5rem);
            overflow-y: auto;
            border-radius: 0.75rem;
            box-shadow: 0 16px 32px rgba(15, 23, 42, 0.28);
            pointer-events: auto;
        }

        body.theme-dark .settings-dropdown {
            background-color: #1e293b;
            border: 1px solid rgba(255, 255, 255, 0.1);
        }

        body.theme-light .settings-dropdown {
            background-color: white;
            border: 1px solid rgba(0, 0, 0, 0.1);
        }

        body.theme-sepia .settings-dropdown {
            background-color: #e8dfc7;
            border: 1px solid rgba(0, 0, 0, 0.1);
        }

        #settings-menu.settings-dropdown.active {
            display: block;
            animation: fadeIn 0.2s ease-out;
        }

        @keyframes fadeIn {
            from {
                opacity: 0;
                transform: translateY(-10px);
            }

            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        /* Premium cover overlay */
        .cover-overlay {
            background: linear-gradient(135deg, rgba(0, 0, 0, 0.4) 0%, rgba(0, 0, 0, 0.8) 100%);
        }

        body.theme-light .cover-overlay,
        body.theme-sepia .cover-overlay {
            background: linear-gradient(135deg, rgba(0, 0, 0, 0.2) 0%, rgba(0, 0, 0, 0.6) 100%);
        }

        /* End page premium style */
        .end-page {
            background: linear-gradient(135deg, rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.7));
        }

        body.theme-light .end-page,
        body.theme-sepia .end-page {
            background: linear-gradient(135deg, rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0.5));
        }

        /* ========== NEW: Background image layer ========== */
        .chapter-bg {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            z-index: -2;
            background-size: cover;
            background-position: center;
            transition: background-image 0.3s ease;
        }

        /* Overlay to keep text readable (adjust opacity as desired) */
        .chapter-bg::after {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0, 0, 0, 0.4);
            /* dark overlay for dark theme */
        }

        /* Light theme overlay is lighter */
        body.theme-light .chapter-bg::after {
            background-color: rgba(255, 255, 255, 0.5);
        }

        body.theme-sepia .chapter-bg::after {
            background-color: rgba(0, 0, 0, 0.3);
        }

        /* Remove any background from the chapter heading area */
        #article-header,
        #chapter-label,
        #chapter-title {
            background: transparent !important;
            box-shadow: none !important;
            border: none !important;
        }

        /* Ensure the parent container has no background either */
        #article-header {
            background-color: transparent;
        }

        #chapter-title {
            text-decoration: underline;
            text-underline-offset: 8px;
            text-decoration-thickness: 2px;
            text-decoration-color: #d4af37;
            /* amber accent to match your theme */
        }

        /* Force center alignment on the end page */
        #chapter-content .end-page-content {
            text-align: center !important;
        }

        #chapter-content:has(.end-page-content) {
            text-align: center;
        }

        /* Comments section styling (matches reader.html) */
        .comments-wrapper {
            display: none;
            margin-top: 3rem;
            padding-top: 2rem;
            border-top: 1px solid rgba(255, 255, 255, 0.1);
        }

        body.theme-light .comments-wrapper {
            border-top-color: rgba(0, 0, 0, 0.1);
        }

        .comments-wrapper h3 {
            font-size: 1.5rem;
            font-weight: bold;
            margin-bottom: 1rem;
            color: #d4af37;
        }

        .comments-wrapper input,
        .comments-wrapper textarea {
            width: 100%;
            padding: 0.5rem;
            margin-bottom: 0.75rem;
            border-radius: 0.5rem;
            background-color: rgba(255, 255, 255, 0.1);
            border: 1px solid rgba(255, 255, 255, 0.2);
            color: inherit;
        }

        body.theme-light .comments-wrapper input,
        body.theme-light .comments-wrapper textarea {
            background-color: rgba(0, 0, 0, 0.05);
            border-color: rgba(0, 0, 0, 0.2);
        }

        .comments-wrapper button {
            background-color: #d4af37;
            color: #0f172a;
            padding: 0.5rem 1.5rem;
            border-radius: 0.5rem;
            font-weight: bold;
            transition: all 0.2s;
        }

        .comments-wrapper button:hover {
            background-color: #e6c34a;
        }

        /* Rating stars styling */
        .rating-stars-small {
            display: inline-flex;
            gap: 4px;
            cursor: pointer;
            font-size: 1.2rem;
        }

        .rating-stars-small i {
            transition: color 0.2s;
        }

        .rating-stars-small i:hover,
        .rating-stars-small i.active {
            color: #fbbf24;
        }

        .total-stars {
            display: inline-flex;
            align-items: center;
            gap: 5px;
            margin-left: 15px;
            font-size: 0.9rem;
        }

        /* Background blur control */
        .chapter-bg {
            transform: scale(1.05);
            /* Prevents white edges when blurred */
            filter: blur(var(--bg-blur, 0px));
            transition: filter 0.2s ease;
        }

        .chapter-bg.no-blur {
            transform: scale(1);
            filter: blur(0) !important;
        }

        /* Eye icon inside password fields */
#loginModal .relative button,
#signupModal .relative button {
    background: transparent;
    border: none;
    padding: 0 8px;
    font-size: 1.1rem;
    cursor: pointer;
    z-index: 5;
}

#loginModal .relative button:hover,
#signupModal .relative button:hover {
    color: #d4af37; /* gold on hover */
}