:root {
  --bg: #f5f6fa;
  --card: #ffffff;
  --ink: #1f2333;
  --ink-2: #5b6178;
  --ink-3: #9298ad;
  --line: #e6e8f0;
  --brand: #5b5bd6;
  --brand-soft: #eeeefb;
  --ok: #16a34a;
  --ok-soft: #e8f6ed;
  --bad: #dc2626;
  --bad-soft: #fdecec;
  --warn: #d97706;
  --warn-soft: #fdf3e3;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

button { font-family: inherit; font-size: inherit; cursor: pointer; }

.app {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 14px calc(84px + var(--safe-b));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(245, 246, 250, 0.92);
  backdrop-filter: saturate(180%) blur(12px);
  padding: calc(12px + var(--safe-t)) 14px 10px;
  margin: 0 -14px;
  border-bottom: 1px solid var(--line);
}
.topbar-row { max-width: 760px; margin: 0 auto; display: flex; align-items: center; gap: 10px; }
.topbar h1 { font-size: 16px; font-weight: 600; margin: 0; flex: 1; min-width: 0; letter-spacing: -0.2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.countdown {
  font-size: 13px;
  font-weight: 600;
  color: var(--brand);
  background: var(--brand-soft);
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
}
.countdown.urgent { color: var(--bad); background: var(--bad-soft); }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 12px;
  border: 1px solid var(--line);
}

.metric-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 12px; }
.metric {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 8px;
  text-align: center;
}
.metric b { display: block; font-size: 22px; font-weight: 600; line-height: 1.2; }
.metric span { font-size: 12px; color: var(--ink-3); }

.progress-track { height: 8px; background: var(--line); border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--brand); border-radius: 999px; transition: width .35s ease; }
.progress-fill.ok { background: var(--ok); }

h2.sec-title { font-size: 14px; font-weight: 600; color: var(--ink-2); margin: 20px 2px 8px; }

.mode-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 12px; }
.mode {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 2px;
  transition: transform .12s ease, border-color .12s ease;
}
.mode:active { transform: scale(.98); }
.mode b { font-size: 15px; font-weight: 600; }
.mode span { font-size: 12px; color: var(--ink-3); }
.mode.primary { background: var(--brand); border-color: var(--brand); }
.mode.primary b, .mode.primary span { color: #fff; }

.chapter-row { display: flex; align-items: center; gap: 10px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.chapter-row:last-child { border-bottom: none; }
.chapter-row .name { flex: 1; font-size: 14px; }
.chapter-row .pct { font-size: 12px; color: var(--ink-3); width: 66px; text-align: right; }
.chapter-row .bar { width: 90px; }

.qmeta { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.tag {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--brand-soft);
  color: var(--brand);
  font-weight: 500;
}
.tag.gray { background: #f0f1f5; color: var(--ink-2); }
.qtext { font-size: 17px; line-height: 1.75; margin: 4px 0 16px; letter-spacing: .1px; }

.opts { display: flex; flex-direction: column; gap: 9px; }
.opt {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  width: 100%;
  text-align: left;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  font-size: 16px;
  line-height: 1.6;
  color: var(--ink);
  transition: background .12s ease, border-color .12s ease;
}
.opt .key {
  flex: none;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: #f0f1f5;
  color: var(--ink-2);
  font-size: 13px;
  font-weight: 600;
  display: flex; align-items: center; justify-content: center;
  margin-top: 1px;
}
.opt.selected { border-color: var(--brand); background: var(--brand-soft); }
.opt.selected .key { background: var(--brand); color: #fff; }
.opt.correct { border-color: var(--ok); background: var(--ok-soft); }
.opt.correct .key { background: var(--ok); color: #fff; }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.opt.wrong .key { background: var(--bad); color: #fff; }
.opt[disabled] { cursor: default; }

.fill-input {
  width: 100%;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 16px;
  background: var(--card);
  color: var(--ink);
  outline: none;
}
.fill-input:focus { border-color: var(--brand); }

.judge-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.judge-btn {
  padding: 18px;
  font-size: 18px;
  font-weight: 600;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
}
.judge-btn.t.picked { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }
.judge-btn.f.picked { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }

.verdict {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 600;
}
.verdict.ok { background: var(--ok-soft); color: var(--ok); }
.verdict.bad { background: var(--bad-soft); color: var(--bad); }
.verdict .ans { display: block; font-weight: 400; font-size: 14px; color: var(--ink-2); margin-top: 4px; }

.expl {
  margin-top: 10px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--warn-soft);
  font-size: 14.5px;
  line-height: 1.75;
  color: #7c4a03;
}
.expl b { font-weight: 600; }

.ref-answer {
  margin-top: 10px;
  padding: 12px 14px;
  border-radius: 12px;
  background: #f0f1f5;
  font-size: 15px;
  line-height: 1.8;
  color: var(--ink);
  white-space: pre-wrap;
}

.rate-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; margin-top: 14px; }
.rate-btn {
  padding: 13px 6px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  font-size: 15px;
  font-weight: 500;
}
.rate-btn small { display: block; font-size: 11px; color: var(--ink-3); font-weight: 400; }
.rate-btn.r0 { border-color: var(--bad); color: var(--bad); background: var(--bad-soft); }
.rate-btn.r1 { border-color: var(--warn); color: var(--warn); background: var(--warn-soft); }
.rate-btn.r2 { border-color: var(--ok); color: var(--ok); background: var(--ok-soft); }

.quiz-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}
.quiz-bar .progress-track { flex: 1; }
.quiz-bar .count { font-size: 13px; color: var(--ink-3); white-space: nowrap; }

.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  display: flex;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: saturate(180%) blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
.tabbar-inner {
  max-width: 760px;
  margin: 0 auto;
  display: flex;
  width: 100%;
}
.tab {
  flex: 1;
  padding: 10px 4px;
  border: none;
  background: none;
  font-size: 12px;
  color: var(--ink-3);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
.tab svg { width: 22px; height: 22px; }
.tab.active { color: var(--brand); }

.btn {
  display: block;
  width: 100%;
  padding: 15px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  font-size: 16px;
  font-weight: 500;
  color: var(--ink);
  margin-top: 12px;
}
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.ghost { background: transparent; }
.btn:active { opacity: .85; }

.list-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  text-align: left;
  width: 100%;
  background: none;
  border-left: none; border-right: none; border-top: none;
  color: var(--ink);
  font-size: 15px;
}
.list-row:last-child { border-bottom: none; }
.list-row .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.list-row .txt { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- 账户 ---------- */
.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 40%;
  min-height: 44px;             /* iOS HIG 最小点击区 */
  padding: 6px 12px 6px 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--ink);
  font-size: 14px;
  font-weight: 500;
  flex: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(91, 91, 214, 0.12);
}
.user-chip:active { background: var(--brand-soft); }
.user-chip #userName { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--brand-soft);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 14px; line-height: 1;
  flex: none;
}
.user-row { align-items: center; }
.user-row .avatar { width: 34px; height: 34px; font-size: 19px; }
.user-row .txt { display: flex; flex-direction: column; white-space: normal; }
.user-row .txt small { font-size: 12px; color: var(--ink-3); font-weight: 400; }
.user-row.cur .txt { color: var(--brand); font-weight: 600; }
.user-row.cur .avatar { background: var(--brand); }
.cur-badge {
  font-size: 11px; font-weight: 600; color: var(--brand);
  background: var(--brand-soft); border-radius: 999px; padding: 2px 8px; flex: none;
}
.ico {
  padding: 6px 7px; margin: -6px 0;
  font-size: 15px; color: var(--ink-3); flex: none;
  border-radius: 8px;
}
.ico:active { background: var(--line); }
.ico.danger { color: var(--bad); }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }

.empty { text-align: center; padding: 40px 20px; color: var(--ink-3); font-size: 15px; }

.sync-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--ink-3);
  flex: none;
}
.sync-dot.on { background: var(--ok); }
.sync-dot.err { background: var(--warn); }
.sync-dot.busy { background: var(--brand); }

.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 12px; }
.metric.sm b { font-size: 19px; }

.hint { font-size: 13px; color: var(--ink-3); line-height: 1.7; }

@media (min-width: 720px) {
  .app { padding-top: 4px; }
  .qtext { font-size: 18px; }
  .mode-grid { grid-template-columns: repeat(4, 1fr); }
  .card { padding: 20px; }
}
