:root {
    --ink: #18202f;
    --ink-soft: #30394d;
    --muted: #687386;
    --paper: #f7f5f0;
    --surface: #fffefd;
    --surface-alt: #f1f6f7;
    --line: #e3ddd2;
    --accent: #b8324a;
    --accent-strong: #8f2438;
    --blue: #2f6f8f;
    --gold: #b9852f;
    --shadow: 0 14px 34px rgba(24, 32, 47, .08);
}

* { box-sizing: border-box; }

html { min-width: 320px; }

body {
    margin: 0;
    background: linear-gradient(180deg, var(--paper) 0, #fbfaf7 42%, #f5f7fa 100%);
    color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif;
    font-size: 16px;
    line-height: 1.65;
}

a { color: inherit; }

.site-shell,
.novel-detail,
.reader-shell,
.error-shell {
    min-height: 100vh;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    border-bottom: 1px solid rgba(227, 221, 210, .9);
    background: rgba(255, 254, 253, .94);
    backdrop-filter: blur(12px);
}

.topbar-inner {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 20px;
    max-width: 1180px;
    margin: 0 auto;
    padding: 14px 20px;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--ink);
    font-size: 19px;
    font-weight: 800;
    letter-spacing: 0;
    text-decoration: none;
    white-space: nowrap;
}

.brand-mark {
    display: grid;
    width: 32px;
    height: 32px;
    place-items: center;
    border-radius: 8px;
    background: var(--ink);
    color: #fff;
    font-size: 16px;
}

.brand-logo {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    object-fit: cover;
}

.main-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-width: 0;
}

.main-nav a {
    border-radius: 8px;
    color: var(--muted);
    font-size: 14px;
    font-weight: 700;
    padding: 8px 11px;
    text-decoration: none;
    white-space: nowrap;
}

.main-nav a:hover,
.main-nav a[aria-current="page"] {
    background: #eef3f5;
    color: var(--blue);
}

.search {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 260px;
}

.search input,
.chapter-tools input {
    width: 100%;
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--ink);
    font: inherit;
    padding: 0 13px;
    outline: none;
}

.search input:focus,
.chapter-tools input:focus {
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(47, 111, 143, .13);
}

.button,
.search button,
.actions a,
.actions button,
.chapter-tools button,
.reader-bar a,
.reader-bar button,
.error-actions a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    border: 0;
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    font: inherit;
    font-weight: 800;
    padding: 9px 14px;
    text-decoration: none;
    white-space: nowrap;
}

.button.secondary,
.actions a.secondary,
.actions button.secondary,
.chapter-tools button,
.reader-bar a,
.reader-bar button,
.error-actions a.secondary {
    background: #475569;
}

.button:hover,
.search button:hover,
.actions a:hover,
.actions button:hover,
.chapter-tools button:hover,
.reader-bar a:hover,
.reader-bar button:hover {
    filter: brightness(.96);
}

.band {
    max-width: 1180px;
    margin: 0 auto;
    padding: 24px 20px;
}

.lead {
    display: grid;
    grid-template-columns: minmax(0, 1.45fr) minmax(280px, .75fr);
    gap: 22px;
    padding-top: 36px;
}

.lead-copy {
    border-radius: 8px;
    background: var(--ink);
    box-shadow: var(--shadow);
    color: #fff;
    min-height: 210px;
    padding: 30px;
}

.eyebrow {
    color: #f3c56a;
    font-size: 13px;
    font-weight: 900;
    letter-spacing: 0;
    margin: 0 0 8px;
}

h1,
h2,
h3 {
    letter-spacing: 0;
    line-height: 1.2;
    margin: 0;
}

h1 {
    font-size: 42px;
}

.lead-copy p {
    color: rgba(255, 255, 255, .78);
    font-size: 17px;
    margin: 14px 0 0;
    max-width: 620px;
}

.stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin-top: 24px;
}

.stat {
    border: 1px solid rgba(255, 255, 255, .16);
    border-radius: 8px;
    background: rgba(255, 255, 255, .08);
    padding: 13px;
}

.stat strong {
    display: block;
    color: #fff;
    font-size: 22px;
    line-height: 1.1;
}

.stat span {
    color: rgba(255, 255, 255, .64);
    font-size: 12px;
}

.side-panel {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
    padding: 22px;
}

.side-panel h2 {
    font-size: 21px;
    margin-bottom: 12px;
}

.side-list {
    display: grid;
    gap: 12px;
    margin: 0;
    padding: 0;
}

.side-list li {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    border-bottom: 1px solid var(--line);
    color: var(--muted);
    list-style: none;
    padding-bottom: 10px;
}

.side-list li:last-child {
    border-bottom: 0;
    padding-bottom: 0;
}

.side-list strong {
    color: var(--ink);
}

.section-title {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 14px;
}

.section-title h2 {
    font-size: 25px;
}

.section-title p {
    color: var(--muted);
    margin: 4px 0 0;
}

.book-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: 14px;
}

.book {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: 0 8px 22px rgba(24, 32, 47, .05);
    overflow: hidden;
}

.book a {
    display: grid;
    grid-template-columns: 78px minmax(0, 1fr);
    gap: 12px;
    min-height: 132px;
    padding: 12px;
    text-decoration: none;
}

.book img,
.book .generated-cover,
.detail-cover {
    width: 100%;
    aspect-ratio: 2 / 3;
    border-radius: 6px;
    background: #e7e1d7;
    object-fit: cover;
}

.generated-cover {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    overflow: hidden;
    padding: 12px 9px;
    background: linear-gradient(160deg, #263241 0%, #415268 55%, #bf3450 100%);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .2);
    color: #fff;
}

.generated-cover strong {
    color: #fff;
    font-size: 15px;
    line-height: 1.25;
    -webkit-line-clamp: 4;
}

.generated-cover em {
    color: rgba(255, 255, 255, .78);
    font-size: 12px;
    line-height: 1.35;
}

.book-info {
    display: flex;
    min-width: 0;
    flex-direction: column;
    gap: 5px;
}

.book strong {
    display: -webkit-box;
    overflow: hidden;
    color: var(--ink);
    font-size: 16px;
    line-height: 1.35;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.book span,
.book em {
    display: -webkit-box;
    overflow: hidden;
    color: var(--muted);
    font-size: 13px;
    font-style: normal;
    line-height: 1.45;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.book em {
    color: var(--blue);
    margin-top: auto;
}

.empty-state {
    border: 1px dashed #c9d2d8;
    border-radius: 8px;
    background: rgba(255, 254, 253, .65);
    color: var(--muted);
    padding: 20px;
}

.update-table {
    width: 100%;
    border-collapse: collapse;
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
}

.update-table th,
.update-table td {
    border-bottom: 1px solid var(--line);
    padding: 10px 12px;
    text-align: left;
    vertical-align: middle;
}

.update-table th {
    background: #f2f5f7;
    color: var(--ink-soft);
    font-size: 13px;
}

.detail-head,
.chapter-tools,
.volume-list {
    max-width: 1080px;
    margin: 0 auto;
}

.detail-head {
    display: grid;
    grid-template-columns: 184px minmax(0, 1fr);
    gap: 26px;
    padding: 38px 20px 24px;
}

.detail-card {
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
    padding: 26px;
}

.detail-meta {
    color: var(--muted);
    font-weight: 700;
    margin: 12px 0;
}

.detail-desc {
    color: var(--ink-soft);
    margin: 0 0 18px;
}

.actions,
.chapter-tools,
.reader-bar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.chapter-tools {
    padding: 0 20px 16px;
}

.chapter-tools form {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.chapter-tools input[type="number"] {
    width: 92px;
}

.catalog-note {
    max-width: 1080px;
    margin: 0 auto 12px;
    padding: 0 20px;
    color: var(--muted);
    font-weight: 700;
}

.volume-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 8px;
    padding: 0 20px 44px;
}

.volume-list a {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--ink);
    overflow: hidden;
    padding: 11px 12px;
    text-decoration: none;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.reader {
    background: #fffdf9;
}

.reader.green {
    background: #eef7ea;
}

.reader.night {
    background: #111827;
    color: #dbe3ee;
}

.reader-bar {
    position: sticky;
    top: 0;
    z-index: 8;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 254, 253, .95);
    padding: 10px max(16px, calc((100vw - 900px) / 2));
    backdrop-filter: blur(10px);
}

.reader.night .reader-bar {
    border-color: #243044;
    background: rgba(17, 24, 39, .95);
}

.reader-bar input[type="range"] {
    width: 120px;
}

.reader-progress {
    color: var(--muted);
    font-weight: 800;
    min-width: 44px;
}

.reader-content {
    max-width: 800px;
    margin: 0 auto;
    padding: 34px 20px 80px;
    font-size: 18px;
    line-height: 1.88;
}

.reader-content h1,
.reader-content h2 {
    margin-bottom: 20px;
}

.reader-content p {
    margin: 0 0 1em;
}

.error-box {
    max-width: 760px;
    margin: 72px auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
    padding: 32px;
}

.error-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

@media(max-width:900px) {
    .topbar-inner,
    .lead,
    .detail-head {
        grid-template-columns: 1fr;
    }

    .main-nav {
        justify-content: flex-start;
        overflow-x: auto;
    }

    .search {
        min-width: 0;
    }

    .detail-cover {
        max-width: 170px;
    }
}

@media(max-width:640px) {
    h1 {
        font-size: 32px;
    }

    .topbar-inner,
    .band {
        padding-left: 16px;
        padding-right: 16px;
    }

    .lead-copy,
    .detail-card,
    .side-panel,
    .error-box {
        padding: 20px;
    }

    .stats {
        grid-template-columns: 1fr;
    }

    .book-grid {
        grid-template-columns: 1fr;
    }

    .reader-bar {
        flex-wrap: nowrap;
        overflow-x: auto;
    }
}
