:root {
    --bg: #f5f5f5;
    --container-bg: #ffffff;
    --text: #333333;
    --border: #dddddd;
    --accent: #2c7be5;
    --toolbar-bg: #fafafa;
    --button-hover: #e8e8e8;
}
body.dark {
    --bg: #1a1a1a;
    --container-bg: #2a2a2a;
    --text: #e0e0e0;
    --border: #444444;
    --accent: #4da3ff;
    --toolbar-bg: #242424;
    --button-hover: #3a3a3a;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
    height: 100vh; height: 100dvh;
    display: flex; flex-direction: column; overflow: hidden;
    transition: background 0.3s, color 0.3s; user-select: none;
}
#topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 2px 6px; background: var(--toolbar-bg);
    border-bottom: 1px solid var(--border); flex-shrink: 0;
    flex-wrap: wrap; gap: 2px;
}
#topbar .title { font-size: 13px; font-weight: 600; white-space: nowrap; }
#topbar .actions { display: flex; flex-wrap: wrap; gap: 2px; align-items: center; }
.btn {
    display: flex; align-items: center; justify-content: center;
    padding: 3px 6px; background: transparent; border: 1px solid var(--border);
    border-radius: 4px; color: var(--text); font-size: 11px; cursor: pointer;
    white-space: nowrap; gap: 2px; min-height: 26px;
}
.btn:hover { background: var(--button-hover); border-color: var(--accent); }
.btn .icon { font-size: 12px; }
.btn.icon-only { padding: 3px 6px; font-size: 13px; }
#main {
    flex: 1; display: flex; overflow: hidden; position: relative; min-height: 0;
    cursor: pointer;
}
#drop-area {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 16px; background: var(--bg);
    position: absolute; top: 0; left: 0; right: 0; bottom: 0; z-index: 1;
}
#drop-area .icon { font-size: 48px; }
#drop-area.dragover { outline: 2px dashed var(--accent); outline-offset: -10px; }
#viewer {
    flex: 1; display: none; position: relative; overflow: hidden;
    background: var(--container-bg); min-height: 0; z-index: 2;
}
#epub-viewer { width: 100%; height: 100%; overflow: auto; }
#cover-overlay {
    position: absolute; top: 0; left: 0; right: 0; bottom: 0;
    display: flex; align-items: center; justify-content: center;
    background: var(--container-bg); z-index: 30;
}
#cover-overlay img { max-width: 100%; max-height: 100%; object-fit: contain; }
.click-zone {
    position: absolute; top: 0; bottom: 0; width: 15%;
    z-index: 10; cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}
#zone-left { left: 0; }
#zone-right { right: 0; }
#loading {
    position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
    background: var(--toolbar-bg); border: 1px solid var(--border); border-radius: 8px;
    padding: 20px 30px; font-size: 14px; z-index: 40; display: none;
}
#controls {
    display: none; flex-direction: column; align-items: stretch;
    justify-content: center; gap: 4px; padding: 4px 6px;
    background: var(--toolbar-bg); border-top: 1px solid var(--border);
    flex-shrink: 0; flex-wrap: wrap;
}
.ctrl-row { display: flex; align-items: center; gap: 6px; width: 100%; }
.progress-row { flex-wrap: nowrap; }
.progress-row input[type="range"] { flex: 1; min-width: 0; }
.chapter-row { justify-content: center; }
#chapter-name {
    font-size: 12px; font-weight: 500;
    text-align: center; white-space: normal; overflow: visible;
    text-overflow: clip; max-width: 70vw; flex: 0 1 auto;
}
#page-info {
    font-size: 11px; min-width: 40px; text-align: center; white-space: nowrap;
}
#progress-slider {
    width: auto; cursor: pointer; accent-color: var(--accent); flex-shrink: 0;
}
#progress-percent { font-size: 11px; min-width: 30px; text-align: right; }
#toc-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5);
    z-index: 100; display: none; justify-content: center; align-items: center;
}
#toc-panel {
    background: var(--toolbar-bg); border: 1px solid var(--border); border-radius: 10px;
    width: 80%; max-width: 500px; max-height: 70vh; display: flex; flex-direction: column;
    padding: 16px; box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}
#toc-panel h3 { margin-bottom: 10px; font-size: 16px; text-align: center; }
#toc-list { flex: 1; overflow-y: auto; list-style: none; }
#toc-list li {
    padding: 8px 12px; border-bottom: 1px solid var(--border); cursor: pointer;
    font-size: 13px; transition: background 0.2s;
}
#toc-list li:hover { background: var(--button-hover); }
#toc-close { align-self: flex-end; margin-top: 10px; }
#file-input, #import-progress-file, #import-notes-file { display: none; }

.epub-hl {
    cursor: pointer; border-radius: 2px;
    transition: background-color 0.2s; -webkit-tap-highlight-color: transparent;
}
.epub-hl:hover { filter: brightness(0.95); }

#hl-toolbar {
    position: absolute; background: var(--toolbar-bg); border: 1px solid var(--border);
    border-radius: 8px; padding: 4px; display: none; z-index: 50;
    box-shadow: 0 4px 16px rgba(0,0,0,0.2); gap: 4px; align-items: center;
    touch-action: manipulation;
}
#hl-toolbar.show { display: flex; }
#hl-toolbar button {
    padding: 4px 8px; background: transparent; border: 1px solid var(--border);
    border-radius: 6px; color: var(--text); cursor: pointer; font-size: 11px;
}
#hl-toolbar button:hover { background: var(--button-hover); }

#hl-detail {
    position: fixed; z-index: 200; display: none; background: var(--toolbar-bg);
    border: 1px solid var(--border); border-radius: 10px; padding: 10px; gap: 6px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3); flex-direction: column;
    max-width: 320px; min-width: 220px; touch-action: manipulation;
}
#hl-detail.show { display: flex; }
#hl-detail .hl-detail-text {
    font-size: 12px; color: var(--text); padding: 6px; background: var(--bg);
    border-radius: 6px; border-left: 3px solid var(--accent);
    max-height: 80px; overflow-y: auto; user-select: text;
}
#hl-detail .hl-detail-note {
    font-size: 11px; color: var(--accent); padding: 4px 6px;
    background: rgba(44,123,229,0.08); border-radius: 6px;
    max-height: 60px; overflow-y: auto; user-select: text; display: none; font-style: italic;
}
#hl-detail .hl-detail-time { font-size: 10px; opacity: 0.6; text-align: right; }
#hl-detail .hl-detail-actions { display: flex; gap: 4px; justify-content: flex-end; margin-top: 2px; }
#hl-detail .hl-detail-actions button {
    padding: 3px 8px; background: transparent; border: 1px solid var(--border);
    border-radius: 6px; color: var(--text); cursor: pointer; font-size: 11px;
}
#hl-detail .hl-detail-actions button:hover { background: var(--button-hover); }
#hl-detail .hl-detail-actions button.danger { color: #e53935; border-color: #e53935; }

#note-dialog {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5); z-index: 300; display: none;
    justify-content: center; align-items: center;
}
#note-dialog.show { display: flex; }
.note-dialog-content {
    background: var(--toolbar-bg); border: 1px solid var(--border);
    border-radius: 12px; padding: 12px; width: 90%; max-width: 420px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}
.note-dialog-content h3 { margin-bottom: 6px; font-size: 14px; }
.note-text-preview {
    font-size: 11px; color: var(--text); opacity: 0.7; margin-bottom: 8px;
    padding: 6px; background: var(--bg); border-radius: 6px;
    max-height: 60px; overflow-y: auto; border-left: 3px solid var(--accent);
    user-select: text;
}
#note-textarea {
    width: 100%; min-height: 80px; padding: 8px; border: 1px solid var(--border);
    border-radius: 6px; background: var(--container-bg); color: var(--text);
    font-family: inherit; font-size: 12px; resize: vertical;
}
.note-dialog-actions { display: flex; gap: 6px; justify-content: flex-end; margin-top: 8px; }

@media (max-width: 600px) {
    .btn { padding: 2px 4px; font-size: 10px; min-height: 24px; }
    .btn .icon { font-size: 11px; }
    #topbar .title { font-size: 12px; }
    #progress-slider { width: auto; }
    #chapter-name { font-size: 11px; }
    #page-info { min-width: 30px; font-size: 10px; }
}