:root {
  --bg: #ffffff;
  --bg-soft: #fbfbfc;
  --fg: #14161a;
  --fg-mid: #3d434d;
  --fg-dim: #6b7280;
  --border: #e7e9ee;
  --border-strong: #d6d9e0;
  --accent: #3992ff;
  --accent-soft: #e9f2ff;
  --code-bg: #282c34;
  --topbar-h: 3.75rem;
  --sidebar-w: 16rem;
  --toc-w: 14rem;
  --doc-w: 44rem;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: "Inter", ui-sans-serif, system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
::selection { background: var(--accent-soft); }

.skip { position: absolute; left: -999px; }
.skip:focus {
  left: 1rem; top: 1rem; z-index: 60;
  background: var(--fg); color: #fff;
  padding: 0.5rem 1rem; border-radius: 6px;
}

/* ── topbar ── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0 1.4rem;
  background: #ffffffcc;
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand {
  font-family: var(--mono);
  font-weight: 500;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  text-decoration: none;
  color: var(--fg);
}
.search {
  display: flex;
  align-items: center;
  gap: 2.5rem;
  min-width: 15rem;
  padding: 0.4rem 0.7rem;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--fg-dim);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}
.search:hover { border-color: var(--border-strong); }
.search kbd {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--fg-dim);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.05rem 0.35rem;
}

/* ── shell: sidebar + content ── */
.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  align-items: start;
}
.sidebar {
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  padding: 1.6rem 1rem 4rem;
  border-right: 1px solid var(--border);
}
.nav-group { margin-bottom: 1.5rem; }
.nav-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0 0 0.5rem 0.5rem;
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--fg);
}
.nav-group.is-empty .nav-label { color: var(--fg-dim); font-weight: 600; }
.soon {
  font-family: var(--mono);
  font-size: 0.58rem;
  letter-spacing: 0.04em;
  color: var(--fg-dim);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.02rem 0.3rem;
}
.sidebar ul { list-style: none; margin: 0; padding: 0; }
.sidebar li a {
  display: block;
  padding: 0.26rem 0.6rem;
  border-radius: 6px;
  color: var(--fg-mid);
  text-decoration: none;
  font-size: 0.875rem;
}
.sidebar li a:hover { color: var(--fg); background: var(--bg-soft); }
.sidebar li a.active { color: var(--accent); background: var(--accent-soft); font-weight: 500; }

/* ── page: article + toc ── */
#content { min-width: 0; }
.page {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--toc-w);
  gap: 2.5rem;
  max-width: calc(var(--doc-w) + var(--toc-w) + 2.5rem);
  margin: 0 auto;
  padding: 3rem 2.5rem 7rem;
}
.doc { min-width: 0; max-width: var(--doc-w); }
.doc > * { min-width: 0; max-width: 100%; }

.toc {
  position: sticky;
  top: calc(var(--topbar-h) + 2rem);
  align-self: start;
  font-size: 0.82rem;
}
.toc-label {
  margin: 0 0 0.6rem;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--fg-dim);
}
.toc ul { list-style: none; margin: 0; padding: 0; border-left: 1px solid var(--border); }
.toc li a {
  display: block;
  padding: 0.22rem 0 0.22rem 0.9rem;
  margin-left: -1px;
  border-left: 2px solid transparent;
  color: var(--fg-dim);
  text-decoration: none;
}
.toc li a:hover { color: var(--fg); }
.toc .toc-sub a { padding-left: 1.7rem; }

/* ── doc content ── */
.doc h1 { font-size: 2.1rem; font-weight: 700; letter-spacing: -0.025em; line-height: 1.15; margin: 0 0 0.9rem; }
.doc h2 { font-size: 1.3rem; font-weight: 650; letter-spacing: -0.015em; margin: 2.6rem 0 0.9rem; }
.doc h3 { font-size: 1.05rem; font-weight: 600; margin: 1.9rem 0 0.6rem; }
.doc h2, .doc h3 { scroll-margin-top: calc(var(--topbar-h) + 1rem); }
.doc a:not(.demo a) { color: var(--accent); text-decoration: none; }
.doc a:not(.demo a):hover { text-decoration: underline; }
.doc p, .doc li { color: var(--fg-mid); }
.doc strong { color: var(--fg); font-weight: 600; }

.doc :not(pre) > code {
  font-family: var(--mono);
  font-size: 0.82em;
  color: #b3387a;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  padding: 0.08em 0.36em;
  border-radius: 5px;
}
.doc pre.hljs {
  background: var(--code-bg);
  border-radius: 10px;
  padding: 1rem 1.15rem;
  overflow-x: auto;
  font-size: 0.83rem;
  line-height: 1.6;
  margin: 1.2rem 0;
}
.doc pre.hljs code { font-family: var(--mono); background: none; padding: 0; }

.doc blockquote {
  margin: 1.3rem 0;
  padding: 0.75rem 1.05rem;
  background: var(--accent-soft);
  border: 1px solid #cfe2ff;
  border-radius: 8px;
}
.doc blockquote p { margin: 0.2rem 0; color: #1f3a5f; }

/* ── tables ── */
.doc table { width: 100%; border-collapse: collapse; margin: 1.3rem 0; font-size: 0.9rem; }
.doc thead th {
  text-align: left;
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--fg);
  padding: 0 0.9rem 0.5rem;
  border-bottom: 1px solid var(--border-strong);
}
.doc tbody td { padding: 0.55rem 0.9rem; border-bottom: 1px solid var(--border); color: var(--fg-mid); vertical-align: top; }
.doc tbody tr:last-child td { border-bottom: none; }
.doc tbody td:first-child { white-space: nowrap; color: var(--fg); }

/* ── demo: code | rendered ── */
.demo {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  margin: 1.4rem 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.demo.demo-stacked,
.demo.demo-codeonly { grid-template-columns: 1fr; }
.demo-pane { position: relative; min-width: 0; }
.demo:not(.demo-stacked) .demo-pane:first-child { border-right: 1px solid var(--border); }
.demo.demo-stacked .demo-pane:first-child { border-bottom: 1px solid var(--border); }
.demo-tab {
  display: block;
  padding: 0.5rem 0.9rem;
  font-family: var(--mono);
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--fg-dim);
  background: var(--bg-soft);
  border-bottom: 1px solid var(--border);
}
.demo-pane pre.hljs { margin: 0; border-radius: 0; }

/* file tabs — part of the dark code block, like an editor tab strip */
.demo-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  background: var(--code-bg);
  border-bottom: 1px solid #ffffff14;
}
.demo-filetab {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: #8b93a7;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 0.5rem 0.85rem;
  cursor: pointer;
}
.demo-filetab:hover { color: #e6e9f0; }
.demo-filetab.is-active { color: #fff; border-bottom-color: var(--accent); }
.demo-file { display: none; max-width: 100%; overflow-x: auto; }
.demo-file.is-active { display: block; }
.try-it {
  display: inline-block;
  margin: -0.6rem 0 0.4rem;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--accent);
  text-decoration: none;
}
.try-it:hover { text-decoration: underline; }

/* little-browser output pane — the demo page served by the SW on :3399 */
.demo-browser { display: flex; flex-direction: column; background: #fff; min-width: 0; }
.browser-bar {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.45rem 0.7rem;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--border);
}
.browser-dots {
  flex: none;
  width: 0.52rem; height: 0.52rem;
  margin: 0 0.9rem 0 0.15rem;
  border-radius: 50%;
  background: #ec6a5e;
  box-shadow: 0.82rem 0 #f4bf4f, 1.64rem 0 #61c554;
}
.browser-url {
  flex: 1;
  min-width: 0;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--fg-mid);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.18rem 0.55rem;
  outline: none;
}
.browser-url:focus { border-color: var(--accent); color: var(--fg); }
.browser-tag {
  flex: none;
  font-size: 0.58rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 4px;
  padding: 0.1rem 0.35rem;
}
.browser-frame { width: 100%; height: 13rem; border: none; background: #fff; display: block; }
.demo-tall .browser-frame { height: 30rem; }

camelon-demo { display: block; }
.demo-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  min-height: 8rem;
  padding: 1.5rem;
}
.demo-bar {
  display: flex;
  justify-content: flex-end;
  padding: 0.4rem 0.6rem;
  border-top: 1px solid var(--border);
  background: var(--bg-soft);
}
.demo-reset {
  font: inherit;
  font-size: 0.74rem;
  color: var(--fg-dim);
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.18rem 0.55rem;
  cursor: pointer;
}
.demo-reset:hover { color: var(--fg); border-color: var(--border-strong); }
.ex-card { max-width: 26rem; text-align: left; }
.ex-card h3 { margin: 0 0 0.4rem; font-size: 1rem; }
.ex-card p { margin: 0; font-size: 0.9rem; color: var(--fg-mid); }
.ex-counter { display: flex; align-items: center; gap: 1rem; }
.ex-counter button {
  width: 2.2rem; height: 2.2rem;
  font-size: 1.2rem;
  border: 1px solid var(--border-strong);
  background: var(--bg);
  border-radius: 8px;
  cursor: pointer;
}
.ex-counter button:hover { border-color: var(--accent); color: var(--accent); }
.ex-counter output { font-size: 1.5rem; font-weight: 600; font-variant-numeric: tabular-nums; min-width: 2ch; text-align: center; }
.ex-greet { display: flex; flex-direction: column; gap: 0.6rem; align-items: center; text-align: center; }
.ex-greet input {
  padding: 0.5rem 0.7rem;
  font: inherit;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  outline: none;
}
.ex-greet input:focus { border-color: var(--accent); }
.ex-greet p { margin: 0; color: var(--fg); }

/* ── ⌘K palette ── */
.kbar[hidden] { display: none; }
.kbar { position: fixed; inset: 0; z-index: 50; display: flex; justify-content: center; align-items: flex-start; padding-top: 13vh; }
.kbar-backdrop { position: absolute; inset: 0; background: #1116203b; backdrop-filter: blur(2px); }
.kbar-panel {
  position: relative;
  width: min(36rem, 92vw);
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  box-shadow: 0 18px 50px #11162033;
  overflow: hidden;
}
.kbar-input {
  width: 100%;
  padding: 1rem 1.15rem;
  border: none;
  border-bottom: 1px solid var(--border);
  font: inherit;
  font-size: 1rem;
  color: var(--fg);
  outline: none;
}
.kbar-input::placeholder { color: var(--fg-dim); }
.kbar-results { list-style: none; margin: 0; padding: 0.4rem; max-height: 21rem; overflow-y: auto; }
.kbar-item { display: flex; align-items: baseline; gap: 0.7rem; padding: 0.55rem 0.75rem; border-radius: 8px; cursor: pointer; }
.kbar-item.is-active { background: var(--accent-soft); }
.kbar-cat { font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--fg-dim); min-width: 6.5rem; }
.kbar-item.is-active .kbar-cat { color: var(--accent); }
.kbar-title { color: var(--fg); font-size: 0.92rem; }
.kbar-empty { padding: 0.9rem 0.75rem; color: var(--fg-dim); font-size: 0.88rem; }

/* ── responsive ── */
@media (max-width: 64rem) {
  .page { grid-template-columns: minmax(0, 1fr); }
  .toc { display: none; }
}
@media (max-width: 48rem) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; border-right: none; border-bottom: 1px solid var(--border); }
  .page { padding: 2rem 1.25rem 4rem; }
  .demo { grid-template-columns: 1fr; }
  .demo-pane:first-child { border-right: none; border-bottom: 1px solid var(--border); }
}
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
