:root {
  --page: #ffffff;
  --ink: #2f302d;
  --muted: #6b7280;
  --faint: #9aa1ad;
  --line: #e6e8ec;
  --line-strong: #d4d8df;
  --soft: #f7f8fa;
  --soft-2: #f1f4f7;
  --accent: #2563eb;
  --teal: #0f766e;
  --rose: #b83f58;
  --gold: #b7791f;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--page);
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.72;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.doc-page {
  width: min(780px, calc(100vw - 48px));
  margin: 0 auto;
  padding: 72px 0 96px;
}

.doc-title {
  margin-bottom: 32px;
}

.doc-title h1 {
  margin: 0;
  color: var(--ink);
  font-size: 36px;
  line-height: 1.18;
  font-weight: 650;
  letter-spacing: 0;
  text-wrap: balance;
}

.doc-subtitle {
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 18px;
  line-height: 1.7;
}

.doc-block {
  margin: 36px 0;
  scroll-margin-top: 28px;
}

.doc-block h2,
.doc-chart h2,
.doc-table h2,
.doc-diagram h2 {
  margin: 0 0 12px;
  color: var(--ink);
  font-size: 23px;
  line-height: 1.35;
  font-weight: 620;
  letter-spacing: 0;
  text-wrap: balance;
}

.doc-block p,
.doc-chart p,
.doc-table p,
.doc-diagram p {
  margin: 10px 0 16px;
  color: #4b5059;
  text-wrap: pretty;
}

.doc-block ul,
.doc-block ol {
  margin: 10px 0 0;
  padding-left: 24px;
}

.doc-block li {
  margin: 8px 0;
}

.doc-block strong,
.doc-callout strong,
.doc-note strong {
  color: var(--ink);
  font-weight: 620;
}

.doc-callout {
  margin: 28px 0 34px;
  padding: 16px 18px;
  border: 1px solid #dfe5e2;
  border-radius: 16px;
  background: #f7faf8;
}

.doc-callout p {
  margin: 6px 0 0;
  color: #46534f;
}

.doc-note {
  margin: 22px 0;
  padding: 13px 15px;
  border-left: 3px solid var(--line-strong);
  border-radius: 0 16px 16px 0;
  background: var(--soft);
  color: #535a66;
}

.doc-note p {
  margin: 0;
}

.doc-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin: 30px 0 42px;
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
  background: #fff;
}

.doc-metric {
  min-width: 0;
  padding: 16px 17px;
}

.doc-metric + .doc-metric {
  border-left: 1px solid var(--line);
}

.doc-metric span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.doc-metric strong {
  display: block;
  margin: 6px 0 3px;
  color: var(--ink);
  font-size: 23px;
  line-height: 1.18;
  font-weight: 640;
}

.doc-metric small {
  display: block;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.doc-chart,
.doc-table,
.doc-diagram {
  margin: 46px 0;
  scroll-margin-top: 28px;
}

.chart-frame,
.table-frame,
.diagram-frame {
  position: relative;
  margin-top: 18px;
}

.mermaid-frame {
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
}

.mermaid {
  min-width: 680px;
  margin: 0;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}

.mermaid svg {
  display: block;
  width: 100%;
  max-width: none;
  height: auto;
}

.diagram-zoom-trigger {
  position: absolute;
  top: 9px;
  right: 9px;
  z-index: 3;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.94);
  color: var(--muted);
  cursor: pointer;
  padding: 0;
  box-shadow: 0 1px 2px rgba(32, 33, 36, 0.04);
  opacity: 0;
  transition: opacity 140ms ease, color 140ms ease, background 140ms ease;
}

.lucide-icon {
  width: 14px;
  height: 14px;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
  pointer-events: none;
}

.mermaid-frame:hover .diagram-zoom-trigger,
.mermaid-frame:focus-within .diagram-zoom-trigger {
  opacity: 1;
}

.diagram-zoom-trigger:hover,
.diagram-zoom-trigger:focus-visible {
  background: #fff;
  color: var(--ink);
  outline: none;
}

.diagram-lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  padding: 34px;
  background: rgba(25, 28, 34, 0.62);
}

.diagram-lightbox.open {
  display: flex;
  align-items: center;
  justify-content: center;
}

.diagram-lightbox-panel {
  position: relative;
  width: min(1120px, calc(100vw - 48px));
  max-height: calc(100vh - 48px);
  overflow: auto;
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 22px 60px rgba(15, 23, 42, 0.28);
  padding: 28px;
}

.diagram-lightbox-content {
  min-width: 880px;
  padding-top: 6px;
}

.diagram-lightbox-content svg {
  display: block;
  width: 100%;
  height: auto;
}

.diagram-lightbox-close {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 4;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
}

.diagram-lightbox-close:hover,
.diagram-lightbox-close:focus-visible {
  background: var(--soft);
  color: var(--ink);
  outline: none;
}

.chart-menu {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 3;
  opacity: 0;
  transition: opacity 140ms ease;
}

.chart-frame:hover .chart-menu,
.chart-frame:focus-within .chart-menu {
  opacity: 1;
}

.chart-menu-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  width: 30px;
  height: 30px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.94);
  color: var(--muted);
  cursor: pointer;
  padding: 0;
  box-shadow: 0 1px 2px rgba(32, 33, 36, 0.04);
}

.chart-menu-trigger span {
  display: block;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: currentColor;
}

.chart-menu-trigger:hover,
.chart-menu-trigger:focus-visible {
  background: #fff;
  color: var(--ink);
  outline: none;
}

.chart-menu-popover {
  display: none;
  position: absolute;
  right: 0;
  top: 34px;
  width: 156px;
  padding: 6px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 8px 18px rgba(32, 33, 36, 0.12);
}

.chart-menu:hover .chart-menu-popover,
.chart-menu:focus-within .chart-menu-popover {
  display: block;
}

.chart-menu-popover button {
  display: block;
  width: 100%;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  text-align: left;
  padding: 8px 10px;
  cursor: pointer;
}

.chart-menu-popover button.active,
.chart-menu-popover button:hover,
.chart-menu-popover button:focus-visible {
  background: var(--soft-2);
  color: var(--ink);
  outline: none;
}

.chart-canvas {
  width: 100%;
  height: 390px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
}

.figure-caption {
  margin-top: 9px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.48;
}

.figure-caption strong {
  display: block;
  color: #343941;
  font-weight: 620;
}

.figure-caption span {
  display: block;
  margin-top: 2px;
}

.table-scroll {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
}

.doc-data-table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
  font-size: 14px;
  line-height: 1.45;
}

.doc-data-table th,
.doc-data-table td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.doc-data-table th {
  background: var(--soft);
  color: #566173;
  font-weight: 620;
}

.doc-data-table tbody tr:last-child td {
  border-bottom: 0;
}

.doc-data-table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.diagram-flow {
  display: grid;
  grid-template-columns: 1fr auto 1fr auto 1fr;
  gap: 10px;
  align-items: stretch;
  min-width: 640px;
}

.diagram-node {
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
}

.diagram-node strong {
  display: block;
  margin-bottom: 4px;
  color: var(--ink);
  font-weight: 620;
}

.diagram-node span {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.diagram-arrow {
  display: flex;
  align-items: center;
  color: var(--faint);
  font-size: 22px;
}

.doc-sources {
  margin-top: 48px;
  padding-top: 4px;
}

.source-links {
  margin: 16px 0 0;
  padding-left: 22px;
  color: #535a66;
  font-size: 14px;
  line-height: 1.6;
}

.source-links li {
  margin: 7px 0;
}

.toc-rail {
  position: fixed;
  left: 18px;
  top: 50%;
  z-index: 10;
  width: 320px;
  transform: translateY(-50%);
}

.toc-lines {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 28px;
  padding: 8px 5px;
}

.toc-line {
  position: relative;
  display: block;
  width: 18px;
  height: 8px;
  color: #c3c6cd;
}

.toc-line::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  width: 18px;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
  transform: translateY(-50%);
}

.toc-line.active,
.toc-line:hover {
  color: var(--ink);
}

.toc-popup {
  position: absolute;
  left: 0;
  top: 50%;
  width: 310px;
  padding: 12px;
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 16px 36px rgba(35, 37, 42, 0.13);
  opacity: 0;
  pointer-events: none;
  transform: translateY(-50%) translateX(-4px);
  transition: opacity 140ms ease, transform 140ms ease;
}

.toc-rail:hover .toc-popup,
.toc-rail:focus-within .toc-popup {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(-50%) translateX(0);
}

.toc-popup a {
  display: block;
  padding: 7px 9px;
  border-radius: 6px;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toc-popup a:hover,
.toc-popup a.active {
  background: var(--soft);
  text-decoration: none;
}

@media (max-width: 1040px) {
  .toc-rail {
    display: none;
  }
}

@media (max-width: 820px) {
  .doc-page {
    width: min(100vw - 32px, 780px);
    padding-top: 44px;
  }

  .doc-title h1 {
    font-size: 30px;
  }

  .doc-subtitle {
    font-size: 16px;
  }

  .doc-metrics {
    grid-template-columns: 1fr 1fr;
  }

  .doc-metric:nth-child(odd) {
    border-left: 0;
  }

  .doc-metric:nth-child(n + 3) {
    border-top: 1px solid var(--line);
  }

  .chart-canvas {
    height: 360px;
  }

  .diagram-lightbox {
    padding: 18px;
  }

  .diagram-lightbox-panel {
    width: calc(100vw - 24px);
    max-height: calc(100vh - 24px);
    padding: 22px;
  }

  .diagram-lightbox-content {
    min-width: 760px;
  }
}

@media (max-width: 560px) {
  .doc-page {
    width: min(100vw - 24px, 780px);
  }

  .doc-title h1 {
    font-size: 27px;
  }

  .doc-block h2,
  .doc-chart h2,
  .doc-table h2,
  .doc-diagram h2 {
    font-size: 21px;
  }

  .doc-metrics {
    grid-template-columns: 1fr;
  }

  .doc-metric,
  .doc-metric + .doc-metric {
    border-left: 0;
  }

  .doc-metric + .doc-metric {
    border-top: 1px solid var(--line);
  }

  .chart-canvas {
    height: 320px;
  }
}
