/* ═══════════════════════════════════════════════════════
   Modern Clean + Subtle Warmth 主题
   ═══════════════════════════════════════════════════════ */

/* ── CSS 变量 ──────────────────────────────────────── */
:root {
    /* 背景层级 */
    --bg-base: #F0F4F8;
    --bg-surface: #FFFFFF;
    --bg-elevated: #F8FAFC;
    --bg-subtle: #E2E8F0;

    /* 主色调 — 蓝紫渐变系 */
    --primary: #5B7FFF;
    --primary-dark: #4F6EF7;
    --primary-light: #EEF1FF;
    --primary-gradient: linear-gradient(135deg, #5B7FFF 0%, #7C5CFC 100%);

    /* 功能色 */
    --success: #10B981;
    --success-light: #ECFDF5;
    --danger: #EF4444;
    --danger-light: #FEF2F2;
    --warning: #F59E0B;
    --warning-light: #FFFBEB;

    /* 文字 */
    --text-primary: #1E293B;
    --text-secondary: #64748B;
    --text-muted: #94A3B8;
    --text-inverse: #FFFFFF;

    /* 边框 */
    --border-light: #E8ECF0;
    --border-medium: #DEE2E8;

    /* 阴影 */
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06), 0 1px 3px rgba(0, 0, 0, 0.04);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.08), 0 2px 6px rgba(0, 0, 0, 0.04);
    --shadow-xl: 0 20px 48px rgba(0, 0, 0, 0.1), 0 4px 12px rgba(0, 0, 0, 0.05);
    --shadow-glow: 0 0 0 3px rgba(91, 127, 255, 0.15);

    /* 圆角 */
    --radius-xs: 4px;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-full: 9999px;

    /* 动画 */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --transition-slow: 350ms ease;

    /* 字体 */
    --font-sans: "Inter", "PingFang SC", "Microsoft YaHei", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --font-mono: "JetBrains Mono", "Cascadia Code", "Fira Code", Consolas, monospace;
}

/* ── 全局重置 ──────────────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-base);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

.hidden { display: none !important; }

/* ── 通用组件 ──────────────────────────────────────── */

input[type="text"],
textarea,
select {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-surface);
    border: 1.5px solid var(--border-light);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 15px;
    font-family: var(--font-sans);
    outline: none;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

input[type="text"]:focus,
textarea:focus,
select:focus {
    border-color: var(--primary);
    box-shadow: var(--shadow-glow);
}

input[type="text"]::placeholder,
textarea::placeholder {
    color: var(--text-muted);
}

textarea {
    resize: vertical;
    min-height: 80px;
}

select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748B' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

/* ── 按钮系统 ──────────────────────────────────────── */

.btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 28px;
    background: var(--primary-gradient);
    color: var(--text-inverse);
    border: none;
    border-radius: var(--radius-md);
    font-size: 15px;
    font-weight: 600;
    font-family: var(--font-sans);
    cursor: pointer;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast), opacity var(--transition-fast);
    box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md), 0 4px 14px rgba(91, 127, 255, 0.25);
}

.btn-primary:active {
    transform: translateY(0);
    box-shadow: var(--shadow-xs);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    background: var(--bg-surface);
    color: var(--text-secondary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    font-family: var(--font-sans);
    cursor: pointer;
    transition: all var(--transition-fast);
}

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

.btn-sm {
    padding: 6px 14px;
    font-size: 12px;
    font-weight: 500;
    background: var(--bg-elevated);
    color: var(--text-secondary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

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

/* ── 加载与错误 ────────────────────────────────────── */

.loading-bar {
    position: fixed;
    top: 56px;
    left: 0;
    right: 0;
    height: 38px;
    background: var(--primary-gradient);
    color: white;
    z-index: 9998;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.3px;
    animation: loadingSlideIn 0.3s ease-out;
    box-shadow: 0 2px 12px rgba(91, 127, 255, 0.3);
}

@keyframes loadingSlideIn {
    from { transform: translateY(-100%); }
    to   { transform: translateY(0); }
}

.error-msg {
    margin-top: 16px;
    padding: 14px 18px;
    background: var(--danger-light);
    border: 1px solid rgba(239, 68, 68, 0.2);
    border-radius: var(--radius-sm);
    color: var(--danger);
    font-size: 14px;
    font-weight: 500;
    animation: fadeIn var(--transition-normal);
}

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

/* ═══════════════════════════════════════════════════════
   首页 — 简洁无框
   ═══════════════════════════════════════════════════════ */
.index-page {
    max-width: 650px;
    margin: 0 auto;
    padding: 60px 24px 40px;
    min-height: 100vh;
}

.index-header {
    text-align: center;
    margin-bottom: 32px;
}

.index-logo {
    width: 56px;
    height: 56px;
    border-radius: var(--radius-md);
    background: var(--primary-gradient);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    margin-bottom: 16px;
}

.index-header h1 {
    font-size: 28px;
    font-weight: 800;
    margin-bottom: 8px;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.5px;
}

.index-subtitle {
    color: var(--text-secondary);
    font-size: 15px;
    line-height: 1.5;
}

.index-form {
    margin-bottom: 12px;
}

.index-form .form-group {
    margin-bottom: 20px;
}

.index-form label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    font-size: 14px;
    color: var(--text-primary);
    letter-spacing: 0.2px;
}

.index-form .optional {
    color: var(--text-muted);
    font-weight: 400;
    font-size: 12px;
}

.index-form .btn-primary {
    width: 100%;
    padding: 14px 24px;
    font-size: 16px;
    margin-top: 4px;
}

.index-err {
    margin-top: 12px;
}

/* 保留旧页面的通用 form-group 样式（学习页等使用） */
.form-group {
    margin-bottom: 22px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    font-size: 14px;
    color: var(--text-primary);
    letter-spacing: 0.2px;
}

.form-group .optional {
    color: var(--text-muted);
    font-weight: 400;
    font-size: 12px;
}

/* ═══════════════════════════════════════════════════════
   学习页布局
   ═══════════════════════════════════════════════════════ */
.layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ── 侧边栏 ───────────────────────────────────────── */
.sidebar {
    width: 280px;
    min-width: 280px;
    background: var(--bg-surface);
    border-right: 1px solid var(--border-light);
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-xs);
    z-index: 10;
}

.sidebar-header {
    padding: 22px 20px;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.sidebar-header h2 {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

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

.outline-item {
    padding: 14px 16px;
    margin-bottom: 6px;
    background: transparent;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    border-left: 3px solid transparent;
    position: relative;
}

.outline-item:hover {
    background: var(--bg-elevated);
    border-left-color: var(--border-medium);
}

.outline-item.active {
    background: var(--primary-light);
    border-left-color: var(--primary);
    box-shadow: var(--shadow-xs);
}

.outline-item.done {
    opacity: 0.55;
}

.outline-item.done .item-title::after {
    content: " ✓";
    color: var(--success);
    font-weight: 700;
}

.item-title {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-primary);
    transition: color var(--transition-fast);
}

.outline-item.active .item-title {
    color: var(--primary);
}

.item-summary {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.4;
}

.expand-badge {
    display: inline-block;
    font-size: 10px;
    font-weight: 600;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: #fff;
    padding: 1px 6px;
    border-radius: 4px;
    margin-right: 6px;
    vertical-align: middle;
    letter-spacing: 0.3px;
}

.outline-item.done .item-title .expand-badge,
.outline-item.preloaded .item-title .expand-badge {
    background: linear-gradient(135deg, #34d399, #059669);
}

.outline-item.has-history::before {
    content: "";
    position: absolute;
    left: -7.5px;
    top: 50%;
    transform: translateY(-50%);
    width: 8px;
    height: 8px;
    background: var(--success);
    border-radius: 50%;
    box-shadow: 0 0 0 2px var(--bg-surface);
}

/* ── 预加载状态 ──────────────────────────────────── */

.preload-progress {
    padding: 6px 16px;
    font-size: 0.75rem;
    color: var(--text-secondary);
    background: var(--bg-elevated);
    border-radius: var(--radius-xs);
    margin: 0 12px 6px;
    text-align: center;
    transition: all 0.3s;
}
.preload-progress.done {
    color: var(--success);
    background: var(--success-light);
}

.outline-item.preloading .item-title::after {
    content: " ⏳";
    font-size: 0.7rem;
}

.outline-item.preloaded .item-title::after {
    content: " ✅";
    font-size: 0.7rem;
    color: var(--success);
}

.outline-item.preload-error .item-title::after {
    content: " ❌";
    font-size: 0.7rem;
    color: var(--danger);
}

@keyframes pulse-dot {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 1; }
}

.outline-item.preloading {
    opacity: 0.85;
}

.outline-item.preloading .item-title::after {
    animation: pulse-dot 1.5s ease-in-out infinite;
}

/* ── 首页话题标签 ──────────────────────────────────── */
/* ── 教学风格选择器 ──────────────────────────────── */
.style-selector {
    margin: 0 0 16px;
}
.style-label {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}
.style-options {
    display: flex;
    gap: 6px;
}
.style-card {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 8px 4px;
    border: 1.5px solid #e2e8f0;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.15s;
    user-select: none;
    background: #fff;
}
.style-card:hover {
    border-color: #a5b4fc;
    background: #f8f9ff;
}
.style-card.selected {
    border-color: #6366f1;
    background: #eef1ff;
    box-shadow: 0 0 0 1px #6366f1;
}
.style-icon {
    font-size: 20px;
    line-height: 1;
}
.style-name {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.2;
}
.style-desc {
    font-size: 10px;
    color: var(--text-muted);
    line-height: 1.2;
    text-align: center;
}

@media (max-width: 480px) {
    .style-card {
        min-width: 80px;
        padding: 8px 6px;
    }
    .style-card-slim {
        max-width: 120px;
    }
    .style-icon { font-size: 16px; }
    .style-name { font-size: 11px; }
    .style-desc { display: none; }
}

/* ── 精简模式开关 ──────────────────────────────── */
.toggle-switch {
    position: relative; display: inline-block;
    width: 40px; height: 22px;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
    position: absolute; cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background: #cbd5e1; border-radius: 22px;
    transition: 0.2s;
}
.toggle-slider:before {
    content: ""; position: absolute;
    height: 16px; width: 16px; left: 3px; bottom: 3px;
    background: #fff; border-radius: 50%;
    transition: 0.2s;
}
.toggle-switch input:checked + .toggle-slider { background: #6366f1; }
.toggle-switch input:checked + .toggle-slider:before { transform: translateX(18px); }
.chip:hover {
    background: var(--primary, #6366f1);
    border-color: var(--primary, #6366f1);
    color: #fff;
}

/* ── 主内容区 ─────────────────────────────────────── */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg-base);
}

.content-header {
    padding: 18px 28px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow-xs);
}

.content-header h1 {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.3px;
}

#progress {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
    background: var(--bg-elevated);
    padding: 6px 14px;
    border-radius: var(--radius-full);
}

/* ── 聊天区 ───────────────────────────────────────── */
.chat-area {
    flex: 1;
    overflow-y: auto;
    padding: 24px 28px;
    scroll-behavior: smooth;
}

/* 自定义滚动条 */
.chat-area::-webkit-scrollbar {
    width: 6px;
}

.chat-area::-webkit-scrollbar-track {
    background: transparent;
}

.chat-area::-webkit-scrollbar-thumb {
    background: var(--border-medium);
    border-radius: var(--radius-full);
}

.chat-area::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

.placeholder {
    text-align: center;
    color: var(--text-muted);
    padding: 100px 20px;
    font-size: 16px;
}

.placeholder::before {
    content: "";
    display: block;
    width: 64px;
    height: 64px;
    border-radius: var(--radius-md);
    background: var(--primary-gradient);
    opacity: 0.12;
    margin: 0 auto 20px;
}

/* ── 消息气泡 ─────────────────────────────────────── */
.message {
    margin-bottom: 20px;
    max-width: 85%;
    animation: msgEnter 0.35s ease-out;
}

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

.msg-user {
    margin-left: auto;
    max-width: 65%;
}

.msg-ai {
    margin-right: auto;
    /* 手机端：可选择但禁止原生菜单干扰划词浮动按钮 */
    -webkit-user-select: text;
    user-select: text;
    -webkit-touch-callout: none;
}

.msg-label {
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: 6px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding-left: 4px;
}

.msg-body {
    padding: 14px 20px;
    border-radius: var(--radius-lg);
    font-size: 15px;
    line-height: 1.8;
    word-break: break-word;
}

.msg-user .msg-body {
    background: var(--primary-gradient);
    color: var(--text-inverse);
    border-bottom-right-radius: var(--radius-xs);
    box-shadow: 0 4px 14px rgba(91, 127, 255, 0.2);
}

.msg-ai .msg-body {
    background: var(--bg-surface);
    border: 1px solid var(--border-light);
    border-bottom-left-radius: var(--radius-xs);
    box-shadow: var(--shadow-sm);
}

/* ── Markdown 渲染样式 ────────────────────────────── */
.msg-body h1, .msg-body h2 {
    font-size: 20px;
    margin: 20px 0 10px;
    color: var(--primary-dark);
    font-weight: 700;
}

.msg-body h3 {
    font-size: 17px;
    margin: 16px 0 8px;
    color: var(--primary);
    font-weight: 700;
}

.msg-body h4 {
    font-size: 15px;
    margin: 12px 0 6px;
    color: var(--text-primary);
    font-weight: 600;
}

.msg-body p {
    margin: 0 0 10px;
}

.msg-body p:last-child {
    margin-bottom: 0;
}

.msg-body ul, .msg-body ol {
    margin: 8px 0 10px;
    padding-left: 24px;
}

.msg-body li {
    margin-bottom: 4px;
}

.msg-body code {
    background: var(--bg-elevated);
    padding: 2px 8px;
    border-radius: var(--radius-xs);
    font-size: 13px;
    font-family: var(--font-mono);
    color: var(--primary-dark);
}

.msg-user .msg-body code {
    background: rgba(255, 255, 255, 0.2);
    color: var(--text-inverse);
}

.msg-body pre {
    background: #1E293B;
    padding: 16px 20px;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    margin: 12px 0;
    font-size: 13px;
    line-height: 1.6;
}

.msg-body pre code {
    background: none;
    color: #E2E8F0;
    padding: 0;
}

.msg-user .msg-body pre {
    background: rgba(0, 0, 0, 0.2);
}

.msg-body strong {
    font-weight: 700;
    color: var(--text-primary);
}

.msg-user .msg-body strong {
    color: var(--text-inverse);
}

.msg-body a {
    color: var(--primary);
    text-decoration: underline;
}

.msg-body blockquote {
    border-left: 4px solid var(--primary);
    padding: 8px 16px;
    margin: 12px 0;
    background: var(--primary-light);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    color: var(--text-secondary);
    font-style: italic;
}

/* ── MathJax 公式样式 ─────────────────────────────── */
.msg-body mjx-container {
    overflow-x: auto;
    overflow-y: hidden;
    margin: 8px 0;
}

.msg-body mjx-container[display="true"] {
    display: block;
    margin: 14px 0;
    text-align: center;
}

/* ── 表格样式 ─────────────────────────────────────── */
.msg-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
    font-size: 14px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.msg-body table thead tr {
    background: var(--primary-gradient);
    color: white;
}

.msg-body table th {
    padding: 10px 14px;
    font-weight: 600;
    text-align: left;
    font-size: 13px;
    border: 1px solid rgba(255,255,255,0.15);
    white-space: nowrap;
}

.msg-body table td {
    padding: 9px 14px;
    border: 1px solid var(--border-light);
    line-height: 1.5;
    color: var(--text-primary);
}

.msg-body table tbody tr:nth-child(odd) {
    background: var(--bg-surface);
}

.msg-body table tbody tr:nth-child(even) {
    background: var(--bg-elevated);
}

.msg-body table tbody tr:hover {
    background: var(--primary-light);
}

/* ── 章节配图 ─────────────────────────────────────── */
.chapter-img-container {
    margin: 16px 0;
}

.chapter-img-wrapper {
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-md);
    background: var(--bg-elevated);
    position: relative;
}

.chapter-img {
    width: 100%;
    max-height: 280px;
    object-fit: cover;
    display: block;
    transition: transform 0.4s ease;
}

.chapter-img:hover {
    transform: scale(1.02);
}

.chapter-img-caption {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 8px 14px;
    background: linear-gradient(transparent, rgba(0,0,0,0.45));
    color: rgba(255,255,255,0.9);
    font-size: 12px;
    font-weight: 500;
}

/* ── 输入区 ───────────────────────────────────────── */
.input-area {
    padding: 12px 28px 16px;
    background: transparent;
    border-top: none;
    box-shadow: none;
}

.input-row {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
    align-items: center;
    background: var(--bg-surface);
    border-radius: var(--radius-xl);
    padding: 6px 6px 6px 16px;
    box-shadow: var(--shadow-md);
    border: 1.5px solid var(--border-light);
    transition: box-shadow var(--transition-fast), border-color var(--transition-fast);
}

.input-row:focus-within {
    box-shadow: var(--shadow-lg), var(--shadow-glow);
    border-color: var(--primary);
}

.input-row input {
    flex: 1;
    padding: 10px 4px;
    border-radius: 0;
    border: none;
    background: transparent;
    font-size: 14px;
    transition: none;
    box-shadow: none;
    outline: none;
}

.input-row input:focus {
    border-color: transparent;
    background: transparent;
    box-shadow: none;
}

.input-row button {
    flex-shrink: 0;
    padding: 10px 20px;
    border-radius: var(--radius-lg);
    font-size: 14px;
}

.action-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    padding: 0 4px;
}

/* ═══════════════════════════════════════════════════════
   选择题交互组件
   ═══════════════════════════════════════════════════════ */
.quiz-container {
    margin-top: 12px;
    padding: 16px 20px;
    background: var(--bg-elevated);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-light);
}

.quiz-title {
    font-weight: 700;
    font-size: 14px;
    margin-bottom: 10px;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 6px;
}

.quiz-question {
    font-size: 14px;
    margin-bottom: 12px;
    line-height: 1.6;
    color: var(--text-primary);
    font-weight: 500;
}

.quiz-option {
    display: block;
    width: 100%;
    text-align: left;
    padding: 10px 16px;
    margin-bottom: 8px;
    background: var(--bg-surface);
    border: 1.5px solid var(--border-light);
    border-radius: var(--radius-sm);
    font-size: 14px;
    cursor: pointer;
    color: var(--text-primary);
    font-family: var(--font-sans);
    transition: all var(--transition-fast);
}

.quiz-option:hover:not(:disabled) {
    border-color: var(--primary);
    background: var(--primary-light);
    transform: translateX(4px);
}

.quiz-option:disabled {
    cursor: default;
    opacity: 0.7;
}

.quiz-option.correct {
    border-color: var(--success);
    background: var(--success-light);
    color: #065F46;
}

.quiz-option.wrong {
    border-color: var(--danger);
    background: var(--danger-light);
    color: #991B1B;
}

.quiz-feedback {
    margin-top: 12px;
    padding: 12px 16px;
    background: var(--bg-surface);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-light);
    font-size: 14px;
    line-height: 1.6;
}

/* ═══════════════════════════════════════════════════════
   划词解释
   ═══════════════════════════════════════════════════════ */
.ask-float-btn {
    position: fixed;
    padding: 10px 18px;
    background: var(--primary-gradient);
    color: var(--text-inverse);
    border-radius: var(--radius-full);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    z-index: 999;
    box-shadow: var(--shadow-lg);
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
    font-family: var(--font-sans);
}

.ask-float-btn:hover {
    transform: scale(1.08);
    box-shadow: var(--shadow-xl);
}

.explain-term {
    border-bottom: 2px dashed var(--primary);
    cursor: pointer;
    position: relative;
    transition: background var(--transition-fast);
    border-radius: 2px;
}

.explain-term:hover {
    background: var(--primary-light);
}

.explain-term.active {
    background: rgba(91, 127, 255, 0.1);
}

.explain-answer {
    margin: 6px 0 6px 20px;
    padding: 12px 16px;
    background: var(--bg-elevated);
    border-left: 3px solid var(--primary);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    font-size: 14px;
    line-height: 1.7;
    color: var(--text-primary);
    animation: fadeIn var(--transition-fast);
}

/* ═══════════════════════════════════════════════════════
   出题弹框
   ═══════════════════════════════════════════════════════ */
.quiz-dialog {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: dialogOverlay 0.2s ease-out;
}

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

.quiz-dialog-content {
    background: var(--bg-surface);
    border-radius: var(--radius-xl);
    width: 500px;
    max-width: 92vw;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: var(--shadow-xl);
    animation: dialogEnter 0.3s ease-out;
}

@keyframes dialogEnter {
    from { opacity: 0; transform: scale(0.95) translateY(12px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}

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

.quiz-dialog-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
}

.quiz-dialog-body {
    padding: 24px;
}

.quiz-config-row {
    margin-bottom: 22px;
    display: flex;
    align-items: flex-start;
    gap: 16px;
}

.quiz-config-label {
    min-width: 72px;
    font-weight: 600;
    font-size: 14px;
    color: var(--text-primary);
    padding-top: 4px;
}

.radio-group,
.checkbox-group {
    display: flex;
    gap: 18px;
    flex-wrap: wrap;
}

.quiz-radio,
.quiz-checkbox {
    font-size: 14px;
    cursor: pointer;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 6px;
    transition: color var(--transition-fast);
}

.quiz-radio:hover,
.quiz-checkbox:hover {
    color: var(--primary);
}

.quiz-radio input,
.quiz-checkbox input {
    accent-color: var(--primary);
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.quiz-select {
    flex: 1;
    max-width: 200px;
    padding: 8px 36px 8px 14px;
    border: 1.5px solid var(--border-light);
    border-radius: var(--radius-sm);
    font-size: 14px;
    background: var(--bg-surface);
    color: var(--text-primary);
    cursor: pointer;
    font-family: var(--font-sans);
    transition: border-color var(--transition-fast);
}

.quiz-select:focus {
    border-color: var(--primary);
}

.quiz-dialog-body .btn-primary {
    width: 100%;
    margin-top: 4px;
}

/* ═══════════════════════════════════════════════════════
   试卷渲染
   ═══════════════════════════════════════════════════════ */
.quiz-paper {
    padding: 18px 22px;
    background: var(--bg-surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
}

.quiz-q-item {
    padding: 20px 22px;
    margin-bottom: 16px;
    background: var(--bg-elevated);
    border-radius: var(--radius-md);
    border: 1.5px solid var(--border-light);
    transition: all var(--transition-fast);
}

.quiz-q-item:hover {
    border-color: var(--border-medium);
    box-shadow: var(--shadow-xs);
}

.quiz-q-correct {
    border-color: var(--success) !important;
    background: var(--success-light) !important;
}

.quiz-q-wrong {
    border-color: var(--danger) !important;
    background: var(--danger-light) !important;
}

.quiz-q-title {
    font-weight: 600;
    font-size: 15px;
    margin-bottom: 14px;
    color: var(--text-primary);
    line-height: 1.6;
    padding-bottom: 10px;
    border-bottom: 1px dashed var(--border-light);
}

.quiz-opt-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.quiz-tf-group {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.quiz-opt-btn {
    display: block;
    width: 100%;
    text-align: left;
    padding: 12px 18px;
    border: 2px solid var(--border-medium);
    border-radius: var(--radius-md);
    background: var(--bg-surface);
    color: var(--text-primary);
    font-size: 14px;
    cursor: pointer;
    font-family: var(--font-sans);
    transition: all var(--transition-fast);
    box-shadow: var(--shadow-xs);
    position: relative;
}

.quiz-tf-btn {
    padding: 12px 24px;
    border: 2px solid var(--border-medium);
    border-radius: var(--radius-md);
    background: var(--bg-surface);
    color: var(--text-primary);
    font-size: 14px;
    cursor: pointer;
    font-family: var(--font-sans);
    transition: all var(--transition-fast);
    box-shadow: var(--shadow-xs);
    min-width: 100px;
    text-align: center;
}

.quiz-opt-btn:hover:not(:disabled) {
    border-color: var(--primary);
    background: var(--primary-light);
    transform: translateX(4px);
    box-shadow: var(--shadow-sm);
}

.quiz-tf-btn:hover:not(:disabled) {
    border-color: var(--primary);
    background: var(--primary-light);
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
}

.quiz-opt-btn.selected {
    border-color: var(--primary);
    background: var(--primary);
    color: white;
    font-weight: 600;
    box-shadow: var(--shadow-sm);
    transform: translateX(4px);
}

.quiz-tf-btn.selected {
    border-color: var(--primary);
    background: var(--primary);
    color: white;
    font-weight: 600;
    box-shadow: var(--shadow-sm);
    transform: translateY(-1px);
}

.quiz-opt-btn.selected::after,
.quiz-tf-btn.selected::after {
    content: "✓";
    position: absolute;
    top: 50%;
    right: 14px;
    transform: translateY(-50%);
    width: 22px;
    height: 22px;
    background: var(--success);
    color: white;
    font-size: 13px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-xs);
}

.quiz-opt-btn.correct,
.quiz-tf-btn.correct {
    border-color: var(--success);
    background: var(--success-light);
    color: #065F46;
}

.quiz-opt-btn:disabled,
.quiz-tf-btn:disabled {
    cursor: default;
    opacity: 0.6;
}

.quiz-fill-input {
    width: 100%;
    padding: 10px 16px;
    border: 1.5px solid var(--border-light);
    border-radius: var(--radius-sm);
    font-size: 14px;
    background: var(--bg-surface);
    color: var(--text-primary);
    font-family: var(--font-sans);
    outline: none;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.quiz-fill-input:focus {
    border-color: var(--primary);
    box-shadow: var(--shadow-glow);
}

.quiz-fill-input:disabled {
    background: var(--bg-elevated);
    opacity: 0.6;
}

.quiz-q-feedback {
    margin-top: 10px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    line-height: 1.6;
    animation: fadeIn var(--transition-fast);
}

.quiz-result-correct {
    color: #065F46;
    font-weight: 600;
}

.quiz-result-wrong {
    color: #991B1B;
    font-weight: 600;
}

.quiz-explanation {
    margin-top: 6px;
    color: var(--text-secondary);
    font-size: 13px;
    line-height: 1.6;
}

.quiz-action-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border-light);
}

.quiz-action-bar .btn-primary {
    width: auto;
}

.quiz-score-summary {
    font-size: 16px;
    font-weight: 700;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    padding: 4px 0;
}

/* ── 复习文档编辑器 ───────────────────────────────── */
.review-editor {
    width: 100%;
    min-height: 400px;
    padding: 14px 18px;
    border: 2px solid var(--primary);
    border-radius: var(--radius-md);
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.8;
    resize: vertical;
    background: var(--bg-surface);
    color: var(--text-primary);
    outline: none;
}

.review-editor:focus {
    box-shadow: var(--shadow-glow);
}

/* ═══════════════════════════════════════════════════════
   响应式
   ═══════════════════════════════════════════════════════ */

/* 汉堡按钮：桌面隐藏，手机显示 */
.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 22px;
    cursor: pointer;
    padding: 4px;
    color: var(--text-primary);
    line-height: 1;
    flex-shrink: 0;
}

@media (max-width: 768px) {
    .sidebar-toggle { display: flex; align-items: center; justify-content: center; }

    .sidebar {
        position: fixed;
        top: 0;
        left: -300px;
        width: 280px;
        height: 100vh;
        z-index: 1000;
        transition: left 0.3s ease;
        box-shadow: 4px 0 20px rgba(0,0,0,0.15);
    }
    .sidebar.open {
        left: 0;
    }

    /* 侧边栏打开时的遮罩层 */
    body.sidebar-open::after {
        content: "";
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.35);
        z-index: 999;
    }

    .loading-bar { font-size: 12px; height: 34px; }

    .card {
        padding: 32px 24px;
        margin: 0 12px;
    }

    .content-header {
        padding: 12px 14px;
        gap: 10px;
    }

    .content-header h1 {
        font-size: 15px;
        flex: 1;
        min-width: 0;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    #progress {
        font-size: 12px;
        padding: 4px 10px;
        white-space: nowrap;
    }

    .chat-area {
        padding: 14px 12px;
    }

    .input-area {
        padding: 10px 12px 14px;
    }

    .message {
        max-width: 95%;
    }

    .msg-user {
        max-width: 85%;
    }

    .msg-body {
        padding: 12px 14px;
        font-size: 14px;
        line-height: 1.7;
    }

    .action-row {
        gap: 6px;
    }
    .action-row .btn-secondary {
        font-size: 12px;
        padding: 6px 10px;
    }

    .quiz-dialog-content {
        width: 100%;
        max-width: 100%;
        max-height: 100vh;
        border-radius: 0;
    }
}

/* ── 反馈栏 ─────────────────────────────────────── */
.feedback-bar {
    max-width: 520px; margin: 24px auto 0;
    text-align: center;
}
.feedback-toggle {
    font-size: 0.82rem; color: var(--text-secondary, #94a3b8);
    cursor: pointer; text-decoration: underline;
    transition: color 0.15s;
}
.feedback-toggle:hover { color: var(--primary, #6366f1); }
.feedback-form {
    margin-top: 10px; text-align: left;
}
.feedback-form textarea {
    width: 100%; padding: 10px 14px;
    border: 1.5px solid var(--border, #e2e8f0);
    border-radius: 8px; font-size: 13px;
    resize: vertical; box-sizing: border-box;
    font-family: inherit;
}
.feedback-form textarea:focus {
    border-color: var(--primary, #6366f1); outline: none;
}