/* ==========================================================================
   Russell Beattie — personal homepage

   Type:    Newsreader (display serif) / Schibsted Grotesk (body) /
            JetBrains Mono (dates + IDs only).
            Set the way good personal sites set type: normal tracking, modest
            weights, restrained display sizes. No tight-tracked ultra-bold.
   Palette: warm paper + ink, with a blue accent.
   Theme:   light by default; dark is opt-in via the toggle and remembered.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Tokens
   -------------------------------------------------------------------------- */

:root {
  /* Type */
  --font-heading: 'Newsreader', ui-serif, Georgia, 'Times New Roman', serif;
  --font-body: 'Schibsted Grotesk', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  /* Fluid scale — 375px → 1440px */
  --fs-xs:    0.8125rem;
  --fs-sm:    0.875rem;
  --fs-base:  1rem;
  --fs-md:    clamp(1.0625rem, 0.99rem + 0.32vw, 1.1875rem);
  --fs-lg:    clamp(1.25rem, 1.13rem + 0.5vw, 1.5rem);
  --fs-xl:    clamp(1.75rem, 1.45rem + 1.3vw, 2.5rem);
  --fs-2xl:   clamp(2rem, 1.6rem + 1.8vw, 3rem);
  --fs-hero:  clamp(2.75rem, 1.85rem + 3.9vw, 5rem);

  /* Spacing — 4/8 rhythm */
  --sp-1: 0.25rem;
  --sp-2: 0.5rem;
  --sp-3: 0.75rem;
  --sp-4: 2rem;
  --sp-5: 1.5rem;
  --sp-6: 2rem;
  --sp-7: 3rem;
  --sp-8: 4rem;
  --sp-9: 6rem;

  --section-y: clamp(4.5rem, 3rem + 6vw, 8.5rem);
  --gutter: clamp(1.25rem, 0.7rem + 2.4vw, 3rem);
  --shell: 72rem;

  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 22px;

  /* Motion */
  --dur-fast: 150ms;
  --dur: 240ms;
  --dur-slow: 600ms;
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);

  --header-h: 4.5rem;
}

/* Dark theme (default) */
[data-theme='dark'] {
  color-scheme: dark;

  --bg:            #0a0a0b;
  --bg-alt:        #101013;
  --surface:       #141418;
  --surface-hover: #1b1b21;
  --border:        #26262d;
  --border-strong: #33333d;

  --text:          #f4f4f5;
  --text-muted:    #a6a6b0;   /* 8.2:1 on --bg, 7.6:1 on --surface */
  --text-subtle:   #85859a;   /* 5.1:1 on --surface — the tightest pairing */

  --accent:        #6aa5ff;   /* accent text on dark — 7.9:1 on --bg   */
  --accent-strong: #2563eb;   /* accent as a background                */
  --on-accent:     #ffffff;
  --accent-soft:   rgba(106, 165, 255, 0.12);
  --accent-ring:   rgba(106, 165, 255, 0.4);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.5);
  --shadow: 0 12px 32px -12px rgba(0, 0, 0, 0.75);
  --shadow-lg: 0 32px 64px -24px rgba(0, 0, 0, 0.85);

  --sig-filter: invert(1) brightness(1.55);
  --glow-a: rgba(120, 110, 95, 0.20);
  --glow-b: rgba(90, 100, 120, 0.14);
}

/* Light theme */
[data-theme='light'] {
  color-scheme: light;

  /* Warm paper rather than cool grey — it sits better under the serif. */
  --bg:            #fbfaf8;
  --bg-alt:        #f4f2ed;
  --surface:       #ffffff;
  --surface-hover: #f8f6f2;
  --border:        #e6e2d9;
  --border-strong: #cec8bb;

  --text:          #14120e;
  --text-muted:    #4f4a42;
  --text-subtle:   #6b6459;

  --accent:        #1d4ed8;   /* accent text on light — 7.4:1 on --bg  */
  --accent-strong: #2563eb;
  --on-accent:     #ffffff;
  --accent-soft:   rgba(37, 99, 235, 0.09);
  --accent-ring:   rgba(37, 99, 235, 0.4);

  --shadow-sm: 0 1px 2px rgba(16, 20, 40, 0.06);
  --shadow: 0 12px 30px -14px rgba(16, 20, 40, 0.22);
  --shadow-lg: 0 30px 60px -28px rgba(16, 20, 40, 0.3);

  --sig-filter: none;
  /* A barely-there warm wash. A blue/purple gradient is the template look. */
  --glow-a: rgba(196, 178, 148, 0.16);
  --glow-b: rgba(170, 178, 190, 0.10);
}

/* --------------------------------------------------------------------------
   2. Base
   -------------------------------------------------------------------------- */

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

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-h) + 1rem);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--fs-base);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}

h1, h2, h3, h4 {
  font-family: var(--font-heading);
  font-optical-sizing: auto;
  font-weight: 400;
  line-height: 1.15;
  /* Normal tracking. Tight negative tracking is the tell of a template. */
  letter-spacing: normal;
  text-wrap: balance;
  margin: 0;
}

/* Small caps-ish meta: dates, kickers, IDs. */
.job__years,
.job__place,
.patent__id {
  font-family: var(--font-mono);
  font-weight: 400;
}

p { margin: 0 0 var(--sp-4); text-wrap: pretty; }
p:last-child { margin-bottom: 0; }

ul, ol { margin: 0; padding: 0; list-style: none; }

a { color: inherit; text-decoration: none; }

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

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
}

strong { font-weight: 700; color: var(--text); }

::selection { background: var(--accent-strong); color: #fff; }

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

.shell {
  width: 100%;
  max-width: var(--shell);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  top: var(--sp-2);
  left: var(--sp-2);
  z-index: 200;
  padding: var(--sp-3) var(--sp-4);
  background: var(--accent-strong);
  color: var(--on-accent);
  border-radius: var(--radius-sm);
  font-weight: 500;
  transform: translateY(-150%);
  transition: transform var(--dur) var(--ease);
}
.skip-link:focus-visible { transform: translateY(0); }

.icon {
  width: 1.25rem;
  height: 1.25rem;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon--brand { fill: currentColor; stroke: none; }

.link {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
  transition: color var(--dur-fast) var(--ease);
}
.link:hover { color: var(--text); }

/* --------------------------------------------------------------------------
   3. Scroll progress + header
   -------------------------------------------------------------------------- */

.progress {
  position: fixed;
  inset: 0 0 auto 0;
  height: 2px;
  z-index: 120;
  background: transparent;
  pointer-events: none;
}
.progress__bar {
  display: block;
  height: 100%;
  width: 100%;
  transform: scaleX(0);
  transform-origin: 0 50%;
  background: linear-gradient(90deg, var(--accent-strong), var(--accent));
}

.site-header {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 100;
  height: var(--header-h);
  display: flex;
  align-items: center;
  background: transparent;
  border-bottom: 1px solid transparent;
  transition: background-color var(--dur) var(--ease),
              border-color var(--dur) var(--ease),
              backdrop-filter var(--dur) var(--ease);
}
.site-header.is-stuck {
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  border-bottom-color: var(--border);
  backdrop-filter: saturate(150%) blur(14px);
  -webkit-backdrop-filter: saturate(150%) blur(14px);
}

.site-header__inner {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-3);
  min-height: 2.75rem;
  margin-right: auto;
  font-family: var(--font-heading);
  font-weight: 500;
  letter-spacing: normal;
}
.brand__mark {
  display: grid;
  place-items: center;
  width: 2.125rem;
  height: 2.125rem;
  border-radius: 10px;
  background: var(--text);
  color: var(--bg);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  transition: transform var(--dur) var(--ease-out), background-color var(--dur) var(--ease);
}
.brand:hover .brand__mark { transform: rotate(-8deg) scale(1.06); background: var(--accent-strong); color: #fff; }
.brand__name { font-size: var(--fs-sm); }

.nav__list { display: flex; align-items: center; gap: var(--sp-1); }

.nav__link {
  position: relative;
  display: block;
  padding: var(--sp-2) var(--sp-3);
  font-size: var(--fs-sm);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  transition: color var(--dur-fast) var(--ease), background-color var(--dur-fast) var(--ease);
}
.nav__link::after {
  content: '';
  position: absolute;
  left: var(--sp-3);
  right: var(--sp-3);
  bottom: 0.35rem;
  height: 1.5px;
  background: var(--accent);
  border-radius: 2px;
  transform: scaleX(0);
  transform-origin: 50%;
  transition: transform var(--dur) var(--ease-out);
}
.nav__link:hover { color: var(--text); background: var(--surface-hover); }
.nav__link.is-active { color: var(--text); }
.nav__link.is-active::after { transform: scaleX(1); }

.site-header__actions { display: flex; align-items: center; gap: var(--sp-2); }

.icon-btn {
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  border: 1px solid transparent;
  transition: color var(--dur-fast) var(--ease),
              background-color var(--dur-fast) var(--ease),
              border-color var(--dur-fast) var(--ease);
}
.icon-btn:hover { color: var(--text); background: var(--surface-hover); border-color: var(--border); }
.icon-btn > .icon { grid-area: 1 / 1; }

/* Theme toggle — crossfade the two glyphs */
#themeToggle .icon { transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease-out); }
[data-theme='dark'] .icon--moon { opacity: 0; transform: rotate(-90deg) scale(0.5); }
[data-theme='dark'] .icon--sun  { opacity: 1; transform: none; }
[data-theme='light'] .icon--sun  { opacity: 0; transform: rotate(90deg) scale(0.5); }
[data-theme='light'] .icon--moon { opacity: 1; transform: none; }

.nav-toggle { display: none; }
.nav-toggle .icon--close { opacity: 0; transform: scale(0.6); transition: opacity var(--dur-fast), transform var(--dur-fast); }
.nav-toggle .icon--menu  { opacity: 1; transition: opacity var(--dur-fast), transform var(--dur-fast); }
.nav-toggle[aria-expanded='true'] .icon--close { opacity: 1; transform: none; }
.nav-toggle[aria-expanded='true'] .icon--menu  { opacity: 0; transform: scale(0.6); }

/* --------------------------------------------------------------------------
   4. Hero
   -------------------------------------------------------------------------- */

.hero {
  position: relative;
  min-height: 100svh;
  display: flex;
  align-items: center;
  padding-top: calc(var(--header-h) + var(--sp-7));
  /* Keeps the scroll cue inside the first viewport at 900px tall. */
  padding-bottom: var(--sp-8);
  overflow: hidden;
}

.hero__glow {
  position: absolute;
  top: -30%;
  right: -10%;
  width: min(80rem, 120%);
  aspect-ratio: 1;
  background:
    radial-gradient(circle at 62% 38%, var(--glow-a), transparent 55%),
    radial-gradient(circle at 30% 70%, var(--glow-b), transparent 55%);
  filter: blur(30px);
  pointer-events: none;
  transform: translate3d(var(--px, 0), var(--py, 0), 0);
  transition: transform 900ms var(--ease-out);
}

.hero__inner { position: relative; }

/* The portrait now lives inside .hero__text as a grid item, so it can sit
   beside the name in a compact row on narrow screens instead of stacking
   as a large block above it. */
.hero__text {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 0.85fr);
  column-gap: clamp(2rem, 5vw, 5rem);
  align-items: start;
  grid-template-areas:
    "title    portrait"
    "role     portrait"
    "summary  portrait"
    "actions  portrait"
    "social   portrait";
}
.hero__title    { grid-area: title; }
.hero__role     { grid-area: role; }
.hero__summary  { grid-area: summary; }
.hero__actions  { grid-area: actions; }
.hero__social   { grid-area: social; }

.hero__title {
  font-size: var(--fs-hero);
  font-weight: 400;
  letter-spacing: normal;
  line-height: 1.02;
  margin-bottom: var(--sp-5);
}

.hero__role {
  font-family: var(--font-heading);
  font-style: italic;
  font-size: var(--fs-lg);
  font-weight: 400;
  color: var(--text-muted);
  letter-spacing: normal;
  margin-bottom: var(--sp-5);
}

.hero__summary {
  max-width: 44ch;
  font-size: var(--fs-md);
  color: var(--text-muted);
  margin-bottom: var(--sp-6);
}

.hero__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-3);
  margin-bottom: var(--sp-6);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: 2.875rem;
  padding: var(--sp-3) var(--sp-5);
  border-radius: 999px;
  border: 1px solid transparent;
  font-family: var(--font-body);
  font-size: var(--fs-sm);
  font-weight: 600;
  cursor: pointer;
  transition: transform var(--dur-fast) var(--ease-out),
              background-color var(--dur-fast) var(--ease),
              border-color var(--dur-fast) var(--ease),
              color var(--dur-fast) var(--ease),
              box-shadow var(--dur) var(--ease);
}
.btn:active { transform: translateY(1px); }

/* Ink, not a saturated blue pill — the blue stays for links and small accents. */
.btn--primary {
  background: var(--text);
  color: var(--bg);
  border-radius: var(--radius-sm);
}
.btn--primary:hover { background: color-mix(in srgb, var(--text) 82%, var(--bg)); }

.btn--ghost { border-radius: var(--radius-sm); }

.btn--ghost {
  border-color: var(--border-strong);
  color: var(--text);
  background: var(--surface);
}
.btn--ghost:hover { background: var(--surface-hover); border-color: var(--text-subtle); }

.hero__social { display: flex; align-items: center; gap: var(--sp-2); }

.social {
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  transition: color var(--dur-fast) var(--ease),
              border-color var(--dur-fast) var(--ease),
              background-color var(--dur-fast) var(--ease),
              transform var(--dur) var(--ease-out);
}
.social:hover {
  color: var(--text);
  border-color: var(--text-subtle);
  background: var(--surface-hover);
  transform: translateY(-3px);
}

/* Portrait --------------------------------------------------------------- */

.hero__portrait { justify-self: center; width: 100%; max-width: 24rem; align-self: center; grid-area: portrait; }

.portrait {
  position: relative;
  margin: 0;
  aspect-ratio: 4 / 5;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--surface);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  transform: translate3d(0, var(--float, 0), 0);
  transition: transform 900ms var(--ease-out);
}
.portrait::after {
  /* Soft vignette so any photo sits comfortably against the page. */
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent 55%, color-mix(in srgb, var(--bg) 78%, transparent));
  pointer-events: none;
}

.portrait__img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 22%;
}

/* Shown only when the photo is missing or fails to load (JS adds .no-photo). */
.portrait__fallback { display: none; }
.portrait.no-photo .portrait__img { display: none; }
.portrait.no-photo .portrait__fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  /* Sits above the signature line rather than behind it. */
  padding-bottom: 22%;
  background:
    radial-gradient(circle at 30% 25%, var(--accent-soft), transparent 60%),
    var(--bg-alt);
}
.portrait__initials {
  font-family: var(--font-heading);
  font-size: clamp(3rem, 9vw, 5rem);
  font-weight: 400;
  letter-spacing: normal;
  color: var(--border-strong);
  user-select: none;
}

/* Sign-off under the contact list. */
.signoff { margin: var(--sp-7) 0 0; }
.signoff img {
  width: clamp(9rem, 26vw, 13rem);
  height: auto;
  opacity: 0.85;
  filter: var(--sig-filter);
}

.hero__scroll {
  position: absolute;
  left: 50%;
  bottom: var(--sp-5);
  translate: -50% 0;
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 50%;
  color: var(--text-subtle);
  transition: color var(--dur-fast) var(--ease);
  animation: bob 2.8s var(--ease) infinite;
}
.hero__scroll:hover { color: var(--text); }
@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(6px); }
}

/* --------------------------------------------------------------------------
   5. Sections
   -------------------------------------------------------------------------- */

.section { padding-block: var(--section-y); position: relative; }
.section--alt { background: var(--bg-alt); }

.section__kicker {
  display: inline-block;
  margin-bottom: var(--sp-4);
  font-family: var(--font-body);
  font-size: var(--fs-xs);
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-subtle);
}

.section__title {
  font-size: var(--fs-2xl);
  font-weight: 400;
  max-width: 26ch;
  margin-bottom: var(--sp-5);
}
.section__title--xl { font-size: clamp(2.5rem, 1.8rem + 2.8vw, 4rem); }

.section__intro {
  max-width: 60ch;
  font-size: var(--fs-md);
  color: var(--text-muted);
  margin-bottom: var(--sp-7);
}

/* Timeline --------------------------------------------------------------- */

.timeline { display: grid; gap: var(--sp-3); }

.job { display: grid; grid-template-columns: 2rem minmax(0, 1fr); gap: var(--sp-4); }

.job__rail { position: relative; display: flex; justify-content: center; padding-top: 1.6rem; }
.job__rail::before {
  content: '';
  position: absolute;
  top: 0; bottom: -1.5rem;
  width: 1px;
  background: var(--border);
}
.job:last-of-type .job__rail::before { bottom: 50%; }

.job__dot {
  position: relative;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--border-strong);
  outline: 5px solid var(--bg-alt);
  transition: background-color var(--dur) var(--ease), transform var(--dur) var(--ease-out);
}
.job:hover .job__dot { background: var(--accent); transform: scale(1.25); }
.job__dot--live {
  background: var(--accent);
  animation: pulse-dot 2.6s ease-out infinite;
}
@keyframes pulse-dot {
  0%   { box-shadow: 0 0 0 0 var(--accent-ring); }
  70%  { box-shadow: 0 0 0 10px rgba(0, 0, 0, 0); }
  100% { box-shadow: 0 0 0 0 rgba(0, 0, 0, 0); }
}

.job__card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.job__card:hover { border-color: var(--border-strong); box-shadow: var(--shadow); }

/* Each role is a heading wrapping its disclosure button (W3C accordion
   pattern), so the work history is navigable by heading. The heading itself
   carries no visual styling — that lives on the spans inside the button. */
.job__h { margin: 0; font: inherit; letter-spacing: normal; }

.job__head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: var(--sp-4);
  width: 100%;
  padding: var(--sp-5);
  text-align: left;
  transition: background-color var(--dur-fast) var(--ease);
}
.job__head:hover { background: var(--surface-hover); }

.job__headings { display: grid; gap: 2px; min-width: 0; }
.job__title {
  font-family: var(--font-heading);
  font-size: var(--fs-md);
  font-weight: 500;
  letter-spacing: normal;
  color: var(--text);
}
.job__org { font-size: var(--fs-sm); color: var(--accent); }

.job__meta { display: grid; gap: 2px; text-align: right; }
.job__years {
  font-size: var(--fs-sm);
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  white-space: nowrap;
}
.job__place { font-size: var(--fs-xs); color: var(--text-subtle); white-space: nowrap; }

.job__chev {
  color: var(--text-subtle);
  transition: transform var(--dur) var(--ease-out), color var(--dur-fast) var(--ease);
}
.job__head[aria-expanded='true'] .job__chev { transform: rotate(180deg); color: var(--accent); }
.job__head:hover .job__chev { color: var(--text); }

/* 0fr → 1fr gives a height animation without measuring anything in JS. */
.job__panel {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows var(--dur-slow) var(--ease-out);
}
.job__h:has(.job__head[aria-expanded='true']) + .job__panel { grid-template-rows: 1fr; }
.job__panel-inner > * { padding-inline: var(--sp-5); }
.job__panel-inner > ul { padding-bottom: var(--sp-5); }

/* Collapsed content is taken out of the tab order, but only once the
   collapse animation has finished — otherwise it snaps away mid-transition. */
.job__panel-inner {
  overflow: hidden;
  visibility: hidden;
  transition: visibility 0s linear var(--dur-slow);
}
.job__h:has(.job__head[aria-expanded='true']) + .job__panel .job__panel-inner {
  visibility: visible;
  transition-delay: 0s;
}

.job__panel ul { display: grid; gap: var(--sp-3); color: var(--text-muted); font-size: var(--fs-sm); }
.job__panel li { position: relative; padding-left: var(--sp-5); }
.job__panel li::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0.6em;
  width: 6px;
  height: 1px;
  background: var(--text-subtle);
}

.job__tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  padding-bottom: var(--sp-5);
  margin: 0;
}
.tag {
  padding: 3px var(--sp-3);
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: var(--fs-xs);
  font-weight: 500;
}

.timeline__foot {
  margin-top: var(--sp-6);
  padding-left: calc(2rem + var(--sp-4));
  font-size: var(--fs-sm);
  color: var(--text-subtle);
}

/* Skills ----------------------------------------------------------------- */

.skills {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 20rem), 1fr));
  gap: var(--sp-4);
}

.skillset {
  padding: var(--sp-5);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  transition: border-color var(--dur) var(--ease),
              transform var(--dur) var(--ease-out),
              box-shadow var(--dur) var(--ease);
}
.skillset:hover {
  border-color: var(--border-strong);
  transform: translateY(-4px);
  box-shadow: var(--shadow);
}

.skillset__name {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
  font-family: var(--font-body);
  font-size: var(--fs-sm);
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.skillset__name .icon { color: var(--accent); }

.chips { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.chip {
  padding: var(--sp-1) var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-alt);
  color: var(--text-muted);
  font-size: var(--fs-xs);
  line-height: 1.6;
  transition: color var(--dur-fast) var(--ease),
              border-color var(--dur-fast) var(--ease),
              background-color var(--dur-fast) var(--ease);
}
.skillset:hover .chip { border-color: var(--border-strong); color: var(--text); }

/* Patents ---------------------------------------------------------------- */

.patents {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 22rem), 1fr));
  gap: var(--sp-4);
}

.patent {
  display: grid;
  align-content: start;
  gap: var(--sp-2);
  padding: var(--sp-6);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  transition: border-color var(--dur) var(--ease),
              transform var(--dur) var(--ease-out),
              box-shadow var(--dur) var(--ease);
}
.patent:hover {
  border-color: var(--accent);
  transform: translateY(-4px);
  box-shadow: var(--shadow);
}

.patent__id {
  font-size: var(--fs-xs);
  letter-spacing: 0.06em;
  color: var(--text-subtle);
}
.patent__title { font-size: var(--fs-lg); font-weight: 400; }
.patent__desc { color: var(--text-muted); font-size: var(--fs-sm); margin: var(--sp-1) 0 var(--sp-3); }
.patent__cta {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--accent);
}
.patent__cta .icon { width: 1rem; height: 1rem; transition: transform var(--dur) var(--ease-out); }
.patent:hover .patent__cta .icon { transform: translate(2px, -2px); }

/* Contact ---------------------------------------------------------------- */

.section--contact { padding-bottom: var(--sp-9); }

.contacts {
  display: grid;
  gap: var(--sp-2);
  max-width: 46rem;
}

.contact-row {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  transition: border-color var(--dur) var(--ease), background-color var(--dur) var(--ease);
}
.contact-row:hover { border-color: var(--border-strong); }

.contact-row__main {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  flex: 1;
  min-width: 0;
  min-height: 3.5rem;
  padding: var(--sp-3) var(--sp-5);
  border-radius: var(--radius);
  transition: background-color var(--dur-fast) var(--ease);
}
a.contact-row__main:hover { background: var(--surface-hover); }
.contact-row__main--static { cursor: default; }
.contact-row__main > .icon { color: var(--text-subtle); }
a.contact-row__main:hover > .icon:first-child { color: var(--accent); }

.contact-row__label {
  width: 6rem;
  flex: none;
  font-family: var(--font-body);
  font-size: var(--fs-sm);
  font-weight: 600;
}
.contact-row__value {
  flex: 1;
  min-width: 0;
  color: var(--text-muted);
  font-size: var(--fs-sm);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.contact-row__ext { width: 1rem; height: 1rem; color: var(--text-subtle); }

.copy-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: 2.75rem;
  margin-right: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-alt);
  color: var(--text-muted);
  font-size: var(--fs-xs);
  font-weight: 500;
  transition: color var(--dur-fast) var(--ease),
              border-color var(--dur-fast) var(--ease),
              background-color var(--dur-fast) var(--ease);
}
.copy-btn:hover { color: var(--text); border-color: var(--border-strong); }
.copy-btn .icon { width: 1rem; height: 1rem; }
.copy-btn .icon--check { display: none; }
.copy-btn.is-copied { color: #22c55e; border-color: currentColor; }
.copy-btn.is-copied .icon--copy { display: none; }
.copy-btn.is-copied .icon--check { display: block; }

/* Footer ----------------------------------------------------------------- */

.site-footer {
  border-top: 1px solid var(--border);
  padding-block: var(--sp-6);
  background: var(--bg);
}
.site-footer__inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
}
.site-footer__copy { margin: 0; font-size: var(--fs-xs); color: var(--text-subtle); }
.site-footer__top {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: 2.75rem;
  font-size: var(--fs-xs);
  color: var(--text-muted);
  transition: color var(--dur-fast) var(--ease);
}
.site-footer__top:hover { color: var(--accent); }
.site-footer__top .icon { width: 1rem; height: 1rem; }

/* --------------------------------------------------------------------------
   6. Reveal-on-scroll
   -------------------------------------------------------------------------- */

/* Hidden only when scripting is available to reveal it again. */
.js .reveal {
  opacity: 0;
  transform: translateY(18px);
  transition: opacity 700ms var(--ease-out), transform 700ms var(--ease-out);
  transition-delay: calc(var(--reveal-delay, 0) * 80ms);
}
.js .reveal.is-visible { opacity: 1; transform: none; }

/* --------------------------------------------------------------------------
   7. Responsive
   -------------------------------------------------------------------------- */

@media (max-width: 62rem) {          /* < 992px — tablet */
  /* The avatar sits beside the name and role rather than as a large photo
     stacked above them — the photo was competing with the name for attention.
     It spans both text rows, so the name can break across two lines and still
     leave the portrait room to breathe. */
  .hero__text {
    grid-template-columns: auto minmax(0, 1fr);
    column-gap: var(--sp-4);
    grid-template-areas:
      "portrait title"
      "portrait role"
      "summary  summary"
      "actions  actions"
      "social   social";
  }
  .hero__portrait {
    width: 7.5rem;
    max-width: 7.5rem;
    justify-self: start;
    align-self: center;
  }
  .portrait { }
  .hero__portrait .portrait__initials { font-size: 2.5rem; }
  .hero__portrait .portrait.no-photo .portrait__fallback { padding-bottom: 0; }

  /* end/start pins the two text rows against each other so the pair reads as
     one block, vertically centred against the portrait. */
  .hero__title {
    font-size: clamp(1.75rem, 1.4rem + 2.6vw, 2.5rem);
    line-height: 1.15;
    margin-bottom: 0;
    align-self: end;
  }
  .hero__role { align-self: start; margin-top: var(--sp-1); }
  /* The portrait overhangs the role row, so the role's own bottom margin
     isn't enough to clear it. */
  .hero__summary { margin-top: var(--sp-4); }

  .hero { min-height: 0; padding-bottom: var(--sp-8); }
  .hero__scroll { display: none; }
}

@media (max-width: 48rem) {          /* < 768px — mobile */
  :root { --header-h: 4rem; }

  .brand__name { display: none; }
  /* Keeps the mark's tap area at 44px once the wordmark is hidden. */
  .brand { min-width: 2.75rem; }
  .nav-toggle { display: grid; }

  .nav {
    position: fixed;
    inset: var(--header-h) 0 auto 0;
    padding: var(--sp-3) var(--gutter) var(--sp-5);
    background: color-mix(in srgb, var(--bg) 96%, transparent);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
    transform: translateY(-115%);
    visibility: hidden;
    transition: transform var(--dur) var(--ease-out), visibility var(--dur);
  }
  .nav.is-open { transform: none; visibility: visible; }
  .nav__list { flex-direction: column; align-items: stretch; gap: 0; }
  .nav__link {
    padding: var(--sp-4) var(--sp-2);
    font-size: var(--fs-md);
    border-radius: 0;
    border-bottom: 1px solid var(--border);
  }
  .nav__list li:last-child .nav__link { border-bottom: none; }
  .nav__link::after { display: none; }
  .nav__link.is-active { color: var(--accent); }

  .hero__actions .btn { flex: 1 1 100%; }

  .job { grid-template-columns: 1rem minmax(0, 1fr); gap: var(--sp-3); }
  .job__head {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: 'headings chev' 'meta meta';
    gap: var(--sp-2);
    padding: var(--sp-4);
  }
  .job__headings { grid-area: headings; }
  .job__chev { grid-area: chev; }
  .job__meta { grid-area: meta; display: flex; gap: var(--sp-3); text-align: left; }
  .job__panel-inner > * { padding-inline: var(--sp-4); }
  .job__panel-inner > ul, .job__tags { padding-bottom: var(--sp-4); }
  .timeline__foot { padding-left: 0; }

  .contact-row { flex-wrap: wrap; }
  .contact-row__main { flex-wrap: wrap; gap: var(--sp-2) var(--sp-3); padding: var(--sp-4); }
  .contact-row__label { width: auto; }
  .contact-row__value { flex-basis: 100%; }
  .copy-btn { margin: 0 var(--sp-4) var(--sp-4); }
}

@media (max-width: 26rem) {          /* < 416px — small phone */
  .hero__social { flex-wrap: wrap; }
}

/* Landscape phones — the hero shouldn't demand a full tall viewport. */
@media (max-height: 34rem) and (orientation: landscape) {
  .hero { min-height: 0; padding-block: calc(var(--header-h) + var(--sp-5)) var(--sp-6); }
  .hero__scroll { display: none; }
}

/* --------------------------------------------------------------------------
   8. Reduced motion & print
   -------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }

  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  /* Content renders in its final state rather than animating in. */
  .reveal { opacity: 1; transform: none; }
  .hero__glow, .portrait { transform: none; }
  .job__panel { transition: none; }
}

@media print {
  .site-header, .progress, .hero__scroll, .site-footer__top, .copy-btn, .hero__glow { display: none; }
  body { background: #fff; color: #000; }
  .section, .hero { padding-block: 1.5rem; }
  .job__panel { grid-template-rows: 1fr !important; }
  .job__panel-inner { visibility: visible !important; }
  .reveal { opacity: 1 !important; transform: none !important; }
}
