:root {
  --ink: #1d2933;
  --muted: #66727c;
  --teal: #14635c;
  --teal-dark: #0f4b46;
  --sand: #f6f2ea;
  --paper: #fffdf8;
  --rule: #e3ddd2;
  --mark: #f2e7cf;
  --ok: #1f7a4d;
  --ok-bg: #eaf5ee;
  --bad: #b3402f;
  --bad-bg: #fbece8;
  --warn: #9a6b1f;
  --warn-bg: #fbf2dc;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--sand);
  color: var(--ink);
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.7;
  -webkit-text-size-adjust: 100%;
}
button, input { font: inherit; }
h1, h2 { line-height: 1.35; }
[hidden] { display: none !important; }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px calc(10px + env(safe-area-inset-top, 0)) 14px;
  padding-top: calc(10px + env(safe-area-inset-top, 0));
  background: var(--teal); color: #fff;
}
.topbar .back {
  width: 36px; height: 36px; border-radius: 10px; flex: 0 0 auto;
  display: grid; place-items: center; color: #fff; text-decoration: none;
  background: rgba(255,255,255,.14); font-size: 19px;
}
.brand-mark { width: 22px; height: 22px; flex: 0 0 auto; border-radius: 50%; }
.topbar-title { flex: 1; min-width: 0; line-height: 1.25; }
.topbar-title strong { display: block; font-size: 15px; font-weight: 600; }
.topbar-title small {
  display: block; font-size: 12px; opacity: .82;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.top-link {
  color: #fff; text-decoration: none; font-size: 14px;
  padding: 6px 10px; border-radius: 9px; background: rgba(255,255,255,.14);
}
@media (max-width: 380px) { .topbar .brand-mark { display: none; } }

/* ---------- 通用 ---------- */
.view { max-width: 880px; margin: 0 auto; padding: 16px 14px 40px; }
.card {
  background: var(--paper); border: 1px solid var(--rule); border-radius: 16px;
  padding: 18px 18px 20px; margin: 0 0 14px;
  box-shadow: 0 1px 2px rgba(29,41,51,.04);
}
.card h2 { margin: 0 0 12px; font-size: 17px; color: var(--teal-dark); }
.foot { color: var(--muted); font-size: 12px; text-align: center; margin: 18px 0 0; }
.kicker {
  margin: 0 0 6px; font-size: 12px; letter-spacing: .16em;
  color: var(--teal); font-weight: 600;
}
.lead { margin: 8px 0 0; color: #3c4a54; }
.intro-head h1 { margin: 0; font-size: 30px; letter-spacing: .04em; }
.primary-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 100%; padding: 13px 18px; border: 0; border-radius: 12px;
  background: var(--teal); color: #fff; font-size: 16px; font-weight: 600;
  text-decoration: none; cursor: pointer;
}
.primary-btn:active { background: var(--teal-dark); }
.primary-btn[disabled] { opacity: .55; }
.ghost-btn {
  padding: 11px 16px; border: 1px solid var(--rule); border-radius: 12px;
  background: #fff; color: var(--ink); font-size: 15px; cursor: pointer;
}
.ghost-btn:disabled { opacity: .45; }
.hint { color: var(--muted); font-size: 13px; margin: 10px 0 0; text-align: center; }

/* ---------- 开始页 ---------- */
.levels { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
@media (max-width: 430px) { .levels { grid-template-columns: 1fr; } }
.level {
  text-align: left; padding: 14px; border: 1.5px solid var(--rule); border-radius: 14px;
  background: #fff; cursor: pointer; color: var(--ink);
}
.level strong { display: block; font-size: 16px; }
.level span { display: block; font-size: 12.5px; color: var(--muted); margin-top: 3px; line-height: 1.5; }
.level em { display: block; font-style: normal; font-size: 12px; color: var(--warn); margin-top: 6px; }
.level.on { border-color: var(--teal); background: #f2f8f6; box-shadow: inset 0 0 0 1px var(--teal); }
/* 三行关键规则放在开始按钮前；完整 10 条折进 details，手机首屏就能看到「开始考试」 */
.exam-keyfacts {
  list-style: none; margin: 0 0 14px; padding: 11px 14px;
  border: 1px solid var(--rule); border-radius: 12px; background: #f2f8f6;
  display: grid; gap: 5px;
}
.exam-keyfacts li {
  position: relative; padding-left: 15px;
  font-size: 13.5px; line-height: 1.5; color: #35434c;
}
.exam-keyfacts li::before {
  content: ""; position: absolute; left: 0; top: .55em;
  width: 6px; height: 6px; border-radius: 50%; background: var(--teal);
}
.rules-more { margin-top: 14px; padding-top: 10px; border-top: 1px dashed var(--rule); }
.rules-more summary { cursor: pointer; font-size: 13px; color: var(--muted); }
.rules-more .rules { margin: 10px 0 0; }
@media (max-width: 520px) {
  #btnStart { position: sticky; bottom: 12px; z-index: 3; box-shadow: 0 10px 24px rgba(20,99,92,.22); }
}
.rules { list-style: none; margin: 0 0 16px; padding: 0; }
.rules li {
  position: relative; padding: 9px 0 9px 26px; border-bottom: 1px dashed var(--rule);
  font-size: 14.5px; color: #35434c;
}
.rules li:last-child { border-bottom: 0; }
.rules li::before {
  content: "✓"; position: absolute; left: 2px; top: 8px;
  width: 18px; height: 18px; border-radius: 50%; background: var(--ok-bg);
  color: var(--ok); font-size: 12px; line-height: 18px; text-align: center; font-weight: 700;
}
.history-row {
  display: flex; align-items: center; gap: 10px; padding: 10px 0;
  border-bottom: 1px dashed var(--rule); font-size: 14px;
}
.history-row:last-child { border-bottom: 0; }
.history-row .score { font-weight: 700; min-width: 52px; }
.history-row .meta { flex: 1; color: var(--muted); font-size: 12.5px; }
.pass-chip, .fail-chip {
  font-size: 12px; padding: 2px 9px; border-radius: 999px; white-space: nowrap;
}
.pass-chip { background: var(--ok-bg); color: var(--ok); }
.fail-chip { background: var(--bad-bg); color: var(--bad); }

/* ---------- 考试中 ---------- */
.exam-bar {
  position: sticky; top: calc(56px + env(safe-area-inset-top, 0)); z-index: 25;
  display: flex; align-items: center; gap: 12px;
  margin: -16px -14px 14px; padding: 10px 14px;
  background: var(--paper); border-bottom: 1px solid var(--rule);
}
.clock {
  font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums;
  color: var(--teal-dark); min-width: 74px;
}
.clock.low { color: var(--bad); }
.bar-mid { flex: 1; min-width: 0; }
.bar-line {
  display: flex; justify-content: space-between; gap: 8px;
  font-size: 12px; color: var(--muted); margin-bottom: 4px;
}
.bar-line #saveState.ok { color: var(--ok); }
.bar-line #saveState.saving { color: var(--warn); }
.bar-track { height: 6px; border-radius: 99px; background: #eae3d7; overflow: hidden; }
.bar-track i { display: block; height: 100%; width: 0; background: var(--teal); transition: width .2s; }
.submit-btn {
  border: 0; border-radius: 10px; padding: 9px 14px;
  background: var(--bad); color: #fff; font-size: 14px; font-weight: 600; cursor: pointer;
}
.exam-body { display: grid; gap: 0; }
.exam-main { min-width: 0; }
@media (min-width: 900px) {
  .view.exam { max-width: 1080px; }
  .exam-body { grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; align-items: start; }
  .palette-card { position: sticky; top: 122px; margin: 0; padding: 14px; }
  .palette-head { flex-direction: column; align-items: flex-start; gap: 4px; }
}
.question-card { padding-top: 16px; }
.q-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.q-no { font-size: 13px; font-weight: 700; color: var(--teal); letter-spacing: .04em; }
.q-tag {
  font-size: 11.5px; color: var(--muted); background: #f1ece2;
  padding: 2px 8px; border-radius: 999px;
}
.stem { font-size: 17px; line-height: 1.62; margin: 10px 0 16px; font-weight: 600; }
.opts { display: grid; gap: 9px; }
.opt {
  display: flex; align-items: flex-start; gap: 11px; width: 100%;
  padding: 12px 14px; border: 1.5px solid var(--rule); border-radius: 12px;
  background: #fff; color: var(--ink); text-align: left; cursor: pointer;
  font-size: 15.5px; line-height: 1.55;
}
.opt .letter {
  flex: 0 0 auto; width: 26px; height: 26px; border-radius: 50%;
  background: #f1ece2; color: #5b6770; font-size: 13px; font-weight: 700;
  display: grid; place-items: center; margin-top: 1px;
}
.opt.on { border-color: var(--teal); background: #eef6f4; }
.opt.on .letter { background: var(--teal); color: #fff; }
/* 正式考试：答过的题当场锁定，未选中的选项淡化，点了只提示不改 */
.opt.locked { cursor: default; }
.opt.locked:not(.on) { opacity: .55; }
.opt.locked:not(.on):hover { border-color: var(--rule); background: #fff; }
.opt.correct { border-color: var(--ok); background: var(--ok-bg); }
.opt.correct .letter { background: var(--ok); color: #fff; }
.opt.wrong { border-color: var(--bad); background: var(--bad-bg); }
.opt.wrong .letter { background: var(--bad); color: #fff; }
.opt.missed { border-color: var(--ok); border-style: dashed; background: #fff; }
.opt.missed .letter { background: var(--ok-bg); color: var(--ok); }
.q-hint { margin: 12px 0 0; font-size: 12px; color: var(--muted); }
.q-cap { margin: 6px 0 0; font-size: 12px; color: var(--muted); }
.multi-confirm { width: 100%; margin-top: 12px; }
.q-nav { display: flex; gap: 9px; margin: 0 0 14px; }
.q-nav button { flex: 1; }
.q-nav #btnFlag.on { border-color: var(--warn); background: var(--warn-bg); color: var(--warn); }
.palette-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.palette-head h2 { margin: 0; }
.legend { display: flex; align-items: center; gap: 5px; font-size: 11.5px; color: var(--muted); }
.legend .dot {
  width: 9px; height: 9px; border-radius: 3px; border: 1px solid var(--rule);
  background: #fff; display: inline-block;
}
.legend .dot.done { background: var(--teal); border-color: var(--teal); }
.legend .dot.flag { background: var(--warn); border-color: var(--warn); }
.palette { display: grid; grid-template-columns: repeat(10, 1fr); gap: 6px; margin-top: 12px; }
.palette button {
  aspect-ratio: 1; border: 1px solid var(--rule); border-radius: 8px;
  background: #fff; color: var(--muted); font-size: 12px; cursor: pointer;
  font-variant-numeric: tabular-nums;
}
.palette button.done { background: #dcebe7; border-color: #b9d6cf; color: var(--teal-dark); }
.palette button.flag { background: var(--warn-bg); border-color: #e3c98f; color: var(--warn); }
.palette button.now { outline: 2px solid var(--teal); outline-offset: 1px; }
@media (max-width: 520px) { .palette { grid-template-columns: repeat(8, 1fr); } }
/* 宽屏右侧答题卡只有 300px：8 列刚好，必须写在基础 .palette 之后才能覆盖 */
@media (min-width: 900px) {
  .view.exam .palette { grid-template-columns: repeat(8, 1fr); gap: 5px; }
  .view.exam .palette button { font-size: 11px; }
}

/* ---------- 成绩单 ---------- */
.result-head { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.score-big { font-size: 56px; font-weight: 800; line-height: 1; color: var(--teal-dark); }
.score-big small { font-size: 16px; font-weight: 500; color: var(--muted); }
.result-meta { flex: 1; min-width: 190px; }
.result-meta h1 { margin: 0 0 4px; font-size: 22px; }
.result-meta p { margin: 2px 0; color: #3c4a54; font-size: 14px; }
.badge {
  display: inline-block; margin-top: 8px; padding: 4px 12px; border-radius: 999px;
  font-size: 13px; font-weight: 700;
}
.badge.pass { background: var(--ok-bg); color: var(--ok); }
.badge.fail { background: var(--bad-bg); color: var(--bad); }
.alert {
  margin: 12px 0 0; padding: 12px 14px; border-radius: 11px;
  font-size: 14px; line-height: 1.6;
}
.alert.bad { background: var(--bad-bg); color: #7d2a1d; border: 1px solid #ecc7bd; }
.alert.warn { background: var(--warn-bg); color: #6d4a10; border: 1px solid #e8d3a4; }
.alert.ok { background: var(--ok-bg); color: #185c3b; border: 1px solid #cbe3d5; }
.dom-row { padding: 10px 0; border-bottom: 1px dashed var(--rule); }
.dom-row:last-child { border-bottom: 0; }
.dom-top { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; }
.dom-top b { font-weight: 600; }
.dom-top span { color: var(--muted); font-variant-numeric: tabular-nums; }
.dom-track { height: 7px; border-radius: 99px; background: #ece6da; margin-top: 6px; overflow: hidden; }
.dom-track i { display: block; height: 100%; border-radius: 99px; background: var(--teal); }
.weak-list { display: flex; flex-wrap: wrap; gap: 8px; }
.weak-list a {
  text-decoration: none; color: var(--teal-dark); background: #f1ece2;
  border-radius: 999px; padding: 5px 11px; font-size: 13px;
}
/* 交卷后的「错题与正确答案」：一题一卡，直接看到自己选了什么、正确是什么 */
.wrong-list { display: grid; gap: 10px; margin-top: 10px; }
.wrong-item { border: 1px solid var(--rule); border-radius: 12px; padding: 11px 13px; background: #fff; }
.wrong-top { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); flex-wrap: wrap; }
.wrong-top b { color: var(--teal); }
.wrong-tag { min-width: 0; }
.wrong-read { margin-left: auto; color: var(--teal); text-decoration: none; white-space: nowrap; }
.wrong-stem { margin: 7px 0 8px; font-size: 14.5px; font-weight: 600; line-height: 1.55; }
.wrong-line { margin: 3px 0; font-size: 13.5px; line-height: 1.55; }
.wrong-line.yours { color: var(--bad); }
.wrong-line.right { color: var(--ok); font-weight: 600; }
.wrong-why { margin: 7px 0 0; font-size: 12.5px; color: var(--muted); line-height: 1.6; }
.wrong-why b { color: var(--teal-dark); }
/* 带画面的题 */
.q-figure { margin: 12px 0 2px; }
.q-figure img { display: block; max-width: 100%; border-radius: 10px; border: 1px solid var(--rule); background: #fff; }
.q-figure figcaption { margin-top: 6px; font-size: 12px; color: var(--muted); }
.rv-figure img, .wrong-figure img { max-width: 100%; border-radius: 8px; border: 1px solid var(--rule); margin: 6px 0; }
.review-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.review-head h2 { margin: 0; }
.seg { display: inline-flex; border: 1px solid var(--rule); border-radius: 9px; overflow: hidden; }
.seg button {
  border: 0; background: #fff; color: var(--muted); font-size: 12.5px;
  padding: 6px 11px; cursor: pointer;
}
.seg button.on { background: var(--teal); color: #fff; }
.review-tools {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-top: 10px;
}
.review-tools .hint { margin: 0; text-align: left; }
.link-btn {
  border: 0; background: none; color: var(--teal); font-size: 13px;
  padding: 4px 0; cursor: pointer; white-space: nowrap;
}
.link-btn:hover { text-decoration: underline; }
.review-item { border-bottom: 1px solid var(--rule); }
.review-item:last-child { border-bottom: 0; }
.rv-head {
  display: block; width: 100%; text-align: left; font: inherit; color: inherit;
  background: none; border: 0; padding: 13px 0; cursor: pointer;
}
.rv-head:hover .rv-stem { color: var(--teal-dark); }
.rv-top { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); }
.rv-no { font-weight: 700; color: var(--teal); white-space: nowrap; }
.rv-tag { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rv-safety { color: var(--bad); }
.rv-res { margin-left: auto; font-weight: 700; white-space: nowrap; }
.rv-res.ok { color: var(--ok); }
.rv-res.bad { color: var(--bad); }
.rv-caret {
  flex: none; width: 7px; height: 7px; margin: 1px 3px 0 2px;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: rotate(45deg); transition: transform .15s ease;
}
.review-item.open .rv-caret { transform: rotate(225deg); margin-top: 5px; }
.rv-stem { display: block; font-weight: 600; margin-top: 6px; font-size: 15px; line-height: 1.55; }
.review-item:not(.open) .rv-stem {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.rv-body { padding: 2px 0 16px; }
.rv-opts { display: grid; gap: 6px; margin-bottom: 10px; }
.rv-opt {
  display: flex; gap: 9px; padding: 8px 11px; border-radius: 9px;
  border: 1px solid var(--rule); font-size: 14px; background: #fff;
}
.rv-opt .letter { font-weight: 700; color: var(--muted); }
.rv-opt.correct { border-color: #b9dcc7; background: var(--ok-bg); }
.rv-opt.wrong { border-color: #ecc7bd; background: var(--bad-bg); }
.rv-opt.picked { box-shadow: inset 0 0 0 1px rgba(20, 99, 92, .18); }
.rv-figure { margin: 4px 0 10px; }
.rv-why {
  background: #f7f3ea; border-radius: 10px; padding: 10px 12px;
  font-size: 13.5px; color: #44515a;
}
.rv-why b { color: var(--teal-dark); }
.rv-why a { color: var(--teal); }
.actions { display: grid; gap: 9px; }
.actions .primary-btn { width: 100%; }

/* ---------- 弹层 / 提示 ---------- */
.modal {
  position: fixed; inset: 0; z-index: 90; background: rgba(16,26,31,.52);
  display: grid; place-items: center; padding: 20px;
}
.modal-card {
  width: min(420px, 100%); background: var(--paper); border-radius: 16px;
  padding: 22px; box-shadow: 0 18px 60px rgba(0,0,0,.28);
}
.modal-card h2 { margin: 0 0 8px; font-size: 18px; }
.modal-card p { margin: 0 0 18px; color: #3c4a54; font-size: 14.5px; }
.modal-actions { display: flex; gap: 9px; }
.modal-actions button { flex: 1; }
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0));
  transform: translateX(-50%); z-index: 100;
  background: #22323c; color: #fff; font-size: 14px;
  padding: 10px 16px; border-radius: 11px; max-width: 86vw; text-align: center;
}
.login { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.login-card {
  width: min(380px, 100%); background: var(--paper); border: 1px solid var(--rule);
  border-radius: 18px; padding: 26px 20px; text-align: center;
}
.login-mark { width: 64px; height: 64px; display: block; margin: 0 auto 14px; border-radius: 50%; }
.login-card h1 { font-size: 20px; margin: 0 0 6px; }
.login-sub { color: var(--muted); font-size: 14px; margin: 0 0 18px; }
.login-card label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 5px; text-align: left; }
.login-card input {
  width: 100%; padding: 11px 12px; border: 1px solid var(--rule); border-radius: 10px;
  font: inherit; font-size: 16px; background: #fff; color: var(--ink);
}
.login-err { min-height: 20px; color: #b3402f; font-size: 13.5px; margin: 10px 0 0; }
.login-tip { color: var(--muted); font-size: 12.5px; margin: 12px 0 0; }
.login-tip a { color: var(--teal); text-decoration: none; }
