* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #faf9f7;
  --surface: #ffffff;
  --surface-hover: #f5f3f0;
  --border: #e8e5e0;
  --text: #2c2c2c;
  --text-muted: #888;
  --accent: #c0392b;
  --accent-light: #e74c3c;
  --accent-bg: #fdf2f0;
  --option-bg: #fff;
  --option-border: #e0ddd8;
  --option-hover: #fdf6f4;
  --user-bubble: #c0392b;
  --ai-bubble: #f8f6f3;
  --radius: 14px;
  --radius-sm: 10px;
  --correct: #27ae60;
  --correct-bg: #eafaf1;
  --wrong: #c0392b;
  --wrong-bg: #fdf2f0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Noto Sans SC', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 680px;
  margin: 0 auto;
  overflow: hidden;
}

/* 头部 */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}
.header-left { display: flex; align-items: center; gap: 10px; }
.logo { font-size: 22px; }
.title { font-size: 17px; font-weight: 700; color: var(--accent); }
.header-right { display: flex; align-items: center; gap: 12px; }
.tree-name { font-size: 13px; color: var(--text-muted); }
.btn-restart {
  background: none; border: 1px solid var(--border);
  color: var(--text-muted); border-radius: 6px;
  padding: 4px 10px; cursor: pointer; font-size: 16px;
  transition: all 0.2s;
}
.btn-restart:hover { border-color: var(--accent); color: var(--accent); }
.btn-nav {
  background: none; border: 1px solid var(--border);
  color: var(--text-muted); border-radius: 6px;
  padding: 4px 10px; cursor: pointer; font-size: 13px;
  text-decoration: none; transition: all 0.2s;
  display: inline-flex; align-items: center; gap: 4px;
}
.btn-nav:hover { border-color: var(--accent); color: var(--accent); }

/* 进度条 */
.progress-bar { height: 3px; background: var(--border); flex-shrink: 0; }
.progress-fill { height: 100%; background: var(--accent); width: 0%; transition: width 0.4s ease; }

/* 统计条 */
.stats-bar {
  display: flex; align-items: center; justify-content: center;
  gap: 8px; padding: 8px 16px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  font-size: 13px; color: var(--text-muted); flex-shrink: 0;
}
.stats-item strong { color: var(--text); font-weight: 600; }
.stats-sep { color: var(--border); }
.stats-correct strong { color: var(--correct); }
.stats-wrong strong { color: var(--wrong); }

/* 快速反馈条 */
.quick-feedback {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; border-radius: var(--radius-sm);
  animation: fadeInUp 0.3s ease; max-width: 90%; align-self: flex-start;
  font-size: 14px;
}
.quick-feedback.correct { background: var(--correct-bg); border: 1px solid var(--correct); }
.quick-feedback.wrong { background: var(--wrong-bg); border: 1px solid var(--wrong); }
.qf-icon { font-size: 20px; flex-shrink: 0; }
.qf-label { font-weight: 600; }
.qf-note { color: var(--text-muted); font-size: 13px; margin-left: 4px; }

/* 对话区 */
.chat-area {
  flex: 1; overflow-y: auto; padding: 20px;
  display: flex; flex-direction: column; gap: 16px;
  scroll-behavior: smooth;
  min-height: 0;
}

.message {
  display: flex; gap: 10px; max-width: 90%;
  animation: fadeInUp 0.3s ease;
}
.message.ai { align-self: flex-start; }
.message.user { align-self: flex-end; flex-direction: row-reverse; }

.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; flex-shrink: 0;
}
.message.ai .avatar { background: var(--accent); color: #fff; }
.message.user .avatar { background: #555; }

.bubble {
  padding: 12px 16px; border-radius: var(--radius);
  line-height: 1.7; font-size: 15px;
}
.message.ai .bubble { background: var(--ai-bubble); border: 1px solid var(--border); }
.message.user .bubble { background: var(--user-bubble); color: #fff; }

/* 正确/错误反馈 */
.bubble.correct { background: var(--correct-bg); border-color: var(--correct); }
.bubble.wrong { background: var(--wrong-bg); border-color: var(--wrong); }

/* 选项区 */
.options-area {
  padding: 16px 20px; border-top: 1px solid var(--border);
  background: var(--surface); display: flex; flex-direction: column;
  gap: 10px; flex-shrink: 0;
  max-height: 45vh; overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.option-card {
  width: 100%; padding: 14px 18px;
  background: var(--option-bg); border: 1px solid var(--option-border);
  border-radius: var(--radius-sm); color: var(--text);
  font-size: 15px; text-align: left; cursor: pointer;
  transition: all 0.2s; position: relative; overflow: hidden;
  line-height: 1.5;
}
.option-card::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0;
  width: 3px; background: var(--accent); opacity: 0; transition: opacity 0.2s;
}
.option-card:hover {
  background: var(--option-hover); border-color: var(--accent);
  transform: translateX(4px);
}
.option-card:hover::before { opacity: 1; }
.option-card:active { transform: scale(0.98); }

.option-index {
  display: inline-block; width: 22px; height: 22px; border-radius: 50%;
  background: var(--border); text-align: center; line-height: 22px;
  font-size: 12px; font-weight: 600; margin-right: 10px; flex-shrink: 0;
}
.option-card:hover .option-index { background: var(--accent); color: #fff; }

/* 正确答案高亮 */
.option-card.correct-answer {
  border-color: var(--correct); background: var(--correct-bg);
}
.option-card.correct-answer .option-index { background: var(--correct); color: #fff; }

/* 错误答案高亮 */
.option-card.wrong-answer {
  border-color: var(--wrong); background: var(--wrong-bg);
  text-decoration: line-through; opacity: 0.7;
}

.options-area.disabled .option-card {
  pointer-events: none; opacity: 0.5;
}

/* 加载动画 */
.loading {
  display: flex; flex-direction: column; align-items: center;
  gap: 8px; padding: 20px; color: var(--text-muted); font-size: 13px;
}
.dots { display: flex; gap: 6px; }
.dots span {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent); animation: dotPulse 1.4s infinite;
}
.dots span:nth-child(2) { animation-delay: 0.2s; }
.dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dotPulse {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1); }
}
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* 结束画面 */
.end-screen { text-align: center; padding: 40px 20px; }
.end-screen .end-icon { font-size: 48px; margin-bottom: 16px; }
.end-screen .end-title { font-size: 20px; font-weight: 700; margin-bottom: 8px; }
.end-screen .end-desc { color: var(--text-muted); font-size: 14px; margin-bottom: 24px; line-height: 1.6; }

/* 错题本按钮 */
.btn-wrong {
  background: none; border: 1px solid var(--border);
  color: var(--text-muted); border-radius: 6px;
  padding: 4px 10px; cursor: pointer; font-size: 13px;
  transition: all 0.2s;
}
.btn-wrong:hover { border-color: var(--wrong); color: var(--wrong); }

/* 答题反馈 */
.answer-feedback {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 16px; border-radius: var(--radius);
  animation: fadeInUp 0.3s ease; max-width: 90%; align-self: flex-start;
}
.answer-feedback.correct { background: var(--correct-bg); border: 1px solid var(--correct); }
.answer-feedback.wrong { background: var(--wrong-bg); border: 1px solid var(--wrong); }
.feedback-icon { font-size: 24px; flex-shrink: 0; }
.feedback-text { font-size: 14px; line-height: 1.6; }
.feedback-text .explanation { color: var(--text-muted); font-size: 13px; }

/* ABCD 选项高亮 */
.option-index.abcd {
  background: var(--accent); color: #fff; font-weight: 700;
}

/* 学习统计 */
.study-stats {
  display: flex; justify-content: center; gap: 32px;
  margin: 20px 0;
}
.stat-item { text-align: center; }
.stat-num { display: block; font-size: 28px; font-weight: 700; color: var(--accent); }
.stat-label { font-size: 12px; color: var(--text-muted); }

/* 错题本 */
.wrong-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 0; border-bottom: 1px solid var(--border); margin-bottom: 16px;
}
.wrong-header h2 { font-size: 18px; }
.wrong-total { font-size: 14px; color: var(--text-muted); font-weight: 400; }
.btn-clear-wrong {
  background: none; border: 1px solid var(--wrong); color: var(--wrong);
  border-radius: 6px; padding: 4px 12px; cursor: pointer; font-size: 13px;
}
.wrong-empty { text-align: center; padding: 40px 0; color: var(--text-muted); }
.wrong-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 14px; margin-bottom: 12px;
}
.wrong-meta { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.wrong-question { font-size: 14px; line-height: 1.5; margin-bottom: 8px; }
.wrong-your-answer { font-size: 13px; color: var(--wrong); margin-bottom: 4px; }
.wrong-correct { font-size: 13px; color: var(--correct); margin-bottom: 8px; }
.btn-remove-wrong {
  background: var(--correct-bg); border: 1px solid var(--correct);
  color: var(--correct); border-radius: 6px; padding: 4px 12px;
  cursor: pointer; font-size: 13px;
}
.btn-remove-wrong:hover { background: var(--correct); color: #fff; }

/* 打字机 */
.typing { border-right: 2px solid var(--accent); animation: blink 0.8s infinite; }
@keyframes blink { 0%, 100% { border-color: var(--accent); } 50% { border-color: transparent; } }

/* 分数显示 */
.score-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 12px; border-radius: 20px;
  font-size: 13px; font-weight: 600;
}
.score-badge.good { background: var(--correct-bg); color: var(--correct); }
.score-badge.bad { background: var(--wrong-bg); color: var(--wrong); }

.chat-area::-webkit-scrollbar { width: 4px; }
.chat-area::-webkit-scrollbar-track { background: transparent; }
.chat-area::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

@media (max-width: 480px) {
  .app { max-width: 100%; }
  .header { padding: 12px 16px; }
  .chat-area { padding: 16px; }
  .options-area { padding: 12px 16px; }
  .message { max-width: 95%; }
}

/* === 登录系统 === */
.auth-btn-header {
  background: none; border: 1px solid var(--border);
  color: var(--text-muted); border-radius: 6px;
  padding: 4px 10px; cursor: pointer; font-size: 13px;
  transition: all 0.2s; display: flex; align-items: center; gap: 4px;
}
.auth-btn-header:hover { border-color: var(--accent); color: var(--accent); }
.auth-avatar { font-size: 14px; }
.auth-name { font-size: 12px; }

/* 弹窗 */
.auth-modal {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
}
.auth-overlay {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.5); backdrop-filter: blur(4px);
}
.auth-dialog {
  position: relative; z-index: 1;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 28px 24px;
  width: 90%; max-width: 360px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.15);
}
.auth-dialog h3 { font-size: 18px; text-align: center; margin-bottom: 4px; }
.auth-subtitle { font-size: 13px; color: var(--text-muted); text-align: center; margin-bottom: 20px; }
.auth-close {
  position: absolute; top: 12px; right: 14px;
  background: none; border: none; font-size: 18px;
  color: var(--text-muted); cursor: pointer;
}
.auth-close:hover { color: var(--text); }
.auth-input {
  width: 100%; padding: 10px 14px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 14px; margin-bottom: 10px;
  background: var(--bg); color: var(--text);
  outline: none; transition: border-color 0.2s;
}
.auth-input:focus { border-color: var(--accent); }
.auth-btns { display: flex; gap: 10px; margin-top: 4px; }
.auth-btn {
  flex: 1; padding: 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--bg);
  font-size: 14px; cursor: pointer; transition: all 0.2s;
  color: var(--text);
}
.auth-btn:hover { border-color: var(--accent); }
.auth-btn.primary {
  background: var(--accent); color: #fff; border-color: var(--accent);
}
.auth-btn.primary:hover { opacity: 0.9; }
.auth-btn.magic {
  width: 100%; text-align: center;
  background: var(--bg); border: 1px dashed var(--border);
}
.auth-btn.magic:hover { border-color: var(--accent); border-style: solid; }
.auth-divider {
  text-align: center; margin: 16px 0; position: relative;
  color: var(--text-muted); font-size: 12px;
}
.auth-divider::before {
  content: ''; position: absolute; left: 0; top: 50%;
  width: 100%; height: 1px; background: var(--border);
}
.auth-divider span {
  position: relative; background: var(--surface); padding: 0 12px;
}
.auth-msg {
  margin-top: 12px; padding: 8px 12px;
  border-radius: var(--radius-sm); font-size: 13px;
  text-align: center;
}
.auth-msg.error { background: var(--wrong-bg); color: var(--wrong); border: 1px solid var(--wrong); }
.auth-msg.success { background: var(--correct-bg); color: var(--correct); border: 1px solid var(--correct); }
