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

:root {
  --accent: #6C4BF4;
  --accent-soft: #efeaff;
  --ink: #1b1a22;
  --ink-2: #494657;
  --ink-3: #8b8798;
  --line: #e9e6f2;
  --bg: #faf9fe;
  --panel: #ffffff;
  --radius: 14px;
  --st-none: #a8a4b5;
  --st-study: #6C4BF4;
  --st-known: #16a34a;
  --st-review: #ea580c;
}

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.65 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
  -webkit-text-size-adjust: 100%;
}

.hidden { display: none !important; }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  background: linear-gradient(135deg, #fff 0%, #f7f4ff 100%);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo {
  width: 34px; height: 34px; flex: 0 0 auto;
  display: grid; place-items: center;
  border-radius: 10px; color: #fff; font-weight: 700; font-size: 18px;
  background: linear-gradient(135deg, #6C4BF4 0%, #a855f7 55%, #f06595 100%);
}
.brand-text { min-width: 0; }
.brand-name { font-size: 16px; font-weight: 700; letter-spacing: 0.3px; }
.brand-sub { font-size: 11.5px; color: var(--ink-3); }

.icon-btn {
  margin-left: auto;
  width: 38px; height: 38px; border-radius: 50%;
  border: 1px solid var(--line); background: #fff; color: var(--ink-2);
  font-size: 24px; line-height: 1; padding: 0 0 4px;
}
.icon-btn:active { background: var(--accent-soft); }

/* ---------- 搜索 ---------- */
.search-wrap {
  position: sticky; top: 55px; z-index: 19;
  padding: 8px 14px 10px;
  background: linear-gradient(#faf9fe 70%, rgba(250, 249, 254, 0));
}
#search {
  width: 100%; padding: 10px 14px;
  border: 1px solid var(--line); border-radius: 999px;
  background: #fff; font-size: 14.5px; color: var(--ink);
  outline: none;
}
#search:focus { border-color: #c9bcff; box-shadow: 0 0 0 3px #f1ecff; }

/* ---------- 列表 ---------- */
main { padding: 4px 14px 40px; }

.book {
  margin: 14px 0 6px;
  font-size: 12.5px; font-weight: 700; color: var(--ink-3);
  letter-spacing: 0.6px;
}
.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden; margin-bottom: 10px;
}
.chapter {
  display: flex; align-items: center; gap: 10px;
  padding: 13px 14px; font-size: 15px; font-weight: 600;
  border-bottom: 1px solid transparent;
}
.chapter:active { background: #f7f5ff; }
.chapter .chev { margin-left: auto; color: var(--ink-3); font-size: 13px; }
.chapter .num {
  font-size: 11.5px; color: var(--accent); background: var(--accent-soft);
  border-radius: 999px; padding: 1px 8px; font-weight: 600;
}

.nodes { border-top: 1px solid var(--line); }
.node-row {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px 12px 16px; font-size: 14.5px; color: var(--ink-2);
  border-bottom: 1px solid #f4f2fa;
}
.node-row:last-child { border-bottom: 0; }
.node-row:active { background: #faf8ff; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; background: var(--st-none); }
.dot.在学 { background: var(--st-study); }
.dot.已会 { background: var(--st-known); }
.dot.待复习 { background: var(--st-review); }
.node-row .t { flex: 1 1 auto; min-width: 0; }
.node-row .mk { font-size: 11px; color: #c2410c; background: #fff3e8; border-radius: 6px; padding: 1px 6px; }

.empty { padding: 40px 10px; text-align: center; color: var(--ink-3); font-size: 14px; }

/* ---------- 详情 ---------- */
.article { padding: 6px 16px 30px; background: var(--bg); }
.crumb { font-size: 12px; color: var(--ink-3); margin: 6px 0 4px; }
.article h1 { font-size: 22px; line-height: 1.35; margin: 4px 0 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 14px; }
.chip {
  font-size: 11.5px; padding: 2px 9px; border-radius: 999px;
  background: #f3f0ff; color: #5b45c9;
}
.chip.st { background: #f1f0f5; color: #6b6678; }
.chip.st.在学 { background: #efeaff; color: #5b3fd6; }
.chip.st.已会 { background: #e7f8ee; color: #15803d; }
.chip.st.待复习 { background: #fff2e6; color: #c2410c; }
.chip.mk { background: #fff1e6; color: #b45309; }

.article h2 { font-size: 17px; margin: 22px 0 8px; padding-left: 10px; border-left: 3px solid var(--accent); line-height: 1.3; }
.article h3 { font-size: 15.5px; margin: 18px 0 6px; }
.article p { margin: 9px 0; }
.article ul, .article ol { margin: 8px 0; padding-left: 22px; }
.article li { margin: 5px 0; }
.article strong { color: #2a2438; }
.article blockquote {
  margin: 12px 0; padding: 10px 12px; background: #fff8ef;
  border-left: 3px solid #f0b978; border-radius: 8px; color: #5b4a35; font-size: 14px;
}
.article code { background: #f4f2fa; padding: 1px 5px; border-radius: 5px; font-size: 13px; }
.article table { width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 13.5px; display: block; overflow-x: auto; }
.article th, .article td { border: 1px solid var(--line); padding: 6px 8px; text-align: left; }
.article th { background: #f8f6ff; }
.article .katex { font-size: 1.02em; }
.article .katex-display { overflow-x: auto; overflow-y: hidden; padding: 4px 0; }
.src { margin-top: 22px; padding-top: 12px; border-top: 1px dashed var(--line); font-size: 12px; color: var(--ink-3); }

.pager { display: flex; gap: 10px; margin-top: 18px; }
.pager button {
  flex: 1 1 0; padding: 11px 10px; font-size: 13.5px;
  border: 1px solid var(--line); border-radius: 12px; background: #fff; color: var(--ink-2);
}
.pager button:disabled { opacity: 0.45; }

.foot {
  padding: 10px 16px calc(16px + env(safe-area-inset-bottom));
  font-size: 11.5px; color: var(--ink-3); text-align: center;
}
