/* theme.css — the shared look of the mp-tikz-wasm pages: design tokens (light
   and dark, following the system unless the reader picks one with the theme
   button, which sets data-theme on <html>), the site bar, and the components
   every page uses: buttons, fields, chips, cards, figure "paper", code blocks,
   status lines and diagnostics. Page-specific layout stays in each page.

   Linked by index.html and tags.html; inlined by the page builders
   (build-pages.mjs, build-guide.mjs, build-standalone.mjs) into the generated
   pages, so a single-file build carries it too. No build step, no framework. */

:root {
  color-scheme: light;
  --bg: #f4f6f8; --bg-2: #eaeef2; --surface: #ffffff; --surface-2: #f8fafb;
  --ink: #18212b; --ink-2: #33404d; --muted: #5d6b7a; --line: #d5dbe2; --line-2: #e6eaef;
  --accent: #1f4e9c; --accent-2: #2f63bf; --accent-ink: #ffffff; --accent-soft: #e5edf9;
  --copper: #b5651d; --copper-soft: #f7ebdf;
  --ok: #2f7d4f; --warn: #a8741a; --bad: #b3372c; --bad-soft: #fbeceb;
  --code: #111820; --code-2: #1a2430; --code-ink: #e9eef3; --code-muted: #8fa0b0;
  --paper: #ffffff; --paper-grid: #eef1f5; --paper-edge: #dfe4ea;
  --shadow: 0 1px 2px rgba(20, 30, 45, .06), 0 4px 16px rgba(20, 30, 45, .06);
  --radius: 10px; --radius-sm: 6px;
  --display: "Fraunces", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --body: "Source Serif 4", Georgia, "Times New Roman", serif;
  --ui: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f141a; --bg-2: #141b23; --surface: #171e26; --surface-2: #1c242e;
    --ink: #e6ebf0; --ink-2: #c5ced8; --muted: #93a1b0; --line: #2a343f; --line-2: #222b35;
    --accent: #86ade9; --accent-2: #a3c1f0; --accent-ink: #0f141a; --accent-soft: #1d2a3b;
    --copper: #e39a5b; --copper-soft: #2c2219;
    --ok: #7fcf9a; --warn: #e2b660; --bad: #f08a7e; --bad-soft: #2e1c1b;
    --code: #0a0e13; --code-2: #111820; --code-ink: #dfe6ee; --code-muted: #8596a8;
    --paper: #f6f7f9; --paper-grid: #e8ecf1; --paper-edge: #3a4550;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f141a; --bg-2: #141b23; --surface: #171e26; --surface-2: #1c242e;
  --ink: #e6ebf0; --ink-2: #c5ced8; --muted: #93a1b0; --line: #2a343f; --line-2: #222b35;
  --accent: #86ade9; --accent-2: #a3c1f0; --accent-ink: #0f141a; --accent-soft: #1d2a3b;
  --copper: #e39a5b; --copper-soft: #2c2219;
  --ok: #7fcf9a; --warn: #e2b660; --bad: #f08a7e; --bad-soft: #2e1c1b;
  --code: #0a0e13; --code-2: #111820; --code-ink: #dfe6ee; --code-muted: #8596a8;
  --paper: #f6f7f9; --paper-grid: #e8ecf1; --paper-edge: #3a4550;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--body); line-height: 1.55; overflow-wrap: break-word; }
a { color: var(--accent); text-underline-offset: 2px; text-decoration-thickness: 1px; }
a:hover { color: var(--accent-2); }
code, kbd, samp { font-family: var(--mono); font-size: .9em; }
:focus-visible { outline: 2px solid var(--copper); outline-offset: 2px; }
[hidden] { display: none !important; }
::selection { background: var(--accent-soft); }

/* ---------------------------------------------------------------- site bar */
.sitebar { display: flex; align-items: center; gap: 6px 18px; flex-wrap: wrap; padding: 10px clamp(16px, 3vw, 32px); border-bottom: 1px solid var(--line); background: var(--surface); font-family: var(--ui); font-size: 14px; position: relative; z-index: 5; }
.sitebar .brand { display: inline-flex; align-items: center; gap: 9px; font: 600 17px/1 var(--display); letter-spacing: -.01em; color: var(--ink); text-decoration: none; white-space: nowrap; }
.sitebar .brand svg { width: 22px; height: 22px; flex: none; }
.sitebar nav { display: flex; gap: 2px; flex-wrap: wrap; margin-right: auto; }
.sitebar nav a { color: var(--muted); text-decoration: none; padding: 5px 10px; border-radius: 999px; white-space: nowrap; }
.sitebar nav a:hover { color: var(--ink); background: var(--bg); }
.sitebar nav a[aria-current="page"] { color: var(--accent); background: var(--accent-soft); font-weight: 500; }
.sitebar .gh { color: var(--muted); text-decoration: none; white-space: nowrap; }
.sitebar .gh:hover { color: var(--ink); }
.theme-toggle { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; padding: 0; flex: none; }
.theme-toggle:hover { border-color: var(--accent); color: var(--accent); }
.theme-toggle svg { width: 16px; height: 16px; }
@media (max-width: 640px) {
  .sitebar { padding: 8px 12px; gap: 6px 10px; }
  .sitebar nav { order: 3; width: 100%; margin: 0 -6px; overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; }
  .sitebar nav::-webkit-scrollbar { display: none; }
  .sitebar .gh { margin-left: auto; }
}

/* ---------------------------------------------------------------- type */
.eyebrow { font: 500 12px/1.3 var(--mono); text-transform: uppercase; letter-spacing: .12em; color: var(--muted); }
.display { font-family: var(--display); font-weight: 600; letter-spacing: -.01em; text-wrap: balance; }
.lede { font-size: clamp(17px, 2.2vw, 20px); line-height: 1.5; color: var(--ink-2); }
.muted { color: var(--muted); }

/* ---------------------------------------------------------------- controls */
.btn, .field select, .field input[type="text"] { font: 500 13px/1.2 var(--ui); color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 7px 12px; }
.btn { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; white-space: nowrap; text-decoration: none; transition: border-color .12s, background .12s, color .12s; }
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent-2); border-color: var(--accent-2); color: var(--accent-ink); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--ink); background: var(--bg); }
.btn:disabled { opacity: .45; cursor: default; }
.btn kbd { font: 11px/1 var(--mono); padding: 2px 5px; border-radius: 4px; background: rgba(255,255,255,.18); border: 1px solid rgba(255,255,255,.3); }
.field { display: inline-flex; align-items: center; gap: 6px; font: 12px/1.2 var(--ui); color: var(--muted); white-space: nowrap; }
.field select { padding: 6px 26px 6px 9px; appearance: none; -webkit-appearance: none; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 13px) 55%, calc(100% - 9px) 55%; background-size: 4px 4px; background-repeat: no-repeat; }
.field select:hover { border-color: var(--accent); }
.check { display: inline-flex; align-items: center; gap: 6px; font: 12px/1.2 var(--ui); color: var(--muted); cursor: pointer; white-space: nowrap; user-select: none; }
.check input { accent-color: var(--accent); width: 15px; height: 15px; margin: 0; }
input[type="range"] { accent-color: var(--accent); }

/* ---------------------------------------------------------------- chips, pills */
.chip { display: inline-flex; align-items: center; gap: 4px; font: 500 11px/1 var(--mono); text-transform: uppercase; letter-spacing: .06em; padding: 4px 7px; border-radius: 999px; background: var(--bg-2); color: var(--muted); white-space: nowrap; }
.chip.mp { background: var(--accent-soft); color: var(--accent); }
.chip.tikz { background: var(--copper-soft); color: var(--copper); }
.chip.lua { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.chip.otf { background: color-mix(in srgb, #8a4fd1 16%, transparent); color: #7b44c4; }
:root[data-theme="dark"] .chip.otf { color: #c3a2f2; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .chip.otf { color: #c3a2f2; } }

/* ---------------------------------------------------------------- cards and figure paper */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; display: flex; flex-direction: column; min-width: 0; }
/* TeX and MetaPost draw in black on nothing: their output always sits on paper, in both themes */
.paper { background-color: var(--paper); background-image: linear-gradient(var(--paper-grid) 1px, transparent 1px), linear-gradient(90deg, var(--paper-grid) 1px, transparent 1px); background-size: 20px 20px; background-position: -1px -1px; color: #18212b; }
.paper svg { max-width: 100%; height: auto; }
.paper .placeholder { color: #6b7886; font: 13px var(--ui); }

/* ---------------------------------------------------------------- code */
pre.code, .code-block { margin: 0; background: var(--code); color: var(--code-ink); font: 12.5px/1.55 var(--mono); padding: 14px 16px; border-radius: var(--radius-sm); overflow: auto; tab-size: 2; }
pre.code code { font-size: inherit; }
details.source { border-top: 1px solid var(--line); }
details.source > summary { cursor: pointer; padding: 9px 16px; font: 500 12.5px var(--mono); color: var(--muted); list-style: none; display: flex; align-items: center; gap: 8px; }
details.source > summary::-webkit-details-marker { display: none; }
details.source > summary::before { content: ""; width: 6px; height: 6px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(-45deg); transition: transform .15s; }
details.source[open] > summary::before { transform: rotate(45deg); }
details.source > summary:hover { color: var(--ink); }
details.source pre { margin: 0; border-radius: 0; max-height: 360px; }

/* ---------------------------------------------------------------- status and diagnostics */
.status-line { display: inline-flex; align-items: center; gap: 8px; font: 12.5px/1.4 var(--mono); color: var(--muted); min-width: 0; }
.status-line b { color: var(--ink); font-weight: 500; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--copper); flex: none; }
.dot.ok { background: var(--ok); } .dot.bad { background: var(--bad); }
@media (prefers-reduced-motion: no-preference) { .dot.busy { animation: mptw-pulse 1s ease-in-out infinite; } }
@keyframes mptw-pulse { 50% { opacity: .3; } }
.spinner { display: inline-block; width: 12px; height: 12px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: mptw-spin .8s linear infinite; vertical-align: -2px; flex: none; }
@keyframes mptw-spin { to { transform: rotate(360deg); } }
.diag { border-left: 3px solid var(--bad); padding: 8px 12px; margin: 0 0 10px; background: var(--surface-2); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; font: 14px/1.45 var(--ui); }
.diag.warning { border-color: var(--warn); }
.diag .where { color: var(--muted); font: 12px var(--mono); margin-top: 2px; }
.diag .help { color: var(--muted); font-size: 13px; margin-top: 4px; white-space: pre-wrap; }

/* ---------------------------------------------------------------- figures from the drop-in tags */
.mpw-figure .mpw-status { font: 13px var(--ui); color: #6b7886; }
.mpw-figure .mpw-console { border-radius: var(--radius-sm); }
