:root {
    color-scheme: light dark;
    --bg: #f3f5f8;
    --surface: #ffffff;
    --surface-2: #e9edf3;
    --ink: #172033;
    --muted: #667085;
    --line: #d9dee7;
    --accent: #e6532f;
    --accent-strong: #bc351b;
    --accent-soft: #ffdfd6;
    --danger: #b42318;
    --success: #176b45;
    --shadow: 0 18px 50px rgba(22, 30, 48, .09);
    --radius: 14px;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0e1117;
    --surface: #171b23;
    --surface-2: #222832;
    --ink: #f3f5f8;
    --muted: #a7b0c0;
    --line: #303744;
    --accent: #ff7452;
    --accent-strong: #ff9479;
    --accent-soft: #3b211b;
    --danger: #ff8a80;
    --success: #62d39a;
    --shadow: 0 20px 60px rgba(0, 0, 0, .32);
}

@media (prefers-color-scheme: dark) {
    html[data-theme="system"] {
        color-scheme: dark;
        --bg: #0e1117;
        --surface: #171b23;
        --surface-2: #222832;
        --ink: #f3f5f8;
        --muted: #a7b0c0;
        --line: #303744;
        --accent: #ff7452;
        --accent-strong: #ff9479;
        --accent-soft: #3b211b;
        --danger: #ff8a80;
        --success: #62d39a;
        --shadow: 0 20px 60px rgba(0, 0, 0, .32);
    }
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--ink); font-size: 1rem; line-height: 1.55; }
a { color: inherit; text-decoration-thickness: .08em; text-underline-offset: .18em; }
img { max-width: 100%; height: auto; }
button, input, select, textarea { font: inherit; }
button, .button { cursor: pointer; }

.skip-link { position: fixed; z-index: 100; top: -5rem; left: 1rem; padding: .75rem 1rem; background: var(--ink); color: var(--bg); }
.skip-link:focus { top: 1rem; }
.site-header { min-height: 68px; display: flex; gap: 1rem; align-items: center; justify-content: space-between; padding: .75rem clamp(1rem, 4vw, 4rem); background: color-mix(in srgb, var(--surface) 92%, transparent); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; backdrop-filter: blur(16px); }
.brand { display: inline-flex; align-items: center; gap: .7rem; font-weight: 780; letter-spacing: -.02em; text-decoration: none; }
.brand-mark, .auth-mark { display: grid; place-items: center; background: var(--accent); color: #fff; font-weight: 900; transform: rotate(-4deg); }
.brand-mark { width: 32px; height: 38px; border-radius: 8px 8px 11px 5px; }
.site-header nav { display: flex; flex-wrap: wrap; align-items: center; gap: clamp(.7rem, 2vw, 1.5rem); }
.site-header nav a, .link-button { color: var(--muted); text-decoration: none; font-weight: 650; }
.site-header nav a:hover, .site-header nav a:focus-visible, .link-button:hover { color: var(--accent); }
.inline { display: inline; margin: 0; }
.link-button { border: 0; background: none; padding: 0; }
.page-shell { width: min(1240px, calc(100% - 2rem)); min-height: calc(100vh - 138px); margin: 0 auto; padding: clamp(2rem, 5vw, 4.5rem) 0; }
.reader-shell { width: min(1500px, 100%); padding-top: 0; }
.site-footer { display: flex; justify-content: space-between; gap: 1rem; width: min(1240px, calc(100% - 2rem)); margin: 0 auto; padding: 1.5rem 0 2.5rem; color: var(--muted); font-size: .875rem; border-top: 1px solid var(--line); }
h1, h2, h3 { line-height: 1.08; letter-spacing: -.035em; }
h1 { margin: .2rem 0 .8rem; font-size: clamp(2rem, 4vw, 3.8rem); }
h2 { font-size: clamp(1.2rem, 2vw, 1.7rem); }
.eyebrow { color: var(--accent); text-transform: uppercase; letter-spacing: .14em; font-weight: 800; font-size: .75rem; }
.muted, small { color: var(--muted); }
.split, .section-title { display: flex; align-items: end; justify-content: space-between; gap: 1rem; }
.page-heading { margin-bottom: 1.4rem; }
.result-count, .section-title span { color: var(--muted); font-variant-numeric: tabular-nums; }

.auth-card { width: min(440px, 100%); margin: clamp(2rem, 10vh, 7rem) auto; background: var(--surface); border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow); padding: clamp(1.5rem, 5vw, 3rem); }
.auth-card.wide { width: min(560px, 100%); }
.auth-mark { width: 56px; height: 66px; border-radius: 13px 13px 17px 9px; font-size: 1.65rem; margin-bottom: 1.5rem; }
.stack { display: grid; gap: 1rem; }
label { display: grid; gap: .35rem; font-weight: 690; }
input, select, textarea { width: 100%; min-height: 44px; padding: .65rem .75rem; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 9px; }
textarea { min-height: 140px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 3px solid color-mix(in srgb, var(--accent) 28%, transparent); border-color: var(--accent); }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; }
legend { padding: 0 .35rem; font-weight: 800; }
label.checkbox { display: flex; align-items: center; gap: .65rem; font-weight: 550; }
label.checkbox input { width: 1.1rem; min-height: 1.1rem; }
button, .button { display: inline-flex; min-height: 42px; align-items: center; justify-content: center; padding: .62rem 1rem; border-radius: 9px; border: 1px solid transparent; font-weight: 760; text-decoration: none; }
.primary { background: var(--accent); color: #fff; }
.primary:hover { background: var(--accent-strong); }
.secondary { background: var(--ink); color: var(--bg); }
.ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.danger-button { background: transparent; border-color: color-mix(in srgb, var(--danger) 45%, var(--line)); color: var(--danger); }
.actions { display: flex; flex-wrap: wrap; gap: .65rem; margin-top: 1.25rem; }
.notice { padding: .85rem 1rem; margin: 0 0 1rem; border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 8px; background: var(--surface); }
.notice.error { border-left-color: var(--danger); color: var(--danger); }
.notice.success { border-left-color: var(--success); }
.job-summary { display: flex; justify-content: space-between; gap: 1rem; }
progress { width: 100%; height: 1rem; accent-color: var(--accent); }
.job-log { max-height: 28rem; overflow: auto; padding-left: 1.5rem; }
.job-log li { margin: .45rem 0; }
.job-log time { color: var(--muted); font-variant-numeric: tabular-nums; margin-right: .5rem; }
.job-error { color: var(--danger); }

.search-panel { display: grid; grid-template-columns: minmax(220px, 1fr) minmax(180px, 280px) auto; align-items: end; gap: 1rem; padding: 1rem; margin-bottom: 2rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.search-panel select { min-height: 92px; }
.manga-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: clamp(1rem, 2vw, 1.5rem); }
.manga-card { min-width: 0; overflow: hidden; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 30px rgba(20, 27, 42, .05); transition: transform .18s ease, box-shadow .18s ease; }
.manga-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.cover { display: block; aspect-ratio: 2 / 3; overflow: hidden; background: var(--surface-2); text-decoration: none; }
.cover img { width: 100%; height: 100%; object-fit: cover; transition: transform .25s ease; }
.manga-card:hover .cover img { transform: scale(1.025); }
.cover-placeholder { display: grid; place-items: center; width: 100%; height: 100%; color: var(--muted); font-size: 3rem; font-weight: 900; background: linear-gradient(145deg, var(--surface-2), var(--surface)); }
.card-body { padding: 1rem; }
.card-meta { display: flex; justify-content: space-between; gap: .5rem; color: var(--muted); font-size: .78rem; text-transform: capitalize; }
.card-body h2 { margin: .45rem 0 .75rem; font-size: 1.1rem; }
.card-body h2 a { text-decoration: none; }
.tag-row { display: flex; flex-wrap: wrap; gap: .4rem; }
.tag { display: inline-flex; padding: .22rem .55rem; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: .75rem; font-weight: 700; }
.empty-state { text-align: center; padding: clamp(2rem, 8vw, 6rem); border: 1px dashed var(--line); border-radius: var(--radius); color: var(--muted); }
.empty-state.compact { padding: 1.5rem; }

.manga-hero { display: grid; grid-template-columns: minmax(190px, 310px) 1fr; gap: clamp(1.5rem, 5vw, 4.5rem); align-items: start; }
.hero-cover { aspect-ratio: 2 / 3; overflow: hidden; border-radius: 18px; background: var(--surface-2); box-shadow: var(--shadow); }
.hero-cover img { width: 100%; height: 100%; object-fit: cover; }
.hero-copy { padding-top: clamp(.4rem, 3vw, 2rem); }
.alternate-title { margin-top: -.5rem; color: var(--muted); font-size: 1.1rem; }
.description { max-width: 78ch; white-space: normal; }
.credits { color: var(--muted); }
.section-block { margin-top: clamp(2.5rem, 7vw, 5rem); }
.section-title { border-bottom: 1px solid var(--line); }
.chapter-list { list-style: none; margin: 0; padding: 0; }
.chapter-list li { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: .5rem; border-bottom: 1px solid var(--line); }
.chapter-list li > a:first-child { display: grid; grid-template-columns: auto minmax(75px, auto) 1fr auto auto; gap: 1rem; align-items: center; padding: 1rem .25rem; text-decoration: none; }
.chapter-thumb { width: 42px; height: 56px; object-fit: cover; border-radius: 5px; background: var(--surface-2); }
.chapter-thumb-empty { display: block; }
.chapter-list li:hover { background: color-mix(in srgb, var(--surface) 70%, transparent); }
.chapter-number { font-weight: 800; }
.chapter-title, .page-count { color: var(--muted); }
.language-pill { padding: .2rem .5rem; border: 1px solid var(--line); border-radius: 6px; font-size: .78rem; }
.icon-link { color: var(--accent); font-size: .8rem; font-weight: 800; padding: .5rem; }
.page-thumb { display: block; width: 64px; max-height: 88px; object-fit: cover; border-radius: 5px; }
.position-input { width: 6rem; }

.reader-bar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; position: sticky; top: 68px; z-index: 15; padding: .75rem clamp(1rem, 3vw, 2rem); background: color-mix(in srgb, var(--surface) 94%, transparent); border-bottom: 1px solid var(--line); backdrop-filter: blur(16px); }
.reader { display: grid; justify-items: center; background: #08090b; padding: 1rem 0 3rem; }
.reader figure { margin: 0; width: min(100%, 1200px); text-align: center; }
.reader img { display: block; width: auto; max-width: 100%; max-height: none; margin: 0 auto; }
.reader figcaption { height: 1px; overflow: hidden; clip-path: inset(50%); position: absolute; }

.admin-nav { display: flex; flex-wrap: wrap; gap: .6rem; margin: 1rem 0 2rem; }
.admin-nav a { padding: .55rem .8rem; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; text-decoration: none; font-weight: 700; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1rem; }
.stat { padding: 1.25rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.stat strong { display: block; font-size: 2rem; line-height: 1; }
.stat span { color: var(--muted); }
.panel { margin: 1rem 0; padding: clamp(1rem, 3vw, 1.5rem); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.span-2 { grid-column: 1 / -1; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .75rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; }
code, .token-reveal { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; overflow-wrap: anywhere; }
.token-reveal { padding: 1rem; border: 1px solid var(--accent); background: var(--accent-soft); border-radius: 8px; }
.error-page { margin-top: 3rem; }
.error-code { font-size: clamp(4rem, 13vw, 9rem); font-weight: 900; line-height: 1; color: var(--line); }

@media (max-width: 760px) {
    .site-header { align-items: flex-start; }
    .site-header nav { justify-content: flex-end; }
    .search-panel { grid-template-columns: 1fr; }
    .manga-hero { grid-template-columns: 120px 1fr; gap: 1rem; }
    .hero-copy h1 { font-size: 2rem; }
    .hero-copy .description, .hero-copy .credits, .hero-copy .actions { grid-column: 1 / -1; }
    .chapter-list li > a:first-child { grid-template-columns: auto 1fr auto; gap: .35rem .75rem; }
    .chapter-thumb { grid-row: 1 / 3; }
    .chapter-number, .chapter-title { grid-column: 2; }
    .language-pill { grid-column: 3; grid-row: 1; }
    .page-count { display: none; }
    .reader-bar { top: 64px; align-items: flex-start; flex-direction: column; }
    .form-grid { grid-template-columns: 1fr; }
    .span-2 { grid-column: auto; }
}

@media (max-width: 480px) {
    .brand > span:last-child { display: none; }
    .page-shell { width: min(100% - 1rem, 1240px); }
    .manga-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .65rem; }
    .card-body { padding: .75rem; }
    .card-meta span:first-child { display: none; }
    .manga-hero { display: block; }
    .hero-cover { width: min(58vw, 240px); margin-bottom: 1.5rem; }
    .site-footer { flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
