/* ============================================================
   Inkdown · 墨记 — 样式
   非线性动画:统一使用弹性/回弹缓动曲线
   ============================================================ */

:root {
  /* 缓动曲线 */
  --spring: cubic-bezier(.34, 1.56, .64, 1);      /* 回弹 */
  --swift:  cubic-bezier(.22, 1, .36, 1);          /* 快出缓停 */
  --smooth: cubic-bezier(.45, 0, .15, 1);

  --font: "PingFang SC", "Microsoft YaHei", ui-sans-serif, system-ui, "Segoe UI", sans-serif;
  --mono: "SF Mono", "JetBrains Mono", ui-monospace, "Cascadia Code", Consolas, monospace;

  --radius: 12px;
  --side-w: 272px;
}

/* ---------- 暗色主题(默认) ---------- */
:root, :root[data-theme="dark"] {
  --bg:        #0d0f14;
  --bg-side:   #12151d;
  --bg-panel:  #171b25;
  --bg-hover:  #1e2330;
  --bg-active: #262c3d;
  --line:      #262b38;
  --text:      #dde2ec;
  --text-dim:  #8b93a7;
  --text-faint:#5a6175;
  --accent:    #8b7cff;
  --accent-2:  #4fd6c5;
  --accent-soft: rgba(139, 124, 255, .16);
  --danger:    #ff6b81;
  --shadow: 0 18px 50px -12px rgba(0, 0, 0, .65);
  --code-bg:   #10131b;
  --mark-bg:   rgba(255, 214, 102, .25);
  --mark-fg:   #ffd666;
}

/* ---------- 亮色主题 ---------- */
:root[data-theme="light"] {
  --bg:        #f6f5f2;
  --bg-side:   #efede8;
  --bg-panel:  #ffffff;
  --bg-hover:  #e7e4dd;
  --bg-active: #ddd9d0;
  --line:      #e0dcd3;
  --text:      #2b2c31;
  --text-dim:  #6f7280;
  --text-faint:#a3a6b0;
  --accent:    #6a5cff;
  --accent-2:  #0aa396;
  --accent-soft: rgba(106, 92, 255, .12);
  --danger:    #e5484d;
  --shadow: 0 18px 50px -18px rgba(60, 50, 30, .35);
  --code-bg:   #f0eee9;
  --mark-bg:   rgba(255, 200, 40, .3);
  --mark-fg:   #7a5b00;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
/* 关键:author 样式的 display 会覆盖 UA 的 [hidden],必须显式压回去,
   否则透明的全屏 overlay 会一直拦截页面点击 */
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  transition: background .4s var(--smooth), color .4s var(--smooth);
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input { font-family: inherit; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; flex-shrink: 0; }

/* ============ 布局 ============ */
.app { display: flex; height: 100vh; }

/* ============ 侧边栏 ============ */
.sidebar {
  width: var(--side-w);
  min-width: var(--side-w);
  background: var(--bg-side);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  transition: margin-left .45s var(--swift), opacity .35s var(--swift);
  animation: side-in .6s var(--swift) both;
}
@keyframes side-in { from { transform: translateX(-40px); opacity: 0; } }
.sidebar.hidden { margin-left: calc(var(--side-w) * -1); opacity: 0; }

.side-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 14px 10px;
}
.brand { display: flex; align-items: center; gap: 9px; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px;
  display: grid; place-items: center;
  font-weight: 700; font-size: 15px; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 4px 14px -4px var(--accent);
  transition: transform .5s var(--spring);
}
.brand-mark:hover { transform: rotate(-8deg) scale(1.12); }
.brand-name { font-weight: 650; letter-spacing: .3px; font-size: 15px; }
.side-actions { display: flex; gap: 2px; }

.icon-btn {
  width: 32px; height: 32px; border-radius: 8px;
  display: grid; place-items: center;
  color: var(--text-dim);
  transition: background .2s, color .2s, transform .35s var(--spring);
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); transform: scale(1.1); }
.icon-btn:active { transform: scale(.92); }
.icon-btn.on { color: var(--accent); background: var(--accent-soft); }

/* 侧栏 tab + 滑块 */
.side-tabs {
  position: relative; display: flex;
  margin: 4px 14px 8px;
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: 10px; padding: 3px;
}
.side-tab {
  flex: 1; padding: 6px 0; font-size: 13px; color: var(--text-dim);
  border-radius: 7px; position: relative; z-index: 1;
  transition: color .25s;
}
.side-tab.active { color: var(--text); }
.side-tab-glider {
  position: absolute; top: 3px; bottom: 3px; left: 3px;
  width: calc((100% - 6px) / 3);
  background: var(--bg-active);
  border-radius: 7px;
  transition: transform .45s var(--spring);
}
.side-tabs[data-active="search"] .side-tab-glider { transform: translateX(100%); }
.side-tabs[data-active="assets"] .side-tab-glider { transform: translateX(200%); }

.side-panels { flex: 1; overflow: hidden; position: relative; }
.side-panel {
  position: absolute; inset: 0; overflow-y: auto; padding: 2px 8px 12px;
  opacity: 0; transform: translateX(14px); pointer-events: none;
  transition: opacity .3s var(--swift), transform .4s var(--spring);
}
.side-panel:first-child { transform: translateX(-14px); }
.side-panel.active { opacity: 1; transform: translateX(0); pointer-events: auto; }

/* ---------- 文件树 ---------- */
.tree { padding-top: 4px; }
.tree-item { animation: tree-in .5s var(--swift) both; animation-delay: calc(var(--i, 0) * 28ms); }
@keyframes tree-in { from { opacity: 0; transform: translateY(-6px); } }

.tree-row {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 8px; margin: 1px 0;
  border-radius: 8px; font-size: 13.5px;
  color: var(--text-dim); cursor: pointer; user-select: none;
  transition: background .18s, color .18s, transform .3s var(--swift);
}
.tree-row:hover { background: var(--bg-hover); color: var(--text); transform: translateX(2px); }
.tree-row.active {
  background: var(--accent-soft); color: var(--accent);
  font-weight: 550;
}
.tree-row svg { width: 15px; height: 15px; opacity: .75; }
.tree-row .chev {
  width: 12px; height: 12px; opacity: .6;
  transition: transform .4s var(--spring);
}
.tree-dir.open > .tree-row .chev { transform: rotate(90deg); }
.tree-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.tree-children {
  display: grid; grid-template-rows: 0fr;
  transition: grid-template-rows .45s var(--swift);
}
.tree-dir.open > .tree-children { grid-template-rows: 1fr; }
.tree-children > div { overflow: hidden; padding-left: 14px; }

.tree-empty { padding: 24px 12px; text-align: center; color: var(--text-faint); font-size: 13px; }

/* ---------- 搜索面板 ---------- */
.search-box {
  display: flex; align-items: center; gap: 8px;
  margin: 6px 6px 10px; padding: 8px 12px;
  background: var(--bg-panel); border: 1px solid var(--line);
  border-radius: 10px;
  transition: border-color .25s, box-shadow .25s;
}
.search-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search-box svg { width: 15px; height: 15px; color: var(--text-faint); }
.search-box input {
  flex: 1; background: none; border: none; outline: none;
  color: var(--text); font-size: 13.5px;
}
.search-hit {
  margin: 4px 6px; padding: 8px 10px;
  border-radius: 9px; cursor: pointer;
  border: 1px solid transparent;
  animation: tree-in .45s var(--swift) both;
  animation-delay: calc(var(--i, 0) * 30ms);
  transition: background .18s, border-color .18s, transform .3s var(--swift);
}
.search-hit:hover { background: var(--bg-hover); border-color: var(--line); transform: translateX(3px); }
.search-hit-path { font-size: 12.5px; font-weight: 600; color: var(--accent); margin-bottom: 3px; }
.search-hit-line { font-size: 12px; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-hit-line b { color: var(--mark-fg); background: var(--mark-bg); border-radius: 3px; padding: 0 2px; font-weight: 600; }

.side-foot {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; border-top: 1px solid var(--line);
}
.side-foot-btns { display: flex; gap: 2px; }
.foot-hint { font-size: 11.5px; color: var(--text-faint); }

/* ============ 主区域 ============ */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  animation: fade-down .55s var(--swift) both;
}
@keyframes fade-down { from { opacity: 0; transform: translateY(-12px); } }

.crumb { flex: 1; display: flex; align-items: center; gap: 6px; font-size: 13.5px; min-width: 0; overflow: hidden; }
.crumb-seg { color: var(--text-faint); white-space: nowrap; }
.crumb-seg.last { color: var(--text); font-weight: 600; }
.crumb-sep { color: var(--text-faint); opacity: .5; }
.crumb-empty { color: var(--text-faint); }

/* 模式切换 */
.mode-switch {
  position: relative; display: flex;
  background: var(--bg-panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 3px;
}
.mode-switch button {
  position: relative; z-index: 1;
  padding: 5px 14px; font-size: 12.5px; color: var(--text-dim);
  border-radius: 7px; transition: color .25s;
}
.mode-switch button.active { color: var(--text); }
.mode-glider {
  position: absolute; top: 3px; bottom: 3px; left: 3px;
  width: calc((100% - 6px) / 3);
  background: var(--bg-active); border-radius: 7px;
  transition: transform .45s var(--spring);
}
.mode-switch[data-mode="split"] .mode-glider { transform: translateX(100%); }
.mode-switch[data-mode="read"]  .mode-glider { transform: translateX(200%); }

/* ---------- 空状态 ---------- */
.empty-state {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 10px;
  animation: pop-in .6s var(--spring) both;
}
@keyframes pop-in { from { opacity: 0; transform: scale(.92) translateY(16px); } }
.empty-ink {
  width: 84px; height: 84px; border-radius: 26px;
  display: grid; place-items: center;
  font-size: 40px; font-weight: 700; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 20px 50px -12px var(--accent);
  animation: float 4s ease-in-out infinite;
}
@keyframes float {
  0%, 100% { transform: translateY(0) rotate(-3deg); }
  50%      { transform: translateY(-12px) rotate(3deg); }
}
.empty-state h2 { font-size: 22px; margin-top: 14px; letter-spacing: 2px; }
.empty-state p { color: var(--text-dim); font-size: 14px; }
.empty-keys { display: flex; gap: 18px; margin-top: 18px; color: var(--text-faint); font-size: 12.5px; }
kbd {
  display: inline-block; padding: 2px 6px; margin: 0 2px;
  font-family: var(--mono); font-size: 11px;
  background: var(--bg-panel); border: 1px solid var(--line);
  border-bottom-width: 2px; border-radius: 5px;
}

.btn-primary {
  margin-top: 8px; padding: 9px 22px;
  font-size: 14px; font-weight: 600; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-radius: 10px;
  box-shadow: 0 8px 24px -8px var(--accent);
  transition: transform .4s var(--spring), box-shadow .3s;
}
.btn-primary:hover { transform: translateY(-2px) scale(1.03); box-shadow: 0 14px 30px -8px var(--accent); }
.btn-primary:active { transform: scale(.96); }
.btn-ghost {
  padding: 9px 18px; font-size: 14px; color: var(--text-dim);
  border-radius: 10px; border: 1px solid var(--line);
  transition: background .2s, color .2s, transform .3s var(--spring);
}
.btn-ghost:hover { background: var(--bg-hover); color: var(--text); }

/* ---------- 标签页 ---------- */
.tabbar {
  display: flex; align-items: flex-end; gap: 4px;
  padding: 6px 10px 0;
  border-bottom: 1px solid var(--line);
  overflow-x: auto; scrollbar-width: thin;
  flex-shrink: 0;
}
.tab {
  display: flex; align-items: center; gap: 7px;
  max-width: 200px; padding: 7px 10px 7px 14px;
  font-size: 13px; color: var(--text-dim);
  background: transparent;
  border: 1px solid transparent; border-bottom: none;
  border-radius: 10px 10px 0 0;
  cursor: pointer; user-select: none; white-space: nowrap;
  position: relative;
  animation: tab-in .45s var(--spring) both;
  transition: background .2s, color .2s;
}
@keyframes tab-in { from { opacity: 0; transform: translateY(8px) scale(.92); } }
.tab:hover { background: var(--bg-hover); color: var(--text); }
.tab.active {
  background: var(--bg-panel); color: var(--text);
  border-color: var(--line);
  font-weight: 550;
}
.tab.active::after {
  content: ""; position: absolute; left: 10px; right: 10px; top: -1px;
  height: 2px; border-radius: 2px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}
.tab-name { overflow: hidden; text-overflow: ellipsis; }
.tab-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent); flex-shrink: 0;
  display: none;
}
.tab.dirty .tab-dot { display: block; }
.tab-close {
  width: 18px; height: 18px; border-radius: 5px;
  display: grid; place-items: center;
  color: var(--text-faint); flex-shrink: 0;
  transition: background .15s, color .15s, transform .3s var(--spring);
}
.tab-close svg { width: 11px; height: 11px; stroke-width: 2.2; }
.tab-close:hover { background: var(--bg-active); color: var(--danger); transform: scale(1.15); }

/* ---------- 编辑工具栏 ---------- */
.toolbar {
  display: flex; align-items: center; gap: 2px; flex-wrap: wrap;
  padding: 6px 12px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg-side) 55%, var(--bg));
}
.tb-btn {
  min-width: 28px; height: 28px; padding: 0 6px;
  border-radius: 7px;
  display: grid; place-items: center;
  color: var(--text-dim); font-size: 12.5px; font-weight: 600;
  transition: background .15s, color .15s, transform .3s var(--spring);
}
.tb-btn svg { width: 15px; height: 15px; }
.tb-btn:hover { background: var(--bg-hover); color: var(--accent); transform: translateY(-1px); }
.tb-btn:active { transform: scale(.9); }
.tb-sep { width: 1px; height: 16px; background: var(--line); margin: 0 5px; }

/* ---------- 工作区 ---------- */
.work-row { flex: 1; display: flex; min-height: 0; }
.workspace { flex: 1; display: flex; min-height: 0; min-width: 0; }

/* ---------- 大纲 ---------- */
.outline {
  width: 0; min-width: 0; overflow: hidden;
  border-left: 1px solid transparent;
  transition: width .45s var(--swift), border-color .3s;
  display: flex; flex-direction: column;
}
.outline.show { width: 230px; min-width: 230px; border-left-color: var(--line); }
.outline-title {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px 6px 18px; font-size: 12px; font-weight: 650;
  letter-spacing: 2px; color: var(--text-faint);
  width: 230px;
}
.outline-close { width: 26px; height: 26px; }
.outline-close svg { width: 13px; height: 13px; }
.outline-list { flex: 1; overflow-y: auto; padding: 0 8px 20px; width: 230px; }
.outline-item {
  display: block; padding: 4px 10px; margin: 1px 0;
  font-size: 12.8px; color: var(--text-dim);
  border-left: 2px solid transparent;
  border-radius: 0 7px 7px 0;
  cursor: pointer; user-select: none;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  animation: tree-in .4s var(--swift) both;
  animation-delay: calc(var(--i, 0) * 22ms);
  transition: background .15s, color .15s, border-color .2s, transform .3s var(--swift);
}
.outline-item:hover { background: var(--bg-hover); color: var(--text); transform: translateX(2px); }
.outline-item.current {
  color: var(--accent); border-left-color: var(--accent);
  background: var(--accent-soft);
}
.outline-empty { padding: 10px 18px; font-size: 12.5px; color: var(--text-faint); }

/* ---------- 设置 ---------- */
.modal.settings { width: min(440px, 92vw); }
.set-group { margin-bottom: 16px; }
.set-group label {
  display: flex; justify-content: space-between;
  font-size: 13px; color: var(--text-dim); margin-bottom: 7px;
}
.set-presets { display: flex; gap: 6px; margin-bottom: 7px; }
.set-presets button {
  flex: 1; padding: 6px 0; font-size: 12.5px;
  color: var(--text-dim);
  background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px;
  transition: all .2s, transform .35s var(--spring);
}
.set-presets button:hover { transform: translateY(-1px); }
.set-presets button.active {
  color: var(--accent); border-color: var(--accent);
  background: var(--accent-soft); font-weight: 600;
}
.set-group input[type="range"] { width: 100%; accent-color: var(--accent); }
.pane { flex: 1; min-width: 0; display: none; overflow: hidden; }
.workspace[data-mode="edit"]  .pane-edit    { display: flex; animation: pane-in .4s var(--swift); }
.workspace[data-mode="read"]  .pane-preview { display: block; animation: pane-in .4s var(--swift); }
.workspace[data-mode="split"] .pane-edit    { display: flex; }
.workspace[data-mode="split"] .pane-preview { display: block; }
.workspace[data-mode="split"] .pane-edit    { border-right: 1px solid var(--line); }
.pane-edit { flex-direction: column; }
@keyframes pane-in { from { opacity: 0; transform: translateY(8px); } }

/* 分屏分隔条:仅在中小屏的上下分屏中出现 */
.split-divider { display: none; }

/* ---------- 中小屏(≤900px):分屏改为上下结构 ---------- */
@media (max-width: 900px) {
  .workspace[data-mode="split"] { flex-direction: column; }
  .workspace[data-mode="split"] .pane-edit {
    border-right: none;
    flex: 0 0 var(--split-top, 52%);
    min-height: 90px;
  }
  .workspace[data-mode="split"] .pane-preview { flex: 1; min-height: 0; }
  .workspace[data-mode="split"] .split-divider {
    display: flex; align-items: center; justify-content: center;
    flex: 0 0 16px;
    background: var(--bg-side);
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    cursor: row-resize;
    touch-action: none;             /* 拖动时不触发页面滚动 */
    user-select: none;
  }
  .split-grip {
    width: 40px; height: 4px; border-radius: 2px;
    background: var(--text-faint); opacity: .55;
    transition: background .2s, opacity .2s, transform .3s var(--spring);
  }
  .split-divider:hover .split-grip,
  .split-divider.drag .split-grip {
    background: var(--accent); opacity: 1; transform: scaleX(1.3);
  }

  /* 键盘弹起(触屏输入中):预览临时让位,编辑区占满 */
  .workspace[data-mode="split"].kb-collapse .pane-edit { flex: 1; }
  .workspace[data-mode="split"].kb-collapse .pane-preview,
  .workspace[data-mode="split"].kb-collapse .split-divider { display: none; }
}

#editor {
  width: 100%; flex: 1; min-height: 0; resize: none; border: none; outline: none;
  background: transparent; color: var(--text);
  font-family: var(--editor-font, var(--mono));
  font-size: var(--editor-size, 14.5px);
  line-height: 1.85;
  padding: 28px 34px 40vh;
  caret-color: var(--accent);
}
#editor::placeholder { color: var(--text-faint); }
#editor::selection { background: var(--accent-soft); }

.pane-preview { overflow-y: auto; }
.md { max-width: 780px; margin: 0 auto; padding: 28px 36px 40vh; }

/* ---------- Markdown 渲染 ---------- */
.md {
  font-family: var(--preview-font, var(--font));
  font-size: var(--preview-size, 15.5px);
  line-height: 1.85;
}
.md > * { animation: md-in .5s var(--swift) both; }
@keyframes md-in { from { opacity: 0; transform: translateY(6px); } }
.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 { margin: 1.4em 0 .55em; line-height: 1.35; font-weight: 650; scroll-margin-top: 20px; }
.md h1 { font-size: 1.9em; padding-bottom: .3em; border-bottom: 1px solid var(--line); }
.md h2 { font-size: 1.5em; padding-bottom: .25em; border-bottom: 1px solid var(--line); }
.md h3 { font-size: 1.25em; }
.md h4 { font-size: 1.1em; }
.md p { margin: .7em 0; }
.md a { color: var(--accent); text-decoration: none; border-bottom: 1px solid transparent; transition: border-color .2s; }
.md a:hover { border-bottom-color: var(--accent); }
.md a.wikilink { color: var(--accent-2); cursor: pointer; }
.md a.wikilink::before { content: "⟦ "; opacity: .5; }
.md a.wikilink::after  { content: " ⟧"; opacity: .5; }
.md ul, .md ol { margin: .6em 0; padding-left: 1.6em; }
.md li { margin: .25em 0; }
.md li.task { list-style: none; margin-left: -1.3em; }
.md li.task input { accent-color: var(--accent); margin-right: 6px; transform: translateY(1px); }
.md li.task.done { color: var(--text-faint); text-decoration: line-through; }
.md blockquote {
  margin: .9em 0; padding: 2px 18px;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 10px 10px 0;
  color: var(--text-dim);
}
.md code {
  font-family: var(--mono); font-size: .88em;
  background: var(--code-bg); border: 1px solid var(--line);
  padding: 2px 6px; border-radius: 6px;
}
.md pre {
  margin: 1em 0; padding: 16px 18px;
  background: var(--code-bg); border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow-x: auto; position: relative;
}
.md pre code { background: none; border: none; padding: 0; font-size: 13.5px; line-height: 1.7; }
.md pre .lang-tag {
  position: absolute; top: 8px; right: 12px;
  font-size: 11px; color: var(--text-faint);
  font-family: var(--mono); text-transform: uppercase; letter-spacing: 1px;
}
.tok-c { color: var(--text-faint); font-style: italic; }
.tok-s { color: var(--accent-2); }
.tok-k { color: var(--accent); font-weight: 600; }
.tok-n { color: #e5a94f; }
.md hr { border: none; border-top: 1px solid var(--line); margin: 1.6em 0; }
.md mark { background: var(--mark-bg); color: var(--mark-fg); padding: 1px 4px; border-radius: 4px; }
.md img { max-width: 100%; border-radius: var(--radius); box-shadow: var(--shadow); }
.md table { border-collapse: collapse; margin: 1em 0; width: 100%; font-size: .93em; }
.md th, .md td { border: 1px solid var(--line); padding: 7px 12px; text-align: left; }
.md th { background: var(--bg-panel); font-weight: 600; }
.md tr:hover td { background: var(--bg-hover); }
.md del { color: var(--text-faint); }

/* ---------- 状态栏 ---------- */
.statusbar {
  display: flex; align-items: center; justify-content: flex-end; gap: 16px;
  padding: 5px 16px;
  border-top: 1px solid var(--line);
  font-size: 12px; color: var(--text-faint);
}
.save-state { display: flex; align-items: center; gap: 5px; transition: color .3s; }
.save-state::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%;
  background: currentColor;
  transition: transform .4s var(--spring);
}
.save-state.saved  { color: var(--accent-2); }
.save-state.saving { color: #e5a94f; }
.save-state.saving::before { animation: pulse 1s ease-in-out infinite; }
.save-state.dirty  { color: var(--text-dim); }
@keyframes pulse { 50% { transform: scale(1.6); opacity: .5; } }

/* ============ 覆盖层:命令面板 / 模态 ============ */
.overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(5, 6, 10, .55);
  backdrop-filter: blur(6px);
  display: flex; justify-content: center;
  opacity: 0; transition: opacity .3s var(--swift);
}
.overlay.show { opacity: 1; }
/* 确认/输入框可能从回收站、历史等浮层里唤起,必须盖在它们之上 */
#modal-overlay { z-index: 150; }

.palette {
  margin-top: 12vh; align-self: flex-start;
  width: min(560px, 92vw);
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
  transform: scale(.94) translateY(-16px); opacity: 0;
  transition: transform .45s var(--spring), opacity .25s;
}
.overlay.show .palette { transform: scale(1) translateY(0); opacity: 1; }
.palette-input-wrap {
  display: flex; align-items: center; gap: 10px;
  padding: 15px 18px; border-bottom: 1px solid var(--line);
}
.palette-input-wrap svg { color: var(--text-faint); width: 17px; height: 17px; }
#palette-input {
  flex: 1; background: none; border: none; outline: none;
  font-size: 15px; color: var(--text);
}
.palette-list { max-height: 46vh; overflow-y: auto; padding: 6px; }
.palette-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 9px; cursor: pointer;
  font-size: 14px; color: var(--text-dim);
  transition: background .15s, color .15s;
}
.palette-item svg { width: 15px; height: 15px; opacity: .7; }
.palette-item.selected { background: var(--accent-soft); color: var(--accent); }
.palette-item .dim { margin-left: auto; font-size: 12px; color: var(--text-faint); }
.palette-item b { color: var(--accent); font-weight: 650; }
.palette-empty { padding: 20px; text-align: center; color: var(--text-faint); font-size: 13.5px; }

/* 模态框 */
.modal {
  margin-top: 22vh; align-self: flex-start;
  width: min(420px, 90vw);
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: 16px; padding: 22px;
  box-shadow: var(--shadow);
  transform: scale(.9); opacity: 0;
  transition: transform .5s var(--spring), opacity .25s;
}
.overlay.show .modal { transform: scale(1); opacity: 1; }
.modal h3 { font-size: 16px; margin-bottom: 14px; }
.modal input {
  width: 100%; padding: 10px 14px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px;
  font-size: 14px; outline: none;
  transition: border-color .25s, box-shadow .25s;
}
.modal input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.modal-desc { font-size: 12.5px; color: var(--text-faint); margin-top: 8px; min-height: 1em; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }
.modal-actions .btn-primary { margin-top: 0; padding: 8px 20px; }

/* ---------- 右键菜单 ---------- */
.ctx-menu {
  position: fixed; z-index: 200;
  min-width: 160px; padding: 5px;
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  transform-origin: top left;
  animation: ctx-pop .35s var(--spring) both;
}
@keyframes ctx-pop { from { transform: scale(.85); opacity: 0; } }
.ctx-item {
  display: flex; align-items: center; gap: 9px;
  width: 100%; padding: 8px 12px;
  font-size: 13.5px; color: var(--text-dim);
  border-radius: 8px; text-align: left;
  transition: background .15s, color .15s;
}
.ctx-item:hover { background: var(--bg-hover); color: var(--text); }
.ctx-item.danger:hover { background: rgba(229, 72, 77, .12); color: var(--danger); }
.ctx-item svg { width: 15px; height: 15px; }
.ctx-sep { height: 1px; background: var(--line); margin: 4px 8px; }

/* ---------- 通知 ---------- */
.toasts {
  position: fixed; bottom: 24px; right: 24px; z-index: 300;
  display: flex; flex-direction: column; gap: 10px;
}
.toast {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 18px;
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  font-size: 13.5px;
  animation: toast-in .55s var(--spring) both;
}
.toast.out { animation: toast-out .35s var(--swift) both; }
@keyframes toast-in  { from { transform: translateX(120%) scale(.9); opacity: 0; } }
@keyframes toast-out { to   { transform: translateY(10px); opacity: 0; } }
.toast.ok    { border-left: 3px solid var(--accent-2); }
.toast.err   { border-left: 3px solid var(--danger); }

/* 上传进度通知 */
.toast.progress { flex-direction: column; align-items: stretch; gap: 8px; min-width: 240px; max-width: 320px; }
.toast-progress-info { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.toast-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toast-pct { color: var(--text-faint); font-size: 12px; font-variant-numeric: tabular-nums; flex-shrink: 0; }
.toast.progress.ok .toast-pct { color: var(--accent-2); font-weight: 700; }
.toast.progress.err .toast-pct { color: var(--danger); font-weight: 700; }
.toast-bar { height: 5px; border-radius: 3px; background: var(--bg-active); overflow: hidden; }
.toast-bar-fill {
  height: 100%; width: 0; border-radius: 3px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width .25s var(--swift);
}

/* ---------- 查找替换 ---------- */
.findbar {
  position: absolute; top: 46px; right: 14px; z-index: 20;
  width: min(320px, calc(100% - 28px));
  padding: 10px;
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  animation: find-in .45s var(--spring) both;
}
@keyframes find-in { from { opacity: 0; transform: translateY(-10px) scale(.96); } }
.pane-edit { position: relative; }
.find-row { display: flex; align-items: center; gap: 5px; }
.find-row + .find-row { margin-top: 7px; }
.find-row input {
  flex: 1; min-width: 0; padding: 6px 10px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
  font-size: 13px; outline: none;
  transition: border-color .2s, box-shadow .2s;
}
.find-row input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.find-count { font-size: 11.5px; color: var(--text-faint); white-space: nowrap; min-width: 34px; text-align: center; }
.find-btn {
  height: 26px; min-width: 26px; padding: 0 4px;
  border-radius: 6px; font-size: 12px; color: var(--text-dim);
  transition: background .15s, color .15s, transform .3s var(--spring);
}
.find-btn:hover { background: var(--bg-hover); color: var(--text); }
.find-btn:active { transform: scale(.9); }
.find-btn.on { color: var(--accent); background: var(--accent-soft); }
.find-btn.wide { padding: 0 10px; }

/* ---------- 文件面板 ---------- */
.assets-head { padding: 0 0 4px; }
.assets-upload {
  display: flex; align-items: center; justify-content: center; gap: 7px;
  width: calc(100% - 12px); margin: 2px 6px 8px;
  padding: 8px 0;
  font-size: 13px; font-weight: 600; color: var(--accent);
  background: var(--accent-soft);
  border: 1px dashed color-mix(in srgb, var(--accent) 45%, transparent);
  border-radius: 10px;
  transition: background .2s, transform .35s var(--spring);
}
.assets-upload:hover { transform: translateY(-1px); background: color-mix(in srgb, var(--accent) 24%, transparent); }
.assets-upload svg { width: 15px; height: 15px; }
.assets-list { padding-bottom: 8px; }
.asset-item {
  display: flex; align-items: center; gap: 10px;
  margin: 3px 6px; padding: 7px 9px;
  border-radius: 10px; cursor: pointer;
  border: 1px solid transparent;
  animation: tree-in .4s var(--swift) both;
  animation-delay: calc(var(--i, 0) * 24ms);
  transition: background .18s, border-color .18s, transform .3s var(--swift);
}
.asset-item:hover { background: var(--bg-hover); border-color: var(--line); transform: translateX(2px); }
.asset-thumb {
  width: 38px; height: 38px; border-radius: 8px; flex-shrink: 0;
  object-fit: cover; background: var(--bg);
  border: 1px solid var(--line);
}
.asset-icon {
  width: 38px; height: 38px; border-radius: 8px; flex-shrink: 0;
  display: grid; place-items: center;
  background: var(--bg); border: 1px solid var(--line);
  font-size: 15px;
}
.asset-info { flex: 1; min-width: 0; }
.asset-name { font-size: 12.8px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.asset-meta { font-size: 11px; color: var(--text-faint); margin-top: 2px; }
.asset-actions { display: flex; gap: 2px; opacity: 0; transition: opacity .2s; }
.asset-item:hover .asset-actions { opacity: 1; }
.asset-btn {
  width: 26px; height: 26px; border-radius: 6px;
  display: grid; place-items: center; color: var(--text-dim);
  transition: background .15s, color .15s, transform .3s var(--spring);
}
.asset-btn svg { width: 14px; height: 14px; }
.asset-btn:hover { background: var(--bg-active); color: var(--text); transform: scale(1.12); }
.asset-btn.danger:hover { color: var(--danger); }
.assets-hint { padding: 6px 14px 10px; font-size: 11.5px; color: var(--text-faint); text-align: center; }
.asset-item.uploading { cursor: default; border-color: color-mix(in srgb, var(--accent) 35%, transparent); background: var(--accent-soft); }
.asset-bar { height: 4px; border-radius: 2px; background: var(--bg-active); overflow: hidden; margin-top: 6px; }
.asset-bar-fill {
  height: 100%; width: 0; border-radius: 2px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width .25s var(--swift);
}
.asset-pct { font-size: 11px; color: var(--accent); font-variant-numeric: tabular-nums; flex-shrink: 0; }
.asset-item.flash { animation: asset-flash 1.8s var(--swift) both; }
@keyframes asset-flash {
  0%, 55% { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
}
.assets-empty { padding: 26px 12px; text-align: center; color: var(--text-faint); font-size: 13px; }

/* 拖拽上传高亮 */
.pane-edit.dropping::after {
  content: "松开即上传"; position: absolute; inset: 10px; z-index: 30;
  display: grid; place-items: center;
  font-size: 15px; font-weight: 600; color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  border: 2px dashed var(--accent); border-radius: 14px;
  pointer-events: none;
  animation: find-in .3s var(--spring) both;
}

/* ---------- 历史版本 ---------- */
.history-modal { width: min(720px, 94vw); }
.history-note { font-weight: 400; font-size: 13px; color: var(--text-faint); margin-left: 8px; }
.history-body {
  display: flex; gap: 12px; margin-top: 4px;
  height: min(420px, 55vh);
}
.history-list { width: 190px; flex-shrink: 0; overflow-y: auto; padding-right: 2px; }
.history-item {
  padding: 8px 12px; margin: 3px 0;
  border-radius: 9px; cursor: pointer;
  border: 1px solid transparent;
  animation: tree-in .4s var(--swift) both;
  animation-delay: calc(var(--i, 0) * 26ms);
  transition: background .15s, border-color .15s;
}
.history-item:hover { background: var(--bg-hover); border-color: var(--line); }
.history-item.selected { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.history-time { font-size: 12.8px; color: var(--text); font-weight: 550; }
.history-item.selected .history-time { color: var(--accent); }
.history-size { font-size: 11px; color: var(--text-faint); margin-top: 2px; }
.history-preview {
  flex: 1; overflow: auto; margin: 0;
  padding: 14px 16px;
  background: var(--bg); border: 1px solid var(--line);
  border-radius: 12px;
  font-family: var(--mono); font-size: 12.5px; line-height: 1.7;
  white-space: pre-wrap; word-break: break-word;
  color: var(--text-dim);
}
.history-placeholder { color: var(--text-faint); font-family: var(--font); }
.history-empty { padding: 20px 10px; text-align: center; color: var(--text-faint); font-size: 13px; }

/* ---------- 图谱 ---------- */
.graph-overlay { align-items: center; }
.graph-wrap {
  width: min(860px, 94vw); height: min(620px, 86vh);
  display: flex; flex-direction: column;
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
  transform: scale(.94); opacity: 0;
  transition: transform .5s var(--spring), opacity .25s;
}
.overlay.show .graph-wrap { transform: scale(1); opacity: 1; }
.graph-head {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 18px;
  border-bottom: 1px solid var(--line);
}
.graph-title { font-weight: 650; font-size: 15px; }
.graph-tip { flex: 1; font-size: 12px; color: var(--text-faint); }
#graph-canvas { flex: 1; width: 100%; cursor: grab; touch-action: none; }
#graph-canvas.dragging { cursor: grabbing; }

/* ---------- 设置扩展 ---------- */
.modal.settings { width: min(720px, 94vw); max-height: 88vh; overflow-y: auto; }
.set-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 0 32px; }
.set-col .set-section:first-child { margin-top: 4px; padding-top: 0; border-top: none; }
@media (max-width: 720px) {
  .set-cols { grid-template-columns: 1fr; }
  .set-col + .set-col .set-section:first-child {
    margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line);
  }
}
/* 设置和历史版本是大面板,垂直居中显示(命令面板保持顶部弹出) */
#settings-overlay, #history-overlay { align-items: center; }
#settings-overlay .modal, #history-overlay .modal { margin-top: 0; align-self: center; }
.set-section {
  font-size: 11.5px; font-weight: 650; letter-spacing: 2px;
  color: var(--text-faint);
  margin: 18px 0 10px; padding-top: 14px;
  border-top: 1px solid var(--line);
}
.set-section:first-of-type { margin-top: 4px; padding-top: 0; border-top: none; }
.set-swatches { display: flex; gap: 9px; align-items: center; }
.set-swatch {
  width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer; position: relative;
  transition: transform .35s var(--spring), border-color .2s;
}
.set-swatch:hover { transform: scale(1.18); }
.set-swatch.active { border-color: var(--text); transform: scale(1.12); }
.set-bgs button { position: relative; padding-left: 22px; }
.set-bgs button::before {
  content: ""; position: absolute; left: 8px; top: 50%;
  width: 10px; height: 10px; margin-top: -5px;
  border-radius: 3px; background: var(--sw, #000);
  border: 1px solid var(--line);
}

/* ---------- 标签云 ---------- */
.tag-cloud { display: flex; flex-wrap: wrap; gap: 7px; padding: 2px 8px 10px; }
.tag-chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 11px;
  font-size: 12.5px; color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid transparent;
  border-radius: 999px; cursor: pointer;
  animation: tree-in .4s var(--swift) both;
  animation-delay: calc(var(--i, 0) * 22ms);
  transition: border-color .2s, transform .3s var(--spring);
}
.tag-chip:hover { border-color: var(--accent); transform: translateY(-1px) scale(1.04); }
.tag-chip b { font-weight: 650; }
.tag-chip .cnt { font-size: 11px; opacity: .65; }
.tag-cloud-title { width: 100%; font-size: 11px; letter-spacing: 2px; color: var(--text-faint); padding: 4px 6px 2px; }

/* ---------- 反向链接 ---------- */
.backlinks {
  flex: 0 0 auto; max-height: 42%;
  display: flex; flex-direction: column;
  border-top: 1px solid var(--line);
}
.backlinks-list { overflow-y: auto; padding: 0 8px 14px; width: 230px; }
.backlink-item {
  margin: 3px 0; padding: 7px 10px;
  border-radius: 9px; cursor: pointer;
  border: 1px solid transparent;
  animation: tree-in .4s var(--swift) both;
  animation-delay: calc(var(--i, 0) * 24ms);
  transition: background .15s, border-color .15s, transform .3s var(--swift);
}
.backlink-item:hover { background: var(--bg-hover); border-color: var(--line); transform: translateX(2px); }
.backlink-name { font-size: 12.5px; font-weight: 600; color: var(--accent-2); }
.backlink-excerpt {
  font-size: 11.5px; color: var(--text-faint); margin-top: 3px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.backlinks-empty { padding: 8px 12px 4px; font-size: 12px; color: var(--text-faint); }

/* ---------- 回收站 ---------- */
.trash-modal { width: min(560px, 94vw); }
.trash-list { max-height: min(420px, 55vh); overflow-y: auto; margin-top: 4px; }
.trash-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; margin: 3px 0;
  border-radius: 10px; border: 1px solid transparent;
  animation: tree-in .4s var(--swift) both;
  animation-delay: calc(var(--i, 0) * 24ms);
  transition: background .15s, border-color .15s;
}
.trash-item:hover { background: var(--bg-hover); border-color: var(--line); }
.trash-item svg { width: 16px; height: 16px; color: var(--text-faint); flex-shrink: 0; }
.trash-info { flex: 1; min-width: 0; }
.trash-name { font-size: 13px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trash-meta { font-size: 11px; color: var(--text-faint); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trash-actions { display: flex; gap: 4px; flex-shrink: 0; }
.trash-btn {
  padding: 5px 12px; font-size: 12px; border-radius: 7px;
  color: var(--text-dim); border: 1px solid var(--line);
  transition: all .2s, transform .3s var(--spring);
}
.trash-btn:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); transform: translateY(-1px); }
.trash-btn.danger:hover { color: var(--danger); border-color: var(--danger); background: rgba(229,72,77,.1); }
.trash-empty-hint { padding: 30px 12px; text-align: center; color: var(--text-faint); font-size: 13px; }
.btn-ghost.danger:hover { color: var(--danger); border-color: var(--danger); background: rgba(229,72,77,.08); }

/* ---------- 置顶笔记 ---------- */
.tree-section {
  font-size: 10.5px; letter-spacing: 2px; font-weight: 650;
  color: var(--text-faint);
  padding: 8px 10px 3px;
}
.tree-row.pinned .pin-star { width: 13px; height: 13px; color: #e5a94f; opacity: .9; }

/* ---------- 模态框下拉 ---------- */
#modal-select {
  width: 100%; margin-top: 10px; padding: 9px 12px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px;
  font-size: 13.5px; font-family: inherit; outline: none;
}
#modal-select:focus { border-color: var(--accent); }

/* ---------- 移动端侧栏遮罩 ---------- */
.side-backdrop {
  position: fixed; inset: 0; z-index: 49;
  background: rgba(5, 6, 10, .45);
  backdrop-filter: blur(2px);
  opacity: 0; transition: opacity .3s var(--swift);
}
.side-backdrop.show { opacity: 1; }

/* ---------- 滚动条 ---------- */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- 响应式(移动端) ---------- */
@media (max-width: 720px) {
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 50;
    box-shadow: var(--shadow);
    width: min(300px, 84vw); min-width: min(300px, 84vw);
  }
  .sidebar.hidden { margin-left: min(-300px, -84vw); }

  .topbar { padding: 8px 8px; gap: 6px; }
  .crumb { font-size: 12.5px; }
  .crumb-seg:not(.last) { display: none; }   /* 只显示当前笔记名 */
  .crumb-sep { display: none; }
  .mode-switch button { padding: 5px 9px; font-size: 12px; }

  #editor { padding: 18px 16px 40vh; font-size: max(var(--editor-size, 16px), 16px); } /* ≥16px 防 iOS 聚焦缩放 */
  .md { padding: 18px 18px 40vh; }
  .toolbar { padding: 5px 6px; overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; }
  .toolbar::-webkit-scrollbar { display: none; }

  /* 大纲在小屏上是右侧抽屉:压在遮罩(z-index 49)之上,带自己的关闭按钮 */
  .outline { position: fixed; top: 0; right: 0; bottom: 0; z-index: 55; background: var(--bg-panel); }
  .outline.show { width: min(260px, 76vw); min-width: min(260px, 76vw); box-shadow: var(--shadow); }
  .outline-title { padding-top: 14px; }
  .outline-title, .outline-list { width: 100%; }

  .findbar { top: 42px; right: 8px; }
  .history-body { flex-direction: column; height: min(480px, 60vh); }
  .history-list { width: 100%; display: flex; gap: 6px; overflow-x: auto; overflow-y: hidden; flex-shrink: 0; padding-bottom: 4px; }
  .history-item { flex-shrink: 0; }
  .graph-wrap { width: 96vw; height: 88vh; border-radius: 14px; }
  .statusbar { padding: 4px 10px; font-size: 11px; }
  .foot-hint { display: none; }
  .toasts { left: 16px; right: 16px; bottom: 16px; align-items: stretch; }
  .palette { margin-top: 6vh; }
  .modal { margin-top: 8vh; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
