/* ======= Theme definitions ======= */
:root,
[data-theme="default"] {
    --bg-color: #1a1a2e;
    --text-color: #e0e0e0;
    --ui-color: #0f3460;
    --card-bg: #16213e;
    --card-border: #222;
    --input-bg: #0a0f1e;
    --muted-color: #888;
    --faint-color: #666;
    --subtle-color: #aaa;
    --secondary-bg: #333;
    --accent-color: #4a90d9;
    --danger-color: #c0392b;
    --danger-text: #e74c3c;
    --success-color: #27ae60;
    --warning-color: #f39c12;
    --info-color: #3498db;
    --highlight-color: #e74c3c;
    --error-bg: #3c1414;
    --font-family: Georgia;
    --font-size: 48px;
}

[data-theme="warm"] {
    --bg-color: #1c1712;
    --text-color: #e8dcc8;
    --ui-color: #8b6b3d;
    --card-bg: #2a2118;
    --card-border: #3a3028;
    --input-bg: #161210;
    --muted-color: #9a8b78;
    --faint-color: #6b5e50;
    --subtle-color: #b5a898;
    --secondary-bg: #3a3028;
    --accent-color: #c8965a;
    --danger-color: #b85c3a;
    --danger-text: #d97a55;
    --success-color: #7a9a4e;
    --warning-color: #d4a24c;
    --info-color: #6a9ab5;
    --highlight-color: #c8965a;
    --error-bg: #2e1a12;
}

[data-theme="midnight"] {
    --bg-color: #13111c;
    --text-color: #d4d0e8;
    --ui-color: #5a4dbf;
    --card-bg: #1e1a2e;
    --card-border: #2e2942;
    --input-bg: #0e0c16;
    --muted-color: #8a84a8;
    --faint-color: #5e587a;
    --subtle-color: #a8a2c4;
    --secondary-bg: #2e2942;
    --accent-color: #7c6aef;
    --danger-color: #c43e5c;
    --danger-text: #d94f6b;
    --success-color: #4eaa6e;
    --warning-color: #d4a24c;
    --info-color: #5a8ad4;
    --highlight-color: #7c6aef;
    --error-bg: #2a1220;
}

[data-theme="forest"] {
    --bg-color: #0f1a14;
    --text-color: #d4e4d8;
    --ui-color: #2d7a4f;
    --card-bg: #162420;
    --card-border: #243832;
    --input-bg: #0a1410;
    --muted-color: #7a9a84;
    --faint-color: #4e6e58;
    --subtle-color: #98b8a4;
    --secondary-bg: #243832;
    --accent-color: #4a9e6e;
    --danger-color: #c45c4a;
    --danger-text: #d47060;
    --success-color: #4a9e6e;
    --warning-color: #c4a24e;
    --info-color: #4a8aaa;
    --highlight-color: #4a9e6e;
    --error-bg: #1e1410;
}

[data-theme="mono"] {
    --bg-color: #141414;
    --text-color: #e0e0e0;
    --ui-color: #3580bb;
    --card-bg: #1e1e1e;
    --card-border: #2e2e2e;
    --input-bg: #111111;
    --muted-color: #888;
    --faint-color: #666;
    --subtle-color: #aaa;
    --secondary-bg: #2e2e2e;
    --accent-color: #4a9edd;
    --danger-color: #d94f4f;
    --danger-text: #e06060;
    --success-color: #4aaa6e;
    --warning-color: #d4a24c;
    --info-color: #4a9edd;
    --highlight-color: #4a9edd;
    --error-bg: #2a1414;
}

/* ======= Base ======= */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Open Sans', sans-serif;
    background: var(--bg-color);
    color: var(--text-color);
    min-height: 100vh;
}

/* ======= Auth pages ======= */
.auth-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 2rem;
}

.auth-title {
    font-size: 2.5rem;
    margin-bottom: 0.25rem;
    color: var(--text-color);
}

.auth-subtitle {
    color: var(--muted-color);
    margin-bottom: 2rem;
}

.auth-form {
    width: 100%;
    max-width: 400px;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.auth-form[hidden] {
    display: none;
}

.auth-form h2 {
    text-align: center;
}

.auth-form input {
    padding: 0.75rem 1rem;
    border: 1px solid var(--card-border);
    border-radius: 6px;
    background: var(--card-bg);
    color: var(--text-color);
    font-size: 1rem;
}

.auth-form input:focus {
    outline: none;
    border-color: var(--ui-color);
}

.auth-switch {
    text-align: center;
    color: var(--muted-color);
}

.auth-switch a {
    color: var(--accent-color);
    text-decoration: none;
}

.error-msg {
    color: var(--danger-text);
    text-align: center;
    font-size: 0.9rem;
}

/* ======= Buttons ======= */
.btn {
    padding: 0.6rem 1.2rem;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.95rem;
    transition: opacity 0.2s;
}

.btn:hover {
    opacity: 0.85;
}

.btn-primary {
    background: var(--ui-color);
    color: var(--text-color);
}

.btn-secondary {
    background: var(--secondary-bg);
    color: var(--text-color);
}

.btn-danger {
    background: var(--danger-color);
    color: white;
}

.btn-sm {
    padding: 0.35rem 0.8rem;
    font-size: 0.85rem;
}

/* ======= Library page ======= */
.library-container {
    max-width: 900px;
    margin: 0 auto;
    padding: 2rem;
}

.library-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.header-actions {
    display: flex;
    gap: 0.75rem;
}

.upload-status {
    background: var(--card-bg);
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    text-align: center;
}

.documents-grid {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.doc-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    background: var(--card-bg);
    padding: 1.25rem;
    border-radius: 8px;
    border: 1px solid var(--card-border);
}

.doc-info {
    flex: 1;
    min-width: 0;
}

.doc-title {
    font-size: 1.1rem;
    margin-bottom: 0.25rem;
}

.doc-meta {
    color: var(--muted-color);
    font-size: 0.85rem;
}

.doc-actions {
    display: flex;
    gap: 0.5rem;
    flex-shrink: 0;
}

.badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 4px;
    font-size: 0.75rem;
    margin-left: 0.5rem;
    text-transform: uppercase;
}

.badge-pending { background: var(--warning-color); color: #000; }
.badge-processing { background: var(--info-color); color: #fff; }
.badge-failed { background: var(--danger-text); color: #fff; }

.progress-bar {
    width: 120px;
    height: 4px;
    background: var(--secondary-bg);
    border-radius: 2px;
    margin-top: 0.5rem;
    display: inline-block;
}

.progress-fill {
    height: 100%;
    background: var(--accent-color);
    border-radius: 2px;
    transition: width 0.3s;
}

.progress-text {
    font-size: 0.8rem;
    color: var(--muted-color);
    margin-left: 0.5rem;
}

.empty-state {
    text-align: center;
    padding: 4rem;
    color: var(--muted-color);
}

.loading-msg {
    text-align: center;
    color: var(--muted-color);
    padding: 2rem;
}

/* ======= Reader page ======= */
.reader-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    background: var(--bg-color);
    color: var(--text-color);
    position: relative;
}

.reader-topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1.5rem;
    background: rgba(0, 0, 0, 0.3);
    font-size: 0.9rem;
}

.back-link {
    color: var(--text-color);
    text-decoration: none;
    opacity: 0.7;
}

.back-link:hover {
    opacity: 1;
}

.reader-topbar .doc-title {
    font-size: 0.9rem;
    opacity: 0.7;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 50%;
}

.progress-indicator {
    font-weight: 600;
}

/* RSVP display */
.rsvp-display {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    user-select: none;
    touch-action: none;
}

.rsvp-word-container {
    font-family: var(--font-family);
    font-size: var(--font-size);
    letter-spacing: 0.02em;
    white-space: nowrap;
    position: relative;
}

.rsvp-before {
    color: var(--text-color);
}

.rsvp-pivot {
    color: var(--text-color);
    font-weight: normal;
}

.rsvp-pivot.highlight {
    color: var(--highlight-color);
    font-weight: bold;
}

.rsvp-after {
    color: var(--text-color);
}

.rsvp-focus-line {
    position: absolute;
    left: 50%;
    top: 45%;
    width: 2px;
    height: 20%;
    background: rgba(231, 76, 60, 0.3);
    transform: translateX(-50%);
    pointer-events: none;
    display: none;
}

.rsvp-focus-line.visible {
    display: block;
}

/* ======= Progress scrubber ======= */
.progress-scrubber {
    padding: 0.5rem 1.5rem 0.25rem;
    background: rgba(0, 0, 0, 0.3);
    user-select: none;
}

.scrubber-track {
    position: relative;
    height: 8px;
    background: var(--secondary-bg);
    border-radius: 4px;
    cursor: pointer;
}

.scrubber-fill {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    background: var(--accent-color);
    border-radius: 4px;
    pointer-events: none;
    transition: width 0.1s linear;
}

.scrubber-handle {
    position: absolute;
    top: 50%;
    width: 16px;
    height: 16px;
    background: var(--text-color);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
    opacity: 0;
    transition: opacity 0.15s;
}

.scrubber-track:hover .scrubber-handle,
.progress-scrubber.dragging .scrubber-handle {
    opacity: 1;
}

.scrubber-chapters {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.chapter-marker {
    position: absolute;
    top: -2px;
    width: 2px;
    height: 12px;
    background: var(--text-color);
    opacity: 0.4;
    border-radius: 1px;
    transform: translateX(-50%);
}

.chapter-marker:first-child {
    display: none;
}

.scrubber-labels {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.75rem;
    color: var(--muted-color);
    margin-top: 0.25rem;
    min-height: 1.5rem;
}

/* ======= Chapter navigation ======= */
.chapter-nav {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.chapter-nav[hidden] {
    display: none;
}

.btn-chapter {
    background: none;
    border: 1px solid var(--secondary-bg);
    color: var(--text-color);
    border-radius: 4px;
    width: 24px;
    height: 24px;
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.btn-chapter:hover {
    background: var(--secondary-bg);
}

.btn-chapter:disabled {
    opacity: 0.3;
    cursor: default;
}

.chapter-label {
    font-size: 0.8rem;
    color: var(--subtle-color);
    min-width: 80px;
    text-align: center;
}

/* Time remaining */
.time-remaining {
    text-align: center;
    font-size: 0.85rem;
    color: var(--muted-color);
    padding: 0.25rem 0;
    background: rgba(0, 0, 0, 0.3);
    min-height: 1.5rem;
}

/* Controls */
.reader-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 1rem 1.5rem;
    background: rgba(0, 0, 0, 0.3);
}

.btn-control {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--ui-color);
    color: var(--text-color);
    font-size: 1.1rem;
    border: none;
    cursor: pointer;
}

.btn-control:hover {
    opacity: 0.85;
}

.btn-play {
    font-size: 1.3rem;
}

#btn-play-pause {
    width: 56px;
    height: 56px;
}

.wpm-control {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    position: relative;
}

#wpm-slider {
    width: 150px;
    accent-color: var(--ui-color);
}

#wpm-label {
    font-size: 0.9rem;
    min-width: 80px;
    cursor: pointer;
}

#wpm-label:hover {
    text-decoration: underline;
    text-decoration-style: dotted;
}

.wpm-edit-input {
    width: 72px;
    padding: 0.2rem 0.4rem;
    background: var(--input-bg);
    border: 1px solid var(--accent-color);
    border-radius: 4px;
    color: var(--text-color);
    font-size: 0.9rem;
    text-align: center;
    outline: none;
}

.wpm-edit-input::-webkit-inner-spin-button,
.wpm-edit-input::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.wpm-edit-input {
    -moz-appearance: textfield;
}

.tts-cap-msg {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.75rem;
    color: var(--warning-color);
    white-space: nowrap;
    margin-bottom: 0.25rem;
}

/* Settings panel */
.settings-panel {
    position: absolute;
    right: 1rem;
    bottom: 5rem;
    max-height: calc(100vh - 6rem);
    overflow-y: auto;
    background: var(--card-bg);
    border: 1px solid var(--secondary-bg);
    border-radius: 12px;
    padding: 1.5rem;
    width: 300px;
    z-index: 100;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.settings-panel h3 {
    margin-bottom: 1rem;
}

.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}

.setting-row label {
    font-size: 0.9rem;
    color: var(--subtle-color);
}

.setting-row input[type="color"] {
    width: 40px;
    height: 30px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    background: transparent;
}

.setting-row select {
    padding: 0.4rem;
    max-width: 140px;
    background: var(--input-bg);
    color: var(--text-color);
    border: 1px solid var(--secondary-bg);
    border-radius: 4px;
    text-overflow: ellipsis;
}

.setting-row input[type="range"] {
    width: 100px;
    accent-color: var(--ui-color);
}

#font-size-label {
    font-size: 0.8rem;
    min-width: 35px;
}

/* ======= Editor page ======= */
.editor-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    background: var(--bg-color);
    color: var(--text-color);
}

.editor-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1.5rem;
    background: rgba(0, 0, 0, 0.3);
}

.editor-header h2 {
    flex: 1;
    font-size: 1rem;
    font-weight: normal;
    opacity: 0.7;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.editor-header .header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.word-count {
    font-size: 0.85rem;
    color: var(--muted-color);
}

.editor-status {
    padding: 0.6rem 1.5rem;
    background: var(--card-bg);
    text-align: center;
    font-size: 0.9rem;
}

.editor-status-error {
    background: var(--error-bg);
    color: var(--danger-text);
}

.text-editor {
    flex: 1;
    overflow: hidden;
    background: var(--input-bg);
    color: var(--text-color);
}

.text-editor .cm-editor {
    height: 100%;
    background: var(--input-bg);
    color: var(--text-color);
}

/* ======= Library toolbar ======= */
.library-toolbar {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.toolbar-input {
    flex: 1;
    min-width: 200px;
    padding: 0.6rem 1rem;
    background: var(--card-bg);
    border: 1px solid var(--secondary-bg);
    border-radius: 6px;
    color: var(--text-color);
    font-size: 0.95rem;
}

.toolbar-input::placeholder {
    color: var(--faint-color);
}

.toolbar-input:focus {
    outline: none;
    border-color: var(--ui-color);
}

.toolbar-select {
    padding: 0.6rem 1rem;
    background: var(--card-bg);
    border: 1px solid var(--secondary-bg);
    border-radius: 6px;
    color: var(--text-color);
    font-size: 0.95rem;
    cursor: pointer;
    min-width: 150px;
}

.toolbar-select:focus {
    outline: none;
    border-color: var(--ui-color);
}

.text-editor .cm-editor.cm-focused {
    outline: none;
}

/* ======= Help button ======= */
.help-btn-wrapper {
    position: relative;
}

.btn-help {
    font-family: Georgia, serif;
    font-size: 1.2rem;
    font-weight: bold;
}

.help-hint {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--accent-color);
    color: #fff;
    font-size: 0.7rem;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    white-space: nowrap;
    margin-bottom: 0.35rem;
    opacity: 1;
    transition: opacity 0.6s ease;
    pointer-events: none;
}

.help-hint::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 4px solid transparent;
    border-top-color: var(--accent-color);
}

.help-hint.hidden {
    opacity: 0;
}

/* ======= Help overlay ======= */
.help-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
}

.help-overlay[hidden] {
    display: none;
}

.help-overlay-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
}

.help-overlay-content {
    position: relative;
    background: var(--card-bg);
    border: 1px solid var(--secondary-bg);
    border-radius: 12px;
    padding: 2rem;
    min-width: 320px;
    max-width: 420px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.7);
    animation: helpFadeIn 0.15s ease-out;
}

@keyframes helpFadeIn {
    from { opacity: 0; transform: scale(0.95); }
    to   { opacity: 1; transform: scale(1); }
}

.help-overlay-content h3 {
    margin-bottom: 1.25rem;
    font-size: 1.1rem;
    color: var(--text-color);
}

.shortcut-list {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.shortcut-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.shortcut-row kbd {
    display: inline-block;
    min-width: 48px;
    text-align: center;
    padding: 0.3rem 0.6rem;
    background: var(--input-bg);
    border: 1px solid var(--secondary-bg);
    border-radius: 4px;
    font-family: 'Roboto Mono', monospace;
    font-size: 0.85rem;
    color: var(--text-color);
}

.shortcut-row span {
    flex: 1;
    color: var(--subtle-color);
    font-size: 0.9rem;
}

.help-dismiss-hint {
    margin-top: 1.25rem;
    text-align: center;
    font-size: 0.8rem;
    color: var(--faint-color);
}

.help-dismiss-hint kbd {
    padding: 0.15rem 0.4rem;
    background: var(--input-bg);
    border: 1px solid var(--secondary-bg);
    border-radius: 3px;
    font-family: 'Roboto Mono', monospace;
    font-size: 0.75rem;
    color: var(--subtle-color);
}

/* ======= Bulk select ======= */
.doc-select-cb {
    width: 18px;
    height: 18px;
    accent-color: var(--ui-color);
    cursor: pointer;
}

/* Paste modal textarea */
#paste-text {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--input-bg);
    border: 1px solid var(--secondary-bg);
    border-radius: 6px;
    color: var(--text-color);
    font-size: 0.95rem;
    resize: vertical;
}

#paste-text:focus,
#paste-title:focus {
    outline: none;
    border-color: var(--ui-color);
}

/* Bulk toolbar */
.bulk-toolbar {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1rem;
    background: var(--card-bg);
    border: 1px solid var(--secondary-bg);
    border-radius: 8px;
    margin-bottom: 1rem;
}

.bulk-toolbar .bulk-count {
    font-size: 0.9rem;
    color: var(--subtle-color);
}

/* ======= Stats page ======= */
.stats-container {
    max-width: 900px;
    margin: 0 auto;
    padding: 2rem;
}

.stats-header {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stats-header h1 {
    font-family: 'Merriweather', serif;
}

.stats-cards {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    padding: 1.25rem;
    text-align: center;
}

.stat-card .stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-color);
}

.stat-card .stat-label {
    font-size: 0.85rem;
    color: var(--muted-color);
    margin-top: 0.25rem;
}

.stat-card .stat-sub {
    font-size: 0.75rem;
    color: var(--faint-color);
    margin-top: 0.25rem;
}

.stats-today {
    text-align: center;
    font-size: 0.95rem;
    color: var(--muted-color);
    margin-bottom: 1.5rem;
}

.chart-section {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.chart-section h3 {
    font-family: 'Merriweather', serif;
    font-size: 1.1rem;
    margin-bottom: 1rem;
}

.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.chart-header h3 {
    margin-bottom: 0;
}

.period-toggle {
    display: flex;
    gap: 0.5rem;
}

.period-btn {
    padding: 0.35rem 0.8rem;
    background: var(--secondary-bg);
    border: none;
    border-radius: 4px;
    color: var(--text-color);
    cursor: pointer;
    font-size: 0.8rem;
}

.period-btn.active {
    background: var(--ui-color);
}

.period-btn:hover {
    opacity: 0.85;
}

.doc-stats-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.doc-stat-row {
    background: var(--input-bg);
    border: 1px solid var(--card-border);
    border-radius: 6px;
    padding: 1rem;
}

.doc-stat-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.doc-stat-title {
    font-weight: 600;
    font-size: 0.95rem;
}

.badge-completed {
    background: var(--success-color);
    color: #fff;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 600;
}

.doc-stat-metrics {
    display: flex;
    gap: 1.5rem;
    font-size: 0.85rem;
    color: var(--muted-color);
    margin-bottom: 0.5rem;
}

.doc-stat-row .progress-bar {
    width: 100%;
}

/* ======= Theme switcher ======= */
.theme-switcher {
    display: flex;
    gap: 0.4rem;
    align-items: center;
}

.theme-swatch {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    transition: border-color 0.2s, transform 0.15s;
}

.theme-swatch:hover {
    transform: scale(1.15);
}

.theme-swatch.active {
    border-color: var(--text-color);
}

.theme-swatch[data-theme="default"] { background: #1a1a2e; box-shadow: inset 0 0 0 3px #0f3460; }
.theme-swatch[data-theme="warm"]    { background: #1c1712; box-shadow: inset 0 0 0 3px #c8965a; }
.theme-swatch[data-theme="midnight"]{ background: #13111c; box-shadow: inset 0 0 0 3px #7c6aef; }
.theme-swatch[data-theme="forest"]  { background: #0f1a14; box-shadow: inset 0 0 0 3px #4a9e6e; }
.theme-swatch[data-theme="mono"]    { background: #141414; box-shadow: inset 0 0 0 3px #4a9edd; }

/* ======= Modal content (replaces inline styles) ======= */
.paste-modal-content,
.url-modal-content {
    max-width: 520px;
    min-width: 400px;
}

/* ======= Fullscreen mode ======= */
.reader-container.fullscreen-active .rsvp-display {
    position: absolute;
    inset: 0;
    z-index: 1;
}

.reader-container.fullscreen-active .reader-topbar,
.reader-container.fullscreen-active .progress-scrubber,
.reader-container.fullscreen-active .time-remaining,
.reader-container.fullscreen-active .reader-controls {
    position: relative;
    z-index: 10;
    transition: opacity 0.3s ease;
}

.reader-container.fullscreen-hide .reader-topbar,
.reader-container.fullscreen-hide .progress-scrubber,
.reader-container.fullscreen-hide .time-remaining,
.reader-container.fullscreen-hide .reader-controls {
    opacity: 0;
    pointer-events: none;
}

/* ======= Responsive ======= */
@media (max-width: 640px) {
    /* --- Reader page --- */
    .reader-topbar {
        padding: 0.5rem 0.75rem;
        font-size: 0.8rem;
    }

    .reader-topbar .doc-title {
        font-size: 0.8rem;
        max-width: 40%;
    }

    .rsvp-word-container {
        font-size: calc(var(--font-size) * 0.75);
        padding: 0 0.5rem;
        word-break: break-word;
        white-space: normal;
        text-align: center;
    }

    .progress-scrubber {
        padding: 0.5rem 0.75rem 0.25rem;
    }

    .btn-chapter {
        width: 44px;
        height: 44px;
        font-size: 1.3rem;
    }

    .reader-controls {
        flex-wrap: wrap;
        gap: 0.5rem;
        padding: 0.75rem;
    }

    .wpm-control {
        order: 1;
        width: 100%;
        justify-content: center;
    }

    #wpm-slider {
        width: 100%;
        flex: 1;
        max-width: 200px;
    }

    .settings-panel {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        top: auto;
        width: 100%;
        max-height: 70vh;
        overflow-y: auto;
        border-radius: 12px 12px 0 0;
        z-index: 150;
    }

    .help-overlay-content {
        min-width: unset;
        max-width: 90vw;
        padding: 1.5rem;
    }

    /* --- Library page --- */
    .library-container {
        padding: 1rem;
    }

    .library-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .header-actions {
        flex-wrap: wrap;
        gap: 0.5rem;
        width: 100%;
    }

    .header-actions .btn {
        flex: 1;
        min-width: calc(33% - 0.5rem);
        text-align: center;
        padding: 0.5rem 0.5rem;
        font-size: 0.85rem;
    }

    .header-actions .theme-switcher {
        width: 100%;
        justify-content: center;
    }

    .library-toolbar {
        flex-direction: column;
    }

    .toolbar-input {
        min-width: unset;
    }

    .toolbar-select {
        min-width: unset;
        width: 100%;
    }

    .doc-card {
        padding: 0.75rem;
        gap: 0.5rem;
    }

    .doc-actions {
        flex-direction: column;
        gap: 0.3rem;
    }

    .doc-actions .btn {
        font-size: 0.8rem;
        padding: 0.3rem 0.6rem;
    }

    .bulk-toolbar {
        gap: 0.5rem;
        padding: 0.5rem 0.75rem;
    }

    /* --- Stats page --- */
    .stats-container {
        padding: 1rem;
    }

    .stats-header {
        flex-wrap: wrap;
        gap: 0.75rem;
    }

    .stats-header h1 {
        font-size: 1.3rem;
    }

    .stat-card .stat-value {
        font-size: 1.5rem;
    }

    .stats-cards {
        grid-template-columns: repeat(2, 1fr);
    }

    .chart-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .doc-stat-metrics {
        flex-wrap: wrap;
        gap: 0.75rem;
    }

    /* --- Modals --- */
    .paste-modal-content,
    .url-modal-content {
        min-width: unset;
        max-width: 95vw;
    }
}
