/* ===== 主题变量 ===== */
:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --brand: #2563eb;
  --brand-soft: #dbeafe;
  --danger: #dc2626;
  --ok: #16a34a;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .06);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --bg: #0b1020;
    --card: #151b2e;
    --text: #e8ebf2;
    --muted: #9aa3b5;
    --line: #26304a;
    --brand: #60a5fa;
    --brand-soft: #1e3a8a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
  }
}
:root[data-theme="dark"] {
  --bg: #0b1020;
  --card: #151b2e;
  --text: #e8ebf2;
  --muted: #9aa3b5;
  --line: #26304a;
  --brand: #60a5fa;
  --brand-soft: #1e3a8a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
}

/* ===== 基础 ===== */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  overscroll-behavior-y: contain;
}

/* ===== 顶栏 ===== */
.app-bar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: calc(var(--safe-top) + 10px) 16px 10px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--line);
}
.app-bar h1 { flex: 1; margin: 0; font-size: 19px; font-weight: 650; letter-spacing: .2px; }
.icon-btn {
  border: 0; background: transparent; color: var(--text);
  font-size: 20px; line-height: 1; padding: 8px 10px; border-radius: 12px; cursor: pointer;
}
.icon-btn:active { background: var(--line); }

/* ===== 内容区 ===== */
.view {
  flex: 1;
  padding: 16px 16px calc(96px + var(--safe-bottom));
  max-width: 720px; width: 100%; margin: 0 auto;
}
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 14px;
}
.card h2 { margin: 0 0 10px; font-size: 16px; font-weight: 650; }
.muted { color: var(--muted); font-size: 14px; }
.empty { text-align: center; color: var(--muted); padding: 48px 16px; }
.empty .big { font-size: 44px; margin-bottom: 8px; }

/* ===== 列表 ===== */
.list { list-style: none; margin: 0; padding: 0; }
.list li {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 4px; border-bottom: 1px solid var(--line);
}
.list li:last-child { border-bottom: 0; }
.list .grow { flex: 1; min-width: 0; }
.list .grow .t { display: block; font-weight: 550; }
.list .grow .s { color: var(--muted); font-size: 13px; }

/* ===== 控件 ===== */
input, textarea, select, button { font: inherit; color: inherit; }
input:not([type="range"]):not([type="file"]):not([type="checkbox"]):not([type="radio"]):not([type="submit"]),
textarea, select {
  width: 100%; padding: 12px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--brand); }
textarea { resize: vertical; min-height: 84px; }
.row { display: flex; gap: 10px; align-items: center; }
.row > * { flex: 1; }
.row .fixed { flex: 0 0 auto; }
.btn {
  border: 0; border-radius: 12px; padding: 13px 16px; font-weight: 600;
  background: var(--brand); color: #fff; cursor: pointer;
}
.btn:active { transform: scale(.985); }
.btn.ghost { background: var(--brand-soft); color: var(--brand); }
.btn.danger { background: transparent; color: var(--danger); padding: 10px 12px; }
.btn:disabled { opacity: .5; }
.chip {
  border: 1px solid var(--line); background: var(--card); color: var(--muted);
  padding: 6px 12px; border-radius: 999px; font-size: 13px; cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: #fff; }

/* ===== 底部导航 ===== */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: space-around; align-items: stretch;
  padding: 6px 8px calc(6px + var(--safe-bottom));
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: saturate(160%) blur(14px);
  border-top: 1px solid var(--line);
}
.tabbar button {
  flex: 1; border: 0; background: transparent; color: var(--muted);
  padding: 6px 4px; border-radius: 12px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 11px;
}
.tabbar button .i { font-size: 20px; line-height: 1.1; }
.tabbar button[aria-current="page"] { color: var(--brand); font-weight: 600; }

/* ===== Toast ===== */
.toast {
  position: fixed; left: 50%; bottom: calc(88px + var(--safe-bottom));
  transform: translate(-50%, 12px);
  background: rgba(17, 24, 39, .92); color: #fff;
  padding: 10px 16px; border-radius: 12px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: .22s ease; z-index: 40;
  max-width: 84vw; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ===== 通用小件 ===== */
.hidden { display: none !important; }
.mt { margin-top: 10px; }
.sm { font-size: 14px; }
.center { text-align: center; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 14px; }
.lbl { display: block; margin: 12px 0 6px; font-size: 13px; color: var(--muted); }
.wide { display: block; width: 100%; margin-bottom: 10px; }
.btn.sm { padding: 8px 12px; font-size: 14px; }
.link {
  border: 0; background: none; color: var(--brand); cursor: pointer;
  padding: 2px 4px; font-size: 14px; text-decoration: underline;
}
.link.danger { color: var(--danger); }
code {
  background: var(--brand-soft); color: var(--brand);
  padding: 1px 5px; border-radius: 6px; font-size: 13px;
}
.card.tight { padding: 12px; }
.card h2 { display: flex; align-items: center; gap: 8px; }

/* ===== 统计条 ===== */
.stats { display: flex; gap: 10px; margin-bottom: 14px; }
.stat {
  flex: 1; background: var(--card); border: 1px solid var(--line);
  border-radius: 14px; padding: 12px 8px; text-align: center; box-shadow: var(--shadow);
}
.stat b { display: block; font-size: 22px; line-height: 1.2; }
.stat span { font-size: 12px; color: var(--muted); }

/* ===== 选图 ===== */
.pick { cursor: pointer; }
.pick-empty {
  border: 2px dashed var(--line); border-radius: var(--radius);
  padding: 28px 16px; text-align: center; color: var(--text);
}
.pick-empty .big { font-size: 40px; }
.preview { width: 100%; border-radius: 12px; display: block; }
.preview.sm { max-height: 220px; object-fit: contain; background: #fff; }
.preview-math {
  margin-top: 10px; padding: 10px 12px; border-radius: 12px;
  background: var(--bg); border: 1px dashed var(--line); overflow-x: auto;
}
details.more { margin-top: 10px; }
details.more summary { color: var(--brand); font-size: 14px; cursor: pointer; }

/* ===== 章节 / 考点 ===== */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip.static { cursor: default; color: var(--brand); border-color: var(--brand-soft); }

/* ===== 步骤编辑 ===== */
.step-edit { border: 1px solid var(--line); border-radius: 12px; padding: 10px; margin-bottom: 10px; }
.step-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.badge {
  background: var(--brand-soft); color: var(--brand);
  padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600;
}
.step-edit input, .step-edit textarea { margin-bottom: 8px; }
.step-edit textarea { min-height: 60px; }

/* ===== 错题卡片 ===== */
.qcard {
  display: flex; gap: 12px; align-items: flex-start;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 12px; margin-bottom: 10px; cursor: pointer;
}
.qcard:active { transform: scale(.995); }
.qcard.slim { align-items: center; }
.qthumb {
  width: 62px; height: 62px; flex: 0 0 auto; object-fit: cover;
  border-radius: 10px; background: var(--bg); border: 1px solid var(--line);
}
.qthumb.ph {
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; color: var(--brand);
}
.qbody { flex: 1; min-width: 0; }
.qstem {
  font-size: 15px; line-height: 1.45; margin-bottom: 6px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.qmeta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.tag {
  font-size: 11px; color: var(--muted); background: var(--bg);
  border: 1px solid var(--line); border-radius: 999px; padding: 2px 8px;
}
.tag.warn { color: #b45309; border-color: #fcd34d; background: #fef3c7; }
.tag.hot { color: #b91c1c; border-color: #fca5a5; background: #fee2e2; }
:root[data-theme="dark"] .tag.warn { background: #422006; color: #fbbf24; border-color: #78350f; }
:root[data-theme="dark"] .tag.hot { background: #450a0a; color: #f87171; border-color: #7f1d1d; }
.dots { display: flex; align-items: center; gap: 4px; margin-top: 6px; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--line); }
.dots i.on { background: var(--ok); }
.dots .muted { margin-left: 6px; font-size: 12px; }
.go { color: var(--brand); font-size: 14px; }
.filter-tag { font-size: 13px; color: var(--muted); }

/* ===== 知识树 ===== */
.tree-sec { padding: 0; overflow: hidden; }
.sec-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px; cursor: pointer; background: var(--card);
}
.sec-icon {
  width: 30px; height: 30px; border-radius: 9px; background: var(--brand-soft);
  color: var(--brand); display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 700;
}
.sec-head b { flex: 1; }
.arrow { color: var(--muted); }
.count {
  font-size: 12px; color: var(--muted); background: var(--bg);
  border: 1px solid var(--line); border-radius: 999px; padding: 2px 9px;
}
.chapter { border-top: 1px solid var(--line); }
.chapter-head {
  display: flex; align-items: center; gap: 8px;
  padding: 11px 14px 8px; cursor: pointer;
}
.chapter-head b { flex: 0 1 auto; font-size: 14px; font-weight: 600; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line); flex: 0 0 auto; }
.dot.has { background: var(--brand); }
.points { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 14px 12px 30px; }
.point {
  font-size: 12px; color: var(--muted);
  border: 1px solid var(--line); border-radius: 8px; padding: 3px 8px;
}
.point.has { color: var(--brand); border-color: var(--brand); background: var(--brand-soft); }
.point i { font-style: normal; margin-left: 4px; font-weight: 700; }

/* ===== 详情 ===== */
.hl {
  background: var(--brand-soft); color: var(--text);
  border-left: 3px solid var(--brand); border-radius: 8px; padding: 10px 12px;
}
.stem { font-size: 16px; line-height: 1.7; overflow-x: auto; }
.step { padding: 10px 0; border-bottom: 1px dashed var(--line); }
.step:last-of-type { border-bottom: 0; }
.step-title { font-weight: 650; display: flex; gap: 8px; align-items: baseline; }
.step-title .num {
  background: var(--brand); color: #fff; border-radius: 50%;
  width: 20px; height: 20px; font-size: 12px; display: inline-flex;
  align-items: center; justify-content: center; flex: 0 0 auto;
}
.step-detail { color: var(--text); font-size: 14.5px; margin-top: 6px; padding-left: 28px; line-height: 1.6; }
.answer {
  margin-top: 12px; padding: 12px; border-radius: 12px;
  background: var(--bg); border: 1px solid var(--line);
}
.answer b, .pitfalls b { display: block; margin-bottom: 6px; font-size: 14px; }
.pitfalls { margin-top: 12px; }
.pitfalls ul { margin: 0; padding-left: 20px; font-size: 14px; line-height: 1.7; }
.answer-mask {
  text-align: center; padding: 20px 12px; border: 2px dashed var(--line); border-radius: 12px;
}
.answer-mask .btn { margin-top: 12px; }
.howto { margin: 0; padding-left: 20px; font-size: 14px; line-height: 1.8; }

/* ===== 状态块 ===== */
.status { padding: 10px 12px; border-radius: 12px; font-size: 14px; margin-bottom: 8px; }
.status.ok { background: rgba(22, 163, 74, .12); color: #15803d; }
.status.bad { background: rgba(220, 38, 38, .1); color: var(--danger); }

/* ===== 覆盖层 ===== */
.modal {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(8, 12, 22, .5); backdrop-filter: blur(3px);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 16px;
}
.sheet {
  background: var(--card); border-radius: 20px; padding: 20px;
  width: 100%; max-width: 520px; max-height: 86vh; overflow: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .35);
}
.sheet.center { text-align: center; }
.spinner {
  width: 38px; height: 38px; margin: 8px auto 14px;
  border: 3px solid var(--line); border-top-color: var(--brand);
  border-radius: 50%; animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.busy-text { font-weight: 650; margin-bottom: 4px; }
.err {
  background: rgba(220, 38, 38, .08); color: var(--danger);
  border-radius: 10px; padding: 10px 12px; font-size: 14px;
  word-break: break-word;
}
.zoom {
  width: 100%; max-width: 720px; max-height: 90vh;
  display: flex; flex-direction: column; gap: 10px; align-items: center;
}
.zoom img { max-width: 100%; max-height: 78vh; border-radius: 12px; background: #fff; }

/* ===== 输入范围 ===== */
input[type="range"] { width: 100%; accent-color: var(--brand); }
input[type="search"] { -webkit-appearance: none; }

/* ===== 拍照后裁剪 ===== */
.crop-sheet { max-width: 620px; }
.crop-stage {
  position: relative; margin: 12px auto 6px; overflow: hidden;
  border-radius: 10px; background: #000;
  touch-action: none; user-select: none; -webkit-user-select: none;
}
.crop-stage img { display: block; pointer-events: none; }
.crop-box {
  position: absolute; left: 0; top: 0; box-sizing: border-box;
  border: 2px solid #fff; border-radius: 4px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, .5);
  touch-action: none; cursor: move;
}
.crop-box .h {
  position: absolute; width: 24px; height: 24px; background: #fff;
  border-radius: 5px; box-shadow: 0 1px 4px rgba(0, 0, 0, .45);
}
.crop-box .h.tl { left: -12px; top: -12px; cursor: nwse-resize; }
.crop-box .h.tr { right: -12px; top: -12px; cursor: nesw-resize; }
.crop-box .h.bl { left: -12px; bottom: -12px; cursor: nesw-resize; }
.crop-box .h.br { right: -12px; bottom: -12px; cursor: nwse-resize; }
.crop-sheet .row .btn { flex: 1; }

/* ===== 答案对照 ===== */
.ans-row {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  background: var(--bg); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px 12px; margin-bottom: 4px;
}
.ans-row b { font-size: 16px; }
.ok-line {
  background: rgba(22, 163, 74, .12); color: #15803d;
  border-radius: 10px; padding: 8px 12px; font-size: 13.5px;
}
.bad-line {
  background: rgba(217, 119, 6, .14); color: #b45309;
  border-radius: 10px; padding: 8px 12px; font-size: 13.5px;
}
:root[data-theme="dark"] .ok-line { color: #4ade80; }
:root[data-theme="dark"] .bad-line { color: #fbbf24; }

/* ===== 真题参考 ===== */
.ref-item {
  border-top: 1px solid var(--line); padding: 10px 0;
}
.ref-item:first-of-type { border-top: 0; padding-top: 6px; }

/* ===== 更新日志（折叠） ===== */details.log summary { cursor: pointer; color: var(--brand); font-size: 14px; padding: 4px 0; }
details.log summary::marker { color: var(--muted); }
details.log[open] summary { margin-bottom: 10px; }
.log-entry { border-top: 1px solid var(--line); padding: 10px 0; }
.log-entry:first-child { border-top: 0; padding-top: 0; }
.log-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.log-head b { font-size: 15px; }
.log-entry ul { margin: 0; padding-left: 20px; font-size: 13.5px; line-height: 1.75; }
.log-entry li { margin-bottom: 2px; }


