/* =========================================================
1. 多主題配色體系 (明亮 / 羊皮紙 / 護眼綠 / 深灰夜間 / 純黑AMOLED)
========================================================= */
:root,
body[data-theme="light"] {
    --bg-color: #f5f5f7;
    --app-bg: #ffffff;
    --text-color: #333333;
    --text-muted: #666666;
    --text-dark: #111111;
    --link-color: #0066cc;
    --link-hover-bg: #f0f7ff;
    --border-color: #e5e5ea;
    --card-shadow: rgba(0, 0, 0, 0.05);
    --card-shadow-hover: rgba(0, 0, 0, 0.08);
    --btn-disabled-bg: #e9ecef;
    --btn-disabled-color: #6c757d;
    --offline-badge-bg: #e8f4fd;
    --offline-badge-color: #0066cc;
    --offline-badge-border: #b8daff;
    --highlight-bg: rgba(255, 226, 0, 0.35);
    --highlight-border: #f0a500;
    --status-unread-bg: #f3f4f6;
    --status-unread-color: #4b5563;
    --status-reading-bg: #e0f2fe;
    --status-reading-color: #0369a1;
    --status-finished-bg: #dcfce7;
    --status-finished-color: #15803d;
    --hud-bg: rgba(255, 255, 255, 0.94);
    --hud-border: rgba(0, 0, 0, 0.08);
    --drawer-bg: #ffffff;
    --prefetch-glow: #10b981;
}

/* 經典羊皮紙 (Sepia) */
body[data-theme="sepia"] {
    --bg-color: #f4ecd8;
    --app-bg: #fbf0d9;
    --text-color: #5f4b32;
    --text-muted: #8b7355;
    --text-dark: #3e2f1e;
    --link-color: #8c5822;
    --link-hover-bg: #efe2c4;
    --border-color: #e2d3b5;
    --card-shadow: rgba(60, 40, 20, 0.07);
    --card-shadow-hover: rgba(60, 40, 20, 0.12);
    --btn-disabled-bg: #ecdcc3;
    --btn-disabled-color: #9c8469;
    --offline-badge-bg: #eddcc0;
    --offline-badge-color: #6d4c1b;
    --offline-badge-border: #d8c29d;
    --highlight-bg: rgba(220, 160, 80, 0.3);
    --highlight-border: #c48332;
    --status-unread-bg: #e9dec9;
    --status-unread-color: #705b45;
    --status-reading-bg: #e4d7bf;
    --status-reading-color: #8c5822;
    --status-finished-bg: #d9e6cc;
    --status-finished-color: #2e6024;
    --hud-bg: rgba(251, 240, 217, 0.94);
    --hud-border: rgba(95, 75, 50, 0.12);
    --drawer-bg: #faf0d8;
    --prefetch-glow: #059669;
}

/* 淡綠護眼 (Mint Green) */
body[data-theme="green"] {
    --bg-color: #dceddf;
    --app-bg: #e8f5e9;
    --text-color: #24523d;
    --text-muted: #4e7d67;
    --text-dark: #153b2a;
    --link-color: #1b5e20;
    --link-hover-bg: #d0ebd3;
    --border-color: #c4dec7;
    --card-shadow: rgba(20, 50, 30, 0.06);
    --card-shadow-hover: rgba(20, 50, 30, 0.1);
    --btn-disabled-bg: #d7eade;
    --btn-disabled-color: #7ba38e;
    --offline-badge-bg: #c8e6c9;
    --offline-badge-color: #1b5e20;
    --offline-badge-border: #a5d6a7;
    --highlight-bg: rgba(160, 220, 100, 0.35);
    --highlight-border: #558b2f;
    --status-unread-bg: #d5e8da;
    --status-unread-color: #3b6652;
    --status-reading-bg: #c9eed2;
    --status-reading-color: #1b5e20;
    --status-finished-bg: #bbf0c8;
    --status-finished-color: #14532d;
    --hud-bg: rgba(232, 245, 233, 0.94);
    --hud-border: rgba(36, 82, 61, 0.12);
    --drawer-bg: #e4f3e6;
    --prefetch-glow: #16a34a;
}

/* 深灰夜間 (Dark) */
body[data-theme="dark"],
body.dark-mode {
    --bg-color: #121212;
    --app-bg: #1e1e1e;
    --text-color: #e0e0e0;
    --text-muted: #aaaaaa;
    --text-dark: #ffffff;
    --link-color: #4da6ff;
    --link-hover-bg: #2c2c2c;
    --border-color: #333333;
    --card-shadow: rgba(0, 0, 0, 0.3);
    --card-shadow-hover: rgba(0, 0, 0, 0.45);
    --btn-disabled-bg: #2d2d2d;
    --btn-disabled-color: #555555;
    --offline-badge-bg: #1a365d;
    --offline-badge-color: #90cdf4;
    --offline-badge-border: #2b6cb0;
    --highlight-bg: rgba(255, 204, 0, 0.22);
    --highlight-border: #ffcc00;
    --status-unread-bg: #2d2d2d;
    --status-unread-color: #9ca3af;
    --status-reading-bg: #0c4a6e;
    --status-reading-color: #7dd3fc;
    --status-finished-bg: #14532d;
    --status-finished-color: #86efac;
    --hud-bg: rgba(30, 30, 30, 0.94);
    --hud-border: rgba(255, 255, 255, 0.1);
    --drawer-bg: #1c1c1c;
    --prefetch-glow: #34d399;
}

/* 純黑省電 (AMOLED Deep Black) */
body[data-theme="amoled"] {
    --bg-color: #000000;
    --app-bg: #000000;
    --text-color: #b5b5b5;
    --text-muted: #737373;
    --text-dark: #f0f0f0;
    --link-color: #64b5f6;
    --link-hover-bg: #151515;
    --border-color: #242424;
    --card-shadow: rgba(0, 0, 0, 0.8);
    --card-shadow-hover: rgba(0, 0, 0, 0.95);
    --btn-disabled-bg: #161616;
    --btn-disabled-color: #444444;
    --offline-badge-bg: #102033;
    --offline-badge-color: #64b5f6;
    --offline-badge-border: #1e3a5f;
    --highlight-bg: rgba(255, 215, 0, 0.25);
    --highlight-border: #ffb300;
    --status-unread-bg: #1c1c1c;
    --status-unread-color: #888888;
    --status-reading-bg: #082f49;
    --status-reading-color: #38bdf8;
    --status-finished-bg: #052e16;
    --status-finished-color: #4ade80;
    --hud-bg: rgba(10, 10, 10, 0.96);
    --hud-border: rgba(255, 255, 255, 0.12);
    --drawer-bg: #080808;
    --prefetch-glow: #10b981;
}

/* 排版與閱讀版心變數預設值 */
:root {
    --content-max-width: 850px;
    --reader-font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang TC", "Microsoft JhengHei", sans-serif;
    --reader-font-size: 20px;
    --reader-line-height: 1.85;
    --reader-text-indent: 2em;
    --reader-para-spacing: 16px;
    --dock-bottom-offset: 0px;
    --hud-bottom-offset: 0px;
    --safe-area-inset-top: env(safe-area-inset-top, 0px);
    --safe-area-inset-bottom: env(safe-area-inset-bottom, 0px);
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    line-height: 1.8;
    color: var(--text-color);
    max-width: var(--content-max-width);
    margin: 0 auto;
    padding: calc(16px + var(--safe-area-inset-top)) 20px calc(24px + var(--safe-area-inset-bottom)) 20px;
    background: var(--bg-color);
    transition: background 0.25s ease, color 0.25s ease, max-width 0.2s ease;
    position: relative;
    min-height: 100vh;
    user-select: text;
}

/* 雙向同步高亮主按鈕樣式 */
.btn-sync-highlight {
    background: linear-gradient(135deg, var(--link-color) 0%, #10b981 100%) !important;
    color: #ffffff !important;
    box-shadow: 0 4px 14px rgba(16, 185, 129, 0.3);
    transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}

.btn-sync-highlight:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(16, 185, 129, 0.45);
    opacity: 0.95;
}

.btn-sync-highlight:active {
    transform: translateY(0);
}

/* 備份彈跳視窗內部頁籤與樣式 */
.backup-tab-bar {
    display: flex;
    gap: 8px;
    border-bottom: 2px solid var(--border-color);
    margin-bottom: 16px;
}

.backup-tab-btn {
    background: none;
    border: none;
    padding: 10px 14px;
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    transition: all 0.2s ease;
}

.backup-tab-btn:hover {
    color: var(--link-color);
}

.backup-tab-btn.active {
    color: var(--link-color);
    border-bottom-color: var(--link-color);
}

.backup-tab-panel {
    display: none;
}

.backup-tab-panel.active {
    display: block;
}

.backup-section-box {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 14px 16px;
}

.backup-section-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 700;
    font-size: 0.92rem;
    color: var(--text-dark);
}

.backup-dropzone {
    border: 2px dashed var(--border-color);
    border-radius: 10px;
    padding: 24px 16px;
    text-align: center;
    cursor: pointer;
    background: var(--app-bg);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
    margin-top: 10px;
}

.backup-dropzone:hover,
.backup-dropzone.dragover {
    border-color: var(--link-color);
    background: var(--link-hover-bg);
}

.import-preview-box {
    background: var(--app-bg);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 14px;
    margin-top: 10px;
}

.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.badge-valid {
    background: rgba(16, 185, 129, 0.15);
    color: #10b981;
    border: 1px solid rgba(16, 185, 129, 0.3);
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.76rem;
    font-weight: 600;
}

.preview-meta-info {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.preview-stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    background: var(--bg-color);
    padding: 10px;
    border-radius: 8px;
    margin-bottom: 10px;
}

.preview-stat-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.preview-stat-item .stat-label {
    font-size: 0.76rem;
    color: var(--text-muted);
}

.preview-stat-item .stat-val {
    font-size: 0.88rem;
    font-weight: 700;
    color: var(--text-dark);
}

.preview-warnings-box {
    background: rgba(245, 158, 11, 0.12);
    border: 1px solid rgba(245, 158, 11, 0.3);
    color: #d97706;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.8rem;
    line-height: 1.5;
    margin-bottom: 10px;
}

.import-mode-selector {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.mode-radio-label {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 12px;
    border: 1.5px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    background: var(--app-bg);
    transition: all 0.2s ease;
}

.mode-radio-label:hover {
    border-color: var(--link-color);
    background: var(--link-hover-bg);
}

.mode-radio-label.active {
    border-color: var(--link-color);
    background: var(--link-hover-bg);
}

/* PWA 離線就緒橫幅與安裝按鈕 */
.pwa-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.76rem;
    background: rgba(16, 185, 129, 0.12);
    color: #10b981;
    border: 1px solid rgba(16, 185, 129, 0.3);
    padding: 2px 8px;
    border-radius: 12px;
    font-weight: 600;
}

.btn-install-pwa {
    display: none;
    background: linear-gradient(135deg, var(--link-color), #004c99);
    color: #ffffff !important;
    border: none;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 102, 204, 0.35);
    animation: pulse-pwa 2.5s infinite;
}

@keyframes pulse-pwa {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.04);
    }
}

/* PWA 離線狀態診斷膠囊標籤 */
.pwa-status-btn {
    background: var(--app-bg);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.82rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-weight: 600;
    transition: all 0.2s;
    box-shadow: 0 2px 5px var(--card-shadow);
}

.pwa-status-btn:hover {
    border-color: var(--link-color);
    background: var(--link-hover-bg);
}

.pwa-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    background-color: #f59e0b;
}

.pwa-status-dot.ready {
    background-color: #10b981;
    box-shadow: 0 0 6px #10b981;
}

.pwa-status-dot.warn {
    background-color: #f59e0b;
}

.pwa-guide-box {
    background: var(--link-hover-bg);
    border: 1px solid var(--border-color);
    border-left: 4px solid var(--link-color);
    border-radius: 8px;
    padding: 14px;
    margin-bottom: 16px;
    font-size: 0.88rem;
    line-height: 1.6;
}

.pwa-guide-step {
    margin: 8px 0;
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

.step-num {
    background: var(--link-color);
    color: #fff;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    flex-shrink: 0;
    margin-top: 2px;
}

/* 頂部工具列 */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: var(--content-max-width);
    margin: 0 auto 15px auto;
    flex-wrap: wrap;
    gap: 12px;
    transition: max-width 0.2s ease;
}

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

.search-box input {
    padding: 9px 18px;
    border-radius: 25px;
    border: 1px solid var(--border-color);
    background: var(--app-bg);
    color: var(--text-color);
    width: 220px;
    outline: none;
    transition: all 0.3s;
    box-shadow: 0 2px 5px var(--card-shadow);
}

.search-box input:focus {
    border-color: var(--link-color);
    box-shadow: 0 0 8px rgba(0, 102, 204, 0.3);
    width: 260px;
}

.top-btn {
    background: var(--app-bg);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    padding: 8px 14px;
    border-radius: 20px;
    cursor: pointer;
    font-weight: 500;
    box-shadow: 0 2px 5px var(--card-shadow);
    transition: all 0.2s;
    font-size: 0.88rem;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    user-select: none;
}

.top-btn:hover {
    background: var(--link-hover-bg);
}

.mobile-more-btn {
    display: none;
}

#app {
    background: var(--app-bg);
    padding: 30px;
    border-radius: 12px;
    box-shadow: 0 4px 20px var(--card-shadow);
    min-height: 420px;
    transition: background 0.25s, box-shadow 0.25s, padding 0.2s;
    position: relative;
}

.loading {
    color: var(--text-muted);
    font-style: italic;
    text-align: center;
    padding: 40px 0;
    font-size: 1.1rem;
}

.error {
    color: #d9534f;
    font-weight: bold;
    text-align: center;
    padding: 40px 0;
    line-height: 1.6;
}

.offline-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--offline-badge-bg);
    color: var(--offline-badge-color);
    border: 1px solid var(--offline-badge-border);
    font-size: 0.78rem;
    padding: 2px 8px;
    border-radius: 12px;
    margin-left: 8px;
    vertical-align: middle;
    font-weight: 500;
}

/* 預載完成樣式 (靜默預載，不顯示突兀的浮動徽章) */
.prefetched-ready {
    border-color: var(--border-color);
}

.home-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 12px;
}

.home-header h1 {
    margin: 0;
    font-size: 1.75rem;
}

.shelf-filter-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 22px;
    flex-wrap: wrap;
    border-bottom: 1.5px solid var(--border-color);
    padding-bottom: 12px;
}

.shelf-filter-btn {
    background: var(--app-bg);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.88rem;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
}

.shelf-filter-btn:hover {
    border-color: var(--link-color);
    color: var(--link-color);
    background: var(--link-hover-bg);
}

.shelf-filter-btn.active {
    background: var(--link-color);
    color: #ffffff;
    border-color: var(--link-color);
    font-weight: 600;
}

.filter-count-pill {
    background: rgba(125, 125, 125, 0.15);
    font-size: 0.76rem;
    padding: 1px 7px;
    border-radius: 10px;
    font-weight: bold;
}

.shelf-filter-btn.active .filter-count-pill {
    background: rgba(255, 255, 255, 0.3);
    color: #ffffff;
}

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

.book-card {
    background: var(--app-bg);
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 2px 8px var(--card-shadow-hover);
    transition: transform 0.2s, background 0.3s;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border-color);
    position: relative;
}

.book-card:hover {
    transform: translateY(-5px);
}

.book-cover-wrapper {
    position: relative;
    width: 100%;
    aspect-ratio: 2 / 3;
    margin-bottom: 10px;
}

.book-cover {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 6px;
    background: #eee;
    display: block;
}

.book-card-floating-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 2;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}

.book-status-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid transparent;
    user-select: none;
}

.book-status-tag.status-unread {
    background: var(--status-unread-bg);
    color: var(--status-unread-color);
}

.book-status-tag.status-reading {
    background: var(--status-reading-bg);
    color: var(--status-reading-color);
}

.book-status-tag.status-finished {
    background: var(--status-finished-bg);
    color: var(--status-finished-color);
}

.book-status-select {
    appearance: none;
    -webkit-appearance: none;
    background: transparent;
    border: none;
    color: inherit;
    font-size: inherit;
    font-family: inherit;
    font-weight: inherit;
    cursor: pointer;
    outline: none;
    padding-right: 14px;
    background-image: url('data:image/svg+xml;charset=US-ASCII,<svg%20xmlns="http://www.w3.org/2000/svg"%20width="10"%20height="6"><path%20d="M0%200l5%205%205-5z"%20fill="%23888888"/></svg>');
    background-repeat: no-repeat;
    background-position: right center;
    background-size: 8px;
}

.book-status-select option {
    background: var(--app-bg);
    color: var(--text-color);
}

.book-title {
    margin: 8px 0 4px 0;
    font-size: 1.18rem;
    color: var(--text-dark);
    line-height: 1.4;
}

.book-author {
    color: var(--text-muted);
    font-size: 0.88rem;
    margin-bottom: 8px;
}

.book-info {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}

.book-desc {
    font-size: 0.86rem;
    color: var(--text-color);
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: auto;
    margin-bottom: 15px;
    flex-grow: 1;
    word-break: break-word;
    scrollbar-width: thin;
    scrollbar-color: rgba(125, 125, 125, 0.35) transparent;
}

.book-progress-mini {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.bookshelf.list-view {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.bookshelf.list-view .book-card {
    flex-direction: row;
    align-items: flex-start;
    padding: 20px;
}

.bookshelf.list-view .book-cover-wrapper {
    width: 160px;
    height: auto;
    aspect-ratio: 2 / 3;
    margin-right: 25px;
    margin-bottom: 0;
    flex-shrink: 0;
}

.bookshelf.list-view .book-desc {
    -webkit-line-clamp: 2;
}

/* 閱讀內文排版樣式 */
.content-area {
    font-family: var(--reader-font-family);
    font-size: var(--reader-font-size);
    line-height: var(--reader-line-height);
    letter-spacing: 0.5px;
    margin-top: 28px;
    color: var(--text-dark);
    text-align: justify;
    transition: font-size 0.15s ease, line-height 0.15s ease;
    position: relative;
    user-select: text;
}

.content-area p {
    margin-top: 0;
    margin-bottom: var(--reader-para-spacing);
    text-indent: var(--reader-text-indent);
    line-height: inherit;
    word-break: break-word;
}

.chapter-header-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 12px;
    margin-bottom: 15px;
}

.chapter-header-bar h1 {
    margin: 0;
    font-size: 1.6rem;
}

.chapter-header-bar,
.chapter-nav,
.back-link,
.paged-footer-bar {
    position: relative;
    z-index: 10;
}

.chapter-quick-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.chapter-autoscroll-btn.active {
    border-color: var(--link-color);
    color: var(--link-color);
    background: var(--link-hover-bg);
}

.chapter-meta-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.82rem;
    color: var(--text-muted);
    background: rgba(125, 125, 125, 0.08);
    border: 1px solid var(--border-color);
    padding: 3px 10px;
    border-radius: 12px;
    margin-top: 6px;
    font-weight: normal;
}

.content-area p.tts-highlight {
    background: var(--highlight-bg);
    border-left: 3.5px solid var(--link-color);
    padding-left: 10px;
    border-radius: 4px;
    transition: all 0.25s ease;
}

/* 金句書籤精準定位高亮動畫樣式 */
@keyframes bookmark-pulse {
    0% {
        background-color: rgba(255, 215, 0, 0.55);
        box-shadow: 0 0 0 0 rgba(255, 215, 0, 0.45);
    }

    40% {
        background-color: rgba(255, 215, 0, 0.35);
        box-shadow: 0 0 0 8px rgba(255, 215, 0, 0.16);
    }

    100% {
        background-color: rgba(255, 215, 0, 0.22);
        box-shadow: 0 0 0 0 rgba(255, 215, 0, 0);
    }
}

.bookmark-target-highlight {
    animation: bookmark-pulse 1.6s ease-in-out 2;
    background-color: var(--highlight-bg) !important;
    border-left: 4px solid var(--highlight-border) !important;
    padding-left: 12px !important;
    border-radius: 6px;
    transition: all 0.3s ease;
}

.bookmark-target-marked {
    background-color: rgba(255, 226, 0, 0.12) !important;
    border-left: 3.5px solid var(--highlight-border) !important;
    padding-left: 12px !important;
    border-radius: 6px;
    transition: background-color 0.4s ease;
}

.touch-zones-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 998;
    display: none;
    pointer-events: none !important;
}

body.reading-active .touch-zones-container {
    display: flex;
    pointer-events: none !important;
}

.touch-zone {
    height: 100%;
    position: relative;
    pointer-events: none !important;
    transition: background 0.25s ease, border-color 0.25s ease;
}

.touch-zone-left {
    width: 22%;
    border-right: 1px dashed transparent;
}

.touch-zone-center {
    width: 56%;
}

.touch-zone-right {
    width: 22%;
    border-left: 1px dashed transparent;
}

body.reading-active.hud-open .touch-zone-left {
    border-right-color: rgba(125, 125, 125, 0.16);
    background: rgba(0, 0, 0, 0.015);
}

body.reading-active.hud-open .touch-zone-right {
    border-left-color: rgba(125, 125, 125, 0.16);
    background: rgba(0, 0, 0, 0.015);
}

.touch-ripple {
    position: fixed;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--link-color);
    opacity: 0.35;
    pointer-events: none;
    transform: translate(-50%, -50%) scale(0.4);
    animation: touch-ripple-anim 0.35s cubic-bezier(0.1, 0.8, 0.3, 1) forwards;
    z-index: 10003;
}

@keyframes touch-ripple-anim {
    0% {
        transform: translate(-50%, -50%) scale(0.4);
        opacity: 0.45;
    }

    100% {
        transform: translate(-50%, -50%) scale(2.2);
        opacity: 0;
    }
}

.flip-page-hint {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0, 0, 0, 0.65);
    color: #ffffff;
    font-size: 0.85rem;
    padding: 8px 14px;
    border-radius: 20px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.25s ease, transform 0.25s ease;
    z-index: 10002;
    backdrop-filter: blur(4px);
}

.flip-page-hint.left {
    left: 24px;
    transform: translateY(-50%) translateX(-8px);
}

.flip-page-hint.right {
    right: 24px;
    transform: translateY(-50%) translateX(8px);
}

.flip-page-hint.show {
    opacity: 1;
    transform: translateY(-50%) translateX(0);
}

/* 沉浸閱讀 HUD */
.reading-hud-top {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    background: var(--hud-bg);
    border-bottom: 1px solid var(--hud-border);
    box-shadow: 0 4px 18px var(--card-shadow);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 10000;
    padding: calc(10px + var(--safe-area-inset-top)) 18px 10px 18px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transform: translateY(-110%);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.reading-hud-top.active {
    transform: translateY(0);
}

.hud-left {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
}

.hud-right {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

/* 工具按鈕容器群組 */
.hud-tools-group {
    display: flex;
    align-items: center;
    gap: 8px;
    max-width: 260px;
    opacity: 1;
    transform: translateX(0);
    overflow: hidden;
    white-space: nowrap;
    transition: max-width 0.32s cubic-bezier(0.25, 1, 0.5, 1),
        opacity 0.22s ease,
        transform 0.32s cubic-bezier(0.25, 1, 0.5, 1);
}

.hud-tools-group .hud-icon-btn {
    flex-shrink: 0;
    transition: transform 0.25s cubic-bezier(0.25, 1, 0.5, 1), opacity 0.2s ease;
}

/* 摺疊切換觸發按鈕 */
.hud-toggle-btn {
    font-size: 1.15rem;
    font-weight: bold;
    flex-shrink: 0;
}

.hud-toggle-arrow {
    display: inline-block;
    transition: transform 0.3s cubic-bezier(0.25, 1, 0.5, 1);
    line-height: 1;
}

/* ──── 收合狀態 (向右堆疊並收納) ──── */
.hud-right.is-collapsed .hud-tools-group {
    max-width: 0;
    opacity: 0;
    transform: translateX(20px);
    pointer-events: none;
    margin-right: -2px;
}

/* 收合時各按鈕向右微縮堆疊效果 */
.hud-right.is-collapsed .hud-tools-group .hud-icon-btn {
    transform: scale(0.75) translateX(12px);
    opacity: 0;
}

/* 收合後箭頭轉向左側 (‹)，示意點擊可向左展開 */
.hud-right.is-collapsed .hud-toggle-arrow {
    transform: rotate(180deg);
}

.hud-title-wrap {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.hud-novel-title {
    font-size: 0.78rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.hud-chapter-title {
    font-size: 0.96rem;
    font-weight: 700;
    color: var(--text-dark);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.reading-hud-bottom {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: var(--hud-bg);
    border-top: 1px solid var(--hud-border);
    box-shadow: 0 -4px 18px var(--card-shadow);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 10000;
    padding: 12px 20px calc(16px + var(--safe-area-inset-bottom)) 20px;
    transform: translateY(110%);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.reading-hud-bottom.active {
    transform: translateY(0);
}

.hud-scrubber-row {
    display: flex;
    align-items: center;
    gap: 14px;
    max-width: 780px;
    margin: 0 auto;
    width: 100%;
}

.hud-scrubber-slider {
    flex-grow: 1;
    accent-color: var(--link-color);
    cursor: pointer;
    height: 5px;
}

.hud-scrubber-badge {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--link-color);
    min-width: 50px;
    text-align: right;
}

.hud-actions-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 780px;
    margin: 0 auto;
    width: 100%;
    gap: 8px;
}

.hud-nav-btn {
    background: var(--app-bg);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    padding: 7px 16px;
    border-radius: 18px;
    font-size: 0.88rem;
    cursor: pointer;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    transition: all 0.2s;
}

.hud-nav-btn:hover {
    border-color: var(--link-color);
    background: var(--link-hover-bg);
    color: var(--link-color);
}

.hud-nav-btn.disabled {
    opacity: 0.4;
    pointer-events: none;
}

.hud-icon-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 1px solid var(--border-color);
    background: var(--app-bg);
    color: var(--text-color);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.05rem;
    transition: all 0.18s;
    box-shadow: 0 2px 6px var(--card-shadow);
}

.hud-icon-btn:hover {
    border-color: var(--link-color);
    background: var(--link-hover-bg);
    color: var(--link-color);
}

/* 側邊目錄抽屜 */
.drawer-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.48);
    backdrop-filter: blur(4px);
    z-index: 10010;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.28s ease;
}

.drawer-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.chapter-drawer {
    position: fixed;
    top: 0;
    left: 0;
    width: 82%;
    max-width: 380px;
    height: 100%;
    background: var(--drawer-bg);
    z-index: 10011;
    box-shadow: 6px 0 25px rgba(0, 0, 0, 0.28);
    border-right: 1px solid var(--border-color);
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    flex-direction: column;
    padding-top: var(--safe-area-inset-top);
    padding-bottom: var(--safe-area-inset-bottom);
}

.chapter-drawer.active {
    transform: translateX(0);
}

.drawer-header {
    padding: 16px 18px 12px 18px;
    border-bottom: 1px solid var(--border-color);
    background: var(--app-bg);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.drawer-title-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.drawer-title-bar h3 {
    margin: 0;
    font-size: 1.15rem;
    color: var(--text-dark);
    display: flex;
    align-items: center;
    gap: 6px;
}

.drawer-search-wrap {
    position: relative;
}

.drawer-search-input {
    width: 100%;
    padding: 8px 12px 8px 32px;
    border-radius: 18px;
    border: 1px solid var(--border-color);
    background: var(--bg-color);
    color: var(--text-color);
    font-size: 0.85rem;
    outline: none;
    transition: border-color 0.2s;
}

.drawer-search-input:focus {
    border-color: var(--link-color);
}

.drawer-search-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.82rem;
    color: var(--text-muted);
    pointer-events: none;
}

.drawer-tools {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.82rem;
    color: var(--text-muted);
    padding-top: 2px;
}

.drawer-tool-btn {
    background: transparent;
    border: none;
    color: var(--link-color);
    cursor: pointer;
    font-size: 0.82rem;
    padding: 3px 6px;
    border-radius: 4px;
    transition: background 0.15s;
}

.drawer-tool-btn:hover {
    background: var(--link-hover-bg);
}

.drawer-body {
    flex-grow: 1;
    overflow-y: auto;
    padding: 8px 0;
    -webkit-overflow-scrolling: touch;
}

.drawer-chapter-item {
    padding: 12px 18px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.18s;
    font-size: 0.95rem;
    color: var(--text-color);
}

.drawer-chapter-item:hover {
    background: var(--link-hover-bg);
}

.drawer-chapter-item.active {
    background: var(--link-hover-bg);
    color: var(--link-color);
    font-weight: 700;
    border-left: 4px solid var(--link-color);
    padding-left: 14px;
}

.drawer-badge-reading {
    font-size: 0.75rem;
    background: var(--link-color);
    color: #ffffff;
    padding: 2px 7px;
    border-radius: 10px;
    font-weight: normal;
}

/* 主章節目錄分段導航列 */
.toc-controls-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    margin: 12px 0 16px 0;
    padding: 8px 14px;
    background: var(--link-hover-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.88rem;
    color: var(--text-dark);
}

.toc-range-select {
    padding: 6px 12px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background: var(--app-bg);
    color: var(--text-color);
    font-size: 0.88rem;
    cursor: pointer;
    outline: none;
}

.toc-sentinel {
    text-align: center;
    padding: 16px 0;
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* 主章節目錄列表 */
.chapter-list {
    list-style: none;
    padding: 0;
    margin-top: 16px;
}

.chapter-list-item {
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background 0.18s ease, color 0.18s ease, border-left-color 0.18s ease, padding-left 0.18s ease;
    position: relative;
}

.chapter-list-item:hover {
    background: var(--link-hover-bg);
}

.chapter-list-item.active {
    background: var(--link-hover-bg);
    border-left: 4px solid var(--link-color);
}

.chapter-list-link {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 13px 18px;
    text-decoration: none;
    color: var(--text-color);
    font-size: 1rem;
    transition: color 0.18s ease;
    width: 100%;
}

.chapter-list-item:hover .chapter-list-link {
    color: var(--link-color);
}

.chapter-list-item.active .chapter-list-link {
    color: var(--link-color);
    font-weight: 700;
    padding-left: 14px;
}

.chapter-item-title {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chapter-item-badges {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

/* 朗讀有聲書與自動滾動列 */
.tts-dock {
    position: fixed;
    bottom: calc(24px + var(--hud-bottom-offset, 0px) + var(--safe-area-inset-bottom));
    left: 50%;
    transform: translateX(-50%) translateY(120px);
    background: var(--app-bg);
    border: 1px solid var(--border-color);
    box-shadow: 0 8px 32px var(--card-shadow-hover);
    border-radius: 30px;
    padding: 8px 18px;
    display: flex;
    align-items: center;
    gap: 10px;
    z-index: 10005;
    transition: bottom 0.25s ease, transform 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28), opacity 0.3s ease, width 0.25s ease, height 0.25s ease, border-radius 0.25s ease;
    opacity: 0;
    pointer-events: none;
    max-width: 92vw;
    flex-wrap: wrap;
}

.tts-dock.active {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
    pointer-events: auto;
}

.tts-dock.minimized {
    width: 48px;
    height: 48px;
    min-width: 48px;
    min-height: 48px;
    padding: 0;
    border-radius: 50%;
    border: none;
    background: transparent;
    box-shadow: none;
    overflow: visible;
}

.tts-dock.minimized>*:not(.tts-mini-trigger) {
    display: none !important;
}

.tts-mini-trigger {
    display: none;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--link-color), #004c99);
    color: #ffffff;
    border: 2px solid var(--app-bg);
    box-shadow: 0 4px 18px rgba(0, 102, 204, 0.45);
    font-size: 1.25rem;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    user-select: none;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.tts-dock.minimized .tts-mini-trigger {
    display: flex;
}

.tts-dock.minimized:hover .tts-mini-trigger {
    transform: scale(1.08);
}

.tts-dock.minimized.playing .tts-mini-trigger {
    animation: tts-wave-pulse 1.8s infinite ease-in-out;
}

@keyframes tts-wave-pulse {

    0%,
    100% {
        box-shadow: 0 0 0 0 rgba(0, 102, 204, 0.5), 0 4px 18px rgba(0, 0, 0, 0.3);
        transform: scale(1);
    }

    50% {
        box-shadow: 0 0 0 8px rgba(0, 102, 204, 0), 0 6px 22px rgba(0, 102, 204, 0.55);
        transform: scale(1.08);
    }
}

.tts-info {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-dark);
    min-width: 90px;
}

.tts-control-btn {
    background: var(--app-bg);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.92rem;
    transition: all 0.15s;
}

.tts-control-btn:hover {
    background: var(--link-hover-bg);
    color: var(--link-color);
    border-color: var(--link-color);
}

.tts-control-btn.primary {
    background: var(--link-color);
    color: #ffffff;
    border-color: var(--link-color);
    width: 38px;
    height: 38px;
}

.tts-select {
    padding: 4px 8px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    background: var(--app-bg);
    color: var(--text-color);
    font-size: 0.82rem;
    outline: none;
    cursor: pointer;
}

.autoscroll-bar {
    position: fixed;
    bottom: calc(24px + var(--hud-bottom-offset, 0px) + var(--safe-area-inset-bottom));
    right: 24px;
    background: var(--app-bg);
    border: 1px solid var(--border-color);
    box-shadow: 0 6px 25px var(--card-shadow);
    border-radius: 24px;
    padding: 6px 14px;
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 10004;
    transform: translateY(100px);
    opacity: 0;
    pointer-events: none;
    transition: bottom 0.25s ease, transform 0.25s ease, opacity 0.25s ease;
}

.autoscroll-bar.active {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
}

.autoscroll-badge {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--link-color);
    display: flex;
    align-items: center;
    gap: 4px;
}

.autoscroll-speed-btn {
    background: var(--app-bg);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    font-size: 0.8rem;
    padding: 3px 8px;
    border-radius: 10px;
    cursor: pointer;
}

.autoscroll-speed-btn.active {
    background: var(--link-color);
    color: #ffffff;
    border-color: var(--link-color);
}

/* 左右分頁模式 */
.paged-viewport-container {
    width: 100%;
    height: calc(100vh - 180px);
    min-height: 420px;
    overflow: hidden;
    position: relative;
    margin-top: 15px;
    user-select: text;
}

.paged-columns-track {
    height: 100%;
    column-fill: auto;
    column-gap: 40px;
    column-rule: 1px dashed var(--border-color);
    transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
    will-change: transform;
    font-family: var(--reader-font-family);
    font-size: var(--reader-font-size);
    line-height: var(--reader-line-height);
    color: var(--text-dark);
    text-align: justify;
}

.paged-columns-track p {
    margin-top: 0;
    margin-bottom: var(--reader-para-spacing);
    text-indent: var(--reader-text-indent);
    line-height: inherit;
    word-break: break-word;
}

.paged-footer-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    border-top: 1px solid var(--border-color);
    margin-top: 12px;
    font-size: 0.84rem;
    color: var(--text-muted);
}

.paged-page-btn {
    background: var(--app-bg);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    padding: 5px 14px;
    border-radius: 16px;
    cursor: pointer;
    font-size: 0.82rem;
    font-weight: 500;
    transition: all 0.2s;
}

.paged-page-btn:hover {
    border-color: var(--link-color);
    color: var(--link-color);
    background: var(--link-hover-bg);
}

.paged-page-btn.disabled {
    opacity: 0.4;
    pointer-events: none;
}

/* 底部 Action Sheet */
.action-sheet-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(4px);
    z-index: 10020;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

.action-sheet-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.action-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: var(--app-bg);
    border-top: 1px solid var(--border-color);
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -8px 30px var(--card-shadow-hover);
    z-index: 10021;
    padding: 12px 20px calc(28px + var(--safe-area-inset-bottom)) 20px;
    transform: translateY(105%);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    max-height: 80vh;
    overflow-y: auto;
}

.action-sheet.active {
    transform: translateY(0);
}

.action-sheet-handle {
    width: 38px;
    height: 4px;
    background: var(--border-color);
    border-radius: 2px;
    margin: 0 auto 12px auto;
}

.action-sheet-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 10px;
    margin-bottom: 14px;
}

.action-sheet-header h4 {
    margin: 0;
    font-size: 1.1rem;
    color: var(--text-dark);
}

.action-sheet-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

.action-sheet-item {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    padding: 14px 8px;
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-size: 0.86rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

.action-sheet-item:hover,
.action-sheet-item:active {
    background: var(--link-hover-bg);
    border-color: var(--link-color);
    color: var(--link-color);
}

.action-sheet-item .sheet-icon {
    font-size: 1.35rem;
}

/* 沉浸全螢幕專注模式 */
body.distraction-free {
    max-width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
    background: var(--app-bg) !important;
}

body.distraction-free .top-bar,
body.distraction-free .back-link,
body.distraction-free .chapter-nav,
body.distraction-free .keyboard-hint,
body.distraction-free .chapter-quick-actions,
body.distraction-free #selection-tooltip {
    display: none !important;
}

body.distraction-free #app {
    box-shadow: none !important;
    border-radius: 0 !important;
    padding: calc(40px + var(--safe-area-inset-top)) 25px calc(80px + var(--safe-area-inset-bottom)) 25px !important;
    max-width: var(--content-max-width) !important;
    margin: 0 auto !important;
    min-height: 100vh !important;
    background: transparent !important;
}

.exit-focus-btn {
    display: none;
    position: fixed;
    top: calc(68px + var(--safe-area-inset-top));
    right: 18px;
    z-index: 10002;
    background: rgba(0, 0, 0, 0.45);
    color: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.25);
    padding: 7px 16px;
    border-radius: 20px;
    font-size: 0.88rem;
    cursor: pointer;
    backdrop-filter: blur(5px);
    opacity: 0.35;
    transition: opacity 0.2s, background 0.2s;
}

.exit-focus-btn:hover {
    opacity: 1;
    background: rgba(0, 0, 0, 0.75);
}

body.distraction-free .exit-focus-btn {
    display: block;
}

.distraction-footer-bar {
    display: none;
    position: fixed;
    bottom: calc(12px + var(--safe-area-inset-bottom));
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.82rem;
    color: var(--text-muted);
    background: var(--app-bg);
    border: 1px solid var(--border-color);
    padding: 4px 16px;
    border-radius: 14px;
    opacity: 0.8;
    pointer-events: none;
    box-shadow: 0 2px 10px var(--card-shadow);
    z-index: 9990;
}

body.distraction-free .distraction-footer-bar {
    display: block;
}

/* 模態彈窗與選項 */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(3px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10020;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.modal-overlay.active {
    display: flex;
    opacity: 1;
}

/* =========================================================
排版設定卡片與專屬滾動條風格
========================================================= */
.settings-card {
    background: var(--app-bg);
    color: var(--text-color);
    padding: 24px 28px;
    border-radius: 16px;
    box-shadow: 0 10px 35px var(--card-shadow);
    border: 1px solid var(--border-color);
    width: 90%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
    overscroll-behavior: contain;
    /* 防止滑動到底部時帶動後方頁面滾動 */
    transform: translateY(15px);
    transition: transform 0.25s ease, background 0.25s ease;
}

/* =========================================================
統一彈窗與抽屜現代精緻滾動條風格
(涵蓋：排版設定、閱讀歷史、目錄抽屜、快捷選單)
========================================================= */
.settings-card,
#history-timeline-body,
.drawer-body,
.action-sheet,
.book-desc {
    /* 現代標準規範 (Firefox 等) */
    scrollbar-width: thin;
    scrollbar-color: rgba(125, 125, 125, 0.35) transparent;
    /* 防止滑到頂部或底部時連帶滾動背景內文 */
    overscroll-behavior: contain;
}

/* WebKit 核心瀏覽器 (Chrome / Safari / Edge / 行動端瀏覽器) */
.settings-card::-webkit-scrollbar,
#history-timeline-body::-webkit-scrollbar,
.drawer-body::-webkit-scrollbar,
.action-sheet::-webkit-scrollbar,
.book-desc::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

/* 滾動條軌道 (透明並預留上下邊距，不頂到容器圓角) */
.settings-card::-webkit-scrollbar-track,
#history-timeline-body::-webkit-scrollbar-track,
.drawer-body::-webkit-scrollbar-track,
.action-sheet::-webkit-scrollbar-track,
.book-desc::-webkit-scrollbar-track {
    background: transparent;
    margin: 8px 0;
}

/* 滾動條滑塊 (半透明灰，隨背景主題自動協調) */
.settings-card::-webkit-scrollbar-thumb,
#history-timeline-body::-webkit-scrollbar-thumb,
.drawer-body::-webkit-scrollbar-thumb,
.action-sheet::-webkit-scrollbar-thumb,
.book-desc::-webkit-scrollbar-thumb {
    background-color: rgba(125, 125, 125, 0.32);
    border-radius: 10px;
    transition: background-color 0.2s ease;
}

/* 滑鼠懸停時亮起當前主題強調色 */
.settings-card::-webkit-scrollbar-thumb:hover,
#history-timeline-body::-webkit-scrollbar-thumb:hover,
.drawer-body::-webkit-scrollbar-thumb:hover,
.action-sheet::-webkit-scrollbar-thumb:hover,
.book-desc::-webkit-scrollbar-thumb:hover {
    background-color: var(--link-color);
}

.modal-overlay.active .settings-card {
    transform: translateY(0);
}

.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 12px;
    margin-bottom: 20px;
}

.settings-header h3 {
    margin: 0;
    font-size: 1.25rem;
    color: var(--text-dark);
}

.close-btn {
    background: transparent;
    border: none;
    font-size: 1.5rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0 6px;
    line-height: 1;
}

.close-btn:hover {
    color: var(--text-dark);
}

.setting-group {
    margin-bottom: 22px;
}

.setting-label {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-dark);
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.options-grid-2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.options-grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.options-grid-4 {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.options-grid-5 {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
}

.option-btn {
    padding: 9px 10px;
    border-radius: 8px;
    border: 1.5px solid var(--border-color);
    background: var(--app-bg);
    color: var(--text-color);
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

.option-btn:hover {
    border-color: var(--link-color);
    background: var(--link-hover-bg);
}

.option-btn.active {
    border-color: var(--link-color);
    background: var(--link-color);
    color: #ffffff !important;
    font-weight: 600;
}

.theme-swatch-btn {
    padding: 8px 4px;
    border-radius: 8px;
    border: 2px solid var(--border-color);
    font-size: 0.8rem;
    cursor: pointer;
    text-align: center;
    transition: transform 0.15s, border-color 0.2s;
    font-weight: 600;
}

.theme-swatch-btn:hover {
    transform: translateY(-2px);
}

.theme-swatch-btn.active {
    border-color: var(--link-color);
    box-shadow: 0 0 0 2px var(--link-color);
}

.font-size-controls {
    display: flex;
    align-items: center;
    gap: 12px;
}

.size-step-btn {
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    border: 1px solid var(--border-color);
    background: var(--app-bg);
    color: var(--text-color);
    cursor: pointer;
    font-weight: bold;
    font-size: 1rem;
    transition: all 0.2s;
}

.font-size-slider {
    flex-grow: 1;
    accent-color: var(--link-color);
    cursor: pointer;
}

.font-size-badge {
    min-width: 48px;
    text-align: center;
    font-weight: bold;
    color: var(--link-color);
    font-size: 0.95rem;
}

/* =========================================================
Toast 提示與 5 秒懸浮 Undo 復原機制樣式
========================================================= */
.toast-msg {
    position: fixed;
    bottom: calc(25px + var(--dock-bottom-offset, 0px) + var(--safe-area-inset-bottom));
    left: 50%;
    transform: translateX(-50%) translateY(30px);
    background: rgba(24, 24, 27, 0.94);
    color: #fff;
    padding: 10px 22px;
    border-radius: 25px;
    font-size: 0.92rem;
    z-index: 10030;
    pointer-events: none;
    opacity: 0;
    transition: transform 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28), opacity 0.3s ease, bottom 0.25s ease;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
    display: flex;
    align-items: center;
    gap: 8px;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.12);
}

.toast-msg.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.toast-msg.has-action {
    pointer-events: auto;
    padding: 7px 10px 7px 18px;
    gap: 12px;
    border-radius: 30px;
    border-color: rgba(255, 204, 0, 0.35);
}

.toast-undo-btn {
    background: #ffcc00;
    color: #111111;
    border: none;
    border-radius: 18px;
    padding: 5px 13px;
    font-size: 0.84rem;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: background 0.15s, transform 0.15s, box-shadow 0.15s;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}

.toast-undo-btn:hover {
    background: #ffe066;
    transform: scale(1.04);
}

.toast-undo-btn:active {
    transform: scale(0.96);
}

.chapter-nav {
    margin: 40px 0 20px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 1px solid var(--border-color);
    padding-top: 20px;
}

.keyboard-hint {
    display: block;
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: -10px;
    margin-bottom: 30px;
}

.nav-btn {
    display: inline-block;
    padding: 10px 20px;
    background: var(--link-color);
    color: #fff;
    text-decoration: none;
    border-radius: 6px;
    font-weight: 500;
    transition: all 0.2s;
}

.nav-btn:hover {
    opacity: 0.88;
}

.nav-btn.secondary {
    background: #6c757d;
}

.nav-btn.secondary:hover {
    background: #5a6268;
}

.nav-btn.disabled {
    background: var(--btn-disabled-bg);
    color: var(--btn-disabled-color);
    pointer-events: none;
    cursor: not-allowed;
    border: 1px solid var(--border-color);
}

.book-card .nav-btn {
    text-align: center;
    margin: 0;
}

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

.back-link:hover {
    text-decoration: underline;
}

#reading-progress-bar {
    position: fixed;
    top: 0;
    left: 0;
    height: 3.5px;
    background: var(--link-color);
    z-index: 10001;
    width: 0%;
    transition: width 0.1s ease;
    pointer-events: none;
}

.resume-reading-card {
    background: linear-gradient(135deg, rgba(0, 102, 204, 0.08) 0%, rgba(0, 102, 204, 0.02) 100%);
    border: 1px solid var(--border-color);
    border-left: 4px solid var(--link-color);
    border-radius: 12px;
    padding: 18px 22px;
    margin-bottom: 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 14px;
    box-shadow: 0 2px 10px var(--card-shadow);
}

.resume-content {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.resume-tag {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--link-color);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.resume-title {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-dark);
    margin: 0;
}

.resume-progress-info {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.resume-progress-bar {
    width: 140px;
    height: 6px;
    background: var(--border-color);
    border-radius: 4px;
    overflow: hidden;
}

.resume-progress-fill {
    height: 100%;
    background: var(--link-color);
    border-radius: 4px;
}

.resume-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.selection-tooltip {
    position: fixed;
    display: none;
    background: var(--app-bg);
    border: 1px solid var(--border-color);
    box-shadow: 0 8px 25px var(--card-shadow);
    border-radius: 24px;
    padding: 5px 8px;
    gap: 4px;
    z-index: 10008;
    transform: translate(-50%, -100%);
    transition: opacity 0.15s ease;
}

.selection-tooltip button {
    background: transparent;
    border: none;
    color: var(--text-color);
    padding: 6px 12px;
    border-radius: 16px;
    cursor: pointer;
    font-size: 0.86rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: all 0.15s;
}

.selection-tooltip button:hover {
    background: var(--link-hover-bg);
    color: var(--link-color);
}

.directory-tabs {
    display: flex;
    gap: 12px;
    border-bottom: 2px solid var(--border-color);
    margin-bottom: 20px;
}

.dir-tab-btn {
    background: none;
    border: none;
    padding: 10px 18px;
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    transition: all 0.2s;
}

.dir-tab-btn:hover {
    color: var(--link-color);
}

.dir-tab-btn.active {
    color: var(--link-color);
    border-bottom-color: var(--link-color);
}

.bookmark-list {
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin-top: 15px;
}

.bookmark-card {
    background: var(--app-bg);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 16px 18px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.bookmark-card:hover {
    border-color: var(--link-color);
    box-shadow: 0 4px 12px var(--card-shadow);
}

.bookmark-text {
    font-size: 1rem;
    line-height: 1.7;
    color: var(--text-dark);
    border-left: 3px solid var(--link-color);
    padding-left: 12px;
    margin: 0;
    font-style: italic;
}

.bookmark-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 4px;
}

.bookmark-del-btn {
    background: none;
    border: none;
    color: #d9534f;
    cursor: pointer;
    font-size: 0.85rem;
    padding: 2px 8px;
    border-radius: 4px;
}

.bookmark-del-btn:hover {
    background: rgba(217, 83, 79, 0.1);
}

@media (max-width: 680px) {
    body {
        padding-left: 10px;
        padding-right: 10px;
    }

    #app {
        padding: 20px 14px;
        border-radius: 10px;
    }

    .top-bar {
        gap: 8px;
    }

    .search-box input {
        width: 140px;
    }

    .search-box input:focus {
        width: 160px;
    }

    .mobile-more-btn {
        display: inline-flex;
    }

    .top-actions .top-btn.desktop-only {
        display: none !important;
    }

    .bookshelf.list-view .book-card {
        flex-direction: column;
    }

    .bookshelf.list-view .book-cover-wrapper {
        width: 100%;
        margin-right: 0;
        margin-bottom: 12px;
    }

    .chapter-nav .nav-btn {
        padding: 8px 14px;
        font-size: 0.9rem;
    }

    .hud-actions-row {
        gap: 6px;
    }

    .hud-nav-btn {
        padding: 6px 12px;
        font-size: 0.82rem;
    }


}

/* 快取全本進度區：加粗、放大百分比、強化對比與動態斜條紋 */
.batch-progress-wrap {
    margin: 20px 0 12px 0;
}

.batch-progress-track {
    width: 100%;
    height: 22px;
    padding: 3px;
    background: var(--border-color);
    border: 1px solid var(--hud-border);
    border-radius: 14px;
    overflow: hidden;
    box-shadow:
        inset 0 1px 3px rgba(0, 0, 0, 0.18),
        0 2px 8px var(--card-shadow);
}

.batch-progress-bar {
    height: 100%;
    min-width: 0;
    background-color: var(--link-color);
    background-image:
        linear-gradient(45deg,
            rgba(255, 255, 255, 0.30) 25%,
            transparent 25%,
            transparent 50%,
            rgba(255, 255, 255, 0.30) 50%,
            rgba(255, 255, 255, 0.30) 75%,
            transparent 75%,
            transparent),
        linear-gradient(90deg, var(--link-color), #10b981);
    background-size: 32px 32px, 100% 100%;
    border-radius: 10px;
    transition: width 0.35s ease;
    box-shadow: 0 0 10px rgba(16, 185, 129, 0.35);
    animation: batch-stripes 1.2s linear infinite;
}

.batch-progress-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-top: 9px;
}

.batch-progress-count {
    font-size: 0.92rem;
    font-weight: 700;
    color: var(--text-color);
}

.batch-progress-percent {
    font-size: 1.35rem;
    line-height: 1;
    font-weight: 800;
    color: var(--link-color);
    font-variant-numeric: tabular-nums;
}

.batch-progress-percent.complete {
    color: #10b981;
}

@keyframes batch-stripes {
    0% {
        background-position: 0 0, 0 0;
    }

    100% {
        background-position: 32px 0, 0 0;
    }
}

.top-btn.chapter-voice-btn.active,
.hud-icon-btn.active {
    border-color: var(--link-color) !important;
    color: var(--link-color) !important;
    background: var(--link-hover-bg) !important;
    box-shadow: 0 0 8px rgba(0, 102, 204, 0.4);
}

/* 首頁最底部版本號樣式 */
.home-version-footer {
    text-align: center;
    margin-top: 36px;
    padding-top: 16px;
    border-top: 1px dashed var(--border-color);
    font-size: 0.78rem;
    color: var(--text-muted);
    letter-spacing: 0.5px;
    user-select: none;
}