:root {
  color-scheme: light;
  --bg: #f7f5ef;
  --panel: #efece3;
  --surface: #fffdfa;
  --text: #20201d;
  --muted: #6d6a60;
  --line: #ddd7ca;
  --accent: #2f6f73;
  --accent-2: #8a5a35;
  --code: #ece5d8;
  --pre-bg: #24231f;
  --pre-text: #f7f5ef;
  --warn: #9a3412;
  --hover: #fdf6e7;
  --active: #f4ead3;
  --ring: rgb(47 111 115 / 22%);
  --radius: 8px;
  --shadow: rgb(32 32 29 / 15%);
  --graph-shadow: rgb(24 23 20 / 38%);
  --graph-node: #9a948733;
  --graph-node-solid: #8c867a;
  --graph-link: rgb(109 106 96 / 28%);
  --graph-current: var(--accent);
  --graph-focus: var(--accent-2);
  --graph-label: #4a4740;
  --graph-halo: #f6f4ec;
  --graph-grid: rgb(32 32 29 / 6%);
  --graph-bg-center: #faf8f3;
  --graph-bg-edge: #f1eee4;
  --graph-backdrop: rgb(24 23 20 / 55%);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-onyx-theme="dark"] {
  color-scheme: dark;
  --bg: #111410;
  --panel: #181d17;
  --surface: #20261e;
  --text: #f0efe6;
  --muted: #aaa595;
  --line: #343b31;
  --accent: #78c9cc;
  --accent-2: #d5a86e;
  --code: #242a22;
  --pre-bg: #090b08;
  --pre-text: #f1f5ea;
  --warn: #fb923c;
  --hover: #252c23;
  --active: #123539;
  --ring: rgb(120 201 204 / 25%);
  --shadow: rgb(0 0 0 / 38%);
  --graph-shadow: rgb(0 0 0 / 55%);
  --graph-node: #78816f55;
  --graph-node-solid: #9aa08e;
  --graph-link: rgb(170 165 149 / 24%);
  --graph-current: var(--accent);
  --graph-focus: var(--accent-2);
  --graph-label: #d8d3c5;
  --graph-halo: #131711;
  --graph-grid: rgb(240 239 230 / 7%);
  --graph-bg-center: #181d16;
  --graph-bg-edge: #0d100c;
  --graph-backdrop: rgb(2 4 3 / 68%);
}

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

* { box-sizing: border-box; }
html { min-height: 100%; }
body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
}

a { color: var(--accent); text-decoration-thickness: .08em; text-underline-offset: .18em; }
a:hover { color: var(--accent-2); }

.skip-link {
  position: absolute;
  top: .75rem;
  left: .75rem;
  transform: translateY(-200%);
  background: var(--text);
  color: var(--bg);
  padding: .45rem .7rem;
  border-radius: 6px;
  z-index: 10;
}
.skip-link:focus { transform: translateY(0); }

.onyx-shell {
  display: grid;
  grid-template-columns: minmax(17rem, 22rem) minmax(0, 1fr);
  min-height: 100vh;
}

.onyx-sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  border-right: 1px solid var(--line);
  background: var(--panel);
  padding: 1.1rem;
}

.onyx-sidebar-top {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-bottom: 1rem;
}

.onyx-brand {
  display: block;
  flex: 1 1 auto;
  min-width: 0;
  color: var(--text);
  font-size: 1.05rem;
  font-weight: 750;
  line-height: 1.2;
  text-decoration: none;
  overflow-wrap: anywhere;
}

.onyx-theme-toggle {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 2rem;
  height: 2rem;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease, color .12s ease;
}
.onyx-theme-toggle:hover {
  background: var(--hover);
  border-color: var(--accent);
  color: var(--accent);
}
.onyx-theme-toggle[hidden] { display: none; }
.onyx-theme-icon {
  display: block;
  width: 1rem;
  height: 1rem;
}
.onyx-theme-icon-sun { display: none; }
:root[data-onyx-theme="dark"] .onyx-theme-icon-moon { display: none; }
:root[data-onyx-theme="dark"] .onyx-theme-icon-sun { display: block; }

.onyx-theme-toggle:active .onyx-theme-icon {
  transform: scale(.94);
}

.onyx-search { position: relative; margin-bottom: 1rem; }
.onyx-search input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  line-height: 1.2;
  padding: .55rem .65rem;
  transition: border-color .12s ease, box-shadow .12s ease;
}
.onyx-search input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--ring);
}
.onyx-search-results {
  position: absolute;
  z-index: 5;
  top: calc(100% + .35rem);
  left: 0;
  right: 0;
  max-height: 60vh;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 14px 28px var(--shadow);
}
.onyx-search-results a {
  display: block;
  padding: .65rem .75rem;
  color: var(--text);
  text-decoration: none;
  border-bottom: 1px solid var(--line);
}
.onyx-search-results a:last-child { border-bottom: 0; }
.onyx-search-results strong { display: block; line-height: 1.25; }
.onyx-search-results span {
  display: block;
  color: var(--muted);
  font-size: .82rem;
  line-height: 1.35;
  margin-top: .15rem;
}

.nav-tree, .nav-tree ul {
  list-style: none;
  margin: 0;
  padding-left: 0;
}
.nav-tree ul {
  margin-left: .55rem;
  padding-left: .55rem;
  border-left: 1px solid var(--line);
}
.nav-tree li { margin: .05rem 0; }
.nav-tree a, .nav-tree span, .nav-tree summary {
  display: flex;
  align-items: center;
  gap: .5rem;
  color: var(--muted);
  font-size: .92rem;
  line-height: 1.3;
  padding: .28rem .45rem;
  text-decoration: none;
  border-radius: 7px;
  transition: background .12s ease, color .12s ease;
}
.nav-tree a:hover, .nav-tree summary:hover { background: var(--hover); color: var(--text); }
.nav-tree a[aria-current="page"] {
  background: var(--active);
  color: var(--accent);
  font-weight: 700;
}

/* Folder rows: a caret that rotates open, with a folder-toned label. */
.nav-tree details { margin: .05rem 0; }
.nav-tree summary {
  cursor: pointer;
  list-style: none;
  font-weight: 600;
  color: var(--text);
}
.nav-tree summary::-webkit-details-marker { display: none; }
.nav-tree summary::before {
  content: "";
  flex: 0 0 auto;
  width: 0;
  height: 0;
  border-left: 5px solid currentColor;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  opacity: .5;
  transition: transform .15s ease;
}
.nav-tree details[open] > summary::before { transform: rotate(90deg); }
.nav-tree summary a, .nav-tree summary span {
  display: inline;
  gap: 0;
  padding: 0;
  color: inherit;
  font: inherit;
}
.nav-tree summary a:hover { background: none; color: inherit; }

/* File rows: a small square dot, filled when it's the current page. */
.nav-tree li > a::before {
  content: "";
  flex: 0 0 auto;
  width: .4rem;
  height: .4rem;
  margin: 0 .05rem;
  border-radius: 2px;
  background: currentColor;
  opacity: .35;
}
.nav-tree li > a:hover::before { opacity: .6; }
.nav-tree li > a[aria-current="page"]::before { opacity: 1; }

.onyx-main {
  width: min(100%, 78rem);
  padding: clamp(1.2rem, 4vw, 4rem);
}
.onyx-note {
  max-width: 52rem;
}
.onyx-note-header {
  border-bottom: 1px solid var(--line);
  margin-bottom: 1.35rem;
  padding-bottom: 1rem;
}
.onyx-path {
  color: var(--muted);
  font-size: .85rem;
  line-height: 1.2;
  margin: 0 0 .35rem;
}
.onyx-note h1 {
  font-size: clamp(2rem, 5vw, 3.2rem);
  letter-spacing: 0;
  line-height: 1.05;
  margin: 0;
}
.onyx-source {
  display: inline-block;
  font-size: .86rem;
  margin-top: .65rem;
}

.onyx-content h2, .onyx-content h3, .onyx-content h4 {
  line-height: 1.15;
  margin-top: 2rem;
}
.onyx-content p, .onyx-content ul, .onyx-content ol, .onyx-content blockquote, .onyx-content table, .onyx-content pre {
  margin-bottom: 1rem;
}
.onyx-content img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
}
.onyx-content code {
  background: var(--code);
  border-radius: 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .92em;
  padding: .08rem .25rem;
}
.onyx-content pre {
  background: var(--pre-bg);
  color: var(--pre-text);
  overflow: auto;
  padding: 1rem;
  border-radius: 8px;
}
.onyx-content pre code {
  background: transparent;
  color: inherit;
  padding: 0;
}
.onyx-content blockquote {
  border-left: 3px solid var(--line);
  color: var(--muted);
  margin-left: 0;
  padding-left: 1rem;
}
.onyx-content table {
  border-collapse: collapse;
  display: block;
  max-width: 100%;
  overflow-x: auto;
}
.onyx-content th, .onyx-content td {
  border: 1px solid var(--line);
  padding: .45rem .6rem;
  vertical-align: top;
}
.onyx-content th { background: var(--panel); text-align: left; }
.onyx-content .onyx-math {
  margin: 1.1rem 0;
  overflow-x: auto;
  overflow-y: hidden;
}

.callout {
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  margin: 1rem 0;
  padding: .8rem 1rem;
  background: var(--surface);
}
.callout-title {
  color: var(--accent);
  font-weight: 800;
  margin: 0 0 .35rem;
}
.callout-warning, .callout-danger, .callout-caution { border-left-color: var(--warn); }
.callout-warning .callout-title, .callout-danger .callout-title, .callout-caution .callout-title { color: var(--warn); }

.broken-link {
  color: var(--warn);
  font-weight: 700;
}
.embed-note {
  border: 1px solid var(--line);
  border-radius: 6px;
  display: inline-block;
  padding: .05rem .35rem;
  text-decoration: none;
}

.onyx-backlinks {
  border-top: 1px solid var(--line);
  margin-top: 2rem;
  padding-top: 1rem;
}
.onyx-backlinks h2 {
  font-size: 1rem;
  letter-spacing: 0;
  margin: 0 0 .5rem;
}
.onyx-backlinks ul { padding-left: 1.1rem; }
.onyx-backlinks span {
  color: var(--muted);
  font-size: .85rem;
}

/* Graph view: a sidebar trigger that opens a full-screen force-directed map. */
.onyx-graph-btn {
  display: flex;
  align-items: center;
  gap: .5rem;
  width: 100%;
  margin-bottom: 1rem;
  padding: .5rem .65rem;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  line-height: 1.2;
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease, color .12s ease;
}
.onyx-graph-btn:hover { background: var(--hover); border-color: var(--accent); color: var(--accent); }
.onyx-graph-btn svg { width: 1.1em; height: 1.1em; flex: 0 0 auto; opacity: .85; }

.onyx-graph-modal { position: fixed; inset: 0; z-index: 50; display: flex; }
.onyx-graph-modal[hidden] { display: none; }
.onyx-graph-backdrop {
  position: absolute;
  inset: 0;
  background: var(--graph-backdrop);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}
.onyx-graph-panel {
  position: relative;
  margin: auto;
  width: min(94vw, 1100px);
  height: min(88vh, 780px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 24px 60px var(--graph-shadow);
  animation: onyx-graph-pop .16s ease;
}
@keyframes onyx-graph-pop {
  from { opacity: 0; transform: translateY(8px) scale(.99); }
  to { opacity: 1; transform: none; }
}
.onyx-graph-toolbar {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .55rem .9rem;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.onyx-graph-title { font-weight: 750; }
/* The count carries the auto margin (not the hint) so the close button stays
   pinned right even when the hint is hidden on narrow screens. */
.onyx-graph-count { color: var(--muted); font-size: .8rem; margin-right: auto; }
.onyx-graph-count:not(:empty)::before {
  content: "";
  display: inline-block;
  width: 1px;
  height: .9em;
  margin-right: .75rem;
  vertical-align: -.1em;
  background: var(--line);
}
.onyx-graph-hint { color: var(--muted); font-size: .8rem; }
.onyx-graph-close {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 1.5rem;
  line-height: 1;
  padding: 0 .25rem;
  border-radius: 6px;
}
.onyx-graph-close:hover { color: var(--text); background: var(--hover); }
#onyx-graph-canvas {
  flex: 1 1 auto;
  width: 100%;
  height: 100%;
  display: block;
  /* Soft center-lit gradient; --graph-halo (label/rim paint) should sit
     between these two tones so halos melt into the backdrop. */
  background: radial-gradient(120% 100% at 50% 32%, var(--graph-bg-center), var(--graph-bg-edge));
  cursor: grab;
  touch-action: none;
}
#onyx-graph-canvas.is-grabbing { cursor: grabbing; }
#onyx-graph-canvas.is-pointing { cursor: pointer; }
body.onyx-graph-lock { overflow: hidden; }

@media (max-width: 820px) {
  .onyx-shell { display: block; }
  .onyx-sidebar {
    position: static;
    height: auto;
    max-height: 45vh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .onyx-main { padding: 1.2rem; }
  .onyx-note h1 { font-size: 2rem; }
  .onyx-graph-panel { width: 96vw; height: 90vh; }
  .onyx-graph-hint { display: none; }
}
