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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* The footer sits at the bottom of the window when a page is short: the page is a column, and main takes the spare height */
body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  background: var(--color-surface);
  color: var(--color-ink);
  font-family: var(--font-body);
  font-size: var(--text-body);
  font-weight: 400;
  line-height: var(--leading-body);
}

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

p,
ul,
ol,
dl,
blockquote,
figure,
pre,
table,
hr {
  margin: 0;
}

/* Avoid single-word last lines in running text */
p,
li,
dd,
blockquote,
figcaption {
  text-wrap: pretty;
}

/* Headings */
h1,
h2,
h3,
h4,
h5,
h6,
.h1,
.h2,
.h3,
.h4,
.h5,
.h6 {
  margin: 0;
  color: var(--color-ink);
  font-family: var(--font-heading);
  line-height: var(--leading-heading);
  text-wrap: balance;
}

h1,
.h1 {
  font-size: var(--text-h1);
  font-weight: 700;
}

h2,
.h2 {
  font-size: var(--text-h2);
  font-weight: 600;
}

h3,
.h3 {
  font-size: var(--text-h3);
  font-weight: 500;
}

h4,
.h4 {
  font-size: var(--text-h4);
  font-weight: 500;
  line-height: var(--leading-tight);
}

h5,
.h5 {
  font-size: 1rem;
  font-weight: 600;
  line-height: var(--leading-tight);
}

h6,
.h6 {
  font-size: var(--text-label);
  font-weight: 600;
  letter-spacing: 0.04em;
  line-height: var(--leading-tight);
  text-transform: uppercase;
}

/* Links */
/* Text links are primary blue and underlined. On hover they stay blue and the background turns primary tint.
   The underline keeps its resting colour and thickness. */
a {
  --link-color: var(--color-primary);
  --link-hover-color: var(--color-primary);
  --link-tint: var(--color-primary-tint); /* the hover background; teal links use the teal tint */
  color: var(--link-color);
  text-decoration-color: var(--link-color);
  text-decoration-thickness: 0.125rem;
  text-underline-offset: 0.2em;
}

/* Hover: the link takes a tint that reaches a little past the text on each side.
   - The sides are box-shadows, which take no space, so nothing around the link moves.
   - A wrapped link has one tint per line. Padding below an inline box is painted but takes no space, so a little
     is added to make each line's tint run down to the next line's and close the gap. --font-box is the height of
     the font's own box, measured in the browser: 1.28em for Outfit and 1.27em for Lora, so one value serves both. The line height is the distance between lines.
   - The tint of a line must not reach the underline of the line above, so a link's line height is never below
     1.35 (see the headings below).
   - Each line is drawn as its own box (box-decoration-break), at rest as well as on hover, because Chrome breaks
     lines differently with and without it and setting it only on hover made words jump. */
a {
  --font-box: 1.28em;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}

:where(a):hover {
  padding-bottom: max(0em, calc(1lh - var(--font-box)));
}

a:hover {
  background-color: var(--link-tint);
  box-shadow: -0.25em 0 0 var(--link-tint), 0.25em 0 0 var(--link-tint);
  color: var(--link-hover-color);
}

/* Headings are set tighter than links can be, so a link in a heading takes the tight body leading */
:is(h1, h2, h3, h4, h5, h6) a {
  line-height: var(--leading-tight);
}

:focus-visible {
  outline: var(--focus-ring);
  outline-offset: 3px;
}

/* Small corner radius on the focus ring of text elements. :where() keeps
   specificity low so components with their own radius are not reshaped. */
:where(a, summary):focus-visible {
  border-radius: var(--radius-sm);
}

/* Inline text */
strong,
b {
  font-weight: 700;
}

small {
  font-family: var(--font-ui);
  font-size: var(--text-label);
}

/* Lists */
ul,
ol {
  padding-inline-start: 1.5em;
}

li + li {
  margin-top: var(--space-2);
}

li > ul,
li > ol {
  margin-top: var(--space-2);
}

dt {
  font-family: var(--font-ui);
  font-weight: 600;
}

dd {
  margin-inline-start: 0;
}

dd + dt {
  margin-top: var(--space-3);
}

/* Blockquote */
blockquote {
  padding-inline-start: var(--space-5);
  border-inline-start: 4px solid var(--color-teal);
  font-style: italic;
}

blockquote > * + * {
  margin-top: var(--space-3);
}

blockquote footer {
  color: var(--color-ink-muted);
  font-family: var(--font-ui);
  font-size: var(--text-label);
  font-style: normal;
}

/* Code */
code,
kbd,
samp {
  padding: 0.1em 0.35em;
  border-radius: var(--radius-sm);
  background: var(--color-code-bg);
  font-family: var(--font-mono);
  font-size: var(--text-code);
}

pre {
  padding: var(--space-4);
  overflow-x: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-code-bg);
  font-family: var(--font-mono);
  font-size: 0.875rem;
  line-height: 1.5;
}

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

/* Tables: wrap in .table-wrap so wide tables scroll rather than the page */
.table-wrap {
  overflow-x: auto;
}

.table-wrap:focus-visible {
  outline: var(--focus-ring);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* Intro paragraph */
.lede {
  font-size: var(--text-lede);
  line-height: var(--leading-tight);
}

table {
  width: 100%;
  border-collapse: collapse;
}

caption {
  padding-bottom: var(--space-2);
  color: var(--color-ink-muted);
  font-family: var(--font-ui);
  font-size: var(--text-label);
  text-align: start;
}

th,
td {
  padding: var(--space-3) var(--space-4);
  font-family: var(--font-ui);
  border-bottom: 1px solid var(--color-border);
  text-align: start;
  vertical-align: top;
}

th {
  font-family: var(--font-ui);
  font-weight: 600;
}

thead th {
  border-bottom: 2px solid var(--color-primary);
}

/* Figures */
figure img {
  border-radius: var(--radius-md);
}

figcaption {
  margin-top: var(--space-2);
  color: var(--color-ink-muted);
  font-family: var(--font-ui);
  font-size: var(--text-label);
  line-height: var(--leading-tight);
}

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

/* Layout */
main {
  flex: 1 0 auto;
  overflow-x: clip; /* full-bleed bands use 100vw, which includes any scrollbar */
}

.container {
  width: 100%;
  max-width: calc(var(--width-content) + var(--gutter) * 2);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

/* Vertical rhythm for long-form content */
.prose {
  max-width: var(--width-prose);
}

.prose > * + * {
  margin-top: var(--space-5);
}

/* Headings get more space above than below: 2rem, 2.5rem, 1.5rem, against 0.75rem below */
.prose > h2 {
  margin-top: var(--space-6);
}

.prose > h3 {
  margin-top: calc(var(--space-6) + var(--space-2));
}

.prose > h4 {
  margin-top: var(--space-5);
}

.prose > :first-child {
  margin-top: 0;
}

.prose > :is(h2, h3, h4) + * {
  margin-top: var(--space-3);
}

/* A heading straight after a heading: close, but not cramped */
.prose > h2 + :is(h3, h4) {
  margin-top: var(--space-4);
}

.skip-link {
  --link-color: var(--color-white);
  --link-hover-color: var(--color-white);
  position: absolute;
  top: var(--space-2);
  left: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  background: var(--color-ink);
  color: var(--color-white);
  font-family: var(--font-ui);
  transform: translateY(-200%);
}

.skip-link:focus {
  transform: none;
}

/* Two classes so the global a:hover cannot override the colour */
.skip-link:hover,
.skip-link:focus {
  background: var(--color-ink);
  box-shadow: none;
  color: var(--color-white);
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
  }
}

/* Hidden visually, still read by assistive technology */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
