/* ===================================================
   Shorthand — Beta Reader App Styles v2.1
   =================================================== */

@import url('https://fonts.googleapis.com/css2?family=Libre+Baskerville:ital,wght@0,400;0,700;1,400&family=Literata:opsz,wght@7..72,400;7..72,500&family=Source+Serif+4:opsz,wght@8..60,400;8..60,500&family=Merriweather:ital,wght@0,400;0,700;1,400&family=EB+Garamond:ital,wght@0,400;0,500;1,400&family=Lora:ital,wght@0,400;0,500;1,400&family=Crimson+Text:ital,wght@0,400;0,600;1,400&family=Inter:wght@400;500&family=Atkinson+Hyperlegible:ital,wght@0,400;0,700;1,400&display=swap');

@font-face {
    font-family: 'Linux Libertine';
    src: url('https://cdn.jsdelivr.net/gh/nicholaides/fonts-linux-libertine@master/webfonts/LinLibertine_R.woff') format('woff');
    font-weight: normal; font-style: normal;
}
@font-face {
    font-family: 'Linux Libertine';
    src: url('https://cdn.jsdelivr.net/gh/nicholaides/fonts-linux-libertine@master/webfonts/LinLibertine_RB.woff') format('woff');
    font-weight: bold; font-style: normal;
}
@font-face {
    font-family: 'Linux Libertine';
    src: url('https://cdn.jsdelivr.net/gh/nicholaides/fonts-linux-libertine@master/webfonts/LinLibertine_RI.woff') format('woff');
    font-weight: normal; font-style: italic;
}
@font-face {
    font-family: 'OpenDyslexic';
    src: url('https://cdn.jsdelivr.net/gh/antijingoist/opendyslexic@master/compiled/OpenDyslexic-Regular.woff') format('woff');
    font-weight: normal; font-style: normal;
}
@font-face {
    font-family: 'OpenDyslexic';
    src: url('https://cdn.jsdelivr.net/gh/antijingoist/opendyslexic@master/compiled/OpenDyslexic-Bold.woff') format('woff');
    font-weight: bold; font-style: normal;
}
@font-face {
    font-family: 'OpenDyslexic';
    src: url('https://cdn.jsdelivr.net/gh/antijingoist/opendyslexic@master/compiled/OpenDyslexic-Italic.woff') format('woff');
    font-weight: normal; font-style: italic;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --paper:        #f0ece4;
    --paper-warm:   #e8e3d9;
    --paper-dark:   #ddd8cc;
    --chrome:       #2c2a26;
    --chrome-mid:   #3d3a34;
    --chrome-light: #4f4b44;
    --chrome-hover: #5a564e;
    --ink:          #1a1816;
    --ink-mid:      #4a4640;
    --ink-dim:      #7a756d;
    --ink-ghost:    #b0aa9f;
    --tag-bg:       #d4c9a8;
    --tag-text:     #3d3520;
    --highlight-bg: #e6dfc4;
    --highlight-border: #d4b86e;
    --highlight-hover: #ddd4b0;
    --active:       #c4a24e;
    --active-dim:   #d4b86e;
    --rule:         #d5d0c6;
    --rule-light:   #e5e1d8;
    --palette-bg:   #1e1c19;
    --palette-item: #28261f;
    --palette-hover:#36332a;
    --palette-text: #e8e4dc;
    --palette-dim:  #8a8578;
    --content-font: 'Linux Libertine', Georgia, serif;
    --content-size: 18px;
    --content-line-height: 1.6;
    --content-margin: 36px;
    --content-width: 640px;
    --content-indent: 0px;
}

body.dark {
    --paper:        #2e2e2e;
    --paper-warm:   #353535;
    --paper-dark:   #272727;
    --chrome:       #1a1a1a;
    --chrome-mid:   #2a2a2a;
    --chrome-light: #404040;
    --chrome-hover: #4a4a4a;
    --ink:          #e8e8e8;
    --ink-mid:      #b5b5b5;
    --ink-dim:      #8a8a8a;
    --ink-ghost:    #6e6e6e;
    --tag-bg:       #3d3520;
    --tag-text:     #d4c9a8;
    --highlight-bg: #3a3425;
    --highlight-border: #a08030;
    --highlight-hover: #453d2a;
    --active:       #c4a24e;
    --active-dim:   #a08030;
    --rule:         #404040;
    --rule-light:   #353535;
    --palette-bg:   #141414;
    --palette-item: #1e1e1e;
    --palette-hover:#2a2a2a;
    --palette-text: #e8e8e8;
    --palette-dim:  #6a6a6a;
}

html, body {
    height: 100%;
    overflow: hidden;
    font-family: -apple-system, 'Segoe UI', system-ui, sans-serif;
    font-size: 13px;
    color: var(--ink);
    background: var(--chrome);
    -webkit-font-smoothing: antialiased;
}

::selection { background: #b8cfe0; }
body.dark ::selection { background: #3a5570; }

/* ── Title Bar ── */

.titlebar {
    height: 38px;
    background: var(--chrome);
    color: var(--paper-dark);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    user-select: none;
    -webkit-app-region: drag;
    border-bottom: 1px solid rgba(0,0,0,0.3);
}
.titlebar-left { display: flex; align-items: center; gap: 6px; }
.titlebar-brand {
    font-family: 'Horizon', 'Arial Black', 'Arial', sans-serif;
    font-weight: 900; font-size: 16px; letter-spacing: -0.02em;
    text-transform: lowercase; color: #e6dfc4; flex-shrink: 0;
}
.titlebar-right { display: flex; gap: 4px; -webkit-app-region: no-drag; flex-shrink: 0; }
.titlebar-btn {
    background: var(--chrome-mid); border: 1px solid var(--chrome-light);
    color: var(--paper-dark); padding: 3px 10px; font-size: 11px;
    cursor: pointer; transition: background 0.1s; font-family: inherit;
}
.titlebar-btn:hover { background: var(--chrome-hover); }
body.dark .titlebar-btn { color: var(--ink-mid); }
body.dark .titlebar-brand { color: #ffffff; }
body.dark .sidebar-tab.active { color: var(--ink); border-bottom-color: #ffffff; }
body.dark .sidebar-count { background: #ffffff; color: #1a1a1a; }

/* ── Document Tabs ── */

.doc-tabs {
    height: 30px;
    background: var(--chrome);
    display: flex;
    align-items: stretch;
    padding: 0 4px;
    gap: 2px;
    border-bottom: 1px solid rgba(0,0,0,0.25);
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-app-region: no-drag;
}

.doc-tabs::-webkit-scrollbar { height: 0; }

.doc-tab {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 10px;
    background: var(--chrome-mid);
    border: none;
    color: var(--ink-ghost);
    font-size: 11px;
    font-family: inherit;
    cursor: pointer;
    white-space: nowrap;
    max-width: 180px;
    transition: all 0.1s;
    position: relative;
}

.doc-tab:hover { background: var(--chrome-hover); color: var(--paper-dark); }

.doc-tab.active {
    background: var(--paper-dark);
    color: var(--ink);
    border-bottom: 2px solid var(--active);
}

body.dark .doc-tab.active { background: var(--chrome-hover); color: var(--ink); }

.doc-tab-name {
    overflow: hidden;
    text-overflow: ellipsis;
}

.doc-tab-close {
    font-size: 14px;
    line-height: 1;
    opacity: 0.4;
    transition: opacity 0.1s;
    flex-shrink: 0;
}

.doc-tab-close:hover { opacity: 1; }

/* ── Layout ── */

.container { display: flex; height: calc(100% - 38px); }
.container.has-tabs { height: calc(100% - 68px); }

/* ── Sidebar ── */

.sidebar {
    width: 270px; background: var(--paper-warm);
    border-right: 1px solid var(--rule);
    display: flex; flex-direction: column; flex-shrink: 0;
}
.sidebar-tabs {
    display: flex; border-bottom: 1px solid var(--rule); background: var(--paper-dark);
}
.sidebar-tab {
    flex: 1; padding: 9px 8px; border: none; background: none; cursor: pointer;
    font-size: 11px; font-weight: 600; font-family: inherit;
    text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-ghost);
    border-bottom: 2px solid transparent; transition: all 0.15s;
    display: flex; align-items: center; justify-content: center; gap: 6px;
}
.sidebar-tab:hover { color: var(--ink-dim); }
.sidebar-tab.active { color: var(--ink-mid); border-bottom-color: var(--active); }
.sidebar-count {
    background: var(--tag-bg); color: var(--tag-text);
    padding: 1px 7px; font-size: 10px; font-weight: 700;
    border-radius: 2px; min-width: 20px; text-align: center;
}
.sidebar-panel { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.sidebar-filter { padding: 6px 8px; border-bottom: 1px solid var(--rule); background: var(--paper-dark); }
.sidebar-filter select {
    width: 100%; padding: 4px 6px; border: 1px solid var(--rule);
    background: var(--paper); color: var(--ink); font-size: 11px; font-family: inherit;
}
.sidebar-list { flex: 1; overflow-y: auto; overflow-x: hidden; }
.sidebar-list::-webkit-scrollbar { width: 6px; }
.sidebar-list::-webkit-scrollbar-track { background: transparent; }
.sidebar-list::-webkit-scrollbar-thumb { background: var(--rule); border-radius: 3px; }

.sidebar-item {
    padding: 10px 14px; border-bottom: 1px solid var(--rule-light);
    cursor: pointer; transition: background 0.1s;
}
.sidebar-item:hover { background: var(--paper-dark); }
.sidebar-item-codes {
    font-family: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
    font-size: 10px; font-weight: 600; color: var(--tag-text);
    margin-bottom: 4px; letter-spacing: 0.02em;
}
.sidebar-item-text {
    font-family: var(--content-font); font-size: 12px; color: var(--ink-mid);
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
    overflow: hidden; line-height: 1.4;
}

/* Chapter list */
.chapter-item {
    padding: 10px 14px; border-bottom: 1px solid var(--rule-light);
    cursor: pointer; transition: background 0.1s;
    display: flex; justify-content: space-between; align-items: center;
}
.chapter-item:hover { background: var(--paper-dark); }
.chapter-item.active { background: var(--highlight-bg); }
.chapter-item-title {
    font-size: 12px; color: var(--ink-mid); font-weight: 500;
    flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chapter-item-meta {
    font-family: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
    font-size: 10px; color: var(--ink-ghost); flex-shrink: 0;
    margin-left: 8px; display: flex; gap: 8px;
}

/* Stats */
.sidebar-stats {
    border-top: 1px solid var(--rule); background: var(--paper-dark);
    max-height: 200px; overflow-y: auto; font-size: 11px;
    flex-shrink: 0;
}
.sidebar-stats::-webkit-scrollbar { width: 5px; }
.sidebar-stats::-webkit-scrollbar-thumb { background: var(--rule); border-radius: 3px; }
.stats-row {
    display: flex; justify-content: space-between;
    padding: 5px 14px; border-bottom: 1px solid var(--rule-light); color: var(--ink-mid);
}
.stats-row-code { font-weight: 500; }
.stats-row-count {
    font-family: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
    font-size: 10px; color: var(--ink-dim);
}

/* Footer */
.sidebar-footer {
    padding: 8px; border-top: 1px solid var(--rule);
    display: flex; gap: 6px; background: var(--paper-dark);
}
.sidebar-footer button {
    flex: 1; padding: 7px; border: 1px solid var(--rule);
    background: var(--paper); cursor: pointer; font-size: 11px;
    font-family: inherit; font-weight: 500; color: var(--ink-mid); transition: all 0.1s;
}
.sidebar-footer button:hover { background: var(--paper-warm); color: var(--ink); }
.sidebar-footer button.active {
    background: var(--tag-bg); color: var(--tag-text); border-color: var(--tag-bg);
}

/* Empty */
.empty-state { padding: 40px 20px; text-align: center; }
.empty-icon { font-size: 28px; opacity: 0.25; margin-bottom: 10px; }
.empty-text { font-size: 12px; color: var(--ink-ghost); }

/* ── Main ── */

.main {
    flex: 1; display: flex; flex-direction: column;
    overflow: hidden; background: var(--paper); position: relative;
}

.page-nav-left, .page-nav-right {
    position: absolute; top: 0; bottom: 28px; width: 60px;
    cursor: pointer; z-index: 5; opacity: 0; transition: opacity 0.2s;
}
.page-nav-left { left: 0; }
.page-nav-right { right: 0; }
.page-nav-left:hover { opacity: 1; background: linear-gradient(to right, rgba(0,0,0,0.03), transparent); }
.page-nav-right:hover { opacity: 1; background: linear-gradient(to left, rgba(0,0,0,0.03), transparent); }

/* Drop zone */
.drop-zone {
    position: absolute; inset: 0; display: flex; align-items: center;
    justify-content: center; background: var(--paper); z-index: 10; transition: background 0.2s;
}
.drop-zone.hidden { display: none; }
.drop-zone.drag-over { background: var(--highlight-bg); }
.drop-content { text-align: center; }
.drop-icon { font-size: 42px; margin-bottom: 16px; opacity: 0.5; }
.drop-title {
    font-family: 'Horizon', 'Arial Black', 'Arial', sans-serif;
    font-weight: 900; font-size: 42px; color: var(--ink);
    letter-spacing: -0.02em; text-transform: lowercase; margin-bottom: 6px;
}
.drop-subtitle { font-size: 14px; color: var(--ink-dim); margin-bottom: 4px; }
.drop-hint {
    font-family: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
    font-size: 11px; color: var(--ink-ghost); margin-bottom: 20px;
}
.drop-btn {
    background: var(--chrome); color: var(--paper); border: none;
    padding: 9px 24px; font-size: 13px; font-family: inherit;
    font-weight: 500; cursor: pointer; transition: background 0.15s;
}
.drop-btn:hover { background: var(--chrome-mid); }
body.dark .drop-btn {
    background: transparent; color: var(--ink-mid);
    border: 1px solid var(--chrome-light);
}
body.dark .drop-btn:hover { background: var(--chrome-light); color: var(--ink); }
.drop-shortcut { margin-top: 8px; font-size: 11px; color: var(--ink-ghost); }

/* ── Reader ── */

.reader-wrap { flex: 1; overflow: hidden; position: relative; }

#md-page {
    width: 100%; height: 100%; overflow: hidden;
    display: flex; justify-content: center; align-items: stretch;
}
#md-wrapper { width: var(--content-width); max-width: calc(100% - 20px); overflow: hidden; position: relative; }

#md-content {
    font-family: var(--content-font);
    font-size: var(--content-size);
    line-height: var(--content-line-height);
    color: var(--ink);
}

#md-content h1, #md-content h2, #md-content h3 {
    font-family: inherit; margin-top: 1.4em; margin-bottom: 0.4em;
    line-height: 1.25; color: var(--ink);
    break-after: avoid;
}

/* Chapter break spacers — invisible blocks sized by JS to push headings
   to column boundaries. Height set dynamically in sizeChapterBreaks().
   No CSS fragmentation properties — pure geometry for cross-browser support. */
.ch-break {
    display: block;
    margin: 0;
    padding: 0;
    border: 0;
    font-size: 0;
    line-height: 0;
    /* height set by JS */
}

#md-content > h1:first-child, #md-content > h2:first-child, #md-content > h3:first-child {
    margin-top: 0;
}
#md-content h1 { font-size: 1.6em; }
#md-content h2 { font-size: 1.3em; }
#md-content h3 { font-size: 1.1em; }

/* Promoted headings: paragraphs detected as chapter titles via heuristics.
   The inner <strong> from Mammoth is redundant since headings are already bold. */
#md-content h2.promoted-heading strong {
    font-weight: inherit;
}

#md-content p {
    margin-bottom: 0.8em; text-align: justify;
    text-indent: var(--content-indent); hyphens: manual; overflow-wrap: break-word;
    orphans: 2; widows: 2;
}

#md-content em { font-style: italic; }
#md-content strong { font-weight: bold; }
#md-content blockquote {
    margin: 1em 0; padding-left: 1.2em;
    border-left: 3px solid var(--rule); color: var(--ink-mid);
}
#md-content hr { border: none; border-top: 1px solid var(--rule); margin: 2em 0; }

/* Highlights */
.sh-highlight {
    background-color: var(--highlight-bg); cursor: pointer;
    transition: background-color 0.1s;
    box-shadow: inset 0 -2px 0 var(--highlight-border);
    position: relative;
}
.sh-highlight:hover { background-color: var(--highlight-hover); }
.sh-highlight-codes {
    font-family: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
    font-size: 0.65em; color: var(--tag-text); background: var(--tag-bg);
    padding: 2px 5px;
    position: absolute; bottom: calc(100% + 2px); left: 0;
    border-radius: 2px; white-space: nowrap;
    pointer-events: none;
    opacity: 0; transition: opacity 0.15s;
    z-index: 10;
    box-shadow: 0 1px 4px rgba(0,0,0,0.15);
}
.sh-highlight:hover .sh-highlight-codes {
    opacity: 1;
}

/* Timer */
.timer-display { cursor: pointer; transition: color 0.15s; user-select: none; }
.timer-display:hover { color: var(--ink); }
.timer-display.paused { color: var(--ink-ghost); }

/* Status bar */
.statusbar {
    height: 28px; background: var(--paper-dark); border-top: 1px solid var(--rule);
    display: flex; align-items: center; justify-content: center; gap: 6px;
    font-size: 11px; color: var(--ink-dim); user-select: none;
}
.statusbar-sep { color: var(--rule); }

/* ── Command Palette ── */

.palette-overlay {
    position: fixed; inset: 0; background: rgba(20, 18, 14, 0.5);
    display: flex; align-items: flex-start; justify-content: center;
    padding-top: 80px; z-index: 2000;
    opacity: 0; pointer-events: none;
    transition: opacity 0.12s ease;
}
body.dark .palette-overlay { background: rgba(0,0,0,0.6); }
.palette-overlay.visible { opacity: 1; pointer-events: auto; }

.palette {
    width: 420px; max-width: 90vw; background: var(--palette-bg);
    border: 1px solid rgba(255,255,255,0.08);
    box-shadow: 0 20px 60px rgba(0,0,0,0.5), 0 0 0 1px rgba(0,0,0,0.3);
    display: flex; flex-direction: column; max-height: 70vh; overflow: hidden;
}
.palette-header { padding: 10px 12px 8px; border-bottom: 1px solid rgba(255,255,255,0.06); }
.palette-input {
    width: 100%; background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.1); color: var(--palette-text);
    padding: 8px 10px; font-size: 14px; font-family: inherit;
    outline: none; transition: border-color 0.15s;
}
.palette-input:focus { border-color: var(--active); }
.palette-input::placeholder { color: var(--palette-dim); }
.palette-codes {
    margin-top: 6px; min-height: 20px;
    font-family: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
    font-size: 11px; color: var(--active); letter-spacing: 0.02em;
}
.palette-excerpt {
    padding: 8px 12px; font-family: var(--content-font);
    font-size: 12px; color: var(--palette-dim);
    border-bottom: 1px solid rgba(255,255,255,0.06);
    line-height: 1.4; max-height: 52px; overflow: hidden;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.palette-list { flex: 1; overflow-y: auto; max-height: 340px; }
.palette-list::-webkit-scrollbar { width: 5px; }
.palette-list::-webkit-scrollbar-track { background: transparent; }
.palette-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }

.palette-group-label {
    padding: 8px 12px 4px; font-size: 10px; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.08em; color: var(--palette-dim);
}
.palette-item {
    padding: 7px 12px 7px 22px; cursor: pointer;
    display: flex; align-items: center; justify-content: space-between;
    transition: background 0.08s; color: var(--palette-text);
    font-size: 13px; position: relative;
}
.palette-item:hover, .palette-item.focused { background: var(--palette-hover); }
.palette-item.active { color: var(--active); }
.palette-item.active::before {
    content: '✓'; position: absolute; left: 8px; font-size: 11px; color: var(--active);
}
.palette-item-code {
    font-family: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
    font-size: 10px; color: var(--palette-dim);
}

.palette-footer {
    padding: 6px 12px; border-top: 1px solid rgba(255,255,255,0.06);
    display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
    font-size: 10px; color: var(--palette-dim);
}
.palette-custom-btn {
    background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.1);
    color: var(--palette-text); padding: 4px 10px; font-size: 11px;
    font-family: inherit; cursor: pointer; white-space: nowrap; transition: background 0.1s;
}
.palette-custom-btn:hover { background: rgba(255,255,255,0.12); }
.palette-clear-btn { color: #c07070; border-color: rgba(192,112,112,0.2); }
.palette-clear-btn:hover { background: rgba(192,112,112,0.12); }
.palette-undo-btn { color: #70a0c0; border-color: rgba(112,160,192,0.2); }
.palette-undo-btn:hover { background: rgba(112,160,192,0.12); }
.palette-save-btn { color: #80b070; border-color: rgba(128,176,112,0.2); }
.palette-save-btn:hover { background: rgba(128,176,112,0.12); }
.palette-footer-hints { display: flex; gap: 10px; margin-left: auto; }
.palette-hint kbd {
    background: rgba(255,255,255,0.08); padding: 1px 4px;
    border-radius: 2px; font-family: inherit; font-size: 10px;
}

/* ── Dialogs ── */

.dialog-overlay {
    position: fixed; inset: 0; background: rgba(20, 18, 14, 0.45);
    display: none; align-items: center; justify-content: center; z-index: 1500;
}
body.dark .dialog-overlay { background: rgba(0,0,0,0.55); }
.dialog-overlay.visible { display: flex; }

.dialog {
    background: var(--paper); border: 1px solid var(--rule);
    width: 360px; max-height: 80vh; display: flex; flex-direction: column;
    box-shadow: 0 12px 40px rgba(0,0,0,0.25);
}
.dialog-wide { width: 480px; }
.dialog-tall { max-height: 85vh; }

.dialog-title {
    padding: 10px 14px; background: var(--paper-dark);
    border-bottom: 1px solid var(--rule); font-weight: 600; font-size: 12px;
    color: var(--ink-mid); text-transform: uppercase; letter-spacing: 0.04em;
}
.dialog-body { flex: 1; overflow-y: auto; }
.dialog-footer {
    padding: 8px; border-top: 1px solid var(--rule);
    display: flex; gap: 6px; background: var(--paper-dark);
}
.dialog-footer button {
    flex: 1; padding: 7px; border: 1px solid var(--rule);
    background: var(--paper); cursor: pointer; font-size: 12px;
    font-family: inherit; font-weight: 500; color: var(--ink-mid); transition: all 0.1s;
}
.dialog-footer button:hover { background: var(--paper-warm); color: var(--ink); }

/* Settings */
.setting-row { padding: 12px 14px; border-bottom: 1px solid var(--rule-light); }
.setting-label {
    display: flex; justify-content: space-between; font-size: 12px;
    font-weight: 500; margin-bottom: 6px; color: var(--ink-mid);
}
.setting-toggle-label { margin-bottom: 0; align-items: center; cursor: pointer; }
.setting-toggle-label input[type="checkbox"] { accent-color: var(--active); cursor: pointer; }
.setting-val {
    font-family: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
    font-size: 11px; color: var(--ink-dim);
}
.setting-row select {
    width: 100%; padding: 6px 8px; border: 1px solid var(--rule);
    background: var(--paper); font-size: 12px; font-family: inherit; color: var(--ink);
}
.setting-row input[type="range"] { width: 100%; margin: 4px 0; accent-color: var(--active); }

.color-swatches { display: flex; gap: 8px; flex-wrap: wrap; padding-top: 2px; }
.color-swatch {
    width: 28px; height: 28px; border: 2px solid var(--rule);
    cursor: pointer; transition: all 0.1s; position: relative;
}
.color-swatch:hover { border-color: var(--ink-dim); transform: scale(1.1); }
.color-swatch.active {
    border-color: var(--ink);
    box-shadow: 0 0 0 2px var(--paper), 0 0 0 4px var(--active);
}

/* ── Codes Editor (proper UI) ── */

.codes-group {
    border-bottom: 1px solid var(--rule);
}
.codes-group-header {
    display: flex; align-items: center; gap: 8px;
    padding: 10px 14px; background: var(--paper-dark);
    border-bottom: 1px solid var(--rule-light);
}
.codes-group-header input {
    flex: 1; padding: 4px 6px; border: 1px solid var(--rule);
    background: var(--paper); font-size: 12px; font-family: inherit;
    font-weight: 600; color: var(--ink);
}
.codes-group-header button {
    padding: 3px 8px; border: 1px solid var(--rule);
    background: var(--paper); cursor: pointer; font-size: 10px;
    font-family: inherit; color: var(--ink-dim); transition: all 0.1s;
}
.codes-group-header button:hover { background: var(--paper-warm); color: var(--ink); }
.codes-group-header .codes-group-del { color: #b06060; }
.codes-group-header .codes-group-del:hover { background: #f0e0e0; color: #903030; }

.codes-item {
    display: flex; align-items: center; gap: 6px;
    padding: 6px 14px 6px 28px; border-bottom: 1px solid var(--rule-light);
}
.codes-item input {
    flex: 1; padding: 3px 6px; border: 1px solid var(--rule);
    background: var(--paper); font-size: 12px; font-family: inherit; color: var(--ink);
}
.codes-item button {
    padding: 2px 6px; border: 1px solid transparent;
    background: none; cursor: pointer; font-size: 12px;
    color: var(--ink-ghost); transition: color 0.1s;
}
.codes-item button:hover { color: #b06060; }

.codes-add-item {
    padding: 6px 14px 6px 28px;
}
.codes-add-item button {
    padding: 3px 10px; border: 1px solid var(--rule);
    background: var(--paper); cursor: pointer; font-size: 11px;
    font-family: inherit; color: var(--ink-dim); transition: all 0.1s;
}
.codes-add-item button:hover { background: var(--paper-warm); color: var(--ink); }

/* ── Chapter prompt ── */

.prompt-question { margin-bottom: 16px; }
.prompt-time {
    padding: 8px 10px; margin-bottom: 14px;
    background: var(--paper-dark); border: 1px solid var(--rule-light);
    font-family: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
    font-size: 11px; color: var(--ink-dim); text-align: center;
}
.prompt-label {
    display: flex; justify-content: space-between; align-items: baseline;
    font-size: 12px; font-weight: 600; color: var(--ink-mid); margin-bottom: 8px;
}
.prompt-optional { font-weight: 400; color: var(--ink-ghost); }
.prompt-rating-num {
    font-family: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
    font-size: 14px; font-weight: 700; color: var(--active);
}
.prompt-options { display: flex; gap: 6px; }
.prompt-opt {
    flex: 1; padding: 8px; border: 1px solid var(--rule);
    background: var(--paper); cursor: pointer; font-size: 12px;
    font-family: inherit; font-weight: 500; color: var(--ink-mid);
    text-align: center; transition: all 0.1s;
}
.prompt-opt:hover { background: var(--paper-warm); }
.prompt-opt.selected {
    background: var(--tag-bg); color: var(--tag-text); border-color: var(--active-dim);
}

.prompt-slider {
    width: 100%; margin: 4px 0; accent-color: var(--active);
}
.prompt-slider-labels {
    display: flex; justify-content: space-between;
    font-size: 10px; color: var(--ink-ghost);
    font-family: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
}

.prompt-textarea {
    width: 100%; padding: 8px; border: 1px solid var(--rule);
    background: var(--paper); color: var(--ink); font-size: 12px;
    font-family: inherit; line-height: 1.5; resize: vertical;
}
.prompt-textarea:focus { outline: none; border-color: var(--active); }

/* Export dialog */
.export-options { display: flex; flex-direction: column; gap: 6px; }
.export-opt {
    display: flex; align-items: center; gap: 8px;
    font-size: 12px; color: var(--ink-mid); cursor: pointer;
    padding: 6px 8px; transition: background 0.1s;
}
.export-opt:hover { background: var(--paper-dark); }
.export-opt input[type="radio"] { accent-color: var(--active); cursor: pointer; }

/* ── Responsive ── */

@media (max-width: 700px) { .sidebar { width: 200px; } }

/* ── Fullscreen ── */

body.fullscreen {
    position: fixed; inset: 0; z-index: 9999;
}
body.fullscreen .titlebar { display: none; }
body.fullscreen .doc-tabs { display: none !important; }
body.fullscreen .sidebar { display: none; }
body.fullscreen .container { height: 100vh; }
body.fullscreen .statusbar {
    position: fixed; bottom: 0; left: 0; right: 0;
    opacity: 0; transition: opacity 0.3s;
}
body.fullscreen .statusbar:hover { opacity: 1; }
body.fullscreen .main { border-radius: 0; }

/* Fullscreen floating toolbar — slides down from top on hover */
.fs-toolbar {
    display: none;
    position: fixed; top: 0; left: 50%; transform: translateX(-50%);
    background: var(--chrome); border: 1px solid var(--chrome-light);
    border-top: none;
    padding: 6px 10px; gap: 4px; z-index: 10000;
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
    opacity: 0; pointer-events: none; transition: opacity 0.25s;
}
body.fullscreen .fs-toolbar {
    display: flex;
}
body.fullscreen .fs-toolbar.visible {
    pointer-events: auto; opacity: 1;
}

.fs-toolbar button {
    background: var(--chrome-mid); border: 1px solid var(--chrome-light);
    color: #ddd8cc; padding: 4px 10px; font-size: 11px;
    cursor: pointer; transition: background 0.1s; font-family: inherit;
    white-space: nowrap;
}
.fs-toolbar button:hover { background: var(--chrome-hover); }
body.dark .fs-toolbar button { color: var(--ink-mid); }
.fs-toolbar button.active { color: var(--active); border-color: var(--active-dim); }
.fs-toolbar-sep {
    width: 1px; background: var(--chrome-light); margin: 0 4px; align-self: stretch;
}

/* Floating stats panel (fullscreen mode) */
.fs-stats-panel {
    display: none;
    position: fixed; top: 60px; right: 20px;
    width: 260px; max-height: 400px; overflow-y: auto;
    background: var(--chrome); border: 1px solid var(--chrome-light);
    border-radius: 6px; padding: 10px 0;
    box-shadow: 0 4px 16px rgba(0,0,0,0.25);
    z-index: 10000;
    font-size: 12px;
}

/* ── Heatmap ── */

.heatmap-container {
    padding: 12px 14px;
}
.heatmap-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 10px;
}
.heatmap-header .heatmap-title { margin-bottom: 0; }
.heatmap-export-btn {
    font-size: 9px; padding: 2px 8px; cursor: pointer;
    background: var(--chrome-mid); border: 1px solid var(--chrome-light);
    color: var(--ink-dim); font-family: inherit; transition: background 0.1s;
}
.heatmap-export-btn:hover { background: var(--chrome-hover); color: var(--ink); }
.heatmap-title {
    font-size: 11px; font-weight: 600; text-transform: uppercase;
    letter-spacing: 0.04em; color: var(--ink-dim);
}
.heatmap-chapter {
    display: flex; align-items: center; gap: 8px;
    margin-bottom: 6px; cursor: pointer; transition: opacity 0.15s;
}
.heatmap-chapter:hover { opacity: 0.8; }
.heatmap-label {
    font-size: 10px; color: var(--ink-mid); width: 120px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    flex-shrink: 0;
}
.heatmap-bar-wrap {
    flex: 1; height: 16px; background: var(--paper-dark);
    border: 1px solid var(--rule-light); position: relative; overflow: hidden;
}
.heatmap-bar {
    height: 100%; display: flex;
}
.heatmap-segment {
    height: 100%; min-width: 1px;
}
.heatmap-count {
    font-family: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
    font-size: 9px; color: var(--ink-ghost); width: 24px; text-align: right;
    flex-shrink: 0;
}
.heatmap-legend {
    display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px;
    padding-top: 8px; border-top: 1px solid var(--rule-light);
}
.heatmap-legend-item {
    display: flex; align-items: center; gap: 4px;
    font-size: 9px; color: var(--ink-dim);
}
.heatmap-legend-swatch {
    width: 10px; height: 10px; flex-shrink: 0;
}

/* ── View mode buttons in titlebar ── */

.titlebar-btn.active {
    background: var(--chrome-hover);
    color: var(--active);
    border-color: var(--active-dim);
}

/* ── Clear All confirmation ── */

.clear-confirm {
    padding: 16px; text-align: center;
}
.clear-confirm p {
    font-size: 13px; color: var(--ink-mid); margin-bottom: 12px; line-height: 1.5;
}
.clear-confirm .warning {
    color: #b06060; font-weight: 600; font-size: 12px;
}
