:root {
  --primary: #1a56db;
  --primary-soft: #e8effd;
  --bg: #f3f5f9;
  --card: #fff;
  --text: #24292f;
  --muted: #6b7280;
  --line: #e5e8ee;
  --green: #0a7d33;
  --green-soft: #e6f4ea;
  --red: #c02626;
  --red-soft: #fdecec;
  --amber: #b25e02;
  --radius: 12px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.7 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  overscroll-behavior-y: none;
}

button { font: inherit; cursor: pointer; }

.hidden { display: none !important; }

/* ---------- 登录页 ---------- */
#authView {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 18px calc(24px + var(--safe-bottom));
}
.auth-card {
  background: var(--card);
  border-radius: 16px;
  padding: 28px 24px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 6px 24px rgba(20, 40, 80, .08);
}
.auth-card h1 { font-size: 20px; margin: 0 0 4px; }
.auth-card .sub { color: var(--muted); font-size: 13px; margin: 0 0 20px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input {
  width: 100%;
  padding: 11px 13px;
  font-size: 16px; /* 16px 可避免 iOS 聚焦时自动放大 */
  border: 1px solid #d0d7de;
  border-radius: 9px;
  outline: none;
  background: #fff;
  color: var(--text);
}
.field input:focus { border-color: var(--primary); }
.btn-primary {
  width: 100%;
  padding: 12px;
  border: 0;
  border-radius: 9px;
  background: var(--primary);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
}
.btn-primary:disabled { opacity: .6; }
.btn-text {
  width: 100%;
  margin-top: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  color: var(--primary);
  font-size: 14px;
}
.auth-msg { min-height: 20px; font-size: 13px; margin: 10px 0 0; color: var(--red); }
.auth-msg.ok { color: var(--green); }
.auth-tip { font-size: 12px; color: var(--muted); margin: 16px 0 0; line-height: 1.6; }

/* ---------- 顶部栏 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(243, 245, 249, .94);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar-row {
  max-width: 900px;
  margin: 0 auto;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand { font-weight: 700; font-size: 15px; white-space: nowrap; }
.spacer { flex: 1; }
.sync-chip {
  font-size: 12px;
  padding: 3px 9px;
  border-radius: 20px;
  background: var(--green-soft);
  color: var(--green);
  white-space: nowrap;
}
.sync-chip[data-state="syncing"] { background: var(--primary-soft); color: var(--primary); }
.sync-chip[data-state="pending"] { background: #fff4e0; color: var(--amber); }
.sync-chip[data-state="error"], .sync-chip[data-state="offline"] { background: var(--red-soft); color: var(--red); }
.icon-btn {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 12px;
  color: var(--muted);
}

.tabs {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 14px 8px;
  display: flex;
  gap: 8px;
}
.tab {
  flex: 1;
  padding: 8px 4px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 9px;
  font-size: 14px;
  color: var(--muted);
}
.tab.active { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.tab .badge { font-size: 11px; opacity: .85; }

/* ---------- 主体 ---------- */
main {
  max-width: 900px;
  margin: 0 auto;
  padding: 14px 14px calc(40px + var(--safe-bottom));
}

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.toolbar input[type="search"], .toolbar input[type="number"] {
  padding: 9px 12px;
  font-size: 16px;
  border: 1px solid #d0d7de;
  border-radius: 9px;
  outline: none;
  background: #fff;
  color: var(--text);
}
.toolbar input[type="search"] { flex: 1 1 180px; min-width: 0; }
.toolbar input[type="number"] { width: 92px; }
.toolbar input:focus { border-color: var(--primary); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip {
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: #fff;
  font-size: 13px;
  color: var(--muted);
}
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.result-count { font-size: 13px; color: var(--muted); margin-bottom: 10px; }

/* ---------- 题目卡片 ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .04);
}
.card-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.qno {
  display: inline-block;
  padding: 1px 9px;
  background: var(--primary);
  color: #fff;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 600;
}
.qtag { font-size: 11px; padding: 1px 7px; border-radius: 6px; background: var(--primary-soft); color: var(--primary); }
.qtag.wrong { background: var(--red-soft); color: var(--red); }
.qtag.right { background: var(--green-soft); color: var(--green); }
.qtag.marked { background: #fff4e0; color: var(--amber); }
.stem { font-weight: 600; word-break: break-word; }

.opts { list-style: none; margin: 12px 0 0; padding: 0; }
.opt {
  display: flex;
  gap: 9px;
  padding: 10px 12px;
  margin-bottom: 7px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  cursor: pointer;
  transition: background .15s, border-color .15s;
  word-break: break-word;
}
.opt .letter {
  flex: 0 0 22px;
  height: 22px;
  line-height: 22px;
  text-align: center;
  border-radius: 50%;
  background: #eef1f6;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}
.opt.picked { border-color: var(--primary); background: var(--primary-soft); }
.opt.picked .letter { background: var(--primary); color: #fff; }
.card.answered .opt { cursor: default; }
.card.answered .opt.is-answer { border-color: var(--green); background: var(--green-soft); }
.card.answered .opt.is-answer .letter { background: var(--green); color: #fff; }
.card.answered .opt.wrong-pick { border-color: var(--red); background: var(--red-soft); }
.card.answered .opt.wrong-pick .letter { background: var(--red); color: #fff; }

.card-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.btn-sm {
  padding: 7px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 13px;
  color: var(--text);
}
.btn-sm.solid { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.btn-sm:disabled { opacity: .5; }

.verdict { margin-top: 12px; font-size: 14px; font-weight: 600; }
.verdict.right { color: var(--green); }
.verdict.wrong { color: var(--red); }

/* ---------- 答案区：未作答时模糊，悬停/点按才显示 ---------- */
.answer-box {
  position: relative;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed #d8dee6;
  cursor: pointer;
}
.veil { filter: blur(7px); user-select: none; transition: filter .25s ease; }
.answer-box:hover .veil,
.answer-box.revealed .veil { filter: none; user-select: auto; }
.card.answered .answer-box { cursor: default; }
.card.answered .veil { filter: none; user-select: auto; }
.ans { color: var(--green); font-weight: 600; }
.exp { color: var(--muted); font-size: 14px; margin-top: 4px; word-break: break-word; }
.hint {
  position: absolute;
  inset: 10px 0 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 13px;
  pointer-events: none;
  transition: opacity .2s ease;
}
.answer-box:hover .hint,
.answer-box.revealed .hint,
.card.answered .hint { opacity: 0; }

/* ---------- 分页 / 统计 ---------- */
.pager { display: flex; align-items: center; justify-content: center; gap: 12px; margin: 18px 0 6px; }
.pager span { font-size: 13px; color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 48px 16px; font-size: 14px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.stat-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.stat-card .k { font-size: 13px; color: var(--muted); }
.stat-card .v { font-size: 26px; font-weight: 700; margin-top: 4px; }
.stat-card .v small { font-size: 13px; font-weight: 400; color: var(--muted); }
.bar { height: 8px; border-radius: 5px; background: #eaeef4; overflow: hidden; margin-top: 10px; }
.bar > i { display: block; height: 100%; background: var(--primary); }
.stat-section { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-top: 12px; }
.stat-section h3 { margin: 0 0 10px; font-size: 15px; }
.stat-row { display: flex; justify-content: space-between; font-size: 14px; padding: 5px 0; }
.stat-row span:last-child { color: var(--muted); }
.danger { color: var(--red); border-color: #f3c6c6; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(28px + var(--safe-bottom));
  transform: translateX(-50%);
  background: rgba(30, 35, 45, .93);
  color: #fff;
  padding: 9px 18px;
  border-radius: 20px;
  font-size: 13px;
  z-index: 60;
  max-width: 86vw;
  text-align: center;
}

@media (max-width: 480px) {
  .brand { font-size: 14px; }
  .card { padding: 14px; }
}
