:root {
  --bg: #fbfaf7; --fg: #1f1d1a; --muted: #77716a; --line: #e6e1d8; --card: #ffffff;
  --accent: #b5442e; --link: #2f5d8a; --mark: #fff1a8; --code: #f3f0ea;
  --note: #2f5d8a; --tip: #2e7d4f; --warn: #b26a00; --danger: #b5442e; --agent: #7a4fd0; --mine: #228b5e;
  --font: -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #1a1917; --fg: #e9e4da; --muted: #9b948a; --line: #34312c; --card: #22211e; --link: #8ab4e0; --mark: #5a4b12; --code: #2b2925; }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 16px/1.75 var(--font); }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }

/* 顶栏 */
.top { position: sticky; top: 0; z-index: 5; display: flex; gap: 8px; align-items: center; padding: 8px 16px; background: var(--bg); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; color: var(--fg); margin-right: 4px; white-space: nowrap; }
.search { flex: 1; min-width: 0; }
.search input, .big-search input, #quick-input, textarea, .login input[type=password] {
  width: 100%; font: inherit; color: var(--fg); background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px;
}
.btn { font: inherit; font-size: 14px; padding: 5px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--fg); cursor: pointer; white-space: nowrap; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; }
.logout { margin: 0; }

main { max-width: 1200px; margin: 0 auto; padding: 20px 16px 80px; }

/* 笔记页 */
.note { display: grid; grid-template-columns: minmax(0, 1fr) 260px; gap: 40px; }
article { min-width: 0; max-width: 820px; }
.crumbs { font-size: 13px; color: var(--muted); }
.crumbs i { font-style: normal; margin: 0 4px; opacity: .5; }
.title { margin: 4px 0 6px; font-size: 28px; line-height: 1.3; }
.summary { color: var(--muted); margin: 0 0 4px; }
.meta { font-size: 13px; color: var(--muted); display: flex; gap: 10px; flex-wrap: wrap; margin: 0 0 12px; }
.badge { padding: 0 8px; border-radius: 99px; background: var(--code); }
.badge.warn { background: #f6dfc7; color: #7a3c00; }
.badge.mine { background: #d6f0e2; color: #145c3a; }
.actions { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.hint { font-size: 13px; color: var(--muted); }
aside { position: sticky; top: 64px; align-self: start; max-height: calc(100vh - 80px); overflow: auto; font-size: 14px; }
aside h4 { margin: 0 0 6px; color: var(--muted); font-weight: 600; font-size: 13px; }
aside section { margin-bottom: 20px; }
aside ul { list-style: none; margin: 0; padding: 0; }
.outline li { display: flex; gap: 6px; align-items: baseline; line-height: 1.5; padding: 2px 0; }
.outline li a { flex: 1; color: var(--fg); }
.outline .l2 { padding-left: 10px; } .outline .l3 { padding-left: 22px; font-size: 13px; }
.ask-sec { font-size: 11px; border: 1px solid var(--line); background: transparent; color: var(--muted); border-radius: 6px; cursor: pointer; padding: 0 5px; visibility: hidden; }
.outline li:hover .ask-sec { visibility: visible; }
.backlinks li { padding: 2px 0; line-height: 1.5; }

/* 正文 */
.content h1, .content h2, .content h3, .content h4 { line-height: 1.35; margin: 1.6em 0 .6em; scroll-margin-top: 70px; }
.content h2 { font-size: 22px; border-bottom: 1px solid var(--line); padding-bottom: 4px; }
.content h3 { font-size: 18px; }
.content p, .content li { overflow-wrap: anywhere; }
.content img, .content video { max-width: 100%; height: auto; border-radius: 6px; }
.content table { border-collapse: collapse; display: block; overflow-x: auto; margin: 1em 0; font-size: 14px; line-height: 1.6; }
.content th, .content td { border: 1px solid var(--line); padding: 6px 10px; vertical-align: top; }
.content th { background: var(--code); }
.content code { font-family: var(--mono); font-size: .88em; background: var(--code); padding: 1px 5px; border-radius: 4px; }
.content pre { background: var(--code); padding: 12px 14px; border-radius: 8px; overflow-x: auto; line-height: 1.5; }
.content pre code { background: none; padding: 0; }
.content blockquote { margin: 1em 0; padding: 4px 14px; border-left: 3px solid var(--line); color: var(--muted); }
.content mark { background: var(--mark); color: inherit; padding: 0 2px; }
.content hr { border: none; border-top: 1px solid var(--line); margin: 2em 0; }
.unresolved { color: var(--muted); border-bottom: 1px dashed var(--muted); }
.wikilink { border-bottom: 1px solid transparent; }
.unsupported { color: var(--muted); font-style: italic; }

/* 标注框 */
.content .callout { --c: var(--note); color: var(--fg); border: 1px solid color-mix(in srgb, var(--c) 30%, transparent); border-left: 4px solid var(--c); background: color-mix(in srgb, var(--c) 7%, var(--card)); border-radius: 8px; padding: 8px 14px; }
.callout-title { display: block; font-weight: 600; color: var(--c); }
.callout[data-callout=tip], .callout[data-callout=success], .callout[data-callout=verified], .callout[data-callout=decided] { --c: var(--tip); }
.callout[data-callout=warning], .callout[data-callout=caution], .callout[data-callout=attention], .callout[data-callout=decide] { --c: var(--warn); }
.callout[data-callout=danger], .callout[data-callout=error], .callout[data-callout=bug] { --c: var(--danger); }
.callout[data-callout=agent] { --c: var(--agent); }
.callout[data-callout=mine] { --c: var(--mine); }
.callout[data-callout=abstract], .callout[data-callout=summary], .callout[data-callout=info] { --c: var(--note); }

/* 嵌入 */
.embed { border: 1px solid var(--line); border-radius: 8px; padding: 6px 14px; margin: 1em 0; background: var(--card); }
.embed-title { display: block; font-size: 13px; color: var(--muted); }
.embed-frame { margin: 1em 0; }
.embed-frame iframe { width: 100%; height: 70vh; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.embed-frame a { font-size: 13px; }

/* 首页、搜索 */
.big-search { max-width: 720px; margin: 10px auto 28px; }
.big-search input { font-size: 18px; padding: 12px 16px; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 40px; }
.home h3 { font-size: 14px; color: var(--muted); margin: 18px 0 6px; }
.home ul { list-style: none; padding: 0; margin: 0; }
.home li { padding: 3px 0; line-height: 1.5; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips li a { display: inline-block; padding: 2px 10px; border: 1px solid var(--line); border-radius: 99px; background: var(--card); color: var(--fg); }
.path { margin-left: 8px; font-size: 12px; color: var(--muted); }
.results ul { list-style: none; padding: 0; }
.results li { padding: 10px 0; border-bottom: 1px solid var(--line); }
.results .snippet { font-size: 14px; color: var(--muted); margin: 2px 0 0; }

/* 弹窗 */
dialog { border: 1px solid var(--line); border-radius: 12px; padding: 14px; width: min(560px, 92vw); background: var(--card); color: var(--fg); }
dialog::backdrop { background: rgba(0, 0, 0, .3); }
#quick-list { list-style: none; margin: 8px 0 0; padding: 0; max-height: 50vh; overflow: auto; }
#quick-list li a { display: block; padding: 6px 8px; border-radius: 6px; color: var(--fg); }
#quick-list li a span { display: block; font-size: 12px; color: var(--muted); }
#quick-list li.on a, #quick-list li a:hover { background: var(--code); text-decoration: none; }
#capture h3 { margin: 0 0 8px; }
#capture .from { display: block; font-size: 13px; color: var(--muted); margin: 6px 0; }
#capture .row { display: flex; gap: 8px; align-items: center; justify-content: flex-end; }
#capture-msg { flex: 1; font-size: 13px; color: var(--danger); }
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: 8px 16px; border-radius: 8px; font-size: 14px; z-index: 10; }

/* 登录 */
body.login { display: grid; place-items: center; min-height: 100vh; }
.login form { width: min(340px, 90vw); display: grid; gap: 12px; }
.login h1 { margin: 0; font-size: 22px; }
.error { color: var(--danger); margin: 0; font-size: 14px; }

/* 窄屏 */
@media (max-width: 900px) {
  .note { grid-template-columns: 1fr; }
  aside { position: static; max-height: none; border-top: 1px solid var(--line); padding-top: 16px; }
  .grid { grid-template-columns: 1fr; gap: 0; }
  .ask-sec { visibility: visible; }
}
@media (max-width: 600px) {
  body { font-size: 15px; }
  .top { padding: 6px 10px; gap: 6px; }
  .top .btn[data-action=quick], .logout { display: none; }
  main { padding: 14px 12px 60px; }
  .title { font-size: 23px; }
  .hint { display: none; }
}

/* 文件夹 */
.files { list-style: none; padding: 0; margin: 0; }
.files li { padding: 6px 0; border-bottom: 1px solid var(--line); line-height: 1.5; }
.files .f-dir a { font-weight: 600; }
.files .f-other { color: var(--muted); }
.crumbs a { color: var(--muted); }
.file-chip { display: inline-block; padding: 2px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--fg); margin: 2px 0; }

/* 预览页 */
body.wide main { max-width: none; }
.preview-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.sheet-tabs { display: flex; gap: 4px; flex-wrap: wrap; margin: 8px 0; }
.sheet-tabs button, .sheet-tabs a { font: inherit; font-size: 13px; padding: 3px 12px; border: 1px solid var(--line); border-radius: 6px; background: var(--card); color: var(--fg); cursor: pointer; }
.sheet-tabs .on { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.sheet-scroll { overflow: auto; max-height: 78vh; border: 1px solid var(--line); border-radius: 8px; }
.sheet-scroll table, .base-table { border-collapse: collapse; font-size: 13px; line-height: 1.5; }
.sheet-scroll td, .sheet-scroll th { border: 1px solid var(--line); padding: 4px 8px; vertical-align: top; min-width: 40px; max-width: 420px; }
.sheet-scroll th { position: sticky; top: 0; background: var(--code); }

/* Base */
.base-view { margin: 1em 0; }
.base-head { display: flex; gap: 8px; align-items: baseline; font-size: 13px; margin-bottom: 6px; }
.base-warn { font-size: 13px; color: var(--warn); }
.base-list { list-style: none; padding: 0; margin: 0; }
.base-list li { padding: 3px 0; }
.base-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.base-card { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--fg); font-size: 13px; }
.base-card b { font-size: 15px; }
.base-card i { font-style: normal; color: var(--muted); }
.base-group { margin: 14px 0 6px; font-size: 14px; color: var(--muted); }

/* Canvas */
.canvas-tools { display: flex; gap: 6px; align-items: center; margin: 8px 0; }
.canvas-view { position: relative; height: 78vh; overflow: hidden; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); cursor: grab; touch-action: none; }
.canvas-view.dragging { cursor: grabbing; }
.canvas-board { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.cv-edges { position: absolute; left: 0; top: 0; color: var(--muted); overflow: visible; pointer-events: none; }
.cv-elabel { font-size: 13px; fill: var(--muted); text-anchor: middle; }
.cv-node { position: absolute; overflow: auto; border-radius: 10px; font-size: 14px; line-height: 1.55; }
.cv-text, .cv-file, .cv-link { background: var(--card); border: 1px solid var(--cv, var(--line)); padding: 8px 12px; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.cv-node .cv-file { display: block; font-weight: 600; border: none; padding: 0; box-shadow: none; }
.cv-file img { max-width: 100%; }
.cv-group { border: 2px dashed var(--cv, var(--line)); background: color-mix(in srgb, var(--cv, var(--line)) 8%, transparent); }
.cv-glabel { position: absolute; top: -26px; left: 0; font-size: 14px; font-weight: 600; color: var(--cv, var(--muted)); white-space: nowrap; }
.cv-node h1, .cv-node h2, .cv-node h3 { margin: .3em 0; font-size: 1.05em; }
.cv-node p { margin: .3em 0; }

/* PDF 阅读器 */
.pdf-viewer { margin: 1em 0; border: 1px solid var(--line); border-radius: 10px; background: var(--card); }
.pdf-bar { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; padding: 6px 10px; border-bottom: 1px solid var(--line); font-size: 13px; position: sticky; top: 56px; background: var(--card); z-index: 2; border-radius: 10px 10px 0 0; }
.pdf-bar .btn { font-size: 13px; padding: 2px 10px; }
.pdf-info { margin-right: auto; color: var(--muted); }
.pdf-pages { --pdf-zoom: 1; overflow: auto; padding: 10px; display: flex; flex-direction: column; align-items: center; gap: 10px; background: color-mix(in srgb, var(--fg) 6%, var(--bg)); }
.pdf-viewer:not(.full) .pdf-pages { max-height: 75vh; }
.pdf-page { width: calc(100% * var(--pdf-zoom)); max-width: none; background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.15); flex: none; }
.pdf-page canvas { display: block; width: 100%; height: auto; }
.pdf-wait { margin: 0; padding: 24px; color: #888; font-size: 13px; text-align: center; }
