:root,
[data-theme="dark"] {
        --bg: #15171e;
        --surface: #1e212b;
        --line: #2d313e;
        --text: #e7e4dd;
        --muted: #8f93a1;
        --accent: #86b6c9;
        --accent-ink: #10222b;
        --read: #5b5f6d;
        color-scheme: dark;
}

[data-theme="light"] {
        --bg: #f3f4f7;
        --surface: #ffffff;
        --line: #d9dce4;
        --text: #1b1d24;
        --muted: #5f6472;
        --accent: #2c6b86;
        --accent-ink: #ffffff;
        --read: #9a9eab;
        color-scheme: light;
}

:root {
        --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
        --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
        --page-w: 860px;
}

body {
        --reader-bg: #0d0e12;
        --rtext: #e7e4dd;
        --rmuted: #8f93a1;
}

body[data-rbg="gray"] {
        --reader-bg: #2a2c35;
}

body[data-rbg="light"] {
        --reader-bg: #efede8;
        --rtext: #1b1d24;
        --rmuted: #5f6472;
}

* {
        box-sizing: border-box;
}

body {
        margin: 0;
        background: var(--bg);
        color: var(--text);
        font: 16px/1.5 var(--sans);
        -webkit-font-smoothing: antialiased;
}

body.reading {
        background: var(--reader-bg);
}

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

button,
select,
input {
        font: inherit;
        color: inherit;
}

:focus-visible {
        outline: 2px solid var(--accent);
        outline-offset: 2px;
}

h1,
h2 {
        font-family: var(--serif);
        font-weight: 600;
        letter-spacing: -0.01em;
        margin: 0;
}

.muted {
        color: var(--muted);
}

.wrap {
        max-width: 1100px;
        margin: 0 auto;
        padding: 32px 20px 64px;
}

/* ---- Buttons & controls ---- */
.btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        padding: 10px 18px;
        min-height: 42px;
        border-radius: 8px;
        border: 1px solid var(--line);
        background: var(--surface);
        cursor: pointer;
}

.btn:hover {
        border-color: var(--muted);
}

.btn.primary {
        background: var(--accent);
        border-color: var(--accent);
        color: var(--accent-ink);
        font-weight: 600;
}

.btn.primary:hover {
        filter: brightness(1.08);
}

.btn.icon {
        min-height: 36px;
        padding: 6px 12px;
}

.btn[aria-disabled="true"] {
        opacity: .35;
        pointer-events: none;
}

.sel,
.search,
.filter {
        background: var(--surface);
        border: 1px solid var(--line);
        border-radius: 8px;
        padding: 10px 14px;
        min-height: 42px;
}

.chip {
        background: var(--surface);
        border: 1px solid var(--line);
        border-radius: 999px;
        padding: 8px 16px;
        cursor: pointer;
}

.chip[aria-pressed="true"] {
        background: var(--accent);
        color: var(--accent-ink);
        border-color: var(--accent);
}

.seg {
        display: inline-flex;
}

.seg button {
        background: var(--surface);
        border: 1px solid var(--line);
        padding: 6px 12px;
        cursor: pointer;
        margin-left: -1px;
}

.seg button:first-child {
        border-radius: 6px 0 0 6px;
        margin-left: 0;
}

.seg button:last-child {
        border-radius: 0 6px 6px 0;
}

.seg button[aria-pressed="true"] {
        background: var(--accent);
        color: var(--accent-ink);
        border-color: var(--accent);
}

/* ---- Home ---- */
.top {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 16px;
        margin-bottom: 20px;
}

.top h1 {
        font-size: 2rem;
}

.tools {
        display: flex;
        gap: 10px;
        flex-wrap: wrap;
        align-items: center;
        margin-bottom: 26px;
}

.tools .search {
        flex: 1;
        min-width: 200px;
}

.sec-h {
        font-size: 1.2rem;
        margin: 0 0 12px;
}

.row-h {
        display: flex;
        gap: 14px;
        overflow-x: auto;
        padding-bottom: 8px;
        margin-bottom: 30px;
        scroll-snap-type: x proximity;
}

.cont {
        flex: 0 0 132px;
        scroll-snap-align: start;
}

.grid {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
        gap: 22px 18px;
}

.card {
        position: relative;
}

.cover {
        position: relative;
        display: block;
        aspect-ratio: 2 / 3;
        border-radius: 6px;
        overflow: hidden;
        background: var(--surface);
        border: 1px solid var(--line);
        color: var(--muted);
}

.cover img {
        width: 100%;
        height: 100%;
        object-fit: cover;
        display: block;
}

.card:hover .cover,
.cont:hover .cover {
        border-color: var(--accent);
}

.card h2,
.cont .t {
        font-size: 1rem;
        margin-top: 10px;
        line-height: 1.3;
        font-family: var(--serif);
        font-weight: 600;
}

.card .meta,
.cont .meta {
        font-size: .85rem;
        color: var(--muted);
}

.fav {
        position: absolute;
        top: 6px;
        right: 6px;
        width: 34px;
        height: 34px;
        border-radius: 50%;
        border: 0;
        cursor: pointer;
        background: rgba(0, 0, 0, .6);
        color: #f5d36b;
        font-size: 1.1rem;
        line-height: 1;
}

.badge {
        position: absolute;
        top: 8px;
        left: 8px;
        background: var(--accent);
        color: var(--accent-ink);
        font-size: .75rem;
        font-weight: 600;
        padding: 2px 8px;
        border-radius: 999px;
}

.prog {
        position: absolute;
        left: 0;
        right: 0;
        bottom: 0;
        height: 4px;
        background: rgba(0, 0, 0, .55);
}

.prog i {
        display: block;
        height: 100%;
        background: var(--accent);
}

.empty {
        border: 1px dashed var(--line);
        border-radius: 10px;
        padding: 40px 24px;
        text-align: center;
        color: var(--muted);
}

.empty code {
        background: var(--surface);
        padding: 2px 8px;
        border-radius: 4px;
        color: var(--text);
}

.sk {
        background: linear-gradient(90deg, var(--surface), var(--line), var(--surface));
        background-size: 200% 100%;
        animation: sk 1.4s linear infinite;
}

.sk.line {
        height: 14px;
        border-radius: 4px;
        margin-top: 10px;
        width: 70%;
}

@keyframes sk {
        to {
                background-position: -200% 0;
        }
}

/* ---- Manga page ---- */
.back {
        color: var(--muted);
        display: inline-block;
        margin-bottom: 18px;
}

.back:hover {
        color: var(--text);
}

.hero {
        --text: #eceae4;
        --muted: #b4b8c4;
        color: var(--text);
        position: relative;
        isolation: isolate;
        overflow: hidden;
        border-radius: 12px;
        padding: 26px;
        display: grid;
        grid-template-columns: 190px 1fr;
        gap: 28px;
        align-items: start;
        margin-bottom: 36px;
        background: var(--surface);
}

.hero::before {
        content: "";
        position: absolute;
        inset: -50px;
        z-index: -1;
        background: var(--cover) center / cover;
        filter: blur(28px) brightness(.38);
}

.hero .cover {
        border-color: rgba(255, 255, 255, .18);
}

.hero .btn:not(.primary) {
        background: rgba(255, 255, 255, .14);
        border-color: rgba(255, 255, 255, .35);
        color: var(--text);
}

.hero .btn:not(.primary):hover {
        background: rgba(255, 255, 255, .24);
        border-color: rgba(255, 255, 255, .6);
}

.hero h1 {
        font-size: 2.1rem;
        line-height: 1.15;
        margin-bottom: 8px;
}

.hero .sub {
        display: flex;
        gap: 10px;
        flex-wrap: wrap;
        align-items: center;
        color: var(--muted);
        margin-bottom: 10px;
}

.pill {
        border: 1px solid rgba(255, 255, 255, .35);
        border-radius: 999px;
        padding: 1px 10px;
        font-size: .85rem;
}

.chips {
        display: flex;
        gap: 6px;
        flex-wrap: wrap;
        margin-bottom: 12px;
}

.chips span {
        background: rgba(255, 255, 255, .12);
        border-radius: 6px;
        padding: 2px 10px;
        font-size: .85rem;
}

.desc {
        margin: 0 0 12px;
        max-width: 70ch;
        color: var(--text);
        opacity: .92;
}

.hero .actions {
        display: flex;
        gap: 10px;
        flex-wrap: wrap;
        margin-top: 18px;
}

.list-head {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 12px;
        flex-wrap: wrap;
        margin-bottom: 14px;
}

.list-head h2 {
        font-size: 1.3rem;
}

.list-head .right {
        display: flex;
        gap: 8px;
}

.chaps {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 8px;
}

.chap {
        display: flex;
        justify-content: space-between;
        align-items: baseline;
        gap: 8px;
        padding: 11px 14px;
        border-radius: 8px;
        background: var(--surface);
        border: 1px solid var(--line);
}

.chap:hover {
        border-color: var(--accent);
}

.chap small {
        color: var(--muted);
}

.chap.read,
.chap.read small {
        color: var(--read);
}

.chap.last {
        border-color: var(--accent);
}

/* ---- Reader ---- */
#progress {
        position: fixed;
        top: 0;
        left: 0;
        height: 3px;
        width: 0;
        background: var(--accent);
        z-index: 40;
}

.bar {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 30;
        display: flex;
        align-items: center;
        gap: 8px;
        padding: 10px 14px;
        background: color-mix(in srgb, var(--bg) 93%, transparent);
        backdrop-filter: blur(8px);
        border-bottom: 1px solid var(--line);
        transition: transform .2s ease;
}

.bar.hide {
        transform: translateY(-100%);
}

.bar .title {
        flex: 1;
        min-width: 0;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        font-family: var(--serif);
}

.bar select {
        background: var(--surface);
        border: 1px solid var(--line);
        border-radius: 6px;
        padding: 6px 10px;
        max-width: 46vw;
}

.panel {
        position: fixed;
        top: 58px;
        right: 12px;
        z-index: 35;
        width: min(330px, calc(100vw - 24px));
        background: var(--surface);
        border: 1px solid var(--line);
        border-radius: 10px;
        padding: 14px;
        display: grid;
        gap: 14px;
        box-shadow: 0 10px 30px rgba(0, 0, 0, .35);
}

.panel[hidden] {
        display: none;
}

.panel .lbl {
        display: block;
        font-size: .85rem;
        color: var(--muted);
        margin-bottom: 6px;
}

.pages {
        max-width: var(--page-w);
        margin: 0 auto;
        padding-top: 52px;
}

.pages.w-narrow {
        --page-w: 680px;
}

.pages.w-wide {
        --page-w: 1100px;
}

.pg {
        margin: 0 0 var(--gap, 0px);
        position: relative;
}

.pg img {
        display: block;
        width: 100%;
        height: auto;
        min-height: 70vh;
        background: rgba(128, 128, 128, .16);
}

.pg img.loaded {
        min-height: 0;
        background: none;
}

.pg .retry {
        display: none;
        width: 100%;
        min-height: 40vh;
        align-items: center;
        justify-content: center;
        background: rgba(128, 128, 128, .16);
        border: 1px dashed var(--rmuted);
        color: var(--rtext);
        cursor: pointer;
}

.pg.fail img {
        display: none;
}

.pg.fail .retry {
        display: flex;
}

.divider {
        padding: 56px 16px 40px;
        text-align: center;
        font-family: var(--serif);
        font-size: 1.25rem;
        color: var(--rmuted);
}

.empty-note {
        padding: 40px 16px;
        text-align: center;
        color: var(--rmuted);
}

.end {
        max-width: var(--page-w);
        margin: 0 auto;
        padding: 36px 16px 110px;
        text-align: center;
        color: var(--rtext);
}

.end p {
        color: var(--rmuted);
        margin: 0 0 16px;
}

.pager {
        position: fixed;
        right: 12px;
        bottom: 12px;
        z-index: 20;
        pointer-events: none;
        font-size: .8rem;
        font-variant-numeric: tabular-nums;
        background: rgba(0, 0, 0, .62);
        color: #fff;
        padding: 3px 11px;
        border-radius: 999px;
}

.pager:empty {
        display: none;
}

@media (max-width: 640px) {
        .wrap {
                padding: 20px 14px 48px;
        }

        .top h1 {
                font-size: 1.5rem;
        }

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

        .hero {
                grid-template-columns: 105px 1fr;
                gap: 16px;
                padding: 16px;
        }

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

        .bar .title {
                display: none;
        }

        .bar select {
                flex: 1;
                max-width: none;
        }

        .bar {
                gap: 6px;
                padding: 8px 10px;
        }

        .pages {
                padding-top: 48px;
        }
}

@media (prefers-reduced-motion: reduce) {
        .bar {
                transition: none;
        }

        .sk {
                animation: none;
        }
}