/* Base: tokens, typography, chrome, and the scrollbars.
   The palette is defined once per role with light-dark(), so the light and dark
   sets cannot drift apart; the theme switch only changes color-scheme. */

:root {
  color-scheme: light dark;

  --paper: light-dark(#e8e7e2, #08090b);
  --paper-2: light-dark(#dedcd5, #0c0e11);
  --panel: light-dark(#f3f2ee, #101317);
  --panel-2: light-dark(#e2e0da, #161a1f);
  --ink: light-dark(#121417, #e9e8e3);
  --ink-2: light-dark(#50565c, #9ba2a8);
  --ink-3: light-dark(#7b8187, #6d757c);
  --line: light-dark(#c9c7c0, #232830);
  --line-2: light-dark(#a8a69f, #333a43);
  --amber: light-dark(#a85c00, #ffab2e);
  --amber-2: light-dark(#d97800, #ffc46b);
  --signal: light-dark(#0c6b56, #34d6a6);
  --alarm: light-dark(#a8271b, #ff6b57);
  --grid: light-dark(rgba(18, 20, 23, 0.055), rgba(233, 232, 227, 0.055));

  --shadow: 0 1px 0 light-dark(rgba(255, 255, 255, 0.6), rgba(255, 255, 255, 0.03)),
    0 18px 40px -28px light-dark(rgba(18, 20, 23, 0.45), rgba(0, 0, 0, 0.9));

  --font-display: "Archivo", "Helvetica Neue", Arial, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;

  --page: 1280px;
  --gut: clamp(18px, 4vw, 56px);
  --bar: 62px;
  --r: 2px;

  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
}

/* light-dark() resolves against the used colour scheme, so the switch has
   nothing to restate but the scheme itself. */
:root[data-theme="light"] {
  color-scheme: light;
}

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

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  background: var(--paper);
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: var(--font-display);
  font-size: 16.5px;
  line-height: 1.66;
  font-synthesis-weight: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  /* Decorative chrome is not selectable; prose and code opt back in below. */
  user-select: none;
}

/* Canvas and inline graphics are plates rather than prose, so they also refuse
   the browser's own drag-and-drop; otherwise a stray drag leaves a ghost image
   and a "copy image" cursor over the page. */
img,
svg,
canvas {
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
}

/* --- scrollbars --------------------------------------------------------- */

@supports selector(::-webkit-scrollbar) {
  html::-webkit-scrollbar {
    width: 11px;
    height: 11px;
  }
  html::-webkit-scrollbar-track {
    background: transparent;
  }
  html::-webkit-scrollbar-thumb {
    border-radius: 99px;
    border: 3px solid transparent;
    background-clip: content-box;
    background-color: color-mix(in srgb, var(--ink) 26%, transparent);
  }
  html::-webkit-scrollbar-thumb:hover {
    background-color: color-mix(in srgb, var(--ink) 44%, transparent);
  }
  html.at-top::-webkit-scrollbar-thumb {
    background-color: transparent;
  }

  /* Inner scrollers: a fine rule that darkens under the pointer. */
  .scroll::-webkit-scrollbar,
  pre::-webkit-scrollbar,
  .table-wrap::-webkit-scrollbar,
  .api-nav::-webkit-scrollbar {
    width: 9px;
    height: 9px;
  }
  .scroll::-webkit-scrollbar-track,
  pre::-webkit-scrollbar-track,
  .table-wrap::-webkit-scrollbar-track,
  .api-nav::-webkit-scrollbar-track {
    background: transparent;
  }
  .scroll::-webkit-scrollbar-thumb,
  pre::-webkit-scrollbar-thumb,
  .table-wrap::-webkit-scrollbar-thumb,
  .api-nav::-webkit-scrollbar-thumb {
    border-radius: 99px;
    border: 2px solid transparent;
    background-clip: content-box;
    background-color: color-mix(in srgb, var(--ink) 14%, transparent);
  }
  .scroll:hover::-webkit-scrollbar-thumb,
  pre:hover::-webkit-scrollbar-thumb,
  .table-wrap:hover::-webkit-scrollbar-thumb,
  .api-nav:hover::-webkit-scrollbar-thumb {
    background-color: color-mix(in srgb, var(--ink) 34%, transparent);
  }
}

@supports not selector(::-webkit-scrollbar) {
  html {
    scrollbar-width: thin;
    scrollbar-color: color-mix(in srgb, var(--ink) 26%, transparent) transparent;
  }
  html.at-top {
    scrollbar-color: transparent transparent;
  }
}

/* --- selection ---------------------------------------------------------- */

.prose,
.prose *,
pre,
pre *,
code,
.api-entry,
.api-entry *,
.sel,
.sel *,
p,
li,
dt,
dd,
th,
td,
h1,
h2,
h3,
h4,
blockquote,
input,
textarea {
  user-select: text;
}

::selection {
  background: color-mix(in srgb, var(--amber) 32%, transparent);
  color: var(--ink);
}

/* --- type --------------------------------------------------------------- */

h1,
h2,
h3,
h4 {
  font-weight: 600;
  letter-spacing: -0.025em;
  line-height: 1.06;
  margin: 0;
  text-wrap: balance;
}

p {
  margin: 0 0 1em;
}

a {
  color: inherit;
  text-decoration-color: color-mix(in srgb, var(--amber) 60%, transparent);
  text-underline-offset: 0.22em;
  text-decoration-thickness: 1px;
}

a:hover {
  text-decoration-color: var(--amber);
}

code,
kbd,
samp,
pre {
  font-family: var(--font-mono);
  font-size: 0.88em;
  font-variant-ligatures: no-contextual;
}

html,
button,
input,
textarea,
select {
  font-variant-ligatures: no-contextual;
}

:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 3px;
}

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

/* --- micro label and rules ---------------------------------------------- */

.tag {
  display: inline-flex;
  align-items: center;
  gap: 0.6em;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-2);
}

.tag::before {
  content: "";
  width: 22px;
  height: 1px;
  background: var(--amber);
}

.tag[data-plain]::before {
  display: none;
}

.num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

/* --- top bar ------------------------------------------------------------ */

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--bar);
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 var(--gut);
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper) 86%, transparent);
  backdrop-filter: blur(12px) saturate(1.2);
}

@supports not (backdrop-filter: blur(2px)) {
  .topbar {
    background: var(--paper);
  }
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  text-decoration: none;
  flex: none;
}

.brand svg {
  width: 26px;
  height: 26px;
  display: block;
  color: var(--amber);
}

.brand b {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.16em;
}

.brand i {
  font-family: var(--font-mono);
  font-style: normal;
  font-size: 10px;
  letter-spacing: 0.12em;
  color: var(--ink-3);
  padding-left: 10px;
  border-left: 1px solid var(--line);
}

.nav {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-left: auto;
}

.nav a {
  display: inline-flex;
  align-items: center;
  height: 32px;
  padding: 0 12px;
  font-size: 13.5px;
  color: var(--ink-2);
  text-decoration: none;
  border: 1px solid transparent;
  border-radius: var(--r);
  transition: color 0.18s var(--ease), border-color 0.18s var(--ease);
}

.nav a:hover {
  color: var(--ink);
}

.nav a[aria-current="page"] {
  color: var(--ink);
  border-color: var(--line-2);
  background: color-mix(in srgb, var(--panel) 80%, transparent);
}

.nav .repo {
  padding: 0 8px;
  margin-left: 4px;
}

.nav svg {
  width: 17px;
  height: 17px;
  display: block;
}

.theme-toggle {
  flex: none;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  color: var(--ink-2);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--r);
  cursor: pointer;
  transition: color 0.18s var(--ease), border-color 0.18s var(--ease);
}

.theme-toggle:hover {
  color: var(--ink);
  border-color: var(--line-2);
}

.theme-toggle svg {
  width: 16px;
  height: 16px;
  grid-area: 1 / 1;
}

.theme-toggle .moon {
  display: none;
}

:root[data-theme="dark"] .theme-toggle .moon {
  display: block;
}

:root[data-theme="dark"] .theme-toggle .sun {
  display: none;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .moon {
    display: block;
  }
  :root:not([data-theme="light"]) .theme-toggle .sun {
    display: none;
  }
}

/* --- page frame --------------------------------------------------------- */

.shell {
  max-width: var(--page);
  margin: 0 auto;
  padding: 0 var(--gut);
}

main {
  display: block;
}

.foot {
  border-top: 1px solid var(--line);
  margin-top: clamp(72px, 10vw, 140px);
  padding: 46px 0 54px;
  background: var(--paper-2);
}

.foot-in {
  max-width: var(--page);
  margin: 0 auto;
  padding: 0 var(--gut);
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr) minmax(0, 1fr);
  gap: 32px;
}

.foot h3 {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-bottom: 14px;
  font-weight: 500;
}

.foot ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
  font-size: 14px;
}

.foot a {
  color: var(--ink-2);
  text-decoration: none;
}

.foot a:hover {
  color: var(--ink);
}

.foot .brand {
  margin-bottom: 14px;
}

.foot p {
  color: var(--ink-3);
  font-size: 13px;
  max-width: 34ch;
}

@media (width <= 780px) {
  :root {
    --bar: 56px;
  }

  .topbar {
    gap: 10px;
    padding: 0 14px;
  }

  .brand {
    gap: 8px;
  }

  .brand b {
    font-size: 13px;
    letter-spacing: 0.12em;
  }

  .brand i {
    display: none;
  }

  .nav a {
    height: 30px;
    padding: 0 7px;
    font-size: 12.5px;
  }

  .nav .repo {
    padding: 0 4px;
    margin-left: 0;
  }

  .foot-in {
    grid-template-columns: minmax(0, 1fr);
    gap: 28px;
  }
}

/* Below this width the four page links, the repository icon and the theme
   switch take the whole bar, so the wordmark gives way to the mark alone. */
@media (width <= 620px) {
  .brand b {
    display: none;
  }

  .nav a {
    padding: 0 6px;
    font-size: 12px;
  }
}

@media (width <= 380px) {
  .topbar {
    padding: 0 10px;
  }

  .nav a {
    padding: 0 4px;
    font-size: 11.5px;
  }

  .nav .repo {
    padding: 0 2px;
  }
}

/* --- buttons ------------------------------------------------------------ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.6em;
  height: 44px;
  padding: 0 20px;
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.01em;
  color: var(--paper);
  background: var(--ink);
  border: 1px solid var(--ink);
  border-radius: var(--r);
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.16s var(--ease), background 0.16s var(--ease);
}

.btn:hover {
  transform: translateY(-1px);
  color: var(--paper);
}

.btn.ghost {
  color: var(--ink);
  background: transparent;
  border-color: var(--line-2);
}

.btn.ghost:hover {
  border-color: var(--ink-2);
  background: color-mix(in srgb, var(--ink) 5%, transparent);
}

.btn svg {
  width: 15px;
  height: 15px;
}

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

pre {
  margin: 0;
  padding: 18px 20px 20px;
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  color: var(--ink);
  font-size: 13px;
  line-height: 1.72;
  tab-size: 2;
  white-space: pre;
}

pre code {
  font-size: inherit;
  background: none;
  padding: 0;
  border: 0;
}

:not(pre) > code {
  padding: 0.14em 0.38em;
  background: color-mix(in srgb, var(--ink) 7%, transparent);
  border-radius: 3px;
  overflow-wrap: anywhere;
}

.code-block {
  position: relative;
}

.code-block .copy {
  position: absolute;
  top: 8px;
  right: 8px;
  height: 26px;
  padding: 0 9px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-3);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 2px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.16s var(--ease), color 0.16s var(--ease);
}

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

.code-block .copy:hover {
  color: var(--ink);
  border-color: var(--line-2);
}

/* token colours, applied by site.js */
.tk-k {
  color: light-dark(#8a2f6b, #ff8fc4);
}
.tk-t {
  color: light-dark(#0b5f74, #5fd7ea);
}
.tk-s {
  color: light-dark(#0a6b3f, #74d99f);
}
.tk-c {
  color: var(--ink-3);
  font-style: italic;
}
.tk-n {
  color: light-dark(#8a4b00, #ffbe6a);
}
.tk-f {
  color: light-dark(#1d3fa8, #9db4ff);
}
