/* Obsidian-ish two-pane layout: fixed explorer on the left, content on the right.
   Dark by default with a light-scheme override, since Obsidian's default is dark. */

:root {
  --bg: #1e1e20;
  --bg-side: #191919;
  --bg-node: #262626;
  --fg: #dcddde;
  --fg-dim: #999;
  --line: #333;
  --accent: #7c9cbf;
  --sidebar-w: 280px;
  --radius: 6px;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #fff; --bg-side: #f6f6f6; --bg-node: #fff;
    --fg: #23272e; --fg-dim: #6a6a6a; --line: #e0e0e0; --accent: #3a6ea5;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--fg);
  font: 16px/1.65 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
a { color: var(--accent); }

/* ---------------------------------------------------------------- sidebar */
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w);
  background: var(--bg-side); border-right: 1px solid var(--line);
  overflow-y: auto; padding: 0 0 2rem;
}
.sidebar-head { padding: 1rem 1rem .5rem; }
.brand { font-weight: 600; text-decoration: none; color: var(--fg); }
.search-wrap { padding: 0 .75rem 1rem; }

.explorer { font-size: 14px; }
.explorer ul { list-style: none; margin: 0; padding-left: .85rem; }
.explorer > ul { padding-left: .35rem; }
.explorer li { margin: 1px 0; }

.explorer summary {
  cursor: pointer; padding: 3px 6px; border-radius: var(--radius);
  list-style: none; user-select: none; color: var(--fg);
}
.explorer summary::-webkit-details-marker { display: none; }
.explorer summary:hover { background: rgba(127,127,127,.14); }

/* Twisty rotates when the folder opens — pure CSS, no JS. */
.twisty {
  display: inline-block; width: 0; height: 0; margin-right: .45rem;
  border-left: 5px solid currentColor; border-top: 4px solid transparent;
  border-bottom: 4px solid transparent; opacity: .55;
  transition: transform .12s ease;
}
details[open] > summary .twisty { transform: rotate(90deg); }

.explorer .file a {
  display: flex; align-items: center; gap: .4rem;
  padding: 3px 6px; border-radius: var(--radius);
  color: var(--fg); text-decoration: none;
}
.explorer .file a:hover { background: rgba(127,127,127,.14); }
.explorer .file.active > a { background: rgba(124,156,191,.22); color: var(--fg); font-weight: 600; }

.ico { width: 12px; height: 12px; flex: 0 0 12px; opacity: .6; }
.ico-doc {
  border: 1px solid currentColor; border-radius: 2px;
  background: linear-gradient(currentColor, currentColor) no-repeat center/6px 1px;
}
.ico-canvas { border: 1px solid currentColor; border-radius: 2px; position: relative; opacity: .85; }
.ico-canvas::after {
  content: ''; position: absolute; inset: 2px;
  background: currentColor; opacity: .45; border-radius: 1px;
}

/* ---------------------------------------------------------------- content */
.content { margin-left: var(--sidebar-w); padding: 2.5rem 3rem 6rem; }
.prose { max-width: 46rem; }
.page-head h1 { margin: 0 0 .25rem; font-size: 1.9rem; line-height: 1.2; }
.page-head time, .muted { color: var(--fg-dim); font-size: .85rem; }
.page-head .source { margin-left: .75rem; font-size: .8rem; }
.prose img { max-width: 100%; height: auto; border-radius: var(--radius); }
.prose video, .prose iframe { max-width: 100%; border: 0; border-radius: var(--radius); }
.prose iframe { aspect-ratio: 16/9; width: 100%; height: auto; }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 2rem 0; }

/* Tables. There was no styling at all before, so browser defaults produced
   unaligned columns and headers wrapping onto three lines. */
/* Frame lives on the wrapper: border-radius on a border-collapse table clips
   unreliably across browsers, and the wrapper is what scrolls anyway. */
.table-wrap {
  overflow-x: auto; margin: 1.4rem 0;
  border: 1px solid var(--line); border-radius: var(--radius);
}
.prose table {
  border-collapse: collapse;
  width: 100%;
  font-size: .93rem;
  line-height: 1.45;
}
.prose thead th {
  text-align: left;
  font-weight: 600;
  padding: .5rem .75rem;
  border-bottom: 2px solid var(--line);
  background: rgba(127,127,127,.07);
  /* Keep multi-word headers on one line where there is room; the wrapper
     scrolls if there is not. */
  white-space: nowrap;
}
.prose tbody td {
  padding: .45rem .75rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.prose tbody tr:last-child td { border-bottom: 0; }
.prose tbody tr:hover { background: rgba(127,127,127,.06); }

/* Code. Like tables before it, there was no styling at all here — the site had
   simply never had a code block until the Coding section. */
.prose code {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: .875em;
}
/* Inline code only: the descendant form would double-decorate code inside pre. */
.prose :not(pre) > code {
  background: rgba(127,127,127,.14);
  padding: .12em .35em; border-radius: 4px;
  /* Long identifiers must not widen the page — the block form scrolls instead. */
  overflow-wrap: break-word;
}
.prose pre {
  background: var(--bg-node);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: .85rem 1rem; margin: 1.4rem 0;
  /* Code is the one thing that must never reflow, so it scrolls on its own
     rather than forcing the page to scroll sideways. */
  overflow-x: auto;
  line-height: 1.55;
}
.prose pre code { background: none; padding: 0; border-radius: 0; font-size: .85rem; }
.prose blockquote {
  margin: 1.4rem 0; padding: .1rem 0 .1rem 1rem;
  border-left: 3px solid var(--line); color: var(--fg-dim);
}

/* Table of contents — only rendered on very long pages (see single.html). */
.toc {
  margin: 1.5rem 0 2rem; padding: .75rem 1rem;
  background: var(--bg-side); border: 1px solid var(--line); border-radius: var(--radius);
  font-size: .9rem;
}
.toc summary { cursor: pointer; font-weight: 600; }
.toc ul { list-style: none; padding-left: 1rem; margin: .5rem 0 0; }
.toc > details > ul { padding-left: 0; }
.toc li { margin: .15rem 0; }
.toc a { text-decoration: none; }
.toc a:hover { text-decoration: underline; }
/* A 200-entry contents list would otherwise dwarf the article it indexes. */
.toc > details[open] > ul { max-height: 22rem; overflow-y: auto; }

.index { list-style: none; padding: 0; }
.index li { padding: .35rem 0; border-bottom: 1px solid var(--line); display: flex; gap: .75rem; justify-content: space-between; }

/* ----------------------------------------------------------------- canvas */
.canvas-page { max-width: none; }
.canvas-tools { display: flex; align-items: center; gap: .4rem; margin: .5rem 0 1rem; }
.canvas-tools button {
  background: var(--bg-node); color: var(--fg); border: 1px solid var(--line);
  border-radius: var(--radius); width: 30px; height: 28px; cursor: pointer; font-size: 14px;
}
.canvas-tools button[data-canvas-zoom="fit"] { width: auto; padding: 0 .6rem; }
.canvas-tools button:hover { border-color: var(--accent); }
.canvas-tools .hint { color: var(--fg-dim); font-size: .8rem; margin-left: .5rem; }

.canvas-viewport {
  position: relative; overflow: hidden; touch-action: none;
  height: min(76vh, 900px);
  background: var(--bg-side);
  border: 1px solid var(--line); border-radius: var(--radius);
  cursor: grab;
}
.canvas-viewport.dragging { cursor: grabbing; }
.canvas-stage { position: absolute; top: 0; left: 0; transform-origin: 0 0; --z: 1; }
.canvas-loading, .canvas-error { padding: 1.25rem; color: var(--fg-dim); }

.canvas-edges { position: absolute; top: 0; left: 0; overflow: visible; color: var(--fg-dim); }
/* Divide out the stage scale so lines stay the same visual weight at any zoom.
   The arrowhead uses markerUnits=strokeWidth, so it compensates with them. */
.canvas-edge {
  fill: none; stroke: var(--fg-dim); opacity: .8;
  stroke-width: calc(2px / var(--z, 1));
  stroke-linejoin: round; stroke-linecap: round;
}
.canvas-edge-label { fill: var(--fg-dim); font-size: calc(12px / var(--z, 1)); }

.canvas-node {
  position: absolute; overflow: auto;
  background: var(--bg-node);
  border-style: solid; border-color: var(--line);
  /* Constant on-screen width regardless of zoom — a plain 1px border shrinks
     with the stage and disappears when zoomed out. */
  border-width: calc(1px / var(--z, 1));
  border-radius: 8px; padding: .6rem .75rem; font-size: 14px; line-height: 1.5;
}
/* Coloured nodes carry meaning (Gavin's commentary vs Marx quotations), so their
   border is deliberately heavier and must stay legible when zoomed out. */
.canvas-node.is-coloured { border-width: calc(2.5px / var(--z, 1)); }
.canvas-node > :first-child { margin-top: 0; }
.canvas-node > :last-child { margin-bottom: 0; }
.canvas-node h1, .canvas-node h2, .canvas-node h3 { font-size: 1.05rem; margin: 0 0 .4rem; }
.canvas-node-file { padding: 0; overflow: hidden; }
.canvas-node-file img { width: 100%; height: 100%; object-fit: contain; display: block; }
.canvas-node-link { display: flex; align-items: center; padding: 1rem; }
.canvas-link { word-break: break-all; }

/* Preview card: stands in for the live webview Obsidian shows, since most sites
   refuse to be framed. Fills the node edge to edge — the node's own padding is
   dropped so the thumbnail can bleed to the border. */
.canvas-node-link.has-card { padding: 0; overflow: hidden; }
.canvas-link-card {
  display: flex; flex-direction: column;
  width: 100%; height: 100%;
  text-decoration: none; color: inherit; word-break: normal;
}
.canvas-link-card:hover .canvas-link-title { text-decoration: underline; }
.canvas-link-thumb {
  width: 100%; flex: 1 1 auto; min-height: 0;
  object-fit: cover; object-position: top center; display: block;
  background: var(--bg);
}
.canvas-link-body {
  flex: 0 0 auto; padding: .6rem .75rem;
  /* Same hairline treatment as the node border, so it holds up when zoomed out. */
  border-top: calc(1px / var(--z, 1)) solid var(--line);
}
.canvas-link-title { font-weight: 600; line-height: 1.3; }
/* Long titles and blurbs must not push the domain out of a fixed-height node. */
.canvas-link-desc {
  margin-top: .25rem; font-size: 13px; line-height: 1.4; color: var(--fg-dim);
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
  overflow: hidden;
}
.canvas-link-domain {
  margin-top: .35rem; font-size: 12px; color: var(--fg-dim);
  text-transform: lowercase; letter-spacing: .02em;
}

/* Internal note card. No thumbnail, so the body fills the node and the excerpt
   gets the room the image would have taken. */
.canvas-node.is-note .canvas-link-card { justify-content: flex-start; }
.canvas-node.is-note .canvas-link-body {
  border-top: 0; padding: .85rem 1rem; display: flex; flex-direction: column; height: 100%;
}
.canvas-note-excerpt { -webkit-line-clamp: 8; flex: 1 1 auto; }
.canvas-node.is-note .canvas-link-domain { margin-top: auto; }

/* YouTube player: fills the node, which Obsidian sizes 16:9 already. */
.canvas-node-link.has-embed { padding: 0; overflow: hidden; background: #000; }
.canvas-embed { width: 100%; height: 100%; border: 0; display: block; }

.canvas-fallback {
  max-width: 46rem; margin-top: 2rem;
  border-top: 1px solid var(--line); padding-top: 1rem;
}
.canvas-fallback summary { cursor: pointer; color: var(--fg-dim); }

/* ----------------------------------------------------------------- mobile */
.nav-toggle {
  display: none; position: fixed; top: .6rem; left: .6rem; z-index: 20;
  background: var(--bg-node); color: var(--fg); border: 1px solid var(--line);
  border-radius: var(--radius); width: 36px; height: 34px; font-size: 16px; cursor: pointer;
}
@media (max-width: 800px) {
  .nav-toggle { display: block; }
  .sidebar { transform: translateX(-100%); transition: transform .18s ease; z-index: 15; }
  .sidebar.open { transform: none; }
  .content { margin-left: 0; padding: 3.5rem 1.1rem 4rem; }
  .canvas-viewport { height: 65vh; }
}

/* Pagefind's own UI, nudged to fit the dark sidebar. */
.pagefind-ui { --pagefind-ui-scale: .8; --pagefind-ui-primary: var(--fg); --pagefind-ui-text: var(--fg);
  --pagefind-ui-background: var(--bg-side); --pagefind-ui-border: var(--line); --pagefind-ui-tag: var(--bg-node); }

/* Obsidian tags (#Metaphysics) kept as their own block, styled like the chips
   Obsidian shows, rather than being folded into the following paragraph. */
.obsidian-tag {
  display: inline-block; margin: .9rem 0 .1rem;
  padding: 1px .5rem; border-radius: 999px;
  background: rgba(124,156,191,.16); color: var(--accent);
  font-size: .8rem; font-weight: 600; text-decoration: none;
}
