/* SECTION: base —— 全局样式与设计变量 */
:root {
  --bg: #f2f4f7;
  --card: #ffffff;
  --ink: #1c2430;
  --sub: #5b6675;
  --line: #e3e8ef;
  --brand: #1f6feb;
  --brand-weak: #e8f1ff;
  --ok: #16a34a;
  --ok-weak: #e7f7ee;
  --bad: #dc2626;
  --bad-weak: #fdecec;
  --warn: #d97706;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(20, 30, 50, .08);
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg); color: var(--ink); font-size: 16px; line-height: 1.6;
}
button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select { font: inherit; }

.app { max-width: 720px; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column; }

/* SECTION: header */
.hd {
  position: sticky; top: 0; z-index: 20;
  background: var(--card); border-bottom: 1px solid var(--line);
  padding: 10px 16px; display: flex; align-items: center; gap: 10px;
}
.hd .logo { font-weight: 700; font-size: 17px; white-space: nowrap; }
.hd .logo em { color: var(--brand); font-style: normal; }
.hd .spacer { flex: 1; }
.hd .stat { font-size: 12px; color: var(--sub); text-align: right; line-height: 1.4; }
.hd-btn {
  padding: 6px 12px; border-radius: 8px; background: var(--brand-weak);
  color: var(--brand); font-size: 13px; font-weight: 600; white-space: nowrap;
}

/* SECTION: tabs (首页顶部模式切换) */
.tabs { display: flex; gap: 8px; padding: 14px 16px 0; }
.tab {
  flex: 1; padding: 12px 8px; border-radius: var(--radius); background: var(--card);
  border: 2px solid var(--line); text-align: center; font-weight: 600; color: var(--sub);
}
.tab.on { border-color: var(--brand); color: var(--brand); background: var(--brand-weak); }
.tab small { display: block; font-weight: 400; font-size: 12px; margin-top: 2px; }

/* SECTION: home cards */
.main { flex: 1; padding: 14px 16px calc(20px + env(safe-area-inset-bottom)); }
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 12px;
}
.card h3 { font-size: 15px; margin-bottom: 10px; color: var(--ink); }
.chap-list { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 480px) { .chap-list { grid-template-columns: 1fr; } }
.chap-item {
  border: 1.5px solid var(--line); border-radius: 12px; padding: 12px 14px;
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  background: var(--card); text-align: left; transition: border-color .15s;
}
.chap-item.on { border-color: var(--brand); background: var(--brand-weak); }
.chap-item .nm { font-weight: 600; font-size: 14px; }
.chap-item .ct { font-size: 12px; color: var(--sub); white-space: nowrap; }
.opt-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.pill {
  padding: 7px 14px; border-radius: 999px; border: 1.5px solid var(--line);
  font-size: 13px; color: var(--sub); background: var(--card);
}
.pill.on { border-color: var(--brand); color: var(--brand); background: var(--brand-weak); font-weight: 600; }
.big-btn {
  width: 100%; padding: 14px; border-radius: 12px; background: var(--brand);
  color: #fff; font-size: 16px; font-weight: 700; margin-top: 14px;
}
.big-btn.ghost { background: var(--card); color: var(--brand); border: 1.5px solid var(--brand); }
.progress-strip { height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; margin-top: 8px; }
.progress-strip i { display: block; height: 100%; background: var(--brand); border-radius: 4px; transition: width .2s; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 10px; }
.stat-cell { text-align: center; padding: 10px 4px; border-radius: 10px; background: var(--bg); }
.stat-cell b { display: block; font-size: 18px; }
.stat-cell span { font-size: 12px; color: var(--sub); }

/* SECTION: quiz bar */
.qz-bar {
  position: sticky; top: 45px; z-index: 15; background: var(--card);
  border-bottom: 1px solid var(--line); padding: 8px 16px;
  display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--sub);
}
.qz-bar .idx { font-weight: 700; color: var(--ink); font-size: 14px; }
.qz-bar .progress-strip { flex: 1; margin: 0; }
.qz-bar button { padding: 4px 10px; border-radius: 8px; background: var(--bg); font-size: 13px; color: var(--sub); }

/* SECTION: question card */
.q-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 16px; }
.q-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.q-tag { font-size: 11px; padding: 3px 9px; border-radius: 999px; background: var(--bg); color: var(--sub); }
.q-tag.t-single { background: #eef2ff; color: #4f46e5; }
.q-tag.t-multi { background: #fdf2f8; color: #db2777; }
.q-stem { font-size: 16.5px; line-height: 1.75; word-break: break-word; white-space: pre-wrap; }
.q-img { margin-top: 12px; }
.q-img img {
  display: block; width: 100%; max-height: 62vh; object-fit: contain;
  border: 1px solid var(--line); border-radius: 10px; background: #fafbfc; cursor: zoom-in;
}
.q-img .zoom-hint { font-size: 12px; color: var(--sub); margin-top: 4px; text-align: center; }

/* SECTION: options */
.opts { margin-top: 14px; display: flex; flex-direction: column; gap: 9px; }
.opt {
  display: flex; gap: 10px; align-items: flex-start; text-align: left;
  border: 1.5px solid var(--line); border-radius: 12px; padding: 11px 13px;
  background: var(--card); font-size: 15px; line-height: 1.6; word-break: break-word;
  transition: border-color .12s, background .12s;
}
.opt .lt {
  flex: 0 0 26px; height: 26px; border-radius: 50%; background: var(--bg);
  color: var(--sub); font-weight: 700; font-size: 13px; display: flex; align-items: center; justify-content: center;
  margin-top: 1px;
}
.opt.sel { border-color: var(--brand); background: var(--brand-weak); }
.opt.sel .lt { background: var(--brand); color: #fff; }
.opt.right { border-color: var(--ok); background: var(--ok-weak); }
.opt.right .lt { background: var(--ok); color: #fff; }
.opt.wrong { border-color: var(--bad); background: var(--bad-weak); }
.opt.wrong .lt { background: var(--bad); color: #fff; }
.opt.dim { opacity: .75; }
.reveal-note { margin-top: 12px; font-size: 14px; font-weight: 700; }
.reveal-note.ok { color: var(--ok); }
.reveal-note.bad { color: var(--bad); }
.analysis {
  margin-top: 12px; border-left: 3px solid var(--brand); background: var(--brand-weak);
  border-radius: 0 10px 10px 0; padding: 10px 12px; font-size: 14px; color: var(--ink);
  white-space: pre-wrap; word-break: break-word;
}
.analysis .an-title { font-weight: 700; color: var(--brand); font-size: 13px; margin-bottom: 3px; }
.q-actions { display: flex; gap: 10px; margin-top: 14px; }
.q-actions .big-btn { margin-top: 0; flex: 1; }
.q-actions .big-btn.sec { background: var(--card); color: var(--sub); border: 1.5px solid var(--line); }

/* SECTION: memorize */
.mem-answer {
  margin-top: 14px; border-top: 1px dashed var(--line); padding-top: 14px;
}
.mem-ans-line { font-size: 16px; font-weight: 700; color: var(--ok); }
.mem-opts { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.mem-opt { font-size: 14.5px; line-height: 1.65; color: var(--ink); padding: 2px 0; word-break: break-word; }
.mem-opt b.ok { color: var(--ok); }
.mem-hint { margin-top: 16px; text-align: center; color: var(--sub); font-size: 14px; }

/* SECTION: nav bottom */
.nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  max-width: 720px; margin: 0 auto; background: var(--card); border-top: 1px solid var(--line);
  display: flex; padding: 6px 10px calc(6px + env(safe-area-inset-bottom));
}
.nav button { flex: 1; padding: 8px 0; text-align: center; font-size: 12px; color: var(--sub); border-radius: 10px; }
.nav button.on { color: var(--brand); font-weight: 700; }
.nav button .n-i { display: block; font-size: 19px; line-height: 1.2; }
.has-nav { padding-bottom: calc(74px + env(safe-area-inset-bottom)) !important; }

/* SECTION: lightbox */
.lb {
  position: fixed; inset: 0; z-index: 99; background: rgba(10, 14, 20, .92);
  display: none; align-items: center; justify-content: center; flex-direction: column; gap: 10px;
}
.lb.show { display: flex; }
.lb img { max-width: 96vw; max-height: 82vh; object-fit: contain; border-radius: 6px; }
.lb .lb-cap { color: #cfd6e0; font-size: 13px; }
.lb .lb-close { position: absolute; top: 14px; right: 18px; color: #fff; font-size: 30px; line-height: 1; padding: 4px 10px; }

/* SECTION: toast & misc */
.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%);
  background: rgba(28, 36, 48, .92); color: #fff; padding: 9px 18px; border-radius: 999px;
  font-size: 13.5px; z-index: 120; display: none; max-width: 86vw; text-align: center;
}
.toast.show { display: block; }
.empty-tip { text-align: center; color: var(--sub); padding: 40px 20px; font-size: 14px; }
.back-row { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; color: var(--sub); font-size: 14px; }
.back-row button { color: var(--brand); font-weight: 600; }
.seg { display: flex; background: var(--bg); border-radius: 10px; padding: 3px; margin-bottom: 12px; }
.seg button { flex: 1; padding: 8px 4px; border-radius: 8px; font-size: 13.5px; color: var(--sub); text-align: center; }
.seg button.on { background: var(--card); color: var(--brand); font-weight: 700; box-shadow: var(--shadow); }
.list-item {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 12px 4px; border-bottom: 1px solid var(--line); font-size: 14.5px;
}
.list-item:last-child { border-bottom: none; }
.list-item .li-q { flex: 1; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .li-n { color: var(--sub); font-size: 12px; white-space: nowrap; }
.link-btn { color: var(--brand); font-size: 13px; padding: 4px 8px; }
.danger-link { color: var(--bad); }
