/* ---------------------------------------------------------------- tokens */

:root {
  --bg:      #0b0d12;
  --surface: #12151d;
  --border:  #232935;
  --text:    #e6e9ef;
  --muted:   #9aa4b6;
  --accent:  #4fd1c5;

  --font-ui:   -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --fs-hero:  clamp(2rem, 6vw, 3.5rem);
  --fs-h2:    clamp(1.5rem, 3vw, 2rem);
  --fs-h3:    1.125rem;
  --fs-body:  1rem;
  --fs-small: 0.875rem;

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-12: 3rem;
  --space-16: 4rem;

  --measure: 68ch;
  --page: 1100px;
  --radius: 4px;
  --header-h: 3.5rem;
}

@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

html { scroll-padding-top: calc(var(--header-h) + var(--space-4)); }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: var(--fs-body);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

/* -------------------------------------------------------- focus and skip */

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

.skip-link {
  position: absolute;
  left: var(--space-4);
  top: -4rem;
  z-index: 100;
  padding: var(--space-2) var(--space-4);
  background: var(--accent);
  color: var(--bg);
  font-weight: 600;
  border-radius: var(--radius);
  transition: top 120ms ease;
}
.skip-link:focus { top: var(--space-2); }

@media (prefers-reduced-motion: reduce) {
  .skip-link { transition: none; }
}

/* ----------------------------------------------------------------- links */

.prose a,
.section__lede a,
.site-footer a,
.case__facts a,
.lab__links a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
}
.prose a:hover,
.section__lede a:hover,
.site-footer a:hover,
.case__facts a:hover,
.lab__links a:hover { text-decoration-thickness: 2px; }

/* ---------------------------------------------------------------- header */

.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.nav {
  max-width: var(--page);
  margin-inline: auto;
  min-height: var(--header-h);
  padding-inline: var(--space-4);
  display: flex;
  align-items: center;
  gap: var(--space-4);
  flex-wrap: wrap;
}

.nav__brand {
  font-family: var(--font-mono);
  font-size: var(--fs-small);
  letter-spacing: 0.02em;
  margin-right: auto;
}
.nav__brand:hover { color: var(--accent); }

.nav__menu {
  display: flex;
  gap: var(--space-6);
  font-size: var(--fs-small);
}

.nav__menu a {
  color: var(--muted);
  padding-block: var(--space-2);
  border-bottom: 2px solid transparent;
}
.nav__menu a:hover { color: var(--text); }
.nav__menu a[aria-current="true"] {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.nav__toggle { display: none; }

/* --------------------------------------------------------- header mobile */

@media (max-width: 720px) {
  .nav { padding-block: var(--space-2); }

  .nav__toggle {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--fs-small);
    font-family: var(--font-mono);
    color: var(--muted);
    padding: var(--space-2);
  }
  .nav__toggle-bars {
    width: 1rem;
    height: 2px;
    background: currentColor;
    box-shadow: 0 -5px 0 currentColor, 0 5px 0 currentColor;
  }

  .nav__menu {
    display: none;
    flex-basis: 100%;
    flex-direction: column;
    gap: 0;
    padding-bottom: var(--space-2);
  }
  .nav[data-open="true"] .nav__menu { display: flex; }

  .nav__menu a {
    display: block;
    padding: var(--space-3) 0;
    border-bottom: 1px solid var(--border);
  }
  .nav__menu a[aria-current="true"] { border-bottom-color: var(--accent); }

  .nav__menu--static { display: flex; flex-direction: row; gap: var(--space-4); }
  .nav__menu--static a { border-bottom: 0; }
}

/* ------------------------------------------------------------------- hero */

.hero {
  border-bottom: 1px solid var(--border);
  background:
    radial-gradient(60rem 24rem at 15% -10%, color-mix(in srgb, var(--accent) 9%, transparent), transparent 70%),
    var(--bg);
}

.hero__inner {
  max-width: var(--page);
  margin-inline: auto;
  padding: var(--space-16) var(--space-4);
  display: flex;
  align-items: center;
  gap: var(--space-12);
}

.hero__photo {
  flex: none;
  width: 180px;
  height: 180px;
  border-radius: 50%;
  border: 1px solid var(--border);
  object-fit: cover;
}

.hero h1 {
  font-size: var(--fs-hero);
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -0.02em;
}

.hero__role {
  margin-top: var(--space-2);
  font-family: var(--font-mono);
  color: var(--accent);
  font-size: var(--fs-body);
}

.hero__pitch {
  margin-top: var(--space-6);
  max-width: 46ch;
  color: var(--muted);
  font-size: 1.0625rem;
}

.hero__actions {
  margin-top: var(--space-8);
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.hero__meta {
  margin-top: var(--space-6);
  font-family: var(--font-mono);
  font-size: var(--fs-small);
  color: var(--muted);
}

.btn {
  display: inline-block;
  padding: var(--space-3) var(--space-6);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: var(--fs-small);
  font-weight: 600;
  color: var(--text);
  background: var(--surface);
}
.btn:hover { border-color: var(--muted); }

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
}
.btn--primary:hover { background: color-mix(in srgb, var(--accent) 85%, white); }

@media (max-width: 720px) {
  .hero__inner {
    flex-direction: column;
    text-align: center;
    gap: var(--space-6);
    padding-block: var(--space-12);
  }
  .hero__pitch { max-width: none; }
  .hero__actions { flex-direction: column; align-items: stretch; }
  .btn { text-align: center; }
}

/* --------------------------------------------------------------- sections */

.section {
  max-width: var(--page);
  margin-inline: auto;
  padding: var(--space-16) var(--space-4);
  border-bottom: 1px solid var(--border);
}
.section:last-of-type { border-bottom: 0; }

.section h2 {
  font-size: var(--fs-h2);
  font-weight: 700;
  letter-spacing: -0.01em;
  margin-bottom: var(--space-6);
}

.section__lede {
  max-width: var(--measure);
  color: var(--muted);
  margin-bottom: var(--space-8);
}

.prose { max-width: var(--measure); }
.prose > * + * { margin-top: var(--space-4); }
.prose p { color: var(--muted); }
.prose strong { color: var(--text); font-weight: 600; }
.prose ul {
  list-style: disc;
  padding-left: 1.25rem;
  color: var(--muted);
}
.prose ul li + li { margin-top: var(--space-2); }

code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.1em 0.35em;
}

/* -------------------------------------------------------------- expertise */

.stack {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: var(--space-8);
}

.stack__group h3 {
  font-size: var(--fs-small);
  font-weight: 600;
  color: var(--text);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--space-4);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}
.chips li {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-1) var(--space-3);
}

/* ------------------------------------------------------------- experience */

.timeline { border-left: 1px solid var(--border); }

.timeline__item {
  position: relative;
  padding: 0 0 var(--space-12) var(--space-8);
}
.timeline__item:last-child { padding-bottom: 0; }

.timeline__item::before {
  content: "";
  position: absolute;
  left: -5px;
  top: 0.6rem;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--bg);
  border: 2px solid var(--border);
}
.timeline__item:first-child::before {
  background: var(--accent);
  border-color: var(--accent);
}

/* Company and location on one line, role and dates on the next, then the bullets. */
.timeline__head,
.timeline__role {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
}

.timeline__head h3 {
  font-size: var(--fs-h3);
  font-weight: 700;
}
.timeline__head span {
  font-size: var(--fs-small);
  color: var(--muted);
}

.timeline__role {
  font-size: var(--fs-small);
  color: var(--accent);
  margin-top: var(--space-1);
}
.timeline__role span {
  font-family: var(--font-mono);
  color: var(--muted);
}

.timeline__points {
  margin-top: var(--space-4);
  max-width: var(--measure);
  list-style: disc;
  padding-left: 1.125rem;
  color: var(--muted);
  font-size: var(--fs-small);
}
.timeline__points li + li { margin-top: var(--space-3); }
.timeline__points::marker { color: var(--border); }

.sidenote {
  margin-top: var(--space-16);
  padding-top: var(--space-8);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: var(--space-8);
}
.sidenote h3 {
  font-size: var(--fs-small);
  font-weight: 600;
  margin-bottom: var(--space-2);
}
.sidenote p {
  color: var(--muted);
  font-size: var(--fs-small);
}

/* ------------------------------------------------------------------ cards */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: var(--space-6);
  margin-bottom: var(--space-12);
}

.card {
  display: flex;
  flex-direction: column;
  border-left: 2px solid var(--border);
  padding-left: var(--space-6);
}
.card:hover { border-left-color: var(--accent); }

.card h3 {
  font-size: var(--fs-h3);
  font-weight: 700;
  margin-bottom: var(--space-3);
}
.card h3 a:hover { color: var(--accent); }

.card p { color: var(--muted); font-size: var(--fs-small); }

.card__stat {
  margin-top: auto;
  padding-top: var(--space-4);
  font-family: var(--font-mono);
  font-size: 0.8125rem;
}
.card__stat span {
  color: var(--accent);
  font-weight: 600;
}

/* ------------------------------------------------------------- ai quality */

/* A tagline sits under the section heading. Italic, and narrower than body copy. */
.section__tagline {
  max-width: var(--measure);
  margin-top: calc(var(--space-6) * -1);
  margin-bottom: var(--space-6);
  font-style: italic;
  font-size: 1.0625rem;
  color: var(--muted);
}

#ai-quality h3 {
  font-size: var(--fs-h3);
  font-weight: 700;
  margin: var(--space-12) 0 var(--space-3);
}
#ai-quality h3:first-of-type { margin-top: var(--space-8); }

.ai__para {
  max-width: var(--measure);
  color: var(--muted);
  font-size: var(--fs-small);
  margin-bottom: var(--space-4);
}
.ai__para strong { color: var(--text); }

.ai__note {
  max-width: var(--measure);
  margin-top: var(--space-4);
  padding-left: var(--space-4);
  border-left: 2px solid var(--accent);
  color: var(--muted);
  font-size: var(--fs-small);
}

/* Five steps in reading order. A real sequence, so it is numbered. */
.steps {
  counter-reset: step;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--space-3);
}

.steps > li {
  counter-increment: step;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 2px solid var(--border);
  border-radius: var(--radius);
  font-size: var(--fs-small);
}
.steps > li:last-child { border-top-color: var(--accent); }

.steps__label {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  color: var(--muted);
}
.steps__label::before {
  content: counter(step) " ";
  color: var(--accent);
}

.steps b { color: var(--text); font-weight: 600; }
.steps span:not(.steps__label) { color: var(--muted); font-size: 0.8125rem; }

/* Four kinds of check, each with the shape of the rule it enforces. */
/* Two by two, so the four kinds read as a set rather than three and a leftover. */
.rules {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-4);
}

@media (max-width: 720px) {
  .rules { grid-template-columns: 1fr; }
}

.rules > li {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-4);
  border: 1px solid var(--border);
  border-left: 2px solid var(--accent);
  border-radius: var(--radius);
}
.rules b { font-weight: 700; }
.rules span { color: var(--muted); font-size: var(--fs-small); }
.rules code {
  margin-top: auto;
  align-self: start;
  max-width: 100%;
  overflow-x: auto;
  font-size: 0.75rem;
}

.judge {
  counter-reset: jstep;
  max-width: var(--measure);
  border-top: 1px solid var(--border);
}
.judge > li {
  counter-increment: jstep;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--space-2);
  padding: var(--space-3) 0 var(--space-3) var(--space-6);
  border-bottom: 1px solid var(--border);
  position: relative;
  font-size: var(--fs-small);
}
.judge > li::before {
  content: counter(jstep);
  position: absolute;
  left: 0;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--accent);
}
.judge b { font-weight: 700; }
.judge span { color: var(--muted); flex: 1 1 100%; }
.judge code { font-size: 0.75rem; }

/* The worked failure. A label column, so it reads as a record. */
.catch {
  border: 1px solid var(--border);
  font-size: var(--fs-small);
}
.catch th[scope="row"] {
  width: 6.5rem;
  vertical-align: top;
  padding: var(--space-3);
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--muted);
  white-space: nowrap;
}
.catch td {
  padding: var(--space-3);
  border-bottom: 1px solid var(--border);
  color: var(--muted);
}
.catch tr:last-child th,
.catch tr:last-child td { border-bottom: 0; }
.catch code { font-size: 0.75rem; white-space: normal; }

.catch__fail {
  display: inline-block;
  margin-right: var(--space-2);
  padding: 0 var(--space-2);
  border: 1px solid #d98a3d;
  border-radius: 3px;
  color: #e5a463;
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  text-transform: uppercase;
}

.section__cta { margin-top: var(--space-12); }

/* ------------------------------------------------------- prose extras */

.quote {
  margin: var(--space-6) 0;
  padding: var(--space-4) var(--space-6);
  border-left: 2px solid var(--accent);
  background: var(--surface);
  color: var(--muted);
  font-size: var(--fs-small);
}
.quote strong { color: var(--text); }

.numbered {
  list-style: decimal;
  padding-left: 1.5rem;
  color: var(--muted);
}
.numbered li + li { margin-top: var(--space-2); }
.numbered::marker { font-family: var(--font-mono); }

/* -------------------------------------------------------------- qa lab */

.lab__table {
  border: 1px solid var(--border);
  font-size: var(--fs-small);
}
.lab__table caption {
  text-align: left;
  color: var(--muted);
  font-size: var(--fs-small);
  padding-bottom: var(--space-2);
}
.lab__table th[scope="col"] {
  background: var(--surface);
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--text);
}
.lab__table th[scope="row"] {
  font-family: var(--font-mono);
  color: var(--accent);
  white-space: nowrap;
  vertical-align: top;
}
.lab__table th,
.lab__table td {
  padding: var(--space-3);
  border-bottom: 1px solid var(--border);
}
.lab__table td { color: var(--muted); }
.lab__table tbody tr:last-child th,
.lab__table tbody tr:last-child td { border-bottom: 0; }

.lab__links {
  display: flex;
  gap: var(--space-6);
  margin-top: var(--space-6);
  font-size: var(--fs-small);
}

.lab__note {
  margin-top: var(--space-6);
  max-width: var(--measure);
  color: var(--muted);
  font-size: var(--fs-small);
}

/* ---------------------------------------------------------------- contact */

.contact {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-8);
}
.contact li {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}
.contact a {
  font-size: var(--fs-h3);
  font-weight: 700;
  border-bottom: 2px solid var(--border);
  padding-bottom: var(--space-1);
}
.contact a:hover { border-bottom-color: var(--accent); color: var(--accent); }
.contact span {
  font-family: var(--font-mono);
  font-size: var(--fs-small);
  color: var(--muted);
}

/* --------------------------------------------------------- back to top */

/* The button must never sit over content, and the content column is --page wide
   and centred, so how it is positioned depends on whether a gutter exists:

     >= 1220px   the leftover width is a real gutter, so the button parks in it
                 and the page is untouched
     >= 640px    no gutter, so the page reserves a lane on the right and the
                 button sits in that
     <  640px    a lane would cost too much of a narrow screen, so there is no
                 floating button and the footer carries the link instead

   The reserved lane is one rule on the body rather than a padding added to every
   container, so there is no convention for a new section to forget. */
:root { --totop-lane: 3.5rem; }

.to-top { display: none; }

.site-footer__top {
  margin-top: var(--space-4);
  font-size: var(--fs-small);
}
.site-footer__top a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
}

@media (min-width: 640px) {
  .site-footer__top { display: none; }

  .to-top {
    position: fixed;
    z-index: 40;
    bottom: var(--space-8);
    right: var(--space-3);
    display: grid;
    place-items: center;
    width: 2.5rem;
    height: 2.5rem;
    color: var(--muted);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 50%;
    opacity: 0;
    visibility: hidden;
    transition: opacity 150ms ease, visibility 150ms ease, color 150ms ease,
                border-color 150ms ease;
  }

  /* visibility, not just opacity, so a hidden button is out of the tab order. */
  .to-top[data-visible="true"] {
    opacity: 1;
    visibility: visible;
  }

  .to-top:hover {
    color: var(--accent);
    border-color: var(--accent);
  }
}

/* No natural gutter at these widths, so make one. */
@media (min-width: 640px) and (max-width: 1219px) {
  body { padding-right: var(--totop-lane); }
}

/* Wide enough that the leftover width already holds it. */
@media (min-width: 1220px) {
  .to-top { right: calc(50% - (var(--page) / 2) - 3.25rem); }
}

@media (prefers-reduced-motion: reduce) {
  .to-top { transition: none; }
}

/* ----------------------------------------------------------------- footer */

.site-footer {
  border-top: 1px solid var(--border);
  padding: var(--space-8) var(--space-4);
}
.site-footer p {
  max-width: var(--page);
  margin-inline: auto;
  color: var(--muted);
  font-size: var(--fs-small);
}

/* ------------------------------------------------------------ case pages */

.case {
  max-width: 760px;
  margin-inline: auto;
  padding: var(--space-16) var(--space-4);
}

.case h1 {
  font-size: clamp(1.75rem, 5vw, 2.75rem);
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.02em;
}

.case__facts {
  margin-top: var(--space-8);
  padding: var(--space-4) 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-4);
  font-size: var(--fs-small);
}
.case__facts dt {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: var(--space-1);
}

.case .prose { margin-top: var(--space-8); max-width: none; }

.case .prose h2 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  margin-top: var(--space-12);
  margin-bottom: var(--space-3);
}
.case .prose > h2:first-child { margin-top: 0; }

.flow {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  line-height: 1.7;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4);
  overflow-x: auto;
}
.flow code {
  background: none;
  border: 0;
  padding: 0;
  color: inherit;
  font-size: inherit;
}

/* Anything that scrolls sideways needs `tabindex="0"` on this wrapper, or a
   keyboard user cannot reach the part that is off-screen. */
.scroll-x { overflow-x: auto; }

.case__table {
  font-size: var(--fs-small);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.case__table th[scope="col"] {
  background: var(--surface);
  font-family: var(--font-mono);
  font-size: 0.8125rem;
}
.case__table th,
.case__table td {
  padding: var(--space-3);
  border-bottom: 1px solid var(--border);
}
.case__table td { color: var(--muted); }
.case__table tbody tr:last-child td { border-bottom: 0; }

.case__back {
  margin-top: var(--space-16);
  padding-top: var(--space-6);
  border-top: 1px solid var(--border);
  font-size: var(--fs-small);
}
.case__back a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.case--404 { text-align: center; padding-block: var(--space-16); }
.case--404 h1 { font-family: var(--font-mono); }
.case--404 .prose { margin-inline: auto; }
.case--404 .case__back { border-top: 0; }

/* ------------------------------------------------------- reduced 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;
  }
}
