/* Header/sidebar helper rules were cleaned and consolidated further down in this file. */
/* Base variables and global styles */
:root { 
    color-scheme: dark light; 
    --bg: #0e0e10; 
    --panel: #17171a; 
    --text: #e6e6ea; 
    --muted: #a0a0a8; 
    --accent: #ff3d6e; 
    --accent-2: #5cc8ff; 
    --border: #2a2a30;
    --gradient: linear-gradient(135deg, var(--accent), var(--accent-2));
    --sidebar-width: 280px;
    --header-height: 64px;
}

/* --- Page-specific small tweaks --- */
/* spacing between controls (clear button) and the history list */
.controls {
    margin-bottom: 1.25rem; /* adds breathing room above the history list */
}

/* Bookmark confirmation modal (custom, replaces browser confirm()) */
.bookmark-confirm-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1200;
}
.bookmark-confirm-overlay.active {
    display: flex;
}
.bookmark-confirm-modal {
    background: #fff;
    color: #111827;
    border-radius: 8px;
    padding: 16px 18px;
    width: 320px;
    max-width: calc(100% - 32px);
    box-shadow: 0 10px 30px rgba(2,6,23,0.2);
    text-align: left;
}
.bookmark-confirm-modal h3 {
    margin: 0 0 8px 0;
    font-size: 16px;
}
.bookmark-confirm-modal p {
    margin: 0 0 12px 0;
    color: #6b7280;
    font-size: 14px;
}
.bookmark-confirm-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}
.bookmark-confirm-actions .btn {
    min-width: 90px;
}

/* Small tweak: make the bookmark remove button more visible without relying on native tooltips */
.bookmark-remove {
    background: rgba(0,0,0,0.6);
    border: none;
    color: #fff;
    width: 36px;
    height: 36px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    right: 8px;
    top: 8px;
    cursor: pointer;
}
.bookmark-remove svg { pointer-events: none; }

* { box-sizing: border-box; }

body { 
    margin: 0; 
    font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif; 
    background: linear-gradient(180deg, #0e0e10 0%, #1a1a1f 100%); 
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
    position: relative;
    padding-left: 0;
    transition: padding-left 0.3s ease;
}

.container { 
    max-width: 1200px; 
    margin: 0 auto; 
    padding: 24px;
    transition: all 0.3s ease;
    position: relative;
    z-index: 1;
}

/* Modern Header Design */
.main-header {
    position: sticky;
    top: 0;
    z-index: 1200;
    height: var(--header-height);
    background: linear-gradient(135deg, rgba(14, 14, 16, 0.95) 0%, rgba(23, 23, 26, 0.98) 100%);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
}

.header-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    max-width: 1400px;
    margin: 0 auto;
    height: 100%;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

/* User menu: username above admin tag, logout on the far right */
.user-menu {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-menu .user-info-col {
    display: flex;
    flex-direction: row; /* show username and admin link side-by-side */
    align-items: center;
    gap: 8px;
    line-height: 1;
}

.user-menu .username {
    font-weight: 600;
    font-size: 0.95rem;
}

.user-menu .admin-btn {
    font-size: 0.82rem;
    margin-top: 2px;
}

.logout-btn {
    margin-left: 12px;
    background: transparent;
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
}

@media (max-width: 768px) {
    /* On small screens keep brand left, but right items stack sensibly */
    .header-container {
        padding: 0 12px;
    }

    .header-right {
        gap: 8px;
    }

    /* header-stats removed from header; stats now live in sidebar */

    .user-menu .user-info-col { align-items: center; gap: 6px; }
}

/* Modern Sidebar Toggle */
.sidebar-toggle {
    position: relative;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: 12px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 44px;
    height: 44px;
    gap: 4px;
}

.sidebar-toggle:hover {
    background: rgba(255, 255, 255, 0.08);
    transform: scale(1.05);
}

.hamburger-line {
    width: 24px;
    height: 3px;
    background: var(--text);
    border-radius: 2px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    transform-origin: center;
}

.sidebar-toggle:hover .hamburger-line {
    background: var(--accent);
}

/* Hamburger animation when sidebar is open */
body.sidebar-open .hamburger-line:nth-child(1) {
    transform: rotate(45deg) translate(6px, 6px);
}

body.sidebar-open .hamburger-line:nth-child(2) {
    opacity: 0;
    transform: scaleX(0);
}

body.sidebar-open .hamburger-line:nth-child(3) {
    transform: rotate(-45deg) translate(6px, -6px);
}

/* Header Stats */
.sidebar-stats {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    background: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0.01));
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px 18px; /* increased padding for breathing room */
    box-shadow: 0 6px 18px rgba(2,6,23,0.12);
    backdrop-filter: blur(6px);
    margin-bottom: 12px;
}

.sidebar-stats .stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    min-width: 72px;
}

.sidebar-stats .stat-value {
    font-size: 18px;
    font-weight: 800;
    color: var(--accent);
    line-height: 1;
}

.sidebar-stats .stat-label {
    font-size: 12px;
    color: var(--muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    margin-top: 4px;
}

.stat-divider {
    width: 1px;
    height: 24px;
    background: var(--border);
    margin: 0 4px;
}

/* Modern Sidebar Design */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 1199;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-overlay.active {
    opacity: 1;
    visibility: visible;
}

.main-sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: 320px;
    height: 100vh;
    background: linear-gradient(180deg, var(--panel) 0%, rgba(23, 23, 26, 0.98) 100%);
    border-right: 1px solid var(--border);
    z-index: 1200;
    transform: translateX(-100%);
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 8px 0 32px rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(20px);
    display: flex;
    flex-direction: column;
}

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

/* Sidebar Header */
.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.02);
    backdrop-filter: blur(10px);
}

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

.sidebar-logo {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: var(--gradient);
    position: relative;
    overflow: hidden;
}

.sidebar-logo::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 50%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
    transform: skewX(-25deg);
    animation: shine 3s infinite;
}

.sidebar-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.5px;
}

.sidebar-close {
    background: transparent;
    border: none;
    color: var(--muted);
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-close:hover {
    background: rgba(255, 61, 110, 0.1);
    color: var(--accent);
    transform: rotate(90deg);
}

/* Sidebar Content */
.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px 0;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.sidebar-content::-webkit-scrollbar {
    width: 6px;
}

/* --- Manga detail page restyle (Ravenscans-like) --- */
.manga-page .summary-background {
    background: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0.01));
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    display: flex;
    gap: 20px;
    align-items: flex-start;
}

.manga-page .cover {
    flex: 0 0 180px;
    max-width: 180px;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 8px 30px rgba(2,6,23,0.45);
}
.manga-page .cover img { width: 100%; display: block; }

.manga-page .info {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.manga-page .info h1 { margin: 0; font-size: 1.6rem; letter-spacing: -0.4px; }
.manga-page .meta-list { display: flex; gap: 16px; flex-wrap: wrap; color: var(--muted); }
.manga-page .meta-item { font-size: 0.95rem; }
.manga-page .genres { margin-top: 6px; }
.manga-page .genres .genre-tag { display: inline-block; margin-right: 8px; margin-bottom: 8px; padding: 6px 10px; background: rgba(255,255,255,0.02); border-radius: 999px; color: var(--muted); text-decoration: none; font-size: 0.9rem; }

/* Read button near cover for quick access */
.manga-actions { margin-top: 8px; display: flex; gap: 8px; }
.manga-actions .btn { padding: 8px 12px; }

.manga-actions-bottom { margin: 18px 0; display: flex; justify-content: flex-start; }
.read-btn { font-size: 1.05rem; padding: 12px 18px; border-radius: 10px; align-items: center; display: inline-flex; gap: 10px; }

/* Chapters panel: clean list with large clickable rows */
.chapters-panel { margin-top: 18px; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); background: linear-gradient(180deg, rgba(255,255,255,0.01), transparent); }
.chapters-header { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.chapters-list { max-height: 420px; overflow: auto; padding: 8px 12px; }
.chapter-item { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-radius: 8px; margin-bottom: 8px; background: transparent; color: var(--text); text-decoration: none; border: 1px solid transparent; transition: all 0.14s ease; }
.chapter-item:hover { background: rgba(255,255,255,0.02); transform: translateY(-2px); border-color: rgba(255,255,255,0.02); }
.chapter-item .chapter-title { font-weight: 600; }
.chapter-item .release-date { color: var(--muted); font-size: 0.9rem; }

/* Chapter navigation controls */
.nav-controls { display: flex; gap: 8px; align-items: center; margin: 12px 0; }
.nav-controls .btn { padding: 8px 10px; }

@media (max-width: 900px) {
    .manga-page .summary-background { flex-direction: column; align-items: center; text-align: center; }
    .manga-page .cover { width: 160px; max-width: 160px; }
    .manga-page .meta-list { justify-content: center; }
    .manga-actions-bottom { justify-content: center; }
}

/* Ensure the bottom Read Now button matches global primary button styles */
.manga-actions-bottom .btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.3s ease;
}
.manga-actions-bottom .btn.primary {
    background: var(--accent);
    color: white;
}
.manga-actions-bottom .btn.primary:hover {
    background: #e63461;
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(255, 61, 110, 0.3);
}

/* Small helper to visually de-emphasize the summary when collapsed */
.summary-panel #summary { max-height: 120px; overflow: hidden; }
.summary-panel.expanded #summary { max-height: none; }

/* --- Reader / Chapter page styles --- */
.chapter .chapter-header { margin-bottom: 12px; }
.container.chapter { max-width: 900px; }
.nav-controls { position: sticky; top: 74px; background: linear-gradient(180deg, rgba(14,14,16,0.7), rgba(14,14,16,0.35)); padding: 10px; z-index: 900; backdrop-filter: blur(6px); border-radius: 8px; }
#pages { display: flex; flex-direction: column; gap: 0; align-items: center; padding: 0; }
#pages img { max-width: 920px; width: 100%; height: auto; box-shadow: none; border-radius: 0; margin-bottom: 0; margin-top: 0; padding: 0; vertical-align: top; }

@media (max-width: 940px) {
    #pages img { max-width: 100%; }
    .container.chapter { padding: 14px; }
}


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

.sidebar-content::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

.sidebar-content::-webkit-scrollbar-thumb:hover {
    background: var(--accent);
}

.sidebar-section {
    margin-bottom: 32px;
    padding: 0 24px;
}

.section-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.section-title svg {
    opacity: 0.7;
}

/* Navigation Items */
.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: var(--muted);
    text-decoration: none;
    border-radius: 12px;
    font-weight: 500;
    font-size: 14px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.nav-item::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--gradient);
    transform: scaleY(0);
    transition: transform 0.3s ease;
    border-radius: 0 2px 2px 0;
}

.nav-item:hover,
.nav-item.active {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text);
    transform: translateX(4px);
}

.nav-item:hover::before,
.nav-item.active::before {
    transform: scaleY(1);
}

.nav-item.active {
    background: linear-gradient(135deg, rgba(255, 61, 110, 0.1), rgba(92, 200, 255, 0.1));
    color: var(--accent);
    font-weight: 600;
}

.nav-item svg {
    flex-shrink: 0;
    opacity: 0.8;
    transition: all 0.3s ease;
}

.nav-item:hover svg,
.nav-item.active svg {
    opacity: 1;
    transform: scale(1.1);
}

/* Quick Actions */
.quick-actions {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    align-items: start;
}

/* If there is only one action button, center it */
.quick-actions:has(.action-btn:nth-child(1):nth-last-child(1)),
.quick-actions:has(.nav-item:nth-child(1):nth-last-child(1)) {
    grid-template-columns: 1fr;
    justify-items: center;
}

.action-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 16px 8px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--muted);
    text-decoration: none;
    font-size: 12px;
    font-weight: 600;
    text-align: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.action-btn:hover {
    background: var(--gradient);
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(255, 61, 110, 0.2);
    border-color: transparent;
}

.action-btn svg {
    opacity: 0.8;
    transition: all 0.3s ease;
}

.action-btn:hover svg {
    opacity: 1;
    transform: scale(1.1);
}

/* Show More Button */
.show-more-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    margin-top: 12px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.show-more-btn:hover {
    background: var(--gradient);
    border-color: transparent;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(255, 61, 110, 0.2);
}

.show-more-btn:hover svg {
    transform: translateX(4px);
}

/* Sidebar Footer */
.sidebar-footer {
    padding: 20px 24px;
    border-top: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.02);
}

.footer-info {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.footer-text {
    font-size: 12px;
    color: var(--muted);
    font-weight: 500;
}

.footer-version {
    font-size: 11px;
    color: var(--accent);
    background: rgba(255, 61, 110, 0.1);
    padding: 4px 8px;
    border-radius: 6px;
    font-weight: 600;
}

/* Body states */
body.sidebar-open {
    overflow: hidden;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    /* On small screens show a compact stats box (values only) so users can still
       see the important counts. We hide the verbose labels to save space and
       shrink branding to make room. */
    .header-stats {
        display: flex;
        gap: 6px;
        padding: 6px 8px;
        border-radius: 8px;
        background: rgba(255,255,255,0.03);
        align-items: center;
        min-width: 0;
    }
    .header-stats .stat-item { gap: 2px; }
    .header-stats .stat-value { font-size: 13px; font-weight: 700; }
    /* hide labels to keep the header tidy on tiny screens */
    .header-stats .stat-label { display: none; }
    .stat-divider { display: none; }

    /* reduce brand text to save horizontal space but keep it visible (truncated) */
    .brand-text {
        display: inline-block;
        max-width: 120px;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
        font-size: 14px;
        font-weight: 700;
        vertical-align: middle;
    }
    .brand-text .accent { display: inline; font-size: 14px; }
    .logo-icon { width: 32px; height: 32px; }
    
    /* Move stats into the sidebar for narrow viewports: hide header stats and show sidebar stats */
    @media (max-width: 480px) {
        .header-stats { display: none !important; }
        .sidebar-stats { display: flex !important; gap: 8px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); margin-bottom: 12px; }
        .sidebar-stats .stat-value { font-size: 16px; font-weight: 700; color: var(--accent); }
        .sidebar-stats .stat-label { font-size: 12px; color: var(--muted); display: inline-block; margin-left: 6px; }
        .sidebar-stats .stat-item { display: flex; align-items: center; gap: 6px; }
        .sidebar-stats .stat-divider { display: block; width: 1px; height: 28px; background: var(--border); margin: 0 8px; }

        /* On very small screens, allow the brand text to show fully rather than truncating it.
           The header-stats are hidden here so there's room for the full name. */
        .brand-text {
            max-width: none !important;
            white-space: normal !important;
            overflow: visible !important;
            font-size: 16px !important;
        }
    }
    .main-sidebar {
        width: 280px;
    }
    
    .quick-actions {
        grid-template-columns: 1fr;
    }
    
    .sidebar-section {
        padding: 0 20px;
    }
    
    .sidebar-header {
        padding: 16px 20px;
    }
    
    .sidebar-footer {
        padding: 16px 20px;
    }
}

@media (max-width: 480px) {
    .header-container {
        padding: 0 16px;
    }
    
    .main-sidebar {
        width: 100vw;
    }
}

/* Modern Brand in Header */
.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: var(--gradient);
    position: relative;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 16px rgba(255, 61, 110, 0.3);
}

.logo-icon::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 50%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
    transform: skewX(-25deg);
    animation: shine 3s infinite;
}

.brand:hover .logo-icon {
    transform: rotate(-8deg) scale(1.05);
    box-shadow: 0 6px 20px rgba(255, 61, 110, 0.4);
}

.brand-text {
    color: var(--text);
    text-decoration: none;
    font-size: 22px;
    font-weight: 800;
    letter-spacing: -0.5px;
    transition: all 0.3s ease;
}

.brand-text:hover {
    transform: scale(1.02);
}

.brand .accent {
    background: var(--gradient);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent;
    font-weight: 900;
}

@keyframes shine {
    0% { left: -100%; }
    20%, 100% { left: 200%; }
}

/* Navigation Links */
.nav-links {
    display: flex;
    gap: 32px;
    margin-left: auto;
    position: relative;
}

.nav-link {
    color: var(--muted);
    text-decoration: none;
    font-weight: 500;
    transition: all 0.3s ease;
    font-size: 15px;
    padding: 8px 12px;
    border-radius: 8px;
    position: relative;
    overflow: hidden;
}

.nav-link:hover {
    color: var(--text);
    background: rgba(255, 255, 255, 0.05);
}

.nav-link.active {
    color: var(--text);
}

.nav-link.active::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 2px;
    background: var(--gradient);
    border-radius: 2px;
    transform: scaleX(0);
    transform-origin: center;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.nav-link.active::after {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--gradient);
    opacity: 0.1;
    border-radius: 8px;
}

.nav-link.active:hover::before {
    transform: scaleX(1);
}

/* Default Header */
.default-header {
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    position: sticky;
    top: 0;
    z-index: 100;
}

.default-header .nav-link {
    display: inline-block;
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    font-weight: 500;
    color: var(--text);
    transition: all 0.3s ease;
}

.default-header .nav-link:hover,
.default-header .nav-link.active {
    background: var(--gradient);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(255, 61, 110, 0.2);
}

/* Home Header */
.home-header {
    position: relative;
    background: linear-gradient(45deg, var(--bg), rgba(255, 61, 110, 0.1));
    border-bottom: none;
    /* make the hero fit the viewport while accounting for the sticky header */
    min-height: calc(100vh - var(--header-height));
    display: flex;
    flex-direction: column;
    justify-content: center;
    text-align: center;
    margin-bottom: 40px;
    overflow: hidden;
    box-sizing: border-box;
    /* a small top inset so the visual elements don't touch the very top */
    padding-top: 12px;
}

.home-header::before,
.home-header::after {
    content: '';
    position: absolute;
    width: 300px;
    height: 300px;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.1;
    z-index: 0;
}

.home-header::before {
    background: var(--accent);
    top: -100px;
    left: -100px;
}

.home-header::after {
    background: var(--accent-2);
    bottom: -100px;
    right: -100px;
}

.hero-section {
    /* reduced padding so the hero fits comfortably on smaller viewports */
    padding: 48px 20px;
    max-width: 800px;
    margin: 0 auto;
    position: relative;
    z-index: 1;
}

.hero-section h1 {
    font-size: 56px;
    margin-bottom: 20px;
    background: var(--gradient);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent;
    text-shadow: 0 2px 10px rgba(255, 61, 110, 0.2);
    animation: fadeInUp 1s ease-out;
}

/* Make the hero scale down on smaller screens so it doesn't overflow */
@media (max-width: 900px) {
    .home-header { min-height: calc(100vh - var(--header-height)); }
    .hero-section { padding: 36px 18px; }
    .hero-section h1 { font-size: 44px; }
    .hero-subtitle { font-size: 18px; }
}

@media (max-width: 480px) {
    .hero-section { padding: 28px 16px; }
    .hero-section h1 { font-size: 32px; }
    .hero-subtitle { font-size: 15px; margin-bottom: 20px; }
}

.hero-subtitle {
    font-size: 20px;
    color: var(--muted);
    margin-bottom: 40px;
    animation: fadeInUp 1s ease-out 0.2s backwards;
}

.hero-search {
    position: relative;
    animation: fadeInUp 1s ease-out 0.4s backwards;
}

.hero-search .search-wrapper {
    max-width: 600px;
    margin: 0 auto;
}

.hero-search input {
    font-size: 18px;
    padding: 20px 28px 20px 56px;
    border-radius: 16px;
    background: rgba(16, 17, 20, 0.8);
    backdrop-filter: blur(10px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    transform-origin: center;
    animation: scaleIn 0.6s ease-out 0.6s backwards;
}

.hero-search .search-wrapper::before {
    left: calc(50% - 260px);
}

.hero-search input:focus {
    transform: scale(1.02);
}

/* Legacy sidebar styles removed — consolidated fixed sidebar rules are defined above. */

.controls { display: flex; align-items: center; gap: 12px; justify-content: center; }
.controls-right { display: flex; align-items: center; gap: 12px; }
.filter-btn {
    background: rgba(255,255,255,0.04);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 8px 12px;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 600;
}
.filter-btn:hover { background: rgba(255,255,255,0.06); }
.filter-panel {
    /* Inline collapsible panel that pushes page content down */
    width: 100%;
    max-width: 1200px;
    margin: 12px 0 18px 0;
    background: linear-gradient(180deg, rgba(23,23,26,0.98), rgba(23,23,26,0.96));
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    max-height: 0;
    transition: max-height 260ms ease, padding 180ms ease;
    padding: 0 0;
}

.filter-panel.open { max-height: 520px; padding: 12px 0; }
.filter-panel-inner { padding: 18px; position: relative; }
.filter-close { position: absolute; right: 12px; top: 12px; background: transparent; border: none; color: var(--muted); font-size: 18px; cursor: pointer; }
.filter-title { margin: 0 0 12px 0; font-size: 18px; color: var(--text); }
.filter-search input { width: 100%; padding: 12px 14px; border-radius: 10px; background: rgba(16,17,20,0.8); border: 1px solid var(--border); color: var(--text); }
.genre-filters { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; max-height: 220px; overflow: auto; padding-right: 6px; }
.genre-item { display: inline-flex; align-items: center; gap: 8px; background: rgba(255,255,255,0.03); padding: 6px 8px; border-radius: 8px; font-size: 13px; }
.filter-actions { display:flex; gap: 8px; margin-top: 14px; justify-content: flex-end; }
.btn { padding: 8px 12px; border-radius: 10px; background: rgba(255,255,255,0.03); color: var(--text); border: 1px solid var(--border); cursor: pointer; }
.btn.primary { background: var(--gradient); border: none; color: white; }

/* Sort select styling */
#sort-select {
    background: rgba(255,255,255,0.03);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 8px 10px;
    border-radius: 8px;
    margin-left: 6px;
    font-weight: 600;
}
#sort-select:focus { box-shadow: 0 6px 20px rgba(0,0,0,0.4); outline: none; }

@media (max-width: 800px) {
    .filter-panel { right: 12px; left: 12px; top: 64px; width: auto; }
}

/* Make select and its options readable on dark background
   and show a clear chevron on the right */
#sort-select, select {
    color: var(--text) !important;
    background: var(--panel) !important;
    border: 1px solid var(--border) !important;
    -webkit-appearance: none !important;
    appearance: none !important;
    /* space for the chevron on the right */
    padding: 8px 36px 8px 10px !important;
    background-repeat: no-repeat !important;
    background-position: right 12px center !important;
    background-size: 14px 14px !important;
    text-overflow: ellipsis;
    /* lightweight chevron SVG (encoded) - uses a neutral muted color */
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none'><path stroke='%23a0a0a8' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.6' d='M5.5 7.5l4 4 4-4'/></svg>") !important;
}

/* Make the chevron more visible on hover/focus */
#sort-select:hover, #sort-select:focus, select:hover, select:focus {
    box-shadow: 0 6px 20px rgba(0,0,0,0.4);
    outline: none;
    /* change the SVG color by swapping background-image to an accent-colored SVG */
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none'><path stroke='%23ff3d6e' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.6' d='M5.5 7.5l4 4 4-4'/></svg>") !important;
}

#sort-select option, select option {
    background: var(--panel) !important;
    color: var(--text) !important;
}

.genre-tag .genre-count {
    display: inline-block;
    background: rgba(255, 255, 255, 0.1);
    padding: 2px 6px;
    border-radius: 10px;
    font-size: 11px;
    margin-left: 6px;
    transition: all 0.2s ease;
}

.genre-tag:hover .genre-count {
    background: rgba(255, 255, 255, 0.2);
}

.genre-loading {
    color: var(--muted);
    text-align: center;
    padding: 10px;
    font-size: 13px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
}



.error-message {
    font-size: 13px;
    color: var(--accent);
    text-align: center;
    padding: 10px;
    background: rgba(255, 61, 110, 0.1);
    border-radius: 8px;
    margin: 0;
}



/* Genre Popup */
.genre-popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(10px);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.genre-popup-overlay.active {
    opacity: 1;
    visibility: visible;
}

.genre-popup {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    overflow: hidden;
    transform: scale(0.9) translateY(20px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.genre-popup-overlay.active .genre-popup {
    transform: scale(1) translateY(0);
}

.popup-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 24px;
    border-bottom: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.02);
}

.popup-header h3 {
    margin: 0;
    font-size: 24px;
    font-weight: 700;
    background: var(--gradient);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent;
}

.close-popup {
    background: none;
    border: none;
    color: var(--muted);
    font-size: 28px;
    font-weight: 300;
    cursor: pointer;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.close-popup:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text);
    transform: rotate(90deg);
}

.popup-content {
    padding: 24px;
    max-height: calc(80vh - 100px);
    overflow-y: auto;
}

.popup-content::-webkit-scrollbar {
    width: 8px;
}

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

.popup-content::-webkit-scrollbar-thumb {
    background-color: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

.popup-content::-webkit-scrollbar-thumb:hover {
    background-color: var(--accent);
}

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

.popup-genre-tag {
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    color: var(--text);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.3s ease;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 1px solid transparent;
}

.popup-genre-tag:hover {
    background: var(--gradient);
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(255, 61, 110, 0.2);
    border-color: rgba(255, 255, 255, 0.1);
}

.popup-genre-tag .genre-count {
    display: inline-block;
    background: rgba(255, 255, 255, 0.1);
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    transition: all 0.2s ease;
}

.popup-genre-tag:hover .genre-count {
    background: rgba(255, 255, 255, 0.2);
}



/* Grid Layout */
#manga-grid,
.manga-grid { 
    display: grid; 
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); 
    gap: 20px; 
}

/* Manga Card */
.manga-card { 
    display: flex; 
    flex-direction: column; 
    background-color: var(--panel); 
    border-radius: 12px; 
    overflow: hidden; 
    border: 1px solid var(--border); 
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

.manga-card::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 12px;
    background: var(--gradient);
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 1;
    pointer-events: none;
}

.manga-card:hover { 
    transform: translateY(-5px) scale(1.02); 
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
}

.manga-card:hover::after {
    opacity: 0.1;
}

.manga-card .thumb-container { 
    position: relative; 
}

.manga-card .thumb { 
    width: 100%; 
    height: auto;
    aspect-ratio: 175 / 238; /* keep thumbnails proportional (approx. common cover ratio) */
    max-height: 320px; /* prevent overly tall images on large cards */
    object-fit: cover; 
    display: block; 
    background-color: var(--bg);
    transition: transform 0.3s ease;
}

.manga-card:hover .thumb {
    transform: scale(1.05);
}

.manga-card .summary { 
    padding: 12px; 
    display: flex; 
    flex-direction: column; 
    gap: 8px; 
}

.manga-card .title { 
    margin: 0; 
    font-size: 15px; 
    line-height: 1.4; 
    font-weight: 600; 
    height: calc(15px * 1.4 * 2);
    overflow: hidden; 
}

.manga-card .title a { 
    color: var(--text); 
    text-decoration: none; 
    transition: color 0.2s; 
    display: -webkit-box;
    display: box; 
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    box-orient: vertical;
    overflow: hidden; 
    text-overflow: ellipsis;
}

.manga-card .title a:hover { 
    color: var(--accent); 
}

.manga-card .chapter-list { 
    display: flex; 
    flex-direction: column; 
    gap: 8px; 
    border-top: 1px solid var(--border); 
    margin-top: 8px;
    padding-top: 12px; 
}

.manga-card .chapter-list:empty {
    display: none;
}

.manga-card .chapter-item { 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    font-size: 13px; 
}

.manga-card .chapter-link { 
    color: var(--muted); 
    text-decoration: none; 
    white-space: nowrap; 
    overflow: hidden; 
    text-overflow: ellipsis; 
    transition: color 0.2s; 
}

.manga-card .chapter-link:hover { 
    color: var(--accent-2); 
}

.manga-card .release-date { 
    font-size: 12px; 
    color: var(--muted); 
    flex-shrink: 0; 
    padding-left: 8px; 
}

/* Search */
.search-wrapper { 
    display: flex; 
    justify-content: center; 
    margin-bottom: 24px; 
    position: relative;
}

.search-wrapper::before {
    content: '🔍';
    position: absolute;
    left: calc(50% - 180px);
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
    pointer-events: none;
    z-index: 1;
}

.search-wrapper input { 
    width: 100%; 
    max-width: 400px; 
    background: #101114; 
    color: var(--text); 
    border: 2px solid var(--border); 
    border-radius: 12px; 
    padding: 12px 16px 12px 40px; 
    font-size: 15px; 
    transition: all 0.3s ease;
}

.search-wrapper input:focus { 
    outline: none; 
    border-color: var(--accent); 
    box-shadow: 0 0 20px rgba(255, 61, 110, 0.15);
    transform: scale(1.02);
}

/* Pagination */
.pagination { 
    display: flex; 
    justify-content: center; 
    align-items: center; 
    gap: 8px; 
    margin-top: 24px;
    margin-bottom: 24px; 
}

.pagination .pagination-btn { 
    background: #22232a; 
    color: var(--text); 
    border: 2px solid var(--border); 
    border-radius: 8px; 
    padding: 10px 16px; 
    font-size: 14px; 
    font-weight: 500;
    cursor: pointer; 
    transition: all 0.3s ease; 
    text-decoration: none;
}

.pagination .pagination-btn:hover:not([disabled]) { 
    background: var(--gradient);
    border-color: transparent;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(255, 61, 110, 0.2);
    color: #fff;
}

.pagination .pagination-btn[disabled] { 
    opacity: 0.5; 
    cursor: not-allowed; 
    pointer-events: none; 
}

.pagination .page-info { 
    font-size: 14px; 
    color: var(--muted); 
}

/* Footer */
.footer { 
    text-align: center; 
    color: var(--muted); 
    padding: 40px;
    margin-top: 40px;
    border-top: 1px solid var(--border);
}

.footer-content {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border-radius: 20px;
    background: var(--panel);
    border: 1px solid var(--border);
}

.footer-text {
    font-size: 14px;
    font-weight: 500;
}

/* Manga Page Styles */
.manga-page .container {
    max-width: 1000px;
    margin: 24px auto;
    padding: 0 24px;
}

.summary-background {
    position: relative;
    border-radius: 16px;
    overflow: hidden;
    margin-bottom: 32px;
    border: 1px solid var(--border);
    background: var(--panel);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
}

.summary-background::before {
    content: '';
    position: absolute;
    inset: 0;
    background-size: cover;
    background-position: center;
    filter: blur(20px) brightness(0.3);
    transform: scale(1.1);
}

.summary-panel {
    position: relative;
    padding: 32px;
    background: linear-gradient(to bottom, rgba(14, 14, 16, 0.8), rgba(14, 14, 16, 0.95));
    border-radius: 16px;
}

.manga-info {
    display: flex;
    gap: 32px;
    margin-bottom: 24px;
    overflow: hidden;
}

.cover img {
    width: 220px;
    height: 320px;
    border-radius: 12px;
    object-fit: cover;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    border: 2px solid rgba(255, 255, 255, 0.1);
    transition: transform 0.3s ease;
}

.cover img:hover {
    transform: scale(1.02);
}

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

.info h1 {
    font-size: 36px;
    font-weight: 800;
    margin: 0 0 16px;
    text-transform: uppercase;
    background: var(--gradient);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent;
}

.meta-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    font-size: 15px;
    color: var(--muted);
    margin-top: 16px;
}

.meta-item strong {
    color: var(--text);
    font-weight: 600;
    margin-right: 8px;
}

.meta-item a {
    color: var(--accent-2);
    text-decoration: none;
    transition: color 0.2s;
}

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

.genres {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 16px;
}

.genre-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.06);
    color: var(--text);
    padding: 8px 12px;
    border-radius: 16px;
    font-size: 12px;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid var(--border);
    margin-bottom: 6px;
    margin-right: 6px;
}

.genre-tag:hover {
    background: var(--gradient);
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(255, 61, 110, 0.25);
    border-color: transparent;
}

.genre-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 12px;
    max-height: 200px;
    overflow-y: auto;
    padding-right: 8px;
}

.genre-tags::-webkit-scrollbar {
    width: 4px;
}

.genre-tags::-webkit-scrollbar-track {
    background: transparent;
}

.genre-tags::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}

.genre-tags::-webkit-scrollbar-thumb:hover {
    background: var(--accent);
}

#summary {
    font-size: 16px;
    line-height: 1.6;
    color: var(--muted);
    margin-top: 24px;
    max-height: 6.2em;
    overflow: hidden;
    position: relative;
    transition: max-height 0.5s ease-in-out;
}

#summary.expanded {
    max-height: 1000px;
}

#summary #desc {
    margin: 0;
}

#read-more {
    color: var(--accent-2);
    cursor: pointer;
    font-weight: 600;
    margin-top: 12px;
    display: inline-block;
    transition: color 0.2s;
}

#read-more:hover {
    color: var(--accent);
}

/* Chapters Panel */
.chapters-panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

.chapters-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 24px;
    border-bottom: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.02);
}

.chapters-header h2 {
    margin: 0;
    font-size: 24px;
    font-weight: 700;
    background: var(--gradient);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent;
}

.chapter-controls {
    display: flex;
    gap: 12px;
}

.chapter-controls input,
.chapter-controls button {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 16px;
    font-size: 14px;
    transition: all 0.2s ease;
}

.chapter-controls input {
    width: 200px;
}

.chapter-controls input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(255, 61, 110, 0.1);
}

.chapter-controls button {
    cursor: pointer;
    font-weight: 600;
}

.chapter-controls button:hover {
    background: var(--gradient);
    border-color: transparent;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(255, 61, 110, 0.2);
}

.chapters-list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    max-height: 600px;
    overflow-y: auto;
    padding: 16px;
}

.chapters-list::-webkit-scrollbar {
    width: 8px;
}

.chapters-list::-webkit-scrollbar-track {
    background: transparent;
}

.chapters-list::-webkit-scrollbar-thumb {
    background-color: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

.chapters-list::-webkit-scrollbar-thumb:hover {
    background-color: var(--accent);
}

.chapter-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.02);
    transition: all 0.2s ease;
    color: var(--text);
    text-decoration: none;
    font-weight: 500;
    border: 1px solid transparent;
}

.chapter-item:hover {
    background: var(--gradient);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(255, 61, 110, 0.2);
}

.chapter-item .chapter-title {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chapter-item .release-date {
    font-size: 12px;
    color: var(--muted);
    margin-left: 12px;
}

.chapter-item:hover .release-date {
    color: rgba(255, 255, 255, 0.8);
}

.breadcrumbs {
    font-size: 14px;
    color: var(--muted);
    margin-bottom: 24px;
}

.breadcrumbs a {
    color: var(--accent-2);
    text-decoration: none;
    transition: color 0.2s;
}

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

@media (max-width: 768px) {
    .manga-info {
        flex-direction: column;
        align-items: center;
        text-align: center;
        gap: 24px;
    }

    .cover img {
        width: 180px;
        height: 260px;
    }

    .info h1 {
        font-size: 28px;
    }

    .meta-list {
        align-items: center;
    }

    .genres {
        justify-content: center;
    }

    .chapters-header {
        flex-direction: column;
        gap: 16px;
    }

    .chapter-controls {
        width: 100%;
    }

    .chapter-controls input {
        flex: 1;
    }

    .chapters-list {
        grid-template-columns: 1fr;
    }
}

/* Utils */
p.muted { 
    color: var(--muted); 
    text-align: center; 
}

h1 { 
    margin-bottom: 16px; 
    text-align: center; 
}

/* Animations */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Responsive */
@media (max-width: 768px) {
    body.sidebar-expanded {
        padding-left: 0;
    }
    
    .genre-popup {
        width: 95%;
        margin: 20px;
    }
    
    .genre-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 10px;
    }
    
    .popup-header {
        padding: 20px;
    }
    
    .popup-content {
        padding: 20px;
    }
}

@media (max-width: 600px) {
    #manga-grid, .manga-grid { 
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); 
        gap: 12px; 
    }
    .manga-card .thumb { 
        height: auto;
        aspect-ratio: 175 / 238;
        max-height: 220px;
    }
}

/* Chapter page specific styles (moved from chapter.html inline styles) */
.container.chapter { max-width: 800px; margin: 20px auto; padding: 12px; background-color: var(--panel); border-radius: 8px; border: 1px solid var(--border); }

/* Header override for pages that include default header */
header.site { position: sticky; top: 0; z-index: 10; background: linear-gradient(180deg, rgba(23, 23, 26, 0.95), rgba(23, 23, 26, 0.85)); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); }
header.site .wrap { display: flex; align-items: center; justify-content: space-between; padding: 14px 24px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; }
.brand .logo { width: 28px; height: 28px; border-radius: 6px; background: var(--gradient); display: inline-block; }
.brand a { color: var(--text); text-decoration: none; font-size: 18px; }

.chapter-header { text-align: center; padding: 16px; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.chapter-header h1 { margin: 0 0 10px; font-size: 26px; font-weight: 700; text-transform: uppercase; }
.chapter-header .breadcrumbs { font-size: 14px; color: var(--muted); }
.chapter-header .breadcrumbs a { color: var(--accent-2); text-decoration: none; }
.chapter-header .breadcrumbs a:hover { text-decoration: underline; }
.chapter-header .breadcrumbs span { color: var(--text); }

.nav-controls { display: flex; justify-content: center; align-items: center; gap: 8px; padding: 16px 0; }
.nav-controls .btn, .nav-controls select { background-color: #22232a; color: var(--text); border: 1px solid #3a3a42; border-radius: 6px; padding: 8px 16px; font-size: 14px; font-weight: 600; cursor: pointer; text-decoration: none; transition: background-color 0.2s, color 0.2s; }
.nav-controls .btn:hover { background-color: var(--accent); color: #fff; }
.nav-controls select { min-width: 250px; appearance: none; background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e"); background-position: right 0.5rem center; background-repeat: no-repeat; background-size: 1.5em 1.5em; padding-right: 2.5rem; }

#pages { text-align: center; }
#pages img { max-width: 100%; display: block; margin: 0 auto; margin-bottom: 0; margin-top: 0; padding: 0; border-radius: 0; box-shadow: none; vertical-align: top; }

/* small utility: muted paragraph */
p.muted { color: var(--muted); text-align: center; }

/* Small utility helpers */
.hidden { display: none !important; }
.mt-20 { margin-top: 20px !important; }

/* Authentication Styles */
.auth-page {
    background: linear-gradient(135deg, #0e0e10 0%, #1a1a1f 50%, #2a1a2a 100%);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.auth-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.auth-form {
    background: var(--panel);
    padding: 48px;
    border-radius: 16px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border);
}

.auth-form h2 {
    text-align: center;
    margin: 0 0 32px;
    color: var(--text);
    font-weight: 700;
    font-size: 28px;
}

.form-group {
    margin-bottom: 24px;
}

.form-label {
    display: block;
    margin-bottom: 8px;
    color: var(--text);
    font-weight: 500;
    font-size: 14px;
}

.form-input, .form-textarea {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg);
    border: 2px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 16px;
    transition: all 0.3s ease;
}

.form-input:focus, .form-textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(255, 61, 110, 0.1);
}

.form-textarea {
    resize: vertical;
    min-height: 100px;
}

.checkbox-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.form-checkbox {
    width: auto;
}

.checkbox-label {
    margin: 0;
    cursor: pointer;
}

.form-errors {
    margin-top: 8px;
}

.error {
    color: #ff6b6b;
    font-size: 14px;
    display: block;
}

.auth-links {
    text-align: center;
    margin-top: 24px;
    padding-top: 24px;
    border-top: 1px solid var(--border);
}

.auth-links p {
    margin: 0;
    color: var(--muted);
}

.auth-links a {
    color: var(--accent);
    text-decoration: none;
}

.auth-links a:hover {
    text-decoration: underline;
}

/* User Menu Styles */
.user-menu {
    display: flex;
    align-items: center;
    gap: 12px;
}

.username {
    color: var(--text);
    font-weight: 500;
    font-size: 14px;
}

.logout-btn {
    color: var(--muted);
    text-decoration: none;
    font-size: 14px;
    transition: color 0.3s ease;
}

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

.auth-buttons {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Page Header Styles */
.page-header {
    text-align: center;
    margin-bottom: 48px;
}

.page-header h1 {
    margin: 0 0 8px;
    font-size: 36px;
    font-weight: 700;
    background: var(--gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.page-subtitle {
    color: var(--muted);
    font-size: 16px;
    margin: 0;
}

/* Auth Required Message */
.auth-required {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 400px;
}

.auth-message {
    text-align: center;
    background: var(--panel);
    padding: 48px;
    border-radius: 16px;
    border: 1px solid var(--border);
    max-width: 400px;
}

.auth-message svg {
    color: var(--muted);
    margin-bottom: 24px;
}

.auth-message h3 {
    margin: 0 0 12px;
    color: var(--text);
    font-size: 24px;
}

.auth-message p {
    color: var(--muted);
    margin: 0 0 24px;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 64px 24px;
}

.empty-state svg {
    color: var(--muted);
    margin-bottom: 24px;
}

.empty-state h3 {
    margin: 0 0 12px;
    color: var(--text);
    font-size: 24px;
}

.empty-state p {
    color: var(--muted);
    margin: 0 0 24px;
    font-size: 16px;
}

/* Bookmarks Grid */
.bookmarks-grid .manga-card {
    position: relative;
}

.bookmark-remove {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.7);
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #ff6b6b;
    transition: all 0.3s ease;
    opacity: 0;
}

.manga-card:hover .bookmark-remove {
    opacity: 1;
}

.bookmark-remove:hover {
    background: rgba(255, 107, 107, 0.2);
    transform: scale(1.1);
}

.bookmark-date {
    color: var(--muted);
    font-size: 12px;
    margin-top: 8px;
}

/* Reading History */
.history-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.history-item {
    display: flex;
    align-items: center;
    gap: 16px;
    background: var(--panel);
    padding: 16px;
    border-radius: 12px;
    border: 1px solid var(--border);
    transition: all 0.3s ease;
}

.history-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.history-thumb {
    flex-shrink: 0;
}

.history-thumb img {
    width: 60px;
    height: 80px;
    object-fit: cover;
    border-radius: 8px;
}

.history-content {
    flex: 1;
}

.history-title {
    margin: 0 0 8px;
    font-size: 16px;
    font-weight: 600;
}

.history-title a {
    color: var(--text);
    text-decoration: none;
}

.history-title a:hover {
    color: var(--accent);
}

.history-chapter {
    margin-bottom: 4px;
}

.chapter-link {
    color: var(--accent-2);
    text-decoration: none;
    font-weight: 500;
}

.chapter-link:hover {
    text-decoration: underline;
}

.history-date {
    color: var(--muted);
    font-size: 12px;
}

.history-actions {
    flex-shrink: 0;
}

.history-remove {
    background: transparent;
    border: none;
    color: var(--muted);
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    transition: all 0.3s ease;
}

.history-remove:hover {
    color: #ff6b6b;
    background: rgba(255, 107, 107, 0.1);
}

/* Categories */
.categories-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 24px;
}

.category-card {
    background: var(--panel);
    border-radius: 16px;
    padding: 24px;
    border: 1px solid var(--border);
    transition: all 0.3s ease;
}

.category-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.2);
}

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

.category-title {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
    color: var(--text);
}

.category-actions {
    display: flex;
    gap: 8px;
}

.category-delete {
    background: transparent;
    border: none;
    color: var(--muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.3s ease;
}

.category-delete:hover {
    color: #ff6b6b;
    background: rgba(255, 107, 107, 0.1);
}

.category-description {
    color: var(--muted);
    margin: 0 0 16px;
    font-size: 14px;
}

.category-manga {
    margin-bottom: 20px;
}

.manga-count {
    color: var(--muted);
    font-size: 14px;
    margin-bottom: 12px;
}

.manga-preview {
    display: flex;
    gap: 8px;
}

.manga-preview img {
    width: 40px;
    height: 50px;
    object-fit: cover;
    border-radius: 4px;
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
}

.modal-content {
    background: var(--panel);
    border-radius: 16px;
    padding: 32px;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
    z-index: 1;
    border: 1px solid var(--border);
}

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

.modal-header h3 {
    margin: 0;
    font-size: 24px;
    color: var(--text);
}

.modal-close {
    background: transparent;
    border: none;
    color: var(--muted);
    cursor: pointer;
    font-size: 24px;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.3s ease;
}

.modal-close:hover {
    color: var(--text);
    background: rgba(255, 255, 255, 0.1);
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 24px;
}

/* Manga Actions */
.manga-actions {
    margin-top: 24px;
    display: flex;
    gap: 12px;
}

.manga-actions .btn {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Button Styles */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: center;
}

.btn.primary {
    background: var(--accent);
    color: white;
}

.btn.primary:hover {
    background: #e63461;
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(255, 61, 110, 0.3);
}

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

.btn.secondary:hover {
    background: var(--border);
    transform: translateY(-1px);
}

.btn.full-width {
    width: 100%;
}

/* Responsive Design */
@media (max-width: 768px) {
    .auth-form {
        padding: 32px 24px;
    }
    
    .categories-grid {
        grid-template-columns: 1fr;
    }
    
    .history-item {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .history-thumb {
        align-self: center;
    }
    
    .user-menu {
        flex-direction: column;
        gap: 4px;
    }
    
    /* Default small-screen layout for auth areas (modals / empty states) */
    .auth-required .auth-buttons,
    .auth-message .auth-buttons {
        flex-direction: column;
        gap: 8px;
        align-items: stretch;
    }

    .auth-required .auth-buttons .btn,
    .auth-message .auth-buttons .btn {
        width: 100%;
        padding: 10px 16px;
    }

    /* Header-specific auth buttons: compact and side-by-side (wrap if needed) */
    .main-header .header-right .auth-buttons {
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 6px;
        align-items: center;
        justify-content: flex-end;
    }

    .main-header .header-right .auth-buttons .btn {
        width: auto; /* keep buttons compact in the header bar */
        padding: 8px 10px;
        font-size: 13px;
        white-space: nowrap;
        min-width: 72px;
    }
}

/* Final overrides to guarantee stacking order (placed at file end to beat legacy rules) */
:root { --header-height: 64px; }
header.site { position: sticky !important; top: 0 !important; z-index: 1200 !important; height: var(--header-height) !important; }
.sidebar { position: fixed !important; top: var(--header-height) !important; left: 0 !important; z-index: 1100 !important; }
.container, .home-container { position: relative; z-index: 1; }

/* Phone-specific tweaks: make history page compact and readable on small phones */
@media (max-width: 480px) {
    .container { padding: 12px; }

    /* Controls: make clear button span full width for easy tapping */
    .controls { margin-bottom: 12px; display: flex; gap: 8px; }
    .controls .btn { flex: 1 1 auto; padding: 10px 12px; font-size: 14px; }

    /* History list: show items in a compact row with tight spacing */
    .history-list { display: flex; flex-direction: column; gap: 10px; }

    .history-item {
        display: flex;
        flex-direction: row;
        align-items: center;
        gap: 12px;
        padding: 10px;
        border-radius: 10px;
    }

    .history-thumb img {
        width: 56px;
        height: 80px;
        object-fit: cover;
        border-radius: 6px;
    }

    .history-content {
        flex: 1 1 auto;
        min-width: 0; /* allow long titles to truncate */
    }

    .history-title { font-size: 15px; margin-bottom: 4px; }

    .history-chapter { font-size: 13px; color: var(--muted); margin-bottom: 2px; }

    .history-date { font-size: 12px; color: var(--muted); }

    /* Actions stay to the right but smaller */
    .history-actions { flex-shrink: 0; margin-left: 8px; }
    .history-remove { width: 36px; height: 36px; border-radius: 8px; }

    /* If the header control area has auth buttons, keep them side-by-side compactly */
    .main-header .header-right .auth-buttons .btn { padding: 8px 10px; }

    /* Reduce auth-required modal padding to fit smaller screens */
    .auth-message { padding: 24px; max-width: calc(100% - 24px); }
}

/* Stronger override to ensure Read Now matches primary buttons even if global rules appear later */
.manga-actions-bottom > a.btn.primary,
.manga-actions-bottom .btn.primary {
    display: inline-flex !important;
    align-items: center !important;
    gap: 8px !important;
    padding: 12px 24px !important;
    border: none !important;
    border-radius: 8px !important;
    font-size: 14px !important;
    font-weight: 600 !important;
    text-decoration: none !important;
    cursor: pointer !important;
    transition: all 0.3s ease !important;
    background: var(--accent) !important;
    color: white !important;
}
.manga-actions-bottom > a.btn.primary:hover,
.manga-actions-bottom .btn.primary:hover {
    background: #e63461 !important;
    transform: translateY(-1px) !important;
    box-shadow: 0 4px 16px rgba(255, 61, 110, 0.3) !important;
}

/* Utility visibility helpers for JS toggles (used by Read Now button) */
.hidden { display: none !important; }
.visible { display: inline-flex !important; }