/* ========== 全局重置 ========== */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif; font-size: 14px; color: #333; background: #f5f7fa; overflow-x: hidden; overscroll-behavior: none; }
input, button, select, textarea { font-family: inherit; font-size: 14px; outline: none; border: none; }
button { cursor: pointer; background: none; }
a { text-decoration: none; color: inherit; }

#app { display: flex; flex-direction: column; height: 100vh; max-width: 480px; margin: 0 auto; background: #f5f7fa; position: relative; }

/* ========== 导航栏 ========== */
.navbar { display: flex; align-items: center; height: 50px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: #fff; padding: 0 12px; flex-shrink: 0; position: relative; z-index: 100; }
.navbar-left, .navbar-right { width: 40px; display: flex; align-items: center; justify-content: center; cursor: pointer; }
.navbar-title { flex: 1; text-align: center; font-size: 17px; font-weight: 600; }

/* ========== 主内容区 ========== */
.main { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; position: relative; overscroll-behavior: none; }
.page { min-height: 100%; padding-bottom: 20px; }

/* ========== 登录页 ========== */
.page-login { display: flex; flex-direction: column; align-items: center; padding: 40px 24px; background: linear-gradient(180deg, #667eea 0%, #764ba2 40%, #f5f7fa 40%); }
.login-logo { text-align: center; margin-bottom: 30px; color: #fff; }
.logo-icon { font-size: 56px; margin-bottom: 12px; }
.login-logo h1 { font-size: 26px; margin-bottom: 8px; }
.login-logo p { font-size: 13px; opacity: 0.85; }
.login-form { width: 100%; background: #fff; border-radius: 16px; padding: 24px 20px; box-shadow: 0 8px 30px rgba(0,0,0,0.08); }
.tab-group { display: flex; margin-bottom: 20px; background: #f0f2f5; border-radius: 8px; padding: 4px; }
.tab { flex: 1; text-align: center; padding: 10px 0; border-radius: 6px; font-size: 15px; color: #999; cursor: pointer; transition: all 0.3s; }
.tab.active { background: #fff; color: #667eea; font-weight: 600; box-shadow: 0 2px 8px rgba(102,126,234,0.15); }
.form-group { margin-bottom: 14px; }
.form-group input, .form-group select { width: 100%; height: 46px; padding: 0 14px; border: 1px solid #e8e8e8; border-radius: 10px; font-size: 15px; background: #fafafa; transition: border-color 0.3s; }
.form-group input:focus, .form-group select:focus { border-color: #667eea; background: #fff; }
.form-label { display: block; font-size: 13px; color: #888; margin-bottom: 6px; }
.btn-primary { width: 100%; height: 48px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: #fff; border-radius: 10px; font-size: 16px; font-weight: 600; margin-top: 8px; transition: opacity 0.3s; }
.btn-primary:active { opacity: 0.85; }
.btn-primary:disabled { opacity: 0.5; }
.login-tip { margin-top: 24px; font-size: 12px; color: #999; }

/* ========== 首页 ========== */
.page-home { padding: 16px; }
.user-card { display: flex; align-items: center; background: #fff; border-radius: 14px; padding: 16px; margin-bottom: 20px; box-shadow: 0 2px 12px rgba(0,0,0,0.04); }
.user-avatar { width: 50px; height: 50px; border-radius: 50%; background: linear-gradient(135deg, #667eea, #764ba2); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 20px; font-weight: 600; margin-right: 12px; }
.user-info { flex: 1; }
.user-name { font-size: 17px; font-weight: 600; margin-bottom: 4px; }
.user-meta { font-size: 13px; color: #999; }
.btn-logout { padding: 6px 14px; border: 1px solid #e8e8e8; border-radius: 20px; font-size: 13px; color: #999; }

.section-title { font-size: 16px; font-weight: 600; margin: 20px 0 12px; display: flex; justify-content: space-between; align-items: center; }
.section-more { font-size: 13px; color: #667eea; font-weight: normal; cursor: pointer; }

.mode-list { display: flex; flex-direction: column; gap: 12px; }
.mode-card { display: flex; align-items: center; background: #fff; border-radius: 14px; padding: 16px; box-shadow: 0 2px 12px rgba(0,0,0,0.04); cursor: pointer; transition: transform 0.2s, box-shadow 0.2s; border-left: 4px solid transparent; }
.mode-card:active { transform: scale(0.98); }
.mode-primary { border-left-color: #52c41a; }
.mode-middle { border-left-color: #faad14; }
.mode-advanced { border-left-color: #f5222d; }
.mode-icon { font-size: 32px; margin-right: 14px; }
.mode-name { font-size: 16px; font-weight: 600; margin-bottom: 4px; }
.mode-desc { font-size: 13px; color: #999; }

/* 会话列表 */
.session-list { display: flex; flex-direction: column; gap: 10px; }
.session-item { background: #fff; border-radius: 12px; padding: 14px; cursor: pointer; box-shadow: 0 2px 8px rgba(0,0,0,0.03); }
.session-item:active { background: #f9f9f9; }
.session-question { font-size: 14px; color: #333; margin-bottom: 8px; line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.session-question-img { max-width: 100%; max-height: 120px; border-radius: 8px; margin-bottom: 8px; border: 1px solid #f0f0f0; display: block; }
.session-meta { display: flex; justify-content: space-between; font-size: 12px; color: #bbb; }
.session-tag { padding: 2px 8px; border-radius: 10px; font-size: 11px; }
.tag-primary { background: #f6ffed; color: #52c41a; }
.tag-middle { background: #fffbe6; color: #faad14; }
.tag-advanced { background: #fff1f0; color: #f5222d; }

.empty-tip { text-align: center; color: #ccc; font-size: 14px; padding: 40px 0; }

/* ========== 拍照页 ========== */
.page-camera { padding: 0; background: #000; position: relative; }
.camera-container { position: relative; width: 100%; height: calc(100vh - 50px - 100px); overflow: hidden; }
#cameraVideo { width: 100%; height: 100%; object-fit: cover; }
.camera-overlay { position: absolute; top: 0; left: 0; right: 0; bottom: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; pointer-events: none; }
.scan-frame { position: relative; width: 80%; height: 60%; border: 2px solid rgba(255,255,255,0.3); border-radius: 12px; }
.scan-corner { position: absolute; width: 24px; height: 24px; border-color: #667eea; border-style: solid; }
.scan-corner.tl { top: -2px; left: -2px; border-width: 3px 0 0 3px; border-radius: 8px 0 0 0; }
.scan-corner.tr { top: -2px; right: -2px; border-width: 3px 3px 0 0; border-radius: 0 8px 0 0; }
.scan-corner.bl { bottom: -2px; left: -2px; border-width: 0 0 3px 3px; border-radius: 0 0 0 8px; }
.scan-corner.br { bottom: -2px; right: -2px; border-width: 0 3px 3px 0; border-radius: 0 0 8px 0; }
.scan-line { position: absolute; left: 10%; right: 10%; height: 2px; background: linear-gradient(90deg, transparent, #667eea, transparent); animation: scan 2s linear infinite; }
@keyframes scan { 0% { top: 10%; } 50% { top: 85%; } 100% { top: 10%; } }
.camera-tip { margin-top: 20px; color: #fff; font-size: 14px; text-shadow: 0 1px 4px rgba(0,0,0,0.5); }

.camera-controls { display: flex; align-items: center; justify-content: space-around; padding: 20px 0; background: #000; }

/* 裁剪识题界面 */
.crop-stage { position: fixed; top: 50px; bottom: 0; left: 50%; transform: translateX(-50%); width: 100%; max-width: 480px; background: #000; z-index: 900; display: flex; flex-direction: column; }
.crop-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; color: #fff; font-size: 16px; }
.crop-title { font-weight: 600; }
.btn-crop-auto { padding: 8px 16px; border-radius: 18px; background: linear-gradient(135deg, #667eea, #764ba2); color: #fff; font-size: 13px; font-weight: 600; }
.crop-container { flex: 1; position: relative; overflow: hidden; min-height: 0; }
#cropImage { position: absolute; user-select: none; -webkit-user-select: none; }
.crop-box { position: absolute; border: 2px solid #667eea; box-shadow: 0 0 0 9999px rgba(0,0,0,0.4); touch-action: none; }
.crop-handle { position: absolute; width: 24px; height: 24px; border: 3px solid #fff; background: #667eea; border-radius: 4px; box-shadow: 0 1px 3px rgba(0,0,0,0.3); }
.crop-handle.tl { top: -2px; left: -2px; cursor: nwse-resize; }
.crop-handle.tr { top: -2px; right: -2px; cursor: nesw-resize; }
.crop-handle.bl { bottom: -2px; left: -2px; cursor: nesw-resize; }
.crop-handle.br { bottom: -2px; right: -2px; cursor: nwse-resize; }
.crop-tip { text-align: center; color: rgba(255,255,255,0.7); font-size: 12px; padding: 8px 16px; }
.crop-controls { display: flex; gap: 12px; padding: 14px 16px 24px; }
.crop-controls .btn-primary, .crop-controls .btn-secondary { flex: 1; height: 46px; margin-top: 0; }
.btn-camera-switch, .btn-album { width: 48px; height: 48px; border-radius: 50%; background: rgba(255,255,255,0.15); color: #fff; font-size: 22px; display: flex; align-items: center; justify-content: center; }
.btn-capture { width: 72px; height: 72px; border-radius: 50%; background: #fff; padding: 5px; }
.capture-inner { width: 100%; height: 100%; border-radius: 50%; background: #fff; border: 3px solid #667eea; }

.ocr-result { position: absolute; bottom: 0; left: 0; right: 0; background: #fff; border-radius: 20px 20px 0 0; padding: 20px; max-height: 72%; overflow-y: auto; }
.ocr-title { font-size: 16px; font-weight: 600; margin-bottom: 10px; color: #333; }
.ocr-image-box { margin-bottom: 12px; text-align: center; }
.ocr-image { max-width: 100%; max-height: 260px; border-radius: 10px; border: 1px solid #e8e8e8; box-shadow: 0 2px 8px rgba(0,0,0,0.08); }
.ocr-figure-tip { font-size: 13px; line-height: 1.6; background: #fff7e6; color: #b8860b; border: 1px solid #ffe7ba; border-radius: 8px; padding: 10px 12px; margin-bottom: 12px; }
.ocr-figure-tip.warn { background: #fff1f0; color: #d4380d; border-color: #ffccc7; }
.ocr-text { font-size: 14px; line-height: 1.7; color: #555; max-height: 150px; overflow-y: auto; background: #f9f9f9; padding: 12px; border-radius: 8px; margin-bottom: 14px; white-space: pre-wrap; }
.ocr-supplement-row { margin-bottom: 14px; }
.ocr-supplement-row .form-label { margin-bottom: 6px; font-size: 13px; color: #b8860b; }
.ocr-supplement { width: 100%; font-size: 14px; line-height: 1.6; color: #555; background: #fffdf5; padding: 10px 12px; border: 1px solid #ffe7ba; border-radius: 8px; resize: vertical; box-sizing: border-box; font-family: inherit; }
.ocr-supplement:focus { outline: none; border-color: #b8860b; }
.ocr-actions { display: flex; gap: 12px; }
.ocr-subject-row { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.ocr-subject-row .form-label { margin-bottom: 0; white-space: nowrap; }
.ocr-subject-row select { flex: 1; height: 40px; padding: 0 10px; border: 1px solid #e8e8e8; border-radius: 8px; font-size: 14px; background: #fafafa; }
.btn-secondary { flex: 1; height: 44px; border: 1px solid #e8e8e8; border-radius: 10px; font-size: 15px; color: #666; }

/* ========== 对话页 ========== */
.page-chat { display: flex; flex-direction: column; height: calc(100vh - 50px); max-height: calc(100vh - 50px); padding: 0; overflow: hidden; overscroll-behavior: contain; }
.chat-question { background: #fff; padding: 12px 16px; font-size: 14px; color: #555; line-height: 1.6; border-bottom: 1px solid #f0f0f0; flex-shrink: 0; z-index: 30; box-shadow: 0 2px 8px rgba(0,0,0,0.06); transition: padding 0.2s; }
.chat-question.frozen { padding: 10px 16px; font-size: 13px; box-shadow: 0 2px 12px rgba(0,0,0,0.12); }
.chat-question-image-box { text-align: center; margin-bottom: 8px; }
.chat-question-image { max-width: 100%; max-height: 240px; border-radius: 10px; border: 1px solid #e8e8e8; box-shadow: 0 2px 8px rgba(0,0,0,0.08); }
.chat-question-text { word-break: break-word; white-space: pre-wrap; }
.chat-mode-badge { display: inline-block; margin: 8px 16px 0; padding: 4px 12px; border-radius: 12px; font-size: 12px; background: #f0f5ff; color: #667eea; align-self: flex-start; flex-shrink: 0; }
.chat-messages { flex: 1; min-height: 0; overflow-y: auto; padding: 12px 16px; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.msg-row { display: flex; margin-bottom: 14px; }
.msg-row.user { justify-content: flex-end; }
.msg-bubble { max-width: 75%; padding: 10px 14px; border-radius: 14px; font-size: 14px; line-height: 1.6; word-break: break-word; white-space: pre-wrap; }
.msg-row.ai .msg-bubble { background: #fff; color: #333; border-bottom-left-radius: 4px; box-shadow: 0 1px 4px rgba(0,0,0,0.05); }
.msg-row.user .msg-bubble { background: linear-gradient(135deg, #667eea, #764ba2); color: #fff; border-bottom-right-radius: 4px; }
.typing-cursor { display: inline-block; animation: blink 0.8s infinite; color: #999; font-weight: normal; }
@keyframes blink { 0%, 50% { opacity: 1; } 51%, 100% { opacity: 0; } }

/* ========== KaTeX 公式渲染适配（数学/物理/化学）========== */
/* 独立公式过长时可横向滚动，避免撑破气泡或容器 */
.msg-bubble .katex-display,
.chat-question .katex-display,
.ocr-text .katex-display,
.exercise-question .katex-display,
.exercise-result .katex-display { margin: 6px 0; overflow-x: auto; overflow-y: hidden; max-width: 100%; }
/* 行内公式随中文正常换行，略微放大提升可读性 */
.msg-bubble .katex, .ocr-text .katex, .chat-question .katex, .exercise-question .katex { font-size: 1.08em; }
.msg-avatar { width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 16px; flex-shrink: 0; margin: 0 8px; }
.msg-row.ai .msg-avatar { background: #f0f5ff; }
.msg-row.user .msg-avatar { background: #fff1f0; }
/* AI 回复重播按钮 */
.btn-replay-ai { width: 30px; height: 30px; border-radius: 50%; background: #f0f5ff; color: #667eea; font-size: 15px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; margin-left: 4px; align-self: flex-end; transition: background 0.2s, transform 0.1s; }
.btn-replay-ai:active { background: #d6e4ff; transform: scale(0.92); }
.msg-typing { display: flex; gap: 4px; padding: 12px 16px; }
.msg-typing span { width: 8px; height: 8px; border-radius: 50%; background: #ccc; animation: typing 1.4s infinite; }
.msg-typing span:nth-child(2) { animation-delay: 0.2s; }
.msg-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing { 0%, 60%, 100% { transform: translateY(0); opacity: 0.4; } 30% { transform: translateY(-6px); opacity: 1; } }

.chat-input-bar { display: flex; align-items: stretch; padding: 8px 10px; background: #fff; border-top: 1px solid #f0f0f0; gap: 6px; flex-shrink: 0; }
.btn-voice, .btn-speech, .btn-clear { width: 32px; height: 32px; border-radius: 50%; background: #f5f7fa; font-size: 16px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.btn-clear:hover { background: #ffe5e5; color: #e74c3c; }
.chat-actions-col { display: flex; flex-direction: column; gap: 4px; flex-shrink: 0; justify-content: flex-end; }
.btn-voice.recording { background: #ff4d4f; animation: pulse 1s infinite; }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.1); } }
.chat-input-area { flex: 1; min-height: 34px; max-height: 120px; padding: 7px 12px; background: #f5f7fa; border: 1px solid #e8e8e8; border-radius: 20px; font-size: 14px; line-height: 1.5; overflow-y: auto; -webkit-overflow-scrolling: touch; transition: border-color 0.2s; word-break: break-word; white-space: pre-wrap; -webkit-user-select: text; user-select: text; }
.chat-input-area:focus { border-color: #667eea; background: #fff; outline: none; }
.chat-input-area:empty::before { content: attr(data-placeholder); color: #999; pointer-events: none; }
.chat-input-area .katex { font-size: 1.05em; }
.chat-input-area .katex-display { margin: 4px 0; overflow-x: auto; overflow-y: hidden; max-width: 100%; }
.btn-send { height: 32px; padding: 0 10px; background: linear-gradient(135deg, #667eea, #764ba2); color: #fff; border-radius: 16px; font-size: 12px; font-weight: 600; flex-shrink: 0; white-space: nowrap; }
.btn-send:disabled { opacity: 0.5; }

.voice-recording { position: absolute; bottom: 130px; left: 50%; transform: translateX(-50%); background: rgba(0,0,0,0.75); color: #fff; padding: 12px 24px; border-radius: 30px; display: flex; align-items: center; gap: 10px; font-size: 14px; z-index: 50; }
.recording-pulse { width: 12px; height: 12px; border-radius: 50%; background: #ff4d4f; animation: pulse 1s infinite; }

/* ========== 输入模式切换 ========== */
.input-mode-switch { display: flex; justify-content: center; align-items: center; gap: 0; padding: 6px 12px 0; background: #fff; border-top: 1px solid #f0f0f0; flex-shrink: 0; }
.input-mode-switch .mode-tab { padding: 6px 24px; font-size: 13px; color: #999; cursor: pointer; border-bottom: 2px solid transparent; transition: all 0.2s; }
.input-mode-switch .mode-tab.active { color: #667eea; border-bottom-color: #667eea; font-weight: 600; }
.input-mode-switch .formula-toggle { margin-left: 6px; margin-right: 0; }

/* ========== 公式工具栏 ========== */
.formula-toggle { margin-left: auto; padding: 4px 12px; font-size: 12px; color: #667eea; cursor: pointer; border: 1px solid #d6e4ff; border-radius: 14px; background: #f0f5ff; transition: all 0.2s; user-select: none; -webkit-user-select: none; }
.formula-toggle.active { background: #667eea; color: #fff; border-color: #667eea; }
.formula-palette-bar { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.formula-palette { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 10px; background: #f9fafc; border-top: 1px solid #f0f0f0; border-bottom: 1px solid #f0f0f0; max-height: 120px; overflow-y: auto; flex-shrink: 0; }
.formula-palette .fp-item { padding: 5px 10px; font-size: 13px; background: #fff; border: 1px solid #e8e8e8; border-radius: 8px; cursor: pointer; white-space: nowrap; transition: all 0.15s; user-select: none; -webkit-user-select: none; }
.formula-palette .fp-item:active { background: #667eea; color: #fff; border-color: #667eea; transform: scale(0.95); }
.formula-palette .fp-item.fp-wrap { background: #f0f5ff; color: #667eea; border-color: #d6e4ff; font-weight: 600; }

/* 消息复制按钮 */
.btn-copy-msg { width: 30px; height: 30px; border-radius: 50%; background: #f0f5ff; color: #667eea; font-size: 14px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; margin-left: 4px; align-self: flex-end; transition: background 0.2s, transform 0.1s; }
.btn-copy-msg:active { background: #d6e4ff; transform: scale(0.92); }
.msg-row.user .btn-copy-msg { background: rgba(255,255,255,0.2); color: #fff; margin-left: 0; margin-right: 4px; }

/* ========== 语音输入栏 ========== */
.chat-voice-bar { display: flex; align-items: center; padding: 10px 12px; background: #fff; border-top: 1px solid #f0f0f0; gap: 10px; flex-shrink: 0; }
.btn-record { flex: 1; height: 44px; background: linear-gradient(135deg, #667eea, #764ba2); color: #fff; border-radius: 22px; font-size: 15px; font-weight: 600; display: flex; align-items: center; justify-content: center; gap: 8px; user-select: none; -webkit-user-select: none; touch-action: manipulation; }
.btn-record.recording { background: linear-gradient(135deg, #ff4d4f, #ff7875); animation: pulse 0.8s infinite; }
.btn-record .record-icon { font-size: 18px; }

/* ========== AI语音播放条 ========== */
.ai-audio-bar { display: flex; align-items: center; padding: 8px 12px; background: #f0f5ff; border-top: 1px solid #d6e4ff; gap: 10px; flex-shrink: 0; }
.btn-audio-play { width: 32px; height: 32px; border-radius: 50%; background: #667eea; color: #fff; font-size: 12px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.audio-progress { flex: 1; height: 4px; background: #d6e4ff; border-radius: 2px; overflow: hidden; }
.audio-progress-fill { height: 100%; background: #667eea; border-radius: 2px; width: 0%; transition: width 0.1s linear; }
.audio-time { font-size: 12px; color: #666; flex-shrink: 0; min-width: 36px; text-align: right; }

/* ========== 习题页 ========== */
.page-exercise { padding: 16px; }
.exercise-card { background: #fff; border-radius: 14px; padding: 16px; margin-bottom: 14px; box-shadow: 0 2px 12px rgba(0,0,0,0.04); }
.exercise-num { display: inline-block; width: 24px; height: 24px; line-height: 24px; text-align: center; background: #667eea; color: #fff; border-radius: 50%; font-size: 13px; margin-right: 8px; }
.exercise-question { font-size: 15px; line-height: 1.7; color: #333; margin: 10px 0; }
.exercise-answer-input { width: 100%; min-height: 80px; padding: 10px 12px; border: 1px solid #e8e8e8; border-radius: 10px; font-size: 14px; resize: vertical; margin-bottom: 10px; background: #fafafa; }
.exercise-result { padding: 10px 12px; border-radius: 8px; font-size: 13px; margin-top: 8px; }
.exercise-result.correct { background: #f6ffed; color: #52c41a; border: 1px solid #b7eb8f; }
.exercise-result.wrong { background: #fff1f0; color: #f5222d; border: 1px solid #ffa39e; }
.exercise-result .answer { margin-top: 6px; color: #666; }

/* ========== 加载遮罩 ========== */
.loading-mask { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.4); display: flex; flex-direction: column; align-items: center; justify-content: center; z-index: 9999; }
.loading-spinner { width: 44px; height: 44px; border: 4px solid rgba(255,255,255,0.3); border-top-color: #fff; border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { color: #fff; margin-top: 14px; font-size: 14px; }

/* ========== Toast ========== */
.toast { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); background: rgba(0,0,0,0.75); color: #fff; padding: 12px 24px; border-radius: 8px; font-size: 14px; z-index: 10000; max-width: 80%; text-align: center; }

/* ========== 文字输入题目按钮 ========== */
.btn-text-input { width: 100%; height: 48px; margin-top: 16px; background: #fff; border: 2px dashed #667eea; border-radius: 12px; color: #667eea; font-size: 15px; font-weight: 600; cursor: pointer; transition: background 0.2s, transform 0.1s; }
.btn-text-input:active { background: #f0f5ff; transform: scale(0.98); }

/* ========== 通用弹窗 ========== */
.modal-mask { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; z-index: 5000; padding: 20px; }
.modal-content { background: #fff; border-radius: 16px; padding: 24px 20px; width: 100%; max-width: 360px; max-height: 80vh; overflow-y: auto; box-shadow: 0 12px 40px rgba(0,0,0,0.15); }
.modal-title { font-size: 18px; font-weight: 600; margin-bottom: 16px; text-align: center; }
.modal-actions { display: flex; gap: 12px; margin-top: 8px; }
.modal-actions .btn-secondary, .modal-actions .btn-primary { flex: 1; height: 46px; margin-top: 0; }
.modal-content .form-group select { width: 100%; height: 42px; padding: 0 12px; border: 1px solid #e8e8e8; border-radius: 8px; font-size: 14px; background: #fafafa; }
.text-question-input { width: 100%; min-height: 120px; padding: 10px 12px; border: 1px solid #e8e8e8; border-radius: 10px; font-size: 14px; line-height: 1.6; resize: vertical; background: #fafafa; transition: border-color 0.3s; }
.text-question-input:focus { border-color: #667eea; background: #fff; }
.text-question-input[contenteditable="true"] { min-height: 120px; overflow-y: auto; white-space: pre-wrap; word-break: break-word; }
.text-question-input[contenteditable="true"]:empty:before { content: attr(data-placeholder); color: #999; pointer-events: none; }
.text-question-input[contenteditable="true"] .katex { font-size: 1.1em; }
.hw-result-preview { min-height: 44px; padding: 10px 12px; background: #fffdf5; border: 1px solid #ffe7ba; border-radius: 8px; margin-bottom: 8px; font-size: 18px; line-height: 1.8; overflow-x: auto; white-space: pre-wrap; word-break: break-word; }
.hw-result-preview:empty { display: none; }
.hw-result-preview .katex { font-size: 1.15em; }

/* ========== 手写板 ========== */
.hw-toggle { margin-left: 8px; }
.handwrite-modal { max-width: 680px; }
.hw-toolbar { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.hw-tool { width: 40px; height: 40px; border-radius: 10px; border: 1px solid #e8e8e8; background: #fafafa; font-size: 18px; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: background 0.2s, border-color 0.2s; }
.hw-tool:hover { background: #f0f5ff; border-color: #667eea; }
.hw-tool.active { background: #667eea; border-color: #667eea; }
.hw-tool-hint { margin-left: auto; font-size: 13px; color: #999; }
.hw-canvas { width: 100%; height: auto; background: #fff; border: 2px dashed #e8e8e8; border-radius: 12px; touch-action: none; cursor: crosshair; display: block; }
.hw-result { margin-top: 12px; background: #f9f9f9; border: 1px solid #e8e8e8; border-radius: 10px; padding: 10px 12px; }
.hw-result-label { font-size: 13px; color: #667eea; font-weight: 600; margin-bottom: 6px; }
.hw-result-text { width: 100%; min-height: 64px; padding: 8px 10px; border: 1px solid #e8e8e8; border-radius: 8px; font-size: 14px; line-height: 1.5; resize: vertical; background: #fff; box-sizing: border-box; }
.hw-result-tip { margin-top: 6px; font-size: 13px; color: #b8860b; line-height: 1.5; }
