/* Critical CSS — applied before the Tailwind bundle arrives so the article
 * body is never rendered unstyled (the "splash" users saw on navigation).
 *
 * Keep this in sync with the prose / base / shiki rules in
 * `app/styles.css`. Tailwind utilities override these once the JS bundle
 * finishes loading; this file only needs to make the page look
 * presentable on the very first paint.
 *
 * If you change a value here, change the matching rule in styles.css.
 * If you only change a value in styles.css, also update this file.
 *
 * IMPORTANT: this file must reference the SAME CSS variable names as
 * `app/styles.css` (`--color-text`, `--color-bg`, `--color-code-bg`,
 * etc.). Earlier this file used a different prefix (`--c-text`) with
 * hardcoded light fallbacks, which broke dark mode — the fallbacks
 * fired and the prose rendered with the light-theme color in dark
 * mode. Now both files read from the same `--color-*` tokens.
 *
 * The prose font sizes read from `--prose-*` tokens defined in the
 * inlined THEME_TOKENS block (app/routes/_renderer.tsx). That block is
 * the single source of truth for the type scale, so the size values
 * here and in styles.css can never drift.
 */

html,
body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Reserve the scrollbar gutter always. The site styles ::-webkit-scrollbar with
 * a fixed width, so the vertical scrollbar occupies layout width instead of
 * overlaying; without a stable gutter it appears on long pages and vanishes on
 * short ones, shifting the full-width topbar horizontally on every navigation. */
html {
  scrollbar-gutter: stable;
}

* {
  scrollbar-color: var(--color-border-strong) transparent;
}
*::-webkit-scrollbar {
  width: 0.75rem;
  height: 0.75rem;
}
*::-webkit-scrollbar-track {
  background: transparent;
}
*::-webkit-scrollbar-thumb {
  background-color: var(--color-border-strong);
  background-clip: content-box;
  border: 3px solid transparent;
  border-radius: 999px;
}
*::-webkit-scrollbar-thumb:hover {
  background-color: var(--color-text-faint);
}

header.topbar-critical {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  height: 56px;
  padding: 0 1.5rem;
  border-bottom: 1px solid var(--color-border);
  background: color-mix(in srgb, var(--color-bg) 85%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 30;
}
header.topbar-critical .logo-mark {
  width: 24px;
  height: 24px;
  flex: none;
  display: block;
}

.topic-scroll-frame {
  position: relative;
}
.topic-scroll-frame::before,
.topic-scroll-frame::after {
  content: "";
  position: absolute;
  top: 50%;
  z-index: 1;
  width: 0;
  height: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.topic-scroll-frame::before {
  left: -0.55rem;
  border-top: 0.28rem solid transparent;
  border-right: 0.38rem solid var(--color-text-faint);
  border-bottom: 0.28rem solid transparent;
  transform: translateY(-50%);
}
.topic-scroll-frame::after {
  right: -0.55rem;
  border-top: 0.28rem solid transparent;
  border-bottom: 0.28rem solid transparent;
  border-left: 0.38rem solid var(--color-text-faint);
  transform: translateY(-50%);
}
@media (max-width: 1023.98px) {
  .topic-scroll-frame[data-scroll-left]::before,
  .topic-scroll-frame[data-scroll-right]::after {
    opacity: 0.45;
  }
}

.prose {
  color: var(--color-text);
  font-size: var(--prose-text-size);
  line-height: 1.7;
}
.prose > * + * {
  margin-top: 1.1em;
}
.prose p + p {
  margin-top: 1.1em;
}
/* A paragraph after a list: `.prose p { margin: 0 }` zeroes its top margin and
   `.prose p + p` only matches a paragraph after a paragraph, so a paragraph
   following a list (which carries `margin: 0`) would butt against the last
   bullet. Restore the rhythm. */
.prose ul + p,
.prose ol + p {
  margin-top: 1.1em;
}
.prose h1 {
  --heading-anchor-line: 1.2;
  position: relative;
  font-size: var(--prose-h1-size);
  line-height: 1.2;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 0.6em;
  color: var(--color-text);
  scroll-margin-top: calc(var(--topbar-height, 3.5rem) + 1.5rem);
}
.prose h2 {
  --heading-anchor-line: 1.3;
  position: relative;
  font-size: var(--prose-h2-size);
  line-height: 1.3;
  font-weight: 600;
  letter-spacing: -0.015em;
  margin: 2em 0 0.6em;
  padding-top: 0.4em;
  color: var(--color-text);
  scroll-margin-top: calc(var(--topbar-height, 3.5rem) + 1.5rem);
}
.prose h3 {
  --heading-anchor-line: 1.4;
  position: relative;
  font-size: var(--prose-h3-size);
  line-height: 1.4;
  font-weight: 600;
  margin: 1.6em 0 0.4em;
  color: var(--color-text);
  scroll-margin-top: calc(var(--topbar-height, 3.5rem) + 1.5rem);
}
.prose h4 {
  font-size: var(--prose-h4-size);
  line-height: 1.4;
  font-weight: 600;
  margin: 1.4em 0 0.4em;
  color: var(--color-text);
}
.prose :is(h1, h2, h3, h4, h5, h6) {
  font-family: var(--font-heading);
}
.prose p {
  margin: 0;
}
.prose a {
  color: var(--color-accent);
  text-decoration: none;
  font-weight: 500;
  border-bottom: 1px solid
    color-mix(in srgb, var(--color-accent) 30%, transparent);
  transition: border-color 0.15s ease;
}
.prose a:hover {
  border-bottom-color: var(--color-accent);
}
.prose a.heading-anchor {
  position: relative;
  color: inherit;
  font-weight: inherit;
  border-bottom: none;
}
.prose a.heading-anchor:hover {
  color: var(--color-accent);
}
/* Hang the permalink icon in the left margin, centered on the heading's FIRST
   line. The box is one line-height tall (--heading-anchor-line) anchored at
   top: 0, so a signature heading that wraps to several lines keeps the icon on
   the top line instead of dropping to the last. left/width and the glyph size
   are pinned to --prose-h3-size so horizontal placement and icon size stay
   uniform across h1/h2/h3 regardless of heading font-size. */
.heading-anchor-icon {
  position: absolute;
  top: 0;
  left: calc(-1.15 * var(--prose-h3-size));
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--prose-h3-size);
  height: calc(var(--heading-anchor-line, 1.4) * 1em);
  opacity: 0;
  color: var(--color-text-faint);
  transition: opacity 0.2s ease-in-out, color 0.2s ease-in-out;
}
.heading-anchor-icon svg {
  width: calc(0.85 * var(--prose-h3-size));
  height: calc(0.85 * var(--prose-h3-size));
}
.prose :is(h1, h2, h3):hover .heading-anchor-icon,
.heading-anchor:focus-visible .heading-anchor-icon {
  opacity: 1;
  color: var(--color-accent);
}
.prose a.badge-link {
  border-bottom: none;
}
.prose strong {
  font-weight: 600;
  color: var(--color-text);
}
.prose code {
  font-family: var(--font-mono);
  font-size: var(--prose-code-size);
  background: var(--color-code-bg);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  padding: 0.1em 0.35em;
  color: var(--color-text);
  /* Break space-less tokens so they can't force page-wide horizontal scroll on
     narrow screens. Mirrors app/styles.css. */
  overflow-wrap: anywhere;
}
/* If a signature code span is wrapped in a plain `.prose a`, the link underline
   already marks it: drop the inline-code border and padding so the chip chrome
   doesn't fight the underline. Excludes `a.heading-anchor` (the detail-heading
   permalink), which keeps its pill. Mirrors app/styles.css; unlayered here so
   it beats the unlayered `.prose code` rule above by specificity. */
.prose a:not(.heading-anchor) .api-signature {
  border-color: transparent;
  padding: 0;
}
.prose pre {
  font-family: var(--font-mono);
  font-size: var(--prose-pre-size);
  line-height: 1.55;
  background: var(--color-code-bg);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 14px 16px;
  overflow-x: auto;
  margin: 1.2em 0;
}
.prose pre code {
  background: transparent;
  border: 0;
  padding: 0;
  font-size: inherit;
  color: inherit;
}
/* Filename chip for `title="…"` fences; mirror of the layered rule in styles.css. */
.prose .code-block {
  margin: 1.2em 0;
}
.prose .code-title {
  font-family: var(--font-mono);
  font-size: var(--prose-code-title-size);
  color: var(--color-text-muted);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-bottom: 0;
  border-radius: 8px 8px 0 0;
  padding: 8px 16px;
}
.prose .code-block pre {
  margin: 0;
  border-top-left-radius: 0;
  border-top-right-radius: 0;
}
/* The CodeCopy island wraps each <pre> in a `.code-body` on hydration. The pre
   keeps its own margin (`.prose pre` 16.8px, or 0 inside a `.code-block`) and it
   collapses out through this zero-margin wrapper, so the block's box is
   unchanged — as long as the wrapper itself contributes no margin. When the
   wrapper IS a direct prose child it otherwise picks up the `.prose > * + *` owl
   (1.1em at the 17px base = 18.7px), overriding the collapse and growing the
   block; zero it so only the pre's margin shows. Must live here (unlayered): the
   styles.css mirror is in @layer components and loses to this file's owl.
   Do NOT zero `.code-body > pre` — a pre nested in a list produces a wrapper
   that is not a direct prose child, gets no compensating margin, and would lose
   its spacing entirely. */
.prose > .code-body {
  margin: 0;
}
.prose ul,
.prose ol {
  padding-left: 1.4em;
  margin: 0;
}
.prose ul {
  list-style: disc;
}
.prose ol {
  list-style: decimal;
}
.prose li {
  margin-top: 0.35em;
}
.prose li::marker {
  color: var(--color-text-faint);
}
.prose ul.not-prose {
  list-style: none;
  padding-left: 0;
}
/* Symmetric block margin like hr / admonition; a zero top would leave the
   blockquote butted against the element above it, because `.prose blockquote`
   out-specifies the `.prose > * + *` owl. Mirror of the layered rule. */
.prose blockquote {
  margin: 1.4em 0;
  padding: 0.4em 1em;
  border-left: 3px solid var(--color-border-strong);
  color: var(--color-text-muted);
  font-style: italic;
}
.prose hr {
  border: 0;
  border-top: 1px solid var(--color-border);
  margin: 2em 0;
}
.prose table {
  width: auto;
  max-width: 100%;
  border-collapse: collapse;
  font-size: var(--prose-table-size);
  margin: 1.2em 0;
}
.prose th,
.prose td {
  text-align: left;
  padding: 8px 16px;
  border-bottom: 1px solid var(--color-border);
}
.prose th {
  font-weight: 600;
  color: var(--color-text);
  background: var(--color-surface);
}
.prose .table-scroll {
  overflow-x: auto;
  max-width: 100%;
  margin: 1.2em 0;
}
.prose .table-scroll > table {
  margin: 0;
  max-width: none;
}
.prose .api-overview {
  margin: 1.2em 0;
}
.prose .api-overview ul {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  margin: 0;
  padding-left: 1.35rem;
}
.prose .api-overview li {
  margin: 0;
  padding-left: 0.1rem;
}
.prose .api-overview a {
  border-bottom: 0;
  text-decoration: none;
}
.prose .api-overview a:hover,
.prose .api-overview a:focus-visible {
  border-bottom: 0;
  text-decoration: none;
}
.prose .api-overview a .api-signature {
  padding: 0.04em 0.2em;
  border-color: transparent;
  background: color-mix(in srgb, var(--color-accent) 6%, var(--color-code-bg));
  font-size: 0.82em;
  line-height: 1.55;
}
.prose .api-overview a:hover .api-signature,
.prose .api-overview a:focus-visible .api-signature {
  background: var(--color-accent-soft);
}
.prose img {
  max-width: 100%;
  margin-top: 0.75rem;
  border-radius: 8px;
}

/* Shiki token spans pinned to the per-theme variable pair, with the per-line
 * `<span class="line">` background forced transparent so the surrounding
 * `.prose pre` background shows through. The `<pre>` itself is intentionally
 * not neutralized — keep in sync with `app/styles.css`.
 */
.shiki span:not(.line) {
  color: var(--shiki-light, currentColor);
  background-color: transparent;
}
html[data-theme="dark"] .shiki span:not(.line) {
  color: var(--shiki-dark, currentColor);
  background-color: transparent;
}
