/*
 * xlmflow docs page. Builds on style.css (tokens, nav, buttons, footer) and adds a two-column reading layout:
 * a sticky table of contents and one readable column of content.
 */

html {
  scroll-padding-top: 96px;
}
@media (max-width: 960px) {
  html {
    scroll-padding-top: 132px;
  }
}
@media (prefers-reduced-motion: no-preference) {
  html {
    scroll-behavior: smooth;
  }
}

.nav__links a[aria-current="page"] {
  color: var(--text);
}
.nav__links a[aria-current="page"]::after {
  transform: scaleX(1);
}

.docs {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr);
  gap: clamp(32px, 5vw, 80px);
  max-width: 1180px;
  margin: 0 auto;
  padding: 120px var(--gutter) 96px;
}

/* ───────── Table of contents ───────── */

.docs__toc {
  position: sticky;
  top: 96px;
  align-self: start;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
  scrollbar-width: thin;
}
.toc__head {
  display: block;
  margin-bottom: 14px;
  color: var(--dim);
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  list-style: none;
  cursor: default;
}
.toc__head::-webkit-details-marker {
  display: none;
}
.toc nav {
  display: grid;
  gap: 2px;
  border-left: 1px solid var(--line);
}
.toc__group {
  margin: 16px 0 6px;
  padding-left: 16px;
  color: var(--dim);
  font-size: 11.5px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.toc__group:first-child {
  margin-top: 0;
}
.toc nav a {
  position: relative;
  padding: 5px 0 5px 16px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.35;
  transition: color 0.2s;
}
.toc nav a::before {
  content: "";
  position: absolute;
  left: -1px;
  top: 4px;
  bottom: 4px;
  width: 2px;
  border-radius: 2px;
  background: var(--brand-soft);
  opacity: 0;
  transform: scaleY(0.4);
  transition:
    opacity 0.25s var(--ease),
    transform 0.25s var(--ease);
}
.toc nav a:hover {
  color: var(--text);
}
.toc nav a.is-active {
  color: var(--text);
}
.toc nav a.is-active::before {
  opacity: 1;
  transform: none;
}

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

.docs__main {
  max-width: 760px;
  min-width: 0;
  color: var(--text-soft);
  font-size: 16px;
  line-height: 1.7;
}
.docs__hero {
  padding-bottom: 40px;
  border-bottom: 1px solid var(--line);
}
.docs__hero .badge {
  margin-bottom: 22px;
}
.docs__hero h1 {
  color: var(--text);
  font-size: clamp(2.4rem, 5vw, 3.8rem);
  font-weight: 600;
  line-height: 1.02;
  letter-spacing: -0.03em;
}
.docs__hero h1 em {
  color: var(--brand-soft);
}
.docs__lead {
  max-width: 36rem;
  margin-top: 18px;
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1.6;
}
.docs__ctas {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 26px;
}

.doc {
  padding: 48px 0 8px;
}
.doc + .doc {
  border-top: 1px solid var(--line);
  margin-top: 40px;
}
.doc h2 {
  margin-bottom: 16px;
  color: var(--text);
  font-size: clamp(1.5rem, 2.6vw, 1.9rem);
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.02em;
}
.doc h3 {
  margin: 28px 0 8px;
  color: var(--text);
  font-size: 1.08rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.doc h3 small {
  margin-left: 8px;
  color: var(--dim);
  font-size: 12px;
  font-weight: 400;
}
.doc p + p,
.doc p + .table,
.doc .table + p,
.doc p + .formula,
.doc .formula + p,
.doc p + .steps,
.doc .steps + p,
.doc p + .bullets,
.doc p + .code,
.doc .code + p,
.doc .note + p,
.doc p + .note,
.doc .steps + .note,
.doc .cards + .note,
.doc .flow + p,
.doc .table + h3 {
  margin-top: 16px;
}
.doc b {
  color: var(--text);
  font-weight: 600;
}
.doc i {
  color: var(--text);
  font-style: normal;
}
.doc a:not(.btn):not(.hash) {
  color: var(--brand-soft);
  text-decoration: underline;
  text-decoration-color: rgba(131, 170, 255, 0.35);
  text-underline-offset: 3px;
  transition: text-decoration-color 0.2s;
}
.doc a:not(.btn):not(.hash):hover {
  text-decoration-color: currentColor;
}
.doc code,
.formula,
.code,
.hash {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
.doc code {
  padding: 1px 6px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--cream-hi);
  font-size: 0.86em;
  overflow-wrap: anywhere;
}

/* Cards in the overview */
.cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 22px;
}
.dcard {
  padding: 18px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.025);
  font-size: 14.5px;
  line-height: 1.5;
}
.dcard__k {
  margin-bottom: 6px;
  color: var(--brand-soft);
  font-size: 12px;
}

/* Callouts */
.note {
  padding: 16px 18px;
  border-radius: 12px;
  border: 1px solid rgba(131, 170, 255, 0.22);
  background: rgba(11, 83, 191, 0.08);
  font-size: 15px;
  line-height: 1.6;
}
.note--warn {
  border-color: rgba(232, 181, 76, 0.28);
  background: rgba(232, 181, 76, 0.06);
}
.note--warn b {
  color: var(--warning);
}
.note b:first-child {
  margin-right: 4px;
}

/* The three-step flow */
.flow {
  display: grid;
  gap: 0;
  margin-top: 6px;
}
.flow li {
  position: relative;
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  gap: 16px;
  padding-bottom: 22px;
}
.flow li:not(:last-child)::before {
  content: "";
  position: absolute;
  left: 17px;
  top: 40px;
  bottom: 4px;
  width: 1px;
  background: linear-gradient(180deg, var(--brand-soft), transparent);
  opacity: 0.5;
}
.flow__n {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid rgba(131, 170, 255, 0.4);
  background: rgba(11, 83, 191, 0.18);
  color: var(--text);
  font-size: 14px;
}
.flow h3 {
  margin: 6px 0 4px;
}

/* Numbered steps */
.steps {
  display: grid;
  gap: 10px;
  counter-reset: step;
}
.steps li {
  position: relative;
  padding-left: 36px;
  counter-increment: step;
}
.steps li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: 2px;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}

.bullets {
  display: grid;
  gap: 10px;
}
.bullets li {
  position: relative;
  padding-left: 22px;
}
.bullets li::before {
  content: "";
  position: absolute;
  left: 4px;
  top: 0.72em;
  width: 6px;
  height: 6px;
  background: var(--brand-soft);
}

/* Definitions and Q&A */
.terms {
  display: grid;
  border-top: 1px solid var(--line);
}
.terms > div {
  display: grid;
  grid-template-columns: 190px minmax(0, 1fr);
  gap: 20px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}
.terms dt {
  color: var(--text);
  font-weight: 600;
}
.terms--qa > div {
  grid-template-columns: minmax(0, 1fr);
  gap: 4px;
}

/* Formula */
.formula {
  display: grid;
  gap: 6px;
  padding: 18px 20px;
  border-radius: 12px;
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.03);
  color: var(--cream-hi);
  font-size: 14.5px;
  overflow-x: auto;
}

/* Tables */
.table {
  overflow-x: auto;
  border-radius: 12px;
  border: 1px solid var(--line);
  -webkit-overflow-scrolling: touch;
}
.table table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14.5px;
  line-height: 1.5;
}
.table th,
.table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}
.table tr:last-child th,
.table tr:last-child td {
  border-bottom: 0;
}
.table thead th {
  background: rgba(255, 255, 255, 0.035);
  color: var(--dim);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.table tbody th {
  width: 34%;
  color: var(--muted);
  font-weight: 500;
}
.table td:first-child {
  color: var(--text);
}
.hash {
  color: var(--brand-soft);
  font-size: 13px;
  white-space: nowrap;
}
a.hash:hover {
  text-decoration: underline;
}

/* Code block */
.code {
  overflow-x: auto;
  margin: 0;
  padding: 18px 20px;
  border-radius: 12px;
  border: 1px solid var(--line-strong);
  background: #0d0c11;
  color: var(--cream-hi);
  font-size: 13.5px;
  line-height: 1.7;
}
.code .c {
  color: var(--dim);
}

.docs__next {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 56px;
  padding-top: 32px;
  border-top: 1px solid var(--line);
}

/* ───────── Tablet and phone ───────── */

@media (max-width: 960px) {
  .docs {
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
    padding-top: 96px;
  }
  /* The contents become a collapsible bar that stays under the nav. */
  .docs__toc {
    top: 68px;
    z-index: 5;
    max-height: none;
    overflow: visible;
    margin: 0 calc(var(--gutter) * -1) 8px;
  }
  .toc {
    padding: 0 var(--gutter);
    border-bottom: 1px solid var(--line);
    background: rgba(10, 9, 13, 0.9);
    -webkit-backdrop-filter: blur(14px);
    backdrop-filter: blur(14px);
  }
  .toc__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 0;
    padding: 14px 0;
    cursor: pointer;
  }
  .toc__head::after {
    content: "";
    width: 8px;
    height: 8px;
    border-right: 1.5px solid currentColor;
    border-bottom: 1.5px solid currentColor;
    transform: translateY(-2px) rotate(45deg);
    transition: transform 0.25s var(--ease);
  }
  .toc[open] .toc__head::after {
    transform: translateY(2px) rotate(-135deg);
  }
  .toc nav {
    max-height: 60vh;
    overflow-y: auto;
    padding-bottom: 14px;
  }
  .docs__main {
    max-width: none;
  }
}

@media (max-width: 640px) {
  .docs__main {
    font-size: 15.5px;
  }
  .cards {
    grid-template-columns: minmax(0, 1fr);
  }
  .terms > div {
    grid-template-columns: minmax(0, 1fr);
    gap: 4px;
  }
  .table th,
  .table td {
    padding: 10px 12px;
  }
  .docs__next .btn {
    flex: 1 1 100%;
  }
}
