/* ---------- Colors and sizes ---------- */
:root {
  --bg: #f5f7f8;
  --surface: #ffffff;
  --text: #14202b;
  --muted: #45545f;
  --line: #c9d3d9;
  --accent: #0b5f66;
  --accent-text: #ffffff;
  --focus: #b24a00;
  --measure: 46rem;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1a21;
    --surface: #16242d;
    --text: #e8eef2;
    --muted: #b3c0c8;
    --line: #2f4350;
    --accent: #6fd0d6;
    --accent-text: #0f1a21;
    --focus: #ffb36b;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1a21;
  --surface: #16242d;
  --text: #e8eef2;
  --muted: #b3c0c8;
  --line: #2f4350;
  --accent: #6fd0d6;
  --accent-text: #0f1a21;
  --focus: #ffb36b;
  color-scheme: dark;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: inherit; }
html { scroll-padding-top: env(safe-area-inset-top, 0px); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 1.0625rem/1.6 var(--font);
}
.wrap { max-width: var(--measure); margin: 0 auto; padding: 0 1.25rem; }
h1, h2, h3 { line-height: 1.2; margin: 0; }
h2 { font-size: 1.5rem; margin-bottom: 1.25rem; }
h3 { font-size: 1.125rem; }
p, ul { margin: 0; }
ul { padding-left: 1.2rem; }
li + li { margin-top: 0.25rem; }
a { color: var(--accent); text-underline-offset: 0.2em; text-decoration-skip-ink: none; }
a:hover { text-decoration-thickness: 2px; }

/* Visible keyboard focus */
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; border-radius: 2px; }

/* Skip link for keyboard and screen reader users */
.skip-link {
  position: absolute; left: 1rem; top: -4rem;
  background: var(--accent); color: var(--accent-text);
  padding: 0.6rem 1rem; border-radius: 0.25rem; z-index: 10;
}
.skip-link:focus { top: 1rem; }

/* ---------- Header ---------- */
.site-header {
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  padding: 3.5rem 0 2rem;
}
.header-grid {
  display: grid;
  grid-template-columns: 1fr;
  row-gap: 1rem;
  align-items: center;
}
@media (min-width: 40rem) {
  .header-grid { grid-template-columns: 1fr auto; }
}

/* Name and job title: the title sits below the name, then moves beside it */
.identity { display: flex; flex-wrap: wrap; align-items: baseline; column-gap: 1rem; }
.site-header h1 { font-size: clamp(2.5rem, 8vw, 4rem); letter-spacing: -0.02em; }
.role { width: 100%; margin-top: 0.5rem; font-size: 1.25rem; color: var(--muted); white-space: nowrap; }

/* The navigation sits below intro and contact; once compact, it moves up beside the name */
.nav { grid-row: 3; grid-column: 1; }
.nav ul { display: flex; flex-wrap: wrap; gap: 0.5rem 1.25rem; list-style: none; padding: 0; }
.nav li + li { margin-top: 0; }

/* Intro and contact: a grid row that can collapse to a height of 0 */
.header-extra { display: grid; grid-template-rows: 1fr; grid-column: 1 / -1; }
.header-extra-inner { min-height: 0; overflow: hidden; }
.intro { max-width: 38rem; }
.contact { display: flex; flex-wrap: wrap; gap: 0.5rem 1.5rem; list-style: none; padding: 0; margin-top: 1.25rem; }
.contact li + li { margin-top: 0; }

/*
  Compact sticky header, driven purely by scroll position (no JavaScript).
  Without support for scroll-driven animations, or with reduced motion
  requested, the header stays static and fully expanded.
*/
@supports (animation-timeline: scroll()) {
  @media (prefers-reduced-motion: no-preference) {
    html {
      scroll-padding-top: calc(env(safe-area-inset-top, 0px) + 6rem);
      /* The header changes height while scrolling. Without this, scroll anchoring
         would counter-steer and hold the page in place. */
      overflow-anchor: none;
    }

    .site-header {
      position: sticky;
      top: env(safe-area-inset-top, 0px);
      z-index: 5;
    }

    /* Covers the area behind the status bar on phones */
    body::before {
      content: "";
      position: fixed;
      inset: 0 0 auto;
      height: env(safe-area-inset-top, 0px);
      background: var(--bg);
      z-index: 10;
    }

    /* All parts share the same scroll timeline: the first 9rem of scrolling */
    .site-header,
    .header-grid,
    .site-header h1,
    .role,
    .nav,
    .header-extra {
      animation-duration: 1ms; /* ignored with a scroll timeline; some browsers still require it */
      animation-timing-function: linear;
      animation-fill-mode: both;
      animation-timeline: scroll();
      animation-range: 0 9rem;
    }
    .site-header   { animation-name: compact-header; }
    .header-grid   { animation-name: compact-grid; }
    .site-header h1 { animation-name: compact-title; }
    .role          { animation-name: compact-role; }
    .header-extra  { animation-name: collapse-extra; }

    /* Wide screens: the nav jumps to the top row shortly before the header is fully compact */
    @media (min-width: 40rem) {
      .nav { animation-name: move-nav; }
    }
  }
}

@keyframes compact-header { to { padding-top: 0.5rem; padding-bottom: 0.25rem; } }
@keyframes compact-grid   { to { row-gap: 0.25rem; } }
@keyframes compact-title  { to { font-size: 1.375rem; } }
@keyframes compact-role   { to { width: 10rem; margin-top: 0; font-size: 0.95rem; } }
@keyframes move-nav {
  /* grid-row and grid-column cannot be animated smoothly: they switch at the midpoint between two keyframes */
  0%, 95% { grid-row: 3; grid-column: 1; }
  100%    { grid-row: 1; grid-column: 2; }
}
@keyframes collapse-extra {
  /* visibility: hidden also removes the collapsed email link from the tab order */
  to { grid-template-rows: 0fr; opacity: 0; visibility: hidden; }
}

/* ---------- Sections ---------- */
section { padding: 2.5rem 0; border-bottom: 1px solid var(--line); }
section:last-of-type { border-bottom: 0; }

/* Timeline: a real chronological sequence */
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline > li { position: relative; padding: 0 0 2rem 1.5rem; border-left: 2px solid var(--line); margin: 0; }
.timeline > li::before {
  content: ""; position: absolute; left: -0.45rem; top: 0.45rem;
  width: 0.8rem; height: 0.8rem; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--bg);
}
.timeline > li:last-child { padding-bottom: 0; }
.period { color: var(--muted); font-size: 0.95rem; }
.org { color: var(--muted); margin-bottom: 0.5rem; }
.station { margin-top: 1rem; }
.station h4 { margin: 0; font-size: 1rem; }
.station p, .station ul { margin-top: 0.25rem; }

/* Education and other stations */
.stations { list-style: none; padding: 0; margin: 0.75rem 0 2rem; }
.stations li + li { margin-top: 1rem; }
.stations:last-child { margin-bottom: 0; }

/* Skills */
.skills { display: grid; grid-template-columns: 1fr; gap: 0.25rem 1.5rem; margin: 0; }
.skills dt { font-weight: 700; margin-top: 0.75rem; }
.skills dd { margin: 0; }
@media (min-width: 40rem) {
  .skills { grid-template-columns: 11rem 1fr; }
  .skills dt, .skills dd { margin-top: 0; padding: 0.5rem 0; border-top: 1px solid var(--line); }
}

.site-footer { padding: 2rem 0 3rem; color: var(--muted); font-size: 0.95rem; }

/* ---------- Preferences and print ---------- */
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }
@media print {
  body { background: #fff; color: #000; font-size: 11pt; }
  .skip-link, .nav { display: none; }
  a { color: inherit; }
  .site-header, .site-header * { position: static; animation: none !important; }
  section { break-inside: avoid; }
}
