/* Vault: Notion-like look. Light and dark tokens, then layout, then editor content. */
:root {
  --bg: #ffffff;
  --bg-side: #f8f8f7;
  --bg-hover: rgba(55, 53, 47, .06);
  --bg-active: rgba(55, 53, 47, .09);
  --bg-elev: #ffffff;
  --bg-code: rgba(135, 131, 120, .1);
  --bg-codeblock: #f7f6f3;
  --border: rgba(55, 53, 47, .09);
  --border-strong: rgba(55, 53, 47, .16);
  --text: #37352f;
  --text-2: rgba(55, 53, 47, .72);
  --text-3: rgba(55, 53, 47, .48);
  --text-4: rgba(55, 53, 47, .32);
  --accent: #2383e2;
  --accent-soft: rgba(35, 131, 226, .14);
  --accent-text: #ffffff;
  --red: #e03e3e;
  --red-soft: rgba(224, 62, 62, .1);
  --mark: rgba(251, 236, 168, .9);
  --code-text: #eb5757;
  --tag-bg: rgba(35, 131, 226, .1);
  --tag-text: #1f6fc0;
  --c-gray: rgba(241, 241, 239, 1);
  --c-blue: rgba(231, 243, 248, 1);
  --c-green: rgba(237, 243, 236, 1);
  --c-yellow: rgba(251, 243, 219, 1);
  --c-red: rgba(253, 235, 236, 1);
  --c-purple: rgba(244, 240, 247, 1);
  --shadow: 0 0 0 1px rgba(15, 15, 15, .05), 0 3px 6px rgba(15, 15, 15, .1), 0 9px 24px rgba(15, 15, 15, .2);
  --shadow-sm: 0 1px 2px rgba(15, 15, 15, .1);
  --side-w: 248px;
  --page-w: 720px;
  --sans: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI Variable Display", "Segoe UI", Helvetica, "Apple Color Emoji", Arial, sans-serif;
  --serif: Lyon-Text, Georgia, ui-serif, serif;
  --mono: "SFMono-Regular", Menlo, Consolas, "PT Mono", "Liberation Mono", Courier, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #191919; --bg-side: #202020; --bg-hover: rgba(255, 255, 255, .055); --bg-active: rgba(255, 255, 255, .085);
    --bg-elev: #252525; --bg-code: rgba(135, 131, 120, .15); --bg-codeblock: #202020;
    --border: rgba(255, 255, 255, .08); --border-strong: rgba(255, 255, 255, .14);
    --text: rgba(255, 255, 255, .87); --text-2: rgba(255, 255, 255, .62); --text-3: rgba(255, 255, 255, .44); --text-4: rgba(255, 255, 255, .28);
    --accent: #2f8ae5; --accent-soft: rgba(47, 138, 229, .22); --red: #ff7369; --red-soft: rgba(255, 115, 105, .14);
    --mark: rgba(137, 99, 42, .55); --code-text: #ff7d7d; --tag-bg: rgba(47, 138, 229, .18); --tag-text: #7ab8f5;
    --c-gray: rgba(255, 255, 255, .055); --c-blue: rgba(45, 85, 115, .45); --c-green: rgba(43, 89, 63, .45);
    --c-yellow: rgba(89, 86, 59, .5); --c-red: rgba(110, 54, 48, .5); --c-purple: rgba(73, 47, 100, .5);
    --shadow: 0 0 0 1px rgba(255, 255, 255, .07), 0 3px 6px rgba(0, 0, 0, .3), 0 9px 24px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #191919; --bg-side: #202020; --bg-hover: rgba(255, 255, 255, .055); --bg-active: rgba(255, 255, 255, .085);
  --bg-elev: #252525; --bg-code: rgba(135, 131, 120, .15); --bg-codeblock: #202020;
  --border: rgba(255, 255, 255, .08); --border-strong: rgba(255, 255, 255, .14);
  --text: rgba(255, 255, 255, .87); --text-2: rgba(255, 255, 255, .62); --text-3: rgba(255, 255, 255, .44); --text-4: rgba(255, 255, 255, .28);
  --accent: #2f8ae5; --accent-soft: rgba(47, 138, 229, .22); --red: #ff7369; --red-soft: rgba(255, 115, 105, .14);
  --mark: rgba(137, 99, 42, .55); --code-text: #ff7d7d; --tag-bg: rgba(47, 138, 229, .18); --tag-text: #7ab8f5;
  --c-gray: rgba(255, 255, 255, .055); --c-blue: rgba(45, 85, 115, .45); --c-green: rgba(43, 89, 63, .45);
  --c-yellow: rgba(89, 86, 59, .5); --c-red: rgba(110, 54, 48, .5); --c-purple: rgba(73, 47, 100, .5);
  --shadow: 0 0 0 1px rgba(255, 255, 255, .07), 0 3px 6px rgba(0, 0, 0, .3), 0 9px 24px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text); font: 16px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased; overflow: hidden; -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; }
input, textarea { font: inherit; color: inherit; }
::selection { background: var(--accent-soft); }
.hidden { display: none !important; }
.muted { color: var(--text-3); }
.spacer { flex: 1; }
kbd { font: 11px var(--sans); color: var(--text-3); border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; }

svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px;
  border: 0; border-radius: 6px; background: transparent; color: var(--text-3); cursor: pointer; flex: none;
  transition: background .1s;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text-2); }
.icon-btn.tiny { width: 22px; height: 22px; }
.icon-btn.tiny svg { width: 15px; height: 15px; }
.icon-btn.on { color: var(--accent); background: var(--accent-soft); }

.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border-strong); background: var(--bg);
  padding: 6px 12px; border-radius: 6px; cursor: pointer; font-size: 14px; line-height: 20px; white-space: nowrap;
  transition: background .1s;
}
.btn svg { width: 16px; height: 16px; }
.btn:hover { background: var(--bg-hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn.small { padding: 3px 9px; font-size: 13px; }
.btn.wide { width: 100%; justify-content: center; padding: 9px; }
.field {
  width: 100%; padding: 7px 10px; border: 1px solid var(--border-strong); border-radius: 6px;
  background: var(--bg-hover); outline: none; font-size: 15px;
}
.field:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); background: var(--bg); }

.logo-mark {
  width: 22px; height: 22px; border-radius: 5px; display: grid; place-items: center; flex: none;
  background: var(--text); color: var(--bg); font: 700 13px var(--sans);
}
.logo-mark.big { width: 48px; height: 48px; border-radius: 12px; font-size: 26px; margin-bottom: 8px; }

/* ---------- login ---------- */
.login { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; background: var(--bg); }
.login-card { width: 100%; max-width: 340px; display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; }
.login-card h1 { margin: 0; font-size: 26px; font-weight: 700; }
.login-card p { margin: 0 0 10px; }
.error { color: var(--red); margin: 0; min-height: 1.3em; font-size: 14px; }

/* ---------- layout ---------- */
.app { display: flex; height: 100dvh; }
.sidebar {
  width: var(--side-w); flex: none; background: var(--bg-side); display: flex; flex-direction: column; min-height: 0;
  padding-top: env(safe-area-inset-top); box-shadow: inset -1px 0 0 var(--border); transition: margin .2s ease;
}
.app.side-collapsed .sidebar { margin-left: calc(-1 * var(--side-w)); }
.ws { display: flex; align-items: center; gap: 8px; padding: 10px 10px 6px 14px; height: 48px; }
.ws-name { flex: 1; font-weight: 600; font-size: 14px; }
.ws-collapse { opacity: 0; }
.sidebar:hover .ws-collapse { opacity: 1; }
.side-nav { padding: 0 6px 8px; }
.side-item {
  display: flex; align-items: center; gap: 9px; width: 100%; border: 0; background: none; padding: 0 8px;
  height: 30px; border-radius: 6px; cursor: pointer; color: var(--text-2); font-size: 14px; font-weight: 500; text-align: left;
}
.side-item:hover { background: var(--bg-hover); }
.side-item svg { width: 18px; height: 18px; color: var(--text-3); }
.side-item span { flex: 1; }
.side-item kbd { opacity: 0; }
.side-item:hover kbd { opacity: 1; }
.side-scroll { flex: 1; overflow: auto; padding: 4px 6px 12px; min-height: 0; }
.side-section + .side-section { margin-top: 14px; }
.side-head {
  display: flex; align-items: center; gap: 2px; height: 26px; padding: 0 4px 0 8px; font-size: 12px; font-weight: 600;
  color: var(--text-3); border-radius: 6px; width: 100%; border: 0; background: none; text-align: left;
}
.side-head span { flex: 1; }
.side-head .icon-btn { opacity: 0; }
.side-section:hover .side-head .icon-btn { opacity: 1; }
.side-head.toggle { cursor: pointer; }
.side-head.toggle:hover { background: var(--bg-hover); }
.side-head .chev { width: 13px; height: 13px; transition: transform .15s; }
.side-head.open .chev { transform: rotate(90deg); }
.side-foot { padding: 6px; border-top: 1px solid var(--border); padding-bottom: calc(6px + env(safe-area-inset-bottom)); }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; padding-top: env(safe-area-inset-top); }
.topbar { display: flex; align-items: center; gap: 2px; height: 45px; padding: 0 10px 0 12px; flex: none; }
.open-side { display: none; }
.app.side-collapsed .open-side { display: inline-flex; }
.crumbs { display: flex; align-items: center; min-width: 0; font-size: 14px; color: var(--text-2); overflow: hidden; }
.crumb { border: 0; background: none; padding: 2px 6px; border-radius: 4px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }
.crumb:hover { background: var(--bg-hover); }
.crumb.current { color: var(--text); }
.crumb-sep { color: var(--text-4); padding: 0 1px; }
.save-status { font-size: 13px; color: var(--text-3); white-space: nowrap; margin-right: 6px; }
.save-status.err { color: var(--red); }

.scroller { flex: 1; overflow: auto; min-height: 0; position: relative; scroll-padding-top: 60px; }

/* ---------- empty state ---------- */
.empty { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.empty-card { text-align: center; }
.empty-card h2 { margin: 0 0 4px; font-size: 22px; }
.empty-card p { margin: 0 0 18px; }
.empty-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

/* ---------- page ---------- */
.page { max-width: calc(var(--page-w) + 192px); margin: 0 auto; padding: 72px 96px 0; }
.page-title {
  font-size: 40px; line-height: 1.2; font-weight: 700; margin: 0 0 6px; outline: none; word-break: break-word;
  letter-spacing: -.01em; padding: 3px 2px;
}
.page-title:empty::before { content: attr(data-placeholder); color: var(--text-4); }
.page-meta { display: flex; flex-wrap: wrap; gap: 4px; margin: 0 0 10px -6px; min-height: 28px; }
.meta-btn {
  display: inline-flex; align-items: center; gap: 6px; border: 0; background: none; color: var(--text-3);
  font-size: 14px; padding: 3px 6px; border-radius: 5px; cursor: pointer;
}
.meta-btn svg { width: 16px; height: 16px; }
.meta-btn:hover { background: var(--bg-hover); color: var(--text-2); }
.meta-btn.ghost { opacity: 0; transition: opacity .15s; }
.page:hover .meta-btn.ghost, .meta-btn.ghost:focus { opacity: 1; }
.backlinks { margin: -4px 0 14px; padding: 6px; border-radius: 8px; background: var(--bg-hover); }
.backlink {
  display: flex; align-items: center; gap: 8px; padding: 4px 8px; border-radius: 5px; cursor: pointer; font-size: 14px;
}
.backlink:hover { background: var(--bg-active); }
.backlink svg { width: 16px; height: 16px; color: var(--text-3); }
.backlink small { color: var(--text-3); margin-left: auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.props { margin: 4px 0 6px; }
.prop { display: flex; align-items: flex-start; gap: 4px; min-height: 32px; }
.prop-key {
  width: 160px; flex: none; display: flex; align-items: center; gap: 6px; color: var(--text-3); font-size: 14px;
  padding: 5px 6px; border-radius: 5px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.prop-key svg { width: 16px; height: 16px; }
.prop-val {
  flex: 1; min-width: 0; border: 0; background: none; outline: none; font-size: 14px; padding: 5px 8px; border-radius: 5px;
  color: var(--text); min-height: 30px;
}
.prop-val:hover { background: var(--bg-hover); }
.prop-val:focus { background: var(--bg-elev); box-shadow: var(--shadow); }
.prop-chips { display: flex; flex-wrap: wrap; gap: 4px; padding: 5px 8px; flex: 1; cursor: text; border-radius: 5px; min-height: 30px; }
.prop-chips:hover { background: var(--bg-hover); }
.chip { background: var(--tag-bg); color: var(--tag-text); padding: 0 7px; border-radius: 4px; font-size: 13px; line-height: 20px; }
.props:not(:empty) { padding-bottom: 8px; margin-bottom: 8px; border-bottom: 1px solid var(--border); }

.banner {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 12px; margin: -40px 0 24px; border-radius: 8px;
  background: var(--c-yellow); font-size: 14px; color: var(--text-2);
}
.banner span { flex: 1; min-width: 220px; }

.editor-host { min-height: 40vh; }
.page-end { height: 40vh; cursor: text; }
.source {
  width: 100%; min-height: 60vh; border: 0; outline: none; resize: none; background: transparent; color: var(--text);
  font: 14.5px/1.75 var(--mono); padding: 0; tab-size: 2;
}

/* ---------- editor content ---------- */
.ProseMirror { outline: none; caret-color: var(--text); word-wrap: break-word; white-space: pre-wrap; white-space: break-spaces; }
.markdown { font-size: 16px; line-height: 1.6; }
.markdown > * { margin: 2px 0; }
.markdown p { margin: 0; padding: 3px 2px; min-height: 1.6em; }
.markdown h1, .markdown h2, .markdown h3, .markdown h4, .markdown h5, .markdown h6 { font-weight: 600; line-height: 1.3; padding: 3px 2px; margin: 0; }
.markdown h1 { font-size: 1.875em; margin-top: 1.1em; }
.markdown h2 { font-size: 1.5em; margin-top: 1em; }
.markdown h3 { font-size: 1.25em; margin-top: .8em; }
.markdown h4, .markdown h5, .markdown h6 { font-size: 1.05em; margin-top: .6em; }
.markdown > :first-child { margin-top: 0 !important; }
.markdown a { color: inherit; text-decoration: underline; text-decoration-color: var(--text-4); text-underline-offset: 2px; cursor: pointer; }
.markdown a:hover { text-decoration-color: var(--text-2); }
.markdown strong { font-weight: 600; }
.markdown code {
  font: .85em var(--mono); background: var(--bg-code); color: var(--code-text); padding: .2em .4em; border-radius: 4px;
}
.markdown pre {
  background: var(--bg-codeblock); border-radius: 6px; padding: 30px 28px 26px; margin: 6px 0; overflow-x: auto;
  font: 14px/1.6 var(--mono); tab-size: 2; position: relative;
}
.markdown pre code { background: none; color: var(--text); padding: 0; font-size: inherit; white-space: pre; }
.markdown pre[data-language]::before, .markdown pre:has(code[class*="language-"])::before {
  content: attr(data-language); position: absolute; top: 8px; left: 14px; font: 12px var(--sans); color: var(--text-3);
}
.markdown blockquote { margin: 6px 0; padding: 2px 0 2px 16px; border-left: 3px solid currentColor; }
.markdown blockquote p { padding: 2px; }
.markdown hr { border: 0; height: 13px; margin: 6px 0; position: relative; }
.markdown hr::after { content: ""; position: absolute; left: 0; right: 0; top: 6px; border-top: 1px solid var(--border-strong); }
.markdown hr.ProseMirror-selectednode::after { border-color: var(--accent); }
.markdown mark { background: var(--mark); color: inherit; border-radius: 3px; padding: 0 2px; }
.markdown img { max-width: 100%; border-radius: 4px; display: inline-block; vertical-align: bottom; }
.markdown img.ProseMirror-selectednode, .markdown .ProseMirror-selectednode img { outline: 3px solid var(--accent-soft); }
.markdown ul, .markdown ol { padding-left: 1.7em; margin: 2px 0; }
.markdown li { padding: 1px 0; }
.markdown li > p { padding: 2px; }
.markdown li::marker { color: var(--text); }
.markdown ul ul { list-style: circle; }
.markdown ul ul ul { list-style: square; }

.markdown ul[data-type="taskList"] { list-style: none; padding-left: 2px; }
.markdown ul[data-type="taskList"] li { display: flex; align-items: flex-start; gap: 8px; }
.markdown ul[data-type="taskList"] li > label { flex: none; margin-top: 6px; user-select: none; }
.markdown ul[data-type="taskList"] li > div { flex: 1; min-width: 0; }
.markdown ul[data-type="taskList"] ul[data-type="taskList"] { padding-left: 4px; }
.markdown ul[data-type="taskList"] input[type="checkbox"] {
  appearance: none; -webkit-appearance: none; width: 16px; height: 16px; margin: 0; border: 1.5px solid var(--text-2);
  border-radius: 3px; cursor: pointer; display: grid; place-items: center; background: var(--bg);
}
.markdown ul[data-type="taskList"] input[type="checkbox"]:checked { background: var(--accent); border-color: var(--accent); }
.markdown ul[data-type="taskList"] input[type="checkbox"]:checked::after {
  content: ""; width: 9px; height: 5px; border: solid #fff; border-width: 0 0 2px 2px; transform: translateY(-1px) rotate(-45deg);
}
.markdown li[data-checked="true"] > div { color: var(--text-3); text-decoration: line-through; text-decoration-color: var(--text-4); }

.markdown table { border-collapse: collapse; margin: 8px 0; width: 100%; table-layout: auto; }
.markdown .tableWrapper { overflow-x: auto; margin: 6px 0; }
.markdown th, .markdown td { border: 1px solid var(--border-strong); padding: 6px 9px; vertical-align: top; min-width: 60px; font-size: 15px; }
.markdown th { font-weight: 500; color: var(--text-2); background: var(--bg-hover); text-align: left; }
.markdown td p, .markdown th p { padding: 0; }
.markdown .selectedCell { background: var(--accent-soft); }

/* callouts: Obsidian syntax "> [!type] title", shown like Notion callouts */
.markdown blockquote.callout { border: 0; background: var(--c-gray); border-radius: 6px; padding: 14px 16px 14px 18px; }
.markdown blockquote.callout .callout-title { font-weight: 600; }
.markdown blockquote.callout[data-type="tip"], .markdown blockquote.callout[data-type="success"], .markdown blockquote.callout[data-type="done"], .markdown blockquote.callout[data-type="check"] { background: var(--c-green); }
.markdown blockquote.callout[data-type="info"], .markdown blockquote.callout[data-type="note"], .markdown blockquote.callout[data-type="abstract"], .markdown blockquote.callout[data-type="todo"] { background: var(--c-blue); }
.markdown blockquote.callout[data-type="warning"], .markdown blockquote.callout[data-type="caution"], .markdown blockquote.callout[data-type="question"], .markdown blockquote.callout[data-type="faq"] { background: var(--c-yellow); }
.markdown blockquote.callout[data-type="danger"], .markdown blockquote.callout[data-type="error"], .markdown blockquote.callout[data-type="bug"], .markdown blockquote.callout[data-type="failure"] { background: var(--c-red); }
.markdown blockquote.callout[data-type="example"], .markdown blockquote.callout[data-type="quote"] { background: var(--c-purple); }
.callout-marker { font: 11px/1 var(--mono); font-weight: 500; color: var(--text-3); background: var(--bg-hover); padding: 2px 5px; border-radius: 4px; margin-right: 4px; vertical-align: 2px; }

.markdown .tag { background: var(--tag-bg); color: var(--tag-text); border-radius: 4px; padding: 0 3px; }

/* page links */
.wl {
  display: inline; cursor: pointer; border-radius: 4px; padding: 1px 2px; white-space: normal;
  text-decoration: underline; text-decoration-color: var(--text-4); text-underline-offset: 2px; font-weight: 500;
}
.wl svg { width: 1.05em; height: 1.05em; vertical-align: -.17em; margin-right: 3px; color: var(--text-3); stroke-width: 1.6; }
.wl:hover { background: var(--bg-hover); }
.wl-missing { color: var(--text-3); text-decoration-style: dashed; }
.wl.ProseMirror-selectednode, .wl-img.ProseMirror-selectednode, .wl-note-embed.ProseMirror-selectednode { background: var(--accent-soft); }
.wl-img { display: inline-block; max-width: 100%; }
.wl-img img { max-width: 100%; border-radius: 4px; display: block; }
.wl-note-embed {
  display: block; border: 1px solid var(--border-strong); border-radius: 8px; margin: 6px 0; padding: 10px 16px 12px; cursor: pointer;
  white-space: normal;
}
.wl-note-embed:hover { background: var(--bg-hover); }
.wl-embed-head { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-3); font-weight: 500; margin-bottom: 4px; }
.wl-embed-head svg { width: 15px; height: 15px; }
.wl-embed-body { display: block; font-size: 15px; max-height: 320px; overflow: hidden; -webkit-mask-image: linear-gradient(#000 80%, transparent); mask-image: linear-gradient(#000 80%, transparent); }
.wl-embed-body > :first-child { margin-top: 0; }
.wl-embed-body p { padding: 1px 0; }

/* placeholder: only on the focused empty line, like Notion */
.ProseMirror .is-empty.has-focus::before, .ProseMirror > .is-editor-empty:first-child::before {
  content: attr(data-placeholder); color: var(--text-4); float: left; height: 0; pointer-events: none;
}
.ProseMirror li .is-empty::before, .ProseMirror blockquote .is-empty.has-focus::before { content: none; }
.ProseMirror h1.is-empty::before, .ProseMirror h2.is-empty::before, .ProseMirror h3.is-empty::before {
  content: attr(data-placeholder); color: var(--text-4); float: left; height: 0; pointer-events: none;
}
.ProseMirror-gapcursor::after { border-top-color: var(--text); }
.ProseMirror .ProseMirror-dropcursor { background: var(--accent-soft); }

/* block handle */
.block-handle { display: flex; align-items: center; gap: 0; padding-right: 4px; transition: opacity .1s; }
.block-handle:not(.on) { opacity: 0; pointer-events: none; }
.block-handle button, .block-handle .bh-grip {
  display: grid; place-items: center; width: 24px; height: 24px; border: 0; background: none; border-radius: 4px;
  color: var(--text-4); cursor: pointer;
}
.block-handle .bh-grip { width: 18px; cursor: grab; }
.block-handle button:hover, .block-handle .bh-grip:hover { background: var(--bg-hover); color: var(--text-3); }
.block-handle svg { width: 17px; height: 17px; }
.markdown h1 + .block-handle, .ProseMirror .ProseMirror-selectednode { }

/* ---------- popups ---------- */
.pop, .menu {
  position: fixed; z-index: 80; background: var(--bg-elev); border-radius: 8px; box-shadow: var(--shadow);
  padding: 6px; max-height: min(380px, 50vh); overflow: auto; min-width: 220px;
}
.pop-slash { width: 300px; }
.pop-links { width: 320px; }
.pop-section { font-size: 12px; font-weight: 500; color: var(--text-3); padding: 6px 8px 4px; }
.pop-item, .menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: none; text-align: left;
  padding: 4px 8px; border-radius: 5px; cursor: pointer; font-size: 14px; min-height: 30px;
}
.pop-item.sel, .pop-item:hover, .menu-item:hover, .menu-item.sel { background: var(--bg-hover); }
.pop-slash .pop-icon {
  width: 42px; height: 42px; border-radius: 6px; border: 1px solid var(--border-strong); background: var(--bg);
  display: grid; place-items: center; flex: none;
}
.pop-slash .pop-icon svg { width: 22px; height: 22px; color: var(--text-2); }
.pop-links .pop-icon svg, .menu-item svg { width: 17px; height: 17px; color: var(--text-3); }
.pop-text { display: flex; flex-direction: column; min-width: 0; }
.pop-text small { font-size: 12px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pop-links .pop-text { flex-direction: row; align-items: baseline; gap: 8px; }
.pop-empty { padding: 8px; color: var(--text-3); font-size: 14px; }
.menu-item.danger { color: var(--red); }
.menu-item.danger svg { color: var(--red); }
.menu-sep { height: 1px; background: var(--border); margin: 5px -6px; }
.menu-item kbd { margin-left: auto; }

.bubble {
  display: flex; align-items: center; gap: 1px; padding: 3px; background: var(--bg-elev); border-radius: 7px;
  box-shadow: var(--shadow); z-index: 70;
}
.bubble button {
  display: inline-flex; align-items: center; gap: 4px; height: 28px; min-width: 28px; justify-content: center; padding: 0 6px;
  border: 0; background: none; border-radius: 4px; cursor: pointer; font-size: 14px; color: var(--text);
}
.bubble button:hover { background: var(--bg-hover); }
.bubble button.on { color: var(--accent); }
.bubble button svg { width: 16px; height: 16px; }
.bubble .bubble-turn svg:last-child { width: 12px; height: 12px; color: var(--text-3); }
.bubble-sep { width: 1px; align-self: stretch; background: var(--border-strong); margin: 3px 2px; }

/* ---------- tree ---------- */
.tree { font-size: 14px; user-select: none; -webkit-user-select: none; }
.tree-row {
  display: flex; align-items: center; gap: 4px; height: 30px; padding-right: 4px; border-radius: 6px; cursor: pointer;
  color: var(--text-2); font-weight: 500; position: relative;
}
.tree-row:hover { background: var(--bg-hover); }
.tree-row.active { background: var(--bg-active); color: var(--text); }
.tree-row.drop { box-shadow: inset 0 0 0 2px var(--accent); }
.tree-row .twisty { width: 22px; height: 22px; display: grid; place-items: center; border-radius: 4px; flex: none; color: var(--text-3); }
.tree-row .twisty:hover { background: var(--bg-active); }
.tree-row .twisty svg { width: 14px; height: 14px; transition: transform .12s; }
.tree-row.open .twisty svg { transform: rotate(90deg); }
.tree-row .ico { width: 18px; height: 18px; color: var(--text-3); }
.tree-row .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-row .ext { color: var(--text-3); font-size: 10px; font-weight: 600; border: 1px solid var(--border-strong); border-radius: 3px; padding: 0 3px; }
.tree-row .row-actions { display: none; gap: 1px; }
.tree-row:hover .row-actions { display: flex; }
.tree-empty { color: var(--text-3); font-size: 13px; padding: 4px 10px; }
.tree-children.closed { display: none; }
.tree-children:empty::after { content: "No pages inside"; display: block; color: var(--text-4); font-size: 13px; padding: 3px 0 3px var(--pad, 30px); }

.tag-list { padding: 2px 0; }
.tag-item { display: flex; align-items: center; gap: 8px; height: 28px; padding: 0 8px; border-radius: 6px; cursor: pointer; font-size: 14px; color: var(--text-2); }
.tag-item:hover { background: var(--bg-hover); }
.tag-item svg { width: 15px; height: 15px; color: var(--text-3); }
.tag-item span:first-of-type { flex: 1; }
.tag-item .count { color: var(--text-3); font-size: 12px; }

/* ---------- modals ---------- */
.modal { position: fixed; inset: 0; background: rgba(15, 15, 15, .4); display: flex; justify-content: center; align-items: flex-start; padding: 12vh 16px 16px; z-index: 60; }
.modal.center { align-items: center; padding-top: 16px; }
.modal-card { background: var(--bg-elev); border-radius: 10px; box-shadow: var(--shadow); width: 100%; overflow: hidden; }
.search-card { max-width: 620px; display: flex; flex-direction: column; max-height: 70vh; }
.search-input-row { display: flex; align-items: center; gap: 10px; padding: 0 14px; height: 52px; border-bottom: 1px solid var(--border); }
.search-input-row svg { color: var(--text-3); width: 20px; height: 20px; }
.search-input-row input { flex: 1; border: 0; outline: none; background: none; font-size: 17px; min-width: 0; }
.search-list { overflow: auto; padding: 6px; flex: 1; }
.search-group { font-size: 12px; font-weight: 500; color: var(--text-3); padding: 8px 10px 4px; }
.search-item { display: flex; align-items: flex-start; gap: 10px; padding: 7px 10px; border-radius: 6px; cursor: pointer; }
.search-item.sel { background: var(--bg-hover); }
.search-item svg { width: 18px; height: 18px; color: var(--text-3); margin-top: 1px; }
.search-item .si-main { min-width: 0; flex: 1; }
.search-item .si-title { font-size: 14px; font-weight: 500; }
.search-item .si-dir { font-size: 12px; color: var(--text-3); margin-left: 6px; font-weight: 400; }
.search-item .si-snip { font-size: 13px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 1px; }
.search-item mark { background: var(--mark); color: inherit; border-radius: 2px; }
.search-empty { padding: 28px 12px; text-align: center; color: var(--text-3); font-size: 14px; }
.search-foot { display: flex; gap: 16px; padding: 8px 14px; border-top: 1px solid var(--border); font-size: 12px; color: var(--text-3); }
.search-foot kbd { margin-right: 3px; }
.dialog-card { max-width: 420px; padding: 20px; }
.dialog-card p { margin: 0 0 14px; white-space: pre-wrap; font-size: 15px; }
.dialog-actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 90;
  background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 8px; font-size: 14px; max-width: calc(100% - 32px);
  box-shadow: var(--shadow);
}

/* ---------- graph ---------- */
.graph { position: fixed; inset: 0; background: var(--bg); z-index: 50; }
.graph canvas { width: 100%; height: 100%; display: block; touch-action: none; }
.graph-bar {
  position: absolute; top: calc(12px + env(safe-area-inset-top)); right: 12px; left: auto; display: flex; gap: 14px; align-items: center; flex-wrap: wrap;
  background: var(--bg-elev); box-shadow: var(--shadow); border-radius: 8px; padding: 4px 4px 4px 14px; font-size: 13px; color: var(--text-2);
}
.graph-bar label { display: flex; gap: 6px; align-items: center; cursor: pointer; }

/* ---------- mobile keyboard bar ---------- */
.kbbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 75; display: flex; overflow-x: auto; gap: 2px; padding: 5px 6px;
  background: var(--bg-elev); border-top: 1px solid var(--border-strong); scrollbar-width: none;
}
.kbbar::-webkit-scrollbar { display: none; }
.kbbar button { flex: none; width: 42px; height: 38px; border: 0; background: none; border-radius: 8px; display: grid; place-items: center; color: var(--text-2); font-size: 17px; }
.kbbar button:active { background: var(--bg-active); }
.kbbar svg { width: 21px; height: 21px; }

.scrim { display: none; }

/* ---------- phones and tablets ---------- */
@media (max-width: 900px) {
  .page { padding: 40px 48px 0; }
}
@media (max-width: 720px) {
  .sidebar {
    position: fixed; z-index: 40; top: 0; bottom: 0; left: 0; width: min(86vw, 320px); margin-left: 0 !important;
    transform: translateX(-102%); transition: transform .22s cubic-bezier(.2, .8, .2, 1); box-shadow: var(--shadow);
  }
  .app.side-open .sidebar { transform: none; }
  .app.side-open .scrim { display: block; position: fixed; inset: 0; background: rgba(15, 15, 15, .4); z-index: 35; }
  .open-side { display: inline-flex !important; }
  .ws-collapse { opacity: 1; }
  .side-item, .tree-row { height: 38px; font-size: 15px; }
  .side-item kbd { display: none; }
  .tree-row .row-actions { display: flex; }
  .side-head .icon-btn { opacity: 1; }
  .topbar { height: 48px; padding: 0 6px; }
  .topbar .icon-btn { width: 36px; height: 36px; }
  .crumb:not(.current), .crumb-sep { display: none; }
  .page { padding: 20px 20px 0; }
  .page-title { font-size: 32px; }
  .banner { margin-top: 0; }
  .meta-btn.ghost { opacity: 1; }
  .prop-key { width: 110px; }
  .block-handle { display: none !important; }
  .markdown pre { padding: 28px 16px 18px; }
  .search-card { max-height: 80vh; }
  .modal { padding-top: calc(10px + env(safe-area-inset-top)); }
  .search-foot { display: none; }
  .pop-slash, .pop-links { width: min(320px, calc(100vw - 16px)); }
  .save-status { display: none; }
}
@media (hover: none) {
  .ws-collapse, .side-head .icon-btn, .meta-btn.ghost { opacity: 1; }
}
