:root, [data-theme="dark"] {
  --bg: #191919;
  --bg-side: #202020;
  --bg-hover: #2c2c2c;
  --bg-active: #37352f22;
  --bg-input: #262626;
  --bg-modal: #252525;
  --border: #333;
  --border-strong: #4a4a4a;
  --text: #e8e6e3;
  --text-dim: #9b9b9b;
  --text-faint: #6f6f6f;
  --accent: #4f9cf9;
  --accent-soft: #4f9cf922;
  --danger: #eb5757;
  --danger-soft: #eb575722;
  --danger-border: #eb575755;
  --danger-text: #ff9a9a;
  --ok: #4caf7d;
  --code-bg: #1e2430;
  --code-inline: #f9a8d4;
  --on-accent: #0b1524;
  --selection: #3b5b8a;
  --scrollbar: #3a3a3a;
  --wash: #ffffff14;
  --tree-line: #ffffff0d;
  --blk-hover: #ffffff08;
  --file-hover: #333;
  --page-link-border: #4f9cf955;
  --page-link-hover: #4f9cf933;
  --login-glow: #22304a;
  --overlay: rgba(0,0,0,.6);
  --lightbox: rgba(0,0,0,.88);
  --hilite-preview: #4d451f;
  --radius: 8px;
  --shadow: 0 10px 40px rgba(0,0,0,.55), 0 0 0 1px var(--border);
  color-scheme: dark;
}

[data-theme="light"] {
  --bg: #ffffff;
  --bg-side: #f7f6f3;
  --bg-hover: #efeee9;
  --bg-active: #37352f14;
  --bg-input: #f1f0ec;
  --bg-modal: #ffffff;
  --border: #e3e2de;
  --border-strong: #cfcbc4;
  --text: #37352f;
  --text-dim: #6f6e69;
  --text-faint: #9b9a97;
  --accent: #2383e2;
  --accent-soft: #2383e21a;
  --danger: #e03e3e;
  --danger-soft: #e03e3e14;
  --danger-border: #e03e3e55;
  --danger-text: #c92a2a;
  --ok: #0f7b6c;
  --code-bg: #f1f1ef;
  --code-inline: #c41d7f;
  --on-accent: #ffffff;
  --selection: #b4d7ff;
  --scrollbar: #c8c6c0;
  --wash: rgba(0,0,0,.06);
  --tree-line: rgba(0,0,0,.08);
  --blk-hover: rgba(55,53,47,.06);
  --file-hover: #e8e7e3;
  --page-link-border: #2383e255;
  --page-link-hover: #2383e222;
  --login-glow: #d6e4f7;
  --overlay: rgba(15,15,15,.45);
  --lightbox: rgba(15,15,15,.82);
  --hilite-preview: #fdecc8;
  --shadow: 0 10px 40px rgba(15,15,15,.12), 0 0 0 1px var(--border);
  color-scheme: light;
}

* { box-sizing: border-box; margin: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 ui-sans-serif, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
a { color: var(--accent); }
kbd {
  background: var(--bg-hover); border: 1px solid var(--border); border-radius: 4px;
  padding: 0 5px; font-size: 11px; color: var(--text-dim);
}
::selection { background: var(--selection); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 5px; border: 2px solid var(--bg); }
::-webkit-scrollbar-track { background: transparent; }

.login-body { display: grid; place-items: center; background: radial-gradient(80vw 80vh at 70% -10%, var(--login-glow) 0%, var(--bg) 55%); }
.login-card {
  width: min(400px, 92vw); padding: 40px 36px; text-align: center;
  background: var(--bg-modal); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow);
}
.login-logo { display: block; width: min(280px, 88vw); height: auto; margin: 0 auto 12px; flex-shrink: 0; }
.login-sub { color: var(--text-dim); margin-bottom: 26px; font-size: 14px; }
.login-error {
  background: var(--danger-soft); border: 1px solid var(--danger-border); color: var(--danger-text);
  border-radius: var(--radius); padding: 8px 12px; margin-bottom: 16px; font-size: 13px;
}
.btn-exafan {
  display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%;
  padding: 12px 14px; border-radius: var(--radius); background: var(--accent); color: var(--on-accent);
  font-weight: 600; font-size: 15px; text-decoration: none; transition: filter .15s, transform .05s;
  box-shadow: 0 1px 2px rgba(0,0,0,.08);
}
.btn-exafan:hover { filter: brightness(1.08); }
.btn-exafan:active { transform: translateY(1px); }
.login-local { margin-top: 14px; text-align: left; }
.login-local > summary {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer; list-style: none;
  color: var(--text-dim); font-size: 13px; padding: 4px 0; user-select: none;
}
.login-local > summary::-webkit-details-marker { display: none; }
.login-local > summary svg { transition: transform .15s; }
.login-local[open] > summary svg { transform: rotate(180deg); }
.login-local > summary:hover { color: var(--text); }
.login-local .login-form { margin-top: 10px; }
.login-form { display: grid; gap: 10px; }
.login-form input {
  background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 12px; color: var(--text); outline: none;
}
.login-form input:focus { border-color: var(--accent); }
.login-form button {
  padding: 10px; border-radius: var(--radius); background: var(--accent); color: var(--on-accent); font-weight: 600;
}
.login-form button:hover { filter: brightness(1.1); }

.consent-lead { font-size: 14px; color: var(--text-dim); margin-bottom: 20px; text-align: left; }
.consent-form { gap: 12px; }
.consent-option {
  display: flex; gap: 10px; align-items: flex-start; text-align: left; cursor: pointer;
  background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px; font-size: 13px; color: var(--text-dim);
}
.consent-option:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.consent-option input { margin-top: 3px; accent-color: var(--accent); }
.consent-option b { color: var(--text); }
.consent-foot { margin-top: 18px; font-size: 12px; color: var(--text-faint); text-align: left; }

#app { display: flex; height: 100vh; }
#sidebar {
  width: 260px; min-width: 260px; background: var(--bg-side); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 8px; gap: 6px; transition: margin-left .2s;
}
#sidebar.hidden { margin-left: -260px; }
#btn-expand {
  position: fixed; left: 8px; top: 12px; z-index: 40; padding: 4px 9px; border-radius: 6px;
  background: var(--bg-hover); border: 1px solid var(--border); color: var(--text-dim);
}
.sb-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 8px; min-height: 40px; }
.sb-logo { display: block; height: 34px; width: auto; max-width: calc(100% - 36px); object-fit: contain; flex-shrink: 0; }
.icon-btn {
  padding: 2px 7px; border-radius: 6px; color: var(--text-dim); text-decoration: none; line-height: 1.4;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.sb-search {
  display: flex; align-items: center; justify-content: space-between; padding: 7px 10px; margin: 0 2px;
  background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text-dim); font-size: 13.5px;
}
.sb-search:hover { border-color: var(--border-strong); }
.sb-section { padding: 4px 2px; overflow-y: auto; }
.sb-grow { flex: 1; }
.sb-label {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px;
  color: var(--text-faint); padding: 4px 8px;
}
.sb-label .icon-btn { visibility: hidden; }
.sb-section:hover .sb-label .icon-btn { visibility: visible; }
.tree-item { position: relative; }
.tree-row {
  display: flex; align-items: center; gap: 4px; padding: 3px 6px; border-radius: 6px;
  cursor: pointer; color: var(--text-dim); font-size: 14px; user-select: none;
}
.tree-row:hover { background: var(--bg-hover); color: var(--text); }
.tree-row.active { background: var(--bg-hover); color: var(--text); font-weight: 500; }
.tree-row .caret {
  width: 18px; height: 18px; display: grid; place-items: center; border-radius: 4px;
  color: var(--text-faint); font-size: 10px; flex: none; transition: transform .12s;
}
.tree-row .caret:hover { background: var(--wash); color: var(--text); }
.tree-row .caret.open { transform: rotate(90deg); }
.tree-row .t-icon { flex: none; width: 20px; text-align: center; }
.tree-row .t-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-row .t-actions { display: none; gap: 2px; }
.tree-row:hover .t-actions { display: flex; }
.tree-kids { margin-left: 14px; border-left: 1px solid var(--tree-line); padding-left: 4px; }
.tree-row.drag-over { box-shadow: inset 0 0 0 1.5px var(--accent); }
.tree-row.drag-above { box-shadow: inset 0 2px 0 var(--accent); }
.tree-row.drag-below { box-shadow: inset 0 -2px 0 var(--accent); }
.sb-foot { border-top: 1px solid var(--border); padding-top: 6px; display: grid; gap: 2px; }
.sb-item {
  display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 6px;
  color: var(--text-dim); font-size: 14px; text-align: left;
}
.sb-item:hover { background: var(--bg-hover); color: var(--text); }
#btn-theme .theme-icon-light { display: none; }
[data-theme="light"] #btn-theme .theme-icon-dark { display: none; }
[data-theme="light"] #btn-theme .theme-icon-light { display: inline; }
.sb-user { display: flex; align-items: center; gap: 8px; padding: 6px 8px; }
.avatar {
  width: 26px; height: 26px; border-radius: 50%; background: linear-gradient(135deg, #4f9cf9, #7c5cff);
  display: grid; place-items: center; font-size: 12px; font-weight: 700; color: #fff; flex: none;
}
.sb-user-name { flex: 1; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 20px; border-bottom: 1px solid var(--border);
}
.topbar-left { display: flex; align-items: center; gap: 14px; min-width: 0; flex: 1; }
.top-logo { display: block; height: 32px; width: auto; flex-shrink: 0; object-fit: contain; }
#crumbs { display: flex; align-items: center; gap: 6px; font-size: 13.5px; color: var(--text-dim); overflow: hidden; min-width: 0; }
#crumbs .crumb { cursor: pointer; padding: 2px 6px; border-radius: 5px; white-space: nowrap; }
#crumbs .crumb:hover { background: var(--bg-hover); color: var(--text); }
#crumbs .crumb-sep { color: var(--text-faint); }
.top-actions { display: flex; align-items: center; gap: 4px; }
#save-state { font-size: 12.5px; color: var(--text-faint); margin-right: 6px; }
#btn-fav.on { color: #f5c518; }

#page-scroll { flex: 1; overflow-y: auto; }
#page { max-width: 780px; margin: 0 auto; padding: 40px 56px 30vh; }
#page-icon { font-size: 64px; line-height: 1; cursor: pointer; width: fit-content; border-radius: 10px; padding: 4px; min-height: 72px; }
#page-icon:hover { background: var(--bg-hover); }
#page-icon.empty { font-size: 14px; color: var(--text-faint); padding: 8px; min-height: 0; }
#page-title {
  font-size: 38px; font-weight: 700; letter-spacing: -1px; line-height: 1.2;
  outline: none; margin: 8px 0 4px; word-break: break-word;
}
[contenteditable][data-placeholder]:empty::before {
  content: attr(data-placeholder); color: var(--text-faint); pointer-events: none; display: block;
}
#page-meta { margin-top: 60px; padding-top: 12px; border-top: 1px solid var(--border); font-size: 12.5px; color: var(--text-faint); }

#editor { outline: none; min-height: 40vh; padding-top: 12px; font-size: 15.5px; }
#editor[data-readonly="1"] { pointer-events: auto; }
#editor > * { margin: 2px 0; padding: 3px 2px; border-radius: 4px; transition: background .12s; }
#editor > *.blk-hover { background: var(--blk-hover); }
#editor h1 { font-size: 30px; margin-top: 22px; letter-spacing: -.5px; }
#editor h2 { font-size: 24px; margin-top: 18px; letter-spacing: -.3px; }
#editor h3 { font-size: 19px; margin-top: 14px; }
#editor h4 { font-size: 16.5px; margin-top: 12px; font-weight: 650; }
#editor h5 { font-size: 15.5px; margin-top: 10px; font-weight: 650; color: var(--text-dim); }
#editor h6 { font-size: 14.5px; margin-top: 10px; font-weight: 650; color: var(--text-faint); text-transform: uppercase; letter-spacing: .4px; }
#editor ul, #editor ol { padding-left: 26px; }
#editor li { padding: 2px 0; }
#editor blockquote, .version-preview blockquote { border-left: 3px solid var(--text-dim); padding-left: 14px; color: var(--text-dim); }
#editor pre, .version-preview pre {
  background: var(--code-bg); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; overflow-x: auto; font: 13.5px/1.5 ui-monospace, "Cascadia Code", Consolas, monospace;
  white-space: pre-wrap;
}
#editor code:not(pre code), .version-preview code:not(pre code) {
  background: var(--code-bg); border: 1px solid var(--border); border-radius: 4px;
  padding: 1px 5px; font-size: .88em; color: var(--code-inline); font-family: ui-monospace, Consolas, monospace;
}
#editor hr, .version-preview hr { border: none; border-top: 1px solid var(--border); margin: 14px 0; }
#editor img { max-width: 100%; border-radius: var(--radius); display: block; cursor: zoom-in; }
#editor video, .version-preview video { max-width: 100%; border-radius: var(--radius); display: block; background: #000; }
#editor iframe.yt, .version-preview iframe.yt { width: 100%; aspect-ratio: 16/9; border: none; border-radius: var(--radius); display: block; }
#editor table, .version-preview table { border-collapse: collapse; width: 100%; margin: 8px 0; }
#editor td, #editor th, .version-preview td, .version-preview th { border: 1px solid var(--border); padding: 6px 10px; min-width: 60px; }
#editor th, .version-preview th { background: var(--bg-hover); text-align: left; }
#editor .todo, .version-preview .todo { display: flex; gap: 8px; align-items: baseline; list-style: none; }
#editor .todo input, .version-preview .todo input { accent-color: var(--accent); transform: translateY(2px); cursor: pointer; }
#editor .todo.done .todo-text, .version-preview .todo.done .todo-text { text-decoration: line-through; color: var(--text-faint); }
#editor .callout, .version-preview .callout {
  display: flex; gap: 10px; background: var(--bg-hover); border-radius: var(--radius);
  padding: 12px 14px; border: 1px solid var(--border);
}
#editor a.page-link, .version-preview a.page-link {
  text-decoration: none; background: var(--accent-soft); border-radius: 4px; padding: 1px 5px;
  color: var(--text); font-weight: 500; border-bottom: 1px solid var(--page-link-border); cursor: pointer;
}
#editor a.page-link:hover, .version-preview a.page-link:hover { background: var(--page-link-hover); }
#editor .file-card, .version-preview .file-card {
  display: flex; align-items: center; gap: 10px; background: var(--bg-hover);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px;
  color: var(--text); text-decoration: none; width: fit-content; max-width: 100%;
}
#editor .file-card:hover, .version-preview .file-card:hover { background: var(--file-hover); }
#editor .file-card .fc-size, .version-preview .file-card .fc-size { color: var(--text-faint); font-size: 12.5px; }

#home { max-width: 860px; margin: 0 auto; padding: 60px 40px; }
#home h1 { font-size: 32px; letter-spacing: -.8px; margin-bottom: 4px; }
#home .home-sub { color: var(--text-dim); margin-bottom: 34px; }
.home-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.home-card {
  background: var(--bg-side); border: 1px solid var(--border); border-radius: 10px;
  padding: 16px; cursor: pointer; transition: transform .1s, border-color .1s;
}
.home-card:hover { border-color: var(--border-strong); transform: translateY(-2px); }
.home-card .hc-icon { font-size: 26px; }
.home-card .hc-title { font-weight: 600; margin: 8px 0 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.home-card .hc-date { font-size: 12px; color: var(--text-faint); }
.home-label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .6px; color: var(--text-faint); margin: 30px 0 12px; }

#slash-menu, #ctx-menu {
  position: fixed; z-index: 60; min-width: 240px; max-height: min(420px, 70vh); overflow-y: auto;
  background: var(--bg-modal); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow); padding: 5px;
}
.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 7px 10px;
  border-radius: 6px; text-align: left; font-size: 14px;
}
.menu-item:hover, .menu-item.sel { background: var(--bg-hover); }
.menu-item .mi-icon { width: 24px; text-align: center; font-size: 16px; flex: none; }
.menu-item .mi-sub { display: block; font-size: 11.5px; color: var(--text-faint); }
.menu-item.danger { color: var(--danger); }
.menu-title { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-faint); padding: 6px 10px 2px; }

#fmt-bar {
  position: fixed; z-index: 60; display: none; gap: 1px; padding: 4px;
  background: var(--bg-modal); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow);
}
#fmt-bar:not([hidden]) { display: flex; }
#fmt-bar button { padding: 4px 9px; border-radius: 5px; font-size: 14px; color: var(--text-dim); }
#fmt-bar button:hover { background: var(--bg-hover); color: var(--text); }
#fmt-bar button.on { color: var(--accent); }

.modal-back {
  position: fixed; inset: 0; z-index: 70; background: var(--overlay);
  display: grid; place-items: start center; padding-top: 12vh;
}
.modal {
  width: min(560px, 92vw); background: var(--bg-modal); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow); max-height: 70vh; display: flex; flex-direction: column;
}
.modal.wide { width: min(720px, 96vw); max-height: 82vh; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px 0; }
.modal-head h3 { font-size: 16px; }
.modal-body { padding: 14px 18px 18px; overflow-y: auto; }
.modal input[type=text], .modal input[type=search], .modal select {
  width: 100%; background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 9px 12px; color: var(--text); outline: none; font: inherit;
}
.modal input:focus { border-color: var(--accent); }
.modal select { width: auto; padding: 5px 8px; font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; padding: 8px 4px; border-radius: 6px; }
.row:hover { background: var(--bg-hover); }
.row .r-main { flex: 1; min-width: 0; }
.row .r-title { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .r-sub { font-size: 12px; color: var(--text-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row.clickable { cursor: pointer; }
.row-indent { padding-left: 22px; }
.avatar.mini { width: 28px; height: 28px; font-size: 12px; flex: none; }
.access-toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.access-tree {
  border: 1px solid var(--border); border-radius: var(--radius);
  max-height: 48vh; overflow: auto; padding: 6px 0;
}
.access-row {
  display: flex; align-items: center; gap: 8px; padding: 6px 10px 6px 0;
  cursor: pointer; font-size: 13px;
}
.access-row:hover { background: var(--bg-hover); }
.access-row input { flex: none; }
.access-icon { flex: none; width: 1.4em; text-align: center; }
.access-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.check-list {
  border: 1px solid var(--border); border-radius: var(--radius);
  max-height: 28vh; overflow: auto; padding: 4px 0;
}
.check-row {
  display: flex; align-items: center; gap: 8px; padding: 7px 10px;
  cursor: pointer; font-size: 13px;
}
.check-row:hover { background: var(--bg-hover); }
.check-row input { flex: none; }
.pill {
  font-size: 11px; padding: 2px 8px; border-radius: 20px; border: 1px solid var(--border);
  color: var(--text-dim); flex: none;
}
.pill.admin { color: #f5c518; border-color: #f5c51844; }
.pill.off { color: var(--danger); border-color: var(--danger-border); }
.btn {
  padding: 7px 14px; border-radius: var(--radius); background: var(--accent); color: var(--on-accent);
  font-weight: 600; font-size: 13.5px;
}
.btn:hover { filter: brightness(1.1); }
.btn.ghost { background: var(--bg-hover); color: var(--text); }
.btn.danger-btn { background: transparent; color: var(--danger); border: 1px solid var(--danger-border); }
.seg { display: inline-flex; background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius); padding: 3px; gap: 3px; }
.seg button { padding: 5px 12px; border-radius: 6px; font-size: 13px; color: var(--text-dim); }
.seg button.on { background: var(--bg-hover); color: var(--text); }
.emoji-grid { display: grid; grid-template-columns: repeat(10, 1fr); gap: 2px; }
.emoji-grid button { font-size: 20px; padding: 5px; border-radius: 6px; }
.emoji-grid button:hover { background: var(--bg-hover); }
.muted { color: var(--text-faint); font-size: 13px; }
.token-setup {
  background: var(--bg-hover); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 14px; margin-bottom: 4px;
}
.token-setup .token-raw {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px; line-height: 1.4; word-break: break-all; user-select: all;
  background: var(--bg-input); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; color: var(--text);
}
.token-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; align-items: center; }
.token-actions .btn { text-decoration: none; display: inline-flex; align-items: center; }
.token-hint {
  margin-top: 10px; padding: 8px 10px; border-radius: 8px;
  background: var(--bg-input); border: 1px solid var(--border);
  color: var(--text-dim); font-size: 12.5px; line-height: 1.45;
}
.token-hint code { font-size: 11.5px; }
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 90;
  background: var(--bg-modal); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 18px; box-shadow: var(--shadow); font-size: 14px; animation: toast-in .18s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }

#editor details, .version-preview details {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 12px; margin: 6px 0;
}
#editor summary, .version-preview summary { cursor: pointer; font-weight: 600; padding: 2px 0; }
#editor summary::marker, .version-preview summary::marker { color: var(--text-dim); }
#editor mark, .version-preview mark { border-radius: 3px; padding: 0 1px; color: inherit; }

#block-bar {
  position: fixed; z-index: 55; display: none; gap: 2px; padding: 4px;
  background: var(--bg-modal); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow);
}
#block-bar:not([hidden]) { display: flex; }
#block-bar button { padding: 3px 9px; border-radius: 5px; font-size: 12.5px; color: var(--text-dim); white-space: nowrap; }
#block-bar button:hover { background: var(--bg-hover); color: var(--text); }
#block-bar button.danger { color: var(--danger); }

#blk-tools {
  position: fixed; z-index: 55; display: none; gap: 2px;
  padding: 6px 4px; border-radius: 8px;
}
#blk-tools:not([hidden]) { display: flex; }
#blk-tools button {
  width: 26px; height: 28px; border-radius: 5px; font-size: 14px; line-height: 1;
  color: var(--text-faint); display: flex; align-items: center; justify-content: center;
  background: var(--bg-modal); border: 1px solid var(--border);
}
#blk-tools button:hover { background: var(--bg-hover); color: var(--text); }
#blk-grab { cursor: grab; }
#blk-grab:active { cursor: grabbing; }
#blk-drop { position: fixed; z-index: 56; height: 2px; background: var(--accent); border-radius: 2px; pointer-events: none; }
#blk-drop[hidden] { display: none !important; }

#img-zoom {
  position: fixed; z-index: 57; display: none;
  gap: 6px; align-items: center;
  padding: 5px 10px; border-radius: 8px;
  background: var(--bg-modal); border: 1px solid var(--border); box-shadow: var(--shadow);
  color: var(--text); font-size: 12.5px; font-weight: 500; white-space: nowrap;
}
#img-zoom:not([hidden]) { display: inline-flex; }
#img-zoom:hover { background: var(--bg-hover); color: var(--accent); }

.img-lightbox {
  position: fixed; inset: 0; z-index: 80; background: var(--lightbox);
  display: grid; place-items: center; padding: 48px 24px; overflow: auto; cursor: zoom-out;
}
.img-lightbox img {
  display: block; max-width: none; max-height: none; width: auto; height: auto;
  border-radius: 4px; box-shadow: 0 12px 48px rgba(0,0,0,.55); cursor: default;
}
.img-lightbox-close {
  position: fixed; top: 14px; right: 14px; z-index: 81;
  width: 36px; height: 36px; border-radius: 8px;
  background: var(--bg-modal); border: 1px solid var(--border); color: var(--text);
  display: grid; place-items: center; font-size: 16px;
}
.img-lightbox-close:hover { background: var(--bg-hover); }
#editor > .blk-dragging { opacity: .4; }

.swatch-row { display: flex; gap: 4px; padding: 6px 10px; }
.swatch { width: 22px; height: 22px; border-radius: 5px; border: 1px solid var(--border); cursor: pointer; }
.swatch:hover { transform: scale(1.15); }
.swatch.none { display: grid; place-items: center; font-size: 11px; color: var(--text-dim); }
.fmt-color-btn { color: #d9730d; }
.fmt-hilite-preview {
  background: var(--hilite-preview); border-radius: 3px; padding: 0 3px; color: var(--text);
}

/* Tema: colores "por defecto" guardados en el HTML del editor */
[data-theme="light"] #editor font[color="#e8e6e3"],
[data-theme="light"] #editor [style*="color: rgb(232, 230, 227)"],
[data-theme="light"] #editor [style*="color:#e8e6e3"],
[data-theme="light"] #editor [style*="color: #e8e6e3"],
[data-theme="light"] .version-preview font[color="#e8e6e3"],
[data-theme="light"] .version-preview [style*="color: rgb(232, 230, 227)"],
[data-theme="light"] .version-preview [style*="color:#e8e6e3"],
[data-theme="light"] .version-preview [style*="color: #e8e6e3"] {
  color: inherit !important;
}
[data-theme="dark"] #editor font[color="#37352f"],
[data-theme="dark"] #editor [style*="color: rgb(55, 53, 47)"],
[data-theme="dark"] #editor [style*="color:#37352f"],
[data-theme="dark"] #editor [style*="color: #37352f"],
[data-theme="dark"] .version-preview font[color="#37352f"],
[data-theme="dark"] .version-preview [style*="color: rgb(55, 53, 47)"],
[data-theme="dark"] .version-preview [style*="color:#37352f"],
[data-theme="dark"] .version-preview [style*="color: #37352f"] {
  color: inherit !important;
}

#backlinks { margin-top: 50px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
#backlinks:empty { display: none; }
#backlinks .bl-label { font-size: 12.5px; color: var(--text-faint); margin-right: 4px; }
#backlinks .bl-chip {
  font-size: 13px; padding: 3px 10px; border-radius: 20px; background: var(--bg-hover);
  border: 1px solid var(--border); cursor: pointer; color: var(--text-dim);
}
#backlinks .bl-chip:hover { color: var(--text); border-color: var(--border-strong); }
#backlinks + #page-meta { margin-top: 16px; }

.comment-row { display: flex; gap: 10px; padding: 10px 4px; border-bottom: 1px solid var(--border); }
.comment-row:last-of-type { border-bottom: none; }
.comment-row .c-body { flex: 1; min-width: 0; }
.comment-row .c-head { display: flex; gap: 8px; align-items: baseline; }
.comment-row .c-name { font-weight: 600; font-size: 13.5px; }
.comment-row .c-date { font-size: 11.5px; color: var(--text-faint); }
.comment-row .c-text { font-size: 14px; white-space: pre-wrap; word-break: break-word; }
.comment-form { display: flex; gap: 8px; margin-top: 12px; }
.comment-form input { flex: 1; }

.version-preview {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-top: 10px;
  max-height: 45vh; overflow-y: auto; background: var(--bg);
}
.version-preview img, .version-preview video { max-width: 100%; }

@media print {
  #sidebar, #topbar, #btn-expand, #backlinks, #page-meta, #modal-root { display: none !important; }
  body, #app { background: #fff; color: #111; height: auto; }
  #page-scroll { overflow: visible; }
  #page { padding: 0; max-width: 100%; }
  #editor pre, #editor code:not(pre code) { background: #f3f3f3; color: #111; border-color: #ddd; }
  #editor blockquote { color: #444; border-color: #999; }
  #editor .callout { background: #f6f6f6; border-color: #ddd; }
  #editor a.page-link { background: none; border: none; color: #0645ad; }
}

@media (max-width: 760px) {
  #sidebar { position: fixed; z-index: 50; height: 100%; }
  #page { padding: 24px 18px 30vh; }
  #page-title { font-size: 30px; }
}
