/* ========================
   KINDLE-LIKE READER UI
   ======================== */

/* Reader window theme variables */
.book-window {
    --reader-bg: #ffffff;
    --reader-text: #1a1a1a;
    --reader-muted: #666666;
    --reader-border: #e0e0e0;
    --reader-accent: #8b6914;
    --reader-toolbar-bg: #f8f8f8;
    --reader-pane-original-bg: #fdfbf7;
    --reader-pane-modern-bg: #fafafa;
    --toc-item-bg: #ffffff;
    --toc-item-hover: #f5f5f5;
    --toc-number-bg: #1a1a1a;
}

.book-window.theme-sepia {
    --reader-bg: #f4ecd8;
    --reader-text: #5b4636;
    --reader-muted: #8a7a6a;
    --reader-border: #d4c5a0;
    --reader-accent: #8b6914;
    --reader-toolbar-bg: #ebe3d0;
    --reader-pane-original-bg: #f0e8d0;
    --reader-pane-modern-bg: #f7f1e3;
    --toc-item-bg: #faf5e8;
    --toc-item-hover: #f0e8d0;
    --toc-number-bg: #5b4636;
}

.book-window.theme-dark {
    --reader-bg: #1a1a1a;
    --reader-text: #d1d1d1;
    --reader-muted: #999999;
    --reader-border: #444444;
    --reader-accent: #c9a84c;
    --reader-toolbar-bg: #2a2a2a;
    --reader-pane-original-bg: #222222;
    --reader-pane-modern-bg: #252525;
    --toc-item-bg: #252525;
    --toc-item-hover: #333333;
    --toc-number-bg: #d1d1d1;
}

.book-window.theme-eye-care {
    --reader-bg: #c7edcc;
    --reader-text: #2a3a2a;
    --reader-muted: #5a7a5a;
    --reader-border: #a5d5ab;
    --reader-accent: #2e7d32;
    --reader-toolbar-bg: #b8e2be;
    --reader-pane-original-bg: #bceac1;
    --reader-pane-modern-bg: #d4f5d7;
    --toc-item-bg: #daf0dc;
    --toc-item-hover: #c5e8c9;
    --toc-number-bg: #2e7d32;
}

.book-window.theme-warm {
    --reader-bg: #fff8e7;
    --reader-text: #4a3a2a;
    --reader-muted: #8a7a6a;
    --reader-border: #f0dcb0;
    --reader-accent: #c7790f;
    --reader-toolbar-bg: #fdf0d5;
    --reader-pane-original-bg: #fff3d6;
    --reader-pane-modern-bg: #fffbf0;
    --toc-item-bg: #fffdf5;
    --toc-item-hover: #fdf3d0;
    --toc-number-bg: #c7790f;
}

.book-window.theme-dark-blue {
    --reader-bg: #1a1f2e;
    --reader-text: #c5cde6;
    --reader-muted: #7a85a0;
    --reader-border: #3a4560;
    --reader-accent: #7aa2f7;
    --reader-toolbar-bg: #232a3d;
    --reader-pane-original-bg: #1f2638;
    --reader-pane-modern-bg: #222a3c;
    --toc-item-bg: #252d40;
    --toc-item-hover: #2f3850;
    --toc-number-bg: #7aa2f7;
}

.book-window.theme-gray {
    --reader-bg: #f2f2f2;
    --reader-text: #2a2a2a;
    --reader-muted: #777777;
    --reader-border: #d0d0d0;
    --reader-accent: #5a5a5a;
    --reader-toolbar-bg: #e8e8e8;
    --reader-pane-original-bg: #f5f5f5;
    --reader-pane-modern-bg: #fafafa;
    --toc-item-bg: #ffffff;
    --toc-item-hover: #eaeaea;
    --toc-number-bg: #5a5a5a;
}

/* ========================
   CONTAINER
   ======================== */
.book-container {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--reader-bg);
    color: var(--reader-text);
    transition: background 0.3s, color 0.3s;
}

/* ========================
   TOP TOOLBAR
   ======================== */
.book-header {
    flex-shrink: 0;
    padding: 0;
    background: var(--reader-toolbar-bg);
    border-bottom: 1px solid var(--reader-border);
    transition: background 0.3s, border-color 0.3s;
    position: relative;
}

.reader-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    min-height: 44px;
}

.reader-topbar .book-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--reader-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    text-align: center;
    padding: 0 12px;
    font-family: "Noto Serif SC", "SimSun", serif;
}

.reader-topbar .reader-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: var(--reader-muted);
    transition: all 0.2s;
    flex-shrink: 0;
}

.reader-topbar .reader-btn:hover {
    background: rgba(128,128,128,0.15);
    color: var(--reader-text);
}

.reader-toolbar-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 16px 10px;
    flex-wrap: wrap;
    justify-content: center;
}

.reader-toolbar-row select {
    padding: 5px 10px;
    border: 1px solid var(--reader-border);
    border-radius: 6px;
    background: var(--reader-bg);
    color: var(--reader-text);
    font-family: inherit;
    font-size: 13px;
    cursor: pointer;
    min-width: 140px;
    max-width: 220px;
}

.view-toggle {
    display: flex;
    gap: 0;
    border: 1px solid var(--reader-border);
    border-radius: 6px;
    overflow: hidden;
}

.view-toggle button {
    padding: 5px 12px;
    border: none;
    border-right: 1px solid var(--reader-border);
    background: var(--reader-bg);
    color: var(--reader-muted);
    font-family: inherit;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.view-toggle button:last-child {
    border-right: none;
}

.view-toggle button:hover {
    background: rgba(128,128,128,0.1);
}

.view-toggle button.active {
    background: var(--reader-accent);
    color: #ffffff;
}

.toolbar-btn {
    padding: 5px 14px;
    border: 1px solid var(--reader-border);
    border-radius: 6px;
    background: var(--reader-bg);
    color: var(--reader-text);
    font-family: inherit;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.toolbar-btn:hover {
    background: rgba(128,128,128,0.1);
}

.toolbar-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ========================
   SEARCH PANEL
   ======================== */
.search-panel {
    position: absolute;
    top: 50px;
    right: 16px;
    width: 360px;
    max-height: 70vh;
    background: var(--reader-bg);
    border: 1px solid var(--reader-border);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.15);
    padding: 16px;
    z-index: 1000;
    display: none;
    flex-direction: column;
    overflow: hidden;
}

.search-panel.open {
    display: flex;
}

.search-header {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.search-input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--reader-border);
    border-radius: 8px;
    background: var(--reader-bg);
    color: var(--reader-text);
    font-size: 14px;
    outline: none;
}

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

.search-close {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: var(--reader-muted);
    font-size: 16px;
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.search-close:hover {
    background: rgba(128,128,128,0.1);
}

.search-status {
    font-size: 12px;
    color: var(--reader-muted);
    margin-bottom: 8px;
    min-height: 18px;
}

.search-results {
    overflow-y: auto;
    flex: 1;
}

.search-result-item {
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    margin-bottom: 6px;
    border: 1px solid transparent;
    transition: all 0.2s;
}

.search-result-item:hover {
    background: var(--toc-item-hover);
    border-color: var(--reader-border);
}

.search-result-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--reader-accent);
    margin-bottom: 4px;
}

.search-result-snippet {
    font-size: 13px;
    color: var(--reader-text);
    line-height: 1.5;
    opacity: 0.85;
}

.search-empty {
    text-align: center;
    padding: 30px 0;
    color: var(--reader-muted);
    font-size: 14px;
}

/* ========================
   SETTINGS PANEL
   ======================== */
.settings-panel {
    position: absolute;
    top: 50px;
    right: 16px;
    width: 280px;
    background: var(--reader-bg);
    border: 1px solid var(--reader-border);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.15);
    padding: 20px;
    z-index: 1000;
    display: none;
}

.settings-panel.open {
    display: block;
}

.settings-panel h3 {
    margin: 0 0 16px;
    font-size: 15px;
    color: var(--reader-text);
    font-weight: 600;
    text-align: center;
}

.settings-section {
    margin-bottom: 18px;
}

.settings-section:last-child {
    margin-bottom: 0;
}

.settings-label {
    font-size: 12px;
    color: var(--reader-muted);
    margin-bottom: 8px;
    display: block;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

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

.font-size-control button {
    width: 36px;
    height: 36px;
    border: 1px solid var(--reader-border);
    border-radius: 50%;
    background: var(--reader-bg);
    color: var(--reader-text);
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.font-size-control button:hover {
    background: var(--reader-accent);
    color: #fff;
    border-color: var(--reader-accent);
}

.font-size-control .size-value {
    font-size: 14px;
    color: var(--reader-text);
    min-width: 40px;
    text-align: center;
    font-weight: 600;
}

.theme-options {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.theme-option {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    position: relative;
    transition: all 0.2s;
}

.theme-option:hover {
    transform: scale(1.1);
}

.theme-option.active {
    border-color: var(--reader-accent);
    box-shadow: 0 0 0 3px rgba(139,105,20,0.2);
}

.theme-option.theme-white {
    background: #ffffff;
    border: 1px solid #ddd;
}

.theme-option.theme-sepia {
    background: #f4ecd8;
    border: 1px solid #d4c5a0;
}

.theme-option.theme-dark {
    background: #1a1a1a;
    border: 1px solid #444;
}

.theme-option.theme-eye-care {
    background: #c7edcc;
    border: 1px solid #a5d5ab;
}

.theme-option.theme-warm {
    background: #fff8e7;
    border: 1px solid #f0dcb0;
}

.theme-option.theme-dark-blue {
    background: #1a1f2e;
    border: 1px solid #3a4560;
}

.theme-option.theme-gray {
    background: #f2f2f2;
    border: 1px solid #d0d0d0;
}

.line-height-options {
    display: flex;
    gap: 6px;
}

.line-height-options button {
    flex: 1;
    padding: 6px 0;
    border: 1px solid var(--reader-border);
    border-radius: 6px;
    background: var(--reader-bg);
    color: var(--reader-muted);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.line-height-options button:hover {
    background: rgba(128,128,128,0.1);
}

.line-height-options button.active {
    background: var(--reader-accent);
    color: #fff;
    border-color: var(--reader-accent);
}

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

.font-family-options button {
    padding: 6px 0;
    border: 1px solid var(--reader-border);
    border-radius: 6px;
    background: var(--reader-bg);
    color: var(--reader-muted);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.font-family-options button[data-ff="serif"] { font-family: "Noto Serif SC", "SimSun", serif; }
.font-family-options button[data-ff="sans"] { font-family: "Microsoft YaHei", "PingFang SC", sans-serif; }
.font-family-options button[data-ff="kai"] { font-family: "KaiTi", "STKaiti", serif; }
.font-family-options button[data-ff="fangsong"] { font-family: "FangSong", "STFangsong", serif; }
.font-family-options button[data-ff="lisu"] { font-family: "LiSu", "STLiti", cursive; }

.font-family-options button:hover {
    background: rgba(128,128,128,0.1);
}

.font-family-options button.active {
    background: var(--reader-accent);
    color: #fff;
    border-color: var(--reader-accent);
}

/* ========================
   BOOK BODY / READING AREA
   ======================== */
.book-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
    background: var(--reader-bg);
    color: var(--reader-text);
    transition: background 0.3s, color 0.3s;
    position: relative;
}

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

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

.book-body::-webkit-scrollbar-thumb {
    background: rgba(128,128,128,0.3);
    border-radius: 3px;
}

.chapter-title {
    font-size: 22px;
    color: var(--reader-text);
    text-align: center;
    margin-bottom: 24px;
    font-weight: bold;
    font-family: "Noto Serif SC", "SimSun", serif;
    line-height: 1.4;
}

/* Dual-pane side-by-side view */
.dual-pane {
    display: flex;
    gap: 16px;
    min-height: 300px;
    flex: 1;
}

.pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--reader-border);
    border-radius: 8px;
    overflow: hidden;
    background: var(--reader-bg);
    transition: background 0.3s, border-color 0.3s;
}

.pane-original {
    background: var(--reader-pane-original-bg);
}

.pane-modern {
    background: var(--reader-pane-modern-bg);
}

.pane-label {
    padding: 6px 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    background: rgba(128,128,128,0.08);
    border-bottom: 1px solid var(--reader-border);
    flex-shrink: 0;
    text-align: center;
    color: var(--reader-muted);
}

.pane-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
}

.pane-content::-webkit-scrollbar {
    width: 5px;
}

.pane-content::-webkit-scrollbar-track {
    background: transparent;
}

.pane-content::-webkit-scrollbar-thumb {
    background: rgba(128,128,128,0.25);
    border-radius: 3px;
}

.text-paragraph {
    margin-bottom: 14px;
    text-indent: 2em;
    color: var(--reader-text);
}

.pane-original .pane-content {
    font-family: "Noto Serif SC", "SimSun", "STSong", serif;
}

.pane-modern .pane-content {
    font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
}

/* Single-pane views */
.single-pane {
    max-width: 760px;
    margin: 0 auto;
    font-family: "Noto Serif SC", "SimSun", "STSong", serif;
}

.single-pane.modern-only {
    font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
}

.single-pane .text-paragraph {
    margin-bottom: 14px;
    text-indent: 2em;
}

/* ========================
   TOC / SUMMARY VIEW
   ======================== */
.view-toc {
    padding: 16px 24px;
}

.toc-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 10px;
    max-width: 1200px;
    margin: 0 auto;
}

.toc-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    background: var(--toc-item-bg);
    border: 1px solid var(--reader-border);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.toc-item:hover {
    background: var(--toc-item-hover);
    border-color: var(--reader-accent);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

.toc-number {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: var(--toc-number-bg);
    color: var(--reader-bg);
    border-radius: 50%;
    font-size: 12px;
    font-weight: bold;
    flex-shrink: 0;
}

.toc-title {
    font-size: 14px;
    color: var(--reader-text);
    font-family: "Noto Serif SC", "SimSun", serif;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ========================
   BOTTOM PROGRESS BAR
   ======================== */
.book-footer {
    flex-shrink: 0;
    background: var(--reader-toolbar-bg);
    border-top: 1px solid var(--reader-border);
    transition: background 0.3s, border-color 0.3s;
}

.reader-bottombar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 16px;
    font-size: 12px;
    color: var(--reader-muted);
}

.reader-progress-bar {
    width: 100%;
    height: 3px;
    background: var(--reader-border);
    cursor: pointer;
    position: relative;
}

.reader-progress-fill {
    height: 100%;
    background: var(--reader-accent);
    transition: width 0.3s;
}

/* ========================
   LOADING & EMPTY STATES
   ======================== */
.loading-state,
.empty-state {
    text-align: center;
    padding: 80px 20px;
    color: var(--reader-muted);
}

.loading-state .icon,
.empty-state .icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}

/* Search highlight */
.search-highlight {
    background: #fde047;
    color: #1a1a1a;
    padding: 0 2px;
    border-radius: 2px;
}

/* ========================
   PANELS (stats, notes, help)
   ======================== */
.stats-panel,
.notes-panel,
.help-panel {
    position: absolute;
    top: 50px;
    right: 16px;
    width: 320px;
    max-height: 70vh;
    background: var(--reader-bg);
    border: 1px solid var(--reader-border);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.15);
    padding: 16px;
    z-index: 1000;
    display: none;
    flex-direction: column;
    overflow: hidden;
}

.stats-panel.open,
.notes-panel.open,
.help-panel.open {
    display: flex;
}

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

.panel-header h3 {
    margin: 0;
    font-size: 15px;
    color: var(--reader-text);
}

.panel-close {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: var(--reader-muted);
    font-size: 16px;
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.panel-close:hover {
    background: rgba(128,128,128,0.1);
}

/* Stats panel */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 16px;
}

.stat-card {
    background: rgba(128,128,128,0.06);
    border: 1px solid var(--reader-border);
    border-radius: 8px;
    padding: 10px;
    text-align: center;
}

.stat-value {
    font-size: 16px;
    font-weight: bold;
    color: var(--reader-accent);
    margin-bottom: 4px;
    word-break: break-all;
}

.stat-label {
    font-size: 11px;
    color: var(--reader-muted);
}

.stats-calendar {
    border-top: 1px solid var(--reader-border);
    padding-top: 12px;
}

.stats-label {
    font-size: 12px;
    color: var(--reader-muted);
    margin-bottom: 10px;
}

.calendar-bars {
    display: flex;
    align-items: flex-end;
    justify-content: space-around;
    gap: 6px;
    height: 80px;
}

.cal-day {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
}

.cal-bar {
    width: 20px;
    background: var(--reader-accent);
    border-radius: 3px 3px 0 0;
    opacity: 0.7;
    min-height: 4px;
}

.cal-label {
    font-size: 11px;
    color: var(--reader-muted);
    margin-top: 4px;
}

.cal-label.today {
    color: var(--reader-accent);
    font-weight: bold;
}

/* Notes panel */
.notes-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}

.notes-content textarea {
    flex: 1;
    width: 100%;
    min-height: 120px;
    padding: 10px;
    border: 1px solid var(--reader-border);
    border-radius: 8px;
    background: var(--reader-bg);
    color: var(--reader-text);
    font-family: inherit;
    font-size: 14px;
    line-height: 1.6;
    resize: none;
    outline: none;
}

.notes-content textarea:focus {
    border-color: var(--reader-accent);
}

.notes-content textarea:disabled {
    opacity: 0.5;
}

.notes-hint {
    font-size: 11px;
    color: var(--reader-muted);
    margin-top: 6px;
    text-align: right;
}

/* Help panel */
.help-content {
    overflow-y: auto;
}

.help-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 1px solid var(--reader-border);
    font-size: 13px;
    color: var(--reader-text);
}

.help-row:last-child {
    border-bottom: none;
}

.help-key {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 56px;
    padding: 3px 8px;
    background: rgba(128,128,128,0.1);
    border: 1px solid var(--reader-border);
    border-radius: 4px;
    font-size: 12px;
    font-family: monospace;
    color: var(--reader-accent);
    font-weight: 600;
}

/* TOC Sidebar */
.toc-sidebar {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 260px;
    background: var(--reader-bg);
    border-right: 1px solid var(--reader-border);
    z-index: 1001;
    display: none;
    flex-direction: column;
    overflow: hidden;
}

.toc-sidebar.open {
    display: flex;
}

.toc-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    border-bottom: 1px solid var(--reader-border);
    font-size: 14px;
    font-weight: 600;
    color: var(--reader-text);
}

.toc-sidebar-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.toc-sidebar-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s;
    font-size: 13px;
    color: var(--reader-text);
}

.toc-sidebar-item:hover {
    background: var(--toc-item-hover);
}

.toc-sidebar-item.active {
    background: rgba(128,128,128,0.12);
    font-weight: 600;
}

.toc-sidebar-num {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    background: var(--toc-number-bg);
    color: var(--reader-bg);
    border-radius: 50%;
    font-size: 11px;
    font-weight: bold;
    flex-shrink: 0;
}

.toc-sidebar-title {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.toc-note-dot {
    width: 6px;
    height: 6px;
    background: #e74c3c;
    border-radius: 50%;
    flex-shrink: 0;
}

/* Quick jump modal */
.quick-jump-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.4);
    z-index: 10000;
    display: none;
    align-items: center;
    justify-content: center;
}

.quick-jump-modal.open {
    display: flex;
}

.quick-jump-box {
    background: var(--reader-bg);
    border: 1px solid var(--reader-border);
    border-radius: 12px;
    padding: 24px;
    width: 280px;
    text-align: center;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}

.quick-jump-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--reader-text);
    margin-bottom: 14px;
}

.quick-jump-box input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--reader-border);
    border-radius: 8px;
    background: var(--reader-bg);
    color: var(--reader-text);
    font-size: 16px;
    text-align: center;
    outline: none;
    margin-bottom: 8px;
}

.quick-jump-box input:focus {
    border-color: var(--reader-accent);
}

.quick-jump-hint {
    font-size: 12px;
    color: var(--reader-muted);
}

/* Loading skeleton */
.loading-skeleton {
    padding: 20px 24px;
    max-width: 760px;
    margin: 0 auto;
}

.skeleton-line {
    height: 16px;
    background: linear-gradient(90deg, var(--reader-border) 25%, rgba(128,128,128,0.15) 50%, var(--reader-border) 75%);
    background-size: 200% 100%;
    animation: skeletonShimmer 1.5s infinite;
    border-radius: 4px;
    margin-bottom: 14px;
    width: 100%;
}

.skeleton-title {
    height: 28px;
    width: 60%;
    margin: 0 auto 24px;
    border-radius: 6px;
}

@keyframes skeletonShimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Mobile nav bar */
.mobile-nav-bar {
    display: none;
    flex-shrink: 0;
    background: var(--reader-toolbar-bg);
    border-top: 1px solid var(--reader-border);
    padding: 6px 8px;
    gap: 6px;
    justify-content: space-around;
    align-items: center;
}

.mobile-nav-btn {
    flex: 1;
    padding: 8px 4px;
    border: 1px solid var(--reader-border);
    border-radius: 6px;
    background: var(--reader-bg);
    color: var(--reader-text);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.mobile-nav-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ========================
   CHARACTER POPUP
   ======================== */
.char-popup {
    position: fixed;
    /* Attached to <body>, outside .book-window — vars are copied over inline
       by showCharPopup(); fallbacks keep the card opaque regardless. */
    background: var(--reader-bg, #ffffff);
    border: 1px solid var(--reader-border, #e0e0e0);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
    padding: 16px;
    z-index: 100000;
    min-width: 120px;
    text-align: center;
    color: var(--reader-text, #1a1a1a);
}
.char-popup-char {
    font-size: 42px;
    font-family: "Noto Serif SC", "SimSun", serif;
    margin-bottom: 4px;
}
.char-popup-pinyin {
    font-size: 14px;
    color: var(--reader-accent, #8b6914);
    margin-bottom: 10px;
}
.char-popup-actions {
    display: flex;
    gap: 8px;
    justify-content: center;
}
.char-popup-btn {
    padding: 5px 12px;
    border: 1px solid var(--reader-border, #e0e0e0);
    border-radius: 6px;
    background: var(--reader-toolbar-bg, #f8f8f8);
    color: var(--reader-text, #1a1a1a);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}
.char-popup-btn:hover {
    background: var(--reader-accent, #8b6914);
    color: #fff;
    border-color: var(--reader-accent, #8b6914);
}

/* Placeholders for chapters/paragraphs with no vernacular translation */
.untranslated-note {
    margin: 24px 12px;
    padding: 14px 16px;
    border: 1px dashed var(--reader-border, #e0e0e0);
    border-radius: 8px;
    color: var(--reader-muted, #666);
    font-size: 14px;
    text-align: center;
}
.text-untranslated {
    color: var(--reader-muted, #666);
    font-style: italic;
}

/* Transient in-window notice (e.g. TTS voice availability) */
.reader-notice {
    position: absolute;
    left: 50%;
    bottom: 56px;
    transform: translateX(-50%);
    max-width: 80%;
    background: rgba(0, 0, 0, 0.78);
    color: #fff;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 13px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
    z-index: 10000;
}
.reader-notice.show {
    opacity: 1;
}

/* ========================
   BOOKMARK PANEL
   ======================== */
.bookmark-panel {
    position: absolute;
    top: 50px;
    right: 16px;
    width: 320px;
    max-height: 70vh;
    background: var(--reader-bg);
    border: 1px solid var(--reader-border);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.15);
    padding: 16px;
    z-index: 1000;
    display: none;
    flex-direction: column;
    overflow: hidden;
}
.bookmark-panel.open {
    display: flex;
}
.bookmark-current {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0 12px;
    border-bottom: 1px solid var(--reader-border);
    margin-bottom: 8px;
    font-size: 13px;
    color: var(--reader-text);
}
.bookmark-toggle-btn {
    padding: 5px 12px;
    border: 1px solid var(--reader-border);
    border-radius: 6px;
    background: var(--reader-toolbar-bg);
    color: var(--reader-text);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}
.bookmark-toggle-btn:hover {
    background: var(--reader-accent);
    color: #fff;
}
.bookmark-list {
    flex: 1;
    overflow-y: auto;
}
.bookmark-item {
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    margin-bottom: 6px;
    border: 1px solid transparent;
    transition: all 0.2s;
}
.bookmark-item:hover {
    background: var(--toc-item-hover);
    border-color: var(--reader-border);
}
.bookmark-item-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--reader-accent);
    margin-bottom: 3px;
}
.bookmark-item-excerpt {
    font-size: 12px;
    color: var(--reader-muted);
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.bookmark-empty {
    text-align: center;
    padding: 20px 0;
    color: var(--reader-muted);
    font-size: 13px;
}

/* ========================
   GOAL RING
   ======================== */
.stats-goal-section {
    border-top: 1px solid var(--reader-border);
    margin-top: 12px;
    padding-top: 8px;
}
.goal-setting {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 0;
    border-bottom: 1px solid var(--reader-border);
    margin-bottom: 8px;
    font-size: 13px;
    color: var(--reader-text);
}
.goal-setting input {
    width: 80px;
    padding: 4px 8px;
    border: 1px solid var(--reader-border);
    border-radius: 6px;
    background: var(--reader-bg);
    color: var(--reader-text);
    font-size: 13px;
    text-align: center;
}
.goal-setting button {
    padding: 4px 12px;
    border: 1px solid var(--reader-border);
    border-radius: 6px;
    background: var(--reader-toolbar-bg);
    color: var(--reader-text);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}
.goal-setting button:hover {
    background: var(--reader-accent);
    color: #fff;
}
.goal-ring-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 12px 0;
}
.goal-ring {
    width: 80px;
    height: 80px;
    transform: rotate(-90deg);
}
.goal-ring-bg {
    fill: none;
    stroke: var(--reader-border);
    stroke-width: 6;
}
.goal-ring-progress {
    fill: none;
    stroke: var(--reader-accent);
    stroke-width: 6;
    stroke-linecap: round;
    transition: stroke-dashoffset 0.5s ease;
}
.goal-ring-text {
    text-align: center;
}
.goal-ring-pct {
    font-size: 18px;
    font-weight: bold;
    color: var(--reader-accent);
}
.goal-ring-label {
    font-size: 11px;
    color: var(--reader-muted);
}

/* ========================
   FOCUS MODE
   ======================== */
.focus-mode .text-paragraph {
    opacity: 0.3;
    filter: blur(1px);
    transition: all 0.3s;
}
.focus-mode .text-paragraph:hover,
.focus-mode .text-paragraph.active-focus {
    opacity: 1;
    filter: none;
}

/* ========================
   VOCABULARY PANEL
   ======================== */
.vocab-panel {
    position: absolute;
    top: 50px;
    right: 16px;
    width: 320px;
    max-height: 70vh;
    background: var(--reader-bg);
    border: 1px solid var(--reader-border);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.15);
    padding: 16px;
    z-index: 1000;
    display: none;
    flex-direction: column;
    overflow: hidden;
}
.vocab-panel.open {
    display: flex;
}
.vocab-list {
    flex: 1;
    overflow-y: auto;
}
.vocab-item {
    padding: 10px 12px;
    border-radius: 8px;
    margin-bottom: 6px;
    border: 1px solid var(--reader-border);
    transition: all 0.2s;
}
.vocab-item:hover {
    background: var(--toc-item-hover);
}
.vocab-item-text {
    font-size: 14px;
    font-weight: 600;
    color: var(--reader-accent);
    margin-bottom: 4px;
}
.vocab-item-context {
    font-size: 12px;
    color: var(--reader-muted);
    line-height: 1.4;
    margin-bottom: 6px;
    word-break: break-all;
}
.vocab-item-del {
    padding: 3px 10px;
    border: 1px solid var(--reader-border);
    border-radius: 4px;
    background: var(--reader-toolbar-bg);
    color: var(--reader-text);
    font-size: 11px;
    cursor: pointer;
    transition: all 0.2s;
}
.vocab-item-del:hover {
    background: #e74c3c;
    color: #fff;
    border-color: #e74c3c;
}
.vocab-empty {
    text-align: center;
    padding: 20px 0;
    color: var(--reader-muted);
    font-size: 13px;
}
.vocab-float-btn {
    position: absolute;
    padding: 4px 10px;
    border: 1px solid var(--reader-accent);
    border-radius: 6px;
    background: var(--reader-accent);
    color: #fff;
    font-size: 12px;
    cursor: pointer;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    transition: all 0.2s;
}
.vocab-float-btn:hover {
    transform: scale(1.05);
}

/* ========================
   QUICK ACCESS BAR
   ======================== */
.quick-access-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 0 12px;
    flex-wrap: wrap;
    border-bottom: 1px solid var(--reader-border);
    margin-bottom: 8px;
}
.quick-access-label {
    font-size: 12px;
    color: var(--reader-muted);
    font-weight: 600;
}
.quick-access-chip {
    padding: 4px 10px;
    border: 1px solid var(--reader-border);
    border-radius: 16px;
    background: var(--reader-toolbar-bg);
    color: var(--reader-text);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
}
.quick-access-chip:hover {
    background: var(--reader-accent);
    color: #fff;
    border-color: var(--reader-accent);
}

/* ========================
   PINNED CHAPTERS IN TOC
   ======================== */
.toc-pinned-section {
    margin-bottom: 16px;
    padding: 0 4px;
}
.toc-pinned-label {
    font-size: 12px;
    color: var(--reader-muted);
    font-weight: 600;
    margin-bottom: 8px;
}
.toc-pinned-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
.toc-pinned-chip {
    padding: 5px 12px;
    border: 1px solid var(--reader-border);
    border-radius: 16px;
    background: var(--reader-toolbar-bg);
    color: var(--reader-text);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
}
.toc-pinned-chip:hover {
    background: var(--reader-accent);
    color: #fff;
    border-color: var(--reader-accent);
}
.toc-pin-btn {
    margin-left: auto;
    padding: 2px 6px;
    border: none;
    background: transparent;
    font-size: 13px;
    cursor: pointer;
    opacity: 0.4;
    transition: all 0.2s;
    flex-shrink: 0;
}
.toc-item:hover .toc-pin-btn {
    opacity: 0.7;
}
.toc-pin-btn.pinned {
    opacity: 1;
}
.toc-pin-btn:hover {
    opacity: 1;
    transform: scale(1.2);
}
.toc-sidebar-pin {
    padding: 2px 4px;
    border: none;
    background: transparent;
    font-size: 11px;
    cursor: pointer;
    opacity: 0.4;
    transition: all 0.2s;
    flex-shrink: 0;
}
.toc-sidebar-item:hover .toc-sidebar-pin {
    opacity: 0.7;
}
.toc-sidebar-pin.pinned {
    opacity: 1;
}
.toc-sidebar-pin:hover {
    opacity: 1;
    transform: scale(1.2);
}

/* ========================
   CITATION DROPDOWN
   ======================== */
.citation-dropdown {
    position: absolute;
    top: 50px;
    right: 16px;
    width: 320px;
    max-height: 70vh;
    background: var(--reader-bg);
    border: 1px solid var(--reader-border);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.15);
    padding: 16px;
    z-index: 1000;
    display: none;
    flex-direction: column;
    overflow: hidden;
}
.citation-dropdown.open {
    display: flex;
}
.citation-list {
    overflow-y: auto;
}
.citation-entry {
    margin-bottom: 12px;
    padding: 10px;
    border: 1px solid var(--reader-border);
    border-radius: 8px;
    background: rgba(128,128,128,0.04);
}
.citation-label {
    font-size: 11px;
    color: var(--reader-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}
.citation-text {
    font-size: 13px;
    color: var(--reader-text);
    line-height: 1.5;
    margin-bottom: 8px;
    word-break: break-all;
}
.citation-copy {
    padding: 4px 12px;
    border: 1px solid var(--reader-border);
    border-radius: 6px;
    background: var(--reader-toolbar-bg);
    color: var(--reader-text);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}
.citation-copy:hover {
    background: var(--reader-accent);
    color: #fff;
    border-color: var(--reader-accent);
}
.citation-empty {
    text-align: center;
    padding: 20px 0;
    color: var(--reader-muted);
    font-size: 13px;
}

/* ========================
   STATS SPEED SECTION
   ======================== */
.stats-speed-section {
    border-top: 1px solid var(--reader-border);
    padding-top: 12px;
    margin-top: 4px;
    text-align: center;
}
.stats-speed-section .stats-label {
    font-size: 12px;
    color: var(--reader-muted);
    margin-bottom: 4px;
}
.stats-speed-value {
    font-size: 18px;
    font-weight: bold;
    color: var(--reader-accent);
}

/* ========================
   CUSTOM CSS TEXTAREA
   ======================== */
.custom-css-textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--reader-border);
    border-radius: 8px;
    background: var(--reader-bg);
    color: var(--reader-text);
    font-family: monospace;
    font-size: 12px;
    line-height: 1.5;
    resize: vertical;
    outline: none;
}
.custom-css-textarea:focus {
    border-color: var(--reader-accent);
}

/* ========================
   SYNC BUTTONS
   ======================== */
.sync-buttons {
    display: flex;
    gap: 8px;
}
.sync-btn {
    flex: 1;
    padding: 6px 0;
    border: 1px solid var(--reader-border);
    border-radius: 6px;
    background: var(--reader-bg);
    color: var(--reader-text);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}
.sync-btn:hover {
    background: var(--reader-accent);
    color: #fff;
    border-color: var(--reader-accent);
}

/* ========================
   RESPONSIVE
   ======================== */
@media (max-width: 768px) {
    .dual-pane {
        flex-direction: column;
        height: auto;
    }
    .pane {
        max-height: 50vh;
    }
    .settings-panel,
    .stats-panel,
    .notes-panel,
    .help-panel,
    .bookmark-panel,
    .vocab-panel,
    .citation-dropdown {
        width: calc(100vw - 40px);
        right: 10px;
        left: 10px;
    }
    .mobile-nav-bar {
        display: flex;
    }
    .book-window {
        min-width: 320px;
        min-height: 300px;
    }
}

/* ========================
   ROUND 36-40 ADDITIONS
   ======================== */

/* Batch loading indicator */
.batch-loading-indicator {
    text-align: center;
    padding: 16px;
    color: var(--reader-muted);
    font-size: 13px;
}
.batch-loading-indicator::after {
    content: '...';
}

/* Diff mode */
.diff-view {
    max-width: 760px;
    margin: 0 auto;
}
.diff-pair {
    border-left: 3px solid var(--reader-accent);
    padding-left: 12px;
    margin-bottom: 20px;
}
.diff-pair.paragraph-pair-heading {
    border-left-width: 4px;
}
.diff-original {
    margin-bottom: 8px;
}
.diff-original .text-paragraph {
    font-family: "Noto Serif SC", "SimSun", "STSong", serif;
    margin-bottom: 8px;
    text-indent: 2em;
}
.diff-modern .text-paragraph {
    font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
    margin-bottom: 0;
    text-indent: 2em;
    color: var(--reader-muted);
}
.diff-label {
    font-size: 11px;
    color: var(--reader-accent);
    font-weight: 600;
    margin-bottom: 4px;
    letter-spacing: 0.5px;
}

/* Frequency panel */
.freq-panel {
    position: absolute;
    top: 50px;
    right: 16px;
    width: 320px;
    max-height: 70vh;
    background: var(--reader-bg);
    border: 1px solid var(--reader-border);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.15);
    padding: 16px;
    z-index: 1000;
    display: none;
    flex-direction: column;
    overflow: hidden;
}
.freq-panel.open {
    display: flex;
}
.freq-list {
    flex: 1;
    overflow-y: auto;
}
.freq-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
    font-size: 13px;
    border-bottom: 1px solid var(--reader-border);
}
.freq-item:last-child {
    border-bottom: none;
}
.freq-char {
    width: 28px;
    text-align: center;
    font-size: 16px;
    font-weight: 600;
    color: var(--reader-accent);
    flex-shrink: 0;
}
.freq-pinyin {
    width: 60px;
    color: var(--reader-muted);
    font-size: 12px;
    flex-shrink: 0;
}
.freq-bar-wrap {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
}
.freq-bar {
    height: 8px;
    background: var(--reader-accent);
    border-radius: 4px;
    min-width: 2px;
    opacity: 0.7;
}
.freq-count {
    width: 40px;
    text-align: right;
    color: var(--reader-muted);
    font-size: 12px;
    flex-shrink: 0;
}

/* Bookmark pulse */
@keyframes bookmarkPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.35); }
    100% { transform: scale(1); }
}
.bookmark-pulse {
    animation: bookmarkPulse 0.4s ease;
}

/* Smooth scroll */
.book-body {
    scroll-behavior: smooth;
}

/* TOC item hover lift */
.toc-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0,0,0,0.1);
}

/* ========================
   PHASE 2/3: SVG ICONS, SELECTION TOOLBAR, READ TICKS, TTS, MOBILE
   ======================== */

/* SVG toolbar icons (currentColor, sized here) */
.reader-btn svg,
.toolbar-btn svg,
.mobile-nav-btn svg {
    width: 18px;
    height: 18px;
    display: block;
    pointer-events: none;
}
.toolbar-btn svg {
    margin: 0 auto;
}
.toolbar-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 34px;
    min-height: 30px;
}

/* Text-selection mini-toolbar */
.selection-toolbar {
    position: absolute;
    display: flex;
    gap: 0;
    background: var(--reader-toolbar-bg, #ffffff);
    border: 1px solid var(--reader-border, #e0e0e0);
    border-radius: 8px;
    box-shadow: 0 6px 24px rgba(0,0,0,0.18);
    overflow: hidden;
    z-index: 1200;
}
.selection-toolbar button {
    padding: 8px 14px;
    border: none;
    border-right: 1px solid var(--reader-border, #e0e0e0);
    background: transparent;
    color: var(--reader-text, #1a1a1a);
    font-size: 13px;
    cursor: pointer;
    white-space: nowrap;
}
.selection-toolbar button:last-child {
    border-right: none;
}
.selection-toolbar button:hover {
    background: var(--reader-accent, #8b6914);
    color: #fff;
}

/* Per-chapter read ticks in TOC */
.toc-read-tick {
    color: var(--reader-accent, #8b6914);
    font-weight: 700;
    font-size: 13px;
    flex-shrink: 0;
    margin-left: 4px;
}
.toc-item.toc-read .toc-title {
    color: var(--reader-muted);
}

/* Touch affordances: 44px targets, scrollable topbar, sticky mobile nav */
@media (max-width: 768px) {
    .reader-topbar {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .reader-topbar::-webkit-scrollbar {
        display: none;
    }
    .reader-topbar .book-title {
        min-width: 90px;
    }
    .reader-topbar .reader-btn {
        width: 44px;
        height: 44px;
    }
    .toolbar-btn {
        min-width: 44px;
        min-height: 40px;
    }
    .view-toggle button {
        padding: 10px 12px;
    }
    .mobile-nav-btn {
        min-height: 44px;
        font-size: 14px;
    }
    .selection-toolbar button {
        padding: 12px 16px;
        font-size: 14px;
    }
    .search-panel,
    .freq-panel {
        width: calc(100vw - 20px);
        right: 10px;
        left: 10px;
        max-width: none;
    }
    .toc-sidebar {
        width: min(320px, 85vw);
    }
}

/* ========================
   SIDE-BY-SIDE: INDEPENDENT PANE SCROLLING
   ======================== */
/* Constrain the dual-pane block to the body viewport so each .pane-content
   becomes its own scroll container — required for the paragraph-anchored
   sync in setupSyncScroll() (and for per-chapter scroll save/restore, which
   already target .pane-original .pane-content in this view). */
@media (min-width: 769px) {
    .book-body.view-sidebyside {
        display: flex;
        flex-direction: column;
        overflow-y: hidden;
    }
    .book-body.view-sidebyside .dual-pane {
        min-height: 0;
    }
}
/* On phones the panes stack (see the 768px block above) and keep the old
   flowing layout: each pane is its own <=50vh scroller, body scrolls the rest. */

/* Semantic metadata is optional; chapter files without it keep legacy styling. */
.text-paragraph.paragraph-heading {
    margin-top: 24px;
    margin-bottom: 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--reader-border);
    color: var(--reader-accent);
    font-weight: 600;
    text-indent: 0;
}

.text-paragraph.paragraph-annotation {
    color: var(--reader-muted);
    font-size: 0.92em;
    text-indent: 0;
}

/* Elements toggled with the `hidden` attribute below carry explicit
   `display` rules, which beat the UA stylesheet's [hidden] { display:none }.
   Restore the attribute's meaning. */
[hidden] {
    display: none !important;
}

/* ============================================================
   ANNOTATIONS (notes · highlights · vocab · bookmarks)
   ============================================================ */

/* --- in-text marks --- */
mark.user-annotation {
    background: transparent;
    color: inherit;
    padding: 0;
    border-radius: 2px;
    cursor: pointer;
}
mark.user-highlight {
    background: #ffe58a;
    color: #1a1a1a;
    box-shadow: 0 0 0 1px rgba(0,0,0,0.04);
}
mark.user-note-anchor {
    border-bottom: 2px dotted var(--reader-accent);
}
mark.user-annotation:hover {
    filter: brightness(0.94);
}
/* The source text changed under an old annotation: flag the paragraph rather
   than losing the note. */
.text-paragraph.ann-orphan {
    border-left: 2px solid var(--reader-accent);
    padding-left: 8px;
}
.text-paragraph.ann-flash,
.ann-item.ann-flash {
    animation: annFlash 1.6s ease-out;
}
@keyframes annFlash {
    0%, 40% { background: rgba(139, 105, 20, 0.18); }
    100% { background: transparent; }
}

/* --- selection toolbar additions --- */
.selection-toolbar .sel-colors-btn {
    padding: 8px 6px;
    font-size: 11px;
}
.selection-toolbar .sel-swatches {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0 8px;
    border-left: 1px solid var(--reader-border, #e0e0e0);
}
.selection-toolbar .sel-swatch {
    width: 18px;
    height: 18px;
    padding: 0;
    border: 1px solid rgba(0,0,0,0.15);
    border-radius: 50%;
    cursor: pointer;
}
.selection-toolbar .sel-swatch:hover {
    transform: scale(1.15);
}

/* --- note composer --- */
.note-composer {
    position: absolute;
    z-index: 1300;
    width: 320px;
    max-width: calc(100% - 16px);
    max-height: calc(100% - 16px);
    overflow-y: auto;
    background: var(--reader-bg);
    border: 1px solid var(--reader-border);
    border-radius: 10px;
    box-shadow: 0 10px 34px rgba(0,0,0,0.22);
    padding: 12px;
}
.note-composer-quote {
    font-size: 12px;
    color: var(--reader-muted);
    border-left: 3px solid var(--reader-accent);
    padding: 2px 0 2px 8px;
    margin-bottom: 8px;
    max-height: 62px;
    overflow: hidden;
}
.note-composer-text {
    width: 100%;
    min-height: 74px;
    padding: 8px;
    border: 1px solid var(--reader-border);
    border-radius: 6px;
    background: var(--reader-bg);
    color: var(--reader-text);
    font-family: inherit;
    font-size: 13px;
    line-height: 1.6;
    resize: vertical;
    outline: none;
    box-sizing: border-box;
}
.note-composer-text:focus {
    border-color: var(--reader-accent);
}
.note-composer-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin: 8px 0;
}
.note-tag {
    padding: 3px 9px;
    border: 1px solid var(--reader-border);
    border-radius: 11px;
    background: transparent;
    color: var(--reader-muted);
    font-size: 11px;
    cursor: pointer;
}
.note-tag.active {
    background: var(--reader-accent);
    border-color: var(--reader-accent);
    color: #fff;
}
.note-composer-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}
.note-composer-hint {
    flex: 1;
    font-size: 10px;
    color: var(--reader-muted);
}
.note-composer-save,
.note-composer-cancel {
    padding: 5px 14px;
    border: 1px solid var(--reader-border);
    border-radius: 6px;
    background: var(--reader-bg);
    color: var(--reader-text);
    font-size: 12px;
    cursor: pointer;
}
.note-composer-save {
    background: var(--reader-accent);
    border-color: var(--reader-accent);
    color: #fff;
}

/* --- 我的批注 panel --- */
.annotations-panel {
    width: 380px;
}
.annotations-panel .panel-header h3 {
    display: flex;
    align-items: center;
    gap: 6px;
}
.annotations-panel .panel-header svg {
    width: 15px;
    height: 15px;
}
.ann-count {
    font-size: 11px;
    color: var(--reader-muted);
    font-weight: 400;
}
.ann-tabs {
    flex-shrink: 0;
    display: flex;
    gap: 2px;
    margin-bottom: 10px;
    border-bottom: 1px solid var(--reader-border);
    overflow-x: auto;
}
.ann-tab {
    flex: 1;
    min-width: 48px;
    padding: 6px 4px;
    border: none;
    border-bottom: 2px solid transparent;
    background: transparent;
    color: var(--reader-muted);
    font-size: 12px;
    cursor: pointer;
    white-space: nowrap;
}
.ann-tab.active {
    color: var(--reader-accent);
    border-bottom-color: var(--reader-accent);
    font-weight: 600;
}
.ann-chapter-note {
    flex-shrink: 0;
    margin-bottom: 10px;
}
.ann-section-label {
    font-size: 11px;
    color: var(--reader-muted);
    margin-bottom: 4px;
}
.ann-chapter-note textarea {
    width: 100%;
    min-height: 72px;
    padding: 8px;
    border: 1px solid var(--reader-border);
    border-radius: 6px;
    background: var(--reader-bg);
    color: var(--reader-text);
    font-family: inherit;
    font-size: 13px;
    line-height: 1.6;
    resize: vertical;
    outline: none;
    box-sizing: border-box;
}
.ann-chapter-note textarea:focus {
    border-color: var(--reader-accent);
}
.ann-chapter-note textarea:disabled {
    opacity: 0.5;
}
.ann-search {
    flex-shrink: 0;
    width: 100%;
    padding: 6px 8px;
    margin-bottom: 8px;
    border: 1px solid var(--reader-border);
    border-radius: 6px;
    background: var(--reader-bg);
    color: var(--reader-text);
    font-size: 12px;
    outline: none;
    box-sizing: border-box;
}
.ann-list {
    flex: 1 1 auto;
    min-height: 60px;
    overflow-y: auto;
}
.ann-empty {
    padding: 24px 8px;
    text-align: center;
    color: var(--reader-muted);
    font-size: 12px;
    line-height: 1.8;
}
.ann-item {
    padding: 8px;
    border-bottom: 1px solid var(--reader-border);
    border-radius: 4px;
}
.ann-item-head {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
}
.ann-badge {
    font-size: 10px;
    padding: 1px 6px;
    border-radius: 3px;
    background: var(--reader-toolbar-bg);
    color: var(--reader-muted);
    border: 1px solid var(--reader-border);
    flex-shrink: 0;
}
.ann-badge-note { color: var(--reader-accent); }
.ann-badge-highlight { color: #1a1a1a; }
.ann-item-chapter {
    font-size: 11px;
    color: var(--reader-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}
.ann-item-date {
    font-size: 10px;
    color: var(--reader-muted);
    flex-shrink: 0;
}
.ann-item-quote {
    font-size: 12px;
    color: var(--reader-muted);
    border-left: 3px solid var(--reader-accent);
    padding-left: 7px;
    margin: 3px 0;
    line-height: 1.6;
    max-height: 58px;
    overflow: hidden;
}
.ann-item-text {
    font-size: 13px;
    color: var(--reader-text);
    line-height: 1.6;
    white-space: pre-wrap;
    margin: 3px 0;
}
.ann-item-actions,
.ann-edit-actions {
    display: flex;
    gap: 6px;
    margin-top: 4px;
}
.ann-act {
    padding: 2px 9px;
    border: 1px solid var(--reader-border);
    border-radius: 4px;
    background: transparent;
    color: var(--reader-muted);
    font-size: 11px;
    cursor: pointer;
}
.ann-act:hover {
    background: var(--reader-accent);
    border-color: var(--reader-accent);
    color: #fff;
}
.ann-act-del:hover {
    background: #c0392b;
    border-color: #c0392b;
}
.ann-edit-box {
    margin-top: 6px;
}
.ann-edit-text {
    width: 100%;
    padding: 6px;
    border: 1px solid var(--reader-border);
    border-radius: 6px;
    background: var(--reader-bg);
    color: var(--reader-text);
    font-family: inherit;
    font-size: 12px;
    box-sizing: border-box;
    outline: none;
}
.ann-footer {
    flex-shrink: 0;
    display: flex;
    gap: 6px;
    padding-top: 8px;
    border-top: 1px solid var(--reader-border);
    margin-top: 6px;
}
.ann-footer-btn {
    flex: 1;
    padding: 6px 0;
    border: 1px solid var(--reader-border);
    border-radius: 6px;
    background: var(--reader-bg);
    color: var(--reader-text);
    font-size: 12px;
    cursor: pointer;
}
.ann-footer-btn:hover {
    background: var(--reader-accent);
    border-color: var(--reader-accent);
    color: #fff;
}

/* --- settings: storage + offline --- */
.settings-section-stack .sync-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.settings-section-stack .sync-btn {
    flex: 1 1 calc(50% - 6px);
}
.sync-btn-warn {
    border-color: #c0392b !important;
    color: #c0392b !important;
}
.sync-btn-warn:hover {
    background: #c0392b !important;
    color: #fff !important;
}
.storage-info,
.offline-progress {
    margin-top: 6px;
    font-size: 11px;
    color: var(--reader-muted);
    line-height: 1.6;
}
.storage-info-warn {
    color: #c0392b;
}
.empty-hint {
    font-size: 12px;
    color: var(--reader-muted);
    margin-top: 6px;
}

/* --- mobile --- */
@media (max-width: 768px) {
    .annotations-panel {
        width: calc(100vw - 40px);
    }
    .note-composer {
        width: calc(100vw - 60px);
    }
    .ann-act,
    .ann-tab {
        min-height: 32px;
    }
}

/* The 简/繁 toggle carries a character rather than an icon: it has to show
   which of the two is active, not merely offer an action. Fixed width keeps
   the toolbar from reflowing as the label changes. */
.toolbar-btn-text {
    min-width: 38px;
    font-weight: 600;
}
