/* ===== CSS Variables & Reset ===== */
:root {
    --bg:           #0f0f0f;
    --bg-surface:   #1a1a2e;
    --bg-card:      #16213e;
    --bg-input:     #0f3460;
    --text:         #e0e0e0;
    --text-muted:   #888;
    --accent:       #e94560;
    --accent-hover: #ff6b81;
    --success:      #2ecc71;
    --warning:      #f39c12;
    --error:        #e74c3c;
    --info:         #3498db;
    --border:       #2a2a4a;
    --radius:       6px;
    --shadow:       0 2px 12px rgba(0,0,0,.4);
    --font:         'Segoe UI', system-ui, -apple-system, sans-serif;
    --font-mono:    'Cascadia Code', 'Fira Code', monospace;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; }
body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

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

/* ===== Layout ===== */
.container { 
    max-width: 1400px; 
    margin: 0 auto; 
    padding: 0 2rem; 
}
.main-content { 
    flex: 1; 
    padding: 2rem 0; 
    width: 100%;
}

/* ===== Header ===== */
.site-header {
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    padding: .75rem 0;
    position: sticky;
    top: 0;
    z-index: 100;
}
.header-inner { 
    display: flex; 
    align-items: center; 
    justify-content: space-between; 
    gap: 1rem; 
    flex-wrap: wrap; 
}
.logo { 
    font-size: 1.25rem; 
    font-weight: 700; 
    color: var(--text); 
}
.logo:hover { color: var(--accent); }
.main-nav { 
    display: flex; 
    gap: 1rem; 
    align-items: center; 
}
.main-nav a { 
    color: var(--text-muted); 
    font-size: .9rem; 
}
.main-nav a:hover, .main-nav a.active { color: var(--accent); }
.admin-link { color: var(--warning) !important; }

/* ===== Buttons ===== */
.btn {
    display: inline-block;
    padding: .5rem 1rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text);
    cursor: pointer;
    font-size: .9rem;
    text-align: center;
    transition: all .2s;
}
.btn:hover { background: var(--bg-input); color: var(--text); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { background: var(--error); border-color: var(--error); color: #fff; }
.btn-danger:hover { background: #c0392b; }
.btn-sm { padding: .3rem .6rem; font-size: .8rem; }
.btn-block { display: block; width: 100%; }

/* ===== Alerts ===== */
.alert {
    padding: .75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: .9rem;
}
.alert-success { background: rgba(46,204,113,.15); border: 1px solid var(--success); color: var(--success); }
.alert-error   { background: rgba(231,76,60,.15);  border: 1px solid var(--error);   color: var(--error); }
.alert-info    { background: rgba(52,152,219,.15);  border: 1px solid var(--info);    color: var(--info); }
.alert-warning { background: rgba(243,156,18,.15);  border: 1px solid var(--warning);  color: var(--warning); }

/* ===== Hero ===== */
.hero-section {
    text-align: center;
    padding: 3rem 0 2rem;
}
.hero-section h1 { font-size: 2rem; margin-bottom: .5rem; }
.hero-section p { color: var(--text-muted); margin-bottom: 1.5rem; }
.search-form { 
    display: flex; 
    gap: .5rem; 
    max-width: 500px; 
    margin: 0 auto; 
}
.search-input {
    flex: 1;
    padding: .6rem 1rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg-surface);
    color: var(--text);
    font-size: 1rem;
}
.search-input:focus { outline: none; border-color: var(--accent); }

/* ===== Works Grid ===== */
.works-section { 
    margin-bottom: 2rem; 
    width: 100%;
}
.works-section h2 { 
    margin-bottom: 1rem; 
    font-size: 1.3rem; 
}
.works-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1.5rem;
    width: 100%;
}
.work-card {
    display: block;
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--bg-card);
    transition: transform .2s, box-shadow .2s;
    color: var(--text);
    height: 100%;
    text-decoration: none;
    width: 100%;
}
.work-card:hover { 
    transform: translateY(-3px); 
    box-shadow: var(--shadow); 
    color: var(--text); 
}
.work-cover {
    position: relative;
    aspect-ratio: 2/3;
    overflow: hidden;
    background: var(--bg-surface);
    width: 100%;
}
.work-cover img { 
    width: 100%; 
    height: 100%; 
    object-fit: cover;
    display: block;
}
.no-cover {
    display: flex; 
    align-items: center; 
    justify-content: center;
    height: 100%; 
    color: var(--text-muted); 
    font-size: .9rem;
}
.no-cover.large { min-height: 300px; font-size: 1.2rem; }
.status-badge {
    position: absolute; 
    top: .5rem; 
    left: .5rem;
    padding: .15rem .5rem;
    border-radius: 3px;
    font-size: .65rem;
    font-weight: 600;
    text-transform: uppercase;
    z-index: 2;
}
.status-ongoing   { background: var(--info);    color: #fff; }
.status-completed { background: var(--success); color: #fff; }
.status-paused    { background: var(--warning); color: #000; }
.status-dropped   { background: var(--error);   color: #fff; }
.status-admin     { background: var(--success); color: #fff; }
.status-user      { background: var(--info);    color: #fff; }
.views-badge {
    position: absolute; 
    bottom: .5rem; 
    right: .5rem;
    padding: .15rem .5rem;
    border-radius: 3px;
    background: rgba(0,0,0,.7);
    color: #fff;
    font-size: .7rem;
}
.list-badge {
    position: absolute; 
    bottom: .5rem; 
    left: .5rem;
    padding: .15rem .5rem;
    border-radius: 3px;
    background: var(--accent);
    color: #fff;
    font-size: .7rem;
}
.work-info { 
    padding: .6rem .75rem; 
    overflow: hidden;
}
.work-info h3 { 
    font-size: .9rem; 
    line-height: 1.3; 
    margin-bottom: .2rem; 
    overflow: hidden; 
    text-overflow: ellipsis; 
    white-space: nowrap;
    width: 100%;
}
.work-genres { 
    font-size: .75rem; 
    color: var(--text-muted); 
    overflow: hidden; 
    text-overflow: ellipsis; 
    white-space: nowrap;
    width: 100%;
    display: block;
}

/* ===== Work Detail ===== */
.work-detail { 
    width: 100%;
}
.work-header { 
    display: flex; 
    gap: 2rem; 
    margin-bottom: 2rem; 
    flex-wrap: wrap; 
}
.work-cover-large { 
    width: 260px; 
    flex-shrink: 0; 
}
.work-cover-large img { 
    width: 100%; 
    border-radius: var(--radius); 
}
.work-meta { 
    flex: 1; 
    min-width: 250px; 
}
.work-meta h1 { 
    font-size: 1.8rem; 
    margin-bottom: .5rem; 
}
.alt-titles { 
    color: var(--text-muted); 
    font-size: .9rem; 
    margin-bottom: 1rem; 
}
.meta-table { 
    margin: 1rem 0; 
}
.meta-table td { 
    padding: .25rem .75rem .25rem 0; 
    font-size: .9rem; 
}
.meta-table td:first-child { 
    color: var(--text-muted); 
    white-space: nowrap; 
}
.work-tags { 
    display: flex; 
    flex-wrap: wrap; 
    gap: .4rem; 
    margin: 1rem 0; 
}
.tag {
    display: inline-block;
    padding: .2rem .6rem;
    background: var(--bg-input);
    border-radius: 3px;
    font-size: .75rem;
    color: var(--text);
}
.tag:hover { 
    background: var(--accent); 
    color: #fff; 
}
.work-description { 
    margin-bottom: 2rem; 
}
.work-description h2 { 
    font-size: 1.2rem; 
    margin-bottom: .5rem; 
}
.work-description p { 
    color: var(--text-muted); 
    font-size: .9rem; 
}

/* ===== Chapters List ===== */
.chapters-list { 
    margin-top: 2rem; 
}
.chapters-list h2 { 
    font-size: 1.2rem; 
    margin-bottom: .75rem; 
}
.volume-heading {
    font-size: .9rem;
    color: var(--text-muted);
    padding: .5rem 0 .25rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: .25rem;
}
.chapter-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .4rem .5rem;
    border-radius: var(--radius);
    transition: background .15s;
    text-decoration: none;
    color: var(--text);
}
.chapter-row:hover { 
    background: var(--bg-surface); 
}
.chapter-title { 
    color: var(--text); 
    font-size: .9rem; 
}
.chapter-title:hover { 
    color: var(--accent); 
}
.chapter-meta { 
    font-size: .75rem; 
    color: var(--text-muted); 
    white-space: nowrap; 
    margin-left: 1rem; 
}

/* ===== Read / Continue button ===== */
.btn-read {
    display: inline-flex;
    align-items: center;
    gap: .6rem;
    margin-top: 1rem;
    background: var(--accent);
    color: #fff;
    font-weight: 600;
    padding: .55rem 1.1rem;
    border-radius: var(--radius);
    border: none;
    cursor: pointer;
    text-decoration: none;
}
.btn-read:hover { 
    filter: brightness(1.1); 
    color: #fff; 
}
.read-progress { 
    font-weight: 400; 
    font-size: .8rem; 
    opacity: .9; 
}

/* ===== Bookmark Form ===== */
.bookmark-form { 
    display: flex; 
    gap: .5rem; 
    align-items: center; 
    margin-top: 1rem; 
    flex-wrap: wrap;
}
.bookmark-form select { 
    padding: .4rem .6rem; 
    background: var(--bg-input); 
    color: var(--text); 
    border: 1px solid var(--border); 
    border-radius: var(--radius); 
}

/* ===== Auth Forms ===== */
.auth-form-wrapper {
    max-width: 400px; 
    margin: 2rem auto;
    background: var(--bg-card); 
    padding: 2rem; 
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.auth-form-wrapper h1 { 
    text-align: center; 
    margin-bottom: 1.5rem; 
}
.auth-form label { 
    display: block; 
    margin-bottom: 1rem; 
    font-size: .9rem; 
    color: var(--text-muted); 
}
.auth-form input {
    display: block; 
    width: 100%; 
    margin-top: .3rem;
    padding: .6rem .8rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: .95rem;
}
.auth-form input:focus { 
    outline: none; 
    border-color: var(--accent); 
}
.auth-switch { 
    text-align: center; 
    margin-top: 1rem; 
    font-size: .85rem; 
    color: var(--text-muted); 
}

/* ===== Profile ===== */
.profile-page { 
    max-width: 900px; 
    margin: 0 auto; 
}
.profile-tabs { 
    display: flex; 
    gap: .5rem; 
    margin-bottom: 1.5rem; 
}
.tab-btn {
    padding: .5rem 1.2rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-muted);
    cursor: pointer;
    font-size: .9rem;
}
.tab-btn.active { 
    background: var(--accent); 
    border-color: var(--accent); 
    color: #fff; 
}
.tab-content { 
    display: none; 
}
.tab-content.active { 
    display: block; 
}
.history-list { 
    display: flex; 
    flex-direction: column; 
    gap: .25rem; 
}
.history-row {
    display: flex; 
    gap: 1rem; 
    align-items: center;
    padding: .5rem .75rem;
    border-radius: var(--radius);
    color: var(--text);
    font-size: .9rem;
    transition: background .15s;
}
.history-row:hover { 
    background: var(--bg-surface); 
    color: var(--text); 
}
.history-title { 
    flex: 1; 
}
.history-time { 
    color: var(--text-muted); 
    font-size: .8rem; 
}

/* ===== Catalog ===== */
.catalog-page h1 { 
    margin-bottom: 1rem; 
}
.filter-form {
    display: flex; 
    gap: .5rem; 
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
    align-items: center;
}
.filter-form select, .filter-form .search-input {
    padding: .5rem .7rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: .9rem;
}
.filter-form select:focus, .filter-form .search-input:focus { 
    outline: none; 
    border-color: var(--accent); 
}
.no-results { 
    text-align: center; 
    color: var(--text-muted); 
    padding: 3rem 0; 
}

/* ===== Pagination ===== */
.pagination { 
    display: flex; 
    gap: .3rem; 
    justify-content: center; 
    margin: 2rem 0; 
    flex-wrap: wrap; 
}
.page-btn {
    display: inline-flex; 
    align-items: center; 
    justify-content: center;
    min-width: 2rem; 
    height: 2rem;
    padding: .3rem .6rem;
    border-radius: var(--radius);
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: .85rem;
}
.page-btn:hover { 
    background: var(--bg-input); 
    color: var(--text); 
}
.page-btn.active { 
    background: var(--accent); 
    border-color: var(--accent); 
    color: #fff; 
}

/* ===== Reader ===== */
.reader-chrome {
    position: relative;
    min-height: calc(100vh - 60px);
}

/* On the reader page the site header scrolls away so the reader bar takes its place */
body.reader-page .site-header { position: static; }

/* Top bar */
.reader-topbar {
    position: sticky;
    top: 0; left: 0; right: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: .55rem 1rem;
    background: rgba(15,15,15,.96);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(6px);
    transition: transform .25s ease;
}
.reader-topbar.hidden { transform: translateY(-100%); }
.reader-topbar-left, .reader-topbar-right { 
    display: flex; 
    align-items: center; 
    gap: .5rem; 
    min-width: 0; 
}
.reader-topbar-title {
    flex: 1;
    text-align: center;
    font-size: .9rem;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.topbar-btn {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .4rem .7rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: .83rem;
    cursor: pointer;
    white-space: nowrap;
}
.topbar-btn:hover { 
    border-color: var(--accent); 
    color: var(--accent-hover); 
}
.topbar-icon { line-height: 1; }
.topbar-text { white-space: nowrap; }

/* Content offsets for fixed bottom bar */
.reader {
    max-width: 100%;
    margin: 0 auto;
    padding: 1rem 0 80px;
}
.reader-progress-top {
    text-align: center;
    padding: .5rem 0 1rem;
    color: var(--text-muted);
    font-size: .85rem;
}

/* Pages */
.reader-pages {
    --reader-width: 60%;
    display: flex;
    flex-direction: column;
    align-items: center;
}
.reader-page {
    width: var(--reader-width);
    margin: 0 auto;
    display: block;
}

/* Single page */
.reader-single .reader-page { display: none; }
.reader-single .reader-page.active { display: block; }

/* Infinite scroll */
.reader-scroll .reader-page {
    display: block;
    margin-bottom: 2px;
    max-width: 100%;
    width: var(--reader-width);
}

/* Webtoon (full-width continuous) */
.reader-webtoon .reader-page {
    display: block;
    width: 100%;
    max-width: 100%;
    margin: 0;
    padding: 0;
    border-radius: 0;
}

/* Bottom bar */
.reader-bottom-bar {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: .5rem 1rem;
    background: rgba(15,15,15,.96);
    border-top: 1px solid var(--border);
    backdrop-filter: blur(6px);
}
.bottombar-group { 
    display: flex; 
    align-items: center; 
    gap: .5rem; 
}
.bottom-btn {
    padding: .45rem .8rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: .9rem;
    cursor: pointer;
    line-height: 1;
}
.bottom-btn:hover { 
    border-color: var(--accent); 
    color: var(--accent-hover); 
}
.bottom-btn.disabled { 
    opacity: .4; 
    pointer-events: none; 
}
.page-counter { 
    color: var(--text-muted); 
    font-size: .9rem; 
    min-width: 4.5rem; 
    text-align: center; 
}

/* TOC panel */
.toc-panel, .settings-panel {
    position: fixed;
    top: 0; bottom: 0;
    width: 320px;
    max-width: 85vw;
    z-index: 150;
    background: var(--bg-surface);
    border-right: 1px solid var(--border);
    box-shadow: var(--shadow);
    transition: transform .25s ease;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}
.toc-panel { left: 0; transform: translateX(-100%); }
.toc-panel.open { transform: translateX(0); }
.settings-panel { 
    right: 0; 
    border-left: 1px solid var(--border); 
    border-right: none; 
    transform: translateX(100%); 
}
.settings-panel.open { transform: translateX(0); }

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.2rem;
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0;
    background: var(--bg-surface);
    z-index: 2;
}
.panel-header h3 { font-size: 1.05rem; }
.panel-close {
    background: none; border: none;
    color: var(--text-muted);
    font-size: 1.6rem;
    line-height: 1;
    cursor: pointer;
}
.panel-close:hover { color: var(--accent-hover); }

.toc-title { 
    padding: .8rem 1.2rem; 
    font-weight: 600; 
    color: var(--text); 
    border-bottom: 1px solid var(--border); 
}
.toc-list { 
    list-style: none; 
    padding: .5rem 0; 
}
.toc-list li { margin: 0; }
.toc-item {
    display: flex;
    align-items: baseline;
    gap: .6rem;
    padding: .6rem 1.2rem;
    color: var(--text);
    font-size: .9rem;
    border-left: 3px solid transparent;
}
.toc-item:hover { 
    background: var(--bg-input); 
    color: var(--accent-hover); 
}
.toc-item.active { 
    border-left-color: var(--accent); 
    background: var(--bg-input); 
}
.toc-number { 
    font-weight: 600; 
    white-space: nowrap; 
}
.toc-name { 
    color: var(--text-muted); 
    overflow: hidden; 
    text-overflow: ellipsis; 
    white-space: nowrap; 
}
.toc-empty { 
    padding: 1rem 1.2rem; 
    color: var(--text-muted); 
}

/* Settings panel */
.setting-group { 
    padding: 1rem 1.2rem; 
    border-bottom: 1px solid var(--border); 
}
.setting-label { 
    display: block; 
    font-size: .85rem; 
    color: var(--text-muted); 
    margin-bottom: .5rem; 
}
.setting-row { 
    display: flex; 
    flex-wrap: wrap; 
    gap: .5rem; 
}
.radio-pill { flex: 1 1 45%; }
.radio-pill input[type="radio"] { display: none; }
.radio-pill span {
    display: block;
    text-align: center;
    padding: .45rem .5rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: .8rem;
    color: var(--text);
    cursor: pointer;
}
.radio-pill input:checked + span { 
    background: var(--accent); 
    border-color: var(--accent); 
    color: #fff; 
}
.setting-select {
    width: 100%;
    padding: .5rem .6rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: .9rem;
}

/* Backdrop */
.reader-settings-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 140;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease;
}
.reader-settings-backdrop.show { 
    opacity: 1; 
    pointer-events: auto; 
}

@media (max-width: 640px) {
    .topbar-text { display: none; }
    .reader { padding: 1rem 0 70px; }
    .bottombar-group { gap: .3rem; }
    .bottom-btn { padding: .4rem .6rem; }
}

/* ===== Tags / chips ===== */
.text-muted { color: var(--text-muted); }

/* ===== Footer ===== */
.site-footer {
    text-align: center;
    padding: 1.5rem 0;
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    font-size: .8rem;
    margin-top: 2rem;
}

/* ===== Responsive ===== */
@media (max-width: 1200px) {
    .works-grid {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
        gap: 1.2rem;
    }
}

@media (max-width: 992px) {
    .container {
        padding: 0 1.5rem;
    }
    
    .works-grid {
        grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
        gap: 1rem;
    }
    
    .work-detail {
        max-width: 100%;
        padding: 0 1rem;
    }
}

@media (max-width: 768px) {
    .container {
        padding: 0 1rem;
    }
    
    .work-header { 
        flex-direction: column; 
        align-items: center;
    }
    .work-cover-large { 
        width: 100%; 
        max-width: 300px; 
        margin: 0 auto; 
    }
    .work-meta {
        width: 100%;
    }
    .work-detail {
        padding: 0 0.75rem;
    }
    .chapter-row {
        flex-wrap: wrap;
        gap: 0.3rem;
    }
    .chapter-meta {
        margin-left: 0;
    }
    
    .works-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 0.8rem;
    }
    
    .work-info h3 {
        font-size: 0.8rem;
    }
    
    .work-genres {
        font-size: 0.65rem;
    }
    
    .filter-form { 
        flex-direction: column; 
    }
    .header-inner { 
        flex-direction: column; 
        gap: .5rem; 
    }
    
    .hero-section h1 { 
        font-size: 1.5rem; 
    }
    .search-form {
        max-width: 100%;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 0 0.75rem;
    }
    
    .works-grid {
        grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
        gap: 0.6rem;
    }
    
    .work-info {
        padding: 0.4rem 0.5rem;
    }
    
    .work-info h3 {
        font-size: 0.7rem;
    }
    
    .work-genres {
        font-size: 0.6rem;
    }
    
    .status-badge {
        font-size: 0.5rem;
        padding: 0.1rem 0.3rem;
        top: 0.3rem;
        left: 0.3rem;
    }
    
    .work-detail {
        padding: 0 0.5rem;
    }
    .work-meta h1 {
        font-size: 1.4rem;
    }
    .meta-table td {
        font-size: 0.8rem;
        padding: 0.15rem 0.5rem 0.15rem 0;
    }
    .bookmark-form {
        flex-direction: column;
        align-items: stretch;
    }
    .btn-read {
        justify-content: center;
        flex-wrap: wrap;
    }
}