/* =============================================
   统计学习题系统 - 移动端优化版
   ============================================= */
:root {
  --primary: #4f6ef7;
  --primary-light: #7b93fa;
  --primary-dark: #3a56d4;
  --primary-bg: #eef1ff;
  --success: #22c55e;
  --success-bg: #f0fdf4;
  --warning: #f59e0b;
  --warning-bg: #fffbeb;
  --danger: #ef4444;
  --danger-bg: #fef2f2;
  --info: #6366f1;
  --bg: #f0f2f5;
  --bg-card: #ffffff;
  --text: #1e293b;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
  --border-light: #f1f5f9;
  --radius: 10px;
  --radius-lg: 16px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.1);
  --nav-height: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
  overflow-x: hidden;
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 8px);
}

/* ═══ 顶部栏 ═══ */
.top-bar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--bg);
  padding: 12px 16px 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-light);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.top-bar h2 { font-size: 17px; font-weight: 700; }
.top-bar .stat-badges { display: flex; gap: 10px; font-size: 12px; }
.stat-badge {
  display: flex; align-items: center; gap: 3px;
  background: var(--bg-card); padding: 4px 10px; border-radius: 16px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05); color: var(--text-secondary);
  white-space: nowrap;
}
.stat-badge .num { font-weight: 700; color: var(--text); }

/* ═══ 底部导航 ═══ */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: calc(var(--nav-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: #fff;
  display: flex;
  align-items: stretch;
  border-top: 1px solid var(--border);
  z-index: 100;
  box-shadow: 0 -2px 10px rgba(0,0,0,0.05);
}
.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 10px;
  color: var(--text-muted);
  cursor: pointer;
  border: none;
  background: none;
  font-family: inherit;
  padding: 6px 2px;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  transition: color 0.15s;
}
.nav-btn .nav-icon { font-size: 20px; line-height: 1.2; }
.nav-btn .nav-label { font-weight: 500; }
.nav-btn:active { opacity: 0.6; }
.nav-btn.active { color: var(--primary); }
.nav-btn .badge {
  position: absolute; top: 4px; right: 50%;
  margin-right: -18px;
  background: var(--danger);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 8px;
  min-width: 16px;
  text-align: center;
  box-shadow: 0 2px 4px rgba(239,68,68,0.3);
}

/* ═══ 章节抽屉 ═══ */
.chapter-drawer {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.4);
  z-index: 200;
  display: none;
  animation: fadeIn 0.2s;
}
.chapter-drawer.open { display: block; }
.chapter-drawer-content {
  position: absolute; bottom: 0; left: 0; right: 0;
  max-height: 70vh;
  background: #fff;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 16px;
  padding-bottom: calc(16px + var(--safe-bottom));
  overflow-y: auto;
  animation: slideUp 0.25s ease;
}
.chapter-drawer-content .drawer-handle {
  width: 40px; height: 4px; border-radius: 2px;
  background: #ddd; margin: 0 auto 16px;
}
.chapter-drawer-content .drawer-title {
  font-size: 16px; font-weight: 700; margin-bottom: 12px;
  text-align: center;
}
.chapter-item {
  display: flex; align-items: center;
  padding: 12px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s;
  font-size: 15px;
  gap: 10px;
}
.chapter-item:active { background: var(--primary-bg); }
.chapter-item.active { background: var(--primary-bg); color: var(--primary); font-weight: 600; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

/* ═══ 内容区 ═══ */
.main-content { padding: 12px 16px; max-width: 600px; margin: 0 auto; }

/* ═══ 卡片 ═══ */
.card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 12px;
  border: 1px solid var(--border-light);
}
.card-title {
  font-size: 15px; font-weight: 700; margin-bottom: 12px;
  padding-bottom: 10px; border-bottom: 2px solid var(--border-light);
}

/* ═══ 筛选栏 ═══ */
.filter-bar {
  display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
}
.filter-bar select, .filter-bar input {
  flex: 1; min-width: 0;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: #fff;
  outline: none;
  color: var(--text);
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}
.filter-bar select:focus, .filter-bar input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-bg);
}


/* ═══ Chip 标签选择 ═══ */
.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.chip {
  display: inline-flex;
  align-items: center;
  padding: 8px 16px;
  border: 1.5px solid var(--border);
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  background: #fff;
  color: var(--text-secondary);
  min-height: 38px;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
}
.chip:active { transform: scale(0.96); }
.chip.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  box-shadow: 0 2px 6px rgba(79,110,247,0.25);
}

/* ═══ 按钮 ═══ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
  min-height: 44px;
  min-width: 44px;
  transition: opacity 0.15s;
}
.btn:active { opacity: 0.7; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-info { background: var(--info); color: #fff; }
.btn-outline {
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--text-secondary);
}
.btn-outline:active { background: var(--primary-bg); border-color: var(--primary); color: var(--primary); }
.btn-sm { padding: 8px 14px; font-size: 12px; min-height: 36px; }
.btn-lg { padding: 12px 28px; font-size: 16px; }
.btn:disabled { opacity: 0.4; }

/* ═══ 底部操作栏（上一题/下一题/进度/返回） ═══ */
.bottom-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 0;
}
.progress-box {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  height: 36px;
  padding: 0 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  background: #f8fafc;
  border: 1px solid var(--border-light);
  border-radius: 6px;
  font-variant-numeric: tabular-nums;
}

/* ═══ 题目卡片 ═══ */
.question-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 14px;
  border-left: 5px solid var(--primary);
  border: 1px solid var(--border-light);
  border-left-width: 5px;
}
.question-card .q-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
  gap: 8px;
}
.question-card .q-tag {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 14px;
  font-size: 11px;
  font-weight: 600;
}
.tag-choice { background: var(--primary-bg); color: var(--primary); }
.tag-judge { background: var(--success-bg); color: var(--success); }
.tag-fill { background: var(--warning-bg); color: var(--warning); }
.tag-term { background: #f0f0ff; color: var(--info); }
.tag-short { background: var(--danger-bg); color: var(--danger); }
.question-card .q-chapter { font-size: 11px; color: var(--text-muted); }
.question-card .q-stem {
  font-size: 15px;
  line-height: 1.9;
  margin-bottom: 16px;
  color: var(--text);
}

/* ═══ 选项 ═══ */
.options-list { display: flex; flex-direction: column; gap: 10px; }
.option-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s;
  background: #fff;
  min-height: 48px;
}
.option-item:active { border-color: var(--primary-light); background: var(--primary-bg); }
.option-item.selected {
  border-color: var(--primary);
  background: var(--primary-bg);
  box-shadow: 0 0 0 3px rgba(79,110,247,0.12);
}
.option-item.correct {
  border-color: var(--success);
  background: var(--success-bg);
  box-shadow: 0 0 0 3px rgba(34,197,94,0.12);
}
.option-item.wrong {
  border-color: var(--danger);
  background: var(--danger-bg);
  box-shadow: 0 0 0 3px rgba(239,68,68,0.12);
}
.option-item .opt-label {
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: #f1f5f9;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}
.option-item.selected .opt-label { background: var(--primary); color: #fff; }
.option-item.correct .opt-label { background: var(--success); color: #fff; }
.option-item.wrong .opt-label { background: var(--danger); color: #fff; }

/* ═══ 输入框 ═══ */
.answer-input {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  outline: none;
  font-family: inherit;
  resize: vertical;
  background: #fff;
  color: var(--text);
  min-height: 44px;
}
.answer-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-bg); }
.answer-actions { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; }

/* ═══ 反馈 ═══ */
.feedback {
  margin-top: 14px;
  padding: 14px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  animation: fadeSlideIn 0.25s ease;
}
.feedback.correct { background: var(--success-bg); border: 1.5px solid #bbf7d0; color: #166534; }
.feedback.wrong { background: var(--danger-bg); border: 1.5px solid #fecaca; color: #991b1b; }
.feedback .correct-answer {
  margin-top: 8px;
  font-weight: 400;
  color: var(--text);
  padding: 8px 10px;
  background: rgba(255,255,255,0.7);
  border-radius: 6px;
  font-size: 13px;
}
@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ═══ 进度条 ═══ */
.progress-bar { height: 6px; background: #e2e8f0; border-radius: 3px; overflow: hidden; }
.progress-bar .progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--primary-light));
  border-radius: 3px;
  transition: width 0.3s;
}
.progress-text { font-size: 12px; color: var(--text-muted); margin-top: 4px; text-align: right; }

/* ═══ 页码 ═══ */
.pagination {
  display: flex; justify-content: center; align-items: center; gap: 8px;
  margin-top: 16px;
}
.pagination button {
  padding: 10px 16px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  min-height: 44px;
}
.pagination button:active { border-color: var(--primary); color: var(--primary); background: var(--primary-bg); }
.pagination button:disabled { opacity: 0.4; }
.pagination .page-info { font-size: 13px; color: var(--text-secondary); }

/* ═══ 考试 ═══ */
.exam-timer {
  text-align: center;
  font-size: 32px;
  font-weight: 800;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
  letter-spacing: 2px;
  padding: 4px 0;
}
.exam-timer.warning { color: var(--warning); }
.exam-timer.danger { color: var(--danger); animation: pulse 0.8s ease infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.4} }

.exam-config { display: flex; flex-direction: column; gap: 14px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; }
.form-group select, .form-group input {
  width: 100%;
  padding: 11px 14px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  background: #fff;
  color: var(--text);
}
.form-group select:focus, .form-group input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-bg); }

/* ═══ 结果面板 ═══ */
.result-panel { text-align: center; padding: 32px 16px; animation: fadeSlideIn 0.3s; }
.result-panel .score { font-size: 60px; font-weight: 800; color: var(--primary); line-height: 1; }
.result-panel .score-label { font-size: 15px; color: var(--text-secondary); margin-top: 6px; font-weight: 500; }
.result-panel .score-stats { display: flex; justify-content: center; gap: 32px; margin-top: 24px; }
.result-panel .score-stat { text-align: center; }
.result-panel .score-stat .num { font-size: 28px; font-weight: 700; line-height: 1.2; }
.result-panel .score-stat .label { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }

/* ═══ 统计卡片 ═══ */
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.stat-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 16px 12px;
  text-align: center;
  border: 1px solid var(--border-light);
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, var(--primary), var(--primary-light));
}
.stat-card .stat-value { font-size: 28px; font-weight: 800; color: var(--primary); line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-card .stat-label { font-size: 12px; color: var(--text-secondary); margin-top: 4px; font-weight: 500; }

/* ═══ 统计表格 ═══ */
.stats-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.stats-table th {
  padding: 10px 10px;
  text-align: left;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--text-secondary);
  border-bottom: 2px solid var(--border);
  background: #f8fafc;
}
.stats-table td { padding: 10px; border-bottom: 1px solid var(--border-light); color: var(--text); }
.stats-table tr:active td { background: #f8fafc; }

/* ═══ 历史记录 ═══ */
.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-light);
}
.history-item:last-child { border-bottom: none; }
.history-item .h-main { flex: 1; min-width: 0; }
.history-item .h-stem {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-size: 14px; color: var(--text);
}
.history-item .h-meta { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.history-item .h-result { flex-shrink: 0; margin-left: 12px; }

/* ═══ 空状态 ═══ */
.empty-state { text-align: center; padding: 48px 16px; color: var(--text-muted); }
.empty-state .icon { font-size: 48px; margin-bottom: 12px; display: block; }
.empty-state p { font-size: 14px; }

/* ═══ 加载 ═══ */
.loading { text-align: center; padding: 48px 20px; color: var(--text-secondary); }
.spinner {
  display: inline-block;
  width: 28px; height: 28px;
  border: 3px solid #e2e8f0;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ═══ Toast ═══ */
.toast-container {
  position: fixed; top: 16px; left: 16px; right: 16px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  padding: 12px 18px;
  border-radius: var(--radius);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.25s ease;
  max-width: 100%;
  margin: 0 auto;
  text-align: center;
  pointer-events: auto;
}
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-info { background: var(--primary); }
.toast-warning { background: var(--warning); }
@keyframes toastIn { from { transform: translateY(-20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ═══ 底部操作栏 ═══ */
.bottom-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 0;
}
.progress-box {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  height: 36px;
  padding: 0 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  background: #f8fafc;
  border: 1px solid var(--border-light);
  border-radius: 6px;
  font-variant-numeric: tabular-nums;
}

/* ═══ 科目选择按钮 ═══ */
.subject-btn {
  display: block;
  width: 100%;
  height: 160px;
  border: none;
  border-radius: 16px;
  cursor: pointer;
  font-family: inherit;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  transition: all 0.2s;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}
.subject-btn:active { transform: scale(0.97); }

.subject-tj {
  background-image: url("统计学背景.png");
}
.subject-lx {
  background-image: url("流行病学背景.png");
}

/* ═══ 认证覆盖层 ═══ */
.auth-tab {
  flex: 1;
  padding: 10px;
  border: none;
  background: none;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  color: #94a3b8;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color 0.2s, border-color 0.2s;
}
.auth-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}

/* 认证覆盖层动画 */
#auth-overlay .auth-container {
  animation: slideUp 0.25s ease;
}
#auth-overlay input:focus {
  border-color: var(--primary) !important;
  box-shadow: 0 0 0 3px var(--primary-bg) !important;
}
#auth-overlay button:active {
  opacity: 0.8;
}

/* 响应式：小屏适配 */
@media (max-width: 400px) {
  #auth-overlay .auth-container {
    padding: 20px 16px !important;
  }
}

/* ═══ 响应式 ═══ */
@media (min-width: 768px) {
  .subject-btn { height: 220px; }
}