:root {
  --bg: #08090b;
  --bg-raised: #0c0e11;
  --surface: #111419;
  --surface-2: #151a20;
  --surface-3: #1a2027;
  --text: #f4f7f8;
  --muted: #a8b0b8;
  --dim: #727d87;
  --line: #252c34;
  --line-strong: #38424c;
  --hover: rgba(255, 255, 255, 0.05);
  --code-bg: #0a0c0f;
  --accent: #c4b5fd;
  --accent-dim: rgba(196, 181, 253, 0.14);
  --accent-2: #a7f3d0;
  --accent-3: #fde68a;
  --danger: #fb7185;
  --glass-bg: rgba(255, 255, 255, 0.06);
  --glass-bg-hover: rgba(255, 255, 255, 0.11);
  --glass-line: rgba(255, 255, 255, 0.16);
  --glass-line-hover: rgba(255, 255, 255, 0.28);
  --glass-shine: rgba(255, 255, 255, 0.14);
  --font: "Inter", system-ui, sans-serif;
  --display: "Instrument Sans", var(--font);
  --mono: "JetBrains Mono", ui-monospace, monospace;
  --topbar-h: 58px;
  --sidebar-w: 268px;
}

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

html {
  -webkit-font-smoothing: antialiased;
  background: var(--bg);
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--topbar-h) + 24px);
}

body {
  min-height: 100vh;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
  font-size: 15.5px;
}

a {
  color: inherit;
  text-decoration: none;
}

img {
  display: block;
  max-width: 100%;
  height: auto;
}

button {
  font: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

svg {
  display: block;
}

::selection {
  color: #061011;
  background: var(--accent);
}

/* ── Top bar ─────────────────────────────────────────── */

.dtop {
  position: fixed;
  inset: 0 0 auto;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--topbar-h);
  padding: 0 20px;
  background: rgba(8, 9, 11, 0.82);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}

.dtop-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 3px;
  color: var(--muted);
}

.dtop-toggle:hover {
  color: var(--text);
  background: var(--hover);
}

.dtop-toggle svg {
  width: 17px;
  height: 17px;
}

.dtop-logo {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-family: var(--display);
  font-weight: 800;
  font-size: 0.98rem;
}

.dtop-logo img {
  width: 28px;
  height: 28px;
  border-radius: 3px;
}

.dtop-logo .crumb {
  color: var(--dim);
  font-weight: 600;
}

.dtop-logo .crumb::before {
  content: "/";
  margin-right: 10px;
  color: var(--line-strong);
}

.dtop-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}

.dtop-link {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  padding: 0 11px;
  border-radius: 3px;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--muted);
}

.dtop-link:hover {
  color: var(--text);
  background: var(--hover);
}

.dtop-link svg {
  width: 15px;
  height: 15px;
}

.dtop-cta {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 12px;
  margin-left: 6px;
  border-radius: 3px;
  font-size: 0.84rem;
  font-weight: 700;
  color: #e4defc;
  border: 1px solid var(--glass-accent-line, rgba(196, 181, 253, 0.32));
  background: rgba(196, 181, 253, 0.1);
  box-shadow: inset 0 1px 0 rgba(230, 222, 255, 0.22);
  transition: background 0.18s ease, border-color 0.18s ease;
}

.dtop-cta:hover {
  background: rgba(196, 181, 253, 0.17);
  border-color: rgba(196, 181, 253, 0.5);
}

/* ── Shell ───────────────────────────────────────────── */

.shell {
  display: flex;
  max-width: 1240px;
  margin: 0 auto;
  padding-top: var(--topbar-h);
}

/* ── Sidebar ─────────────────────────────────────────── */

.sidebar {
  position: sticky;
  top: var(--topbar-h);
  flex: 0 0 var(--sidebar-w);
  align-self: flex-start;
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  padding: 26px 18px 40px 24px;
  border-right: 1px solid var(--line);
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.side-group {
  margin-bottom: 22px;
}

.side-group > span {
  display: block;
  margin-bottom: 7px;
  padding-left: 10px;
  font-family: var(--mono);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--dim);
}

.side-link {
  display: block;
  padding: 5px 10px;
  border-left: 2px solid transparent;
  border-radius: 0;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 500;
  line-height: 1.45;
  transition: color 0.14s ease, background 0.14s ease, border-color 0.14s ease;
}

.side-link:hover {
  color: var(--text);
  background: var(--hover);
}

.side-link.active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: var(--accent-dim);
  font-weight: 600;
}

.side-foot {
  margin-top: 26px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.side-foot a {
  display: block;
  padding: 4px 10px;
  color: var(--dim);
  font-size: 0.8rem;
}

.side-foot a:hover {
  color: var(--text);
}

.side-foot .side-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  margin: 0 10px 10px;
  padding: 0 12px;
  border: 1px solid var(--glass-line);
  border-radius: 3px;
  background: var(--glass-bg);
  box-shadow: inset 0 1px 0 var(--glass-shine);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
  transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease;
}

.side-foot .side-btn:hover {
  color: var(--text);
  background: var(--glass-bg-hover);
  border-color: var(--glass-line-hover);
}

.backdrop {
  display: none;
}

/* ── Content ─────────────────────────────────────────── */

.doc {
  min-width: 0;
  flex: 1;
  max-width: 820px;
  padding: 40px 28px 90px 48px;
}

.doc-eyebrow {
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 12px;
}

.doc h1 {
  font-family: var(--display);
  font-size: 2.6rem;
  line-height: 1.08;
  letter-spacing: -0.01em;
  margin-bottom: 16px;
}

.doc-lead {
  color: var(--muted);
  font-size: 1.06rem;
  line-height: 1.7;
  max-width: 62ch;
}

.doc section {
  margin-top: 58px;
  padding-top: 8px;
}

.doc h2 {
  position: relative;
  font-family: var(--display);
  font-size: 1.72rem;
  line-height: 1.15;
  margin-bottom: 14px;
  padding-top: 26px;
  border-top: 1px solid var(--line);
}

.doc h3 {
  font-family: var(--display);
  font-size: 1.14rem;
  margin: 34px 0 10px;
}

.doc h4 {
  font-size: 0.95rem;
  margin: 24px 0 8px;
}

.h-ico {
  display: inline-block;
  width: 16px;
  height: 16px;
  margin-right: 9px;
  vertical-align: -2px;
  color: var(--accent);
}

.doc h4 .h-ico {
  width: 14px;
  height: 14px;
  margin-right: 8px;
  vertical-align: -2px;
}

.doc h2 .anchor,
.doc h3 .anchor {
  position: absolute;
  margin-left: 8px;
  color: var(--dim);
  font-family: var(--mono);
  font-size: 0.8em;
  font-weight: 500;
  opacity: 0;
  transition: opacity 0.14s ease;
}

.doc h3 .anchor {
  position: static;
}

.doc h2:hover .anchor,
.doc h3:hover .anchor {
  opacity: 1;
}

.doc p {
  color: var(--muted);
  margin-bottom: 14px;
  max-width: 70ch;
}

.doc p strong,
.doc li strong {
  color: var(--text);
  font-weight: 600;
}

.doc ul,
.doc ol {
  color: var(--muted);
  margin: 0 0 16px 22px;
}

.doc li {
  margin-bottom: 6px;
  max-width: 66ch;
}

.doc a:not(.side-link):not(.dtop-link) {
  color: var(--accent);
  border-bottom: 1px solid rgba(196, 181, 253, 0.3);
}

.doc a:not(.side-link):not(.dtop-link):hover {
  border-bottom-color: var(--accent);
}

/* inline code */
.doc code {
  font-family: var(--mono);
  font-size: 0.82em;
  color: var(--text);
  background: var(--surface-3);
  border: 1px solid var(--line);
  border-radius: 2px;
  padding: 1.5px 6px;
  white-space: nowrap;
}

kbd {
  font-family: var(--mono);
  font-size: 0.76em;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-3);
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 3px;
  padding: 2px 7px;
}

/* code blocks */
.codeblock {
  position: relative;
  margin: 14px 0 20px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--code-bg);
  overflow: hidden;
}

.codeblock-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  color: var(--dim);
  font-family: var(--mono);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.codeblock pre {
  padding: 13px 14px;
  overflow-x: auto;
  scrollbar-width: thin;
}

.codeblock pre code {
  display: block;
  background: none;
  border: none;
  padding: 0;
  white-space: pre;
  font-size: 0.8rem;
  line-height: 1.7;
  color: #cfd8e0;
}

.codeblock .cmt {
  color: var(--dim);
}

.codeblock .hl {
  color: var(--accent);
}

.copy-btn {
  flex-shrink: 0;
  min-height: 24px;
  padding: 0 9px;
  border-radius: 3px;
  border: 1px solid var(--glass-line);
  background: var(--glass-bg);
  color: var(--muted);
  font-family: var(--font);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: none;
  transition: background 0.16s ease, color 0.16s ease;
}

.copy-btn:hover {
  color: var(--text);
  background: var(--glass-bg-hover);
}

.copy-btn.done {
  color: var(--accent-2);
  border-color: rgba(167, 243, 208, 0.35);
}

/* tables */
.doc table {
  width: 100%;
  margin: 14px 0 22px;
  border-collapse: separate;
  border-spacing: 0;
  border: 1px solid var(--line);
  border-radius: 3px;
  overflow: hidden;
  font-size: 0.87rem;
}

.doc th {
  text-align: left;
  padding: 9px 13px;
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  font-size: 0.8rem;
  border-bottom: 1px solid var(--line);
}

.doc td {
  padding: 9px 13px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.doc tr:last-child td {
  border-bottom: none;
}

.doc .table-scroll {
  overflow-x: auto;
}

/* callouts */
.note,
.warn {
  display: block;
  margin: 16px 0 20px;
  padding: 13px 16px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 3px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.9rem;
  max-width: none;
}

.warn {
  border-left-color: var(--accent-3);
}

.note strong,
.warn strong {
  color: var(--text);
}

/* step list */
.steps {
  counter-reset: step;
  list-style: none;
  margin: 18px 0 22px;
}

.steps > li {
  position: relative;
  counter-increment: step;
  padding: 0 0 18px 44px;
  margin: 0;
  max-width: none;
}

.steps > li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: -1px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 27px;
  height: 27px;
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  background: var(--surface);
  color: var(--accent);
  font-family: var(--mono);
  font-size: 0.76rem;
  font-weight: 700;
}

.steps > li::after {
  content: "";
  position: absolute;
  left: 13px;
  top: 30px;
  bottom: 2px;
  width: 1px;
  background: var(--line);
}

.steps > li:last-child::after {
  display: none;
}

.steps > li > strong {
  display: block;
  color: var(--text);
  margin-bottom: 3px;
}

.steps p {
  margin-bottom: 6px;
}

/* component cards */
.card-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: 20px 0 8px;
}

.card {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--surface);
}

.card .tagline {
  display: block;
  font-family: var(--mono);
  font-size: 0.64rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--dim);
  margin-bottom: 7px;
}

.card strong {
  display: block;
  color: var(--text);
  font-size: 0.94rem;
  margin-bottom: 5px;
}

.card p {
  font-size: 0.84rem;
  margin: 0;
}

/* version chips */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 18px 0 6px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 30px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--surface);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.74rem;
  font-weight: 600;
}

.chip b {
  color: var(--text);
  font-weight: 700;
}

/* diagrams */
.diagram {
  margin: 20px 0 24px;
  padding: 22px 18px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--bg-raised);
  overflow-x: auto;
}

.diagram svg {
  min-width: 560px;
  width: 100%;
  height: auto;
}

.diagram-caption {
  margin-top: 12px;
  color: var(--dim);
  font-size: 0.8rem;
  text-align: center;
}

/* footer */
.doc-foot {
  margin-top: 70px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  gap: 8px 22px;
  color: var(--dim);
  font-size: 0.84rem;
}

.doc-foot a {
  color: var(--muted) !important;
  border-bottom: none !important;
}

.doc-foot a:hover {
  color: var(--text) !important;
}

/* ── Responsive ──────────────────────────────────────── */

@media (max-width: 980px) {
  .dtop-toggle {
    display: inline-flex;
  }

  .sidebar {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    bottom: 0;
    z-index: 55;
    width: min(300px, 84vw);
    height: auto;
    background: var(--bg-raised);
    border-right: 1px solid var(--line-strong);
    transform: translateX(-102%);
    transition: transform 0.22s ease;
  }

  body.nav-open .sidebar {
    transform: translateX(0);
  }

  .backdrop {
    position: fixed;
    inset: var(--topbar-h) 0 0;
    z-index: 54;
    background: rgba(0, 0, 0, 0.55);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease;
  }

  body.nav-open .backdrop {
    display: block;
    opacity: 1;
    pointer-events: auto;
  }

  .doc {
    padding: 30px 20px 70px;
  }

  .card-row {
    grid-template-columns: minmax(0, 1fr);
  }

  .doc h1 {
    font-size: 2.1rem;
  }

  .dtop-link span {
    display: none;
  }

  .dtop-link {
    padding: 0 9px;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  .sidebar,
  .backdrop {
    transition: none;
  }
}
