/*
 * The developer site on the Brightwild design system (@brightwild/design,
 * docs/specs/guest-interfaces.md). Every colour, size and face comes from
 * tokens.css, which the build copies beside this file; nothing here names a
 * ramp step or a hex value. The frame (top bar and contents rail) is one
 * surface, bg-sunken; the page is bg-canvas; code and tables are plates.
 * There is no accent and no blue: links are underlined ink.
 */

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg-canvas);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--fs-15);
  line-height: var(--lh-24);
  -webkit-font-smoothing: antialiased;
}

.prose a,
.site-footer a {
  color: var(--text-primary);
  text-decoration: underline;
  text-decoration-thickness: var(--border-width);
  text-underline-offset: 0.2em;
  text-decoration-color: var(--border-strong);
  border-radius: var(--radius-sm);
}

.prose a:hover,
.site-footer a:hover {
  text-decoration-color: currentColor;
}

:focus-visible {
  outline: var(--ring-width) solid var(--focus-ring);
  outline-offset: 2px;
}

.skip {
  position: absolute;
  left: -999px;
  color: var(--text-primary);
}

.skip:focus {
  left: var(--space-4);
  top: var(--space-2);
  z-index: var(--z-tooltip);
  padding: var(--space-2) var(--space-3);
  background: var(--bg-overlay);
  border-radius: var(--radius-lg);
}

/* --- The frame: top bar ---------------------------------------------------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  display: flex;
  align-items: center;
  gap: var(--space-2) var(--space-8);
  min-height: var(--page-bar-h);
  padding: 0 var(--space-6);
  background: var(--bg-sunken);
  font-size: var(--fs-13);
  line-height: var(--lh-20);
}

.site-header a {
  color: var(--text-primary);
  text-decoration: none;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  flex: none;
  font-weight: var(--fw-strong);
}

.brand svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
  flex: none;
}

.brand span {
  font-weight: var(--fw-regular);
  color: var(--text-tertiary);
}

/* The TopBar's links: pills, selection a fill (D-97). */
.site-header nav {
  display: flex;
  flex: 1 1 auto;
  min-width: 0;
  gap: var(--space-1);
  overflow-x: auto;
  scrollbar-width: none;
}

.site-header nav a {
  display: inline-flex;
  flex: none;
  align-items: center;
  height: var(--ctl-md);
  padding: 0 var(--space-3);
  border-radius: var(--radius-pill);
  color: var(--text-secondary);
  white-space: nowrap;
  transition:
    background var(--duration-fast) var(--ease-standard),
    color var(--duration-fast) var(--ease-standard);
}

.site-header nav a:hover {
  background: var(--state-hover);
  color: var(--text-primary);
}

.site-header nav a[aria-current="page"] {
  background: var(--state-selected);
  color: var(--text-primary);
}

/* --- The frame: contents rail (the Sidebar's nav rows), and the page -------- */

.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: calc(100vh - var(--page-bar-h));
}

.toc {
  background: var(--bg-sunken);
}

.toc nav {
  position: sticky;
  top: var(--page-bar-h);
  max-height: calc(100vh - var(--page-bar-h));
  overflow-y: auto;
  padding: var(--space-6) var(--space-3) var(--space-8);
}

.toc p {
  display: flex;
  align-items: center;
  height: 24px;
  margin: 0;
  padding: 0 var(--space-3);
  font-size: var(--fs-12);
  line-height: var(--lh-16);
  color: var(--text-tertiary);
}

.toc ol {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 1px;
}

/* A heading can run to two lines, so a row grows from the nav-row height. */
.toc a {
  display: block;
  min-height: var(--nav-row);
  padding: var(--space-cell) var(--space-3);
  border-radius: var(--radius-pill);
  font-size: var(--fs-13);
  line-height: var(--lh-20);
  color: var(--text-secondary);
  text-decoration: none;
  transition:
    background var(--duration-fast) var(--ease-standard),
    color var(--duration-fast) var(--ease-standard);
}

.toc a:hover {
  background: var(--state-hover);
  color: var(--text-primary);
}

.prose {
  min-width: 0;
  padding: var(--space-10) var(--space-12) var(--space-16);
}

.prose > * {
  max-width: 820px;
}

/* --- Type: the closed scale, two weights, a bigger heading stays regular ----- */

/* Display's headline register. */
.prose h1 {
  margin: 0 0 var(--space-6);
  font-size: var(--fs-34);
  line-height: var(--lh-40);
  font-weight: var(--fw-regular);
  letter-spacing: -0.02em;
  text-wrap: pretty;
}

/* Display's title register. */
.prose h2 {
  margin: var(--space-12) 0 var(--space-3);
  font-size: var(--fs-23);
  line-height: var(--lh-28);
  font-weight: var(--fw-regular);
  letter-spacing: -0.015em;
  text-wrap: pretty;
}

.prose h3 {
  margin: var(--space-8) 0 var(--space-2);
  font-size: var(--fs-15);
  line-height: var(--lh-24);
  font-weight: var(--fw-strong);
}

.prose h4 {
  margin: var(--space-6) 0 var(--space-1);
  font-size: var(--fs-13);
  line-height: var(--lh-20);
  font-weight: var(--fw-strong);
}

.prose h2,
.prose h3,
.prose h4 {
  scroll-margin-top: calc(var(--page-bar-h) + var(--space-4));
}

.prose p,
.prose li {
  max-width: var(--measure);
}

.prose p {
  margin: 0 0 var(--space-4);
}

.prose ul,
.prose ol {
  margin: 0 0 var(--space-4);
  padding-left: var(--space-6);
}

.prose li + li {
  margin-top: var(--space-1);
}

.prose strong {
  font-weight: var(--fw-strong);
}

.prose hr {
  height: var(--border-width);
  margin: var(--space-10) 0;
  border: 0;
  background: var(--border-subtle);
}

/* --- Machine facts in mono; code and tables are plates ----------------------- */

.prose code {
  font-family: var(--font-mono);
  font-size: 0.87em;
  padding: 0.1em 0.35em;
  background: var(--bg-plate);
  border-radius: var(--radius-sm);
  overflow-wrap: anywhere;
}

.prose pre {
  margin: 0 0 var(--space-6);
  padding: var(--space-4) var(--space-5);
  background: var(--bg-plate);
  border-radius: var(--radius-none);
  overflow-x: auto;
  font-size: var(--fs-13);
  line-height: var(--lh-20);
}

.prose pre code {
  padding: 0;
  font-size: inherit;
  background: none;
  overflow-wrap: normal;
}

/* The Table on a plate; prose cells wrap, so rows grow from the default height. */
.prose .table-wrap {
  margin: 0 0 var(--space-6);
  background: var(--bg-plate);
  overflow-x: auto;
}

.prose table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: var(--fs-13);
  line-height: var(--lh-20);
  font-variant-numeric: tabular-nums;
}

.prose th,
.prose td {
  padding: calc((var(--row-default) - var(--lh-20)) / 2) var(--space-3);
  text-align: left;
  vertical-align: top;
  border-bottom: var(--border-width) solid var(--border-subtle);
}

.prose th:first-child,
.prose td:first-child {
  padding-left: var(--space-5);
}

.prose th:last-child,
.prose td:last-child {
  padding-right: var(--space-5);
}

.prose tbody tr:last-child td {
  border-bottom: 0;
}

.prose th {
  font-weight: var(--fw-regular);
  color: var(--text-tertiary);
  white-space: nowrap;
}

.prose td code {
  background: var(--bg-field);
}

.prose blockquote {
  margin: 0 0 var(--space-6);
  padding: var(--space-4) var(--space-5);
  background: var(--bg-plate);
  color: var(--text-secondary);
}

.prose blockquote > :last-child {
  margin-bottom: 0;
}

/* --- Footer: on the frame, in caption type ----------------------------------- */

.site-footer {
  padding: var(--space-5) var(--space-6);
  background: var(--bg-sunken);
  color: var(--text-tertiary);
  font-size: var(--fs-12);
  line-height: var(--lh-16);
}

.site-footer a {
  color: var(--text-secondary);
}

/* --- The API reference: Scalar on the same tokens ---------------------------- */

.reference-page {
  min-height: 100vh;
}

/* Scalar marks some cards (the request example) dark-mode on their own; they
   follow the page's theme here like everything else. */
body.reference-page,
body.reference-page.light-mode,
body.reference-page.dark-mode,
.reference-page #app .light-mode,
.reference-page #app .dark-mode {
  --scalar-font: var(--font-sans);
  --scalar-font-code: var(--font-mono);
  --scalar-background-1: var(--bg-canvas);
  --scalar-background-2: var(--bg-plate);
  --scalar-background-3: var(--bg-field);
  --scalar-background-accent: var(--state-selected);
  --scalar-color-1: var(--text-primary);
  --scalar-color-2: var(--text-secondary);
  --scalar-color-3: var(--text-tertiary);
  --scalar-color-accent: var(--text-primary);
  --scalar-border-color: var(--border-subtle);
  --scalar-color-green: var(--success-text);
  --scalar-color-red: var(--danger-text);
  --scalar-color-yellow: var(--warning-text);
  --scalar-color-orange: var(--warning-text);
  --scalar-color-blue: var(--text-primary);
  --scalar-color-purple: var(--text-secondary);
  --scalar-button-1: var(--action-primary);
  --scalar-button-1-color: var(--text-inverse);
  --scalar-button-1-hover: var(--action-primary-hover);
  --scalar-sidebar-background-1: var(--bg-sunken);
  --scalar-sidebar-color-1: var(--text-primary);
  --scalar-sidebar-color-2: var(--text-secondary);
  --scalar-sidebar-color-active: var(--text-primary);
  --scalar-sidebar-item-hover-background: var(--state-hover);
  --scalar-sidebar-item-active-background: var(--state-selected);
  --scalar-sidebar-border-color: transparent;
  --scalar-sidebar-search-background: var(--control-fill);
  --scalar-sidebar-search-border-color: transparent;
  --scalar-sidebar-search-color: var(--text-tertiary);
  --scalar-heading-1: var(--fs-23);
  --scalar-heading-2: var(--fs-19);
  --scalar-heading-3: var(--fs-15);
  --scalar-heading-4: var(--fs-15);
  --scalar-heading-5: var(--fs-15);
  --scalar-heading-6: var(--fs-15);
  --scalar-font-size-1: var(--fs-23);
  --scalar-font-size-2: var(--fs-15);
  --scalar-font-size-3: var(--fs-13);
  --scalar-font-size-4: var(--fs-13);
  --scalar-font-size-5: var(--fs-12);
  --scalar-font-size-6: var(--fs-12);
  --scalar-font-size-7: var(--fs-11);
  --scalar-link-color: var(--text-primary);
  --scalar-link-color-hover: var(--text-primary);
  --scalar-link-color-visited: var(--text-primary);
  --scalar-text-decoration-color: var(--border-strong);
  --scalar-text-decoration-color-hover: currentColor;
  --scalar-semibold: var(--fw-strong);
  --scalar-bold: var(--fw-strong);
  --scalar-radius: var(--radius-sm);
  --scalar-radius-lg: var(--radius-lg);
  /* The reference's own rail sticks under the site's top bar. */
  --scalar-custom-header-height: var(--page-bar-h);
}

/* A bigger heading stays regular. */
.reference-page #app :is(h1, h2) {
  font-weight: var(--fw-regular);
}

/* --- Motion and narrow screens ----------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  * {
    transition-duration: 0.01ms !important;
  }
}

@media (max-width: 860px) {
  .site-header {
    flex-wrap: wrap;
    padding: var(--space-2) var(--space-4) 0;
  }

  .site-header nav {
    flex-basis: 100%;
    padding-bottom: var(--space-2);
  }

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

  /* On phones the rail becomes a row that scrolls sideways, as the portal's does. */
  .toc nav {
    position: static;
    max-height: none;
    padding: 0 var(--space-4) var(--space-2);
  }

  .toc p {
    display: none;
  }

  .toc ol {
    display: flex;
    gap: var(--space-1);
    overflow-x: auto;
    scrollbar-width: none;
  }

  .toc li {
    flex: none;
  }

  .toc a {
    white-space: nowrap;
  }

  .prose {
    padding: var(--space-6) var(--space-4) var(--space-12);
  }

  .prose h1 {
    font-size: var(--fs-23);
    line-height: var(--lh-28);
  }

  .prose h2 {
    font-size: var(--fs-19);
    line-height: var(--lh-24);
  }
}
