:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #4f46e5;
  --primary-d: #4338ca;
  --accent: #0ea5e9;
  --good: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --shadow: 0 10px 30px rgba(31, 41, 55, 0.08);
  --radius: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 640px;
  margin: 0 auto;
  padding: 24px 16px 48px;
  min-height: 100vh;
}

.screen { display: none; }
.screen.active { display: block; animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 24px;
  margin-bottom: 20px;
}

/* 开始页 */
.start-card { text-align: center; padding: 40px 28px; }
.badge {
  display: inline-block;
  background: #eef2ff;
  color: var(--primary);
  font-size: 13px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 999px;
  margin-bottom: 14px;
}
.start-card h1 { font-size: 34px; margin: 6px 0 2px; letter-spacing: 1px; }
.subtitle { color: var(--muted); margin: 0 0 18px; letter-spacing: 2px; font-size: 14px; }
.desc { color: #374151; line-height: 1.7; font-size: 15px; }
.desc b { color: var(--primary); }
.group-legend {
  display: flex; flex-wrap: wrap; gap: 8px; justify-content: center;
  margin: 18px 0 24px;
}
.group-legend span {
  font-size: 12px; color: var(--muted);
  background: #f3f4f6; padding: 5px 10px; border-radius: 8px;
}
.hint { color: var(--muted); font-size: 12px; margin-top: 16px; }

/* 按钮 */
.btn-row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 8px; }
.btn {
  border: none; cursor: pointer; font-size: 15px; font-weight: 600;
  padding: 12px 22px; border-radius: 12px; transition: transform .08s, background .2s, box-shadow .2s;
  font-family: inherit;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-d); }
.btn-ghost { background: #f3f4f6; color: var(--ink); }
.btn-ghost:hover { background: #e5e7eb; }
.btn-submit { background: var(--good); color: #fff; }
.btn-submit:hover { filter: brightness(0.95); }
.btn.small { padding: 8px 14px; font-size: 13px; }

/* 答题页 */
.quiz-top {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 10px;
}
.quiz-meta { display: flex; align-items: center; gap: 10px; }
.quiz-meta.right { margin-left: auto; }
.tag {
  background: #eef2ff; color: var(--primary); font-weight: 700;
  font-size: 13px; padding: 4px 10px; border-radius: 8px;
}
.q-index { font-weight: 600; color: var(--ink); }
.timer {
  font-variant-numeric: tabular-nums; font-weight: 700; color: var(--muted);
  background: #f3f4f6; padding: 4px 10px; border-radius: 8px;
}
.progress { height: 8px; background: #e5e7eb; border-radius: 999px; overflow: hidden; margin-bottom: 14px; }
.progress-bar { height: 100%; width: 0; background: linear-gradient(90deg, var(--primary), var(--accent)); transition: width .25s; }

/* 完全按视口高度 vh 自适应：矩阵高度=视口高的固定比例，选项随之缩放，任何屏幕一屏铺满不溢出 */
.quiz-card {
  padding: 16px 16px;
  max-height: calc(100vh - 96px);
  overflow-y: auto;
}
.matrix {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  width: min(100%, 42vh);
  margin: 0 auto 12px;
  aspect-ratio: 1 / 1;
}
.cell {
  background: #fafafa;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  padding: 3px;
  aspect-ratio: 1 / 1;
  overflow: hidden;
}
.cell.empty {
  border-style: dashed;
  border-color: var(--primary);
  background: #eef2ff;
  color: var(--primary);
  font-size: 28px; font-weight: 700;
}
.cell.empty.filled { border-style: solid; }
.cell svg { width: 100%; height: 100%; max-height: 100%; display: block; }

.stem { font-size: 14px; color: #374151; font-weight: 600; text-align: center; margin: 0 auto 10px; }
.options {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: min(100%, 42vh);
  margin: 0 auto;
}
.option {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #fafafa;
  border: 2px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
  padding: 2px 12px 2px 8px;
  transition: border-color .15s, background .15s, box-shadow .15s;
}
.option:hover { border-color: #c7d2fe; }
.option:active { transform: scale(0.985); }
.option.selected { border-color: var(--primary); background: #eef2ff; box-shadow: 0 0 0 3px rgba(79,70,229,0.15); }
.option.correct { border-color: var(--good); background: #f0fdf4; }
.option.wrong { border-color: var(--bad); background: #fef2f2; }
.opt-fig { width: 6.5vh; height: 6.5vh; flex-shrink: 0; display: flex; align-items: center; justify-content: center; }
.opt-fig svg { width: 100%; height: 100%; display: block; }
.opt-mark {
  margin-left: auto;
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid #cbd5e1;
  background: #fff;
  flex-shrink: 0;
}
.option.selected .opt-mark { background: var(--primary); border-color: var(--primary); box-shadow: inset 0 0 0 4px #fff; }

.quiz-nav { display: flex; gap: 10px; }
.quiz-nav .btn { flex: 1; }

/* 结果页 */
.result-card { text-align: center; padding: 32px 24px; }
.result-score {
  font-size: 64px; font-weight: 800; color: var(--primary); line-height: 1;
}
.result-level { font-size: 22px; font-weight: 700; margin: 8px 0 4px; }
.result-iq { color: var(--muted); font-size: 15px; }
.result-time { color: var(--muted); font-size: 13px; margin-top: 6px; }
.result-bars { margin: 22px 0 8px; text-align: left; }
.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; font-size: 13px; }
.bar-row .bar-name { width: 92px; color: var(--muted); flex-shrink: 0; }
.bar-track { flex: 1; height: 12px; background: #eef2f6; border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--primary), var(--accent)); border-radius: 999px; }
.bar-val { width: 38px; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }

/* 历史 */
.history-card h3, .history-card h2 { margin: 0 0 14px; }
.history-card.wide { max-width: 100%; }
.history-head { display: flex; justify-content: space-between; align-items: center; }
.history-list { display: flex; flex-direction: column; gap: 10px; }
.history-item {
  display: flex; align-items: center; gap: 12px;
  background: #fafafa; border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px;
}
.history-item .h-score { font-size: 22px; font-weight: 800; color: var(--primary); width: 46px; }
.history-item .h-main { flex: 1; }
.history-item .h-level { font-weight: 600; }
.history-item .h-sub { font-size: 12px; color: var(--muted); }
.history-empty { color: var(--muted); text-align: center; padding: 20px; font-size: 14px; }

/* 弹窗 */
.modal { display: none; position: fixed; inset: 0; background: rgba(15,23,42,0.55); align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.modal.active { display: flex; }
.modal-card { background: #fff; border-radius: var(--radius); padding: 22px; text-align: center; max-width: 360px; width: 100%; }
.modal-card h3 { margin: 0 0 14px; }
.modal-card canvas { width: 100%; height: auto; border-radius: 12px; border: 1px solid var(--line); margin-bottom: 14px; }

@media (max-width: 480px) {
  .start-card h1 { font-size: 28px; }
  .result-score { font-size: 52px; }
  .card { padding: 22px 16px; }
}
