/* ==========================================================================
   SwfMesh docs - one small design system, no framework.

   Every colour is a token defined on :root (light). Dark mode redefines only
   the tokens, twice: once for the OS preference and once for the manual
   toggle, so both directions work.
   ========================================================================== */

:root {
  --bg:            #ffffff;
  --bg-soft:       #f7f8fa;
  --bg-sunken:     #f1f3f6;
  --surface:       #ffffff;
  --border:        #e3e6ec;
  --border-strong: #cbd1db;

  --text:          #1c2129;
  --text-soft:     #5b6474;
  --text-faint:    #8b94a3;

  --accent:        #1f6feb;
  --accent-soft:   #e8f0fe;
  --accent-text:   #1558c4;

  --code-bg:       #f7f8fa;
  --code-text:     #1c2129;
  --hl-keyword:    #a01ca5;
  --hl-string:     #0a7d33;
  --hl-number:     #b3541e;
  --hl-comment:    #7b8494;
  --hl-title:      #1558c4;
  --hl-attr:       #b3541e;

  --shadow:        0 1px 2px rgba(16, 22, 32, .06), 0 8px 24px rgba(16, 22, 32, .08);

  --sidebar-w:     16rem;
  --topbar-h:      3.5rem;
  --radius:        8px;

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "JetBrains Mono", Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:            #0f1218;
    --bg-soft:       #151a22;
    --bg-sunken:     #1b212b;
    --surface:       #151a22;
    --border:        #262d39;
    --border-strong: #3a4351;

    --text:          #e5e9f0;
    --text-soft:     #a3adbd;
    --text-faint:    #737f91;

    --accent:        #61a0ff;
    --accent-soft:   #17263f;
    --accent-text:   #8cbaff;

    --code-bg:       #12161d;
    --code-text:     #e5e9f0;
    --hl-keyword:    #d9a6ff;
    --hl-string:     #8ee29b;
    --hl-number:     #ffb37a;
    --hl-comment:    #6f7b8c;
    --hl-title:      #7fb2ff;
    --hl-attr:       #ffc08a;

    --shadow:        0 1px 2px rgba(0, 0, 0, .5), 0 8px 24px rgba(0, 0, 0, .45);
  }
}

:root[data-theme="dark"] {
  --bg:            #0f1218;
  --bg-soft:       #151a22;
  --bg-sunken:     #1b212b;
  --surface:       #151a22;
  --border:        #262d39;
  --border-strong: #3a4351;

  --text:          #e5e9f0;
  --text-soft:     #a3adbd;
  --text-faint:    #737f91;

  --accent:        #61a0ff;
  --accent-soft:   #17263f;
  --accent-text:   #8cbaff;

  --code-bg:       #12161d;
  --code-text:     #e5e9f0;
  --hl-keyword:    #d9a6ff;
  --hl-string:     #8ee29b;
  --hl-number:     #ffb37a;
  --hl-comment:    #6f7b8c;
  --hl-title:      #7fb2ff;
  --hl-attr:       #ffc08a;

  --shadow:        0 1px 2px rgba(0, 0, 0, .5), 0 8px 24px rgba(0, 0, 0, .45);
}

/* ------------------------------------------------------------------ base */

*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; scroll-padding-top: calc(var(--topbar-h) + 1rem); }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent-text); text-decoration-color: color-mix(in srgb, var(--accent) 35%, transparent); text-underline-offset: 2px; }
a:hover { text-decoration-color: currentColor; }

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

.skip {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--accent); color: #fff; padding: .6rem 1rem; border-radius: 0 0 var(--radius) 0;
}
.skip:focus { left: 0; }

/* ---------------------------------------------------------------- topbar */

.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: .75rem;
  height: var(--topbar-h);
  padding: 0 1rem;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: baseline; gap: .5rem; text-decoration: none; color: var(--text); }
.brand-name { font-weight: 650; letter-spacing: -.01em; font-size: 1.05rem; }
.brand-tag { color: var(--text-faint); font-size: .8rem; }
@media (max-width: 600px) { .brand-tag { display: none; } }

.menu-btn, .theme-btn {
  place-items: center;
  width: 2.25rem; height: 2.25rem; flex: none;
  background: none; border: 1px solid transparent; border-radius: var(--radius);
  color: var(--text-soft); cursor: pointer;
}
.menu-btn:hover, .theme-btn:hover { background: var(--bg-sunken); color: var(--text); }

/* Both buttons only do something once app.js has run, so both stay hidden
   until the inline head script adds `js` to <html>. */
.menu-btn, .theme-btn { display: none; }
.js .theme-btn { display: grid; }

.theme-btn svg { grid-area: 1 / 1; display: none; }
.theme-btn[data-theme="auto"]  .i-auto,
.theme-btn[data-theme="light"] .i-light,
.theme-btn[data-theme="dark"]  .i-dark { display: block; }
.theme-btn:not([data-theme]) .i-auto { display: block; }

/* ---------------------------------------------------------------- search */

.search { position: relative; margin-left: auto; width: min(22rem, 45vw); }

.search input {
  width: 100%; height: 2.25rem;
  padding: 0 2rem 0 .75rem;
  font: inherit; font-size: .9rem;
  color: var(--text); background: var(--bg-sunken);
  border: 1px solid var(--border); border-radius: var(--radius);
  appearance: none;
}
.search input::placeholder { color: var(--text-faint); }
.search input:focus { background: var(--surface); border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }

.search-hint {
  position: absolute; right: .5rem; top: 50%; transform: translateY(-50%);
  pointer-events: none;
  font: 600 .7rem/1.5 var(--mono);
  color: var(--text-faint);
  border: 1px solid var(--border-strong); border-radius: 4px;
  padding: 0 .35rem;
}
.search input:focus ~ .search-hint { display: none; }

.search-results {
  position: absolute; top: calc(100% + .4rem); right: 0; left: 0; z-index: 50;
  margin: 0; padding: .3rem; list-style: none;
  max-height: min(28rem, 70vh); overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.search-results a { display: block; padding: .5rem .6rem; border-radius: 6px; text-decoration: none; color: var(--text); }
.search-results strong { display: block; font-size: .9rem; font-weight: 600; }
.search-results span { display: block; margin-top: .1rem; font-size: .78rem; color: var(--text-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-results li[aria-selected="true"] a, .search-results a:hover { background: var(--accent-soft); }
.no-hits { padding: .7rem .6rem; font-size: .85rem; color: var(--text-soft); }

/* ----------------------------------------------------------------- shell */

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  max-width: 82rem;
  margin: 0 auto;
}

.sidebar {
  position: sticky; top: var(--topbar-h);
  align-self: start;
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  padding: 1.5rem .75rem 3rem;
  border-right: 1px solid var(--border);
}

.nav-group {
  margin: 1.4rem .75rem .4rem;
  font-size: .72rem; font-weight: 650; letter-spacing: .06em; text-transform: uppercase;
  color: var(--text-faint);
}
.nav-group:first-child { margin-top: 0; }

.nav-list { margin: 0 0 .25rem; padding: 0; list-style: none; }
.nav-list a {
  display: block; padding: .35rem .75rem;
  font-size: .9rem; color: var(--text-soft);
  text-decoration: none; border-radius: 6px;
}
.nav-list a:hover { background: var(--bg-sunken); color: var(--text); }
.nav-list a[aria-current="page"] {
  background: var(--accent-soft); color: var(--accent-text); font-weight: 600;
  box-shadow: inset 2px 0 0 var(--accent);
}

/* Nested pages: a child list indented under its parent link. */
.nav-list .nav-sub {
  margin: .15rem 0 .35rem;
  padding-left: .75rem;
  border-left: 1px solid var(--border);
  margin-left: .75rem;
}
.nav-list .nav-sub a { font-size: .86rem; }
.nav-section { list-style: none; }
.nav-section > .nav-group { display: block; }
.nav-section > .nav-sub {
  margin-left: 0; padding-left: 0; border-left: 0;
}

/* Video: a click-to-play YouTube facade, or a self-hosted <video>. */
.video { margin: 1.75rem 0; }
.video video,
.video iframe,
.video-play {
  display: block; width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 10px;
  background: var(--bg-sunken);
}
.video video, .video-play { border: 1px solid var(--border); }
.video iframe { border: 0; }

.video-play { position: relative; padding: 0; cursor: pointer; overflow: hidden; }
.video-play img { width: 100%; height: 100%; object-fit: cover; display: block; }
.video-btn {
  position: absolute; inset: 0; margin: auto;
  width: 4.4rem; height: 3rem; border-radius: 12px;
  background: rgba(0, 0, 0, .7);
  transition: background .15s ease, transform .15s ease;
}
.video-btn::after {
  content: ''; position: absolute; inset: 0; margin: auto;
  width: 0; height: 0;
  border-style: solid; border-width: .55rem 0 .55rem .95rem;
  border-color: transparent transparent transparent #fff;
}
.video-play:hover .video-btn,
.video-play:focus-visible .video-btn { background: #e62117; transform: scale(1.06); }

.video figcaption {
  margin-top: .55rem;
  font-size: .85rem; color: var(--text-faint); text-align: center;
}

@media (prefers-reduced-motion: reduce) {
  .video-btn { transition: none; }
}

.content { min-width: 0; padding: 2.5rem 2.5rem 5rem; }
.prose { max-width: 46rem; }

.page-footer {
  max-width: 46rem;
  margin-top: 4rem; padding-top: 1.25rem;
  border-top: 1px solid var(--border);
  font-size: .82rem; color: var(--text-faint);
}
.page-footer p { margin: 0; }

/* ----------------------------------------------------------------- prose */

.prose > :first-child { margin-top: 0; }

.prose h1 { margin: 0 0 .6rem; font-size: 2.1rem; line-height: 1.2; letter-spacing: -.025em; font-weight: 680; }
.prose h2 { margin: 2.6rem 0 .8rem; font-size: 1.4rem; line-height: 1.3; letter-spacing: -.015em; font-weight: 650; padding-bottom: .35rem; border-bottom: 1px solid var(--border); }
.prose h3 { margin: 2rem 0 .6rem; font-size: 1.1rem; font-weight: 650; }
.prose h4 { margin: 1.6rem 0 .5rem; font-size: .95rem; font-weight: 650; color: var(--text-soft); }

.anchor {
  margin-left: .4rem; padding: 0 .15rem;
  color: var(--text-faint); text-decoration: none;
  opacity: 0; font-weight: 400;
}
h2:hover .anchor, h3:hover .anchor, .anchor:focus { opacity: 1; }

.prose p, .prose ul, .prose ol { margin: 0 0 1rem; }
.prose li { margin: .25rem 0; }
.prose li > ul, .prose li > ol { margin: .25rem 0; }

.prose hr { margin: 2.5rem 0; border: 0; border-top: 1px solid var(--border); }

.prose blockquote {
  margin: 1.25rem 0; padding: .1rem 1rem;
  border-left: 3px solid var(--border-strong);
  color: var(--text-soft);
}
.prose blockquote p:last-child { margin-bottom: 0; }

.prose img { max-width: 100%; height: auto; border-radius: var(--radius); }

/* Inline code (code blocks are restyled below). */
.prose :not(pre) > code {
  font-family: var(--mono); font-size: .875em;
  padding: .15em .35em;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: 4px;
}

/* ------------------------------------------------------------ code blocks */

figure.code {
  margin: 1.25rem 0;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.code-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .3rem .4rem .3rem .85rem;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--border);
}
.code-lang { font: 600 .72rem/1.6 var(--mono); letter-spacing: .04em; text-transform: uppercase; color: var(--text-faint); }

.copy {
  font: 500 .75rem/1 var(--font);
  padding: .35rem .6rem;
  color: var(--text-soft); background: transparent;
  border: 1px solid var(--border); border-radius: 5px;
  cursor: pointer;
}
.copy:hover { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.copy.is-copied { color: var(--hl-string); border-color: currentColor; }

figure.code pre { margin: 0; padding: .9rem 1rem; overflow-x: auto; }
figure.code code {
  font-family: var(--mono); font-size: .85rem; line-height: 1.6;
  color: var(--code-text); background: none; border: 0; padding: 0;
  display: block; min-width: max-content;
}

/* highlight.js tokens, mapped onto the theme tokens - no external theme file. */
.hljs-comment, .hljs-quote                          { color: var(--hl-comment); font-style: italic; }
.hljs-keyword, .hljs-selector-tag, .hljs-literal,
.hljs-doctag, .hljs-type, .hljs-name                { color: var(--hl-keyword); }
.hljs-string, .hljs-regexp, .hljs-addition,
.hljs-meta .hljs-string                             { color: var(--hl-string); }
.hljs-number, .hljs-symbol, .hljs-bullet,
.hljs-link, .hljs-deletion                          { color: var(--hl-number); }
.hljs-title, .hljs-title.function_, .hljs-section,
.hljs-built_in, .hljs-class .hljs-title             { color: var(--hl-title); }
.hljs-attr, .hljs-attribute, .hljs-variable,
.hljs-template-variable, .hljs-selector-attr,
.hljs-selector-class, .hljs-selector-id, .hljs-params { color: var(--hl-attr); }
.hljs-meta, .hljs-tag                               { color: var(--text-soft); }
.hljs-emphasis { font-style: italic; }
.hljs-strong   { font-weight: 600; }

/* --------------------------------------------------------------- tables */

.table-wrap { margin: 1.25rem 0; overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.table-wrap table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table-wrap th, .table-wrap td { padding: .55rem .85rem; text-align: left; border-bottom: 1px solid var(--border); }
.table-wrap th { background: var(--bg-soft); font-weight: 650; font-size: .82rem; letter-spacing: .01em; white-space: nowrap; }
.table-wrap tr:last-child td { border-bottom: 0; }

/* -------------------------------------------------------------- responsive */

@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); }

  /* No JS: the nav is simply a block of links stacked above the content,
     so every page stays reachable. */
  .sidebar {
    position: static;
    height: auto;
    padding: 1rem 1.25rem;
    border-right: 0; border-bottom: 1px solid var(--border);
  }

  /* With JS: the same nav becomes a drawer behind the menu button. */
  .js .menu-btn { display: grid; }
  .js .sidebar {
    display: none;
    position: fixed; inset: var(--topbar-h) 0 auto 0; z-index: 30;
    max-height: calc(100vh - var(--topbar-h)); overflow-y: auto;
    padding: 1rem;
    background: var(--surface);
    box-shadow: var(--shadow);
  }
  .js .sidebar.is-open { display: block; }

  .content { padding: 1.75rem 1.25rem 4rem; }
  .search { width: auto; flex: 1 1 auto; min-width: 0; }
  .search-hint { display: none; }
  .prose h1 { font-size: 1.7rem; }
}

@media print {
  .topbar, .sidebar, .copy, .anchor { display: none !important; }
  .shell { display: block; }
  .content { padding: 0; }
  figure.code, .table-wrap { break-inside: avoid; }
}
