/* ==========================================================================
   Ernesto Reig — personal site
   Dark-first, editorial/tech. No external fonts or libraries.
   ========================================================================== */

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

  --bg: #0c0e12;
  --bg-elev: #13161c;
  --bg-elev-2: #1a1e26;
  --line: #262b35;
  --line-strong: #3a4150;
  --text: #eceef2;
  --text-muted: #a3abb8;
  --text-subtle: #858d9b;
  --accent: #f0b54a;
  --accent-ink: #0c0e12;
  --accent-soft: rgb(240 181 74 / 0.12);
  --glow: rgb(240 181 74 / 0.10);
  --grid-dot: rgb(255 255 255 / 0.05);

  --font-display: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  --step--1: clamp(0.8rem, 0.78rem + 0.1vw, 0.85rem);
  --step-0: clamp(1rem, 0.96rem + 0.2vw, 1.075rem);
  --step-1: clamp(1.2rem, 1.1rem + 0.45vw, 1.4rem);
  --step-2: clamp(1.5rem, 1.3rem + 0.9vw, 2rem);
  --step-3: clamp(2rem, 1.6rem + 1.8vw, 3rem);
  --step-4: clamp(2.75rem, 1.9rem + 4.2vw, 5.5rem);

  --space-section: clamp(4.5rem, 3rem + 6vw, 8rem);
  --gutter: clamp(1.25rem, 0.8rem + 2.5vw, 3rem);
  --container: 74rem;
  --radius: 14px;
  --radius-sm: 8px;

  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
}

:root[data-theme="light"] {
  color-scheme: light;

  --bg: #f7f6f2;
  --bg-elev: #ffffff;
  --bg-elev-2: #efede7;
  --line: #dedad0;
  --line-strong: #c4bfb2;
  --text: #14171c;
  --text-muted: #474e59;
  --text-subtle: #5f6773;
  --accent: #975800;
  --accent-ink: #ffffff;
  --accent-soft: rgb(151 88 0 / 0.08);
  --glow: rgb(214 150 40 / 0.14);
  --grid-dot: rgb(20 23 28 / 0.06);
}

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-padding-top: 5rem;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--step-0);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

h1,
h2,
h3,
h4 {
  margin: 0;
  line-height: 1.1;
  font-weight: 500;
  text-wrap: balance;
}

p {
  margin: 0;
  text-wrap: pretty;
}

ul,
ol {
  margin: 0;
  padding: 0;
}

a {
  color: inherit;
  text-decoration-color: var(--line-strong);
  text-underline-offset: 0.2em;
  text-decoration-thickness: 1px;
}

a:hover {
  text-decoration-color: var(--accent);
}

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

::selection {
  background: var(--accent);
  color: var(--accent-ink);
}

.visually-hidden {
  position: absolute !important;
  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;
  left: var(--gutter);
  top: 0.75rem;
  z-index: 100;
  padding: 0.6rem 1rem;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  border-radius: var(--radius-sm);
  transform: translateY(-200%);
}

.skip-link:focus {
  transform: none;
}

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

.mono {
  font-family: var(--font-mono);
  font-size: var(--step--1);
  letter-spacing: 0.02em;
}

/* ---------- Header ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(140%) blur(12px);
  -webkit-backdrop-filter: saturate(140%) blur(12px);
  border-bottom: 1px solid transparent;
  transition: border-color 0.3s ease;
}

.site-header.is-scrolled {
  border-bottom-color: var(--line);
}

.site-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 4rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  font-family: var(--font-mono);
  font-size: var(--step--1);
  text-decoration: none;
  letter-spacing: 0.04em;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  font-family: var(--font-display);
  font-size: 0.95rem;
  letter-spacing: 0;
}

.nav {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.nav ul {
  display: flex;
  gap: 0.25rem;
  list-style: none;
}

.nav a {
  display: inline-block;
  padding: 0.45rem 0.7rem;
  border-radius: 999px;
  font-size: 0.9rem;
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.2s ease, background-color 0.2s ease;
}

.nav a:hover,
.nav a[aria-current="location"] {
  color: var(--text);
  background: var(--bg-elev-2);
}

.menu-toggle {
  display: none;
  align-items: center;
  gap: 0.55rem;
  min-height: 2.25rem;
  padding: 0 0.85rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

.menu-icon,
.menu-icon::before {
  display: block;
  width: 0.9rem;
  height: 1px;
  background: currentColor;
  transition: transform 0.25s var(--ease-out);
}

.menu-icon {
  position: relative;
  transform: translateY(-3px);
}

.menu-icon::before {
  content: "";
  position: absolute;
  top: 6px;
}

.menu-toggle[aria-expanded="true"] .menu-icon {
  transform: translateY(0) rotate(45deg);
}

.menu-toggle[aria-expanded="true"] .menu-icon::before {
  transform: translateY(-6px) rotate(-90deg);
}

.theme-toggle {
  display: grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  margin-left: 0.25rem;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease;
}

.theme-toggle:hover {
  color: var(--text);
  border-color: var(--line-strong);
}

.theme-toggle svg {
  width: 1.05rem;
  height: 1.05rem;
}

.theme-toggle .icon-sun,
:root[data-theme="light"] .theme-toggle .icon-moon {
  display: none;
}

:root[data-theme="light"] .theme-toggle .icon-sun {
  display: block;
}

/* ---------- Hero ---------- */
.hero {
  position: relative;
  padding-block: clamp(3.5rem, 2rem + 7vw, 8rem) clamp(3rem, 2rem + 4vw, 5rem);
  overflow: hidden;
  isolation: isolate;
}

.hero::before {
  /* faint dot grid, faded at the edges */
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background-image: radial-gradient(var(--grid-dot) 1px, transparent 1px);
  background-size: 22px 22px;
  mask-image: radial-gradient(ellipse 70% 60% at 70% 30%, #000 30%, transparent 75%);
  -webkit-mask-image: radial-gradient(ellipse 70% 60% at 70% 30%, #000 30%, transparent 75%);
}

.hero::after {
  content: "";
  position: absolute;
  z-index: -1;
  width: 46rem;
  height: 46rem;
  right: -14rem;
  top: -18rem;
  background: radial-gradient(circle, var(--glow), transparent 65%);
  pointer-events: none;
}

.hero-grid {
  display: grid;
  gap: clamp(2rem, 1.5rem + 3vw, 4rem);
  align-items: center;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--text-muted);
}

.status-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.hero h1 {
  margin-top: 1.25rem;
  font-family: var(--font-display);
  font-size: var(--step-4);
  font-weight: 400;
  letter-spacing: -0.02em;
  line-height: 0.98;
}

.hero-lede {
  margin-top: 1.5rem;
  max-width: 34ch;
  font-family: var(--font-display);
  font-size: var(--step-2);
  line-height: 1.3;
  color: var(--text);
}

.hero-lede em {
  font-style: italic;
  color: var(--accent);
}

.hero-body {
  margin-top: 1.25rem;
  max-width: 60ch;
  color: var(--text-muted);
}

.hero-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
  margin-top: 2rem;
  list-style: none;
  color: var(--text-subtle);
}

.hero-meta li {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.hero-meta svg {
  width: 0.95rem;
  height: 0.95rem;
  flex: none;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 2.25rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1.2rem;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  font-size: 0.95rem;
  font-weight: 500;
  text-decoration: none;
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease, transform 0.2s var(--ease-out);
}

.btn:hover {
  border-color: var(--text-muted);
}

.btn-primary {
  background: var(--text);
  border-color: var(--text);
  color: var(--bg);
}

.btn-primary:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.btn svg {
  width: 1rem;
  height: 1rem;
  transition: transform 0.2s var(--ease-out);
}

.btn:hover svg {
  transform: translateX(2px);
}

/* Portrait */
.portrait {
  /* small, above the name on narrow screens; full size beside the text on desktop */
  position: relative;
  order: -1;
  justify-self: start;
  width: clamp(7.5rem, 28vw, 11rem);
  margin: 0;
}

.portrait-frame {
  position: relative;
  aspect-ratio: 4 / 5;
  border-radius: var(--radius);
  overflow: hidden;
  background: linear-gradient(160deg, var(--bg-elev-2), var(--bg-elev));
  border: 1px solid var(--line);
}

.portrait-frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 20%;
}

.portrait::after {
  /* offset hairline frame behind the photo */
  content: "";
  position: absolute;
  inset: 0.9rem -0.9rem -0.9rem 0.9rem;
  z-index: -1;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
}

/* ---------- Sections ---------- */
.section {
  padding-block: var(--space-section);
  border-top: 1px solid var(--line);
}

.section-head {
  display: grid;
  gap: 1rem;
  margin-bottom: clamp(2.5rem, 2rem + 2vw, 4rem);
}

.section-index {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--accent);
}

.section-index::after {
  content: "";
  width: 2.5rem;
  height: 1px;
  background: currentColor;
  opacity: 0.6;
}

.section-title {
  font-family: var(--font-display);
  font-size: var(--step-3);
  font-weight: 400;
  letter-spacing: -0.015em;
}

.section-intro {
  max-width: 62ch;
  color: var(--text-muted);
}

/* ---------- At a glance ---------- */
.glance {
  padding-block: clamp(2.5rem, 2rem + 2vw, 3.5rem);
  border-top: 1px solid var(--line);
}

.figures {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 2rem 1.5rem;
  list-style: none;
}

.figure {
  display: grid;
  align-content: start;
  gap: 0.5rem;
}

@media (max-width: 39.99rem) {
  .figure:last-child {
    grid-column: 1 / -1;
  }

  .figure:last-child .figure-label {
    max-width: none;
  }
}

.figure-value {
  font-family: var(--font-display);
  font-size: var(--step-3);
  line-height: 1;
  letter-spacing: -0.02em;
}

.figure-num {
  display: inline-block;
  font-variant-numeric: tabular-nums;
}

.figure-value sup {
  font-size: 0.5em;
  color: var(--accent);
  vertical-align: 0.8em;
  margin-left: 0.05em;
}

.figure-label {
  max-width: 22ch;
  font-size: 0.92rem;
  line-height: 1.45;
  color: var(--text-muted);
}

/* Certifications strip */
.certs {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 1rem 1.5rem;
  align-items: center;
  margin-top: clamp(2.5rem, 2rem + 2vw, 3.5rem);
  padding-top: 2rem;
  border-top: 1px dashed var(--line);
}

.certs-label {
  color: var(--text-subtle);
  max-width: 16ch;
}

.certs-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  list-style: none;
}

.certs-list li {
  --tilt: -1;
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  overflow: hidden;
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-muted);
  transition: border-color 0.25s ease, color 0.25s ease, background-color 0.25s ease;
}

.certs-list li:nth-child(even) {
  --tilt: 1;
}

.certs-list img {
  display: block;
  width: 1rem;
  height: 1rem;
  flex: none;
  object-fit: contain;
}

.certs-list li:hover {
  border-color: var(--accent);
  color: var(--text);
  background: var(--accent-soft);
}

/* ---------- Selected work ---------- */
.work-grid {
  display: grid;
  gap: 1rem;
  list-style: none;
}

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  height: 100%;
  padding: clamp(1.4rem, 1.1rem + 1vw, 2rem);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  transition: border-color 0.3s ease, transform 0.35s var(--ease-out), background-color 0.3s ease;
}

.card::before {
  /* accent hairline that draws in on hover */
  content: "";
  position: absolute;
  left: clamp(1.4rem, 1.1rem + 1vw, 2rem);
  right: clamp(1.4rem, 1.1rem + 1vw, 2rem);
  top: -1px;
  height: 1px;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.5s var(--ease-out);
}

.card:hover {
  border-color: var(--line-strong);
  transform: translateY(-3px);
}

.card:hover::before {
  transform: scaleX(1);
}

.card-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  color: var(--text-subtle);
}

.card-flow {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  align-self: flex-start;
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent);
}

.card-flow span {
  display: inline-block;
  transition: transform 0.4s var(--ease-out);
}

.card:hover .card-flow span {
  transform: translateX(3px);
}

.card h3 {
  font-family: var(--font-display);
  font-size: var(--step-2);
  font-weight: 400;
  letter-spacing: -0.01em;
}

.card p {
  color: var(--text-muted);
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: auto;
  padding-top: 0.5rem;
  list-style: none;
}

.tags li {
  padding: 0.25rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ---------- Experience ---------- */
.timeline {
  list-style: none;
}

.role {
  display: grid;
  gap: 0.75rem 3rem;
  padding-block: 2.25rem;
  border-top: 1px solid var(--line);
}

.role:first-child {
  border-top: 0;
  padding-top: 0;
}

.role-when {
  display: grid;
  align-content: start;
  gap: 0.35rem;
  color: var(--text-subtle);
}

.role-when .is-current {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  color: var(--accent);
}

.role-body {
  display: grid;
  gap: 0.9rem;
  max-width: 64ch;
}

.role-title {
  font-family: var(--font-display);
  font-size: var(--step-2);
  font-weight: 400;
}

.role-org {
  color: var(--text-muted);
}

.role-logo {
  display: inline-block;
  width: 1em;
  height: 1em;
  margin-right: 0.4em;
  vertical-align: -0.15em;
  object-fit: contain;
}

:root[data-theme="dark"] .role-logo--upv {
  filter: invert(1);
}

.role-org .org-note {
  color: var(--text-subtle);
}

.role-summary {
  color: var(--text-muted);
}

.role-points {
  display: grid;
  gap: 0.55rem;
  list-style: none;
  color: var(--text-muted);
}

.role-points li {
  position: relative;
  padding-left: 1.25rem;
}

.role-points li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.75em;
  width: 0.5rem;
  height: 1px;
  background: var(--accent);
}

.role-points strong {
  color: var(--text);
  font-weight: 600;
}

/* Earlier roles */
.earlier {
  margin-top: 3rem;
  padding: clamp(1.4rem, 1.1rem + 1vw, 2rem);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.earlier h3 {
  font-family: var(--font-display);
  font-size: var(--step-1);
  font-weight: 400;
}

.earlier-intro {
  margin-top: 0.5rem;
  color: var(--text-muted);
  max-width: 62ch;
}

.earlier-list {
  display: grid;
  gap: 0;
  margin-top: 1.5rem;
  list-style: none;
}

.earlier-list li {
  display: grid;
  gap: 0.15rem 1.5rem;
  padding-block: 0.9rem;
  border-top: 1px solid var(--line);
}

.earlier-list .when {
  color: var(--text-subtle);
}

.earlier-list .what {
  color: var(--text);
  font-weight: 600;
}

.earlier-list .where {
  color: var(--text-muted);
}

.earlier-list .note {
  grid-column: 1 / -1;
  font-size: 0.92rem;
  color: var(--text-subtle);
}

/* ---------- Expertise ---------- */
.skills-grid {
  display: grid;
  gap: 1rem;
  list-style: none;
}

.skill-group {
  padding: clamp(1.4rem, 1.1rem + 1vw, 2rem);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-elev);
}

.skill-group h3 {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  font-family: var(--font-display);
  font-size: var(--step-1);
  font-weight: 400;
}

.skill-group h3 .mono {
  color: var(--text-subtle);
}

.skill-group .tags {
  margin-top: 1.25rem;
  padding-top: 0;
}

.skill-group .tags li {
  font-size: 0.78rem;
  color: var(--text);
  transition: border-color 0.2s ease, background-color 0.2s ease;
}

.skill-group .tags li:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.industries {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem 1.25rem;
  margin-top: 2rem;
  color: var(--text-muted);
}

.industries-label {
  color: var(--text-subtle);
}

.industries ul {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0;
  list-style: none;
}

.industries li:not(:last-child)::after {
  content: "·";
  margin-inline: 0.6rem;
  color: var(--text-subtle);
}

/* ---------- Credentials ---------- */
.creds-grid {
  display: grid;
  gap: 2.5rem 2rem;
}

.creds-col h3 {
  margin-bottom: 1rem;
  color: var(--text-subtle);
  font-family: var(--font-mono);
  font-size: var(--step--1);
  font-weight: 400;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.creds-list {
  list-style: none;
}

.creds-list li {
  display: grid;
  gap: 0.15rem;
  padding-block: 0.85rem;
  border-top: 1px solid var(--line);
}

.creds-list li:last-child {
  border-bottom: 1px solid var(--line);
}

.creds-list .name {
  color: var(--text);
}

.creds-list .issuer {
  font-size: 0.9rem;
  color: var(--text-subtle);
}

.creds-list .name .flag-icon {
  margin-right: 0.5em;
}

/* ---------- Contact ---------- */
.contact {
  padding-block: var(--space-section);
  border-top: 1px solid var(--line);
}

.contact .section-index {
  margin-bottom: 1.25rem;
}

.contact-title {
  font-family: var(--font-display);
  font-size: var(--step-3);
  font-weight: 400;
  letter-spacing: -0.015em;
  max-width: 17em;
}

.contact-intro {
  margin-top: 1rem;
  max-width: 56ch;
  color: var(--text-muted);
}

.contact-links {
  display: grid;
  gap: 0;
  margin-top: 2.5rem;
  list-style: none;
  border-top: 1px solid var(--line);
}

.contact-links a,
.contact-links .static {
  display: grid;
  grid-template-columns: 7rem 1fr auto;
  align-items: center;
  gap: 1rem;
  padding-block: 1.25rem;
  border-bottom: 1px solid var(--line);
  text-decoration: none;
}

.contact-links .label {
  color: var(--text-subtle);
}

.contact-links .value {
  font-family: var(--font-display);
  font-size: var(--step-1);
  overflow-wrap: anywhere;
  transition: color 0.2s ease;
}

.contact-links svg {
  width: 1.1rem;
  height: 1.1rem;
  color: var(--text-subtle);
  transition: transform 0.25s var(--ease-out), color 0.2s ease;
}

.flag-icon {
  display: inline-block;
  width: 1.5rem;
  height: 1rem;
  vertical-align: -0.1em;
  border-radius: 2px;
  object-fit: contain;
}

.contact-links .flag-icon {
  margin: 0 0.35em 0 0.15em;
}

.contact-links a:hover .value {
  color: var(--accent);
}

.contact-links a:hover svg {
  color: var(--accent);
  transform: translate(2px, -2px);
}

/* ---------- Footer ---------- */
.site-footer {
  padding-block: 2rem 2.5rem;
  border-top: 1px solid var(--line);
  color: var(--text-subtle);
}

.site-footer .container {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.75rem 2rem;
}

.site-footer a {
  text-decoration: none;
}

.site-footer a:hover {
  color: var(--text);
}

/* ---------- Responsive ---------- */
@media (min-width: 40rem) {
  .figures {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .work-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .work-grid > li:last-child {
    grid-column: 1 / -1;
  }

  .earlier-list li {
    grid-template-columns: 9rem 1fr;
  }

  .earlier-list .note {
    grid-column: 2;
  }

  .skills-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .creds-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 56rem) {
  .hero-grid {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .portrait {
    order: 0;
    justify-self: end;
    width: clamp(15rem, 22vw, 20rem);
  }

  .section-head {
    grid-template-columns: 12rem minmax(0, 1fr);
    align-items: baseline;
  }

  .section-head .section-intro {
    grid-column: 2;
  }

  .figures {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .work-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  .work-grid > li,
  .work-grid > li:last-child {
    grid-column: span 2;
  }

  .work-grid > li.is-lead {
    grid-column: span 3;
  }

  .role {
    grid-template-columns: 12rem minmax(0, 1fr);
  }

  .creds-grid {
    grid-template-columns: 1fr 1.3fr 0.8fr 1.1fr;
  }
}

@media (max-width: 40rem) {
  /* Without JS the links simply stay visible; with JS they collapse behind the menu button. */
  .js .menu-toggle {
    display: inline-flex;
  }

  .js .nav ul {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    display: none;
    flex-direction: column;
    gap: 0;
    padding: 0.5rem var(--gutter) 1rem;
    background: var(--bg);
    border-bottom: 1px solid var(--line);
  }

  .js .nav.is-open ul {
    display: flex;
  }

  .js .nav ul a {
    display: block;
    padding: 0.85rem 0;
    border-radius: 0;
    border-bottom: 1px solid var(--line);
    font-size: 1rem;
    background: none;
  }

  .js .nav ul li:last-child a {
    border-bottom: 0;
  }

  .nav a[aria-current="location"] {
    color: var(--accent);
  }

  html:not(.js) .site-header .container {
    flex-wrap: wrap;
    padding-block: 0.5rem;
  }

  html:not(.js) .nav ul {
    flex-wrap: wrap;
  }

  .certs {
    grid-template-columns: 1fr;
  }

  .certs-label {
    max-width: none;
  }

  .contact-links a,
  .contact-links .static {
    grid-template-columns: 1fr auto;
  }

  .contact-links .label {
    grid-column: 1 / -1;
  }
}

/* ---------- Motion preferences ---------- */
@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;
  }

  .card:hover {
    transform: none;
  }
}

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

  /* Hero: one staggered entrance on load (CSS only, so it runs even before JS). */
  .hero-grid > div > *,
  .portrait {
    animation: rise 0.9s var(--ease-out) both;
  }

  .hero-grid > div > :nth-child(2) { animation-delay: 0.06s; }
  .hero-grid > div > :nth-child(3) { animation-delay: 0.14s; }
  .hero-grid > div > :nth-child(4) { animation-delay: 0.22s; }
  .hero-grid > div > :nth-child(5) { animation-delay: 0.3s; }
  .hero-grid > div > :nth-child(6) { animation-delay: 0.36s; }
  .portrait { animation-delay: 0.2s; animation-duration: 1.1s; }

  .status-dot {
    animation: pulse 2.8s ease-in-out 1.2s 3; /* a few pulses, then still */
  }

  /* Scroll reveal: hidden state applies only once JS has marked elements (see main.js). */
  .js [data-reveal] {
    opacity: 0;
    transform: translateY(18px);
    transition:
      opacity 0.7s var(--ease-out) var(--reveal-delay, 0s),
      transform 0.8s var(--ease-out) var(--reveal-delay, 0s),
      border-color 0.3s ease,
      background-color 0.3s ease;
  }

  .js [data-reveal].is-visible {
    opacity: 1;
    transform: none;
  }

  /* Certification badges stamp in one by one, then a single pass of light catches each. */
  .certs.is-visible .certs-list li {
    animation: cert-stamp 0.5s var(--ease-out) both;
    animation-delay: calc(var(--i, 0) * 70ms + 0.15s);
  }

  .certs.is-visible .certs-list li::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(115deg, transparent 30%, var(--accent-soft) 50%, transparent 70%);
    transform: translateX(-120%);
    animation: cert-shine 0.9s ease-out both;
    animation-delay: calc(var(--i, 0) * 70ms + 0.45s);
    pointer-events: none;
  }

  @keyframes rise {
    from {
      opacity: 0;
      transform: translateY(16px);
    }
  }

  @keyframes pulse {
    50% {
      box-shadow: 0 0 0 7px transparent;
    }
  }

  @keyframes cert-stamp {
    from {
      opacity: 0;
      transform: scale(0.6) rotate(calc(var(--tilt, -1) * 10deg));
    }
    60% {
      opacity: 1;
      transform: scale(1.05) rotate(calc(var(--tilt, -1) * -3deg));
    }
    to {
      opacity: 1;
      transform: scale(1) rotate(0deg);
    }
  }

  @keyframes cert-shine {
    to {
      transform: translateX(120%);
    }
  }
}

main:focus {
  outline: none;
}
