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

:root {
  --primary: #3b5bdb;
  --primary-dark: #364fc7;
  --purple: #7048e8;
  --accent: #22b8cf;
  --bg: #f5f6fa;
  --card: #fff;
  --text: #1a1a2e;
  --text-secondary: #666;
  --text-muted: #999;
  --border: #e8e8e8;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(59, 91, 219, 0.08);
  --gradient: linear-gradient(135deg, #364fc7 0%, #5c7cfa 40%, #7048e8 100%);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Helvetica Neue', sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
}

.hidden { display: none !important; }

/* ===== 页面容器 ===== */
.page {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: none;
  padding-bottom: calc(60px + var(--safe-bottom));
}

.page.active { display: block; }

.page-scroll { padding-bottom: 20px; }

/* ===== 首页搜索 ===== */
.home-search-wrap {
  padding: 16px 16px 0;
}

.search-bar {
  display: flex;
  align-items: center;
  background: #fff;
  border-radius: 28px;
  padding: 4px 4px 4px 14px;
  height: 44px;
  gap: 8px;
  box-shadow: var(--shadow);
}

.search-svg { color: #adb5bd; flex-shrink: 0; }

.search-bar input {
  flex: 1;
  border: none;
  outline: none;
  font-size: 14px;
  background: transparent;
  min-width: 0;
}

.search-bar input::placeholder { color: #bbb; }

.search-go {
  background: var(--gradient);
  color: #fff;
  border: none;
  border-radius: 22px;
  padding: 0 16px;
  height: 36px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
}

.search-go:active { opacity: 0.9; }

/* 旧 header 兼容 */
.header { display: none; }
.profile-header { display: none; }

/* ===== 卡片 ===== */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

/* ===== 统计 ===== */
.stats-card {
  margin: 16px 16px 12px;
  padding: 16px 8px;
  display: flex;
  position: relative;
  z-index: 2;
}

.stat-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.stat-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  margin-bottom: 6px;
}

.stat-icon-purple { background: rgba(99,102,241,0.12); }
.stat-icon-green  { background: rgba(34,197,94,0.12); }
.stat-icon-pink   { background: rgba(236,72,153,0.12); }
.stat-icon-blue   { background: rgba(59,130,246,0.12); }

.stat-num {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}

.stat-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ===== 工种切换 ===== */
.category-switch-card {
  margin: 0 16px 12px;
  padding: 14px 14px 12px;
  background: var(--card);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.category-switch-card.hidden {
  display: none !important;
}

.category-switch-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.category-switch-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.category-switch-label::before {
  content: '';
  width: 4px;
  height: 14px;
  border-radius: 2px;
  background: var(--gradient);
}

.category-switch-tip {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}

.category-switch-track {
  display: flex;
  gap: 8px;
  padding: 4px;
  background: #f3f5fb;
  border-radius: 14px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.category-switch-track::-webkit-scrollbar {
  display: none;
}

.category-switch-tab {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  color: #64748b;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.45;
  padding: 11px 12px;
  border-radius: 11px;
  cursor: pointer;
  transition: background 0.22s ease, color 0.22s ease, box-shadow 0.22s ease, transform 0.15s ease;
  white-space: normal;
  text-align: center;
}

.category-switch-tab:active {
  transform: scale(0.98);
}

.category-switch-tab.active {
  background: var(--gradient);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 4px 14px rgba(59, 91, 219, 0.28);
}

.category-active-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  padding: 8px 12px;
  border-radius: 10px;
  background: linear-gradient(135deg, rgba(59, 91, 219, 0.08), rgba(112, 72, 232, 0.05));
  border: 1px solid rgba(59, 91, 219, 0.1);
  font-size: 12px;
  color: var(--primary);
  line-height: 1.4;
}

.category-active-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--gradient);
  flex-shrink: 0;
  box-shadow: 0 0 0 3px rgba(59, 91, 219, 0.15);
}

.category-single-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(59, 91, 219, 0.08), rgba(112, 72, 232, 0.05));
  border: 1px solid rgba(59, 91, 219, 0.1);
  font-size: 13px;
  font-weight: 600;
  color: var(--primary);
}

.category-single-icon {
  font-size: 16px;
  line-height: 1;
}

/* ===== 考试卡片 ===== */
.exam-card { margin: 0 16px 12px; }

/* ===== 练习卡片 ===== */
.practice-card { margin: 0 16px 12px; }

.practice-icon-wrap { background: rgba(255,255,255,0.22); }

.practice-categories-list {
  padding-bottom: 4px;
}

.practice-category-block {
  padding: 4px 16px 16px;
}

.practice-category-block:last-child {
  border-bottom: none;
  padding-bottom: 16px;
}

.practice-category-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  padding: 12px 0 8px;
}

.practice-empty-hint {
  margin: 0 16px 16px;
  padding: 12px;
  background: #f8f9ff;
  border: 1px solid #e8eaf6;
  border-radius: 10px;
  font-size: 13px;
  color: #6b7280;
  line-height: 1.5;
  text-align: center;
}

.practice-modes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  padding: 12px 16px 16px;
}

.practice-modes-dual {
  grid-template-columns: repeat(2, 1fr);
  padding: 0;
  gap: 12px;
}

.practice-mode-btn {
  border: 1.5px solid #e8ecf4;
  background: linear-gradient(180deg, #fff 0%, #f8faff 100%);
  border-radius: 14px;
  padding: 16px 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.15s ease;
  box-shadow: 0 2px 8px rgba(59, 91, 219, 0.04);
}

.practice-mode-btn:active {
  transform: scale(0.98);
  border-color: var(--primary);
  background: rgba(59, 91, 219, 0.04);
  box-shadow: 0 4px 14px rgba(59, 91, 219, 0.12);
}

.mode-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.mode-desc {
  font-size: 11px;
  color: var(--text-muted);
}

.mode-count {
  font-size: 24px;
  font-weight: 700;
  color: var(--primary);
  line-height: 1.2;
}

.mode-count-unit {
  font-size: 12px;
  color: var(--text-muted);
}

.mode-count-hint {
  font-size: 13px;
  color: var(--text-muted);
}

.practice-mode-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--primary);
}

.practice-stats-bar {
  font-size: 13px;
  color: var(--text-muted);
  padding: 0 4px 10px;
}

.practice-feedback {
  margin-bottom: 12px;
  padding: 12px 14px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.6;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.practice-feedback.is-correct {
  background: rgba(34,197,94,0.1);
  color: #15803d;
  border: 1px solid rgba(34,197,94,0.25);
}

.practice-feedback.is-wrong {
  background: rgba(239,68,68,0.08);
  color: #b91c1c;
  border: 1px solid rgba(239,68,68,0.2);
}

.option-item.correct {
  border-color: #22c55e;
  background: rgba(34,197,94,0.08);
}

.option-item.correct .option-label {
  background: #22c55e;
  color: #fff;
}

.option-item.wrong {
  border-color: #ef4444;
  background: rgba(239,68,68,0.06);
}

.option-item.wrong .option-label {
  background: #ef4444;
  color: #fff;
}

.exam-card-top {
  display: flex;
  align-items: center;
  padding: 18px 16px;
  gap: 12px;
  background: var(--gradient);
}

.exam-icon-wrap {
  width: 48px;
  height: 48px;
  background: rgba(255,255,255,0.2);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}

.exam-title {
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  display: block;
  margin-bottom: 4px;
}

.exam-desc {
  font-size: 12px;
  color: rgba(255,255,255,0.85);
  line-height: 1.5;
}

.exam-meta {
  display: flex;
  justify-content: space-around;
  padding: 14px 8px;
  border-bottom: 1px solid #f0f0f0;
}

.meta-item {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: var(--text-secondary);
}

.btn-primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin: 14px 16px 16px;
  height: 48px;
  background: var(--gradient);
  color: #fff;
  border: none;
  border-radius: 24px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  width: calc(100% - 32px);
}

.btn-primary:active { opacity: 0.9; }

/* ===== 考试须知 ===== */
.rules-card { margin: 0 16px; }

.rules-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  cursor: pointer;
}

.rules-title {
  font-size: 15px;
  font-weight: 600;
}

.rules-arrow { color: var(--text-muted); }

.rules-body { padding: 0 16px 14px; }

.rule-item {
  display: flex;
  gap: 4px;
  margin-bottom: 8px;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
}

.rule-num { color: var(--primary); font-weight: 600; flex-shrink: 0; }

/* ===== 我的页 ===== */
.profile-header { height: 100px; }

.login-card {
  margin: 16px 16px 12px;
  padding: 18px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
  z-index: 2;
}

.login-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #f0f0f5;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  overflow: hidden;
  flex-shrink: 0;
}

.avatar img { width: 100%; height: 100%; object-fit: cover; }

.login-title {
  font-size: 17px;
  font-weight: 700;
  display: block;
  margin-bottom: 2px;
}

.login-subtitle { font-size: 12px; color: var(--text-muted); }

.login-btn {
  background: var(--gradient);
  color: #fff;
  border: none;
  border-radius: 16px;
  padding: 8px 18px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
}

.menu-card { margin: 0 16px 12px; }

.menu-item {
  display: flex;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid #f5f5f5;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
}

.menu-item:last-child { border-bottom: none; }
.menu-item:active { background: #fafafa; }

.menu-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  margin-right: 12px;
  flex-shrink: 0;
}

.menu-icon-green  { background: rgba(34,197,94,0.12); }
.menu-icon-red    { background: rgba(239,68,68,0.12); }
.menu-icon-purple { background: rgba(139,92,246,0.12); }
.menu-icon-pink   { background: rgba(236,72,153,0.12); }
.menu-icon-blue   { background: rgba(59,130,246,0.12); }
.menu-icon-gray   { background: rgba(107,114,128,0.12); }
.menu-icon-orange { background: rgba(249,115,22,0.12); }

.menu-label { flex: 1; font-size: 15px; }
.menu-arrow { font-size: 18px; color: #ccc; }

.menu-item-btn {
  width: 100%;
  border: none;
  background: #fff;
  font: inherit;
  text-align: left;
  appearance: none;
}

.menu-item-btn:active { background: #fafafa; }

.login-modal {
  position: fixed;
  inset: 0;
  z-index: 3000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-modal-mask {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 0;
}

.login-modal-box {
  position: relative;
  width: 100%;
  max-width: 360px;
  padding: 24px 20px 20px;
  z-index: 2;
  background: #fff;
}

.login-modal-box:active { background: #fff; }

.login-modal-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 8px;
  text-align: center;
}

.login-modal-tip {
  font-size: 13px;
  color: var(--text-secondary);
  text-align: center;
  margin-bottom: 20px;
}

.login-field {
  margin-bottom: 14px;
}

.login-field label {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.login-field input {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  outline: none;
}

.login-field input:focus { border-color: var(--primary); }

.login-modal-actions {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}

.login-cancel-btn,
.login-submit-btn {
  flex: 1;
  height: 44px;
  padding: 0 12px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.login-cancel-btn {
  background: #fff;
  border: 1px solid #d1d5db;
  color: #374151;
}

.login-cancel-btn:active {
  background: #f3f4f6;
}

.login-submit-btn {
  background: var(--primary);
  border: none;
  color: #fff;
}

.login-submit-btn:active {
  opacity: 0.9;
}

/* ===== 底部 TabBar ===== */
.tabbar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  height: calc(50px + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: #fff;
  border-top: 1px solid #eee;
  display: flex;
  z-index: 100;
}

.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 10px;
  border: none;
  background: none;
}

.tab-item.active { color: var(--primary); }
.tab-icon { font-size: 20px; }

/* ===== 子页面 ===== */
.subpage {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 200;
  display: none;
  flex-direction: column;
  max-width: 480px;
  margin: 0 auto;
  left: 0;
  right: 0;
}

.subpage.active { display: flex; }

.subpage-header {
  background: var(--gradient);
  color: #fff;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.subpage-back {
  background: none;
  border: none;
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  padding: 4px;
}

.subpage-title { font-size: 17px; font-weight: 600; }

.subpage-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  -webkit-overflow-scrolling: touch;
}

.empty-state {
  text-align: center;
  padding: 60px 24px;
}

.empty-icon { font-size: 48px; display: block; margin-bottom: 12px; }
.empty-title { font-size: 16px; font-weight: 600; margin-bottom: 6px; }
.empty-desc { font-size: 13px; color: var(--text-muted); }

/* ===== 答题页 ===== */
.exam-page .subpage-body { padding: 12px 16px; }

.exam-topbar {
  display: flex;
  justify-content: space-between;
  padding: 8px 4px 12px;
}

.exam-timer { font-size: 15px; font-weight: 600; color: var(--primary); }
.exam-progress { font-size: 14px; color: var(--text-muted); }

.question-card { padding: 18px 16px; margin-bottom: 16px; }

.q-type {
  display: inline-block;
  background: rgba(99,102,241,0.1);
  color: var(--primary);
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 4px;
  margin-bottom: 10px;
}

.q-text {
  font-size: 16px;
  line-height: 1.7;
  margin-bottom: 16px;
  display: block;
  word-break: break-word;
}

.q-content {
  margin-bottom: 16px;
}

.q-rich {
  font-size: 16px;
  line-height: 1.7;
  word-break: break-word;
}

.q-rich p {
  margin: 0 0 10px;
}

.q-rich p:last-child {
  margin-bottom: 0;
}

.q-image-wrap {
  margin: 12px 0;
}

.q-image {
  max-width: 100%;
  height: auto;
  display: block;
  border-radius: 8px;
  background: #f5f6fa;
}

.q-image-missing {
  display: none;
  min-height: 120px;
  border: 1px dashed #d8dce8;
  border-radius: 8px;
  background: #f8f9fc;
  color: #666;
  font-size: 14px;
  line-height: 1.6;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  text-align: center;
  padding: 24px 16px;
}

.q-image-missing span {
  font-size: 12px;
  color: #999;
}

.options { display: flex; flex-direction: column; gap: 10px; }

.option-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border: 1.5px solid #eee;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
}

.option-item.selected {
  border-color: var(--primary);
  background: rgba(99,102,241,0.06);
}

.option-label {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #f0f0f5;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.option-item.selected .option-label {
  background: var(--primary);
  color: #fff;
}

.exam-nav {
  display: flex;
  gap: 12px;
  padding: 0 0 16px;
}

.nav-btn {
  flex: 1;
  height: 44px;
  border-radius: 22px;
  font-size: 15px;
  cursor: pointer;
  border: 1.5px solid #eee;
  background: #fff;
  color: var(--text-secondary);
}

.nav-btn.primary {
  background: var(--gradient);
  color: #fff;
  border: none;
}

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

/* ===== 结果页 ===== */
.result-card {
  text-align: center;
  padding: 40px 24px;
  margin-top: 40px;
}

.result-icon { font-size: 48px; display: block; margin-bottom: 12px; }
.result-score { font-size: 42px; font-weight: 700; color: var(--primary); display: block; margin-bottom: 6px; }
.result-status { font-size: 16px; margin-bottom: 4px; display: block; }
.result-detail { font-size: 13px; color: var(--text-muted); margin-bottom: 24px; display: block; }

/* ===== 答题记录 ===== */
.record-item {
  padding: 14px 16px;
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.record-score { font-size: 20px; font-weight: 700; color: var(--primary); }
.record-meta { font-size: 12px; color: var(--text-muted); }
.record-pass { color: #22c55e; font-size: 12px; font-weight: 600; }
.record-fail { color: #ef4444; font-size: 12px; font-weight: 600; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0,0,0,0.75);
  color: #fff;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 999;
  display: none;
  pointer-events: none;
}

.toast.show { display: block; }
