/* ---------- Theme tokens ---------- */
:root {
  --bg: #fcfbf8;
  --surface: #ffffff;
  --ink: #1b1d22;
  --muted: #5d6270;
  --line: #e2ddd4;
  --accent: #1f4e8c;
  --accent-ink: #ffffff;
  --accent-soft: #e2e9f2;
  --shadow: 0 1px 2px rgb(20 20 30 / 0.05), 0 8px 24px rgb(20 20 30 / 0.06);

  --serif: "Fraunces", Georgia, "Times New Roman", serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --max: 68rem;
  --gutter: clamp(1rem, 4vw, 2rem);
  color-scheme: light;
}

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

html { scroll-behavior: smooth; scroll-padding-top: 5rem; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 1.0625rem/1.65 var(--sans);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; line-height: 1.2; }
p { margin: 0; }
a { color: var(--accent); text-underline-offset: 0.2em; }
img { max-width: 100%; display: block; }
ul, ol { margin: 0; padding: 0; list-style: none; }

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

.skip {
  position: absolute; left: 1rem; top: -3rem;
  background: var(--accent); color: var(--accent-ink);
  padding: 0.5rem 1rem; z-index: 20;
}
.skip:focus { top: 1rem; }

main, .topbar-inner, .footer {
  max-width: var(--max);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s;
}
.topbar.scrolled { border-bottom-color: var(--line); }

.topbar-inner {
  display: flex;
  align-items: baseline; /* name and tabs sit on the same text line */
  gap: 1rem;
  padding-block: 0.75rem;
}

.mark {
  font: 600 1.15rem/1.2 var(--serif);
  color: var(--ink);
  text-decoration: none;
  letter-spacing: 0.02em;
}

.nav { display: flex; gap: 0.25rem; margin-left: auto; }
.nav a {
  display: block;
  padding: 0.4rem 0.6rem;
  color: var(--muted);
  font-size: 0.925rem;
  font-weight: 500;
  text-decoration: none;
  transition: color 0.15s;
}
.nav a:hover { color: var(--ink); }
/* The current section gets an underline instead of a filled pill. */
.nav a.active {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 2px;
  text-underline-offset: 0.45em;
}

/* ---------- Hero ---------- */
.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr);
  align-items: center;
  gap: clamp(2rem, 6vw, 5rem);
  padding-block: clamp(3rem, 9vw, 7rem) clamp(2.5rem, 6vw, 4.5rem);
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 1rem;
}

.hero h1 {
  font: 600 clamp(3rem, 8vw, 5.5rem)/1 var(--serif);
  letter-spacing: -0.02em;
}

.role {
  font: 400 clamp(1.3rem, 2.6vw, 1.7rem)/1.3 var(--serif);
  font-style: italic;
  color: var(--muted);
  margin-top: 0.75rem;
}

.bio {
  max-width: 38rem;
  margin-top: 1.75rem;
  font-size: 1.15rem;
  color: var(--muted);
}

.links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 2.5rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 1.1rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font-size: 0.925rem;
  font-weight: 500;
  text-decoration: none;
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.btn:hover { transform: translateY(-1px); border-color: var(--accent); box-shadow: var(--shadow); }
.btn svg {
  width: 1.05rem; height: 1.05rem; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.btn svg.filled { fill: currentColor; stroke: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
/* Hero links: a touch more compact so all four fit on one line. */
.links .btn { gap: 0.4rem; padding: 0.6rem 0.9rem; font-size: 0.875rem; white-space: nowrap; }
/* Square, ink-outlined boxes; on hover they lift up-left onto a hard shadow. */
.links .btn { border-radius: 0; border-color: var(--ink); background: transparent; }
.links .btn:hover { transform: translate(-2px, -2px); border-color: var(--ink); box-shadow: 3px 3px 0 var(--ink); }
.links .btn-primary { background: var(--accent); border-color: var(--accent); }
.links .btn-primary:hover { border-color: var(--accent); }
/* On wider screens the intro fills the first screen (below the top bar), so
   Education starts below the fold. Capped so huge monitors don't overdo it. */
@media (min-width: 761px) {
  /* Less padding on top than below, so the intro sits a bit above center. */
  .hero {
    min-height: min(calc(100svh - 3.5rem), 56rem);
    padding-block: clamp(1.5rem, 4vh, 3rem) clamp(4rem, 12vh, 8rem);
  }
}

.portrait { margin: 0; justify-self: center; width: min(100%, 27rem); }
.portrait img { width: 100%; height: auto; }

/* ---------- Sections ---------- */
.section {
  display: grid;
  grid-template-columns: 14rem minmax(0, 1fr);
  gap: 2rem;
  padding-block: clamp(3rem, 7vw, 5rem);
  border-bottom: 1px solid var(--line);
}
.section:last-child { border-bottom: 0; }

.section-head h2 { font: 600 1.9rem var(--serif); letter-spacing: -0.01em; }
.section-head p { color: var(--muted); font-size: 0.925rem; margin-top: 0.35rem; }
@media (min-width: 761px) {
  .section-head { position: sticky; top: 6rem; align-self: start; }
}

h3 { font-size: 1.05rem; font-weight: 600; }
.meta { color: var(--muted); font-size: 0.925rem; margin-top: 0.2rem; }

/* Publications */
.pubs { display: grid; gap: 0.25rem; }
.pub {
  display: grid;
  grid-template-columns: 7.5rem minmax(0, 1fr);
  gap: 1rem;
  padding: 1rem 0;
  border-bottom: 1px dashed var(--line);
}
.pub:last-child { border-bottom: 0; }
.pub h3 { font: 600 1.15rem/1.35 var(--serif); }
.pub-status {
  align-self: start;
  justify-self: start;
  padding: 0.15rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 500;
  white-space: nowrap;
  margin-top: 0.15rem;
}
.pub-status.published { background: var(--accent-soft); border-color: transparent; color: var(--accent); }

/* Experience timeline */
.timeline { position: relative; }
.job {
  display: grid;
  grid-template-columns: 9.5rem minmax(0, 1fr);
  gap: 1.5rem;
  padding-bottom: 2.25rem;
}
.job:last-child { padding-bottom: 0; }
.job-when { color: var(--muted); font-size: 0.875rem; font-variant-numeric: tabular-nums; padding-top: 0.15rem; }
.job-body {
  position: relative;
  padding-left: 1.5rem;
  border-left: 1px solid var(--line);
}
.job-body::before {
  content: "";
  position: absolute;
  left: -0.35rem; top: 0.45rem;
  width: 0.7rem; height: 0.7rem;
  border-radius: 50%;
  background: var(--bg);
  border: 2px solid var(--accent);
}
.job-body ul { margin-top: 0.75rem; display: grid; gap: 0.4rem; }
.job-body li {
  position: relative;
  padding-left: 1rem;
  color: var(--muted);
  font-size: 0.975rem;
}
.job-body li::before {
  content: "";
  position: absolute;
  left: 0; top: 0.7em;
  width: 0.35rem; height: 1px;
  background: var(--muted);
}

/* Education */
/* Education and Projects use the same divided list as Research, not cards. */
.degrees { display: grid; gap: 0.25rem; }
.degree {
  padding: 1rem 0;
  border-bottom: 1px dashed var(--line);
}
.degree:first-child, .project:first-child { padding-top: 0; }
.degree:last-child, .project:last-child { border-bottom: 0; }
.degree-when { color: var(--accent); font-size: 0.8rem; font-weight: 600; letter-spacing: 0.06em; margin-bottom: 0.3rem; }
.degree h3 { font: 600 1.15rem var(--serif); }
.degree .meta + p { margin-top: 0.5rem; font-size: 0.95rem; }

/* Projects */
.projects { display: grid; gap: 0.25rem; }
.project {
  padding: 1.25rem 0;
  border-bottom: 1px dashed var(--line);
}
.project-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.25rem 1rem;
}
.project h3 { font: 600 1.15rem var(--serif); }
.project-link { font-size: 0.875rem; font-weight: 500; text-decoration: none; white-space: nowrap; }
.project-link:hover { text-decoration: underline; }
.project-links { display: flex; flex-wrap: wrap; gap: 0.25rem 1rem; }
.tags { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: 0.6rem; }
.tags li {
  padding: 0.1rem 0.55rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 500;
}
.project-points { margin-top: 0.85rem; display: grid; gap: 0.4rem; }
.project-points li {
  position: relative;
  padding-left: 1rem;
  color: var(--muted);
  font-size: 0.975rem;
}
.project-points li::before {
  content: "";
  position: absolute;
  left: 0; top: 0.7em;
  width: 0.35rem; height: 1px;
  background: var(--muted);
}

/* Awards (reuse the publication list layout) */
.award-note { color: var(--muted); font-size: 0.95rem; margin-top: 0.4rem; }

/* ---------- Footer ---------- */
.footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 1rem;
  padding-block: 2rem 2.5rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.875rem;
}
.footer-links { display: flex; gap: 1.25rem; }
.footer-links a { color: var(--muted); text-decoration: none; }
.footer-links a:hover { color: var(--accent); }

/* ---------- Scroll reveal (only when JS is running) ---------- */
.js .reveal { opacity: 0; transform: translateY(16px); transition: opacity 0.6s ease, transform 0.6s ease; }
.js .reveal.visible { opacity: 1; transform: none; }

/* Page fade-in: hidden while fonts load, then fades in as the intro rises. */
body { transition: opacity 0.7s ease; }
html.loading body { opacity: 0; }

html:not(.loading) .hero-text > *,
html:not(.loading) .portrait { animation: rise 0.8s ease both; }
.hero-text > :nth-child(2) { animation-delay: 0.05s; }
.hero-text > :nth-child(3) { animation-delay: 0.1s; }
.hero-text > :nth-child(4) { animation-delay: 0.15s; }
.hero-text > :nth-child(5) { animation-delay: 0.2s; }
.portrait { animation-delay: 0.15s; }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .js .reveal { opacity: 1; transform: none; }
}

/* ---------- Narrow screens ---------- */
@media (max-width: 760px) {
  .nav { display: none; }

  .hero { grid-template-columns: 1fr; text-align: left; }
  .portrait { grid-row: 1; justify-self: start; width: 10rem; }

  .section { grid-template-columns: 1fr; gap: 1.5rem; }
  .pub { grid-template-columns: 1fr; gap: 0.4rem; }
  .job { grid-template-columns: 1fr; gap: 0.4rem; }
  .job-when { padding-left: 1.5rem; }
}

/* ---------- Top-bar app links (every page) ---------- */
/* A divider, a solid navy "Apps" tag, then the two app links in navy with an
   arrow, so the group reads apart from the section links. */
.mark { white-space: nowrap; }
/* Push the section links and the app links to the right of the name. */
.topbar-inner > nav { margin-left: auto; }
.apps-label {
  margin-left: 1.5rem;
  align-self: center;
  position: relative;
  padding: 0.2rem 0.45rem;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  line-height: 1.4;
}
/* Divider: a dark rule to the left of the tag. */
.apps-label::before {
  content: "";
  position: absolute;
  left: -1rem; top: 50%;
  width: 1px; height: 1.6rem;
  transform: translateY(-50%);
  background: var(--ink);
  opacity: 0.35;
}
.demo-link {
  align-self: center;
  padding: 0.4rem 0.1rem;
  color: var(--accent);
  font-size: 0.925rem;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
}
.demo-link::after { content: "\2197"; font-size: 0.85em; margin-left: 0.2rem; }
.demo-link:hover { text-decoration: underline; text-decoration-thickness: 1px; }
/* On an app's own page, its link is underlined like the current section. */
.demo-link[aria-current="page"] {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 2px;
  text-underline-offset: 0.45em;
}
.demo-link[aria-current="page"]::after { content: none; }

/* Mid widths: tighten the section links to make room. */
@media (min-width: 761px) and (max-width: 980px) {
  .nav a { padding-inline: 0.45rem; font-size: 0.875rem; }
}
/* Narrow screens hide the section links (and their <nav>, or the empty element
   still takes a flex slot), so drop the divider and push the group right. */
@media (max-width: 760px) {
  .topbar-inner > nav { display: none; }
  .apps-label { margin-left: auto; }
  .apps-label::before { display: none; }
}
/* Phones: the app links wrap onto a second line under the name. */
@media (max-width: 520px) {
  .topbar-inner { flex-wrap: wrap; row-gap: 0.5rem; }
  .mark { flex-basis: 100%; }
  .apps-label { margin-left: 0; }
}
