:root {
  color-scheme: light dark;
  --bg: #fbfbfd;
  --text: #10233a;
  --muted: #3b5068;
  --accent: #0b3d7a;
  --on-accent: #ffffff;
  --border: #d2dbe3;
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1b29;
    --text: #e6edf3;
    --muted: #a9bbcc;
    --accent: #9fcfee;
    --on-accent: #0f1b29;
    --border: #2c4560;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, sans-serif;
  font-size: 1.0625rem;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  /* Pin the footer to the bottom of tall windows instead of leaving empty space under it */
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

main { flex: 1 0 auto; width: 100%; }

h1, h2, h3 { line-height: 1.2; }

h1 { font-size: 1.6rem; margin: 0 0 1.5rem; }
h2 { font-size: 1.35rem; margin: 2.5rem 0 1.25rem; }

a {
  color: var(--accent);
  transition: color 0.15s ease, opacity 0.15s ease;
}

/* Press feedback shows instantly; the fade only plays on release */
a:active { opacity: 0.6; transition-duration: 0s; }

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

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ===== Header ===== */

header {
  border-bottom: 1px solid var(--border);
  /* Keep the top menu still while the page changes */
  view-transition-name: site-header;
}

.nav {
  max-width: 900px;
  margin: 0 auto;
  padding: 0.5rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  column-gap: 1.5rem;
}

.nav .site-name {
  font-size: 1.2rem;
  font-weight: bold;
  color: var(--text);
  text-decoration: none;
}

.nav ul {
  list-style: none;
  display: flex;
  gap: 1.5rem;
  margin: 0;
  padding: 0;
}

/* Vertical padding makes each link a 44px-tall tap target */
.nav ul a {
  position: relative;
  display: block;
  padding: 10px 0;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.95rem;
}

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

/* Underline that slides in under menu links */
.nav ul a::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: 6px;
  width: 100%;
  height: 2px;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.25s var(--ease-out);
}

.nav ul a[aria-current="page"]::after,
.nav ul a:focus-visible::after {
  transform: scaleX(1);
}

/* ===== Layout ===== */

main {
  max-width: 900px;
  margin: 0 auto;
  padding: 3rem 1.5rem;
}

footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  padding: 1.25rem;
  border-top: 1px solid var(--border);
}

/* ===== Home ===== */

.profile {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 3rem;
  align-items: start;
}

.profile img {
  display: block;
  width: 100%;
  max-width: 240px;
  height: auto;
  border-radius: 4px;
}

.sidebar h1 { margin: 1.25rem 0 0.5rem; }
.sidebar .title { margin: 0; color: var(--muted); white-space: nowrap; }
/* Role in full text colour; the school line below stays muted */
.sidebar .title:first-of-type { color: var(--text); }

/* Contact icons: 20px glyph centred in a 40×44px tap target.
   The negative margin keeps the first icon lined up with the text above. */
.links {
  display: flex;
  align-items: center;
  margin: 0.25rem 0 0.25rem -10px;
}

.links a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 44px;
}

.links svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.degrees {
  font-size: 0.8rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
  padding-top: 1rem;
}

.degrees p { margin: 0.2rem 0; }

.bio p:first-of-type { margin-top: 0; }

/* Keep reading text to a comfortable line length */
.bio,
.papers,
main > p {
  max-width: 66ch;
}

/* ===== Research ===== */

.papers {
  list-style: none;
  margin: 0;
  padding: 0;
}

.paper { margin-bottom: 1.75rem; }

.paper h3 {
  margin: 0 0 0.25rem;
  font-size: 1.0625rem;
  font-weight: normal;
  line-height: 1.4;
}

.paper h3 a { text-decoration: none; }

.paper .venue {
  margin: 0;
  font-style: italic;
  color: var(--muted);
}

/* ===== CV ===== */

.cv-actions {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  margin: 0 0 1.5rem;
}

.cv-actions a:not(.cv-button) { padding: 10px 0; }

.cv-button {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 1.25rem;
  border-radius: 8px;
  background: var(--accent);
  color: var(--on-accent);
  text-decoration: none;
  transition: transform 0.15s var(--ease-out), opacity 0.15s ease;
}

.cv-button:active { transform: scale(0.97); }

.cv-preview {
  display: block;
  width: 100%;
  height: 80vh;
  border: 1px solid var(--border);
  border-radius: 4px;
}

/* ===== Hover (mouse only; touch screens leave hover stuck on after a tap) ===== */

@media (hover: hover) and (pointer: fine) {
  .nav ul a:hover { color: var(--accent); }
  .nav ul a:hover::after { transform: scaleX(1); }
  .links a:hover { color: var(--text); }
  .paper h3 a:hover { text-decoration: underline; }
  .cv-button:hover { opacity: 0.88; }
}

/* ===== Small screens ===== */

@media (max-width: 700px) {
  main { padding: 2rem 1.5rem; }
  .profile { grid-template-columns: 1fr; gap: 1.75rem; }
  /* Centered photo with name, title, icons and degrees stacked below it */
  .sidebar { text-align: center; }
  .profile img { max-width: 160px; margin: 0 auto; }
  .sidebar h1 { margin: 1rem 0 0.4rem; }
  .sidebar .links {
    justify-content: center;
    flex-wrap: wrap;
    margin: 0.4rem 0 0;
  }
  /* No dividers on phones; spacing alone sets the credentials apart */
  .sidebar .degrees {
    margin-top: 0.75rem;
    padding: 0;
    border: 0;
    font-size: 0.7rem;
  }
  .degrees p { margin: 0; }
  .sidebar .title { white-space: normal; line-height: 1.5; font-size: 0.95rem; }
  /* Phone browsers can't reliably show a PDF inside a page; the buttons above open it instead */
  .cv-preview { display: none; }
}

/* ===== Page motion ===== */

/* Quick crossfade between pages */
@view-transition {
  navigation: auto;
}

::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: 0.2s;
  animation-timing-function: ease-out;
}

/* Welcome fade-in on first visit */
@keyframes intro-fade {
  from { opacity: 0; transform: translateY(8px); }
}

@keyframes intro-fade-still {
  from { opacity: 0; }
}

.intro header,
.intro main {
  animation: intro-fade 0.4s var(--ease-out) both;
}

/* Less motion: keep the gentle fades, drop anything that moves */
@media (prefers-reduced-motion: reduce) {
  .intro header,
  .intro main { animation-name: intro-fade-still; }
  .nav ul a::after,
  .cv-button { transition: none; }
}
