/* =========================================================================
   adames.cc — design system
   Near-monochrome, single accent, system grotesque for prose + mono for
   metadata. One column, generous whitespace, motion <=200ms. No framework.
   One exception to the single accent: the pixel mark is a portrait, not UI,
   and wears its own five fixed paints in both themes. What appears beside
   him (a bubble, lines of text) is page ink.
   ========================================================================= */

/* ---- Display face -------------------------------------------------------- */
/* Self-hosted, subsetted Fraunces — lowercase + digits + a little punctuation
   only (see scripts/subset-fraunces.sh), ~7.8 KB instead of the ~18 KB full
   latin cut, because every Fraunces element is text-transform: lowercase. The
   url() is hashed by Vite; BaseHead preloads the same file by ?url import. */
@font-face {
  font-family: "Fraunces";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("/fonts/fraunces-latin-600-subset.woff2") format("woff2");
}

/* ---- Fallback face ------------------------------------------------------ */
/* Metric-matched stand-in for Fraunces while it loads (font-display: swap).
   Headings render in Georgia scaled to Fraunces' advance width (size-adjust
   94% — Fraunces is slightly narrower, measured), so they don't re-wrap and
   shove the page down when the real font arrives. Every heading uses a unitless
   line-height, so the line box is font-size x multiplier regardless of metrics —
   no ascent/descent overrides needed (they'd be bytes that change nothing here).
   On systems without Georgia (most Android), this face is skipped and
   --font-serif falls through unchanged: no gain, no regression. */
@font-face {
  font-family: "Fraunces Fallback";
  src: local("Georgia");
  size-adjust: 94%;
}

/* ---- Tokens ------------------------------------------------------------- */
:root {
  /* Match native UI (scrollbars, form controls, caret) to the active theme. */
  color-scheme: light;

  /* Type stacks. System grotesque ships zero font bytes — the leanest
     "only code that contributes" choice. Mono is reserved for dates, tags,
     and code. */
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  --font-mono: ui-monospace, "SF Mono", "JetBrains Mono", "Menlo", "Consolas",
    monospace;
  /* Display serif for the name + headings. Body stays system sans. */
  --font-serif: "Fraunces", "Fraunces Fallback", Georgia, Cambria,
    "Times New Roman", serif;

  /* Fluid type scale — uniform 1.2 ratio (minor third), 16→17px base, no gaps.
     step-3 is the largest heading (h1); the home hero is a one-off above it.
     Restrained on purpose: headings recede, the prose leads. */
  --step--1: clamp(0.833rem, 0.816rem + 0.087vw, 0.885rem);
  --step-0: clamp(1rem, 0.979rem + 0.104vw, 1.0625rem);
  --step-1: clamp(1.2rem, 1.175rem + 0.125vw, 1.275rem);
  --step-2: clamp(1.44rem, 1.41rem + 0.15vw, 1.53rem);
  --step-3: clamp(1.728rem, 1.692rem + 0.18vw, 1.836rem);

  /* Rhythm — 4px base scale (adames ember). Snap to a step; never invent an
     in-between value. */
  --space-0: 0.125rem;
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 3rem;
  --measure: 65ch;
  --section: clamp(2.5rem, 1.8rem + 3vw, 4rem);
  --wrap-max: 42rem;
  /* Shape — 4/6/8, plus the hairline. Edges are drawn, not cast. */
  --radius-sm: 4px;
  --radius: 6px;
  --radius-lg: 8px;
  --border-w: 1px;
  /* Controls — one height kit; coarse pointers get the 44px floor below. */
  --control-sm: 2rem;
  --control-md: 2.25rem;
  /* Motion — chrome hover / press, and everything else. Nothing over 200ms. */
  --transition-fast: 100ms ease;
  --transition: 150ms ease;
  /* The site's one motion: the mark's cross-fade between pages. One token
     so the duration lives in a single auditable place, not three pseudos. */
  --mark-step: 180ms;

  /* Light palette — warm off-white ground, near-black ink. */
  --bg: #faf9f7;
  --surface: #f2f0ec;
  --surface-press: #e8e6e0;
  --raised: #ffffff;
  --text: #1a1a18;
  --text-secondary: #4a4946;
  --muted: #6b6a66;
  --border: #e3e1db;
  --border-strong: #c9c6bf;
  /* Ink-density ramp — the only wash palette. Mixes ink, so it themes itself. */
  --fill-1: color-mix(in srgb, var(--text) 8%, transparent);
  --fill-2: color-mix(in srgb, var(--text) 18%, transparent);
  /* Oxblood, links only. Hex first as the fallback; the OKLCH line wins where
     supported and is the exact same colour, authored in a perceptual space so
     lightness/chroma can be tuned by eye later. */
  --accent: #8c2f39;
  --accent: oklch(44.48% 0.126 17.63);
  --accent-soft: rgba(140, 47, 57, 0.1);

  /* Shiki (css-variables theme) — light */
  --astro-code-color-text: #1a1a18;
  --astro-code-color-background: #f2f0ec;
  --astro-code-token-comment: #8a8780;
  --astro-code-token-keyword: #a3262b;
  --astro-code-token-string: #2f6f43;
  --astro-code-token-function: #1d4ed8;
  --astro-code-token-constant: #8a5a00;
  --astro-code-token-parameter: #1a1a18;
  --astro-code-token-string-expression: #2f6f43;
  --astro-code-token-punctuation: #6b6a66;
  --astro-code-token-link: #1d4ed8;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0c0c0d;
  --surface: #161617;
  --surface-press: #1f1f21;
  --raised: #19191b;
  --text: #ededec;
  --text-secondary: #b4b3b0;
  /* #9b9a96, not #8d8c87: the AA bump on near-black (ember, system-wide). */
  --muted: #9b9a96;
  --border: #262628;
  --border-strong: #55555b;
  /* Warm clay-rose: a lighter, slightly warmer tint of the oxblood so it stays
     legible on near-black (not the same hue — independently chosen). */
  --accent: #df938b;
  --accent: oklch(73.75% 0.0935 26.15);
  --accent-soft: rgba(223, 147, 139, 0.14);

  /* Shiki — dark */
  --astro-code-color-text: #ededec;
  --astro-code-color-background: #161617;
  --astro-code-token-comment: #6c6b66;
  --astro-code-token-keyword: #ff7b72;
  --astro-code-token-string: #8ddb9b;
  --astro-code-token-function: #7aa2ff;
  --astro-code-token-constant: #e3b341;
  --astro-code-token-parameter: #ededec;
  --astro-code-token-string-expression: #8ddb9b;
  --astro-code-token-punctuation: #8d8c87;
  --astro-code-token-link: #7aa2ff;
}

/* The head script stamps data-theme before paint. Without JS the OS choice
   still carries dark: the same block, gated on the un-stamped root. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0c0c0d;
    --surface: #161617;
    --surface-press: #1f1f21;
    --raised: #19191b;
    --text: #ededec;
    --text-secondary: #b4b3b0;
    /* #9b9a96, not #8d8c87: the AA bump on near-black (ember, system-wide). */
    --muted: #9b9a96;
    --border: #262628;
    --border-strong: #55555b;
    /* Warm clay-rose: a lighter, slightly warmer tint of the oxblood so it stays
       legible on near-black (not the same hue — independently chosen). */
    --accent: #df938b;
    --accent: oklch(73.75% 0.0935 26.15);
    --accent-soft: rgba(223, 147, 139, 0.14);

    /* Shiki — dark */
    --astro-code-color-text: #ededec;
    --astro-code-color-background: #161617;
    --astro-code-token-comment: #6c6b66;
    --astro-code-token-keyword: #ff7b72;
    --astro-code-token-string: #8ddb9b;
    --astro-code-token-function: #7aa2ff;
    --astro-code-token-constant: #e3b341;
    --astro-code-token-parameter: #ededec;
    --astro-code-token-string-expression: #8ddb9b;
    --astro-code-token-punctuation: #8d8c87;
    --astro-code-token-link: #7aa2ff;
  }
}


@media (pointer: coarse) {
  :root {
    --control-sm: 2.75rem; /* 44px tap floor */
  }
}

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

html {
  -webkit-text-size-adjust: 100%; /* stop iOS resizing text on rotate */
  -moz-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--step-0);
  line-height: 1.65;
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  /* Numerals align everywhere — dates, counts, code. */
  font-variant-numeric: tabular-nums;
  /* Theme transition kept tiny and scoped — never animate on theme switch
     across every property. */
  transition: background-color 150ms ease, color 150ms ease;
}

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

::selection {
  background: var(--accent-soft);
}

/* ---- Layout ------------------------------------------------------------- */
.wrap {
  width: 100%;
  max-width: var(--wrap-max);
  margin-inline: auto;
  padding-inline: var(--space-5);
}

main {
  /* sticky footer */
  min-height: 60vh;
  padding-block: var(--section) calc(var(--section) * 1.2);
}

hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin-block: var(--section);
}

/* ---- Typography --------------------------------------------------------- */
h1,
h2,
h3,
h4 {
  font-family: var(--font-serif);
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -0.005em;
  text-transform: lowercase; /* casual lowercase design */
  text-wrap: balance;
}

h1 {
  font-size: var(--step-3);
}
h2 {
  font-size: var(--step-2);
}
h3 {
  font-size: var(--step-1);
}

p,
ul,
ol {
  max-width: var(--measure);
}

a {
  color: var(--accent);
  text-decoration: none;
  text-underline-offset: 0.18em;
  text-decoration-thickness: from-font;
}
@media (hover: hover) {
  a:hover {
    text-decoration: underline;
  }
}

/* Monospace metadata: dates, tags, technical labels. The cheapest signal of
   "an engineer who cares" without tipping into gimmick. */
.mono {
  font-family: var(--font-mono);
  font-size: var(--step--1);
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  letter-spacing: -0.01em;
}

.muted {
  color: var(--muted);
}

/* The provenance line — the one sentence that's also a design element. It signs
   pages the way the view-source comment signs the HTML: mono, muted, small.
   Inside prose it closes a piece, so it takes a signature-scale gap instead of
   the paragraph rhythm. */
.provenance {
  font-family: var(--font-mono);
  font-size: var(--step--1);
  letter-spacing: -0.01em;
  color: var(--muted);
}
.prose .provenance {
  margin-top: calc(var(--section) * 0.6);
}

.lead {
  font-size: var(--step-1);
  line-height: 1.5;
}

/* The casual register. Everything the site says about itself — splash, page
   leads, about, labs, empty states, the 404 — renders lowercase, one sentence
   per line, no final period. Applied by CSS so the source strings stay
   truthful and the essays (.prose without .casual) keep their own case. */
.casual,
.casual p,
.casual h1 {
  text-transform: lowercase;
}

/* ---- Long-form prose ---------------------------------------------------- */
.prose {
  max-width: var(--measure);
}
/* Even out the rag and avoid orphans in the long-form prose that is the site's
   core content. Headings already use text-wrap: balance; this is the
   paragraph-grade counterpart. Degrades to normal wrapping where unsupported. */
.prose p,
.prose li {
  text-wrap: pretty;
}
.prose > * + * {
  margin-top: 1.25em;
}
.prose h2 {
  margin-top: 2em;
}
.prose h3 {
  margin-top: 1.6em;
}
.prose ul,
.prose ol {
  padding-left: 1.4em;
}
.prose li + li {
  margin-top: 0.35em;
}
.prose blockquote {
  border-left: 2px solid var(--border);
  padding-left: 1em;
  color: var(--muted);
  font-style: italic;
}
.prose code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--surface);
  padding: 0.12em 0.35em;
  border-radius: var(--radius-sm);
}
.prose :not(pre) > code {
  white-space: nowrap;
}
/* A long identifier or URL must never widen the page past the screen. The
   wrap is a last resort: it only fires when a word is wider than the line. */
.prose {
  overflow-wrap: anywhere;
}
@media (max-width: 40rem) {
  .prose :not(pre) > code {
    white-space: normal;
  }
}
.prose pre {
  font-size: var(--step--1);
  line-height: 1.6;
  padding: 1rem 1.15rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow-x: auto;
}
.prose pre code {
  background: none;
  padding: 0;
  font-size: inherit;
}
.prose img {
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

/* Body links carry an always-on underline so they're identifiable in running
   prose on touch, where :hover never fires. Chrome links (header, nav, post
   list, footer) keep their hover-only treatment from the base `a` rule above.
   `:not(.mono)` spares metadata links — the date/tag chips that share .prose. */
.prose a:not(.mono) {
  text-decoration-line: underline;
  text-decoration-thickness: 0.08em;
}
@media (hover: hover) {
  .prose a:not(.mono):hover {
    text-decoration-thickness: 0.12em;
  }
}

/* ---- Focus & accessibility --------------------------------------------- */
:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent);
  border-radius: var(--radius-sm);
}

.skip-link {
  position: absolute;
  left: var(--space-3);
  top: -3rem;
  background: var(--text);
  color: var(--bg);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius);
  z-index: 10;
  transition: top var(--transition);
}
.skip-link:focus {
  top: var(--space-3);
}

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

/* ---- Page transitions: the signature steps between sections ------------- */
/* The mark gets its own snapshot pair so it steps calmly between pages while
   the prose swaps instantly. Pure CSS cross-document View Transitions — zero
   JS, no router. Today the portrait holds one pose, so the step is invisible;
   this is the rail the per-section performances will ride when they return.
   Browsers without support (Firefox, older Safari) just navigate: graceful,
   no penalty. */
/* Gate the opt-in itself behind reduced-motion: motion-sensitive users get an
   ordinary instant navigation with no snapshot machinery at all. The explicit
   `animation: none` reduce block below stays as a backstop for engines that
   honor the opt-in regardless. */
@media (prefers-reduced-motion: no-preference) {
  @view-transition {
    navigation: auto;
  }
}

/* Tag only the header mark's BUST so it gets its own snapshot pair; the page
   itself never animates — prose stays dead still, the signature is the one
   thing that moves. The gesture layer is deliberately left out: a snapshot
   captures ink overflow, and a lit bulb caught mid-hover would cross-fade
   out of every navigation as a flash. (Set globally so it applies on every
   page's mark.) */
.site-header__mark .mark__bust {
  view-transition-name: mark;
}

/* Kill the default whole-page crossfade — only the mark steps. */
::view-transition-old(root),
::view-transition-new(root) {
  animation: none;
}

/* The mark cross-fades in <=200ms. Both snapshots are the same portrait at
   the same box and scale, so the fade reads as him holding still rather than
   two icons blinking. object-fit:contain keeps the pixels undistorted. */
::view-transition-group(mark) {
  animation-duration: var(--mark-step);
}
::view-transition-old(mark),
::view-transition-new(mark) {
  height: 100%;
  object-fit: contain;
  animation-duration: var(--mark-step);
  animation-timing-function: ease;
}

/* Reduced motion: cut the cross-fade to an instant. The universal
   reduced-motion rule above does not reach ::view-transition-* pseudos, so
   neutralize them explicitly. */
@media (prefers-reduced-motion: reduce) {
  ::view-transition-group(*),
  ::view-transition-old(*),
  ::view-transition-new(*) {
    animation: none !important;
  }
}


/* ---- Gestures: one thing appears beside the portrait per section ---------
   "hi" on Home, lines of text in Writing, a lit bulb in Workshop, a viewfinder
   in About. Each is drawn outside the mark's 13×13 box (the svg overflows), so
   the header is laid out identically on every page and the 180ms cross-fade
   between pages stays a plain fade. At rest there is nothing — the portrait
   alone. The gesture appears while the header is hovered (or the name link
   focused): an opacity flip, no transform, nothing leaves the pixel grid, so
   it is safe under reduced motion. Nothing on the portrait itself ever
   changes. Drawings and rules: docs/design/pixel-mark/. */
.mark {
  position: relative;
  display: inline-block;
  flex: none;
  line-height: 0;
}
/* The reset's `svg { max-width: 100% }` is for pictures in prose; in a tight
   header it let the portrait shrink to nothing. He is 26px, always. */
.mark svg {
  max-width: none;
}
.mark__gesture {
  position: absolute;
  inset: 0;
  overflow: visible;
}
.mark__ink {
  fill: var(--text);
}
.mark__muted {
  fill: var(--muted);
}
/* Which gesture shows is decided on the header, not the svg: every layer
   reads its own flag, the header sets exactly one. */
.mark__gesture {
  opacity: 0;
}
.mark__gesture[data-gesture="hi"] {
  opacity: var(--gesture-hi, 0);
}
.mark__gesture[data-gesture="lines"] {
  opacity: var(--gesture-lines, 0);
}
.mark__gesture[data-gesture="bulb"] {
  opacity: var(--gesture-bulb, 0);
}
.mark__gesture[data-gesture="frame"] {
  opacity: var(--gesture-frame, 0);
}
.mark__gesture[data-gesture="play"] {
  opacity: var(--gesture-play, 0);
}

/* 1. The page's own gesture, while the header is hovered or the name link is
   focused. [data-hover] is the held state after a click (Header.astro): the
   pointer is still on the header, the browser just hasn't noticed yet. */
.site-header[data-gesture="hi"]:is(:hover, [data-hover], :has(.site-header__name:focus-visible)) {
  --gesture-hi: 1;
}
.site-header[data-gesture="lines"]:is(:hover, [data-hover], :has(.site-header__name:focus-visible)) {
  --gesture-lines: 1;
}
.site-header[data-gesture="bulb"]:is(:hover, [data-hover], :has(.site-header__name:focus-visible)) {
  --gesture-bulb: 1;
}
.site-header[data-gesture="frame"]:is(:hover, [data-hover], :has(.site-header__name:focus-visible)) {
  --gesture-frame: 1;
}
.site-header[data-gesture="play"]:is(:hover, [data-hover], :has(.site-header__name:focus-visible)) {
  --gesture-play: 1;
}

/* 2. A link singled out wins over the page: hovering "workshop" from Home
   lights the bulb, not the bubble. Click it and the next page's gesture is
   the bulb too, so nothing changes under the pointer. The [data-gesture]
   on the header is only there to outrank rule 1. Browsers without
   :has() skip this block and keep rule 1, which is the old behaviour. */
.site-header[data-gesture]:has(a[data-gesture]:is(:hover, :focus-visible)) {
  --gesture-hi: 0;
  --gesture-lines: 0;
  --gesture-bulb: 0;
  --gesture-frame: 0;
  --gesture-play: 0;
}
.site-header[data-gesture]:has(a[data-gesture="hi"]:is(:hover, :focus-visible)) {
  --gesture-hi: 1;
}
.site-header[data-gesture]:has(a[data-gesture="lines"]:is(:hover, :focus-visible)) {
  --gesture-lines: 1;
}
.site-header[data-gesture]:has(a[data-gesture="bulb"]:is(:hover, :focus-visible)) {
  --gesture-bulb: 1;
}
.site-header[data-gesture]:has(a[data-gesture="frame"]:is(:hover, :focus-visible)) {
  --gesture-frame: 1;
}
.site-header[data-gesture]:has(a[data-gesture="play"]:is(:hover, :focus-visible)) {
  --gesture-play: 1;
}

/* ---- The full-length figure (Figure.astro) -------------------------------
   Content-scale portrait. Same contract as the mark: his paint is fixed in
   both themes, and only what belongs to the page — the sneaker soles, the
   edge he sits on — flips with the ink. Never scale him to a non-integer
   multiple of the grid in a place where it matters; `crispEdges` keeps the
   pixels hard, but a fractional multiple makes some rows a pixel taller. */
.figure {
  display: block;
  height: auto;
}
.figure__ink {
  fill: var(--text);
}
.figure__muted {
  fill: var(--muted);
}
