/* nicolasluraschi.dev: single stylesheet, no JavaScript.
   Direction H3 (Fraunces), terracotta palette. Mobile-first; breakpoints at 45em, plus 70em for the essay's contents column. */

/* ---------- Font: Fraunces, self-hosted (SIL OFL 1.1, see /fonts/OFL.txt) ----------
   Latin subset, variable: optical size 9-144, weight 400-700. About 62 KB. */
@font-face {
  font-family: "Fraunces";
  src: url("/fonts/fraunces-latin.woff2") format("woff2");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}

/* Metric-adjusted fallbacks, so the page barely moves when Fraunces swaps in. Tuned for Liberation
   Serif, Chromium's serif on Linux; on Apple and Windows, Charter and Georgia already wrap like
   Fraunces and tuning them measured no gain. Measured in Chromium: Fraunces' ascent is 97.8% and
   its descent 25.5% of the em, no line gap; each override is that divided by size-adjust.
   size-adjust is Fraunces' width over Liberation's on the site's copy at body size (110%), then
   checked against the layout shift (tests/browser/font-swap.spec.mjs). Fraunces is narrower at
   display optical sizes, so h1 and the pull quote use their own face (103%). */
@font-face {
  font-family: "Fraunces fallback";
  src: local("Liberation Serif");
  font-weight: 400 500;
  size-adjust: 110%;
  ascent-override: 88.91%;
  descent-override: 23.18%;
  line-gap-override: 0%;
}
@font-face {
  font-family: "Fraunces fallback";
  src: local("Liberation Serif Bold");
  font-weight: 600 700;
  size-adjust: 111%;
  ascent-override: 88.11%;
  descent-override: 22.97%;
  line-gap-override: 0%;
}
@font-face {
  font-family: "Fraunces fallback display";
  src: local("Liberation Serif");
  font-weight: 400 500;
  size-adjust: 103%;
  ascent-override: 94.95%;
  descent-override: 24.76%;
  line-gap-override: 0%;
}

/* ---------- Tokens ---------- */
:root {
  color-scheme: light dark;

  --font: Fraunces, "Fraunces fallback", Charter, "Iowan Old Style", Georgia, serif;
  --font-display: Fraunces, "Fraunces fallback display", Charter, "Iowan Old Style", Georgia, serif; /* h1, pull quote */

  /* Colour: light */
  --bg: #F6F1EB;
  --surface: #ECE0D3;   /* tinted toward the accent: image frames, diagram cards, tags */
  --text: #1E1915;      /* 15.5:1 on --bg */
  --muted: #5C5047;     /* 6.9:1 on --bg, 6.0:1 on --surface */
  --hair: #DDD0C2;      /* decorative hairlines only, never text */
  --accent: #A33D1A;    /* terracotta. 5.8:1 on --bg, 5.0:1 on --surface. Uses: DESIGN.md */

  /* Type scale (rem). The base and display steps grow at the breakpoint. */
  --text-sm: 0.875rem;
  --text-base: 1.0625rem;
  --text-lg: 1.25rem;   /* lead paragraph, org line, job titles */
  --text-xl: 1.5rem;    /* project titles, essay h2 */
  --text-2xl: 2rem;     /* pull quote */
  --text-3xl: 2.75rem;  /* h1 */
  --leading-tight: 1;
  --leading-snug: 1.3;
  --leading-body: 1.6;

  /* Spacing scale */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2.5rem;
  --space-7: 3.5rem;
  --space-8: 5rem;

  /* Layout */
  --gutter: 1.25rem;
  --measure: 37rem;     /* about 68 characters at the body size */
  --wide: 70rem;
  --col-gap: 4rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15110E;
    --surface: #241B15;
    --text: #F0E8E0;    /* 15.5:1 */
    --muted: #B9A898;   /* 8.2:1 */
    --hair: #3A2E25;
    --accent: #EE9466;  /* 8.1:1 */
  }
}

@media (min-width: 45em) {
  :root {
    --text-base: 1.125rem;
    --text-lg: 1.5rem;
    --text-xl: 1.875rem;
    --text-2xl: 2.5rem;
    --text-3xl: 4.5rem;
    --leading-tight: 0.98;
    --space-6: 3.5rem;
    --gutter: 2.5rem;
  }
}

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

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

body {
  margin: 0;
  padding-inline: var(--gutter);
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-optical-sizing: auto;
  font-size: var(--text-base);
  line-height: var(--leading-body);
  text-wrap: pretty;
}

h1, h2, h3 { text-wrap: balance; font-weight: 500; }
p, ul, ol, dl { margin-block: 0 var(--space-4); }

a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
}
a:hover { text-decoration-thickness: 2px; }
a:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
  border-radius: 2px;
}
/* External-link marker; the second declaration gives it an empty text alternative. The link does
   not wrap, so the marker cannot drop onto a line of its own. */
a[href^="https:"] { white-space: nowrap; }
a[href^="https:"]::after {
  content: "\2197";
  content: "\2197" / "";
  display: inline-block;
  margin-left: 0.15em;
  font-size: 0.8em;
  text-decoration: none;
}

.skip {
  position: absolute;
  left: var(--space-2);
  top: -4rem;
  padding: var(--space-2) var(--space-3);
  background: var(--bg);
  border: 2px solid var(--accent);
}
.skip:focus { top: var(--space-2); }

@media (prefers-reduced-motion: no-preference) {
  a { transition: text-decoration-thickness 0.12s ease; }
}

.wrap { max-width: var(--wide); margin-inline: auto; }

/* ---------- Header and footer ---------- */
.site-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-4);
}
.site-header a {
  display: inline-flex;
  align-items: center;
  min-height: 2.75rem;          /* 44px tap target */
  font-size: var(--text-sm);
}
.site-footer {
  margin-top: var(--space-6);
  padding-block: var(--space-4) var(--space-6);
  border-top: 1px solid var(--hair);
  color: var(--muted);
  font-size: var(--text-sm);
}
.site-footer p { margin: 0; }

/* ---------- Headings ---------- */
h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: var(--text-3xl);
  line-height: var(--leading-tight);
  letter-spacing: -0.03em;
}
h3 {
  margin: 0 0 var(--space-3);
  font-size: var(--text-xl);
  line-height: 1.15;
  letter-spacing: -0.015em;
}

/* Section label */
.sec-h {
  margin: var(--space-6) 0 var(--space-5);
  font-size: var(--text-sm);
  line-height: 1.4;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
}

/* ---------- Home: hero ---------- */
.hero { padding-block: var(--space-5) var(--space-5); border-bottom: 1px solid var(--hair); }
.role { margin: var(--space-3) 0 var(--space-4); font-size: 1.125rem; line-height: var(--leading-snug); }
.lead { margin: 0 0 var(--space-4); font-size: 1.25rem; line-height: 1.5; }
.meta { margin: 0; color: var(--muted); font-size: 0.9375rem; }
.hero-body { margin-top: var(--space-4); } /* one column: space below the location line */

/* ---------- Home: selected work ---------- */
.work {
  display: flex;
  flex-direction: column;
  margin-bottom: var(--space-6);
  padding-top: var(--space-5);
  border-top: 1px solid var(--hair);
}
.work:first-of-type { padding-top: 0; border-top: 0; }
.work p { margin-bottom: var(--space-3); }
.shot { order: -1; margin: 0 0 var(--space-4); }
.shot a { display: block; } /* one box, the image's, so the focus ring paints around it */
.shot img {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--hair);
  border-radius: 4px;
  background: var(--surface);
}
/* Labelled stack: one row per layer, label and items on the same line. */
.stack { margin: 0 0 var(--space-3); color: var(--muted); font-size: 0.9375rem; line-height: var(--leading-snug); }
.stack > div { padding-left: var(--space-5); text-indent: calc(-1 * var(--space-5)); } /* wrapped items hang past the label */
.stack > div + div { margin-top: var(--space-2); }
.stack dt {
  display: inline;
  margin-right: var(--space-2);
  font-size: 0.8125rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
}
.stack dd { display: inline; margin: 0; }
.site { white-space: nowrap; } /* the "·" separator wraps with its link, never alone */
.tag {
  display: inline-block;
  padding: 0 0.45rem;
  border: 1px solid var(--accent);
  border-radius: 3px;
  background: var(--surface);
  color: var(--accent);
  font-size: 0.8125rem;
  font-weight: 400;
  letter-spacing: 0;
  vertical-align: 0.2em;
}
.note { margin: 0 0 var(--space-6); color: var(--muted); font-size: 0.9375rem; max-width: var(--measure); }

/* ---------- Home: experience, toolbox ---------- */
.org { margin-bottom: var(--space-5); font-size: var(--text-lg); line-height: var(--leading-snug); }
.org span { color: var(--muted); font-size: var(--text-base); }
.job + .org { margin-top: var(--space-6); padding-top: var(--space-5); border-top: 1px solid var(--hair); } /* an employer after an earlier entry starts its own group */
.job {
  margin-bottom: var(--space-5);
  padding-top: var(--space-5);
  border-top: 1px solid var(--hair);
}
.job h3 { font-size: var(--text-lg); margin-bottom: 0; }
.job .dates { margin: 0 0 var(--space-2); font-size: var(--text-sm); line-height: 1.4; color: var(--muted); }
.job ul { margin: 0; padding-left: 1.15rem; }
.job li { margin-bottom: var(--space-2); }
.job li::marker { color: var(--muted); }
.job p { margin: 0; }

.toolbox { margin: 0; }
.toolbox > div { padding-block: var(--space-3); border-top: 1px solid var(--hair); }
.toolbox > div:first-child { border-top: 0; padding-top: 0; }
.toolbox dt {
  font-size: var(--text-sm);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
}
.toolbox dd { margin: 0; }

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

/* ---------- Home: contact ---------- */
.links {
  display: flex;
  flex-wrap: wrap;
  gap: 0 var(--space-5);
  margin: var(--space-3) 0 0;
  padding: 0;
  list-style: none;
}
.links a { display: inline-flex; align-items: center; min-height: 2.75rem; }
.links .cv { font-size: var(--text-lg); font-weight: 700; }

/* ---------- Essay ----------
   One column with the contents first; from 70em the contents sit in a sticky column beside the
   body. Prose keeps the measure; diagrams (.diagram) take the whole content column. */
.essay { max-width: var(--wide); margin-inline: auto; padding-top: var(--space-6); }
.essay-head > *,
.essay-body > section > :not(.diagram) { max-width: var(--measure); }
.essay h1 { margin-bottom: var(--space-5); }
.essay-head .meta { margin-bottom: var(--space-4); }

.toc { margin-bottom: var(--space-6); font-size: var(--text-sm); line-height: 1.4; }
.toc-h {
  margin-bottom: var(--space-2);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}
.essay .toc ol { margin: 0; padding: 0; list-style: none; }
.essay .toc li { margin: 0; padding: 0; }
.toc a { display: block; padding-block: var(--space-1); }
.essay h2 { margin: var(--space-7) 0 var(--space-4); font-size: var(--text-xl); line-height: 1.15; letter-spacing: -0.015em; }
.essay .lead { font-size: var(--text-lg); }
.essay ul, .essay ol { padding-left: 1.4rem; }
.essay li { margin-bottom: var(--space-3); padding-left: 0.25rem; }
.essay li::marker { color: var(--muted); font-weight: 700; }

.pullquote {
  margin: var(--space-6) 0;
  padding-top: var(--space-4);
  border-top: 2px solid var(--accent);
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  line-height: 1.15;
  font-weight: 500;
  letter-spacing: -0.015em;
}
.pullquote span {
  display: block;
  font-family: var(--font);     /* a small label: the body-size fallback, not the display one */
  margin-bottom: var(--space-2);
  font-size: var(--text-sm);
  line-height: 1.4;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
}

/* Workflow diagram: a visual summary of the numbered list below it (hidden from assistive tech). */
.flow {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-3);
  margin: 0 0 var(--space-5);
  padding: 0;
  list-style: none;
}
.essay .flow { padding: 0; }
.essay .flow li,
.essay .loop li {
  display: grid;
  grid-template-columns: 2.25rem minmax(0, 1fr);
  align-items: start;
  align-content: start;         /* a card shorter than its row keeps its content at the top */
  gap: var(--space-3);
  margin: 0;
}
.flow .n,
.loop .n { font-size: var(--text-xl); line-height: 1; color: var(--accent); font-variant-numeric: lining-nums tabular-nums; }
.flow .t { font-weight: 700; line-height: var(--leading-snug); }
.chip {
  display: inline-block;
  margin-top: var(--space-2);
  padding: 0 0.5rem;
  border: 1px solid var(--text);
  border-radius: 999px;
  font-size: 0.8125rem;
  line-height: 1.6;
  font-weight: 700;
}

/* Diagrams share one card look: --surface, a hairline, 4px corners. */
.diagram { margin: 0 0 var(--space-5); }
.essay .flow li,
.essay .roles li,
.essay .loop li,
.guards {
  padding: var(--space-4);
  border: 1px solid var(--hair);
  border-radius: 4px;
  background: var(--surface);
}

/* Who does what: one card per party. */
.essay .roles { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-3); padding: 0; list-style: none; }
.essay .roles li { margin: 0; }
.roles p { margin: 0; }
.roles .who { margin-bottom: var(--space-2); font-size: var(--text-lg); font-weight: 700; line-height: var(--leading-snug); }
.roles .who span,
.risk thead span,
.loop figcaption,
.guards figcaption {
  display: block;
  font-size: var(--text-sm);
  font-weight: 500;
  line-height: 1.4;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.risk thead span { text-transform: none; letter-spacing: 0; font-weight: 400; }

/* Process sized by risk: a real table, lanes across, steps down. */
.risk {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  background: var(--surface);
  border: 1px solid var(--hair);
  font-size: var(--text-sm);
  line-height: 1.4;
}
.risk caption { margin-bottom: var(--space-2); text-align: left; color: var(--muted); }
.risk th, .risk td { padding: var(--space-2); border-top: 1px solid var(--hair); text-align: left; vertical-align: top; overflow-wrap: break-word; }
.risk th { font-weight: 700; }

/* Phones: four columns are too narrow to read, so each step becomes a card listing its lanes.
   The column headers stay in the table for screen readers, and the visible lane label is given
   an empty text alternative so it is not announced twice. Screen only: print keeps the table. */
@media screen and (max-width: 44.99em) {
  .risk, .risk caption, .risk tbody, .risk tr, .risk th { display: block; }
  .risk { border: 0; background: none; }
  .risk thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .risk tr { padding: var(--space-3) var(--space-4); border: 1px solid var(--hair); border-radius: 4px; background: var(--surface); }
  .risk tr + tr { margin-top: var(--space-2); }
  .risk th, .risk td { padding: 0; border: 0; }
  .risk tbody th { margin-bottom: var(--space-1); }
  .risk td { display: grid; grid-template-columns: 5.5rem minmax(0, 1fr); gap: var(--space-2); }
  .risk td + td { margin-top: var(--space-1); }
  .risk td::before { content: attr(data-lane); content: attr(data-lane) / ""; color: var(--muted); }
}

/* The second opinion: the cross-review loop, one numbered card per step (cards share the flow's grid). */
.essay .loop ol { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-3); margin: 0; padding: 0; list-style: none; }
.loop li p { margin: 0; }

/* Guardrails: what the hooks block. */
.loop figcaption,
.guards figcaption { margin-bottom: var(--space-2); }
.essay .guards ul { margin: 0; }
.essay .guards li { margin-bottom: var(--space-2); }
.essay .guards li:last-child { margin-bottom: 0; }

.essay-page .site-header,
.essay-page .site-footer { max-width: var(--wide); margin-inline: auto; }

/* ---------- Wide screens ---------- */
@media (min-width: 45em) {
  .hero {
    display: grid;
    grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
    column-gap: var(--col-gap);
    align-items: start;
    padding-block: var(--space-7) var(--space-6);
  }
  .role { font-size: 1.25rem; }
  .hero-head .meta { margin-top: var(--space-6); }
  .hero-body { margin-top: 0; }
  .lead { font-size: var(--text-lg); }

  .work { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); column-gap: var(--col-gap); align-items: start; }
  .work-text { grid-column: 1; grid-row: 1; }
  .shot { order: 0; grid-column: 2; grid-row: 1; margin: 0; }

  .job { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); column-gap: var(--col-gap); }
  .job .dates { margin-bottom: 0; }
  .toolbox > div { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); column-gap: var(--col-gap); }
  .org { margin-bottom: var(--space-5); }

  .flow { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .essay .roles { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .risk { font-size: var(--text-base); }
  .risk th, .risk td { padding: var(--space-3); }
  .essay .flow li { grid-template-columns: minmax(0, 1fr); gap: var(--space-2); }
}

@media (min-width: 70em) {
  .essay article {
    display: grid;
    grid-template-columns: 12rem minmax(0, 1fr);
    column-gap: var(--col-gap);
  }
  .essay-head, .essay-body { grid-column: 2; }
  .toc {
    grid-column: 1;
    grid-row: 1 / span 2;
    align-self: start;
    position: sticky;
    top: var(--space-5);
    margin-bottom: 0;
  }
}

/* ---------- Print ----------
   Black on white in either scheme: the one place colours other than the tokens' are allowed
   (scripts/check.py enforces it). No navigation; external links show their URL. */
@media print {
  :root {
    color-scheme: light;
    --bg: #fff;
    --surface: #fff;
    --text: #000;
    --muted: #000;
    --hair: #000;
    --accent: #000;
  }
  .skip, .site-header, .toc { display: none; }
  a[href^="https:"]::after {
    content: " (" attr(href) ")";
    display: inline;
    font-size: 0.8em;
    white-space: normal;          /* the link itself is nowrap; its printed URL may wrap */
    overflow-wrap: anywhere;
  }
  .job, .work, .diagram, .essay .flow li, .essay .roles li, .essay .loop li, .risk tr { break-inside: avoid; }
}
