@layer base {
  html,
  body {
    --font-sans: "Helvetica Neue", system-ui;
    --font-serif: ui-serif, serif;
    --font-mono: ui-monospace, monospace;

    -moz-osx-font-smoothing: grayscale;
    -webkit-font-smoothing: antialiased;
    -webkit-text-size-adjust: none;
    background: var(--color-bg);
    color: var(--color-ink);
    font-family: var(--font-sans);
    line-height: 1.4;
    overflow: unset;
    scroll-behavior: auto;
    scrollbar-gutter: stable;
    text-rendering: optimizeLegibility;
    text-size-adjust: none;
  }

  kbd {
    border: 1px solid;
    border-radius: 0.3em;
    box-shadow: 0 0.1em 0 currentColor;
    font-family: var(--font-mono);
    font-size: 0.8em;
    font-weight: 600;
    opacity: 0.7;
    padding: 0 0.4em;
    vertical-align: middle;
    white-space: nowrap;
  }

  a {
    text-decoration: none;
  }

  /* Links are blue by design — everywhere except buttons, and they keep that
     colour on hover (underline + cursor are the affordance). The :where() keeps
     this at `a` specificity (0,0,1) so component classes (.txt-ink, .txt-subtle,
     …) still override it; it only filters .btn out of the default link colour. */
  a:where(:not(.btn)) {
    color: var(--color-blue);
  }

  /* Bare links also get an underline affordance. */
  a:not([class]) {
    text-decoration: underline;
    text-decoration-skip-ink: auto;
  }

  :is(a, button, input, textarea, .switch, .toc, .toc__title) {
    --outline-size: max(2px, 0.08em);

    caret-color: var(--color-blue);
    text-decoration: none;
    touch-action: manipulation;
    transition:
      color 150ms ease,
      box-shadow 150ms ease,
      outline-offset 150ms ease,
      background-color 150ms ease,
      opacity 150ms ease,
      filter 150ms ease;

    /* Keyboard navigation */
    &:where(:not(:active)):focus-visible {
      outline-width: var(--outline-size);
      outline-color: var(--outline-color, currentColor);
      outline-offset: var(--outline-offset, calc(var(--outline-size) * 2));
    }

    &:where(:focus-visible):active {
      outline: 0;
    }

    /* Pressing */
    &:focus:not(:focus-visible) {
      --outline-offset: 0;
    }

    /* Disabled */
    &:where([disabled]):not(:hover):not(:active) {
      cursor: not-allowed;
      filter: brightness(0.75);
    }
  }

  ::selection {
    background-color: var(--color-blue-light);
  }

  :where(ul, ol):where([role="list"]) {
    margin: 0;
    padding: 0;
    list-style: none;
  }

  /* Printing */
  @page {
    margin: 1in;
  }

  @media print {
    .no-print {
      display: none;
    }
  }

  /* Turbo */
  turbo-frame {
    display: contents;
  }

  /* Fix for lazy-loading turbo frames - they need dimensions for intersection observer */
  turbo-frame[loading="lazy"] {
    display: block;
  }

  /* Nicer scrollbars on Chrome 29+. This is intended for Windows machines, but */
  /* there's not a way to target Windows using CSS, so Chrome on Mac will have */
  /* slightly thinner scrollbars than normal. #C1C1C1 is the default color on Macs. */
  @media screen and (-webkit-min-device-pixel-ratio: 0) and (min-resolution: 0.001dpcm) {
    * {
      scrollbar-color: #c1c1c1 transparent;
      scrollbar-width: thin;
    }
  }
}
