* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #ffffff;
  --bg-panel: #f8fafc;
  --bg-hover: #f1f5f9;
  --band: #f1f5f9;
  --fg: #273142;
  --fg-dim: #64748b;
  --heading: #334155;
  --accent: #15a16a;
  --accent-soft: #6fe3aa;
  --accent-ink: #144129;
  --danger: #b42318;
  --border: #e2e8f0;
  --sel: #d6f5e6;
  --code-bg: #f8fafc;
  --code-border: #e8edf3;
  --pal-bg: #ffffff;
  --pal-shadow: 0 0 0 1px rgba(15, 23, 42, 0.04), 0 24px 64px rgba(15, 23, 42, 0.18);
  --tok-str: #8a4b08;
  --tok-num: #1d4ed8;
  --tok-type: #6d28d9;
  --tok-fn: #0e7490;
  --tok-prop: #475569;
}

:root[data-theme="dark"] {
  --bg: #14161a;
  --bg-panel: #1c1f26;
  --bg-hover: #262a33;
  --band: #1c1f26;
  --fg: #d8dee9;
  --fg-dim: #6b7280;
  --heading: #e5e9f0;
  --accent: #5ee0a3;
  --accent-soft: #1f4d3a;
  --accent-ink: #a7f3d0;
  --danger: #f87171;
  --border: #2e333d;
  --sel: #1f3a37;
  --code-bg: #1c1f26;
  --code-border: #2e333d;
  --pal-bg: #101216;
  --pal-shadow: 0 0 0 1px rgba(94, 224, 163, 0.10), 0 24px 64px rgba(0, 0, 0, 0.6);
  --tok-str: #e3b27a;
  --tok-num: #93c5fd;
  --tok-type: #c4b5fd;
  --tok-fn: #67e8f9;
  --tok-prop: #a8b3c4;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14161a;
    --bg-panel: #1c1f26;
    --bg-hover: #262a33;
    --band: #1c1f26;
    --fg: #d8dee9;
    --fg-dim: #6b7280;
    --heading: #e5e9f0;
    --accent: #5ee0a3;
    --accent-soft: #1f4d3a;
    --accent-ink: #a7f3d0;
    --danger: #f87171;
    --border: #2e333d;
    --sel: #1f3a37;
    --code-bg: #1c1f26;
    --code-border: #2e333d;
    --pal-bg: #101216;
    --pal-shadow: 0 0 0 1px rgba(94, 224, 163, 0.10), 0 24px 64px rgba(0, 0, 0, 0.6);
  --tok-str: #e3b27a;
  --tok-num: #93c5fd;
  --tok-type: #c4b5fd;
  --tok-fn: #67e8f9;
  --tok-prop: #a8b3c4;
  }
}

html, body { height: 100%; overscroll-behavior: none; }

body {
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.65 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, sans-serif;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) 0 env(safe-area-inset-left, 0px);
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
html { scrollbar-color: var(--border) transparent; }

.dim { color: var(--fg-dim); }
kbd, code {
  font: 0.9em ui-monospace, SF Mono, Menlo, monospace;
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: 4px;
  padding: 0 0.3em;
}

/* --- top bar --- */

#bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 14px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  color: var(--fg-dim);
  flex: none;
  min-width: 0;
}
#bar-palette {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--accent);
  font: 13px ui-monospace, SF Mono, Menlo, monospace;
  padding: 1px 8px;
  cursor: pointer;
  flex: none;
}
#bar-palette:hover { background: var(--bg-hover); }
#bar-title { color: var(--heading); font-weight: 500; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#bar-path { font: 12px ui-monospace, SF Mono, Menlo, monospace; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#bar-public {
  font: 11px ui-monospace, SF Mono, Menlo, monospace;
  background: var(--accent-soft);
  color: var(--accent-ink);
  border-radius: 3px;
  padding: 0 6px;
  flex: none;
}
#bar-public[hidden] { display: none; }
#bar-draft {
  font: 11px ui-monospace, SF Mono, Menlo, monospace;
  border: 1px dashed var(--fg-dim);
  color: var(--fg-dim);
  border-radius: 3px;
  padding: 0 6px;
  flex: none;
}
#bar-draft[hidden] { display: none; }
#bar-status { margin-left: auto; white-space: nowrap; flex: none; }
#bar-status.warn { color: var(--danger); }
#bar-mode {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--fg-dim);
  font: 11px ui-monospace, SF Mono, Menlo, monospace;
  padding: 0 6px;
  cursor: pointer;
  flex: none;
}
#bar-mode:hover { background: var(--bg-hover); }
#bar-mode.on { background: var(--accent-soft); color: var(--accent-ink); border-color: transparent; }
#bar-mode[hidden] { display: none; }
#bar-keys {
  font: 11px ui-monospace, SF Mono, Menlo, monospace;
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0 5px;
  flex: none;
}
#bar-keys:empty { display: none; }

/* --- editor --- */

#body { flex: 1; min-height: 0; display: flex; }
#editor { flex: 1; min-width: 0; min-height: 0; }
#editor[hidden] { display: none; }
.cm-editor { height: 100%; }

/* --- read mode --- */

#reader { flex: 1; min-width: 0; min-height: 0; overflow-y: auto; }
#reader[hidden] { display: none; }
.prose { max-width: 44rem; margin: 0 auto; padding: 2.25rem 1.25rem 45vh; line-height: 1.65; }
.prose > :first-child { margin-top: 0; }
.prose h1 { font-size: 1.85em; font-weight: 700; letter-spacing: -0.015em; line-height: 1.25; color: var(--heading); margin: 0.6em 0 0.5em; }
.prose h2 { font-size: 1.4em; font-weight: 650; letter-spacing: -0.01em; line-height: 1.3; color: var(--heading); margin: 1.4em 0 0.5em; }
.prose h3 { font-size: 1.15em; font-weight: 650; line-height: 1.4; color: var(--heading); margin: 1.3em 0 0.4em; }
.prose h4, .prose h5, .prose h6 { font-weight: 650; color: var(--heading); margin: 1.2em 0 0.3em; }
.prose p, .prose ul, .prose ol, .prose pre, .prose blockquote, .prose table, .prose dl { margin: 0 0 0.9em; }
.prose ul, .prose ol { padding-left: 1.4em; }
.prose li { margin: 0.15em 0; }
.prose li::marker { color: var(--accent); }
.prose li.task { list-style: none; margin-left: -1.4em; }
.prose li.task input { accent-color: var(--accent); width: 1em; height: 1em; vertical-align: -0.12em; margin: 0 0.4em 0 0; }
.prose a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; text-decoration-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.prose a.wiki { text-decoration-style: dotted; cursor: pointer; }
.prose .tag { color: var(--accent); }
.prose code { font-size: 0.88em; }
.prose pre { tab-size: 4; background: var(--code-bg); border: 1px solid var(--code-border); border-radius: 6px; padding: 0.6em 0.8em; overflow-x: auto; font-size: 0.88em; line-height: 1.5; }
.prose pre code { background: none; border: 0; padding: 0; font-size: inherit; }
.prose blockquote { border-left: 3px solid var(--accent-soft); padding-left: 0.8em; color: var(--fg-dim); font-style: italic; }
.prose hr { border: 0; border-top: 1px solid var(--border); margin: 1.4em 0; }
.prose img { display: block; max-width: 100%; border-radius: 6px; }
.prose table { border-collapse: collapse; font-size: 0.92em; line-height: 1.45; }
.prose th, .prose td { border: 1px solid var(--border); padding: 0.3em 0.7em; vertical-align: top; }
.prose [align="center"] { text-align: center; }
.prose [align="right"] { text-align: right; }
.prose th { background: var(--bg-panel); font-weight: 600; color: var(--heading); }
.prose dl.props { background: var(--bg-panel); border: 1px solid var(--border); border-radius: 6px; padding: 0.5em 0.9em; font-size: 0.88em; display: grid; grid-template-columns: max-content 1fr; gap: 0.1em 1em; }
.prose dl.props dt { color: var(--fg-dim); font-family: ui-monospace, SF Mono, Menlo, monospace; font-size: 0.85em; line-height: 1.9; }
.prose dl.props dd { margin: 0; }

/* --- "On this note": heading outline, wide screens only --- */

#toc {
  display: none;
  flex: none;
  width: 232px;
  overflow-y: auto;
  padding: 2.4rem 1.25rem 2rem 0;
  font-size: 13px;
  line-height: 1.4;
}
#toc h2 {
  font: 600 11px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, sans-serif;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg-dim);
  margin: 0 0 0.6em 12px;
}
#toc ol { list-style: none; border-left: 1px solid var(--border); }
#toc li a {
  display: block;
  color: var(--fg-dim);
  text-decoration: none;
  padding: 3px 8px 3px 11px;
  margin-left: -1px;
  border-left: 2px solid transparent;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#toc li a:hover { color: var(--fg); }
#toc li.active a { color: var(--heading); border-left-color: var(--accent); }
#toc li.l1 a { padding-left: 23px; }
#toc li.l2 a { padding-left: 35px; }
#toc li.l3 a { padding-left: 47px; }
#toc li.l4 a { padding-left: 59px; }
@media (min-width: 1024px) {
  #toc:not([hidden]) { display: block; }
}

/* --- folder pages + breadcrumb (view mode) --- */

.prose .crumb { color: var(--fg-dim); font-size: 0.9em; margin: 0 0 1em; }
.prose .crumb a, .prose .children a { color: inherit; text-decoration: none; cursor: pointer; }
.prose .crumb a:hover, .prose .children a:hover { color: var(--accent); }
.children-head { display: flex; justify-content: space-between; align-items: baseline; font-size: 0.8em; font-weight: 650; text-transform: uppercase; letter-spacing: 0.08em; color: var(--fg-dim); margin: 2em 0 0.4em; }
.children-head a { font-weight: 500; text-transform: none; letter-spacing: 0; color: var(--accent); }
.prose ul.children-list { list-style: none; padding: 0; margin: 0; }
.prose ul.children-list li { display: flex; flex-wrap: wrap; gap: 0 0.8em; justify-content: space-between; align-items: baseline; padding: 0.4em 0; border-bottom: 1px solid color-mix(in srgb, var(--fg-dim) 18%, transparent); margin: 0; }
.prose ul.children-list li::marker { content: ""; }
.prose ul.children-list li > a { font-weight: 600; }
.prose ul.children-list li > p.snip { flex-basis: 100%; margin: 0.1em 0 0; font-size: 0.92em; color: var(--fg-dim); }
.prose ul.children-list li .dim { flex: none; font-size: 0.85em; }

.prose.doc code { font-size: 0.88em; }
.stats .stat-row b { font-weight: 650; color: var(--heading); }
.stats ul.stats-list { list-style: none; padding: 0; margin: 0; }
.stats ul.stats-list li { display: flex; gap: 0.8em; justify-content: space-between; align-items: baseline; padding: 0.35em 0; border-bottom: 1px solid color-mix(in srgb, var(--fg-dim) 18%, transparent); }
.stats ul.stats-list li > :first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stats ul.stats-list li .dim { flex: none; font-size: 0.85em; }
.stats .bars { display: inline-flex; align-items: flex-end; gap: 2px; height: 14px; margin-left: 0.5em; vertical-align: -2px; }
.stats .bars i { display: inline-block; width: 4px; background: var(--accent); border-radius: 1px; opacity: 0.8; }
.stats h2 .n a { color: var(--accent); text-decoration: none; text-transform: none; letter-spacing: 0; }
.home a[data-stats] { color: var(--accent); cursor: pointer; }
.prose.doc h2 { margin-top: 1.8em; }

/* --- home --- */

#home { flex: 1; min-width: 0; min-height: 0; overflow-y: auto; }
#home[hidden] { display: none; }
.home a[data-path], .home a[data-today] { cursor: pointer; text-decoration: none; color: inherit; }
.home a[data-path]:hover, .home a[data-today]:hover { color: var(--accent); }
.home a.act { color: var(--accent); }
.home h1 { margin-bottom: 0.1em; }
.home-meta { color: var(--fg-dim); margin-bottom: 0; }
.home h2 { font-size: 0.8em; font-weight: 650; text-transform: uppercase; letter-spacing: 0.08em; color: var(--fg-dim); margin: 2.2em 0 0.5em; }
.home h2 .n { font-weight: 500; margin-left: 0.5em; }
.home h4 { margin: 1em 0 0.1em; font-size: 0.95em; }
.home > ul { list-style: none; padding: 0; margin: 0; }
.home > ul > li { display: flex; gap: 0.8em; justify-content: space-between; align-items: baseline; padding: 0.35em 0; border-bottom: 1px solid color-mix(in srgb, var(--fg-dim) 18%, transparent); }
.home > ul > li > :first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.home > ul > li .dim { flex: none; font-size: 0.85em; }
.home > ul.home-tasks > li { justify-content: flex-start; }
.home > ul.home-tasks > li::before { content: "☐"; color: var(--accent); flex: none; }
.home-today { margin: 0 0 0.5em; padding: 0.6em 0.9em; border-left: 3px solid var(--accent); background: color-mix(in srgb, var(--accent) 7%, transparent); border-radius: 0 6px 6px 0; }
.home-today > :last-child { margin-bottom: 0; }

.md-h1 { font-size: 1.85em; font-weight: 700; letter-spacing: -0.015em; line-height: 1.25; color: var(--heading); }
.md-h2 { font-size: 1.4em; font-weight: 650; letter-spacing: -0.01em; line-height: 1.3; color: var(--heading); }
.md-h3 { font-size: 1.15em; font-weight: 650; line-height: 1.4; color: var(--heading); }
.md-h4 { font-weight: 650; color: var(--heading); }
#editor .cm-line.md-hl-first { padding-top: 0.55em; }
#editor .cm-line.md-hl1 { background: var(--band); border-radius: 6px; padding: 0.2em 0.5em; margin: 0.4em -0.5em 0.3em; }
.md-hash {
  background: var(--accent-soft);
  color: var(--accent-ink) !important;
  border-radius: 4px;
  padding: 0 0.2em;
  font-weight: 650;
}
.md-strong { font-weight: 650; }
.md-em { font-style: italic; }
.md-strike { text-decoration: line-through; color: var(--fg-dim); }
.md-mark { color: var(--fg-dim); font-weight: 400; }
.md-code {
  font-family: ui-monospace, SF Mono, Menlo, monospace;
  font-size: 0.88em;
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: 4px;
  padding: 0.05em 0.3em;
}
#editor .cm-line.md-codeblock {
  tab-size: 4;
  background: var(--code-bg);
  border-left: 1px solid var(--code-border);
  border-right: 1px solid var(--code-border);
  font-family: ui-monospace, SF Mono, Menlo, monospace;
  font-size: 0.88em;
  padding: 0 0.8em;
}
#editor .cm-line.md-codeblock .md-code { background: none; border: 0; padding: 0; font-size: inherit; }
#editor .cm-line.md-codeblock-first { border-top: 1px solid var(--code-border); border-radius: 6px 6px 0 0; padding-top: 0.35em; }
#editor .cm-line.md-codeblock-last { border-bottom: 1px solid var(--code-border); border-radius: 0 0 6px 6px; padding-bottom: 0.35em; }
.md-link { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; text-decoration-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.md-url { color: var(--fg-dim); }
.md-wiki { color: var(--accent); cursor: pointer; text-decoration: underline dotted; text-underline-offset: 2px; }
.md-quote { color: var(--fg-dim); font-style: italic; }
#editor .cm-line.md-bq { border-left: 3px solid var(--accent-soft); padding-left: 0.8em; }
.md-bullet { color: var(--accent); display: inline-block; width: 1ch; text-align: center; }
.md-check { accent-color: var(--accent); width: 1em; height: 1em; vertical-align: -0.12em; margin: 0 0.1em 0 0; cursor: pointer; }
.md-hr { display: inline-block; width: 100%; border-top: 1px solid var(--border); vertical-align: middle; }

/* code tokens inside fenced blocks */
.tok-kw { color: var(--accent); font-weight: 600; }
.tok-str { color: var(--tok-str); }
.tok-cmt { color: var(--fg-dim); font-style: italic; }
.tok-num { color: var(--tok-num); }
.tok-type { color: var(--tok-type); }
.tok-fn { color: var(--tok-fn); }
.tok-prop { color: var(--tok-prop); }
.tok-tag { color: var(--tok-type); }
.tok-meta { color: var(--fg-dim); }

/* tables: a grid away from the cursor, aligned monospace while editing */
#editor .cm-line.md-tbl { font-family: ui-monospace, SF Mono, Menlo, monospace; font-size: 0.88em; white-space: pre; overflow-x: auto; }
.md-table { overflow-x: auto; margin: 0.4em 0; }
.md-table table { border-collapse: collapse; font-size: 0.92em; line-height: 1.45; min-width: 50%; }
.md-table th, .md-table td { border: 1px solid var(--border); padding: 0.3em 0.7em; text-align: left; vertical-align: top; }
.md-table th { background: var(--bg-panel); font-weight: 600; color: var(--heading); }
.md-table tr:nth-child(even) td { background: color-mix(in srgb, var(--bg-panel) 50%, transparent); }

.md-img { display: block; max-width: 100%; max-height: 70vh; border-radius: 6px; margin: 0.3em 0; }

/* --- front matter: properties strip --- */

#editor .cm-line.md-fm {
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  padding: 0.05em 0.9em;
  font-size: 0.88em;
  line-height: 1.6;
  color: var(--fg);
}
#editor .cm-line.md-fm span { font-size: inherit; font-weight: 400; color: inherit; letter-spacing: 0; line-height: inherit; }
#editor .cm-line.md-fm-open { border-top: 1px solid var(--border); border-radius: 6px 6px 0 0; padding-top: 0.3em; margin-top: 0.2em; }
#editor .cm-line.md-fm-close { border-bottom: 1px solid var(--border); border-radius: 0 0 6px 6px; padding-bottom: 0.3em; margin-bottom: 0.6em; }
#editor .cm-line.md-fm .md-fm-key {
  display: inline-block;
  min-width: 5.5em;
  color: var(--fg-dim);
  font-family: ui-monospace, SF Mono, Menlo, monospace;
  font-size: 0.85em;
}
#editor .cm-line.md-fm .md-fm-fence {
  color: var(--fg-dim);
  font-size: 0.7em;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
#editor .cm-line.md-fm-close:not(.md-fm-raw) { font-size: 0.4em; line-height: 1; padding-bottom: 0.9em; }
#editor .cm-line.md-fm-raw .md-fm-key { min-width: 0; }
#editor .cm-line.md-fm-raw { color: var(--fg-dim); }

/* --- command palette: spotlight, muxdeck-style --- */

#palette {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: rgba(15, 23, 42, 0.22);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 15vh;
}
#palette[hidden] { display: none; }

.pal-box {
  width: min(560px, 92vw);
  background: var(--pal-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--pal-shadow);
  font: 14px/1.5 ui-monospace, SF Mono, Menlo, monospace;
  overflow: hidden;
}

.pal-prompt {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.pal-mode { color: var(--accent); white-space: pre; }
.pal-field { position: relative; flex: 1; overflow: hidden; }
.pal-field textarea {
  display: block;
  width: 100%;
  background: none;
  border: none;
  color: var(--fg);
  font: inherit;
  line-height: inherit;
  caret-color: transparent;
  padding: 0;
  margin: 0;
  resize: none;
  overflow: hidden;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 30vh;
}
.pal-field textarea.wrapped { caret-color: var(--accent); }
.pal-field textarea:focus { outline: none; }
.pal-prompt { align-items: flex-start; }
.pal-mode { line-height: inherit; }
.pal-ghost {
  position: absolute;
  top: 0;
  right: 0;
  color: var(--fg-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: left;
  pointer-events: none;
}
.pal-caret {
  position: absolute;
  top: 0;
  left: 0;
  width: 1ch;
  text-align: center;
  background: var(--accent-soft);
  color: var(--accent-ink);
  white-space: pre;
  pointer-events: none;
  animation: pal-blink 1.1s steps(1) infinite;
}
.pal-caret[hidden] { display: none; }
@keyframes pal-blink { 50% { opacity: 0; } }

.pal-list { list-style: none; max-height: 42vh; overflow-y: auto; }
.pal-list:empty { display: none; }
.pal-list li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 14px;
  cursor: pointer;
  white-space: nowrap;
}
.pal-list li > span:first-child { overflow: hidden; text-overflow: ellipsis; flex: none; max-width: 70%; }
.pal-list li .dim { color: var(--fg-dim); overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.pal-list li .cmd { color: var(--accent); }
.pal-list li:hover:not(.selected) { background: var(--bg-hover); }
.pal-list li.selected { background: var(--accent-soft); color: var(--accent-ink); }
.pal-list li.selected .dim { color: color-mix(in srgb, var(--accent-ink) 70%, transparent); }
.pal-list li.selected .cmd { color: var(--accent-ink); }

.pal-list li.pal-text {
  display: block;
  white-space: pre-wrap;
  font: 13px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, sans-serif;
  color: var(--fg);
  cursor: default;
  padding: 8px 14px;
}
.pal-list li.pal-text:hover { background: none; }
.pal-list li.pal-text.selected { background: none; color: var(--fg); }
.pal-md { max-width: none; padding: 0; line-height: 1.5; }
.pal-md > :last-child { margin-bottom: 0; }
.pal-md p, .pal-md ul, .pal-md ol { margin-bottom: 0.5em; }

.pal-hint {
  padding: 6px 14px;
  border-top: 1px solid var(--border);
  color: var(--fg-dim);
  font-size: 11px;
}

@media (max-width: 640px) {
  #palette { padding-top: calc(8px + env(safe-area-inset-top, 0px)); }
  .pal-box { width: 96vw; }
  .pal-list { max-height: 48vh; }
  #bar-path { display: none; }
}
