:root {
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-light: #eef2ff;
  --green: #16a34a;
  --green-light: #f0fdf4;
  --red: #dc2626;
  --red-light: #fef2f2;
  --amber: #d97706;
  --text: #1e293b;
  --text-dim: #64748b;
  --bg: #f4f5fb;
  --card: #ffffff;
  --border: #e2e8f0;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .06), 0 4px 16px rgba(15, 23, 42, .05);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ===== 顶栏 ===== */
.topbar {
  background: #fff;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-inner {
  max-width: 980px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 10px;
  background: linear-gradient(135deg, #6366f1, #4338ca);
  color: #fff; font-weight: 800; font-size: 20px;
  display: flex; align-items: center; justify-content: center;
}
.brand-text { font-size: 16px; color: var(--text-dim); }
.brand-text b { color: var(--text); }
.tabs { display: flex; gap: 4px; overflow-x: auto; }
.tab {
  border: none; background: none; padding: 8px 14px;
  font-size: 15px; color: var(--text-dim);
  border-radius: 10px; cursor: pointer; white-space: nowrap;
}
.tab:hover { background: var(--primary-light); color: var(--primary); }
.tab.active { background: var(--primary); color: #fff; font-weight: 600; }

/* ===== 布局 ===== */
.container { max-width: 980px; width: 100%; margin: 0 auto; padding: 20px 16px 48px; flex: 1; }
.view.hidden { display: none; }
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}

/* ===== 首页 ===== */
.hero { text-align: center; padding: 40px 24px; background: linear-gradient(135deg, #eef2ff 0%, #fff 60%); }
.hero h1 { font-size: 26px; margin-bottom: 8px; }
.hero p { color: var(--text-dim); font-size: 14px; margin-bottom: 24px; }
.stat-row {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 12px; margin: 20px 0 32px;
}
.stat {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; text-align: center;
}
.stat .num { font-size: 24px; font-weight: 700; color: var(--primary); }
.stat .lbl { font-size: 12px; color: var(--text-dim); }
.sec-title { font-size: 18px; margin: 8px 0 4px; }
.sec-sub { font-size: 13px; color: var(--text-dim); margin-bottom: 16px; }

.topic-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.topic-card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px;
  display: flex; flex-direction: column; gap: 8px;
  transition: transform .12s ease;
}
.topic-card:hover { transform: translateY(-2px); }
.topic-card .tname { font-weight: 600; font-size: 15px; }
.topic-card .tmeta { font-size: 12px; color: var(--text-dim); }
.topic-card .btn { margin-top: 4px; align-self: flex-start; }
.badge {
  display: inline-block; font-size: 11px; padding: 2px 8px;
  border-radius: 999px; background: var(--primary-light); color: var(--primary);
  font-weight: 600;
}
.badge.key { background: #fef3c7; color: #92400e; }

/* ===== 按钮 ===== */
.btn {
  border: none; cursor: pointer; border-radius: 10px;
  padding: 10px 18px; font-size: 15px;
  background: var(--primary-light); color: var(--primary);
  transition: background .15s ease;
}
.btn:hover { background: #e0e7ff; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-lg { padding: 14px 32px; font-size: 17px; border-radius: 12px; }
.btn-ghost { background: none; border: 1px solid var(--border); color: var(--text-dim); }
.btn-ghost:hover { background: #f8fafc; }
.btn-danger { background: var(--red-light); color: var(--red); }
.btn-danger:hover { background: #fee2e2; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* ===== 做题 ===== */
.q-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.q-progress { font-size: 14px; color: var(--text-dim); font-weight: 600; }
.q-timer { font-size: 14px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.progress-track { height: 6px; background: #e2e8f0; border-radius: 999px; overflow: hidden; margin-bottom: 20px; }
.progress-fill { height: 100%; background: var(--primary); border-radius: 999px; transition: width .2s ease; }

.q-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; }
.q-meta { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.q-type { font-size: 12px; padding: 2px 10px; border-radius: 999px; font-weight: 600; }
.q-type.single { background: var(--primary-light); color: var(--primary); }
.q-type.judge { background: #ecfeff; color: #0e7490; }
.q-type.fill { background: #fef3c7; color: #b45309; }
.q-type.q-hard { background: var(--red-light); color: var(--red); }

/* ===== 填空题 ===== */
.fill-box { margin-top: 4px; }
.fill-input {
  width: 100%;
  padding: 12px 14px;
  font-size: 15px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  outline: none;
  transition: border-color .15s;
}
.fill-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.fill-input:disabled { background: var(--bg); color: var(--text-dim); }
.fill-hint { font-size: 12px; color: var(--text-dim); margin-top: 8px; }
.fill-review { margin-top: 12px; font-size: 14px; line-height: 2; }
.fill-review .ok { color: var(--green); }
.q-topic { font-size: 12px; color: var(--text-dim); }
.q-text { font-size: 17px; font-weight: 600; margin-bottom: 18px; line-height: 1.7; }

.opts { display: flex; flex-direction: column; gap: 10px; }
.opt {
  display: flex; gap: 12px; align-items: flex-start;
  border: 2px solid var(--border); border-radius: 12px;
  padding: 13px 16px; cursor: pointer; font-size: 15px;
  background: #fff; text-align: left; width: 100%;
  transition: border-color .12s ease, background .12s ease;
}
.opt:hover { border-color: #a5b4fc; }
.opt .opt-key {
  flex: none; width: 26px; height: 26px; border-radius: 8px;
  background: #f1f5f9; color: var(--text-dim);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; margin-top: 1px;
}
.opt.selected { border-color: var(--primary); background: var(--primary-light); }
.opt.selected .opt-key { background: var(--primary); color: #fff; }
.opt.correct { border-color: var(--green); background: var(--green-light); }
.opt.correct .opt-key { background: var(--green); color: #fff; }
.opt.wrong { border-color: var(--red); background: var(--red-light); }
.opt.wrong .opt-key { background: var(--red); color: #fff; }
.opt.locked { cursor: default; }

.explain {
  margin-top: 16px; padding: 14px 16px; border-radius: 12px;
  background: #fffbeb; border: 1px solid #fde68a;
  font-size: 14px; color: #78350f;
}
.explain b { display: block; margin-bottom: 4px; }

.palette { display: grid; grid-template-columns: repeat(10, 1fr); gap: 8px; margin: 18px 0; }
.pal {
  aspect-ratio: 1; border-radius: 9px; border: 1.5px solid var(--border);
  background: #fff; font-size: 13px; color: var(--text-dim);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.pal.answered { background: #dbeafe; border-color: #93c5fd; color: #1d4ed8; font-weight: 700; }
.pal.current { outline: 2.5px solid var(--primary); outline-offset: 1px; }

/* ===== 结果页 ===== */
.result-hero { text-align: center; padding: 32px 24px; }
.result-score { font-size: 52px; font-weight: 800; color: var(--primary); }
.result-score small { font-size: 22px; color: var(--text-dim); font-weight: 600; }
.result-pct { font-size: 16px; color: var(--text-dim); margin: 6px 0 14px; }
.pass-flag { display: inline-block; padding: 4px 16px; border-radius: 999px; font-weight: 700; font-size: 14px; }
.pass-flag.pass { background: var(--green-light); color: var(--green); }
.pass-flag.fail { background: var(--red-light); color: var(--red); }

.topic-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.topic-table th, .topic-table td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); }
.topic-table th { color: var(--text-dim); font-size: 12px; font-weight: 600; }
.topic-table td .mini-bar { display: inline-block; height: 6px; border-radius: 999px; background: var(--primary); vertical-align: middle; }

.review-item { margin-top: 14px; }
.review-item .q-text { font-size: 15px; }

/* ===== 错题本 / 成绩 ===== */
.wrong-item {
  background: var(--card); border-radius: 12px; box-shadow: var(--shadow);
  padding: 14px 18px; margin-bottom: 10px;
  display: flex; justify-content: space-between; gap: 12px; align-items: center;
}
.wrong-item .wq { font-size: 14px; flex: 1; }
.wrong-item .wcount { font-size: 12px; color: var(--red); white-space: nowrap; }
.hist-row {
  display: flex; align-items: center; gap: 14px;
  background: var(--card); border-radius: 12px; box-shadow: var(--shadow);
  padding: 12px 18px; margin-bottom: 10px; font-size: 14px;
}
.hist-row .hscore { font-weight: 800; color: var(--primary); min-width: 64px; font-size: 17px; }
.hist-row .hmeta { color: var(--text-dim); font-size: 12.5px; }
.hist-bar { flex: 1; height: 8px; background: #e2e8f0; border-radius: 999px; overflow: hidden; }
.hist-bar span { display: block; height: 100%; border-radius: 999px; background: var(--primary); }
.empty {
  text-align: center; color: var(--text-dim); padding: 48px 20px;
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
}
.empty .big { font-size: 40px; margin-bottom: 8px; }

/* ===== 页脚 / 杂项 ===== */
.footer { text-align: center; padding: 24px 16px 36px; font-size: 12.5px; color: var(--text-dim); }
.footer .dim { opacity: .7; margin-top: 4px; }
.toast {
  position: fixed; left: 50%; bottom: 32px; transform: translateX(-50%);
  background: #1e293b; color: #fff; padding: 10px 22px; border-radius: 999px;
  font-size: 14px; z-index: 100; box-shadow: 0 4px 20px rgba(0,0,0,.25);
}
.toast.hidden { display: none; }
.check-line { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text-dim); cursor: pointer; }
.check-line input { width: 16px; height: 16px; accent-color: var(--primary); }

@media (max-width: 640px) {
  .stat-row { grid-template-columns: repeat(2, 1fr); }
  .palette { grid-template-columns: repeat(7, 1fr); }
  .hero h1 { font-size: 21px; }
  .q-text { font-size: 16px; }
  .card { padding: 18px; }
  .topbar-inner { justify-content: center; }
}
