/* =============================================================================
   BASE — element defaults and font loading
   ========================================================================== */

/* --- Fonts ---------------------------------------------------------------- */
/* Self-hosted so there is no third-party request and no flash of fallback on
   a cold local start. font-display: swap keeps text painted immediately. */

@font-face {
  font-family: "Departure Mono";
  src: url("/fonts/DepartureMono-Regular.woff2") format("woff2");
  font-weight: 400 500;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "EB Garamond";
  src: url("/fonts/EBGaramond-latin.woff2") format("woff2");
  font-weight: 400 600;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "EB Garamond";
  src: url("/fonts/EBGaramond-Italic-latin.woff2") format("woff2");
  font-weight: 400 600;
  font-style: italic;
  font-display: swap;
}

/* --- Reset ---------------------------------------------------------------- */

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: 5rem;
  /* Stops the double-tap-to-zoom 300ms delay without disabling pinch zoom. */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

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

body {
  background: var(--background);
  color: var(--foreground);
  font-family: var(--font-serif);
  font-size: var(--text-sm);
  line-height: var(--leading-body);
  font-feature-settings: "calt";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* Notch and home-indicator safety for the full-bleed layout. */
  padding-inline: env(safe-area-inset-left) env(safe-area-inset-right);
  /* Nothing in this layout should scroll sideways. */
  overflow-x: hidden;
}

::selection {
  background-color: var(--amber-200);
  text-decoration: underline dotted;
}

/* --- Headings ------------------------------------------------------------- */
/* Sizes are set per-component; here we only fix the shared behaviour. */

h1,
h2,
h3,
h4,
h5,
h6 {
  font-size: inherit;
  font-weight: inherit;
  text-wrap: balance; /* no widows on headings */
  scroll-margin-top: var(--space-12);
}

p {
  text-wrap: pretty;
}

/* --- Links --------------------------------------------------------------- */

a {
  color: inherit;
  text-decoration-line: underline;
  text-decoration-color: var(--ink-muted);
  text-decoration-style: dotted;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
  text-decoration-skip-ink: all;
  transition:
    color var(--duration) var(--ease-out),
    text-decoration-color var(--duration) var(--ease-out);
}

@media (hover: hover) {
  a:hover {
    color: var(--accent);
    text-decoration-color: var(--accent);
  }
}

a:active {
  color: var(--accent-strong);
}

/* --- Focus --------------------------------------------------------------- */
/* Every focusable thing gets a visible ring. :focus-visible so it does not
   appear on mouse click, only on keyboard and programmatic focus. */

:focus-visible {
  outline: var(--focus-ring-width) solid var(--focus-ring-color);
  outline-offset: var(--focus-ring-offset);
  border-radius: var(--radius-xs);
}

/* --- Media --------------------------------------------------------------- */

img,
svg,
video,
canvas {
  display: block;
  vertical-align: middle;
}

img,
video {
  max-width: 100%;
  height: auto;
}

/* --- Lists and tables ---------------------------------------------------- */

ul,
ol {
  list-style: none;
}

table {
  border-collapse: collapse;
  text-indent: 0;
}

/* --- Form controls ------------------------------------------------------- */

button,
input,
select,
textarea {
  font: inherit;
  letter-spacing: inherit;
  color: inherit;
  background-color: transparent;
  border: 0;
  border-radius: 0;
}

button {
  cursor: pointer;
}

/* Windows dark mode paints native selects black-on-black without this. */
select {
  background-color: var(--background);
  color: var(--foreground);
}

::placeholder {
  color: var(--ink-subtle);
  opacity: 1;
}

textarea {
  resize: vertical;
}

/* --- Utilities ----------------------------------------------------------- */

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

.u-nums {
  font-variant-numeric: tabular-nums;
}

/* Keyboard users land here first. */
.skip-link {
  position: absolute;
  top: var(--space-2);
  left: var(--space-2);
  z-index: 100;
  padding: var(--space-2) var(--space-3);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  text-transform: uppercase;
  text-decoration: none;
  background: var(--background);
  border: var(--border-hairline) solid var(--rule-strong);
  border-radius: var(--radius-sm);
  transform: translateY(-200%);
}

.skip-link:focus-visible {
  transform: translateY(0);
}
