@import url('theme.css');

/* 阅读模式 — 使用 theme.css 统一深色主题 */
:root {
    --reading-header-h: 56px;
    --reading-radius: 12px;
    --annotation-sidebar-w: 220px;
    --reading-chat-w: 320px;
    --reader-panel-pad-y: 20px;
    --reader-panel-pad-bottom: 28px;
    --reader-mobile-bottom-inset: 14px;
    --reader-max-height: calc(
        100vh - var(--reading-header-h) - var(--reader-panel-pad-y) - var(--reader-panel-pad-bottom) - 8px
    );
    --c-reading-selection-bg: rgba(59, 130, 246, 0.52);
    --c-reading-selection-color: #ffffff;
    --c-reading-chat-underline: #60a5fa;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    height: 100%;
}

body.reading-page {
    font-family: var(--c-font-family);
    background: var(--c-bg-body);
    color: var(--c-text);
    min-height: 100vh;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.reading-header {
    height: var(--reading-header-h);
    padding: 0 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px solid var(--c-border);
    background: var(--c-bg-main);
    backdrop-filter: blur(8px);
    position: sticky;
    top: 0;
    z-index: 20;
}

.reading-header__left {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    flex: 1;
}

.reading-header__title-row {
    display: flex;
    align-items: baseline;
    gap: 8px;
    min-width: 0;
    flex: 1;
    flex-wrap: nowrap;
}

.reading-header__title {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex-shrink: 1;
    min-width: 0;
    max-width: 36%;
}

.reading-header__subtitle {
    font-size: 13px;
    color: var(--c-text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex-shrink: 0;
    max-width: 22%;
}

.reading-header__progress {
    font-size: 13px;
    color: var(--c-text-muted);
    white-space: nowrap;
    flex-shrink: 0;
}

.reading-header__progress::before {
    content: '·';
    margin-right: 8px;
    color: var(--c-text-faint);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.header-btn {
    border: 1px solid var(--c-border);
    background: var(--c-bg-surface);
    color: var(--c-text);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.header-btn:hover {
    background: var(--c-bg-card-hover);
    border-color: var(--c-border-strong);
}

.header-btn--icon {
    width: 36px;
    height: 36px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.header-btn--active {
    border-color: var(--c-accent-border);
    background: var(--c-accent-soft);
    color: var(--c-accent);
}

.reading-font-controls {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px;
    border: 1px solid var(--c-border);
    border-radius: 8px;
    background: var(--c-bg-surface);
}

.reading-font-controls[hidden] {
    display: none !important;
}

.reading-font-controls__label {
    min-width: 42px;
    text-align: center;
    font-size: 12px;
    color: var(--c-text-muted);
    user-select: none;
}

.reading-font-controls .header-btn--icon {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    font-size: 15px;
    font-weight: 600;
}

.reading-font-controls .header-btn--icon:hover {
    background: var(--c-bg-card-hover);
}

.reading-font-controls .header-btn--icon:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.reading-main {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

body.reading-in-book .reading-main {
    overflow: hidden;
}

.book-library[hidden],
.reader-panel[hidden] {
    display: none !important;
}

.book-library {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    width: 100%;
    padding: 24px;
    padding-bottom: max(32px, env(safe-area-inset-bottom, 0px));
    scrollbar-width: thin;
    scrollbar-color: var(--c-border-subtle) transparent;
}

.book-library::-webkit-scrollbar {
    width: 6px;
}

.book-library::-webkit-scrollbar-track {
    background: transparent;
}

.book-library::-webkit-scrollbar-thumb {
    background: var(--c-border-subtle);
    border-radius: 3px;
}

.book-library::-webkit-scrollbar-thumb:hover {
    background: var(--c-border);
}

.book-library__intro,
.book-grid {
    max-width: 1100px;
    margin-left: auto;
    margin-right: auto;
    width: 100%;
}

.book-library__intro h2 {
    margin: 0 0 8px;
    font-size: 22px;
}

.book-library__intro p {
    margin: 0 0 24px;
    color: var(--c-text-muted);
}

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

.book-grid__loading,
.book-grid__empty,
.book-grid__error {
    grid-column: 1 / -1;
    text-align: center;
    color: var(--c-text-muted);
    padding: 48px 16px;
}

.book-card--unavailable {
    opacity: 0.55;
    cursor: not-allowed;
}

.book-card--unavailable:hover {
    transform: none;
    border-color: var(--c-border);
    box-shadow: none;
    background: var(--c-bg-card);
}

.book-card__status {
    margin-top: auto;
    font-size: 12px;
    color: var(--c-danger);
}

.book-card {
    border: 1px solid var(--c-border);
    background: var(--c-bg-card);
    border-radius: var(--reading-radius);
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
    display: flex;
    flex-direction: column;
}

.book-card:hover {
    transform: translateY(-2px);
    border-color: var(--c-accent-border);
    box-shadow: var(--c-shadow-card);
    background: var(--c-bg-card-hover);
}

.book-card__cover {
    aspect-ratio: 3 / 4;
    background: linear-gradient(135deg, var(--c-bg-raised), var(--c-bg-code));
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.book-card__cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.book-card__cover-placeholder {
    font-size: 48px;
    opacity: 0.5;
}

.book-card__body {
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
}

.book-card__title {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    line-height: 1.35;
}

.book-card__author {
    margin: 0;
    font-size: 13px;
    color: var(--c-text-muted);
}

.book-card__progress {
    margin-top: auto;
    font-size: 12px;
    color: var(--c-success);
}

.book-card__progress--new {
    color: var(--c-text-muted);
}

/* 阅读区：三栏布局（标注树 + EPUB + 对话面板） */
.reader-panel {
    flex: 1;
    min-height: 0;
    display: flex;
    align-items: stretch;
    gap: 16px;
    padding: var(--reader-panel-pad-y) 16px var(--reader-panel-pad-bottom);
}

.annotation-sidebar {
    width: var(--annotation-sidebar-w);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--c-border);
    border-radius: var(--reading-radius);
    background: var(--c-bg-card);
    overflow: hidden;
    min-height: 0;
    max-height: var(--reader-max-height);
}

.annotation-sidebar[hidden] {
    display: none !important;
}

.annotation-sidebar__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--c-border);
    flex-shrink: 0;
    background: var(--c-bg-card);
}

.annotation-sidebar__title {
    margin: 0;
    font-size: 13px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
}

.annotation-sidebar__close {
    border: none;
    background: transparent;
    color: var(--c-text-muted);
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
}

.annotation-sidebar__close:hover {
    color: var(--c-text);
}

.annotation-tree {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
    min-height: 120px;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.annotation-tree::-webkit-scrollbar {
    display: none;
}

.annotation-tree__empty,
.annotation-tree__error {
    padding: 16px 14px;
    font-size: 12px;
    color: var(--c-text-muted);
    line-height: 1.5;
}

.annotation-tree__error {
    color: var(--c-danger);
}

.annotation-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.annotation-chapter {
    margin-bottom: 8px;
}

.annotation-chapter__title {
    padding: 6px 14px;
    font-size: 12px;
    font-weight: 600;
    color: var(--c-text-secondary);
}

.annotation-chapter__list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.annotation-item {
    padding: 0 8px;
    margin-bottom: 2px;
}

.annotation-item--active .annotation-item__btn {
    background: var(--c-accent-soft);
    border-color: var(--c-accent-border);
}

.annotation-item--has-chat .annotation-item__label {
    color: var(--c-text);
    text-decoration: underline;
    text-decoration-color: var(--c-reading-chat-underline, var(--c-link));
    text-underline-offset: 2px;
}

.annotation-item--memo .annotation-item__label::before {
    content: '✎ ';
    color: var(--c-text-muted);
    font-size: 11px;
}

.annotation-item__btn {
    width: 100%;
    min-width: 0;
    border: 1px solid transparent;
    background: transparent;
    color: var(--c-text);
    border-radius: 6px;
    padding: 6px 8px;
    font-size: 12px;
    text-align: left;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.annotation-item__btn:hover {
    background: var(--c-bg-surface);
    border-color: var(--c-border);
}

.annotation-item__label {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 500;
}

.annotation-item__preview {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 11px;
    color: var(--c-text-muted);
    line-height: 1.35;
}

/* 阅读工作区：主阅读区 + 对话侧栏（对齐 chat-workspace） */
.reader-workspace {
    flex: 1;
    min-width: 0;
    min-height: 0;
    display: flex;
    align-items: stretch;
    gap: 16px;
    height: var(--reader-max-height);
    max-height: var(--reader-max-height);
}

.reader-stage {
    flex: 1 1 0;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.reader-mobile-meta {
    display: none;
    flex-shrink: 0;
    padding: 10px 14px 8px;
    border: 1px solid var(--c-border);
    border-bottom: none;
    border-radius: var(--reading-radius) var(--reading-radius) 0 0;
    background: var(--c-bg-card);
}

.reader-mobile-meta__title {
    display: block;
    margin: 0 0 4px;
    font-size: 15px;
    font-weight: 600;
    line-height: 1.35;
    color: var(--c-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-height: 1.35em;
}

.reader-mobile-meta__row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-width: 0;
}

.reader-mobile-meta__author {
    font-size: 12px;
    color: var(--c-text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
    flex: 1;
}

.reader-mobile-meta__progress {
    font-size: 12px;
    color: var(--c-text-muted);
    white-space: nowrap;
    flex-shrink: 0;
}

.reading-panel-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 110;
    background: var(--c-overlay);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}

.reading-panel-backdrop:not([hidden]) {
    display: block;
}

/* 划词对话侧栏：复用 chat.css 消息/输入样式，收窄布局变量 */
.reading-chat-panel.main-area {
    flex: 0 0 var(--reading-chat-w);
    width: var(--reading-chat-w);
    align-self: stretch;
    border: 1px solid var(--c-border);
    border-radius: var(--reading-radius);
    background: var(--c-bg-main);
    overflow: hidden;
    min-height: 0;
    max-height: var(--reader-max-height);
    --msg-side-gutter: 0;
    --msg-h-padding: 10px;
    --msg-header-name-size: 13px;
    --msg-header-time-size: 10px;
    --msg-gap: 4px;
}

.reading-chat-panel[hidden] {
    display: none !important;
}

.reading-chat-panel__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--c-border);
    flex-shrink: 0;
    background: var(--c-bg-main);
}

.reading-chat-panel__title {
    margin: 0;
    font-size: 13px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
}

.reading-chat-panel__close {
    border: none;
    background: transparent;
    color: var(--c-text-muted);
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
}

.reading-chat-panel__close:hover {
    color: var(--c-text);
}

.reading-chat-panel .chat-container {
    padding: 12px var(--msg-h-padding);
    gap: 14px;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.reading-chat-panel .chat-container::-webkit-scrollbar {
    display: none;
}

.reading-chat-panel .input-area {
    padding: 6px var(--msg-h-padding) 8px;
}

.reading-chat-panel .composer-body textarea {
    font-size: 12px;
    min-height: 36px;
}

.reading-chat-panel .input-container {
    width: 100%;
    margin-left: 0;
    margin-right: 0;
}

.reading-chat-panel .msg-row {
    width: 100%;
}

.reading-chat-panel .msg-block {
    max-width: 100%;
}

.reading-chat-panel .msg-aside {
    display: none;
}

.reading-chat-panel .msg-header {
    display: none;
}

.reading-chat-panel .composer-toolbar--compact {
    justify-content: space-between;
    padding: 6px 8px;
}

.reading-chat-panel .composer-toolbar--compact .toolbar-left,
.reading-chat-panel .composer-toolbar--compact .toolbar-right {
    display: flex;
    align-items: center;
}

.reading-chat-panel .composer-toolbar--compact .toolbar-right {
    margin-left: 0;
}

.reading-mode-toggle {
    gap: 4px;
    padding: 2px;
    border: 1px solid var(--c-border);
    border-radius: 8px;
    background: var(--c-bg-surface);
}

.reading-mode-btn {
    border: none;
    background: transparent;
    color: var(--c-text-muted);
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
}

.reading-mode-btn:hover {
    color: var(--c-text);
    background: var(--c-bg-card-hover);
}

.reading-mode-btn--active {
    background: var(--c-accent-soft);
    color: var(--c-accent);
}

.reading-mode-btn--active:hover {
    background: var(--c-accent-soft);
    color: var(--c-accent);
}

.reading-chat-panel .message-content {
    font-size: 12px;
}

.reading-chat-panel .message-content h1,
.reading-chat-panel .message-content h2,
.reading-chat-panel .message-content h3 {
    font-size: 13px;
}

.reading-chat-panel .msg-bubble {
    padding: 8px 10px;
}

.reading-chat-panel .message-controls {
    display: none;
}

.selection-popover {
    position: fixed;
    z-index: 1000;
    transform: translateZ(0);
}

.selection-popover[hidden] {
    display: none !important;
}

.selection-popover__menu {
    display: flex;
    flex-direction: column;
    min-width: 128px;
    border: 1px solid var(--c-border);
    border-radius: var(--reading-radius);
    background: var(--c-bg-elevated);
    box-shadow: var(--c-shadow-dropdown);
    overflow: hidden;
}

.selection-popover__btn {
    display: block;
    width: 100%;
    border: none;
    border-radius: 0;
    background: var(--c-bg-elevated);
    color: var(--c-text);
    padding: 10px 14px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    text-align: left;
    white-space: nowrap;
    box-shadow: none;
    transition: background 0.15s, color 0.15s;
}

.selection-popover__btn + .selection-popover__btn {
    border-top: 1px solid var(--c-border);
}

.selection-popover__btn:hover {
    background: var(--c-bg-card-hover);
    color: var(--c-text);
}

.reader-book-wrap {
    flex: 1;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.reader-content {
    position: relative;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--c-border);
    border-radius: var(--reading-radius);
    background: var(--c-bg-main);
    box-shadow: var(--c-shadow-dropdown);
    overflow: hidden;
}

.epub-viewer {
    flex: 1 1 auto;
    width: 100%;
    min-height: 0;
    background: var(--c-bg-main);
    overflow: hidden;
}

.epub-viewer iframe {
    border: none;
    background: var(--c-bg-main);
}

/* 阅读区左右翻页：悬浮在内侧边缘，移入显示 */
.reader-nav-zone {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 72px;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
}

.reader-nav-zone--prev {
    left: 0;
    justify-content: flex-start;
    padding-left: 10px;
}

.reader-nav-zone--next {
    right: 0;
    justify-content: flex-end;
    padding-right: 10px;
}

.reader-side-nav {
    width: 40px;
    height: 72px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--c-text-secondary);
    font-size: 32px;
    font-weight: 300;
    line-height: 1;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transform: scale(0.92);
    transition:
        opacity 0.2s ease,
        visibility 0.2s ease,
        transform 0.2s ease,
        color 0.15s ease;
    user-select: none;
    box-shadow: none;
    text-shadow: 0 0 12px var(--c-bg-body), 0 0 4px var(--c-bg-body);
}

.reader-nav-zone:hover .reader-side-nav,
.reader-side-nav:hover,
.reader-side-nav:focus-visible {
    opacity: 1;
    visibility: visible;
    transform: scale(1);
}

.reader-side-nav span {
    display: block;
    margin-top: -2px;
}

.reader-side-nav:hover {
    background: transparent;
    border: none;
    color: var(--c-accent);
    box-shadow: none;
}

.reader-side-nav:active {
    transform: scale(0.96);
}

.reader-side-nav:focus-visible {
    outline: 2px solid var(--c-accent);
    outline-offset: 2px;
}

.toast-container {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-radius: 8px;
    background: var(--c-bg-elevated);
    border: 1px solid var(--c-border);
    box-shadow: var(--c-shadow-dropdown);
    animation: toast-in 0.2s ease;
}

.toast.success { border-color: var(--c-success-border); }
.toast.error { border-color: var(--c-danger); }
.toast.info { border-color: var(--c-accent-border); }

.toast.hiding {
    opacity: 0;
    transform: translateX(12px);
    transition: opacity 0.2s, transform 0.2s;
}

@keyframes toast-in {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 768px) {
    :root {
        --reader-mobile-meta-h: 52px;
        --reader-panel-pad-bottom: 4px;
        --reader-mobile-bottom-inset: max(14px, env(safe-area-inset-bottom, 0px));
    }

    body.reading-page {
        height: 100dvh;
    }

    .book-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
    }

    .book-library {
        padding: 16px 12px;
        padding-bottom: max(40px, env(safe-area-inset-bottom, 0px));
    }

    .book-library__intro {
        margin-bottom: 12px;
    }

    .book-library__intro h2 {
        font-size: 18px;
    }

    .book-library__intro p {
        margin-bottom: 16px;
        font-size: 13px;
    }

    .book-card__cover {
        aspect-ratio: unset;
        height: 128px;
    }

    .book-card__body {
        padding: 10px;
        gap: 4px;
    }

    .book-card__title {
        font-size: 14px;
        line-height: 1.3;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
        white-space: normal;
    }

    .book-card__author,
    .book-card__progress {
        font-size: 11px;
    }

    .reading-header {
        padding: 0 10px;
        padding-top: env(safe-area-inset-top, 0px);
        gap: 6px;
    }

    body.reading-in-book .reading-header__subtitle,
    body.reading-in-book .reading-header__progress {
        display: none !important;
    }

    body.reading-in-book .reading-header__title {
        max-width: none;
        font-size: 15px;
    }

    .header-actions {
        gap: 4px;
    }

    body.reading-in-book .header-btn:not(.header-btn--icon) {
        display: none;
    }

    .reader-panel {
        flex-direction: column;
        padding: 6px 6px var(--reader-panel-pad-bottom);
        gap: 0;
    }

    body.reading-in-book .reader-panel {
        padding: 4px 4px var(--reader-mobile-bottom-inset);
        flex: 1;
        min-height: 0;
    }

    body.reading-in-book .reader-mobile-meta:not([hidden]) {
        display: block !important;
    }

    body.reading-in-book .reading-main {
        overflow: hidden;
    }

    body.reading-in-book .reader-content {
        border-top-left-radius: 0;
        border-top-right-radius: 0;
        box-sizing: border-box;
        /* 缩小 epub 分页高度，避免末行被 overflow 裁切 */
        padding-bottom: var(--reader-mobile-bottom-inset);
    }

    .annotation-sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        width: min(280px, 85vw);
        max-height: none;
        height: 100dvh;
        z-index: 120;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.35);
        border-radius: 0;
        padding-top: env(safe-area-inset-top, 0px);
    }

    .annotation-sidebar[hidden] {
        display: flex !important;
        pointer-events: none;
    }

    .annotation-sidebar.show {
        transform: translateX(0);
        pointer-events: auto;
    }

    .reader-workspace {
        flex-direction: column;
        height: auto;
        max-height: none;
        flex: 1;
        min-height: 0;
        gap: 0;
    }

    .reader-stage {
        flex: 1;
        min-height: 0;
    }

    body.reading-in-book .reader-stage {
        display: flex;
        flex-direction: column;
    }

    .reading-chat-panel.main-area {
        position: fixed;
        right: 0;
        top: 0;
        bottom: 0;
        width: min(320px, 100vw);
        max-height: 100dvh;
        height: 100dvh;
        flex: none;
        z-index: 120;
        transform: translateX(100%);
        transition: transform 0.25s ease;
        box-shadow: -4px 0 24px rgba(0, 0, 0, 0.35);
        border-radius: 0;
        padding-top: env(safe-area-inset-top, 0px);
        display: flex;
        flex-direction: column;
    }

    .reading-chat-panel[hidden] {
        display: flex !important;
        pointer-events: none;
    }

    .reading-chat-panel.show {
        transform: translateX(0);
        pointer-events: auto;
    }

    .reading-chat-panel .chat-container {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
    }

    .reading-chat-panel .input-area {
        position: static;
        flex-shrink: 0;
        width: 100%;
        box-shadow: none;
        padding-bottom: max(10px, env(safe-area-inset-bottom, 10px));
    }

    .reader-nav-zone {
        width: 44px;
        pointer-events: none;
    }

    .reader-nav-zone--prev {
        padding-left: 4px;
    }

    .reader-nav-zone--next {
        padding-right: 4px;
    }

    .reader-side-nav {
        display: none;
    }

    .epub-viewer {
        min-height: 0;
        flex: 1;
        touch-action: pan-y pinch-zoom;
    }

    body.reading-in-book .epub-viewer {
        /* 允许长按选词，避免 touch-action 拦截手势 */
        touch-action: auto;
    }

    .selection-popover {
        z-index: 1310;
    }

    .selection-popover__btn {
        padding: 14px 18px;
        font-size: 15px;
    }

    .reader-book-wrap,
    .reader-content {
        flex: 1;
        min-height: 0;
    }

    body.reading-in-book .reader-book-wrap {
        flex: 1;
        min-height: 0;
        display: flex;
        flex-direction: column;
    }

    body.reading-in-book .reader-content {
        flex: 1;
        min-height: 0;
        max-height: none;
        height: auto;
    }
}

@media (max-width: 640px) {
    .reading-header__subtitle {
        display: none;
    }

    .reading-header__progress {
        font-size: 12px;
    }

    .reading-header__title {
        max-width: 48%;
    }

    body.reading-in-book .reading-header__title {
        max-width: none;
    }

    .header-btn {
        padding: 8px 10px;
        font-size: 12px;
    }

    .reading-font-controls__label {
        min-width: 36px;
        font-size: 11px;
    }

    .reading-font-controls .header-btn--icon {
        width: 28px;
        height: 28px;
        font-size: 13px;
    }

    .book-library {
        padding: 12px 10px;
        padding-bottom: max(36px, env(safe-area-inset-bottom, 0px));
    }

    .book-card__cover {
        height: 112px;
    }

    body.reading-in-book .reader-panel {
        padding: 4px 4px var(--reader-mobile-bottom-inset);
    }

    .reader-mobile-meta {
        padding: 8px 10px 6px;
    }

    .reader-mobile-meta__title {
        font-size: 14px;
    }
}
