/* ========== CSS 变量与基础样式 ========== */
:root {
  --primary: #2563eb;
  --primary-light: #dbeafe;
  --primary-dark: #1d4ed8;
  --success: #16a34a;
  --success-light: #dcfce7;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --warning: #f59e0b;
  --warning-light: #fef3c7;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05);
  --max-width: 640px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC',
    'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  background: var(--gray-100);
  color: var(--gray-800);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

/* ========== 顶部导航栏 ========== */
.header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: var(--primary);
  color: white;
  padding: 0 16px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-md);
}

.header-title {
  font-size: 18px;
  font-weight: 600;
  flex: 1;
  text-align: center;
}

.header-btn {
  background: none;
  border: none;
  color: white;
  font-size: 16px;
  padding: 8px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  min-width: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.header-btn:active {
  background: rgba(255,255,255,0.2);
}

.header-btn.hidden { visibility: hidden; }

/* ========== 主内容区 ========== */
.main-content {
  margin-top: 56px;
  padding-bottom: 80px;
  min-height: calc(100vh - 56px);
}

/* ========== 首页 ========== */
.home-page { padding: 16px; }

.today-stats {
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  border-radius: var(--radius);
  color: white;
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-lg);
}

.today-stats h3 {
  font-size: 14px;
  opacity: 0.9;
  margin-bottom: 12px;
}

.stats-row {
  display: flex;
  justify-content: space-around;
}

.stat-item {
  text-align: center;
}

.stat-num {
  font-size: 28px;
  font-weight: 700;
  line-height: 1.2;
}

.stat-label {
  font-size: 12px;
  opacity: 0.85;
  margin-top: 4px;
}

/* 功能菜单网格 */
.menu-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

.menu-card {
  background: white;
  border-radius: var(--radius);
  padding: 20px 16px;
  text-align: center;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  border: 2px solid transparent;
}

.menu-card:active {
  transform: scale(0.97);
}

.menu-card .icon {
  font-size: 36px;
  margin-bottom: 8px;
  display: block;
}

.menu-card .title {
  font-size: 16px;
  font-weight: 600;
  color: var(--gray-800);
  margin-bottom: 4px;
}

.menu-card .desc {
  font-size: 12px;
  color: var(--gray-500);
}

.menu-card .count {
  font-size: 13px;
  color: var(--primary);
  font-weight: 500;
  margin-top: 4px;
}

/* 分类选择 */
.category-section {
  background: white;
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.category-section h3 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--gray-700);
}

.category-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.category-tag {
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  border: 1.5px solid var(--gray-200);
  background: var(--gray-50);
  color: var(--gray-600);
  cursor: pointer;
  transition: all 0.15s;
}

.category-tag.active {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
  font-weight: 500;
}

/* ========== 练习页面 ========== */
.practice-page { padding: 16px; }

/* 进度条 */
.progress-bar-container {
  background: var(--gray-200);
  border-radius: 10px;
  height: 6px;
  margin-bottom: 16px;
  overflow: hidden;
}

.progress-bar-fill {
  background: var(--primary);
  height: 100%;
  border-radius: 10px;
  transition: width 0.3s ease;
}

.progress-text {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--gray-500);
  margin-bottom: 8px;
}

/* 题目卡片 */
.question-card {
  background: white;
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.question-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.question-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
}

.badge-single { background: var(--primary-light); color: var(--primary); }
.badge-multi { background: var(--warning-light); color: #b45309; }
.badge-judge { background: #ede9fe; color: #7c3aed; }

.favorite-btn {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}

.question-text {
  font-size: 16px;
  font-weight: 500;
  line-height: 1.7;
  color: var(--gray-800);
  margin-bottom: 16px;
}

/* 题目配图 */
.question-images {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.question-img {
  max-width: 100%;
  max-height: 300px;
  border-radius: 8px;
  border: 1px solid var(--gray-200);
  cursor: pointer;
  transition: transform 0.2s;
  object-fit: contain;
  background: #f8f9fa;
}

.question-img:active {
  transform: scale(0.97);
}

/* 全屏查看图片 */
.image-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.9);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.image-overlay img {
  max-width: 100%;
  max-height: 85vh;
  object-fit: contain;
  border-radius: 4px;
}

.image-close-hint {
  color: rgba(255, 255, 255, 0.6);
  font-size: 14px;
  margin-top: 16px;
}

/* 选项列表 */
.options-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.option-item {
  display: flex;
  align-items: flex-start;
  padding: 12px 14px;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
  font-size: 15px;
  line-height: 1.5;
  -webkit-user-select: none;
  user-select: none;
}

.option-item:active {
  transform: scale(0.99);
}

.option-item.selected {
  border-color: var(--primary);
  background: var(--primary-light);
}

.option-item.correct {
  border-color: var(--success);
  background: var(--success-light);
}

.option-item.wrong {
  border-color: var(--danger);
  background: var(--danger-light);
}

.option-item.disabled {
  cursor: default;
  opacity: 0.9;
}

.option-radio {
  width: 22px;
  height: 22px;
  min-width: 22px;
  border: 2px solid var(--gray-300);
  border-radius: 50%;
  margin-right: 10px;
  margin-top: 1px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  transition: all 0.15s;
}

.option-item.multi .option-radio {
  border-radius: 4px;
}

.option-item.selected .option-radio {
  border-color: var(--primary);
  background: var(--primary);
  color: white;
}

.option-item.correct .option-radio {
  border-color: var(--success);
  background: var(--success);
  color: white;
}

.option-item.wrong .option-radio {
  border-color: var(--danger);
  background: var(--danger);
  color: white;
}

.option-text {
  flex: 1;
}

/* 解析区域 */
.explanation-box {
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: var(--radius-sm);
  padding: 14px;
  margin-top: 16px;
}

.explanation-box .title {
  font-size: 14px;
  font-weight: 600;
  color: #b45309;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.explanation-box .content {
  font-size: 14px;
  color: var(--gray-700);
  line-height: 1.7;
}

.correct-answer {
  color: var(--success);
  font-weight: 600;
}

/* 操作按钮区 */
.action-bar {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.btn {
  flex: 1;
  padding: 12px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-outline {
  background: white;
  color: var(--primary);
  border: 1.5px solid var(--primary);
}

.btn-success {
  background: var(--success);
  color: white;
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-gray {
  background: var(--gray-200);
  color: var(--gray-700);
}

/* ========== 考试模式 ========== */
.exam-header-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: white;
  padding: 10px 16px;
  margin: 0 -16px 16px;
  box-shadow: var(--shadow);
}

.exam-timer {
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.exam-timer.warning { color: var(--danger); }

.exam-progress-text {
  font-size: 14px;
  color: var(--gray-500);
}

/* 答题卡 */
.answer-sheet {
  background: white;
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.answer-sheet h3 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 12px;
}

.sheet-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 8px;
}

.sheet-cell {
  width: 100%;
  aspect-ratio: 1;
  border: 1.5px solid var(--gray-200);
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s;
  background: white;
}

.sheet-cell.answered {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}

.sheet-cell.current {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.sheet-cell.correct-cell {
  background: var(--success-light);
  border-color: var(--success);
  color: var(--success);
}

.sheet-cell.wrong-cell {
  background: var(--danger-light);
  border-color: var(--danger);
  color: var(--danger);
}

/* ========== 考试结果 ========== */
.exam-result {
  text-align: center;
  padding: 20px 0;
}

.result-score-circle {
  width: 140px;
  height: 140px;
  border-radius: 50%;
  margin: 0 auto 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-lg);
}

.result-score-circle.passed {
  background: linear-gradient(135deg, #16a34a, #22c55e);
  color: white;
}

.result-score-circle.failed {
  background: linear-gradient(135deg, #dc2626, #ef4444);
  color: white;
}

.result-score-num {
  font-size: 42px;
  font-weight: 800;
  line-height: 1.1;
}

.result-score-label {
  font-size: 14px;
  opacity: 0.9;
}

.result-status {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 16px;
}

.result-status.passed { color: var(--success); }
.result-status.failed { color: var(--danger); }

.result-detail-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 16px 0;
}

.result-detail-item {
  background: var(--gray-50);
  border-radius: var(--radius-sm);
  padding: 12px;
  text-align: center;
}

.result-detail-item .num {
  font-size: 22px;
  font-weight: 700;
  color: var(--gray-800);
}

.result-detail-item .label {
  font-size: 12px;
  color: var(--gray-500);
  margin-top: 2px;
}

/* ========== 统计页面 ========== */
.stats-page { padding: 16px; }

.stats-card {
  background: white;
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.stats-card h3 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--gray-700);
}

.stats-bar {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
}

.stats-bar-label {
  width: 90px;
  font-size: 13px;
  color: var(--gray-600);
  flex-shrink: 0;
}

.stats-bar-track {
  flex: 1;
  height: 20px;
  background: var(--gray-100);
  border-radius: 10px;
  overflow: hidden;
  margin: 0 10px;
}

.stats-bar-fill {
  height: 100%;
  border-radius: 10px;
  background: var(--primary);
  transition: width 0.5s ease;
  min-width: 2px;
}

.stats-bar-fill.good { background: var(--success); }
.stats-bar-fill.medium { background: var(--warning); }
.stats-bar-fill.poor { background: var(--danger); }

.stats-bar-value {
  width: 48px;
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-700);
  text-align: right;
}

/* 考试历史 */
.exam-history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--gray-100);
}

.exam-history-item:last-child { border-bottom: none; }

.exam-history-score {
  font-size: 20px;
  font-weight: 700;
}

.exam-history-score.passed { color: var(--success); }
.exam-history-score.failed { color: var(--danger); }

.exam-history-date {
  font-size: 13px;
  color: var(--gray-500);
}

/* ========== 空状态 ========== */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--gray-400);
}

.empty-state .icon {
  font-size: 48px;
  margin-bottom: 12px;
  display: block;
}

.empty-state .text {
  font-size: 15px;
}

/* ========== 题目导航浮动按钮 ========== */
.question-nav-float {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 12px;
  background: white;
  padding: 10px 20px;
  border-radius: 30px;
  box-shadow: var(--shadow-lg);
  z-index: 50;
  max-width: var(--max-width);
}

.nav-float-btn {
  padding: 10px 20px;
  border: none;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

.nav-float-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.nav-float-btn.prev {
  background: var(--gray-100);
  color: var(--gray-700);
}

.nav-float-btn.next {
  background: var(--primary);
  color: white;
}

.nav-float-btn.submit-exam {
  background: var(--success);
  color: white;
}

/* ========== 对话框/弹窗 ========== */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.2s;
}

.modal-content {
  background: white;
  border-radius: var(--radius);
  padding: 24px;
  max-width: 360px;
  width: 100%;
  animation: slideUp 0.25s;
}

.modal-content h3 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 12px;
  text-align: center;
}

.modal-content p {
  font-size: 15px;
  color: var(--gray-600);
  text-align: center;
  margin-bottom: 20px;
  line-height: 1.6;
}

.modal-actions {
  display: flex;
  gap: 10px;
}

/* ========== 考试设置 ========== */
.exam-config {
  background: white;
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.config-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--gray-100);
}

.config-row:last-child { border-bottom: none; }

.config-label {
  font-size: 15px;
  color: var(--gray-700);
}

.config-value {
  display: flex;
  align-items: center;
  gap: 8px;
}

.config-value select,
.config-value input {
  padding: 6px 10px;
  border: 1.5px solid var(--gray-200);
  border-radius: 6px;
  font-size: 14px;
  background: var(--gray-50);
  color: var(--gray-800);
}

.config-value select {
  min-width: 100px;
}

/* ========== 题号快速跳转 ========== */
.question-jumper {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.jumper-info {
  font-size: 13px;
  color: var(--gray-500);
}

/* ========== 动画 ========== */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

@keyframes slideIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

.fade-in { animation: fadeIn 0.3s; }
.slide-in { animation: slideIn 0.3s; }

/* ========== 页面切换动画 ========== */
.page {
  display: none;
  animation: fadeIn 0.25s;
}

.page.active {
  display: block;
}

/* ========== 响应式适配 ========== */
@media (min-width: 640px) {
  .main-content {
    max-width: var(--max-width);
    margin-left: auto;
    margin-right: auto;
  }

  .question-nav-float {
    max-width: calc(var(--max-width) - 40px);
  }
}

/* 安全区域适配（iPhone X 等） */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .question-nav-float {
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }

  .main-content {
    padding-bottom: calc(80px + env(safe-area-inset-bottom));
  }
}

/* ========== 暗色模式（可选，跟随系统） ========== */
@media (prefers-color-scheme: dark) {
  :root {
    --gray-50: #1a1a2e;
    --gray-100: #16213e;
    --gray-200: #2a2a4a;
    --gray-300: #3a3a5a;
    --gray-400: #6b6b8b;
    --gray-500: #9090b0;
    --gray-600: #b0b0d0;
    --gray-700: #d0d0e8;
    --gray-800: #e8e8f8;
    --gray-900: #f5f5ff;
    --primary-light: #1e3a5f;
    --success-light: #1a3a2a;
    --danger-light: #3a1a1a;
    --warning-light: #3a2e1a;
  }

  body { background: #0f0f1f; }

  .question-card, .menu-card, .stats-card, .answer-sheet,
  .category-section, .exam-config, .modal-content {
    background: #1a1a2e;
  }

  .question-nav-float { background: #1a1a2e; }

  .explanation-box {
    background: #2a2510;
    border-color: #5a4a10;
  }

  .today-stats {
    background: linear-gradient(135deg, #1d4ed8, #5b21b6);
  }
}
