/* =========================================
   1. 基础重置与动态 CSS 变量
   ========================================= */
:root {
    --bg-app: #ffffff; --bg-msg-ai: #f9fafb; --bg-msg-user: #111827;
    --text-main: #111827; --text-muted: #6b7280; --text-user: #ffffff;
    --border-color: #f3f4f6; --border-strong: #e5e7eb;
    --header-bg: rgba(255, 255, 255, 0.85); --input-bg: #ffffff; --input-hover: #f9fafb;
    --accent-color: #111827; --accent-hover: #374151;
    --shadow-sm: 0 4px 12px rgba(0, 0, 0, 0.05); --shadow-lg: 0 20px 40px rgba(0, 0, 0, 0.08);
    --code-bg: #f3f4f6; --success-color: #10b981; --error-color: #ef4444;
    --success-bg: #d1fae5; --error-bg: #fee2e2;
    --toast-bg: #111827; --toast-text: #ffffff;
}

[data-theme="dark"] {
    --bg-app: #0f111a; --bg-msg-ai: #1a1d27; --bg-msg-user: #ffffff;
    --text-main: #f3f4f6; --text-muted: #9ca3af; --text-user: #111827;
    --border-color: #1f2330; --border-strong: #2b3040;
    --header-bg: rgba(15, 17, 26, 0.85); --input-bg: #1a1d27; --input-hover: #1f2330;
    --accent-color: #ffffff; --accent-hover: #e5e7eb;
    --shadow-sm: 0 4px 12px rgba(0, 0, 0, 0.3); --shadow-lg: 0 20px 40px rgba(0, 0, 0, 0.4);
    --code-bg: #1f2330; --success-color: #34d399; --error-color: #f87171;
    --success-bg: rgba(16, 185, 129, 0.15); --error-bg: rgba(239, 68, 68, 0.15);
    --toast-bg: #f3f4f6; --toast-text: #111827;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background-color: var(--border-strong); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background-color: var(--text-muted); }

body {
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-app); color: var(--text-main);
    width: 100vw; height: 100vh; height: 100dvh; overflow: hidden;
    transition: background-color 0.3s ease, color 0.3s ease; display: flex; flex-direction: column;
}
.chat-app { flex: 1; width: 100%; display: flex; flex-direction: column; position: relative; overflow: hidden; }

/* =========================================
   2. 头部导航与下拉菜单
   ========================================= */
.header {
    flex-shrink: 0; height: 60px; padding: 0 24px;
    display: flex; align-items: center; justify-content: space-between;
    background: var(--header-bg); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border-color); z-index: 50; transition: background 0.3s, border-color 0.3s;
}
.header-left { display: flex; align-items: center; gap: 40px; height: 100%; }
.header-title {
    font-weight: 700; font-size: 1.2rem; letter-spacing: -0.01em;
    display: flex; align-items: center; gap: 10px; color: var(--text-main);
}
.nav-links { display: flex; gap: 24px; height: 100%; }
.nav-links a {
    display: flex; align-items: center; text-decoration: none;
    color: var(--text-muted); font-size: 0.95rem; font-weight: 500;
    cursor: pointer; position: relative; transition: color 0.2s; height: 100%;
}
.nav-links a:hover, .nav-links a.active { color: var(--text-main); }
.nav-links a.active::after {
    content: ''; position: absolute; bottom: -1px; left: 0;
    width: 100%; height: 2px; background-color: var(--text-main); border-radius: 2px;
}
@media (max-width: 640px) { .nav-links { display: none; } .header-left { gap: 16px; } }

.header-right { position: relative; display: flex; align-items: center; height: 100%; }
.user-profile { position: relative; cursor: pointer; padding: 4px 0; display: flex; align-items: center; height: 100%; }
.avatar {
    width: 32px; height: 32px; border-radius: 50%; object-fit: cover;
    border: 1px solid var(--border-strong); transition: transform 0.2s;
}
.user-profile:hover .avatar { transform: scale(1.05); }

.dropdown-menu {
    position: absolute; top: 100%; right: 0; margin-top: 8px; width: 260px;
    background-color: var(--bg-app); border: 1px solid var(--border-strong);
    border-radius: 16px; box-shadow: var(--shadow-lg); padding: 8px 0;
    opacity: 0; visibility: hidden; transform: translateY(-10px);
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1); z-index: 100;
}
.user-profile:hover .dropdown-menu { opacity: 1; visibility: visible; transform: translateY(0); }
.dropdown-header { padding: 8px 16px; font-size: 0.8rem; font-weight: 600; color: var(--text-muted); }
.current-plan-card {
    background: linear-gradient(135deg, #111827, #374151); color: white;
    padding: 16px; border-radius: 12px; margin: 4px 12px 16px 12px;
    cursor: pointer; display: flex; align-items: center; justify-content: space-between;
    transition: transform 0.2s, box-shadow 0.2s;
}
[data-theme="dark"] .current-plan-card { background: linear-gradient(135deg, #2b3040, #3b4252); }
.current-plan-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-sm); }
.current-plan-card .plan-name { font-size: 1.1rem; font-weight: 700; }
.current-plan-card .plan-action { font-size: 0.75rem; background: rgba(255, 255, 255, 0.2); padding: 4px 10px; border-radius: 12px; }
.credits-info { display: flex; justify-content: space-between; align-items: center; padding: 0 16px 12px 16px; }
.credits-label { color: var(--text-muted); font-size: 0.85rem; display: flex; align-items: center; gap: 4px; }
.credits-value { font-weight: 600; color: var(--text-main); font-size: 1rem; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
.dropdown-item {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 16px; margin: 0 8px; border-radius: 10px;
    cursor: pointer; transition: background 0.2s; font-size: 0.9rem;
    color: var(--text-main); font-weight: 500;
}
.dropdown-item:hover { background-color: var(--input-hover); }
.dropdown-item .icon-wrapper { display: flex; align-items: center; gap: 10px; }

.toggle-switch { width: 36px; height: 20px; background: var(--border-strong); border-radius: 10px; position: relative; transition: background 0.3s; }
.toggle-switch::after {
    content: ''; position: absolute; top: 2px; left: 2px;
    width: 16px; height: 16px; background: white; border-radius: 50%;
    transition: transform 0.3s; box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
[data-theme="dark"] .toggle-switch { background: #3b82f6; }
[data-theme="dark"] .toggle-switch::after { transform: translateX(16px); }
.dropdown-divider { height: 1px; background-color: var(--border-strong); margin: 8px 16px; }

/* =========================================
   3. 视图与列表 (列表页面卡片排版)
   ========================================= */
.main-wrapper { flex: 1; position: relative; overflow: hidden; width: 100%; display: flex; }
.view-container { display: none !important; width: 100%; height: 100%; flex-direction: column; position: absolute; top: 0; left: 0; }
.view-container.active { display: flex !important; }

.list-area { padding: 24px 15%; overflow-y: auto; display: flex; flex-direction: column; gap: 0; -webkit-overflow-scrolling: touch; }
@media (max-width: 800px) { .list-area { padding: 24px 16px; } }

/* 列表工具栏（搜索 + 批量操作） */
.list-toolbar { flex-shrink: 0; margin-bottom: 16px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.search-bar { flex: 1; min-width: 0;
    display: flex; align-items: center; gap: 8px;
    background: var(--input-bg); border: 1px solid var(--border-strong);
    border-radius: 12px; padding: 8px 14px; transition: border-color 0.2s;
}
.search-bar:focus-within { border-color: var(--text-main); }
.search-bar svg { flex-shrink: 0; color: var(--text-muted); }
.search-input {
    flex: 1; border: none; background: transparent; outline: none;
    font-size: 0.9rem; color: var(--text-main); font-family: inherit;
}
.batch-actions {
    display: flex; align-items: center; gap: 10px; padding: 8px 4px;
    animation: fadeIn 0.2s ease-out;
}
.batch-count { font-size: 0.85rem; color: var(--text-muted); font-weight: 500; }
.batch-delete-btn {
    background: var(--error-color); color: white; border: none;
    padding: 6px 16px; border-radius: 8px; font-size: 0.85rem;
    font-weight: 600; cursor: pointer; transition: opacity 0.2s;
}
.batch-delete-btn:hover { opacity: 0.85; }
.batch-cancel-btn {
    background: transparent; color: var(--text-muted); border: 1px solid var(--border-strong);
    padding: 6px 16px; border-radius: 8px; font-size: 0.85rem;
    font-weight: 500; cursor: pointer; transition: all 0.2s;
}
.batch-cancel-btn:hover { color: var(--text-main); border-color: var(--text-muted); }
.delete-mode-btn {
    flex-shrink: 0;
    background: transparent; border: 1px solid var(--border-strong);
    color: var(--text-muted); cursor: pointer; padding: 8px 10px;
    border-radius: 10px; display: flex; align-items: center;
    transition: all 0.2s; line-height: 0;
}
.delete-mode-btn:hover { color: var(--error-color); border-color: var(--error-color); background: rgba(239,68,68,0.05); }
.delete-mode-btn.active { color: white; background: var(--error-color); border-color: var(--error-color); }
.history-tabs-container { display: flex; gap: 8px; margin-bottom: 24px; padding-bottom: 16px; border-bottom: 1px solid var(--border-color); flex-shrink: 0; }
.history-tab {
    background: transparent; border: none; padding: 8px 16px;
    font-size: 0.95rem; font-weight: 600; color: var(--text-muted);
    cursor: pointer; border-radius: 8px; transition: all 0.2s;
}
.history-tab.active { background: var(--border-strong); color: var(--text-main); }
.list-content { display: flex; flex-direction: column; gap: 16px; }

.list-card {
    background: var(--input-bg); border: 1px solid var(--border-color);
    border-radius: 16px; padding: 20px; display: flex; flex-direction: column;
    gap: 12px; cursor: pointer; transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
}
.list-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-sm); border-color: var(--border-strong); }
.list-card-header { display: flex; justify-content: space-between; align-items: center; }
.list-card-role { font-size: 0.75rem; font-weight: 700; color: var(--bg-app); background: var(--text-main); padding: 4px 10px; border-radius: 12px; }
.list-card-date { font-size: 0.8rem; color: var(--text-muted); }
.rename-btn {
    background: transparent; border: none; color: var(--text-muted);
    cursor: pointer; padding: 4px; border-radius: 4px;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.2s; opacity: 0.5;
}
.rename-btn:hover { opacity: 1; color: var(--text-main); background: var(--input-hover); }
.delete-btn {
    background: transparent; border: none; color: var(--text-muted);
    cursor: pointer; padding: 4px; border-radius: 4px;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.2s; opacity: 0.4;
}

/* ---- 模型切换按钮 ---- */
.model-toggle {
    display: flex; align-items: center; gap: 4px; flex-shrink: 0;
    background: transparent; border: none; cursor: pointer;
    font-size: 0.77rem; color: var(--text-muted); font-weight: 500;
    padding: 4px 8px; border-radius: 8px; font-family: inherit; line-height: 1;
    transition: background 0.15s, color 0.15s; align-self: center;
    margin-bottom: 2px;
}
.model-toggle:hover { background: var(--input-hover); color: var(--text-main); }
.model-cost-display {
    font-size: 0.7rem; color: var(--text-muted); font-weight: 400;
    background: var(--border-color); padding: 1px 6px; border-radius: 6px; line-height: 1.4;
}
.list-card-check {
    width: 18px; height: 18px; border: 2px solid var(--border-strong);
    border-radius: 4px; cursor: pointer; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.2s; background: transparent; margin-right: 12px;
}
.list-card-check.checked { background: var(--accent-color); border-color: var(--accent-color); }
.list-card-check.checked::after { content: '✓'; color: var(--bg-app); font-size: 12px; font-weight: 700; }
.list-card-body { display: flex; flex: 1; flex-direction: column; min-width: 0; gap: 10px; }
.list-card-content {
    font-size: 0.95rem; line-height: 1.6; color: var(--text-main);
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
    overflow: hidden; word-break: break-word;
}
.list-card-content code { background: rgba(150,150,150,0.15); color: #ff79c6; padding: 2px 6px; border-radius: 4px; font-size: 0.85em; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
.empty-state { text-align: center; color: var(--text-muted); margin-top: 80px; font-size: 1rem; }

/* =========================================
   4. 聊天区域与输入框
   ========================================= */
.welcome-container { display: none; flex-direction: column; align-items: center; justify-content: center; padding: 20px; margin-bottom: 20px; flex-shrink: 0; }
.welcome-logo {
    width: 56px; height: 56px; background: var(--text-main); color: var(--bg-app);
    border-radius: 16px; display: flex; align-items: center; justify-content: center;
    margin-bottom: 24px; box-shadow: var(--shadow-sm);
}
.welcome-title { font-size: 2.2rem; font-weight: 700; margin-bottom: 8px; text-align: center; letter-spacing: -0.02em; }

.message-area {
    flex: 1; overflow-y: auto; overflow-x: hidden; padding: 24px 15%;
    display: flex; flex-direction: column; gap: 32px; scroll-behavior: smooth; -webkit-overflow-scrolling: touch;
}
@media (max-width: 800px) { .message-area { padding: 24px 16px; } }

.chat-app.is-home #chatView { justify-content: center; padding-bottom: 12vh; }
.chat-app.is-home #chatView .welcome-container { display: flex; flex: 0 0 auto; }
.chat-app.is-home #chatView .message-area { display: none; }
.chat-app.is-home #chatView .input-area { border-top: none; padding-bottom: 0; background: transparent; flex: 0 0 auto; }

.input-area {
    flex-shrink: 0; padding: 16px 15% 32px 15%;
    background-color: var(--bg-app); border-top: 1px solid var(--border-color);
}
@media (max-width: 800px) { .input-area { padding: 16px 16px 24px 16px; } }
.mode-switch-container { display: flex; justify-content: center; margin-bottom: 16px; width: 100%; flex-direction: column; align-items: center; gap: 10px; }
.mode-switch { display: inline-flex; background: var(--border-color); border: 1px solid var(--border-strong); border-radius: 20px; padding: 4px; }
.difficulty-selector { display: inline-flex; background: transparent; border: 1px solid var(--border-strong); border-radius: 16px; padding: 2px; gap: 0; }
.diff-btn {
    background: transparent; border: none; padding: 4px 14px; border-radius: 13px;
    font-size: 0.78rem; font-weight: 500; color: var(--text-muted); cursor: pointer;
    transition: all 0.2s;
}
.diff-btn.active { background: var(--bg-app); color: var(--text-main); box-shadow: 0 1px 4px rgba(0,0,0,0.06); }
[data-theme="dark"] .diff-btn.active { background: var(--border-strong); }
.diff-btn:hover:not(.active) { color: var(--text-main); }
.mode-btn {
    background: transparent; border: none; padding: 6px 16px; border-radius: 16px;
    font-size: 0.85rem; font-weight: 600; color: var(--text-muted); cursor: pointer; transition: all 0.2s;
}
.mode-btn.active { background: var(--bg-app); color: var(--text-main); box-shadow: 0 2px 8px rgba(0,0,0,0.06); }
[data-theme="dark"] .mode-switch { background: var(--input-bg); }
[data-theme="dark"] .mode-btn.active { background: var(--border-strong); }

.input-box {
    display: flex; align-items: flex-end; background-color: var(--input-bg);
    border: 1px solid var(--border-strong); border-radius: 28px;
    padding: 10px 14px; box-shadow: var(--shadow-sm); transition: all 0.2s; position: relative;
}
.input-box.disabled { opacity: 0.5; pointer-events: none; background-color: var(--border-color); }
.input-box:focus-within:not(.disabled) { border-color: var(--text-main); box-shadow: var(--shadow-lg); background-color: var(--bg-app); }
.input-box textarea {
    flex: 1; border: none; background: transparent; padding: 8px 12px;
    font-size: 1rem; color: var(--text-main); outline: none; resize: none;
    max-height: 200px; min-height: 24px; line-height: 1.5;
}
.btn-icon { border: none; width: 38px; height: 38px; margin-bottom: 2px; border-radius: 50%; cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.upload-btn { background: transparent; color: var(--text-muted); margin-right: 4px; }
.send-btn { background-color: var(--accent-color); color: var(--bg-app); margin-left: 8px; }

.input-hint {
    text-align: center; font-size: 0.75rem; color: var(--text-muted);
    margin-top: 8px; user-select: none; opacity: 0.6;
}
.chat-app.is-home .input-hint { opacity: 0.4; }

/* =========================================
   5. 聊天气泡样式与操作栏
   ========================================= */
.message-row { display: flex; width: 100%; max-width: 100%; flex-shrink: 0; }
.message-row.user { justify-content: flex-end; }
.message-row.ai { justify-content: flex-start; overflow: hidden; }
.bubble {
    max-width: 90%; padding: 16px 20px; font-size: 1rem; line-height: 1.6;
    word-wrap: break-word; overflow-wrap: break-word; word-break: break-word;
    position: relative; border-radius: 20px; overflow-x: auto;
}
@media (min-width: 768px) { .bubble { max-width: 85%; } }
.message-row.user .bubble { background-color: var(--bg-msg-user); color: var(--text-user); border-bottom-right-radius: 4px; }
.message-row.ai .bubble { background-color: var(--bg-msg-ai); border: 1px solid var(--border-color); border-bottom-left-radius: 4px; color: var(--text-main); }
.bubble p { margin-bottom: 12px; } .bubble p:last-child { margin-bottom: 0; }

.markdown-body pre {
    background: #282a36; color: #f8f8f2; padding: 16px; border-radius: 12px;
    overflow-x: auto; margin: 16px 0; font-size: 0.9rem;
    border: 1px solid rgba(0,0,0,0.2); position: relative; padding-top: 40px;
}
.markdown-body pre::before {
    content: ''; position: absolute; top: 14px; left: 16px;
    width: 12px; height: 12px; border-radius: 50%; background: #ff5f56;
    box-shadow: 20px 0 0 #ffbd2e, 40px 0 0 #27c93f;
}
.markdown-body code { font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace; }
.markdown-body p code, .markdown-body li code, .markdown-body span code {
    background: rgba(150,150,150,0.15); color: #ff79c6;
    padding: 2px 6px; border-radius: 4px; font-size: 0.85em;
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}

mjx-container[display="true"] { overflow-x: auto; overflow-y: hidden; max-width: 100%; padding-bottom: 4px; }
mjx-container[display="true"]::-webkit-scrollbar { height: 4px; }
mjx-container[display="true"]::-webkit-scrollbar-thumb { background-color: var(--border-strong); border-radius: 4px; }

.bubble-actions { display: flex; justify-content: flex-start; margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border-color); gap: 4px; }
.action-btn {
    background: transparent; border: none; color: var(--text-muted);
    cursor: pointer; padding: 6px; border-radius: 6px;
    display: flex; align-items: center; justify-content: center; transition: all 0.2s;
}
.action-btn:hover { color: var(--text-main); background: var(--border-strong); transform: scale(1.05); }
.action-btn.fav-active { color: #f59e0b; }
.action-btn.fav-active svg { fill: #f59e0b; }

/* =========================================
   6. 题生题交互卡片样式
   ========================================= */
.message-row.q2q-msg-row { width: 100%; max-width: 100%; }
.bubble.q2q-bubble {
    max-width: 100%; width: 100%; border-radius: 16px;
    background-color: var(--bg-app); border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm); padding: 0; overflow: hidden;
}
.message-row.ai.q2q-msg-row .bubble { border-bottom-left-radius: 16px; }
[data-theme="dark"] .bubble.q2q-bubble { background-color: var(--input-bg); }

.q2q-card { width: 100%; display: flex; flex-direction: column; }
.q2q-tag-bar { padding: 16px 24px 0 24px; display: flex; align-items: center; gap: 8px; }
.q2q-type-badge { font-size: 0.75rem; background: var(--text-main); color: var(--bg-app); padding: 4px 12px; border-radius: 12px; font-weight: 600; display: inline-block; letter-spacing: 0.02em; }

.q2q-body { padding: 16px 24px 24px 24px; display: flex; flex-direction: column; gap: 20px; }
.q2q-question-focus { font-size: 1.05rem; font-weight: 600; color: var(--text-main); margin-bottom: 4px; line-height: 1.6; }
.q2q-options { display: flex; flex-direction: column; gap: 12px; }
.q2q-option {
    padding: 14px 18px; border: 1px solid var(--border-strong); border-radius: 12px;
    cursor: pointer; transition: all 0.2s; background: var(--input-bg); font-size: 0.95rem;
}
.q2q-option > p:first-child { margin-top: 0; }
.q2q-option > p:last-child { margin-bottom: 0; }
.q2q-option:hover:not(.locked) { border-color: var(--accent-color); background: var(--input-hover); transform: translateY(-1px); }
.q2q-option.selected { border-color: var(--accent-color); background: var(--border-color); box-shadow: inset 0 0 0 1px var(--accent-color); font-weight: 500; }
.q2q-option.locked { pointer-events: none; opacity: 0.7; }
.q2q-option.locked.selected { opacity: 1; border-color: var(--accent-color); }

.q2q-blank-input {
    width: 80px; border: none; border-bottom: 2px solid var(--border-strong);
    background: transparent; outline: none; text-align: center; color: var(--text-main);
    font-size: 1rem; padding: 2px; transition: border-color 0.2s; font-weight: 600;
}
.q2q-blank-input:focus { border-color: var(--accent-color); }
.q2q-blank-input.locked { pointer-events: none; opacity: 0.7; border-bottom-style: dashed; }

.q2q-textarea-wrapper { position: relative; border: 1px solid var(--border-strong); border-radius: 12px; background: var(--input-bg); padding: 12px; }
.q2q-textarea-wrapper:focus-within { border-color: var(--accent-color); }
.q2q-textarea-wrapper.locked { pointer-events: none; opacity: 0.7; background: transparent; }
.q2q-textarea { width: 100%; border: none; background: transparent; outline: none; resize: vertical; min-height: 100px; color: var(--text-main); font-family: inherit; font-size: 0.95rem; line-height: 1.6; }
.q2q-actions { display: flex; justify-content: flex-end; margin-top: 8px; border-top: 1px solid var(--border-color); padding-top: 16px; }
.q2q-submit-btn {
    background: var(--accent-color); color: var(--bg-app); border: none;
    padding: 10px 28px; border-radius: 20px; font-weight: 600;
    cursor: pointer; transition: opacity 0.2s, transform 0.2s; font-size: 0.95rem;
}
.q2q-submit-btn:hover { opacity: 0.9; transform: scale(1.02); }

/* ===== 题生题底部操作栏（批改后出现） ===== */
.q2q-bottom-bar {
    display: flex; align-items: center; gap: 6px;
    padding: 12px 0 0 0; margin-top: 16px;
    border-top: 1px solid var(--border-color);
}
.q2q-bar-btn {
    width: 34px; height: 34px; border: none; border-radius: 8px;
    background: transparent; color: var(--text-muted);
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    transition: all 0.2s;
}
.q2q-bar-btn:hover { color: var(--text-main); background: var(--input-hover); }
.q2q-bar-btn.fav-active { color: #f59e0b; }
.q2q-bar-btn.fav-active svg { fill: #f59e0b; }

.q2q-result-area { margin-top: 16px; animation: fadeIn 0.4s ease-out; }
.q2q-result-box {
    display: flex; justify-content: space-between; align-items: center;
    padding: 14px 20px; border-radius: 12px; font-size: 1.05rem; font-weight: 700; margin-bottom: 20px;
}
.q2q-result-box.correct { background: #f0fdf4; border: 1px solid #bbf7d0; color: #16a34a; }
.q2q-result-box.wrong { background: #fef2f2; border: 1px solid #fca5a5; color: #dc2626; }
[data-theme="dark"] .q2q-result-box.correct { background: rgba(22, 163, 74, 0.15); border-color: rgba(187, 247, 208, 0.2); }
[data-theme="dark"] .q2q-result-box.wrong { background: rgba(220, 38, 38, 0.15); border-color: rgba(254, 202, 202, 0.2); }
.q2q-result-header { display: flex; align-items: center; gap: 8px; }
.q2q-user-answer-display { font-size: 0.95rem; color: var(--text-muted); font-weight: 500; }
.q2q-explanation h4 { margin-bottom: 8px; color: var(--text-muted); font-size: 0.9rem; text-transform: uppercase; letter-spacing: 0.05em; }
.q2q-explanation .std-answer { margin-bottom: 16px; font-weight: 600; font-size: 1.1rem; color: var(--text-main); }

.markdown-body { font-size: 0.95rem; line-height: 1.8; letter-spacing: 0.02em; }
.markdown-body p { margin-bottom: 12px; }
.markdown-body ol, .markdown-body ul { padding-left: 1.25em; margin-top: 4px; margin-bottom: 12px; }
.markdown-body li { margin-bottom: 6px; }
.markdown-body > *:first-child { margin-top: 0; }
.markdown-body > *:last-child { margin-bottom: 0; }

.markdown-body table { width: 100%; border-collapse: collapse; margin: 16px 0; display: block; overflow-x: auto; white-space: nowrap; border-radius: 8px; border: 1px solid var(--border-strong); }
.markdown-body th, .markdown-body td { border: 1px solid var(--border-strong); padding: 10px 16px; text-align: center; font-size: 0.95rem; }
.markdown-body th { background-color: var(--input-hover); font-weight: 600; color: var(--text-main); }
.markdown-body tr:nth-child(even) { background-color: rgba(0,0,0,0.015); }
[data-theme="dark"] .markdown-body tr:nth-child(even) { background-color: rgba(255,255,255,0.015); }
.markdown-body table::-webkit-scrollbar { height: 4px; }
.markdown-body table::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }

/* =========================================
   7. 弹窗 (Modal)
   ========================================= */
.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(0,0,0,0.4); backdrop-filter: blur(6px);
    display: flex; align-items: center; justify-content: center;
    opacity: 0; visibility: hidden; transition: all 0.3s; z-index: 1000;
}
.modal-overlay.active { opacity: 1; visibility: visible; }
.modal-content {
    background: var(--bg-app); width: 90%; max-width: 440px;
    border-radius: 24px; padding: 28px; box-shadow: var(--shadow-lg);
    transform: translateY(20px) scale(0.98); transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    border: 1px solid var(--border-color); max-height: 90vh; overflow-y: auto;
}
.modal-overlay.active .modal-content { transform: translateY(0) scale(1); }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.modal-header h2 { font-size: 1.4rem; font-weight: 700; }
.close-btn {
    background: transparent; border: none; color: var(--text-muted);
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    width: 32px; height: 32px; border-radius: 50%; transition: background 0.2s;
}
.close-btn:hover { background: var(--border-color); color: var(--text-main); }
.modal-body .setting-item { display: flex; justify-content: space-between; align-items: center; padding: 16px 0; border-bottom: 1px solid var(--border-color); }
.setting-info span { display: block; font-weight: 600; font-size: 1rem; margin-bottom: 4px; }
.setting-info p { font-size: 0.85rem; color: var(--text-muted); }
.danger-btn { background: #fee2e2; color: #dc2626; border: none; padding: 8px 16px; border-radius: 8px; font-weight: 600; cursor: pointer; transition: all 0.2s; }
[data-theme="dark"] .danger-btn { background: rgba(220, 38, 38, 0.2); }
.danger-btn:hover { background: #fecaca; }

.pricing-modal-content { max-width: 1000px; width: 95%; padding: 32px; }
.pricing-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-top: 16px; }
.pricing-card { border: 1px solid var(--border-strong); border-radius: 16px; padding: 24px; display: flex; flex-direction: column; background: var(--bg-app); transition: border-color 0.2s; }
.pricing-card:hover { border-color: var(--text-main); }
.pricing-card h3 { font-size: 1.5rem; font-weight: 600; margin-bottom: 8px; color: var(--text-main); }
.pricing-desc { font-size: 0.9rem; color: var(--text-muted); margin-bottom: 24px; line-height: 1.5; min-height: 40px; }
.pricing-card .price { font-size: 2.2rem; font-weight: 700; margin-bottom: 24px; color: var(--text-main); }
.pricing-card .price span { font-size: 0.9rem; color: var(--text-muted); font-weight: 400; }
.pricing-btn {
    border-radius: 24px; padding: 12px; font-weight: 600; text-align: center;
    cursor: pointer; transition: all 0.2s; border: 1px solid transparent;
    width: 100%; margin-bottom: 24px; font-size: 0.95rem;
}
.pricing-btn.primary { background: var(--text-main); color: var(--bg-app); }
.pricing-btn.primary:hover { opacity: 0.9; }
.pricing-btn.secondary { background: transparent; color: var(--text-main); border-color: var(--border-strong); cursor: default; }
.pricing-btn:not(.primary):not(.secondary) { background: var(--input-bg); color: var(--text-main); border-color: var(--border-strong); }
.pricing-btn:not(.primary):not(.secondary):hover { background: var(--input-hover); }
.feature-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 16px; font-size: 0.9rem; color: var(--text-main); }
.feature-list li { display: flex; align-items: flex-start; gap: 10px; line-height: 1.4; }
.feature-list li svg { width: 18px; height: 18px; flex-shrink: 0; color: var(--text-main); }
.feature-list-title { font-size: 0.85rem; font-weight: 600; margin-bottom: 16px; color: var(--text-main); }

@media (max-width: 900px) { .pricing-grid { grid-template-columns: repeat(2, 1fr); } .pricing-modal-content { padding: 24px; } }
@media (max-width: 550px) { .pricing-grid { grid-template-columns: 1fr; } }

/* 文件解析 */
.parsed-q-item {
    padding: 12px 16px; background: var(--input-bg); border: 1px solid var(--border-strong);
    border-radius: 12px; cursor: pointer; transition: all 0.2s; font-size: 0.95rem;
    line-height: 1.6; color: var(--text-main); text-align: left; margin-bottom: 8px; word-break: break-word;
}
.parsed-q-item code { background: rgba(150,150,150,0.15); color: #ff79c6; padding: 2px 6px; border-radius: 4px; font-size: 0.85em; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
.parsed-q-item:hover { border-color: var(--accent-color); background: var(--input-hover); transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.parsed-q-item:last-child { margin-bottom: 0; }

/* 打字指示器 */
.typing-indicator { display: flex; gap: 4px; padding: 8px 4px; }
.typing-indicator span {
    width: 6px; height: 6px; background-color: var(--text-muted);
    border-radius: 50%; animation: bounce 1.4s infinite ease-in-out both;
}
.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }
@keyframes bounce { 0%, 80%, 100% { transform: scale(0); } 40% { transform: scale(1); } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* =========================================
   8. Toast 通知系统
   ========================================= */
.toast-container {
    position: fixed; top: 20px; right: 20px; z-index: 9999;
    display: none; flex-direction: column; gap: 8px; pointer-events: none;
}
.toast {
    pointer-events: auto; padding: 12px 20px; border-radius: 12px;
    font-size: 0.9rem; font-weight: 500; color: var(--toast-text);
    background: var(--toast-bg); box-shadow: var(--shadow-lg);
    display: flex; align-items: center; gap: 10px;
    animation: toastIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    max-width: 360px; word-break: break-word;
}
.toast.toast-success { --toast-bg: #059669; --toast-text: #ffffff; }
.toast.toast-error { --toast-bg: #dc2626; --toast-text: #ffffff; }
.toast.toast-info { --toast-bg: var(--toast-bg); --toast-text: var(--toast-text); }
.toast.toast-out { animation: toastOut 0.25s ease-in forwards; }
@keyframes toastIn {
    from { opacity: 0; transform: translateX(40px); }
    to { opacity: 1; transform: translateX(0); }
}
@keyframes toastOut {
    from { opacity: 1; transform: translateX(0); }
    to { opacity: 0; transform: translateX(40px); }
}

/* =========================================
   9. Auth UI - 用户菜单 + 登录弹窗 + 点数页
   ========================================= */

/* ---- 用户菜单 ---- */
#userMenuContainer { display: flex; align-items: center; margin-right: 10px; }
/* 默认隐藏登录态元素，防止刷新闪现 */
#navHistory, #navFavorites, #oldUserProfile { display: none; }
#navHistory.auth-visible, #navFavorites.auth-visible { display: flex; }
.user-menu { position: relative; }
.user-menu-trigger:hover svg.avatar { transform: scale(1.05); }
svg.avatar {
    width: 32px; height: 32px; border-radius: 50%; object-fit: cover;
    border: 1px solid var(--border-strong); transition: transform 0.2s;
    color: var(--text-muted);
}

/* ---- 下拉菜单（与 ai.html 原版一致） ---- */
.user-dropdown {
    display: none; position: absolute; top: 100%; right: 0; margin-top: 8px;
    width: 260px; background-color: var(--bg-app); border: 1px solid var(--border-strong);
    border-radius: 16px; box-shadow: var(--shadow-lg); padding: 8px 0;
    z-index: 100;
}
.user-dropdown.show { display: block; }
.dropdown-header { padding: 8px 16px; font-size: 0.8rem; font-weight: 600; color: var(--text-muted); }
.current-plan-card {
    background: linear-gradient(135deg, #111827, #374151); color: white;
    padding: 16px; border-radius: 12px; margin: 4px 12px 16px 12px;
    cursor: pointer; display: flex; align-items: center; justify-content: space-between;
    transition: transform 0.2s, box-shadow 0.2s;
}
[data-theme="dark"] .current-plan-card { background: linear-gradient(135deg, #2b3040, #3b4252); }
.current-plan-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-sm); }
.current-plan-card .plan-name { font-size: 1.1rem; font-weight: 700; }
.current-plan-card .plan-action { font-size: 0.75rem; background: rgba(255,255,255,0.2); padding: 4px 10px; border-radius: 12px; }
.credits-info { display: flex; justify-content: space-between; align-items: center; padding: 0 16px 12px 16px; }
.credits-label { color: var(--text-muted); font-size: 0.85rem; display: flex; align-items: center; gap: 4px; }
.credits-value { font-weight: 600; color: var(--text-main); font-size: 1rem; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
.dropdown-divider { height: 1px; background-color: var(--border-strong); margin: 8px 16px; }
.dropdown-item {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 16px; margin: 0 8px; border-radius: 10px;
    cursor: pointer; transition: background 0.2s; font-size: 0.9rem;
    color: var(--text-main); font-weight: 500;
}
.dropdown-item:hover { background-color: var(--input-hover); }
.dropdown-item .icon-wrapper { display: flex; align-items: center; gap: 10px; }

/* ---- 登录按钮（未登录时） ---- */
.auth-login-btn {
    background: var(--accent-color); color: var(--bg-app);
    border: none; padding: 6px 18px; border-radius: 10px;
    font-size: 0.85rem; font-weight: 600; cursor: pointer;
    transition: opacity 0.2s; font-family: inherit;
}
.auth-login-btn:hover { opacity: 0.85; }

/* ---- Auth 弹窗（极简扁平化设计） ---- */
.auth-modal {
    background: #fff; border-radius: 20px;
    width: 90%; max-width: 400px; position: relative;
    padding: 40px 32px 32px; box-sizing: border-box;
    animation: fadeIn 0.25s ease-out;
}
.auth-close {
    position: absolute; top: 16px; right: 16px;
    background: none; border: none; cursor: pointer;
    color: #000; padding: 4px; line-height: 0;
    border-radius: 6px; transition: background 0.15s;
}
.auth-close:hover { background: #f3f4f6; }
#authFormContainer { width: 100%; }

/* 标题 */
.auth-title {
    font-size: 1.5rem; font-weight: 800; text-align: center;
    color: #000; margin: 0 0 8px; letter-spacing: -0.02em;
    line-height: 1.3;
}
.auth-desc {
    font-size: 0.85rem; color: #9ca3af; text-align: center;
    margin: 0 0 28px; line-height: 1.5;
}

/* 第三方快捷登录按钮组 */
.auth-social-group { display: flex; flex-direction: column; gap: 10px; margin-bottom: 24px; }
.auth-social-btn {
    display: flex; align-items: center; justify-content: center; gap: 10px;
    width: 100%; height: 48px; padding: 0 20px;
    background: #fff; border: 1px solid #e5e7eb; border-radius: 12px;
    cursor: pointer; transition: background 0.15s, border-color 0.15s;
    font-size: 0.9rem; font-weight: 500; color: #000; font-family: inherit;
}
.auth-social-btn:hover { background: #f9fafb; border-color: #d1d5db; }
.auth-social-btn svg { flex-shrink: 0; }
.auth-social-btn span { white-space: nowrap; }

/* 分割线 */
.auth-divider {
    display: flex; align-items: center; gap: 16px;
    margin-bottom: 24px; color: #d1d5db; font-size: 0.8rem;
}
.auth-divider::before,
.auth-divider::after {
    content: ''; flex: 1; height: 1px; background: #e5e7eb;
}

/* 输入框 */
.auth-input {
    width: 100%; height: 48px; padding: 0 16px;
    border: 1px solid #e5e7eb; border-radius: 12px;
    font-size: 0.9rem; color: #000; background: #fff;
    font-family: inherit; outline: none; transition: border-color 0.15s;
    box-sizing: border-box;
}
.auth-input:focus { border-color: #000; }
.auth-input::placeholder { color: #d1d5db; }
.auth-input + .auth-input { margin-top: 10px; }

/* 错误提示 */
.auth-error {
    color: #ef4444; font-size: 0.8rem; margin: 10px 0;
    min-height: 20px; line-height: 1.4;
}

/* 提交按钮 */
.auth-submit-btn {
    width: 100%; height: 48px; border: none; border-radius: 12px;
    background: #000; color: #fff; font-size: 0.95rem;
    font-weight: 600; cursor: pointer; font-family: inherit;
    transition: opacity 0.15s; margin-top: 0;
}
.auth-submit-btn:hover { opacity: 0.85; }
.auth-submit-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* 切换登录/注册 */
.auth-switch {
    text-align: center; margin-top: 20px; font-size: 0.85rem;
    color: #9ca3af;
}
.auth-switch a { color: #000; text-decoration: none; font-weight: 600; }
.auth-switch a:hover { text-decoration: underline; }
.auth-register-link { text-align: center; margin-top: 16px; }
.auth-register-btn {
    background: none; border: none; color: #9ca3af; font-size: 0.85rem;
    cursor: pointer; font-family: inherit; transition: color 0.15s;
}
.auth-register-btn:hover { color: #000; }

/* 深色主题适配 */
[data-theme="dark"] .auth-modal { background: #1a1d27; }
[data-theme="dark"] .auth-title { color: #f3f4f6; }
[data-theme="dark"] .auth-close { color: #f3f4f6; }
[data-theme="dark"] .auth-close:hover { background: #2b3040; }
[data-theme="dark"] .auth-social-btn {
    background: #1a1d27; border-color: #2b3040; color: #f3f4f6;
}
[data-theme="dark"] .auth-social-btn:hover { background: #1f2330; }
[data-theme="dark"] .auth-input {
    background: #1a1d27; border-color: #2b3040; color: #f3f4f6;
}
[data-theme="dark"] .auth-input:focus { border-color: #f3f4f6; }
[data-theme="dark"] .auth-submit-btn { background: #f3f4f6; color: #111827; }
[data-theme="dark"] .auth-switch a { color: #f3f4f6; }

/* ---- 点数明细页（极简风格） ---- */
.credits-page { padding: 0; }
.credits-cards {
    display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 32px;
}
.credits-card {
    background: var(--input-bg); border: 1px solid var(--border-color);
    border-radius: 12px; padding: 20px;
}
.credits-card-title {
    font-size: 0.8rem; font-weight: 500; color: var(--text-muted); margin-bottom: 8px;
}
.credits-card-value {
    font-size: 1.6rem; font-weight: 600; color: var(--text-main);
    line-height: 1.2;
}
.credits-card-note {
    font-size: 0.75rem; color: var(--text-muted); margin-top: 4px;
}
.credits-history h3 {
    font-size: 0.95rem; font-weight: 600; margin-bottom: 16px; color: var(--text-main);
}
.credits-log-list .empty-state {
    margin-top: 24px;
}
.usage-log-item {
    display: flex; justify-content: space-between; align-items: center;
    padding: 12px 0; border-bottom: 1px solid var(--border-color);
}
.usage-log-item:last-child { border-bottom: none; }
.usage-log-info { display: flex; flex-direction: column; gap: 2px; }
.usage-log-action {
    font-size: 0.85rem; font-weight: 500; color: var(--text-main);
    text-transform: capitalize;
}
.usage-log-date { font-size: 0.75rem; color: var(--text-muted); }
.usage-log-cost {
    font-size: 0.9rem; font-weight: 500; font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    color: var(--text-muted);
}

/* ---- 深色主题适配 ---- */
[data-theme="dark"] .user-tier-badge.free { background: #374151; color: #d1d5db; }
[data-theme="dark"] .user-tier-badge.lite { background: #1e3a5f; color: #93c5fd; }
[data-theme="dark"] .user-tier-badge.pro { background: #5c4a1e; color: #fcd34d; }
[data-theme="dark"] .user-tier-badge.ultra { background: #3b2d6e; color: #c4b5fd; }
