/* ---------------------------------------------------------------------------
   Design tokens. Colors live here (with a dark-mode set below) so the rest of
   the sheet never hardcodes a value. Sizes use rem + clamp() so type scales
   fluidly and we need very few breakpoints
--------------------------------------------------------------------------- */
:root {
  --font-display: 'Martel Sans', system-ui, sans-serif; /* Name, headings, nav */
  --font-body: 'Lato', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;

  --bg: #ffffff;
  --fg: #141414;         /* Body text */
  --fg-strong: #000000;  /* Headings */
  --muted: #707070;      /* Inactive nav links; readable on the light nav */
  --icon: #565656;       /* Social icons at rest */
  --link: #1670dd;
  --link-underline: rgba(22, 112, 221, 0.4);
  --chip-link: #0f63c2;
  --chip-bg: #f2f2f2;
  --chip-bg-hover: #e4e4e4;
  --rule: #e8e8e8;

  --nav-bg: rgba(250, 250, 250, 0.85);
  --nav-bg-scrolled: rgba(236, 236, 236, 0.9);
  --nav-border: #f0f0f0;
  --nav-border-scrolled: #dcdcdc;
  --nav-h: 3.4rem;

  /* Include the iOS top inset everywhere the fixed nav height is used */
  --nav-total-h: calc(var(--nav-h) + env(safe-area-inset-top, 0px));

  --icon-size: 1.85rem;  /* Default social icon size */
  --measure: 46rem;      /* Comfortable maximum length for prose lines */
  --intro-photo: clamp(84px, 8vw, 116px);
  --intro-gap: clamp(1.5rem, 4vw, 2.5rem);
  --intro-max: calc(var(--intro-photo) + var(--intro-gap) + var(--measure));

  /* Content column: fluid on small screens, capped on large ones */
  --content: min(85%, 64rem);
}

@media (prefers-color-scheme: dark) {
  /* Swap tokens here so every component inherits dark mode automatically */
  :root {
    --bg: #0f1115;
    --fg: #d7dae1;
    --fg-strong: #f3f4f7;
    --muted: #7c828c;
    --icon: #9aa0aa;
    --link: #6aa8ff;
    --link-underline: rgba(106, 168, 255, 0.5);
    --chip-link: #6aa8ff;
    --chip-bg: #1b1e24;
    --chip-bg-hover: #292d35;
    --rule: #262a31;

    --nav-bg: rgba(18, 20, 25, 0.8);
    --nav-bg-scrolled: rgba(28, 31, 38, 0.92);
    --nav-border: #23272e;
    --nav-border-scrolled: #2f343d;
  }
}

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

html {
  /* Anchor targets land below the fixed nav instead of behind it */
  scroll-padding-top: calc(var(--nav-total-h) + 1rem);
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%; /* Stop iOS bumping font size in landscape */
}

body {
  margin: 0;
  /* Keep the last content clear of the iOS home indicator */
  padding-bottom: calc(3rem + env(safe-area-inset-bottom, 0px));
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: 1.0625rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
a:focus-visible { outline: 2px solid var(--link); outline-offset: 3px; }

/* Give links inside sentences a quiet cue without underlining larger controls */
.intro__bio a,
.section__lead a,
.package > p:not(.chips) a {
  text-decoration: underline;
  text-decoration-color: var(--link-underline);
  text-decoration-thickness: 0.08em;
  text-underline-offset: 0.15em;
}
.intro__bio a:hover,
.section__lead a:hover,
.package > p:not(.chips) a:hover { text-decoration-color: var(--link); }

img { max-width: 100%; height: auto; }

hr {
  border: 0;
  width: var(--content);
  max-width: var(--measure);
  height: 2px;
  background: var(--rule);
  margin: 0 auto;
}

/* Visible only when tabbed to — lets keyboard users skip the nav */
.skip-link {
  position: absolute;
  left: 0.5rem;
  top: -3rem;
  z-index: 10;
  display: inline-flex;
  align-items: center;
  min-height: 2.75rem;
  padding: 0.5rem 0.9rem;
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 0.4rem;
  transition: top 150ms ease;
}
.skip-link:focus { top: 0.5rem; }

/* ---------------------------------------------------------------------------
   Nav — fixed, translucent, links centered
--------------------------------------------------------------------------- */
.nav {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 5;
  height: var(--nav-total-h);
  display: flex;
  align-items: center;
  justify-content: center;

  /* Keep nav content clear of notches and rounded screen edges */
  padding-top: env(safe-area-inset-top, 0px);
  padding-inline:
    max(1rem, env(safe-area-inset-left, 0px))
    max(1rem, env(safe-area-inset-right, 0px));
  background: var(--nav-bg);
  border-bottom: 2px solid var(--nav-border);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: background 250ms linear, border-color 250ms linear;
  will-change: transform; /* Smooths sporadic mobile repaint of the blurred bar */
}
.nav.is-scrolled {
  background: var(--nav-bg-scrolled);
  border-bottom-color: var(--nav-border-scrolled);
}

.nav ul {
  display: flex;
  gap: clamp(1.2rem, 5vw, 3.5rem);
  margin: 0;
  padding: 0;
  list-style: none;
}
.nav a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.75rem;
  min-height: 2.75rem;
  color: var(--muted);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(0.95rem, 0.8rem + 0.7vw, 1.2rem);
  text-transform: uppercase;
  letter-spacing: 0.02em;
  transition: color 200ms ease;
}
.nav a:hover { color: var(--fg-strong); text-decoration: none; }
.nav a.is-active { color: var(--fg-strong); }

/* On touch devices the :hover color can stick after a tap — neutralize it */
@media (hover: none) {
  .nav a:hover { color: var(--muted); }
  .nav a.is-active:hover { color: var(--fg-strong); }
}

/* ---------------------------------------------------------------------------
   Layout — content stays centered while rules span the full viewport
--------------------------------------------------------------------------- */
/* The fixed nav is out of flow, so reserve its full height here */
main { padding-top: var(--nav-total-h); }

.intro, .section {
  width: var(--content);
  margin-inline: auto;
}

.intro { max-width: var(--intro-max); }
.section {
  max-width: var(--measure);
  margin-block: clamp(2.5rem, 6vw, 4rem);
}

/* ---------------------------------------------------------------------------
   Intro — photo beside a column of name / bio / links.
   A two-column grid on desktop; it reflows to photo+name over a full-width
   bio on narrow screens (see the mobile block at the bottom)
--------------------------------------------------------------------------- */
.intro {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-areas:
    'photo name'
    'photo bio'
    'photo links';
  align-items: start;
  column-gap: var(--intro-gap);
  row-gap: 1.25rem;

  /* Grow the opening space smoothly without a jump at the mobile breakpoint */
  margin-top: clamp(2.5rem, min(8vw, 12vh), 8rem);
  margin-bottom: clamp(3rem, 8vw, 5rem);
}

.intro__photo {
  grid-area: photo;
  width: var(--intro-photo);
  aspect-ratio: 1;
  border-radius: 50%;
  object-fit: cover;
}

.intro__name {
  grid-area: name;
  margin: 0;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(1.7rem, 1.3rem + 1.9vw, 2.35rem);
  line-height: 1.15;
  color: var(--fg-strong);
}

/* Keep long prose comfortable to read on wide screens */
.intro__bio { grid-area: bio; max-width: var(--measure); }
.intro__bio p { margin: 0 0 0.9rem; font-size: 1.15rem; line-height: 1.5; }
.intro__bio p:last-child { margin-bottom: 0; }

/* Social / contact icons */
.socials {
  grid-area: links;
  display: flex;
  align-items: center;
  gap: clamp(1rem, 3vw, 1.75rem);
  /* Offset the first hit area so the visible CV aligns with the bio */
  margin: 0.6rem 0 0 -0.75rem;
  padding: 0;
  list-style: none;
}
.social {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  /* The box stays finger-sized even though the glyph is smaller */
  min-width: 2.75rem;
  min-height: 2.75rem;
  color: var(--icon);
  transition: color 200ms ease;
}
.social:hover { color: var(--fg-strong); }
.social svg { width: var(--icon-size); height: var(--icon-size); display: block; }

/* Optical sizing keeps the filled and outlined marks at similar visual weight */
.social--cv svg { width: 2rem; height: 2rem; }
.social--twitter svg { width: 1.7rem; height: 1.7rem; }
.social--github svg { width: 1.75rem; height: 1.75rem; }
.social--email svg { width: 1.8rem; height: 1.8rem; }

/* ---------------------------------------------------------------------------
   Sections — papers & software
--------------------------------------------------------------------------- */
.section__title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(1.6rem, 1.3rem + 1.6vw, 2.15rem);
  color: var(--fg-strong);
  margin: 0 0 1.25rem;
}
.section__lead { margin: 0 0 2rem; }

.paper { margin-bottom: 2.25rem; }

/* Long paper titles share the same readable measure as the bio */
.paper__title {
  max-width: var(--measure);
  margin: 0 0 0.35rem;
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.35;
}
.paper__authors, .paper__meta { margin: 0.15rem 0; }
.paper__meta { color: var(--muted); }
.paper__meta .journal { font-style: italic; }
.paper .me { font-weight: 900; }

.package { margin-bottom: 2rem; }
.package__name {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 1.4rem;
  margin: 0 0 0.4rem;
  color: var(--fg-strong);
}
.package p { margin: 0 0 0.6rem; }

/* Software descriptions use the same readable measure as the bio */
.package > p:not(.chips) { max-width: var(--measure); }

/* Rows of small link "chips" */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.9rem;
  margin: 0.5rem 0 0;
}
.chip {
  display: inline-flex;
  align-items: center;
  min-height: 2.25rem;
  color: var(--chip-link);
  background: var(--chip-bg);
  padding: 0.25rem 0.55rem;
  border-radius: 0.25rem;
  transition: background-color 150ms ease;
}
.chip:hover,
.chip:focus-visible { background: var(--chip-bg-hover); text-decoration: none; }

/* Restore the full 44px target when a finger is the likely input */
@media (hover: none), (pointer: coarse) {
  .chip { min-height: 2.75rem; padding: 0.35rem 0.6rem; }
  .chip:hover { background: var(--chip-bg); }
}

.notfound { margin-top: clamp(4rem, 15vh, 8rem); text-align: center; }
/* The 404 has no fixed nav, so it does not need the main offset */
.notfound-page main { padding-top: 0; }

/* ---------------------------------------------------------------------------
   Narrow screens — photo sits beside the name, bio drops to full width
--------------------------------------------------------------------------- */
@media (max-width: 40rem) {
  .intro {
    grid-template-areas:
      'photo name'
      'bio   bio'
      'links links';
    align-items: center;
    column-gap: 1.1rem;
    row-gap: 1rem;
    margin-top: 2.5rem;
  }
  .intro__bio p { font-size: 1.08rem; }
}

/* Phone landscape uses the same compact gap above the bio */
@media (max-height: 35rem) {
  .intro { margin-top: 2.5rem; }
}

/* ---------------------------------------------------------------------------
   Respect reduced-motion preferences
--------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition-duration: 0.01ms !important; }
}
