/* mybrain — an Obsidian-style workspace.
   Tokens approximate Obsidian's default theme. Dark follows the system unless
   the user picked a theme (data-theme on <html>). */

:root {
  --bg: #ffffff;              /* background-primary */
  --bg-alt: #fafafa;          /* background-primary-alt */
  --surface: #f6f6f6;         /* background-secondary */
  --surface-alt: #ebebeb;
  --hover: rgba(0, 0, 0, .06);
  --active: rgba(0, 0, 0, .09);
  --fg: #222222;
  --muted: #5c5c5c;
  --faint: #ababab;
  --line: #e0e0e0;
  --line-strong: #cfcfcf;
  --accent: #705dcf;
  --accent-hover: #7f6df2;
  --accent-fg: #ffffff;
  --accent-soft: rgba(112, 93, 207, .14);
  --link: #705dcf;
  --unresolved: #9a8fd6;
  --danger: #e93147;
  --mark: rgba(255, 208, 0, .4);
  --code-bg: #f6f6f6;
  --shadow: 0 6px 24px rgba(0, 0, 0, .14), 0 1px 3px rgba(0, 0, 0, .08);
  /* Data colours (graph groups, canvas presets 1–6: red, orange, yellow, green, cyan, purple). */
  --c1: #e93147; --c2: #ec7500; --c3: #e0ac00; --c4: #08b94e; --c5: #00bfbc; --c6: #7852ee;

  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, monospace;
  --ribbon: 44px;
  --left: 260px;
  --right: 300px;
  --header: 40px;
  --radius: 6px;
  --line-width: 700px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1e1e1e; --bg-alt: #242424; --surface: #262626; --surface-alt: #2f2f2f;
    --hover: rgba(255, 255, 255, .07); --active: rgba(255, 255, 255, .1);
    --fg: #dadada; --muted: #b3b3b3; --faint: #666666; --line: #363636; --line-strong: #444444;
    --accent: #8a5cf5; --accent-hover: #9a74f7; --accent-soft: rgba(138, 92, 245, .2);
    --link: #a88bfa; --unresolved: #7f6aa8; --mark: rgba(255, 208, 0, .3); --code-bg: #262626;
    --shadow: 0 8px 28px rgba(0, 0, 0, .5), 0 1px 3px rgba(0, 0, 0, .4);
    --c1: #fb464c; --c2: #e9973f; --c3: #e0de71; --c4: #44cf6e; --c5: #53dfdd; --c6: #a882ff;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1e1e1e; --bg-alt: #242424; --surface: #262626; --surface-alt: #2f2f2f;
  --hover: rgba(255, 255, 255, .07); --active: rgba(255, 255, 255, .1);
  --fg: #dadada; --muted: #b3b3b3; --faint: #666666; --line: #363636; --line-strong: #444444;
  --accent: #8a5cf5; --accent-hover: #9a74f7; --accent-soft: rgba(138, 92, 245, .2);
  --link: #a88bfa; --unresolved: #7f6aa8; --mark: rgba(255, 208, 0, .3); --code-bg: #262626;
  --shadow: 0 8px 28px rgba(0, 0, 0, .5), 0 1px 3px rgba(0, 0, 0, .4);
  --c1: #fb464c; --c2: #e9973f; --c3: #e0de71; --c4: #44cf6e; --c5: #53dfdd; --c6: #a882ff;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; overflow: hidden; }
body { background: var(--bg); color: var(--fg); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--link); }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12px; }
.row { display: flex; gap: 8px; align-items: center; }
.row.end { justify-content: flex-end; }
.icon { flex: none; stroke-width: 1.75; }

/* --- controls ------------------------------------------------------------- */
button {
  font: 500 13px/1 var(--font); padding: 7px 12px; border-radius: var(--radius); cursor: pointer;
  border: 0; background: var(--surface-alt); color: var(--fg); box-shadow: 0 0 0 1px var(--line) inset;
}
button:hover { background: var(--active); }
button.primary, button.mod-cta { background: var(--accent); color: var(--accent-fg); box-shadow: none; }
button.primary:hover, button.mod-cta:hover { background: var(--accent-hover); }
button.danger { background: var(--danger); color: #fff; box-shadow: none; }
button.small { font-size: 12px; padding: 5px 9px; }
button.on { background: var(--accent-soft); color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
button:disabled { opacity: .5; cursor: progress; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible, [tabindex]:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.clickable-icon {
  display: inline-flex; align-items: center; justify-content: center; padding: 6px; border-radius: var(--radius);
  background: transparent; box-shadow: none; color: var(--muted);
}
.clickable-icon:hover { background: var(--hover); color: var(--fg); }
.clickable-icon.is-active { color: var(--accent); background: var(--accent-soft); }

input[type="text"], input[type="password"], input[type="search"], input[type="number"], select {
  width: 100%; font: 14px var(--font); padding: 6px 10px; color: var(--fg); background: var(--bg);
  border: 1px solid var(--line-strong); border-radius: var(--radius);
}
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
input[type="range"] { width: 100%; accent-color: var(--accent); }
input[type="checkbox"] { accent-color: var(--accent); }
input.code { font-family: var(--mono); letter-spacing: .25em; }
label.field { display: grid; gap: 6px; font-size: 13px; font-weight: 600; margin-bottom: 14px; }
.error { color: var(--danger); font-weight: 600; min-height: 1.2em; margin: 0 0 12px; }

/* --- sign-in --------------------------------------------------------------- */
.login { height: 100%; display: grid; place-items: center; padding: 24px 16px; background: var(--surface); overflow: auto; }
.login form { width: 100%; max-width: 360px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 28px; box-shadow: var(--shadow); }
.login h1 { font-size: 22px; margin: 0 0 4px; }
.login .sub { margin: 0 0 22px; color: var(--muted); }
.wordmark { font-weight: 700; letter-spacing: -.01em; }
.wordmark b { color: var(--accent); }

/* --- workspace grid -------------------------------------------------------- */
.app { display: grid; height: 100%; grid-template-columns: var(--ribbon) auto 1fr auto; grid-template-rows: 1fr; }
.ribbon { grid-column: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 0;
  background: var(--surface); border-right: 1px solid var(--line); }
.ribbon .spacer { flex: 1; }
.sidebar { background: var(--surface); display: flex; flex-direction: column; min-height: 0; overflow: hidden; width: var(--left); }
.sidebar.left { grid-column: 2; border-right: 1px solid var(--line); }
.sidebar.right { grid-column: 4; width: var(--right); border-left: 1px solid var(--line); }
.app.left-collapsed .sidebar.left, .app.right-collapsed .sidebar.right { display: none; }
.sidebar-tabs { display: flex; gap: 2px; padding: 6px 8px; height: var(--header); align-items: center; border-bottom: 1px solid var(--line); flex: none; }
.sidebar-tabs .push { margin-left: auto; }
.sidebar-body { flex: 1; overflow: auto; padding: 6px 6px 24px; min-height: 0; }
.pane-title { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--muted); padding: 10px 8px 6px; text-transform: none; }
.pane-title .push { margin-left: auto; }
.pane-section + .pane-section { border-top: 1px solid var(--line); margin-top: 8px; }
.empty-state { color: var(--faint); font-size: 13px; padding: 8px; }

.main-area { grid-column: 3; display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }

/* --- tabs ------------------------------------------------------------------- */
.tab-bar { display: flex; align-items: flex-end; height: var(--header); background: var(--surface); border-bottom: 1px solid var(--line);
  padding: 0 6px; gap: 2px; flex: none; overflow-x: auto; scrollbar-width: none; }
.tab-bar::-webkit-scrollbar { display: none; }
.tab { display: flex; align-items: center; gap: 6px; height: 32px; padding: 0 6px 0 10px; max-width: 220px; min-width: 90px;
  border-radius: var(--radius) var(--radius) 0 0; color: var(--muted); cursor: pointer; font-size: 13px; user-select: none; flex: none; }
.tab:hover { background: var(--hover); color: var(--fg); }
.tab.active { background: var(--bg); color: var(--fg); box-shadow: 0 0 0 1px var(--line); clip-path: inset(-1px -1px 0 -1px); }
.tab .title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tab .clickable-icon { padding: 2px; opacity: 0; }
.tab:hover .clickable-icon, .tab.active .clickable-icon { opacity: 1; }
.tab-bar .new-tab { margin: 0 0 4px 4px; align-self: center; }

/* --- view header ---------------------------------------------------------- */
.view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.view-header { display: flex; align-items: center; gap: 4px; height: var(--header); padding: 0 8px; flex: none; }
.view-title { flex: 1; text-align: center; font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.view-title .sep { color: var(--faint); margin: 0 4px; }
.view-title b { color: var(--fg); font-weight: 500; }
.view-content { flex: 1; overflow: auto; min-height: 0; position: relative; }
.readable { max-width: var(--line-width); margin: 0 auto; padding: 24px 32px 120px; }

/* --- reading view (markdown-preview) -------------------------------------- */
.inline-title { font-size: 2em; font-weight: 700; line-height: 1.2; margin: 8px 0 16px; letter-spacing: -.015em; outline: none; overflow-wrap: anywhere; }
.properties { margin: 0 0 20px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.properties-title { font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.property { display: grid; grid-template-columns: 140px 1fr; gap: 8px; padding: 3px 0; font-size: 13px; align-items: baseline; }
.property .key { color: var(--muted); display: flex; gap: 6px; align-items: center; overflow: hidden; text-overflow: ellipsis; }
.property .value { overflow-wrap: anywhere; }
.pill { display: inline-block; font-size: 12px; padding: 1px 8px; margin: 1px 3px 1px 0; border-radius: 10px; background: var(--accent-soft); color: var(--accent); border: 0; cursor: pointer; }
.pill.plain { background: var(--surface-alt); color: var(--fg); cursor: default; }

.markdown { font-size: 16px; line-height: 1.6; overflow-wrap: break-word; }
.markdown > :first-child { margin-top: 0; }
.markdown h1, .markdown h2, .markdown h3, .markdown h4, .markdown h5, .markdown h6 { line-height: 1.3; margin: 1.4em 0 .5em; font-weight: 700; scroll-margin-top: 16px; }
.markdown h1 { font-size: 1.8em; } .markdown h2 { font-size: 1.5em; } .markdown h3 { font-size: 1.3em; }
.markdown h4 { font-size: 1.15em; } .markdown h5, .markdown h6 { font-size: 1em; }
.markdown p, .markdown ul, .markdown ol, .markdown pre, .markdown table, .markdown blockquote { margin: 0 0 1em; }
.markdown ul, .markdown ol { padding-left: 1.6em; }
.markdown li { margin: .15em 0; }
.markdown li::marker { color: var(--faint); }
.markdown a { color: var(--link); text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--link) 40%, transparent); text-underline-offset: 2px; }
.markdown a:hover { text-decoration-color: var(--link); }
.markdown a.external::after { content: "↗"; font-size: .75em; margin-left: 1px; vertical-align: super; }
.markdown .internal-link { text-decoration: none; }
.markdown .internal-link:hover { text-decoration: underline; }
.markdown .internal-link.is-unresolved { color: var(--unresolved); opacity: .85; cursor: pointer; }
.markdown code { font: .875em var(--mono); background: var(--code-bg); padding: .1em .35em; border-radius: 4px; color: #e0525f; }
:root[data-theme="dark"] .markdown code { color: #f08d8d; }
.markdown pre { background: var(--code-bg); padding: 12px 16px; overflow: auto; border-radius: var(--radius); border: 1px solid var(--line); }
.markdown pre code { background: none; padding: 0; color: var(--fg); font-size: 13px; line-height: 1.55; }
.markdown blockquote { border-left: 2px solid var(--accent); padding: 0 0 0 1em; margin-left: 0; color: var(--fg); }
.markdown mark { background: var(--mark); color: inherit; padding: 0 2px; border-radius: 2px; }
.markdown table { border-collapse: collapse; display: block; overflow-x: auto; font-size: 14px; }
.markdown th, .markdown td { border: 1px solid var(--line); padding: 6px 12px; text-align: left; vertical-align: top; }
.markdown th { background: var(--surface); font-weight: 600; }
.markdown hr { border: 0; border-top: 1px solid var(--line); margin: 2em 0; }
.markdown img { max-width: 100%; border-radius: 4px; }
.markdown .task-list-item { list-style: none; margin-left: -1.4em; }
.markdown .task-list-item input { margin: 0 .5em 0 0; vertical-align: middle; }
.markdown .tag { background: var(--accent-soft); color: var(--accent); border-radius: 10px; padding: 1px 7px; font-size: .875em; text-decoration: none; }
.markdown .tag:hover { background: var(--accent); color: var(--accent-fg); }

/* Callouts — Obsidian style: tinted box per type. */
.callout { --callout: var(--c5); background: color-mix(in srgb, var(--callout) 10%, transparent); border-radius: 4px; padding: 12px 16px; margin: 0 0 1em; }
.callout-title { display: flex; gap: 8px; align-items: center; font-weight: 600; color: var(--callout); margin-bottom: 4px; }
.callout-content > :last-child { margin-bottom: 0; }
.callout[data-callout="tip"], .callout[data-callout="success"], .callout[data-callout="check"], .callout[data-callout="done"] { --callout: var(--c4); }
.callout[data-callout="warning"], .callout[data-callout="caution"], .callout[data-callout="attention"] { --callout: var(--c2); }
.callout[data-callout="danger"], .callout[data-callout="error"], .callout[data-callout="bug"], .callout[data-callout="failure"] { --callout: var(--c1); }
.callout[data-callout="example"] { --callout: var(--c6); }
.callout[data-callout="quote"], .callout[data-callout="cite"] { --callout: var(--faint); }
.callout[data-callout="question"], .callout[data-callout="faq"], .callout[data-callout="help"] { --callout: var(--c3); }

/* Embeds ![[note]] */
.internal-embed { border-left: 2px solid var(--accent); padding: 4px 0 4px 16px; margin: 0 0 1em; }
.internal-embed .embed-title { font-weight: 600; font-size: 1.1em; margin-bottom: 8px; display: flex; gap: 6px; align-items: center; }
.internal-embed .embed-title a { color: var(--fg); text-decoration: none; }
.internal-embed .embed-title .clickable-icon { padding: 2px; margin-left: auto; }
.internal-embed.base-embed { border-left: 0; padding: 0; }

/* Backlinks & meta below the note */
.embedded-backlinks { margin-top: 48px; border-top: 1px solid var(--line); padding-top: 12px; }
.metadata-foot { margin-top: 24px; font-size: 12px; color: var(--faint); }

/* --- tree items (file explorer, outline, search, backlinks) ---------------- */
.tree-item { display: flex; align-items: center; gap: 4px; padding: 3px 8px 3px var(--indent, 8px); border-radius: var(--radius);
  color: var(--muted); font-size: 13px; cursor: pointer; text-decoration: none; user-select: none; min-height: 26px; }
.tree-item:hover { background: var(--hover); color: var(--fg); }
.tree-item.is-active { background: var(--active); color: var(--fg); }
.tree-item .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-item .flair { font-size: 11px; color: var(--faint); background: var(--surface-alt); border-radius: 4px; padding: 0 5px; text-transform: uppercase; }
.tree-item .collapse { width: 16px; display: inline-flex; color: var(--faint); }
.tree-item.folder { color: var(--fg); }
.tree-item.dragover { background: var(--accent-soft); box-shadow: 0 0 0 1px var(--accent) inset; }
.search-result { padding: 6px 8px; border-radius: var(--radius); cursor: pointer; display: block; text-decoration: none; color: var(--fg); }
.search-result:hover { background: var(--hover); }
.search-result .name { font-weight: 600; font-size: 13px; }
.search-result .match { font-size: 12px; color: var(--muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.search-result .match mark { background: var(--mark); color: inherit; }
.search-box { padding: 6px 8px; display: grid; gap: 6px; }

/* --- status bar ------------------------------------------------------------- */
.status-bar { position: fixed; right: 0; bottom: 0; display: flex; gap: 14px; padding: 4px 12px; font-size: 12px; color: var(--muted);
  background: var(--surface); border: 1px solid var(--line); border-right: 0; border-bottom: 0; border-top-left-radius: var(--radius); z-index: 5; }

/* --- CodeMirror Live Preview ------------------------------------------------ */
.cm-host { height: 100%; }
.cm-editor { height: 100%; font-size: 16px; }
.cm-editor.cm-focused { outline: none; }
.cm-scroller { font-family: var(--font); line-height: 1.6; }
.cm-content { max-width: var(--line-width); margin: 0 auto; padding: 0 32px 50vh; caret-color: var(--accent); }
.cm-line { padding: 0; }
.cm-cursor { border-left: 2px solid var(--accent); }
.cm-selectionBackground, .cm-focused .cm-selectionBackground, ::selection { background: var(--accent-soft) !important; }
.cm-activeLine { background: transparent; }
.cm-gutters { display: none; }
.cm-header-1 { font-size: 1.8em; font-weight: 700; line-height: 1.3; }
.cm-header-2 { font-size: 1.5em; font-weight: 700; line-height: 1.3; }
.cm-header-3 { font-size: 1.3em; font-weight: 700; }
.cm-header-4, .cm-header-5, .cm-header-6 { font-size: 1.1em; font-weight: 700; }
.cm-strong { font-weight: 700; }
.cm-em { font-style: italic; }
.cm-strike { text-decoration: line-through; }
.cm-formatting { color: var(--faint); }
.cm-inline-code { font-family: var(--mono); font-size: .875em; background: var(--code-bg); border-radius: 3px; padding: .1em .2em; color: #e0525f; }
.cm-codeblock { font-family: var(--mono); font-size: 14px; background: var(--code-bg); }
.cm-quote { border-left: 2px solid var(--accent); padding-left: 12px !important; }
.cm-url, .cm-link { color: var(--link); }
.cm-wikilink { color: var(--link); cursor: pointer; }
.cm-wikilink.is-unresolved { color: var(--unresolved); }
.cm-tag { background: var(--accent-soft); color: var(--accent); border-radius: 10px; padding: 0 6px; }
.cm-hr { display: inline-block; width: 100%; border-top: 1px solid var(--line); vertical-align: middle; }
.cm-frontmatter { font-family: var(--mono); font-size: 13px; color: var(--muted); }
.cm-highlight { background: var(--mark); }
.cm-tooltip { background: var(--bg) !important; border: 1px solid var(--line) !important; border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.cm-tooltip-autocomplete ul li { padding: 4px 10px !important; font-family: var(--font); font-size: 13px; }
.cm-tooltip-autocomplete ul li[aria-selected] { background: var(--accent) !important; color: var(--accent-fg) !important; }
.cm-completionDetail { color: var(--faint); margin-left: 8px; font-style: normal; }
.cm-panels { background: var(--surface); color: var(--fg); border-color: var(--line) !important; }
.cm-panel.cm-search { padding: 6px 8px; font-family: var(--font); }
.cm-panel.cm-search input, .cm-panel.cm-search button { font-size: 12px; }
.cm-searchMatch { background: var(--mark); }

/* --- graph ------------------------------------------------------------------ */
.graph-view { position: relative; height: 100%; background: var(--bg); overflow: hidden; }
.graph-canvas { display: block; touch-action: none; cursor: grab; }
.graph-controls { position: absolute; top: 10px; right: 10px; width: 260px; max-height: calc(100% - 20px); overflow: auto;
  background: var(--bg-alt); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); font-size: 13px; }
.graph-controls.collapsed { width: auto; }
.graph-controls.collapsed .graph-control-sections { display: none; }
.graph-controls-head { display: flex; justify-content: flex-end; gap: 2px; padding: 4px; }
.graph-control-sections details { border-top: 1px solid var(--line); padding: 4px 12px 10px; }
.graph-control-sections summary { cursor: pointer; font-weight: 600; padding: 6px 0; list-style: none; display: flex; gap: 6px; align-items: center; }
.graph-control-sections summary::-webkit-details-marker { display: none; }
.setting { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 5px 0; }
.setting.stack { display: grid; gap: 4px; }
.setting .label { color: var(--muted); }
.toggle { appearance: none; width: 32px; height: 18px; border-radius: 9px; background: var(--line-strong); position: relative; cursor: pointer; flex: none; transition: background .15s; }
.toggle::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: transform .15s; }
.toggle:checked { background: var(--accent); }
.toggle:checked::after { transform: translateX(14px); }
.group-row { display: grid; grid-template-columns: 14px 1fr; gap: 8px; align-items: center; padding: 3px 0; }
.swatch { width: 12px; height: 12px; border-radius: 50%; }
.local-graph { height: 260px; position: relative; border-radius: var(--radius); background: var(--bg); border: 1px solid var(--line); margin: 0 4px; overflow: hidden; }
.local-graph-settings { display: flex; gap: 10px; align-items: center; padding: 6px 8px; font-size: 12px; color: var(--muted); }
.local-graph-settings input[type="range"] { width: 80px; }

/* --- canvas ------------------------------------------------------------------ */
.canvas-view { display: flex; flex-direction: column; height: 100%; }
.cv-toolbar { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); z-index: 3; display: flex; gap: 4px; align-items: center;
  background: var(--bg-alt); border: 1px solid var(--line); border-radius: 8px; padding: 4px; box-shadow: var(--shadow); flex-wrap: wrap; max-width: calc(100% - 20px); }
.cv-toolbar .status { padding: 0 6px; font-size: 12px; color: var(--muted); }
.cv-viewport { position: relative; flex: 1; overflow: hidden; cursor: grab; touch-action: none; outline: none;
  background-color: var(--bg); background-image: radial-gradient(var(--line-strong) 1px, transparent 1px); background-size: 20px 20px; }
.cv-viewport:active { cursor: grabbing; }
.cv-world { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.cv-edges { position: absolute; overflow: visible; pointer-events: none; }
.cv-edges path { fill: none; stroke-width: 2.5; }
.cv-node { --node-color: var(--line-strong); position: absolute; border: 2px solid var(--node-color); border-radius: 8px; background: var(--bg);
  overflow: hidden; display: flex; flex-direction: column; box-shadow: 0 1px 2px rgba(0, 0, 0, .06); }
.cv-node:not(.cv-group) { background: color-mix(in srgb, var(--node-color) 6%, var(--bg)); }
.cv-group { background: color-mix(in srgb, var(--node-color) 7%, transparent); overflow: visible; box-shadow: none; }
.cv-group-label { position: absolute; bottom: 100%; left: 0; margin-bottom: 6px; font-size: 22px; font-weight: 600; white-space: nowrap; color: var(--fg);
  background: color-mix(in srgb, var(--node-color) 18%, var(--bg)); padding: 2px 10px; border-radius: 6px; }
.cv-body { padding: 10px 16px; overflow: auto; flex: 1; font-size: 15px; }
.cv-body > :first-child { margin-top: 0; }
.cv-file-title { display: block; padding: 6px 12px; font-weight: 600; color: var(--fg); text-decoration: none; border-bottom: 1px solid var(--line); background: var(--bg-alt); }
.cv-file-title:hover { color: var(--accent); }
.cv-node.missing { opacity: .6; border-style: dashed; }
.cv-link { display: grid; gap: 2px; padding: 12px 16px; text-decoration: none; color: var(--fg); overflow-wrap: anywhere; }
.cv-edge-label { position: absolute; transform: translate(-50%, -50%); background: var(--bg); padding: 2px 8px; border-radius: 4px; font-size: 14px; white-space: nowrap; color: var(--muted); pointer-events: none; }
.cv-viewport.editing .cv-node { cursor: move; }
.cv-viewport.editing .cv-node:hover { box-shadow: 0 0 0 2px var(--accent); }
.cv-textarea { width: 100%; height: 100%; border: 0; resize: none; padding: 10px 16px; font: 15px/1.5 var(--mono); background: var(--bg); color: var(--fg); }

/* --- bases ------------------------------------------------------------------- */
.base-view { padding: 16px 24px 80px; }
.base-toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.base-toolbar .count { margin-left: auto; color: var(--faint); font-size: 12px; }
.base-table { border-collapse: collapse; width: 100%; font-size: 13px; }
.base-table th { text-align: left; font-weight: 600; color: var(--muted); padding: 6px 10px; border-bottom: 1px solid var(--line-strong); white-space: nowrap; cursor: pointer; user-select: none; }
.base-table th:hover { color: var(--fg); }
.base-table td { padding: 6px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.base-table tr:hover td { background: var(--hover); }
.base-table .base-group td { background: var(--surface); font-weight: 600; color: var(--fg); padding-top: 10px; }
.base-table a { color: var(--fg); font-weight: 500; text-decoration: none; }
.base-table a:hover { color: var(--accent); }
.base-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.base-group-title { font-weight: 600; margin: 18px 0 8px; color: var(--muted); }
.base-card { border: 1px solid var(--line); border-radius: 8px; padding: 12px; background: var(--bg-alt); text-decoration: none; color: var(--fg); display: grid; gap: 6px; align-content: start; }
.base-card:hover { border-color: var(--accent); }
.base-card .title { font-weight: 600; }
.base-card .prop { font-size: 12px; color: var(--muted); }
.base-warning { font-size: 12px; color: var(--c2); margin-bottom: 8px; }

/* --- modals: prompt, palette, switcher ---------------------------------------- */
.modal { border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--fg); padding: 20px; width: min(460px, calc(100vw - 24px)); box-shadow: var(--shadow); }
.modal::backdrop { background: rgba(0, 0, 0, .45); }
.modal h2 { font-size: 17px; margin: 0 0 14px; }
.modal p { margin: 0 0 16px; color: var(--muted); }
.modal label { display: grid; gap: 6px; font-size: 13px; margin-bottom: 14px; }
.prompt { border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--fg); padding: 0; width: min(640px, calc(100vw - 24px));
  box-shadow: var(--shadow); margin-top: 12vh; overflow: hidden; }
.prompt::backdrop { background: rgba(0, 0, 0, .35); }
.prompt input { border: 0; border-bottom: 1px solid var(--line); border-radius: 0; padding: 14px 16px; font-size: 16px; background: transparent; box-shadow: none !important; }
.prompt-results { max-height: 50vh; overflow: auto; padding: 6px; }
.suggestion { display: flex; gap: 10px; align-items: center; padding: 8px 10px; border-radius: var(--radius); cursor: pointer; }
.suggestion .title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.suggestion .note { font-size: 12px; color: var(--faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 45%; }
.suggestion kbd { font: 11px var(--mono); background: var(--surface-alt); padding: 2px 6px; border-radius: 4px; color: var(--muted); }
.suggestion.is-selected { background: var(--accent-soft); }
.suggestion b { color: var(--accent); }
.prompt-instructions { display: flex; gap: 14px; padding: 8px 14px; font-size: 12px; color: var(--faint); border-top: 1px solid var(--line); }
.menu { position: fixed; z-index: 50; min-width: 180px; background: var(--bg-alt); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); padding: 4px; }
.menu-item { display: flex; gap: 10px; align-items: center; padding: 6px 10px; border-radius: 4px; cursor: pointer; font-size: 13px; }
.menu-item:hover { background: var(--hover); }
.menu-item.danger { color: var(--danger); }
.menu-sep { height: 1px; background: var(--line); margin: 4px 0; }

.toast { position: fixed; right: 16px; top: 16px; transform: translateY(-10px); opacity: 0; pointer-events: none; z-index: 60;
  background: var(--bg-alt); color: var(--fg); border: 1px solid var(--line); padding: 10px 16px; border-radius: 8px; font-size: 13px; transition: .2s; box-shadow: var(--shadow); max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: none; }
.toast.error { border-color: var(--danger); color: var(--danger); }

/* --- mobile ------------------------------------------------------------------- */
.mobile-nav { display: none; }
.scrim { display: none; }
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .ribbon { display: none; }
  .main-area { grid-column: 1; grid-row: 1; }
  .sidebar { position: fixed; top: 0; bottom: 0; z-index: 30; width: min(85vw, 340px) !important; display: flex !important; transition: transform .2s ease; box-shadow: var(--shadow); }
  .sidebar.left { left: 0; transform: translateX(-105%); }
  .sidebar.right { right: 0; transform: translateX(105%); }
  .app.left-open .sidebar.left, .app.right-open .sidebar.right { transform: none; }
  .app.left-open .scrim, .app.right-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .4); z-index: 20; }
  .tab-bar { display: none; }
  .mobile-nav { display: flex; grid-row: 2; justify-content: space-around; padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--line); }
  .mobile-nav .clickable-icon { padding: 10px; }
  .readable { padding: 12px 18px 100px; }
  .cm-content { padding: 0 18px 50vh; }
  .status-bar { display: none; }
  .graph-controls { width: calc(100% - 20px); max-height: 50%; }
  .graph-controls.collapsed { width: auto; }
  .property { grid-template-columns: 110px 1fr; }
  .base-view { padding: 12px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* --- workspace extras ---------------------------------------------------------- */
.views { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.views > .view:not([hidden]) { flex: 1; }
@media (min-width: 821px) { .sidebar { position: relative; } }
.resize-handle { position: absolute; top: 0; bottom: 0; width: 6px; cursor: col-resize; z-index: 4; touch-action: none; }
.resize-handle.left { right: -3px; }
.resize-handle.right { left: -3px; }
.resize-handle:hover { background: var(--accent-soft); }
.empty-tab { padding-top: 18vh; text-align: center; }
.empty-tab .inline-title { color: var(--faint); font-size: 1.6em; }
.empty-tab .row { justify-content: center; flex-wrap: wrap; }
.empty-tab kbd, .suggestion kbd { font: 11px var(--mono); color: var(--faint); }
.view-header .clickable-icon:disabled { opacity: .35; cursor: default; background: none; }
.readable.editing { padding-bottom: 0; height: 100%; display: flex; flex-direction: column; }
.readable.editing .cm-host { flex: 1; min-height: 0; }
.readable.editing .cm-content { padding: 0 0 50vh; max-width: none; }
.inline-title:focus { outline: none; }
.group-row.with-delete { grid-template-columns: 14px 1fr auto; }
.group-row .swatch { border: 0; padding: 0; box-shadow: none; cursor: pointer; }
.graph-controls-head .clickable-icon { padding: 4px; }
.local-graph { height: 320px; }
.local-graph .graph-view { height: 100%; }
.local-graph-settings.floating { position: absolute; left: 8px; right: 8px; bottom: 6px; background: color-mix(in srgb, var(--bg) 85%, transparent); border-radius: 6px; }
.table-wrap { overflow-x: auto; }
.cv-toolbar .push { margin-left: 6px; }
.callout > summary { list-style: none; cursor: pointer; }
.callout > summary::-webkit-details-marker { display: none; }
.callout > summary::after { content: "›"; margin-left: 4px; transition: transform .15s; }
.callout[open] > summary::after { transform: rotate(90deg); }
.cm-task { margin: 0 4px 0 0; vertical-align: middle; cursor: pointer; }
.embed-body.markdown { font-size: 15px; }
.tree-item .icon { color: var(--faint); }
.cm-properties { margin: 4px 0 16px; cursor: text; font-family: var(--font); }
.cm-properties .pill { margin-right: 4px; }
.graph-spacing { padding: 0 12px 6px; }
.graph-controls.collapsed { width: 220px; }
.local-graph-settings.floating { flex-wrap: wrap; row-gap: 2px; }
.local-graph-settings input[type="range"] { width: 64px; }

/* --- canvas editor -------------------------------------------------------------- */
.canvas-view { position: relative; }
.cv-toolbar { top: auto; bottom: 14px; gap: 2px; }
.cv-toolbar .clickable-icon { padding: 6px; }
.cv-toolbar .clickable-icon:disabled { opacity: .35; cursor: default; background: none; }
.cv-sep { width: 1px; align-self: stretch; background: var(--line); margin: 2px 4px; }
.cv-overlay { position: absolute; inset: 0; pointer-events: none; }
.cv-marquee { position: absolute; border: 1px solid var(--accent); background: var(--accent-soft); border-radius: 2px; }
.cv-viewport.panning, .cv-viewport.panning * { cursor: grab !important; }
.cv-node { overflow: visible; cursor: default; }
.cv-inner { position: absolute; inset: 0; overflow: hidden; border-radius: 6px; display: flex; flex-direction: column; }
.cv-group .cv-inner { border-radius: 8px; }
.cv-node.is-selected { box-shadow: 0 0 0 2px var(--accent); }
.cv-node.missing { opacity: .6; border-style: dashed; }
.cv-viewport.editing .cv-node, .cv-viewport.editing .cv-node:hover { box-shadow: none; }
.cv-group-label { cursor: text; z-index: 3; }
/* connection dots: on hover or selection */
.cv-connector { position: absolute; width: 12px; height: 12px; border-radius: 50%; background: var(--bg); border: 2px solid var(--accent);
  opacity: 0; cursor: crosshair; z-index: 5; transition: opacity .1s; }
.cv-node:hover > .cv-connector, .cv-node.is-selected > .cv-connector { opacity: 1; }
.cv-connector.top { left: calc(50% - 6px); top: -8px; }
.cv-connector.bottom { left: calc(50% - 6px); bottom: -8px; }
.cv-connector.left { top: calc(50% - 6px); left: -8px; }
.cv-connector.right { top: calc(50% - 6px); right: -8px; }
/* resize handles: only for a single selected card */
.cv-resize { position: absolute; z-index: 4; display: none; }
.cv-node.is-solo > .cv-resize { display: block; }
.cv-resize.n, .cv-resize.s { left: 8px; right: 8px; height: 10px; cursor: ns-resize; }
.cv-resize.n { top: -6px; } .cv-resize.s { bottom: -6px; }
.cv-resize.e, .cv-resize.w { top: 8px; bottom: 8px; width: 10px; cursor: ew-resize; }
.cv-resize.e { right: -6px; } .cv-resize.w { left: -6px; }
.cv-resize.ne, .cv-resize.nw, .cv-resize.se, .cv-resize.sw { width: 12px; height: 12px; background: var(--bg); border: 2px solid var(--accent); border-radius: 3px; }
.cv-resize.ne { top: -7px; right: -7px; cursor: nesw-resize; } .cv-resize.sw { bottom: -7px; left: -7px; cursor: nesw-resize; }
.cv-resize.nw { top: -7px; left: -7px; cursor: nwse-resize; } .cv-resize.se { bottom: -7px; right: -7px; cursor: nwse-resize; }
/* edges */
.cv-edges { pointer-events: none; z-index: 0; }
.cv-edge-hit { fill: none; stroke: transparent; stroke-width: 16; pointer-events: stroke; cursor: pointer; }
.cv-edge-temp { stroke-dasharray: 6 6; }
.cv-edge-label { pointer-events: auto; cursor: pointer; z-index: 3; }
.cv-edge-label.is-selected { color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
/* floating selection menu */
.cv-selmenu { position: absolute; transform: translateX(-50%); z-index: 6; display: flex; gap: 2px; align-items: center;
  background: var(--bg-alt); border: 1px solid var(--line); border-radius: 8px; padding: 3px; box-shadow: var(--shadow); }
.cv-selmenu .clickable-icon { padding: 5px; }
.cv-colors { position: absolute; top: calc(100% + 6px); left: 50%; transform: translateX(-50%); display: flex; gap: 6px; padding: 6px;
  background: var(--bg-alt); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); }
.cv-swatch { width: 22px; height: 22px; border-radius: 50%; padding: 0; border: 0; box-shadow: 0 0 0 1px var(--line) inset; cursor: pointer; }
.cv-swatch.none { display: inline-flex; align-items: center; justify-content: center; background: var(--bg); color: var(--muted); }
.cv-swatch.none .icon { width: 14px; height: 14px; }
.cv-textarea { position: absolute; inset: 0; outline: none; }
.cv-toolbar { flex-wrap: nowrap; white-space: nowrap; }
.cv-toolbar .status { min-width: 56px; }
.cm-image { display: block; max-width: 100%; border-radius: 4px; margin: 4px 0; }
.markdown img[src^="/app/api/img"] { background: var(--surface); min-height: 24px; }
