/* Surform docs — hand-rolled, no framework. Dark-first, one accent. */

:root, [data-theme="dark"] {
  --bg: #0d1117;
  --bg2: #151b23;
  --bg3: #1b232e;
  --fg: #d6dee8;
  --muted: #94a3b3;
  --border: #252d38;
  --code-bg: #0f141b;
  --accent: #ff2e88;
  --accent-soft: rgba(255, 46, 136, 0.12);
  --ok: #3ddc97;
  --ok-soft: rgba(61, 220, 151, 0.1);
  --warn-soft: rgba(255, 170, 60, 0.1);
  --ink-string: #7ec699;
  --ink-number: #e0a458;
  --ink-variable: #6fb7ff;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}
[data-theme="light"] {
  --bg: #ffffff;
  --bg2: #f6f8fa;
  --bg3: #eef1f5;
  --fg: #1f2733;
  --muted: #5c6b7c;
  --border: #dfe5ec;
  --code-bg: #f6f8fa;
  --accent: #d60f6e;
  --accent-soft: rgba(214, 15, 110, 0.08);
  --ok: #0e9f6e;
  --ok-soft: rgba(14, 159, 110, 0.09);
  --warn-soft: rgba(180, 110, 0, 0.08);
  --ink-string: #1a7f4b;
  --ink-number: #a05e00;
  --ink-variable: #0b62c4;
  --shadow: 0 8px 30px rgba(20, 30, 45, 0.12);
  color-scheme: light;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.68 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  text-rendering: optimizeLegibility;
}

/* ---------- top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 16px;
  height: 56px;
  padding: 0 20px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  text-decoration: none;
  color: var(--fg);
  white-space: nowrap;
}
.brand-mark {
  font-weight: 800;
  font-size: 20px;
  letter-spacing: -0.5px;
  color: var(--accent);
}
.brand-tag {
  font-size: 12.5px;
  color: var(--muted);
}
@media (max-width: 640px) { .brand-tag { display: none; } }

.search { position: relative; flex: 1; max-width: 460px; margin-left: auto; }
.search input {
  width: 100%;
  height: 36px;
  padding: 0 14px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--bg2);
  color: var(--fg);
  font: inherit;
  font-size: 14px;
}
.search input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.search-results {
  position: absolute;
  top: 42px;
  left: 0;
  right: 0;
  max-height: 60vh;
  overflow-y: auto;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 6px;
}
.search-results a {
  display: block;
  padding: 8px 10px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--fg);
}
.search-results a:hover, .search-results a.sel { background: var(--accent-soft); }
.search-results .r-title { font-weight: 600; font-size: 14px; }
.search-results .r-body {
  font-size: 12.5px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.search-empty { padding: 10px; color: var(--muted); font-size: 14px; }

.theme {
  background: none;
  border: 1px solid var(--border);
  border-radius: 9px;
  width: 36px;
  height: 36px;
  color: var(--fg);
  font-size: 15px;
  cursor: pointer;
}
.theme:hover { border-color: var(--accent); }

.navtoggle {
  display: none;
  background: none;
  border: 1px solid var(--border);
  border-radius: 9px;
  width: 36px;
  height: 36px;
  color: var(--fg);
  font-size: 16px;
  cursor: pointer;
}

/* ---------- layout ---------- */

.shell {
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr) 224px;
  gap: 40px;
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 24px;
}
@media (max-width: 1140px) {
  .shell { grid-template-columns: 250px minmax(0, 1fr); }
  .toc { display: none; }
}
@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .navtoggle { display: block; }
  .sidebar {
    position: fixed !important;
    top: 56px;
    bottom: 0;
    left: 0;
    width: 280px;
    background: var(--bg);
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    z-index: 40;
    box-shadow: var(--shadow);
    padding: 20px !important;
  }
  .sidebar.open { transform: translateX(0); }
}

/* ---------- sidebar ---------- */

.sidebar {
  padding: 32px 0 40px;
  border-right: 1px solid var(--border);
  font-size: 14px;
}
.nav-group { margin-bottom: 26px; }
.nav-head {
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 0 0 8px 10px;
}
.sidebar a {
  display: block;
  padding: 5px 10px;
  border-radius: 8px;
  color: var(--fg);
  text-decoration: none;
  line-height: 1.4;
}
.sidebar a:hover { background: var(--bg3); }
.sidebar a.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

/* ---------- article ---------- */

.content { padding: 36px 0 64px; min-width: 0; }
.breadcrumb {
  font-size: 12.5px;
  color: var(--muted);
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.crumb-group { text-transform: uppercase; letter-spacing: 0.07em; font-weight: 700; font-size: 11px; }
.crumb-title { font-weight: 600; }

article { max-width: 780px; }
article h1, article h2, article h3, article h4 { line-height: 1.25; font-weight: 700; }
article h1 { font-size: 34px; letter-spacing: -0.02em; margin: 6px 0 18px; }
/* Pages do not carry their own h1 — the breadcrumb does the naming.
   An injected h1 only exists on welcome. */
article > h1:first-child { margin-top: 0; }
article h2 {
  font-size: 24px;
  margin: 44px 0 14px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  scroll-margin-top: 76px;
}
article h2:first-of-type { border-top: none; padding-top: 0; }
article h3 { font-size: 19px; margin: 32px 0 10px; scroll-margin-top: 76px; }
article h4 { font-size: 16px; margin: 24px 0 8px; }
article p { margin: 12px 0; }
article a { color: var(--accent); text-decoration: none; }
article a:hover { text-decoration: underline; }
article strong { font-weight: 650; }
article code {
  font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.86em;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1.5px 5px;
  white-space: nowrap;
}
article ul, article ol { padding-left: 24px; margin: 12px 0; }
article li { margin: 5px 0; }
ul.sub { margin: 4px 0 2px; }
article hr { border: none; border-top: 1px solid var(--border); margin: 36px 0; }

blockquote {
  margin: 18px 0;
  padding: 12px 18px;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 10px 10px 0;
}
blockquote p { margin: 6px 0; }

.tablewrap { overflow-x: auto; margin: 16px 0; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td {
  text-align: left;
  padding: 8px 12px;
  border: 1px solid var(--border);
  vertical-align: top;
}
th { background: var(--bg3); font-weight: 650; }
td code, th code { white-space: normal; }

/* ---------- code boxes ---------- */

.codebox { position: relative; margin: 14px 0; }
.codebox pre {
  margin: 0;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 15px 17px;
  overflow-x: auto;
}
.codebox code {
  font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13.2px;
  line-height: 1.6;
  background: none;
  border: none;
  padding: 0;
  white-space: pre;
}
.lang-chip {
  position: absolute;
  top: 9px;
  right: 12px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  opacity: 0.75;
  pointer-events: none;
}
.code-note {
  position: absolute;
  top: 9px;
  left: 16px;
  font-size: 10.5px;
  font-weight: 650;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ok);
  opacity: 0.85;
  pointer-events: none;
}
.copy {
  position: absolute;
  top: 7px;
  right: 12px;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 9px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--bg2);
  color: var(--muted);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s ease;
}
.codebox:hover .copy, .copy:focus-visible { opacity: 1; }
.copy:hover { color: var(--fg); border-color: var(--accent); }
.copy.done { color: var(--ok); border-color: var(--ok); opacity: 1; }
/* Lang chip moves out of the copy button's way on hover */
.codebox:hover .lang-chip { visibility: hidden; }

/* token colors */
.tok-k { color: var(--accent); font-weight: 600; }
.tok-s { color: var(--ink-string); }
.tok-c { color: var(--muted); font-style: italic; }
.tok-n { color: var(--ink-number); }
.tok-v { color: var(--ink-variable); }

/* token colors from the OFFICIAL SurrealQL grammar (@surrealdb/lezer,
   via classHighlighter) — the client-side ink on the generated-SurrealQL
   panes. Same palette as the build-time classes above, so the
   hydration repaint reads as the same scheme. The ink-* variables are
   shared with the editors' region ink (main.js), whose marks carry
   inline styles and therefore cannot carry per-theme selectors. */

.tok-string, .tok-literal { color: var(--ink-string); }
.tok-number { color: var(--ink-number); }
.tok-variableName, .tok-propertyName { color: var(--ink-variable); }
.tok-comment { color: var(--muted); font-style: italic; }
.tok-keyword, .tok-typeName, .tok-bool, .tok-atom, .tok-macroName {
  color: var(--accent);
  font-weight: 600;
}

/* ---------- example cards ---------- */

.example {
  margin: 26px 0;
  padding: 18px 18px 6px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 14px;
}
.example .badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 650;
  color: var(--ok);
  background: var(--ok-soft);
  border: 1px solid color-mix(in srgb, var(--ok) 30%, transparent);
  border-radius: 999px;
  padding: 3px 11px;
  margin-bottom: 6px;
}
.ex-block { margin: 4px 0 14px; }
.ex-label {
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 10px 0 6px;
}
.example .codebox { margin: 6px 0; }
.example .codebox pre { background: var(--code-bg); }

/* ---------- toc ---------- */

.toc {
  padding: 40px 0;
  font-size: 13px;
  position: sticky;
  top: 56px;
  align-self: start;
  max-height: calc(100vh - 56px);
  overflow-y: auto;
}
.toc-head {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 8px;
}
.toc a {
  display: block;
  color: var(--muted);
  text-decoration: none;
  padding: 3px 0 3px 12px;
  border-left: 2px solid var(--border);
  line-height: 1.45;
}
.toc a.toc-3 { padding-left: 26px; font-size: 12.5px; }
.toc a:hover { color: var(--fg); border-left-color: var(--accent); }
.toc a.active { color: var(--accent); border-left-color: var(--accent); }

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

.pager {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 56px;
  border-top: 1px solid var(--border);
  padding-top: 20px;
  max-width: 780px;
}
.pager a {
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 10px 16px;
  max-width: 46%;
  color: var(--fg);
}
.pager a:hover { border-color: var(--accent); }
.pager .dir { display: block; font-size: 11.5px; color: var(--muted); }
.pager .next { margin-left: auto; text-align: right; }
.pager .label { font-weight: 650; font-size: 14px; }

.footer {
  border-top: 1px solid var(--border);
  margin-top: 20px;
  padding: 26px 24px 34px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}
.footer a { color: var(--muted); }
.footer .edit { color: var(--accent); text-decoration: none; font-weight: 600; }
.footer .edit:hover { text-decoration: underline; }

/* ---------- the playground (docs/editor + docs/src/playground.rs) ---------- */

:root, [data-theme="dark"] {
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --warn: #e8a13a;
}
[data-theme="light"] {
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --warn: #b45309;
}

.pg-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin: 14px 0 10px;
}
.pg-example {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--muted);
}
.pg-example select {
  background: var(--bg2);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font: inherit;
  font-size: 14px;
}
.pg-compile {
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  border-radius: 8px;
  padding: 6px 12px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.pg-compile kbd {
  font: 12px var(--mono);
  background: var(--bg3);
  border-radius: 4px;
  padding: 1px 5px;
}
.pg-toolbar .badge {
  display: inline-flex;
  align-items: center;
  font-size: 13px;
  font-weight: 650;
  border-radius: 999px;
  padding: 3px 11px;
  border: 1px solid transparent;
}
.pg-toolbar .badge.pg-ok {
  color: var(--ok);
  background: var(--ok-soft);
  border-color: color-mix(in srgb, var(--ok) 30%, transparent);
}
.pg-toolbar .badge.pg-bad {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 30%, transparent);
}
.pg-version { font-size: 12.5px; color: var(--muted); }

.pg-editor {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  height: 400px;
  background: var(--code-bg);
}
.pg-editor .cm-editor { height: 100%; }
.pg-editor .cm-editor.cm-focused { outline: none; }
.pg-diag { text-decoration-line: underline; text-decoration-style: wavy; text-decoration-thickness: 1.5px; text-underline-offset: 3px; }
.pg-diag.pg-error { text-decoration-color: var(--accent); }
.pg-diag.pg-warn { text-decoration-color: var(--warn); }

.pg-diags { margin: 10px 0 4px; display: grid; gap: 8px; }
.pg-diags:empty { display: none; }
.pg-diag-item {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 14px;
  line-height: 1.5;
  cursor: pointer;
  display: grid;
  grid-template-columns: auto auto 1fr;
  gap: 4px 10px;
  align-items: baseline;
}
.pg-diag-item:hover { border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }
.pg-diag-item.pg-diag-item-warning { border-left-color: var(--warn); }
.pg-diag-item.pg-diag-item-warning .pg-diag-code { color: var(--warn); }
.pg-diag-code {
  font: 12px var(--mono);
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
}
.pg-diag-where { font: 12px var(--mono); color: var(--muted); white-space: nowrap; }
.pg-diag-msg { white-space: pre-wrap; overflow-wrap: anywhere; }
.pg-diag-help {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 13px;
  border-top: 1px dashed var(--border);
  padding-top: 6px;
}

.pg-outputs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 14px;
}
.pg-outputs .codebox pre { max-height: 340px; overflow: auto; }
.pg-foot { font-size: 13.5px; color: var(--muted); margin-top: 14px; }

@media (max-width: 900px) {
  .pg-editor { height: 320px; }
  .pg-outputs { grid-template-columns: minmax(0, 1fr); }
}

/* ---------- interactive examples ---------- */
/* Every verified SDL example is a small editor (hydrated lazily from
   the same bundle the playground uses): a toolbar — status badge,
   Reset restores the verified original, Format canonicalizes — and
   the example's output panes recomputed live. Until hydration the
   static server-highlighted panels are the whole story. */
.ex-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 0 4px;
}
.ex-toolbar[hidden] { display: none; }
.ex-status { margin-right: auto; font-size: 12px; }
.ex-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--bg2);
  color: var(--fg);
  font: inherit;
  font-size: 12.5px;
  padding: 3px 12px;
  border-radius: 999px;
  cursor: pointer;
}
.ex-btn:hover { border-color: var(--accent); color: var(--accent); }
.ex-editor {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 11px;
  overflow: hidden;
  min-height: 96px;
}
.ex-editor .cm-editor { max-height: 360px; }
