@font-face {
    font-family: 'HuWenMingChao';
    src: url('https://mx.bdfz.net/data/fonts/HuWenMingChaoTi.woff2') format('woff2');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

:root {
    --ghibli-bg: #fbfaf5;
    --ghibli-text: #5d5551;
    --ghibli-text-light: #8d837c;
    --ghibli-primary: #789594;
    --ghibli-primary-dark: #617d7b;
    --ghibli-accent: #b8cca7;
    --ghibli-warm: #e0d8cc;
    --ghibli-border: rgba(150, 137, 126, 0.28);
    --ghibli-panel: rgba(255, 255, 255, 0.68);
    --ghibli-panel-strong: rgba(255, 255, 255, 0.84);
    --ghibli-shadow: 0 18px 60px rgba(93, 85, 81, 0.13);
    --font-main: 'HuWenMingChao', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    scroll-behavior: smooth;
}

body {
    margin: 0;
    min-height: 100vh;
    color: var(--ghibli-text);
    font-family: var(--font-main);
    line-height: 1.65;
    background:
        linear-gradient(rgba(251, 250, 245, 0.82), rgba(251, 250, 245, 0.9)),
        url('background.jpg');
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
}

button,
input,
select {
    font: inherit;
}

button {
    border: 1px solid var(--ghibli-border);
    color: var(--ghibli-text);
    background: var(--ghibli-panel-strong);
    border-radius: 8px;
    cursor: pointer;
    transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

button:hover {
    transform: translateY(-1px);
    border-color: rgba(97, 125, 123, 0.48);
    background: rgba(255, 255, 255, 0.95);
}

input,
select {
    width: 100%;
    border: 1px solid var(--ghibli-border);
    border-radius: 8px;
    color: var(--ghibli-text);
    background: rgba(255, 255, 255, 0.82);
    outline: none;
}

input:focus,
select:focus {
    border-color: var(--ghibli-primary);
    box-shadow: 0 0 0 3px rgba(120, 149, 148, 0.16);
}

.shell {
    display: grid;
    grid-template-columns: minmax(310px, 380px) 1fr;
    min-height: 100vh;
}

.sidebar {
    height: 100vh;
    position: sticky;
    top: 0;
    display: grid;
    grid-template-rows: auto auto 1fr;
    gap: 18px;
    padding: 24px;
    border-right: 1px solid var(--ghibli-border);
    background: rgba(251, 250, 245, 0.72);
    backdrop-filter: blur(16px);
    overflow: hidden;
}

.brand {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.home-link {
    color: var(--ghibli-primary-dark);
    font-size: 2rem;
    line-height: 1;
    text-decoration: none;
}

#sync-status,
#book-count,
#result-count {
    color: var(--ghibli-text-light);
    font-size: 0.9rem;
    white-space: nowrap;
}

.search-panel,
.book-section,
.results-panel,
.reader-panel,
.overview {
    border: 1px solid var(--ghibli-border);
    border-radius: 8px;
    background: var(--ghibli-panel);
    box-shadow: var(--ghibli-shadow);
}

.search-panel {
    padding: 16px;
}

.field-label,
.eyebrow {
    display: block;
    color: var(--ghibli-primary-dark);
    font-size: 0.82rem;
    letter-spacing: 0;
}

.search-box {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    margin-top: 8px;
}

.search-box input {
    min-width: 0;
    padding: 10px 12px;
}

.search-box button,
.reader-actions button {
    padding: 10px 14px;
}

.filter-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 10px;
}

.filter-grid select {
    padding: 9px 10px;
}

.book-section {
    min-height: 0;
    display: grid;
    grid-template-rows: auto 1fr;
    overflow: hidden;
}

.section-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--ghibli-border);
}

.section-head h2 {
    margin: 0;
    color: var(--ghibli-primary-dark);
    font-size: 1.2rem;
    font-weight: normal;
}

.book-list {
    min-height: 0;
    overflow: auto;
    padding: 10px;
}

.book-item {
    width: 100%;
    display: grid;
    grid-template-columns: 52px 1fr;
    gap: 10px;
    margin-bottom: 8px;
    padding: 8px;
    text-align: left;
    border-radius: 8px;
}

.book-item.active {
    border-color: var(--ghibli-primary);
    background: rgba(232, 237, 229, 0.95);
}

.book-cover {
    width: 52px;
    aspect-ratio: 3 / 4;
    border-radius: 5px;
    object-fit: cover;
    background: var(--ghibli-warm);
}

.book-name {
    display: block;
    color: var(--ghibli-text);
    line-height: 1.4;
}

.book-detail {
    display: block;
    margin-top: 4px;
    color: var(--ghibli-text-light);
    font-size: 0.82rem;
}

.reader {
    min-width: 0;
    padding: 28px;
}

.overview {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 18px;
    padding: 28px;
}

.overview h1 {
    margin: 0;
    color: var(--ghibli-primary-dark);
    font-size: clamp(2.2rem, 5vw, 4.5rem);
    font-weight: normal;
    line-height: 1;
}

.lead {
    max-width: 620px;
    margin: 14px 0 0;
    color: var(--ghibli-text);
}

.stats {
    display: grid;
    grid-template-columns: repeat(2, minmax(90px, 1fr));
    gap: 8px;
}

.stat {
    min-width: 100px;
    padding: 10px 12px;
    border: 1px solid var(--ghibli-border);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.58);
}

.stat strong {
    display: block;
    color: var(--ghibli-primary-dark);
    font-size: 1.4rem;
    font-weight: normal;
}

.stat span {
    color: var(--ghibli-text-light);
    font-size: 0.82rem;
}

.hidden {
    display: none !important;
}

.results-panel,
.reader-panel {
    margin-bottom: 18px;
    overflow: hidden;
}

.results {
    display: grid;
    gap: 8px;
    max-height: 36vh;
    overflow: auto;
    padding: 10px;
}

.result-item {
    display: grid;
    grid-template-columns: 80px 1fr;
    gap: 12px;
    width: 100%;
    padding: 10px;
    text-align: left;
}

.result-thumb {
    width: 80px;
    aspect-ratio: 3 / 4;
    border-radius: 6px;
    object-fit: cover;
    background: var(--ghibli-warm);
}

.result-title {
    color: var(--ghibli-primary-dark);
}

.result-meta,
.result-snippet {
    color: var(--ghibli-text-light);
    font-size: 0.9rem;
}

mark {
    color: #7b5330;
    background: #f8e8a8;
    border-radius: 4px;
    padding: 0 2px;
}

.reader-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 18px 20px;
    border-bottom: 1px solid var(--ghibli-border);
}

.reader-top h2 {
    margin: 0;
    color: var(--ghibli-primary-dark);
    font-size: 1.45rem;
    font-weight: normal;
}

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

#page-indicator {
    min-width: 86px;
    text-align: center;
    color: var(--ghibli-text-light);
}

.reader-layout {
    display: grid;
    grid-template-columns: minmax(230px, 300px) minmax(0, 1fr);
    min-height: 68vh;
}

.page-nav {
    border-right: 1px solid var(--ghibli-border);
    background: rgba(255, 255, 255, 0.38);
    overflow: auto;
    max-height: calc(100vh - 170px);
}

.toc-list {
    display: grid;
    gap: 6px;
    padding: 12px;
    border-bottom: 1px solid var(--ghibli-border);
}

.toc-link {
    width: 100%;
    padding: 7px 8px;
    text-align: left;
    color: var(--ghibli-text);
    background: rgba(255, 255, 255, 0.56);
}

.page-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(46px, 1fr));
    gap: 6px;
    padding: 12px;
}

.page-button {
    min-height: 38px;
    padding: 6px 4px;
    color: var(--ghibli-text-light);
}

.page-button.current {
    color: #fff;
    border-color: var(--ghibli-primary-dark);
    background: var(--ghibli-primary);
}

.page-frame {
    display: grid;
    place-items: center;
    gap: 10px;
    margin: 0;
    padding: 18px;
    min-width: 0;
}

#page-image {
    max-width: min(100%, 980px);
    max-height: calc(100vh - 190px);
    object-fit: contain;
    border-radius: 8px;
    background: white;
    box-shadow: 0 20px 70px rgba(93, 85, 81, 0.22);
}

#page-caption {
    color: var(--ghibli-text-light);
    font-size: 0.9rem;
}

@media (max-width: 900px) {
    body {
        background-attachment: scroll;
    }

    .shell {
        display: block;
    }

    .sidebar {
        position: static;
        height: auto;
        max-height: none;
        border-right: none;
        border-bottom: 1px solid var(--ghibli-border);
        overflow: visible;
    }

    .book-list {
        max-height: 44vh;
    }

    .reader {
        padding: 14px;
    }

    .overview,
    .reader-top {
        display: block;
    }

    .stats {
        margin-top: 18px;
    }

    .reader-actions {
        margin-top: 12px;
        justify-content: space-between;
    }

    .reader-layout {
        grid-template-columns: 1fr;
    }

    .page-nav {
        border-right: none;
        border-bottom: 1px solid var(--ghibli-border);
        max-height: 38vh;
    }

    #page-image {
        max-height: 74vh;
    }
}
