/* ==========================================================================
   LUMINA LIBRARY & FLIPBOOK 3D - MODERN DESIGN SYSTEM & STYLES
   ========================================================================== */

:root {
    /* Color Palette */
    --bg-dark: #0a0c10;
    --bg-surface: #12161f;
    --bg-surface-elevated: #1a202c;
    --bg-glass: rgba(22, 28, 38, 0.75);
    
    --accent-gold: #e5b95c;
    --accent-gold-hover: #f5cc70;
    --accent-gold-glow: rgba(229, 185, 92, 0.3);
    --accent-blue: #3b82f6;
    
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border-color: rgba(255, 255, 255, 0.08);
    --border-gold: rgba(229, 185, 92, 0.25);

    /* Fonts */
    --font-heading: 'Cormorant Garamond', Georgia, serif;
    --font-ui: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;

    /* Shadow & Effects */
    --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.6);
    --shadow-gold: 0 0 20px rgba(229, 185, 92, 0.25);
    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --radius-full: 9999px;
    --transition-fast: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-normal: 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Light Theme Override */
body.theme-light {
    --bg-dark: #f1f5f9;
    --bg-surface: #ffffff;
    --bg-surface-elevated: #e2e8f0;
    --bg-glass: rgba(255, 255, 255, 0.85);
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #64748b;
    --border-color: rgba(0, 0, 0, 0.08);
    --border-gold: rgba(229, 185, 92, 0.5);
}

/* Reset & Global */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-ui);
    background-color: var(--bg-dark);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    line-height: 1.5;
}

button, input, select, textarea {
    font-family: inherit;
    color: inherit;
}

button {
    cursor: pointer;
    border: none;
    background: none;
    outline: none;
}

/* Utility Helpers */
.text-gold { color: var(--accent-gold); }
.hidden { display: none !important; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    font-size: 0.92rem;
    font-weight: 600;
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
}

.btn-primary {
    background: linear-gradient(135deg, #d4af37, #ab7d1c);
    color: #0d0f14;
    box-shadow: 0 4px 15px var(--accent-gold-glow);
}

.btn-primary:hover {
    background: linear-gradient(135deg, #f3c748, #c49226);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px var(--accent-gold-glow);
}

.btn-secondary {
    background: var(--bg-surface-elevated);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--text-secondary);
}

.btn.icon-only {
    width: 42px;
    height: 42px;
    padding: 0;
    border-radius: var(--radius-full);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.82rem;
    border-radius: var(--radius-sm);
}

.btn-text {
    color: var(--accent-gold);
    text-decoration: underline;
    font-size: 0.85rem;
}

/* ==========================================================================
   NAVIGATION BAR
   ========================================================================== */

.navbar {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--bg-glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border-color);
    padding: 12px 24px;
}

.nav-container {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 14px;
}

.brand-icon {
    font-size: 1.8rem;
    color: var(--accent-gold);
    filter: drop-shadow(0 0 10px var(--accent-gold-glow));
}

.brand-name {
    display: block;
    font-family: var(--font-heading);
    font-size: 1.7rem;
    font-weight: 700;
    line-height: 1;
    letter-spacing: 0.5px;
    background: linear-gradient(135deg, #fff 30%, var(--accent-gold));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.brand-sub {
    font-size: 0.72rem;
    color: var(--text-secondary);
    letter-spacing: 1.5px;
    text-transform: uppercase;
}

/* Search Box */
.search-box {
    position: relative;
    flex: 1;
    max-width: 500px;
}

.search-icon {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

.search-box input {
    width: 100%;
    padding: 10px 42px;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-full);
    color: var(--text-primary);
    font-size: 0.9rem;
    transition: all var(--transition-fast);
}

.search-box input:focus {
    border-color: var(--accent-gold);
    box-shadow: 0 0 0 3px var(--accent-gold-glow);
    outline: none;
}

.clear-search-btn {
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    display: none;
}

.search-box input:not(:placeholder-shown) ~ .clear-search-btn {
    display: block;
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* ==========================================================================
   AMBIENCE AUDIO PANEL
   ========================================================================== */

.ambience-panel {
    position: fixed;
    top: 75px;
    right: 24px;
    width: 320px;
    background: var(--bg-surface);
    border: 1px solid var(--border-gold);
    border-radius: var(--radius-lg);
    padding: 20px;
    box-shadow: var(--shadow-lg), var(--shadow-gold);
    z-index: 120;
    display: none;
    animation: fadeInDown 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.ambience-panel.active {
    display: block;
}

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

.ambience-header h3 {
    font-size: 1rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--accent-gold);
}

.close-panel-btn {
    color: var(--text-muted);
}
.close-panel-btn:hover { color: var(--text-primary); }

.ambience-tracks {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 16px;
}

.track-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
}

.track-card:hover {
    border-color: var(--border-gold);
    background: rgba(255, 255, 255, 0.06);
}

.track-card.playing {
    border-color: var(--accent-gold);
    background: rgba(229, 185, 92, 0.1);
}

.track-icon {
    font-size: 1.2rem;
    color: var(--accent-gold);
    width: 24px;
    text-align: center;
}

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

.track-name {
    font-size: 0.88rem;
    font-weight: 600;
}

.track-desc {
    font-size: 0.72rem;
    color: var(--text-muted);
}

.track-play-btn {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    background: var(--bg-surface-elevated);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent-gold);
    font-size: 0.8rem;
}

.track-card.playing .track-play-btn {
    background: var(--accent-gold);
    color: var(--bg-dark);
}

.ambience-volume-box {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
    color: var(--text-secondary);
}

.ambience-volume-box input[type="range"] {
    flex: 1;
    accent-color: var(--accent-gold);
}

/* ==========================================================================
   HERO SECTION & STATS
   ========================================================================== */

.app-main {
    max-width: 1400px;
    margin: 0 auto;
    padding: 30px 24px 80px;
}

.hero-section {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 30px;
    margin-bottom: 35px;
    padding: 30px;
    background: radial-gradient(circle at top left, rgba(229, 185, 92, 0.12), transparent 60%), var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
}

.hero-title {
    font-family: var(--font-heading);
    font-size: 2.3rem;
    font-weight: 700;
    margin-bottom: 8px;
    letter-spacing: -0.5px;
}

.hero-subtitle {
    color: var(--text-secondary);
    font-size: 0.95rem;
    max-width: 600px;
}

.stats-row {
    display: flex;
    gap: 16px;
}

.stat-card {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px 20px;
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    min-width: 170px;
}

.stat-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-sm);
    background: rgba(229, 185, 92, 0.15);
    color: var(--accent-gold);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

.stat-meta {
    display: flex;
    flex-direction: column;
}

.stat-value {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text-primary);
}

.stat-label {
    font-size: 0.78rem;
    color: var(--text-secondary);
}

/* ==========================================================================
   FILTER TABS & CONTROLS
   ========================================================================== */

.filter-section {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 30px;
    flex-wrap: wrap;
}

.category-tabs {
    display: flex;
    align-items: center;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 4px;
}

.tab-btn {
    padding: 8px 18px;
    font-size: 0.88rem;
    font-weight: 500;
    border-radius: var(--radius-full);
    background: var(--bg-surface);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    white-space: nowrap;
    transition: all var(--transition-fast);
}

.tab-btn:hover {
    color: var(--text-primary);
    border-color: var(--text-secondary);
}

.tab-btn.active {
    background: var(--accent-gold);
    color: #0d0f14;
    font-weight: 600;
    border-color: var(--accent-gold);
    box-shadow: 0 4px 12px var(--accent-gold-glow);
}

.view-switchers {
    display: flex;
    gap: 4px;
    background: var(--bg-surface);
    padding: 4px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

.view-btn {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.view-btn.active {
    background: var(--bg-surface-elevated);
    color: var(--accent-gold);
}

/* ==========================================================================
   LIBRARY CONTAINER: GRID MODE & 3D BOOKSHELF MODE
   ========================================================================== */

.library-container {
    min-height: 400px;
}

/* GRID MODE */
.library-container.grid-mode {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 28px;
}

.book-card {
    position: relative;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: all var(--transition-normal);
    cursor: pointer;
}

.book-card:hover {
    transform: translateY(-8px) scale(1.02);
    border-color: var(--border-gold);
    box-shadow: var(--shadow-lg), var(--shadow-gold);
}

.book-cover-wrapper {
    position: relative;
    width: 100%;
    aspect-ratio: 3 / 4;
    background: #181d28;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.book-cover-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.5s ease;
}

.book-card:hover .book-cover-img {
    transform: scale(1.05);
}

.book-badge {
    position: absolute;
    top: 10px;
    left: 10px;
    padding: 4px 10px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-radius: var(--radius-sm);
    background: rgba(10, 12, 16, 0.85);
    backdrop-filter: blur(4px);
    color: var(--accent-gold);
    border: 1px solid var(--border-gold);
}

.book-fav-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    background: rgba(10, 12, 16, 0.7);
    backdrop-filter: blur(4px);
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.book-fav-btn:hover, .book-fav-btn.is-fav {
    color: #f39c12;
    background: rgba(10, 12, 16, 0.9);
}

.book-overlay-read {
    position: absolute;
    inset: 0;
    background: rgba(10, 12, 16, 0.7);
    backdrop-filter: blur(2px);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.book-card:hover .book-overlay-read {
    opacity: 1;
}

.btn-read-hover {
    padding: 10px 18px;
    background: var(--accent-gold);
    color: #000;
    font-weight: 700;
    border-radius: var(--radius-full);
    font-size: 0.85rem;
    box-shadow: 0 4px 15px rgba(229, 185, 92, 0.5);
}

.book-info {
    padding: 16px;
    display: flex;
    flex-direction: column;
    flex: 1;
}

.book-title {
    font-family: var(--font-heading);
    font-size: 1.15rem;
    font-weight: 700;
    line-height: 1.3;
    margin-bottom: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.book-author {
    font-size: 0.82rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.book-meta-footer {
    margin-top: auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.76rem;
    color: var(--text-muted);
    padding-top: 8px;
    border-top: 1px solid var(--border-color);
}

/* 3D BOOKSHELF MODE */
.library-container.shelf-mode {
    display: flex;
    flex-direction: column;
    gap: 50px;
    padding: 20px 0;
}

.shelf-row {
    position: relative;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.02) 0%, rgba(30, 20, 10, 0.4) 100%);
    border-bottom: 16px solid #4a3319;
    box-shadow: 0 12px 25px rgba(0, 0, 0, 0.8);
    border-radius: 4px;
    padding: 20px 30px 10px;
    display: flex;
    align-items: flex-end;
    gap: 30px;
    overflow-x: auto;
    perspective: 1000px;
}

.shelf-row::after {
    content: '';
    position: absolute;
    bottom: -16px;
    left: 0;
    right: 0;
    height: 6px;
    background: #2d1e0f;
}

.shelf-book {
    position: relative;
    width: 140px;
    aspect-ratio: 3 / 4.2;
    background: #1e2533;
    border-radius: 4px 8px 8px 4px;
    box-shadow: -6px 0 12px rgba(0, 0, 0, 0.6), 4px 4px 10px rgba(0, 0, 0, 0.5);
    transform-style: preserve-3d;
    transform: rotateY(-15deg);
    transition: all 0.3s ease;
    cursor: pointer;
    flex-shrink: 0;
}

.shelf-book:hover {
    transform: rotateY(0deg) translateY(-15deg) scale(1.1);
    box-shadow: 0 15px 30px rgba(0, 0, 0, 0.9), var(--shadow-gold);
    z-index: 10;
}

.shelf-book-spine {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 16px;
    background: linear-gradient(90deg, rgba(255,255,255,0.3) 0%, rgba(0,0,0,0.4) 100%);
    border-radius: 4px 0 0 4px;
    z-index: 2;
}

.shelf-book-cover {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 4px 8px 8px 4px;
}

/* Loading & Empty State */
.loading-spinner, .empty-state {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px 20px;
    text-align: center;
    color: var(--text-secondary);
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border-color);
    border-top-color: var(--accent-gold);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
}

@keyframes spin { to { transform: rotate(360deg); } }

.empty-icon {
    font-size: 3.5rem;
    color: var(--text-muted);
    margin-bottom: 16px;
}

/* ==========================================================================
   FULLSCREEN FLIPBOOK READER MODAL
   ========================================================================== */

.reader-modal {
    position: fixed;
    inset: 0;
    background: #080a0f;
    z-index: 1000;
    display: none;
    flex-direction: column;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.reader-modal.active {
    display: flex;
    opacity: 1;
}

/* Reader Header Bar */
.reader-header {
    height: 60px;
    background: #11151f;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    z-index: 10;
}

.reader-book-info {
    display: flex;
    align-items: center;
    gap: 16px;
}

.reader-back-btn {
    width: 38px;
    height: 38px;
    border-radius: var(--radius-full);
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.reader-back-btn:hover {
    background: var(--accent-gold);
    color: #000;
}

.reader-book-title {
    font-family: var(--font-heading);
    font-size: 1.25rem;
    font-weight: 700;
    line-height: 1.1;
    color: var(--text-primary);
}

.reader-book-author {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* Central Toolbar */
.reader-toolbar {
    display: flex;
    align-items: center;
    gap: 6px;
    background: #1a202c;
    padding: 4px 12px;
    border-radius: var(--radius-full);
    border: 1px solid var(--border-color);
}

.tool-btn {
    width: 34px;
    height: 34px;
    border-radius: var(--radius-full);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    transition: all var(--transition-fast);
}

.tool-btn:hover, .tool-btn.active {
    color: var(--accent-gold);
    background: rgba(255, 255, 255, 0.08);
}

.toolbar-divider {
    width: 1px;
    height: 18px;
    background: var(--border-color);
    margin: 0 4px;
}

.zoom-level {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-primary);
    min-width: 44px;
    text-align: center;
}

/* Reader Actions Right */
.reader-actions {
    display: flex;
    align-items: center;
    gap: 14px;
}

.reader-theme-picker {
    display: flex;
    gap: 6px;
    background: #1a202c;
    padding: 4px;
    border-radius: var(--radius-full);
}

.theme-chip {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 2px solid transparent;
}

.theme-chip.active {
    border-color: var(--accent-gold);
}

.theme-paper { background: #fdfbf7; }
.theme-sepia { background: #f4ecd8; }
.theme-darkness { background: #181c24; }

/* Sidebar Drawer */
.reader-sidebar {
    position: absolute;
    left: 0;
    top: 60px;
    bottom: 50px;
    width: 320px;
    background: #11151f;
    border-right: 1px solid var(--border-color);
    z-index: 20;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
}

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

.sidebar-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
}

.s-tab {
    flex: 1;
    padding: 12px 4px;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 2px solid transparent;
}

.s-tab.active {
    color: var(--accent-gold);
    border-bottom-color: var(--accent-gold);
}

.sidebar-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.side-panel {
    display: none;
}
.side-panel.active { display: block; }

/* Thumbnails Grid */
#panelThumbs {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.thumb-item {
    cursor: pointer;
    border: 2px solid transparent;
    border-radius: var(--radius-sm);
    overflow: hidden;
    transition: all var(--transition-fast);
    background: #1a202c;
    text-align: center;
}

.thumb-item:hover, .thumb-item.active {
    border-color: var(--accent-gold);
}

.thumb-img {
    width: 100%;
    aspect-ratio: 3 / 4;
    object-fit: cover;
    display: block;
}

.thumb-label {
    font-size: 0.72rem;
    padding: 4px;
    color: var(--text-secondary);
}

/* Notes Form */
.notes-form {
    margin-bottom: 20px;
}

.notes-form textarea {
    width: 100%;
    background: #1a202c;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 10px;
    color: #fff;
    font-size: 0.85rem;
    resize: vertical;
    margin-bottom: 10px;
}

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

.note-card {
    background: #1a202c;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    border-left: 3px solid var(--accent-gold);
}

.note-page-tag {
    font-size: 0.72rem;
    color: var(--accent-gold);
    font-weight: 700;
    margin-bottom: 4px;
}

/* ==========================================================================
   FLIPBOOK VIEWPORT & 3D FLIP ENGINE
   ========================================================================== */

.flipbook-viewport {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: radial-gradient(circle, rgba(30, 38, 55, 0.6) 0%, rgba(8, 10, 15, 1) 100%);
    perspective: 2200px;
}

.nav-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 50px;
    height: 50px;
    border-radius: var(--radius-full);
    background: rgba(26, 32, 44, 0.8);
    backdrop-filter: blur(8px);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 15;
    transition: all var(--transition-fast);
}

.nav-arrow:hover {
    background: var(--accent-gold);
    color: #000;
    box-shadow: 0 0 20px var(--accent-gold-glow);
}

.prev-page-btn { left: 24px; }
.next-page-btn { right: 24px; }

.flipbook-wrapper {
    position: relative;
    transition: transform 0.2s ease-out;
}

/* 3D Flipbook Main Container */
.flipbook {
    position: relative;
    width: 800px;
    height: 560px;
    transform-style: preserve-3d;
    transition: width 0.3s ease, height 0.3s ease;
}

.flipbook.single-page {
    width: 420px;
}

/* Page Card Structure */
.fb-page {
    position: absolute;
    width: 50%;
    height: 100%;
    top: 0;
    background: #ffffff;
    box-shadow: 0 5px 25px rgba(0, 0, 0, 0.3);
    transform-style: preserve-3d;
    transform-origin: left center;
    transition: transform 0.6s cubic-bezier(0.645, 0.045, 0.355, 1);
    overflow: hidden;
    user-select: none;
}

.flipbook.single-page .fb-page {
    width: 100%;
}

.fb-page.left-page {
    left: 0;
    transform-origin: right center;
    border-radius: 6px 0 0 6px;
    border-right: 1px solid rgba(0,0,0,0.1);
}

.fb-page.right-page {
    right: 0;
    transform-origin: left center;
    border-radius: 0 6px 6px 0;
    border-left: 1px solid rgba(0,0,0,0.1);
}

/* Reader Color Themes for Pages */
.reader-modal.theme-sepia .fb-page {
    background: #f4ecd8 !important;
    color: #433422 !important;
}

.reader-modal.theme-darkness .fb-page {
    background: #181c24 !important;
    color: #e2e8f0 !important;
}

.fb-page-content {
    width: 100%;
    height: 100%;
    padding: 35px 30px;
    overflow-y: auto;
    position: relative;
    font-size: 0.95rem;
    line-height: 1.7;
}

.fb-page canvas, .fb-page img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

/* Spine Shadow Overlay */
.fb-page::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    width: 30px;
    pointer-events: none;
}

.fb-page.left-page::after {
    right: 0;
    background: linear-gradient(to left, rgba(0,0,0,0.2) 0%, transparent 100%);
}

.fb-page.right-page::after {
    left: 0;
    background: linear-gradient(to right, rgba(0,0,0,0.2) 0%, transparent 100%);
}

/* Page Flip Turned Class */
.fb-page.turned {
    transform: rotateY(-180deg);
}

.fb-page.left-page.turned {
    transform: rotateY(180deg);
}

/* Reader Footer */
.reader-footer {
    height: 50px;
    background: #11151f;
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.page-counter span {
    font-weight: 700;
    color: var(--text-primary);
}

.page-scrubber-box {
    flex: 1;
    max-width: 400px;
    margin: 0 20px;
}

.page-scrubber-box input[type="range"] {
    width: 100%;
    accent-color: var(--accent-gold);
}

.tts-status-box {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #1a202c;
    padding: 4px 12px;
    border-radius: var(--radius-full);
}

/* ==========================================================================
   MODAL CREATOR & UPLOADER
   ========================================================================== */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(5, 7, 10, 0.85);
    backdrop-filter: blur(10px);
    z-index: 900;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-overlay.active {
    display: flex;
}

.modal-card {
    width: 100%;
    max-width: 680px;
    background: var(--bg-surface);
    border: 1px solid var(--border-gold);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg), var(--shadow-gold);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: zoomIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes zoomIn {
    from { opacity: 0; transform: scale(0.92); }
    to { opacity: 1; transform: scale(1); }
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h2 {
    font-size: 1.25rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 10px;
}

.close-modal-btn {
    color: var(--text-muted);
    font-size: 1.1rem;
}
.close-modal-btn:hover { color: #fff; }

.modal-body {
    padding: 24px;
    overflow-y: auto;
    max-height: 75vh;
}

.creator-type-selector {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 24px;
}

.type-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 16px 10px;
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    transition: all var(--transition-fast);
}

.type-btn i {
    margin-bottom: 10px;
    color: var(--text-muted);
    transition: color var(--transition-fast);
}

.type-btn span {
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.type-btn small {
    font-size: 0.7rem;
    color: var(--text-muted);
    line-height: 1.2;
}

.type-btn:hover {
    border-color: var(--border-gold);
}

.type-btn.active {
    border-color: var(--accent-gold);
    background: rgba(229, 185, 92, 0.1);
}

.type-btn.active i {
    color: var(--accent-gold);
}

/* Forms */
.creator-form {
    display: none;
}

.creator-form.active {
    display: block;
}

.dropzone {
    border: 2px dashed var(--border-gold);
    border-radius: var(--radius-md);
    padding: 35px 20px;
    text-align: center;
    background: rgba(229, 185, 92, 0.03);
    margin-bottom: 20px;
    position: relative;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.dropzone:hover {
    background: rgba(229, 185, 92, 0.08);
    border-color: var(--accent-gold);
}

.dropzone-icon {
    font-size: 2.5rem;
    color: var(--accent-gold);
    margin-bottom: 12px;
}

.dropzone h3 {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 4px;
}

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

.file-input {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

.file-selected-name {
    display: inline-block;
    margin-top: 10px;
    font-size: 0.8rem;
    color: var(--accent-gold);
    font-weight: 600;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    margin-bottom: 16px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 16px;
}

.form-group label {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.form-group input, .form-group select, .form-group textarea {
    padding: 10px 14px;
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: #fff;
    font-size: 0.9rem;
}

.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    border-color: var(--accent-gold);
    outline: none;
}

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

.color-dot {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 2px solid transparent;
}

.color-dot.active {
    border-color: var(--accent-gold);
    box-shadow: 0 0 10px var(--accent-gold-glow);
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    background: rgba(0, 0, 0, 0.2);
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-gold);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    color: var(--text-primary);
    font-size: 0.88rem;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* Mobile Responsive Adjustments */
@media (max-width: 900px) {
    .nav-container { flex-wrap: wrap; }
    .search-box { order: 3; max-width: 100%; width: 100%; margin-top: 10px; }
    .hero-section { flex-direction: column; text-align: center; }
    .stats-row { width: 100%; justify-content: center; flex-wrap: wrap; }
    .flipbook { width: 95vw !important; height: 60vh !important; }
    .flipbook.single-page { width: 95vw !important; }
    .nav-arrow { width: 40px; height: 40px; font-size: 1rem; }
    .prev-page-btn { left: 8px; }
    .next-page-btn { right: 8px; }
}
