/* ==========================================================================
   Joel Mastrian — personal site
   One stylesheet for every page. Sections, in order:
   1. Fonts   2. Design tokens (colors, type, spacing)   3. Base
   4. Header and navigation   5. Home page   6. Case-study pages
   7. Footer and 404   8. Motion   9. Print
   ========================================================================== */

/* 1. Fonts (self-hosted, so the site makes no third-party requests) -------- */
@font-face {
  font-family: "Fraunces";
  src: url("fonts/fraunces-var.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Fraunces";
  src: url("fonts/fraunces-var-italic.woff2") format("woff2");
  font-weight: 100 900;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: "IBM Plex Sans";
  src: url("fonts/plex-sans-var.woff2") format("woff2");
  font-weight: 100 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "IBM Plex Mono";
  src: url("fonts/plex-mono-400.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "IBM Plex Mono";
  src: url("fonts/plex-mono-500.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}

/* 2. Design tokens ---------------------------------------------------------
   Every color on the site comes from these variables. Change a value here
   and it changes everywhere. The dark theme only redefines the variables. */
:root {
  --paper: #f4f1e8;        /* page background */
  --paper-2: #ebe7da;      /* raised or hovered surfaces */
  --ink: #15181b;          /* main text */
  --ink-2: #33383e;        /* secondary text */
  --muted: #62676e;        /* captions and labels */
  --rule: #d5d0c0;         /* hairlines */
  --accent: #bf3f0a;       /* links, emphasis */
  --accent-soft: rgba(191, 63, 10, 0.1);
  --ok: #2f9e44;           /* status lights */
  --warn: #d98e04;

  /* the equipment panels stay dark in both themes */
  --panel: #0f1317;
  --panel-2: #171c22;
  --panel-ink: #ece8dd;
  --panel-muted: #8d949c;
  --panel-rule: #272d35;
  --panel-accent: #ff8a4c;
  --panel-link: #4dabf7;   /* lab panel: layers that connect to the outside (edge, off-site) */

  --serif: "Fraunces", Georgia, "Times New Roman", serif;
  --sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Consolas, "Courier New", monospace;

  --wrap: 1140px;
  --gutter: clamp(20px, 4vw, 40px);
  --section: clamp(64px, 9vw, 120px);

  color-scheme: light;
}

/* Dark theme: used when the visitor's system is dark (unless they chose
   light with the toggle), or when they chose dark with the toggle. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0d1013;
    --paper-2: #151a1f;
    --ink: #ece8dd;
    --ink-2: #c9c5ba;
    --muted: #8d949c;
    --rule: #262c33;
    --accent: #ff8a4c;
    --accent-soft: rgba(255, 138, 76, 0.12);
    --ok: #51cf66;
    --warn: #fcc419;
    --panel: #14191e;
    --panel-2: #1b2128;
    --panel-rule: #2c333b;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #0d1013;
  --paper-2: #151a1f;
  --ink: #ece8dd;
  --ink-2: #c9c5ba;
  --muted: #8d949c;
  --rule: #262c33;
  --accent: #ff8a4c;
  --accent-soft: rgba(255, 138, 76, 0.12);
  --ok: #51cf66;
  --warn: #fcc419;
  --panel: #14191e;
  --panel-2: #1b2128;
  --panel-rule: #2c333b;
  color-scheme: dark;
}

/* 3. Base ------------------------------------------------------------------ */
*,
*::before,
*::after {
  box-sizing: border-box;
}
html {
  scroll-behavior: smooth;
  scroll-padding-top: 84px;
  -webkit-text-size-adjust: 100%;
}
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1.0625rem;
  line-height: 1.62;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
img,
svg {
  max-width: 100%;
  display: block;
}
a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}
a:hover {
  text-decoration-thickness: 2px;
}
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 2px;
}
h1,
h2,
h3 {
  font-family: var(--serif);
  font-weight: 500;
  line-height: 1.1;
  letter-spacing: -0.015em;
  margin: 0;
  text-wrap: balance;
}
p {
  margin: 0 0 1em;
  text-wrap: pretty;
}
ul,
ol {
  margin: 0;
  padding: 0;
}
::selection {
  background: var(--accent);
  color: #fff;
}

.wrap {
  width: 100%;
  max-width: var(--wrap);
  margin-inline: auto;
  padding-inline: var(--gutter);
}
.mono,
.eyebrow,
.label {
  font-family: var(--mono);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.skip {
  position: absolute;
  left: 12px;
  top: -60px;
  z-index: 100;
  padding: 10px 14px;
  background: var(--ink);
  color: var(--paper);
  border-radius: 4px;
}
.skip:focus {
  top: 12px;
}

/* 4. Header and navigation ------------------------------------------------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: color-mix(in srgb, var(--paper) 86%, transparent);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--rule);
}
.site-header .wrap {
  display: flex;
  align-items: center;
  gap: 24px;
  min-height: 64px;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  margin-right: auto;
  color: var(--ink);
  text-decoration: none;
  font-family: var(--serif);
  font-size: 1.125rem;
  font-weight: 500;
  letter-spacing: -0.01em;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 7px;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--mono);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  position: relative;
}
.brand-mark::after {
  /* the small status light on the monogram */
  content: "";
  position: absolute;
  right: 5px;
  top: 5px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--panel-accent);
}
.site-nav {
  display: flex;
  align-items: center;
  gap: 4px;
}
.site-nav a {
  padding: 8px 12px;
  border-radius: 6px;
  color: var(--ink-2);
  font-size: 0.9375rem;
  text-decoration: none;
}
.site-nav a:hover,
.site-nav a[aria-current="page"] {
  color: var(--ink);
  background: var(--paper-2);
}
.icon-btn {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}
.icon-btn:hover {
  background: var(--paper-2);
}
.icon-btn svg {
  width: 18px;
  height: 18px;
}
.nav-toggle {
  display: none;
}

@media (max-width: 760px) {
  .nav-toggle {
    display: grid;
  }
  .site-nav {
    display: none;
    position: absolute;
    left: 0;
    right: 0;
    top: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding: 8px var(--gutter) 16px;
    background: var(--paper);
    border-bottom: 1px solid var(--rule);
  }
  .site-nav.is-open {
    display: flex;
  }
  .site-nav a {
    padding: 14px 4px;
    border-radius: 0;
    border-bottom: 1px solid var(--rule);
    font-size: 1.0625rem;
  }
  .site-nav a:last-child {
    border-bottom: 0;
  }
  /* without JavaScript the menu button can't work, so show the links inline */
  html:not(.js) .nav-toggle {
    display: none;
  }
  html:not(.js) .site-nav {
    display: flex;
    position: static;
    flex-direction: row;
    padding: 0;
    border: 0;
    overflow-x: auto;
  }
  html:not(.js) .site-nav a {
    border: 0;
    padding: 8px 10px;
    font-size: 0.9375rem;
  }
}

/* 5. Home page ------------------------------------------------------------- */
.hero {
  position: relative;
  padding-block: clamp(48px, 8vw, 104px) clamp(40px, 6vw, 72px);
  overflow: hidden;
}
.hero::before {
  /* faint dotted "engineering paper" grid behind the hero */
  content: "";
  position: absolute;
  inset: 0;
  background-image: radial-gradient(var(--rule) 1.1px, transparent 1.1px);
  background-size: 22px 22px;
  -webkit-mask-image: radial-gradient(120% 90% at 80% 0%, #000 0%, transparent 70%);
  mask-image: radial-gradient(120% 90% at 80% 0%, #000 0%, transparent 70%);
  opacity: 0.9;
  pointer-events: none;
}
.hero .wrap {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1.12fr) minmax(0, 0.88fr);
  gap: clamp(32px, 5vw, 72px);
  align-items: center;
}
.hero h1 {
  margin-top: 22px;
  font-size: clamp(2.5rem, 5.1vw, 4.25rem);
  line-height: 1.03;
  letter-spacing: -0.025em;
}
.hero h1 em {
  font-style: italic;
  font-weight: 400;
  color: var(--accent);
}
.lede {
  margin-top: 26px;
  max-width: 56ch;
  font-size: clamp(1.0625rem, 1.3vw, 1.1875rem);
  color: var(--ink-2);
}
.cta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 30px;
}
.btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 13px 20px;
  border: 1px solid var(--ink);
  border-radius: 8px;
  background: var(--ink);
  color: var(--paper);
  font-weight: 500;
  font-size: 1rem;
  text-decoration: none;
  transition: transform 0.15s ease, background 0.15s ease, color 0.15s ease;
}
.btn:hover {
  transform: translateY(-1px);
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-ghost {
  background: transparent;
  color: var(--ink);
  border-color: var(--rule);
}
.btn-ghost:hover {
  background: var(--paper-2);
  border-color: var(--ink);
  color: var(--ink);
}
.btn .arrow {
  transition: transform 0.15s ease;
}
.btn:hover .arrow {
  transform: translateX(3px);
}
.hero-note {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-top: 30px;
  text-transform: none;
  letter-spacing: 0.01em;
  font-size: 0.8125rem;
}
.led {
  flex: none;
  width: 8px;
  height: 8px;
  margin-top: 0.55em;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 22%, transparent);
}

/* The lab panel: a logical view of the homelab, drawn like rack equipment */
.rack {
  margin: 0;
  border: 1px solid var(--panel-rule);
  border-radius: 14px;
  background: var(--panel);
  color: var(--panel-ink);
  box-shadow: 0 30px 60px -30px rgba(0, 0, 0, 0.45), 0 2px 0 rgba(255, 255, 255, 0.04) inset;
  overflow: hidden;
}
.rack-head,
.rack-foot {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 18px;
  font-family: var(--mono);
  font-size: 0.6875rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--panel-muted);
}
.rack-head {
  border-bottom: 1px solid var(--panel-rule);
}
.rack-foot {
  border-top: 1px solid var(--panel-rule);
  text-transform: none;
  letter-spacing: 0;
  font-family: var(--serif);
  font-style: italic;
  font-size: 0.9375rem;
  color: var(--panel-ink);
}
.rack-foot span {
  font-family: var(--mono);
  font-style: normal;
  font-size: 0.6875rem;
  color: var(--panel-muted);
  white-space: nowrap;
  align-self: center;
}
.units {
  list-style: none;
  padding: 8px;
  display: grid;
  gap: 6px;
}
.unit {
  display: grid;
  grid-template-columns: 26px 86px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border: 1px solid var(--panel-rule);
  border-radius: 7px;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
}
.unit-led {
  width: 7px;
  height: 7px;
  margin-left: 6px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 8px var(--ok);
}
.unit:nth-child(1) .unit-led,
.unit:nth-child(6) .unit-led {
  background: var(--panel-link);
  box-shadow: 0 0 8px var(--panel-link);
}
.unit-k {
  font-family: var(--mono);
  font-size: 0.6875rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--panel-muted);
}
.unit-v {
  display: block;
  font-size: 0.9375rem;
  font-weight: 500;
  line-height: 1.3;
}
.unit-d {
  display: block;
  font-family: var(--mono);
  font-size: 0.71875rem;
  color: var(--panel-muted);
  line-height: 1.4;
}

/* Numbers strip */
.stats {
  border-block: 1px solid var(--rule);
}
.stats ul {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr)) minmax(0, 1.55fr);
}
.stat {
  padding: 26px 20px 24px 0;
  border-left: 1px solid var(--rule);
  padding-left: 20px;
}
.stat:first-child {
  border-left: 0;
  padding-left: 0;
}
.stat-n {
  display: block;
  font-family: var(--serif);
  font-size: clamp(1.375rem, 2.05vw, 1.875rem);
  font-weight: 500;
  letter-spacing: -0.02em;
  line-height: 1.1;
  white-space: nowrap;
}
.stat-n small {
  font-size: 0.6em;
  color: var(--accent);
  padding-inline: 0.15em;
}
.stat-l {
  display: block;
  margin-top: 8px;
  font-size: 0.8125rem;
  line-height: 1.4;
  color: var(--muted);
}

/* Section scaffolding */
.section {
  padding-block: var(--section);
}
.section + .section {
  border-top: 1px solid var(--rule);
}
.section-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr);
  gap: 24px clamp(32px, 5vw, 72px);
  align-items: end;
  margin-bottom: clamp(32px, 4vw, 56px);
}
.section-head h2 {
  margin-top: 14px;
  font-size: clamp(2rem, 3.6vw, 3rem);
}
.section-head p {
  margin: 0;
  max-width: 58ch;
  color: var(--ink-2);
}

/* Selected work: one full-width row per case study */
.work-list {
  list-style: none;
  border-bottom: 1px solid var(--rule);
}
.work-row {
  display: grid;
  grid-template-columns: 56px minmax(0, 1.25fr) minmax(0, 1fr) 28px;
  gap: 8px clamp(16px, 3vw, 40px);
  align-items: baseline;
  padding: 26px 12px;
  margin-inline: -12px;
  border-top: 1px solid var(--rule);
  border-radius: 4px;
  color: inherit;
  text-decoration: none;
  transition: background 0.15s ease;
}
.work-row:hover {
  background: var(--paper-2);
}
.work-num {
  font-family: var(--mono);
  font-size: 0.8125rem;
  color: var(--muted);
}
.work-title {
  font-family: var(--serif);
  font-size: clamp(1.3rem, 2.1vw, 1.75rem);
  font-weight: 500;
  line-height: 1.15;
  letter-spacing: -0.015em;
  transition: color 0.15s ease;
}
.work-row:hover .work-title {
  color: var(--accent);
}
.work-result {
  color: var(--ink-2);
  font-size: 0.9875rem;
  line-height: 1.5;
}
.work-tags {
  display: block;
  margin-top: 8px;
  font-family: var(--mono);
  font-size: 0.71875rem;
  color: var(--muted);
}
.work-arrow {
  justify-self: end;
  font-size: 1.25rem;
  color: var(--muted);
  transition: transform 0.15s ease, color 0.15s ease;
}
.work-row:hover .work-arrow {
  transform: translateX(4px);
  color: var(--accent);
}
.also {
  margin-top: 28px;
  color: var(--ink-2);
  font-size: 0.9875rem;
  max-width: 78ch;
}
.also strong {
  font-weight: 500;
  color: var(--ink);
}

/* How I work */
.principles {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(20px, 3vw, 40px);
  counter-reset: p;
}
.principles li {
  padding-top: 20px;
  border-top: 2px solid var(--ink);
}
.principles h3 {
  margin: 12px 0 10px;
  font-size: 1.4375rem;
}
.principles p {
  margin: 0;
  color: var(--ink-2);
  font-size: 0.9875rem;
}
.pull {
  margin: clamp(36px, 5vw, 64px) 0 0;
  max-width: 30ch;
  font-family: var(--serif);
  font-size: clamp(1.5rem, 2.6vw, 2.125rem);
  font-style: italic;
  font-weight: 400;
  line-height: 1.25;
  letter-spacing: -0.01em;
}
.pull::before {
  content: "";
  display: block;
  width: 44px;
  height: 2px;
  margin-bottom: 20px;
  background: var(--accent);
}

/* Experience */
.roles {
  list-style: none;
}
.role {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 2.4fr);
  gap: 8px clamp(24px, 5vw, 72px);
  padding-block: 30px;
  border-top: 1px solid var(--rule);
}
.role-when {
  padding-top: 6px;
}
.role-when .tag {
  display: inline-block;
  margin-top: 10px;
  padding: 3px 8px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  font-size: 0.65625rem;
}
.role h3 {
  font-size: 1.5rem;
}
.role-org {
  margin: 6px 0 14px;
  color: var(--ink-2);
}
.role-org b {
  font-weight: 500;
  color: var(--ink);
}
.role ul {
  list-style: none;
  display: grid;
  gap: 9px;
}
.role li {
  position: relative;
  padding-left: 20px;
  color: var(--ink-2);
  font-size: 0.9875rem;
}
.role li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.72em;
  width: 9px;
  height: 1px;
  background: var(--accent);
}

/* Skills */
.skills {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 clamp(32px, 5vw, 72px);
}
.skills dl {
  margin: 0;
}
.skills .row {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  gap: 16px;
  padding-block: 14px;
  border-top: 1px solid var(--rule);
}
.skills dt {
  padding-top: 3px;
}
.skills dd {
  margin: 0;
  color: var(--ink-2);
  font-size: 0.9875rem;
}
.skills h3 {
  margin-bottom: 18px;
  font-size: 1.4375rem;
}

/* Contact */
.contact {
  background: var(--panel);
  color: var(--panel-ink);
  border-top: 0 !important;
}
.contact .eyebrow {
  color: var(--panel-muted);
}
.contact h2 {
  margin-top: 16px;
  max-width: 18ch;
  font-size: clamp(2.25rem, 5vw, 4rem);
  letter-spacing: -0.025em;
}
.contact h2 em {
  font-weight: 400;
  color: var(--panel-accent);
}
.contact p {
  margin-top: 22px;
  max-width: 52ch;
  color: var(--panel-muted);
}
.contact-links {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 40px;
}
.contact-links a {
  display: block;
  padding: 18px 20px;
  border: 1px solid var(--panel-rule);
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--panel-ink);
  text-decoration: none;
  transition: border-color 0.15s ease, transform 0.15s ease;
}
.contact-links a:hover {
  border-color: var(--panel-accent);
  transform: translateY(-2px);
}
.contact-links .label {
  display: block;
  margin-bottom: 6px;
  color: var(--panel-muted);
}
.contact-links .val {
  font-size: 1rem;
  overflow-wrap: anywhere;
}
.contact :focus-visible {
  outline-color: var(--panel-accent);
}

/* 6. Case-study pages ------------------------------------------------------ */
.case-hero {
  padding-block: clamp(40px, 6vw, 80px) clamp(28px, 4vw, 48px);
  border-bottom: 1px solid var(--rule);
}
.crumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.crumbs a {
  color: var(--muted);
  text-decoration: none;
}
.crumbs a:hover {
  color: var(--accent);
}
.case-hero h1 {
  margin-top: 22px;
  max-width: 20ch;
  font-size: clamp(2.25rem, 4.6vw, 3.75rem);
  letter-spacing: -0.025em;
  line-height: 1.04;
}
.case-hero .lede {
  max-width: 64ch;
}
.case-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: clamp(32px, 6vw, 88px);
  padding-block: clamp(40px, 6vw, 72px) var(--section);
  align-items: start;
}
.facts {
  position: sticky;
  top: 92px;
  order: 2;
  margin: 0;
  padding: 4px 0 0;
}
.facts .row {
  padding-block: 14px;
  border-top: 1px solid var(--rule);
}
.facts .row:last-child {
  border-bottom: 1px solid var(--rule);
}
.facts dt {
  margin-bottom: 4px;
}
.facts dd {
  margin: 0;
  font-size: 0.9375rem;
  color: var(--ink-2);
}
.facts dd b {
  font-family: var(--serif);
  font-size: 1.375rem;
  font-weight: 500;
  color: var(--ink);
  letter-spacing: -0.01em;
}

.prose {
  min-width: 0;
  max-width: 70ch;
}
.prose > * + * {
  margin-top: 1.05em;
}
.prose h2 {
  margin-top: 2.2em;
  font-size: clamp(1.5rem, 2.4vw, 1.9375rem);
}
.prose h2:first-child {
  margin-top: 0;
}
.prose h3 {
  margin-top: 1.8em;
  font-family: var(--sans);
  font-size: 1.0625rem;
  font-weight: 600;
  letter-spacing: 0;
  line-height: 1.4;
}
.prose p,
.prose li {
  color: var(--ink-2);
}
.prose strong {
  color: var(--ink);
  font-weight: 600;
}
.prose ul,
.prose ol {
  padding-left: 1.25em;
  display: grid;
  gap: 0.5em;
}
.prose li::marker {
  color: var(--accent);
}
.prose code {
  padding: 0.12em 0.4em;
  border-radius: 4px;
  background: var(--paper-2);
  font-family: var(--mono);
  font-size: 0.875em;
  color: var(--ink);
}
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.prose table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9375rem;
}
.prose th,
.prose td {
  padding: 11px 14px 11px 0;
  border-bottom: 1px solid var(--rule);
  text-align: left;
  vertical-align: top;
  color: var(--ink-2);
}
.prose th {
  font-family: var(--mono);
  font-size: 0.71875rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom-color: var(--ink);
  white-space: nowrap;
}
.prose td b {
  color: var(--ink);
  font-weight: 600;
}
.good {
  color: var(--ok) !important;
  font-weight: 600;
}

/* Flow diagram: boxes joined by arrows; stacks vertically on small screens.
   Written as ".prose .flow" so it wins over the generic list rules above. */
.prose .flow {
  list-style: none;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: 30px;
  padding: 18px;
  margin-block: 1.6em;
  border: 1px solid var(--panel-rule);
  border-radius: 12px;
  background: var(--panel);
}
.flow li {
  position: relative;
  padding: 14px;
  border: 1px solid var(--panel-rule);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--panel-ink);
  font-size: 0.875rem;
  line-height: 1.4;
}
.flow li + li::before {
  content: "→";
  position: absolute;
  left: -15px;
  top: 50%;
  transform: translate(-50%, -50%);
  color: var(--panel-accent);
  font-family: var(--mono);
}
.flow .k {
  display: block;
  margin-bottom: 6px;
  font-family: var(--mono);
  font-size: 0.65625rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--panel-accent);
}
.flow b {
  display: block;
  font-weight: 500;
  color: var(--panel-ink);
}
.flow span:not(.k) {
  display: block;
  margin-top: 4px;
  font-size: 0.78125rem;
  color: var(--panel-muted);
}
.prose .flow-caption {
  margin-top: -0.6em;
  font-size: 0.8125rem;
  color: var(--muted);
}
/* Variant for longer flows: one step per row, read top to bottom */
.prose .flow.is-rows {
  grid-auto-flow: row;
  gap: 26px;
}
.flow.is-rows li {
  display: grid;
  grid-template-columns: 118px minmax(0, 1fr) minmax(0, 1.25fr);
  gap: 4px 16px;
  align-items: baseline;
}
.flow.is-rows .k,
.flow.is-rows span:not(.k) {
  margin: 0;
}
.flow.is-rows li + li::before {
  content: "↓";
  left: 28px;
  top: -13px;
}
.flow.is-before li + li::before {
  color: var(--panel-muted);
}

/* Dated event list */
.prose .events {
  list-style: none;
  padding: 0;
  gap: 0;
  margin-block: 1.6em;
}
.events li {
  position: relative;
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 20px;
  padding: 0 0 24px 22px;
  border-left: 1px solid var(--rule);
}
.events li:last-child {
  padding-bottom: 0;
}
.events li::before {
  content: "";
  position: absolute;
  left: -5px;
  top: 7px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--paper);
  border: 2px solid var(--accent);
}
.events li.is-key::before {
  background: var(--accent);
}
.events time {
  padding-top: 3px;
  font-family: var(--mono);
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  color: var(--muted);
  white-space: nowrap;
}
.events p {
  margin: 0;
}
.events p + p {
  margin-top: 0.5em;
}

.callout {
  padding: 18px 20px;
  border-left: 3px solid var(--accent);
  border-radius: 0 8px 8px 0;
  background: var(--accent-soft);
}
.callout .label {
  display: block;
  margin-bottom: 6px;
  color: var(--accent);
}
.callout p {
  margin: 0;
  color: var(--ink);
}

.case-nav {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding-block: 0 var(--section);
}
.case-nav a {
  display: block;
  padding: 22px 24px;
  border: 1px solid var(--rule);
  border-radius: 10px;
  color: var(--ink);
  text-decoration: none;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.case-nav a:hover {
  border-color: var(--accent);
  background: var(--paper-2);
}
.case-nav .next {
  text-align: right;
}
.case-nav b {
  display: block;
  margin-top: 8px;
  font-family: var(--serif);
  font-size: 1.25rem;
  font-weight: 500;
  line-height: 1.2;
}

/* 7. Footer and 404 -------------------------------------------------------- */
.site-footer {
  padding-block: 28px;
  border-top: 1px solid var(--rule);
  font-size: 0.875rem;
  color: var(--muted);
}
.contact + .site-footer {
  background: var(--panel);
  border-top-color: var(--panel-rule);
  color: var(--panel-muted);
}
.site-footer .wrap {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px 24px;
}
.site-footer a {
  color: inherit;
}
.notfound {
  min-height: 62vh;
  display: grid;
  align-content: center;
  padding-block: var(--section);
}
.notfound h1 {
  margin-top: 18px;
  font-size: clamp(2.5rem, 6vw, 4.5rem);
  letter-spacing: -0.025em;
}
.notfound p {
  margin-top: 20px;
  max-width: 50ch;
  color: var(--ink-2);
}

/* Responsive adjustments */
@media (max-width: 1000px) {
  .stats ul {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .stat:nth-child(4) {
    border-left: 0;
    padding-left: 0;
  }
  .stat:nth-child(n + 4) {
    border-top: 1px solid var(--rule);
  }
  .case-body {
    grid-template-columns: minmax(0, 1fr);
  }
  .facts {
    position: static;
    order: 0;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: 24px;
  }
  .facts .row:last-child,
  .facts .row:nth-last-child(2) {
    border-bottom: 1px solid var(--rule);
  }
}
@media (max-width: 860px) {
  .hero .wrap {
    grid-template-columns: minmax(0, 1fr);
  }
  .section-head {
    grid-template-columns: minmax(0, 1fr);
    align-items: start;
  }
  .principles {
    grid-template-columns: minmax(0, 1fr);
  }
  .skills {
    grid-template-columns: minmax(0, 1fr);
    gap: 40px;
  }
  .role {
    grid-template-columns: minmax(0, 1fr);
  }
  .work-row {
    grid-template-columns: 40px minmax(0, 1fr) 24px;
  }
  .work-result {
    grid-column: 2 / 3;
  }
  .work-arrow {
    grid-column: 3;
    grid-row: 1;
  }
  .contact-links {
    grid-template-columns: minmax(0, 1fr);
  }
  .prose .flow {
    grid-auto-flow: row;
    gap: 26px;
  }
  .flow li + li::before,
  .flow.is-rows li + li::before {
    content: "↓";
    left: 28px;
    top: -13px;
  }
  .flow.is-rows li {
    grid-template-columns: minmax(0, 1fr);
  }
  .flow.is-rows span:not(.k) {
    margin-top: 2px;
  }
}
@media (max-width: 560px) {
  .stats ul {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .stat {
    padding: 20px 12px 18px 16px;
  }
  .stat:nth-child(odd) {
    border-left: 0;
    padding-left: 0;
  }
  .stat:nth-child(4) {
    border-left: 1px solid var(--rule);
    padding-left: 16px;
  }
  .stat:nth-child(n + 3) {
    border-top: 1px solid var(--rule);
  }
  .unit {
    grid-template-columns: 20px minmax(0, 1fr);
  }
  .unit-k {
    grid-column: 2;
  }
  .unit-body {
    grid-column: 2;
  }
  .unit-led {
    grid-row: 1 / 3;
    margin-left: 2px;
  }
  .skills .row {
    grid-template-columns: minmax(0, 1fr);
    gap: 4px;
  }
  .facts {
    grid-template-columns: minmax(0, 1fr);
  }
  .facts .row:nth-last-child(2) {
    border-bottom: 0;
  }
  .events li {
    grid-template-columns: minmax(0, 1fr);
    gap: 4px;
  }
  .case-nav {
    grid-template-columns: minmax(0, 1fr);
  }
  .case-nav .next {
    text-align: left;
  }
  .prose th {
    white-space: normal;
  }
  .prose th,
  .prose td {
    padding-right: 10px;
  }
}

/* 8. Motion ----------------------------------------------------------------
   Only runs when JavaScript has loaded (html.js) and the visitor has not
   asked their system to reduce motion. Without either, everything is simply
   visible. */
@media (prefers-reduced-motion: no-preference) {
  .js .rise {
    opacity: 0;
    transform: translateY(14px);
    animation: rise 0.7s cubic-bezier(0.2, 0.7, 0.2, 1) forwards;
    animation-delay: calc(var(--i, 0) * 90ms + 60ms);
  }
  .js .reveal {
    opacity: 0;
    transform: translateY(18px);
    transition: opacity 0.7s ease, transform 0.7s cubic-bezier(0.2, 0.7, 0.2, 1);
  }
  .js .reveal.is-in {
    opacity: 1;
    transform: none;
  }
  .unit-led {
    animation: blink 4.2s ease-in-out infinite;
    animation-delay: calc(var(--i, 0) * 0.55s);
  }
}
@keyframes rise {
  to {
    opacity: 1;
    transform: none;
  }
}
@keyframes blink {
  0%,
  86%,
  100% {
    opacity: 1;
  }
  92% {
    opacity: 0.25;
  }
}
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

/* 9. Print ----------------------------------------------------------------- */
@media print {
  .site-header,
  .cta-row,
  .case-nav,
  .icon-btn {
    display: none !important;
  }
  body {
    background: #fff;
    color: #000;
    font-size: 11pt;
  }
  .section {
    padding-block: 24pt;
  }
}

/* Projects page: the case-study list under a page header */
.projects-body {
  padding-block: clamp(24px, 4vw, 48px) var(--section);
}
