/* ==========================================================================
   Theme. All visual decisions live in the tokens below.
   Templates carry structure only; restyle the site by editing this block.
   ========================================================================== */

:root {
  /* Cards are paper in both light and dark mode, like a card on a table;
     dark mode darkens the photo around them instead. */
  color-scheme: light;

  /* type: the web font family itself is set in site.toml [fonts];
     the build appends it in front of these fallbacks. */
  --font-fallback: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --font-body: var(--font-fallback);
  --font-head: var(--font-body);
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --weight-head: 600;
  --step--1: 0.875rem;
  --step-0: clamp(0.98rem, 0.95rem + 0.15vw, 1.06rem);
  --step-1: clamp(1.12rem, 1.05rem + 0.35vw, 1.3rem);
  --step-2: clamp(1.5rem, 1.3rem + 1vw, 1.95rem);

  /* paper (every pairing below measured: ink 14.8:1, muted 6.5:1, brick 7.0:1) */
  --paper: #f2eee5;
  --paper-texture: none;         /* the build sets a generated grain tile */
  --paper-grain: 1;              /* grain strength, 0 to 1 */
  --paper-grain-size: 64px;      /* tile size; smaller is finer grain */
  --ink: #1e1b16;
  --ink-muted: #5b544a;
  --rule: #d6cfc1;
  --accent: #8a3324;             /* brick: button fill and links */
  --on-accent: #ffffff;
  --link: #8a3324;
  --focus: #1e1b16;
  --field-bg: #fbf9f4;
  --field-border: #7d7466;
  --card-radius: 0;
  /* Layered depth: contact + near + far, slightly weighted low, so the card
     reads as a sheet resting above the surface with its edges barely lifted. */
  --card-shadow:
    0 1px 1px rgb(0 0 0 / 0.16),
    0 10px 20px rgb(0 0 0 / 0.16),   /* near: wide blur, so no hard shadow edge */
    0 20px 34px rgb(0 0 0 / 0.20),
    0 34px 58px rgb(0 0 0 / 0.15);
  --card-edge: url(#deckle);      /* very subtle hand-made paper edge; none to disable */

  /* photo */
  --page-bg: #14110d;            /* shown before the photo loads */
  --scrim: rgb(0 0 0 / 0.12);

  /* background motion. Turn any part off by setting its strength to 0. */
  --bg-zoom: 1.03;               /* held zoom, so the sway never shows an edge */
  --bg-sway: 6px;                /* how far the photo sways */
  --bg-sway-period: 47s;         /* one sway pass; alternates back */
  --bg-soft-max: 0.35;           /* peak opacity of the blurred copy (0 = off) */
  --bg-soft-blur: 14px;
  --bg-soft-period: 31s;
  --twinkle-max: 0.85;           /* how far warm lights dim at their dimmest (0 = off) */
  --twinkle-period: 11s;         /* base period; the three layers run at 1x, 1.37x, 1.73x */

  /* layout: narrow cards leave room for the photo */
  --measure: 27rem;
  --gutter: 16px;
  --space: 0.9rem;
  --pad: clamp(1rem, 3vw, 1.5rem);
}

@media (prefers-color-scheme: dark) {
  :root { --scrim: rgb(0 0 0 / 0.38); }
}

/* ---- reset ------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--page-bg);
  color: var(--ink);
  font: 400 var(--step-0)/1.55 var(--font-body);
  font-variant-numeric: oldstyle-nums proportional-nums;
  font-kerning: normal;
  overflow-x: hidden;
}
img { display: block; max-width: 100%; }
[hidden] { display: none !important; }   /* author display rules must never un-hide things */
h1, h2, h3 { font-family: var(--font-head); font-weight: var(--weight-head); line-height: 1.15; margin: 0 0 0.5em; }
h1 {
  font-size: var(--step-2);
  padding-bottom: 0.35em;
  border-bottom: 1px solid var(--rule);   /* echoes the rule on the printed card */
}
h2 { font-size: var(--step-1); }
p { margin: 0 0 1em; }
a { color: var(--link); text-underline-offset: 0.18em; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }

/* ---- fixed backdrop ------------------------------------------------------
   position: fixed instead of background-attachment: fixed, which iOS ignores. */
.backdrop {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
}
.backdrop::after { content: ""; position: absolute; inset: 0; background: var(--scrim); }
.backdrop img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: var(--bg-focus, 50% 50%);
}

/* ---- ember background (style = "embers"): still photo + drifting canvas ---- */
.backdrop.is-embers::after { display: none; }   /* ember scrim replaces the fixed one */
.backdrop-still { position: absolute; inset: 0; }
.backdrop-scrim { position: absolute; inset: 0; background: #0a0705; opacity: 0; }
canvas.embers { position: absolute; inset: 0; width: 100%; height: 100%; }

/* ---- backdrop motion ------------------------------------------------------
   Only transform and opacity animate, which the GPU composites without
   re-rendering the image. Periods share no common factor, so the combined
   motion effectively never repeats and reads as random. */
.backdrop-motion {
  position: absolute;
  inset: 0;
  transform: scale(var(--bg-zoom));
  will-change: transform;
  animation: bg-sway var(--bg-sway-period) ease-in-out infinite alternate;
}
.backdrop-motion > picture,
.backdrop-motion > .backdrop-twinkle { position: absolute; inset: 0; width: 100%; height: 100%; }
.backdrop-soft {
  filter: blur(var(--bg-soft-blur));
  opacity: 0;
  will-change: opacity;
  animation: bg-soften var(--bg-soft-period) ease-in-out infinite alternate;
}
/* Near-black masks over the warm lights, built from the photo by build.py.
   Each fades on its own clock, so different lights dim at different times. */
.backdrop-twinkle {
  object-fit: cover;
  object-position: var(--bg-focus, 50% 50%);
  opacity: 0;
  will-change: opacity;
  animation: twinkle var(--twinkle-period) ease-in-out infinite alternate;
}
.backdrop-twinkle.t2 { animation-duration: calc(var(--twinkle-period) * 1.37); animation-delay: calc(var(--twinkle-period) * -0.6); }
.backdrop-twinkle.t3 { animation-duration: calc(var(--twinkle-period) * 1.73); animation-delay: calc(var(--twinkle-period) * -1.3); }

@keyframes bg-sway {
  0%   { transform: scale(var(--bg-zoom)) translate3d(0, 0, 0); }
  27%  { transform: scale(var(--bg-zoom)) translate3d(calc(var(--bg-sway) * -1), calc(var(--bg-sway) * 0.4), 0); }
  58%  { transform: scale(var(--bg-zoom)) translate3d(calc(var(--bg-sway) * 0.7), calc(var(--bg-sway) * -0.6), 0); }
  100% { transform: scale(var(--bg-zoom)) translate3d(calc(var(--bg-sway) * 0.2), calc(var(--bg-sway) * 0.9), 0); }
}
@keyframes bg-soften {
  0%   { opacity: 0; }
  22%  { opacity: calc(var(--bg-soft-max) * 0.8); }
  45%  { opacity: calc(var(--bg-soft-max) * 0.2); }
  70%  { opacity: var(--bg-soft-max); }
  100% { opacity: calc(var(--bg-soft-max) * 0.1); }
}
@keyframes twinkle {
  0%   { opacity: 0; }
  30%  { opacity: var(--twinkle-max); }
  52%  { opacity: calc(var(--twinkle-max) * 0.35); }
  78%  { opacity: calc(var(--twinkle-max) * 0.9); }
  100% { opacity: 0; }
}

/* ---- layout ------------------------------------------------------------ */
.skip-link {
  position: absolute;
  left: var(--gutter);
  top: -100%;
  padding: 0.5em 1em;
  background: var(--paper);
  color: var(--ink);
  z-index: 10;
}
.skip-link:focus { top: var(--gutter); }

.stack {
  width: min(100% - 2 * var(--gutter), var(--measure));
  margin-inline: auto;
  padding-block: clamp(1.5rem, 11vh, 6rem) 3rem;
}
main { display: grid; gap: var(--space); }
main:focus { outline: none; }

/* ---- card: opaque paper, so contrast never depends on the photo --------
   Three layers: the panel carries the depth shadow (clean, never clipped by a
   filter); ::before is the paper sheet (fill + grain + a faint deckle edge);
   ::after lifts the bottom corners. Text sits in the padded panel, well inside
   the ragged edge, so contrast is never touched. */
.panel {
  position: relative;
  color: var(--ink);
  border-radius: var(--card-radius);
  box-shadow: var(--card-shadow);
  padding: var(--pad);
  isolation: isolate;
}
.panel::before {                 /* the paper sheet */
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background-color: var(--paper);
  background-image: var(--paper-texture);
  background-size: var(--paper-grain-size) var(--paper-grain-size);
  background-blend-mode: soft-light;   /* grain x paper, self-contained: tone is kept */
  filter: var(--card-edge);            /* ragged paper edge; ripples the fill, not the text */
  pointer-events: none;
}
.panel::after {                  /* corner lift: two soft shadows under the bottom corners */
  content: "";
  position: absolute;
  z-index: -2;
  left: 14px;
  right: 14px;
  bottom: 13px;
  height: 45%;
  max-height: 90px;
  box-shadow:
    -10px 18px 22px -10px rgb(0 0 0 / 0.40),   /* bottom-left corner */
     10px 18px 22px -10px rgb(0 0 0 / 0.40);   /* bottom-right corner */
  pointer-events: none;
}
.panel > :last-child { margin-bottom: 0; }
.muted { color: var(--ink-muted); }

/* ---- card structure ---------------------------------------------------- */
.card { view-transition-name: card; }      /* lets the browser morph one card into the next */
.card-head > :last-child { margin-bottom: 0; }
.card-head p { margin: 0 0 0.6em; }
.card-section { margin: 1.1rem 0 0; }
.card-section h2 { font-size: var(--step-1); margin-bottom: 0.45em; }

/* expandable sections: native <details>, so keyboard and screen readers work for free */
.fold { margin-top: 1.1rem; }
.fold > summary {
  display: flex;
  align-items: center;
  gap: 0.55em;
  min-height: 44px;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}
.fold > summary::-webkit-details-marker { display: none; }
.fold > summary::before {               /* chevron that turns when opened */
  content: "";
  width: 0.42em;
  height: 0.42em;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg);
  transition: transform 0.2s ease;
  flex: none;
}
.fold[open] > summary::before { transform: rotate(45deg) translate(-0.1em, -0.1em); }
.fold > summary:hover { color: var(--accent); }
.fold-body { padding-top: 0.25rem; }
.fold-body > :last-child { margin-bottom: 0; }

/* page-to-page and unlock-to-shelf transitions, where the browser supports them */
@media (prefers-reduced-motion: no-preference) {
  @view-transition { navigation: auto; }
  ::view-transition-old(card),
  ::view-transition-new(card) { animation-duration: 0.35s; animation-timing-function: ease; }
}

/* ---- form -------------------------------------------------------------- */
.form { display: grid; gap: 0.85rem; }
.field { display: grid; gap: 0.3rem; }
.field label { font-weight: 600; }
.hint { margin: 0; font-size: var(--step--1); color: var(--ink-muted); }
.field input {
  font: inherit;
  color: var(--ink);
  background: var(--field-bg);
  border: 1px solid var(--field-border);
  border-radius: var(--card-radius);
  padding: 0.55em 0.7em;
  min-height: 44px;
  width: 100%;
}
.field input[aria-invalid="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
button {
  font: inherit;
  font-weight: 600;
  color: var(--on-accent);
  background: var(--accent);
  border: 0;
  border-radius: var(--card-radius);
  padding: 0.55em 1.3em;
  min-height: 44px;
  cursor: pointer;
  justify-self: start;
}
button:hover { filter: brightness(1.12); }
button:disabled { opacity: 0.6; cursor: progress; }
.status { margin: 0; min-height: 1.55em; font-size: var(--step--1); }

/* ---- icons ------------------------------------------------------------- */
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: 1.35em; height: 1.35em; fill: currentColor; flex: none; }
.icon-accent { color: var(--accent); }

/* ---- recording note: a paper slip under the card ----------------------- */
.slip { margin-top: var(--space); padding: 0; justify-self: start; }
.slip-open {
  display: flex;
  align-items: center;
  gap: 0.6em;
  min-height: 44px;
  padding: 0.55rem 1rem;
  color: var(--ink);
  font-weight: 600;
  text-decoration: none;
}
.slip-open:hover { color: var(--accent); }
.slip-time { font-weight: 400; font-variant-numeric: lining-nums tabular-nums; }
.slip-desc {
  margin: 0;
  padding: 0 1rem 0.6rem calc(1rem + 1.1em + 0.6em);  /* align under the label, past the icon */
  max-width: 34rem;
}

/* ---- theater: the recording, front and center ------------------------- */
.theater {
  /* Width is driven by the video's own aspect ratio (--ar, set per dialog),
     bounded by the viewport width and, via the height term, its height. So a
     portrait clip stays tall-but-contained instead of stretching to 16:9. */
  width: min(92vw, calc((90dvh - 3.5rem) * var(--ar, 16 / 9)));
  max-width: none;
  max-height: none;
  padding: 0;
  border: 0;
  background: transparent;
  overflow: visible;
}
.theater::backdrop { background: rgb(8 6 4 / 0.86); }
.theater-frame { box-shadow: 0 20px 60px rgb(0 0 0 / 0.55); }
.theater video {
  display: block;
  width: 100%;
  height: auto;               /* width/height attributes reserve the aspect ratio */
  max-height: calc(90dvh - 3.5rem);  /* safety clamp if the ratio math is off */
  object-fit: contain;
  background: #000;
  cursor: pointer;
}
.controls {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.5rem;
  background: var(--paper);
  color: var(--ink);
}
.ctl {
  display: inline-grid;
  place-items: center;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  background: none;
  color: inherit;
  border-radius: 0;
}
.ctl:hover { filter: none; color: var(--accent); }
.ctl-text { font-size: var(--step--1); font-weight: 600; letter-spacing: 0.04em; }
.ctl-text[aria-pressed="true"] { color: var(--on-accent); background: var(--accent); }
.time { font-size: var(--step--1); font-variant-numeric: lining-nums tabular-nums; color: var(--ink-muted); }
.scrub { flex: 1; min-width: 4rem; accent-color: var(--accent); cursor: pointer; }
.video-fallback { margin: 0; padding: 0.6rem 0.8rem; background: var(--paper); font-size: var(--step--1); }

@media (prefers-reduced-motion: no-preference) {
  .theater[open] { animation: theater-in 0.22s ease-out; }
  .theater[open]::backdrop { animation: fade-in 0.22s ease-out; }
}
@keyframes theater-in { from { opacity: 0; transform: scale(0.97); } }
@keyframes fade-in { from { opacity: 0; } }

/* plain watch page (no-JS fallback) */
.video-plain { margin-inline: 0; }
.video-plain video { display: block; width: 100%; height: auto; max-height: 80dvh; object-fit: contain; background: #000; }

/* ---- file list --------------------------------------------------------- */
.files { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.9rem; }
/* icon in its own column; name, description and meta stack in the second */
.file {
  display: grid;
  grid-template-columns: 1.4em 1fr;
  column-gap: 0.65em;
  row-gap: 0.05rem;
  align-items: start;
}
.file-icon { grid-row: 1 / span 3; width: 1.4em; height: 1.4em; margin-top: 0.1em; fill: var(--accent); flex: none; }
.file a { font-weight: 600; word-break: break-word; align-self: center; }
.file-desc { margin: 0.1em 0 0.15em; }
.file-meta { font-size: var(--step--1); }

/* ---- library: boxes of external download links ------------------------- */
.library { margin-top: var(--space); }
.library-title {
  display: flex;
  align-items: center;
  gap: 0.5em;
  font-size: var(--step-1);
  margin: 0 0 0.3rem;
}
.library-group { margin-top: 0.7rem; }
.library-group:first-of-type { margin-top: 0.4rem; }
.library-files {
  list-style: none;
  margin: 0.4rem 0 0;
  padding: 0 0 0 1.6em;   /* align under the summary text, past the chevron */
  display: grid;
  gap: 0.5rem;
}
.library-files.is-numbered {
  list-style: decimal;
  padding-left: 3em;       /* room for two-digit markers */
}
.library-files.is-numbered li { padding-left: 0.2em; }
.library-files.is-numbered::marker { color: var(--muted); }   /* fallback; li::marker below is primary */
.library-files.is-numbered li::marker { color: var(--muted); font-variant-numeric: tabular-nums; }
.library-files a { font-weight: 600; word-break: break-word; font-variant-numeric: lining-nums tabular-nums; }

/* ---- contact page ------------------------------------------------------ */
.contact { margin: 0; display: grid; gap: 0.6rem; }
.contact-row { display: grid; grid-template-columns: 7rem 1fr; gap: 0.2rem 1rem; align-items: baseline; }
.contact dt { font-weight: 600; }
.contact dd { margin: 0; word-break: break-word; }
.keyblock { margin-top: 0.7rem; }
.keyblock .key {
  margin: 0.5rem 0 0;
  padding: 0.75rem 0.85rem;
  background: var(--field-bg);
  border: 1px solid var(--field-border);
  border-radius: var(--card-radius);
  font: 0.8rem/1.4 var(--font-mono);
  color: var(--ink);
  white-space: pre;
  overflow-x: auto;
}
@media (max-width: 26rem) {
  .contact-row { grid-template-columns: 1fr; gap: 0; }
  .contact dt { margin-top: 0.4rem; }
}

/* ---- user preferences -------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;   /* otherwise infinite loops would flicker */
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .backdrop-motion, .backdrop-soft, .backdrop-twinkle { animation: none !important; }
  .backdrop-soft, .backdrop-twinkle { display: none; }
}
@media (forced-colors: active) {
  .panel { border: 1px solid CanvasText; box-shadow: none; }
  .panel::before { filter: none; background: Canvas; }
  .panel::after { display: none; }
  .backdrop { display: none; }
}
@media print {
  .backdrop, .skip-link { display: none; }
  .panel { box-shadow: none; padding: 0; }
  .panel::before, .panel::after { display: none; }
}

/* ---- hidden treasure page ---------------------------------------------- */
.treasure-open { margin-top: 1.1rem; }
.treasure-open a { font-weight: 600; }

.treasure-hero {
  display: block;
  width: 100%;
  height: auto;
  margin: 0 0 1rem;
  border-radius: var(--card-radius);
}

/* ---- generated by build.py from site.toml [fonts] ---- */
@font-face { font-family: "EB Garamond"; font-style: normal; font-weight: 400; font-display: swap; src: url("/assets/eb-garamond-400-normal.912929db.woff2") format("woff2"); }
@font-face { font-family: "EB Garamond"; font-style: italic; font-weight: 400; font-display: swap; src: url("/assets/eb-garamond-400-italic.fc5851c4.woff2") format("woff2"); }
@font-face { font-family: "EB Garamond"; font-style: normal; font-weight: 600; font-display: swap; src: url("/assets/eb-garamond-600-normal.6a195b7e.woff2") format("woff2"); }
:root { --font-body: "EB Garamond", var(--font-fallback); --weight-head: 600; }
:root { --paper-texture: url("/assets/paper.c4d5ef24.webp"); }
