/* ============================
   NianNian Library - Professional Design System
   ============================ */

:root {
    /* Colors */
    --primary: #FFD700;
    --primary-50: #FFFDE7;
    --primary-100: #FFF9C4;
    --primary-200: #FFF59D;
    --primary-300: #FFF176;
    --primary-400: #FFEE58;
    --primary-500: #FFD700;
    --primary-600: #FFC107;
    --primary-700: #FFA000;
    --primary-800: #FF8F00;
    --primary-900: #E65100;

    --accent: #FF69B4;
    --accent-50: #FFF0F5;
    --accent-100: #FFB6C1;
    --accent-200: #FF91A4;
    --accent-400: #FF69B4;
    --accent-600: #E55A9B;

    --neutral-50: #FAFAFA;
    --neutral-100: #F5F5F5;
    --neutral-200: #EEEEEE;
    --neutral-300: #E0E0E0;
    --neutral-400: #BDBDBD;
    --neutral-500: #9E9E9E;
    --neutral-600: #757575;
    --neutral-700: #616161;
    --neutral-800: #424242;
    --neutral-900: #212121;

    /* Semantic Colors */
    --bg: #FAFAFA;
    --bg-surface: #FFFFFF;
    --bg-elevated: #FFFFFF;
    --text-primary: #212121;
    --text-secondary: #616161;
    --text-tertiary: #9E9E9E;
    --border: #E0E0E0;
    --border-light: #F0F0F0;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.04), 0 2px 4px rgba(0,0,0,0.03);
    --shadow-lg: 0 10px 25px rgba(0,0,0,0.06), 0 4px 10px rgba(0,0,0,0.04);
    --shadow-xl: 0 20px 50px rgba(0,0,0,0.08);

    /* Typography */
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif;
    --font-serif: 'Georgia', 'Noto Serif SC', 'Source Han Serif SC', 'SimSun', serif;

    /* Spacing */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-8: 32px;
    --space-10: 40px;
    --space-12: 48px;
    --space-16: 64px;

    /* Border Radius */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 20px;
    --radius-full: 9999px;

    /* Transitions */
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);

    /* Z-index */
    --z-dropdown: 100;
    --z-sticky: 200;
    --z-overlay: 300;
    --z-modal: 400;
    --z-toast: 500;
}

/* Dark Mode */
[data-theme="dark"] {
    --bg: #1A1A1A;
    --bg-surface: #242424;
    --bg-elevated: #2D2D2D;
    --text-primary: #F5F5F5;
    --text-secondary: #BDBDBD;
    --text-tertiary: #757575;
    --border: #3D3D3D;
    --border-light: #333333;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.2);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.25);
    --shadow-lg: 0 10px 25px rgba(0,0,0,0.3);
    --shadow-xl: 0 20px 50px rgba(0,0,0,0.4);
    --primary-50: #3D2B1F;
    --primary-100: #4A3728;
    --accent-50: #2D1F2A;
}

/* ============================
   Reset & Base
   ============================ */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-sans);
    background: var(--bg);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    transition: background var(--transition-base), color var(--transition-base);
}

a {
    color: inherit;
    text-decoration: none;
}

button {
    font-family: inherit;
    cursor: pointer;
}

img {
    max-width: 100%;
    display: block;
}

/* ============================
   Layout
   ============================ */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 var(--space-6);
}

/* ============================
   Header
   ============================ */
.header {
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: var(--z-sticky);
    backdrop-filter: blur(10px);
    background: rgba(255,255,255,0.92);
}

[data-theme="dark"] .header {
    background: rgba(36,36,36,0.92);
}

.nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 64px;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 var(--space-6);
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--text-primary);
}

.nav-logo {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--primary-400), var(--primary-600));
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(255,215,0,0.25);
    overflow: hidden;
}

.nav-logo-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: inherit;
}

.nav-menu {
    display: flex;
    list-style: none;
    gap: var(--space-1);
}

.nav-link {
    display: block;
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius-full);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all var(--transition-fast);
    position: relative;
}

.nav-link:hover {
    color: var(--text-primary);
    background: var(--neutral-100);
}

[data-theme="dark"] .nav-link:hover {
    background: var(--neutral-800);
}

.nav-link.active {
    color: var(--primary-700);
    background: var(--primary-100);
    font-weight: 600;
}

[data-theme="dark"] .nav-link.active {
    color: var(--primary-400);
    background: var(--primary-50);
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.nav-toggle {
    display: none;
    flex-direction: column;
    gap: 5px;
    background: none;
    border: none;
    padding: var(--space-2);
    cursor: pointer;
}

.nav-toggle span {
    display: block;
    width: 20px;
    height: 2px;
    background: var(--text-primary);
    border-radius: 1px;
    transition: all var(--transition-fast);
}

.user-menu {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.user-avatar-sm {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    background: linear-gradient(135deg, var(--accent), var(--accent-600));
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 0.8rem;
}

.user-name {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
}

/* ============================
   Buttons
   ============================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-5);
    border-radius: var(--radius-full);
    border: none;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
    line-height: 1.5;
}

.btn-primary {
    background: var(--primary-500);
    color: var(--neutral-900);
    box-shadow: 0 1px 3px rgba(255,215,0,0.3);
}

.btn-primary:hover {
    background: var(--primary-400);
    box-shadow: 0 2px 8px rgba(255,215,0,0.4);
    transform: translateY(-1px);
}

.btn-accent {
    background: var(--accent);
    color: white;
    box-shadow: 0 1px 3px rgba(255,105,180,0.3);
}

.btn-accent:hover {
    background: var(--accent-600);
    box-shadow: 0 2px 8px rgba(255,105,180,0.4);
    transform: translateY(-1px);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn-ghost:hover {
    background: var(--neutral-100);
    color: var(--text-primary);
    border-color: var(--neutral-300);
}

[data-theme="dark"] .btn-ghost:hover {
    background: var(--neutral-800);
    border-color: var(--neutral-600);
}

.btn-sm {
    padding: var(--space-1) var(--space-3);
    font-size: 0.8rem;
}

.btn-lg {
    padding: var(--space-3) var(--space-6);
    font-size: 1rem;
}

.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid transparent;
}

.btn-icon:hover {
    background: var(--neutral-100);
    color: var(--text-primary);
}

[data-theme="dark"] .btn-icon:hover {
    background: var(--neutral-800);
}

/* ============================
   Main Content
   ============================ */
.main-content {
    min-height: calc(100vh - 64px - 48px);
    padding: var(--space-8) 0;
}

.main-content .container {
    animation: fadeIn 0.3s ease;
}

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

/* ============================
   Footer
   ============================ */
.footer {
    border-top: 1px solid var(--border);
    padding: var(--space-5) 0;
    text-align: center;
    background: var(--bg-surface);
}

.footer-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 var(--space-6);
}

.footer-brand {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--space-1);
}

.footer-text {
    font-size: 0.8rem;
    color: var(--text-tertiary);
}

/* ============================
   Hero Section
   ============================ */
.hero {
    text-align: center;
    padding: var(--space-12) 0 var(--space-10);
    max-width: 700px;
    margin: 0 auto;
}

.hero-logo {
    width: 80px;
    height: 80px;
    margin: 0 auto var(--space-6);
    border-radius: var(--radius-xl);
    background: linear-gradient(135deg, var(--primary-300), var(--primary-500));
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 30px rgba(255,215,0,0.2);
    animation: float 3s ease-in-out infinite;
}

.hero-logo svg {
    width: 48px;
    height: 48px;
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

.hero h1 {
    font-family: var(--font-serif);
    font-size: 2.25rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: var(--space-4);
    letter-spacing: -0.02em;
}

.hero h1 span {
    color: var(--accent);
}

.hero p {
    color: var(--text-secondary);
    font-size: 1.05rem;
    line-height: 1.7;
    margin-bottom: var(--space-8);
    max-width: 500px;
    margin-left: auto;
    margin-right: auto;
}

.hero-actions {
    display: flex;
    gap: var(--space-3);
    justify-content: center;
    flex-wrap: wrap;
}

/* ============================
   Feature Cards
   ============================ */
.features {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-5);
    margin-top: var(--space-12);
}

.feature-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: var(--space-6);
    text-align: center;
    transition: all var(--transition-base);
}

.feature-card:hover {
    border-color: var(--primary-200);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

[data-theme="dark"] .feature-card:hover {
    border-color: var(--primary-50);
}

.feature-icon {
    width: 48px;
    height: 48px;
    margin: 0 auto var(--space-4);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

.feature-icon.yellow { background: var(--primary-100); }
.feature-icon.pink { background: var(--accent-50); }

[data-theme="dark"] .feature-icon.yellow { background: var(--primary-50); }
[data-theme="dark"] .feature-icon.pink { background: #3D2030; }

.feature-card h3 {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--space-2);
}

.feature-card p {
    font-size: 0.8rem;
    color: var(--text-tertiary);
    line-height: 1.5;
}

/* ============================
   Section Title
   ============================ */
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-6);
}

.section-title {
    font-family: var(--font-serif);
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.01em;
}

.section-link {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--accent);
    transition: color var(--transition-fast);
}

.section-link:hover {
    color: var(--accent-600);
}

/* ============================
   Book Grid
   ============================ */
.book-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: var(--space-5);
}

.shelf-btn {
    position: absolute;
    top: var(--space-2);
    left: var(--space-2);
    z-index: 10;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: rgba(255,255,255,0.9);
    color: var(--text-secondary);
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    backdrop-filter: blur(4px);
    box-shadow: var(--shadow-sm);
}

.shelf-btn:hover {
    background: white;
    transform: scale(1.1);
}

.shelf-btn.active {
    color: #E53E3E;
}

.shelf-btn.remove {
    background: rgba(229,62,62,0.9);
    color: white;
}

.shelf-btn.remove:hover {
    background: #C53030;
}

[data-theme="dark"] .shelf-btn {
    background: rgba(45,45,45,0.9);
    color: var(--text-secondary);
}

[data-theme="dark"] .shelf-btn.active {
    color: #FC8181;
}

.book-cover {
    width: 100%;
    aspect-ratio: 3/4;
    position: relative;
    overflow: hidden;
}

.book-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform var(--transition-slow);
}

.book-cover-img-wrap {
    width: 100%;
    height: 100%;
}

.book-cover-img-wrap img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform var(--transition-slow);
}

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

.book-cover-overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(to top, rgba(0,0,0,0.4) 0%, transparent 50%);
    opacity: 0;
    transition: opacity var(--transition-base);
}

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

.book-format-badge {
    position: absolute;
    top: var(--space-2);
    right: var(--space-2);
    padding: 2px 8px;
    border-radius: var(--radius-full);
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    backdrop-filter: blur(4px);
}

.book-format-badge.epub { background: rgba(255,215,0,0.9); color: #5D4037; }
.book-format-badge.pdf { background: rgba(244,67,54,0.9); color: white; }
.book-format-badge.mobi { background: rgba(76,175,80,0.9); color: white; }
.book-format-badge.txt { background: rgba(158,158,158,0.9); color: white; }

.book-info {
    padding: var(--space-3);
}

.book-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.3;
    margin-bottom: var(--space-1);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.book-author {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    margin-bottom: var(--space-2);
}

.book-progress {
    height: 3px;
    background: var(--neutral-200);
    border-radius: 2px;
    overflow: hidden;
}

[data-theme="dark"] .book-progress {
    background: var(--neutral-700);
}

.book-progress-bar {
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
    transition: width var(--transition-base);
}

/* ============================
   Search Enhancements
   ============================ */
.search-filters {
    display: flex;
    gap: var(--space-4);
    margin-bottom: var(--space-4);
    flex-wrap: wrap;
    align-items: center;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.filter-group label {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    white-space: nowrap;
}

.filter-select {
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 0.8rem;
    background: var(--bg-surface);
    color: var(--text-primary);
    font-family: var(--font-sans);
    cursor: pointer;
    transition: all var(--transition-fast);
    min-width: 100px;
}

.filter-select:focus {
    outline: none;
    border-color: var(--primary-400);
    box-shadow: 0 0 0 3px rgba(255,215,0,0.12);
}

.search-suggestions {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    z-index: var(--z-dropdown);
    max-height: 360px;
    overflow-y: auto;
    padding: var(--space-2) 0;
}

.suggestion-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-4);
    cursor: pointer;
    transition: background var(--transition-fast);
    font-size: 0.875rem;
}

.suggestion-item:hover,
.suggestion-item.active {
    background: var(--primary-50);
}

[data-theme="dark"] .suggestion-item:hover,
[data-theme="dark"] .suggestion-item.active {
    background: var(--primary-900);
}

.suggestion-icon {
    font-size: 1rem;
    flex-shrink: 0;
}

.suggestion-text {
    flex: 1;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.suggestion-text mark {
    background: var(--primary-200);
    color: var(--neutral-900);
    border-radius: 2px;
    padding: 0 2px;
    font-weight: 600;
}

.suggestion-type {
    font-size: 0.7rem;
    color: var(--text-tertiary);
    background: var(--neutral-100);
    padding: 2px 8px;
    border-radius: var(--radius-full);
    flex-shrink: 0;
}

[data-theme="dark"] .suggestion-type {
    background: var(--neutral-800);
}

.suggestions-divider {
    height: 1px;
    background: var(--border-light);
    margin: var(--space-2) var(--space-4);
}

.suggestions-section-title {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: var(--space-2) var(--space-4);
}

.suggestions-clear {
    font-size: 0.8rem;
    color: var(--accent);
    text-align: center;
    padding: var(--space-2) var(--space-4);
    cursor: pointer;
    transition: color var(--transition-fast);
    border-top: 1px solid var(--border-light);
    margin-top: var(--space-1);
}

.suggestions-clear:hover {
    color: var(--accent-600);
    text-decoration: underline;
}

.popular-searches {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex-wrap: wrap;
    margin-bottom: var(--space-4);
}

.popular-label {
    font-size: 0.8rem;
    color: var(--text-tertiary);
    font-weight: 500;
}

.popular-chip {
    padding: var(--space-1) var(--space-3);
    border-radius: var(--radius-full);
    border: 1px solid var(--border);
    background: var(--bg-surface);
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: var(--font-sans);
}

.popular-chip:hover {
    border-color: var(--primary-400);
    background: var(--primary-50);
    color: var(--primary-700);
}

[data-theme="dark"] .popular-chip:hover {
    background: var(--primary-900);
    color: var(--primary-400);
}

.result-count {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: var(--space-4);
    font-weight: 500;
}

.book-title mark,
.book-author mark {
    background: var(--primary-200);
    color: var(--neutral-900);
    border-radius: 2px;
    padding: 0 2px;
    font-weight: 600;
}

[data-theme="dark"] .book-title mark,
[data-theme="dark"] .book-author mark {
    background: var(--primary-700);
    color: var(--primary-100);
}

/* Mobile responsive for filters */
@media (max-width: 768px) {
    .search-filters {
        gap: var(--space-3);
    }

    .filter-group {
        flex: 1;
        min-width: 100px;
    }

    .filter-select {
        width: 100%;
        min-width: auto;
    }

    .search-suggestions {
        max-height: 280px;
    }
}

@media (max-width: 480px) {
    .search-filters {
        flex-direction: column;
        align-items: stretch;
    }

    .filter-group {
        width: 100%;
    }

    .filter-group label {
        width: 60px;
        flex-shrink: 0;
    }

    .filter-select {
        flex: 1;
    }

    .popular-searches {
        gap: var(--space-1);
    }

    .popular-chip {
        font-size: 0.75rem;
        padding: 2px 10px;
    }
}

/* ============================
   Library Page
   ============================ */
.library-toolbar {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    margin-bottom: var(--space-5);
    flex-wrap: wrap;
}

.search-box {
    flex: 1;
    min-width: 240px;
    position: relative;
}

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

.search-box input:focus {
    outline: none;
    border-color: var(--primary-300);
    box-shadow: 0 0 0 3px rgba(255,215,0,0.15);
}

.search-box input::placeholder {
    color: var(--text-tertiary);
}

.search-box .search-icon {
    position: absolute;
    left: var(--space-4);
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-tertiary);
    font-size: 1rem;
    pointer-events: none;
    transition: color var(--transition-fast);
}

.search-box:focus-within .search-icon {
    color: var(--primary-500);
}

.categories {
    display: flex;
    gap: var(--space-2);
    flex-wrap: wrap;
    margin-bottom: var(--space-6);
    padding-bottom: var(--space-5);
    border-bottom: 1px solid var(--border-light);
}

.category-btn {
    padding: var(--space-1) var(--space-4);
    border-radius: var(--radius-full);
    border: 1px solid var(--border);
    background: var(--bg-surface);
    color: var(--text-secondary);
    font-size: 0.825rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: var(--font-sans);
}

.category-btn:hover {
    border-color: var(--primary-300);
    color: var(--primary-700);
}

.category-btn.active {
    background: var(--primary-500);
    border-color: var(--primary-500);
    color: var(--neutral-900);
    font-weight: 600;
}

[data-theme="dark"] .category-btn:hover {
    border-color: var(--primary-50);
    color: var(--primary-400);
}

[data-theme="dark"] .category-btn.active {
    background: var(--primary-500);
    border-color: var(--primary-500);
}

/* ============================
   Auth Page
   ============================ */
.auth-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 112px);
    padding: var(--space-6);
}

.auth-card {
    width: 100%;
    max-width: 420px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: var(--space-8);
    box-shadow: var(--shadow-lg);
}

.auth-header {
    text-align: center;
    margin-bottom: var(--space-6);
}

.auth-header h2 {
    font-family: var(--font-serif);
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: var(--space-2);
}

.auth-header p {
    font-size: 0.875rem;
    color: var(--text-tertiary);
}

.auth-tabs {
    display: flex;
    background: var(--neutral-100);
    border-radius: var(--radius-full);
    padding: var(--space-1);
    margin-bottom: var(--space-6);
}

[data-theme="dark"] .auth-tabs {
    background: var(--neutral-800);
}

.auth-tab {
    flex: 1;
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius-full);
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: var(--font-sans);
}

.auth-tab.active {
    background: var(--bg-surface);
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
    font-weight: 600;
}

[data-theme="dark"] .auth-tab.active {
    background: var(--bg-elevated);
}

.form-group {
    margin-bottom: var(--space-4);
}

.form-group label {
    display: block;
    font-size: 0.825rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: var(--space-2);
}

.form-input {
    width: 100%;
    padding: var(--space-3) var(--space-4);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    background: var(--bg);
    color: var(--text-primary);
    transition: all var(--transition-fast);
    font-family: var(--font-sans);
}

.form-input:focus {
    outline: none;
    border-color: var(--primary-400);
    box-shadow: 0 0 0 3px rgba(255,215,0,0.12);
}

.form-input::placeholder {
    color: var(--text-tertiary);
}

.auth-submit {
    width: 100%;
    padding: var(--space-3);
    margin-top: var(--space-5);
}

.form-error {
    color: #E53E3E;
    font-size: 0.8rem;
    margin-top: var(--space-2);
    display: none;
    padding: var(--space-2) var(--space-3);
    background: rgba(229,62,62,0.08);
    border-radius: var(--radius-sm);
}

.form-error.show {
    display: block;
}

/* ============================
   Bookshelf Stats
   ============================ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-4);
    margin-bottom: var(--space-8);
}

.stat-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    text-align: center;
    transition: all var(--transition-base);
}

.stat-card:hover {
    border-color: var(--primary-200);
    box-shadow: var(--shadow-sm);
}

.stat-number {
    font-size: 2rem;
    font-weight: 800;
    color: var(--primary-600);
    line-height: 1;
    margin-bottom: var(--space-2);
}

[data-theme="dark"] .stat-number {
    color: var(--primary-400);
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-tertiary);
    font-weight: 500;
}

/* ============================
   Reader - Top-Tier Design
   ============================ */

/* Reader Page Layout */
.reader-page {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    background: var(--bg);
    overflow: hidden;
}

/* Reader Toolbar */
.reader-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 56px;
    min-height: 56px;
    padding: 0 var(--space-5);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-light);
    flex-shrink: 0;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    transition: transform var(--transition-base), opacity var(--transition-base);
    z-index: 10;
}

.reader-toolbar-left {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-width: 0;
    flex: 1;
}

.reader-back {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.reader-back:hover {
    color: var(--primary-500);
    background: var(--primary-50);
}

.reader-book-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 280px;
    line-height: 1.4;
}

.reader-toolbar-center {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    flex-shrink: 0;
}

.reader-progress-text {
    font-size: 0.8rem;
    color: var(--text-tertiary);
    font-weight: 500;
    font-variant-numeric: tabular-nums;
}

#readerChapterInfo {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    font-weight: 400;
    opacity: 0.7;
}

.reader-toolbar-right {
    display: flex;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
}

/* Icon Buttons */
.btn-icon {
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.1rem;
    cursor: pointer;
    border-radius: var(--radius-lg);
    transition: all var(--transition-fast);
    position: relative;
    overflow: hidden;
}

.btn-icon::after {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--primary-500);
    opacity: 0;
    border-radius: inherit;
    transition: opacity var(--transition-fast);
}

.btn-icon:hover {
    color: var(--primary-500);
    background: var(--primary-50);
}

.btn-icon:active {
    transform: scale(0.92);
}

.btn-icon:active::after {
    opacity: 0.1;
}

/* Reader Body */
.reader-body {
    flex: 1;
    display: flex;
    position: relative;
    overflow: hidden;
}

/* Reader Content */
.reader-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: var(--space-12) var(--space-8) var(--space-24);
    max-width: 720px;
    margin: 0 auto;
    width: 100%;
    line-height: 1.9;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

/* Reader Progress Bar */
.reader-progress-bar {
    position: absolute;
    top: 0;
    left: 0;
    height: 2px;
    width: 0%;
    background: var(--primary-500);
    z-index: 5;
    transition: width 0.1s linear;
    border-radius: 0 1px 1px 0;
}

[data-reader-theme="night"] .reader-progress-bar {
    background: #555;
}

[data-reader-theme="eye-comfort"] .reader-progress-bar {
    background: #B8A070;
}

.reader-content p {
    margin-bottom: var(--space-4);
    text-indent: 2em;
    color: var(--text-primary);
    word-break: break-word;
    overflow-wrap: break-word;
    font-size: inherit;
}

.reader-content p:first-child {
    text-indent: 0;
}

.reader-chapter-title {
    font-family: var(--font-serif);
    font-size: 1.5rem;
    font-weight: 700;
    text-align: center;
    margin-bottom: var(--space-8);
    color: var(--text-primary);
    text-indent: 0 !important;
    padding-bottom: var(--space-4);
    border-bottom: 1px solid var(--border-light);
}

/* EPUB Content */
.epub-content {
    line-height: inherit;
}

.epub-content p {
    margin-bottom: var(--space-4);
    text-indent: 2em;
    word-break: break-word;
    overflow-wrap: break-word;
}

.epub-content h1,
.epub-content h2,
.epub-content h3,
.epub-content h4,
.epub-content h5,
.epub-content h6 {
    margin-top: var(--space-6);
    margin-bottom: var(--space-3);
    font-family: var(--font-serif);
    font-weight: 700;
    color: var(--text-primary);
}

.epub-content h1 { font-size: 1.5rem; }
.epub-content h2 { font-size: 1.35rem; }
.epub-content h3 { font-size: 1.2rem; }
.epub-content h4 { font-size: 1.1rem; }
.epub-content h5 { font-size: 1rem; }
.epub-content h6 { font-size: 0.95rem; }

.epub-content img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: var(--space-6) auto;
    border-radius: var(--radius-md);
    cursor: zoom-in;
    transition: transform var(--transition-fast);
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

[data-theme="dark"] .epub-content img {
    opacity: 0.9;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.epub-content a {
    color: var(--primary-500);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.epub-content blockquote {
    margin: var(--space-4) 0;
    padding: var(--space-3) var(--space-5);
    border-left: 3px solid var(--primary-300);
    background: var(--neutral-50);
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
    color: var(--text-secondary);
}

[data-theme="dark"] .epub-content blockquote {
    background: var(--neutral-800);
}

.epub-content ul, .epub-content ol {
    margin: var(--space-3) 0;
    padding-left: var(--space-6);
}

.epub-content li {
    margin-bottom: var(--space-1);
}

.epub-content table {
    width: 100%;
    border-collapse: collapse;
    margin: var(--space-4) 0;
}

.epub-content th, .epub-content td {
    border: 1px solid var(--border);
    padding: var(--space-2) var(--space-3);
    text-align: left;
}

.epub-content th {
    background: var(--neutral-100);
    font-weight: 600;
}

[data-theme="dark"] .epub-content th {
    background: var(--neutral-800);
}

/* Font Size */
.reader-content.font-xs { font-size: 0.75rem; }
.reader-content.font-small { font-size: 0.875rem; }
.reader-content.font-medium { font-size: 1rem; }
.reader-content.font-large { font-size: 1.125rem; }
.reader-content.font-xlarge { font-size: 1.25rem; }
.reader-content.font-xxl { font-size: 1.5rem; }

/* Line Height */
.reader-content.lh-compact { line-height: 1.5; }
.reader-content.lh-normal { line-height: 1.9; }
.reader-content.lh-relaxed { line-height: 2.2; }
.reader-content.lh-loose { line-height: 2.6; }

/* Content Width */
.reader-content.cw-narrow { max-width: 520px; }
.reader-content.cw-normal { max-width: 720px; }
.reader-content.cw-wide { max-width: 960px; }

/* Font Family */
.reader-content.ff-sans { font-family: var(--font-sans); }
.reader-content.ff-serif { font-family: var(--font-serif); }
.reader-content.ff-mono { font-family: 'Consolas', 'Monaco', 'Courier New', monospace; }

/* Page Buttons */
.reader-page-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 44px;
    height: 88px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-surface);
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    opacity: 0;
    transition: all var(--transition-fast);
    z-index: 5;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.reader-page-btn:hover,
.reader-page-btn:active {
    opacity: 1;
    color: var(--primary-500);
}

.reader-page-prev {
    left: 4px;
}

.reader-page-next {
    right: 4px;
}

.reader-body:hover .reader-page-btn {
    opacity: 0.5;
}

.reader-body:hover .reader-page-btn:hover {
    opacity: 1;
}

/* Reader Sidebar */
.reader-sidebar {
    width: 320px;
    background: var(--bg-surface);
    border-left: 1px solid var(--border);
    overflow-y: auto;
    flex-shrink: 0;
    transition: transform var(--transition-base);
    -webkit-overflow-scrolling: touch;
}

.reader-sidebar.hidden {
    display: none;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4);
    border-bottom: 1px solid var(--border);
    gap: var(--space-3);
}

.sidebar-header-info {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-width: 0;
    flex: 1;
}

.sidebar-header-info h3 {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-author {
    font-size: 0.8rem;
    color: var(--text-tertiary);
    margin-top: 2px;
}

.sidebar-cover {
    width: 36px;
    height: 50px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    flex-shrink: 0;
}

.sidebar-close {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-full);
    border: none;
    background: var(--neutral-100);
    color: var(--text-tertiary);
    font-size: 1.1rem;
    cursor: pointer;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.sidebar-close:hover {
    background: var(--neutral-200);
    color: var(--text-primary);
}

.sidebar-section {
    padding: var(--space-4);
    border-bottom: 1px solid var(--border-light);
}

.sidebar-section:last-child {
    border-bottom: none;
}

.sidebar-section-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: var(--space-3);
}

.toc-item {
    padding: var(--space-2) var(--space-3);
    font-size: 0.85rem;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
    line-height: 1.5;
    border-left: 2px solid transparent;
}

.toc-item:hover {
    background: var(--neutral-50);
    color: var(--text-primary);
}

.toc-item.active {
    background: var(--primary-50);
    color: var(--primary-600);
    border-left-color: var(--primary-500);
    font-weight: 500;
}

[data-theme="dark"] .toc-item:hover {
    background: var(--neutral-800);
}

[data-theme="dark"] .toc-item.active {
    background: var(--primary-900);
    color: var(--primary-300);
}

.bookmark-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-2) var(--space-3);
    font-size: 0.85rem;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
}

.bookmark-item:hover {
    background: var(--neutral-50);
    color: var(--text-primary);
}

.bookmark-delete {
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-full);
    border: none;
    background: transparent;
    color: var(--text-tertiary);
    font-size: 0.9rem;
    cursor: pointer;
    opacity: 0;
    transition: all var(--transition-fast);
}

.bookmark-item:hover .bookmark-delete {
    opacity: 1;
}

.bookmark-delete:hover {
    background: #FEE2E2;
    color: #EF4444;
}

/* Reader Navigation Bar */
.reader-nav-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-2) var(--space-6);
    background: var(--bg-surface);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    gap: var(--space-3);
}

.reader-nav-btn {
    padding: var(--space-2) var(--space-5);
    border-radius: var(--radius-full);
    border: 1px solid var(--border);
    background: var(--bg-surface);
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: var(--font-sans);
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
    position: relative;
    overflow: hidden;
}

.reader-nav-btn::after {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--primary-500);
    opacity: 0;
    border-radius: inherit;
    transition: opacity var(--transition-fast);
}

.reader-nav-btn:hover:not(:disabled) {
    background: var(--primary-500);
    border-color: var(--primary-500);
    color: var(--neutral-900);
}

.reader-nav-btn:active:not(:disabled) {
    transform: scale(0.96);
}

.reader-nav-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.reader-nav-progress {
    flex: 1;
    display: flex;
    align-items: center;
    gap: var(--space-2);
    justify-content: center;
}

.reader-nav-progress-text {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* Reader Settings Panel */
.reader-settings-panel {
    position: fixed;
    bottom: 60px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    box-shadow: 0 20px 60px rgba(0,0,0,0.15), 0 1px 3px rgba(0,0,0,0.08);
    z-index: var(--z-overlay);
    width: 360px;
    max-width: calc(100vw - 32px);
    animation: settingsSlideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

.reader-settings-panel.hidden {
    display: none;
}

@keyframes settingsSlideUp {
    from { opacity: 0; transform: translateX(-50%) translateY(12px) scale(0.97); }
    to { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
}

.settings-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--border-light);
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-primary);
}

.settings-panel-body {
    padding: var(--space-5);
}

.settings-panel-section {
    margin-bottom: var(--space-5);
}

.settings-panel-section:last-child {
    margin-bottom: 0;
}

.settings-panel-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: var(--space-3);
}

.font-size-slider {
    display: flex;
    gap: var(--space-2);
}

.font-size-slider .font-size-btn {
    flex: 1;
    padding: var(--space-2);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text-secondary);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: var(--font-sans);
    font-weight: 500;
    -webkit-tap-highlight-color: transparent;
    position: relative;
    overflow: hidden;
}

.font-size-slider .font-size-btn::after {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--primary-500);
    opacity: 0;
    border-radius: inherit;
    transition: opacity var(--transition-fast);
}

.font-size-slider .font-size-btn:hover {
    border-color: var(--primary-300);
    color: var(--primary-600);
}

.font-size-slider .font-size-btn:active {
    transform: scale(0.96);
}

.font-size-slider .font-size-btn.active {
    background: var(--primary-500);
    border-color: var(--primary-500);
    color: var(--neutral-900);
    font-weight: 600;
}

.theme-options {
    display: flex;
    gap: var(--space-3);
}

.theme-btn {
    flex: 1;
    padding: var(--space-3) var(--space-2);
    border-radius: var(--radius-lg);
    border: 2px solid var(--border);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-size: 0.8rem;
    font-weight: 500;
    font-family: var(--font-sans);
    -webkit-tap-highlight-color: transparent;
}

.theme-btn:hover {
    border-color: var(--primary-300);
    transform: translateY(-1px);
}

.theme-btn:active {
    transform: scale(0.96);
}

.theme-btn.active {
    border-color: var(--primary-500);
    box-shadow: 0 0 0 1px var(--primary-500);
}

/* Sepia Theme Overrides */
[data-reader-theme="sepia"] {
    --bg: #faf6ed;
    --bg-surface: #f4ecd8;
    --text-primary: #5b4636;
    --text-secondary: #7a6652;
    --text-tertiary: #9a8572;
    --border: #d4c5a9;
    --border-light: #e0d5bf;
}

[data-reader-theme="sepia"] .reader-content {
    background: #faf6ed;
    color: #5b4636;
}

[data-reader-theme="sepia"] .reader-settings-panel {
    background: #f4ecd8;
    border-color: #d4c5a9;
    box-shadow: 0 20px 60px rgba(92,70,54,0.15), 0 1px 3px rgba(92,70,54,0.08);
}

[data-reader-theme="sepia"] .reader-nav-bar {
    background: #f4ecd8;
}

[data-reader-theme="sepia"] .reader-toolbar {
    background: #f4ecd8;
}

[data-reader-theme="sepia"] .toc-item.active {
    background: rgba(91,70,54,0.1);
    color: #5b4636;
    border-left-color: #5b4636;
}

/* Night Theme - AMOLED */
[data-reader-theme="night"] .reader-content {
    background: #000000;
    color: #A0A0A0;
}

[data-reader-theme="night"] .reader-content p {
    color: #A0A0A0;
}

[data-reader-theme="night"] .reader-chapter-title {
    color: #C0C0C0;
    border-bottom-color: #333;
}

[data-reader-theme="night"] .reader-toolbar {
    background: #111111;
    border-bottom-color: #222;
}

[data-reader-theme="night"] .reader-nav-bar {
    background: #111111;
    border-top-color: #222;
}

[data-reader-theme="night"] .reader-content img {
    opacity: 0.7;
}

[data-reader-theme="night"] .reader-back {
    color: #888;
}

[data-reader-theme="night"] .reader-book-title {
    color: #C0C0C0;
}

[data-reader-theme="night"] .btn-icon {
    color: #888;
}

[data-reader-theme="night"] .reader-page-btn {
    background: #111;
    color: #888;
}

[data-reader-theme="night"] .epub-content blockquote {
    background: #111;
    border-left-color: #444;
}

[data-reader-theme="night"] .epub-content a {
    color: #6688AA;
}

/* Eye Comfort Theme */
[data-reader-theme="eye-comfort"] .reader-content {
    background: #F5EDDC;
    color: #5B4636;
}

[data-reader-theme="eye-comfort"] .reader-content p {
    color: #5B4636;
}

[data-reader-theme="eye-comfort"] .reader-chapter-title {
    color: #4A3728;
    border-bottom-color: #D4C9B5;
}

[data-reader-theme="eye-comfort"] .reader-toolbar {
    background: #EDE4D0;
    border-bottom-color: #D4C9B5;
}

[data-reader-theme="eye-comfort"] .reader-nav-bar {
    background: #EDE4D0;
    border-top-color: #D4C9B5;
}

[data-reader-theme="eye-comfort"] .reader-back {
    color: #7A6555;
}

[data-reader-theme="eye-comfort"] .reader-book-title {
    color: #4A3728;
}

[data-reader-theme="eye-comfort"] .btn-icon {
    color: #7A6555;
}

[data-reader-theme="eye-comfort"] .reader-page-btn {
    background: #EDE4D0;
    color: #7A6555;
}

[data-reader-theme="eye-comfort"] .epub-content blockquote {
    background: #EDE4D0;
    border-left-color: #B8A88A;
    color: #6B5646;
}

[data-reader-theme="eye-comfort"] .epub-content a {
    color: #7A5A3A;
}

/* Dark Theme Reader Overrides */
[data-reader-theme="dark"] .reader-content {
    background: var(--neutral-900);
    color: var(--neutral-200);
}

[data-reader-theme="dark"] .reader-content p {
    color: var(--neutral-200);
}

[data-reader-theme="dark"] .reader-toolbar {
    background: var(--neutral-800);
    border-bottom-color: var(--neutral-700);
}

[data-reader-theme="dark"] .reader-nav-bar {
    background: var(--neutral-800);
    border-top-color: var(--neutral-700);
}

[data-reader-theme="dark"] .reader-back {
    color: var(--neutral-400);
}

[data-reader-theme="dark"] .reader-book-title {
    color: var(--neutral-200);
}

[data-reader-theme="dark"] .btn-icon {
    color: var(--neutral-400);
}

[data-reader-theme="dark"] .reader-page-btn:hover,
[data-reader-theme="dark"] .reader-page-btn:active {
    background: var(--neutral-700);
    color: var(--primary-400);
}

[data-reader-theme="dark"] .epub-content blockquote {
    background: var(--neutral-800);
    border-left-color: var(--neutral-600);
}

[data-reader-theme="dark"] .epub-content a {
    color: var(--primary-400);
}

/* Dark Theme Reader Overrides (legacy data-theme) */
[data-theme="dark"] .reader-content {
    background: var(--bg);
}

[data-theme="dark"] .reader-settings-panel {
    box-shadow: 0 20px 60px rgba(0,0,0,0.5), 0 1px 3px rgba(0,0,0,0.2);
}

[data-theme="dark"] .reader-nav-btn:hover:not(:disabled) {
    background: var(--primary-400);
    border-color: var(--primary-400);
    color: var(--neutral-900);
}

[data-theme="dark"] .btn-icon:hover {
    background: var(--neutral-800);
}

[data-theme="dark"] .reader-page-btn:hover,
[data-theme="dark"] .reader-page-btn:active {
    color: var(--primary-400);
}

/* Image Lightbox */
.image-lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.92);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-modal);
    cursor: zoom-out;
    animation: lightboxFadeIn 0.2s ease;
}

@keyframes lightboxFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.lightbox-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255,255,255,0.1);
    border: none;
    border-radius: var(--radius-full);
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    transition: background var(--transition-fast);
    z-index: 2;
    -webkit-tap-highlight-color: transparent;
}

.lightbox-close:hover {
    background: rgba(255,255,255,0.2);
}

.lightbox-img-container {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.lightbox-img {
    max-width: 95vw;
    max-height: 90vh;
    object-fit: contain;
    border-radius: var(--radius-sm);
    transition: transform 0.15s ease;
    cursor: zoom-in;
}

.lightbox-hint {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.8rem;
    color: rgba(255,255,255,0.5);
    pointer-events: none;
}

/* Reader Content Transition */
.reader-content {
    transition: opacity 0.18s ease;
}

/* Chapter Slide Animations */
.reader-content.slide-in-right {
    animation: slideInRight 0.25s ease-out forwards;
}

.reader-content.slide-in-left {
    animation: slideInLeft 0.25s ease-out forwards;
}

@keyframes slideInRight {
    from { opacity: 0; transform: translateX(30px); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes slideInLeft {
    from { opacity: 0; transform: translateX(-30px); }
    to { opacity: 1; transform: translateX(0); }
}

/* Reader Scrollbar */
.reader-content::-webkit-scrollbar {
    width: 4px;
}

.reader-content::-webkit-scrollbar-track {
    background: transparent;
}

.reader-content::-webkit-scrollbar-thumb {
    background: var(--neutral-300);
    border-radius: 2px;
    transition: background var(--transition-fast);
}

.reader-content::-webkit-scrollbar-thumb:hover {
    background: var(--neutral-400);
}

[data-theme="dark"] .reader-content::-webkit-scrollbar-thumb {
    background: var(--neutral-600);
}

[data-theme="dark"] .reader-content::-webkit-scrollbar-thumb:hover {
    background: var(--neutral-500);
}

/* Responsive - Tablet */
@media (max-width: 900px) {
    .reader-content {
        padding: var(--space-8) var(--space-5) var(--space-20);
    }

    .reader-sidebar {
        position: fixed;
        right: 0;
        top: 0;
        bottom: 0;
        z-index: var(--z-overlay);
        box-shadow: var(--shadow-xl);
        transform: translateX(100%);
        transition: transform var(--transition-base);
        display: block !important;
    }

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

    .reader-sidebar.hidden {
        transform: translateX(100%);
    }

    .reader-page-next {
        right: 8px;
    }
}

/* Responsive - Mobile */
@media (max-width: 768px) {
    .reader-book-title {
        max-width: 150px;
    }

    .reader-toolbar-center {
        display: none;
    }

    .reader-content {
        padding: var(--space-6) var(--space-4) var(--space-16);
        font-size: 1rem;
    }

    .reader-content.font-xs { font-size: 14px; }
    .reader-content.font-small { font-size: 16px; }
    .reader-content.font-medium { font-size: 18px; }
    .reader-content.font-large { font-size: 20px; }
    .reader-content.font-xlarge { font-size: 22px; }
    .reader-content.font-xxl { font-size: 26px; }

    .reader-content.lh-compact { line-height: 1.6; }
    .reader-content.lh-normal { line-height: 1.9; }
    .reader-content.lh-relaxed { line-height: 2.3; }
    .reader-content.lh-loose { line-height: 2.7; }

    .reader-chapter-title {
        font-size: 1.25rem;
    }

    .reader-page-btn {
        width: 48px;
        height: 100%;
        border-radius: 0;
    }

    .reader-page-prev { left: 0; }
    .reader-page-next { right: 0; }

    .reader-nav-bar {
        padding: var(--space-2) var(--space-4);
    }

    .reader-nav-btn {
        padding: var(--space-2) var(--space-4);
        font-size: 0.8rem;
    }

    .reader-settings-panel {
        bottom: 0;
        left: 0;
        right: 0;
        transform: none;
        width: 100%;
        max-width: 100%;
        max-height: 70vh;
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
        animation: settingsSlideUpMobile 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    }

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

    .font-size-btn {
        min-width: 44px;
        min-height: 44px;
        padding: 8px 12px;
        font-size: 0.85rem;
    }

    .font-size-slider {
        gap: 8px;
    }

    .theme-btn {
        min-width: 44px;
        min-height: 36px;
        padding: 8px 12px;
    }

    .theme-options {
        gap: 8px;
    }

    .settings-panel-label {
        margin-bottom: 10px;
    }

    .settings-panel-section {
        margin-bottom: 16px;
    }
}

@media (max-width: 480px) {
    .reader-toolbar {
        padding: 0 var(--space-3);
        height: 52px;
        min-height: 52px;
    }

    .reader-book-title {
        max-width: 120px;
    }

    .btn-icon {
        width: 32px;
        height: 32px;
        font-size: 1rem;
    }

    .reader-content {
        padding: var(--space-5) var(--space-3) var(--space-16);
    }
}

/* Landscape Reading Optimization */
@media (max-height: 500px) and (orientation: landscape) {
    .reader-toolbar {
        height: 44px;
        min-height: 44px;
        padding: 0 var(--space-3);
    }

    .reader-book-title {
        max-width: 200px;
        font-size: 0.85rem;
    }

    .btn-icon {
        width: 32px;
        height: 32px;
        font-size: 0.95rem;
    }

    .reader-content {
        padding: var(--space-4) var(--space-6) var(--space-12);
    }

    .reader-nav-bar {
        padding: var(--space-1) var(--space-4);
    }

    .reader-nav-btn {
        padding: var(--space-1) var(--space-3);
        font-size: 0.8rem;
    }

    /* Hide app bottom nav in landscape reader */
    .bottom-nav {
        display: none !important;
    }

    /* Settings panel full width in landscape */
    .reader-settings-panel {
        max-width: 100%;
        left: 0;
        right: 0;
        transform: none;
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    }

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

/* ============================
   Settings
   ============================ */
.settings-wrapper {
    max-width: 640px;
    margin: 0 auto;
}

.settings-section {
    background: var(--bg-surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: var(--space-6);
    margin-bottom: var(--space-4);
}

.settings-section-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--space-4);
    padding-bottom: var(--space-3);
    border-bottom: 1px solid var(--border-light);
}

.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-3) 0;
    border-bottom: 1px solid var(--border-light);
}

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

.setting-label {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-primary);
}

.setting-value {
    font-size: 0.85rem;
    color: var(--text-tertiary);
}

.font-size-options {
    display: flex;
    gap: var(--space-2);
}

.font-size-btn {
    padding: var(--space-1) var(--space-3);
    border-radius: var(--radius-full);
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text-secondary);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: var(--font-sans);
}

.font-size-btn:hover {
    border-color: var(--primary-300);
}

.font-size-btn.active {
    background: var(--primary-500);
    border-color: var(--primary-500);
    color: var(--neutral-900);
    font-weight: 600;
}

.toggle-row {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.toggle {
    position: relative;
    width: 44px;
    height: 24px;
    background: var(--neutral-300);
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: background var(--transition-fast);
    border: none;
}

.toggle.active {
    background: var(--primary-500);
}

.toggle::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    background: white;
    border-radius: 50%;
    top: 2px;
    left: 2px;
    transition: transform var(--transition-fast);
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.toggle.active::after {
    transform: translateX(20px);
}

/* ============================
   Modal
   ============================ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-modal);
    padding: var(--space-4);
}

.modal {
    background: var(--bg-surface);
    border-radius: var(--radius-xl);
    width: 100%;
    max-width: 480px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: var(--shadow-xl);
    animation: modalSlideUp 0.25s ease;
}

@keyframes modalSlideUp {
    from { opacity: 0; transform: translateY(20px) scale(0.97); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

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

.modal-header h3 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-tertiary);
    cursor: pointer;
    line-height: 1;
    padding: var(--space-1);
}

.modal-close:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: var(--space-6);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-6);
    border-top: 1px solid var(--border-light);
}

/* Upload Zone */
.upload-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-8) var(--space-6);
    text-align: center;
    cursor: pointer;
    transition: all var(--transition-fast);
    background: var(--bg);
}

.upload-zone:hover,
.upload-zone.dragover {
    border-color: var(--primary-400);
    background: var(--primary-50);
}

.upload-icon {
    font-size: 2.5rem;
    margin-bottom: var(--space-3);
}

.upload-text {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--space-1);
}

.upload-hint {
    color: var(--text-tertiary);
    font-size: 0.8rem;
    margin-bottom: var(--space-2);
}

.upload-formats {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    background: var(--neutral-100);
    display: inline-block;
    padding: var(--space-1) var(--space-3);
    border-radius: var(--radius-full);
}

[data-theme="dark"] .upload-formats {
    background: var(--neutral-800);
}

.upload-list {
    margin-top: var(--space-4);
}

.upload-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
    background: var(--bg);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-2);
}

.upload-item-icon {
    font-size: 1.2rem;
    flex-shrink: 0;
}

.upload-item-name {
    flex: 1;
    font-size: 0.85rem;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.upload-item-format {
    font-size: 0.65rem;
    padding: 2px 8px;
    border-radius: var(--radius-full);
    background: var(--primary-100);
    color: var(--primary-800);
    font-weight: 600;
    text-transform: uppercase;
    flex-shrink: 0;
}

.upload-item-remove {
    background: none;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    font-size: 1.1rem;
    padding: var(--space-1);
    line-height: 1;
}

.upload-item-remove:hover {
    color: #E53E3E;
}

/* Progress */
.upload-progress {
    margin-top: var(--space-4);
}

.progress-bar {
    width: 100%;
    height: 6px;
    background: var(--neutral-200);
    border-radius: var(--radius-full);
    overflow: hidden;
    margin-bottom: var(--space-2);
}

[data-theme="dark"] .progress-bar {
    background: var(--neutral-700);
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-500), var(--accent));
    border-radius: var(--radius-full);
    transition: width 0.3s ease;
}

.progress-text {
    text-align: center;
    color: var(--text-tertiary);
    font-size: 0.8rem;
}

/* ============================
   Empty State
   ============================ */
.empty-state {
    text-align: center;
    padding: var(--space-16) var(--space-6);
}

.empty-icon {
    font-size: 3.5rem;
    margin-bottom: var(--space-4);
    opacity: 0.4;
}

.empty-state h3 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--space-2);
}

.empty-state p {
    color: var(--text-tertiary);
    font-size: 0.9rem;
    margin-bottom: var(--space-6);
}

/* ============================
   Toast
   ============================ */
.toast-container {
    position: fixed;
    top: 80px;
    right: var(--space-5);
    z-index: var(--z-toast);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    pointer-events: none;
}

.toast {
    padding: var(--space-3) var(--space-5);
    border-radius: var(--radius-full);
    font-size: 0.85rem;
    font-weight: 500;
    color: white;
    box-shadow: var(--shadow-lg);
    animation: toastSlideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    backdrop-filter: blur(10px);
    pointer-events: auto;
    max-width: 320px;
}

.toast.toast-success { background: rgba(34, 197, 94, 0.9); }
.toast.toast-error { background: rgba(239, 68, 68, 0.9); }
.toast.toast-warning { background: rgba(234, 179, 8, 0.9); }
.toast.toast-info { background: rgba(59, 130, 246, 0.9); }

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

.toast.toast-out {
    animation: toastSlideOut 0.25s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes toastSlideOut {
    to { opacity: 0; transform: translateX(100%) scale(0.9); }
}

/* ============================
   Loading & Skeleton
   ============================ */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-16) 0;
    grid-column: 1 / -1;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--neutral-200);
    border-top-color: var(--primary-500);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

[data-theme="dark"] .spinner {
    border-color: var(--neutral-700);
}

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

/* Skeleton Card */
.skeleton-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    overflow: hidden;
    animation: skeletonFadeIn 0.3s ease;
}

.skeleton-cover {
    width: 100%;
    aspect-ratio: 3/4;
    background: linear-gradient(90deg, var(--neutral-100) 25%, var(--neutral-50) 50%, var(--neutral-100) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s ease-in-out infinite;
}

[data-theme="dark"] .skeleton-cover {
    background: linear-gradient(90deg, var(--neutral-800) 25%, var(--neutral-700) 50%, var(--neutral-800) 75%);
    background-size: 200% 100%;
}

.skeleton-info {
    padding: var(--space-3);
}

.skeleton-line {
    height: 10px;
    border-radius: var(--radius-sm);
    background: linear-gradient(90deg, var(--neutral-100) 25%, var(--neutral-50) 50%, var(--neutral-100) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s ease-in-out infinite;
    margin-bottom: var(--space-2);
}

.skeleton-line:last-child {
    width: 60%;
    margin-bottom: 0;
}

[data-theme="dark"] .skeleton-line {
    background: linear-gradient(90deg, var(--neutral-800) 25%, var(--neutral-700) 50%, var(--neutral-800) 75%);
    background-size: 200% 100%;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

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

/* Empty State Enhancement */
.empty-state {
    text-align: center;
    padding: var(--space-16) var(--space-6);
    grid-column: 1 / -1;
    animation: emptyStateFadeIn 0.5s ease;
}

.empty-icon {
    font-size: 4rem;
    margin-bottom: var(--space-4);
    opacity: 0.6;
    animation: emptyIconBounce 2s ease-in-out infinite;
}

@keyframes emptyStateFadeIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

@keyframes emptyIconBounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

/* Card Micro-interactions */
.book-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    overflow: hidden;
    transition: all var(--transition-base);
    cursor: pointer;
    position: relative;
    animation: cardFadeIn 0.4s ease backwards;
}

.book-card:nth-child(1) { animation-delay: 0.05s; }
.book-card:nth-child(2) { animation-delay: 0.1s; }
.book-card:nth-child(3) { animation-delay: 0.15s; }
.book-card:nth-child(4) { animation-delay: 0.2s; }
.book-card:nth-child(5) { animation-delay: 0.25s; }
.book-card:nth-child(6) { animation-delay: 0.3s; }
.book-card:nth-child(7) { animation-delay: 0.35s; }
.book-card:nth-child(8) { animation-delay: 0.4s; }

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

.book-card:hover {
    border-color: var(--primary-200);
    box-shadow: var(--shadow-md);
    transform: translateY(-3px);
}

[data-theme="dark"] .book-card:hover {
    border-color: var(--primary-50);
}

/* ============================
   Responsive
   ============================ */
@media (max-width: 900px) {
    .features {
        grid-template-columns: repeat(2, 1fr);
    }

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

@media (max-width: 768px) {
    /* Hide top nav dropdown menu, replaced by bottom nav */
    .nav-menu {
        display: none;
    }

    .nav-toggle {
        display: none;
    }

    .hero {
        padding: var(--space-8) 0 var(--space-6);
    }

    .hero h1 {
        font-size: 1.75rem;
    }

    .hero p {
        font-size: 0.95rem;
    }

    .features {
        grid-template-columns: 1fr 1fr;
        gap: var(--space-3);
    }

    .stats-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: var(--space-3);
    }

    .stat-card {
        padding: var(--space-4);
    }

    .stat-number {
        font-size: 1.5rem;
    }

    .library-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .search-box {
        min-width: auto;
    }

    .auth-card {
        padding: var(--space-5);
    }
}

@media (max-width: 480px) {
    .features {
        grid-template-columns: 1fr;
    }

    .book-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: var(--space-3);
    }

    .hero-actions {
        flex-direction: column;
        align-items: center;
    }

    .hero-actions .btn {
        width: 100%;
        max-width: 240px;
    }

    .stats-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* ============================
   Mobile Bottom Nav - Show at ≤768px
   ============================ */
@media (max-width: 768px) {
    /* Show bottom nav, hide top nav menu */
    .bottom-nav {
        display: flex;
    }

    .nav-menu {
        display: none;
    }

    .nav-toggle {
        display: none;
    }

    /* Add bottom padding to main content to avoid overlap */
    .main-content {
        padding-bottom: calc(var(--space-8) + 64px);
    }

    /* Footer spacing adjustment */
    .footer {
        padding-bottom: calc(var(--space-5) + 56px);
    }

    /* Reader page hides bottom nav */
    .reader-page ~ .bottom-nav,
    .bottom-nav.reader-hidden {
        display: none;
    }
}

/* ============================
   Small Screen Adaptation ≤375px
   ============================ */
@media (max-width: 375px) {
    .bottom-nav-item {
        padding: 6px 2px;
        min-height: 50px;
    }

    .bottom-nav-icon {
        width: 20px;
        height: 20px;
    }

    .bottom-nav-label {
        font-size: 9px;
    }

    .bottom-nav {
        padding-bottom: env(safe-area-inset-bottom, 0);
    }
}

/* ============================
   Regular Screen 376-480px
   ============================ */
@media (min-width: 376px) and (max-width: 480px) {
    .bottom-nav-item {
        padding: 8px 4px;
    }

    .bottom-nav-icon {
        width: 22px;
        height: 22px;
    }

    .bottom-nav-label {
        font-size: 10px;
    }
}

/* ============================
   Large Screen / Small Tablet 481-768px
   ============================ */
@media (min-width: 481px) and (max-width: 768px) {
    .bottom-nav-item {
        padding: 10px 8px;
        min-height: 60px;
    }

    .bottom-nav-icon {
        width: 24px;
        height: 24px;
    }

    .bottom-nav-label {
        font-size: 11px;
    }
}

/* ============================
   Landscape Mode Adaptation
   ============================ */
@media (max-height: 500px) and (orientation: landscape) {
    .bottom-nav {
        padding-top: 2px;
        padding-bottom: env(safe-area-inset-bottom, 2px);
    }

    .bottom-nav-item {
        padding: 2px 4px;
        min-height: 44px;
        gap: 0;
    }

    .bottom-nav-icon {
        width: 18px;
        height: 18px;
    }

    .bottom-nav-label {
        font-size: 9px;
    }
}

/* ============================
   Shortcuts Help Panel
   ============================ */
.shortcuts-help {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-modal);
    animation: fadeIn 0.2s ease;
}

.shortcuts-card {
    background: var(--bg-surface);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    padding: var(--space-8);
    max-width: 400px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
}

.shortcuts-card h3 {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: var(--space-5);
    color: var(--text-primary);
    text-align: center;
}

.shortcuts-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    margin-bottom: var(--space-5);
}

.shortcut-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-md);
}

.shortcut-item:hover {
    background: var(--neutral-50);
}

[data-theme="dark"] .shortcut-item:hover {
    background: var(--neutral-800);
}

.shortcut-item kbd {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 28px;
    padding: 0 var(--space-2);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 600;
    font-family: var(--font-sans);
    color: var(--text-secondary);
    box-shadow: 0 1px 0 var(--border);
}

.shortcut-item span {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.shortcuts-card .btn {
    display: block;
    margin: 0 auto;
}

/* ============================
   Settings Page
   ============================ */
.settings-page {
    max-width: 600px;
    margin: 0 auto;
}

/* ============================
   Reading Statistics Dashboard
   ============================ */
.stats-page {
    max-width: 900px;
    margin: 0 auto;
}

/* Summary Cards Grid */
.stats-summary-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-4);
    margin-bottom: var(--space-8);
}

.stats-summary-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    text-align: center;
    transition: all var(--transition-base);
}

.stats-summary-card:hover {
    border-color: var(--primary-200);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.stats-summary-icon {
    font-size: 1.75rem;
    margin-bottom: var(--space-2);
}

.stats-summary-value {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.3;
    margin-bottom: var(--space-1);
}

.stats-summary-label {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    font-weight: 500;
}

/* Chart Cards */
.stats-chart-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: var(--space-6);
    margin-bottom: var(--space-5);
}

.stats-chart-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--space-5);
}

/* Weekly Bar Chart */
.stats-bar-chart {
    display: flex;
    align-items: flex-end;
    justify-content: space-around;
    height: 180px;
    gap: var(--space-3);
    padding: var(--space-2) 0;
}

.stats-bar-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
    height: 100%;
    gap: var(--space-2);
}

.stats-bar-wrapper {
    flex: 1;
    width: 100%;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    background: var(--neutral-50);
    border-radius: var(--radius-md);
    padding: var(--space-1);
    position: relative;
}

[data-theme="dark"] .stats-bar-wrapper {
    background: var(--neutral-800);
}

.stats-bar {
    width: 60%;
    max-width: 40px;
    background: linear-gradient(to top, var(--primary-500), var(--primary-300));
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    transition: height 0.4s ease;
    min-height: 4px;
}

.stats-bar-label {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    font-weight: 500;
}

.stats-bar-value {
    font-size: 0.7rem;
    color: var(--text-tertiary);
}

/* Monthly Trend Chart */
.stats-trend-chart {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    height: 120px;
    gap: 2px;
    padding: var(--space-2) 0;
}

.stats-trend-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
    height: 100%;
    gap: var(--space-1);
}

.stats-trend-wrapper {
    flex: 1;
    width: 100%;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.stats-trend-bar {
    width: 100%;
    max-width: 8px;
    background: linear-gradient(to top, var(--accent-400), var(--accent-200));
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    transition: height 0.3s ease;
    min-height: 2px;
}

.stats-trend-label {
    font-size: 0.65rem;
    color: var(--text-tertiary);
}

/* Reading Goal */
.stats-goal {
    padding: var(--space-2) 0;
}

.stats-goal-header {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: var(--space-3);
}

.stats-goal-bar {
    width: 100%;
    height: 12px;
    background: var(--neutral-100);
    border-radius: var(--radius-full);
    overflow: hidden;
    margin-bottom: var(--space-2);
}

[data-theme="dark"] .stats-goal-bar {
    background: var(--neutral-800);
}

.stats-goal-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-500), var(--accent));
    border-radius: var(--radius-full);
    transition: width 0.5s ease;
}

.stats-goal-text {
    font-size: 0.8rem;
    color: var(--text-tertiary);
    text-align: center;
}

/* Recent Finished Books */
.stats-books-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.stats-book-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    background: var(--bg);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    border: 1px solid transparent;
}

.stats-book-item:hover {
    background: var(--primary-50);
    border-color: var(--primary-200);
}

[data-theme="dark"] .stats-book-item:hover {
    background: var(--primary-900);
    border-color: var(--primary-50);
}

.stats-book-icon {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    background: var(--primary-100);
    color: var(--primary-700);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    font-weight: 700;
    flex-shrink: 0;
}

[data-theme="dark"] .stats-book-icon {
    background: var(--primary-50);
    color: var(--primary-400);
}

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

.stats-book-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.stats-book-meta {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    margin-top: 2px;
}

.stats-empty {
    text-align: center;
    padding: var(--space-8) 0;
    color: var(--text-tertiary);
    font-size: 0.9rem;
}

/* Responsive Stats */
@media (max-width: 768px) {
    .stats-summary-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: var(--space-3);
    }

    .stats-summary-card {
        padding: var(--space-4);
    }

    .stats-summary-value {
        font-size: 1.1rem;
    }

    .stats-bar-chart {
        height: 150px;
    }

    .stats-trend-chart {
        height: 100px;
    }

    .stats-chart-card {
        padding: var(--space-4);
    }
}

@media (max-width: 480px) {
    .stats-summary-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: var(--space-2);
    }

    .stats-summary-card {
        padding: var(--space-3);
    }

    .stats-summary-icon {
        font-size: 1.4rem;
    }

    .stats-summary-value {
        font-size: 1rem;
    }

    .stats-summary-label {
        font-size: 0.7rem;
    }

    .stats-bar-chart {
        height: 130px;
        gap: var(--space-1);
    }

    .stats-bar-value {
        font-size: 0.6rem;
    }

    .stats-trend-chart {
        height: 90px;
    }
}

.settings-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: var(--space-6);
    margin-bottom: var(--space-4);
}

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

.settings-card-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--space-3);
}

/* ============================
   Language Selector
   ============================ */
.lang-selector {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.lang-selector select {
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    background: var(--bg);
    color: var(--text-primary);
    cursor: pointer;
}

/* ============================
   Scrollbar
   ============================ */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--neutral-300);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--neutral-400);
}

[data-theme="dark"]::-webkit-scrollbar-thumb {
    background: var(--neutral-600);
}

/* ============================
   Book Cover Fallback
   ============================ */
.book-cover-fallback {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    inset: 0;
    overflow: hidden;
    font-size: 2rem;
    color: white;
    text-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.book-cover-fallback svg {
    width: 100%;
    height: 100%;
}

/* ============================
   Mobile Bottom Navigation Bar
   ============================ */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: calc(var(--z-sticky) + 1);
    display: none;
    background: rgba(255,255,255,0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom, 0);
    box-shadow: 0 -2px 10px rgba(0,0,0,0.05);
}

[data-theme="dark"] .bottom-nav {
    background: rgba(36,36,36,0.95);
    border-top-color: var(--border);
    box-shadow: 0 -2px 10px rgba(0,0,0,0.2);
}

.bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    padding: 8px 4px;
    min-height: 56px;
    color: var(--text-tertiary);
    text-decoration: none;
    transition: all var(--transition-fast);
    position: relative;
    gap: 2px;
    -webkit-tap-highlight-color: transparent;
}

.bottom-nav-item::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%) scaleX(0);
    width: 40px;
    height: 2px;
    background: var(--primary-500);
    border-radius: 0 0 2px 2px;
    transition: transform var(--transition-fast);
}

.bottom-nav-item.active::before {
    transform: translateX(-50%) scaleX(1);
}

.bottom-nav-icon {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
    transition: all var(--transition-fast);
}

.bottom-nav-label {
    font-size: 10px;
    font-weight: 500;
    line-height: 1.2;
    white-space: nowrap;
    transition: all var(--transition-fast);
}

.bottom-nav-item.active {
    color: var(--primary-600);
}

[data-theme="dark"] .bottom-nav-item.active {
    color: var(--primary-400);
}

.bottom-nav-item:active {
    opacity: 0.7;
}

/* ============================
   PDF Viewer Styles
   ============================ */

/* PDF Container */
.pdf-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: var(--space-4);
    background: var(--bg);
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.pdf-container::-webkit-scrollbar {
    width: 6px;
}

.pdf-container::-webkit-scrollbar-track {
    background: transparent;
}

.pdf-container::-webkit-scrollbar-thumb {
    background: var(--neutral-300);
    border-radius: 3px;
}

[data-theme="dark"] .pdf-container::-webkit-scrollbar-thumb {
    background: var(--neutral-600);
}

/* PDF Canvas Wrapper */
.pdf-canvas-wrapper {
    position: relative;
    display: inline-block;
    margin: 0 auto;
    box-shadow: var(--shadow-lg);
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: white;
}

[data-reader-theme="dark"] .pdf-canvas-wrapper,
[data-reader-theme="night"] .pdf-canvas-wrapper {
    background: #1a1a1a;
}

[data-reader-theme="sepia"] .pdf-canvas-wrapper {
    background: #f4ecd8;
}

[data-reader-theme="eye-comfort"] .pdf-canvas-wrapper {
    background: #f5eddc;
}

/* PDF Canvas */
.pdf-canvas {
    display: block;
    background: white;
}

/* PDF Text Layer (for text selection) */
.pdf-text-layer {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    overflow: hidden;
    opacity: 1;
    line-height: 1;
    pointer-events: auto;
}

.pdf-text-layer span {
    position: absolute;
    white-space: pre;
    cursor: text;
    transform-origin: 0% 0%;
    color: transparent;
    user-select: text;
    -webkit-user-select: text;
}

.pdf-text-layer ::selection {
    background: rgba(255, 215, 0, 0.3);
}

[data-reader-theme="dark"] .pdf-text-layer ::selection,
[data-reader-theme="night"] .pdf-text-layer ::selection {
    background: rgba(100, 149, 237, 0.4);
}

/* PDF Loading State */
.pdf-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-3);
    padding: var(--space-12);
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.pdf-loading .spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--neutral-200);
    border-top-color: var(--primary-500);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

[data-theme="dark"] .pdf-loading .spinner {
    border-color: var(--neutral-700);
}

/* PDF Toolbar (additional controls) */
.pdf-toolbar-controls {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex-shrink: 0;
}

.pdf-page-input {
    width: 48px;
    padding: var(--space-1) var(--space-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg);
    color: var(--text-primary);
    font-size: 0.85rem;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.pdf-page-input:focus {
    outline: none;
    border-color: var(--primary-400);
    box-shadow: 0 0 0 2px rgba(255, 215, 0, 0.15);
}

.pdf-page-separator {
    font-size: 0.8rem;
    color: var(--text-tertiary);
}

.pdf-zoom-controls {
    display: flex;
    align-items: center;
    gap: 2px;
}

.pdf-zoom-btn {
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1rem;
    cursor: pointer;
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
}

.pdf-zoom-btn:hover {
    background: var(--neutral-100);
    color: var(--text-primary);
}

[data-theme="dark"] .pdf-zoom-btn:hover {
    background: var(--neutral-800);
}

.pdf-zoom-level {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    min-width: 48px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.pdf-fit-btn {
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background: var(--bg-surface);
    color: var(--text-secondary);
    font-size: 0.75rem;
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: var(--font-sans);
}

.pdf-fit-btn:hover {
    border-color: var(--primary-300);
    color: var(--primary-600);
}

.pdf-fit-btn.active {
    background: var(--primary-500);
    border-color: var(--primary-500);
    color: var(--neutral-900);
}

/* Theme-specific PDF backgrounds */
[data-reader-theme="dark"] .pdf-container,
[data-reader-theme="night"] .pdf-container {
    background: var(--neutral-900);
}

[data-reader-theme="sepia"] .pdf-container {
    background: #faf6ed;
}

[data-reader-theme="eye-comfort"] .pdf-container {
    background: #f5eddc;
}

/* Responsive PDF */
@media (max-width: 768px) {
    .pdf-container {
        padding: var(--space-2);
    }

    .pdf-canvas-wrapper {
        max-width: 100%;
    }

    .pdf-toolbar-controls {
        gap: var(--space-1);
    }

    .pdf-zoom-level {
        display: none;
    }

    .pdf-fit-btn {
        padding: 2px var(--space-2);
        font-size: 0.7rem;
    }
}

@media (max-width: 480px) {
    .pdf-page-input {
        width: 40px;
        font-size: 0.8rem;
    }

    .pdf-zoom-btn {
        width: 28px;
        height: 28px;
        font-size: 0.9rem;
    }
}

/* ============================
   Admin Batch Upload
   ============================ */

/* Drop Zone */
.upload-drop-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-10) var(--space-6);
    text-align: center;
    cursor: pointer;
    transition: all var(--transition-fast);
    background: var(--bg);
    margin-bottom: var(--space-6);
}

.upload-drop-zone:hover,
.upload-drop-zone.dragover {
    border-color: var(--primary-400);
    background: var(--primary-50);
}

[data-theme="dark"] .upload-drop-zone:hover,
[data-theme="dark"] .upload-drop-zone.dragover {
    background: var(--primary-900);
}

.upload-drop-icon {
    font-size: 2.5rem;
    margin-bottom: var(--space-3);
}

.upload-drop-title {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--space-2);
    font-size: 1rem;
}

.upload-drop-hint {
    color: var(--text-tertiary);
    font-size: 0.85rem;
    margin-bottom: var(--space-2);
}

.upload-drop-label {
    color: var(--accent);
    font-weight: 500;
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.upload-drop-label:hover {
    color: var(--accent-600);
}

.upload-drop-formats {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    background: var(--neutral-100);
    display: inline-block;
    padding: var(--space-1) var(--space-3);
    border-radius: var(--radius-full);
}

[data-theme="dark"] .upload-drop-formats {
    background: var(--neutral-800);
}

/* Progress Bar */
.upload-progress-wrap {
    margin-bottom: var(--space-6);
}

.upload-progress-bar-bg {
    width: 100%;
    height: 8px;
    background: var(--neutral-200);
    border-radius: var(--radius-full);
    overflow: hidden;
    margin-bottom: var(--space-2);
}

[data-theme="dark"] .upload-progress-bar-bg {
    background: var(--neutral-700);
}

.upload-progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-500), var(--accent));
    border-radius: var(--radius-full);
    transition: width 0.3s ease;
}

.upload-progress-text {
    text-align: center;
    color: var(--text-tertiary);
    font-size: 0.8rem;
    font-weight: 500;
}

/* Upload Table */
.upload-table-wrap {
    overflow-x: auto;
    margin-bottom: var(--space-6);
}

.upload-table {
    min-width: 640px;
}

.upload-table th {
    white-space: nowrap;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    padding: var(--space-3) var(--space-4);
    background: var(--neutral-50);
    border-bottom: 1px solid var(--border);
}

[data-theme="dark"] .upload-table th {
    background: var(--neutral-800);
}

.upload-table td {
    padding: var(--space-3) var(--space-4);
    vertical-align: middle;
    font-size: 0.85rem;
}

.upload-empty {
    text-align: center;
    color: var(--text-tertiary);
    padding: var(--space-8) var(--space-4);
    font-size: 0.9rem;
}

/* File cell with cover */
.upload-file-name {
    display: block;
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-primary);
    font-weight: 500;
}

.upload-cover-thumb {
    width: 36px;
    height: 48px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    margin-bottom: var(--space-1);
    display: block;
    box-shadow: var(--shadow-sm);
}

.upload-cover-placeholder {
    width: 36px;
    height: 48px;
    border-radius: var(--radius-sm);
    background: var(--neutral-200);
    color: var(--text-tertiary);
    font-size: 0.6rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: var(--space-1);
}

[data-theme="dark"] .upload-cover-placeholder {
    background: var(--neutral-700);
}

.upload-error-tip {
    font-size: 0.75rem;
    color: #E53E3E;
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-top: 2px;
}

/* Editable inputs in table */
.upload-edit-input {
    width: 100%;
    min-width: 120px;
    padding: var(--space-1) var(--space-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    background: var(--bg);
    color: var(--text-primary);
    font-family: var(--font-sans);
    transition: border-color var(--transition-fast);
}

.upload-edit-input:focus {
    outline: none;
    border-color: var(--primary-400);
    box-shadow: 0 0 0 2px rgba(255,215,0,0.12);
}

/* Format badges */
.upload-format-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: var(--radius-full);
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.upload-format-badge.epub { background: rgba(255,215,0,0.15); color: var(--primary-800); }
.upload-format-badge.pdf { background: rgba(244,67,54,0.12); color: #C62828; }
.upload-format-badge.mobi { background: rgba(76,175,80,0.12); color: #2E7D32; }
.upload-format-badge.txt { background: rgba(158,158,158,0.15); color: var(--neutral-700); }

[data-theme="dark"] .upload-format-badge.epub { background: rgba(255,215,0,0.2); color: var(--primary-300); }

/* ============================================
   PWA Install Banner Styles
   ============================================ */

.pwa-install-banner {
    display: flex;
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(120%);
    z-index: 10000;
    background: linear-gradient(135deg, #FFD700, #FFA500);
    color: #4A3B2A;
    border-radius: 16px;
    padding: 14px 20px;
    align-items: center;
    gap: 14px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.15);
    max-width: 90vw;
    width: 360px;
    font-size: 0.95rem;
    font-weight: 500;
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.pwa-install-banner.show {
    transform: translateX(-50%) translateY(0);
}

.pwa-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    flex-shrink: 0;
}

.pwa-text {
    flex: 1;
    line-height: 1.4;
}

.pwa-title {
    font-weight: 700;
    font-size: 1rem;
}

.pwa-desc {
    font-size: 0.8rem;
    opacity: 0.9;
}

.pwa-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.pwa-install-btn,
.pwa-dismiss-btn {
    border: none;
    border-radius: 10px;
    padding: 8px 14px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s;
}

.pwa-install-btn:hover,
.pwa-dismiss-btn:hover {
    opacity: 0.85;
}

.pwa-install-btn {
    background: #4A3B2A;
    color: #FFD700;
}

.pwa-dismiss-btn {
    background: rgba(74, 59, 42, 0.15);
    color: #4A3B2A;
}

@media (max-width: 420px) {
    .pwa-install-banner {
        width: calc(100vw - 20px);
        padding: 10px 14px;
        bottom: 70px;
    }
    .pwa-icon { font-size: 1.4rem; }
    .pwa-title { font-size: 0.85rem; }
    .pwa-desc { font-size: 0.7rem; }
    .pwa-install-btn, .pwa-dismiss-btn { padding: 5px 10px; font-size: 0.75rem; }
}

/* ============================================
   Admin Panel Styles
   ============================================ */

.admin-layout {
    display: flex;
    min-height: calc(100vh - 56px);
    position: relative;
}

.admin-sidebar {
    width: 240px;
    background: var(--bg);
    border-right: 1px solid var(--border);
    padding: 20px 0;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 56px;
    left: 0;
    bottom: 0;
    z-index: 100;
    transition: transform 0.3s ease;
}

.admin-sidebar-header {
    padding: 0 20px 20px;
    border-bottom: 1px solid var(--border);
}

.admin-sidebar-header h2 {
    font-size: 1.1rem;
    margin: 0 0 4px;
}

.admin-sidebar-header p {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin: 0;
}

.admin-nav {
    flex: 1;
    padding: 10px 0;
    overflow-y: auto;
}

.admin-nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    cursor: pointer;
    transition: background 0.2s ease;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.admin-nav-item:hover {
    background: var(--bg-secondary);
}

.admin-nav-item.active {
    background: var(--primary-50);
    color: var(--primary-700);
    font-weight: 600;
}

.admin-nav-icon {
    font-size: 1.1rem;
    width: 24px;
    text-align: center;
}

.admin-sidebar-footer {
    padding: 15px 20px;
    border-top: 1px solid var(--border);
}

.admin-back-link {
    display: inline-block;
    padding: 8px 16px;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.85rem;
    transition: all 0.2s ease;
}

.admin-back-link:hover {
    background: var(--primary-50);
    color: var(--primary-700);
}

.admin-main {
    flex: 1;
    margin-left: 240px;
    padding: 24px;
    min-height: calc(100vh - 56px);
}

.admin-menu-toggle {
    display: none;
    position: fixed;
    top: 72px;
    left: 12px;
    z-index: 200;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 8px 12px;
    cursor: pointer;
    font-size: 1.2rem;
}

.admin-sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.3);
    z-index: 99;
}

.admin-sidebar.open ~ .admin-sidebar-overlay {
    display: block;
}

.admin-page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 12px;
}

.admin-page-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0 0 4px;
}

.admin-page-subtitle {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin: 0;
}

.admin-btn {
    padding: 8px 20px;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.2s ease;
}

.admin-btn-primary {
    background: var(--primary-500);
    color: #fff;
}

.admin-btn-primary:hover {
    background: var(--primary-600);
}

.admin-btn-secondary {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.admin-btn-secondary:hover {
    background: var(--bg-tertiary);
}

.admin-btn-danger {
    background: rgba(239,68,68,0.1);
    color: #dc2626;
}

.admin-btn-danger:hover {
    background: rgba(239,68,68,0.2);
}

.admin-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.admin-card-body {
    padding: 20px;
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
}

.admin-table th,
.admin-table td {
    text-align: left;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    font-size: 0.85rem;
}

.admin-table th {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.admin-table tbody tr:last-child td {
    border-bottom: none;
}

.admin-table tbody tr:hover {
    background: var(--bg-secondary);
}

.admin-badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 600;
}

.admin-badge-success {
    background: rgba(34,197,94,0.1);
    color: #15803d;
}

.admin-badge-danger {
    background: rgba(239,68,68,0.1);
    color: #b91c1c;
}

.admin-perm-tag {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 600;
}

.admin-perm-tag-admin {
    background: rgba(255,184,0,0.15);
    color: var(--primary-700);
}

.admin-perm-tag-editor {
    background: rgba(34,197,94,0.1);
    color: #15803d;
}

.admin-perm-tag-reader {
    background: var(--bg-secondary);
    color: var(--text-secondary);
}

.admin-stat-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.admin-stat-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
}

.admin-stat-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.admin-stat-value {
    font-size: 1.5rem;
    font-weight: 700;
}

/* Admin settings form */
.admin-form-group {
    margin-bottom: 20px;
}

.admin-form-label {
    display: block;
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text-primary);
}

.admin-form-input,
.admin-form-select {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg);
    color: var(--text-primary);
    font-size: 0.9rem;
    transition: border-color 0.2s ease;
}

.admin-form-input:focus,
.admin-form-select:focus {
    outline: none;
    border-color: var(--primary-400);
    box-shadow: 0 0 0 3px rgba(255,184,0,0.15);
}

/* Admin log */
.admin-log-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.admin-log-item {
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.85rem;
}

.admin-log-item:last-child {
    border-bottom: none;
}

.admin-log-time {
    color: var(--text-tertiary);
    font-size: 0.8rem;
    margin-bottom: 4px;
}

/* Admin modal */
.admin-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.admin-modal {
    background: var(--bg);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
}

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

.admin-modal-title {
    font-size: 1.1rem;
    font-weight: 700;
    margin: 0;
}

.admin-modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0 4px;
}

.admin-modal-body {
    padding: 24px;
}

.admin-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 16px 24px;
    border-top: 1px solid var(--border);
}

/* Admin mobile */
@media (max-width: 768px) {
    .admin-sidebar {
        transform: translateX(-100%);
    }
    .admin-sidebar.open {
        transform: translateX(0);
    }
    .admin-sidebar.open ~ .admin-sidebar-overlay {
        display: block;
    }
    .admin-menu-toggle {
        display: block;
    }
    .admin-main {
        margin-left: 0;
        padding: 60px 16px 24px;
    }
    .admin-page-header {
        flex-direction: column;
    }
    .admin-table th:nth-child(4),
    .admin-table td:nth-child(4),
    .admin-table th:nth-child(5),
    .admin-table td:nth-child(5) {
        display: none;
    }
    .admin-stat-cards {
        grid-template-columns: 1fr 1fr;
    }
}

/* ============================================
   Mobile Reader - Tap Zone Navigation
   ============================================ */

@media (max-width: 768px) {
    .reader-body {
        position: relative;
    }

    /* Hide page buttons on mobile */
    .reader-page-btn {
        display: none !important;
    }

    /* Tap zones for page navigation */
    .reader-tap-zone {
        position: absolute;
        top: 0;
        bottom: 0;
        width: 35%;
        z-index: 50;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }

    .reader-tap-zone:hover {
        background: rgba(0,0,0,0.02);
    }

    .reader-tap-zone:active {
        background: rgba(0,0,0,0.04);
    }

    .reader-tap-zone.prev {
        left: 0;
    }

    .reader-tap-zone.next {
        right: 0;
    }

    /* Center area for settings */
    .reader-tap-zone.center {
        left: 35%;
        right: 35%;
        width: 30%;
        background: none;
    }
}
[data-theme="dark"] .upload-format-badge.pdf { background: rgba(244,67,54,0.2); color: #EF5350; }
[data-theme="dark"] .upload-format-badge.mobi { background: rgba(76,175,80,0.2); color: #66BB6A; }
[data-theme="dark"] .upload-format-badge.txt { background: rgba(158,158,158,0.2); color: var(--neutral-400); }

/* Status indicators */
.upload-status {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 10px;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 600;
}

.upload-status::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    display: inline-block;
}

.upload-status.pending { background: var(--neutral-100); color: var(--text-tertiary); }
.upload-status.pending::before { background: var(--neutral-400); }

.upload-status.processing { background: var(--primary-50); color: var(--primary-700); }
.upload-status.processing::before { background: var(--primary-500); animation: pulse 1.2s infinite; }

.upload-status.success { background: rgba(34,197,94,0.1); color: #15803d; }
.upload-status.success::before { background: #22c55e; }

.upload-status.error { background: rgba(239,68,68,0.1); color: #b91c1c; }
.upload-status.error::before { background: #ef4444; }

[data-theme="dark"] .upload-status.pending { background: var(--neutral-800); }
[data-theme="dark"] .upload-status.processing { background: var(--primary-900); color: var(--primary-300); }
[data-theme="dark"] .upload-status.success { background: rgba(34,197,94,0.15); color: #4ade80; }
[data-theme="dark"] .upload-status.error { background: rgba(239,68,68,0.15); color: #f87171; }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* Upload actions */
.upload-actions {
    display: flex;
    gap: var(--space-2);
    flex-wrap: nowrap;
}

.upload-actions-bar {
    display: flex;
    gap: var(--space-3);
    flex-wrap: wrap;
    margin-bottom: var(--space-6);
}

/* Manifest Preview */
.manifest-preview {
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    overflow: hidden;
    background: var(--bg);
}

.manifest-preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-3) var(--space-4);
    background: var(--neutral-50);
    border-bottom: 1px solid var(--border-light);
    flex-wrap: wrap;
    gap: var(--space-2);
}

[data-theme="dark"] .manifest-preview-header {
    background: var(--neutral-800);
}

.manifest-preview-title {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-primary);
}

.manifest-preview-tip {
    font-size: 0.75rem;
    color: var(--text-tertiary);
}

.manifest-preview-textarea {
    width: 100%;
    min-height: 240px;
    padding: var(--space-4);
    border: none;
    background: var(--bg);
    color: var(--text-primary);
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.8rem;
    line-height: 1.6;
    resize: vertical;
    outline: none;
}

/* Mobile responsive for upload */
@media (max-width: 768px) {
    .upload-drop-zone {
        padding: var(--space-6) var(--space-4);
    }

    .upload-drop-icon {
        font-size: 2rem;
    }

    .upload-drop-title {
        font-size: 0.9rem;
    }

    .upload-table-wrap {
        margin: 0 calc(-1 * var(--space-4));
        padding: 0 var(--space-4);
    }

    .upload-table th,
    .upload-table td {
        padding: var(--space-2) var(--space-3);
    }

    .upload-file-name {
        max-width: 120px;
    }

    .upload-edit-input {
        min-width: 80px;
        font-size: 0.8rem;
    }

    .upload-cover-thumb,
    .upload-cover-placeholder {
        width: 28px;
        height: 38px;
    }

    .manifest-preview-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .manifest-preview-textarea {
        min-height: 180px;
    }
}

@media (max-width: 480px) {
    .upload-actions-bar {
        flex-direction: column;
    }

    .upload-actions-bar .admin-btn {
        width: 100%;
    }

    .upload-format-badge {
        font-size: 0.6rem;
        padding: 1px 6px;
    }

    .upload-status {
        font-size: 0.7rem;
        padding: 1px 8px;
    }
}

