/* The developer site's one stylesheet (no inline style: the site's CSP).
   System fonts only (font-src 'self', no font host). Prose rules are scoped
   to .prose, the chrome's to its own classes: the API reference page (Scalar)
   lays out its own sidebar and columns, and none of these rules reach into it. */

/* ---------- Tokens ---------- */
:root {
  color-scheme: light dark;
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  --bg: #ffffff;
  --surface: #f6f8fb;
  --surface-2: #eef2f7;
  --fg: #111827;
  --fg-strong: #0b1220;
  --muted: #4b5563;
  --line: #e2e7ef;
  --line-strong: #cbd3df;
  --accent: #4338ca;
  --accent-hover: #3730a3;
  --accent-soft: #eef0ff;
  --accent-line: #c7cbfb;
  --code-bg: #f1f4f9;
  --code-fg: #1f2a44;
  --pre-bg: #0f172a;
  --pre-head: #1a2338;
  --pre-fg: #e2e8f0;
  --pre-muted: #94a3b8;
  --warn-bg: #fff7e6;
  --warn-fg: #7a4100;
  --warn-line: #f5c56b;
  --hero-from: #eef0ff;
  --hero-to: #ffffff;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 1px 3px rgb(16 24 40 / 8%);
  --shadow-hover: 0 4px 12px rgb(16 24 40 / 10%), 0 2px 4px rgb(16 24 40 / 6%);

  --topbar-h: 60px;
  --radius: 10px;
  --measure: 72ch;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0f19;
    --surface: #111726;
    --surface-2: #182033;
    --fg: #e5e9f0;
    --fg-strong: #f8fafc;
    --muted: #a3adbd;
    --line: #232c40;
    --line-strong: #344057;
    --accent: #a5b4fc;
    --accent-hover: #c7d2fe;
    --accent-soft: #1b2142;
    --accent-line: #3b4380;
    --code-bg: #1a2133;
    --code-fg: #dbe3f0;
    --pre-bg: #070b14;
    --pre-head: #101727;
    --pre-fg: #e2e8f0;
    --pre-muted: #94a3b8;
    --warn-bg: #2a1f08;
    --warn-fg: #fcd68a;
    --warn-line: #6b4d12;
    --hero-from: #141a33;
    --hero-to: #0b0f19;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%);
    --shadow-hover: 0 6px 16px rgb(0 0 0 / 45%);
  }
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.65 var(--font-sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
.topbar a, .layout a, .sitefooter a, .mobilenav a, .hero a { color: var(--accent); }
.topbar :focus-visible, .layout :focus-visible, .sitefooter :focus-visible,
.mobilenav :focus-visible, .hero :focus-visible, .skip-link:focus-visible, .notice :focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}
main:focus { outline: none; }

.skip-link {
  position: absolute;
  left: 12px;
  top: -100px;
  z-index: 100;
  padding: 0.5rem 0.9rem;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  text-decoration: none;
}
.skip-link:focus { top: 12px; }
@media (prefers-color-scheme: dark) { .skip-link { color: #0b0f19; } }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(10px);
  backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1440px;
  margin: 0 auto;
  min-height: var(--topbar-h);
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 2rem;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--fg-strong) !important;
  text-decoration: none;
  white-space: nowrap;
}
.brand-mark { color: #4338ca; flex: none; }
.brand-name { font-weight: 700; font-size: 1.05rem; letter-spacing: -0.01em; }
.brand-sub { color: var(--muted); font-size: 0.95rem; }
.mainnav { display: flex; gap: 0.25rem; flex: 1; min-width: 0; }
.mainnav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.925rem;
  font-weight: 500;
  padding: 0.4rem 0.7rem;
  border-radius: 7px;
  white-space: nowrap;
}
.mainnav a:hover { color: var(--fg-strong); background: var(--surface-2); }
.mainnav a[aria-current="page"], .mainnav a.active { color: var(--fg-strong); background: var(--surface-2); }
.env-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.2rem 0.65rem;
  border: 1px solid var(--warn-line);
  border-radius: 999px;
  background: var(--warn-bg);
  color: var(--warn-fg);
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}
.env-badge::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

/* ---------- Mobile menu (no script: details/summary) ---------- */
.mobilenav { display: none; }

/* ---------- Hero (home) ---------- */
.hero {
  background: linear-gradient(180deg, var(--hero-from), var(--hero-to));
  border-bottom: 1px solid var(--line);
}
.hero-inner { max-width: 1200px; margin: 0 auto; padding: 4rem 24px 3.25rem; }
.hero h1 {
  margin: 0.25rem 0 1rem;
  font-size: clamp(2.1rem, 4.5vw, 3.1rem);
  line-height: 1.1;
  letter-spacing: -0.03em;
  color: var(--fg-strong);
}
.hero .tagline { max-width: 62ch; font-size: 1.2rem; line-height: 1.6; color: var(--muted); }
.hero .tagline p { margin: 0; }
.hero .tagline strong { color: var(--fg); }

/* ---------- Page layout ---------- */
.layout {
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 24px;
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr) 220px;
  gap: 3rem;
}
.layout.no-toc { grid-template-columns: 248px minmax(0, 1fr); }
.layout.no-side { max-width: 1200px; grid-template-columns: minmax(0, 1fr) 220px; }
.layout.no-side.no-toc { grid-template-columns: minmax(0, 1fr); }
main { min-width: 0; padding: 2.5rem 0 4rem; }

.sidebar, .toc { font-size: 0.9rem; }
.sidebar nav, .toc nav {
  position: sticky;
  top: calc(var(--topbar-h) + 1px);
  max-height: calc(100vh - var(--topbar-h) - 1px);
  overflow-y: auto;
  padding: 2.25rem 0 2rem;
}
.sidebar { border-right: 1px solid var(--line); margin-right: -1.5rem; padding-right: 1.5rem; }
.nav-heading {
  margin: 1.5rem 0 0.4rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
}
.sidebar .nav-heading:first-child, .toc .nav-heading:first-child, .mobilenav .nav-heading:first-child { margin-top: 0; }
.sidebar ul, .toc ul, .mobilenav ul { list-style: none; margin: 0; padding: 0; }
.sidebar a, .mobilenav nav a {
  display: block;
  padding: 0.32rem 0.75rem;
  margin: 1px 0;
  border-radius: 7px;
  color: var(--fg);
  text-decoration: none;
  line-height: 1.4;
}
.sidebar a:hover, .mobilenav nav a:hover { background: var(--surface-2); color: var(--fg-strong); }
.sidebar a[aria-current="page"], .sidebar a.active,
.mobilenav nav a[aria-current="page"], .mobilenav nav a.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
.toc ul { border-left: 1px solid var(--line); }
.toc a {
  display: block;
  padding: 0.25rem 0 0.25rem 0.9rem;
  margin-left: -1px;
  border-left: 1px solid transparent;
  color: var(--muted);
  text-decoration: none;
  line-height: 1.4;
}
.toc a:hover { color: var(--fg-strong); border-left-color: var(--line-strong); }

/* ---------- Home cards ---------- */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 1rem;
  margin: 0 0 3rem;
}
.card {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 1.15rem 1.25rem 1.25rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  box-shadow: var(--shadow);
  text-decoration: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}
.card:hover { border-color: var(--accent-line); box-shadow: var(--shadow-hover); transform: translateY(-1px); }
.card-title { color: var(--fg-strong); font-weight: 650; font-size: 1.02rem; }
.card-title::after { content: " \2192"; color: var(--accent); transition: margin 0.15s ease; }
.card:hover .card-title::after { margin-left: 0.2rem; }
.card-text { color: var(--muted); font-size: 0.92rem; line-height: 1.5; }
@media (prefers-reduced-motion: reduce) {
  .card, .card-title::after { transition: none; }
  .card:hover { transform: none; }
}

/* ---------- Prose ---------- */
.prose { max-width: var(--measure); }
.page-home .prose { max-width: 80ch; }
.prose > :first-child { margin-top: 0; }
.prose .eyebrow, .hero .eyebrow {
  margin: 0 0 0.5rem;
  font-size: 0.8rem;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
}
.prose h1 {
  margin: 0 0 1.25rem;
  font-size: 2.25rem;
  line-height: 1.2;
  letter-spacing: -0.025em;
  color: var(--fg-strong);
}
.prose h2 {
  margin: 2.75rem 0 0.9rem;
  padding-top: 0.25rem;
  font-size: 1.5rem;
  line-height: 1.3;
  letter-spacing: -0.015em;
  color: var(--fg-strong);
}
.prose h3 { margin: 2rem 0 0.6rem; font-size: 1.15rem; line-height: 1.4; color: var(--fg-strong); }
.prose h4 { margin: 1.5rem 0 0.5rem; font-size: 1rem; color: var(--fg-strong); }
.prose h2, .prose h3, .prose h4 { scroll-margin-top: calc(var(--topbar-h) + 1.25rem); }
.prose p, .prose ul, .prose ol, .prose dl, .prose blockquote, .prose pre, .prose table { margin: 0 0 1.15rem; }
.prose ul, .prose ol { padding-left: 1.4rem; }
.prose li { margin: 0.35rem 0; }
.prose li::marker { color: var(--muted); }
.prose strong { color: var(--fg-strong); font-weight: 650; }
.prose a { text-decoration: underline; text-decoration-color: var(--accent-line); text-underline-offset: 3px; text-decoration-thickness: 1px; }
.prose a:hover { color: var(--accent-hover); text-decoration-color: currentColor; }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 2.5rem 0; }

.prose code {
  font-family: var(--font-mono);
  font-size: 0.86em;
  background: var(--code-bg);
  color: var(--code-fg);
  padding: 0.12em 0.38em;
  border-radius: 5px;
  border: 1px solid var(--line);
  overflow-wrap: break-word;
}
.prose a code { color: inherit; }
.prose h1 code, .prose h2 code { font-size: 0.85em; border: 0; }

/* Code blocks: dark panel in both modes. site.js adds the header (language, copy). */
.prose pre {
  background: var(--pre-bg);
  color: var(--pre-fg);
  padding: 1rem 1.15rem;
  border-radius: var(--radius);
  overflow-x: auto;
  font-size: 0.86rem;
  line-height: 1.6;
  border: 1px solid var(--line);
}
.prose pre code { padding: 0; background: none; border: 0; color: inherit; font-size: inherit; overflow-wrap: normal; }
.codeblock { margin: 0 0 1.15rem; border-radius: var(--radius); border: 1px solid var(--line); overflow: hidden; background: var(--pre-bg); }
.codeblock pre { margin: 0; border: 0; border-radius: 0; }
.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.3rem 0.5rem 0.3rem 1.15rem;
  background: var(--pre-head);
  border-bottom: 1px solid rgb(255 255 255 / 8%);
  color: var(--pre-muted);
  font: 600 0.72rem/1.6 var(--font-sans);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.copy-btn {
  font: 500 0.78rem/1 var(--font-sans);
  letter-spacing: 0;
  text-transform: none;
  color: var(--pre-fg);
  background: transparent;
  border: 1px solid rgb(255 255 255 / 18%);
  border-radius: 6px;
  padding: 0.35rem 0.6rem;
  cursor: pointer;
}
.copy-btn:hover { background: rgb(255 255 255 / 8%); }
.copy-btn:focus-visible { outline: 2px solid #a5b4fc; outline-offset: 2px; }

/* Tables */
.prose table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 0.925rem;
  line-height: 1.5;
}
.prose th, .prose td { padding: 0.6rem 0.85rem; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
.prose tr:last-child td { border-bottom: 0; }
.prose th {
  background: var(--surface);
  color: var(--fg-strong);
  font-weight: 650;
  font-size: 0.85rem;
}
.prose thead th:first-child { border-top-left-radius: var(--radius); }
.prose thead th:last-child { border-top-right-radius: var(--radius); }
.prose tbody tr:hover td { background: color-mix(in srgb, var(--surface) 60%, transparent); }
.prose td code { white-space: nowrap; }

/* Callouts: a blockquote is a note; .notice is the test-environment warning. */
.prose blockquote {
  padding: 0.85rem 1.1rem;
  border: 1px solid var(--accent-line);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  background: var(--accent-soft);
}
.prose blockquote > :last-child { margin-bottom: 0; }
.notice {
  padding: 0.85rem 1.1rem;
  border: 1px solid var(--warn-line);
  border-left: 4px solid #d97706;
  border-radius: 8px;
  background: var(--warn-bg);
  color: var(--warn-fg);
}
.notice a { color: inherit; }
.notice code { font-family: var(--font-mono); font-size: 0.88em; }

/* Definition lists: the home page's key facts. */
.prose dl {
  display: grid;
  grid-template-columns: minmax(9rem, max-content) minmax(0, 1fr);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface);
}
.prose dt, .prose dd { margin: 0; padding: 0.8rem 1.1rem; border-top: 1px solid var(--line); }
.prose dt:first-of-type, .prose dt:first-of-type + dd { border-top: 0; }
.prose dt { font-weight: 650; color: var(--fg-strong); font-size: 0.92rem; }
.prose dd { color: var(--fg); }

/* ---------- Problem pages ---------- */
.page-problem .prose h1 { font-family: var(--font-mono); font-size: 1.9rem; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.page-problem .prose > table:first-of-type {
  background: var(--surface);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.page-problem .prose > table:first-of-type thead { display: none; }
.page-problem .prose > table:first-of-type td:first-child {
  width: 8rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 650;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding-top: 0.8rem;
}
.page-problem .prose > table:first-of-type tr:first-child td code {
  font-size: 0.95em;
  font-weight: 650;
  background: var(--accent-soft);
  border-color: var(--accent-line);
  color: var(--accent);
}
.page-problem .prose > table:first-of-type td code { white-space: normal; overflow-wrap: anywhere; }
.page-problem .prose > table:first-of-type tbody tr:hover td { background: none; }
.page-problems .prose table td:first-child { width: 45%; }

/* ---------- API reference page (Scalar) ---------- */
/* Full width, and the prose rules above stay out of it (they once squeezed its
   content to one letter wide). Scalar's sidebar is sticky from the top. */
main.reference { max-width: none; padding: 0; }
main.reference .notice { max-width: 1392px; margin: 1rem auto; }
@media (max-width: 1439px) { main.reference .notice { margin: 1rem 24px; } }
.page-reference .topbar { position: static; }

/* ---------- Footer ---------- */
.sitefooter { border-top: 1px solid var(--line); background: var(--surface); color: var(--muted); font-size: 0.9rem; }
.footer-inner {
  max-width: 1440px;
  margin: 0 auto;
  padding: 2.5rem 24px 2.75rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1.5rem 3rem;
}
.footer-brand p { margin: 0 0 0.6rem; }
.footer-brand strong { color: var(--fg-strong); }
.footer-env { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; }
.version code, .footer-note code { font-family: var(--font-mono); font-size: 0.85em; }
.sitefooter nav ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 0.4rem 1.5rem; }
.sitefooter nav .nav-heading { margin-top: 0; }
.sitefooter nav a { text-decoration: none; }
.sitefooter nav a:hover { text-decoration: underline; }
.footer-note { grid-column: 1 / -1; margin: 0; padding-top: 1.25rem; border-top: 1px solid var(--line); font-size: 0.85rem; overflow-wrap: anywhere; }

/* ---------- Responsive ---------- */
@media (max-width: 1199px) {
  .layout { grid-template-columns: 232px minmax(0, 1fr); gap: 2.5rem; }
  .layout.no-side { grid-template-columns: minmax(0, 1fr); }
  .toc { display: none; }
}
@media (max-width: 959px) {
  .topbar { position: static; }
  .topbar-inner { flex-wrap: wrap; gap: 0.25rem 1rem; padding: 0.6rem 16px 0; min-height: 0; }
  .brand { flex: 1; min-height: 40px; }
  .brand-sub { display: none; }
  .mainnav {
    order: 3;
    flex: 0 0 100%;
    overflow-x: auto;
    margin: 0 -16px;
    padding: 0.35rem 16px 0.5rem;
    scrollbar-width: none;
    /* A fade at the right edge shows the row scrolls. */
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 40px), transparent);
    mask-image: linear-gradient(to right, #000 calc(100% - 40px), transparent);
  }
  .mainnav a { padding: 0.4rem 0.6rem; font-size: 0.9rem; }
  .mainnav::-webkit-scrollbar { display: none; }
  .layout, .layout.no-toc, .layout.no-side { grid-template-columns: minmax(0, 1fr); gap: 0; padding: 0 16px; }
  .sidebar { display: none; }
  .mobilenav { display: block; border-bottom: 1px solid var(--line); background: var(--surface); }
  .mobilenav summary {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.7rem 16px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.92rem;
    color: var(--fg-strong);
    list-style: none;
  }
  .mobilenav summary::-webkit-details-marker { display: none; }
  .mobilenav summary::before { content: "\2630"; color: var(--muted); }
  .mobilenav[open] summary::before { content: "\2715"; }
  .mobilenav summary:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
  .mobilenav nav { padding: 0.25rem 16px 1rem; font-size: 0.95rem; }
  .mobilenav .nav-heading { margin-top: 1rem; }
  main { padding: 1.75rem 0 3rem; }
  .hero-inner { padding: 2.5rem 16px 2.25rem; }
  .hero .tagline { font-size: 1.08rem; }
  .prose h1 { font-size: 1.85rem; }
  .prose h2 { font-size: 1.3rem; margin-top: 2.25rem; }
  .prose table { display: block; overflow-x: auto; width: auto; max-width: 100%; }
  .prose td code { white-space: normal; overflow-wrap: anywhere; }
  .prose dl { grid-template-columns: minmax(0, 1fr); }
  .prose dd { border-top: 0; padding-top: 0; }
  .page-problem .prose > table:first-of-type td:first-child { width: 5.5rem; }
  .page-problems .prose table td:first-child { width: auto; }
  .cards { grid-template-columns: minmax(0, 1fr); gap: 0.75rem; margin-bottom: 2.25rem; }
  .footer-inner { grid-template-columns: minmax(0, 1fr); padding: 2rem 16px; }
  main.reference .notice { margin: 1rem 16px; }
}
@media print {
  .topbar, .sidebar, .toc, .mobilenav, .copy-btn, .skip-link { display: none !important; }
  .layout { display: block; }
}
