/* ===== 全局 ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #0f1117;
  --bg-card: #1a1d28;
  --bg-card-hover: #232738;
  --text: #e0e0e0;
  --text-dim: #8b8fa3;
  --accent: #6c8cff;
  --accent-dim: #4a62cc;
  --correct: #4ade80;
  --wrong: #f87171;
  --os: #f59e0b;
  --ds: #3b82f6;
  --co: #8b5cf6;
  --cn: #10b981;
  --radius: 12px;
  --radius-sm: 8px;
}

body {
  font-family: -apple-system, "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow-y: auto;
  user-select: none;
  -webkit-user-select: none;
}

.view { display: none; flex-direction: column; height: 100vh; }
.view.active { display: flex; }

/* ===== 首页 ===== */
.home-header {
  padding: 20px 20px 12px;
  text-align: center;
}
.home-header h1 { font-size: 22px; font-weight: 700; margin-bottom: 14px; }

/* ===== 用户栏 ===== */
.user-bar {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  margin-bottom: 14px;
}
.user-name { font-size: 13px; color: var(--text-dim); }
.btn-logout {
  padding: 4px 12px; font-size: 12px;
  border: 1px solid #334155; border-radius: 6px;
  background: transparent; color: var(--text-dim); cursor: pointer;
  transition: all .2s;
}
.btn-logout:hover { border-color: var(--wrong); color: var(--wrong); }

.mode-switch {
  display: flex;
  gap: 6px;
  justify-content: center;
  background: var(--bg-card);
  border-radius: 20px;
  padding: 4px;
  width: fit-content;
  margin: 0 auto;
}
.mode-btn {
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 13px;
  padding: 6px 16px;
  border-radius: 16px;
  cursor: pointer;
  transition: all 0.2s;
}
.mode-btn.active {
  background: var(--accent);
  color: #fff;
}

/* 科目卡片 */
.subject-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 16px 20px;
}
.subject-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 18px 16px;
  cursor: pointer;
  transition: all 0.2s;
  border: 2px solid transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.subject-card:hover { background: var(--bg-card-hover); transform: translateY(-1px); }
.subject-card.selected { border-color: var(--accent); }

.subject-card .icon {
  font-size: 32px;
  width: 52px; height: 52px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 4px;
}
.subject-card .name { font-size: 15px; font-weight: 600; }
.subject-card .progress { font-size: 12px; color: var(--text-dim); }
.subject-card .bar {
  width: 100%; height: 4px;
  background: rgba(255,255,255,0.08);
  border-radius: 2px;
  margin-top: 4px;
  overflow: hidden;
}
.subject-card .bar-fill {
  height: 100%; border-radius: 2px;
  transition: width 0.3s;
}

/* 统计 */
.home-stats {
  display: flex;
  justify-content: center;
  gap: 28px;
  padding: 8px 20px 16px;
  font-size: 13px;
  color: var(--text-dim);
}
.home-stats strong { color: var(--text); font-size: 16px; margin-right: 4px; }

/* 底部按钮 */
.home-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 0 20px 24px;
  justify-content: center;
  align-items: center;
}
.btn-primary, .btn-secondary {
  border: none;
  font-size: 15px;
  font-weight: 600;
  padding: 12px 32px;
  border-radius: 24px;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dim); }
.btn-secondary { background: var(--bg-card); color: var(--text); }
.btn-secondary:hover { background: var(--bg-card-hover); }

/* ===== 答题页 ===== */
.quiz-header {
  display: flex;
  align-items: center;
  padding: 14px 16px;
  gap: 12px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
}
.btn-back {
  background: none; border: none;
  color: var(--accent); font-size: 15px;
  cursor: pointer; padding: 4px 8px; border-radius: 6px;
}
.btn-back:hover { background: rgba(108,140,255,0.1); }

.btn-fav {
  background: none; border: none;
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
  transition: all 0.2s;
  line-height: 1;
}
.btn-fav:hover { color: #f59e0b; }
.btn-fav.active { color: #f59e0b; }

.quiz-meta { font-size: 13px; color: var(--text-dim); flex: 1; }
.quiz-progress { font-size: 13px; color: var(--accent); white-space: nowrap; }

.quiz-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 20px 28px;
}

/* 题干 */
.quiz-question {
  font-size: 16px;
  line-height: 1.7;
  margin-bottom: 20px;
  white-space: pre-wrap;
}

/* 选项 */
.quiz-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.quiz-option {
  background: var(--bg-card);
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  gap: 10px;
}
.quiz-option:hover { background: var(--bg-card-hover); }
.quiz-option .opt-label {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: rgba(255,255,255,0.06);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600; flex-shrink: 0;
}
.quiz-option.correct { border-color: var(--correct); background: rgba(74,222,128,0.08); }
.quiz-option.correct .opt-label { background: var(--correct); color: #000; }
.quiz-option.wrong { border-color: var(--wrong); background: rgba(248,113,113,0.08); }
.quiz-option.wrong .opt-label { background: var(--wrong); color: #000; }
.quiz-option.dim { opacity: 0.5; }
.quiz-option.disabled { pointer-events: none; }

/* 解析 */
.quiz-explanation {
  margin-top: 16px;
  padding: 14px 16px;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-dim);
  display: none;
}
.quiz-explanation.show { display: block; }
.quiz-explanation .exp-label { color: var(--accent); font-weight: 600; margin-bottom: 6px; }

/* 大题 */
.quiz-big-answer {
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  padding: 16px;
  margin-top: 16px;
  font-size: 14px;
  line-height: 1.7;
  white-space: pre-wrap;
  display: none;
}
.quiz-big-answer.show { display: block; }

.btn-show-answer {
  display: block;
  margin-top: 20px;
  padding: 12px 24px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
}
.btn-show-answer:hover { background: var(--accent-dim); }

.quiz-self-check {
  display: flex; gap: 12px; margin-top: 16px;
  display: none;
}
.quiz-self-check.show { display: flex; }
.btn-self {
  flex: 1; padding: 10px;
  border-radius: 20px; border: none;
  font-size: 14px; font-weight: 600; cursor: pointer;
}
.btn-self.got { background: var(--correct); color: #000; }
.btn-self.miss { background: var(--wrong); color: #fff; }

/* ===== 错题本 ===== */
.review-filter {
  display: flex;
  gap: 6px;
  padding: 12px 16px;
  flex-wrap: wrap;
}
.review-filter button {
  background: var(--bg-card);
  border: none; color: var(--text-dim);
  font-size: 12px; padding: 6px 14px;
  border-radius: 14px; cursor: pointer;
}
.review-filter button.active { background: var(--accent); color: #fff; }

.review-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 16px 20px;
}
.review-item {
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: background 0.15s;
}
.review-item:hover { background: var(--bg-card-hover); }
.review-item .ri-chapter { font-size: 11px; color: var(--text-dim); margin-bottom: 4px; }
.review-item .ri-question { font-size: 13px; line-height: 1.5; }

.review-empty {
  flex: 1;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-dim); font-size: 15px;
}

.btn-next {
  display: block;
  width: 100%;
  margin-top: 18px;
  padding: 12px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 15px;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn-next:hover { opacity: 0.85; }

.quiz-done { text-align: center; padding: 20px; color: var(--accent); font-size: 15px; }

/* ===== 章节选择 ===== */
.chapter-select {
  display: none;
  flex-direction: column;
  padding: 0 20px;
  flex: 1;
  overflow-y: auto;
}
.chapter-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0 14px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  margin-bottom: 10px;
}
.chapter-title { font-size: 15px; font-weight: 600; flex: 1; }
.chapter-total { font-size: 12px; color: var(--text-dim); }

.chapter-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-card);
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  margin-bottom: 6px;
  transition: background 0.15s;
  text-align: left;
}
.chapter-item:hover { background: var(--bg-card-hover); }
.chapter-count { font-size: 12px; color: var(--text-dim); }

/* ===== 今日统计 ===== */
.today-stats {
  text-align: center;
  font-size: 13px;
  color: var(--accent);
  padding: 0 20px 8px;
}

/* ===== 首页操作行 ===== */
.home-actions-row { display: flex; gap: 8px; }
.btn-sm { font-size: 12px; padding: 8px 16px; }

/* ===== 键盘提示 ===== */
.quiz-hint {
  text-align: center;
  padding: 10px 16px;
  font-size: 11px;
  color: var(--text-dim);
  border-top: 1px solid rgba(255,255,255,0.04);
  flex-shrink: 0;
}

/* ===== 批量操作栏 ===== */
.review-batch {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  font-size: 13px;
  color: var(--text-dim);
  background: rgba(108,140,255,0.06);
  margin: 0 16px 10px;
  border-radius: var(--radius-sm);
}
.btn-batch {
  background: var(--accent);
  border: none; color: #fff;
  font-size: 12px; padding: 6px 14px;
  border-radius: 14px; cursor: pointer;
}
.btn-batch-clear { background: var(--wrong); }

/* ===== 统计面板 ===== */
.stats-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
}
.stats-subject {
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  padding: 16px;
  margin-bottom: 12px;
}
.stats-subj-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-size: 14px;
}
.stats-subj-name { font-weight: 600; }
.stats-row {
  display: flex;
  gap: 20px;
  font-size: 13px;
  color: var(--text-dim);
}
.stats-row strong { color: var(--text); }
.stats-chapters {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(255,255,255,0.04);
}
.stats-chapter-item {
  display: flex;
  align-items: center;
  font-size: 12px;
  color: var(--text-dim);
  padding: 4px 0;
}
.stats-ch-name {
  flex: 1;
  color: var(--text);
  font-size: 12px;
}
.stats-chart {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  height: 90px;
  padding-top: 8px;
}
.chart-bar-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  height: 100%;
  justify-content: flex-end;
}
.chart-bar {
  width: 100%;
  max-width: 32px;
  background: var(--accent);
  border-radius: 4px 4px 0 0;
  min-height: 2px;
  transition: height 0.3s;
}
.chart-label {
  font-size: 10px;
  color: var(--text-dim);
  white-space: nowrap;
}

/* ===== Toast 组件 ===== */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-card);
  color: var(--text);
  padding: 10px 24px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  z-index: 10000;
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  border: 1px solid rgba(255,255,255,0.08);
}
.toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast-success { border-color: var(--correct); color: var(--correct); }
.toast-error { border-color: var(--wrong); color: var(--wrong); }
.toast-warn { border-color: var(--os); color: var(--os); }

/* ===== Modal 组件 ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.modal-overlay.visible { opacity: 1; pointer-events: auto; }

.modal-box {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 380px;
  width: 90%;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  border: 1px solid rgba(255,255,255,0.06);
}
.modal-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 12px;
}
.modal-message {
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.6;
  white-space: pre-line;
  margin-bottom: 20px;
}
.modal-btns {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}
.modal-btns .btn-secondary {
  background: var(--bg);
  border: 1px solid rgba(255,255,255,0.08);
  color: var(--text-dim);
}
.modal-btns .btn-primary {
  background: var(--accent);
  border: none;
  color: #fff;
}
