/* Cortex v2 — Precision Editorial Studio.
   One signature accent, disciplined tonal layering, crisp hairline depth,
   and first-class Dark, Warm Light, System, and Atlas parchment modes. */

/* impeccable-disable monotonous-spacing: --s1 is the 4px base of this
   project's spacing scale; sections use the 8–48px steps. */
:root {
  color-scheme: dark;

  --bg: #08090c;
  --canvas-bg: #07080b;
  --surface: #0f1116;
  --surface-2: #161920;
  --surface-3: #1e222b;
  --surface-elevated: #14171e;
  --line: #232731;
  --line-subtle: rgba(255, 255, 255, 0.06);
  --line-strong: #373e4d;

  --ink: #eef0f4;
  --ink-2: #b4bac6;
  --ink-3: #8c93a1;
  --prose-ink: #d9dde5;

  --accent: #ffd9a0;
  --accent-hover: #ffe5bd;
  --accent-soft: rgba(255, 217, 160, 0.11);
  --accent-line: rgba(255, 217, 160, 0.34);
  --accent-ink: #1a1206;

  --danger: #e48e7b;
  --danger-soft: rgba(228, 142, 123, 0.12);
  --danger-line: rgba(228, 142, 123, 0.42);

  --info: #89b4fa;
  --info-soft: rgba(137, 180, 250, 0.10);
  --info-line: rgba(137, 180, 250, 0.34);

  --tip: #94e2d5;
  --tip-soft: rgba(148, 226, 213, 0.10);
  --tip-line: rgba(148, 226, 213, 0.34);

  --warn: #f9c97c;
  --warn-soft: rgba(249, 201, 124, 0.11);
  --warn-line: rgba(249, 201, 124, 0.38);

  --scrim: rgba(5, 6, 9, 0.68);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.28);
  --shadow-md: 0 12px 36px rgba(0, 0, 0, 0.44);
  --shadow-lg: 0 28px 72px rgba(0, 0, 0, 0.56);

  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, ui-serif, serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;
  --s7: 48px;

  --r-sm: 4px;
  --r: 6px;
  --r-lg: 10px;

  --toolbar-h: 50px;
  --dock-h: 0px;
  --target-size: 24px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --sidebar-w: 236px;
  --notes-list-w: 272px;
  --notes-inspector-w: 296px;
  --left: 0px;
  --panel-w: 460px;
  --ease: cubic-bezier(0.2, 0.7, 0.3, 1);

  accent-color: var(--accent);
}

:root:has(> head > meta[name="color-scheme"][content="light dark"]) {
  color-scheme: light dark;
}
:root:has(> head > meta[name="color-scheme"][content="light"]) {
  color-scheme: light;
}
:root:has(> head > meta[name="color-scheme"][content="dark"]) {
  color-scheme: dark;
}

/* Warm Light studio theme (explicit or via System preference). */
:root[data-theme="light"] {
  color-scheme: light;

  --bg: #f5f1e8;
  --surface: #fbf8f2;
  --surface-2: #efe9dc;
  --surface-3: #e3dac7;
  --surface-elevated: #fffdf8;
  --line: #ddd3bf;
  --line-subtle: rgba(45, 36, 22, 0.06);
  --line-strong: #bfb299;

  --ink: #1e1912;
  --ink-2: #4a4031;
  --ink-3: #685b48;
  --prose-ink: #2c2419;

  --accent: #9a4b16;
  --accent-hover: #7f3c10;
  --accent-soft: rgba(154, 75, 22, 0.10);
  --accent-line: rgba(154, 75, 22, 0.34);
  --accent-ink: #fffaf2;

  --danger: #b03a28;
  --danger-soft: rgba(176, 58, 40, 0.10);
  --danger-line: rgba(176, 58, 40, 0.38);

  --info: #2563eb;
  --info-soft: rgba(37, 99, 235, 0.08);
  --info-line: rgba(37, 99, 235, 0.30);

  --tip: #0d7a68;
  --tip-soft: rgba(13, 122, 104, 0.08);
  --tip-line: rgba(13, 122, 104, 0.30);

  --warn: #b45309;
  --warn-soft: rgba(180, 83, 9, 0.09);
  --warn-line: rgba(180, 83, 9, 0.34);

  --scrim: rgba(26, 21, 14, 0.42);
  --shadow-sm: 0 2px 8px rgba(32, 24, 12, 0.08);
  --shadow-md: 0 12px 32px rgba(32, 24, 12, 0.14);
  --shadow-lg: 0 24px 64px rgba(32, 24, 12, 0.20);
}

@media (prefers-color-scheme: light) {
  :root[data-theme="system"] {
    --bg: #f5f1e8;
    --surface: #fbf8f2;
    --surface-2: #efe9dc;
    --surface-3: #e3dac7;
    --surface-elevated: #fffdf8;
    --line: #ddd3bf;
    --line-subtle: rgba(45, 36, 22, 0.06);
    --line-strong: #bfb299;

    --ink: #1e1912;
    --ink-2: #4a4031;
    --ink-3: #685b48;
    --prose-ink: #2c2419;

    --accent: #9a4b16;
    --accent-hover: #7f3c10;
    --accent-soft: rgba(154, 75, 22, 0.10);
    --accent-line: rgba(154, 75, 22, 0.34);
    --accent-ink: #fffaf2;

    --danger: #b03a28;
    --danger-soft: rgba(176, 58, 40, 0.10);
    --danger-line: rgba(176, 58, 40, 0.38);

    --scrim: rgba(26, 21, 14, 0.42);
    --shadow-sm: 0 2px 8px rgba(32, 24, 12, 0.08);
    --shadow-md: 0 12px 32px rgba(32, 24, 12, 0.14);
    --shadow-lg: 0 24px 64px rgba(32, 24, 12, 0.20);
  }
}

/* Theme toggle icon branches purely in CSS so icon matches rendered theme without flash. */
.theme-icon-moon { display: none; }
.theme-icon-sun { display: block; }
:root[data-theme="light"] .theme-icon-sun { display: none; }
:root[data-theme="light"] .theme-icon-moon { display: block; }
@media (prefers-color-scheme: light) {
  :root[data-theme="system"] .theme-icon-sun { display: none; }
  :root[data-theme="system"] .theme-icon-moon { display: block; }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

body.is-resizing {
  user-select: none;
  cursor: col-resize;
}
body.is-resizing #stage,
body.is-resizing #atlas {
  pointer-events: none;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

b, strong { font-weight: 600; }
code, kbd {
  font-family: var(--mono);
  font-size: 0.9em;
}
kbd {
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  padding: 1px 5px;
  background: var(--surface-2);
  color: var(--ink-3);
}

/* Tabler paths are inline in index.html; one optical size across the chrome. */
.icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon {
  width: 16px;
  height: 16px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.85;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* The 3D WebGL stage keeps its deep obsidian backdrop for star/fibre luminance. */
#stage {
  position: fixed;
  top: var(--toolbar-h);
  left: var(--left);
  width: calc(100vw - var(--left));
  height: calc(100svh - var(--toolbar-h) - var(--dock-h));
  display: block;
  background: var(--canvas-bg);
  cursor: grab;
  touch-action: none;
}
#stage:active { cursor: grabbing; }

.labels {
  position: fixed;
  top: var(--toolbar-h);
  left: var(--left);
  right: 0;
  bottom: var(--dock-h);
  pointer-events: none;
  overflow: hidden;
  z-index: 1;
}

/* ---------- boot ---------- */
.boot {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  background: var(--bg);
  transition: opacity 380ms var(--ease), visibility 380ms;
}
.boot.is-done { opacity: 0; visibility: hidden; }
.boot-status {
  margin: 0;
  font-size: 13px;
  color: var(--ink-3);
}
.boot-status::after {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-left: 8px;
  border-radius: 50%;
  background: var(--accent);
  vertical-align: 1px;
}

/* ---------- toolbar ---------- */
.toolbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--toolbar-h);
  z-index: 30;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: var(--s3);
  padding: 0 var(--s3);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.toolbar-left {
  display: flex;
  align-items: center;
  gap: var(--s1);
  min-width: 0;
}

.sidebar-toggle.is-active {
  color: var(--ink);
  background: var(--surface-2);
}

.vault-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  max-width: 240px;
  padding: 5px var(--s2);
  border: 0;
  border-radius: var(--r);
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 140ms var(--ease);
}
.vault-button:hover { background: var(--surface-2); }
.vault-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.vault-path {
  display: none;
}
.vault-caret {
  display: inline-flex;
  flex: none;
  align-items: center;
  color: var(--ink-3);
}
.vault-caret .icon { width: 13px; height: 13px; }
.brand-mark {
  width: 22px;
  height: 22px;
  border-radius: 5px;
  flex: none;
  display: block;
}

.views {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line-subtle);
  border-radius: var(--r);
  background: var(--bg);
}
.view {
  appearance: none;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--ink-3);
  font-family: var(--sans);
  font-size: 12.5px;
  font-weight: 500;
  padding: 5px 11px;
  cursor: pointer;
  transition: color 140ms var(--ease), background 140ms var(--ease);
}
.view-icon { display: none; }
#mobile-more-btn { display: none; }
.view:hover { color: var(--ink); }
.view.is-active {
  color: var(--ink);
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--line);
}

.toolbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--s1);
  min-width: 0;
}

.toolbar-more {
  position: relative;
  display: inline-flex;
  align-items: center;
}
.toolbar-more-btn {
  position: relative;
}
.toolbar-more-btn.has-tour-dot::after {
  content: "";
  position: absolute;
  top: 5px;
  right: 5px;
  width: 5px;
  height: 5px;
  border-radius: 999px;
  background: var(--accent);
  pointer-events: none;
}
.toolbar-more-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 60;
  min-width: 228px;
  padding: 5px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-lg);
  background: var(--surface-elevated);
  box-shadow: var(--shadow-lg);
  display: grid;
  gap: 2px;
}
.toolbar-more-item {
  appearance: none;
  display: flex;
  align-items: center;
  gap: var(--s2);
  width: 100%;
  min-height: 32px;
  padding: 6px 10px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--ink-2);
  font-family: var(--sans);
  font-size: 12.5px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background 120ms var(--ease), color 120ms var(--ease);
}
.toolbar-more-item .icon {
  width: 15px;
  height: 15px;
  color: var(--ink-3);
}
.toolbar-more-item kbd {
  margin-left: auto;
  font-size: 10.5px;
}
@media (hover: hover) {
  .toolbar-more-item:hover {
    background: var(--surface-2);
    color: var(--ink);
  }
  .toolbar-more-item:hover .icon {
    color: var(--ink);
  }
}
.toolbar-more-sep {
  height: 1px;
  margin: 4px 6px;
  background: var(--line);
}

.search-button {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  height: 28px;
  padding: 0 var(--s2);
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--bg);
  color: var(--ink-3);
  font-family: var(--sans);
  font-size: 12px;
  cursor: pointer;
  transition: color 140ms var(--ease), border-color 140ms var(--ease), background 140ms var(--ease);
}
.search-button .icon { width: 14px; height: 14px; }
.search-button:hover { color: var(--ink); border-color: var(--line-strong); background: var(--surface-2); }
.search-button kbd { font-size: 11px; }

.open-vault-button {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 var(--s2);
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--bg);
  color: var(--ink-2);
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: color 140ms var(--ease), border-color 140ms var(--ease), background 140ms var(--ease);
}
.open-vault-button[hidden] { display: none; }
.open-vault-button .icon { width: 14px; height: 14px; }
@media (hover: hover) {
  .open-vault-button:hover {
    color: var(--ink);
    border-color: var(--line-strong);
    background: var(--surface-2);
  }
}

.icon-button {
  appearance: none;
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: var(--r);
  padding: 0;
  background: transparent;
  color: var(--ink-2);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  transition: background 140ms var(--ease), color 140ms var(--ease);
}
.icon-button .icon { width: 15px; height: 15px; }
.icon-button:hover:not(:disabled) { background: var(--surface-2); color: var(--ink); }
.icon-button:disabled { opacity: 0.32; cursor: default; }

/* ---------- quiet bottom-left canvas status pill ---------- */
.canvas-status {
  position: fixed;
  left: calc(var(--left) + 14px);
  bottom: 14px;
  z-index: 18;
  display: inline-flex;
  align-items: center;
  margin: 0;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-3);
  white-space: nowrap;
  pointer-events: none;
  transition: left 140ms var(--ease);
}
.canvas-status span { display: inline-flex; gap: 4px; }
.canvas-status span + span::before {
  content: "·";
  margin: 0 var(--s2);
  color: var(--line-strong);
}
.canvas-status b { color: var(--ink); font-weight: 500; }
.canvas-status .overview-tag {
  color: var(--accent);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
body.mode-replay .canvas-status {
  top: calc(var(--toolbar-h) + 14px);
  bottom: auto;
}
body.mode-notes .canvas-status,
body.mode-bento .canvas-status,
body.mode-decisions .canvas-status,
body.mode-atlas .canvas-status {
  display: none;
}

@media (max-width: 1024px) {
  .toolbar {
    display: flex;
    justify-content: space-between;
    gap: var(--s2);
  }
  .vault-button { max-width: 210px; }
}
@media (max-width: 760px) {
  .canvas-status { display: none; }
}

/* ---------- sidebar & resize handles ---------- */
.sidebar {
  position: fixed;
  top: var(--toolbar-h);
  left: 0;
  bottom: 0;
  width: var(--sidebar-w);
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: var(--s3);
  padding: var(--s3) var(--s2) var(--s4);
  background: var(--surface);
  border-right: 1px solid var(--line);
  overflow: hidden;
}
body.has-sidebar { --left: var(--sidebar-w); }
body.is-static .block-vaults { display: none; }

.resize-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 8px;
  z-index: 5;
  cursor: col-resize;
  touch-action: none;
}
.resize-handle::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: transparent;
  transition: background 140ms var(--ease);
}
.resize-handle:hover::after,
.resize-handle:focus-visible::after,
body.is-resizing .resize-handle:active::after {
  background: var(--accent);
}
.resize-handle-sidebar { right: -3px; }
.resize-handle-sidebar::after { right: 3px; }
.resize-handle-panel { left: -3px; }
.resize-handle-panel::after { left: 3px; }

.block { display: flex; flex-direction: column; min-height: 0; }
.block-folders { flex: 1; overflow: hidden; }
.block-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s2);
  margin: 0 var(--s2) var(--s2);
  font-size: 11.5px;
  font-weight: 600;
  color: var(--ink-3);
}
.block-title span { color: var(--ink-2); font-variant-numeric: tabular-nums; }

.sidebar-disclosure {
  display: block;
}
.sidebar-summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px var(--s2);
  border-radius: var(--r-sm);
  color: var(--ink-3);
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  transition: color 120ms var(--ease), background 120ms var(--ease);
}
.sidebar-summary::-webkit-details-marker { display: none; }
.sidebar-summary::before {
  content: "";
  width: 5px;
  height: 5px;
  margin-left: 2px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg);
  transition: transform 120ms var(--ease);
}
.sidebar-disclosure[open] > .sidebar-summary::before {
  transform: rotate(45deg);
}
@media (hover: hover) {
  .sidebar-summary:hover {
    color: var(--ink);
    background: var(--surface-2);
  }
}
.sidebar-summary-meta {
  margin-left: auto;
  color: var(--ink-3);
  font-size: 11px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.sidebar-disclosure-body {
  display: grid;
  gap: var(--s2);
  padding-top: var(--s2);
}
.tallies-actions-row {
  display: flex;
  justify-content: flex-end;
  padding: 0 var(--s1);
}

.vault-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.vault-item {
  display: flex;
  align-items: center;
  gap: var(--s2);
  width: 100%;
  padding: 6px var(--s2);
  border: 0;
  border-radius: var(--r);
  background: transparent;
  color: var(--ink-2);
  font-family: var(--sans);
  font-size: 12.5px;
  text-align: left;
  cursor: pointer;
  transition: background 120ms var(--ease), color 120ms var(--ease);
}
.vault-item:hover { background: var(--surface-2); color: var(--ink); }
.vault-item.is-active {
  background: var(--surface-2);
  color: var(--ink);
  font-weight: 600;
  box-shadow: inset 2px 0 0 var(--accent);
}
.vault-item-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vault-item-count {
  margin-left: auto;
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-3);
  font-weight: 400;
}
.vault-item.is-missing .vault-item-name { color: var(--ink-3); text-decoration: line-through; }
.vault-item.is-missing .vault-item-count::after { content: "missing"; }

.folders {
  display: grid;
  gap: 2px;
  overflow-y: auto;
  padding-bottom: var(--s5);
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}
.folder-group {
  display: grid;
  gap: 1px;
}
.folder-row {
  display: flex;
  align-items: center;
  gap: 1px;
}
.folder-expand {
  appearance: none;
  flex: 0 0 auto;
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 24px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--ink-3);
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
  transition: color 120ms var(--ease), background 120ms var(--ease);
}
.folder-expand:hover {
  background: var(--surface-2);
  color: var(--ink);
}
.folder-item {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: var(--s2);
  padding: 5px var(--s2) 5px 4px;
  border: 0;
  border-radius: var(--r);
  background: transparent;
  color: var(--ink-2);
  font-family: var(--sans);
  font-size: 12.5px;
  text-align: left;
  cursor: pointer;
  transition: color 120ms var(--ease), opacity 120ms var(--ease), background 120ms var(--ease);
}
.folder-item:hover { background: var(--surface-2); color: var(--ink); }
.folder-item.is-off { opacity: 0.38; }
.folder-dot { width: 8px; height: 8px; border-radius: 2px; flex: 0 0 auto; }
.folder-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-count {
  margin-left: auto;
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-3);
}
.folder-notes {
  display: grid;
  gap: 1px;
  margin: 1px 0 4px 19px;
  padding-left: var(--s2);
  border-left: 1px solid var(--line);
}
.folder-note {
  appearance: none;
  display: flex;
  align-items: center;
  gap: 5px;
  width: 100%;
  min-width: 0;
  padding: 4px 6px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--ink-2);
  font-family: var(--sans);
  font-size: 12px;
  text-align: left;
  cursor: pointer;
  transition: background 120ms var(--ease), color 120ms var(--ease);
}
.folder-note:hover {
  background: var(--surface-2);
  color: var(--ink);
}
.folder-note.is-active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 500;
}
.folder-note-sub {
  flex: none;
  padding: 0 4px;
  border-radius: 3px;
  background: var(--surface-2);
  color: var(--ink-3);
  font-size: 10px;
  font-family: var(--mono);
}
.folder-note-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- sidebar tallies & point trackers ---------- */
.block-tallies {
  flex: 0 0 auto;
  max-height: 248px;
  padding-top: var(--s3);
  border-top: 1px solid var(--line);
}
.tallies {
  display: flex;
  flex-direction: column;
  gap: var(--s2);
  min-width: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 0 var(--s1) var(--s1);
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}
.tally-tabs {
  display: flex;
  align-items: center;
  gap: 2px;
  min-width: 0;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--bg);
}
.tally-tab {
  appearance: none;
  flex: 1 1 0;
  min-width: 0;
  padding: 3px 4px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--ink-3);
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
  transition: color 120ms var(--ease), background 120ms var(--ease);
}
.tally-tab:hover { color: var(--ink); }
.tally-tab.is-active {
  background: var(--surface-2);
  color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--line-strong);
}
.tally-source-btn {
  appearance: none;
  flex: none;
  width: 20px;
  height: 20px;
  padding: 0;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--ink-3);
  font-size: 11px;
  cursor: pointer;
}
.tally-source-btn:hover {
  background: var(--surface-2);
  color: var(--accent);
}
.tally-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.tally-list-custom {
  padding-top: var(--s1);
  border-top: 1px solid var(--line-subtle);
}
.tally-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  min-width: 0;
  padding: 3px 4px;
  border-radius: var(--r-sm);
}
.tally-row:hover {
  background: var(--surface-2);
}
.tally-label {
  appearance: none;
  flex: 1;
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink-2);
  font-family: var(--sans);
  font-size: 12px;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}
button.tally-label:hover {
  color: var(--accent);
}
.tally-pips {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.tally-pip {
  appearance: none;
  display: inline-grid;
  place-items: center;
  width: 17px;
  height: 17px;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  background: var(--surface-2);
  color: var(--accent);
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  vertical-align: middle;
  transition: border-color 120ms var(--ease), background 120ms var(--ease), transform 80ms var(--ease);
}
.tally-pip:hover {
  border-color: var(--accent);
  transform: scale(1.06);
}
.tally-pip.is-checked {
  border-color: var(--accent-line);
  background: var(--accent-soft);
  color: var(--accent);
}
.tally-row.is-crybaby .tally-pip.is-checked {
  border-color: var(--danger-line);
  background: var(--danger-soft);
  color: var(--danger);
}
.tally-pip.is-bonus {
  margin-left: 3px;
  border-radius: 50%;
}
.tally-step,
.tally-del {
  appearance: none;
  display: inline-grid;
  place-items: center;
  width: 17px;
  height: 17px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--surface);
  color: var(--ink-3);
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
}
.tally-step:hover {
  border-color: var(--line-strong);
  color: var(--ink);
}
.tally-del:hover {
  border-color: var(--danger-line);
  color: var(--danger);
}
.tally-add-form {
  display: grid;
  gap: var(--s1);
  padding: var(--s2);
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface-2);
}
.tally-add-input {
  width: 100%;
  padding: 5px 7px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 12px;
}
.tally-add-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--s2);
}
.tally-add-btn {
  padding: 3px 9px;
  font-size: 11.5px;
}
.tally-empty {
  margin: 0;
  padding: 2px var(--s1);
  font-size: 11.5px;
  line-height: 1.45;
  color: var(--ink-3);
}
.biome-choices {
  margin-top: var(--s2);
}
.biome-choices.is-disabled {
  opacity: 0.42;
  pointer-events: none;
}

.block-selection {
  gap: var(--s2);
  padding: var(--s3) var(--s2) 0;
  border-top: 1px solid var(--line);
}
.block-selection .block-title { margin-left: 0; margin-right: 0; }
.selection-actions { display: flex; flex-wrap: wrap; gap: var(--s1); }

.sidebar-hint {
  display: none;
}

@media (max-width: 860px) {
  body.has-sidebar { --left: 0px; }
  .sidebar { box-shadow: var(--shadow-lg); }
}

/* ---------- note panel (studio reader) ---------- */
.panel {
  position: fixed;
  top: var(--toolbar-h);
  right: 0;
  bottom: 0;
  width: min(var(--panel-w), 100vw);
  z-index: 25;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow-md);
  animation: panel-in 160ms var(--ease);
}
body.panel-expanded .panel {
  left: var(--left);
  width: calc(100vw - var(--left));
  border-left: 0;
  box-shadow: none;
}
body.panel-expanded .resize-handle-panel { display: none; }

@keyframes panel-in { from { transform: translateX(10px); opacity: 0; } }

.panel-head {
  display: flex;
  align-items: center;
  gap: var(--s2);
  min-height: 44px;
  padding: var(--s1) var(--s3);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.panel-history { display: flex; gap: 2px; }
.panel-head-actions { display: flex; align-items: center; gap: 2px; }
.panel-crumbs {
  flex: 1;
  margin: 0;
  font-size: 12px;
  color: var(--ink-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.panel-scroll {
  flex: 1;
  overflow-y: auto;
  padding: var(--s6) var(--s5) var(--s7);
  scroll-padding-top: var(--s5);
  scroll-padding-bottom: calc(var(--s6) + var(--dock-h));
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}
.panel-article {
  width: 100%;
  max-width: 680px;
  margin: 0 auto;
}
body.panel-expanded .panel-scroll {
  padding: var(--s7) var(--s6);
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: var(--s2);
  min-height: 48px;
  padding: var(--s2) var(--s4);
  border-top: 1px solid var(--line);
  background: var(--surface);
}

/* ---------- note content ---------- */
.note-crumb { margin: 0 0 var(--s1); font-size: 12px; color: var(--ink-3); }
.note-title {
  margin: 0 0 var(--s3);
  font-family: var(--serif);
  font-size: 30px;
  font-weight: 400;
  line-height: 1.18;
  letter-spacing: -0.01em;
  color: var(--ink);
  overflow-wrap: break-word;
}
.note-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s1) var(--s3);
  padding-bottom: var(--s4);
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-3);
}
.note-tags { display: flex; flex-wrap: wrap; gap: var(--s1); margin: var(--s3) 0 0; }
.note-tag {
  padding: 2px 7px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  font-size: 12px;
  color: var(--ink-2);
}

.prose {
  margin-top: var(--s4);
  font-size: 15px;
  line-height: 1.74;
  color: var(--prose-ink);
  overflow-wrap: break-word;
}
.prose h1, .prose h2, .prose h3, .prose h4 {
  font-family: var(--serif);
  font-weight: 400;
  line-height: 1.3;
  margin: var(--s5) 0 var(--s2);
  color: var(--ink);
}
.prose h1 { font-size: 23px; }
.prose h2 { font-size: 19.5px; }
.prose h3 { font-size: 16.5px; }
.prose h4 { font-size: 15px; color: var(--ink-2); }
.prose p { margin: 0 0 var(--s3); }
.prose a.wikilink {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid var(--accent-line);
  cursor: pointer;
  transition: border-color 120ms var(--ease);
}
.prose a.wikilink:hover { border-bottom-color: var(--accent); }
.prose a.wikilink.is-missing { color: var(--ink-3); border-bottom-style: dotted; cursor: default; }
.prose ul, .prose ol { padding-left: var(--s4); margin: 0 0 var(--s3); }
.prose li { margin: 3px 0; }
.prose blockquote {
  margin: 0 0 var(--s4);
  padding: var(--s2) var(--s3);
  border-left: 2px solid var(--accent-line);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  background: var(--surface-2);
  color: var(--ink-2);
}
.prose blockquote p:last-child { margin-bottom: 0; }
.prose code {
  background: var(--surface-2);
  border: 1px solid var(--line-subtle);
  border-radius: var(--r-sm);
  padding: 1px 5px;
  font-size: 0.86em;
}
.prose pre {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: var(--s3);
  overflow: auto;
}
.prose pre code { background: none; border: 0; padding: 0; }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: var(--s5) 0; }
.prose .frontmatter { display: none; }

/* Highlights, strikethrough, task items, and file attachment pills */
.prose mark {
  padding: 1px 5px;
  border-radius: var(--r-sm);
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
  color: var(--ink);
}
.prose del {
  color: var(--ink-3);
  text-decoration: line-through;
}
.prose a.wikilink-file {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 1px 7px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: 0.9em;
  line-height: 1.5;
  vertical-align: baseline;
}
.prose a.wikilink-file::before {
  content: "↗";
  font-size: 0.85em;
  color: var(--accent);
}
.prose a.wikilink-file:hover {
  border-color: var(--accent-line);
  color: var(--ink);
}

.prose li.task-item {
  list-style: none;
  display: flex;
  align-items: baseline;
  gap: var(--s2);
  margin-left: -18px;
}
.prose .task-box {
  appearance: none;
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 15px;
  height: 15px;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  background: var(--surface-2);
  color: var(--accent);
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
  transform: translateY(1px);
}
.prose li.task-item.is-done {
  color: var(--ink-3);
}
.prose li.task-item.is-done .task-box {
  border-color: var(--accent-line);
  background: var(--accent-soft);
}

/* ---------- Obsidian Callouts (> [!info], > [!warning], > [!quote], etc.) ---------- */
.callout {
  margin: 0 0 var(--s4);
  padding: var(--s3) var(--s4);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--r);
  background: var(--surface-2);
}
.callout-title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s2);
  font-weight: 600;
  font-size: 13.5px;
  color: var(--ink);
}
.callout-badge {
  padding: 1px 6px;
  border-radius: var(--r-sm);
  border: 1px solid var(--accent-line);
  background: var(--accent-soft);
  color: var(--accent);
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.callout-heading {
  color: var(--ink);
}
.callout-body {
  margin-top: var(--s2);
  font-size: 14px;
  color: var(--prose-ink);
}
.callout-body > :last-child {
  margin-bottom: 0;
}

.callout-info {
  border-left-color: var(--info);
  background: var(--info-soft);
}
.callout-info .callout-badge {
  border-color: var(--info-line);
  background: var(--info-soft);
  color: var(--info);
}

.callout-tip {
  border-left-color: var(--tip);
  background: var(--tip-soft);
}
.callout-tip .callout-badge {
  border-color: var(--tip-line);
  background: var(--tip-soft);
  color: var(--tip);
}

.callout-warning {
  border-left-color: var(--warn);
  background: var(--warn-soft);
}
.callout-warning .callout-badge {
  border-color: var(--warn-line);
  background: var(--warn-soft);
  color: var(--warn);
}

.callout-danger {
  border-left-color: var(--danger);
  background: var(--danger-soft);
}
.callout-danger .callout-badge {
  border-color: var(--danger-line);
  background: var(--danger-soft);
  color: var(--danger);
}

.callout-quote {
  border-left-color: var(--accent-line);
  background: var(--surface-2);
  font-family: var(--serif);
}
.callout-quote .callout-body {
  font-style: italic;
  font-size: 15px;
}

/* ---------- Markdown Tables ---------- */
.table-wrap {
  margin: 0 0 var(--s4);
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface);
}
.md-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
}
.md-table th,
.md-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line-subtle);
  text-align: left;
  vertical-align: top;
}
.md-table th:last-child,
.md-table td:last-child {
  border-right: 0;
}
.md-table thead th {
  background: var(--surface-2);
  color: var(--ink);
  font-weight: 600;
  font-size: 12.5px;
  letter-spacing: 0.01em;
  border-bottom: 1px solid var(--line-strong);
}
.md-table tbody tr:last-child td {
  border-bottom: 0;
}
.md-table tbody tr:nth-child(even) {
  background: var(--line-subtle);
}
.md-table tbody tr:hover {
  background: var(--surface-2);
}
.md-table .is-center { text-align: center; }
.md-table .is-right { text-align: right; }

/* ---------- LaTeX Math Preview ---------- */
.math-block {
  margin: var(--s3) 0 var(--s4);
  padding: var(--s3) var(--s4);
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface-2);
  text-align: center;
  font-family: var(--serif);
  font-size: 16.5px;
  line-height: 1.6;
  color: var(--ink);
}
.math-inline {
  display: inline-flex;
  align-items: baseline;
  padding: 0 2px;
  font-family: var(--serif);
  font-size: 1.04em;
  color: var(--ink);
}
.math-inline.is-display {
  display: flex;
  justify-content: center;
  margin: var(--s3) 0;
  padding: var(--s2) var(--s3);
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface-2);
  font-size: 16px;
}
.math-expr {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1px;
}
.math-frac {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  vertical-align: middle;
  margin: 0 3px;
  font-size: 0.88em;
  line-height: 1.15;
}
.math-num {
  padding: 0 4px 2px;
  border-bottom: 1px solid var(--ink-2);
}
.math-den {
  padding: 2px 4px 0;
}
.math-sqrt {
  display: inline-flex;
  align-items: stretch;
  vertical-align: middle;
  margin: 0 2px;
}
.math-root {
  font-size: 0.7em;
  transform: translate(3px, -0.45em);
  color: var(--ink-2);
}
.math-radic {
  font-size: 1.15em;
  line-height: 1;
  padding-right: 1px;
}
.math-radicand {
  border-top: 1px solid var(--ink-2);
  padding: 1px 3px 0;
}
.math-scripts {
  display: inline-flex;
  flex-direction: column;
  justify-content: center;
  vertical-align: middle;
  font-size: 0.74em;
  line-height: 1.05;
  margin-left: 1px;
}
.math-sup {
  font-size: 0.76em;
  line-height: 1;
}
.math-sub {
  font-size: 0.76em;
  line-height: 1;
}
.math-op {
  font-size: 1.28em;
  line-height: 1;
  margin: 0 2px;
  font-style: normal;
}
.math-overline {
  border-top: 1px solid currentColor;
  padding-top: 1px;
}
.math-accent {
  position: relative;
  display: inline-block;
}
.math-bb {
  font-weight: 700;
  letter-spacing: 0.02em;
}
.math-cal {
  font-style: italic;
}
.math-fn,
.math-rm {
  font-style: normal;
  font-family: var(--sans);
  font-size: 0.92em;
}
.math-fn {
  margin: 0 2px;
}
.math-matrix {
  display: inline-flex;
  align-items: center;
  vertical-align: middle;
  margin: 0 4px;
}
.math-matrix-delim {
  font-size: 1.4em;
  font-weight: 300;
  color: var(--ink-2);
  padding: 0 2px;
}
.math-matrix-grid {
  display: inline-grid;
  gap: 2px 10px;
}
.math-matrix-row {
  display: flex;
  gap: 12px;
  justify-content: space-around;
}
.math-matrix-cell {
  text-align: center;
  min-width: 1.2em;
}

/* ---------- tabbed connections ---------- */
.connections {
  margin-top: var(--s6);
  padding-top: var(--s2);
  border-top: 1px solid var(--line);
}
.connections-tabs {
  display: flex;
  gap: var(--s1);
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
  scrollbar-width: none;
}
.connections-tabs::-webkit-scrollbar { display: none; }

.connections-tab {
  position: relative;
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: var(--s2) var(--s2);
  border: 0;
  background: none;
  color: var(--ink-3);
  font-family: var(--sans);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: color 120ms var(--ease);
}
.connections-tab:hover { color: var(--ink); }
.connections-tab[aria-selected="true"] {
  color: var(--ink);
}
.connections-tab[aria-selected="true"]::after {
  content: "";
  position: absolute;
  inset: auto 0 0;
  border-block-end: 2px solid var(--accent);
}
.connections-count {
  padding: 0 5px;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-3);
}
.connections-tab[aria-selected="true"] .connections-count {
  background: var(--accent-soft);
  color: var(--accent);
}

/* Keep tabpanel element itself unstyled so hidden="until-found" renders no empty strip. */
.connections-panels { display: grid; }
.connections-panel { grid-area: 1 / 1; }
.connections-list {
  padding-top: var(--s2);
  display: grid;
  gap: 2px;
}

.relation {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s3);
  width: 100%;
  padding: 7px var(--s2);
  border: 0;
  border-radius: var(--r-sm);
  background: none;
  color: var(--ink-2);
  font-family: var(--sans);
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  transition: background 120ms var(--ease), color 120ms var(--ease);
}
.relation:hover { background: var(--surface-2); color: var(--accent); }
.relation-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.relation-folder { flex: none; font-size: 11.5px; color: var(--ink-3); }
.empty { margin: var(--s2) 0; font-size: 12.5px; color: var(--ink-3); }

/* ---------- controls ---------- */
.btn {
  appearance: none;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface-2);
  color: var(--ink-2);
  font-family: var(--sans);
  font-size: 12.5px;
  font-weight: 500;
  padding: 6px 11px;
  cursor: pointer;
  transition: color 140ms var(--ease), border-color 140ms var(--ease), background 140ms var(--ease);
}
.btn:hover { color: var(--ink); border-color: var(--line-strong); background: var(--surface-3); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: var(--accent-ink);
}

.text-button {
  appearance: none;
  border: 0;
  background: none;
  padding: 2px 4px;
  border-radius: var(--r-sm);
  color: var(--ink-3);
  font-family: var(--sans);
  font-size: 12px;
  text-align: left;
  cursor: pointer;
}
.text-button:hover { color: var(--ink); }

/* ---------- edit bar & markdown textarea ---------- */
.editor-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  padding: var(--s1) var(--s2);
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: var(--r) var(--r) 0 0;
  background: var(--surface-2);
}
.editor-tool-group {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  flex: none;
}
.editor-sep {
  display: inline-block;
  flex: none;
  width: 1px;
  height: 16px;
  margin: 0 3px;
  background: var(--line);
}
.editor-tool {
  appearance: none;
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
  transition: background 120ms var(--ease), color 120ms var(--ease);
}
.editor-tool .icon { width: 15px; height: 15px; }
@media (hover: hover) {
  .editor-tool:hover { background: var(--surface-3); color: var(--ink); }
}
.editor-tool[aria-pressed="true"] {
  background: var(--accent-soft);
  color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent-line);
}

.editor {
  display: block;
  width: 100%;
  min-height: 48svh;
  resize: vertical;
  padding: var(--s3) var(--s4);
  border: 1px solid var(--line);
  border-radius: 0 0 var(--r) var(--r);
  background: var(--bg);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.72;
}
.editor:focus-visible { outline-offset: -1px; }
.editor-hint {
  margin: var(--s2) 0 0;
  font-size: 12px;
  line-height: 1.6;
  color: var(--ink-3);
}
.panel-status { margin-left: auto; font-size: 12px; color: var(--ink-3); }

/* ---------- command palette & search ---------- */
.palette {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  justify-items: center;
  align-content: start;
  padding-top: 12svh;
  background: var(--scrim);
  backdrop-filter: blur(4px);
}
.palette-box {
  width: min(640px, calc(100vw - 32px));
  border: 1px solid var(--line-strong);
  border-radius: var(--r-lg);
  background: var(--surface-elevated);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.palette-input-wrap {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: 0 var(--s4);
  border-bottom: 1px solid var(--line);
}
.palette-input-icon { color: var(--ink-3); width: 17px; height: 17px; }
#palette-input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15.5px;
  padding: var(--s4) 0;
}
#palette-input:focus-visible { outline: none; }
#palette-input::placeholder { color: var(--ink-3); }

.palette-results {
  max-height: 50svh;
  overflow-y: auto;
  padding: var(--s2);
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}
.palette-group {
  margin: var(--s2) var(--s2) var(--s1);
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-3);
}
.palette-group:first-child { margin-top: var(--s1); }

.palette-hit {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 2px var(--s3);
  width: 100%;
  padding: 8px var(--s3);
  border: 0;
  border-radius: var(--r);
  background: none;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}
.palette-hit.is-active {
  background: var(--surface-2);
  box-shadow: inset 2px 0 0 var(--accent);
}
.palette-hit-main {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  min-width: 0;
}
.palette-hit-icon { width: 14px; height: 14px; color: var(--accent); }
.palette-hit-title {
  font-size: 13.5px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.palette-hit-path { font-size: 12px; color: var(--ink-3); text-align: right; }
.palette-hit-kbd { font-size: 11px; }
.palette-hit-snippet {
  grid-column: 1 / -1;
  font-size: 12px;
  color: var(--ink-3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.palette-empty { padding: var(--s4); font-size: 13px; color: var(--ink-3); }
.palette-foot {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s4);
  margin: 0;
  padding: var(--s2) var(--s4);
  border-top: 1px solid var(--line);
  background: var(--surface);
  font-size: 11.5px;
  color: var(--ink-3);
}

/* ---------- timeline ---------- */
.timeline {
  position: fixed;
  bottom: var(--s4);
  left: calc(var(--left) + (100vw - var(--left)) / 2);
  transform: translateX(-50%);
  z-index: 22;
  display: flex;
  align-items: center;
  gap: var(--s3);
  width: min(520px, calc(100vw - var(--left) - 32px));
  padding: var(--s2) var(--s3);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-lg);
  background: var(--surface-elevated);
  box-shadow: var(--shadow-md);
}
.timeline-date {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-2);
  min-width: 76px;
}
.timeline-range { flex: 1; accent-color: var(--accent); }

/* ---------- tooltip ---------- */
.tooltip {
  position: fixed;
  z-index: 40;
  pointer-events: none;
  display: grid;
  gap: 2px;
  max-width: 260px;
  padding: var(--s2) var(--s3);
  border: 1px solid var(--line-strong);
  border-radius: var(--r);
  background: var(--surface-elevated);
  box-shadow: var(--shadow-md);
}
.tooltip-title { font-size: 13px; font-weight: 500; color: var(--ink); }
.tooltip-meta { font-size: 11.5px; color: var(--ink-3); }

/* ---------- compose ---------- */
.compose {
  position: fixed;
  inset: 0;
  z-index: 55;
  display: grid;
  place-items: center;
  padding: var(--s4);
  background: var(--scrim);
  backdrop-filter: blur(3px);
}
.compose-box {
  width: min(440px, 100%);
  display: grid;
  gap: var(--s2);
  padding: var(--s5);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-lg);
  background: var(--surface-elevated);
  box-shadow: var(--shadow-lg);
}
.compose-kicker { margin: 0; font-size: 12px; font-weight: 600; color: var(--accent); }
.compose-actions { display: flex; justify-content: flex-end; gap: var(--s2); margin-top: var(--s2); }

.field-label { font-size: 12px; font-weight: 500; color: var(--ink-2); }
.field-input {
  width: 100%;
  height: 36px;
  padding: 0 var(--s3);
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 13.5px;
}
.field-input:focus-visible { outline-offset: 1px; }
.field-help { margin: 0; font-size: 12px; line-height: 1.5; color: var(--ink-3); }
.field-error { margin: 0; font-size: 12px; color: var(--danger); }

/* ---------- launch ---------- */
.launch {
  position: fixed;
  inset: 0;
  z-index: 45;
  display: grid;
  place-items: center;
  padding: var(--s5);
  background: var(--bg);
  overflow-y: auto;
}
.launch-inner {
  width: min(580px, 100%);
  padding: var(--s6);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-md);
}
.launch-brand {
  display: flex;
  align-items: center;
  gap: var(--s3);
  margin-bottom: var(--s5);
}
.launch-logo {
  display: block;
  width: 40px;
  height: 40px;
  border-radius: 9px;
  border: 1px solid var(--line);
}
.launch-wordmark { font-family: var(--serif); font-size: 24px; letter-spacing: 0.01em; }
.launch-tag {
  margin-left: auto;
  padding: 3px 10px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  font-size: 11.5px;
  color: var(--ink-3);
}
.launch-title {
  margin: 0 0 var(--s3);
  font-family: var(--serif);
  font-size: clamp(30px, 4vw, 40px);
  font-weight: 400;
  line-height: 1.08;
  letter-spacing: -0.015em;
}
.launch-sub {
  max-width: 48ch;
  margin: 0 0 var(--s5);
  font-size: 14px;
  line-height: 1.65;
  color: var(--ink-2);
}
.launch-recents { margin-bottom: var(--s5); }
.launch-label {
  display: flex;
  justify-content: space-between;
  margin-bottom: var(--s2);
  font-size: 11.5px;
  font-weight: 500;
  color: var(--ink-3);
}

.launch-list { list-style: none; margin: 0 0 var(--s5); padding: 0; display: grid; gap: var(--s2); }
.launch-row {
  display: flex;
  align-items: center;
  gap: var(--s2);
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--bg);
  padding-right: var(--s3);
  transition: border-color 140ms var(--ease), background 140ms var(--ease);
}
.launch-row:hover { border-color: var(--line-strong); background: var(--surface-2); }
.launch-open {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: 9px 10px;
  border: 0;
  border-radius: var(--r);
  background: none;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}
.launch-item-tile {
  flex: none;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface-2);
  color: var(--accent);
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1;
}
.launch-item-text { display: grid; gap: 1px; min-width: 0; }
.launch-item-name { font-size: 13.5px; font-weight: 500; }
.launch-item-path {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--ink-3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.launch-item-meta {
  margin-left: auto;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-3);
  white-space: nowrap;
}
.launch-item-forget {
  margin-left: var(--s2);
  font-size: 12px;
  color: var(--ink-3);
  background: none;
  border: 0;
  cursor: pointer;
}
.launch-item-forget:hover { color: var(--danger); }

.launch-form {
  display: grid;
  gap: var(--s2);
  padding-top: var(--s5);
  border-top: 1px solid var(--line);
}
.field-row { display: flex; gap: var(--s2); }
.field-row .field-input { flex: 1; }
.launch-points {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s2) var(--s4);
  margin: var(--s5) 0 0;
  padding: 0;
  list-style: none;
  font-size: 12px;
  color: var(--ink-3);
}
.launch-points li::before {
  content: "";
  display: inline-block;
  width: 5px;
  height: 5px;
  margin-right: 8px;
  border-radius: 50%;
  background: var(--accent);
  vertical-align: 1px;
}
.launch-foot { margin: var(--s4) 0 0; font-size: 12px; color: var(--ink-3); }
.launch-foot code { color: var(--ink-2); }
.launch-foot kbd {
  padding: 1px 5px;
  font-size: 11px;
  color: var(--ink-2);
}

@media (max-width: 640px) {
  .launch-inner { padding: var(--s4); }
  .field-row { flex-wrap: wrap; }
}

/* ---------- guided tour ---------- */
.tour {
  position: fixed;
  inset: 0;
  z-index: 70;
}
.tour-shade {
  position: absolute;
  inset: 0;
  background: var(--scrim);
}
.tour.has-spot .tour-shade { opacity: 0; }
.tour-spot {
  position: fixed;
  z-index: 1;
  border: 2px solid var(--accent);
  border-radius: var(--r);
  background: transparent;
  box-shadow: 0 0 0 9999px rgba(5, 6, 8, 0.66), 0 0 0 5px var(--accent-soft);
  pointer-events: none;
  transition: left 180ms var(--ease), top 180ms var(--ease), width 180ms var(--ease), height 180ms var(--ease);
}
.tour-card {
  position: fixed;
  z-index: 2;
  width: min(420px, calc(100vw - 32px));
  max-height: calc(100svh - 32px);
  overflow-y: auto;
  padding: var(--s4);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-lg);
  background: var(--surface-elevated);
  box-shadow: var(--shadow-lg);
}
.tour-card:focus { outline: none; }
.tour.is-center .tour-card {
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}
.tour-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s3); }
.tour-labels { display: grid; gap: var(--s1); min-width: 0; }
.tour-kicker { margin: 0; font-size: 12px; font-weight: 600; color: var(--accent); }
.tour-context {
  width: fit-content;
  max-width: 100%;
  padding: 2px 6px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  color: var(--ink-3);
  font-size: 12px;
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tour-progress { height: 2px; margin: var(--s3) 0 var(--s4); background: var(--line); overflow: hidden; }
.tour-progress span { display: block; width: 0; height: 100%; background: var(--accent); transition: width 180ms var(--ease); }
.tour-title {
  margin: 0 0 var(--s2);
  font-family: var(--serif);
  font-size: 23px;
  font-weight: 400;
  line-height: 1.2;
}
.tour-body { font-size: 13px; line-height: 1.65; color: var(--ink-2); }
.tour-body p { margin: 0 0 var(--s3); }
.tour-body p:last-child { margin-bottom: 0; }
.tour-body ul { margin: var(--s3) 0 0; padding-left: var(--s4); }
.tour-body li { margin: 3px 0; }
.tour-body kbd { white-space: nowrap; }
.tour-hint {
  margin: var(--s3) 0 0;
  padding: var(--s2) var(--s3);
  border-left: 2px solid var(--line-strong);
  background: var(--surface-2);
  color: var(--ink-3);
  font-size: 12px;
  line-height: 1.55;
}
.tour-actions { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); margin-top: var(--s4); }
.tour-nav { display: flex; align-items: center; gap: var(--s2); }
.tour .text-button:disabled { opacity: 0.35; cursor: default; }
.is-touring .update { display: none; }

@media (max-width: 640px) {
  .tour-card { padding: var(--s3); }
  .tour-title { font-size: 21px; }
}

/* ---------- toast ---------- */
.toast {
  position: fixed;
  bottom: var(--s5);
  left: calc(var(--left) + (100vw - var(--left)) / 2);
  transform: translateX(-50%);
  z-index: 58;
  max-width: calc(100vw - 32px);
  padding: var(--s2) var(--s3);
  border: 1px solid var(--line-strong);
  border-radius: var(--r);
  background: var(--surface-elevated);
  box-shadow: var(--shadow-md);
  font-size: 12.5px;
  color: var(--ink);
}

/* ---------- graph labels (always over dark WebGL canvas) ---------- */
.star-label {
  position: absolute;
  transform: translate(-50%, -150%);
  font-size: 12px;
  color: rgba(236, 239, 244, 0.8);
  text-shadow: 0 1px 10px #000, 0 0 3px #000;
  white-space: nowrap;
  will-change: transform, opacity;
}
.galaxy-label {
  appearance: none;
  pointer-events: auto;
  transform: translate(-50%, -50%);
  padding: 2px 7px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--r-sm);
  background: rgba(8, 10, 16, 0.62);
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: rgba(241, 244, 249, 0.92);
  text-shadow: 0 1px 4px #000, 0 0 10px #000;
  cursor: pointer;
}
.galaxy-label:hover {
  border-color: rgba(255, 217, 160, 0.6);
  background: rgba(12, 15, 23, 0.86);
  color: #fff;
}
.galaxy-label.is-active {
  z-index: 2;
  border-color: #ffd9a0;
  background: rgba(12, 15, 23, 0.92);
  color: #ffd9a0;
}

/* A section title is also a way back out: no hidden camera state. */
.section-focus {
  position: fixed;
  top: calc(var(--toolbar-h) + 12px);
  left: calc(var(--left) + 12px);
  z-index: 22;
  display: flex;
  align-items: center;
  gap: var(--s2);
  max-width: min(360px, calc(100vw - 24px));
  padding: 5px 6px 5px 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r);
  background: var(--surface-elevated);
  box-shadow: var(--shadow-sm);
}
.section-focus-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
}
.section-focus-exit {
  appearance: none;
  flex: none;
  padding: 2px 7px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--ink-2);
  font-family: var(--sans);
  font-size: 12px;
  cursor: pointer;
}
.section-focus-exit:hover { border-color: var(--line-strong); color: var(--ink); }

/* An available release, offered without stealing the scene. */
.update {
  position: fixed;
  top: calc(var(--toolbar-h) + 12px);
  right: var(--s3);
  z-index: 24;
  display: flex;
  align-items: center;
  gap: var(--s2);
  max-width: min(420px, calc(100vw - 24px));
  padding: 5px 6px 5px 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r);
  background: var(--surface-elevated);
  box-shadow: var(--shadow-md);
}
.update-text { font-size: 12px; color: var(--ink-2); }
.update .btn { padding: 3px 8px; font-size: 12px; }

@media (max-width: 640px) {
  .update { left: var(--s3); right: var(--s3); top: calc(var(--toolbar-h) + 8px); }
}

/* ---------- atlas (parchment map) ---------- */
.atlas {
  position: fixed;
  top: var(--toolbar-h);
  left: var(--left);
  width: calc(100vw - var(--left));
  height: calc(100svh - var(--toolbar-h) - var(--dock-h));
  display: block;
  cursor: grab;
  touch-action: none;
}
.atlas:active { cursor: grabbing; }
.atlas:focus-visible { outline: 2px solid var(--accent); outline-offset: -6px; }

/* The whole chrome is re-inked for Atlas; components stay token-driven. */
body.mode-atlas {
  --bg: #e9dcc0;
  --surface: #f4ebd6;
  --surface-2: #e9dcc0;
  --surface-3: #dcc9a4;
  --surface-elevated: #f8f1e0;
  --line: #cbb890;
  --line-subtle: rgba(47, 38, 24, 0.08);
  --line-strong: #a88f66;
  --ink: #2f2618;
  --ink-2: #55452e;
  --ink-3: #6f5c40;
  --prose-ink: #3f3423;
  --accent: #8c2f1f;
  --accent-hover: #732517;
  --accent-soft: rgba(140, 47, 31, 0.10);
  --accent-line: rgba(140, 47, 31, 0.36);
  --accent-ink: #fbf1dd;
  --danger: #9c3320;
  --danger-soft: rgba(156, 51, 32, 0.10);
  --danger-line: rgba(156, 51, 32, 0.42);
  --shadow-sm: 0 2px 8px rgba(47, 38, 24, 0.10);
  --shadow-md: 0 12px 32px rgba(47, 38, 24, 0.16);
  color-scheme: light;
}
body.mode-atlas .note-title { letter-spacing: 0; }

/* ---------- bento (folders as boxes) ---------- */
.bento {
  position: fixed;
  top: var(--toolbar-h);
  left: var(--left);
  right: 0;
  bottom: var(--dock-h);
  overflow-y: auto;
  padding: var(--s6) var(--s6) var(--s7);
  background: var(--bg);
}
.bento-header { max-width: 1360px; margin: 0 auto var(--s5); }
.bento-heading {
  margin: 0 0 var(--s1);
  font-family: var(--serif);
  font-size: 28px;
  font-weight: 400;
  line-height: 1.18;
}
.bento-sub { margin: 0; max-width: 620px; font-size: 13.5px; line-height: 1.6; color: var(--ink-2); }
.bento-board {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-auto-rows: 172px;
  grid-auto-flow: dense;
  gap: var(--s3);
  max-width: 1360px;
  margin: 0 auto;
}
.bento-cell {
  --folder: var(--line-strong);
  display: flex;
  flex-direction: column;
  gap: var(--s2);
  min-width: 0;
  padding: var(--s4);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: inset 0 2px 0 var(--folder), var(--shadow-sm);
  overflow: hidden;
  transition: border-color 140ms var(--ease), background 140ms var(--ease), transform 140ms var(--ease);
}
.bento-cell:hover { border-color: var(--line-strong); background: var(--surface-elevated); }
.bento-cell.is-off { opacity: 0.36; }
.bento-cell.is-large { grid-column: span 2; grid-row: span 2; }
.bento-cell.is-wide { grid-column: span 2; }
.bento-head {
  display: flex;
  align-items: center;
  gap: var(--s2);
  min-width: 0;
  flex: none;
}
.bento-dot { width: 8px; height: 8px; border-radius: 2px; background: var(--folder); flex: 0 0 auto; }
.bento-title {
  min-width: 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.25;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}
.bento-cell.is-large .bento-title { font-size: 22px; }
.bento-title:hover { color: var(--accent); }
.bento-count {
  margin-left: auto;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-3);
}
.bento-meta {
  flex: none;
  margin: 0;
  font-size: 12px;
  color: var(--ink-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bento-notes {
  display: grid;
  align-content: start;
  gap: 1px;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}
.bento-note {
  display: flex;
  align-items: baseline;
  gap: var(--s2);
  width: 100%;
  padding: 4px var(--s2);
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--ink-2);
  font-family: var(--sans);
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}
.bento-note:hover { background: var(--surface-2); color: var(--ink); }
.bento-note-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bento-note-meta {
  margin-left: auto;
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-3);
}
.bento-more {
  justify-self: start;
  padding: var(--s1) var(--s2);
  border: 0;
  background: none;
  color: var(--ink-3);
  font-family: var(--sans);
  font-size: 12px;
  cursor: pointer;
}
.bento-more:hover { color: var(--accent); }
.bento-foot {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s2);
  flex: none;
  margin-top: auto;
}
.bento-graph {
  align-self: flex-start;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink-3);
  font-family: var(--sans);
  font-size: 12px;
  cursor: pointer;
}
.bento-graph:hover { color: var(--accent); }
.bento-empty { grid-column: 1 / -1; max-width: 520px; padding: var(--s6) 0; }
.bento-empty h2 { margin: 0 0 var(--s2); font-family: var(--serif); font-size: 21px; font-weight: 400; }
.bento-empty p { margin: 0; font-size: 13px; line-height: 1.65; color: var(--ink-2); }

@media (max-width: 1180px) {
  .bento-board { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .bento-board { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .bento { padding: var(--s5) var(--s4) var(--s6); }
  .bento-board { grid-template-columns: 1fr; grid-auto-rows: auto; }
  .bento-cell.is-large, .bento-cell.is-wide { grid-column: span 1; grid-row: span 1; }
  .bento-notes { overflow: visible; }
}

/* ---------- decisions (structure notes) ---------- */
.decisions {
  position: fixed;
  top: var(--toolbar-h);
  left: var(--left);
  right: 0;
  bottom: var(--dock-h);
  overflow-y: auto;
  padding: var(--s6) var(--s6) var(--s7);
  background: var(--bg);
}
.decisions-head { max-width: 1180px; margin: 0 auto var(--s6); }
.decisions-title {
  margin: 0 0 var(--s1);
  font-family: var(--serif);
  font-size: 28px;
  font-weight: 400;
  line-height: 1.18;
}
.decisions-sub { margin: 0; font-size: 13.5px; line-height: 1.6; color: var(--ink-2); }
.decisions-board {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: var(--s4);
  max-width: 1180px;
  margin: 0 auto;
  align-items: start;
}
.decisions-summary {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: var(--s3);
}
.decisions-stat {
  display: flex;
  align-items: baseline;
  gap: var(--s2);
  padding: var(--s2) var(--s4);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.decisions-stat.is-due {
  border-color: var(--danger-line);
  background: var(--danger-soft);
}
.decisions-stat-value {
  font-family: var(--serif);
  font-size: 20px;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
.decisions-stat.is-due .decisions-stat-value,
.decisions-stat.is-due .decisions-stat-label {
  color: var(--danger);
}
.decisions-stat-label {
  font-size: 12px;
  color: var(--ink-3);
}
.decision-col { display: grid; gap: var(--s3); }
.decision-col-title {
  display: flex;
  align-items: baseline;
  gap: var(--s2);
  margin: 0;
  padding-bottom: var(--s2);
  border-bottom: 1px solid var(--line);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-2);
}
.decision-col-count {
  font-weight: 400;
  font-variant-numeric: tabular-nums;
  color: var(--ink-3);
}
.decision-card {
  display: grid;
  gap: var(--s2);
  padding: var(--s4);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  transition: border-color 140ms var(--ease), background 140ms var(--ease);
}
.decision-card:hover { border-color: var(--line-strong); background: var(--surface-elevated); }
.decision-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s2);
}
.decision-kind {
  display: inline-flex;
  padding: 2px 7px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  font-size: 11.5px;
  font-weight: 500;
  color: var(--ink-2);
}
.decision-title {
  justify-self: start;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.32;
  text-align: left;
  cursor: pointer;
}
.decision-title:hover { color: var(--accent); }
.decision-meta { margin: 0; font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.decision-sources { display: flex; flex-wrap: wrap; gap: var(--s1); }
.decision-source {
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--ink-2);
  font-family: var(--sans);
  font-size: 12px;
  line-height: 1.4;
  cursor: pointer;
  transition: border-color 120ms var(--ease), color 120ms var(--ease);
}
.decision-source:hover { border-color: var(--line-strong); color: var(--ink); }
.decision-missing { margin: 0; font-size: 12px; color: var(--danger); }
.decision-card.is-due { border-color: var(--danger-line); }
.decision-review {
  display: inline-flex;
  padding: 2px 7px;
  border: 1px solid var(--danger-line);
  border-radius: var(--r-sm);
  background: var(--danger-soft);
  font-size: 11.5px;
  font-weight: 500;
  color: var(--danger);
}
.decision-supersedes {
  justify-self: start;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink-3);
  font-family: var(--sans);
  font-size: 12px;
  text-align: left;
  cursor: pointer;
}
.decision-supersedes:hover { color: var(--accent); }
.decision-trail-link { color: var(--ink-2); font-weight: 500; }

/* Confidence meter (used in Decision Trail and Decision Cards). */
.confidence-meter {
  height: 5px;
  border-radius: 999px;
  background: var(--surface-3);
  overflow: hidden;
}
.confidence-fill {
  display: block;
  height: 100%;
  width: var(--confidence, 0%);
  border-radius: 999px;
  background: var(--accent);
}
.is-due .confidence-fill { background: var(--danger); }

/* The decision trail in the note panel: the why layer, not another graph. */
.decision-trail {
  display: grid;
  gap: var(--s2);
  margin: var(--s4) 0;
  padding: var(--s4);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--r);
  background: var(--surface-2);
}
.decision-trail.is-due { border-left-color: var(--danger); }
.trail-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); }
.trail-kicker { margin: 0; font-size: 12px; font-weight: 600; color: var(--ink); }
.trail-flag {
  padding: 2px 7px;
  border: 1px solid var(--danger-line);
  border-radius: var(--r-sm);
  background: var(--danger-soft);
  font-size: 11.5px;
  font-weight: 500;
  color: var(--danger);
}
.trail-facts { display: flex; flex-wrap: wrap; gap: var(--s2) var(--s3); align-items: center; }
.trail-fact { font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.trail-fact strong { color: var(--ink); font-weight: 500; }
.trail-status-pill {
  padding: 1px 6px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
}
.trail-review strong { color: var(--danger); }
.trail-supersedes {
  justify-self: start;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink-2);
  font-family: var(--sans);
  font-size: 12.5px;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}
.trail-supersedes:hover { color: var(--accent); }
.trail-help { margin: 0; font-size: 12px; line-height: 1.5; color: var(--ink-3); }
.decision-trail.is-flash { animation: trail-flash 1.2s var(--ease); }
@keyframes trail-flash {
  0%, 100% { background: var(--surface-2); }
  35% { background: var(--surface-3); }
}
.decisions-empty { grid-column: 1 / -1; max-width: 520px; margin: 0 auto; padding: var(--s6) 0; }
.decisions-empty h2 {
  margin: 0 0 var(--s2);
  font-family: var(--serif);
  font-size: 21px;
  font-weight: 400;
}
.decisions-empty p { margin: 0; font-size: 13px; line-height: 1.65; color: var(--ink-2); }
.decisions-more { grid-column: 1 / -1; margin: 0; font-size: 12px; color: var(--ink-3); }

@media (max-width: 720px) {
  .decisions { padding: var(--s5) var(--s4) var(--s6); }
}

/* ---------- settings ---------- */
.settings {
  position: fixed;
  inset: 0;
  z-index: 56;
  display: grid;
  place-items: center;
  padding: var(--s5);
  background: var(--scrim);
  backdrop-filter: blur(3px);
}
.settings-box {
  width: min(480px, 100%);
  max-height: 86svh;
  overflow-y: auto;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-lg);
  background: var(--surface-elevated);
  box-shadow: var(--shadow-lg);
}
.settings-head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  padding: var(--s3) var(--s4);
  border-bottom: 1px solid var(--line);
  background: var(--surface-elevated);
}
.settings-head h2 { margin: 0; font-size: 14px; font-weight: 600; }
.settings-body { display: grid; gap: var(--s5); padding: var(--s4); }
.settings-section { display: grid; gap: var(--s2); }
.settings-section h3 {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-3);
}
.settings-name { margin: 0; font-family: var(--serif); font-size: 22px; }
.settings-path {
  margin: 0;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-3);
  overflow-wrap: anywhere;
}
.badge {
  display: inline-flex;
  width: fit-content;
  margin: 0;
  padding: 2px 8px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  font-size: 12px;
  color: var(--ink-2);
}
.check { display: flex; align-items: center; gap: var(--s2); font-size: 12.5px; color: var(--ink-2); }
.check input { accent-color: var(--accent); }

.choice-row { display: flex; flex-wrap: wrap; gap: 6px; }
.choice {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface-2);
  color: var(--ink-2);
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: color 120ms var(--ease), border-color 120ms var(--ease), background 120ms var(--ease);
}
.choice:hover { color: var(--ink); border-color: var(--line-strong); }
.choice.is-active {
  color: var(--ink);
  border-color: var(--accent);
  background: var(--accent-soft);
}
.choice input { accent-color: var(--accent); margin: 0; }

.launch-views { margin: var(--s4) 0 0; padding: 0; border: 0; display: grid; gap: var(--s2); }
.launch-views legend { padding: 0; margin-bottom: var(--s1); }

/* A vault row opens the vault; the small button shows it in the OS. */
.vault-row { display: flex; align-items: stretch; gap: 2px; }
.vault-row .vault-item { flex: 1; min-width: 0; }
.vault-reveal {
  flex: none;
  width: 28px;
  border: 0;
  border-radius: var(--r);
  background: transparent;
  color: var(--ink-3);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  transition: color 120ms var(--ease), background 120ms var(--ease);
}
.vault-reveal .icon { width: 14px; height: 14px; }
.vault-reveal:hover:not(:disabled) { background: var(--surface-2); color: var(--ink); }
.vault-reveal:disabled { opacity: 0.3; cursor: default; }
.settings-actions { display: flex; flex-wrap: wrap; gap: var(--s2); margin-top: var(--s2); }

/* ---------- pinned notes in sidebar ---------- */
.pinned-list { display: grid; gap: 2px; }
.pinned-empty { margin: 0; font-size: 12px; line-height: 1.5; color: var(--ink-3); }
.pinned-row {
  display: flex;
  align-items: center;
  gap: 2px;
  border-radius: var(--r-sm);
}
.pinned-item {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s2);
  padding: 5px var(--s2);
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--ink-2);
  font-family: var(--sans);
  font-size: 12.5px;
  text-align: left;
  cursor: pointer;
}
.pinned-row:hover .pinned-item,
.pinned-row.is-active .pinned-item {
  background: var(--surface-2);
  color: var(--ink);
}
.pinned-row.is-active .pinned-title { color: var(--accent); font-weight: 600; }
.pinned-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pinned-folder { flex: none; font-size: 11px; color: var(--ink-3); }
.pinned-unpin {
  flex: none;
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--ink-3);
  font-size: 13px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 120ms var(--ease), color 120ms var(--ease);
}
.pinned-row:hover .pinned-unpin { opacity: 1; }
.pinned-unpin:hover { color: var(--danger); background: var(--surface-2); }

/* ---------- contextual backlink & mention snippets ---------- */
.relation-card {
  display: grid;
  gap: 4px;
  padding: var(--s2) var(--s3);
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface-2);
  transition: border-color 120ms var(--ease), background 120ms var(--ease);
}
.relation-card:hover {
  border-color: var(--line-strong);
  background: var(--surface-elevated);
}
.relation-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s2);
  min-width: 0;
}
.relation-top .relation {
  flex: 1;
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
}
.relation-top .relation:hover { background: transparent; }
.relation-snippet {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: 12px;
  line-height: 1.5;
  color: var(--ink-3);
}
.mention-highlight {
  padding: 1px 5px;
  border-radius: var(--r-sm);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 500;
}
.relation-link-btn {
  flex: none;
  padding: 2px 8px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--accent);
  font-family: var(--sans);
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 120ms var(--ease), background 120ms var(--ease);
}
.relation-link-btn:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

/* ---------- editor autocomplete popover ([[wikilink & /slash) ---------- */
.editor-host {
  position: relative;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
.editor-popover {
  position: absolute;
  top: var(--s3);
  left: var(--s3);
  z-index: 45;
  width: min(340px, calc(100% - var(--s5)));
  max-height: 290px;
  overflow-y: auto;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-lg);
  background: var(--surface-elevated);
  box-shadow: var(--shadow-lg);
}
.editor-popover-head {
  padding: 6px var(--s3);
  border-bottom: 1px solid var(--line);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.editor-popover-list {
  display: grid;
  padding: var(--s1);
}
.editor-popover-item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s2);
  width: 100%;
  padding: 7px var(--s2);
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--ink-2);
  font-family: var(--sans);
  font-size: 12.5px;
  text-align: left;
  cursor: pointer;
}
.editor-popover-item:hover,
.editor-popover-item.is-selected {
  background: var(--accent-soft);
  color: var(--ink);
}
.editor-popover-main {
  font-weight: 500;
  color: var(--ink);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.editor-popover-meta {
  flex: none;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-3);
}

/* ---------- notes studio workspace (3-column layout) ---------- */
/* Use position: absolute + z-index: auto (body is 100% viewport with overflow: hidden)
   so .notes-studio does NOT establish a stacking context (position: fixed always does
   in Blink/WebKit), letting .notes-inspector-pane.is-mobile-open (z-index: 45) sit above
   #mobile-backdrop (z-index: 40) while .notes-main-pane (z-index: 12) stays dimmed behind it. */
.notes-studio {
  position: absolute;
  top: var(--toolbar-h);
  left: var(--left);
  right: 0;
  bottom: var(--dock-h);
  z-index: auto;
  display: grid;
  grid-template-columns: var(--notes-list-w) minmax(0, 1fr) var(--notes-inspector-w);
  background: var(--bg);
  overflow: hidden;
}
.notes-studio.is-list-collapsed {
  grid-template-columns: 0px minmax(0, 1fr) var(--notes-inspector-w);
}
.notes-studio.is-inspector-collapsed {
  grid-template-columns: var(--notes-list-w) minmax(0, 1fr) 0px;
}
.notes-studio.is-list-collapsed.is-inspector-collapsed,
.notes-studio.is-zen {
  grid-template-columns: 0px minmax(0, 1fr) 0px;
}
@media (min-width: 761px) {
  #notes-toggle-list,
  .notes-tab-add {
    display: none;
  }
}
.notes-studio.is-list-collapsed .notes-list-pane,
.notes-studio.is-zen .notes-list-pane,
.notes-studio.is-inspector-collapsed .notes-inspector-pane:not(.is-mobile-open),
.notes-studio.is-zen .notes-inspector-pane:not(.is-mobile-open) {
  visibility: hidden;
  pointer-events: none;
  overflow: hidden;
  border: 0;
}

/* Left Note List Pane */
.notes-list-pane {
  position: relative;
  z-index: 12;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  border-right: 1px solid var(--line);
  background: var(--surface);
}
.notes-list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s2);
  padding: var(--s3) var(--s3) var(--s2);
}
.notes-list-title-wrap {
  display: flex;
  align-items: baseline;
  gap: var(--s2);
  min-width: 0;
}
.notes-list-title {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.notes-list-count {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-3);
}
.notes-list-actions {
  display: flex;
  align-items: center;
  gap: var(--s2);
  flex: none;
}
.btn-compact {
  padding: 4px 10px;
  font-size: 12px;
}
.notes-filter-wrap {
  position: relative;
  margin: 0 var(--s3) var(--s2);
}
.notes-filter-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  color: var(--ink-3);
  pointer-events: none;
}
.notes-filter-input {
  width: 100%;
  padding: 7px 10px 7px 30px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface-2);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 12.5px;
}
.notes-filter-input:focus {
  outline: none;
  border-color: var(--accent);
}
.notes-scopes {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 0 var(--s3) var(--s2);
  border-bottom: 1px solid var(--line);
}
.notes-scope {
  padding: 3px 9px;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--ink-3);
  font-family: var(--sans);
  font-size: 11.5px;
  font-weight: 500;
  cursor: pointer;
}
.notes-scope:hover { color: var(--ink); background: var(--surface-2); }
.notes-scope.is-active {
  border-color: var(--line-strong);
  background: var(--surface-2);
  color: var(--ink);
}
.notes-quick-form {
  padding: var(--s2) var(--s3);
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}
.notes-quick-input {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--accent);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 12.5px;
}
.notes-feed {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: var(--s2) var(--s2) calc(var(--s7) + var(--s4));
  scroll-padding-top: var(--s3);
  scroll-padding-bottom: calc(var(--s7) + var(--dock-h));
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.notes-feed-group {
  padding: var(--s2) var(--s2) 4px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.notes-feed-empty {
  padding: var(--s5) var(--s3);
  text-align: center;
  color: var(--ink-2);
  font-size: 13px;
}
.notes-feed-empty-sub {
  margin-top: var(--s1);
  font-size: 12px;
  color: var(--ink-3);
}
.notes-card {
  position: relative;
  display: flex;
  align-items: flex-start;
  border: 1px solid transparent;
  border-radius: var(--r);
  transition: background 120ms var(--ease), border-color 120ms var(--ease);
}
.notes-card:hover {
  background: var(--surface-2);
}
.notes-card.is-active {
  border-color: var(--line-strong);
  background: var(--surface-elevated);
  box-shadow: var(--shadow-sm);
}
.notes-card-main {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 4px;
  padding: var(--s2) var(--s3);
  border: 0;
  background: transparent;
  color: var(--ink);
  font-family: var(--sans);
  text-align: left;
  cursor: pointer;
}
.notes-card-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s2);
  min-width: 0;
}
.notes-card-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.notes-card.is-active .notes-card-title { color: var(--accent); }
.notes-card-date {
  flex: none;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-3);
}
.notes-card-excerpt {
  margin: 0;
  font-size: 12px;
  line-height: 1.45;
  color: var(--ink-2);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.notes-card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s2);
  margin-top: 2px;
  font-size: 11px;
  color: var(--ink-3);
}
.notes-card-folder {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.notes-card-dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  flex: none;
}
.notes-card-pin {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 24px;
  height: 24px;
  display: inline-grid;
  place-items: center;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--ink-3);
  cursor: pointer;
  opacity: 0;
  transition: opacity 120ms var(--ease), color 120ms var(--ease);
}
.notes-card-pin .icon { width: 13px; height: 13px; }
.notes-card:hover .notes-card-pin,
.notes-card-pin.is-pinned {
  opacity: 1;
}
.notes-card-pin.is-pinned { color: var(--accent); }

/* Center Main Document & Editor Pane */
.notes-main-pane {
  position: relative;
  z-index: 12;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg);
}
.notes-tabs-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 40px;
  padding: 0 var(--s3);
  border-bottom: 1px solid var(--line-subtle);
  background: var(--bg);
}
.notes-mobile-back {
  display: none;
}
.notes-mobile-back .icon {
  width: 15px;
  height: 15px;
}
.notes-tabs {
  display: flex;
  align-items: center;
  gap: 3px;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.notes-tabs::-webkit-scrollbar { display: none; }
.notes-tab {
  flex: none;
  display: inline-flex;
  align-items: center;
  max-width: 190px;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--ink-2);
  transition: background 120ms var(--ease), border-color 120ms var(--ease);
}
.notes-tab:hover { background: var(--surface-2); color: var(--ink); }
.notes-tab.is-active {
  border-color: var(--line-strong);
  background: var(--surface-elevated);
  color: var(--ink);
}
.notes-tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
  padding: 4px 6px 4px 10px;
  border: 0;
  background: transparent;
  color: inherit;
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
}
.notes-tab-pin { color: var(--accent); font-weight: 700; }
.notes-tab.is-dirty .notes-tab-title::after {
  content: ' •';
  color: var(--accent);
}
.notes-tab-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.notes-tab-close {
  flex: none;
  width: 20px;
  height: 20px;
  margin-right: 3px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--ink-3);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
}
.notes-tab-close:hover { background: var(--surface-3); color: var(--ink); }
.notes-toolbar-right {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: none;
}
.notes-save-status {
  padding: 2px 8px;
  border-radius: var(--r-sm);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-3);
}
.notes-save-status[data-state="dirty"],
.notes-save-status[data-state="saving"] {
  color: var(--accent);
}
.notes-view-modes {
  display: inline-flex;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface-2);
}
.notes-mode-btn {
  padding: 3px 9px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--ink-2);
  font-family: var(--sans);
  font-size: 11.5px;
  font-weight: 500;
  cursor: pointer;
}
.notes-mode-btn:hover:not(:disabled) { color: var(--ink); }
.notes-mode-btn.is-active {
  background: var(--surface-elevated);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}
.notes-mode-btn:disabled { opacity: 0.4; cursor: default; }

.notes-workspace {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  overflow: hidden;
}
.notes-canvas {
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  padding: var(--s6) var(--s6) var(--s7);
  scroll-padding-top: var(--s5);
  scroll-padding-bottom: calc(var(--s6) + var(--dock-h));
}
.notes-empty-state {
  max-width: 480px;
  margin: 14svh auto 0;
  text-align: center;
}
.notes-empty-state h2 {
  margin: 0 0 var(--s2);
  font-family: var(--serif);
  font-size: 24px;
  font-weight: 400;
}
.notes-empty-state p {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.65;
  color: var(--ink-2);
}

.studio-article {
  max-width: 740px;
  margin: 0 auto;
}
.studio-article-edit {
  display: flex;
  flex-direction: column;
  min-height: calc(100svh - 140px);
}
.studio-doc-head {
  display: grid;
  gap: var(--s2);
  margin-bottom: var(--s4);
  padding-bottom: var(--s3);
  border-bottom: 1px solid var(--line);
}
.studio-breadcrumbs {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--ink-3);
}
.studio-folder-crumb {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 7px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--ink-2);
  font-family: var(--sans);
  font-size: 12px;
  cursor: pointer;
}
.studio-folder-crumb:hover { border-color: var(--line-strong); color: var(--ink); }
.studio-crumb-dot { width: 7px; height: 7px; border-radius: 999px; }
.studio-note-crumb {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--ink-3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.studio-meta-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s2) var(--s3);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-3);
}
.studio-tags {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
}
.studio-tag-chip {
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--surface-2);
}
.studio-tag-chip:hover { border-color: var(--accent); color: var(--accent); }
.studio-frontmatter {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: var(--s2) var(--s3);
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface);
  font-family: var(--mono);
  font-size: 11.5px;
}
.studio-prop {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 7px;
  border-radius: var(--r-sm);
  background: var(--surface-2);
}
.studio-prop-key { color: var(--ink-3); }
.studio-prop-val { color: var(--ink); }

.studio-read-bar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s3);
  margin-bottom: var(--s4);
}
.studio-doc-title {
  margin: 0 0 var(--s3);
  font-family: var(--serif);
  font-size: 34px;
  font-weight: 400;
  line-height: 1.16;
  color: var(--ink);
}
.studio-read-bar .studio-doc-title { margin-bottom: 0; }
.studio-quick-edit { flex: none; font-size: 12px; }

.studio-split-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: var(--s5);
  max-width: 1440px;
  margin: 0 auto;
  min-height: calc(100svh - 150px);
}
.studio-editor-col,
.studio-preview-col {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.studio-preview-col {
  padding-left: var(--s5);
  border-left: 1px solid var(--line);
}
.studio-preview-kicker {
  margin-bottom: var(--s2);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.studio-editor-host {
  flex: 1;
  min-height: 440px;
}
.studio-editor {
  flex: 1;
  field-sizing: content;
  width: 100%;
  height: auto;
  min-block-size: 440px;
  font-size: 13.5px;
  line-height: 1.7;
}
.studio-prose h1.is-flash,
.studio-prose h2.is-flash,
.studio-prose h3.is-flash,
.studio-prose h4.is-flash {
  animation: trail-flash 1.1s var(--ease);
}

/* Notion-Style Right-Edge Floating Mini-Outline Rail */
.notes-mini-outline {
  position: absolute;
  top: 50%;
  right: 14px;
  transform: translateY(-50%);
  z-index: 25;
  display: flex;
  align-items: center;
}
.mini-outline-ticks {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 7px;
  padding: var(--s2) 6px;
  cursor: pointer;
}
.mini-outline-tick {
  display: block;
  height: 2px;
  border-radius: 999px;
  background: var(--line-strong);
  transition: background 120ms var(--ease), width 120ms var(--ease);
}
.mini-outline-tick.is-h1 { width: 18px; background: var(--ink-2); }
.mini-outline-tick.is-h2 { width: 14px; }
.mini-outline-tick.is-h3 { width: 10px; }
.mini-outline-tick.is-h4 { width: 7px; }
.notes-mini-outline:hover .mini-outline-tick { background: var(--accent); }

.mini-outline-card {
  position: absolute;
  right: 26px;
  top: 50%;
  transform: translateY(-50%) translateX(6px);
  width: 230px;
  max-height: 360px;
  overflow-y: auto;
  padding: var(--s2);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-lg);
  background: var(--surface-elevated);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 140ms var(--ease), transform 140ms var(--ease), visibility 140ms;
}
.notes-mini-outline:hover .mini-outline-card,
.notes-mini-outline:focus-within .mini-outline-card {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(-50%) translateX(0);
}
.mini-outline-kicker {
  margin: 0 0 6px;
  padding: 2px var(--s2);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.mini-outline-item {
  display: block;
  width: 100%;
  padding: 5px var(--s2);
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--ink-2);
  font-family: var(--sans);
  font-size: 12px;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}
.mini-outline-item:hover { background: var(--surface-2); color: var(--accent); }
.mini-outline-item.is-h2 { padding-left: 16px; }
.mini-outline-item.is-h3 { padding-left: 26px; font-size: 11.5px; color: var(--ink-3); }
.mini-outline-item.is-h4 { padding-left: 34px; font-size: 11px; color: var(--ink-3); }

/* Right Inspector Pane (Connections & Outline) */
.notes-inspector-pane {
  position: relative;
  z-index: 12;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  border-left: 1px solid var(--line);
  background: var(--surface);
}
.notes-inspector-head {
  display: flex;
  align-items: center;
  gap: var(--s1);
  padding: var(--s2);
  border-bottom: 1px solid var(--line);
}
.notes-inspector-tabs {
  flex: 1;
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 2px;
}
.notes-inspector-close {
  display: inline-grid;
  flex: none;
}
#notes-toggle-inspector {
  position: relative;
}
.inspector-badge {
  position: absolute;
  top: 1px;
  right: 1px;
  min-width: 14px;
  height: 14px;
  padding: 0 3px;
  border-radius: 999px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
  color: var(--accent);
  font-size: 9.5px;
  font-weight: 600;
  line-height: 12px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}
.notes-inspector-tab {
  padding: 6px 4px;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--ink-3);
  font-family: var(--sans);
  font-size: 11.5px;
  font-weight: 500;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}
.notes-inspector-tab:hover { color: var(--ink); background: var(--surface-2); }
.notes-inspector-tab.is-active {
  border-color: var(--line-strong);
  background: var(--surface-2);
  color: var(--ink);
}
.notes-inspector-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: var(--s3);
}
.inspector-section {
  display: grid;
  gap: var(--s2);
}
.inspector-kicker {
  margin: var(--s1) 0 0;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.inspector-help {
  margin: 0;
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--ink-3);
}
.inspector-cards {
  display: grid;
  gap: var(--s2);
}
.inspector-outline {
  display: grid;
  gap: 2px;
}
.inspector-outline-item {
  width: 100%;
  padding: 6px var(--s2);
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--ink-2);
  font-family: var(--sans);
  font-size: 12.5px;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.inspector-outline-item:hover { background: var(--surface-2); color: var(--accent); }
.inspector-outline-item.is-h1 { font-weight: 600; color: var(--ink); }
.inspector-outline-item.is-h2 { padding-left: 16px; }
.inspector-outline-item.is-h3 { padding-left: 28px; font-size: 12px; color: var(--ink-3); }
.inspector-outline-item.is-h4 { padding-left: 38px; font-size: 11.5px; color: var(--ink-3); }

/* Quick Note / Template Modal & Shortcuts Reference Modal */
.quick-note-box {
  width: min(560px, 100%);
  display: grid;
  gap: var(--s3);
}
.quick-note-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s3);
}
.quick-note-title {
  margin: 2px 0 0;
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 400;
}
.quick-note-grid {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: var(--s3);
}
.quick-note-field {
  display: grid;
  gap: var(--s1);
}
.quick-note-textarea {
  resize: vertical;
  min-height: 88px;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.55;
}
.shortcuts-box {
  width: min(740px, 100%);
}
.shortcuts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: var(--s5);
}
.shortcut-list {
  margin: 0;
  display: grid;
  gap: 8px;
}
.shortcut-list > div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s3);
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
  font-size: 12.5px;
}
.shortcut-list dt {
  flex: none;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--ink);
}
.shortcut-list dd {
  margin: 0;
  color: var(--ink-2);
  text-align: right;
}

@media (max-width: 1120px) {
  .notes-studio,
  .notes-studio.is-inspector-collapsed {
    grid-template-columns: 260px minmax(0, 1fr);
  }
  .notes-studio.is-list-collapsed,
  .notes-studio.is-list-collapsed.is-inspector-collapsed,
  .notes-studio.is-zen {
    grid-template-columns: 0px minmax(0, 1fr);
  }
  .notes-inspector-pane:not(.is-mobile-open) {
    display: none;
  }
  .notes-studio .notes-inspector-pane.is-mobile-open {
    display: flex;
    visibility: visible;
    pointer-events: auto;
    position: fixed;
    top: var(--toolbar-h);
    right: 0;
    bottom: var(--dock-h);
    width: min(360px, 90vw);
    z-index: 45;
    border-left: 1px solid var(--line-strong);
    box-shadow: var(--shadow-lg);
    padding-right: var(--safe-right);
    animation: panel-in 160ms var(--ease);
  }
  .notes-inspector-pane.is-mobile-open .notes-inspector-close {
    display: inline-grid;
  }
  .studio-split-layout { grid-template-columns: 1fr; }
  .studio-preview-col {
    padding-left: 0;
    padding-top: var(--s4);
    border-left: 0;
    border-top: 1px solid var(--line);
  }
}
@media (max-width: 900px) {
  .notes-mode-split { display: none; }
}

/* Forced Colors Mode (Windows High Contrast) compatibility. */
@media (forced-colors: active) {
  .view.is-active,
  .vault-item.is-active,
  .palette-hit.is-active,
  .choice.is-active {
    outline: 2px solid Highlight;
    outline-offset: -2px;
  }
  .confidence-meter { border: 1px solid CanvasText; }
  .confidence-fill { background: Highlight; forced-color-adjust: none; }
}

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

/* ---- Notes studio: folder explorer, calmer list, overflow menu ---- */
.notes-view-toggle {
  display: inline-flex;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface-2);
}
.notes-view-opt {
  padding: 2px 8px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--ink-3);
  font: inherit;
  font-size: 11.5px;
  cursor: pointer;
}
.notes-view-opt:hover { color: var(--ink); }
.notes-view-opt.is-active { background: var(--surface-3); color: var(--ink); }

.notes-feed.is-tree { gap: 0; padding: var(--s1) 4px calc(var(--s7) + var(--s4)); }
.tree-folder,
.tree-note {
  --indent: calc(var(--depth, 0) * 14px + 6px);
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  min-height: 26px;
  padding: 2px 6px 2px var(--indent);
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--ink-2);
  font: inherit;
  font-size: 12.5px;
  text-align: left;
  cursor: pointer;
}
.tree-folder:hover,
.tree-note:hover { background: var(--surface-2); color: var(--ink); }
.tree-folder { font-weight: 600; color: var(--ink); }
.tree-chevron {
  flex: none;
  width: 14px;
  height: 14px;
  position: relative;
}
.tree-chevron::before {
  content: '';
  position: absolute;
  left: 4px;
  top: 3px;
  width: 5px;
  height: 5px;
  border-right: 1.5px solid var(--ink-3);
  border-bottom: 1.5px solid var(--ink-3);
  transform: rotate(-45deg);
  transition: transform 120ms ease;
}
.tree-folder.is-open .tree-chevron::before { transform: rotate(45deg); }
.tree-folder-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-folder-count { flex: none; font-size: 10.5px; font-weight: 400; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.tree-note { padding-left: calc(var(--indent) + 20px); padding-right: 2px; }
.tree-note.is-active { background: var(--surface-3); color: var(--accent); }
.tree-note-main {
  flex: 1;
  min-width: 0;
  padding: 3px 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tree-note-pin {
  flex: none;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--ink-3);
  opacity: 0;
  cursor: pointer;
}
.tree-note-pin .icon { width: 12px; height: 12px; }
.tree-note:hover .tree-note-pin,
.tree-note-pin.is-pinned,
.tree-note-pin:focus-visible { opacity: 1; }
.tree-note-pin.is-pinned { color: var(--accent); }

/* Flat list: titles first, detail only on hover or for the open note. */
.notes-feed:not(.is-tree) .notes-card-excerpt,
.notes-feed:not(.is-tree) .notes-card-stats { display: none; }
.notes-feed:not(.is-tree) .notes-card:hover .notes-card-excerpt,
.notes-feed:not(.is-tree) .notes-card.is-active .notes-card-excerpt { display: -webkit-box; }

/* Secondary note actions live in one menu instead of four loose icons. */
.notes-more { position: relative; }
.notes-more-dots { font-size: 18px; line-height: 1; }
.notes-more-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 30;
  min-width: 210px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
}
.notes-more-menu[hidden] { display: none; }
.notes-more-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 10px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--ink-2);
  font: inherit;
  font-size: 12.5px;
  text-align: left;
  cursor: pointer;
}
.notes-more-item:hover { background: var(--surface-2); color: var(--ink); }
.notes-more-item.is-active { color: var(--accent); }

.notes-feed { padding-bottom: 44px; }
.notes-list-head { flex-wrap: wrap; row-gap: 6px; }
.notes-list-title { white-space: nowrap; }

/* ---- Obsidian-style Notes Live Preview editor & selection bubble ------ */

.studio-doc-top {
  display: grid;
  gap: var(--s2);
}
.studio-article-live {
  position: relative;
}
.studio-article-live .studio-doc-top {
  margin-bottom: var(--s3);
  padding-bottom: var(--s3);
  border-bottom: 1px solid var(--line-subtle);
}
.studio-article-live .studio-editor-bar {
  position: sticky;
  top: calc(-1 * var(--s6));
  z-index: 15;
  margin-bottom: var(--s3);
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.studio-live-host {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--s3);
}

.studio-properties {
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface);
  overflow: hidden;
}
.studio-properties > summary,
.studio-properties-summary {
  display: flex;
  align-items: center;
  gap: var(--s2);
  padding: var(--s2) var(--s3);
  color: var(--ink-3);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.studio-properties > summary::-webkit-details-marker,
.studio-properties-summary::-webkit-details-marker {
  display: none;
}
.studio-properties > summary::before,
.studio-properties-summary::before {
  content: "";
  display: inline-block;
  width: 5px;
  height: 5px;
  border-right: 1.5px solid var(--ink-3);
  border-bottom: 1.5px solid var(--ink-3);
  transform: rotate(-45deg);
  transition: transform 120ms var(--ease);
  flex: none;
}
.studio-properties[open] > summary::before,
.studio-properties[open] > .studio-properties-summary::before {
  transform: rotate(45deg);
}
@media (hover: hover) {
  .studio-properties > summary:hover,
  .studio-properties-summary:hover {
    color: var(--ink);
    background: var(--surface-2);
  }
}
.studio-properties > div,
.studio-properties-body,
.studio-properties-list {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: var(--s2) var(--s3) var(--s3);
  border-top: 1px solid var(--line-subtle);
}
.studio-prop-chip,
.studio-properties .studio-prop {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--ink-2);
}
.studio-tag-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px 2px 9px;
  border: 1px solid var(--accent-line);
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11.5px;
  font-weight: 500;
  line-height: 1.4;
}
.studio-tag-pill-label,
.studio-tag-pill > button:first-child {
  appearance: none;
  border: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
}
.studio-tag-remove,
.studio-tag-pill .studio-tag-x {
  appearance: none;
  display: inline-grid;
  place-items: center;
  width: 16px;
  height: 16px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--accent);
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  opacity: 0.72;
  transition: opacity 120ms var(--ease), color 120ms var(--ease), background 120ms var(--ease);
}
@media (hover: hover) {
  .studio-tag-remove:hover,
  .studio-tag-pill .studio-tag-x:hover {
    opacity: 1;
    color: var(--danger);
    background: var(--danger-soft);
  }
}
.studio-tag-add {
  field-sizing: content;
  min-width: 68px;
  max-width: 180px;
  padding: 3px 9px;
  border: 1px dashed var(--line-strong);
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 11.5px;
  line-height: 1.4;
  transition: border-color 120ms var(--ease), background 120ms var(--ease);
}
.studio-tag-add::placeholder {
  color: var(--ink-3);
}
.studio-tag-add:focus {
  outline: none;
  border-style: solid;
  border-color: var(--accent);
  background: var(--surface-2);
}

.studio-inline-title {
  display: block;
  width: 100%;
  margin: 0;
  padding: 2px 0 4px;
  border: 0;
  border-bottom: 1px solid transparent;
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 34px;
  font-weight: 400;
  line-height: 1.16;
  letter-spacing: -0.01em;
  transition: border-color 140ms var(--ease);
}
.studio-inline-title::placeholder {
  color: var(--ink-3);
}
.studio-inline-title:focus,
.studio-inline-title:focus-visible {
  outline: none;
  border-bottom-color: var(--accent-line);
}

.live-editor {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-block-size: 280px;
}
.live-block {
  position: relative;
  padding: 4px var(--s2);
  margin: 0 calc(-1 * var(--s2));
  border: 1px solid transparent;
  border-radius: var(--r);
  cursor: text;
  transition: background 120ms var(--ease), border-color 120ms var(--ease), box-shadow 120ms var(--ease);
}
@media (hover: hover) {
  .live-block:hover:not(.is-editing) {
    background: var(--surface);
    border-color: var(--line-subtle);
  }
}
.live-block-view.prose {
  margin-top: 0;
}
.live-block-view.prose > :first-child {
  margin-top: 0;
}
.live-block-view.prose > :last-child {
  margin-bottom: 0;
}
.live-block.is-editing {
  background: var(--accent-soft);
  border-color: var(--accent-line);
  box-shadow: var(--shadow-sm);
  padding: var(--s2) var(--s3);
}
.live-block-input {
  display: block;
  width: 100%;
  height: auto;
  min-block-size: 1.74em;
  field-sizing: content;
  resize: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.74;
  overflow: hidden;
}
.live-block-input:focus,
.live-block-input:focus-visible {
  outline: none;
}
.live-block.is-editing.is-heading .live-block-input {
  font-family: var(--serif);
  font-size: 22px;
  line-height: 1.3;
  color: var(--ink);
}
.live-block.is-editing.is-code .live-block-input,
.live-block.is-editing.is-math .live-block-input,
.live-block.is-editing.is-table .live-block-input {
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.6;
}
.live-block.is-editing.is-blockquote .live-block-input,
.live-block.is-editing.is-callout .live-block-input {
  color: var(--prose-ink);
}
.live-block-append {
  appearance: none;
  display: block;
  width: 100%;
  min-block-size: 72px;
  margin-top: var(--s2);
  padding: var(--s3) var(--s2);
  border: 1px dashed transparent;
  border-radius: var(--r);
  background: transparent;
  color: var(--ink-3);
  font-family: var(--sans);
  font-size: 13px;
  text-align: left;
  cursor: text;
  opacity: 0.68;
  transition: opacity 140ms var(--ease), border-color 140ms var(--ease), background 140ms var(--ease);
}
@media (hover: hover) {
  .live-block-append:hover {
    opacity: 1;
    border-color: var(--line);
    background: var(--surface);
  }
}
.live-block-append:focus-visible {
  opacity: 1;
  border-color: var(--accent-line);
}

.selection-bubble {
  position: absolute;
  z-index: 46;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface-elevated);
  box-shadow: var(--shadow-lg);
  transform: translate(-50%, calc(-100% - 8px));
  animation: bubble-in 120ms var(--ease);
}
@keyframes bubble-in {
  from {
    opacity: 0;
    transform: translate(-50%, calc(-100% - 2px)) scale(0.96);
  }
}
.selection-bubble button {
  appearance: none;
  display: inline-grid;
  place-items: center;
  min-width: 28px;
  height: 28px;
  padding: 0 7px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--ink-2);
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 100ms var(--ease), color 100ms var(--ease);
}
@media (hover: hover) {
  .selection-bubble button:hover {
    background: var(--accent-soft);
    color: var(--accent);
  }
}

/* ---- local vaults, mobile sheets, touch & iOS/mobile layout ----------- */

.local-vault {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: grid;
  place-items: center;
  padding: var(--s5);
  background: var(--scrim);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}
.local-vault[hidden] { display: none; }
.local-vault-card {
  width: min(480px, 100%);
  max-height: calc(100svh - 32px);
  overflow-y: auto;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-lg);
  background: var(--surface-elevated);
  color: var(--ink);
  padding: var(--s5);
  box-shadow: var(--shadow-lg);
  transition: border-color 140ms var(--ease), background 140ms var(--ease), box-shadow 140ms var(--ease);
}
.local-vault-card.is-dragover {
  border-color: var(--accent);
  background: var(--surface-elevated);
  box-shadow: 0 0 0 2px var(--accent-soft), var(--shadow-lg);
}
.local-vault-card h2 {
  margin: 0 0 var(--s2);
  font-family: var(--serif);
  font-size: 20px;
  font-weight: 400;
  line-height: 1.3;
}
.local-vault-copy,
.local-vault-help {
  margin: 0 0 var(--s3);
  color: var(--ink-2);
  font-size: 13px;
  line-height: 1.55;
}
.local-vault-ios-guide {
  margin: 0 0 var(--s3);
  padding: var(--s3);
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: 12.5px;
  line-height: 1.5;
}
.local-vault-ios-title {
  margin: 0 0 var(--s2);
  color: var(--ink);
  font-weight: 500;
}
.local-vault-ios-steps {
  margin: 0;
  padding-left: var(--s4);
  display: grid;
  gap: 4px;
}
.local-vault-status {
  min-height: 1.2em;
  margin: 0 0 var(--s3);
  font-size: 12.5px;
  color: var(--accent);
}
.local-vault-actions {
  display: flex;
  gap: var(--s2);
  margin-bottom: var(--s3);
}
.local-vault-actions .btn { min-height: 40px; }
.local-vault-foot {
  display: flex;
  justify-content: space-between;
  gap: var(--s3);
  margin-top: var(--s3);
}

/* Mobile backdrop & "More" bottom sheet */
.mobile-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: var(--scrim);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}
.mobile-more-sheet {
  position: fixed;
  left: max(var(--s2), var(--safe-left));
  right: max(var(--s2), var(--safe-right));
  bottom: calc(var(--dock-h) + var(--s2));
  z-index: 50;
  max-height: calc(100svh - var(--toolbar-h) - var(--dock-h) - var(--s5));
  overflow-y: auto;
  display: grid;
  gap: var(--s3);
  padding: var(--s3);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-lg);
  background: var(--surface-elevated);
  box-shadow: var(--shadow-lg);
  animation: sheet-up 160ms var(--ease);
}
@keyframes sheet-up {
  from {
    transform: translateY(14px);
    opacity: 0;
  }
}
.mobile-more-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s2);
  padding-bottom: var(--s2);
  border-bottom: 1px solid var(--line);
}
.mobile-more-title {
  margin: 0;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink);
}
.mobile-more-group {
  display: grid;
  gap: 4px;
}
.mobile-more-kicker {
  margin: 0 0 2px;
  padding: 0 var(--s2);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.mobile-sheet-item {
  appearance: none;
  display: flex;
  align-items: center;
  gap: var(--s3);
  width: 100%;
  min-height: 44px;
  padding: var(--s2) var(--s3);
  border: 1px solid transparent;
  border-radius: var(--r);
  background: var(--surface-2);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background 120ms var(--ease), border-color 120ms var(--ease), color 120ms var(--ease);
}
.mobile-sheet-item .icon {
  width: 18px;
  height: 18px;
  color: var(--ink-2);
}
.mobile-sheet-item.is-active {
  border-color: var(--accent-line);
  background: var(--accent-soft);
  color: var(--accent);
}
.mobile-sheet-item.is-active .icon {
  color: var(--accent);
}

/* Coarse pointer (touch) hit-target adaptation */
@media (pointer: coarse) {
  :root {
    --target-size: 44px;
  }
  .icon-button,
  .search-button,
  .view,
  .editor-tool {
    min-width: var(--target-size);
    min-height: var(--target-size);
  }
  .btn,
  .choice,
  .notes-mode-btn,
  .notes-scope,
  .notes-view-opt,
  .notes-inspector-tab,
  .mobile-sheet-item,
  .notes-more-item,
  .tree-folder,
  .tree-note,
  .folder-item,
  .vault-item,
  .relation {
    min-height: var(--target-size);
  }
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not(.studio-tag-add),
  textarea:not(.live-block-input) {
    min-height: var(--target-size);
  }
  .notes-card-pin,
  .tree-note-pin,
  .pinned-unpin {
    opacity: 1;
    min-width: 36px;
    min-height: 36px;
  }
  .selection-bubble button {
    min-width: 36px;
    height: 36px;
  }
}

/* iOS / Mobile shell (<= 760px) */
@media (max-width: 760px) {
  :root {
    --toolbar-h: calc(52px + var(--safe-top));
    --dock-h: calc(60px + var(--safe-bottom));
  }

  .toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 4px;
    height: var(--toolbar-h);
    min-height: var(--toolbar-h);
    padding: var(--safe-top) max(10px, var(--safe-right)) 0 max(10px, var(--safe-left));
  }
  .toolbar-left {
    flex: 1 1 auto;
    min-width: 0;
    gap: 2px;
  }
  .toolbar-actions {
    flex: 0 0 auto;
    gap: 2px;
  }
  .brand-mark,
  .vault-path,
  .toolbar-more {
    display: none;
  }
  .vault-button {
    flex: 0 1 auto;
    min-width: 0;
    max-width: min(160px, 100%);
    grid-template-areas: "name caret";
    padding: 4px 6px;
  }
  .search-button {
    width: 40px;
    height: 40px;
    padding: 0;
    justify-content: center;
    border-color: transparent;
    background: transparent;
    color: var(--ink-2);
  }
  .search-button span,
  .search-button kbd {
    display: none;
  }
  .icon-button {
    width: 40px;
    height: 40px;
  }
  .open-vault-button {
    width: 40px;
    height: 40px;
    padding: 0;
    justify-content: center;
    border-color: transparent;
    background: transparent;
  }
  .open-vault-button span {
    display: none;
  }

  /* Bottom iOS-style 5-tab navigation dock */
  .views {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 32;
    min-block-size: var(--dock-h);
    padding: 6px max(8px, var(--safe-right)) max(6px, var(--safe-bottom)) max(8px, var(--safe-left));
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    align-items: stretch;
    gap: 2px;
    border: 0;
    border-top: 1px solid var(--line);
    border-radius: 0;
    background: var(--surface);
    box-shadow: var(--shadow-sm);
  }
  .views [data-mobile-tier="secondary"] {
    display: none;
  }
  #mobile-more-btn {
    display: flex;
  }
  .views .view {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-width: 0;
    min-height: 44px;
    padding: 4px 2px;
    border-radius: var(--r);
    font-size: 10.5px;
    font-weight: 500;
    line-height: 1.1;
    color: var(--ink-3);
    background: transparent;
    box-shadow: none;
  }
  .views .view .view-icon {
    display: block;
    width: 20px;
    height: 20px;
  }
  .views .view .view-label {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .views .view.is-active,
  .views .view[aria-expanded="true"] {
    color: var(--accent);
    background: var(--accent-soft);
    box-shadow: none;
  }

  /* Offset floating bars & views above the bottom dock */
  .timeline {
    bottom: calc(var(--dock-h) + var(--s3));
    width: calc(100vw - 24px);
    left: 50%;
  }
  .toast {
    bottom: calc(var(--dock-h) + var(--s3));
    left: 50%;
  }
  .bento,
  .decisions {
    padding: var(--s4) max(var(--s4), var(--safe-right)) calc(var(--dock-h) + var(--s5)) max(var(--s4), var(--safe-left));
  }
  .resize-handle,
  .sidebar-hint {
    display: none;
  }

  /* Mobile slide-over drawers (sidebar, note panel, inspector) */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    height: 100svh;
    width: min(320px, 86vw);
    z-index: 45;
    padding: calc(var(--s4) + var(--safe-top)) var(--s3) calc(var(--s4) + var(--safe-bottom)) max(var(--s3), var(--safe-left));
    border-right: 1px solid var(--line-strong);
    box-shadow: var(--shadow-lg);
  }
  .panel {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100svh;
    z-index: 45;
    border-left: 0;
    box-shadow: var(--shadow-lg);
  }
  .panel-head {
    padding-top: calc(var(--s2) + var(--safe-top));
    padding-left: max(var(--s3), var(--safe-left));
    padding-right: max(var(--s3), var(--safe-right));
  }
  .panel-scroll {
    padding: var(--s4) max(var(--s4), var(--safe-right)) var(--s6) max(var(--s4), var(--safe-left));
  }
  .panel-actions {
    padding-bottom: calc(var(--s2) + var(--safe-bottom));
    padding-left: max(var(--s3), var(--safe-left));
    padding-right: max(var(--s3), var(--safe-right));
  }
  .notes-studio .notes-inspector-pane.is-mobile-open {
    top: 0;
    bottom: 0;
    height: 100svh;
    padding-top: var(--safe-top);
    padding-bottom: var(--safe-bottom);
    padding-right: var(--safe-right);
  }

  /* Notes Studio mobile two-step navigation (list -> reading/editing) */
  .notes-studio,
  .notes-studio.is-list-collapsed,
  .notes-studio.is-inspector-collapsed,
  .notes-studio.is-list-collapsed.is-inspector-collapsed,
  .notes-studio.is-zen {
    grid-template-columns: 1fr;
    bottom: var(--dock-h);
  }
  .notes-studio:not(.is-mobile-reading) .notes-main-pane {
    display: none;
  }
  .notes-studio:not(.is-mobile-reading) .notes-list-pane {
    display: flex;
    width: 100%;
    visibility: visible;
    pointer-events: auto;
    border-right: 0;
  }
  .notes-studio.is-mobile-reading .notes-list-pane {
    display: none;
  }
  .notes-studio.is-mobile-reading .notes-main-pane {
    display: flex;
    width: 100%;
  }
  .notes-studio.is-mobile-reading .notes-mobile-back {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    flex: none;
    padding: 4px 8px 4px 4px;
    min-height: 40px;
  }
  .notes-studio.is-mobile-reading .notes-tabs,
  .notes-studio.is-mobile-reading #notes-toggle-list,
  .notes-studio.is-mobile-reading #notes-tab-new,
  .notes-studio.is-mobile-reading .notes-mini-outline,
  .notes-studio.is-mobile-reading .notes-mode-split {
    display: none;
  }
  .notes-studio.is-mobile-reading .notes-tabs-bar {
    height: auto;
    min-height: 48px;
    justify-content: space-between;
    gap: 4px;
    padding: var(--s1) max(var(--s2), var(--safe-right)) var(--s1) max(var(--s2), var(--safe-left));
  }
  .notes-studio.is-mobile-reading .notes-toolbar-right {
    gap: 2px;
    min-width: 0;
  }
  .notes-studio.is-mobile-reading .notes-toolbar-right .icon-button {
    width: 36px;
    min-width: 36px;
    height: 40px;
    min-height: 40px;
  }
  .notes-studio.is-mobile-reading .notes-mode-btn {
    padding: 4px 7px;
    min-height: 34px;
    font-size: 11.5px;
  }
  .notes-studio.is-mobile-reading .notes-save-status {
    display: none;
  }
  .notes-studio.is-mobile-reading .notes-save-status[data-state="dirty"],
  .notes-studio.is-mobile-reading .notes-save-status[data-state="saving"] {
    display: inline-flex;
    padding: 2px 6px;
    font-size: 10.5px;
  }
  .notes-canvas {
    padding: var(--s4) max(var(--s4), var(--safe-right)) calc(var(--s7) + var(--s4)) max(var(--s4), var(--safe-left));
  }

  /* Horizontal scrollable sticky formatting ribbon on mobile */
  .studio-editor-bar {
    position: sticky;
    top: calc(-1 * var(--s4));
    z-index: 15;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
    mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 20px), transparent 100%);
    -webkit-mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 20px), transparent 100%);
    padding-right: var(--s5);
  }
  .studio-editor-bar::-webkit-scrollbar { display: none; }
  .studio-editor-bar .editor-tool {
    scroll-snap-align: start;
    flex: none;
  }

  /* Prevent iOS Safari auto-zoom on form controls (font-size >= 16px) */
  #notes-filter,
  #studio-editor,
  .live-block-input,
  .studio-tag-add,
  #palette-input,
  #notes-quick-input,
  .field-input,
  .quick-note-textarea,
  .tally-add-input {
    font-size: 16px;
  }
  .studio-inline-title {
    font-size: 26px;
  }

  .quick-note-grid { grid-template-columns: 1fr; }
  .local-vault { padding: max(16px, var(--safe-top)) 16px max(16px, var(--safe-bottom)); }
  .local-vault-card { padding: 18px; border-radius: var(--r-lg); }
  .local-vault-actions { flex-direction: column; }
  .local-vault-actions .btn { width: 100%; min-height: 46px; }
}
