/* Shared tokens, type, header, footer, code. See README. */
@layer reset, base, layout, components, page, motion, print;

@font-face {
  font-family: "Ferro Sans";
  src: url("../fonts/ferro-sans.woff2") format("woff2");
  font-weight: 300 700;
  font-stretch: 80% 100%;
  font-display: swap;
}
@font-face {
  font-family: "Ferro Sans Mono";
  src: url("../fonts/ferro-sans-mono.woff2") format("woff2");
  font-weight: 200 900;
  font-display: swap;
}
@font-face {
  font-family: "Ferro Sans Fallback";
  src: local("Arial"), local("Helvetica Neue"), local("Helvetica");
  size-adjust: 101.1%;
  ascent-override: 107.8%;
  descent-override: 31.7%;
  line-gap-override: 0%;
}
@font-face {
  font-family: "Ferro Display Fallback";
  src: local("Arial"), local("Helvetica Neue"), local("Helvetica");
  size-adjust: 82.2%;
  ascent-override: 132.6%;
  descent-override: 38.9%;
  line-gap-override: 0%;
}
@font-face {
  font-family: "Ferro Mono Fallback";
  src: local("Courier New"), local("Menlo");
  size-adjust: 103%;
  ascent-override: 105.8%;
  descent-override: 31.1%;
  line-gap-override: 0%;
}

:root {
  --night: #0c1014;
  --night-2: #151b21;
  --fg: oklch(.95 .006 85);
  --fg-2: oklch(.84 .010 250);
  --fg-3: oklch(.70 .012 250);
  --hair: oklch(1 0 0 / .1);
  --accent: #e8a13c;

  --t-13: .8125rem;
  --t-16: 1rem;
  --t-m: clamp(.8125rem, .789rem + .095vw, .875rem);
  --t-h3: clamp(1.125rem, 1.079rem + .19vw, 1.25rem);
  --t-h2: clamp(1.75rem, 1.564rem + .762vw, 2.25rem);
  --t-h1: clamp(2.5rem, 1.757rem + 3.048vw, 4.5rem);
  --t-h1-page: clamp(2rem, 1.629rem + 1.524vw, 3rem);
  --t-num: clamp(2.5rem, 2.129rem + 1.524vw, 3.5rem);
  --sans: "Ferro Sans", "Ferro Sans Fallback", system-ui, sans-serif;
  --display: "Ferro Sans", "Ferro Display Fallback", system-ui, sans-serif;
  --mono: "Ferro Sans Mono", "Ferro Mono Fallback", ui-monospace, monospace;

  --s-4: .25rem;
  --s-8: .5rem;
  --s-16: 1rem;
  --s-24: 1.5rem;
  --s-40: 2.5rem;
  --s-64: 4rem;
  --s-96: 6rem;
  --section: clamp(3.5rem, 2.5rem + 4vw, 6rem);
  --gutter: var(--s-16);
  --container: 1200px;
  --text: 38rem;
  --r: 6px;

  --ease: cubic-bezier(.25, 1, .5, 1);
  --hover: 150ms var(--ease-sheet);

  /* Motion: max 300 ms, no bounce. --spring: damped spring (w = 10). */
  --ease-out: cubic-bezier(.19, 1, .22, 1);
  --ease-sheet: cubic-bezier(.32, .72, 0, 1);
  --spring: var(--ease-out);
  --glide: 280ms;
  --glide-hover: 180ms;
  --press: 150ms;
  --pill: oklch(1 0 0 / .07);
  --pill-hover: oklch(1 0 0 / .04);

  color-scheme: dark;
}
@supports (animation-timing-function: linear(0, 1)) {
  :root { --spring: linear(0, .144, .385, .594, .746, .846, .909, .947, .97, .983, .991, .995, .997, .999, 1); }
}
/* Black pills on light bands. */
.paper { --pill: oklch(0 0 0 / .07); --pill-hover: oklch(0 0 0 / .04); }
@media (width >= 768px) { :root { --gutter: var(--s-24); } }
@media (width >= 1024px) { :root { --gutter: var(--s-40); } }

@layer reset {
  [hidden] { display: none !important; }
  *, *::before, *::after { box-sizing: border-box; }
  body, h1, h2, h3, h4, p, ol, ul, dl, dd, figure, pre, blockquote { margin: 0; }
  ol, ul { padding: 0; list-style: none; }
  img, svg, canvas { display: block; max-width: 100%; }
  button, input { font: inherit; color: inherit; }
  table { border-collapse: collapse; }
}

@layer base {
  html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
  @media (prefers-reduced-motion: no-preference) { html { scroll-behavior: smooth; } }
  body {
    background: var(--night);
    color: var(--fg);
    font-family: var(--sans);
    font-size: var(--t-16);
    line-height: 1.6;
    font-optical-sizing: auto;
    font-kerning: normal;
    -webkit-font-smoothing: antialiased;
    overflow-x: clip;
  }
  :target, [id] { scroll-margin-top: var(--s-64); }
  h1, h2, h3, h4 { text-wrap: balance; font-weight: 560; }
  h1 { font-family: var(--display); font-size: var(--t-h1-page); line-height: 1; font-weight: 600; font-stretch: 85%; letter-spacing: -0.02em; }
  h2 { font-size: var(--t-h2); line-height: 1.15; letter-spacing: -0.012em; }
  h3 { font-size: var(--t-h3); line-height: 1.35; }
  p, li, figcaption, dd, td { text-wrap: pretty; }
  code, pre, kbd, .n, .v { font-family: var(--mono); font-feature-settings: "ss10", "calt" 0; font-variant-ligatures: none; }
  code { font-size: .875em; }
  .nw, p > code { white-space: nowrap; }
  a {
    color: var(--fg);
    text-decoration-line: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: .2em;
    text-decoration-color: color-mix(in oklch, currentColor 45%, transparent);
    transition: color var(--hover), text-decoration-color 150ms ease;
    @media (hover: hover) { &:hover { text-decoration-color: currentColor; } }
  }
  a[target="_blank"]::after {
    content: ""; display: inline-block; width: .62em; height: .62em; margin-inline: .18em .04em;
    vertical-align: .08em; background: currentColor; opacity: .7;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 10' fill='none' stroke='%23000' stroke-width='1.4'%3E%3Cpath d='M2.5 7.5 8 2M3.5 2H8v4.5'/%3E%3C/svg%3E") center / contain no-repeat;
  }
  button { transition: scale var(--press) var(--ease-out); }
  :focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--r); animation: ring 150ms ease; }
  @keyframes ring { from { outline-offset: 0; } }
  ::selection { background: color-mix(in oklch, var(--accent) 35%, transparent); }
  .sr {
    position: absolute; width: 1px; height: 1px; overflow: hidden;
    clip-path: inset(50%); white-space: nowrap;
  }
  .defs { position: absolute; }
  .skip {
    position: absolute; left: var(--s-16); top: var(--s-16); z-index: 20;
    padding: var(--s-8) var(--s-16); background: var(--fg); color: var(--night);
    border-radius: var(--r); translate: 0 -200%;
    &:focus { translate: 0; }
  }
}

@layer layout {
  .wrap { width: min(var(--container), 100% - 2 * var(--gutter)); margin-inline: auto; }

  .top {
    position: relative; z-index: 3;
    display: flex; align-items: center; justify-content: space-between; gap: var(--s-16);
    padding-block: var(--s-16);
    view-transition-name: doc-top;
    nav { margin-inline-end: calc(-1 * var(--s-8)); }
    nav ul { display: flex; @media (width >= 600px) { gap: var(--s-8); } }
    nav a { padding: var(--s-4) var(--s-8); border-radius: var(--r); color: var(--fg-2); text-decoration: none; font-size: var(--t-m); white-space: nowrap; }
    @media (hover: hover) { nav a:hover { color: var(--fg); } }
  }
}

@layer components {
  .wordmark {
    display: inline-flex; align-items: center; gap: .4em;
    color: var(--fg); text-decoration: none; font-weight: 600; letter-spacing: -0.012em; line-height: 1.6;
    font-size: var(--t-h3);
  }
  .mark { fill: currentColor; flex: none; }
  .lede { font-size: var(--t-h3); line-height: 1.5; color: var(--fg-2); max-width: 52ch; }

  .copy {
    flex: none; border: 0; background: none; cursor: pointer;
    padding: var(--s-4) var(--s-8); font-size: var(--t-13); line-height: 1.5; color: var(--fg-3);
    border-radius: var(--r);
    transition: color 150ms ease, background-color 150ms ease, scale var(--press) var(--ease-out);
    @media (hover: hover) { &:hover { color: var(--fg); background: var(--night-2); } }
    &[data-state="done"] { color: var(--accent); }
    .sw { --rise: 2px; display: inline-block; animation: rise 150ms ease; }
  }
  @keyframes rise { from { opacity: 0; translate: 0 var(--rise, 8px); } }

  /* Pills: nav-pill.js sets --x --y --w --h; clip-path moves them. */
  [data-pill] { position: relative; isolation: isolate; }
  [data-pill]:not([data-pill-on]) a[aria-current] { background: var(--pill); }
  .pill {
    position: absolute; top: 0; left: 0; width: var(--pw, 100%); height: var(--ph, 100%); z-index: -1; pointer-events: none;
    background: var(--pill); opacity: var(--o, 0);
    clip-path: inset(var(--y) calc(100% - var(--x) - var(--w)) calc(100% - var(--y) - var(--h)) var(--x) round var(--r));
  }
  .pill-hov { background: var(--pill-hover); }
  [data-ready] .pill-cur:not(.pill-vt) { transition: clip-path var(--glide) var(--spring), opacity 150ms ease; }
  [data-ready] .pill-hov { transition: clip-path var(--glide-hover) var(--ease-out), opacity 150ms ease; }
  [data-ready] .pill.snap { transition: opacity 150ms ease; }

  pre {
    min-width: 0; overflow-x: auto;
    padding: var(--s-16) var(--s-24);
    background: var(--night-2); border: 1px solid var(--hair); border-radius: var(--r);
    font-size: var(--t-m); line-height: 1.6; tab-size: 4;
    .c { color: var(--fg); }
    .c::before { content: "$ "; color: var(--fg-3); user-select: none; }
    .o { color: var(--fg-3); }
    b { font-weight: 600; color: var(--fg); }
  }

  .foot {
    padding-block: var(--s-40); border-block-start: 1px solid var(--hair);
    font-size: var(--t-13); line-height: 1.6; color: var(--fg-3);
    > div { display: grid; gap: var(--s-40) var(--s-24); grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .foot-id { grid-column: 1 / -1; display: grid; gap: var(--s-8); align-content: start; }
    h2 { font-size: var(--t-13); line-height: 1.6; font-weight: 500; letter-spacing: 0; color: var(--fg-2); margin-block-end: var(--s-8); }
    ul { display: grid; gap: var(--s-8); }
    a { color: var(--fg-3); text-decoration: none; &:hover { color: var(--fg); } }
    .foot-id a { color: var(--fg-2); }
    @media (width >= 960px) {
      > div { grid-template-columns: repeat(12, minmax(0, 1fr)); }
      .foot-id { grid-column: 1 / span 6; }
      nav { grid-column: span 2; }
    }
  }
  .foot-mark { display: flex; align-items: center; gap: .45em; color: var(--fg); font-size: var(--t-16); margin-block-end: var(--s-8); }

}

/* Unlayered; elsewhere pages just load. */
@media (prefers-reduced-motion: no-preference) {
  @view-transition { navigation: auto; }
}

@layer motion {
  /* Between pages: header still, content cross-fades. */
  main { view-transition-name: doc-main; }
  @media (prefers-reduced-motion: no-preference) {
    ::view-transition-group(*) { animation-duration: 180ms; animation-timing-function: var(--ease); }
    ::view-transition-old(root), ::view-transition-new(root) { animation: none; }
    ::view-transition-old(doc-main) { animation: 120ms var(--ease) both fade-out; }
    ::view-transition-new(doc-main) { animation: 180ms var(--ease) both fade-in; }
    ::view-transition-group(doc-main) { animation-duration: 0s; }
  }
  @keyframes fade-out { to { opacity: 0; } }
  @keyframes fade-in { from { opacity: 0; } }
  /* Press: lists with their own transition include scale. */
  button:not(:disabled):active { scale: .97; }
  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition-duration: 0ms !important; animation: none !important; scroll-behavior: auto !important; }
    ::view-transition-group(*), ::view-transition-image-pair(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
  }
}

@media (prefers-contrast: more) {
  :root { --fg-2: var(--fg); --fg-3: var(--fg); --hair: var(--fg-3); }
}

@layer print {
  @media print {
    body, pre { background: #fff; color: #000; }
    .top nav, .copy, .skip { display: none; }
    a { color: inherit; }
    a[target="_blank"]::after { display: none; }
  }
}
