/* ============================================================
   CORE VARIABLES & BACKGROUND THEMES
   ============================================================ */
:root {
    --bg: #0b0b12;
    --surface: #16161f;
    --surface2: #1e1e2d;
    --text: #ececf0;
    --text2: #9a9ab0;
    --accent: #7c5cfc;
    --border: #2a2a3f;
    --radius: 12px;
    --sidebar-width: 60px;
    --bg-pattern: none;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    --border-light: rgba(255, 255, 255, 0.06);
    --task-bg: var(--surface);
    --bg-overlay: rgba(0, 0, 0, 0.65);
    --text3: #6a6a8a;
}

.light-mode {
    --bg: #f2f2f7;
    --surface: #fff;
    --surface2: #eaeaef;
    --text: #1c1c26;
    --text2: #5a5a72;
    --border: #d0d0dd;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.06);
    --border-light: rgba(0, 0, 0, 0.06);
    --task-bg: #fff;
    --bg-overlay: rgba(0, 0, 0, 0.45);
    --text3: #8a8aaa;
}

/* ----- Background themes ----- */
.bg-default {
    --bg: #f4f7fc;
    --surface: #fff;
    --surface2: #eaeaef;
    --text: #1c1c26;
    --text2: #5a5a72;
    --border: #d0d0dd;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.06);
}

.bg-ocean {
    --bg: linear-gradient(135deg, #1a2980, #26d0ce);
    --surface: rgba(20, 30, 60, 0.88);
    --surface2: rgba(30, 45, 80, 0.85);
    --text: #f0f4ff;
    --text2: #b0c8ff;
    --border: #3a5a9a;
    --shadow: 0 8px 32px rgba(0, 0, 50, 0.5);
    --bg-pattern: radial-gradient(circle at 20% 80%, rgba(38, 208, 206, 0.15) 0%, transparent 50%);
}

.bg-sunset {
    --bg: linear-gradient(135deg, #f12711, #f5af19);
    --surface: rgba(40, 20, 10, 0.88);
    --surface2: rgba(60, 30, 15, 0.85);
    --text: #fff5e6;
    --text2: #ffd9b3;
    --border: #b06a3a;
    --shadow: 0 8px 32px rgba(100, 30, 0, 0.5);
    --bg-pattern: radial-gradient(circle at 30% 70%, rgba(245, 175, 25, 0.2) 0%, transparent 60%);
}

.bg-forest {
    --bg: linear-gradient(135deg, #0f2027, #203a43, #2c5364);
    --surface: rgba(15, 30, 25, 0.88);
    --surface2: rgba(25, 45, 40, 0.85);
    --text: #e8f0ec;
    --text2: #a0c0b0;
    --border: #2a5a4a;
    --shadow: 0 8px 32px rgba(0, 20, 10, 0.5);
    --bg-pattern: radial-gradient(circle at 20% 80%, rgba(46, 204, 113, 0.15) 0%, transparent 50%);
}

.bg-night {
    --bg: linear-gradient(135deg, #0c0e1a, #1a1a3e, #2d1b4e);
    --surface: rgba(15, 15, 35, 0.88);
    --surface2: rgba(25, 25, 55, 0.85);
    --text: #e8e0f0;
    --text2: #b0a0cc;
    --border: #3a2a6a;
    --shadow: 0 8px 32px rgba(0, 0, 30, 0.6);
    --bg-pattern: radial-gradient(circle at 30% 20%, rgba(255, 255, 255, 0.05) 0%, transparent 40%),
        radial-gradient(circle at 70% 60%, rgba(255, 255, 200, 0.04) 0%, transparent 30%);
}

.bg-beach {
    --bg: linear-gradient(180deg, #f7dc6f 0%, #f5b041 30%, #5dade2 60%, #1a5276 100%);
    --surface: rgba(30, 40, 50, 0.88);
    --surface2: rgba(40, 55, 70, 0.85);
    --text: #f0f8ff;
    --text2: #b0d4e8;
    --border: #3a7a9a;
    --shadow: 0 8px 32px rgba(0, 30, 50, 0.5);
    --bg-pattern: radial-gradient(ellipse at 10% 90%, rgba(255, 255, 200, 0.1) 0%, transparent 40%);
}

.bg-modern {
    --bg: linear-gradient(135deg, #0c0e1a, #1a1a3e);
    --surface: rgba(15, 15, 35, 0.88);
    --surface2: rgba(25, 25, 55, 0.85);
    --text: #e8e0f0;
    --text2: #b0a0cc;
    --border: #3a3a6a;
    --shadow: 0 8px 32px rgba(0, 0, 30, 0.6);
    --bg-pattern: repeating-linear-gradient(45deg, rgba(108, 92, 231, 0.06) 0px, rgba(108, 92, 231, 0.06) 2px, transparent 2px, transparent 8px),
        repeating-linear-gradient(-45deg, rgba(108, 92, 231, 0.06) 0px, rgba(108, 92, 231, 0.06) 2px, transparent 2px, transparent 8px);
}

.bg-city {
    --bg: linear-gradient(180deg, #0c0e1a 0%, #1a1a3e 40%, #2d1b4e 70%, #1a1a3e 100%);
    --surface: rgba(15, 15, 35, 0.88);
    --surface2: rgba(25, 25, 55, 0.85);
    --text: #e8e0f0;
    --text2: #b0a0cc;
    --border: #3a3a6a;
    --shadow: 0 8px 32px rgba(0, 0, 30, 0.6);
    --bg-pattern: radial-gradient(ellipse at 10% 90%, rgba(255, 200, 100, 0.08) 0%, transparent 30%),
        radial-gradient(ellipse at 90% 85%, rgba(255, 200, 100, 0.06) 0%, transparent 25%),
        radial-gradient(ellipse at 50% 95%, rgba(255, 200, 100, 0.04) 0%, transparent 40%);
}

.bg-lavender {
    --bg: linear-gradient(135deg, #8e44ad, #9b59b6, #a29bfe);
    --surface: rgba(40, 20, 60, 0.88);
    --surface2: rgba(55, 30, 80, 0.85);
    --text: #f4eef8;
    --text2: #c8b0e0;
    --border: #6a4a8a;
    --shadow: 0 8px 32px rgba(40, 0, 60, 0.5);
    --bg-pattern: radial-gradient(circle at 70% 30%, rgba(162, 155, 254, 0.2) 0%, transparent 60%);
}

.bg-autumn {
    --bg: linear-gradient(135deg, #d35400, #f39c12, #e67e22);
    --surface: rgba(40, 20, 10, 0.88);
    --surface2: rgba(60, 30, 15, 0.85);
    --text: #fef6e6;
    --text2: #f5d5a0;
    --border: #b06a3a;
    --shadow: 0 8px 32px rgba(80, 30, 0, 0.5);
    --bg-pattern: radial-gradient(circle at 30% 80%, rgba(243, 156, 18, 0.15) 0%, transparent 50%);
}

.bg-aurora {
    --bg: linear-gradient(135deg, #0f0c29, #302b63, #24243e);
    --surface: rgba(15, 12, 40, 0.88);
    --surface2: rgba(30, 25, 60, 0.85);
    --text: #e8e0f8;
    --text2: #b0a0d0;
    --border: #4a3a7a;
    --shadow: 0 8px 32px rgba(0, 0, 40, 0.6);
    --bg-pattern: radial-gradient(ellipse at 20% 30%, rgba(0, 255, 200, 0.06) 0%, transparent 40%),
        radial-gradient(ellipse at 80% 70%, rgba(255, 0, 200, 0.06) 0%, transparent 40%),
        radial-gradient(ellipse at 50% 50%, rgba(0, 200, 255, 0.04) 0%, transparent 50%);
}

.bg-rose {
    --bg: linear-gradient(135deg, #ff6b6b, #ee5a24, #6c5ce7);
    --surface: rgba(40, 20, 30, 0.88);
    --surface2: rgba(60, 30, 45, 0.85);
    --text: #fef0f0;
    --text2: #f5b0b0;
    --border: #9a4a6a;
    --shadow: 0 8px 32px rgba(80, 0, 30, 0.5);
    --bg-pattern: radial-gradient(circle at 50% 50%, rgba(255, 255, 200, 0.1) 0%, transparent 60%);
}

.bg-spring {
    --bg: linear-gradient(135deg, #11998e, #38ef7d);
    --surface: rgba(15, 40, 30, 0.88);
    --surface2: rgba(25, 60, 45, 0.85);
    --text: #e8f8ec;
    --text2: #a0d8b0;
    --border: #2a7a5a;
    --shadow: 0 8px 32px rgba(0, 40, 20, 0.5);
    --bg-pattern: radial-gradient(circle at 70% 30%, rgba(56, 239, 125, 0.15) 0%, transparent 60%);
}

.bg-charcoal {
    --bg: linear-gradient(135deg, #1a1a1a, #2a2a2a);
    --surface: rgba(30, 30, 30, 0.88);
    --surface2: rgba(40, 40, 40, 0.85);
    --text: #e8e8f0;
    --text2: #b0b0b0;
    --border: #4a4a4a;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.7);
    --bg-pattern: none;
}

.bg-deepspace {
    --bg: linear-gradient(135deg, #0b0b1a, #1a1a3e, #2d1b4e);
    --surface: rgba(15, 15, 35, 0.88);
    --surface2: rgba(25, 25, 55, 0.85);
    --text: #e8e8f0;
    --text2: #b0b0cc;
    --border: #3a3a6a;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.8);
    --bg-pattern: radial-gradient(1px 1px at 10% 20%, rgba(255, 255, 255, 0.4), transparent),
        radial-gradient(1px 1px at 80% 70%, rgba(255, 255, 255, 0.3), transparent),
        radial-gradient(1.5px 1.5px at 50% 90%, rgba(255, 255, 255, 0.5), transparent),
        radial-gradient(1px 1px at 90% 10%, rgba(255, 255, 255, 0.2), transparent);
}

.bg-minimal {
    --bg: #ffffff;
    --surface: rgba(240, 240, 245, 0.7);
    --surface2: rgba(230, 230, 235, 0.8);
    --text: #1a1a2e;
    --text2: #4a4a6a;
    --border: #d0d0dd;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.04);
    --bg-pattern: none;
    --task-bg: #ffffff;
    --bg-overlay: rgba(0, 0, 0, 0.3);
    --text3: #8a8aaa;
}

.bg-cream {
    --bg: #fdfbf7;
    --surface: rgba(255, 252, 245, 0.85);
    --surface2: rgba(245, 240, 230, 0.8);
    --text: #2a2418;
    --text2: #5a5040;
    --border: #d0c8b8;
    --shadow: 0 8px 32px rgba(160, 130, 100, 0.08);
    --bg-pattern: none;
    --task-bg: #ffffff;
    --bg-overlay: rgba(0, 0, 0, 0.25);
    --text3: #8a8070;
}

/* ----- Apply background to #app ----- */
#app {
    background: var(--bg);
    transition: background 0.5s ease, color 0.3s ease;
    position: relative;
    min-height: 100vh;
    font-family: 'Inter', sans-serif;
    color: var(--text);
}

#app::before {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--bg-pattern);
    pointer-events: none;
    z-index: 0;
}

#app>* {
    position: relative;
    z-index: 1;
}

/* ============================================================
   MODAL – PERFECTLY CENTERED WITH SEMI-TRANSPARENT OVERLAY
   ============================================================ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-overlay);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.25s ease;
}

.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px 28px;
    width: 100%;
    max-width: 460px;
    max-height: 88vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    margin: 0 16px;
    color: var(--text);
}

.modal h2 {
    margin-bottom: 12px;
    font-size: 1.2rem;
    font-weight: 700;
}

.modal .field-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 14px;
    margin-top: 6px;
}

.modal label {
    display: block;
    font-size: 0.7rem;
    color: var(--text2);
    margin-top: 6px;
    font-weight: 500;
}

.modal input,
.modal select,
.modal textarea {
    width: 100%;
    padding: 6px 10px;
    border-radius: 6px;
    border: 1.5px solid var(--border);
    background: var(--surface2);
    color: var(--text);
    font-size: 0.8rem;
    margin-top: 2px;
    outline: none;
    transition: border-color 0.2s;
}

.modal input:focus,
.modal select:focus,
.modal textarea:focus {
    border-color: var(--accent);
}

#starPicker {
    font-size: 1.3rem;
    letter-spacing: 4px;
    cursor: pointer;
    color: var(--text2);
    padding: 4px 0;
}

#starPicker .star-on {
    color: #fbbf24;
}

.modal .actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

/* ============================================================
   REST OF STYLES
   ============================================================ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg);
    color: var(--text);
    transition: 0.3s;
}

.app-layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px 0;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 20;
    overflow-y: auto;
}

.sidebar-btn {
    width: 44px;
    height: 44px;
    margin: 4px 0;
    border-radius: 10px;
    border: none;
    background: transparent;
    color: var(--text2);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 0.55rem;
    padding: 4px;
    transition: 0.2s;
    position: relative;
}

.sidebar-btn .icon {
    font-size: 1.3rem;
    line-height: 1;
}

.sidebar-btn span {
    font-size: 0.4rem;
    margin-top: 1px;
}

.sidebar-btn:hover,
.sidebar-btn.active {
    background: var(--surface2);
    color: var(--text);
}

.sidebar-btn.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 20%;
    height: 60%;
    width: 3px;
    background: var(--accent);
    border-radius: 0 3px 3px 0;
}

.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    padding: 14px 18px 30px;
    max-width: 1200px;
}

.view {
    display: none;
    animation: fadeIn 0.2s;
}

.view.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.header {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 16px;
    padding: 10px 16px;
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.header h1 {
    font-size: 1.2rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent), #5b8def);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.header-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 5px 12px;
    border-radius: 50px;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid var(--border);
    background: var(--surface2);
    color: var(--text);
    transition: 0.2s;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.btn-primary:hover {
    opacity: 0.85;
}

.btn-sm {
    padding: 3px 8px;
    font-size: 0.65rem;
}

.btn-danger {
    border-color: #f87171;
    color: #f87171;
}

.btn-danger:hover {
    background: #f87171;
    color: #fff;
}

.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
    gap: 10px;
    margin-bottom: 14px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px;
    text-align: center;
}

.stat-number {
    font-size: 1.4rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--accent), #5b8def);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.stat-label {
    font-size: 0.55rem;
    color: var(--text2);
    text-transform: uppercase;
}

.filters-bar {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 14px;
    padding: 6px 12px;
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    align-items: center;
}

.filters-bar .search-input {
    flex: 1;
    min-width: 120px;
    padding: 4px 10px;
    border-radius: 50px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: 0.75rem;
    outline: none;
}

.filters-bar select {
    padding: 4px 10px;
    border-radius: 50px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: 0.75rem;
}

.book-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 12px;
}

.book-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    display: flex;
    gap: 10px;
    position: relative;
    transition: 0.2s;
}

.book-card:hover {
    transform: translateY(-2px);
    border-color: var(--accent);
}

.book-cover {
    width: 44px;
    height: 64px;
    border-radius: 6px;
    flex-shrink: 0;
    background: var(--surface2);
    background-size: cover;
    background-position: center;
    border: 1px solid var(--border);
}

.book-info {
    flex: 1;
    min-width: 0;
}

.book-title {
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 0.9rem;
}

.book-author {
    font-size: 0.65rem;
    color: var(--text2);
}

.tag {
    display: inline-block;
    font-size: 0.5rem;
    padding: 1px 5px;
    background: var(--accent);
    color: #fff;
    border-radius: 20px;
    margin: 2px 2px 0 0;
    opacity: 0.8;
}

.progress-bar-wrap {
    height: 3px;
    background: var(--surface2);
    border-radius: 10px;
    overflow: hidden;
    margin: 4px 0;
}

.progress-bar-fill {
    height: 100%;
    border-radius: 10px;
    background: var(--accent);
    transition: width 0.3s;
}

.status-badge {
    position: absolute;
    top: 6px;
    right: 6px;
    font-size: 0.5rem;
    padding: 1px 6px;
    border-radius: 50px;
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--text2);
}

.book-actions {
    display: flex;
    gap: 4px;
    margin-top: 4px;
    flex-wrap: wrap;
}

.book-actions .btn-sm {
    font-size: 0.55rem;
    padding: 2px 6px;
}

#readerView {
    padding: 0;
    background: var(--bg);
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border);
    min-height: 65vh;
}

.reader-layout {
    display: flex;
    min-height: 65vh;
    background: var(--bg);
}

.reader-sidebar {
    width: 240px;
    min-width: 240px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 12px;
    overflow-y: auto;
    max-height: 65vh;
    gap: 4px;
}

.reader-sidebar .brand {
    display: flex;
    align-items: center;
    gap: 6px;
}

.reader-sidebar .brand-mark {
    font-weight: 700;
    font-size: 16px;
    background: linear-gradient(135deg, var(--accent), #5b8def);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.reader-sidebar .upload-zone {
    border: 1.5px dashed var(--border);
    border-radius: 8px;
    padding: 8px;
    text-align: center;
    cursor: pointer;
    transition: 0.2s;
}

.reader-sidebar .upload-zone:hover {
    border-color: var(--accent);
    background: var(--surface2);
}

.reader-sidebar .upload-zone .title {
    font-weight: 600;
    font-size: 10px;
}

.reader-sidebar .upload-zone .hint {
    font-size: 8px;
    opacity: 0.5;
}

.reader-sidebar input[type="file"] {
    display: none;
}

.reader-sidebar .browse-btn {
    width: 100%;
    padding: 4px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 6px;
    font-weight: 600;
    font-size: 9px;
    cursor: pointer;
    margin-top: 2px;
}

.reader-sidebar .browse-btn:hover {
    opacity: 0.85;
}

.reader-sidebar .url-load-box input {
    width: 100%;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 3px 6px;
    color: var(--text);
    font-size: 9px;
    outline: none;
}

.reader-sidebar .url-load-box button {
    width: 100%;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 4px;
    font-weight: 600;
    font-size: 9px;
    margin-top: 2px;
    cursor: pointer;
}

.reader-sidebar .doc-meta {
    display: none;
    border-top: 1px solid var(--border);
    padding-top: 4px;
    margin-top: 4px;
}

.reader-sidebar .doc-meta.show {
    display: block;
}

.reader-sidebar .doc-title {
    font-weight: 600;
    font-size: 11px;
}

.reader-sidebar .doc-stats {
    font-size: 8px;
    opacity: 0.6;
}

.reader-sidebar .overall-progress {
    height: 3px;
    background: var(--surface2);
    border-radius: 4px;
    margin: 4px 0;
    display: none;
}

.reader-sidebar .overall-progress.show {
    display: block;
}

.reader-sidebar .overall-progress-fill {
    height: 100%;
    background: var(--accent);
    width: 0%;
    transition: width 0.3s;
}

.reader-sidebar .page-nav {
    max-height: 80px;
    overflow-y: auto;
    margin-top: 4px;
    display: none;
    border-top: 1px solid var(--border);
    padding-top: 4px;
}

.reader-sidebar .page-nav.show {
    display: block;
}

.reader-sidebar .page-nav-label {
    font-size: 7px;
    text-transform: uppercase;
    color: var(--text2);
    opacity: 0.4;
    display: flex;
    justify-content: space-between;
    position: sticky;
    top: 0;
    background: var(--surface);
    z-index: 1;
}

.reader-sidebar .page-chip {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 2px 4px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 9px;
    color: var(--text2);
    transition: 0.15s;
    border-left: 3px solid transparent;
}

.reader-sidebar .page-chip:hover {
    background: var(--surface2);
    color: var(--text);
}

.reader-sidebar .page-chip.active {
    background: var(--surface2);
    color: var(--text);
    border-left-color: var(--accent);
}

.reader-sidebar .page-chip .num {
    font-family: monospace;
    color: var(--accent);
    width: 18px;
    text-align: right;
    font-weight: 700;
    flex-shrink: 0;
    font-size: 8px;
}

.reader-sidebar .page-chip .excerpt {
    flex: 1;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    font-size: 8px;
}

.reader-sidebar .general-notes-area textarea {
    width: 100%;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 2px 4px;
    color: var(--text);
    font-size: 8px;
    resize: vertical;
    min-height: 24px;
    outline: none;
}

.reader-sidebar .general-notes-area textarea:focus {
    border-color: var(--accent);
}

.reader-sidebar .annotations-panel {
    border-top: 1px solid var(--border);
    padding-top: 4px;
    margin-top: 4px;
    display: none;
    max-height: 120px;
    overflow-y: auto;
}

.reader-sidebar .annotations-panel.show {
    display: block;
}

.reader-sidebar .annotations-panel .title {
    font-size: 7px;
    text-transform: uppercase;
    color: var(--text2);
    opacity: 0.4;
    display: flex;
    justify-content: space-between;
}

.reader-sidebar .annotations-panel .anno-item {
    font-size: 8px;
    padding: 2px 4px;
    border-left: 2px solid var(--accent);
    margin-bottom: 2px;
    background: var(--surface2);
    border-radius: 2px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 4px;
}

.reader-sidebar .annotations-panel .anno-item .page-num {
    color: var(--accent);
    font-weight: 700;
    min-width: 18px;
}

.reader-sidebar .annotations-panel .anno-item .del-anno {
    cursor: pointer;
    color: var(--text2);
    opacity: 0.4;
    font-size: 9px;
}

.reader-sidebar .annotations-panel .anno-item .del-anno:hover {
    opacity: 1;
    color: #f87171;
}

.reader-sidebar .sidebar-footer {
    font-size: 7px;
    opacity: 0.2;
    border-top: 1px solid var(--border);
    padding-top: 4px;
    margin-top: 4px;
}

#selectionToolbar {
    position: fixed;
    background: var(--surface);
    border: 1px solid var(--accent);
    border-radius: 8px;
    padding: 4px 6px;
    display: none;
    z-index: 999;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    gap: 4px;
    align-items: center;
    backdrop-filter: blur(8px);
}

#selectionToolbar button {
    background: transparent;
    border: none;
    color: var(--text);
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 11px;
}

#selectionToolbar button:hover {
    background: var(--surface2);
}

#selectionToolbar .sep {
    width: 1px;
    height: 16px;
    background: var(--border);
}

.reader-main .page-content .word.highlighted {
    background: #fbbf24;
    color: #1c1c26;
    border-radius: 2px;
    padding: 0 1px;
    cursor: pointer;
}

.reader-main .page-content .word.highlighted:hover {
    filter: brightness(1.2);
}

.reader-main .read-toolbar {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 4px 10px;
    margin-bottom: 8px;
}

.reader-main .read-toolbar .btn-icon {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--surface2);
    color: var(--text);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
}

.reader-main .read-toolbar .btn-icon.primary {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
    width: 30px;
    height: 30px;
    font-size: 13px;
}

.reader-main .read-toolbar .btn-icon:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.reader-main .read-toolbar select {
    padding: 2px 4px;
    border-radius: 4px;
    border: 1px solid var(--border);
    background: var(--surface2);
    color: var(--text);
    font-size: 8px;
}

.reader-main .read-toolbar .rate-slider {
    width: 50px;
    accent-color: var(--accent);
}

.reader-main .read-toolbar .page-indicator {
    font-family: monospace;
    font-size: 9px;
    color: var(--text2);
    margin-left: auto;
}

.reader-main .page-content {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 24px;
    flex: 1;
    font-family: 'Fraunces', serif;
    font-size: 16px;
    line-height: 1.6;
    color: var(--text);
    max-width: 660px;
    margin: 0 auto;
    width: 100%;
    overflow-y: auto;
    min-height: 180px;
    user-select: text;
}

.reader-main .page-content .word {
    transition: 0.1s;
    border-radius: 2px;
    padding: 0 1px;
    cursor: default;
}

.reader-main .page-content .word:hover {
    background: rgba(124, 92, 252, 0.08);
}

.reader-main .page-content .word.speaking {
    background: var(--accent);
    color: #fff;
}

.reader-main .page-content.empty {
    color: var(--text2);
    opacity: 0.3;
    font-style: italic;
    display: flex;
    align-items: center;
    justify-content: center;
}

.reader-main .note-area textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 10px;
    background: var(--surface);
    color: var(--text);
    resize: vertical;
    min-height: 28px;
    outline: none;
}

.reader-main .note-area textarea:focus {
    border-color: var(--accent);
}

.ai-view {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 55vh;
}

.ai-view .toolbar {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 12px;
    margin-bottom: 12px;
    align-items: center;
}

.ai-view .toolbar select,
.ai-view .toolbar input {
    padding: 3px 8px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--surface2);
    color: var(--text);
    font-size: 0.7rem;
    outline: none;
}

.ai-view .toolbar select:focus {
    border-color: var(--accent);
}

.ai-view .toolbar label {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.7rem;
    color: var(--text2);
}

.ai-view .chat-log {
    flex: 1;
    overflow-y: auto;
    padding: 4px 0 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 340px;
    min-height: 140px;
}

.ai-view .msg {
    max-width: 80%;
    padding: 6px 12px;
    border-radius: 12px;
    font-size: 13px;
    line-height: 1.4;
}

.ai-view .msg.user {
    align-self: flex-end;
    background: var(--accent);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.ai-view .msg.assistant {
    align-self: flex-start;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

.ai-view .msg.thinking {
    align-self: flex-start;
    color: var(--text2);
    font-style: italic;
    font-size: 12px;
    opacity: 0.6;
}

.ai-view .input-row {
    display: flex;
    gap: 6px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
}

.ai-view .input-row textarea {
    flex: 1;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 12px;
    height: 36px;
    background: var(--surface2);
    color: var(--text);
    resize: none;
    outline: none;
}

.ai-view .input-row textarea:focus {
    border-color: var(--accent);
}

.ai-view .input-row .send-btn {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 0 14px;
    font-weight: 600;
    cursor: pointer;
}

.ai-view .input-row .send-btn:hover {
    opacity: 0.85;
}

.ai-view .input-row .send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.ai-view .output-pane {
    flex: 1;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 18px;
    overflow-y: auto;
    min-height: 140px;
    max-height: 420px;
    font-size: 13px;
    line-height: 1.6;
}

.ai-view .output-pane .placeholder {
    color: var(--text2);
    opacity: 0.4;
    font-style: italic;
}

.ai-view .progress-bar {
    height: 3px;
    background: var(--surface2);
    border-radius: 4px;
    overflow: hidden;
    margin: 6px 0;
    display: none;
}

.ai-view .progress-bar.show {
    display: block;
}

.ai-view .progress-bar .fill {
    height: 100%;
    background: var(--accent);
    width: 0%;
    transition: width 0.3s;
}

.ai-view .status-msg {
    font-size: 9px;
    color: var(--text2);
    opacity: 0.6;
    margin-top: 4px;
    min-height: 14px;
}

.settings-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 16px;
    margin-bottom: 12px;
}

.settings-card label {
    font-size: 0.7rem;
    color: var(--text2);
    display: block;
    margin-bottom: 4px;
}

.settings-card input[type="password"] {
    width: 100%;
    padding: 4px 10px;
    border-radius: 6px;
    border: 1.5px solid var(--border);
    background: var(--surface2);
    color: var(--text);
    font-size: 0.8rem;
    outline: none;
}

.settings-card input:focus {
    border-color: var(--accent);
}

.settings-card .hint {
    font-size: 0.6rem;
    color: var(--text2);
    opacity: 0.5;
    margin-top: 4px;
}

#toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--surface);
    border: 1px solid var(--accent);
    color: var(--text);
    padding: 6px 16px;
    border-radius: 50px;
    z-index: 200;
    opacity: 0;
    transition: 0.3s;
    font-weight: 500;
    font-size: 0.8rem;
    white-space: nowrap;
}

#toast.show {
    opacity: 1;
}

@media (max-width:760px) {
    .reader-sidebar {
        width: 100%;
        min-width: unset;
        max-height: 200px;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
    .reader-layout {
        flex-direction: column;
    }
    .book-grid {
        grid-template-columns: 1fr;
    }
    .modal .field-group {
        grid-template-columns: 1fr;
    }
    .main-content {
        padding: 8px;
    }
}

@media (max-width:500px) {
    :root {
        --sidebar-width: 48px;
    }
    .sidebar-btn {
        width: 36px;
        height: 36px;
        font-size: 0.45rem;
    }
    .sidebar-btn .icon {
        font-size: 1rem;
    }
    .main-content {
        margin-left: 48px;
        padding: 6px;
    }
    .modal {
        padding: 16px 18px;
        max-width: 96%;
        margin: 0 8px;
    }
}