:root {
  --bg: #f2f5fb;
  --bg-soft: #eaf0fa;
  --card: #ffffff;
  --text: #1b2233;
  --muted: #6b7690;
  --line: #e3e9f4;
  --accent: #4c6fff;
  --accent-strong: #3a5bee;
  --accent-weak: #eef2ff;
  --green: #0f9d6b;
  --green-weak: #e8f7f1;
  --red: #e0454b;
  --red-weak: #fdecee;
  --orange: #b7791f;
  --orange-weak: #fff5e2;
  --shadow: 0 10px 30px rgba(28, 42, 84, .07);
  --shadow-sm: 0 4px 14px rgba(28, 42, 84, .05);
  --radius: 16px;
  --ring-bg: #e8edf7;
}

body[data-theme="dark"] {
  --bg: #0f1219;
  --bg-soft: #151a25;
  --card: #191f2b;
  --text: #e8ecf6;
  --muted: #97a1b8;
  --line: #2a3242;
  --accent: #7f97ff;
  --accent-strong: #93a7ff;
  --accent-weak: #232c45;
  --green: #3ddc9c;
  --green-weak: #173328;
  --red: #ff7b80;
  --red-weak: #3a1f22;
  --orange: #f5c26b;
  --orange-weak: #3a2e19;
  --shadow: 0 10px 30px rgba(0, 0, 0, .28);
  --shadow-sm: 0 4px 14px rgba(0, 0, 0, .2);
  --ring-bg: #232b3a;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background:
    radial-gradient(1000px 500px at 10% -10%, rgba(76, 111, 255, .13), transparent 70%),
    radial-gradient(800px 400px at 95% 0%, rgba(15, 157, 107, .10), transparent 70%),
    var(--bg);
  color: var(--text);
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.7;
  min-height: 100vh;
}

body[data-theme="dark"] {
  background:
    radial-gradient(1000px 500px at 10% -10%, rgba(127, 151, 255, .16), transparent 70%),
    radial-gradient(800px 400px at 95% 0%, rgba(61, 220, 156, .08), transparent 70%),
    var(--bg);
}

button, input { font-family: inherit; }
h1, h2, h3, h4, p { margin: 0; }

.page {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 24px 40px;
}

/* ---------- 顶栏 ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
  padding: 18px 4px 16px;
  margin-bottom: 20px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
}

.brand { display: flex; align-items: center; gap: 12px; margin-right: auto; }

.brand-icon {
  width: 46px; height: 46px;
  display: grid; place-items: center;
  font-size: 22px;
  border-radius: 14px;
  color: #fff;
  background: linear-gradient(135deg, #4c6fff, #7b5cff 55%, #12a374);
  box-shadow: 0 8px 18px rgba(76, 111, 255, .3);
}

.brand-text h1 { font-size: 19px; letter-spacing: .3px; }
.brand-text p { font-size: 12.5px; color: var(--muted); line-height: 1.4; }

.tabs { display: flex; gap: 6px; background: var(--bg-soft); padding: 5px; border-radius: 999px; }

.tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  padding: 8px 16px;
  border-radius: 999px;
  cursor: pointer;
  transition: .2s ease;
  white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active {
  background: var(--card);
  color: var(--text);
  font-weight: 700;
  box-shadow: var(--shadow-sm);
}

.tab-badge {
  display: inline-block;
  min-width: 18px;
  padding: 0 5px;
  margin-left: 2px;
  border-radius: 999px;
  background: var(--red);
  color: #fff;
  font-size: 11px;
  line-height: 18px;
  text-align: center;
  font-weight: 600;
}
.tab-badge:empty, .tab-badge.zero { display: none; }

.icon-btn {
  width: 42px; height: 42px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  transition: .2s;
}
.icon-btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-sm); }

/* ---------- 通用 ---------- */
.panel { display: none; animation: fade .28s ease; }
.panel.active { display: block; }
.hidden { display: none !important; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.muted { color: var(--muted); font-size: 13.5px; }

.btn {
  border: 1px solid transparent;
  border-radius: 11px;
  padding: 10px 20px;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  transition: .18s ease;
  background: var(--bg-soft);
  color: var(--text);
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn.primary {
  background: linear-gradient(135deg, var(--accent), #7b5cff);
  color: #fff;
  box-shadow: 0 8px 18px rgba(76, 111, 255, .25);
}
.btn.primary:hover { box-shadow: 0 10px 22px rgba(76, 111, 255, .35); }
.btn.primary:disabled {
  opacity: .45; cursor: not-allowed; transform: none; box-shadow: none;
}
.btn.ghost { background: transparent; border-color: var(--line); color: var(--text); }
.btn.ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn.small { padding: 7px 14px; font-size: 13px; border-radius: 9px; }

/* ---------- 统计条 ---------- */
.stats-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 18px;
}
.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 18px;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.stat .num { font-size: 26px; font-weight: 800; letter-spacing: .5px; color: var(--accent); font-variant-numeric: tabular-nums; }
.stat .num.green { color: var(--green); }
.stat .num.red { color: var(--red); }
.stat .label { font-size: 13px; color: var(--muted); }

/* ---------- 筛选 ---------- */
.filters { padding: 16px 20px; margin-bottom: 24px; display: grid; gap: 12px; }

.filter-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.filter-label {
  width: 44px;
  flex: none;
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}

.chips { display: flex; flex-wrap: wrap; gap: 7px; }

.chip {
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--muted);
  border-radius: 999px;
  padding: 5px 14px;
  font-size: 13px;
  cursor: pointer;
  transition: .16s ease;
  line-height: 1.6;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip.active {
  background: var(--accent-weak);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 700;
}

.switch { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; color: var(--muted); cursor: pointer; user-select: none; margin-left: 4px; }
.switch input { accent-color: var(--accent); width: 15px; height: 15px; cursor: pointer; }

.search {
  position: relative;
  margin-left: auto;
  min-width: 250px;
  flex: 1 1 250px;
  max-width: 360px;
}
.search-icon {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  font-size: 13px; opacity: .75; pointer-events: none;
}
.search input {
  width: 100%;
  padding: 9px 14px 9px 34px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--text);
  font-size: 13.5px;
  outline: none;
  transition: .18s;
}
.search input:focus { border-color: var(--accent); background: var(--card); box-shadow: 0 0 0 3px var(--accent-weak); }
.search input::placeholder { color: var(--muted); }

/* ---------- 列表 ---------- */
.list-head { display: flex; align-items: baseline; justify-content: space-between; margin: 0 2px 12px; }
.list-head h2 { font-size: 17px; }

.q-list { display: grid; gap: 14px; }

.q-card {
  padding: 18px 20px 16px;
  transition: border-color .18s ease, box-shadow .18s ease;
}
.q-card:hover { border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); box-shadow: var(--shadow); }

.q-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 7px; margin-bottom: 9px; }

.tag {
  display: inline-block;
  padding: 1px 9px;
  border-radius: 6px;
  font-size: 11.5px;
  line-height: 1.8;
  font-weight: 600;
  background: var(--bg-soft);
  color: var(--muted);
}
.tag.set { background: var(--accent-weak); color: var(--accent); }
.tag.star { background: var(--orange-weak); color: var(--orange); }
.tag.type-single { background: #eef4ff; color: #3867d6; }
.tag.type-judge { background: #eaf8f2; color: #12805e; }
.tag.type-multi { background: #f8edff; color: #8a46c9; }
body[data-theme="dark"] .tag.type-single { background: #202c48; color: #92b0ff; }
body[data-theme="dark"] .tag.type-judge { background: #173328; color: #5fd6a8; }
body[data-theme="dark"] .tag.type-multi { background: #332244; color: #cd9bff; }

.q-no { margin-left: auto; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

.stem {
  font-size: 15.5px;
  line-height: 1.8;
  font-weight: 600;
  margin-bottom: 12px;
  white-space: pre-line;
  word-break: break-word;
}

.opt-list { display: grid; gap: 8px; }

.opt {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-soft);
  font-size: 14px;
  line-height: 1.65;
  white-space: pre-line;
  word-break: break-word;
}

.opt .key {
  flex: none;
  width: 24px; height: 24px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--card);
  border: 1px solid var(--line);
  font-size: 12.5px;
  font-weight: 700;
  color: var(--muted);
  margin-top: 1px;
}

.q-foot { display: flex; align-items: center; gap: 10px; margin-top: 14px; }

.explain {
  margin-top: 14px;
  padding: 16px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--accent-weak) 55%, var(--card));
  border: 1px dashed color-mix(in srgb, var(--accent) 25%, var(--line));
  animation: fade .2s ease;
}

.ans-line { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 10px; flex-wrap: wrap; }
.ans-label {
  flex: none;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 1px 8px;
  margin-top: 2px;
}
.ans-value { font-weight: 700; color: var(--green); font-size: 14px; }
.ans-value.pick { color: var(--red); }

.exp-block { margin-top: 12px; }
.exp-block h4 {
  font-size: 12.5px;
  color: var(--accent);
  margin-bottom: 3px;
  font-weight: 700;
  letter-spacing: .5px;
}
.exp-block p { font-size: 14px; line-height: 1.85; white-space: pre-line; word-break: break-word; color: var(--text); }
.exp-block p.warn { color: var(--orange); }

.load-more-wrap { text-align: center; margin: 20px 0 8px; }

/* ---------- 自测设置 ---------- */
.setup { padding: 22px 24px; display: grid; gap: 14px; }
.setup h2 { font-size: 18px; }
.setup > p { margin-top: -6px; }

.setup-foot {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; flex-wrap: wrap;
  border-top: 1px dashed var(--line);
  padding-top: 16px;
  margin-top: 4px;
}
.setup-foot p { font-size: 13.5px; color: var(--muted); }

.tip { margin-top: 16px; padding: 16px 20px; border-left: 3px solid var(--accent); }
.tip strong { font-size: 13.5px; color: var(--accent); }
.tip p { font-size: 13.5px; color: var(--muted); margin-top: 3px; }

/* ---------- 答题 ---------- */
.quiz-top {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 18px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.quiz-progress-text { font-size: 13.5px; color: var(--muted); white-space: nowrap; }
.quiz-progress-text strong { color: var(--text); font-size: 16px; }
.quiz-top .progress { flex: 1 1 160px; height: 7px; border-radius: 99px; background: var(--ring-bg); overflow: hidden; min-width: 120px; }
.quiz-top .progress span { display: block; height: 100%; width: 0; border-radius: inherit; background: linear-gradient(90deg, var(--accent), #7b5cff); transition: width .3s ease; }
.quiz-score { font-size: 13.5px; color: var(--muted); white-space: nowrap; }
.quiz-score strong { color: var(--green); font-size: 16px; }

.quiz-card { padding: 26px 28px; }
.quiz-card .stem { font-size: 17px; }

.opt-list.quiz .opt {
  cursor: pointer;
  background: var(--bg-soft);
  border: 1.5px solid var(--line);
  transition: .16s ease;
  user-select: none;
}
.opt-list.quiz .opt:hover { border-color: var(--accent); }
.opt-list.quiz .opt.selected { border-color: var(--accent); background: var(--accent-weak); }
.opt-list.quiz .opt.selected .key { background: var(--accent); color: #fff; border-color: var(--accent); }
.opt-list.quiz .opt.correct { border-color: var(--green); background: var(--green-weak); }
.opt-list.quiz .opt.correct .key { background: var(--green); color: #fff; border-color: var(--green); }
.opt-list.quiz .opt.wrong-pick { border-color: var(--red); background: var(--red-weak); }
.opt-list.quiz .opt.wrong-pick .key { background: var(--red); color: #fff; border-color: var(--red); }
.opt-list.quiz .opt.disabled { cursor: default; }
.opt-list.quiz .opt.disabled:hover { border-color: var(--line); }
.opt-list.quiz .opt.correct.disabled:hover { border-color: var(--green); }
.opt-list.quiz .opt.wrong-pick.disabled:hover { border-color: var(--red); }

.quiz-actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 16px; }
.quiz-actions .btn { min-width: 140px; padding: 12px 24px; }

/* ---------- 结果 ---------- */
.result-card {
  padding: 28px;
  text-align: center;
  display: grid;
  justify-items: center;
  gap: 10px;
  margin-bottom: 18px;
}
.result-ring {
  --pct: 0;
  width: 132px; height: 132px;
  border-radius: 50%;
  background: conic-gradient(var(--accent) calc(var(--pct) * 1%), var(--ring-bg) 0);
  display: grid; place-items: center;
  margin-bottom: 4px;
}
.result-ring .inner {
  width: 106px; height: 106px;
  border-radius: 50%;
  background: var(--card);
  display: grid; place-items: center;
  align-content: center;
  line-height: 1.25;
}
.result-ring .pct { font-size: 26px; font-weight: 800; color: var(--accent); }
.result-ring .sub { font-size: 11.5px; color: var(--muted); }
.result-card h2 { font-size: 20px; }
.result-card .desc { color: var(--muted); font-size: 14px; }
.result-btns { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 8px; }

.result-sec-title { font-size: 16px; margin: 22px 2px 12px; }

/* ---------- 错题本 ---------- */
.wrong-head {
  padding: 18px 22px;
  margin-bottom: 18px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; flex-wrap: wrap;
}
.wrong-head h2 { font-size: 18px; margin-bottom: 2px; }
.wrong-actions { display: flex; gap: 10px; }
.wrong-actions .btn:disabled, #practiceWrongBtn:disabled { opacity: .45; cursor: not-allowed; transform: none; }

.empty {
  text-align: center;
  padding: 56px 20px;
  color: var(--muted);
  background: var(--card);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  font-size: 14px;
}
.empty .big { font-size: 40px; display: block; margin-bottom: 8px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 30px;
  transform: translate(-50%, 20px);
  background: var(--text);
  color: var(--card);
  padding: 10px 20px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: .25s ease;
  z-index: 100;
  max-width: 90vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.footer {
  margin-top: 36px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  text-align: center;
  font-size: 12.5px;
  color: var(--muted);
}

/* ---------- 响应式 ---------- */
@media (max-width: 820px) {
  .page { padding: 0 14px 32px; }
  .app-header { gap: 12px; padding: 14px 2px 12px; }
  .brand-icon { width: 40px; height: 40px; font-size: 19px; }
  .brand-text h1 { font-size: 16.5px; }
  .brand-text p { font-size: 11.5px; }
  .tabs { order: 3; width: 100%; justify-content: center; }
  .tab { flex: 1; padding: 8px 10px; font-size: 13px; }
  .icon-btn { margin-left: auto; width: 38px; height: 38px; font-size: 16px; }
  .stats-bar { grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
  .stat { padding: 10px 12px; display: block; }
  .stat .num { font-size: 20px; display: block; }
  .stat .label { font-size: 11.5px; }
  .filter-label { width: auto; }
  .search { margin-left: 0; min-width: 100%; max-width: none; }
  .q-card { padding: 15px 15px 14px; }
  .stem { font-size: 15px; }
  .quiz-card { padding: 18px 16px; }
  .quiz-card .stem { font-size: 16px; }
  .quiz-actions { flex-direction: column; }
  .quiz-actions .btn { width: 100%; }
  .wrong-actions { width: 100%; }
  .wrong-actions .btn { flex: 1; }
  .result-card { padding: 22px 16px; }
}
