/* Mode 8 - shared brand styles for the website and the manual.
   Tokens are documented in site/brand/BRAND.md. No external requests: fonts are self-hosted (OFL). */

@font-face {
  font-family: "Atkinson Hyperlegible Next";
  src: url("../fonts/AtkinsonHyperlegibleNext-latin.woff2") format("woff2");
  font-weight: 200 800; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Atkinson Hyperlegible Next";
  src: url("../fonts/AtkinsonHyperlegibleNext-Italic-latin.woff2") format("woff2");
  font-weight: 200 800; font-style: italic; font-display: swap;
}
@font-face {
  font-family: "Atkinson Hyperlegible Mono";
  src: url("../fonts/AtkinsonHyperlegibleMono-latin.woff2") format("woff2");
  font-weight: 200 800; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Departure Mono";
  src: url("../fonts/DepartureMono-Regular.woff2") format("woff2");
  font-weight: 400; font-style: normal; font-display: swap;
}

/* ------------------------------------------------------------------ tokens */

:root {
  --font-sans: "Atkinson Hyperlegible Next", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "Atkinson Hyperlegible Mono", ui-monospace, "JetBrains Mono", "Cascadia Mono", "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --font-sys-mono: ui-monospace, "JetBrains Mono", "Cascadia Mono", "SF Mono", Menlo, Consolas, "DejaVu Sans Mono", "Liberation Mono", monospace;
  --font-pixel: "Departure Mono", "Atkinson Hyperlegible Mono", ui-monospace, Menlo, Consolas, monospace;

  /* brand constants (same in both themes) */
  --mint: #5ee6c8;
  --mint-ink: #06231d;
  --coral: #ff6b5e;
  --amber: #ffb84d;
  --blue: #5c9dff;
  --screen: #080818;          /* backdrop for pixel art: always dark, like a display */
  --screen-line: #232842;
  --screen-text: #d6daea;
  --screen-dim: #8b93b4;

  --radius: 2px;
  --header-h: 56px;
  --wrap: 1200px;

  /* dark theme (default): grounded editor charcoal, crisp rules, zero blur */
  color-scheme: dark;
  --bg: #0f1117;
  --bg-2: #151821;
  --bg-3: #1c202c;
  --line: #262b3b;
  --line-2: #363d54;
  --text: #e6e8f0;
  --text-2: #a8afc4;
  --text-3: #7c849e;
  --accent-text: #5ee6c8;     /* links and small accents on --bg */
  --coral-text: #ff8b80;
  --amber-text: #ffc266;
  --blue-text: #8ab8ff;
  --focus: #5ee6c8;
  --shadow: 3px 3px 0 rgba(0, 0, 0, .55);
  --code-bg: #12151e;
  --syn-kw: #ff9488;
  --syn-str: #ffc978;
  --syn-num: #8ab8ff;
  --syn-com: #8089ab;
  --syn-fn: #5ee6c8;
  --syn-const: #c7adff;
  --syn-punct: #aab1cc;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f3efe4;
  --bg-2: #faf7ee;
  --bg-3: #e9e3d3;
  --line: #d4ccb8;
  --line-2: #b5ac96;
  --text: #181b24;
  --text-2: #434859;
  --text-3: #5f6578;
  --accent-text: #0a6654;
  --coral-text: #b32a20;
  --amber-text: #855400;
  --blue-text: #1d57c2;
  --focus: #0a6654;
  --shadow: 3px 3px 0 #cfc7b4;
  --code-bg: #faf7ee;
  --syn-kw: #b32a20;
  --syn-str: #855400;
  --syn-num: #1d57c2;
  --syn-com: #666d87;
  --syn-fn: #0a6654;
  --syn-const: #6a3fc0;
  --syn-punct: #434960;
}

@media (prefers-color-scheme: light) {
  /* no-JS fallback: theme.js normally sets data-theme before first paint */
  :root:not([data-theme]) {
    color-scheme: light;
    --bg: #f3efe4; --bg-2: #faf7ee; --bg-3: #e9e3d3; --line: #d4ccb8; --line-2: #b5ac96;
    --text: #181b24; --text-2: #434859; --text-3: #5f6578;
    --accent-text: #0a6654; --coral-text: #b32a20; --amber-text: #855400; --blue-text: #1d57c2;
    --focus: #0a6654; --shadow: 3px 3px 0 #cfc7b4;
    --code-bg: #faf7ee; --syn-kw: #b32a20; --syn-str: #855400; --syn-num: #1d57c2; --syn-com: #666d87;
    --syn-fn: #0a6654; --syn-const: #6a3fc0; --syn-punct: #434960;
  }
}

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

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-padding-top: calc(var(--header-h) + 16px);
  scroll-behavior: smooth;
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 1.0625rem/1.6 var(--font-sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

[hidden] { display: none !important; }
img, svg, canvas { max-width: 100%; }
img { height: auto; }

h1, h2, h3, h4 { line-height: 1.2; margin: 0; font-weight: 700; text-wrap: balance; }
p { margin: 0 0 1em; text-wrap: pretty; }

a { color: var(--accent-text); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }

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

code, kbd, pre, samp { font-family: var(--font-mono); font-size: .92em; }
:not(pre) > code {
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: .08em .36em;
  font-size: .88em;
  overflow-wrap: anywhere;
}
kbd {
  display: inline-block;
  font-size: .8em;
  line-height: 1.3;
  padding: .12em .5em;
  border: 1px solid var(--line-2);
  border-bottom-width: 3px;
  border-radius: 4px;
  background: var(--bg-2);
  color: var(--text);
}

.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: 12px; top: -64px; z-index: 100;
  background: var(--mint); color: var(--mint-ink); padding: 10px 14px; border-radius: 4px;
  font-weight: 700; text-decoration: none;
}
.skip-link:focus { top: 8px; }

.wrap { width: 100%; max-width: var(--wrap); margin-inline: auto; padding-inline: 24px; }
@media (max-width: 480px) { .wrap { padding-inline: 16px; } }

/* pixel type: Departure Mono is drawn on an 11px grid, so sizes are multiples of 11 */
.px { font-family: var(--font-pixel); font-weight: 400; font-size: 11px; line-height: 1.45; letter-spacing: .04em; text-transform: uppercase; }

/* pixel art is always shown nearest-neighbor, at integer scale */
.pixel, .pixel img, canvas.pixel, .spr {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  image-rendering: pixelated;
}
img.pixel, canvas.pixel {
  width: calc(var(--w) * var(--s, 2) * 1px);
  height: calc(var(--h) * var(--s, 2) * 1px);
  max-width: none;
  display: block;
}
.spr {
  display: inline-block;
  flex: none;
  width: calc(var(--w) * var(--s, 2) * 1px);
  height: calc(var(--h) * var(--s, 2) * 1px);
  background-repeat: no-repeat;
  background-size: calc(var(--sw) * var(--s, 2) * 1px) calc(var(--sh) * var(--s, 2) * 1px);
  background-position: calc(var(--x) * var(--s, 2) * -1px) calc(var(--y) * var(--s, 2) * -1px);
}

/* ------------------------------------------------------------------ header */

.site-header {
  position: sticky; top: 0; z-index: 50;
  height: var(--header-h);
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.site-header .wrap { height: 100%; display: flex; align-items: center; gap: 16px; }
.site-header.wide .wrap { max-width: none; }

.brand { display: inline-flex; align-items: center; color: var(--text); text-decoration: none; flex: none; border-radius: 2px; }
.brand-ver { color: var(--text-3); text-decoration: none; padding-left: 12px; border-left: 1px solid var(--line); }
.brand-ver:hover { color: var(--accent-text); }
.brand svg { display: block; height: 32px; width: 130px; overflow: visible; }   /* 65x16 at exactly 2x */
.brand .k-body { fill: var(--k-body, #5ee6c8); }
.brand .k-shadow { fill: var(--k-shadow, #0f5a4c); }
.brand .k-light { fill: var(--k-light, #f0fffa); }
.brand .k-ink { fill: var(--k-ink, #06231d); }
.brand-sub { margin-left: 10px; padding-left: 10px; border-left: 1px solid var(--line-2); color: var(--text-2); }

.nav { display: flex; align-items: center; gap: 4px; margin-left: auto; min-width: 0; }
.nav a {
  color: var(--text-2); text-decoration: none; font-size: .95rem; font-weight: 500;
  padding: 6px 10px; border-radius: 4px; white-space: nowrap;
}
.nav a:hover, .nav a[aria-current="page"] { color: var(--text); background: var(--bg-3); }
.nav a.ext::after { content: "\2197"; font-family: var(--font-sys-mono); font-size: .8em; margin-left: 4px; color: var(--text-3); }

.icon-btn {
  appearance: none; flex: none;
  display: inline-grid; place-items: center;
  width: 36px; height: 36px;
  border: 1px solid var(--line-2); border-radius: 4px;
  background: var(--bg-2); color: var(--text);
  cursor: pointer;
}
.icon-btn:hover { border-color: var(--text-3); }
.icon-btn svg { width: 16px; height: 16px; display: block; }
.theme-toggle .sun { display: none; }
:root[data-theme="light"] .theme-toggle .sun { display: block; }
:root[data-theme="light"] .theme-toggle .moon { display: none; }

/* ------------------------------------------------------------------ buttons, chips */

.btn {
  appearance: none; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 8px 18px;
  font: 700 1rem/1.2 var(--font-sans); text-decoration: none; white-space: nowrap;
  color: var(--text);
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  border-radius: 4px;
  box-shadow: 0 3px 0 var(--line-2);
  transition: transform .06s steps(2), box-shadow .06s steps(2);
}
.btn:hover { border-color: var(--text-3); }
.btn:active { transform: translateY(3px); box-shadow: 0 0 0 var(--line-2); }
.btn.primary { background: var(--mint); color: var(--mint-ink); border-color: #000; box-shadow: 0 3px 0 #0f5a4c; }
.btn.primary:hover { background: #7ff0d6; border-color: #000; }
.btn.primary:active { box-shadow: 0 0 0 #0f5a4c; }
.btn.small { min-height: 34px; padding: 4px 12px; font-size: .9rem; box-shadow: 0 2px 0 var(--line-2); }
.btn.small:active { transform: translateY(2px); }
.btn[aria-pressed="true"] { background: var(--mint); color: var(--mint-ink); border-color: #000; box-shadow: 0 2px 0 #0f5a4c; }

.chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 4px 10px;
  border: 1px solid var(--line-2); border-radius: 999px;
  background: var(--bg-2); color: var(--text-2);
  text-decoration: none;
}
.chip b { color: var(--accent-text); font-weight: 400; }
a.chip:hover { border-color: var(--text-3); color: var(--text); }

.tag { display: inline-block; padding: 1px 7px; border-radius: 3px; border: 1px solid var(--line-2); color: var(--text-2); vertical-align: middle; }
.tag.stable { color: var(--accent-text); border-color: color-mix(in srgb, var(--accent-text) 45%, transparent); }
.tag.experimental { color: var(--amber-text); border-color: color-mix(in srgb, var(--amber-text) 50%, transparent); }
.tag.pass { color: var(--mint-ink); background: var(--mint); border-color: #000; }
.tag.fail { color: #2b0503; background: var(--coral); border-color: #000; }

/* ------------------------------------------------------------------ screens (pixel-art backdrops) */

.screen {
  position: relative;
  background: var(--screen);
  color: var(--screen-text);
  border: 1px solid var(--screen-line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
:root[data-theme="light"] .screen { border-color: #0d0f18; }
.screen.checker {
  background-color: #0b0c1c;
  background-image:
    linear-gradient(45deg, #11132a 25%, transparent 25%, transparent 75%, #11132a 75%),
    linear-gradient(45deg, #11132a 25%, transparent 25%, transparent 75%, #11132a 75%);
  background-size: 16px 16px;
  background-position: 0 0, 8px 8px;
}
/* the CRT gag: scanlines over every screen, off by default */
.crt .screen::after {
  content: ""; position: absolute; inset: 0; pointer-events: none; z-index: 5;
  background: repeating-linear-gradient(to bottom, rgba(0, 0, 0, 0) 0 2px, rgba(0, 0, 0, .28) 2px 4px);
  box-shadow: inset 0 0 60px rgba(0, 0, 0, .55);
}

/* ------------------------------------------------------------------ code and terminals */

.code, .term {
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--code-bg);
  margin: 0 0 1.25em;
  min-width: 0;
}
.code pre, .term pre {
  margin: 0; padding: 14px 16px;
  overflow-x: auto;
  font: 400 .875rem/1.6 var(--font-mono);
  tab-size: 2;
  color: var(--text);
}
.code.sys pre, .term.sys pre { font-family: var(--font-sys-mono); font-size: .82rem; }
.code-head, .term-head {
  display: flex; align-items: center; gap: 10px;
  min-height: 34px; padding: 0 8px 0 12px;
  border-bottom: 1px solid var(--line);
  color: var(--text-3);
}
.code-head .lang, .term-head .title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.copy-btn {
  appearance: none; cursor: pointer; flex: none;
  font: 400 11px/1 var(--font-pixel); letter-spacing: .04em; text-transform: uppercase;
  color: var(--text-2); background: transparent;
  border: 1px solid var(--line-2); border-radius: 3px;
  padding: 5px 8px; min-height: 24px;
}
.copy-btn:hover { color: var(--text); border-color: var(--text-3); }
.copy-btn.done { color: var(--mint-ink); background: var(--mint); border-color: #000; }

/* a terminal is always dark, in both themes */
.term {
  --text: #d6daea; --text-2: #aab1cc; --text-3: #8089ab; --line: #232842; --line-2: #323a5c;
  --syn-kw: #ff9488; --syn-str: #ffc978; --syn-num: #8ab8ff; --syn-com: #8089ab; --syn-fn: #5ee6c8;
  --syn-const: #c7adff; --syn-punct: #aab1cc;
  background: #0a0b14;
  border-color: #232842;
  color: #d6daea;
}
:root[data-theme="light"] .term { border-color: #0d0f18; }
.term-head .dots { display: none; }
.term .ps { color: var(--mint); user-select: none; -webkit-user-select: none; }
.term .cmd { color: #f4f6ff; font-weight: 600; }
.term .out { color: #aab1cc; }
.term .exit { margin-left: auto; flex: none; }
.term .exit.ok { color: var(--mint); }
.term .exit.check { color: var(--amber); }
.term .exit.bad { color: var(--coral); }

.tok-kw { color: var(--syn-kw); }
.tok-str { color: var(--syn-str); }
.tok-num { color: var(--syn-num); }
.tok-com { color: var(--syn-com); font-style: italic; }
.tok-fn { color: var(--syn-fn); }
.tok-key { color: var(--syn-fn); }
.tok-const { color: var(--syn-const); }
.tok-punct { color: var(--syn-punct); }
.tok-ell { color: var(--syn-com); }

/* ------------------------------------------------------------------ footer */

.site-footer { border-top: 1px solid var(--line); margin-top: 72px; padding: 36px 0 48px; color: var(--text-2); font-size: .95rem; }
.site-footer a { color: var(--text-2); }
.site-footer a:hover { color: var(--text); }
.footer-grid { display: grid; grid-template-columns: minmax(0, 1.4fr) repeat(3, minmax(0, 1fr)); gap: 32px; }
.footer-grid h2 { font: 400 11px/1.45 var(--font-pixel); letter-spacing: .04em; text-transform: uppercase; color: var(--text-3); margin-bottom: 10px; }
.footer-grid ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.footer-brand { display: flex; gap: 14px; align-items: flex-start; }
.footer-brand img { width: 48px; height: 48px; flex: none; }
.footer-fine { margin-top: 32px; padding-top: 20px; border-top: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: 12px 24px; align-items: center; color: var(--text-3); font-size: .875rem; }
.footer-fine .spacer { flex: 1; }
.switch { appearance: none; cursor: pointer; background: transparent; color: var(--text-2); border: 1px solid var(--line-2); border-radius: 3px; padding: 5px 9px; min-height: 28px; }
.switch:hover { color: var(--text); border-color: var(--text-3); }
.switch b { font-weight: 400; color: var(--accent-text); }
@media (max-width: 760px) {
  .footer-grid { grid-template-columns: 1fr 1fr; }
  .footer-brand { grid-column: 1 / -1; }
}
