:root { --reader-font-size: 20px; --reader-line-height: 1.8; --reader-font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
html, body { height: 100%; }
body { margin: 0; overflow: hidden; }
.app-shell { min-height: 100vh; display: flex; flex-direction: column; transition: background-color .2s ease, color .2s ease; }
.app-navbar, .app-footer, .reader-toolbar, .reader-sidebar, .offcanvas { background: var(--panel-bg); color: var(--text-color); }
.app-main { flex: 1; min-height: 0; overflow: hidden; }
.reader-sidebar { height: calc(100vh - 113px); overflow: hidden; display: flex; flex-direction: column; }
.sidebar-header { padding: 12px; }
.library-tree { overflow: auto; padding: 4px 8px 16px; }
.tree-node { display: block; width: 100%; border: 0; background: transparent; color: var(--text-color); text-align: left; padding: 7px 8px; border-radius: 8px; word-break: break-word; }
.tree-node:hover, .tree-node.active { background: var(--active-bg); }
.tree-children { margin-left: 14px; padding-left: 8px; border-left: 1px solid var(--border-color); }
.reader-section { min-width: 0; height: calc(100vh - 113px); display: flex; flex-direction: column; }
.reader-toolbar { min-height: 58px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; }
.reader-title-wrap { min-width: 0; }
.reader-title { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reader-path { font-size: 12px; opacity: .7; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reader-actions { display: flex; gap: 6px; flex-shrink: 0; }
.reader-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 24px; opacity: .75; }
.reader-empty h1 { font-size: 1.5rem; }
.reader-viewport { position: relative; flex: 1; overflow: auto; padding: 24px clamp(18px, 5vw, 72px); }
.reader-content { min-height: 100%; overflow: visible; font-size: var(--reader-font-size); line-height: var(--reader-line-height); font-family: var(--reader-font-family); white-space: pre-wrap; word-break: break-word; letter-spacing: .02em; }
.tap-zone { position: absolute; top: 0; width: 34%; height: 100%; border: 0; background: transparent; z-index: 3; display: none; }
.tap-zone-left { left: 0; }
.tap-zone-right { right: 0; }
.progress-wrap { padding: 8px 14px 12px; background: var(--panel-bg); }
.progress-info { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 5px; }
.thin-progress { height: 6px; }
.bottom-controls { display: none; justify-content: space-between; margin-top: 8px; }
.settings-body .setting-value { font-size: 13px; opacity: .75; text-align: right; }
.nav-control { width: 150px; }
.app-footer { font-size: 12px; padding: 8px 12px; text-align: center; line-height: 1.6; }
.theme-day { --bg-color: #f7f8fb; --panel-bg: #ffffff; --text-color: #222222; --border-color: #dee2e6; --active-bg: #e9f2ff; background: var(--bg-color); color: var(--text-color); }
.theme-night { --bg-color: #111318; --panel-bg: #181b22; --text-color: #d7dce5; --border-color: #303642; --active-bg: #263246; background: var(--bg-color); color: var(--text-color); }
.theme-sepia { --bg-color: #f4ecd8; --panel-bg: #fbf4e3; --text-color: #4a3928; --border-color: #ded0b8; --active-bg: #ead9b9; background: var(--bg-color); color: var(--text-color); }
.theme-green { --bg-color: #edf6ee; --panel-bg: #f8fff8; --text-color: #243528; --border-color: #c8decf; --active-bg: #d9ecdc; background: var(--bg-color); color: var(--text-color); }
.theme-night .form-control, .theme-night .form-select, .theme-night .input-group-text, .theme-night .btn-close { background-color: #20242d; color: #d7dce5; border-color: #303642; }
.font-system { --reader-font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
.font-serif { --reader-font-family: Georgia, "Times New Roman", "Noto Serif TC", serif; }
.font-mono { --reader-font-family: Consolas, Monaco, "Courier New", monospace; }

.reader-scroll-mode .reader-viewport { overflow-y: auto; overflow-x: hidden; }
.reader-scroll-mode .reader-content { max-width: 920px; margin: 0 auto; padding-bottom: 42px; }
.reader-scroll-mode .tap-zone, .reader-scroll-mode .bottom-controls { display: none; }
.reader-paged-mode .reader-viewport { overflow: hidden; }
.reader-paged-mode .reader-content { height: 100%; min-height: 0; overflow: hidden; max-width: none; margin: 0; padding-bottom: 0; }
@media (max-width: 991.98px) { body { overflow: auto; } .app-main { overflow: visible; } .reader-sidebar { position: fixed; top: 57px; left: 0; width: min(86vw, 360px); height: calc(100vh - 57px); z-index: 1050; transform: translateX(-105%); transition: transform .2s ease; box-shadow: 0 0 24px rgba(0,0,0,.25); } .reader-sidebar.show { transform: translateX(0); } .reader-section { height: calc(100vh - 113px); } .reader-toolbar { align-items: flex-start; } .reader-viewport { padding: 18px 18px 10px; } .tap-zone { display: block; } .bottom-controls { display: flex; } .reader-content { letter-spacing: 0; } }
@media (max-width: 575.98px) { .reader-toolbar { min-height: 66px; padding: 8px 10px; } .reader-title { font-size: 14px; } .reader-actions .btn span { display: none; } .reader-viewport { padding-left: 14px; padding-right: 14px; } .app-footer { font-size: 11px; } }


.offcanvas {
    background-color: var(--panel-bg) !important;
    color: var(--text-color) !important;
    box-shadow: -12px 0 36px rgba(0, 0, 0, .32);
}
.offcanvas-backdrop.show {
    opacity: .72;
}
.mobile-catalog-fab {
    display: none !important;
}
.reader-paged-mode .reader-content {
    box-sizing: border-box;
    padding-bottom: 0;
}
@media (max-width: 991.98px) {
    .reader-sidebar {
        background: var(--panel-bg);
        color: var(--text-color);
        border-right: 1px solid var(--border-color);
    }
    .reader-sidebar.show::after {
        content: "";
        position: fixed;
        top: 0;
        left: 100%;
        width: 100vw;
        height: 100%;
        background: rgba(0, 0, 0, .28);
    }
    .reader-viewport {
        padding-bottom: calc(20px + env(safe-area-inset-bottom));
    }
    .progress-wrap {
        padding-bottom: calc(14px + env(safe-area-inset-bottom));
    }
}
@media (max-width: 575.98px) {
    .reader-actions {
        gap: 4px;
    }
}


/* 手機和平板目錄入口固定在閱讀工具列，不使用浮動按鈕，避免遮擋上一頁按鈕 */
@media (max-width: 991.98px) {
    #toggleSidebarToolbarBtn {
        order: -1;
        flex: 0 0 auto;
    }
    .reader-actions {
        flex-wrap: nowrap;
        align-items: center;
    }
    .reader-paged-mode .reader-viewport {
        padding-top: 16px;
        padding-bottom: 16px;
    }
    .reader-paged-mode .reader-content {
        height: 100%;
        max-height: 100%;
    }
}


/* Google 登入狀態顯示 */
.login-user-box {
    display: flex;
    align-items: center;
    gap: 6px;
    max-width: 220px;
    font-size: 13px;
    color: var(--text-color);
}
.login-user-avatar {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    object-fit: cover;
    flex: 0 0 auto;
}
.login-user-avatar-empty {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--active-bg);
}
.login-user-name {
    display: inline-block;
    max-width: 170px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.login-page-body {
    min-height: 100vh;
    margin: 0;
    background: #f4f6fb;
    overflow: auto;
}
.login-page-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}
.login-card {
    width: min(100%, 420px);
    background: #ffffff;
    border-radius: 20px;
    padding: 34px 28px;
    text-align: center;
}
.login-icon {
    width: 72px;
    height: 72px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: #e9f2ff;
    color: #0d6efd;
    font-size: 34px;
    margin-bottom: 18px;
}
.login-card h1 {
    font-size: 28px;
    font-weight: 800;
    margin-bottom: 12px;
}
.login-card p {
    color: #5c6675;
    line-height: 1.8;
    margin-bottom: 24px;
}
@media (max-width: 991.98px) {
    .login-user-box {
        width: 100%;
        max-width: 100%;
    }
    .login-user-name {
        max-width: calc(100vw - 120px);
    }
}


/* 手機和平板左右拖曳翻頁設定 */
.reader-paged-mode .reader-viewport {
    touch-action: pan-y;
    user-select: none;
    -webkit-user-select: none;
}

/* 2026-05-20 手機和平板閱讀版面修正
   使用動態視窗高度與 flex 版面，避免閱讀區超出手機或平板畫面高度 */
@media (max-width: 991.98px) {
    html,
    body {
        height: 100%;
        overflow: hidden;
    }

    .app-shell {
        height: 100dvh;
        min-height: 100dvh;
        overflow: hidden;
    }

    .app-navbar,
    .app-footer,
    .reader-toolbar,
    .progress-wrap {
        flex: 0 0 auto;
    }

    .app-main {
        flex: 1 1 auto;
        min-height: 0;
        overflow: hidden;
    }

    .app-main > .row {
        height: 100%;
        min-height: 0;
    }

    .reader-section {
        height: 100%;
        min-height: 0;
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }

    .reader-toolbar {
        min-height: 0;
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: center;
        gap: 8px;
        padding: 8px 10px;
    }

    .reader-title-wrap {
        min-width: 0;
        overflow: hidden;
    }

    .reader-actions {
        flex-wrap: nowrap;
        gap: 4px;
        white-space: nowrap;
    }

    .reader-actions .btn {
        min-width: 34px;
        height: 34px;
        padding: 4px 8px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        flex: 0 0 auto;
    }

    .reader-actions .btn span {
        display: none;
    }

    .reader-actions .btn i {
        margin-left: 0 !important;
        margin-right: 0 !important;
    }

    .reader-viewport {
        flex: 1 1 auto;
        min-height: 0;
        height: auto;
        overflow: hidden;
        padding: 14px 14px calc(14px + env(safe-area-inset-bottom));
    }

    .reader-paged-mode .reader-content {
        height: 100%;
        max-height: 100%;
        min-height: 0;
        overflow: hidden;
    }

    .progress-wrap {
        padding: 6px 10px calc(10px + env(safe-area-inset-bottom));
    }

    .progress-info {
        font-size: 12px;
        margin-bottom: 4px;
    }

    .bottom-controls {
        margin-top: 6px;
        gap: 8px;
    }

    .bottom-controls .btn {
        flex: 1 1 0;
        min-width: 0;
        white-space: nowrap;
    }

    .reader-sidebar {
        top: 0;
        height: 100dvh;
        max-height: 100dvh;
    }
}

@media (max-width: 575.98px) {
    .reader-toolbar {
        padding: 7px 8px;
        gap: 6px;
    }

    .reader-title {
        font-size: 13px;
    }

    .reader-path {
        font-size: 11px;
    }

    .reader-actions .btn {
        min-width: 32px;
        height: 32px;
        padding: 3px 7px;
    }

    .reader-viewport {
        padding-left: 12px;
        padding-right: 12px;
    }
}


/* iPhone Safari / Chrome 動態工具列高度修正 */
@supports (height: 100dvh) {
    .app-shell {
        min-height: 100dvh;
    }

    .reader-sidebar {
        height: calc(100dvh - 113px);
    }

    .reader-section {
        height: calc(100dvh - 113px);
    }

    @media (max-width: 991.98px) {
        .reader-sidebar {
            height: calc(100dvh - 57px);
        }

        .reader-section {
            height: calc(100dvh - 113px);
        }

        .reader-viewport {
            height: 100%;
            max-height: 100%;
            box-sizing: border-box;
            overflow: hidden;
        }

        .reader-paged-mode .reader-content {
            height: 100%;
            max-height: 100%;
            overflow: hidden;
        }

        .reader-toolbar {
            flex-wrap: nowrap;
            overflow: hidden;
        }

        .reader-actions {
            flex-wrap: nowrap;
            overflow-x: auto;
            overflow-y: hidden;
            -webkit-overflow-scrolling: touch;
        }

        .reader-actions .btn {
            flex: 0 0 auto;
            white-space: nowrap;
        }
    }
}


/* 大型文字檔分段載入提示 */
.reader-loading-box {
    min-height: 180px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    text-align: center;
    opacity: .86;
    font-size: 15px;
}
.reader-loading-size {
    font-size: 13px;
    opacity: .7;
}

/* 2026-05-20 V11 效能與設定面板可讀性修正
   設定面板使用獨立標題底色，避免背景色與標題文字混在一起 */
.offcanvas-header {
    background: var(--active-bg) !important;
    color: var(--text-color) !important;
    border-bottom: 1px solid var(--border-color);
}
.offcanvas-title {
    color: var(--text-color) !important;
    font-weight: 800;
}
.offcanvas-body {
    background: var(--panel-bg) !important;
    color: var(--text-color) !important;
}
.theme-day .offcanvas-header,
.theme-sepia .offcanvas-header,
.theme-green .offcanvas-header {
    background: #1f2937 !important;
    color: #ffffff !important;
}
.theme-day .offcanvas-title,
.theme-sepia .offcanvas-title,
.theme-green .offcanvas-title {
    color: #ffffff !important;
}
.theme-day .offcanvas-header .btn-close,
.theme-sepia .offcanvas-header .btn-close,
.theme-green .offcanvas-header .btn-close {
    filter: invert(1) grayscale(100%);
}

/* 手機和平板版面高度再收斂，避免 iPhone 實機因網址列與工具列變化造成內容突破畫面 */
@media (max-width: 991.98px) {
    .app-shell {
        height: 100svh;
        min-height: 100svh;
        max-height: 100svh;
    }

    @supports (height: 100dvh) {
        .app-shell {
            height: 100dvh;
            min-height: 100dvh;
            max-height: 100dvh;
        }
    }

    .reader-toolbar {
        grid-template-columns: minmax(0, 1fr) max-content;
    }

    .reader-actions {
        max-width: min(52vw, 250px);
    }

    .reader-viewport {
        contain: layout paint;
    }

    .reader-content {
        overflow-wrap: anywhere;
    }
}


/* 2026-05-20 V12 實機修正
   強制設定面板標題列使用固定深色，避免與日間、夜間、護眼背景混在一起。 */
#settingsPanel.offcanvas {
    background: var(--panel-bg) !important;
    color: var(--text-color) !important;
    opacity: 1 !important;
}
#settingsPanel .offcanvas-header {
    background: #172033 !important;
    color: #ffffff !important;
    border-bottom: 1px solid rgba(255,255,255,.16) !important;
}
#settingsPanel .offcanvas-title,
#settingsPanel .offcanvas-title span,
#settingsPanel .offcanvas-title i {
    color: #ffffff !important;
}
#settingsPanel .btn-close {
    filter: invert(1) grayscale(100%) !important;
    opacity: .95;
}
#settingsPanel .offcanvas-body {
    background: var(--panel-bg) !important;
    color: var(--text-color) !important;
}

@media (max-width: 991.98px) {
    .reader-toolbar {
        max-height: 48px;
        overflow: hidden;
    }
    .progress-wrap {
        max-height: 78px;
        overflow: hidden;
    }
    .reader-viewport {
        min-height: 0 !important;
        max-height: none !important;
    }
    .reader-paged-mode .reader-content {
        contain: content;
    }
}


/* 2026-05-20 V13 設定面板可讀性修正
   設定項目改為獨立卡片區塊，避免標題文字與半透明背景或閱讀背景混在一起 */
#settingsPanel {
    background-color: #ffffff !important;
    color: #1f2937 !important;
    opacity: 1 !important;
}

#settingsPanel .offcanvas-header {
    background: #111827 !important;
    color: #ffffff !important;
    border-bottom: 1px solid rgba(255, 255, 255, .18) !important;
}

#settingsPanel .offcanvas-title,
#settingsPanel .offcanvas-title span,
#settingsPanel .offcanvas-title i {
    color: #ffffff !important;
}

#settingsPanel .btn-close {
    filter: invert(1) grayscale(100%) !important;
    opacity: .95 !important;
}

#settingsPanel .offcanvas-body {
    background: #f3f4f6 !important;
    color: #111827 !important;
    padding: 16px !important;
}

#settingsPanel .form-label,
#settingsPanel .form-check-label {
    display: block;
    width: 100%;
    margin: 0 0 8px;
    padding: 7px 10px;
    border-radius: 8px;
    background: #111827 !important;
    color: #ffffff !important;
    font-weight: 700;
    line-height: 1.4;
    letter-spacing: .02em;
}

#settingsPanel .form-range,
#settingsPanel .form-select,
#settingsPanel .form-check,
#settingsPanel .setting-value {
    position: relative;
    z-index: 1;
}

#settingsPanel .form-range,
#settingsPanel .form-select {
    margin-bottom: 8px;
}

#settingsPanel .form-select {
    background-color: #ffffff !important;
    color: #111827 !important;
    border-color: #cbd5e1 !important;
}

#settingsPanel .setting-value {
    color: #374151 !important;
    opacity: 1 !important;
    font-weight: 700;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 5px 8px;
}

#settingsPanel .form-check {
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 12px 12px 12px 48px;
}

#settingsPanel .form-check .form-check-label {
    display: inline;
    width: auto;
    margin: 0;
    padding: 0;
    background: transparent !important;
    color: #111827 !important;
    font-weight: 700;
}

#settingsPanel .form-check-input {
    margin-left: -36px;
}

#settingsPanel #resetSettingsBtn {
    background: #ffffff;
    font-weight: 700;
}

.theme-night #settingsPanel,
.theme-night #settingsPanel .offcanvas-body,
.theme-day #settingsPanel,
.theme-sepia #settingsPanel,
.theme-green #settingsPanel {
    background-color: #f3f4f6 !important;
    color: #111827 !important;
}

@media (max-width: 991.98px) {
    #settingsPanel {
        width: min(92vw, 420px) !important;
    }

    #settingsPanel .offcanvas-body {
        padding: 14px !important;
    }
}

/* 2026-05-20 V14 目錄與設定拉桿修正
   只調整目錄收合、手機目錄可讀性、空白處關閉與設定拉桿辨識度 */
.tree-folder.collapsed > .tree-children {
    display: none;
}

.tree-folder.expanded > .folder-node .tree-folder-arrow {
    transform: rotate(90deg);
}

.tree-folder-arrow {
    width: 14px;
    margin-right: 6px;
    transition: transform .16s ease;
    flex: 0 0 auto;
}

.tree-folder-icon,
.tree-file-icon {
    width: 18px;
    margin-right: 8px;
    flex: 0 0 auto;
}

.tree-node {
    display: flex !important;
    align-items: flex-start;
    gap: 0;
    line-height: 1.45;
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.tree-node-text {
    min-width: 0;
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.folder-node {
    font-weight: 700;
}

.file-node {
    font-weight: 500;
}

@media (max-width: 991.98px) {
    .reader-sidebar {
        width: min(82vw, 340px);
        max-width: 340px;
    }

    .library-tree {
        padding-right: 10px;
    }

    .tree-node {
        padding: 9px 8px;
        font-size: 14px;
        line-height: 1.5;
    }

    .tree-children {
        margin-left: 10px;
        padding-left: 8px;
    }
}

#settingsPanel .form-range {
    --range-percent: 0%;
    height: 26px;
    cursor: pointer;
    accent-color: #2563eb;
}

#settingsPanel .form-range::-webkit-slider-runnable-track {
    height: 10px;
    border-radius: 999px;
    background: linear-gradient(to right, #2563eb 0%, #2563eb var(--range-percent), #d1d5db var(--range-percent), #d1d5db 100%) !important;
    border: 1px solid #9ca3af;
}

#settingsPanel .form-range::-webkit-slider-thumb {
    width: 22px;
    height: 22px;
    margin-top: -7px;
    border-radius: 50%;
    background: #ffffff;
    border: 3px solid #1d4ed8;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .28);
}

#settingsPanel .form-range::-moz-range-track {
    height: 10px;
    border-radius: 999px;
    background: #d1d5db !important;
    border: 1px solid #9ca3af;
}

#settingsPanel .form-range::-moz-range-progress {
    height: 10px;
    border-radius: 999px;
    background: #2563eb !important;
}

#settingsPanel .form-range::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #ffffff;
    border: 3px solid #1d4ed8;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .28);
}


/* 2026-05-20 V16 導覽列與閱讀工具列對比修正
   只調整頂部區塊和操作按鈕在各背景模式下的辨識度，避免夜間模式按鈕與背景混在一起 */
.app-navbar,
.reader-toolbar,
.progress-wrap,
.app-footer {
    border-color: var(--border-color) !important;
}

.app-navbar {
    border-bottom: 1px solid var(--border-color) !important;
}

.reader-toolbar {
    border-bottom: 1px solid var(--border-color) !important;
}

.app-footer {
    border-top: 1px solid var(--border-color) !important;
}

.app-navbar .navbar-brand,
.app-navbar .navbar-brand span,
.app-navbar .navbar-brand i,
.app-navbar .nav-link,
.app-navbar .dropdown-toggle,
.reader-toolbar,
.reader-title,
.reader-path {
    color: var(--text-color) !important;
}

.app-navbar .navbar-toggler {
    border: 1px solid var(--border-color) !important;
    background: var(--active-bg) !important;
    box-shadow: none !important;
}

.app-navbar .navbar-toggler-icon {
    filter: none;
}

.reader-actions .btn,
.app-navbar .btn,
.bottom-controls .btn {
    border-width: 2px !important;
    font-weight: 700;
}

.theme-night .app-navbar,
.theme-night .reader-toolbar,
.theme-night .progress-wrap,
.theme-night .app-footer {
    background: #151922 !important;
    color: #f1f5f9 !important;
    border-color: #4b5563 !important;
}

.theme-night .app-navbar .navbar-brand,
.theme-night .app-navbar .navbar-brand span,
.theme-night .app-navbar .navbar-brand i,
.theme-night .app-navbar .nav-link,
.theme-night .app-navbar .dropdown-toggle,
.theme-night .reader-title,
.theme-night .reader-path,
.theme-night .progress-info,
.theme-night .app-footer {
    color: #f1f5f9 !important;
    opacity: 1 !important;
}

.theme-night .app-navbar .navbar-toggler {
    background: #243044 !important;
    border-color: #64748b !important;
}

.theme-night .navbar-toggler-icon {
    filter: invert(1) grayscale(100%) brightness(1.8) !important;
}

.theme-night .reader-actions .btn-outline-secondary,
.theme-night .bottom-controls .btn-outline-secondary {
    color: #e5e7eb !important;
    border-color: #94a3b8 !important;
    background: #1f2937 !important;
}

.theme-night .reader-actions .btn-outline-secondary:hover,
.theme-night .bottom-controls .btn-outline-secondary:hover,
.theme-night .reader-actions .btn-outline-secondary:focus,
.theme-night .bottom-controls .btn-outline-secondary:focus {
    color: #ffffff !important;
    border-color: #ffffff !important;
    background: #334155 !important;
}

.theme-night .reader-actions .btn-outline-secondary:disabled,
.theme-night .bottom-controls .btn-outline-secondary:disabled {
    color: #94a3b8 !important;
    border-color: #475569 !important;
    background: #111827 !important;
    opacity: .72 !important;
}

.theme-night .reader-actions .btn-primary,
.theme-night .app-navbar .btn-primary {
    color: #ffffff !important;
    background: #2563eb !important;
    border-color: #60a5fa !important;
}

.theme-day .app-navbar,
.theme-day .reader-toolbar,
.theme-day .progress-wrap,
.theme-day .app-footer,
.theme-sepia .app-navbar,
.theme-sepia .reader-toolbar,
.theme-sepia .progress-wrap,
.theme-sepia .app-footer,
.theme-green .app-navbar,
.theme-green .reader-toolbar,
.theme-green .progress-wrap,
.theme-green .app-footer {
    box-shadow: 0 1px 0 rgba(0, 0, 0, .06);
}

.theme-day .reader-actions .btn-outline-secondary,
.theme-day .bottom-controls .btn-outline-secondary,
.theme-sepia .reader-actions .btn-outline-secondary,
.theme-sepia .bottom-controls .btn-outline-secondary,
.theme-green .reader-actions .btn-outline-secondary,
.theme-green .bottom-controls .btn-outline-secondary {
    color: #1f2937 !important;
    border-color: #6b7280 !important;
    background: rgba(255, 255, 255, .86) !important;
}

.theme-day .reader-actions .btn-outline-secondary:disabled,
.theme-day .bottom-controls .btn-outline-secondary:disabled,
.theme-sepia .reader-actions .btn-outline-secondary:disabled,
.theme-sepia .bottom-controls .btn-outline-secondary:disabled,
.theme-green .reader-actions .btn-outline-secondary:disabled,
.theme-green .bottom-controls .btn-outline-secondary:disabled {
    color: #6b7280 !important;
    border-color: #9ca3af !important;
    background: rgba(255, 255, 255, .62) !important;
    opacity: .78 !important;
}


/* 2026-05-20 V17 章節目錄功能
   只新增章節目錄面板與章節按鈕樣式，不修改閱讀核心版面 */
#chapterPanel {
    background-color: var(--panel-bg) !important;
    color: var(--text-color) !important;
    opacity: 1 !important;
}

#chapterPanel .offcanvas-header {
    background: #172033 !important;
    color: #ffffff !important;
    border-bottom: 1px solid rgba(255,255,255,.16) !important;
}

#chapterPanel .offcanvas-title,
#chapterPanel .offcanvas-title span,
#chapterPanel .offcanvas-title i {
    color: #ffffff !important;
}

#chapterPanel .btn-close {
    filter: invert(1) grayscale(100%) !important;
    opacity: .95 !important;
}

.chapter-body {
    padding: 12px !important;
}

.chapter-summary {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-color);
    opacity: .78;
    margin-bottom: 10px;
}

.chapter-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.chapter-node {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    width: 100%;
    border: 1px solid var(--border-color);
    background: var(--panel-bg);
    color: var(--text-color);
    border-radius: 10px;
    padding: 9px 10px;
    text-align: left;
    line-height: 1.45;
}

.chapter-node:hover,
.chapter-node.active {
    background: var(--active-bg);
    border-color: #2563eb;
}

.chapter-order {
    min-width: 28px;
    height: 22px;
    padding: 1px 6px;
    border-radius: 999px;
    background: #2563eb;
    color: #ffffff;
    font-size: 12px;
    font-weight: 800;
    text-align: center;
    flex: 0 0 auto;
}

.chapter-title {
    min-width: 0;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.theme-night .chapter-node {
    background: #1f2937;
    border-color: #475569;
    color: #f1f5f9;
}

.theme-night .chapter-node:hover,
.theme-night .chapter-node.active {
    background: #263246;
    border-color: #60a5fa;
}

@media (max-width: 991.98px) {
    #chapterPanel {
        width: min(92vw, 420px) !important;
    }
}

/* 2026-05-20 V19 章節面板對比與小說模式資訊
   只覆蓋章節面板顏色與章節列顯示，不調整閱讀核心版面 */
body.theme-day #chapterPanel,
body.theme-sepia #chapterPanel,
body.theme-green #chapterPanel,
body.theme-night #chapterPanel {
    background-color: var(--panel-bg) !important;
    color: var(--text-color) !important;
}

body.theme-night #chapterPanel {
    --chapter-panel-bg: #111827;
    --chapter-card-bg: #1f2937;
    --chapter-card-hover: #263246;
    --chapter-text: #f8fafc;
    --chapter-subtext: #cbd5e1;
    --chapter-border: #475569;
    --chapter-badge-bg: #2563eb;
    --chapter-badge-text: #ffffff;
}

body.theme-day #chapterPanel {
    --chapter-panel-bg: #ffffff;
    --chapter-card-bg: #ffffff;
    --chapter-card-hover: #e9f2ff;
    --chapter-text: #111827;
    --chapter-subtext: #4b5563;
    --chapter-border: #cbd5e1;
    --chapter-badge-bg: #2563eb;
    --chapter-badge-text: #ffffff;
}

body.theme-sepia #chapterPanel {
    --chapter-panel-bg: #fbf4e3;
    --chapter-card-bg: #fff9ec;
    --chapter-card-hover: #ead9b9;
    --chapter-text: #3f2f20;
    --chapter-subtext: #6b5138;
    --chapter-border: #c9b996;
    --chapter-badge-bg: #9a5b1f;
    --chapter-badge-text: #ffffff;
}

body.theme-green #chapterPanel {
    --chapter-panel-bg: #f8fff8;
    --chapter-card-bg: #ffffff;
    --chapter-card-hover: #d9ecdc;
    --chapter-text: #1f3526;
    --chapter-subtext: #4b6b55;
    --chapter-border: #b6d4be;
    --chapter-badge-bg: #247a45;
    --chapter-badge-text: #ffffff;
}

#chapterPanel .offcanvas-body {
    background-color: var(--chapter-panel-bg, var(--panel-bg)) !important;
    color: var(--chapter-text, var(--text-color)) !important;
}

.chapter-summary {
    color: var(--chapter-text, var(--text-color)) !important;
    opacity: 1 !important;
    background: var(--chapter-card-bg, var(--panel-bg));
    border: 1px solid var(--chapter-border, var(--border-color));
    border-radius: 12px;
    padding: 10px 12px;
}

.chapter-summary-main {
    font-size: 14px;
    font-weight: 800;
    color: var(--chapter-text, var(--text-color));
}

.chapter-summary-sub {
    margin-top: 3px;
    font-size: 12px;
    font-weight: 600;
    color: var(--chapter-subtext, var(--text-color));
}

.chapter-node {
    background: var(--chapter-card-bg, var(--panel-bg)) !important;
    color: var(--chapter-text, var(--text-color)) !important;
    border-color: var(--chapter-border, var(--border-color)) !important;
}

.chapter-node:hover,
.chapter-node.active {
    background: var(--chapter-card-hover, var(--active-bg)) !important;
    border-color: #60a5fa !important;
}

.chapter-node.active {
    box-shadow: inset 4px 0 0 #3b82f6;
}

.chapter-main {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
    flex: 1 1 auto;
}

.chapter-title {
    display: block;
    color: var(--chapter-text, var(--text-color)) !important;
    font-weight: 700;
}

.chapter-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    color: var(--chapter-subtext, var(--text-color)) !important;
    font-size: 12px;
    font-weight: 700;
}

.chapter-type-label {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 1px 8px;
    background: rgba(37, 99, 235, .14);
    color: var(--chapter-text, var(--text-color));
    border: 1px solid var(--chapter-border, var(--border-color));
}

.chapter-order {
    background: var(--chapter-badge-bg, #2563eb) !important;
    color: var(--chapter-badge-text, #ffffff) !important;
}

.chapter-type-volume .chapter-order,
.chapter-type-volume .chapter-type-label {
    background: #7c3aed !important;
    color: #ffffff !important;
    border-color: #7c3aed !important;
}

.chapter-type-extra .chapter-order,
.chapter-type-extra .chapter-type-label {
    background: #db2777 !important;
    color: #ffffff !important;
    border-color: #db2777 !important;
}

.chapter-type-intro .chapter-order,
.chapter-type-intro .chapter-type-label,
.chapter-type-ending .chapter-order,
.chapter-type-ending .chapter-type-label {
    background: #64748b !important;
    color: #ffffff !important;
    border-color: #64748b !important;
}

.fullscreen-mode {
    width: 100vw !important;
    height: 100dvh !important;
    max-width: 100vw !important;
    max-height: 100dvh !important;
    overflow: hidden;
}

.fullscreen-mode .app-main {
    height: calc(100dvh - 56px - 58px);
}

.fullscreen-mode .reader-viewport {
    height: 100%;
}

.fullscreen-mode #sidebar,
.fullscreen-mode #chapterPanel,
.fullscreen-mode #settingsPanel {
    z-index: 3000;
}

@media (max-width: 991.98px) {
    .fullscreen-mode .app-main {
        height: calc(100dvh - 52px - 54px);
    }
}


/* [2026-05-21] V21 iOS Chrome 不支援標準 Fullscreen API，因此提供視覺全螢幕模式。 */
.fullscreen-switching,
.fullscreen-switching * {
    transition: none !important;
}

.visual-fullscreen-mode {
    position: fixed !important;
    inset: 0 !important;
    z-index: 2147483000 !important;
    width: 100vw !important;
    height: 100dvh !important;
    min-height: 100dvh !important;
    background: var(--bg-color) !important;
}

.visual-fullscreen-mode .app-navbar {
    flex: 0 0 auto;
}

.visual-fullscreen-mode .app-footer {
    flex: 0 0 auto;
}

.visual-fullscreen-mode .app-main {
    flex: 1 1 auto;
    min-height: 0;
}

.visual-fullscreen-mode .reader-sidebar {
    height: calc(100dvh - 56px - 58px);
}

@supports (-webkit-touch-callout: none) {
    .visual-fullscreen-mode,
    .fullscreen-mode {
        height: -webkit-fill-available !important;
        min-height: -webkit-fill-available !important;
    }

    .visual-fullscreen-mode .app-main,
    .fullscreen-mode .app-main {
        height: calc(100dvh - 52px - 54px);
    }
}


/* [2026-05-21] V22 iOS Chrome 視覺全螢幕修正。
   iOS Chrome 不允許網頁使用真正的 Fullscreen API，因此改用整頁固定定位模擬最大畫面。
   這段只影響開啟全螢幕時的狀態，不改動一般閱讀模式。 */
:root {
    --tool-books-visual-vh: 100dvh;
    --tool-books-visual-vw: 100vw;
}

html.tool-books-visual-fullscreen-active,
body.tool-books-visual-fullscreen-active {
    width: var(--tool-books-visual-vw) !important;
    height: var(--tool-books-visual-vh) !important;
    min-height: var(--tool-books-visual-vh) !important;
    max-height: var(--tool-books-visual-vh) !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    overscroll-behavior: none !important;
    background: var(--bg-color) !important;
}

body.tool-books-visual-fullscreen-active {
    position: fixed !important;
    inset: 0 !important;
    touch-action: manipulation;
    -webkit-overflow-scrolling: auto;
}

body.tool-books-visual-fullscreen-active .visual-fullscreen-mode {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: auto !important;
    bottom: auto !important;
    z-index: 2147483000 !important;
    width: var(--tool-books-visual-vw) !important;
    max-width: var(--tool-books-visual-vw) !important;
    height: var(--tool-books-visual-vh) !important;
    min-height: var(--tool-books-visual-vh) !important;
    max-height: var(--tool-books-visual-vh) !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
    background: var(--bg-color) !important;
}

body.tool-books-visual-fullscreen-active .visual-fullscreen-mode .app-footer {
    display: none !important;
}

body.tool-books-visual-fullscreen-active .visual-fullscreen-mode .app-navbar {
    flex: 0 0 auto !important;
    position: relative !important;
    top: auto !important;
    z-index: 2147483001 !important;
}

body.tool-books-visual-fullscreen-active .visual-fullscreen-mode .app-main {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    height: calc(var(--tool-books-visual-vh) - 56px) !important;
    max-height: calc(var(--tool-books-visual-vh) - 56px) !important;
    overflow: hidden !important;
}

body.tool-books-visual-fullscreen-active .visual-fullscreen-mode .reader-section,
body.tool-books-visual-fullscreen-active .visual-fullscreen-mode .reader-sidebar {
    height: 100% !important;
    max-height: 100% !important;
}

body.tool-books-visual-fullscreen-active .visual-fullscreen-mode .reader-viewport {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    height: auto !important;
    max-height: none !important;
    overflow: auto !important;
    -webkit-overflow-scrolling: touch;
}

body.tool-books-visual-fullscreen-active .visual-fullscreen-mode .progress-wrap {
    flex: 0 0 auto !important;
}

body.tool-books-visual-fullscreen-active .visual-fullscreen-mode #sidebar,
body.tool-books-visual-fullscreen-active .visual-fullscreen-mode #chapterPanel,
body.tool-books-visual-fullscreen-active .visual-fullscreen-mode #settingsPanel {
    z-index: 2147483100 !important;
}

@media (max-width: 991.98px) {
    body.tool-books-visual-fullscreen-active .visual-fullscreen-mode .app-main {
        height: calc(var(--tool-books-visual-vh) - 52px) !important;
        max-height: calc(var(--tool-books-visual-vh) - 52px) !important;
    }

    body.tool-books-visual-fullscreen-active .visual-fullscreen-mode .reader-toolbar {
        min-height: 54px !important;
    }
}


/* [2026-05-22] 目前章節名稱顯示，僅在偵測到小說章節時顯示 */
.reader-current-chapter {
    display: inline-flex;
    align-items: center;
    max-width: 100%;
    margin-top: 3px;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    line-height: 1.35;
    color: #ffffff;
    background: #2563eb;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.reader-current-chapter.d-none {
    display: none !important;
}
.theme-night .reader-current-chapter {
    color: #dbeafe;
    background: #1d4ed8;
    border: 1px solid #60a5fa;
}
.theme-sepia .reader-current-chapter {
    color: #3b2606;
    background: #facc15;
}
.theme-green .reader-current-chapter {
    color: #052e16;
    background: #86efac;
}
@media (max-width: 575.98px) {
    .reader-current-chapter {
        max-width: 72vw;
        font-size: 11px;
        padding: 2px 7px;
    }
}

/* [2026-05-22] V24 修正：避免手機小說模式中檔名、章節、路徑與工具按鈕互相擠壓 */
.reader-title-wrap {
    flex: 1 1 auto;
    min-width: 0;
    max-width: 100%;
}
.reader-title,
.reader-path {
    max-width: 100%;
}
.reader-current-chapter {
    max-width: 100%;
}
.reader-actions {
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}
.reader-actions .btn {
    flex: 0 0 auto;
}
@media (max-width: 991.98px) {
    .reader-toolbar {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }
    .reader-title-wrap {
        width: 100%;
    }
    .reader-title {
        white-space: normal;
        overflow: visible;
        text-overflow: clip;
        line-height: 1.35;
    }
    .reader-current-chapter {
        display: flex;
        width: fit-content;
        max-width: 100%;
        white-space: normal;
        word-break: break-word;
        overflow: visible;
        text-overflow: clip;
    }
    .reader-path {
        white-space: normal;
        overflow: visible;
        text-overflow: clip;
        word-break: break-word;
        line-height: 1.35;
    }
    .reader-actions {
        width: 100%;
        padding-bottom: 2px;
    }
}
@media (max-width: 575.98px) {
    .reader-current-chapter {
        max-width: 100%;
        font-size: 12px;
    }
}


/* [2026-05-22] V25 手機標題資訊重新分層，避免小說名稱、章節名稱、路徑和按鈕互相擠壓 */
.reader-title-wrap {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1 1 auto;
    min-width: 0;
}
.reader-title {
    line-height: 1.35;
}
.reader-path {
    line-height: 1.35;
}
@media (max-width: 991.98px) {
    .reader-toolbar {
        align-items: stretch;
        flex-direction: column;
        gap: 8px;
        padding: 8px 12px;
    }
    .reader-title-wrap {
        width: 100%;
        max-width: 100%;
        gap: 5px;
    }
    .reader-title {
        white-space: normal;
        overflow: visible;
        text-overflow: clip;
        word-break: break-word;
        font-size: 15px;
    }
    .reader-current-chapter {
        display: block;
        width: fit-content;
        max-width: 100%;
        white-space: normal;
        word-break: break-word;
        padding: 3px 8px;
        font-size: 12px;
        line-height: 1.45;
    }
    .reader-current-chapter.d-none {
        display: none !important;
    }
    .reader-path {
        white-space: normal;
        overflow: visible;
        text-overflow: clip;
        word-break: break-word;
        font-size: 11px;
        line-height: 1.45;
    }
    .reader-actions {
        width: 100%;
        max-width: 100%;
        overflow-x: auto;
        overflow-y: hidden;
        flex-wrap: nowrap;
        padding-bottom: 2px;
        -webkit-overflow-scrolling: touch;
    }
    .reader-actions .btn {
        flex: 0 0 auto;
    }
}


/* [2026-05-22] V26 手機標題資訊修正。
   讓小說名稱、目前章節、路徑與檔案大小固定分層顯示，不再和右側功能按鈕擠在同一行。 */
.reader-title-wrap {
    overflow: visible !important;
}
.reader-title {
    font-weight: 800;
}
.reader-path {
    opacity: .86;
}
@media (max-width: 991.98px) {
    .reader-toolbar {
        display: flex !important;
        flex-direction: column !important;
        align-items: stretch !important;
        justify-content: flex-start !important;
        gap: 7px !important;
        min-height: 0 !important;
        max-height: none !important;
        height: auto !important;
        overflow: visible !important;
        padding: 8px 10px !important;
    }

    .reader-title-wrap {
        display: grid !important;
        grid-template-columns: minmax(0, 1fr) !important;
        row-gap: 4px !important;
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        overflow: visible !important;
        order: 1 !important;
    }

    .reader-title {
        display: block !important;
        width: 100% !important;
        max-width: 100% !important;
        white-space: normal !important;
        overflow: visible !important;
        text-overflow: clip !important;
        word-break: break-word !important;
        line-height: 1.3 !important;
        font-size: 15px !important;
    }

    .reader-current-chapter {
        display: block !important;
        width: fit-content !important;
        max-width: 100% !important;
        white-space: normal !important;
        overflow: visible !important;
        text-overflow: clip !important;
        word-break: break-word !important;
        line-height: 1.35 !important;
        font-size: 12px !important;
        padding: 3px 8px !important;
    }

    .reader-current-chapter.d-none {
        display: none !important;
    }

    .reader-path {
        display: block !important;
        width: 100% !important;
        max-width: 100% !important;
        white-space: normal !important;
        overflow: visible !important;
        text-overflow: clip !important;
        word-break: break-word !important;
        line-height: 1.35 !important;
        font-size: 11px !important;
    }

    .reader-actions {
        order: 2 !important;
        display: flex !important;
        width: 100% !important;
        max-width: 100% !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        flex-wrap: nowrap !important;
        gap: 5px !important;
        padding-bottom: 2px !important;
        -webkit-overflow-scrolling: touch !important;
    }

    .reader-actions .btn {
        flex: 0 0 auto !important;
    }

    .reader-paged-mode .reader-viewport {
        padding-top: 12px !important;
        padding-bottom: 8px !important;
    }
}

/* [2026-05-22] V27 手機和平板閱讀工具列壓縮修正。
   左側固定顯示小說名稱、目前章節、路徑與檔案大小，右側按鈕改為二到三個一排自動換行，避免整個工具列過高壓縮內文區。 */
@media (max-width: 991.98px) {
    .reader-toolbar {
        display: grid !important;
        grid-template-columns: minmax(0, 1fr) auto !important;
        grid-template-areas: "title actions" !important;
        align-items: start !important;
        column-gap: 8px !important;
        row-gap: 0 !important;
        min-height: 0 !important;
        height: auto !important;
        max-height: none !important;
        overflow: visible !important;
        padding: 7px 10px !important;
    }

    .reader-title-wrap {
        grid-area: title !important;
        display: flex !important;
        flex-direction: column !important;
        gap: 3px !important;
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100% !important;
        overflow: hidden !important;
    }

    .reader-title {
        font-size: 15px !important;
        line-height: 1.25 !important;
        font-weight: 800 !important;
        white-space: normal !important;
        overflow: visible !important;
        text-overflow: clip !important;
        word-break: break-word !important;
    }

    .reader-current-chapter {
        display: block !important;
        width: fit-content !important;
        max-width: 100% !important;
        padding: 2px 7px !important;
        font-size: 11px !important;
        line-height: 1.25 !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }

    .reader-current-chapter.d-none {
        display: none !important;
    }

    .reader-path {
        font-size: 10.5px !important;
        line-height: 1.25 !important;
        white-space: normal !important;
        overflow: visible !important;
        text-overflow: clip !important;
        word-break: break-word !important;
    }

    .reader-actions {
        grid-area: actions !important;
        display: flex !important;
        flex-wrap: wrap !important;
        justify-content: flex-end !important;
        align-content: flex-start !important;
        align-items: flex-start !important;
        gap: 4px !important;
        width: 132px !important;
        max-width: 132px !important;
        min-width: 132px !important;
        overflow: visible !important;
        padding: 0 !important;
        margin: 0 !important;
        -webkit-overflow-scrolling: auto !important;
    }

    .reader-actions .btn {
        flex: 0 0 40px !important;
        width: 40px !important;
        min-width: 40px !important;
        max-width: 40px !important;
        height: 34px !important;
        min-height: 34px !important;
        padding: 3px 0 !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        line-height: 1 !important;
    }

    .reader-actions .btn span {
        display: none !important;
    }

    .reader-actions .btn i {
        margin: 0 !important;
    }

    .progress-wrap {
        max-height: none !important;
        overflow: visible !important;
        padding: 5px 10px 7px !important;
    }

    .progress-info {
        font-size: 12px !important;
        line-height: 1.25 !important;
        margin-bottom: 4px !important;
    }

    .thin-progress {
        height: 5px !important;
    }

    .bottom-controls {
        display: flex !important;
        gap: 8px !important;
        margin-top: 6px !important;
    }

    .bottom-controls .btn {
        flex: 1 1 0 !important;
        min-width: 0 !important;
        height: 36px !important;
        min-height: 36px !important;
        padding: 4px 8px !important;
        line-height: 1.2 !important;
        white-space: nowrap !important;
    }

    .reader-paged-mode .reader-viewport {
        padding-top: 12px !important;
        padding-bottom: 8px !important;
    }
}

@media (max-width: 380px) {
    .reader-toolbar {
        column-gap: 6px !important;
        padding-left: 8px !important;
        padding-right: 8px !important;
    }

    .reader-actions {
        width: 88px !important;
        max-width: 88px !important;
        min-width: 88px !important;
    }

    .reader-actions .btn {
        flex-basis: 40px !important;
    }
}
