:root {
  --bg: #f7f6f3; --card: #ffffff; --fg: #1d1d1f; --muted: #6e6e73; --line: #e5e3de;
  --accent: #2f6f5e; --accent-weak: #e3efe9; --warn: #a15c07; --danger: #b3261e;
  --hl: #fff1a8; --radius: 12px; --tab-h: 58px;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #16171a; --card: #1f2024; --fg: #ececf0; --muted: #9a9aa3; --line: #2d2e33;
    --accent: #6fbfa4; --accent-weak: #1f3530; --warn: #e0a84a; --danger: #ef7b72; --hl: #5a4d12; }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--fg); -webkit-text-size-adjust: 100%; }
body { font-size: 16px; line-height: 1.6; }
a { color: var(--accent); text-decoration: none; }
button, input, textarea, select { font: inherit; color: inherit; }
button { white-space: nowrap; cursor: pointer; border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 8px 14px; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); padding: 6px 8px; }
button.danger { color: var(--danger); }
button:disabled { opacity: .5; cursor: default; }
input[type=text], input[type=password], input[type=search], input[type=url], textarea, select {
  width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 10px 12px; outline: none; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 96px; }

/* ---------- 布局：移动端底部标签栏；宽屏左侧栏 ---------- */
#view { padding: 12px 16px calc(var(--tab-h) + 24px + env(safe-area-inset-bottom)); max-width: 820px; margin: 0 auto; min-height: 100vh; }
.nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom); height: calc(var(--tab-h) + env(safe-area-inset-bottom)); }
.nav .brand { display: none; }
.nav a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--muted); font-size: 11px; gap: 2px; }
.nav a .ic { font-size: 20px; line-height: 1; filter: grayscale(1); opacity: .7; }
.nav a.on { color: var(--accent); }
.nav a.on .ic { filter: none; opacity: 1; }
@media (min-width: 900px) {
  .nav { top: 0; right: auto; width: 180px; height: auto; flex-direction: column; border-top: 0; border-right: 1px solid var(--line); padding: 16px 10px; gap: 4px; }
  .nav .brand { display: block; font-weight: 700; font-size: 18px; padding: 4px 12px 16px; }
  .nav a { flex: 0; flex-direction: row; justify-content: flex-start; gap: 10px; font-size: 15px; padding: 10px 12px; border-radius: 10px; }
  .nav a.on { background: var(--accent-weak); }
  #view { margin-left: 180px; margin-right: auto; padding: 24px 40px 60px; max-width: 900px; }
  .composer { left: 180px !important; }
}

h1 { font-size: 22px; margin: 4px 0 12px; }
h2 { font-size: 17px; margin: 20px 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin: 10px 0; }
.card.tap { cursor: pointer; }
.card.tap:active { background: var(--accent-weak); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { font-size: 12px; padding: 2px 9px; border-radius: 99px; background: var(--accent-weak); color: var(--accent); border: 0; }
.chip.on { background: var(--accent); color: #fff; }
.chip.plain { background: transparent; border: 1px solid var(--line); color: var(--muted); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.stat b { display: block; font-size: 24px; }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }
mark { background: var(--hl); color: inherit; border-radius: 3px; padding: 0 1px; }
.seg { display: flex; background: var(--line); border-radius: 10px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 7px; }
.seg button.on { background: var(--card); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
label.check { display: flex; gap: 8px; align-items: center; font-size: 14px; }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status-dot.ok { background: var(--accent); } .status-dot.run { background: var(--warn); } .status-dot.err { background: var(--danger); }

/* ---------- 正文 ---------- */
.md { word-wrap: break-word; overflow-wrap: anywhere; }
.md h1 { font-size: 20px; } .md h2 { font-size: 17px; border-bottom: 1px solid var(--line); padding-bottom: 4px; } .md h3 { font-size: 16px; }
.md table { border-collapse: collapse; display: block; overflow-x: auto; font-size: 14px; }
.md th, .md td { border: 1px solid var(--line); padding: 4px 6px; min-width: 4.2em; font-variant-numeric: tabular-nums; } /* 窄屏不把 49.4 拆成两行；列多时表格内横向滚动 */
.md tr > :first-child { min-width: 7em; }
.md pre { overflow-x: auto; background: var(--bg); padding: 10px; border-radius: 8px; }
.md blockquote { margin: 8px 0; padding: 4px 12px; border-left: 3px solid var(--accent); color: var(--muted); }
.md p { margin: 8px 0; } .md ul, .md ol { padding-left: 22px; }
sup.cite { cursor: pointer; color: var(--accent); font-weight: 600; font-size: 11px; padding: 0 1px; }

/* ---------- 问答 ---------- */
.thread { display: flex; flex-direction: column; gap: 10px; padding-bottom: 110px; }
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; border-radius: 16px 16px 4px 16px; padding: 8px 14px; max-width: 85%; white-space: pre-wrap; }
.msg.bot { background: var(--card); border: 1px solid var(--line); border-radius: 16px 16px 16px 4px; padding: 10px 14px; }
.msg.bot .srcs { margin-top: 8px; border-top: 1px dashed var(--line); padding-top: 6px; font-size: 13px; }
.msg.bot .srcs div { cursor: pointer; padding: 2px 0; color: var(--muted); }
.msg.bot .acts { margin-top: 6px; display: flex; gap: 4px; flex-wrap: wrap; }
.composer { position: fixed; left: 0; right: 0; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom)); z-index: 15; background: var(--bg); padding: 8px 16px; border-top: 1px solid var(--line); }
.composer .inner { max-width: 820px; margin: 0 auto; display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { min-height: 44px; max-height: 140px; }
@media (min-width: 900px) { .composer { bottom: 0; } .thread { padding-bottom: 100px; } }
.typing::after { content: '▍'; animation: blink 1s steps(1) infinite; } @keyframes blink { 50% { opacity: 0; } }

/* ---------- 底部弹层 / 提示 ---------- */
.sheet { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.35); display: flex; align-items: flex-end; justify-content: center; }
.sheet-card { background: var(--card); width: 100%; max-width: 640px; max-height: 80vh; overflow: auto; border-radius: 16px 16px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); position: relative; }
@media (min-width: 900px) { .sheet { align-items: center; } .sheet-card { border-radius: 16px; } }
.sheet-x { position: absolute; right: 8px; top: 6px; border: 0; background: transparent; font-size: 24px; color: var(--muted); }
.toast { position: fixed; left: 50%; bottom: calc(var(--tab-h) + 20px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 60;
  background: var(--fg); color: var(--bg); padding: 8px 16px; border-radius: 99px; font-size: 14px; max-width: 90vw; }

/* ---------- 知识层（LLM Wiki） ---------- */
.badge { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 6px; vertical-align: 2px; background: var(--line); color: var(--muted); }
.badge.wiki { background: var(--accent-weak); color: var(--accent); }
.badge.new { background: #e7eefb; color: #2856a3; }
@media (prefers-color-scheme: dark) { .badge.new { background: #1e2c45; color: #8fb3f0; } }
.chip.warn { background: #fdf0dc; color: var(--warn); }
@media (prefers-color-scheme: dark) { .chip.warn { background: #3a2c14; } }
a.redlink { color: var(--danger); text-decoration: underline dotted; }
.pinned { border-left: 3px solid var(--warn); background: color-mix(in srgb, var(--warn) 8%, transparent); padding: 2px 10px; margin: 8px 0; border-radius: 0 6px 6px 0; }
.pinned::before { content: '📌 已钉住'; display: block; font-size: 11px; color: var(--warn); }
details > summary { cursor: pointer; }
.overview .md { margin-top: 6px; }
.diff { font-family: ui-monospace, Menlo, monospace; font-size: 12px; line-height: 1.5; margin-top: 8px; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.diff div { padding: 1px 8px; white-space: pre-wrap; word-break: break-all; }
.d-add { background: color-mix(in srgb, #2e9d57 16%, transparent); }
.d-add::before { content: '+ '; color: #2e9d57; }
.d-del { background: color-mix(in srgb, var(--danger) 14%, transparent); text-decoration: line-through; opacity: .8; }
.d-del::before { content: '− '; color: var(--danger); }
.d-same { color: var(--muted); }
.d-gap { text-align: center; color: var(--muted); background: var(--bg); }
button.small { padding: 4px 10px; font-size: 13px; }
sup.sref { font-size: 10px; margin: 0 1px; } sup.sref a { color: var(--muted); background: var(--line); border-radius: 4px; padding: 0 4px; }

.composer .modes { max-width: 820px; margin: 0 auto 6px; display: flex; gap: 6px; align-items: center; }
.composer .modes .chip { cursor: pointer; }
.msg.bot .steps { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.msg.bot .steps div::before { content: '· '; }
table.usage { border-collapse: collapse; width: 100%; font-size: 12px; }
table.usage th, table.usage td { text-align: left; padding: 3px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.usage-wrap { overflow-x: auto; }
.thread { padding-bottom: 140px; }

/* 分类树（领域 → 主题 → 页） */
.tree { margin-top: 10px; }
.tnode { border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); margin: 8px 0; }
.tnode .tnode { border: 0; border-left: 2px solid var(--accent-weak); border-radius: 0; margin: 2px 0 2px 4px; background: transparent; }
.tnode > summary { display: flex; align-items: center; gap: 8px; padding: 10px 12px; list-style: none; font-weight: 600; }
.tnode > summary::-webkit-details-marker { display: none; }
.tnode > summary::before { content: '▸'; color: var(--muted); font-size: 12px; transition: transform .15s; }
.tnode[open] > summary::before { transform: rotate(90deg); }
.tnode.d1 > summary, .tnode.d2 > summary { font-weight: 500; padding: 7px 10px; }
.tnode.unc > summary { color: var(--muted); }
.tkids { padding: 0 8px 6px 14px; }
.tl { display: flex; align-items: center; gap: 8px; padding: 7px 4px; color: inherit; border-top: 1px solid var(--line); min-height: 36px; }
.tl:active { background: var(--accent-weak); }
.hublink { padding: 0 6px; font-size: 18px; line-height: 1; color: var(--accent); }
.crumbs { margin: 6px 0 -4px; display: flex; flex-wrap: wrap; gap: 4px 12px; }

/* 回顾：复习卡 */
.rcard .q { font-size: 18px; font-weight: 600; margin: 10px 0; line-height: 1.5; }
.rcard .ans { border-top: 1px dashed var(--line); padding-top: 8px; margin-bottom: 10px; }
.rate { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.rate button { padding: 10px 0; }
button.wide { width: 100%; padding: 10px; margin-top: 4px; }
.row select { width: auto; }
/* 成长：近 8 周柱状 */
.bars { display: flex; align-items: flex-end; gap: 6px; height: 110px; margin-top: 8px; }
.bar { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: stretch; height: 100%; }
.bar .b1 { background: var(--accent); border-radius: 3px 3px 0 0; }
.bar .b2 { background: var(--accent-weak); }
.bar span { font-size: 10px; color: var(--muted); text-align: center; margin-top: 3px; }
/* 信息流 */
.feedlink { display: flex; gap: 10px; align-items: center; color: inherit; }
.score { flex: none; min-width: 26px; height: 22px; line-height: 22px; text-align: center; border-radius: 6px; font-size: 13px; font-weight: 700; background: var(--line); color: var(--muted); margin-top: 1px; }
.score.s9, .score.s10 { background: var(--accent); color: #fff; }
.score.s7, .score.s8 { background: var(--accent-weak); color: var(--accent); }
.feeditem a b { word-break: break-word; }
/* 正文图片（来源页「原文图片」等） */
.md img { max-width: 100%; height: auto; border-radius: 6px; display: block; margin: 8px 0; }
.md.reader { font-size: 16px; line-height: 1.8; }
.badge.track { background: #fdf0dc; color: var(--warn); }
.preset { padding: 5px 0; border-top: 1px solid var(--line); align-items: center; }
#presets h3 { margin: 12px 0 4px; font-size: 14px; }
.prog { height: 6px; background: var(--line); border-radius: 3px; margin: 6px 0; overflow: hidden; }
.prog i { display: block; height: 100%; background: var(--accent); }
