:root {
  --bg: #ffffff;
  --ink: #111111;
  --muted: #4a4a4a;
  --accent: #0000ee;
  --border: #dddddd;
  --max-width: 1440px;
}

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

body {
  margin: 0;
  font-family: 'Lato', sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.3;
}

a {
  color: var(--accent);
  text-decoration: underline;
  transition: color 0.2s ease;
}

a:hover {
  color: var(--ink);
}

/* ── Topbar ── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  will-change: transform;
}

.logo {
  font-family: 'Lato', sans-serif;
  font-weight: 700;
  text-transform: uppercase;
}

.nav {
  display: flex;
  gap: 15px;
}

.nav a {
  font-family: 'Lato', sans-serif;
  text-decoration: none;
  color: var(--ink);
  font-size: 14px;
  position: relative;
  padding-bottom: 2px;
}

.nav a::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 0;
  height: 1px;
  background: var(--ink);
  transition: width 0.25s ease;
}

.nav a:hover::after {
  width: 100%;
}

.nav a:hover {
  text-decoration: none;
}

.menu {
  display: none;
  flex-direction: column;
  gap: 4px;
  background: none;
  border: 1px solid var(--ink);
  padding: 6px;
  cursor: pointer;
}

.menu span {
  width: 20px;
  height: 2px;
  background: var(--ink);
}

/* ── Layout ── */
main {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 40px 20px 80px;
  display: grid;
  grid-template-columns: 500px 1fr;
  gap: 60px;
}

.sidebar {
  position: sticky;
  top: 60px;
  align-self: start;
  max-height: calc(100vh - 60px);
  overflow-y: auto;
  padding-right: 15px;
  padding-bottom: 40px;
  font-family: 'Lato', sans-serif;
}

.sidebar::-webkit-scrollbar {
  width: 6px;
}

.sidebar::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
  background: var(--muted);
}

/* ── Typography ── */
h1, h2, h3, h4 {
  font-family: 'Lato', sans-serif;
  margin-top: 1.5em;
  margin-bottom: 0.5em;
  color: var(--ink);
}

h1 {
  font-size: 2em;
  margin-top: 0;
}

h2 {
  font-size: 1.5em;
  border-bottom: 1px solid var(--border);
  padding-bottom: 5px;
}

h3 {
  font-size: 1.2em;
}

p {
  margin: 1em 0;
}

ul {
  padding-left: 20px;
  margin: 1em 0;
}

li {
  margin-bottom: 5px;
}

/* ── Profile ── */
.profile-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 15px;
}

.profile-text {
  flex: 1;
}

.profile-text h1 {
  font-family: 'Outfit', sans-serif;
  font-size: 1.8em;
  font-weight: 300;
  letter-spacing: -0.5px;
}

.profile-image {
  width: 100%;
  max-width: 200px;
  border-radius: 50%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  margin-bottom: 10px;
}

.muted {
  color: var(--muted);
  font-size: 0.9em;
}

/* ── Footer ── */
.footer {
  margin-top: 60px;
  padding: 20px;
  text-align: center;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.9em;
}

/* ── Social Links ── */
.profile-text p a {
  transition: color 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

/* ── Section Reveal Animation ── */
@keyframes revealUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Sections start hidden, revealed by JS */
.content-area > section {
  opacity: 0;
  transform: translateY(20px);
}

.content-area > section.revealed {
  animation: revealUp 0.5s ease forwards;
}

/* Profile loads immediately with a gentle fade */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.sidebar {
  animation: fadeIn 0.4s ease forwards;
}

/* Stagger child items within a revealed section */
.content-area > section.revealed > div[style*="display: flex"],
.content-area > section.revealed > h3,
.content-area > section.revealed > p {
  animation: revealUp 0.4s ease backwards;
}

.content-area > section.revealed > :nth-child(2) { animation-delay: 0.05s; }
.content-area > section.revealed > :nth-child(3) { animation-delay: 0.1s; }
.content-area > section.revealed > :nth-child(4) { animation-delay: 0.15s; }
.content-area > section.revealed > :nth-child(5) { animation-delay: 0.2s; }
.content-area > section.revealed > :nth-child(6) { animation-delay: 0.25s; }

/* ── Performance: off-screen content ── */
.content-area > section {
  content-visibility: auto;
  contain-intrinsic-size: auto 500px;
}

/* ── Responsive ── */
@media (max-width: 900px) {
  main {
    grid-template-columns: 1fr;
    gap: 30px;
    padding: 20px 16px 60px;
    overflow-x: hidden;
  }
  
  .sidebar {
    position: static;
    max-height: none;
    overflow-y: visible;
  }

  /* Center profile on mobile */
  .profile-section {
    align-items: center;
    text-align: center;
  }

  .profile-image {
    max-width: 160px;
    width: 160px;
  }

  .profile-text h1 {
    font-size: 1.5em;
  }

  /* Center social links */
  .profile-text p[style*="flex"] {
    justify-content: center !important;
  }

  /* Stack flex containers vertically */
  .sidebar > section > div,
  .content-area > section > div {
    flex-direction: column !important;
    align-items: flex-start !important;
  }

  /* Prevent any image overflow */
  img {
    max-width: 100% !important;
    height: auto !important;
  }

  /* Publication images: stack above text, full width */
  .pub-image-container {
    width: 100%;
    max-width: 100%;
  }

  .content-area > section > div[style*="display: flex"] img {
    width: 100% !important;
    max-width: 100% !important;
    flex-shrink: 1 !important;
  }

  /* Experience/research logos: keep small */
  .content-area > section > div[style*="display: flex"] img[style*="width: 100px"] {
    width: 60px !important;
    height: 60px !important;
  }

  /* Tighten typography */
  h2 {
    font-size: 1.3em;
    margin-top: 1em;
  }

  h3 {
    font-size: 1.05em;
  }

  body {
    font-size: 15px;
    line-height: 1.5;
    overflow-x: hidden;
    overflow-wrap: break-word;
    word-break: break-word;
  }

  /* Prevent text overflow in all containers */
  .content-area,
  .sidebar,
  .content-area > section,
  .content-area > section > div {
    overflow-wrap: break-word;
    word-break: break-word;
    max-width: 100%;
    overflow-x: hidden;
  }

  /* Better touch targets for links */
  a {
    -webkit-tap-highlight-color: rgba(0, 0, 238, 0.1);
  }

  .nav {
    position: absolute;
    top: 50px;
    right: 16px;
    background: var(--bg);
    border: 1px solid var(--border);
    padding: 10px;
    flex-direction: column;
    display: none;
    min-width: 150px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    border-radius: 6px;
  }

  .nav a {
    padding: 8px 12px;
    font-size: 15px;
  }

  .nav.open {
    display: flex;
  }

  .menu {
    display: flex;
  }


  /* Education logo on mobile */
  .sidebar > section > div[style*="display: flex"] img {
    width: 70px !important;
  }

  /* Footer spacing */
  .footer {
    margin-top: 40px;
    padding: 16px;
    font-size: 0.85em;
  }
}

/* Small phones */
@media (max-width: 400px) {
  main {
    padding: 16px 12px 50px;
  }

  .profile-image {
    max-width: 130px;
  }

  .profile-text h1 {
    font-size: 1.3em;
  }

  h2 {
    font-size: 1.2em;
  }
}

/* Safe area for notched phones */
@supports (padding: env(safe-area-inset-bottom)) {
  .footer {
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }
}

/* Respect reduced-motion preference */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .content-area > section {
    opacity: 1;
    transform: none;
  }
}

/* ── Publications Image Interaction ── */
.pub-image-container {
  position: relative;
  flex-shrink: 0;
  width: 300px;
}

.pub-image {
  display: block;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  cursor: zoom-in;
}

.pub-image:hover {
  transform: translateY(-5px);
  box-shadow: 0 10px 20px rgba(0,0,0,0.1);
}

.pub-image-hint {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%) translateY(0);
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  opacity: 0;
  transition: opacity 0.3s ease, transform 0.3s ease;
  pointer-events: none;
  white-space: nowrap;
  font-family: 'Lato', sans-serif;
  z-index: 5;
}

.pub-image:hover + .pub-image-hint {
  opacity: 1;
  transform: translateX(-50%) translateY(-5px);
}

/* ── Lightbox ── */
.lightbox {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  background-color: rgba(0,0,0,0.85);
  backdrop-filter: blur(5px);
  align-items: center;
  justify-content: center;
  flex-direction: column;
}

.lightbox-content {
  margin: auto;
  display: block;
  max-width: 90%;
  max-height: 80vh;
  border-radius: 8px;
  animation: zoomIn 0.3s ease;
  object-fit: contain;
}

@keyframes zoomIn {
  from {transform: scale(0.9); opacity: 0;}
  to {transform: scale(1); opacity: 1;}
}

.lightbox-close {
  position: absolute;
  top: 20px;
  right: 40px;
  color: #fff;
  font-size: 40px;
  font-weight: bold;
  cursor: pointer;
  transition: color 0.2s;
  z-index: 1001;
}

.lightbox-close:hover,
.lightbox-close:focus {
  color: #ccc;
  text-decoration: none;
  cursor: pointer;
}

#lightbox-caption {
  margin: 15px auto 0;
  display: block;
  width: 80%;
  max-width: 700px;
  text-align: center;
  color: #eee;
  font-family: 'Lato', sans-serif;
  font-size: 1.1em;
  animation: zoomIn 0.3s ease;
}
