@font-face {
  font-family: 'IBM Plex Mono';
  src: url('/assets/IBMPlexMono-Regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light dark;
  --fg: light-dark(#1f2328, #CED7E2);
  --muted: light-dark(#59636e, #94A5B8);
  --bg: light-dark(#ffffff, #1F242B);
  --bg-keyword: light-dark(#cf222e1f, #ff7b721f);
  --subtle: light-dark(#f8f8f8, #262D35);
  --code: light-dark(#eeeeee, #313B46);
  --highlight: light-dark(#ffffff, #465464);
  --border: light-dark(#e8e8e8, #363E47);
  --link: light-dark(#0969da, #4493f8);
  --flash: light-dark(#F8EFE2, #4B443B);
  --tok-comment: light-dark(#637080, #8296aa);
  --tok-keyword: light-dark(#cf222e, #ff7b72);
  --tok-string: light-dark(#0a3069, #a5d6ff);
  --tok-name: light-dark(#8250df, #d2a8ff);
  --tok-number: light-dark(#0550ae, #79c0ff);
}

:root[data-theme='light'] {
  color-scheme: light;
}

:root[data-theme='dark'] {
  color-scheme: dark;
}

.controls {
  position: fixed;
  top: 14px;
  right: 12px;
  z-index: 1;
  display: flex;
  gap: 8px;
  align-items: flex-start;
}

.theme-toggle {
  display: flex;
  gap: 2px;
  padding: 4px;
  border-radius: 999px;
  background: var(--code);
}

.theme-toggle button {
  display: grid;
  place-items: center;
  width: 32px;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--muted);
  cursor: pointer;
}

.theme-toggle button[aria-pressed='true'] {
  background: var(--highlight);
  color: var(--fg);
}

/* The icons draw with currentColor, which an <img> can't inherit, so they're masks */
.theme-toggle button::before {
  content: '';
  width: 16px;
  height: 16px;
  background: currentColor;
  mask: var(--icon) center / contain no-repeat;
}

.theme-toggle [data-theme-value='light'] {
  --icon: url('/assets/sun.svg');
}

.theme-toggle [data-theme-value='dark'] {
  --icon: url('/assets/moon.svg');
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 system-ui, -apple-system, 'Segoe UI', sans-serif;
}

strong {
  font-weight: 700;
}

main {
  max-width: 880px;
  margin: 0 auto;
  padding: 48px 24px 64px;
}

h1,
h2,
h3 {
  line-height: 1.25;
  margin: 1.75em 0 0.5em;
  font-weight: 600;
  border-radius: 0.05em;
}

h1 {
  font-size: 2.8em;
  font-weight: normal;
  margin-top: 0;
  margin-bottom: 1em;
}

h2 {
  font-size: 1.9em;
  margin-bottom: 0.8em;
  margin-top: 2.2em;
  counter-increment: count;
  display: flex;
  align-items: center;
}

h3 {
  font-size: 1.3em;
}

p,
ul,
ol,
blockquote,
pre,
table {
  margin: 0.5em 0 1.75em;
}

h2 + p {
  font-size: 1.15em;
}

ul,
ol {
  padding-left: 1em;
}

li {
  padding-left: 0.4em;
}

li + li {
  margin-top: 0.4em;
}

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

a:hover {
  text-decoration: underline;
}

blockquote {
  margin-left: 0;
  margin-bottom: 3rem;
  font-size: 1.4em;
  line-height: 1.75;
  color: var(--muted);
}

code,
pre {
  font-family: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--subtle);
  font-size: 0.9em;
  border: 1px solid var(--border);
}

code {
  padding: 0.05em 0.25em 0.1em;
  border-radius: 4px;
  overflow-wrap: anywhere;
}

pre > code {
  background: none;
  padding: 0;
  line-height: 1.6;
  border: none;
}

:not(pre) > code {
  white-space: break-spaces;
}

pre {
  padding: 2em;
  border-radius: 24px;
  overflow-x: auto;
}

pre code {
  font-size: inherit;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 12px 24px 12px 0;
  text-align: left;
  vertical-align: top;
}

th:last-child,
td:last-child {
  padding-right: 0;
}

th {
  font-weight: 600;
  font-size: 0.92em;
  code {
    font: inherit;
  }
}

td {
  border-top: 1px solid var(--border);
}

td:first-child code {
  /* white-space: nowrap; */
  color: var(--tok-keyword);
  background: none;
  border: none;
  padding: 0;
  font-size: 0.92em;
}

th:nth-child(1) {
  min-width: 200px;
}

th:nth-child(2) {
  min-width: 180px;
}

th:nth-child(3) {
  min-width: 180px;
}

/* Prism tokens from @11ty/eleventy-plugin-syntaxhighlight */
.token.comment,
.token.prolog,
.token.doctype {
  color: var(--tok-comment);
}

.token.keyword,
.token.tag,
.token.operator {
  color: var(--tok-keyword);
}

.token.string,
.token.attr-value,
.token.template-string {
  color: var(--tok-string);
}

.token.function,
.token.attr-name,
.token.class-name {
  color: var(--tok-name);
}

.token.number,
.token.boolean,
.token.property {
  color: var(--tok-number);
}

.token.punctuation {
  color: var(--muted);
}

:is(h2, h3)[id] {
  scroll-margin-top: 32px;
}

/* Focus moves to the heading only so Tab continues from it, so no ring */
:is(h2, h3)[tabindex='-1']:focus {
  outline: none;
}

/* A spread shadow, so the flash reaches past the text without shifting layout */
.heading-jump-target {
  animation: heading-jump-flash 1.2s ease-out;
}

@keyframes heading-jump-flash {
  from {
    background: var(--flash);
    box-shadow: 0 0 0 6px var(--flash);
  }
}

.toc {
  --toc-open-width: min(280px, calc(100vw - 118px));
  position: relative;
}

/* Inputs can't hold pseudo-elements, so the icon sits on the wrapper, over the input */
.toc::before {
  content: '';
  position: absolute;
  top: 9px;
  left: 12px;
  width: 16px;
  height: 16px;
  background: var(--muted);
  mask: url('/assets/list.svg') center / contain no-repeat;
  pointer-events: none;
}

.toc-input {
  width: 92px;
  height: 34px;
  padding: 0 14px 0 36px;
  border: 0;
  border-radius: 999px;
  background: var(--code);
  color: var(--fg);
  font: inherit;
  font-size: 0.9em;
  cursor: pointer;
  transition: width 0.2s ease;
}

.toc-input::placeholder {
  color: var(--muted);
}

.toc-input:focus {
  width: var(--toc-open-width);
  outline: 2px solid var(--link);
  outline-offset: -2px;
  cursor: text;
}

.toc-popup {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: var(--toc-open-width);
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  box-shadow: 0 2px 6px rgb(0 0 0 / 0.06);
  transform-origin: top;
  opacity: 0;
  scale: 0.96;
  visibility: hidden;
  transition: opacity 0.1s, scale 0.1s, visibility 0s 0.1s;
}

/* Waits out the input's 0.2s widening, then fades and scales in */
.toc-input[aria-expanded='true'] + .toc-popup {
  opacity: 1;
  scale: 1;
  visibility: visible;
  transition: opacity 0.15s ease-out 0.2s, scale 0.15s ease-out 0.2s, visibility 0s 0.2s;
}

.toc-list li[hidden] {
  display: none;
}

/*
The list scrolls, not the popup, so the scrollbar sits inside the popup's padding,
clear of its rounded corners.
*/
.toc-list {
  max-height: min(70vh, 520px);
  margin: 0;
  padding: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  list-style: none;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.toc-list li {
  margin: 0;
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9em;
}

.toc-list .toc-sub {
  padding-left: 22px;
  color: var(--muted);
}

.toc-list li:hover {
  background: var(--subtle);
}

.toc-list li[aria-selected='true'] {
  background: var(--code);
  color: var(--fg);
}

.toc-empty {
  margin: 0;
  padding: 4px 8px;
  color: var(--muted);
}

@media (prefers-reduced-motion: reduce) {
  .toc-input,
  .toc-popup,
  .toc-input[aria-expanded='true'] + .toc-popup {
    transition: none;
  }
}
