:root {
    --bg: #efe6d6;
    --paper: #fbf7ef;
    --ink: #241c16;
    --muted: #6f6256;
    --line: #e4d8c6;
    --seal: #8d332c;
    --seal-soft: #f6e1dc;
    --shadow: 0 18px 50px rgba(70, 42, 18, 0.08);
    --serif: "Noto Serif SC", "Songti SC", "SimSun", serif;
    --sans: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
    --read-size: 20px;
    --read-leading: 2;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    min-height: 100vh;
    background:
        radial-gradient(circle at top left, rgba(141, 51, 44, 0.08), transparent 28rem),
        var(--bg);
    color: var(--ink);
    font-family: var(--sans);
    font-size: 16px;
    line-height: 1.6;
}
a { color: inherit; }
button, input, textarea { font: inherit; color: inherit; }
h1, h2, h3, strong { font-family: var(--serif); font-weight: 600; }

.site-header {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    column-gap: 1.5rem;
    padding: 1rem max(1rem, 6vw);
    padding-top: max(1rem, env(safe-area-inset-top));
    position: sticky;
    top: 0;
    z-index: 20;
    background: rgba(239, 230, 214, 0.92);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid transparent;
}
.brand { display: flex; gap: 0.75rem; align-items: center; text-decoration: none; min-width: 0; }
.brand strong { display: block; font-size: 1.25rem; letter-spacing: 0.12em; }
.brand small { color: var(--muted); letter-spacing: 0.18em; }
.seal {
    width: 2.4rem;
    height: 2.4rem;
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    border: 2px solid var(--seal);
    color: var(--seal);
    font-family: var(--serif);
    font-size: 1.2rem;
}
.site-nav { display: flex; gap: 1.1rem; min-width: 0; }
.site-nav a { text-decoration: none; color: var(--muted); white-space: nowrap; }
.site-nav a.is-active, .site-nav a:hover { color: var(--ink); }
.account { display: flex; align-items: center; gap: 0.8rem; }
.who { color: var(--muted); }
.text-button { background: none; border: 0; padding: 0; cursor: pointer; color: var(--muted); }

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--seal);
    color: #fffaf6;
    text-decoration: none;
    border: 0;
    border-radius: 999px;
    padding: 0.7rem 1.2rem;
    cursor: pointer;
}
.button-small { padding: 0.4rem 0.9rem; }
.button-ghost { background: transparent; color: var(--ink); border: 1px solid var(--ink); }

main { padding: 1.5rem 6vw 4rem; }
.is-reader main { padding: 0; }
.is-reader .site-header { display: none; }

.hero { max-width: 46rem; padding: 3.5rem 0 1rem; }
.hero h1 { font-size: clamp(2.4rem, 5vw, 4.4rem); line-height: 1.2; margin: 0.4rem 0 1rem; }
.lede { font-size: 1.1rem; color: var(--muted); max-width: 36rem; }
.eyebrow { letter-spacing: 0.16em; color: var(--seal); font-size: 0.82rem; margin: 0; }
.hero-actions { display: flex; gap: 0.8rem; margin-top: 1.4rem; }
.continue {
    display: grid;
    margin-top: 2rem;
    max-width: 24rem;
    padding: 1rem 1.1rem;
    background: var(--paper);
    text-decoration: none;
    box-shadow: var(--shadow);
}
.continue span, .continue em { color: var(--muted); font-style: normal; }
.continue strong { font-size: 1.3rem; }

.shelf-block { margin-top: 2.5rem; }
.section-head, .page-head { display: flex; justify-content: space-between; align-items: end; gap: 1rem; }
.section-head h2, .page-head h1 { margin: 0; font-size: 1.8rem; }
.book-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}
.book-card {
    display: flex;
    gap: 0.9rem;
    padding: 1rem;
    background: var(--paper);
    text-decoration: none;
    box-shadow: var(--shadow);
    min-height: 8.5rem;
}
.book-card:hover { transform: translateY(-2px); }
.book-mark {
    flex: 0 0 3rem;
    height: 4.2rem;
    display: grid;
    place-items: center;
    background: var(--seal);
    color: #fffaf6;
    font-family: var(--serif);
    font-size: 1.4rem;
}
.book-card-body { display: flex; flex-direction: column; gap: 0.2rem; }
.book-card-body strong { font-size: 1.2rem; }
.meta, .quiet { color: var(--muted); }
.search { display: flex; gap: 0.5rem; }
.search input, .auth-card input, .toc input, textarea {
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 0.65rem 0.9rem;
}
textarea { border-radius: 0.6rem; width: 100%; min-height: 4.5rem; }
.filters { display: flex; gap: 0.6rem; flex-wrap: wrap; margin: 1rem 0 1.4rem; }
.filters a {
    text-decoration: none;
    border: 1px solid var(--line);
    background: var(--paper);
    border-radius: 999px;
    padding: 0.35rem 0.8rem;
    color: var(--muted);
}
.filters a.is-active { color: var(--seal); border-color: var(--seal); }

.book-hero { max-width: 46rem; }
.book-hero h1 { font-size: clamp(2.2rem, 4vw, 3.6rem); margin: 0.3rem 0; }
.summary { font-size: 1.08rem; }
.source-line a { color: var(--seal); }
.chapter-index ol, .toc ol { list-style: none; padding: 0; margin: 0; }
.chapter-index { max-width: 46rem; margin-top: 2rem; }
.chapter-index a, .toc a {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    text-decoration: none;
    padding: 0.7rem 0;
    border-bottom: 1px solid var(--line);
}
.chapter-index em, .toc em { color: var(--seal); font-style: normal; font-size: 0.85rem; }

.reader,
.reader[data-theme="paper"] {
    --paper: #fbf7ef;
    --ink: #241c16;
    --muted: #6f6256;
    --line: #e4d8c6;
    --bg: #efe6d6;
}
.reader {
    min-height: 100vh;
    background: var(--bg);
    color: var(--ink);
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto 1fr;
    transition: background-color 0.25s ease, color 0.25s ease;
}
.reader .reader-toolbar,
.reader .reading,
.reader .toc,
.reader .notes {
    transition: background-color 0.25s ease, color 0.25s ease, border-color 0.25s ease;
}
.reader[data-theme="night"] {
    --paper: #221c17;
    --ink: #f3eadc;
    --muted: #b5a894;
    --line: #3c332b;
    --bg: #14110e;
}
.reader[data-theme="moss"] {
    --paper: #f3f6ef;
    --ink: #1d2a22;
    --muted: #5d6d62;
    --line: #d5e0d4;
    --bg: #e4eee4;
}
.reader-toolbar {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1.2rem;
    padding-top: max(0.75rem, env(safe-area-inset-top));
    background: var(--paper);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 60;
}
.reader-toolbar .back {
    text-decoration: none;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 34%;
}
.chapter-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tools { display: flex; align-items: center; gap: 0.35rem; flex-wrap: wrap; }
.tools button, .para-mark, .note-actions button {
    background: transparent;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 0.25rem 0.6rem;
    cursor: pointer;
}
.tools label { display: flex; align-items: center; gap: 0.3rem; color: var(--muted); font-size: 0.85rem; }
.tools input[type="range"] { width: 5rem; }
.toc, .notes {
    position: fixed;
    z-index: 55;
    top: 0;
    bottom: 0;
    width: min(20rem, 88vw);
    padding: calc(3.6rem + env(safe-area-inset-top, 0px)) 1rem 1.25rem;
    background: var(--paper);
    border: 1px solid var(--line);
    box-shadow: 0 12px 40px rgba(36, 28, 22, 0.18);
    overflow: auto;
    visibility: hidden;
    pointer-events: none;
    transition: transform 0.22s ease, visibility 0.22s;
}
.toc {
    left: 0;
    transform: translateX(-105%);
    border-left: 0;
}
.notes {
    right: 0;
    transform: translateX(105%);
    border-right: 0;
}
.toc.is-open, .notes.is-open {
    visibility: visible;
    pointer-events: auto;
    transform: translateX(0);
}
.reader-backdrop {
    position: fixed;
    inset: 0;
    z-index: 50;
    background: rgba(36, 28, 22, 0.42);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease;
}
.reader-backdrop.is-visible {
    opacity: 1;
    pointer-events: auto;
}
body.reader-panel-open { overflow: hidden; }
.tools [data-panel][aria-expanded="true"],
.tools [data-theme][aria-pressed="true"] {
    background: color-mix(in srgb, var(--seal) 14%, var(--paper));
    border-color: color-mix(in srgb, var(--seal) 35%, var(--line));
    color: var(--seal);
}
.toc li.is-current a { color: var(--seal); }
.reading {
    background: var(--paper);
    padding: 2.5rem 8vw 4rem;
}
.reading h1 { font-size: 2rem; margin-top: 0.2rem; }
.para { display: grid; grid-template-columns: auto 1fr; gap: 0.6rem; align-items: start; }
.paragraph-text {
    margin: 0 0 1.15rem;
    font-family: var(--serif);
    font-size: var(--read-size);
    line-height: var(--read-leading);
}
.reader[data-pinyin="on"] .paragraph-text { line-height: calc(var(--read-leading) * 1.35); }
.reader[data-pinyin="on"] .reading h1 { margin-bottom: 0.6rem; }
.reader ruby { ruby-align: center; ruby-position: over; }
.reader rt { font-size: 0.42em; font-weight: 400; color: var(--muted); letter-spacing: 0.02em; }
.para-mark.is-on { background: var(--seal); color: white; border-color: var(--seal); }
.chapter-turn {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    margin-top: 2rem;
    padding-top: 1rem;
    border-top: 1px solid var(--line);
}
.chapter-turn a { text-decoration: none; }
.guest-hint { color: var(--muted); }
mark.hl { color: inherit; border-radius: 0.2rem; padding: 0 0.05rem; }
.hl-yellow, mark.hl-yellow { background: #f4e2a4; }
.hl-green, mark.hl-green { background: #d7e7c8; }
.hl-blue, mark.hl-blue { background: #d5e4f5; }
.hl-red, mark.hl-red { background: #f4d0cb; }
.reader[data-theme="night"] mark.hl-yellow { background: #6d5a28; }
.reader[data-theme="night"] mark.hl-green { background: #345238; }
.reader[data-theme="night"] mark.hl-blue { background: #2d455c; }
.reader[data-theme="night"] mark.hl-red { background: #6a3330; }
.note-card, .shelf-row, .auth-card {
    background: var(--paper);
    padding: 1rem;
    margin-bottom: 0.8rem;
    box-shadow: var(--shadow);
}
.note-card a { display: block; margin: 0.3rem 0; font-family: var(--serif); }
.note-actions { display: flex; gap: 0.4rem; }
.shelf-row { display: flex; justify-content: space-between; gap: 1rem; align-items: center; }
.shelf-row p { margin: 0.2rem 0 0; color: var(--muted); }
.auth-card { max-width: 26rem; margin: 2rem auto; display: grid; gap: 0.7rem; }
.auth-card h1 { margin: 0 0 0.4rem; }
.auth-card label { display: grid; gap: 0.3rem; }
.check { grid-template-columns: auto 1fr; align-items: center; }
.error { color: var(--seal); margin: 0; }
.empty, .empty-library { color: var(--muted); }
#select-toolbar {
    position: absolute;
    z-index: 30;
    display: flex;
    gap: 0.3rem;
    padding: 0.35rem;
    background: var(--ink);
    border-radius: 999px;
}
#select-toolbar button { background: transparent; color: #fffaf6; border: 0; cursor: pointer; }
.pager { display: flex; gap: 1rem; align-items: center; margin-top: 1.5rem; }
.pager a { color: var(--seal); }

@media (max-width: 980px) {
    main { padding: 1rem 1rem 3rem; }
    .reading { padding: 1.4rem 1rem 3rem; }
    .reader-toolbar {
        display: grid;
        grid-template-columns: minmax(0, auto) minmax(0, 1fr);
        gap: 0.35rem 0.75rem;
        padding: 0.55rem 0.85rem 0.45rem;
        padding-top: max(0.55rem, env(safe-area-inset-top));
    }
    .reader-toolbar .back { max-width: none; }
    .tools {
        grid-column: 1 / -1;
        flex-wrap: nowrap;
        overflow-x: auto;
        scrollbar-width: none;
        margin: 0 -0.85rem;
        padding: 0.15rem 0.85rem 0.2rem;
    }
    .tools::-webkit-scrollbar { display: none; }
    .tools button, .tools label { flex: 0 0 auto; }
}

@media (max-width: 760px) {
    .site-header {
        grid-template-columns: minmax(0, 1fr) auto;
        column-gap: 0.75rem;
        row-gap: 0.15rem;
        padding: 0.55rem 0.85rem 0.35rem;
        padding-top: max(0.55rem, env(safe-area-inset-top));
    }
    .brand small { display: none; }
    .brand { gap: 0.55rem; grid-column: 1; grid-row: 1; }
    .brand strong { font-size: 1.12rem; letter-spacing: 0.08em; }
    .seal { width: 2rem; height: 2rem; font-size: 1.05rem; }
    .site-nav {
        grid-column: 1 / -1;
        grid-row: 2;
        gap: 0.15rem 1rem;
        overflow-x: auto;
        scrollbar-width: none;
        margin: 0 -0.85rem;
        padding: 0.1rem 0.85rem 0.2rem;
    }
    .site-nav::-webkit-scrollbar { display: none; }
    .site-nav a {
        display: inline-flex;
        align-items: center;
        min-height: 2.5rem;
        padding: 0.2rem 0;
    }
    .account { gap: 0.65rem; grid-column: 2; grid-row: 1; }
    .who {
        max-width: 5.5rem;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .account a, .text-button {
        display: inline-flex;
        align-items: center;
        min-height: 2.5rem;
    }
    .page-head {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }
    .search { width: 100%; }
    .search input { flex: 1; min-width: 0; width: auto; }
}
