/* ===== 全局基础 ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #4F46E5;
  --primary-light: #EEF2FF;
  --success: #10B981;
  --warning: #F59E0B;
  --danger: #EF4444;
  --gray-50: #F9FAFB;
  --gray-100: #F3F4F6;
  --gray-200: #E5E7EB;
  --gray-400: #9CA3AF;
  --gray-600: #4B5563;
  --gray-800: #1F2937;
  --radius: 12px;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.12);
}

html { font-size: 16px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Helvetica Neue', sans-serif;
  background: var(--gray-50);
  color: var(--gray-800);
  min-height: 100vh;
  -webkit-text-size-adjust: 100%;
}

a { text-decoration: none; color: inherit; }
img { max-width: 100%; display: block; }
button { cursor: pointer; border: none; background: none; font: inherit; }

/* ===== 布局 ===== */
.page { max-width: 480px; margin: 0 auto; min-height: 100vh; background: #fff; position: relative; }

/* ===== 顶部导航栏 ===== */
.navbar {
  position: sticky; top: 0; z-index: 100;
  background: #fff;
  border-bottom: 1px solid var(--gray-200);
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  height: 56px;
}
.navbar-title { font-size: 18px; font-weight: 700; color: var(--primary); }
.navbar-action { font-size: 14px; color: var(--primary); font-weight: 500; padding: 6px 0; }
.back-btn {
  display: flex; align-items: center; gap: 4px;
  color: var(--primary); font-size: 15px;
}
.back-btn svg { width: 20px; height: 20px; }

/* ===== 底部导航 ===== */
.tab-bar {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 480px;
  background: #fff;
  border-top: 1px solid var(--gray-200);
  display: flex;
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 100;
}
.tab-item {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  padding: 8px 0; gap: 2px;
  color: var(--gray-400); font-size: 11px;
  transition: color 0.2s;
}
.tab-item.active { color: var(--primary); }
.tab-item svg { width: 24px; height: 24px; }

/* 给底部导航留空间 */
.has-tab-bar { padding-bottom: calc(60px + env(safe-area-inset-bottom)); }

/* ===== 按钮 ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 24px; border-radius: var(--radius);
  font-size: 16px; font-weight: 600;
  transition: all 0.15s; user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:active { background: #4338CA; }
.btn-outline { background: #fff; color: var(--primary); border: 1.5px solid var(--primary); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-gray { background: var(--gray-100); color: var(--gray-600); }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 16px; font-size: 14px; border-radius: 8px; }

/* ===== 卡片 ===== */
.card {
  background: #fff; border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px;
}
.card + .card { margin-top: 12px; }

/* ===== 标签 / Badge ===== */
.badge {
  display: inline-block; padding: 3px 10px;
  border-radius: 999px; font-size: 12px; font-weight: 500;
}
.badge-blue { background: var(--primary-light); color: var(--primary); }
.badge-green { background: #D1FAE5; color: #065F46; }
.badge-yellow { background: #FEF3C7; color: #92400E; }
.badge-red { background: #FEE2E2; color: #991B1B; }
.badge-gray { background: var(--gray-100); color: var(--gray-600); }

/* ===== 表单 ===== */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 14px; font-weight: 500; color: var(--gray-600); margin-bottom: 6px; }
.form-input {
  width: 100%; padding: 10px 14px;
  border: 1.5px solid var(--gray-200); border-radius: 8px;
  font-size: 15px; color: var(--gray-800);
  outline: none; transition: border-color 0.2s;
  -webkit-appearance: none;
}
.form-input:focus { border-color: var(--primary); }

/* ===== 拍照区域 ===== */
.upload-zone {
  border: 2px dashed var(--gray-200);
  border-radius: var(--radius);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; padding: 40px 20px;
  background: var(--gray-50);
  cursor: pointer; transition: border-color 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.upload-zone:active, .upload-zone.drag-over { border-color: var(--primary); background: var(--primary-light); }
.upload-zone svg { width: 48px; height: 48px; color: var(--gray-400); }
.upload-zone p { color: var(--gray-400); font-size: 14px; text-align: center; }

/* 图片预览 */
.preview-container { position: relative; border-radius: var(--radius); overflow: hidden; }
.preview-container img { width: 100%; max-height: 400px; object-fit: contain; background: var(--gray-100); }
.preview-remove {
  position: absolute; top: 8px; right: 8px;
  width: 28px; height: 28px; border-radius: 50%;
  background: rgba(0,0,0,0.5); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 18px;
}

/* ===== 加载动画 ===== */
.loading-overlay {
  position: fixed; inset: 0; z-index: 999;
  background: rgba(255,255,255,0.9);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
}
.loading-overlay.hidden { display: none; }
.spinner {
  width: 48px; height: 48px;
  border: 4px solid var(--gray-200);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { color: var(--gray-600); font-size: 15px; }

/* ===== 分析结果 ===== */
.result-section { margin-bottom: 20px; }
.result-section-title {
  font-size: 13px; font-weight: 600; color: var(--gray-400);
  text-transform: uppercase; letter-spacing: 0.5px;
  margin-bottom: 8px;
}
.result-content {
  font-size: 15px; line-height: 1.8; color: var(--gray-800);
  white-space: pre-wrap;
}
.keywords-list { display: flex; flex-wrap: wrap; gap: 8px; }

/* ===== 错题卡片（列表） ===== */
.mistake-card {
  background: #fff; border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: hidden; margin-bottom: 12px;
  -webkit-tap-highlight-color: transparent;
}
.mistake-card-img { width: 100%; height: 140px; object-fit: cover; background: var(--gray-100); }
.mistake-card-body { padding: 12px; }
.mistake-card-meta { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.mistake-card-preview { font-size: 14px; color: var(--gray-600); line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.mistake-card-time { font-size: 12px; color: var(--gray-400); margin-top: 8px; }

/* ===== 筛选栏 ===== */
.filter-bar { display: flex; gap: 8px; overflow-x: auto; padding: 12px 16px; scrollbar-width: none; }
.filter-bar::-webkit-scrollbar { display: none; }
.filter-chip {
  flex-shrink: 0; padding: 6px 14px;
  border: 1.5px solid var(--gray-200); border-radius: 999px;
  font-size: 13px; color: var(--gray-600);
  background: #fff; transition: all 0.15s;
  white-space: nowrap;
}
.filter-chip.active { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }

/* ===== 复习卡片（翻转） ===== */
.flip-card { perspective: 1000px; height: 380px; }
.flip-card-inner {
  position: relative; width: 100%; height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.5s ease;
}
.flip-card.flipped .flip-card-inner { transform: rotateY(180deg); }
.flip-card-front, .flip-card-back {
  position: absolute; width: 100%; height: 100%;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  border-radius: var(--radius); overflow: hidden;
  display: flex; flex-direction: column;
}
.flip-card-front { background: var(--gray-100); }
.flip-card-front img { width: 100%; height: 100%; object-fit: contain; }
.flip-card-back {
  transform: rotateY(180deg);
  background: #fff; padding: 20px;
  border: 2px solid var(--primary-light);
  overflow-y: auto;
}

/* ===== 进度条 ===== */
.progress-bar { background: var(--gray-200); border-radius: 999px; height: 8px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--primary); border-radius: 999px; transition: width 0.3s; }

/* ===== 空状态 ===== */
.empty-state {
  display: flex; flex-direction: column; align-items: center;
  padding: 60px 20px; gap: 16px; color: var(--gray-400);
}
.empty-state svg { width: 64px; height: 64px; }
.empty-state p { font-size: 15px; text-align: center; }

/* ===== Toast 提示 ===== */
.toast {
  position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,0.75); color: #fff;
  padding: 10px 20px; border-radius: 999px; font-size: 14px;
  z-index: 9999; pointer-events: none;
  animation: fadeInUp 0.2s ease, fadeOut 0.3s ease 2s forwards;
}
@keyframes fadeInUp { from { opacity:0; transform: translateX(-50%) translateY(10px); } to { opacity:1; transform: translateX(-50%) translateY(0); } }
@keyframes fadeOut { to { opacity:0; } }

/* ===== 设置页 ===== */
.settings-section { margin: 16px; }
.settings-section-title { font-size: 12px; color: var(--gray-400); margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.5px; }
.settings-item {
  background: #fff; border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px 16px; margin-bottom: 8px;
}
.settings-item-label { font-size: 14px; font-weight: 500; margin-bottom: 6px; }
.settings-item-desc { font-size: 12px; color: var(--gray-400); margin-bottom: 10px; line-height: 1.5; }

/* ===== 响应式 ===== */
@media (min-width: 480px) {
  .page { box-shadow: 0 0 40px rgba(0,0,0,0.1); }
}
