:root {
  --bg: #eef1f6;
  --card: #ffffff;
  --line: #e5e9f0;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-soft: #eaf1ff;
  --ok: #16a34a;
  --ok-soft: #e9f8ee;
  --bad: #dc2626;
  --bad-soft: #fdecec;
  --warn: #b45309;
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.6;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.shell {
  width: min(520px, 100%);
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--bg);
  position: relative;
}
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 9px; font-size: 17px; font-weight: 600; }
.brand-mark, .dialog-badge {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: var(--primary);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
}
.whoami {
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border: 1px solid var(--line);
  background: #f8fafc;
  border-radius: 999px;
  padding: 6px 13px;
  font-size: 13px;
  color: var(--muted);
}
main { padding: 16px 14px calc(96px + env(safe-area-inset-bottom)); }
.view { display: block; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}
.card-title { font-size: 16px; font-weight: 600; margin: 0 0 4px; }
.section-title { font-size: 13px; font-weight: 600; color: var(--muted); margin: 18px 2px 8px; }
.muted { color: var(--muted); }
.fine { font-size: 12px; color: var(--muted); line-height: 1.6; margin: 12px 0 0; }
p { margin: 0 0 12px; }

.field-label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 6px; }
.input, .select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #fbfcfe;
  border-radius: 10px;
  padding: 11px 12px;
  font-size: 16px;
  outline: none;
}
textarea { resize: vertical; min-height: 110px; line-height: 1.6; }
.input:focus, .select:focus, textarea:focus { border-color: var(--primary); background: #fff; }
.select-row { display: flex; gap: 10px; }
.select-row > div { flex: 1; min-width: 0; }

.btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 10px;
  min-height: 44px;
  padding: 10px 16px;
  font-size: 15px;
  font-weight: 500;
  transition: background .15s, opacity .15s;
}
.btn:active { opacity: .82; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.ghost { background: #f6f8fb; }
.btn.block { width: 100%; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 13px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-row { display: flex; gap: 10px; margin-top: 12px; }
.btn-row > .btn { flex: 1; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 4px; }
.chip {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 14px;
  min-height: 36px;
}
.chip.active { background: var(--primary-soft); border-color: #bcd3ff; color: var(--primary); font-weight: 500; }

.quiz-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.quiz-progress { font-size: 13px; color: var(--muted); }
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  background: var(--primary-soft);
  color: var(--primary);
}
.badge.score { background: #fff5e6; color: var(--warn); }
.progress { height: 6px; border-radius: 99px; background: #edf1f7; overflow: hidden; margin-bottom: 16px; }
.progress > span { display: block; height: 100%; background: var(--primary); border-radius: 99px; transition: width .25s; }
.stem { font-size: 17px; line-height: 1.7; font-weight: 500; margin: 4px 0 16px; white-space: pre-wrap; }

.options { display: grid; gap: 10px; }
.option {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 11px;
  padding: 12px 13px;
  min-height: 50px;
  font-size: 15px;
  line-height: 1.5;
  word-break: break-word;
}
.option .key {
  flex: 0 0 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #f1f4f9;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}
.option.selected { border-color: var(--primary); background: var(--primary-soft); }
.option.selected .key { background: var(--primary); color: #fff; }
.option.ok { border-color: var(--ok); background: var(--ok-soft); }
.option.bad { border-color: var(--bad); background: var(--bad-soft); }
.option:disabled { cursor: default; }

.result {
  margin-top: 16px;
  border-radius: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  background: #fafbfd;
}
.result.ok { border-color: #b9e6c8; background: var(--ok-soft); }
.result.bad { border-color: #f5c4c4; background: var(--bad-soft); }
.result-head { font-weight: 600; font-size: 16px; margin-bottom: 10px; }
.result.ok .result-head { color: var(--ok); }
.result.bad .result-head { color: var(--bad); }
.result-row { margin-top: 9px; font-size: 14px; line-height: 1.65; word-break: break-word; }
.result-label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.tag {
  display: inline-block;
  border-radius: 6px;
  padding: 2px 7px;
  margin: 3px 4px 0 0;
  font-size: 12px;
  background: #e7f5ec;
  color: var(--ok);
}
.tag.miss { background: #fdecec; color: var(--bad); }

.score-ring {
  width: 128px;
  height: 128px;
  margin: 6px auto 14px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: conic-gradient(var(--primary) var(--pct, 0%), #e9edf4 0);
  position: relative;
}
.score-ring::before {
  content: "";
  position: absolute;
  inset: 12px;
  background: #fff;
  border-radius: 50%;
}
.score-ring > div { position: relative; text-align: center; line-height: 1.2; }
.score-num { font-size: 30px; font-weight: 700; color: var(--primary); }
.score-den { font-size: 12px; color: var(--muted); }
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: #f7f9fc; border-radius: 11px; padding: 12px 8px; text-align: center; }
.stat-num { font-size: 20px; font-weight: 600; }
.stat-label { font-size: 12px; color: var(--muted); }

.topic-row { margin-bottom: 12px; }
.topic-line { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 5px; }
.bar { height: 8px; border-radius: 99px; background: #edf1f7; overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: 99px; background: var(--primary); }
.bar > span.low { background: #f0a33a; }

.list-item {
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #fff;
  padding: 12px 13px;
  margin-bottom: 10px;
}
.list-title { font-size: 14px; line-height: 1.6; margin-bottom: 6px; }
.list-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 40px 12px; font-size: 14px; }

.exam-nav { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 14px; }
.exam-dot {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 13px;
  color: var(--muted);
}
.exam-dot.answered { background: var(--primary-soft); border-color: #bcd3ff; color: var(--primary); }
.exam-dot.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.report-item { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 12px; }
.report-head { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; font-weight: 500; }
.pill { border-radius: 999px; padding: 2px 9px; font-size: 12px; white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }

.tabbar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: min(520px, 100%);
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: #fff;
  border-top: 1px solid var(--line);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.tab {
  border: 0;
  background: transparent;
  display: grid;
  justify-items: center;
  gap: 2px;
  padding: 4px 0;
  font-size: 11px;
  color: var(--muted);
}
.tab svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tab.active { color: var(--primary); font-weight: 600; }

.overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(24, 32, 48, .48);
  display: grid;
  place-items: center;
  padding: 20px;
}
.dialog {
  width: min(400px, 100%);
  background: #fff;
  border-radius: 18px;
  padding: 24px 20px;
  text-align: left;
}
.dialog-badge { width: 42px; height: 42px; font-size: 18px; border-radius: 12px; }
.dialog h2 { margin: 14px 0 8px; font-size: 20px; }
.dialog p { font-size: 14px; color: var(--muted); }
.toast {
  position: fixed;
  z-index: 80;
  bottom: calc(88px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: #1f2937;
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  max-width: 88%;
  text-align: center;
}
.link { color: var(--primary); text-decoration: none; font-size: 13px; }
