/* ------------------------------------------------------------------ *
 * Theme palette — kept in sync with the main site (site/style.css):
 * same backgrounds, text, accent (green), and borders, in both light
 * and dark, so /wiki looks like the rest of the site. Light is the
 * default; dark applies when the page has `data-theme="dark"` (set by
 * the site theme toggle + its pre-paint bootstrap) or, absent an
 * explicit choice, when the OS prefers dark. Code blocks stay dark in
 * both themes (see the syntax section).
 * ------------------------------------------------------------------ */
:root {
  color-scheme: light;
  --ink: #1a1a1a;          /* site --fg */
  --ink-soft: #555f6d;     /* site --muted */
  --ink-muted: #555f6d;    /* site --muted */
  --accent: #2f7d4f;       /* site --accent */
  --accent-strong: #276b43;
  --page-glow: transparent;
  --page-bg-top: #ffffff;      /* site --bg */
  --page-bg-bottom: #ffffff;   /* site --bg */
  --sidebar-bg: #f5f7f6;   /* site --card */
  --surface: #f5f7f6;      /* site --card */
  --input-bg: #ffffff;
  --pop-bg: #ffffff;
  --hair: #e2e6e4;         /* site --border */
  --hair-soft: #e2e6e4;
  --hair-strong: #d3d9d6;
  --hair-header: #e2e6e4;
  --hair-table: #e2e6e4;
  --shadow: rgba(0, 0, 0, 0.08);
  --shadow-soft: rgba(0, 0, 0, 0.05);
  --accent-wash: rgba(47, 125, 79, 0.1);
  --quote-bar: rgba(47, 125, 79, 0.35);
}

/* Dark palette (mirrors site/style.css dark) — reused by the explicit
   `data-theme="dark"` selector and the OS-preference fallback. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --ink: #e8ece9;          /* site --fg */
  --ink-soft: #9aa6a0;     /* site --muted */
  --ink-muted: #9aa6a0;
  --accent: #5cc98a;       /* site --accent */
  --accent-strong: #7ad9a2;
  --page-glow: transparent;
  --page-bg-top: #0f1311;      /* site --bg */
  --page-bg-bottom: #0f1311;
  --sidebar-bg: #182019;   /* site --card */
  --surface: #182019;
  --input-bg: #0b0f0d;
  --pop-bg: #182019;
  --hair: #26302a;         /* site --border */
  --hair-soft: #26302a;
  --hair-strong: #333f38;
  --hair-header: #26302a;
  --hair-table: #26302a;
  --shadow: rgba(0, 0, 0, 0.45);
  --shadow-soft: rgba(0, 0, 0, 0.35);
  --accent-wash: rgba(92, 201, 138, 0.16);
  --quote-bar: rgba(92, 201, 138, 0.4);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --ink: #e8ece9;
    --ink-soft: #9aa6a0;
    --ink-muted: #9aa6a0;
    --accent: #5cc98a;
    --accent-strong: #7ad9a2;
    --page-glow: transparent;
    --page-bg-top: #0f1311;
    --page-bg-bottom: #0f1311;
    --sidebar-bg: #182019;
    --surface: #182019;
    --input-bg: #0b0f0d;
    --pop-bg: #182019;
    --hair: #26302a;
    --hair-soft: #26302a;
    --hair-strong: #333f38;
    --hair-header: #26302a;
    --hair-table: #26302a;
    --shadow: rgba(0, 0, 0, 0.45);
    --shadow-soft: rgba(0, 0, 0, 0.35);
    --accent-wash: rgba(92, 201, 138, 0.16);
    --quote-bar: rgba(92, 201, 138, 0.4);
  }
}

* { box-sizing: border-box; }
/* Theme the canvas (html), not just body, so short pages and the macOS
   overscroll area follow the theme instead of showing white. */
html { background: var(--page-bg-bottom); }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, var(--page-glow), transparent 28rem),
    linear-gradient(180deg, var(--page-bg-top) 0%, var(--page-bg-bottom) 100%);
}
a { color: var(--accent); }
a:hover { color: var(--accent-strong); }
.site-layout {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(16rem, 20rem) minmax(0, 1fr);
}
.site-sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  overflow: auto;
  padding: 1.5rem 1.25rem 2rem;
  border-right: 1px solid var(--hair);
  background: var(--sidebar-bg);
}
.site-brand {
  display: inline-block;
  margin-bottom: 0.4rem;
  color: var(--ink);
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-decoration: none;
}
.site-tagline {
  margin: 0 0 1.25rem;
  color: var(--ink-muted);
}
.search-label {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--ink-muted);
}
.site-search {
  width: 100%;
  padding: 0.75rem 0.85rem;
  border: 1px solid var(--hair-strong);
  border-radius: 0.8rem;
  background: var(--input-bg);
  color: var(--ink);
  font: inherit;
}
.search-results {
  display: none;
  margin-top: 0.8rem;
  border: 1px solid var(--hair);
  border-radius: 1rem;
  overflow: hidden;
  background: var(--pop-bg);
  box-shadow: 0 18px 40px var(--shadow);
}
.search-results.active { display: block; }
.search-result {
  display: block;
  padding: 0.85rem 0.95rem;
  text-decoration: none;
  border-top: 1px solid var(--hair-soft);
}
.search-result:first-child { border-top: 0; }
.search-result strong {
  display: block;
  margin-bottom: 0.2rem;
  color: var(--ink);
}
.search-result span {
  color: var(--ink-muted);
  font-size: 0.95rem;
}
.site-nav ul {
  list-style: none;
  margin: 1.25rem 0 0;
  padding: 0;
}
.site-nav a {
  display: block;
  padding: 0.45rem 0.6rem;
  border-radius: 0.65rem;
  color: var(--ink-soft);
  text-decoration: none;
}
.site-nav a.active,
.site-nav a:hover {
  color: var(--ink);
  background: var(--accent-wash);
}
.site-main {
  padding: 3rem min(6vw, 4rem) 4rem;
}
.page-card,
#content {
  max-width: 56rem;
  padding: 2rem 2.2rem;
  border: 1px solid var(--hair-soft);
  border-radius: 1.4rem;
  background: var(--surface);
  box-shadow: 0 24px 50px var(--shadow-soft);
}
.page-header {
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--hair-header);
}
.page-kicker {
  margin: 0 0 0.3rem;
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.site-hero {
  max-width: 56rem;
  margin-bottom: 1.5rem;
}
.site-hero h1 {
  margin: 0 0 0.5rem;
  font-size: clamp(2rem, 5vw, 3.4rem);
  line-height: 1.05;
  letter-spacing: -0.01em;
}
.site-hero p {
  max-width: 42rem;
  color: var(--ink-soft);
  font-size: 1.1rem;
}
.page-grid {
  display: grid;
  gap: 1rem;
}
.page-card h2 {
  margin-top: 0;
  margin-bottom: 0.5rem;
}
.page-card p {
  margin-bottom: 0;
  color: var(--ink-soft);
}
#content h1, #content h2, #content h3, #content h4 {
  line-height: 1.2;
}
#content h1.title {
  margin-top: 0;
  font-size: clamp(1.9rem, 4vw, 3rem);
  letter-spacing: -0.01em;
}
#content pre, #content code {
  font-family: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;
}
#content pre {
  overflow-x: auto;
  padding: 1rem;
  border-radius: 1rem;
  background: #0b0f0d;
  color: #e8ece9;
}
#content blockquote {
  margin-left: 0;
  padding-left: 1rem;
  border-left: 3px solid var(--quote-bar);
  color: var(--ink-soft);
}
#content table {
  border-collapse: collapse;
}
#content td, #content th {
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--hair-table);
}
/* ------------------------------------------------------------------ *
 * Tabbed code blocks (built by wiki.js from `#+begin_tabs` blocks).
 * These are part of the (always-dark) code card, so they keep fixed
 * colors in both themes; the active tab uses the site accent.
 * ------------------------------------------------------------------ */
#content .tabs {
  margin: 1.5rem 0;
  border: 1px solid var(--hair);
  border-radius: 1rem;
  overflow: hidden;
  background: #0b0f0d;
  box-shadow: 0 18px 40px var(--shadow);
}
#content .tab-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  padding: 0.5rem 0.5rem 0;
  background: #060907;
  border-bottom: 1px solid rgba(232, 236, 233, 0.08);
}
#content .tab-button {
  appearance: none;
  border: 0;
  padding: 0.5rem 1rem;
  border-radius: 0.6rem 0.6rem 0 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: #9aa6a0;
  background: transparent;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
#content .tab-button:hover {
  color: #e8ece9;
  background: rgba(232, 236, 233, 0.08);
}
#content .tab-button.active {
  color: #0f1311;
  background: #5cc98a;
}
#content .tab-panes {
  padding: 0.25rem 0.75rem 0.75rem;
}
#content .tab-pane {
  display: none;
}
#content .tab-pane.active {
  display: block;
}
/* Let panes reuse the shared <pre> styling but without doubling the card. */
#content .tabs .org-src-container {
  margin: 0.75rem 0 0;
}
#content .tabs pre.src,
#content .tabs pre.example {
  margin: 0.5rem 0 0;
  background: #060907;
}
#content .tabs pre.example {
  color: #a9d99a;
  border-left: 3px solid rgba(92, 201, 138, 0.4);
}
/* Before JS runs, show every block stacked so no-JS readers still see all. */
#content .tabs:not(.tabs-ready) > .org-src-container { margin-top: 0.75rem; }

/* ------------------------------------------------------------------ *
 * Syntax highlighting (htmlize `css' output; classes are Org face names).
 * Tuned for the dark code background used by <pre> and the tab panes.
 *
 * Distinct hues per token category so highlighting reads clearly:
 *   keyword=orange  type=teal  function=yellow  string=green
 *   constant/number=purple  variable=tan  builtin=salmon  macro=lavender
 * Covers C/C++, Python, and R.  R uses ESS faces (`org-ess-*`), which are
 * mapped onto the same categories so R blocks highlight like the others.
 * ------------------------------------------------------------------ */
/* keywords / control flow */
#content pre .org-keyword,
#content pre .org-ess-keyword,
#content pre .org-rst-directive { color: #f0a35a; }
/* strings */
#content pre .org-string,
#content pre .org-doc-string { color: #a9d99a; }
/* comments & docstrings */
#content pre .org-comment,
#content pre .org-comment-delimiter { color: #9a8a79; font-style: italic; }
#content pre .org-doc { color: #b3a892; font-style: italic; }
/* definitions */
#content pre .org-function-name { color: #f5d370; }
#content pre .org-variable-name { color: #ebcaa2; }
/* types & classes */
#content pre .org-type { color: #79cdba; }
/* literals: numbers, booleans, symbolic constants */
#content pre .org-constant,
#content pre .org-ess-constant { color: #d0b3ec; }
/* built-in functions */
#content pre .org-builtin { color: #f0a074; }
/* preprocessor / macros / modifiers (e.g. C `#define`, R modifiers) */
#content pre .org-preprocessor,
#content pre .org-ess-modifiers { color: #c9a6f0; }
/* operators, incl. R's `<-` assignment */
#content pre .org-operator { color: #cdb89b; }
#content pre .org-ess-assignment,
#content pre .org-negation-char { color: #f0a35a; }
/* warnings */
#content pre .org-warning { color: #ef8a7a; font-weight: 600; }

@media (max-width: 900px) {
  .site-layout {
    grid-template-columns: 1fr;
  }
  .site-sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--hair);
  }
  .site-main {
    padding: 1.25rem 1rem 2rem;
  }
  .page-card,
  #content {
    padding: 1.25rem;
  }
}

/* Search-led wiki navigation. The home page is intentionally sidebar-free;
   article pages keep a compact finder in place of the former page directory. */
.wiki-home .site-layout { display: block; }
.wiki-home .site-main {
  min-height: calc(100vh - 4.5rem);
  display: grid;
  place-items: center;
  padding: clamp(3rem, 8vw, 7rem) 1.25rem;
}
.wiki-home .site-hero { width: min(100%, 52rem); margin: 0 auto; text-align: center; }
.wiki-home .site-hero .page-kicker { margin-bottom: .8rem; }
.wiki-home .site-hero > p:not(.page-kicker):not(.note-count) { margin: 0 auto 2rem; }
.wiki-finder { position: relative; }
.wiki-finder--hero { text-align: left; }
.wiki-finder--hero .search-label {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0);
}
.search-field { position: relative; display: flex; align-items: center; }
.search-field > svg {
  position: absolute; left: 1rem; z-index: 1; width: 1.25rem; height: 1.25rem;
  fill: none; stroke: var(--ink-muted); stroke-width: 1.8; stroke-linecap: round;
}
.search-field .site-search { padding-left: 2.9rem; padding-right: 3.2rem; }
.site-search:focus { outline: 3px solid var(--accent-wash); border-color: var(--accent); }
.search-field kbd {
  position: absolute; right: .7rem; padding: .2rem .4rem;
  border: 1px solid var(--hair-strong); border-radius: .35rem;
  color: var(--ink-muted); background: var(--surface); font: 600 .72rem/1.2 inherit;
}
.wiki-finder--hero .site-search {
  min-height: 4.25rem; padding-left: 3.5rem; font-size: 1.08rem;
  border-radius: 1.15rem; box-shadow: 0 20px 55px var(--shadow);
}
.wiki-finder--hero .search-field > svg { left: 1.25rem; width: 1.45rem; height: 1.45rem; }
.wiki-finder--hero .search-results { margin-top: .75rem; max-height: min(50vh, 34rem); }
.search-results { max-height: min(65vh, 42rem); overflow-y: auto; }
.search-result {
  display: grid; grid-template-columns: 3.25rem minmax(0, 1fr) auto;
  align-items: center; gap: .85rem;
}
.search-result:hover, .search-result.selected { background: var(--accent-wash); }
.result-image {
  display: grid !important; place-items: center; width: 3.25rem; aspect-ratio: 1;
  border-radius: .7rem; color: var(--accent) !important; background: var(--accent-wash);
}
.result-image svg {
  width: 2rem; fill: none; stroke: currentColor; stroke-width: 1.7;
  stroke-linecap: round; stroke-linejoin: round;
}
.result-copy { min-width: 0; }
.search-result .result-copy > span {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; line-height: 1.4;
}
.result-arrow { color: var(--ink-muted); font-size: 1.25rem; }
.search-empty { margin: 0; padding: 1.25rem; color: var(--ink-muted); text-align: center; }
.note-count { margin: 1rem 0 0; color: var(--ink-muted); font-size: .88rem; }

@media (max-width: 900px) {
  .wiki-home .site-main { padding: 3rem 1rem; }
  .wiki-page .site-sidebar { padding-bottom: 1.25rem; }
  .wiki-page .search-results { max-height: 22rem; }
}

@media (max-width: 520px) {
  .search-field kbd { display: none; }
  .search-field .site-search { padding-right: 1rem; }
  .search-result { grid-template-columns: 2.65rem minmax(0, 1fr); }
  .result-image { width: 2.65rem; }
  .result-arrow { display: none !important; }
}
