/* Debug MD documentation - single shared stylesheet.
   Design tokens first; components follow. Dark is the default theme,
   light applies via prefers-color-scheme or the manual toggle. */

/* ---------------------------------------------------------------- tokens */

:root {
  --nav-h: 3.5rem;
  --sidebar-w: 17rem;
  --toc-w: 13rem;
  --content-w: 45rem;
  --site-w: 90rem;
  --radius: 10px;
  --radius-sm: 6px;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", "Noto Sans", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas,
    "Liberation Mono", monospace;

  color-scheme: dark;
  --bg: #17181c;
  --bg-alt: #121316;
  --bg-elev: #1e2026;
  --fg: #dfdfd6;
  --fg-2: #9a9aa2;
  --fg-3: #6a6a71;
  --border: rgba(255, 255, 255, 0.1);
  --border-strong: rgba(255, 255, 255, 0.17);
  --accent: #a8b1ff;
  --accent-strong: #5c73e7;
  --accent-soft: rgba(100, 108, 255, 0.16);
  --green: #3dd68c;
  --green-soft: rgba(16, 185, 129, 0.15);
  --yellow: #f9b44e;
  --yellow-soft: rgba(234, 179, 8, 0.14);
  --red: #f66f81;
  --red-soft: rgba(244, 63, 94, 0.15);
  --inline-code-bg: rgba(142, 150, 170, 0.14);

  --tok-c: #7d8590; /* comment */
  --tok-k: #c8abfa; /* keyword */
  --tok-s: #3dd68c; /* string */
  --tok-t: #f9b44e; /* type */
  --tok-f: #a8b1ff; /* method / member */
  --tok-n: #f6907f; /* number */

  --shadow-card: 0 12px 32px rgba(0, 0, 0, 0.1), 0 2px 6px rgba(0, 0, 0, 0.08);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #ffffff;
    --bg-alt: #f6f6f7;
    --bg-elev: #ffffff;
    --fg: #3c3c43;
    --fg-2: #67676c;
    --fg-3: #929295;
    --border: #e2e2e3;
    --border-strong: #c8c8ca;
    --accent: #3451b2;
    --accent-strong: #3a5ccc;
    --accent-soft: rgba(100, 108, 255, 0.14);
    --green: #18794e;
    --yellow: #915930;
    --red: #b8272c;
    --inline-code-bg: rgba(142, 150, 170, 0.16);
    --tok-c: #6e7781;
    --tok-k: #8250df;
    --tok-s: #18794e;
    --tok-t: #915930;
    --tok-f: #3451b2;
    --tok-n: #b8272c;
  }
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #ffffff;
  --bg-alt: #f6f6f7;
  --bg-elev: #ffffff;
  --fg: #3c3c43;
  --fg-2: #67676c;
  --fg-3: #929295;
  --border: #e2e2e3;
  --border-strong: #c8c8ca;
  --accent: #3451b2;
  --accent-strong: #3a5ccc;
  --accent-soft: rgba(100, 108, 255, 0.14);
  --green: #18794e;
  --yellow: #915930;
  --red: #b8272c;
  --inline-code-bg: rgba(142, 150, 170, 0.16);
  --tok-c: #6e7781;
  --tok-k: #8250df;
  --tok-s: #18794e;
  --tok-t: #915930;
  --tok-f: #3451b2;
  --tok-n: #b8272c;
}

/* ------------------------------------------------------------------ base */

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

html {
  scroll-padding-top: calc(var(--nav-h) + 1.5rem);
}

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

::selection {
  background: var(--accent-soft);
}

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

a:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

:focus-visible {
  outline: 2px solid var(--accent-strong);
  outline-offset: 2px;
  border-radius: 2px;
}

h1,
h2,
h3,
h4 {
  line-height: 1.25;
  letter-spacing: -0.01em;
  font-weight: 600;
  color: var(--fg);
}

h1 {
  font-size: 2.25rem;
  font-weight: 700;
  margin: 0.5rem 0 1rem;
}

h2 {
  font-size: 1.5rem;
  margin: 3rem 0 1rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

h3 {
  font-size: 1.2rem;
  margin: 2.25rem 0 0.75rem;
}

h4 {
  font-size: 1rem;
  margin: 1.75rem 0 0.5rem;
}

/* Hover anchors on linkable headings */
h2 > a,
h3 > a {
  color: inherit;
}

h2 > a:hover,
h3 > a:hover {
  text-decoration: none;
}

h2 > a:hover::after,
h3 > a:hover::after {
  content: " #";
  color: var(--accent);
}

p,
ul,
ol {
  margin: 0 0 1rem;
}

li {
  margin: 0.25rem 0;
}

hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2.5rem 0;
}

strong {
  color: var(--fg);
  font-weight: 600;
}

.lead {
  font-size: 1.125rem;
  color: var(--fg-2);
  margin-bottom: 2rem;
}

/* ---------------------------------------------------------------- navbar */

.navbar {
  position: sticky;
  top: 0;
  z-index: 10;
  height: var(--nav-h);
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

@supports not (background: color-mix(in srgb, red 50%, blue)) {
  .navbar {
    background: var(--bg);
  }
}

.navbar__inner {
  max-width: var(--site-w);
  height: 100%;
  margin-inline: auto;
  padding-inline: 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.navbar__brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 700;
  font-size: 1rem;
  color: var(--fg);
}

.navbar__brand:hover {
  text-decoration: none;
}

.navbar__logo {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  display: block;
}

.navbar__version {
  font: 600 11px/1 var(--font-mono);
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 4px 8px;
}

.navbar__spacer {
  flex: 1;
}

.navbar__links {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  font-size: 0.875rem;
}

.navbar__links a {
  color: var(--fg-2);
}

.navbar__links a:hover {
  color: var(--fg);
  text-decoration: none;
}

.theme-toggle,
.menu-toggle {
  appearance: none;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--fg-2);
  width: 2rem;
  height: 2rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.theme-toggle:hover,
.menu-toggle:hover {
  color: var(--fg);
  border-color: var(--border-strong);
}

.theme-toggle svg,
.menu-toggle svg {
  width: 16px;
  height: 16px;
}

.theme-toggle .icon-sun,
:root[data-theme="light"] .theme-toggle .icon-moon {
  display: none;
}

:root[data-theme="light"] .theme-toggle .icon-sun {
  display: block;
}

.menu-toggle {
  display: none;
}

/* ---------------------------------------------------------------- layout */

.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  max-width: var(--site-w);
  margin-inline: auto;
  min-height: calc(100vh - var(--nav-h));
}

.sidebar {
  background: var(--bg-alt);
  border-right: 1px solid var(--border);
  padding: 1.5rem 1rem 3rem;
  position: sticky;
  top: var(--nav-h);
  max-height: calc(100vh - var(--nav-h));
  overflow-y: auto;
  font-size: 0.875rem;
}

.sidebar__section {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--fg-3);
  margin: 1.5rem 0 0.4rem;
  padding-inline: 10px;
}

.sidebar__section:first-child {
  margin-top: 0;
}

.sidebar a {
  display: block;
  color: var(--fg-2);
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  line-height: 1.5;
}

.sidebar a:hover {
  color: var(--fg);
  text-decoration: none;
}

.sidebar a.is-active {
  color: var(--accent);
  background: var(--accent-soft);
  font-weight: 600;
}

.page {
  display: grid;
  grid-template-columns: minmax(0, var(--content-w)) var(--toc-w);
  gap: 3.5rem;
  justify-content: center;
  padding: 2.5rem 2rem 4rem;
  width: 100%;
}

.content {
  min-width: 0;
}

/* On this page */
.toc {
  font-size: 13px;
  line-height: 1.6;
}

.toc__inner {
  position: sticky;
  top: calc(var(--nav-h) + 2rem);
  max-height: calc(100vh - var(--nav-h) - 4rem);
  overflow-y: auto;
}

.toc__title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--fg-3);
  margin-bottom: 0.6rem;
}

.toc ul {
  list-style: none;
  margin: 0;
  padding: 0 0 0 1rem;
  border-left: 1px solid var(--border);
}

.toc li {
  margin: 0.35rem 0;
}

.toc a {
  color: var(--fg-2);
  display: block;
}

.toc a:hover {
  color: var(--fg);
  text-decoration: none;
}

.toc li.toc--h3 {
  padding-left: 0.85rem;
}

/* Reading position (docs.js): the bar rides the list's left rule and spans
   the sections on screen; their entries lift from fg-2 to fg. */
.toc ul {
  position: relative;
}

.toc__marker {
  position: absolute;
  left: -1px;
  top: 0;
  width: 2px;
  height: 0;
  border-radius: 2px;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent-soft);
  opacity: 0;
  pointer-events: none;
}

.toc__marker--ready {
  transition: transform 0.28s cubic-bezier(0.2, 0.7, 0.2, 1),
    height 0.28s cubic-bezier(0.2, 0.7, 0.2, 1), opacity 0.2s;
}

.toc a {
  transition: color 0.2s;
}

.toc li.is-visible > a {
  color: var(--fg);
}

@media (prefers-reduced-motion: reduce) {
  .toc__marker--ready,
  .toc a {
    transition: none;
  }
}

.breadcrumbs {
  font-size: 13px;
  color: var(--fg-3);
  margin-bottom: 0.25rem;
}

.breadcrumbs a {
  color: var(--fg-3);
}

.breadcrumbs a:hover {
  color: var(--fg-2);
}

.breadcrumbs .sep {
  margin-inline: 0.4rem;
}

/* ------------------------------------------------------------------ code */

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

p code,
li code,
td code,
h1 code,
h2 code,
h3 code,
h4 code,
.callout code,
figcaption code {
  background: var(--inline-code-bg);
  padding: 0.15em 0.4em;
  border-radius: 4px;
}

.code {
  margin: 1.25rem 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-alt);
  overflow: hidden;
}

.code > figcaption {
  display: flex;
  align-items: center;
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--border);
  font: 12px/1.4 var(--font-mono);
  color: var(--fg-2);
}

.code pre {
  margin: 0;
  padding: 1rem 1.25rem;
  overflow-x: auto;
  line-height: 1.7;
}

.code pre code {
  font-size: 0.875rem;
  background: none;
  padding: 0;
}

.code {
  position: relative;
}

.code__copy {
  position: absolute;
  top: 8px;
  right: 8px;
  appearance: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elev);
  color: var(--fg-2);
  font: 12px var(--font-sans);
  padding: 4px 10px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 120ms ease;
}

.code:hover .code__copy,
.code__copy:focus-visible {
  opacity: 1;
}

.code__copy:hover {
  color: var(--fg);
  border-color: var(--border-strong);
}

.code--titled .code__copy {
  top: 5px;
}

/* Baked-in syntax tokens */
.tk-c { color: var(--tok-c); font-style: italic; }
.tk-k { color: var(--tok-k); }
.tk-s { color: var(--tok-s); }
.tk-t { color: var(--tok-t); }
.tk-f { color: var(--tok-f); }
.tk-n { color: var(--tok-n); }

.code .hl {
  display: block;
  background: var(--accent-soft);
  box-shadow: inset 3px 0 0 var(--accent-strong);
  margin-inline: -1.25rem;
  padding-inline: 1.25rem;
}

/* -------------------------------------------------------------- callouts */

.callout {
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  font-size: 0.875rem;
  line-height: 1.7;
  margin: 1.25rem 0;
  background: var(--accent-soft);
}

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

.callout__title {
  font-weight: 600;
  margin-bottom: 0.35rem;
  color: var(--accent);
}

.callout--tip {
  background: var(--green-soft);
}

.callout--tip .callout__title {
  color: var(--green);
}

.callout--warn {
  background: var(--yellow-soft);
}

.callout--warn .callout__title {
  color: var(--yellow);
}

.callout--danger {
  background: var(--red-soft);
}

.callout--danger .callout__title {
  color: var(--red);
}

/* ----------------------------------------------------------------- cards */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
  margin: 1.5rem 0;
}

.card {
  display: block;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  color: var(--fg);
  transition: border-color 150ms ease, transform 150ms ease;
}

.card:hover {
  text-decoration: none;
  border-color: var(--accent-strong);
  transform: translateY(-1px);
}

.card svg {
  width: 20px;
  height: 20px;
  color: var(--accent);
  margin-bottom: 0.6rem;
}

.card h3 {
  font-size: 1rem;
  margin: 0 0 0.35rem;
}

.card p {
  font-size: 0.875rem;
  color: var(--fg-2);
  margin: 0;
  line-height: 1.6;
}

/* ----------------------------------------------------------------- steps */

.steps {
  list-style: none;
  counter-reset: step;
  margin: 1.5rem 0;
  padding: 0;
}

.steps > li {
  counter-increment: step;
  position: relative;
  padding: 0 0 1.75rem 3rem;
  margin: 0;
}

.steps > li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  color: var(--fg);
  font: 600 13px/26px var(--font-sans);
  text-align: center;
}

.steps > li::after {
  content: "";
  position: absolute;
  left: 13.5px;
  top: 34px;
  bottom: 4px;
  width: 1px;
  background: var(--border);
}

.steps > li:last-child::after {
  display: none;
}

.steps > li > strong:first-child {
  display: block;
  margin-bottom: 0.25rem;
}

/* ------------------------------------------------------------- reference */

.pill {
  display: inline-block;
  font: 600 11px/1 var(--font-sans);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 3px 8px;
  border-radius: 999px;
  vertical-align: 2px;
  margin-right: 0.35rem;
}

/* Single-letter chips in member tables; data-tip spells the kind out on hover. */
.pill[data-tip] {
  width: 20px;
  height: 20px;
  padding: 0;
  border-radius: 6px;
  font-size: 11px;
  line-height: 20px;
  text-align: center;
  letter-spacing: 0;
  cursor: help;
}

.pill[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  left: calc(100% + 6px);
  top: 50%;
  transform: translateY(-50%);
  z-index: 2;
  padding: 3px 8px;
  border-radius: 6px;
  border: 1px solid var(--border-strong);
  background: var(--bg-elev);
  color: var(--fg);
  font-size: 12px;
  font-weight: 500;
  text-transform: none;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.12s;
}

.pill[data-tip]:hover::after {
  opacity: 1;
  visibility: visible;
}

.pill--method { background: var(--accent-soft); color: var(--accent); }
.pill--prop { background: var(--green-soft); color: var(--green); }
.pill--event { background: var(--yellow-soft); color: var(--yellow); }
.pill--class { background: var(--inline-code-bg); color: var(--fg-2); }
.pill--enum { background: var(--red-soft); color: var(--red); }
.pill--ext { background: var(--accent-soft); color: var(--accent); }

.member {
  margin: 2rem 0;
}

.member > h3,
.member > h4 {
  margin-bottom: 0.5rem;
}

.member > h3 code,
.member > h4 code {
  background: none;
  padding: 0;
  font-size: 0.95em;
}

.table-wrap {
  overflow-x: auto;
  margin: 1.25rem 0;
}

table.api {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.875rem;
  line-height: 1.6;
}

table.api th {
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--fg-3);
  font-weight: 600;
  padding: 0.5rem 1rem 0.5rem 0;
  border-bottom: 1px solid var(--border-strong);
}

table.api td {
  padding: 0.55rem 1rem 0.55rem 0;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

/* Member column. Short signatures never wrap. Long ones are pre-split into
   unbreakable runs (<code class="sig"><span>run</span> <span>run</span>) at
   the preferred points - after the return type first, then after top-level
   commas - so the browser can only break where a human would. Continuation
   lines hang-indent under the first. */
table.api td:first-child code {
  white-space: nowrap;
}

/* Descriptions never collapse to a sliver; on a phone the table scrolls. */
table.api td:last-child:not(:first-child) {
  min-width: 14rem;
}

table.api td:first-child code.sig {
  display: inline-block;
  white-space: normal;
  padding-left: calc(6px + 2ch);
  text-indent: -2ch;
  max-width: 100%;
  box-sizing: border-box;
}

table.api td:first-child code.sig > span {
  white-space: nowrap;
}

/* The kind chip sits in a gutter of its own, so every signature in a table
   starts at the same x and wrapped lines never slide under the chip. */
table.api td.kind-cell {
  position: relative;
  padding-left: 1.85rem;
}

table.api td.kind-cell > .pill {
  position: absolute;
  left: 0;
  top: calc(0.55rem + 0.8em - 10px);
  margin: 0;
}

/* ------------------------------------------------------------------- kbd */

kbd {
  font: 0.75em var(--font-mono);
  padding: 2px 6px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--bg-elev);
  color: var(--fg);
}

/* --------------------------------------------------------------- figures */

.figure {
  margin: 1.5rem 0;
}

.figure img,
.figure video {
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: block;
}

.figure figcaption {
  font-size: 0.8125rem;
  color: var(--fg-3);
  margin-top: 0.5rem;
  line-height: 1.6;
}

.figure__slot {
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg-alt);
  color: var(--fg-3);
  font-size: 0.875rem;
  padding: 3rem 1.5rem;
  text-align: center;
}

/* ----------------------------------------------------------- hero & btns */

.hero {
  padding: 2.5rem 0 1rem;
  text-align: left;
}

.hero h1 {
  font-size: 3rem;
  letter-spacing: -0.02em;
  margin: 0 0 0.75rem;
}

.hero h1 .grad {
  background: linear-gradient(120deg, var(--accent) 20%, var(--accent-strong));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}

.hero p {
  font-size: 1.2rem;
  color: var(--fg-2);
  max-width: 34rem;
  margin-bottom: 1.75rem;
}

.btn {
  display: inline-block;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.55rem 1.4rem;
  border-radius: 999px;
  border: 1px solid transparent;
  margin-right: 0.6rem;
}

.btn:hover {
  text-decoration: none;
}

.btn--primary {
  background: var(--accent-strong);
  color: #fff;
}

.btn--primary:hover {
  filter: brightness(1.1);
}

.btn--ghost {
  border-color: var(--border-strong);
  color: var(--fg);
}

.btn--ghost:hover {
  border-color: var(--accent-strong);
  color: var(--accent);
}

/* ----------------------------------------------------------- prev / next */

.pagenav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-top: 3.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.pagenav a {
  display: block;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1.1rem;
  color: var(--accent);
  font-weight: 600;
  font-size: 0.95rem;
  transition: border-color 150ms ease;
}

.pagenav a:hover {
  text-decoration: none;
  border-color: var(--accent-strong);
}

.pagenav a span {
  display: block;
  font: 400 12px var(--font-sans);
  color: var(--fg-3);
  margin-bottom: 0.15rem;
}

.pagenav__next {
  grid-column: 2;
  text-align: right;
}

.pagenav__prev {
  grid-column: 1;
}

/* ---------------------------------------------------------------- footer */

.footer {
  border-top: 1px solid var(--border);
  margin-top: 3rem;
  padding: 1.5rem 0 0;
  font-size: 0.8125rem;
  color: var(--fg-3);
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.footer a {
  color: var(--fg-3);
}

.footer a:hover {
  color: var(--fg-2);
}

/* ------------------------------------------------------------ responsive */

@media (max-width: 1150px) {
  .page {
    grid-template-columns: minmax(0, var(--content-w));
  }

  .toc {
    display: none;
  }
}

@media (max-width: 860px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    z-index: 9;
    top: var(--nav-h);
    left: 0;
    bottom: 0;
    width: min(var(--sidebar-w), 84vw);
    max-height: none;
    transform: translateX(-100%);
    transition: transform 180ms ease;
    box-shadow: var(--shadow-card);
  }

  body.nav-open .sidebar {
    transform: translateX(0);
  }

  .menu-toggle {
    display: inline-flex;
  }

  .navbar__links a {
    display: none;
  }

  .page {
    padding-inline: 1.25rem;
  }

  .hero h1 {
    font-size: 2.25rem;
  }

  h1 {
    font-size: 1.875rem;
  }

  .pagenav {
    grid-template-columns: 1fr;
  }

  .pagenav__next {
    grid-column: 1;
  }
}
