:root {
  --bg: #f4f6f5;
  --card: #ffffff;
  --ink: #1f2a2e;
  --ink-soft: #5d6b70;
  --line: #e2e7e5;
  --brand: #2f6f6a;
  --brand-soft: #e6f1ef;
  --accent: #c9622f;
  --danger: #c0392b;
  --ok: #2e8b57;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(20, 40, 40, .06), 0 6px 18px rgba(20, 40, 40, .06);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.6 -apple-system, "PingFang SC", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
}

.app { min-height: 100dvh; padding-bottom: calc(84px + var(--safe-bottom)); }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  padding: calc(var(--safe-top) + 14px) 18px 12px;
  background: var(--brand);
  color: #fff;
  display: flex; align-items: center; gap: 10px;
}
.topbar h1 { margin: 0; font-size: 19px; font-weight: 600; letter-spacing: .5px; }
.topbar .sub { margin-left: auto; font-size: 13px; opacity: .8; }
.topbar button.back {
  background: rgba(255,255,255,.16); border: 0; color: #fff;
  width: 34px; height: 34px; border-radius: 10px; font-size: 17px;
}

/* ---------- 内容区 ---------- */
.page { padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.card {
  background: var(--card); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 6px; font-size: 17px; }
.card .hint { color: var(--ink-soft); font-size: 13.5px; }

/* ---------- 首页大按钮 ---------- */
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.action {
  background: var(--card); border: 0; border-radius: var(--radius);
  padding: 20px 14px; text-align: left; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 8px; color: var(--ink);
}
.action .ico { font-size: 26px; }
.action .t { font-size: 16px; font-weight: 600; }
.action .d { font-size: 12.5px; color: var(--ink-soft); }
.action.primary { background: var(--brand); color: #fff; grid-column: 1 / -1; flex-direction: row; align-items: center; }
.action.primary .d { color: rgba(255,255,255,.85); }
.action.primary .ico { font-size: 30px; }

/* ---------- 统计 ---------- */
.stats { display: flex; gap: 10px; }
.stat { flex: 1; background: var(--card); border-radius: 12px; padding: 12px; text-align: center; box-shadow: var(--shadow); }
.stat b { display: block; font-size: 22px; color: var(--brand); }
.stat span { font-size: 12px; color: var(--ink-soft); }

/* ---------- 表单 ---------- */
label.field { display: block; margin-bottom: 12px; }
label.field span { display: block; font-size: 13px; color: var(--ink-soft); margin-bottom: 5px; }
input, select, textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 10px;
  padding: 11px 12px; font: inherit; background: #fbfcfc; color: var(--ink);
}
textarea { resize: vertical; min-height: 76px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }

.btn {
  border: 0; border-radius: 12px; padding: 13px 18px; font: inherit; font-weight: 600;
  background: var(--brand); color: #fff; width: 100%;
}
.btn.ghost { background: var(--brand-soft); color: var(--brand); }
.btn.subtle { background: #eef1f0; color: var(--ink-soft); }
.btn.danger { background: #fdecea; color: var(--danger); }
.btn:disabled { opacity: .5; }
.btn-row { display: flex; gap: 10px; }

/* ---------- 拍照 ---------- */
.shot {
  width: 100%; border: 2px dashed var(--line); border-radius: var(--radius);
  background: #fbfcfc; min-height: 210px; display: flex; align-items: center;
  justify-content: center; flex-direction: column; gap: 8px; color: var(--ink-soft);
  overflow: hidden; position: relative;
}
.shot img { width: 100%; display: block; }
.shot .ico { font-size: 34px; }

/* ---------- 错题列表 ---------- */
.qitem { display: flex; gap: 12px; align-items: flex-start; }
.qitem .no { font-size: 12px; color: var(--ink-soft); padding-top: 3px; }
.qitem .body { flex: 1; min-width: 0; }
.qitem .stem { font-size: 14.5px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 7px; }
.tag { font-size: 11.5px; padding: 2px 8px; border-radius: 999px; background: var(--brand-soft); color: var(--brand); }
.tag.warn { background: #fdf0e8; color: var(--accent); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 6px 13px; font-size: 13px; white-space: nowrap; color: var(--ink-soft); }
.chip.on { background: var(--brand); color: #fff; border-color: var(--brand); }

/* ---------- 刷题 ---------- */
.opt {
  display: flex; gap: 11px; align-items: flex-start;
  border: 1px solid var(--line); background: #fff; border-radius: 12px;
  padding: 13px; width: 100%; text-align: left; font: inherit; color: var(--ink);
}
.opt .k { font-weight: 700; color: var(--brand); min-width: 18px; }
.opt.picked { border-color: var(--brand); background: var(--brand-soft); }
.opt.right { border-color: var(--ok); background: #eaf6ef; }
.opt.wrong { border-color: var(--danger); background: #fdecea; }
.verdict { font-weight: 700; }
.verdict.ok { color: var(--ok); }
.verdict.no { color: var(--danger); }
.explain { background: #f7f9f8; border-left: 3px solid var(--brand); border-radius: 8px; padding: 12px 13px; font-size: 14.5px; white-space: pre-wrap; }

/* ---------- 知识点思维导图（树状） ---------- */
.tree { display: flex; flex-direction: column; }

.tnode {
  display: flex; align-items: center; gap: 8px; width: 100%; text-align: left;
  border: 0; background: none; font: inherit; color: var(--ink); padding: 0; cursor: pointer;
}
.tnode .label { flex: 1; min-width: 0; }

/* 单元节点 */
.unit-node {
  padding: 12px 14px; border-radius: 12px; font-weight: 600; font-size: 14.5px;
  background: var(--brand); color: #fff; margin-bottom: 2px;
}
.unit-node .cnt { font-size: 11.5px; opacity: .8; font-weight: 400; white-space: nowrap; }
.unit-node .caret { font-size: 11px; transition: transform .18s; opacity: .9; }
.unit-node.collapsed .caret { transform: rotate(-90deg); }

/* 分支（连线） */
.branch {
  margin: 2px 0 14px 15px; padding-left: 15px;
  border-left: 2px solid var(--brand-soft);
  display: flex; flex-direction: column; gap: 8px;
}
.branch[hidden] { display: none; }

/* 考点节点 */
.topic-node {
  position: relative; background: #fff; border: 1px solid var(--line);
  border-radius: 11px; padding: 11px 13px;
}
.topic-node::before {
  content: ''; position: absolute; left: -17px; top: 50%; width: 15px; height: 2px;
  background: var(--brand-soft);
}
.topic-node .n { font-size: 11.5px; color: var(--accent); white-space: nowrap; }
.topic-node .n.zero { opacity: 0; }

/* 考频徽章 */
.freq { font-size: 10.5px; padding: 1.5px 7px; border-radius: 999px; white-space: nowrap; }
.freq.high { background: #fdecea; color: #c0392b; }
.freq.mid { background: #fdf0e8; color: #c9622f; }
.freq.base { background: #eef1f0; color: #6b7a7f; }

/* ---------- 考点详情 ---------- */
.sec { margin-top: 16px; }
.sec:first-child { margin-top: 0; }
.sec > h3 { font-size: 14px; margin: 0 0 9px; display: flex; align-items: center; gap: 6px; }
.formula-list { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 7px; }
.formula-list li { background: #f7f9f8; border-left: 3px solid var(--brand); border-radius: 8px; padding: 9px 12px; font-size: 14px; }
.method { border: 1px solid var(--line); border-radius: 11px; padding: 11px 13px; margin-bottom: 8px; }
.method:last-child { margin-bottom: 0; }
.method .mname { font-weight: 600; font-size: 14.5px; margin-bottom: 6px; }
.method ol { margin: 0; padding-left: 19px; font-size: 13.8px; color: var(--ink-soft); }
.method ol li { margin-bottom: 2px; }
.traps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 7px; }
.traps li { background: #fff8ec; border-left: 3px solid #e0a13a; border-radius: 8px; padding: 9px 12px; font-size: 13.8px; color: #7a5a1e; }
.ex { border-top: 1px dashed var(--line); padding-top: 13px; margin-top: 13px; }
.ex:first-child { border-top: 0; padding-top: 0; margin-top: 0; }
.ex .q { font-size: 15px; white-space: pre-wrap; }
.ex .opt { margin: 5px 0 0 4px; color: var(--ink-soft); font-size: 14px; }
.ex .ans { margin: 9px 0 7px; font-size: 14px; }
.ex .ans b { color: var(--ok); }

/* 学科选择入口 */
.subj-entry {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  background: #fff; border: 1px solid var(--line); border-radius: 12px;
  padding: 13px; margin-bottom: 8px; font: inherit; color: var(--ink);
}
.subj-entry .n { margin-left: auto; font-size: 12px; color: var(--accent); }
.subj-entry .n.zero { color: var(--ink-soft); opacity: .6; }

/* ---------- 底部导航 ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; background: rgba(255,255,255,.96); backdrop-filter: blur(10px);
  border-top: 1px solid var(--line); padding-bottom: var(--safe-bottom);
}
.tabbar button {
  flex: 1; border: 0; background: none; padding: 9px 0 8px; color: var(--ink-soft);
  font: inherit; font-size: 11.5px; display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.tabbar button .ico { font-size: 20px; line-height: 1; }
.tabbar button.on { color: var(--brand); }

/* ---------- 空状态 ---------- */
.empty { text-align: center; color: var(--ink-soft); padding: 40px 20px; }
.empty .ico { font-size: 40px; display: block; margin-bottom: 10px; opacity: .8; }

/* ---------- 提示 ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(96px + var(--safe-bottom)); transform: translate(-50%, 12px);
  background: #24312f; color: #fff; padding: 10px 18px; border-radius: 999px;
  font-size: 14px; opacity: 0; pointer-events: none; transition: .22s; z-index: 50; max-width: 86vw; text-align: center;
}
.toast.show { opacity: .96; transform: translate(-50%, 0); }

.overlay { position: fixed; inset: 0; background: rgba(20,30,30,.35); z-index: 40; display: flex; align-items: center; justify-content: center; }
.overlay[hidden] { display: none; }
.spinner { width: 42px; height: 42px; border: 4px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.overlay .msg { position: absolute; top: 58%; color: #fff; font-size: 14px; }

.banner { background: #fff8ec; border: 1px solid #f2e2c4; color: #8a6d3b; font-size: 13px; padding: 10px 13px; border-radius: 12px; }

@media (min-width: 560px) {
  .app { max-width: 560px; margin: 0 auto; }
  .tabbar { max-width: 560px; left: 50%; transform: translateX(-50%); }
}

/* ================= 打印预览 ================= */
.print-wrap { background: #fff; min-height: 100dvh; }

.print-bar {
  position: sticky; top: 0; z-index: 30; background: #fff;
  border-bottom: 1px solid var(--line);
  padding: calc(var(--safe-top) + 12px) 16px 12px;
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
}
.print-bar .grow { flex: 1; }
.print-bar .tip { font-size: 12px; color: var(--ink-soft); width: 100%; margin-top: 2px; }
.print-bar label.toggle { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink); }
.print-bar .btn { width: auto; padding: 10px 16px; font-size: 14px; }

.print-doc { padding: 22px 18px 80px; color: #111; }
.print-doc h1 { font-size: 19px; margin: 0 0 5px; }
.print-doc .meta { font-size: 12px; color: #666; margin-bottom: 20px; }

.p-unit { margin-bottom: 20px; }
.p-unit > h2 {
  font-size: 14.5px; margin: 0 0 10px; padding-left: 9px;
  border-left: 4px solid #2f6f6a;
}
.p-topic { margin-bottom: 15px; }
.p-topic > h3 { font-size: 13.5px; margin: 0 0 6px; }
.p-topic .fq {
  font-size: 10.5px; border: 1px solid #aaa; border-radius: 3px;
  padding: 0 4px; margin-left: 6px; color: #555; font-weight: 400; vertical-align: 1px;
}
.p-blk { margin: 0 0 7px; }
.p-blk > h4 { font-size: 12px; margin: 0 0 3px; color: #444; }
.p-blk ul, .p-blk ol { margin: 0; padding-left: 17px; font-size: 12.5px; line-height: 1.6; }
.p-blk li { margin-bottom: 1px; }
.p-method { margin-bottom: 5px; }
.p-method b { font-size: 12.5px; }
.p-ex { border-top: 1px dotted #bbb; padding-top: 6px; margin-top: 6px; font-size: 12.5px; line-height: 1.6; }
.p-opt { color: #444; margin: 1px 0 1px 4px; font-size: 12.5px; line-height: 1.6; }
.p-ex .ans { font-weight: 700; margin: 3px 0; }
.p-ex .exp { color: #333; }

.p-wrong { margin-bottom: 16px; padding-bottom: 12px; border-bottom: 1px solid #e3e3e3; }
.p-wrong .hdr { font-size: 12px; color: #666; margin-bottom: 5px; }
.p-wrong .stem { font-size: 13px; line-height: 1.65; white-space: pre-wrap; }
.p-wrong img { max-width: 100%; max-height: 320px; margin: 6px 0; border: 1px solid #ddd; border-radius: 4px; }
.print-bar label.toggle span { white-space: nowrap; }

@media print {
  @page { size: A4; margin: 12mm 10mm; }
  html, body { background: #fff !important; }
  .app { padding-bottom: 0 !important; max-width: none !important; }
  .no-print, .tabbar, .topbar, .toast { display: none !important; }
  .print-doc { padding: 0; }
  .p-unit > h2 { break-after: avoid; }
  .p-topic, .p-method, .p-ex, .p-wrong { break-inside: avoid; }
  .p-unit { break-inside: auto; }
}
