/* =========================================
   CORE FOUNDATION & VARIABLES
   ========================================= */
:root {
    /* Colors */
    --bg-dark: #121212;
    --bg-surface: #1e1e1e;
    --bg-surface-hover: #2a2a2a;
    
    --text-primary: #ffffff;
    --text-primary-rgb: 255, 255, 255; /* Added for transparent borders */
    --text-secondary: #a0a0a0;
    
    /* Aliases for Reader Styles */
    --text: var(--text-primary); 
    --bg: var(--bg-dark);

    --accent: #ffb703; 
    
    /* Typography */
    --font-family-base: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    --font-size-base: 16px;
    --line-height-base: 1.5;
    
    /* Layout & Structure */
    --sidebar-width: 260px;
    --player-height: 80px;
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-pill: 50px;
    --transition-speed: 0.2s;
}

html {
    scroll-behavior: smooth;
}

/* =========================================
   GLOBAL RESETS
   ========================================= */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-primary);
    font-family: var(--font-family-base);
    font-size: var(--font-size-base);
    line-height: var(--line-height-base);
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

/* Core Media Handling: Ensures images/videos never break out of containers */
img, picture, video, canvas, svg, iframe {
    display: block;
    max-width: 100%;
    height: auto;
    object-fit: cover;
}

/* =========================================
   SIDEBAR
   ========================================= */
.sidebar {
    width: var(--sidebar-width);
    height: 100vh;
    background-color: var(--bg-surface);
    position: fixed;
    top: 0;
    left: 0;
    display: flex;
    flex-direction: column;
    padding: 20px;
    transition: transform 0.3s ease;
    z-index: 100;
    overflow: hidden; /* Hide main scrollbar, we will scroll the inner div */
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
}

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

/* Scrollable area for the sidebar */
.sidebar-scroll-area {
    flex: 1;
    overflow-y: auto;
    padding-right: 5px; /* Prevent scrollbar from overlapping text */
}

/* Custom Webkit Scrollbar for Sidebar */
.sidebar-scroll-area::-webkit-scrollbar {
    width: 4px;
}
.sidebar-scroll-area::-webkit-scrollbar-track {
    background: transparent;
}
.sidebar-scroll-area::-webkit-scrollbar-thumb {
    background: #333;
    border-radius: var(--radius-pill);
}
.sidebar-scroll-area::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Section labels inside the sidebar */
.nav-label {
    display: block;
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--text-secondary);
    letter-spacing: 1px;
    margin: 20px 0 10px 12px;
    font-weight: 700;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: var(--radius-md);
    margin-bottom: 5px;
    font-weight: 500;
    transition: background var(--transition-speed), color var(--transition-speed);
}

.sidebar-nav a:hover, .sidebar-nav a.active {
    background-color: rgba(255, 183, 3, 0.1);
    color: var(--accent);
}

.sidebar-nav i {
    font-size: 1.25rem;
}

.nav-divider {
    border: none;
    border-top: 1px solid #333;
    margin: 15px 0;
}

/* Sidebar Legal/Policy Footer */
.sidebar-footer {
    margin-top: 40px;
    margin-bottom: 20px;
    padding: 0 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 12px 15px;
}

.sidebar-footer a {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-decoration: none;
    transition: color var(--transition-speed);
}

.sidebar-footer a:hover {
    color: var(--accent);
    text-decoration: underline;
}

.sidebar-footer .copyright {
    font-size: 0.75rem;
    color: #555;
    width: 100%;
    margin-top: 10px;
}

/* =========================================
   MAIN CONTENT & HEADER
   ========================================= */
.main-content {
    margin-left: var(--sidebar-width);
    padding: 20px;
    padding-bottom: calc(var(--player-height) + 40px);
    transition: margin-left 0.3s ease;
}

.top-header {
    display: flex;
    align-items: center;
    gap: 20px;
    margin-bottom: 30px;
}

/* End-to-End Search Bar */
.search-bar {
    background-color: var(--bg-surface);
    border-radius: var(--radius-pill);
    padding: 12px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
}

.search-bar input {
    background: transparent;
    border: none;
    color: var(--text-primary);
    outline: none;
    width: 100%;
    font-family: inherit;
    font-size: 1rem;
}

.search-bar input::placeholder {
    color: var(--text-secondary);
}

.search-bar i {
    color: var(--text-secondary);
    font-size: 1.2rem;
}

/* =========================================
   MEDIA CARDS (NOVELS, AUDIO, VIDEO)
   ========================================= */
.content-section {
    margin-bottom: 40px;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 20px;
}

.section-header h2 {
    margin-bottom: 0;
    font-size: 1.5rem;
    font-weight: 700;
}

.see-all {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    transition: color var(--transition-speed);
}

.see-all i {
    font-size: 1.2rem;
}

.see-all:hover {
    color: var(--accent);
}

.media-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 24px;
}

.video-grid {
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
}

.card {
    cursor: pointer;
    transition: transform var(--transition-speed);
}

.card:hover {
    transform: translateY(-5px);
}

.card-media {
    background-color: var(--bg-surface-hover);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    color: #444;
    margin-bottom: 12px;
    overflow: hidden;
}

.placeholder-media {
    aspect-ratio: 2 / 3;
}

.placeholder-media.video-ratio {
    aspect-ratio: 16 / 9;
}

.card h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card p {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* =========================================
   BOTTOM PLAYER (Perfectly Centered Layout)
   ========================================= */
.bottom-player {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: var(--player-height);
    background-color: #181818;
    border-top: 1px solid #282828;
    /* CHANGED: Grid makes sure the middle section is ALWAYS dead center */
    display: grid;
    grid-template-columns: 1fr auto 1fr; 
    align-items: center;
    padding: 0 20px;
    z-index: 200;
    transition: opacity 0.3s ease, height 0.3s ease; /* Smooth hide/show */
}

/* 1. LEFT COLUMN: Info */
.player-info {
    display: flex;
    align-items: center;
    gap: 15px;
    min-width: 0; /* Prevents long titles from blowing out the grid */
}

.player-thumb {
    width: 56px;
    height: 56px;
    min-width: 56px; /* Prevents squishing */
    background-color: var(--bg-surface-hover);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    overflow: hidden;
}

.player-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.player-text {
    min-width: 0; 
    /* Allows the text to shrink and truncate instead of pushing the center controls */
}

.player-text h4 {
    font-size: 0.95rem;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.player-text p {
    font-size: 0.8rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* 2. CENTER COLUMN: Play Controls */
.player-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 24px;
}

/* 3. RIGHT COLUMN: Tools (Volume, Expand, etc.) */
.player-tools {
    display: flex;
    align-items: center;
    justify-content: flex-end; /* Pushes tools to the far right */
    gap: 15px;
}

/* Shared Button Styles */
.player-controls button, 
.player-tools button {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.5rem;
    cursor: pointer;
    transition: color var(--transition-speed), transform var(--transition-speed);
    display: flex;
    align-items: center;
    justify-content: center;
}

.player-controls button:hover, 
.player-tools button:hover {
    color: var(--accent);
    transform: scale(1.1);
}

.player-controls .play-btn {
    font-size: 2.5rem;
}

/* =========================================
   MOBILE RESPONSIVENESS
   ========================================= */
.mobile-only-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.5rem;
    cursor: pointer;
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.active {
        transform: translateX(0);
        box-shadow: 4px 0 15px rgba(0, 0, 0, 0.5);
    }

    .main-content {
        margin-left: 0;
    }

    .mobile-only-btn {
        display: block;
    }
    
    .player-tools {
        display: none; 
    }
    
    .player-info {
        width: 50%;
    }
    
    .search-bar {
        padding: 10px 15px;
    }
}

/* =========================================
   SETTINGS PAGE STYLES
   ========================================= */
.settings-container {
    max-width: 800px;
    margin: 0 auto;
}

.page-title h2 {
    font-size: 1.8rem;
    font-weight: 700;
}

.settings-group {
    background-color: var(--bg-surface);
    border-radius: var(--radius-md);
    padding: 24px;
    margin-bottom: 24px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.settings-group h3 {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.2rem;
    color: var(--accent);
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.setting-item:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.setting-info h4 {
    font-size: 1rem;
    margin-bottom: 4px;
}

.setting-info p {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.setting-control {
    background-color: var(--bg-dark);
    color: var(--text-primary);
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 10px 15px;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.9rem;
    cursor: pointer;
    outline: none;
}

.setting-control:focus {
    border-color: var(--accent);
}

.color-picker {
    display: flex;
    gap: 12px;
}

.color-btn {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    transition: transform var(--transition-speed);
}

.color-btn:hover {
    transform: scale(1.1);
}

.color-btn.active {
    border-color: #fff;
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
}

.setting-slider {
    flex: 1;
    margin: 0 20px;
    cursor: pointer;
    accent-color: var(--accent);
}

.setting-value {
    min-width: 40px;
    text-align: right;
    font-weight: bold;
    color: var(--accent);
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 26px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: #444;
    transition: .3s;
    border-radius: 34px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: .3s;
    border-radius: 50%;
}

.toggle-switch input:checked + .slider {
    background-color: var(--accent);
}

.toggle-switch input:checked + .slider:before {
    transform: translateX(24px);
}

.btn-danger {
    background-color: transparent;
    color: #ef4444;
    border: 1px solid #ef4444;
    padding: 10px 20px;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-weight: bold;
    transition: background-color var(--transition-speed), color var(--transition-speed);
}

.btn-danger:hover {
    background-color: #ef4444;
    color: white;
}

/* =========================================
   LIGHT MODE OVERRIDES
   ========================================= */
body.light-theme {
    --bg-dark: #f3f4f6;
    --bg-surface: #ffffff;
    --bg-surface-hover: #e5e7eb;
    --text-primary: #1f2937;
    --text-primary-rgb: 31, 41, 55;
    --text-secondary: #4b5563;
    
    --text: var(--text-primary);
    --bg: var(--bg-dark);
}
body.light-theme .nav-divider {
    border-top-color: #e5e7eb;
}
body.light-theme .bottom-player {
    background-color: #ffffff;
    border-top-color: #e5e7eb;
}

/* =========================================
   INFINITE SCROLL & LOADER STYLES
   ========================================= */
.scroll-sentinel {
    grid-column: 1 / -1; 
    padding: 40px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.scroll-sentinel.visible {
    opacity: 1;
}

.loader-spinner {
    width: 30px;
    height: 30px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top: 3px solid var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.scroll-sentinel p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
}

#discover-grid {
    min-height: 200px;
}

.search-sticky

.search-container {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.filter-bar {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    width: 100%;
    padding-bottom: 5px;
}

.filter-bar::-webkit-scrollbar {
    display: none; 
}

.filter-btn {
    background-color: var(--bg-surface);
    color: var(--text-secondary);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 8px 18px;
    border-radius: var(--radius-pill);
    cursor: pointer;
    white-space: nowrap;
    font-size: 0.85rem;
    font-weight: 600;
    transition: all 0.2s ease;
}

.filter-btn:hover {
    background-color: var(--bg-surface-hover);
}

.filter-btn.active {
    background-color: var(--accent);
    color: #000;
    border-color: var(--accent);
}

/* =========================================
   GENRE PAGE STYLES
   ========================================= */
.genre-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 20px;
}

.genre-box {
    background-color: var(--bg-surface); /* FIXED VARIABLE */
    aspect-ratio: 1 / 1;
    border-radius: var(--radius-md);
    padding: 20px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    cursor: pointer;
    transition: transform 0.2s ease, filter 0.2s ease;
    position: relative;
    overflow: hidden;
}

.genre-box:hover {
    transform: scale(1.03);
    filter: brightness(1.1);
}

.genre-box i {
    font-size: 3rem;
    align-self: flex-end;
    opacity: 0.3;
    position: absolute;
    bottom: -10px;
    right: -10px;
}

.genre-box span {
    font-size: 1.4rem;
    font-weight: 800;
    color: #fff;
    text-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.hidden { display: none !important; }

.back-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: 10px;
}

.back-btn:hover { color: var(--accent); }

/* Ebook Card Actions */
.card-actions {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 36px;
    background-color: var(--bg-surface-hover);
    color: var(--text-primary);
    border-radius: var(--radius-sm);
    text-decoration: none;
    transition: all 0.2s ease;
    font-size: 1.1rem;
}

.action-btn:hover:not(.disabled) {
    background-color: var(--accent);
    color: #000;
    transform: translateY(-2px);
}

.action-btn.disabled {
    opacity: 0.3;
    cursor: not-allowed;
    pointer-events: none;
    background-color: #111;
    color: var(--text-secondary);
}

.card-locked .card-media {
    filter: grayscale(1);
}

.lock-overlay {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    color: var(--accent);
}

.ebook-card .card-info h3 {
    margin-top: 10px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Audio Page Design Tweaks */
.audio-layout {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
}

.square-ratio {
    aspect-ratio: 1 / 1 !important; 
    border-radius: var(--radius-md);
    background: linear-gradient(145deg, #232323, #1a1a1a);
}

.audio-card-wide .card-media i {
    font-size: 4rem;
    color: rgba(255, 183, 3, 0.2); 
}

.audio-actions {
    grid-template-columns: 2fr 1fr 1fr 1fr; 
}

.audio-actions .action-btn:first-child:not(.disabled) {
    background-color: var(--accent);
    color: #000;
}

.audio-actions .action-btn:first-child:not(.disabled):hover {
    filter: brightness(1.2);
    transform: scale(1.05);
}

.audio-card-wide .card-info {
    text-align: center;
    margin-top: 12px;
}

.audio-card-wide h3 {
    font-size: 1rem;
    font-weight: 700;
}

/* Video Page Layout */
.video-layout-main {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); /* Wider than ebooks */
    gap: 25px;
    padding: 20px 0;
}

.video-ratio {
    aspect-ratio: 16 / 9 !important;
    position: relative;
    background-color: #000;
}

.play-overlay {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}
.play-overlay i {
    font-size: 3rem;
    color: var(--accent);
    filter: drop-shadow(0 0 10px rgba(0,0,0,0.5));
}

.video-card-wide:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3);
}
.video-card-wide .card-info h3 {
    font-size: 1.1rem;
    margin-top: 10px;
}

.video-card-wide .card-media.video-ratio {
    aspect-ratio: 16 / 9;
    width: 100%;
    position: relative;
    background: #000;
}

.video-card-wide .card-media img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.video-actions {
    display: grid;
    /* 5 Columns: Watch is wide (2.5fr), the 4 icons are equal squares (1fr) */
    grid-template-columns: 2.5fr 1fr 1fr 1fr 1fr; 
    gap: 8px;
    margin-top: auto;
}

/* Optional: Make the favorite button turn gold when hovered */
.video-actions .fav-btn:hover {
    background-color: rgba(255, 183, 3, 0.15) !important;
    color: var(--accent) !important;
}

.video-actions .action-btn:first-child {
    display: flex;
    gap: 8px;
    font-size: 0.9rem;
    font-weight: 700;
}

.video-actions .action-btn:first-child:not(.disabled) {
    background-color: var(--accent);
    color: #000;
}

.video-card-wide {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    overflow: hidden;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    border: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    flex-direction: column;
}

.video-card-wide .card-media i {
    color: rgba(255, 255, 255, 0.1);
}

/* Spotify Tracklist Style */
.playlist-header {
    display: flex;
    gap: 30px;
    padding: 40px 0;
    align-items: flex-end;
}

.playlist-img {
    width: 200px;
    height: 200px;
    background: linear-gradient(135deg, #444, #111);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 5rem;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}

.playlist-details .label {
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
}

.tracklist-container {
    margin-top: 20px;
}

.tracklist-header, .track-row {
    display: grid;
    grid-template-columns: 50px 2fr 1fr 50px;
    padding: 12px 20px;
    border-radius: 8px;
    align-items: center;
}

.tracklist-header {
    border-bottom: 1px solid rgba(255,255,255,0.1);
    color: var(--text-secondary);
    font-size: 0.8rem;
    text-transform: uppercase;
}

.track-row {
    cursor: pointer;
    transition: background 0.2s;
}

.track-row:hover {
    background-color: rgba(255,255,255,0.05);
}

.track-info {
    display: flex;
    flex-direction: column;
}

.track-name {
    font-weight: 600;
    color: var(--text-primary);
}

.track-meta {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.col-id { color: var(--text-secondary); }
.col-action { opacity: 0; transition: opacity 0.2s; color: var(--accent); }
.track-row:hover .col-action { opacity: 1; }

.category-tag {
    font-size: 0.7rem;
    color: var(--accent);
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 0.5px;
    margin-top: 5px;
    display: inline-block;
}

/* Table of Contents Layout */
.chapters-block {
    margin-top: 50px;
}

.chapters-block h3 {
    margin-bottom: 20px;
    font-size: 1.4rem;
    color: var(--text-secondary);
}

.details-chapter-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.detail-chapter-item {
    display: flex;
    align-items: center;
    padding: 18px 24px;
    background: rgba(255,255,255,0.03);
    border-radius: 12px;
    text-decoration: none;
    color: white;
    transition: all 0.2s ease;
}

.detail-chapter-item:hover {
    background: rgba(255,255,255,0.08);
    transform: translateX(8px);
}

.chap-num {
    font-weight: 800;
    color: var(--accent);
    margin-right: 20px;
    font-family: 'Courier New', Courier, monospace; 
    width: 20px;
}

.chap-name {
    flex-grow: 1;
    font-weight: 500;
}

/* ==========================================
   HANDWRITIUM READER: CHAPTER STYLES
   ========================================== */
.chapter-wrapper {
    max-width: 800px;
    margin: 0 auto;
    padding: 60px 20px;
    animation: fadeInPage 0.8s ease-in-out;
}

.chapter-heading {
    font-family: var(--font-family-base); 
    font-size: clamp(2rem, 5vw, 3rem);    
    font-weight: 800;
    text-align: center;
    margin-bottom: 80px;
    letter-spacing: -1.5px;
    color: var(--text);
    line-height: 1.1;
    position: relative;
}

.chapter-heading::after {
    content: '';
    display: block;
    width: 60px;
    height: 4px;
    background: var(--accent);
    margin: 25px auto 0;
    border-radius: 2px;
}

.chapter-body {
    font-family: "Georgia", "serif"; 
    font-size: 1.25rem;
    line-height: 1.8; 
    color: var(--text);
}

.chapter-body p {
    margin-bottom: 1.5em;
    text-align: justify;
    hyphens: auto;
}

.chapter-body p.drop-cap::first-letter {
    font-family: var(--font-family-base);
    float: left;
    font-size: 5rem;
    line-height: 0.85;
    padding-top: 10px;
    padding-right: 12px;
    padding-left: 4px;
    font-weight: 900;
    color: var(--accent);
    text-transform: uppercase;
}

/* Theme Specific Adjustments */
.dark-theme .chapter-body {
    color: rgba(255, 255, 255, 0.9);
    font-weight: 300;
}

.sepia-theme .chapter-body {
    color: #433422;
}
.sepia-theme .chapter-heading {
    color: #433422;
}

@keyframes fadeInPage {
    from { opacity: 0; transform: translateY(15px); }
    to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 600px) {
    .chapter-wrapper {
        padding: 40px 15px;
    }
    .chapter-body {
        font-size: 1.15rem;
        line-height: 1.7;
    }
    .chapter-body p.drop-cap::first-letter {
        font-size: 4rem;
    }
}

.chapter-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 80px;
    padding-top: 40px;
    border-top: 1px solid rgba(255,255,255,0.1);
}

.nav-btn {
    background: var(--accent);
    color: #000;
    padding: 12px 25px;
    border-radius: 8px;
    text-decoration: none;
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: 0.3s;
}

.nav-btn.disabled {
    background: #333;
    color: #666;
    pointer-events: none;
}

.page-count {
    font-family: var(--font-family-base);
    opacity: 0.5;
    font-weight: bold;
}

/* --- PREMIUM BACK TO TOP BUTTON --- */
.reader-footer {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 60px 0 100px; 
    gap: 30px;
}

.footer-divider {
    width: 80px;
    height: 1px;
    background: rgba(var(--text-primary-rgb), 0.2); /* FIXED VARIABLE */
    margin-bottom: 20px;
}

.end-marker {
    font-family: var(--font-family-base);
    text-transform: uppercase;
    letter-spacing: 3px;
    font-size: 0.8rem;
    opacity: 0.4;
}

.btt-button {
    background: transparent;
    border: 1px solid var(--accent);
    color: var(--accent);
    padding: 12px 24px;
    border-radius: 50px;
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-family: var(--font-family-base);
    font-weight: 700;
    font-size: 0.9rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 10; 
}

.btt-button i {
    font-size: 1.2rem;
}

.btt-button:hover {
    background: var(--accent);
    color: #000; 
    transform: translateY(-5px);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
}

.btt-button span {
    text-transform: uppercase;
    letter-spacing: 1px;
}

.pb-spacer {
    height: 120px;
}

/* =========================================
   RAW HTML READER STYLES (For directly loaded content)
   ========================================= */

/* Center the text and apply the classic book font */
#full-story-content {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    font-family: "Georgia", "Times New Roman", serif;
    font-size: 1.25rem;
    line-height: 1.8;
    color: var(--text);
}

/* Style the big titles */
#full-story-content h1 {
    font-family: var(--font-family-base);
    font-size: clamp(2rem, 5vw, 3rem);
    font-weight: 800;
    text-align: center;
    margin-bottom: 50px;
    letter-spacing: -1.5px;
    line-height: 1.2;
    color: var(--text);
}

/* Style the chapter headers */
#full-story-content h2 {
    font-family: var(--font-family-base);
    font-size: 2rem;
    font-weight: 800;
    text-align: center;
    margin-top: 80px;
    margin-bottom: 40px;
    color: var(--text);
    position: relative;
}

/* Add the premium accent line under H2s */
#full-story-content h2::after {
    content: '';
    display: block;
    width: 60px;
    height: 4px;
    background: var(--accent);
    margin: 20px auto 0;
    border-radius: 2px;
}

/* Clean up paragraphs */
#full-story-content p {
    margin-bottom: 1.5em;
    text-align: justify;
    hyphens: auto;
}

/* Add a drop-cap to the very first paragraph after an H2 */
#full-story-content h2 + p::first-letter {
    font-family: var(--font-family-base);
    float: left;
    font-size: 4.5rem;
    line-height: 0.85;
    padding-top: 10px;
    padding-right: 12px;
    font-weight: 900;
    color: var(--accent);
}

/* Fix lists and links inside the raw text */
#full-story-content ol, 
#full-story-content ul {
    margin-bottom: 2em;
    padding-left: 40px;
}

#full-story-content li {
    margin-bottom: 10px;
}

#full-story-content a {
    color: var(--accent);
    text-decoration: none;
}
#full-story-content a:hover {
    text-decoration: underline;
}

/* =========================================
   READING PROGRESS BAR & LOADER
   ========================================= */

/* Fixed Progress Bar at the top of the screen */
.progress-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 4px;
    background: transparent;
    z-index: 3000; /* High z-index keeps it above the sidebar and ToC */
}

.progress-bar {
    height: 100%;
    background: var(--accent);
    width: 0%; /* Controlled by JavaScript */
    transition: width 0.1s ease-out;
    border-top-right-radius: 2px;
    border-bottom-right-radius: 2px;
    box-shadow: 0 0 10px rgba(255, 183, 3, 0.6); /* Adds a premium glow */
}

/* Beautiful Loading State */
.loader-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 15px;
    padding: 80px 20px;
    color: var(--text-secondary);
    animation: pulseLoader 2s infinite ease-in-out;
}

.loader-placeholder i {
    font-size: 2.5rem;
    color: var(--accent);
}

.loader-placeholder p {
    font-family: var(--font-family-base);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 2px;
    font-size: 0.9rem;
}

@keyframes pulseLoader {
    0%, 100% { opacity: 0.4; transform: scale(0.98); }
    50% { opacity: 1; transform: scale(1); }
}

/* =========================================
   HEADER BUTTONS (The Toggle Icon)
   ========================================= */
.nav-circle-btn {
    background-color: var(--bg-surface-hover);
    color: var(--text-primary);
    border: none;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.nav-circle-btn:hover {
    background-color: var(--accent);
    color: #000;
    transform: scale(1.1);
}

/* =========================================
   TABLE OF CONTENTS SIDEBAR (READER)
   ========================================= */

/* The Main Container */
.toc-sidebar {
    position: fixed;
    top: 0;
    right: 0;
    width: 320px;
    height: 100vh;
    background-color: var(--bg-surface);
    border-left: 1px solid rgba(var(--text-primary-rgb), 0.1);
    z-index: 4000; /* Extremely high to sit above everything */
    padding: 30px 20px;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
    box-shadow: -10px 0 30px rgba(0, 0, 0, 0.5); 
}

/* Hidden State (Slides it off the right edge) */
.toc-sidebar.hidden {
    transform: translateX(100%);
}

/* Header Area inside the ToC */
.toc-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid rgba(var(--text-primary-rgb), 0.1);
}

.toc-header h3 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 2px;
}

/* Close Button inside ToC */
#close-toc {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.8rem;
    cursor: pointer;
    transition: color 0.2s, transform 0.2s;
}

#close-toc:hover {
    color: var(--accent);
    transform: scale(1.1);
}

/* The List Items */
.toc-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.toc-list li {
    margin-bottom: 5px;
}

/* The Links inside the list */
.toc-list a {
    display: block;
    text-decoration: none;
    color: var(--text-secondary);
    font-size: 0.95rem;
    line-height: 1.5;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
    border-left: 2px solid transparent; 
}

/* Premium Hover Effect */
.toc-list a:hover {
    background-color: rgba(255, 183, 3, 0.05); 
    color: var(--text-primary);
    border-left: 2px solid var(--accent);
    padding-left: 16px; 
}

/* Custom Scrollbar for the ToC */
.toc-sidebar::-webkit-scrollbar {
    width: 4px;
}
.toc-sidebar::-webkit-scrollbar-track {
    background: transparent;
}
.toc-sidebar::-webkit-scrollbar-thumb {
    background: #444;
    border-radius: 50px;
}
.toc-sidebar::-webkit-scrollbar-thumb:hover {
    background: var(--accent);
}

/* Mobile Adjustments */
@media (max-width: 600px) {
    .toc-sidebar {
        width: 100%; 
    }
}



/* =========================================
   LEGAL DOCUMENTS (PRIVACY POLICY / TOS)
   ========================================= */

.legal-document {
    max-width: 800px;
    margin: 0 auto;
    background-color: var(--bg-surface);
    border-radius: var(--radius-md);
    padding: 40px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.document-header {
    border-bottom: 2px solid rgba(var(--text-primary-rgb), 0.1);
    padding-bottom: 20px;
    margin-bottom: 30px;
    text-align: center;
}

.document-header h1 {
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--text-primary);
    margin-bottom: 10px;
    letter-spacing: -0.5px;
}

.last-updated {
    color: var(--accent);
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.document-body {
    font-family: var(--font-family-base);
    color: var(--text-secondary);
    font-size: 1.05rem;
    line-height: 1.7;
}

.document-body h2 {
    color: var(--text-primary);
    font-size: 1.4rem;
    font-weight: 700;
    margin-top: 40px;
    margin-bottom: 15px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding-bottom: 8px;
}

.document-body p {
    margin-bottom: 20px;
}

.document-body strong {
    color: var(--text-primary);
    font-weight: 600;
}

.document-body ul {
    margin-bottom: 25px;
    padding-left: 20px;
    list-style-type: none;
}

.document-body ul li {
    position: relative;
    margin-bottom: 10px;
    padding-left: 15px;
}

.document-body ul li::before {
    content: "•";
    color: var(--accent);
    font-weight: bold;
    font-size: 1.2rem;
    position: absolute;
    left: 0;
    top: -2px;
}

.contact-card {
    background-color: var(--bg-dark);
    border-left: 4px solid var(--accent);
    padding: 20px;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    margin-top: 20px;
}

.contact-card p {
    margin-bottom: 8px;
    color: var(--text-primary);
}

.contact-card p:last-child {
    margin-bottom: 0;
}

.contact-card a {
    color: var(--accent);
    text-decoration: none;
    font-weight: bold;
    transition: color var(--transition-speed);
}

.contact-card a:hover {
    text-decoration: underline;
}

/* Mobile Adjustments for Legal Docs */
@media (max-width: 600px) {
    .legal-document {
        padding: 20px;
    }
    
    .document-header h1 {
        font-size: 2rem;
    }
    
    .document-body {
        font-size: 1rem;
    }
}