/* ==================== CSS Variables - Modern Dark Theme ==================== */
:root {
    /* Primary Colors */
    --bg-primary: #0a0a0f;
    --bg-secondary: rgba(20, 20, 35, 0.8);
    --bg-card: rgba(30, 30, 50, 0.6);
    --bg-glass: rgba(255, 255, 255, 0.05);
    --bg-hover: rgba(255, 255, 255, 0.1);

    /* Accent Colors */
    --accent: #8b5cf6;
    --accent-hover: #a78bfa;
    --accent-glow: rgba(139, 92, 246, 0.3);
    --gradient-1: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --gradient-2: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    --gradient-accent: linear-gradient(135deg, #8b5cf6 0%, #ec4899 100%);

    /* Text Colors */
    --text-primary: #ffffff;
    --text-secondary: #a1a1aa;
    --text-muted: #52525b;

    /* Status Colors */
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;

    /* Utilities */
    --border-color: rgba(255, 255, 255, 0.1);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 8px 32px rgba(0, 0, 0, 0.4);
    --shadow-glow: 0 0 40px var(--accent-glow);
    --radius: 16px;
    --radius-sm: 10px;
    --radius-full: 9999px;
    --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-fast: 0.15s ease;

    /* Spacing */
    --nav-height: 60px;
    --tab-height: 70px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ==================== Reset & Base ==================== */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
    overflow-x: hidden;
    padding-bottom: calc(var(--tab-height) + var(--safe-bottom));
}

/* Background Gradient Effect */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 50vh;
    background: radial-gradient(ellipse at top, rgba(139, 92, 246, 0.15) 0%, transparent 70%);
    pointer-events: none;
    z-index: -1;
}

/* ==================== Navigation Bar ==================== */
.navbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--nav-height);
    background: var(--bg-secondary);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-color);
    z-index: 1000;
    transition: transform var(--transition), opacity var(--transition);
}

.navbar.hidden {
    transform: translateY(-100%);
    opacity: 0;
}

.nav-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 100%;
    padding: 0 16px;
    max-width: 1200px;
    margin: 0 auto;
}

.nav-title {
    font-size: 1.1rem;
    font-weight: 700;
    background: var(--gradient-accent);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 60%;
}

.nav-btn {
    background: var(--bg-glass);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.nav-btn:hover {
    background: var(--bg-hover);
    border-color: var(--accent);
    transform: scale(1.05);
}

.nav-btn:active {
    transform: scale(0.95);
}

/* ==================== Bottom Tab Navigation ==================== */
.tab-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(var(--tab-height) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: var(--bg-secondary);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: space-around;
    align-items: flex-start;
    padding-top: 8px;
    z-index: 1000;
}

.tab-bar.hidden {
    transform: translateY(100%);
}

.tab-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px 20px;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition);
    border-radius: var(--radius-sm);
    position: relative;
}

.tab-item.active {
    color: var(--accent);
}

.tab-item.active::before {
    content: '';
    position: absolute;
    top: -8px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 3px;
    background: var(--gradient-accent);
    border-radius: var(--radius-full);
}

.tab-item:hover {
    color: var(--text-primary);
}

.tab-item svg {
    width: 24px;
    height: 24px;
    transition: transform var(--transition);
}

.tab-item.active svg {
    transform: scale(1.1);
}

.tab-label {
    font-size: 0.7rem;
    font-weight: 500;
}

.tab-badge {
    position: absolute;
    top: 2px;
    right: 10px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    background: var(--danger);
    color: white;
    font-size: 0.65rem;
    font-weight: 700;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ==================== Main Content ==================== */
.main-content {
    padding-top: var(--nav-height);
    min-height: 100vh;
}

.page {
    display: none;
    padding: 20px 16px;
    max-width: 1200px;
    margin: 0 auto;
    animation: fadeIn 0.3s ease;
}

.page.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.reader-page {
    padding: 0;
    max-width: 100%;
}

/* ==================== Page Header ==================== */
.page-header {
    margin-bottom: 24px;
}

.page-title {
    font-size: 1.5rem;
    font-weight: 800;
    margin-bottom: 4px;
}

.page-subtitle {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* ==================== Search Bar ==================== */
.search-container {
    margin-bottom: 24px;
    position: relative;
}

.search-input {
    width: 100%;
    padding: 14px 20px 14px 48px;
    background: var(--bg-glass);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-full);
    color: var(--text-primary);
    font-size: 0.95rem;
    outline: none;
    transition: all var(--transition);
}

.search-input::placeholder {
    color: var(--text-muted);
}

.search-input:focus {
    border-color: var(--accent);
    box-shadow: var(--shadow-glow);
    background: var(--bg-secondary);
}

.search-icon {
    position: absolute;
    left: 18px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

/* ==================== Manga Grid ==================== */
.manga-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 16px;
}

@media (min-width: 640px) {
    .manga-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
        gap: 20px;
    }
}

@media (min-width: 1024px) {
    .manga-grid {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
        gap: 24px;
    }
}

/* ==================== Load More Button ==================== */
.load-more-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    max-width: 300px;
    margin: 32px auto 0;
    padding: 16px 32px;
    background: var(--gradient-accent);
    color: white;
    border: none;
    border-radius: var(--radius-full);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    box-shadow: var(--shadow-sm);
}

.load-more-btn:hover {
    transform: scale(1.02);
    box-shadow: var(--shadow-glow);
}

.load-more-btn:active {
    transform: scale(0.98);
}

.load-more-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none;
}

.load-more-btn.loading .load-more-text {
    display: none;
}

.load-more-btn .load-more-spinner {
    display: none;
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.load-more-btn.loading .load-more-spinner {
    display: block;
}

/* ==================== Manga Card ==================== */
.manga-card {
    position: relative;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    transition: all var(--transition);
}

.manga-card:hover {
    transform: translateY(-8px) scale(1.02);
    border-color: var(--accent);
    box-shadow: var(--shadow-md), var(--shadow-glow);
}

.manga-card:active {
    transform: scale(0.98);
}

.manga-cover-wrapper {
    position: relative;
    aspect-ratio: 2/3;
    overflow: hidden;
}

.manga-cover {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform var(--transition);
}

.manga-card:hover .manga-cover {
    transform: scale(1.1);
}

/* Reading Progress Indicator */
.progress-indicator {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: rgba(0, 0, 0, 0.5);
}

.progress-indicator-fill {
    height: 100%;
    background: var(--gradient-accent);
    transition: width var(--transition);
}

/* Bookmark Badge */
.bookmark-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 32px;
    height: 32px;
    background: var(--bg-secondary);
    backdrop-filter: blur(10px);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent);
    opacity: 0;
    transform: scale(0.8);
    transition: all var(--transition);
}

.manga-card.bookmarked .bookmark-badge,
.manga-card:hover .bookmark-badge {
    opacity: 1;
    transform: scale(1);
}

.manga-card.bookmarked .bookmark-badge {
    background: var(--accent);
    color: white;
}

.manga-info {
    padding: 12px;
}

.manga-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-bottom: 6px;
    line-height: 1.3;
}

.manga-chapter {
    font-size: 0.75rem;
    color: var(--accent);
    font-weight: 500;
    margin-bottom: 4px;
}

.manga-time {
    font-size: 0.7rem;
    color: var(--text-muted);
}

/* ==================== Loading States ==================== */
.loading,
.reader-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px 20px;
    text-align: center;
}

.loading.hidden,
.reader-loading.hidden {
    display: none;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 16px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.loading p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* Skeleton Loading */
.skeleton {
    background: linear-gradient(90deg,
            var(--bg-card) 0%,
            var(--bg-hover) 50%,
            var(--bg-card) 100%);
    background-size: 200% 100%;
    animation: shimmer 1.5s ease infinite;
    border-radius: var(--radius-sm);
}

@keyframes shimmer {
    0% {
        background-position: 200% 0;
    }

    100% {
        background-position: -200% 0;
    }
}

/* ==================== Manga Detail Page ==================== */
.manga-detail {
    padding: 0;
}

.detail-header {
    display: flex;
    gap: 20px;
    margin-bottom: 24px;
}

.detail-cover-wrapper {
    position: relative;
    flex-shrink: 0;
}

.detail-cover {
    width: 130px;
    aspect-ratio: 2/3;
    object-fit: cover;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
}

@media (min-width: 640px) {
    .detail-cover {
        width: 180px;
    }
}

.detail-bookmark-btn {
    position: absolute;
    bottom: -12px;
    left: 50%;
    transform: translateX(-50%);
    width: 48px;
    height: 48px;
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
    box-shadow: var(--shadow-sm);
}

.detail-bookmark-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    transform: translateX(-50%) scale(1.1);
}

.detail-bookmark-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.detail-info {
    flex: 1;
    min-width: 0;
}

.detail-title {
    font-size: 1.3rem;
    font-weight: 800;
    margin-bottom: 8px;
    line-height: 1.3;
}

.detail-meta {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.detail-genres {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 12px;
}

.genre-tag {
    padding: 4px 12px;
    background: var(--bg-glass);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-full);
    font-size: 0.7rem;
    color: var(--text-secondary);
    transition: all var(--transition);
}

.genre-tag:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.detail-description {
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.7;
    margin-bottom: 28px;
    padding: 16px;
    background: var(--bg-glass);
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
}

/* Chapter Section */
.chapter-section {
    margin-top: 24px;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.section-title {
    font-size: 1.1rem;
    font-weight: 700;
}

.chapter-count {
    font-size: 0.8rem;
    color: var(--text-muted);
    background: var(--bg-glass);
    padding: 4px 12px;
    border-radius: var(--radius-full);
}

.chapter-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chapter-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
}

.chapter-item:hover {
    background: var(--bg-hover);
    border-color: var(--accent);
    transform: translateX(4px);
}

.chapter-item.read {
    opacity: 0.6;
}

.chapter-title {
    font-size: 0.9rem;
    color: var(--text-primary);
    font-weight: 500;
}

.chapter-arrow {
    color: var(--text-muted);
    transition: transform var(--transition);
}

.chapter-item:hover .chapter-arrow {
    transform: translateX(4px);
    color: var(--accent);
}

/* ==================== Reader Page ==================== */
.reader-container {
    display: flex;
    flex-direction: column;
    background: #000;
    min-height: 100vh;
    width: 100%;
}

.reader-image {
    width: 100%;
    max-width: 100%;
    display: block;
}

/* Reader Controls */
.reader-controls {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.95));
    padding: 60px 16px calc(24px + var(--safe-bottom));
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition);
    z-index: 100;
}

.reader-controls.visible {
    opacity: 1;
    pointer-events: auto;
}

.chapter-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    max-width: 500px;
    margin: 0 auto;
}

.chapter-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--gradient-accent);
    color: white;
    border: none;
    padding: 14px 24px;
    border-radius: var(--radius-full);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    box-shadow: var(--shadow-sm);
}

.chapter-btn:hover {
    transform: scale(1.05);
    box-shadow: var(--shadow-glow);
}

.chapter-btn:active {
    transform: scale(0.95);
}

.chapter-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

.chapter-info {
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-align: center;
    flex: 1;
}

/* Reader Bookmark FAB */
.reader-bookmark-fab {
    position: fixed;
    top: calc(var(--nav-height) + 16px);
    right: 16px;
    width: 48px;
    height: 48px;
    background: var(--bg-secondary);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
    z-index: 50;
    opacity: 0;
}

.reader-bookmark-fab.visible {
    opacity: 1;
}

.reader-bookmark-fab:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.reader-bookmark-fab.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

/* ==================== Progress Bar ==================== */
.progress-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--border-color);
    z-index: 1001;
    opacity: 0;
    transition: opacity var(--transition);
}

.progress-bar.visible {
    opacity: 1;
}

.progress-fill {
    height: 100%;
    background: var(--gradient-accent);
    width: 0%;
    transition: width 0.1s linear;
}

/* ==================== Scroll to Top Button ==================== */
.scroll-top-btn {
    position: fixed;
    bottom: calc(var(--tab-height) + var(--safe-bottom) + 16px);
    right: 16px;
    width: 48px;
    height: 48px;
    background: var(--gradient-accent);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-md);
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.8);
    transition: all var(--transition);
    z-index: 50;
}

.scroll-top-btn.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

.scroll-top-btn:hover {
    transform: scale(1.1);
    box-shadow: var(--shadow-glow);
}

.scroll-top-btn:active {
    transform: scale(0.95);
}

/* ==================== Empty State ==================== */
.empty-state {
    text-align: center;
    padding: 80px 20px;
    color: var(--text-muted);
}

.empty-state svg {
    width: 80px;
    height: 80px;
    margin-bottom: 20px;
    opacity: 0.3;
}

.empty-state h3 {
    font-size: 1.1rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.empty-state p {
    font-size: 0.9rem;
}

/* ==================== History Card ==================== */
.history-card {
    display: flex;
    gap: 16px;
    padding: 16px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
    margin-bottom: 12px;
}

.history-card:hover {
    border-color: var(--accent);
    transform: translateX(4px);
}

.history-cover {
    width: 70px;
    aspect-ratio: 2/3;
    object-fit: cover;
    border-radius: var(--radius-sm);
    flex-shrink: 0;
}

.history-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.history-title {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.history-chapter {
    font-size: 0.8rem;
    color: var(--accent);
    margin-bottom: 8px;
}

.history-progress {
    height: 4px;
    background: var(--border-color);
    border-radius: var(--radius-full);
    overflow: hidden;
    margin-bottom: 6px;
}

.history-progress-fill {
    height: 100%;
    background: var(--gradient-accent);
}

.history-time {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.history-actions {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 8px;
}

.continue-btn {
    padding: 8px 16px;
    background: var(--gradient-accent);
    color: white;
    border: none;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.continue-btn:hover {
    transform: scale(1.05);
}

/* ==================== Clear History Button ==================== */
.clear-history-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 14px;
    background: transparent;
    border: 1px dashed var(--border-color);
    border-radius: var(--radius);
    color: var(--text-muted);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all var(--transition);
    margin-top: 16px;
}

.clear-history-btn:hover {
    border-color: var(--danger);
    color: var(--danger);
}

/* ==================== Custom Scrollbar ==================== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ==================== Touch Device Optimization ==================== */
@media (hover: none) and (pointer: coarse) {
    .manga-card:hover {
        transform: none;
        box-shadow: none;
    }

    .manga-card:hover .manga-cover {
        transform: none;
    }

    .chapter-item:hover {
        transform: none;
    }

    .history-card:hover {
        transform: none;
    }
}

/* Hide tab bar in reader mode */
body.reader-mode .tab-bar {
    transform: translateY(100%);
}

body.reader-mode {
    padding-bottom: 0;
}

body.reader-mode .main-content {
    padding-top: 0;
}

body.reader-mode .reader-page {
    padding: 0;
    max-width: 100%;
    margin: 0;
}