/* Reset, element defaults, the line-art system and motion primitives. */

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

* {
  margin: 0;
}

/* Scenes let art run past the edges. clip on both elements: html's value is
 * the one that goes to the viewport, so body's own clip then really clips.
 * clip (not hidden) makes no scroll container, so sticky stages still work. */
html {
  overflow-x: clip;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
  hanging-punctuation: first last;
}

body {
  min-height: 100svh;
  background: var(--color-bg);
  color: var(--color-ink);
  font-family: var(--font-body);
  font-size: var(--step-0);
  line-height: var(--leading-body);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: clip;
}

img,
svg,
video {
  display: block;
  max-width: 100%;
}

h1,
h2,
h3,
h4 {
  font-family: var(--font-display);
  font-weight: var(--display-weight);
  font-variation-settings: var(--display-variation);
  line-height: var(--leading-tight);
  text-wrap: balance;
}

p {
  text-wrap: pretty;
}

a {
  color: inherit;
  text-underline-offset: 0.2em;
  text-decoration-thickness: 1px;
}

button {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: 3px;
  border-radius: 4px;
}

::selection {
  background: color-mix(in oklab, var(--color-glow) 55%, transparent);
  color: var(--color-ink);
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  top: var(--space-s);
  left: var(--space-s);
  z-index: 100;
  padding: var(--space-2xs) var(--space-s);
  background: var(--color-surface);
  color: var(--color-ink);
  border-radius: var(--radius-pill);
  translate: 0 -200%;
}

.skip-link:focus {
  translate: 0 0;
}

/* ---------------------------------------------------------------------------
 * Line art
 *
 * Every drawing is stroked in currentColor (or --art-line). Every stroked
 * shape in the sprite carries pathLength="1", so a dash of length 1 covers
 * the whole shape and the drawing can be "drawn on" by moving
 * stroke-dashoffset from 1 to 0. Both properties inherit into <use> shadow
 * trees, which is what lets one rule animate a whole symbol.
 * ------------------------------------------------------------------------- */
.art {
  width: 100%;
  height: auto;
  overflow: visible;
  fill: none;
  stroke: var(--art-line, currentColor);
  stroke-width: var(--art-stroke, var(--line));
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* --glow-opacity is registered so it can transition, and so a calc() over
 * scroll progress computes to a plain number before it is inherited into
 * <use> shadow trees. */
@property --glow-opacity {
  syntax: "<number>";
  inherits: true;
  initial-value: 0;
}

/* Parts of a drawing, as classes inside the sprite's symbols. They are
 * matched on the element itself (never through an .art ancestor), because
 * <use> clones its symbol into a shadow tree that outer selectors cannot
 * reach; per-instance tuning comes in through inherited custom properties. */
.ln-a {
  stroke: var(--art-accent, var(--color-accent));
}
.ln-fine {
  stroke-width: calc(var(--art-stroke, var(--line)) * 0.6 / var(--ln-k, 1));
}
.ln-dot {
  fill: var(--art-line, currentColor);
  stroke: none;
}
.ln-dot-a {
  fill: var(--art-accent, var(--color-accent));
  stroke: none;
}
.ln-dot,
.ln-dot-a {
  opacity: var(--ln-fill-opacity, 1);
  transition: opacity var(--dur-slow) var(--ease-out) calc(var(--draw-delay, 0ms) + var(--dur-draw) * 0.6);
}
.ln-glow {
  fill: var(--art-glow, var(--color-glow));
  stroke: none;
  opacity: var(--glow-opacity, 0);
}
/* Paint: flat colour laid under a drawing's line work. Every slot is none
 * unless a scene sets its colour, so a drawing stays pure line art
 * everywhere else. What each slot paints is up to the drawing; its source
 * says which part is which. A scene can also outline the paint, for drawings
 * that are paint only: --art-paint-line outlines every slot, and
 * --art-shade-line and --art-light-line override it for those two. */
.ln-fill {
  fill: var(--art-fill, none);
  stroke: var(--art-paint-line, none);
}
.ln-shade {
  fill: var(--art-shade, none);
  stroke: var(--art-shade-line, var(--art-paint-line, none));
}
.ln-light {
  fill: var(--art-light, none);
  stroke: var(--art-light-line, var(--art-paint-line, none));
}
.ln-fill-2 {
  fill: var(--art-fill-2, none);
  stroke: var(--art-paint-line, none);
}
.ln-fill-a {
  fill: var(--art-fill-a, none);
  stroke: var(--art-paint-line, none);
}
.ln-smoke {
  stroke: var(--art-smoke, var(--art-line, currentColor));
  opacity: var(--smoke-opacity, 0.7);
}

/* Drawn on when it enters the viewport (forest.js adds .is-in). */
@media (scripting: enabled) and (prefers-reduced-motion: no-preference) {
  [data-draw] .art,
  .art[data-draw] {
    stroke-dasharray: 1 2;
    stroke-dashoffset: 1;
    --ln-fill-opacity: 0;
    transition: stroke-dashoffset var(--draw-duration, var(--dur-draw)) var(--ease-in-out) var(--draw-delay, 0ms);
  }
  [data-draw].is-in .art,
  .is-in > .art[data-draw],
  .art[data-draw].is-in {
    stroke-dashoffset: 0;
    --ln-fill-opacity: 1;
  }

  /* Drawn in step with scrolling: --p (0..1) comes from forest.js. */
  [data-draw="scroll"] .art,
  .art[data-draw="scroll"] {
    transition: none;
    stroke-dashoffset: calc(1 - var(--p, 0));
    --ln-fill-opacity: var(--p, 0);
  }
}

/* ---------------------------------------------------------------------------
 * Reveal: content rises in once when it enters the viewport.
 * ------------------------------------------------------------------------- */
@media (scripting: enabled) and (prefers-reduced-motion: no-preference) {
  [data-reveal] {
    opacity: 0;
    translate: 0 var(--reveal-shift, 1.5rem);
    transition:
      opacity var(--dur-slow) var(--ease-out) var(--reveal-delay, 0ms),
      translate var(--dur-slow) var(--ease-out) var(--reveal-delay, 0ms);
  }
  [data-reveal].is-in {
    opacity: 1;
    translate: 0 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }
}

/* Layout helpers */
.wrap {
  width: min(100% - 2 * var(--gutter), var(--page-max));
  margin-inline: auto;
}

.flow > * + * {
  margin-top: var(--flow-space, 1em);
}
