/* Mounted into www, so every rule is scoped under .docs and the shell's tokens
   are the palette. Nothing here restyles an element the shell owns. */

.docs {
  --rail-width: 16.5rem;
  --rail-collapsed: 3.25rem;
  display: grid;
  grid-template-columns: var(--rail-collapsed) minmax(0, 1fr);
  gap: 2.5rem;
  align-items: start;
}

.docs-rail {
  position: sticky;
  top: 1.5rem;
  width: 100%;
  z-index: 20;
}

.docs-rail .rail-inner {
  background: var(--card-bg, #111418);
  border: 1px solid var(--border, #22272e);
  border-radius: var(--radius, 12px);
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 3rem);
  overflow: hidden;
  transition: width 160ms ease, box-shadow 160ms ease;
  width: var(--rail-width);
}

.docs-rail.is-collapsed .rail-inner {
  width: var(--rail-collapsed);
}

.docs-rail.is-collapsed:hover .rail-inner,
.docs-rail.is-collapsed:focus-within .rail-inner {
  box-shadow: 0 12px 32px rgb(0 0 0 / 28%);
  width: var(--rail-width);
}

.docs-rail.is-pinned {
  position: sticky;
}

.docs:has(.docs-rail.is-pinned),
.docs:has(.docs-rail:not(.is-collapsed)) {
  grid-template-columns: var(--rail-width) minmax(0, 1fr);
}

.rail-head {
  align-items: center;
  border-bottom: 1px solid var(--border, #22272e);
  display: flex;
  gap: 0.5rem;
  justify-content: space-between;
  padding: 0.75rem 0.9rem;
}

.rail-title {
  color: var(--ink, #e6edf3);
  font-weight: 600;
  letter-spacing: 0.01em;
  text-decoration: none;
  white-space: nowrap;
}

.rail-pin {
  background: none;
  border: 0;
  border-radius: 6px;
  color: var(--dim, #8b949e);
  cursor: pointer;
  font-size: 0.95rem;
  line-height: 1;
  padding: 0.3rem 0.4rem;
}

.rail-pin:hover {
  background: var(--accent-soft, #1f6feb22);
  color: var(--accent, #58a6ff);
}

.rail-nav {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 0.6rem 0.5rem 0.9rem;
}

.rail-section + .rail-section {
  margin-top: 0.9rem;
}

.rail-section-title {
  color: var(--dim, #8b949e);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.09em;
  margin: 0 0 0.35rem;
  padding: 0 0.45rem;
  text-transform: uppercase;
  white-space: nowrap;
}

.rail-item {
  align-items: center;
  border-radius: 7px;
  color: var(--dim, #8b949e);
  display: flex;
  gap: 0.6rem;
  padding: 0.34rem 0.45rem;
  text-decoration: none;
  white-space: nowrap;
}

.rail-item:hover {
  background: var(--accent-soft, #1f6feb22);
  color: var(--ink, #e6edf3);
}

.rail-item.is-active {
  background: var(--accent-soft, #1f6feb22);
  color: var(--accent, #58a6ff);
}

.rail-dot {
  background: currentColor;
  border-radius: 50%;
  flex: 0 0 auto;
  height: 5px;
  margin-left: 0.35rem;
  opacity: 0.55;
  width: 5px;
}

.rail-item.is-active .rail-dot {
  opacity: 1;
}

.rail-label {
  font-size: 0.86rem;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rail-foot {
  border-top: 1px solid var(--border, #22272e);
  display: flex;
  gap: 0.5rem;
  padding: 0.65rem 0.9rem;
}

.rail-link {
  color: var(--dim, #8b949e);
  font-size: 0.8rem;
  text-decoration: none;
  white-space: nowrap;
}

.rail-link:hover {
  color: var(--accent, #58a6ff);
}

/* Collapsed: the labels and the footer links go, the dots stay as the rail. */
.docs-rail.is-collapsed .rail-label,
.docs-rail.is-collapsed .rail-section-title,
.docs-rail.is-collapsed .rail-title,
.docs-rail.is-collapsed .rail-link {
  opacity: 0;
  transition: opacity 100ms ease;
}

.docs-rail.is-collapsed:hover .rail-label,
.docs-rail.is-collapsed:hover .rail-section-title,
.docs-rail.is-collapsed:hover .rail-title,
.docs-rail.is-collapsed:hover .rail-link,
.docs-rail.is-collapsed:focus-within .rail-label,
.docs-rail.is-collapsed:focus-within .rail-section-title,
.docs-rail.is-collapsed:focus-within .rail-title,
.docs-rail.is-collapsed:focus-within .rail-link {
  opacity: 1;
}

.docs-main {
  min-width: 0;
  padding-bottom: 3rem;
}

.docs-head {
  border-bottom: 1px solid var(--border, #22272e);
  margin-bottom: 1.6rem;
  padding-bottom: 1.1rem;
}

.docs-eyebrow {
  color: var(--dim, #8b949e);
  display: block;
  font-size: 0.76rem;
  letter-spacing: 0.06em;
  margin-bottom: 0.45rem;
  text-transform: uppercase;
}

.docs-page h1 {
  font-size: 1.85rem;
  line-height: 1.25;
  margin: 0;
}

.docs-lede {
  color: var(--dim, #8b949e);
  font-size: 1.02rem;
  margin: 0.7rem 0 0;
  max-width: 46rem;
}

.docs-group {
  margin-top: 2rem;
}

.docs-group h2 {
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.09em;
  margin: 0 0 0.7rem;
  text-transform: uppercase;
}

.docs-cards {
  display: grid;
  gap: 0.6rem;
  grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
  list-style: none;
  margin: 0;
  padding: 0;
}

.docs-card {
  background: var(--card-bg, #111418);
  border: 1px solid var(--border, #22272e);
  border-radius: var(--radius, 12px);
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  height: 100%;
  padding: 0.85rem 1rem;
  text-decoration: none;
}

.docs-card:hover {
  border-color: var(--accent, #58a6ff);
}

.docs-card-title {
  color: var(--ink, #e6edf3);
  font-weight: 600;
}

.docs-card-meta {
  color: var(--dim, #8b949e);
  font-size: 0.8rem;
}

.docs-pager {
  border-top: 1px solid var(--border, #22272e);
  display: grid;
  gap: 0.75rem;
  grid-template-columns: 1fr 1fr;
  margin-top: 2.5rem;
  padding-top: 1.25rem;
}

/* The rail is on screen at this width, so the pager's third button is not. */
.docs-pager > sf-s {
  display: none;
}

.docs-pager-toc {
  background: none;
  border: 1px solid var(--border, #22272e);
  border-radius: var(--radius, 12px);
  color: inherit;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  font: inherit;
  gap: 0.2rem;
  padding: 0.7rem 1.1rem;
  text-align: center;
  width: 100%;
}

.docs-pager-toc:hover {
  border-color: var(--accent, #58a6ff);
}

.rail-close {
  background: none;
  border: 0;
  border-radius: 6px;
  color: var(--dim, #8b949e);
  cursor: pointer;
  display: none;
  font-size: 1rem;
  line-height: 1;
  padding: 0.3rem 0.45rem;
}

.docs-pager-link {
  border: 1px solid var(--border, #22272e);
  border-radius: var(--radius, 12px);
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.7rem 0.95rem;
  text-decoration: none;
}

.docs-pager-link:hover {
  border-color: var(--accent, #58a6ff);
}

.docs-pager-link.next {
  text-align: right;
}

.docs-pager-dir {
  color: var(--dim, #8b949e);
  font-size: 0.74rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.docs-pager-title {
  color: var(--ink, #e6edf3);
  font-size: 0.92rem;
}

.docs-back {
  color: var(--accent, #58a6ff);
  text-decoration: none;
}

.diagram {
  margin: 1.6rem 0;
}

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

.diagram-box rect {
  fill: var(--card-bg, #111418);
  stroke: var(--border, #22272e);
  stroke-width: 1.5;
}

.diagram-box rect.diagram-box-accent {
  stroke: var(--accent, #58a6ff);
}

.diagram-box rect.diagram-box-soft {
  fill: none;
  stroke-dasharray: 4 4;
}

.diagram-label text {
  fill: var(--ink, #e6edf3);
  font-family: var(--mono, ui-monospace, monospace);
  font-size: 12px;
  text-anchor: middle;
}

.diagram-label text:nth-child(even) {
  fill: var(--dim, #8b949e);
  font-size: 10.5px;
}

.diagram-edge path {
  fill: none;
  stroke: var(--dim, #8b949e);
  stroke-width: 1.5;
}

/* The marker lives in the svg's `defs`, not under the edge group that
   references it, so it is reached from the root or not at all. */
.diagram-svg marker path {
  fill: var(--dim, #8b949e);
  stroke: none;
}

.diagram-edge-label text {
  fill: var(--dim, #8b949e);
  font-family: var(--mono, ui-monospace, monospace);
  font-size: 10.5px;
  text-anchor: middle;
  /* A label sits over the edge it names, so the glyphs are painted onto a halo
     of the page's own colour and the line runs behind them. */
  paint-order: stroke;
  stroke: var(--paper, #0d1117);
  stroke-width: 4;
  stroke-linejoin: round;
}

.diagram-missing {
  color: var(--dim, #8b949e);
  font-style: italic;
}

@media (max-width: 720px) {
  .docs,
  .docs:has(.docs-rail.is-pinned),
  .docs:has(.docs-rail:not(.is-collapsed)) {
    gap: 1.25rem;
    grid-template-columns: minmax(0, 1fr);
  }

  /* The chapter starts at the top of the page. The index is a place you go,
     reached from the pager, and it takes the whole screen when you go there. */
  .docs-rail {
    display: none;
  }

  .docs-rail.is-open {
    display: block;
    inset: 0;
    position: fixed;
    z-index: 60;
  }

  .docs-rail.is-open .rail-inner,
  .docs-rail.is-open.is-collapsed .rail-inner {
    border: 0;
    border-radius: 0;
    height: 100%;
    max-height: none;
    width: 100%;
  }

  .docs-rail.is-open .rail-nav,
  .docs-rail.is-open .rail-label,
  .docs-rail.is-open .rail-section-title,
  .docs-rail.is-open .rail-title,
  .docs-rail.is-open .rail-link {
    display: revert;
    opacity: 1;
  }

  .docs-rail.is-open .rail-head {
    padding: 1rem 1.1rem;
  }

  .docs-rail.is-open .rail-item {
    padding: 0.7rem 0.45rem;
  }

  .rail-close {
    display: block;
  }

  .rail-pin {
    display: none;
  }

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

  .docs-pager > sf-s {
    display: block;
  }

  .docs-pager-link.next {
    text-align: left;
  }
}
