/* ── Variables ─────────────────────────── */
:root {
  --bg:      #0d1117;
  --bg2:     #10161e;
  --bg3:     #0c1118;
  --border:  #1d2a3b;
  --border2: #253142;
  --text:    #e2eaf3;
  --muted:   #7a8fa6;
  --accent:  #4aa3ff;
  --accent2: #88c0ff;
  --sidebar: 16.25rem;
  --tabh:    2.25rem;
  --font:    "Klee One","Hiragino Sans","Yu Gothic UI",sans-serif;
  --mono:    "Cascadia Code","Consolas","Menlo",monospace;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 100%; line-height: 1.5; }
a { color: var(--accent2); }
button { font: inherit; cursor: pointer; background: none; border: none; color: inherit; padding: 0; }

/* ── Layout ────────────────────────────── */
.app {
  display: grid;
  grid-template-columns: var(--sidebar) 1fr;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ───────────────────────────── */
.sidebar {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  min-width: 7.5rem;
  max-width: 40rem;
  overflow: hidden;
}
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 0.75rem;
  height: var(--tabh);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sidebar-title {
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}
.sidebar-btn {
  padding: 0.1875rem 0.4375rem;
  border-radius: 0.375rem;
  color: var(--muted);
  font-size: 0.875rem;
  transition: background 0.1s;
}
.sidebar-btn:hover { background: rgba(255,255,255,0.07); color: var(--text); }
.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.25rem 0 0.5rem;
}
.sidebar-scroll::-webkit-scrollbar { width: 0.3125rem; }
.sidebar-scroll::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 0.1875rem; }
.sidebar-footer {
  flex-shrink: 0;
  padding: 0.5rem 0.625rem 0.625rem;
  border-top: 1px solid var(--border);
  background: rgba(12,17,24,0.96);
}
.sidebar-wide-btn {
  width: 100%;
  text-align: left;
  padding: 0.5rem 0.625rem;
  border-radius: 0.5rem;
  border: 1px solid var(--border2);
  background: rgba(255,255,255,0.04);
  color: var(--text);
  font-size: 0.8125rem;
}
.sidebar-wide-btn:hover {
  background: rgba(74,163,255,0.12);
  border-color: rgba(74,163,255,0.22);
}
.sidebar-dragger {
  position: absolute;
  top: 0; right: 0;
  width: 0.25rem;
  height: 100%;
  cursor: col-resize;
  z-index: 20;
}
.sidebar-dragger::after {
  content: '';
  display: block;
  width: 100%; height: 100%;
  background: transparent;
  transition: background 0.15s;
}
.sidebar-dragger:hover::after,
.sidebar-dragger.active::after { background: var(--accent); }

/* ── File tree ─────────────────────────── */
.tree { list-style: none; }
.tree .tree {
  margin-left: 0.875rem;
  padding-left: 0.625rem;
  border-left: 1px solid var(--border);
}
.tree-row {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.1875rem 0.5rem 0.1875rem 0.25rem;
  border-radius: 0.3125rem;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.tree-row:hover { background: rgba(255,255,255,0.05); }
.tree-row.sel { background: rgba(74,163,255,0.14); }
.tree-row[draggable="true"] { cursor: grab; }
.tree-row[draggable="true"]:active { cursor: grabbing; }
.tree-tog { width: 0.6875rem; font-size: 0.5625rem; color: var(--muted); flex-shrink: 0; text-align: center; }
.tree-ico { font-size: 0.75rem; flex-shrink: 0; }
.tree-lbl { font-size: 0.8125rem; overflow: hidden; text-overflow: ellipsis; }

/* ── Workspace ─────────────────────────── */
.workspace {
  display: flex;
  flex-direction: row;
  height: 100%;
  overflow: hidden;
}
.workspace.split-v,
.split-node.split-v { flex-direction: column; }
.split-node {
  display: flex;
  flex-direction: row;
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}
.pane-slot {
  display: flex;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

/* ── Panel ─────────────────────────────── */
.panel {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  position: relative;
}
.panel.focused { box-shadow: inset 0 0 0 1px rgba(74,163,255,0.22); }
.panel.panel-drop-center::after,
.panel.panel-drop-left::after,
.panel.panel-drop-right::after,
.panel.panel-drop-top::after,
.panel.panel-drop-bottom::after {
  content: '';
  position: absolute;
  inset: 0.5rem;
  border: 1px dashed rgba(136,192,255,0.55);
  background: rgba(74,163,255,0.08);
  pointer-events: none;
  z-index: 3;
}
.panel.panel-drop-left::after { inset: 0.5rem 60% 0.5rem 0.5rem; }
.panel.panel-drop-right::after { inset: 0.5rem 0.5rem 0.5rem 60%; }
.panel.panel-drop-top::after { inset: 0.5rem 0.5rem 60% 0.5rem; }
.panel.panel-drop-bottom::after { inset: 60% 0.5rem 0.5rem 0.5rem; }
.panel.panel-drop-center::after { inset: 1rem; }

/* ── Tab bar ───────────────────────────── */
.tabbar {
  display: flex;
  align-items: stretch;
  height: var(--tabh);
  background: var(--bg3);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  overflow-y: hidden;
  flex-shrink: 0;
  scrollbar-width: none;
}
.tabbar::-webkit-scrollbar { display: none; }
.tabbar.drop-over { background: rgba(74,163,255,0.07); outline: 1px dashed var(--accent); }
.tab {
  display: flex;
  align-items: center;
  gap: 0.3125rem;
  padding: 0 0.625rem;
  min-width: 4.375rem;
  max-width: 12.5rem;
  border-right: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.8125rem;
  cursor: pointer;
  flex-shrink: 0;
  white-space: nowrap;
  position: relative;
  transition: background 0.1s;
}
.tab:hover { background: rgba(255,255,255,0.04); color: var(--text); }
.tab.on {
  background: var(--bg);
  color: var(--text);
  border-top: 2px solid var(--accent);
}
.tab.drag-hi { background: rgba(74,163,255,0.18); }
.tab-lbl { overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0; }
.tab-x {
  flex-shrink: 0;
  width: 1rem; height: 1rem;
  display: flex; align-items: center; justify-content: center;
  border-radius: 0.25rem;
  font-size: 0.8125rem;
  color: var(--muted);
  opacity: 0;
  transition: opacity 0.1s, background 0.1s;
}
.tab:hover .tab-x, .tab.on .tab-x { opacity: 1; }
.tab-x:hover { background: rgba(255,255,255,0.13); color: var(--text); }
.tabbar-end {
  margin-left: auto;
  display: flex;
  align-items: center;
  padding: 0 0.375rem;
  gap: 0.125rem;
  flex-shrink: 0;
  border-left: 1px solid var(--border);
}
.tabbar-empty {
  display: flex;
  align-items: center;
  padding: 0 0.75rem;
  color: var(--muted);
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  white-space: nowrap;
}
.panel-btn {
  padding: 0.1875rem 0.5rem;
  border-radius: 0.3125rem;
  font-size: 0.6875rem;
  color: var(--muted);
  white-space: nowrap;
  transition: background 0.1s;
}
.panel-btn:hover { background: rgba(255,255,255,0.08); color: var(--text); }
.panel-btn:disabled { opacity: 0.3; cursor: default; }

/* ── Resize handle ─────────────────────── */
.pane-split {
  flex-shrink: 0;
  background: var(--border);
  transition: background 0.15s;
  position: relative;
}
.pane-split.split-h { width: 0.1875rem; cursor: col-resize; }
.pane-split.split-v { height: 0.1875rem; cursor: row-resize; }
.pane-split:hover, .pane-split.active { background: var(--accent); }
body.is-resizing-panels { cursor: default; }
body.is-resizing-panels .pane-split.split-h { cursor: col-resize; }
body.is-resizing-panels .pane-split.split-v { cursor: row-resize; }
body.is-resizing-panels * { user-select: none !important; }

/* ── Content area ──────────────────────── */
.content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  --content-scale: var(--tab-scale, 1);
  --content-font-size: calc(0.875rem * var(--content-scale));
  font-size: var(--content-font-size);
  padding: 1.6em 1.9em 3.4em;
  min-height: 0;
}
.content::-webkit-scrollbar { width: 0.45em; }
.content::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 0.24em; }
.zoom-badge {
  margin-left: 0.6em;
  padding: 0.15em 0.55em;
  border-radius: 999em;
  border: 1px solid var(--border2);
  background: rgba(255,255,255,0.03);
  color: var(--muted);
  font-size: 0.72em;
  font-family: var(--mono);
}
.panel-placeholder {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.6em;
  color: var(--muted);
  font-size: 0.95em;
}
.panel-placeholder .keys { font-size: 0.78em; opacity: 0.6; }
.panel-placeholder .icon { font-size: 2.2em; opacity: 0.3; line-height: 1; }

/* ── File header ───────────────────────── */
.f-head { margin-bottom: 1.3em; padding-bottom: 1em; border-bottom: 1px solid var(--border); }
.f-kind { font-size: 0.72em; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); margin-bottom: 0.22em; }
.f-name { font-size: 1.05em; font-weight: 600; margin-bottom: 0.32em; }
.f-path { font-size: 0.8em; font-family: var(--mono); color: var(--muted); background: rgba(255,255,255,0.04); border: 1px solid var(--border); border-radius: 0.36em; padding: 0.15em 0.55em; display: inline-block; }

/* ── Lint ──────────────────────────────── */
.lint-warn {
  background: rgba(255,160,60,0.07);
  border: 1px solid rgba(255,160,60,0.3);
  border-radius: 0.5em;
  padding: 0.65em 0.95em;
  margin-bottom: 1em;
  font-size: 0.88em;
  color: #ffc575;
}
.lint-warn ul { margin: 0.36em 0 0 1.2em; }

/* ── Source view ───────────────────────── */
details.src-wrap { margin-top: 1.85em; border-top: 1px solid var(--border); padding-top: 0.85em; }
details.src-wrap summary {
  list-style: none;
  cursor: pointer;
  font-size: 0.86em;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 0.35em;
  user-select: none;
}
details.src-wrap summary:hover { color: var(--text); }
details.src-wrap summary::before { content: '▶'; font-size: 0.72em; }
details.src-wrap[open] summary::before { content: '▼'; }
.src-pre {
  margin-top: 0.72em;
  background: #0a0f16;
  border: 1px solid var(--border);
  border-radius: 0.58em;
  padding: 1em 1.15em;
  font-size: 0.88em;
  font-family: var(--mono);
  white-space: pre;
  overflow-x: auto;
  line-height: 1.6;
}

/* ── Image view ────────────────────────── */
.img-wrap {
  display: flex;
  justify-content: center;
  padding: 1.15em;
  background: rgba(255,255,255,0.02);
  border: 1px solid var(--border);
  border-radius: 0.72em;
}
.img-wrap img { max-width: 100%; height: auto; border-radius: 0.45em; }

/* ── Rendered markdown ─────────────────── */
.rendered { line-height: 1.8; }
.rendered, .rendered * { user-select: none; -webkit-user-select: none; }
.rendered .nm-unit { cursor: text; }
.rendered .nm-unit.nm-unit-selected {
  background: rgba(74,163,255,0.22);
  box-shadow: inset 0 -0.08em 0 rgba(136,192,255,0.38);
}
.rendered .nm-unit.nm-unit-selected-start {
  border-top-left-radius: 0.22em;
  border-bottom-left-radius: 0.22em;
}
.rendered .nm-unit.nm-unit-selected-end {
  border-top-right-radius: 0.22em;
  border-bottom-right-radius: 0.22em;
}
.rendered h1,.rendered h2,.rendered h3,
.rendered h4,.rendered h5,.rendered h6 { margin: 1.4em 0 0.65em; line-height: 1.3; }
.rendered h1 { font-size: 1.55em; }
.rendered h2 { font-size: 1.25em; padding-bottom: 0.35em; border-bottom: 1px solid var(--border); }
.rendered h3 { font-size: 1.05em; }
.rendered p { margin: 0.7em 0; }
.rendered ul,.rendered ol { margin: 0.6em 0 0.6em 1.55em; }
.rendered li { margin: 0.22em 0; }
.rendered hr { border: none; border-top: 1px solid var(--border); margin: 1.4em 0; }
.rendered strong { font-weight: 700; }
.rendered em { font-style: italic; }
.rendered del { color: var(--muted); }
.rendered a { color: var(--accent2); }
.rendered .nm-blockquote,.rendered blockquote {
  border-left: 0.2em solid var(--border2);
  padding: 0.45em 1em; margin: 0.85em 0;
  color: var(--muted);
  background: rgba(255,255,255,0.02);
  border-radius: 0 0.5em 0.5em 0;
}
.rendered .nm-callout {
  margin: 0.9em 0;
  padding: 0.8em 1em;
  border-radius: 0.7em;
  border: 1px solid var(--border2);
}
.rendered .nm-callout-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.7em;
  height: 1.7em;
  margin-bottom: 0.45em;
  border-radius: 999px;
  font-weight: 700;
  line-height: 1;
}
.rendered .nm-callout > :first-child { margin-top: 0; }
.rendered .nm-callout > :last-child { margin-bottom: 0; }
.rendered .nm-callout-message {
  background: rgba(255, 214, 102, 0.08);
  border-color: rgba(255, 214, 102, 0.38);
}
.rendered .nm-callout-alert {
  background: rgba(255, 107, 107, 0.08);
  border-color: rgba(255, 107, 107, 0.42);
}
.rendered .nm-callout-display {
  background: rgba(255,255,255,0.02);
}
.rendered .nm-callout-correct {
  background: rgba(61, 214, 140, 0.08);
  border-color: rgba(61, 214, 140, 0.36);
}
.rendered .nm-callout-incorrect {
  background: rgba(255, 107, 107, 0.08);
  border-color: rgba(255, 107, 107, 0.42);
}
.rendered .nm-callout-badge-correct {
  background: rgba(61, 214, 140, 0.18);
  color: #79efb3;
  border: 1px solid rgba(61, 214, 140, 0.42);
}
.rendered .nm-callout-badge-incorrect {
  background: rgba(255, 107, 107, 0.18);
  color: #ff9f9f;
  border: 1px solid rgba(255, 107, 107, 0.42);
}
.rendered .nm-callout-display p {
  font-size: 1.06em;
  line-height: 1.7;
}
.rendered code,.rendered .nm-code-inline {
  font-family: var(--mono); font-size: 0.88em;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 0.36em; padding: 0.08em 0.42em;
}
.rendered .nm-code-container { border: 1px solid var(--border); border-radius: 0.72em; background: #101722; margin: 1.25em 0; overflow: hidden; }
.rendered .nm-code-header { display: flex; align-items: center; gap: 0.6em; padding: 0.45em 0.85em; background: rgba(255,255,255,0.03); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.rendered .nm-code-content { }
.rendered .nm-code { background: #0b1016; padding: 1em 1.15em; overflow-x: auto; margin: 0; font-family: var(--mono); font-size: 0.92em; line-height: 1.6; }
.rendered .nm-badge-main { display: inline-block; padding: 0.08em 0.58em; border-radius: 0.36em; background: var(--accent); color: #07111d; font-size: 0.78em; font-weight: 700; }
.rendered .nm-badge-flag { display: inline-block; padding: 0.08em 0.58em; border-radius: 0.36em; border: 1px solid var(--border2); color: var(--muted); font-size: 0.78em; }
.rendered .nm-table-wrap { overflow-x: auto; margin: 1.15em 0; }
.rendered .nm-table { border-collapse: collapse; width: 100%; font-size: 0.94em; }
.rendered .nm-table th,.rendered .nm-table td { border: 1px solid var(--border); padding: 0.45em 0.85em; text-align: left; }
.rendered .nm-table thead tr { background: rgba(74,163,255,0.07); }
.rendered .nm-image { max-width: 100%; border-radius: 0.5em; }
.rendered .nm-sec { padding: 0.6em 0 0.3em 1.15em; border-left: 0.15em solid var(--border); margin: 0.85em 0; }
.rendered ruby rt { font-size: 0.6em; color: var(--muted); line-height: 1; }
.rendered .nm-ruby { ruby-position: over; }
.rendered .nm-anno { ruby-position: under; }
.rendered .nm-anno-note + .nm-anno-note::before { content: ' / '; opacity: 0.5; }
.rendered .nm-frontmatter {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.35em 1em;
  padding: 0.55em 1em; margin-bottom: 1.15em;
  border-left: 0.2em solid var(--accent);
  background: rgba(74,163,255,0.05);
  border-radius: 0 0.58em 0.58em 0; font-size: 0.88em;
}
.rendered .nm-fm-meta { display: flex; flex-wrap: wrap; gap: 0.3em 0.85em; align-items: center; }
.rendered .nm-fm-field { display: inline-flex; align-items: center; gap: 0.22em; }
.rendered .nm-fm-key { color: var(--muted); }
.rendered .nm-fm-key::after { content: ':'; }
.rendered .nm-fm-val { color: var(--text); font-weight: 500; }
.rendered .nm-fm-tags { display: flex; flex-wrap: wrap; gap: 0.3em; }
.rendered .nm-fm-tag { background: rgba(74,163,255,0.12); border: 1px solid rgba(74,163,255,0.28); color: var(--accent2); border-radius: 999em; padding: 0.08em 0.65em; font-size: 0.8em; }
.rendered .nm-fm-sep { color: var(--muted); opacity: 0.6; }
.rendered .nm-internal-link { color: var(--accent2); text-decoration: underline; cursor: pointer; }
.rendered .math-display {
  display: inline-block;
  vertical-align: middle;
}
.rendered .math-display .katex-display {
  display: inline-block;
  margin: 0;
  text-align: left;
}
.rendered .math-block {
  display: block; padding: 0.72em; margin: 0.85em 0;
  background: rgba(255,255,255,0.025);
  border: 1px dashed var(--border2);
  border-radius: 0.58em; overflow-x: auto; text-align: center;
}
.rendered .nm-card-link {
  display: flex; flex-direction: column; align-items: flex-start; gap: 0.55em;
  border: 1px solid var(--border2); border-radius: 0.65em;
  padding: 0.85em 1em; margin: 0.72em 0;
  background: linear-gradient(180deg, rgba(255,255,255,0.03), rgba(255,255,255,0.015));
  color: var(--text); text-decoration: none;
  text-align: left;
}
.rendered .nm-card-link[draggable="true"],
.rendered .nm-internal-card[draggable="true"],
.rendered .nm-internal-link[draggable="true"] { cursor: grab; }
.rendered .nm-card-link:hover { border-color: var(--accent); background: rgba(74,163,255,0.04); }
.rendered .nm-card-url { font-size: 0.78em; color: var(--muted); font-family: var(--mono); word-break: break-all; }
.rendered .nm-internal-card {
  display: flex; flex-direction: column; align-items: flex-start; gap: 0.48em;
  border: 1px solid var(--border2); border-radius: 0.65em;
  padding: 0.85em 1em; margin: 0.72em 0;
  background: linear-gradient(180deg, rgba(255,255,255,0.03), rgba(255,255,255,0.015));
  color: var(--text); text-decoration: none; cursor: pointer;
  text-align: left;
}
.rendered .nm-internal-card:hover { border-color: var(--accent); background: rgba(74,163,255,0.05); }
.rendered .nm-internal-card.nm-card-disabled {
  border-color: rgba(255,180,120,0.24);
  background: rgba(255,180,120,0.04);
  color: var(--text);
  cursor: not-allowed;
}
.rendered .nm-internal-card.nm-card-disabled:hover {
  border-color: rgba(255,180,120,0.34);
  background: rgba(255,180,120,0.07);
}
.rendered .nm-card-head {
  display: flex;
  width: 100%;
  justify-content: space-between;
  gap: 0.75em;
  align-items: flex-start;
}
.rendered .nm-card-main {
  display: flex;
  flex-direction: column;
  gap: 0.18em;
  min-width: 0;
}
.rendered .nm-card-title {
  font-weight: 600;
  font-size: 1em;
  line-height: 1.35;
}
.rendered .nm-card-type {
  font-size: 0.72em;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}
.rendered .nm-card-desc {
  font-size: 0.86em;
  line-height: 1.55;
  color: #c7d3e0;
}
.rendered .nm-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.38em;
  align-items: center;
}
.rendered .nm-card-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.12em 0.58em;
  border-radius: 999em;
  border: 1px solid var(--border2);
  background: rgba(255,255,255,0.035);
  color: var(--muted);
  font-size: 0.74em;
  line-height: 1.4;
}
.rendered .nm-card-badge.status-active {
  color: #7ee787;
  border-color: rgba(46,160,67,0.5);
  background: rgba(46,160,67,0.1);
}
.rendered .nm-card-badge.status-draft {
  color: #f2cc60;
  border-color: rgba(242,204,96,0.45);
  background: rgba(242,204,96,0.08);
}
.rendered .nm-card-badge.status-disabled {
  color: #ffb86b;
  border-color: rgba(255,184,107,0.45);
  background: rgba(255,184,107,0.08);
}
.rendered .nm-card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3em;
}
.rendered .nm-card-prereqs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.32em;
  margin-top: 0.45em;
}
.rendered .nm-card-prereq {
  background: rgba(255,255,255,0.045);
  border: 1px solid rgba(255,255,255,0.12);
  color: var(--muted);
  border-radius: 999em;
  padding: 0.08em 0.62em;
  font-size: 0.75em;
}
.rendered .nm-card-tag {
  background: rgba(74,163,255,0.12);
  border: 1px solid rgba(74,163,255,0.28);
  color: var(--accent2);
  border-radius: 999em;
  padding: 0.08em 0.65em;
  font-size: 0.76em;
}
.nm-unwritten-badge {
  display: inline-block; margin-left: 0.45em;
  padding: 0.08em 0.55em; border-radius: 0.36em;
  background: rgba(255,160,60,0.14); border: 1px solid rgba(255,160,60,0.4);
  color: #ffa03c; font-size: 0.8em; font-weight: 700;
}
.rendered .nm-footnotes { font-size: 0.94em; border-top: 1px solid var(--border); margin-top: 2em; padding-top: 1em; }
/* ── Context menu ──────────────────────────────── */
#ctx-menu, #tree-ctx-menu, #tab-ctx-menu {
  position: fixed; z-index: 9999;
  background: rgba(16,22,30,0.98); border: 1px solid var(--border2);
  border-radius: 0.5rem; padding: 0.25rem; min-width: 12.5rem;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  backdrop-filter: blur(0.5rem);
  display: none;
}
#ctx-menu.show, #tree-ctx-menu.show, #tab-ctx-menu.show { display: block; }
.ctx-item {
  padding: 0.375rem 0.75rem; border-radius: 0.3125rem; cursor: pointer;
  font-size: 0.8125rem; color: var(--text); white-space: nowrap;
  background: rgba(12,17,24,0.92);
  border: 1px solid rgba(255,255,255,0.07);
}
.ctx-item:hover { background: rgba(74,163,255,0.16); border-color: rgba(74,163,255,0.22); }
.ctx-item.disabled { opacity: 0.4; pointer-events: none; }
.ctx-sep { height: 1px; background: var(--border); margin: 0.25rem 0; }

/* ── Change notifications ─────────────────────────── */
.notify-stack {
  position: fixed;
  top: 0.875rem;
  right: 0.875rem;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: 22.5rem;
}
.notify-card {
  border: 1px solid var(--border2);
  background: rgba(12,17,24,0.96);
  border-radius: 0.625rem;
  padding: 0.625rem 0.75rem;
  box-shadow: 0 10px 30px rgba(0,0,0,0.28);
  cursor: pointer;
}
.notify-card:hover { border-color: var(--accent); }
.notify-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
}
.notify-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.625rem;
  margin-bottom: 0.375rem;
}
.notify-dismiss {
  flex-shrink: 0;
  width: 1.5rem;
  height: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.35rem;
  color: var(--muted);
}
.notify-dismiss:hover {
  background: rgba(255,255,255,0.08);
  color: var(--text);
}
.notify-kind {
  font-size: 0.625rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent2);
}
.notify-path {
  font-family: var(--mono);
  font-size: 0.6875rem;
  color: var(--text);
  word-break: break-all;
}
.notify-meta {
  margin-top: 0.375rem;
  display: flex;
  gap: 0.5rem;
  font-size: 0.6875rem;
}
.notify-add { color: #7ee787; }
.notify-del { color: #ff7b72; }

/* ── Diff view ────────────────────────────────────── */
.diff-wrap {
  margin: 1.3em 0 1.7em;
  border: 1px solid var(--border);
  border-radius: 0.72em;
  overflow: hidden;
  background: #0a1016;
}
.diff-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.85em;
  padding: 0.72em 1em;
  border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,0.02);
}
.diff-title {
  font-size: 0.86em;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.diff-meta {
  display: flex;
  gap: 0.58em;
  font-size: 0.8em;
  align-items: center;
}
.diff-check {
  padding: 0.3em 0.75em;
  border: 1px solid var(--border2);
  border-radius: 0.5em;
  background: rgba(255,255,255,0.03);
  color: var(--muted);
  font-size: 1em;
  cursor: pointer;
}
.diff-check:hover {
  color: var(--text);
  border-color: var(--accent);
  background: rgba(74,163,255,0.10);
}
.diff-body {
  overflow-x: auto;
  font-size: 0.88em;
  line-height: 1.6;
  display: flex;
  flex-direction: column;
  gap: 1em;
  padding: 1em;
}
.diff-hunk {
  border: 1px solid var(--border);
  border-radius: 0.75em;
  overflow: hidden;
  background: rgba(255,255,255,0.02);
}
.diff-hunk-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75em;
  padding: 0.72em 1em;
  border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,0.03);
}
.diff-hunk-title {
  font-size: 0.82em;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}
.diff-hunk-meta {
  font-size: 0.8em;
  color: var(--muted);
}
.diff-pane {
  padding: 0.8em 1em 0.95em;
  border-top: 1px solid rgba(255,255,255,0.04);
}
.diff-pane.before {
  background: rgba(248,81,73,0.05);
}
.diff-pane.after {
  background: rgba(46,160,67,0.06);
}
.diff-pane.context {
  background: rgba(255,255,255,0.01);
}
.diff-pane-head {
  display: flex;
  align-items: center;
  gap: 0.6em;
  margin-bottom: 0.55em;
  font-size: 0.78em;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.diff-pane.before .diff-pane-head { color: #ffaba3; }
.diff-pane.after .diff-pane-head { color: #7ee787; }
.diff-pane.context .diff-pane-head { color: var(--muted); }
.diff-pane-lines {
  display: flex;
  flex-direction: column;
  gap: 0.4em;
}
.diff-line {
  display: grid;
  grid-template-columns: 2.2em 1fr;
  align-items: start;
}
.diff-mark {
  color: var(--muted);
  user-select: none;
  padding-top: 0.15em;
}
.diff-render {
  min-width: 0;
}
.diff-render.rendered {
  padding: 0.2em 0;
}
.diff-render.rendered > :first-child { margin-top: 0; }
.diff-render.rendered > :last-child { margin-bottom: 0; }
.diff-render.structured {
  white-space: pre-wrap;
  font-family: var(--mono);
  font-size: 0.92em;
  color: #d9e2ee;
}
.diff-render.structured .diff-struct-key {
  color: var(--accent2);
}
.diff-render.structured .diff-struct-sep {
  color: var(--muted);
}
.diff-render.structured .diff-struct-value {
  color: var(--text);
}
.diff-render .nm-unit.nm-diff-unit-add {
  background: rgba(46,160,67,0.52);
  box-shadow: 0 0 0 1px rgba(126,231,135,0.35);
  border-radius: 0.18em;
}
.diff-render .nm-unit.nm-diff-unit-del {
  background: rgba(248,81,73,0.5);
  box-shadow: 0 0 0 1px rgba(255,123,114,0.35);
  border-radius: 0.18em;
}
.diff-expand-wrap {
  padding: 0.2em 0;
  display: flex;
  justify-content: center;
}
.diff-expand {
  padding: 0.38em 0.9em;
  border: 1px solid var(--border2);
  border-radius: 999em;
  background: rgba(255,255,255,0.03);
  color: var(--muted);
  font-size: 0.84em;
  cursor: pointer;
}
.diff-expand:hover {
  color: var(--text);
  border-color: var(--accent);
  background: rgba(74,163,255,0.1);
}
.diff-empty {
  padding: 1em;
  color: var(--muted);
  font-size: 0.88em;
}
.file-actions {
  margin: 0 0 1em;
  display: flex;
  gap: 0.58em;
  flex-wrap: wrap;
}
.file-toggle {
  padding: 0.38em 0.75em;
  border: 1px solid var(--border2);
  border-radius: 0.5em;
  background: rgba(255,255,255,0.03);
  color: var(--muted);
  font-size: 0.88em;
  cursor: pointer;
}
.file-toggle.on {
  color: var(--text);
  border-color: var(--accent);
  background: rgba(74,163,255,0.12);
}

/* ── Publish static page ───────────────── */
.publish-static-page {
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(74,163,255,0.08), transparent 34%),
    linear-gradient(180deg, #0d1117 0%, #10161e 100%);
  color: var(--text);
}
.publish-static-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.1rem 1.5rem 0.8rem;
  border-bottom: 1px solid var(--border);
  background: rgba(12,17,24,0.9);
  backdrop-filter: blur(10px);
}
.publish-static-brand {
  color: var(--text);
  text-decoration: none;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.publish-static-path {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--muted);
}
.publish-static-layout {
  display: grid;
  grid-template-columns: minmax(16rem, 19rem) minmax(0, 1fr);
  gap: 0;
  min-height: calc(100vh - 4rem);
}
.publish-static-sidebar {
  border-right: 1px solid var(--border);
  background: rgba(16,22,30,0.88);
  padding: 1rem 0.9rem 1.25rem;
  overflow: auto;
}
.publish-static-sidebar-title {
  margin-bottom: 0.8rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}
.publish-static-nav {
  font-size: 0.87rem;
}
.publish-static-tree {
  list-style: none;
  margin: 0;
  padding: 0;
}
.publish-static-tree .publish-static-tree {
  margin-left: 0.9rem;
  padding-left: 0.7rem;
  border-left: 1px solid var(--border);
}
.publish-static-tree-dir,
.publish-static-tree-file {
  margin: 0.14rem 0;
}
.publish-static-tree details > summary {
  cursor: pointer;
  color: var(--text);
  padding: 0.18rem 0.3rem;
  border-radius: 0.35rem;
}
.publish-static-tree details > summary:hover {
  background: rgba(255,255,255,0.05);
}
.publish-static-link {
  display: block;
  padding: 0.22rem 0.38rem;
  border-radius: 0.38rem;
  color: var(--accent2);
  text-decoration: none;
}
.publish-static-link:hover {
  background: rgba(74,163,255,0.12);
}
.publish-static-link.is-current {
  color: var(--text);
  background: rgba(74,163,255,0.18);
  border: 1px solid rgba(74,163,255,0.22);
}
.publish-static-main {
  min-width: 0;
  padding: 1.5rem 1.8rem 3rem;
}
.publish-static-article {
  max-width: 68rem;
}
.publish-static-kicker {
  margin-bottom: 0.35rem;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}
.publish-static-title {
  margin: 0;
  font-size: clamp(1.7rem, 3vw, 2.45rem);
  line-height: 1.15;
}
.publish-static-article-path {
  margin: 0.75rem 0 1.4rem;
  display: inline-block;
  padding: 0.28rem 0.62rem;
  border-radius: 0.45rem;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.04);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.8rem;
}
.publish-static-rendered {
  font-size: 1rem;
}
.publish-static-rendered,
.publish-static-rendered * {
  user-select: text;
  -webkit-user-select: text;
}
.publish-static-rendered .nm-unit {
  cursor: auto;
}
body.publish-enhanced #publish-static-page {
  display: none;
}
body.publish-enhanced #bemstudy-app-shell {
  display: block;
}
@media (max-width: 880px) {
  .publish-static-layout {
    grid-template-columns: 1fr;
  }
  .publish-static-sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 40vh;
  }
  .publish-static-main {
    padding: 1.1rem 1rem 2rem;
  }
  .publish-static-header {
    flex-direction: column;
    align-items: flex-start;
  }
}