:root {
    --reader-paper: #fff;
    --reader-ink: #191919;
    --reader-line: rgba(0, 0, 0, 0.12);
    --reader-soft: #f3f4f6;
    --reader-font-size: 1.08rem;
}

html.dark {
    --reader-paper: #111214;
    --reader-ink: #ededed;
    --reader-line: rgba(255, 255, 255, 0.14);
    --reader-soft: #191a1d;
}

.header.mobile-header .logo {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 1.45rem;
    letter-spacing: -0.02em;
    line-height: 1;
    margin: 0;
}

.book-reader {
    min-height: 80vh;
    padding: 1.5rem 1rem 4rem;
}

.book-heading,
.reader-shell {
    margin-left: auto;
    margin-right: auto;
    max-width: 1040px;
}

.book-heading {
    padding: 1rem 0 1.5rem;
}

.book-heading-inner {
    max-width: 780px;
}

.back-link {
    color: var(--accent);
    display: inline-block;
    font-size: 0.82rem;
    font-weight: 600;
    margin-bottom: 1rem;
    text-decoration: none;
}

.back-link::before {
    content: "‹ ";
}

.book-kicker {
    color: var(--accent);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    margin: 0 0 0.6rem;
    text-transform: uppercase;
}

.book-heading h1 {
    color: var(--text-main);
    font-family: Georgia, "Times New Roman", serif;
    font-size: clamp(2.5rem, 6vw, 4.2rem);
    font-weight: 500;
    line-height: 1;
    margin: 0;
}

.book-byline {
    color: var(--text-main);
    font-size: 1.05rem;
    margin: 1rem 0 0;
}

.book-edition {
    color: var(--text-muted);
    font-size: 0.82rem;
    margin: 0.35rem 0 0;
}

.reader-shell {
    background: transparent;
    border: 0;
    border-radius: 0;
    color: var(--reader-ink);
    overflow: visible;
}

@media (min-width: 821px) and (max-width: 1440px),
       (min-width: 821px) and (max-height: 850px) {
    .header.mobile-header .logo {
        font-size: 1.08rem;
    }
}

@media (max-width: 820px) {
    .header.mobile-header .logo {
        font-size: clamp(1.05rem, 5.15vw, 1.35rem);
    }
}

.reader-topbar {
    align-items: center;
    border-bottom: 0;
    display: flex;
    gap: 1rem;
    justify-content: space-between;
    padding: 0.85rem 0 1rem;
}

.reader-modes {
    background: var(--reader-soft);
    border: 1px solid var(--reader-line);
    border-radius: 7px;
    display: inline-grid;
    grid-template-columns: repeat(2, auto);
    padding: 3px;
}

.mode-button {
    background: transparent;
    border: 0;
    border-radius: 5px;
    color: var(--text-muted);
    cursor: pointer;
    font: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    min-height: 34px;
    padding: 0.4rem 0.75rem;
}

.mode-button.active {
    background: var(--reader-paper);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
    color: var(--reader-ink);
}

.reader-actions {
    display: flex;
    gap: 0.4rem;
}

.text-button,
.book-search-form button {
    background: transparent;
    border: 1px solid var(--reader-line);
    border-radius: 6px;
    color: var(--reader-ink);
    cursor: pointer;
    font: inherit;
    font-size: 0.78rem;
    font-weight: 600;
    min-height: 36px;
    padding: 0.45rem 0.7rem;
    text-decoration: none;
}

.reader-panel {
    background: var(--reader-soft);
    border: 1px solid var(--reader-line);
    border-radius: 8px;
    margin-bottom: 1rem;
    padding: 1rem;
}

.reader-panel[hidden] {
    display: none;
}

.panel-heading {
    align-items: center;
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.8rem;
}

.panel-heading h2 {
    color: var(--reader-ink);
    font-size: 0.92rem;
    margin: 0;
}

.panel-close {
    background: transparent;
    border: 0;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.45rem;
    height: 32px;
    line-height: 1;
    width: 32px;
}

.toc-list {
    display: grid;
    gap: 0.25rem;
    max-height: 330px;
    overflow: auto;
}

.toc-link {
    background: transparent;
    border: 0;
    border-radius: 5px;
    color: var(--reader-ink);
    cursor: pointer;
    display: grid;
    font: inherit;
    font-size: 0.8rem;
    gap: 1rem;
    grid-template-columns: minmax(0, 1fr) auto;
    padding: 0.55rem 0.65rem;
    text-align: left;
}

.toc-link:hover,
.toc-link.current {
    background: rgba(77, 150, 255, 0.12);
}

.toc-page {
    color: var(--text-muted);
}

.book-search-form {
    display: grid;
    gap: 0.5rem;
    grid-template-columns: minmax(0, 1fr) auto;
}

.book-search-form input {
    background: var(--reader-paper);
    border: 1px solid var(--reader-line);
    border-radius: 6px;
    color: var(--reader-ink);
    font: inherit;
    min-height: 42px;
    outline: 0;
    padding: 0.6rem 0.75rem;
}

.book-search-form input:focus {
    border-color: var(--accent);
}

.book-search-form button {
    background: var(--reader-ink);
    color: var(--reader-paper);
    min-height: 42px;
}

.search-summary {
    color: var(--text-muted);
    font-size: 0.76rem;
    margin: 0.7rem 0 0;
}

.search-results {
    display: grid;
    gap: 0.35rem;
    margin-top: 0.75rem;
    max-height: 330px;
    overflow: auto;
}

.search-result {
    background: var(--reader-paper);
    border: 1px solid var(--reader-line);
    border-radius: 6px;
    color: var(--reader-ink);
    cursor: pointer;
    display: grid;
    font: inherit;
    gap: 0.25rem;
    padding: 0.65rem 0.75rem;
    text-align: left;
}

.search-result strong {
    color: var(--accent);
    font-size: 0.76rem;
}

.search-result span {
    color: var(--text-muted);
    font-size: 0.78rem;
    line-height: 1.4;
}

.page-toolbar {
    align-items: center;
    border-bottom: 0;
    display: grid;
    gap: 0.6rem;
    grid-template-columns: 38px auto 38px minmax(0, 1fr) auto;
    min-height: 58px;
    padding: 0.6rem 0;
}

.page-toolbar-bottom {
    border-bottom: 0;
    border-top: 0;
    grid-template-columns: 38px auto 38px;
    justify-content: center;
    padding-top: 1rem;
}

.page-arrow,
.font-controls button {
    background: var(--reader-soft);
    border: 1px solid var(--reader-line);
    border-radius: 6px;
    color: var(--reader-ink);
    cursor: pointer;
    font: inherit;
    height: 36px;
    min-width: 36px;
}

.page-arrow {
    font-size: 1.55rem;
    line-height: 1;
}

.page-arrow:disabled {
    cursor: default;
    opacity: 0.35;
}

.page-field {
    align-items: center;
    color: var(--text-muted);
    display: flex;
    font-size: 0.76rem;
    gap: 0.4rem;
    white-space: nowrap;
}

.page-input {
    appearance: textfield;
    background: var(--reader-paper);
    border: 1px solid var(--reader-line);
    border-radius: 5px;
    color: var(--reader-ink);
    font: inherit;
    font-weight: 600;
    height: 34px;
    text-align: center;
    width: 54px;
}

.page-input::-webkit-inner-spin-button,
.page-input::-webkit-outer-spin-button {
    appearance: none;
}

.current-section {
    color: var(--text-muted);
    font-size: 0.72rem;
    overflow: hidden;
    text-align: center;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.font-controls {
    display: flex;
    gap: 0.25rem;
}

.page-content {
    font-family: Georgia, "Times New Roman", serif;
    font-size: var(--reader-font-size);
    line-height: 1.75;
    margin: 0 auto;
    max-width: 760px;
    min-height: 620px;
    padding: clamp(2rem, 6vw, 5rem) clamp(1.25rem, 7vw, 5rem);
}

.page-content p {
    margin: 0 0 1.15em;
    text-align: justify;
}

.page-content .book-title {
    font-size: 2.3em;
    line-height: 1.08;
    margin: 0 0 0.4em;
    text-align: center;
}

.page-content .book-subtitle {
    font-size: 1.05em;
    margin: 0 0 1.6em;
    text-align: center;
}

.page-content .chapter,
.page-content .heading {
    font-size: 1.05em;
    letter-spacing: 0.04em;
    margin: 2.2em 0 0.8em;
    text-align: center;
    text-transform: uppercase;
}

.page-content .subheading {
    font-size: 1.05em;
    margin: 1.8em 0 0.75em;
}

.page-content .divider {
    color: var(--text-muted);
    margin: 2em 0;
    text-align: center;
}

.page-content .toc-item {
    border-bottom: 1px solid var(--reader-line);
    font-size: 0.92em;
    margin: 0;
    padding: 0.5em 0;
    text-align: left;
}

.page-content .signature {
    font-size: 0.92em;
    margin-left: auto;
    max-width: 280px;
    text-align: right;
}

.page-content .note {
    border-top: 1px solid var(--reader-line);
    color: var(--text-muted);
    font-size: 0.8em;
    margin-top: 2em;
    padding-top: 1em;
}

.original-page {
    background: transparent;
    margin: 0;
    min-height: 620px;
    padding: 1.25rem 0;
    text-align: center;
}

.original-page[hidden] {
    display: none;
}

.original-page img {
    background: white;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.16);
    display: block;
    height: auto;
    margin: 0 auto;
    max-width: min(100%, 920px);
}

.original-page figcaption {
    color: var(--text-muted);
    font-size: 0.72rem;
    margin-top: 0.8rem;
}

@media (max-width: 720px) {
    .book-reader {
        padding: 1rem 0.65rem 2.5rem;
    }

    .book-heading {
        padding: 1rem 0.3rem 1.6rem;
    }

    .back-link {
        margin-bottom: 1.35rem;
    }

    .reader-topbar {
        align-items: stretch;
        flex-direction: column;
        gap: 0.6rem;
    }

    .reader-modes,
    .reader-actions {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
    }

    .reader-actions {
        grid-template-columns: repeat(3, 1fr);
    }

    .text-button {
        text-align: center;
    }

    .page-toolbar {
        grid-template-columns: 36px minmax(0, auto) 36px;
        justify-content: center;
        padding: 0.6rem;
    }

    .current-section {
        grid-column: 1 / -1;
        grid-row: 2;
        max-width: 100%;
    }

    .font-controls {
        grid-column: 1 / -1;
        justify-content: center;
    }

    .page-toolbar-bottom .page-field {
        grid-column: auto;
    }

    .page-content {
        line-height: 1.68;
        min-height: 520px;
        padding: 2.2rem 1.1rem 3rem;
    }

    .page-content p {
        text-align: left;
    }

    .original-page {
        min-height: 520px;
        padding: 0.7rem;
    }

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

@media (max-width: 390px) {
    .page-field > span:first-child {
        display: none;
    }

    .book-heading h1 {
        font-size: 2.45rem;
    }
}
