*, *::before, *::after { box-sizing: border-box; }

:root {
  --ink: #1F1F1D;
  --ink2: #4A4A46;
  --muted: #8A8780;
  --line: #E9E7DF;
  --line2: #F2F0E9;
  --bg: #FAF9F5;
  --card: #FFFFFF;
  --accent: #534AB7;
  --accent-soft: #EEEDFE;
  --accent-line: #D6D2F5;
  --ok: #2F7A3D;
  --ok-soft: #E8F5E9;
  --bad: #C0392B;
  --bad-soft: #FDECEA;
  --warn: #9A6B00;
  --warn-soft: #FDF3DC;
  --radius: 14px;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button, input, textarea, select { font-family: inherit; font-size: 100%; }
button { cursor: pointer; border: none; background: none; color: inherit; }

#app {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--bg);
  position: relative;
  display: flex;
  flex-direction: column;
}

.boot {
  padding: 80px 20px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

/* ---------- 通用 ---------- */
.pad { padding: 18px 18px 96px; }
.stack > * + * { margin-top: 12px; }

.h1 { font-size: 22px; font-weight: 600; letter-spacing: 0.2px; line-height: 1.4; }
.h2 { font-size: 16px; font-weight: 600; line-height: 1.4; }
.sub { font-size: 13.5px; color: var(--muted); line-height: 1.7; }
.tiny { font-size: 11.5px; color: var(--muted); letter-spacing: 0.3px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.card.flat { border-color: var(--line2); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 48px;
  padding: 0 22px;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-size: 15.5px;
  font-weight: 500;
  letter-spacing: 0.4px;
  width: 100%;
  transition: opacity 0.18s, transform 0.12s;
}
.btn:active { transform: scale(0.99); }
.btn:disabled { opacity: 0.45; }
.btn.ghost {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent-line);
}
.btn.gray {
  background: var(--card);
  color: var(--ink2);
  border: 1px solid var(--line);
}
.btn.sm { height: 40px; font-size: 14px; padding: 0 16px; width: auto; }

.input {
  width: 100%;
  height: 48px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--ink);
  font-size: 15px;
  outline: none;
  transition: border-color 0.18s;
}
.input:focus { border-color: var(--accent); }
textarea.input { height: 84px; padding: 12px 14px; line-height: 1.6; resize: none; }

.row { display: flex; gap: 10px; align-items: center; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  padding: 3px 10px;
  border-radius: 20px;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--accent-line);
  white-space: nowrap;
}
.pill.ok { background: var(--ok-soft); color: var(--ok); border-color: #C6E6CA; }
.pill.bad { background: var(--bad-soft); color: var(--bad); border-color: #F5C9C3; }
.pill.warn { background: var(--warn-soft); color: var(--warn); border-color: #EFDDA9; }
.pill.plain { background: var(--line2); color: var(--muted); border-color: transparent; }

/* ---------- 登录 ---------- */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 32px 22px;
}
.auth-logo {
  width: 46px; height: 46px;
  border-radius: 13px;
  background: var(--accent);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  margin-bottom: 20px;
}
.auth-tabs {
  display: flex;
  gap: 4px;
  background: var(--line2);
  padding: 4px;
  border-radius: 11px;
  margin-bottom: 18px;
}
.auth-tabs button {
  flex: 1;
  height: 38px;
  border-radius: 8px;
  font-size: 14px;
  color: var(--muted);
  transition: all 0.2s;
}
.auth-tabs button.on {
  background: var(--card);
  color: var(--ink);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.err { color: var(--bad); font-size: 12.5px; min-height: 18px; margin-top: 8px; }

/* ---------- 主框架 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(250, 249, 245, 0.94);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line2);
  padding: 12px 18px 10px;
}
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.topbar h1 { font-size: 16px; font-weight: 600; margin: 0; }
.stage-line {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 7px;
  font-size: 12px;
  color: var(--muted);
}
.stage-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); flex: 0 0 auto; }
.stage-dot.review { background: var(--warn); }
.stage-dot.practice { background: var(--ok); }

.main { flex: 1; }

.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-width: 520px;
  margin: 0 auto;
  background: rgba(255,255,255,0.96);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  display: flex;
  padding: 6px 0 calc(6px + env(safe-area-inset-bottom));
  z-index: 30;
}
.tabbar button {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 5px 0;
  color: var(--muted);
  font-size: 10.5px;
  transition: color 0.18s;
}
.tabbar button.on { color: var(--accent); }
.tabbar .ico { font-size: 17px; line-height: 1; }
.tabbar button.on .ico { transform: translateY(-1px); }

/* ---------- 计划 ---------- */
.hero {
  background: linear-gradient(160deg, #5B52C4 0%, #4A41A8 100%);
  color: #fff;
  border-radius: 18px;
  padding: 20px;
  position: relative;
  overflow: hidden;
}
.hero::after {
  content: "";
  position: absolute;
  right: -40px; top: -50px;
  width: 150px; height: 150px;
  border-radius: 50%;
  background: rgba(255,255,255,0.07);
}
.hero-num { font-size: 32px; font-weight: 600; line-height: 1; }
.hero-label { font-size: 12px; opacity: 0.8; margin-top: 6px; }
.hero-row { display: flex; gap: 26px; margin-top: 16px; }
.hero-bar {
  height: 4px;
  background: rgba(255,255,255,0.22);
  border-radius: 2px;
  margin-top: 16px;
  overflow: hidden;
}
.hero-bar i {
  display: block;
  height: 100%;
  background: #fff;
  border-radius: 2px;
  transition: width 0.5s ease;
}

.task {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 14px 15px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 13px;
  width: 100%;
  text-align: left;
  transition: border-color 0.18s, transform 0.12s;
}
.task:active { transform: scale(0.995); }
.task-num {
  flex: 0 0 auto;
  width: 26px; height: 26px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 12.5px; font-weight: 600;
  margin-top: 1px;
}
.task-title { font-size: 14.5px; font-weight: 500; line-height: 1.45; }
.task-meta { font-size: 11.5px; color: var(--muted); margin-top: 5px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------- 学习页 ---------- */
.study-head { padding: 16px 18px 0; }
.prose { font-size: 15px; line-height: 1.85; color: var(--ink2); }
.prose p { margin: 0 0 14px; }
.prose h4 { font-size: 15.5px; font-weight: 600; color: var(--ink); margin: 22px 0 10px; }
.prose ul, .prose ol { margin: 0 0 14px; padding-left: 20px; }
.prose li { margin-bottom: 6px; }
.prose strong { color: var(--ink); font-weight: 600; }
.prose code {
  background: var(--line2);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 13.5px;
  color: #4A3E8A;
}
.prose pre {
  background: #F7F6F1;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.7;
}
.prose pre code { background: none; padding: 0; }
.prose table { width: 100%; border-collapse: collapse; font-size: 13.5px; margin-bottom: 14px; }
.prose th, .prose td { border: 1px solid var(--line); padding: 8px 10px; text-align: left; vertical-align: top; line-height: 1.6; }
.prose th { background: #F5F4EE; font-weight: 600; white-space: nowrap; }
.prose blockquote {
  margin: 0 0 14px;
  padding: 10px 14px;
  background: var(--accent-soft);
  border-left: 3px solid var(--accent);
  border-radius: 0 8px 8px 0;
  color: #3C3489;
  font-size: 14px;
}

.q-block { border-top: 1px dashed var(--line); padding-top: 20px; margin-top: 24px; }
.q-stem { font-size: 15.5px; font-weight: 500; line-height: 1.7; color: var(--ink); margin-bottom: 14px; }
.opt {
  display: flex;
  gap: 11px;
  align-items: flex-start;
  width: 100%;
  text-align: left;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  margin-bottom: 9px;
  font-size: 14.5px;
  line-height: 1.6;
  color: var(--ink2);
  transition: all 0.18s;
}
.opt-key {
  flex: 0 0 auto;
  width: 22px; height: 22px;
  border-radius: 7px;
  background: var(--line2);
  color: var(--muted);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600;
  margin-top: 1px;
}
.opt.sel { border-color: var(--accent); background: var(--accent-soft); }
.opt.sel .opt-key { background: var(--accent); color: #fff; }
.opt.right { border-color: #9ACFA3; background: var(--ok-soft); }
.opt.right .opt-key { background: var(--ok); color: #fff; }
.opt.wrong { border-color: #EFB3AB; background: var(--bad-soft); }
.opt.wrong .opt-key { background: var(--bad); color: #fff; }
.opt:disabled { cursor: default; }

.feedback {
  border-radius: 12px;
  padding: 14px;
  margin-top: 14px;
  font-size: 14px;
  line-height: 1.75;
}
.feedback.good { background: var(--ok-soft); border: 1px solid #C6E6CA; color: #1F5A2B; }
.feedback.bad { background: var(--bad-soft); border: 1px solid #F5C9C3; color: #8E2B20; }
.feedback .fb-title { font-weight: 600; margin-bottom: 6px; display: flex; align-items: center; gap: 6px; }
.feedback .fb-explain { color: var(--ink2); }
.feedback .fb-hint { margin-bottom: 8px; padding-bottom: 8px; border-bottom: 1px dashed rgba(0,0,0,0.08); }

.sticky-actions {
  position: sticky;
  bottom: 76px;
  padding: 10px 18px;
  background: linear-gradient(to top, var(--bg) 60%, rgba(250,249,245,0));
  z-index: 10;
}

/* ---------- 错题 ---------- */
.wrong-item { border-bottom: 1px solid var(--line2); padding: 14px 0; }
.wrong-item:last-child { border-bottom: none; }
.wrong-stem { font-size: 14.5px; line-height: 1.65; color: var(--ink); }
.wrong-meta { font-size: 11.5px; color: var(--muted); margin-top: 8px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- 我的 ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat-cell {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 8px;
  text-align: center;
}
.stat-cell b { display: block; font-size: 20px; font-weight: 600; color: var(--ink); line-height: 1.2; }
.stat-cell span { font-size: 11px; color: var(--muted); }

.bar-list { margin-top: 4px; }
.bar-row { display: flex; align-items: center; gap: 10px; padding: 9px 0; }
.bar-row .name { flex: 0 0 96px; font-size: 12.5px; color: var(--ink2); line-height: 1.4; }
.bar-track { flex: 1; height: 6px; background: var(--line2); border-radius: 3px; overflow: hidden; }
.bar-track i { display: block; height: 100%; border-radius: 3px; background: var(--accent); transition: width 0.5s; }
.bar-row .rate { flex: 0 0 38px; text-align: right; font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- 摸底 ---------- */
.diag-progress {
  display: flex;
  gap: 4px;
  margin: 14px 0 20px;
}
.diag-progress i {
  flex: 1;
  height: 3px;
  border-radius: 2px;
  background: var(--line);
}
.diag-progress i.on { background: var(--accent); }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 100px;
  transform: translateX(-50%) translateY(10px);
  background: rgba(31,31,29,0.92);
  color: #fff;
  font-size: 13.5px;
  padding: 10px 18px;
  border-radius: 22px;
  opacity: 0;
  pointer-events: none;
  transition: all 0.28s;
  z-index: 99;
  max-width: 80vw;
  text-align: center;
}
.toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }

.empty {
  text-align: center;
  padding: 48px 20px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.8;
}

@media (min-width: 521px) {
  #app { border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
  .tabbar { border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
}
