/* ApeMind Docs — shared design baseline.
   Tokens follow the product (web/src/app/globals.css, web/DESIGN.md): GitHub Primer neutrals
   and one brand orange. Pages and diagrams are built from ink, greys and orange only;
   distinguish things by weight, outline and texture before reaching for another hue.
   Red is reserved for genuine failure or risk. One font family everywhere. */

:root {
  --bg: #ffffff;
  --canvas: #f6f8fa;
  --surface: #ffffff;
  --hover: #eff2f5;
  --ink: #1f2328;
  --text: #1f2328;
  --muted: #59636e;
  --faint: #818b98;
  --line: #d1d9e0;
  --line-soft: #e5e9ed;

  --brand: #b4532f;
  --brand-emphasis: #c96442;
  --brand-soft: #fbede4;
  --brand-muted: #f1c7b4;
  --brand-deep: #7a3320;
  --danger: #d1242f;
  --danger-muted: #ffcecb;

  --code-bg: #f6f8fa;
  --shadow: 0 1px 0 rgb(31 35 40 / 0.04), 0 8px 24px -12px rgb(31 35 40 / 0.18);

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial,
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif,
    "Apple Color Emoji", "Segoe UI Emoji";
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  --radius: 8px;
  --top-h: 64px;
  --side-w: 288px;
  --toc-w: 232px;
  --measure: 780px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0d1117;
  --canvas: #151b23;
  --surface: #151b23;
  --hover: #212830;
  --ink: #f0f6fc;
  --text: #e6edf3;
  --muted: #9198a1;
  --faint: #6e7681;
  --line: #3d444d;
  --line-soft: #2a313a;

  --brand: #e5916f;
  --brand-emphasis: #d97757;
  --brand-soft: rgb(217 119 87 / 0.15);
  --brand-muted: rgb(217 119 87 / 0.4);
  --brand-deep: #fbede4;
  --danger: #f85149;
  --danger-muted: rgb(248 81 73 / 0.4);

  --code-bg: #151b23;
  --shadow: 0 0 0 1px #3d444d, 0 8px 24px -12px rgb(0 0 0 / 0.6);
  color-scheme: dark;
}

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-padding-top: calc(var(--top-h) + 24px);
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.75 var(--font-sans);
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
}

button {
  font: inherit;
  color: inherit;
}

::selection {
  background: var(--brand-soft);
  color: var(--ink);
}

:focus-visible {
  outline: 2px solid var(--brand-emphasis);
  outline-offset: 2px;
  border-radius: 4px;
}

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

.dx-top {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--top-h);
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 24px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: saturate(1.6) blur(16px);
  -webkit-backdrop-filter: saturate(1.6) blur(16px);
  border-bottom: 1px solid var(--line);
}

.dx-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-weight: 600;
  font-size: 16px;
  white-space: nowrap;
}

.dx-brand a {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: inherit;
  text-decoration: none;
}

.dx-brand img {
  width: 26px;
  height: 26px;
}

:root[data-theme="dark"] .dx-brand img {
  filter: invert(1);
}

.dx-brand .slash {
  color: var(--line);
  font-weight: 300;
  font-size: 20px;
}

.dx-brand small {
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
}

.dx-sections {
  display: flex;
  align-self: stretch;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}

.dx-sections a {
  position: relative;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 10px;
  font-size: 14px;
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
  transition: color 0.15s;
}

.dx-sections a::after {
  content: "";
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 14px;
  height: 1px;
  background: var(--brand-emphasis);
  transform: scaleX(0);
  transition: transform 220ms;
}

.dx-sections a:hover {
  color: var(--ink);
}

.dx-sections a:hover::after {
  transform: scaleX(1);
}

.dx-sections a[aria-current="true"] {
  color: var(--ink);
  font-weight: 600;
}

.dx-sections a[aria-current="true"]::after {
  bottom: -1px;
  height: 2px;
  border-radius: 2px;
  transform: scaleX(1);
}

.dx-top-tools {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.dx-search-box {
  position: relative;
  display: flex;
  align-items: center;
  width: 260px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--canvas);
  color: var(--muted);
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s, width 0.2s;
}

.dx-search-box:focus-within {
  width: 320px;
  border-color: var(--brand-emphasis);
  background: var(--bg);
  box-shadow: 0 0 0 3px var(--brand-soft);
}

.dx-search-box svg,
.dx-search-hero svg {
  position: absolute;
  left: 10px;
  width: 15px;
  height: 15px;
  pointer-events: none;
}

.dx-search-box input,
.dx-search-hero input {
  width: 100%;
  height: 100%;
  padding: 0 44px 0 32px;
  border: 0;
  outline: 0;
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  appearance: none;
}

.dx-search-box input::placeholder,
.dx-search-hero input::placeholder {
  color: var(--faint);
}

.dx-search-box input::-webkit-search-cancel-button,
.dx-search-hero input::-webkit-search-cancel-button {
  display: none;
}

kbd {
  font: 11px/1 var(--font-mono);
  color: var(--muted);
  padding: 3px 5px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--bg);
}

.dx-search-box kbd {
  position: absolute;
  right: 6px;
  pointer-events: none;
}

.dx-search-box:focus-within kbd {
  display: none;
}

.dx-search-hero {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
  height: 48px;
  margin-top: 20px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--muted);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.dx-search-hero:focus-within {
  border-color: var(--brand-emphasis);
  box-shadow: 0 0 0 4px var(--brand-soft);
}

.dx-search-hero svg {
  left: 16px;
  width: 18px;
  height: 18px;
}

.dx-search-hero input {
  padding: 0 18px 0 44px;
  font-size: 16px;
}

body[data-layout="home"] .dx-search-box,
body[data-layout="search"] .dx-search-box {
  display: none;
}

.dx-icon-btn {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  color: var(--muted);
  cursor: pointer;
}

.dx-icon-btn:hover {
  background: var(--hover);
  color: var(--ink);
}

.dx-icon-btn svg {
  width: 16px;
  height: 16px;
}

.dx-app-link {
  height: 34px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 14px;
  border-radius: 4px;
  background: var(--ink);
  color: var(--bg);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.15s;
}

.dx-app-link:hover {
  background: color-mix(in srgb, var(--ink) 80%, var(--brand-emphasis));
}

.dx-menu-btn {
  display: none;
}

.dx-shell {
  display: grid;
  grid-template-columns: var(--side-w) minmax(0, 1fr);
}

.dx-side {
  position: sticky;
  top: var(--top-h);
  height: calc(100vh - var(--top-h));
  overflow-y: auto;
  padding: 24px 16px 48px;
  border-right: 1px solid var(--line);
  scrollbar-width: thin;
}

.dx-side-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 8px 20px;
  text-decoration: none;
}

.dx-side-head i {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--ink);
  color: var(--bg);
  font: 600 13px/1 var(--font-mono);
  font-style: normal;
}

.dx-side-head b {
  display: block;
  font-size: 15px;
  color: var(--ink);
  line-height: 1.3;
}

.dx-side-head small {
  display: block;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}

.dx-side-group {
  margin: 0 0 14px;
}

.dx-side-group > button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border: 0;
  border-radius: 6px;
  background: none;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  text-align: left;
}

.dx-side-group > button:hover {
  background: var(--hover);
}

.dx-side-group > button svg {
  width: 12px;
  height: 12px;
  transition: transform 0.2s;
}

.dx-side-group.is-collapsed > button svg {
  transform: rotate(-90deg);
}

.dx-side-group.is-collapsed > ol {
  display: none;
}

.dx-side ol {
  list-style: none;
  margin: 2px 0 0;
  padding: 0;
}

.dx-side li > a,
.dx-side li > span {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px 5px 22px;
  border-radius: 6px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  text-decoration: none;
}

.dx-side li > a:hover {
  background: var(--hover);
}

.dx-side li > a[aria-current="page"] {
  background: var(--hover);
  font-weight: 600;
}

.dx-side li > a[aria-current="page"]::before {
  content: "";
  position: absolute;
  left: 6px;
  top: 7px;
  bottom: 7px;
  width: 3px;
  border-radius: 3px;
  background: var(--brand-emphasis);
}

.dx-side li > span {
  color: var(--faint);
  cursor: default;
}

.dx-side li > span::before {
  content: "";
  position: absolute;
  left: 10px;
  top: 50%;
  width: 5px;
  height: 5px;
  margin-top: -2.5px;
  border-radius: 50%;
  border: 1px solid var(--line);
}

.dx-page {
  display: grid;
  grid-template-columns: minmax(0, var(--measure)) var(--toc-w);
  justify-content: center;
  gap: 64px;
  padding: 40px 48px 120px;
  min-width: 0;
}

.dx-toc {
  position: sticky;
  top: calc(var(--top-h) + 40px);
  align-self: start;
  max-height: calc(100vh - var(--top-h) - 64px);
  overflow-y: auto;
  font-size: 13px;
  transition: opacity 0.25s;
}

.dx-toc.is-hidden {
  opacity: 0;
  pointer-events: none;
}

.dx-toc-title {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
}

.dx-toc ol {
  list-style: none;
  margin: 0;
  padding: 0;
}

.dx-toc a {
  display: block;
  padding: 4px 0 4px 12px;
  border-left: 2px solid transparent;
  line-height: 1.5;
  color: var(--muted);
  text-decoration: none;
  transition: color 0.15s, border-color 0.15s;
}

.dx-toc a.is-h3 {
  padding-left: 24px;
}

.dx-toc a:hover {
  color: var(--ink);
}

.dx-toc a.is-active {
  color: var(--ink);
  font-weight: 500;
  border-left-color: var(--brand-emphasis);
}

/* ───────────── Document ───────────── */

main.doc {
  min-width: 0;
  max-width: var(--measure);
  margin: 0 auto;
}

.dx-page main.doc {
  margin: 0;
}

.dx-crumbs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 16px;
  font-size: 13px;
  color: var(--muted);
}

.dx-crumbs a {
  text-decoration: none;
  color: var(--muted);
}

.dx-crumbs a:hover {
  color: var(--ink);
}

.dx-crumbs .sep {
  color: var(--faint);
}

.doc-head h1 {
  margin: 0;
  font-size: 36px;
  line-height: 1.3;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: -0.01em;
  text-wrap: balance;
}

.doc-head .lede {
  margin: 12px 0 0;
  font-size: 18px;
  line-height: 1.7;
  color: var(--muted);
  text-wrap: pretty;
}

.doc-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 20px 0 0;
  font-size: 12px;
}

.doc-body {
  margin-top: 40px;
  counter-reset: fig h2;
}

.doc-body > :first-child {
  margin-top: 0;
}

.doc-body h2 {
  counter-increment: h2;
  margin: 56px 0 16px;
  font-size: 24px;
  line-height: 1.4;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: -0.01em;
}

.doc-body h2::before {
  content: counter(h2, decimal-leading-zero);
  display: block;
  margin-bottom: 6px;
  font: 500 12px/1 var(--font-mono);
  letter-spacing: 0.08em;
  color: var(--brand-emphasis);
}

.dx-overview-group h2::before {
  display: none;
}

.doc-body h3 {
  margin: 32px 0 8px;
  font-size: 18px;
  line-height: 1.5;
  font-weight: 600;
  color: var(--ink);
}

.doc-body h2,
.doc-body h3 {
  position: relative;
}

.doc-body .dx-anchor {
  margin-left: 8px;
  color: var(--faint);
  text-decoration: none;
  font-weight: 400;
  opacity: 0;
  transition: opacity 0.15s;
}

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

.doc-body p,
.doc-body ul,
.doc-body ol {
  margin: 0 0 16px;
  text-wrap: pretty;
}

.doc-body ul,
.doc-body ol {
  padding-left: 1.6em;
}

.doc-body li {
  margin: 4px 0;
}

.doc-body strong {
  font-weight: 600;
  color: var(--ink);
}

.doc-body a:not([class]) {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-color: var(--brand-muted);
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
  transition: text-decoration-color 0.15s;
}

.doc-body a:not([class]):hover {
  text-decoration-color: var(--brand-emphasis);
}

.doc-body hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 40px 0;
}

code {
  font-family: var(--font-mono);
  font-size: 0.85em;
}

.doc-body :not(pre) > code {
  padding: 0.15em 0.4em;
  border-radius: 6px;
  background: color-mix(in srgb, var(--faint) 16%, transparent);
  color: var(--ink);
}

.doc-body pre {
  position: relative;
  margin: 16px 0 20px;
  padding: 16px;
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--line-soft);
  background: var(--code-bg);
  color: var(--text);
  font-size: 13.5px;
  line-height: 1.6;
}

.dx-copy {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
}

.doc-body pre:hover .dx-copy,
.dx-copy:focus-visible {
  opacity: 1;
}

.doc-body table {
  display: block;
  width: max-content;
  max-width: 100%;
  overflow-x: auto;
  margin: 16px 0 20px;
  border-collapse: collapse;
  font-size: 14px;
  line-height: 1.6;
}

.doc-body th,
.doc-body td {
  padding: 8px 14px;
  border: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.doc-body th {
  font-weight: 600;
  background: var(--canvas);
}

.doc-body tr:nth-child(2n) td {
  background: color-mix(in srgb, var(--canvas) 60%, transparent);
}

/* Expandable blocks */
.doc-body details {
  margin: 0 0 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  overflow: hidden;
}

.doc-body summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  list-style: none;
  cursor: pointer;
  font-weight: 600;
  color: var(--ink);
}

.doc-body summary::-webkit-details-marker {
  display: none;
}

.doc-body summary::before {
  content: "";
  flex: none;
  width: 7px;
  height: 7px;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  transform: rotate(-45deg);
  transition: transform 0.2s;
}

.doc-body details[open] > summary::before {
  transform: rotate(45deg);
}

.doc-body summary:hover {
  background: var(--canvas);
}

.doc-body details > :not(summary) {
  margin: 0;
  padding: 0 16px 14px 33px;
  color: var(--muted);
}

.doc-body details[open] > :not(summary) {
  animation: dx-open 0.25s ease;
}

@keyframes dx-open {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
}

.doc-body details.deep {
  border-style: dashed;
  background: var(--canvas);
}

.doc-body details.deep > summary::after {
  content: "深入";
  margin-left: auto;
  font-size: 11px;
  font-weight: 500;
  padding: 1px 8px;
  border-radius: 999px;
  color: var(--muted);
  border: 1px solid var(--line);
  background: var(--bg);
}

.wide {
  margin-right: calc(-1 * (var(--toc-w) + 64px));
}

/* ───────────── Badges ───────────── */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-size: 12px;
  font-weight: 500;
  line-height: 1;
  color: var(--muted);
  white-space: nowrap;
}

/* Palette discipline: neutrals carry the page, brand orange is the only accent,
   red appears only for genuine failure or risk. */
.badge.brand { color: var(--brand); background: var(--brand-soft); border-color: var(--brand-muted); }
.badge.ink { color: var(--bg); background: var(--ink); border-color: var(--ink); }
.badge.danger { color: var(--danger); border-color: var(--danger-muted); }
.badge.dot::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.badge.live { color: var(--ink); }
.badge.live::before { background: var(--brand-emphasis); }

/* ───────────── Components ───────────── */

doc-callout {
  --c: var(--faint);
  display: block;
  margin: 24px 0;
  padding: 12px 18px 14px;
  border-left: 2px solid var(--c);
  border-radius: 0 8px 8px 0;
  background: var(--canvas);
  font-size: 15px;
}

doc-callout::before {
  display: block;
  margin-bottom: 4px;
  font: 600 11px/1.6 var(--font-mono);
  letter-spacing: 0.1em;
  color: var(--muted);
  content: "说明";
}

doc-callout[type="tip"],
doc-callout[type="important"] { --c: var(--brand-emphasis); }
doc-callout[type="tip"]::before { content: "建议"; color: var(--brand); }
doc-callout[type="important"]::before { content: "重要"; color: var(--brand); }
doc-callout[type="warn"] { --c: var(--ink); }
doc-callout[type="warn"]::before { content: "注意"; color: var(--ink); }
doc-callout[type="caution"] { --c: var(--danger); }
doc-callout[type="caution"]::before { content: "风险"; color: var(--danger); }
doc-callout[label]::before { content: attr(label); }

doc-callout > :last-child {
  margin-bottom: 0;
}

doc-term {
  position: relative;
  border-bottom: 1px dashed var(--brand-emphasis);
  cursor: help;
}

doc-term::after {
  content: attr(tip);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  z-index: 20;
  width: max-content;
  max-width: 300px;
  padding: 8px 12px;
  border-radius: 6px;
  background: var(--ink);
  color: var(--bg);
  font-size: 13px;
  line-height: 1.6;
  font-weight: 400;
  transform: translate(-50%, 4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s, transform 0.15s;
}

doc-term:hover::after,
doc-term:focus::after {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* Steps */
doc-steps {
  display: block;
  margin: 24px 0;
  counter-reset: step;
}

.dx-steps-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--muted);
}

.dx-steps-bar .track {
  flex: 1;
  height: 3px;
  border-radius: 3px;
  background: var(--line-soft);
  overflow: hidden;
}

.dx-steps-bar .fill {
  height: 100%;
  width: 0;
  border-radius: 3px;
  background: var(--brand-emphasis);
  transition: width 0.45s cubic-bezier(0.2, 0.8, 0.2, 1);
}

doc-step {
  display: block;
  position: relative;
  counter-increment: step;
  padding: 0 0 24px 48px;
}

doc-step::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: 0;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--bg);
  font: 600 13px/1 var(--font-mono);
  color: var(--ink);
  z-index: 1;
  transition: all 0.25s;
}

doc-step::after {
  content: "";
  position: absolute;
  left: 15px;
  top: 30px;
  bottom: 0;
  width: 1px;
  background: var(--line);
}

doc-step:last-child::after {
  display: none;
}

doc-step.is-done::before {
  content: "✓";
  border-color: var(--ink);
  background: var(--ink);
  color: var(--bg);
}

doc-step .dx-step-title {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 30px;
  margin-bottom: 4px;
  font-weight: 600;
  color: var(--ink);
}

doc-step .dx-step-check {
  margin-left: auto;
  padding: 2px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}

doc-step .dx-step-check:hover {
  background: var(--hover);
  color: var(--ink);
}

doc-step.is-done .dx-step-check {
  color: var(--ink);
  border-color: var(--line);
  background: var(--canvas);
}

doc-step > :last-child {
  margin-bottom: 0;
}

/* Tabs */
doc-tabs {
  display: block;
  margin: 20px 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.dx-tablist {
  display: flex;
  gap: 2px;
  padding: 0 8px;
  border-bottom: 1px solid var(--line);
  background: var(--canvas);
  overflow-x: auto;
}

.dx-tablist button {
  position: relative;
  padding: 10px 12px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
}

.dx-tablist button:hover {
  color: var(--ink);
}

.dx-tablist button[aria-selected="true"] {
  color: var(--ink);
  font-weight: 600;
}

.dx-tablist button[aria-selected="true"]::after {
  content: "";
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: -1px;
  height: 2px;
  border-radius: 2px;
  background: var(--brand-emphasis);
}

doc-tab {
  display: block;
  padding: 16px 20px;
}

doc-tabs.is-ready doc-tab:not(.is-active) {
  display: none;
}

doc-tabs.is-ready doc-tab.is-active {
  animation: dx-open 0.25s ease;
}

doc-tab > :last-child {
  margin-bottom: 0;
}

doc-tab > pre:only-child {
  margin: -16px -20px;
  border: 0;
  border-radius: 0;
}

/* Figures */
figure.doc-figure {
  margin: 28px 0;
  counter-increment: fig;
}

.doc-figure > .frame {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 12px;
  background:
    radial-gradient(circle at 1px 1px, color-mix(in srgb, var(--faint) 30%, transparent) 1px, transparent 0) 0 0 / 16px 16px,
    var(--canvas);
  padding: 24px;
  overflow: hidden;
}

.doc-figure figcaption {
  margin-top: 10px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--muted);
}

.doc-figure figcaption::before {
  content: "图 " counter(fig) "  ";
  font-weight: 600;
  color: var(--ink);
}

.doc-figure .live {
  position: absolute;
  top: 10px;
  right: 12px;
  z-index: 2;
}

/* Cards */
.doc-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 12px;
  margin: 20px 0;
}

.doc-card {
  --c: var(--brand-emphasis);
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  text-decoration: none;
  color: var(--text);
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.2s;
}

a.doc-card:hover {
  border-color: color-mix(in srgb, var(--c) 50%, var(--line));
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}

.doc-card .row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.doc-card strong {
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
}

.doc-card p {
  margin: 0;
  font-size: 13px;
  line-height: 1.6;
  color: var(--muted);
}

.doc-card .k {
  font: 500 11px/1.6 var(--font-mono);
  letter-spacing: 0.08em;
  color: var(--brand-emphasis);
}

.doc-card .state {
  margin-left: auto;
  font-size: 12px;
  color: var(--faint);
}

.doc-card.is-draft {
  border-style: dashed;
  background: transparent;
}

.doc-card.is-draft .k {
  color: var(--faint);
}

.doc-card.is-draft strong {
  color: var(--muted);
}

/* ── Flow player: click-driven, step-by-step diagram. ── */
doc-flow {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
  gap: 0;
  margin: 28px 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: var(--bg);
}

doc-flow .flow-stage {
  position: relative;
  padding: 24px;
  border-right: 1px solid var(--line);
  background:
    radial-gradient(circle at 1px 1px, color-mix(in srgb, var(--faint) 30%, transparent) 1px, transparent 0) 0 0 / 16px 16px,
    var(--canvas);
}

doc-flow .flow-steps {
  list-style: none;
  margin: 0;
  padding: 8px;
  counter-reset: fstep;
  max-height: 560px;
  overflow-y: auto;
}

doc-flow .flow-steps > li {
  counter-increment: fstep;
  position: relative;
  margin: 0;
  padding: 10px 12px 10px 44px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s;
}

doc-flow .flow-steps > li::before {
  content: counter(fstep);
  position: absolute;
  left: 12px;
  top: 11px;
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid var(--line);
  font: 600 11px/1 var(--font-mono);
  color: var(--muted);
  background: var(--bg);
  transition: all 0.25s;
}

doc-flow .flow-steps > li:hover {
  background: var(--canvas);
}

doc-flow .flow-steps > li > b {
  display: block;
  font-size: 14.5px;
  font-weight: 600;
  color: var(--muted);
  line-height: 1.6;
}

doc-flow .flow-steps > li > :not(b) {
  display: none;
  margin: 4px 0 0;
  font-size: 14px;
  line-height: 1.7;
  color: var(--muted);
}

doc-flow .flow-steps > li.is-past::before {
  content: "✓";
  color: var(--bg);
  border-color: var(--ink);
  background: var(--ink);
}

doc-flow .flow-steps > li.is-active {
  background: var(--canvas);
  box-shadow: inset 0 0 0 1px var(--line);
}

doc-flow .flow-steps > li.is-active::before {
  border-color: var(--brand-emphasis);
  background: var(--brand-emphasis);
  color: #fff;
}

doc-flow .flow-steps > li.is-active > b {
  color: var(--ink);
}

doc-flow .flow-steps > li.is-active > :not(b) {
  display: block;
  animation: dx-open 0.3s ease;
}

.dx-flow-bar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  background: var(--bg);
  font-size: 13px;
  color: var(--muted);
}

.dx-flow-bar button {
  flex: none;
  white-space: nowrap;
  height: 30px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  color: var(--ink);
  font-size: 13px;
  cursor: pointer;
}

.dx-flow-bar button:hover:not(:disabled) {
  background: var(--hover);
}

.dx-flow-bar button:disabled {
  opacity: 0.45;
  cursor: default;
}

.dx-flow-bar button.play {
  background: var(--brand-emphasis);
  border-color: var(--brand-emphasis);
  color: #fff;
}

.dx-flow-bar button.play:hover {
  background: var(--brand);
}

.dx-flow-bar .dots {
  display: flex;
  gap: 4px;
  margin-left: auto;
}

.dx-flow-bar .dots i {
  width: 18px;
  height: 4px;
  border-radius: 4px;
  background: var(--line);
  cursor: pointer;
  transition: background 0.25s, width 0.25s;
}

.dx-flow-bar .dots i.is-past {
  background: var(--muted);
}

.dx-flow-bar .dots i.is-active {
  width: 30px;
  background: var(--brand-emphasis);
}

.dx-flow-bar .count {
  font-family: var(--font-mono);
  min-width: 40px;
  text-align: right;
}

/* Stage nodes react to the active step via data-on="1 2". */
[data-on] {
  transition: opacity 0.4s, transform 0.4s, background-color 0.4s, border-color 0.4s, color 0.4s,
    box-shadow 0.4s;
}

/* ── Hotspots: numbered pins on a picture or mock UI. ── */
doc-hotspots {
  display: block;
  margin: 28px 0;
}

doc-hotspots .hs-canvas {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: var(--bg);
}

.dx-pin {
  position: absolute;
  left: var(--x);
  top: var(--y);
  z-index: 3;
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  margin: -13px 0 0 -13px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--brand-emphasis);
  color: #fff;
  font: 700 12px/1 var(--font-mono);
  box-shadow: 0 2px 8px rgb(0 0 0 / 0.25);
  cursor: pointer;
  transition: transform 0.2s;
}

.dx-pin::after {
  content: "";
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 2px solid var(--brand-emphasis);
  opacity: 0;
  animation: dx-ping 2s ease-out infinite;
}

.dx-pin:hover,
.dx-pin.is-active {
  transform: scale(1.15);
}

.dx-pin.is-active {
  background: var(--ink);
}

.dx-pin.is-active::after {
  animation: none;
}

@keyframes dx-ping {
  0% {
    opacity: 0.6;
    transform: scale(0.7);
  }
  100% {
    opacity: 0;
    transform: scale(1.5);
  }
}

doc-hotspots [data-hs-area] {
  transition: box-shadow 0.3s, background-color 0.3s;
}

doc-hotspots [data-hs-area].is-lit {
  box-shadow: 0 0 0 2px var(--brand-emphasis), 0 0 0 6px color-mix(in srgb, var(--brand-emphasis) 20%, transparent);
  border-radius: 6px;
}

doc-hotspots .hs-notes {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 8px;
  margin-top: 12px;
  padding: 0;
  list-style: none;
  counter-reset: hs;
}

doc-hotspots .hs-notes > li {
  counter-increment: hs;
  position: relative;
  margin: 0;
  padding: 10px 12px 10px 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--muted);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

doc-hotspots .hs-notes > li::before {
  content: counter(hs);
  position: absolute;
  left: 12px;
  top: 11px;
  width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--canvas);
  border: 1px solid var(--line);
  font: 700 11px/1 var(--font-mono);
  color: var(--ink);
}

doc-hotspots .hs-notes > li b {
  display: block;
  color: var(--ink);
  font-weight: 600;
}

doc-hotspots .hs-notes > li.is-active {
  border-color: var(--brand-emphasis);
  background: var(--brand-soft);
}

doc-hotspots .hs-notes > li.is-active::before {
  background: var(--brand-emphasis);
  border-color: var(--brand-emphasis);
  color: #fff;
}

/* ── Compare: drag or click to reveal before / after. ── */
doc-compare {
  display: block;
  margin: 28px 0;
}

doc-compare .cmp-view {
  position: relative;
  display: grid;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  user-select: none;
  touch-action: pan-y;
}

doc-compare .cmp-view > * {
  grid-area: 1 / 1;
  min-width: 0;
}

doc-compare .cmp-view > :last-child {
  clip-path: inset(0 0 0 var(--pos, 50%));
}

.dx-cmp-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--pos, 50%);
  z-index: 3;
  width: 2px;
  margin-left: -1px;
  background: var(--brand-emphasis);
  cursor: ew-resize;
}

.dx-cmp-handle::after {
  content: "⇆";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: var(--brand-emphasis);
  color: #fff;
  font-size: 14px;
  box-shadow: 0 2px 10px rgb(0 0 0 / 0.25);
}

.dx-cmp-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  font-size: 12.5px;
}

.dx-cmp-labels button {
  border: 0;
  background: none;
  padding: 0;
  color: var(--muted);
  cursor: pointer;
}

.dx-cmp-labels button:hover {
  color: var(--ink);
}

/* Search results (in page) */
.dx-results-count {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--muted);
}

.dx-results {
  list-style: none;
  margin: 0 !important;
  padding: 0 !important;
  border-top: 1px solid var(--line);
}

.dx-results > li {
  margin: 0;
  border-bottom: 1px solid var(--line);
}

.dx-results a,
.dx-results .is-draft {
  position: relative;
  display: grid;
  gap: 2px;
  padding: 14px 4px;
  text-decoration: none;
  color: var(--text);
}

.dx-results a:hover strong {
  text-decoration: underline;
  text-decoration-color: var(--brand-emphasis);
  text-underline-offset: 4px;
}

.dx-results .path {
  font-size: 12px;
  color: var(--faint);
}

.dx-results strong {
  font-size: 16px;
  font-weight: 600;
  color: var(--ink);
}

.dx-results .desc {
  font-size: 14px;
  line-height: 1.6;
  color: var(--muted);
}

.dx-results .is-draft strong {
  color: var(--muted);
}

.dx-results .state {
  position: absolute;
  right: 4px;
  top: 16px;
  font-size: 12px;
  color: var(--faint);
}

.dx-results mark {
  background: var(--brand-soft);
  color: inherit;
  border-radius: 3px;
  padding: 0 1px;
}

/* Pager & footer */
.dx-pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 64px;
}

.dx-pager a {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  text-decoration: none;
  transition: border-color 0.2s;
}

.dx-pager a:hover {
  border-color: var(--ink);
}

.dx-pager a.next {
  grid-column: 2;
  text-align: right;
}

.dx-pager small {
  font-size: 12px;
  color: var(--muted);
}

.dx-pager strong {
  color: var(--ink);
  font-weight: 500;
}

.dx-foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px 16px;
  margin-top: 40px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  font-size: 12.5px;
  color: var(--muted);
}

.dx-foot a {
  color: var(--muted);
}

/* Section overview (rendered from the manifest) */
.dx-overview-group {
  margin-top: 36px;
}

.dx-overview-group h2 {
  display: flex;
  align-items: center;
  gap: 10px;
}

.dx-overview-group h2 .count {
  font-size: 13px;
  font-weight: 400;
  color: var(--muted);
}

/* ───────────── Home & section layouts ───────────── */

body[data-layout="home"] .dx-shell,
body[data-layout="search"] .dx-shell {
  grid-template-columns: minmax(0, 1fr);
}

body[data-layout="home"] .dx-side,
body[data-layout="home"] .dx-toc,
body[data-layout="search"] .dx-side,
body[data-layout="search"] .dx-toc {
  display: none;
}

body[data-layout="search"] .dx-page {
  grid-template-columns: minmax(0, var(--measure));
}

body[data-layout="home"] .dx-page {
  display: block;
  padding: 0;
}

body[data-layout="home"] main.doc {
  max-width: none;
}

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

@media (max-width: 1280px) {
  .dx-page {
    grid-template-columns: minmax(0, var(--measure));
  }

  .dx-toc {
    display: none;
  }

  .wide {
    margin-right: 0;
  }
}

@media (max-width: 1080px) {
  .dx-sections a::before {
    display: none;
  }

  .dx-search-box,
  .dx-search-box:focus-within {
    width: 200px;
  }
}

@media (max-width: 960px) {
  .dx-shell {
    grid-template-columns: minmax(0, 1fr);
  }

  .dx-menu-btn {
    display: grid;
  }

  .dx-side {
    position: fixed;
    top: var(--top-h);
    left: 0;
    z-index: 30;
    width: min(320px, 86vw);
    background: var(--bg);
    transform: translateX(-100%);
    transition: transform 0.25s;
  }

  body.side-open .dx-side {
    transform: none;
    box-shadow: 0 0 0 100vmax rgb(1 4 9 / 0.3);
  }

  .dx-sections,
  .dx-search-box kbd,
  .dx-app-link,
  .dx-brand .slash,
  .dx-brand small {
    display: none;
  }

  .dx-top {
    gap: 12px;
    padding: 0 16px;
  }

  .dx-top-tools {
    flex: 1;
    justify-content: flex-end;
  }

  .dx-search-box,
  .dx-search-box:focus-within {
    width: auto;
    flex: 1;
  }

  .dx-page {
    padding: 28px 20px 96px;
  }

  doc-flow {
    grid-template-columns: minmax(0, 1fr);
  }

  doc-flow .flow-stage {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 16px;
  }

  .doc-head h1 {
    font-size: 28px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001s !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001s !important;
  }
}

@media print {
  .dx-top,
  .dx-side,
  .dx-toc,
  .dx-pager,
  .dx-copy,
  .dx-flow-bar {
    display: none !important;
  }

  .dx-shell,
  .dx-page {
    display: block;
    padding: 0;
  }
}
