:root {
  --bg: #fafaf8;
  --surface: #ffffff;
  --text: #1c1c1a;
  --muted: #6b6b66;
  --faint: #9a9a93;
  --accent: #1a2c42;
  --border: #e8e7e2;
  --rail-w: 264px;
  --serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html.dark {
  --bg: #15171b;
  --surface: #1e2127;
  --text: #e6e6e1;
  --muted: #9a9a93;
  --faint: #6f6f69;
  --accent: #9db8da;
  --border: #2a2e36;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: 32px;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background 0.3s ease, color 0.3s ease;
}

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

/* ---------- LAYOUT ---------- */
.layout {
  max-width: 1060px;
  margin: 0 auto;
  padding: 0 48px;
  display: grid;
  grid-template-columns: var(--rail-w) 1fr;
  gap: 72px;
  align-items: start;
}

/* ---------- LEFT RAIL ---------- */
.rail {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 72px 0 40px;
}

.rail-inner {
  display: flex;
  flex-direction: column;
  gap: 28px;
  min-height: 0;
}

.identity {
  margin: 0;
}

.name {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 44px;
  line-height: 1.02;
  letter-spacing: -0.015em;
  margin: 0 0 14px;
}

.title {
  font-size: 14.5px;
  color: var(--text);
  margin: 0 0 2px;
  line-height: 1.45;
}

.affil {
  font-size: 14.5px;
  color: var(--muted);
  margin: 0;
}

.photo {
  width: 92px;
  height: 92px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
}

.photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-placeholder {
  font-family: var(--serif);
  font-size: 28px;
  color: var(--faint);
  letter-spacing: 1px;
}

/* Rail nav */
.rail-nav {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.rail-nav a {
  position: relative;
  font-size: 14.5px;
  font-weight: 500;
  color: var(--muted);
  width: fit-content;
  padding-left: 0;
  transition: color 0.2s ease, padding-left 0.2s ease;
}

.rail-nav a::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  width: 0;
  height: 1px;
  background: var(--accent);
  transform: translateY(-50%);
  transition: width 0.25s ease;
}

.rail-nav a:hover {
  color: var(--text);
}

.rail-nav a.active {
  color: var(--text);
  padding-left: 26px;
}

.rail-nav a.active::before {
  width: 18px;
}

/* Rail external links */
.rail-links {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.rail-links a {
  font-size: 13.5px;
  color: var(--faint);
  width: fit-content;
  border-bottom: 1px solid transparent;
  transition: color 0.2s ease, border-color 0.2s ease;
}

.rail-links a:hover {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* Theme toggle */
.theme-toggle {
  margin-top: auto;
  background: none;
  border: none;
  color: var(--faint);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--sans);
  font-size: 13px;
  padding: 0;
  width: fit-content;
  transition: color 0.2s ease;
}

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

.theme-icon-moon {
  display: none;
}
html.dark .theme-icon-sun {
  display: none;
}
html.dark .theme-icon-moon {
  display: inline;
}

/* ---------- RIGHT CONTENT ---------- */
.content {
  min-width: 0;
  padding: 72px 0 0;
}

.section {
  padding: 0 0 52px;
}

.section:last-of-type {
  padding-bottom: 28px;
}

.section-title {
  font-family: var(--sans);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--faint);
  margin: 0 0 20px;
}

.section p {
  margin: 0 0 16px;
}

.section p:last-child {
  margin-bottom: 0;
}

.lead {
  font-family: var(--serif);
  font-size: 20px;
  line-height: 1.55;
  color: var(--text);
}

.content a:not(.rail-links a) {
  border-bottom: 1px solid var(--border);
  transition: border-color 0.2s ease;
}

.content a:hover {
  border-bottom-color: var(--accent);
}

/* ---------- PUBLICATIONS ---------- */
.pub-group + .pub-group {
  margin-top: 26px;
}

.pub-group-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 14px;
}

.pub {
  display: flex;
  gap: 20px;
  padding: 14px 0;
  border-top: 1px solid var(--border);
}

.pub:first-of-type {
  border-top: none;
  padding-top: 0;
}

.pub-year {
  flex: 0 0 44px;
  color: var(--faint);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  padding-top: 3px;
}

.pub-body {
  flex: 1;
  min-width: 0;
}

.pub-title {
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.4;
  margin: 0 0 4px;
}

.pub-title a {
  color: var(--text);
  border-bottom-color: var(--border);
}

.pub-authors {
  font-size: 14.5px;
  color: var(--text);
  margin: 0 0 2px;
}

.pub-venue {
  font-size: 14.5px;
  color: var(--muted);
  font-style: italic;
  margin: 0;
}

/* ---------- TIMELINE (experience + education) ---------- */
.entry {
  display: flex;
  gap: 20px;
  padding: 16px 0;
  border-top: 1px solid var(--border);
}

.entry:first-of-type {
  border-top: none;
  padding-top: 0;
}

.entry-period {
  flex: 0 0 104px;
  color: var(--faint);
  font-size: 13.5px;
  font-variant-numeric: tabular-nums;
  padding-top: 4px;
}

.entry-body {
  flex: 1;
  min-width: 0;
}

.entry-role {
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 600;
  margin: 0 0 2px;
}

.entry-org {
  font-size: 15px;
  color: var(--accent);
  margin: 0 0 4px;
}

.entry-detail {
  font-size: 15px;
  color: var(--muted);
  margin: 0;
  line-height: 1.6;
}

/* ---------- SKILLS ---------- */
.skill-row {
  display: flex;
  gap: 20px;
  padding: 14px 0;
  border-top: 1px solid var(--border);
}

.skill-row:first-of-type {
  border-top: none;
  padding-top: 0;
}

.skill-group {
  flex: 0 0 104px;
  color: var(--faint);
  font-size: 13.5px;
  padding-top: 5px;
}

.skill-items {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  font-size: 13px;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 4px 12px;
  line-height: 1.3;
  transition: border-color 0.2s ease, color 0.2s ease;
}

.chip:hover {
  color: var(--text);
  border-color: var(--accent);
}

/* ---------- FOOTER ---------- */
.footer {
  padding: 24px 0 64px;
  border-top: 1px solid var(--border);
}

.footer p {
  color: var(--faint);
  font-size: 13.5px;
  margin: 0;
}

.footer a {
  color: var(--faint);
  border-bottom: 1px solid var(--border);
}

.footer a:hover {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.footer-sep {
  margin: 0 5px;
  opacity: 0.6;
}

/* ---------- REVEAL ANIMATION ---------- */
.reveal {
  opacity: 0;
  transform: translateY(14px);
  transition: opacity 0.6s ease, transform 0.6s ease;
}

.reveal.is-visible {
  opacity: 1;
  transform: none;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
  .reveal {
    opacity: 1;
    transform: none;
    transition: none;
  }
}

/* ---------- RESPONSIVE ---------- */
@media (max-width: 820px) {
  .layout {
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 0 28px;
  }
  .rail {
    position: static;
    height: auto;
    padding: 52px 0 0;
  }
  .rail-inner {
    gap: 22px;
  }
  .name {
    font-size: 40px;
  }
  /* On mobile, name on one line reads better */
  .name br {
    display: none;
  }
  .rail-nav {
    display: none; /* sections are right below; rail nav is desktop-only */
  }
  .rail-links {
    flex-flow: row wrap;
    gap: 8px 16px;
  }
  .theme-toggle {
    margin-top: 8px;
  }
  .content {
    padding-top: 40px;
  }
  .lead {
    font-size: 18px;
  }
}

@media (max-width: 480px) {
  body {
    font-size: 16px;
  }
  .layout {
    padding: 0 20px;
  }
  .pub-year,
  .entry-period {
    flex-basis: 56px;
  }
  .entry {
    gap: 14px;
  }
  .skill-row {
    flex-direction: column;
    gap: 9px;
    padding: 16px 0;
  }
  .skill-group {
    padding-top: 0;
    flex-basis: auto;
  }
}
