/*
 * Practical UX
 * Design foundation adapted from The A11Y Project (Apache-2.0)
 * https://github.com/a11yproject/a11yproject.com
 *
 * Brand colour is the Practical UX logo orange (#b43c0d), chosen over the old
 * CSS orange (#d9480f) because only the former clears WCAG AA on white (5.84:1
 * vs 4.30:1). See MIGRATION.md §5.
 */

/* ---------- Tokens ---------- */
:root {
  --color-brand: #b43c0d;
  --color-brand-shade: #8f2f0a;
  --color-brand-tint: #fdf1ec;

  --color-black: #1b1b1b;
  --color-charcoal: #222222;
  --color-gray-shade: #5b5b5b;
  --color-gray: #707070;
  --color-gray-tint: #d8d8d8;
  --color-gray-wash: #ececec;
  --color-sand: #f7f6f4;
  --color-white: #ffffff;

  --color-text: var(--color-black);
  --color-text-muted: var(--color-gray-shade);
  --color-background: var(--color-white);
  --color-background-offset: var(--color-sand);
  --color-border: var(--color-gray-tint);
  --color-link: var(--color-brand);
  --color-link-hover: var(--color-brand-shade);
  --color-focus: #0b57d0;
  --color-on-brand: #ffffff;
  /* Fixed brand colours for surfaces that are dark in both schemes (photo hero). */
  --color-brand-solid: #b43c0d;
  --color-brand-shade-solid: #8f2f0a;

  --font-primary: "Noto Serif", Georgia, "Times New Roman", serif;
  --font-secondary: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  --line-height-tight: 1.2;
  --line-height-default: 1.6;

  --space-2xs: 0.25rem;
  --space-xs: 0.5rem;
  --space-s: 0.75rem;
  --space-m: 1rem;
  --space-l: 1.5rem;
  --space-xl: 2.5rem;
  --space-2xl: 4rem;

  --measure: 42rem;
  --wrapper: 70rem;
  --radius: 4px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --color-brand: #ff8a5c;
    --color-brand-shade: #ffa982;
    --color-brand-tint: #2a1610;

    --color-text: #ededed;
    --color-text-muted: #bdbdbd;
    --color-background: #1a1a1a;
    --color-background-offset: #242424;
    --color-border: #444444;
    --color-link: var(--color-brand);
    --color-link-hover: var(--color-brand-shade);
    --color-focus: #9ec3ff;
    --color-on-brand: #1a1a1a;
  }
}

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

html {
  font-size: 100%;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

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

body {
  margin: 0;
  background-color: var(--color-background);
  color: var(--color-text);
  font-family: var(--font-primary);
  font-size: 1.125rem;
  line-height: var(--line-height-default);
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-secondary);
  line-height: var(--line-height-tight);
  margin: 0 0 var(--space-m);
  text-wrap: balance;
}

h1 { font-size: clamp(2rem, 1.4rem + 2.6vw, 3rem); letter-spacing: -0.02em; }
h2 { font-size: clamp(1.5rem, 1.2rem + 1.4vw, 2rem); margin-top: var(--space-xl); }
h3 { font-size: clamp(1.25rem, 1.1rem + 0.7vw, 1.5rem); margin-top: var(--space-l); }
h4 { font-size: 1.125rem; margin-top: var(--space-l); }

p, ul, ol, dl, figure, blockquote, table { margin: 0 0 var(--space-m); }

a { color: var(--color-link); text-decoration-thickness: 0.08em; text-underline-offset: 0.15em; }
a:hover { color: var(--color-link-hover); text-decoration-thickness: 0.16em; }

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

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

figure { margin-inline: 0; }
figure img { border-radius: var(--radius); }
figcaption {
  color: var(--color-text-muted);
  font-family: var(--font-secondary);
  font-size: 0.875rem;
  margin-top: var(--space-xs);
}

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

blockquote {
  border-left: 4px solid var(--color-brand);
  margin-left: 0;
  padding-left: var(--space-m);
  color: var(--color-text-muted);
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
  background: var(--color-background-offset);
  padding: 0.15em 0.35em;
  border-radius: 3px;
}

/* ---------- Utilities ---------- */
.u-visually-hidden {
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  height: 1px;
  overflow: hidden;
  position: absolute;
  white-space: nowrap;
  width: 1px;
}

.wrapper {
  margin-inline: auto;
  max-width: var(--wrapper);
  padding-inline: var(--space-m);
  width: 100%;
}

.measure { max-width: var(--measure); }

/* ---------- Skip link ---------- */
.c-skipnav {
  background-color: var(--color-brand);
  /* --color-on-brand flips with the scheme: the dark-mode brand tint is light,
     so white-on-brand would drop to ~2.3:1 there. */
  color: var(--color-on-brand);
  display: block;
  font-family: var(--font-secondary);
  font-size: 0.9rem;
  font-weight: 700;
  left: 0;
  padding: var(--space-s) var(--space-m);
  position: absolute;
  text-transform: uppercase;
  top: 0;
  transform: translateY(-110%);
  z-index: 100;
}
.c-skipnav:focus {
  color: var(--color-on-brand);
  transform: translateY(0);
  position: fixed;
}

/* ---------- Header / nav ---------- */
.c-header {
  border-bottom: 1px solid var(--color-border);
  background: var(--color-background);
}
.c-header__inner {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-m);
  justify-content: space-between;
  padding-block: var(--space-m);
}
.c-brand {
  align-items: center;
  display: inline-flex;
  gap: var(--space-xs);
  font-family: var(--font-secondary);
  font-weight: 700;
  text-decoration: none;
  color: var(--color-text);
}
.c-brand:hover { color: var(--color-text); }
.c-brand img { display: block; width: 44px; height: 44px; border-radius: var(--radius); }
.c-brand__text { font-size: 1.05rem; letter-spacing: -0.01em; }

.c-nav ul {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-m);
  list-style: none;
  margin: 0;
  padding: 0;
}
.c-nav a {
  font-family: var(--font-secondary);
  font-size: 1rem;
  font-weight: 600;
  text-decoration: none;
  padding-block: var(--space-2xs);
  border-bottom: 2px solid transparent;
  color: var(--color-text);
}
.c-nav a:hover { border-bottom-color: var(--color-brand); color: var(--color-link-hover); }
.c-nav a[aria-current="page"] { border-bottom-color: var(--color-brand); color: var(--color-link); }

/* ---------- Hero ---------- */
.c-hero {
  background-color: var(--color-background-offset);
  border-bottom: 1px solid var(--color-border);
  padding-block: var(--space-2xl);
}
.c-hero p.c-hero__lede {
  color: var(--color-text-muted);
  font-size: 1.25rem;
  max-width: var(--measure);
}

/*
 * Photographic hero, as on the pre-migration site: a cover-positioned photo
 * behind a darkening overlay, with light text on top.
 *
 * The overlay reproduces the original two-part treatment — a flat black wash
 * plus a 2x2 dither tile (one opaque pixel in four, from the old
 * `patternify.com` base64 PNG, now inlined as a gradient so there is no extra
 * request).
 *
 * The wash is 0.6, not the original 0.5. Measured against the three hero
 * images, 0.5 leaves light text below the 4.5:1 AA threshold over 11% of the
 * homepage photo and 51% of the cookie-essay collage, which is mostly white
 * dialog boxes. At 0.6 every pixel of all three images clears 4.5:1. The
 * visual difference is slight; the readability difference is not.
 */
.c-hero--image {
  background-color: #2a2a2a;
  background-position: center center;
  background-repeat: no-repeat;
  background-size: cover;
  border-bottom: 0;
  color: #f8f8f8;
  isolation: isolate;
  position: relative;
  text-align: center;
}

.c-hero--image::before {
  background-color: rgba(0, 0, 0, 0.6);
  /* The original 2x2 dither tile from the old site, inlined verbatim: one
     opaque black pixel in four. Kept as the same PNG so the texture is
     identical, and inlined so it costs no extra request. */
  background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAYAAABytg0kAAAAFElEQVQYV2NkYGD4z8DAwMjIAAUADikBA/gvnngAAAAASUVORK5CYII=");
  background-repeat: repeat;
  bottom: 0;
  content: "";
  display: block;
  left: 0;
  position: absolute;
  right: 0;
  top: 0;
  z-index: -1;
}

/* The photo is decorative; the h1 carries the meaning.
   These must beat `.c-hero p.c-hero__lede`, which sets the muted body colour —
   measured on the composited hero, that grey falls below 4.5:1 over ~62% of
   the image, while #f8f8f8 stays at 5.4:1 or better everywhere. */
.c-hero--image h1,
.c-hero--image p.c-hero__lede,
.c-hero--image .c-card__eyebrow {
  color: #f8f8f8;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

.c-hero--image p.c-hero__lede {
  margin-inline: auto;
}

.c-hero--image .c-card__meta,
.c-hero--image .c-card__meta time {
  color: #f8f8f8;
}

.c-hero--image .c-btn {
  background-color: var(--color-brand-solid);
  border-color: var(--color-brand-solid);
  color: #ffffff;
}
.c-hero--image .c-btn:hover {
  background-color: var(--color-brand-shade-solid);
  border-color: var(--color-brand-shade-solid);
  color: #ffffff;
}

@media (min-width: 48rem) {
  .c-hero--image {
    padding-block: calc(var(--space-2xl) * 1.5);
  }
}

/* ---------- Buttons ---------- */
.c-btn {
  background-color: var(--color-brand);
  border: 2px solid var(--color-brand);
  border-radius: var(--radius);
  color: var(--color-on-brand);
  display: inline-block;
  font-family: var(--font-secondary);
  font-size: 1rem;
  font-weight: 700;
  padding: var(--space-s) var(--space-l);
  text-decoration: none;
}
.c-btn:hover {
  background-color: var(--color-brand-shade);
  border-color: var(--color-brand-shade);
  color: var(--color-on-brand);
}

/* ---------- Main / post list ---------- */
.l-main { padding-block: var(--space-xl); }

.c-post-list { list-style: none; margin: 0; padding: 0; }
.c-post-list > li + li {
  border-top: 1px solid var(--color-border);
  margin-top: var(--space-xl);
  padding-top: var(--space-xl);
}

.c-card__eyebrow {
  color: var(--color-text-muted);
  display: block;
  font-family: var(--font-secondary);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  margin-bottom: var(--space-2xs);
  text-transform: uppercase;
}
.c-card__title { margin-top: 0; margin-bottom: var(--space-xs); }
.c-card__title a { text-decoration: none; color: var(--color-text); }
.c-card__title a:hover { color: var(--color-link-hover); text-decoration: underline; }
.c-card__meta {
  color: var(--color-text-muted);
  font-family: var(--font-secondary);
  font-size: 0.9rem;
}
.c-card__lede { font-size: 1.1rem; }

.c-tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
  list-style: none;
  margin: 0 0 var(--space-m);
  padding: 0;
}
.c-tag {
  background: var(--color-brand-tint);
  border: 1px solid var(--color-brand);
  border-radius: 999px;
  color: var(--color-link);
  font-family: var(--font-secondary);
  font-size: 0.8rem;
  font-weight: 700;
  padding: 0.1rem var(--space-s);
  text-decoration: none;
}

/* ---------- Embeds ---------- */
.c-embed {
  aspect-ratio: 16 / 9;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  margin-bottom: var(--space-m);
  max-width: 100%;
  overflow: hidden;
}
.c-embed iframe { border: 0; display: block; height: 100%; width: 100%; }
.c-embed--audio { aspect-ratio: auto; height: 166px; }

/* ---------- Post layout ---------- */
.l-post { }
.l-post__body { max-width: var(--measure); }
.l-post__body img { border-radius: var(--radius); }

/* Footnotes (markdown-it-footnote) */
.footnotes {
  border-top: 1px solid var(--color-border);
  font-size: 0.95rem;
  margin-top: var(--space-xl);
  padding-top: var(--space-m);
}
.footnotes-list { padding-left: var(--space-l); }

/* Heading anchor links from markdown-it-anchor */
.l-post__body :is(h2, h3, h4) > a.header-anchor {
  color: inherit;
  text-decoration: none;
}
.l-post__body :is(h2, h3, h4) > a.header-anchor:hover {
  color: var(--color-link-hover);
  text-decoration: underline;
}

/* ---------- Join banner ---------- */
.c-join {
  background-color: var(--color-background-offset);
  border-block: 1px solid var(--color-border);
  margin-top: var(--space-2xl);
  padding-block: var(--space-xl);
  text-align: center;
}
.c-join h2 { margin-top: 0; }
.c-join p { margin-inline: auto; max-width: var(--measure); }

/* ---------- Footer ---------- */
.c-footer {
  border-top: 1px solid var(--color-border);
  color: var(--color-text-muted);
  font-family: var(--font-secondary);
  font-size: 0.9rem;
  margin-top: var(--space-2xl);
  padding-block: var(--space-xl);
}
.c-footer a { color: var(--color-link); }
.c-footer ul {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-m);
  list-style: none;
  margin: 0 0 var(--space-m);
  padding: 0;
}

/* ---------- Tables ---------- */
table { border-collapse: collapse; width: 100%; }
th, td { border: 1px solid var(--color-border); padding: var(--space-xs) var(--space-s); text-align: left; }
th { background: var(--color-background-offset); font-family: var(--font-secondary); }

.u-table-scroll { overflow-x: auto; }
