/* ========== Reset & Variables ========== */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --primary: #0891b2;
    --primary-light: #ecfeff;
    --primary-dark: #0e7490;
    --primary-soft: #cffafe;
    --success: #059669;
    --warning: #d97706;
    --danger: #dc2626;
    --bg: #f0f9fa;
    --card-bg: #ffffff;
    --text: #164e63;
    --text-secondary: #5b8c9e;
    --border: #cbd5e1;
    --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-lg: 0 10px 25px rgba(0,0,0,0.08);
    --radius: 8px;
    --radius-lg: 12px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.6;
}

/* ========== Top Bar ========== */
.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}

.logo {
    font-size: 18px;
    font-weight: 700;
    color: var(--primary);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* ========== Buttons ========== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
    white-space: nowrap;
}

.btn-primary {
    background: var(--primary);
    color: white;
}
.btn-primary:hover { background: var(--primary-dark); }

.btn-outline {
    background: white;
    color: var(--text);
    border: 1px solid var(--border);
}
.btn-outline:hover { background: var(--bg); border-color: var(--primary); }

.btn-sm {
    padding: 5px 12px;
    font-size: 13px;
}

.btn-close {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    padding: 2px 6px;
    color: var(--text-secondary);
    border-radius: 4px;
}
.btn-close:hover { background: var(--bg); color: var(--text); }

.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--primary);
    color: white;
    font-size: 11px;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    padding: 0 6px;
}

/* ========== User Info ========== */
.user-info {
    display: flex;
    align-items: center;
    gap: 8px;
}
.user-name {
    font-size: 13px;
    color: var(--text-secondary);
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.btn-logout {
    color: var(--danger) !important;
    border-color: var(--danger) !important;
}
.btn-logout:hover {
    background: #fef2f2 !important;
}
.avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid var(--primary-light);
}
.hidden { display: none !important; }

/* ========== Main Layout ========== */
.main-container {
    display: flex;
    height: calc(100vh - 58px);
    overflow: hidden;
}

.reader-panel {
    flex: 1;
    overflow-y: auto;
    padding: 32px;
    transition: margin-right 0.3s;
}

.reader-panel.shifted {
    margin-right: 380px;
}

/* ========== Article ========== */
.article-toolbar {
    margin-bottom: 24px;
    max-width: var(--reader-max-width, 780px);
    margin-left: auto;
    margin-right: auto;
}

.article-title-input {
    width: 100%;
    border: none;
    font-size: 28px;
    font-weight: 700;
    color: var(--text);
    background: transparent;
    outline: none;
    padding: 4px 0;
    border-bottom: 2px solid transparent;
}
.article-title-input:focus {
    border-bottom-color: var(--primary);
}

.article-content {
    max-width: var(--reader-max-width, 780px);
    margin: 0 auto;
    font-size: var(--article-font-size, 18px);
    line-height: var(--reader-line-height, 1.6);
    letter-spacing: 0.3px;
}

.article-content p {
    margin-bottom: 20px;
    position: relative;
    padding-right: 30px;
    line-height: var(--reader-line-height, 1.6);
}

/* ========== Article Editor (Edit Mode) ========== */
.article-editor {
    width: 100%;
    min-height: 400px;
    max-width: var(--reader-max-width, 780px);
    margin: 0 auto;
    display: block;
    font-size: var(--article-font-size, 18px);
    line-height: var(--reader-line-height, 1.6);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    padding: 16px;
    border: 2px solid var(--primary);
    border-radius: 8px;
    resize: vertical;
    outline: none;
    color: var(--text);
    background: var(--card-bg);
    transition: border-color 0.2s;
}

.article-editor:focus {
    border-color: var(--primary-dark);
    box-shadow: 0 0 0 3px var(--primary-light);
}

[data-theme="dark"] .article-editor {
    color: var(--text);
    background: var(--card-bg);
    border-color: var(--primary);
}

[data-theme="dark"] .article-editor:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(8, 145, 178, 0.2);
}

/* ========== Clickable Words ========== */
.word {
    cursor: pointer;
    padding: 1px 3px;
    border-radius: 3px;
    transition: background 0.15s;
    position: relative;
    display: inline;
}

.word:hover {
    background: var(--primary-light);
    color: var(--primary);
}

.word.annotated {
    border-bottom: 2px solid var(--primary);
    background: rgba(8, 145, 178, 0.08);
}

.word-annotation {
    display: inline;
    font-size: var(--reader-annot-font-size, 10px);
    color: var(--primary);
    font-weight: 500;
    margin-left: 1px;
    vertical-align: super;
    line-height: 1;
    opacity: 0.8;
}

.word-highlight {
    background: rgba(79, 70, 229, 0.12);
    border-radius: 3px;
    padding: 1px 3px;
}

/* ========== Paragraph Translate Trigger ========== */
.para-translate-trigger {
    display: inline;
    cursor: pointer;
    color: var(--primary);
    font-size: 14px;
    margin-left: 2px;
    opacity: 0;
    transition: opacity 0.2s;
    user-select: none;
    vertical-align: middle;
}

p:hover .para-translate-trigger {
    opacity: 0.6;
}

.para-translate-trigger:hover {
    opacity: 1 !important;
}

.para-translate-trigger.loading {
    animation: spin 1s linear infinite;
    opacity: 1;
}

/* ========== Inline Paragraph Translation ========== */
.para-translation-inline {
    margin: 8px 0 12px 0;
    padding: 10px 14px;
    background: var(--primary-light);
    border-left: 3px solid var(--primary);
    border-radius: 0 var(--radius) var(--radius) 0;
    font-size: 14px;
    line-height: 1.8;
    color: var(--text);
    animation: fadeIn 0.2s ease-out;
    position: relative;
}

.para-translation-inline .pt-close {
    position: absolute;
    top: 6px;
    right: 10px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-secondary);
    padding: 2px 4px;
    border-radius: 4px;
}
.para-translation-inline .pt-close:hover {
    color: var(--danger);
    background: #fef2f2;
}

/* ========== Wordbook Panel ========== */
.wordbook-panel {
    width: 380px;
    min-width: 380px;
    background: var(--card-bg);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: fixed;
    right: 0;
    top: 58px;
    bottom: 0;
    z-index: 50;
    box-shadow: var(--shadow-lg);
}

.wordbook-panel.hidden {
    display: none;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.panel-header h3 { font-size: 16px; }

.panel-search {
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
}

.panel-search input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    outline: none;
}
.panel-search input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(8,145,178,0.1);
}

.panel-actions {
    display: flex;
    gap: 8px;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
}

.word-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px 20px;
}

.empty-state {
    text-align: center;
    color: var(--text-secondary);
    padding: 40px 20px;
    font-size: 14px;
}

/* ========== Word Item ========== */
.word-item {
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 8px;
    transition: all 0.15s;
}

.word-item:hover {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(8,145,178,0.08);
}

.word-item-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}

.word-item-word {
    font-weight: 600;
    font-size: 15px;
    color: var(--primary);
}

.word-item-phonetic {
    font-size: 12px;
    color: var(--text-secondary);
}

.word-item-actions {
    display: flex;
    gap: 4px;
}

.word-item-actions button {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 13px;
    padding: 2px 4px;
    color: var(--text-secondary);
    border-radius: 4px;
}

.word-item-actions button:hover {
    color: var(--danger);
    background: #fef2f2;
}

.word-item-meaning {
    font-size: 14px;
    color: var(--text);
    padding: 4px 8px;
    border-radius: 4px;
    display: inline-block;
    cursor: pointer;
    margin: 2px;
    background: var(--primary-light);
    border: 1px solid transparent;
}

.word-item-meaning:hover {
    border-color: var(--primary);
}

.word-item-meaning.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.word-item-meanings {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

/* ========== Popover ========== */
.popover {
    position: fixed;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    z-index: 200;
    min-width: 300px;
    max-width: 400px;
    animation: popoverIn 0.15s ease-out;
}

@keyframes popoverIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

.popover-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
}

.popover-word {
    font-size: 20px;
    font-weight: 700;
    color: var(--primary);
}

.popover-word-row {
    display: flex;
    align-items: baseline;
    gap: 6px;
}

.popover-original-word {
    font-size: 14px;
    font-weight: 400;
    color: var(--text-secondary);
    white-space: nowrap;
}

.popover-phonetic {
    font-size: 14px;
    color: var(--text-secondary);
}

.btn-pronounce {
    background: none;
    border: 1px solid var(--border);
    border-radius: 50%;
    width: 30px;
    height: 30px;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    margin-left: auto;
    margin-right: 4px;
}

.btn-pronounce:hover {
    background: var(--primary-light);
    border-color: var(--primary);
}

.popover-body {
    padding: 12px 16px;
    max-height: 260px;
    overflow-y: auto;
}

.def-item {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.1s;
    margin-bottom: 4px;
    border: 1px solid transparent;
}

.def-item:hover {
    background: var(--primary-soft);
    border-color: var(--primary);
}

.def-item.selected {
    background: var(--primary-light);
    border-color: var(--primary);
}

.def-pos {
    font-size: 12px;
    color: var(--text-secondary);
    background: var(--bg);
    padding: 2px 6px;
    border-radius: 4px;
    white-space: nowrap;
    flex-shrink: 0;
    margin-top: 2px;
}

.def-text {
    font-size: 14px;
    color: var(--text);
    flex: 1;
}

.def-check {
    color: var(--primary);
    font-size: 16px;
    flex-shrink: 0;
    margin-top: 1px;
}

.def-notfound {
    cursor: default;
    color: var(--text-secondary);
    background: #fefce8;
    border-color: #fef08a;
}

.def-notfound:hover {
    background: #fefce8;
    border-color: #fef08a;
}

.def-notfound .def-text {
    color: #92400e;
    font-size: 13px;
}

.popover-footer {
    padding: 10px 16px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.popover-footer .danger-btn {
    color: var(--danger);
    border-color: var(--danger);
}

.popover-footer .danger-btn:hover {
    background: #fef2f2;
    border-color: var(--danger);
}

.popover-source {
    font-size: 11px;
    color: var(--text-secondary);
    padding: 2px 8px;
    background: var(--bg);
    border-radius: 10px;
}

.loading-spinner {
    text-align: center;
    color: var(--text-secondary);
    padding: 20px;
    font-size: 14px;
}

/* ========== Modal ========== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 300;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.15s;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 24px;
    min-width: 360px;
    box-shadow: var(--shadow-lg);
}

.modal h4 {
    margin-bottom: 16px;
    font-size: 16px;
}

.modal input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 15px;
    outline: none;
    margin-bottom: 16px;
}

.modal input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(8,145,178,0.1);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* ========== Paragraph Translation ========== */
.paragraph-translation {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 450px;
    max-height: 400px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    z-index: 150;
    display: flex;
    flex-direction: column;
    animation: slideUp 0.2s ease-out;
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.paragraph-translation.hidden { display: none; }

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

.pt-content {
    padding: 16px;
    overflow-y: auto;
    flex: 1;
    font-size: 15px;
    line-height: 1.8;
    color: var(--text);
}

/* ========== Toast ========== */
.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text);
    color: white;
    padding: 10px 24px;
    border-radius: 20px;
    font-size: 14px;
    z-index: 400;
    animation: toastIn 0.3s ease-out;
    box-shadow: var(--shadow-lg);
}

@keyframes toastIn {
    from { opacity: 0; transform: translateX(-50%) translateY(10px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.toast.hidden { display: none; }

/* ========== Scrollbar ========== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ========== Responsive ========== */

/* --- 平板 + 手机 (≤768px) --- */
@media (max-width: 768px) {
    /* === Top Bar === */
    .top-bar {
        padding: 8px 12px;
        gap: 4px;
        flex-wrap: nowrap;
        overflow: hidden;
    }
    .logo {
        font-size: 14px;
        white-space: nowrap;
        margin-right: 2px;
    }
    .header-left {
        gap: 4px;
        min-width: 0;
    }
    .header-actions {
        gap: 4px;
        min-width: 0;
    }
    /* 按钮隐藏文字，仅显示 emoji 图标 */
    .btn {
        padding: 5px 8px;
        font-size: 13px;
        gap: 2px;
        line-height: 1.2;
        white-space: nowrap;
    }
    #btnWordbook span:not(.badge),
    #btnBookshelf span:not(.badge) {
        display: none !important;
    }
    .btn-sm {
        padding: 4px 6px;
        font-size: 14px;
    }
    .user-info {
        gap: 4px;
    }
    .user-name {
        display: none !important;
    }

    /* === 阅读器页面：仅保留返回 + Logo === */
    .view-reader .header-actions {
        display: none !important;
    }
    .view-reader .sync-badge {
        display: none !important;
    }
    .view-reader .btn-back {
        padding: 5px 8px;
        font-size: 14px;
    }

    /* === Main Layout === */
    .main-container {
        height: calc(100vh - 50px);
    }

    /* === Reader Panel === */
    .reader-panel {
        padding: 14px 12px;
    }
    .reader-panel.shifted {
        margin-right: 0;
    }

    /* === Word Annotations - 移动端显示内联上标 === */
    .word.annotated {
        border-bottom-width: 2px;
        padding-bottom: 1px;
    }

    /* === Word Touch Target === */
    .word {
        padding: 2px 4px;
        margin: 0 1px;
    }

    /* === Article === */
    .article-toolbar {
        margin-bottom: 16px;
    }
    .article-title-input {
        font-size: 20px;
        padding: 6px 0;
    }
    .article-content {
        font-size: 16px;
    }
    .article-content p {
        margin-bottom: 16px;
        padding-right: 24px;
    }
    .article-editor {
        font-size: 16px;
        min-height: 300px;
    }

    /* === Reader Toolbar === */
    .reader-toolbar {
        flex-wrap: nowrap;
        gap: 4px;
        padding: 4px 0;
        margin-bottom: 12px !important;
    }
    .toolbar-left {
        gap: 2px;
    }
    .toolbar-right {
        gap: 2px;
    }
    .tool-btn {
        width: 30px;
        height: 30px;
        font-size: 13px;
    }
    .tool-label {
        font-size: 11px;
        min-width: 28px;
        color: var(--text-secondary);
        opacity: 0.7;
    }

    /* === Wordbook Panel - 全屏遮罩 === */
    .wordbook-panel {
        width: 100%;
        min-width: 100%;
        max-width: 100%;
        top: 0;
        bottom: 0;
        z-index: 150;
        border-radius: 0;
        border-left: none;
    }
    .panel-header {
        padding: 14px 16px;
    }
    .panel-header h3 {
        font-size: 15px;
    }
    .panel-search {
        padding: 10px 16px;
    }
    .panel-actions {
        padding: 10px 16px;
        flex-wrap: wrap;
    }
    .word-list {
        padding: 10px 16px;
    }

    /* === Word Item === */
    .word-item {
        padding: 10px;
    }
    .word-item-header {
        flex-wrap: wrap;
        gap: 6px;
    }

    /* === Popover - 底部面板 (Bottom Sheet) === */
    .popover {
        position: fixed;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        top: auto !important;
        width: 100%;
        max-width: none;
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -4px 30px rgba(0,0,0,0.15);
        animation: sheetUp 0.25s ease-out;
    }
    /* 拖拽指示条 */
    .popover::before {
        content: '';
        display: block;
        width: 36px;
        height: 4px;
        background: #cbd5e1;
        border-radius: 2px;
        margin: 8px auto;
    }
    [data-theme="dark"] .popover::before {
        background: #4a6b7a;
    }
    @keyframes sheetUp {
        from { opacity: 0; transform: translateY(100%); }
        to { opacity: 1; transform: translateY(0); }
    }
    .popover-header {
        padding: 4px 16px 12px;
    }
    .popover-word {
        font-size: 20px;
    }
    .popover-phonetic {
        font-size: 15px;
    }
    .popover-body {
        padding: 8px 16px;
        max-height: 45vh;
        overflow-y: auto;
    }
    .popover-footer {
        padding: 10px 16px;
        padding-bottom: calc(10px + env(safe-area-inset-bottom));
        flex-wrap: wrap;
    }

    /* === Paragraph Translation === */
    .paragraph-translation {
        width: calc(100vw - 24px);
        max-height: 50vh;
        left: 12px;
        right: auto;
        bottom: 12px;
    }
    .pt-header {
        padding: 10px 14px;
        font-size: 13px;
    }
    .pt-content {
        padding: 12px 14px;
        font-size: 14px;
    }

    /* === Modal === */
    .modal-overlay {
        align-items: flex-end;
        padding-bottom: 12px;
    }
    .modal {
        min-width: auto !important;
        max-width: 100% !important;
        width: calc(100vw - 24px);
        padding: 20px;
        margin: 0 12px;
        border-radius: var(--radius-lg) var(--radius-lg) 4px 4px;
    }
    .modal h4 {
        font-size: 15px;
    }
    .modal input {
        font-size: 14px;
        padding: 10px 12px;
    }
    .modal-actions {
        flex-wrap: wrap;
    }
    .modal-actions .btn {
        flex: 1;
        justify-content: center;
        min-width: 80px;
    }

    /* === Import Modal === */
    .import-modal .modal {
        min-width: auto !important;
    }
    .import-modal textarea {
        min-height: 160px;
        font-size: 14px;
    }

    /* === Auth Modal === */
    .auth-modal-box {
        min-width: auto !important;
    }

    /* === Bookshelf Page === */
    .bookshelf-page {
        padding: 16px 12px;
        height: calc(100vh - 50px);
    }
    .shelf-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    .shelf-header h2 {
        font-size: 18px;
    }
    .shelf-header-actions {
        width: 100%;
        flex-wrap: wrap;
    }
    .shelf-header-actions .btn {
        flex: 1;
        justify-content: center;
        min-width: 0;
    }

    /* === Folder Tree === */
    .tree-node-header {
        padding: 10px 12px;
        font-size: 13px;
        flex-wrap: wrap;
    }
    .tree-node-label {
        flex: 1;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .tree-node-count {
        font-size: 11px;
        padding: 2px 8px;
    }
    /* 移动端始终显示操作按钮 */
    .tree-node-actions {
        display: flex !important;
    }
    .tree-node-actions button {
        padding: 4px 8px;
        font-size: 14px;
    }

    /* === Tree Article Item === */
    .tree-article-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
        padding: 10px 12px;
    }
    .tree-article-main {
        width: 100%;
    }
    .tree-article-title {
        font-size: 13px;
    }
    .tree-article-preview {
        font-size: 11px;
    }
    .tree-article-meta {
        width: 100%;
        justify-content: space-between;
        margin-left: 0;
        gap: 6px;
    }
    .tree-article-date {
        font-size: 11px;
    }
    /* 移动端始终显示文章操作按钮 */
    .tree-article-actions {
        opacity: 1 !important;
    }
    .tree-article-actions button {
        padding: 4px 8px;
        font-size: 14px;
    }
    .tree-node-children {
        padding: 6px;
    }
    .tree-empty-tip {
        padding: 16px;
        font-size: 12px;
    }

    /* === Move Modal === */
    .folder-move-list {
        max-height: 45vh;
    }
    .move-tree-item {
        padding: 10px 12px;
    }
    .move-tree-name {
        font-size: 13px;
    }

    /* === Bookshelf Modal === */
    .bookshelf-modal .modal {
        min-width: auto !important;
        max-width: 100% !important;
    }
    .bookshelf-item {
        padding: 10px 12px;
        flex-wrap: wrap;
        gap: 8px;
    }
    .bookshelf-item-title {
        font-size: 13px;
    }
    .bookshelf-item-actions {
        margin-left: 0;
    }
    .bookshelf-item-actions button {
        padding: 6px 10px;
        font-size: 14px;
    }

    /* === Reader Settings Modal === */
    .reader-settings-modal .modal {
        min-width: auto !important;
        max-width: 100% !important;
    }
    .settings-group label {
        font-size: 13px;
    }
    .settings-group label .settings-val {
        font-size: 12px;
    }

    /* === Pack Modal === */
    .pack-modal .modal {
        min-width: auto !important;
        max-width: 100% !important;
    }
    .pack-item {
        flex-wrap: wrap;
        gap: 8px;
    }

    /* === Toast === */
    .toast {
        bottom: 16px;
        left: 12px;
        right: 12px;
        transform: none;
        text-align: center;
        font-size: 13px;
        padding: 10px 16px;
        border-radius: 12px;
    }
    @keyframes toastIn {
        from { opacity: 0; transform: translateY(10px); }
        to { opacity: 1; transform: translateY(0); }
    }

    /* === Para Translation Trigger === */
    .para-translate-trigger {
        opacity: 0.5 !important;
        font-size: 16px;
    }

    /* === Scrollbar (thinner for mobile) === */
    ::-webkit-scrollbar { width: 4px; }
}

/* --- 小屏手机 (≤480px) --- */
@media (max-width: 480px) {
    /* === Top Bar - 更紧凑 === */
    .top-bar {
        padding: 6px 8px;
        gap: 2px;
    }
    .logo {
        font-size: 13px;
    }
    .btn {
        padding: 4px 6px;
        font-size: 12px;
    }
    .btn-sm {
        padding: 3px 5px;
        font-size: 13px;
    }

    /* === Reader Panel === */
    .reader-panel {
        padding: 10px 8px;
    }
    .article-toolbar {
        margin-bottom: 12px;
    }
    .article-title-input {
        font-size: 18px;
        padding: 4px 0;
    }
    .article-content {
        font-size: 15px;
    }
    .article-content p {
        margin-bottom: 14px;
        padding-right: 20px;
    }
    .article-editor {
        font-size: 15px;
        min-height: 250px;
        padding: 12px;
    }

    /* === Toolbar 更紧凑 === */
    .reader-toolbar {
        gap: 2px;
        margin-bottom: 8px !important;
        padding: 2px 0;
    }
    .tool-btn {
        width: 28px;
        height: 28px;
        font-size: 12px;
    }
    .tool-label {
        font-size: 10px;
        min-width: 24px;
    }

    /* === Bookshelf === */
    .bookshelf-page {
        padding: 12px 8px;
    }
    .shelf-header h2 {
        font-size: 16px;
    }

    /* === Tree Item 更紧凑 === */
    .tree-article-item {
        padding: 8px 10px;
    }
    .tree-article-meta {
        flex-wrap: wrap;
    }

    /* === Popover (继承 768px 底部面板，无需覆盖) === */

    /* === Modal 贴底 === */
    .modal-overlay {
        align-items: flex-end;
        padding-bottom: 0;
    }
    .modal {
        width: 100vw;
        margin: 0;
        border-radius: 16px 16px 0 0;
        padding: 18px 14px;
    }
}

/* ========== Import Modal ========== */
.import-modal .modal { min-width: 500px; }
.import-modal textarea {
    width: 100%;
    min-height: 200px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 15px;
    line-height: 1.8;
    resize: vertical;
    outline: none;
    font-family: inherit;
    margin-bottom: 16px;
}
.import-modal textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(8,145,178,0.1);
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* ========== Pack Manager ========== */
.pack-modal .modal { min-width: 500px; max-width: 560px; }

.pack-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 8px;
    transition: border-color 0.15s;
}

.pack-item:hover {
    border-color: var(--primary);
}

.pack-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.pack-name {
    font-weight: 600;
    font-size: 14px;
}

.pack-meta {
    font-size: 12px;
    color: var(--text-secondary);
}

.btn-done {
    background: #f0fdf4;
    color: var(--success);
    border: 1px solid #bbf7d0;
    cursor: default;
}

.pack-dl-btn {
    min-width: 90px;
}

/* ========== Reader Toolbar ========== */
.reader-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    max-width: var(--reader-max-width, 780px);
    margin: 0 auto 16px auto;
    padding: 6px 0;
    border-bottom: 1px solid var(--border);
}

.toolbar-left, .toolbar-right {
    display: flex;
    align-items: center;
    gap: 6px;
}

.tool-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--card-bg);
    cursor: pointer;
    font-size: 14px;
    transition: all 0.15s;
    color: var(--text-secondary);
}

.tool-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-light);
}

.tool-label {
    font-size: 13px;
    color: var(--text-secondary);
    min-width: 36px;
    text-align: center;
}

/* ========== Auth Modal ========== */
.auth-modal-box {
    min-width: 380px;
}

.auth-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 16px;
    border-bottom: 2px solid var(--border);
}

.auth-tab {
    flex: 1;
    padding: 10px;
    border: none;
    background: none;
    font-size: 15px;
    cursor: pointer;
    color: var(--text-secondary);
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.15s;
}

.auth-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    font-weight: 600;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.auth-form input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 15px;
    outline: none;
    margin-bottom: 12px;
}

.auth-form input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(8,145,178,0.1);
}

.auth-error {
    background: #fef2f2;
    color: var(--danger);
    padding: 8px 12px;
    border-radius: var(--radius);
    font-size: 13px;
    margin-bottom: 12px;
}

.auth-error.hidden { display: none; }

/* ========== Dark Mode ========== */
[data-theme="dark"] {
    --bg: #0f2027;
    --card-bg: #1a2c34;
    --text: #e2f0f5;
    --text-secondary: #7b9eaa;
    --border: #2d4a55;
    --primary-light: #0d3039;
    --primary-soft: #164e63;
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-lg: 0 10px 25px rgba(0,0,0,0.4);
}

[data-theme="dark"] body {
    background: var(--bg);
    color: var(--text);
}

[data-theme="dark"] .word.annotated {
    background: rgba(8, 145, 178, 0.18);
}

[data-theme="dark"] .word:hover {
    background: rgba(8, 145, 178, 0.22);
}

[data-theme="dark"] .btn-outline {
    background: var(--card-bg);
    color: var(--text);
}

[data-theme="dark"] .def-item:hover {
    background: rgba(8, 145, 178, 0.15);
}

[data-theme="dark"] .def-item.selected {
    background: rgba(8, 145, 178, 0.22);
    border-color: rgba(8, 145, 178, 0.4);
}

[data-theme="dark"] .word-item-meaning {
    background: rgba(8, 145, 178, 0.22);
}

[data-theme="dark"] .popover-footer,
[data-theme="dark"] .popover-header,
[data-theme="dark"] .popover-source {
    background: var(--card-bg);
}

[data-theme="dark"] .def-pos {
    background: rgba(255,255,255,0.05);
}

[data-theme="dark"] .def-notfound {
    background: rgba(251, 191, 36, 0.1);
    border-color: rgba(251, 191, 36, 0.3);
}

[data-theme="dark"] .def-notfound .def-text {
    color: #fbbf24;
}

[data-theme="dark"] .article-content p {
    color: var(--text);
}

[data-theme="dark"] .article-title-input {
    color: var(--text);
}

[data-theme="dark"] .auth-error {
    background: rgba(220, 38, 38, 0.15);
}

[data-theme="dark"] .tool-btn {
    background: var(--card-bg);
}

[data-theme="dark"] .para-translate-trigger {
    color: var(--primary);
}

[data-theme="dark"] .para-translation-inline {
    background: var(--primary-light);
}

[data-theme="dark"] .tree-article-item:hover {
    background: rgba(8, 145, 178, 0.12);
}

[data-theme="dark"] .tree-article-actions button {
    background: var(--card-bg);
}

[data-theme="dark"] .tree-node-header:hover {
    background: rgba(8, 145, 178, 0.12);
}

[data-theme="dark"] .unclassified-node > .tree-node-header {
    background: rgba(255,255,255,0.03);
}

/* ========== Header Left ========== */
.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.btn-back {
    background: var(--primary-light);
    color: var(--primary);
    border: 1px solid var(--primary);
    font-size: 13px;
    padding: 5px 12px;
}

.btn-back:hover {
    background: var(--primary);
    color: white;
}

.sync-badge {
    background: var(--success);
    font-size: 11px;
}

/* ========== Bookshelf Page ========== */
.bookshelf-page {
    height: calc(100vh - 58px);
    overflow-y: auto;
    padding: 24px 32px;
    max-width: 1100px;
    margin: 0 auto;
}

.bookshelf-page.hidden {
    display: none;
}

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

.shelf-header h2 {
    font-size: 22px;
    color: var(--text);
}

.shelf-header-actions {
    display: flex;
    gap: 8px;
}

/* ========== Folder Tree ========== */
.folder-tree {
    max-width: 100%;
}

.tree-node {
    margin-bottom: 8px;
}

.tree-node-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
    background: var(--card-bg);
    transition: all 0.15s;
    user-select: none;
}

.tree-node-header:hover {
    border-color: var(--primary);
    background: var(--primary-light);
}

.tree-node-header.expanded {
    border-color: var(--primary);
    background: var(--primary-light);
    border-radius: var(--radius) var(--radius) 0 0;
    margin-bottom: -1px;
}

.tree-toggle {
    font-size: 10px;
    width: 16px;
    text-align: center;
    color: var(--text-secondary);
    flex-shrink: 0;
    transition: transform 0.2s;
}

.tree-node-label {
    flex: 1;
}

.tree-node-count {
    font-size: 12px;
    color: var(--text-secondary);
    background: var(--bg);
    padding: 2px 10px;
    border-radius: 10px;
}

.tree-node-actions {
    display: none;
    gap: 2px;
}

.tree-node-header:hover .tree-node-actions {
    display: flex;
}

.tree-node-actions button {
    background: none;
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    padding: 3px 6px;
    color: var(--text-secondary);
    transition: all 0.15s;
}

.tree-node-actions button:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--bg);
}

.tree-node-actions .tree-del-btn:hover {
    border-color: var(--danger);
    color: var(--danger);
    background: #fef2f2;
}

.tree-node-children {
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 var(--radius) var(--radius);
    padding: 8px;
    background: var(--card-bg);
    overflow: hidden;
    transition: all 0.2s;
}

.tree-node-children.collapsed {
    display: none;
}

/* ========== Tree Article List Item ========== */
.tree-article-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 6px;
    cursor: pointer;
    transition: all 0.15s;
    background: var(--card-bg);
}

.tree-article-item:hover {
    border-color: var(--primary);
    background: var(--primary-light);
}

.tree-article-item:last-child {
    margin-bottom: 0;
}

.tree-article-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.tree-article-title {
    font-weight: 600;
    font-size: 14px;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tree-article-preview {
    font-size: 12px;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tree-article-meta {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
    margin-left: 12px;
}

.tree-article-date {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
}

.tree-article-actions {
    display: flex;
    gap: 2px;
    opacity: 0;
    transition: opacity 0.15s;
}

.tree-article-item:hover .tree-article-actions {
    opacity: 1;
}

.tree-article-actions button {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    padding: 3px 6px;
    color: var(--text-secondary);
    transition: all 0.15s;
}

.tree-article-actions button:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-light);
}

.tree-article-actions button.danger:hover {
    border-color: var(--danger);
    color: var(--danger);
    background: #fef2f2;
}

.tree-empty-tip {
    text-align: center;
    color: var(--text-secondary);
    padding: 20px;
    font-size: 13px;
}

/* 未分类节点特殊样式 */
.unclassified-node > .tree-node-header {
    background: #f8fafc;
}
.unclassified-node > .tree-node-header:hover {
    background: var(--primary-light);
}

/* All node special */
/* (deprecated - removed in favor of tree list) */

/* ========== Article Card (deprecated, replaced by tree-article-item) ========== */

/* ========== Move Article Modal ========== */
.folder-move-list {
    max-height: 360px;
    overflow-y: auto;
    margin-bottom: 16px;
}

/* 文件夹分组区域 */
.move-tree-section {
    margin-bottom: 4px;
}

.move-tree-section + .move-tree-section {
    border-top: 1px solid var(--border);
    padding-top: 8px;
    margin-top: 4px;
}

/* 文件夹分类标题行 */
.move-tree-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 4px;
    cursor: pointer;
    user-select: none;
    border-radius: var(--radius);
    transition: background 0.15s;
}
.move-tree-header:hover {
    background: var(--bg);
}

.move-tree-toggle {
    font-size: 10px;
    color: var(--text-secondary);
    width: 14px;
    text-align: center;
    flex-shrink: 0;
    transition: transform 0.15s;
}

.move-tree-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    flex: 1;
}

.move-tree-count {
    font-size: 11px;
    color: var(--text-secondary);
}

/* 文件夹子节点列表 */
.move-tree-children {
    padding-left: 4px;
}
.move-tree-children.collapsed {
    display: none;
}

/* 单个可选文件夹/未分类项 */
.move-tree-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 12px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    margin: 2px 0;
    cursor: pointer;
    transition: all 0.15s;
}

.move-tree-item:hover {
    border-color: var(--primary);
    background: var(--primary-light);
}

.move-tree-item.selected {
    border-color: var(--primary);
    background: var(--primary-light);
}

.move-tree-icon {
    font-size: 16px;
    flex-shrink: 0;
}

.move-tree-name {
    flex: 1;
    font-size: 14px;
    color: var(--text);
}

.move-tree-count {
    font-size: 11px;
    color: var(--text-secondary);
    flex-shrink: 0;
}

/* 未分类项高亮 */
.move-tree-unclassified {
    border: 1px solid var(--border);
}
.move-tree-unclassified:hover {
    border-color: var(--primary);
    background: var(--primary-light);
}

/* ========== Rename Input (inline) ========== */
.rename-input {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid var(--primary);
    border-radius: var(--radius);
    font-size: 13px;
    outline: none;
    background: var(--card-bg);
    color: var(--text);
}

/* ========== Bookshelf Modal (legacy) ========== */
.bookshelf-modal .modal {
    min-width: 520px;
    max-width: 600px;
}

.bookshelf-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 8px;
    transition: all 0.15s;
    cursor: pointer;
}

.bookshelf-item:hover {
    border-color: var(--primary);
    background: var(--primary-light);
}

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

.bookshelf-item-title {
    font-weight: 600;
    font-size: 14px;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.bookshelf-item-meta {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.bookshelf-item-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
    margin-left: 12px;
}

.bookshelf-item-actions button {
    background: none;
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    padding: 4px 8px;
    font-size: 12px;
    color: var(--text-secondary);
    transition: all 0.15s;
}

.bookshelf-item-actions button:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-light);
}

.bookshelf-item-actions button.danger:hover {
    border-color: var(--danger);
    color: var(--danger);
    background: #fef2f2;
}

/* ========== Reader Settings Modal ========== */
.reader-settings-modal .modal {
    min-width: 400px;
    max-width: 460px;
}

.reader-settings-modal .settings-body {
    display: flex;
    flex-direction: column;
    gap: 18px;
    margin-bottom: 20px;
}

.settings-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.settings-group label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
}

.settings-group label .settings-val {
    font-size: 13px;
    color: var(--primary);
    font-weight: 600;
    background: var(--primary-light);
    padding: 2px 10px;
    border-radius: 10px;
    min-width: 56px;
    text-align: center;
}

.settings-group input[type="range"] {
    -webkit-appearance: none;
    width: 100%;
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    outline: none;
    cursor: pointer;
}

.settings-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    background: var(--primary);
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
    transition: transform 0.15s;
}

.settings-group input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

.settings-desc {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: -2px;
}

.settings-reset {
    font-size: 13px;
    color: var(--primary);
    cursor: pointer;
    background: none;
    border: none;
    text-decoration: underline;
    padding: 4px 0;
    align-self: flex-start;
}

.settings-reset:hover {
    color: var(--primary-dark);
}

[data-theme="dark"] .settings-group input[type="range"] {
    background: #2d4a55;
}

[data-theme="dark"] .settings-group input[type="range"]::-webkit-slider-thumb {
    border-color: var(--card-bg);
}
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
    font-size: 14px;
}
.shelf-empty {
    grid-column: 1 / -1;
}
