:root {
  --bg: #0e0e11;
  --surface: #161619;
  --surface-hover: #1e1e23;
  --border: #27272a;
  --text: #fafafa;
  --text-secondary: #a1a1aa;
  --text-muted: #71717a;
  --accent: #3b82f6;
  --accent-dim: rgba(59, 130, 246, 0.12);
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  --max-width: 1000px;
  --nav-height: 64px;
}

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

html {
  scroll-behavior: smooth;
  scroll-padding-top: var(--nav-height);
}

/* ── Page load fade-in ────────────────────────────── */

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  opacity: 0;
  transition: opacity 0.6s ease;
}

body.loaded {
  opacity: 1;
}

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

a:hover {
  color: #60a5fa;
}

.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 1.5rem;
}

/* ── Nav ──────────────────────────────────────────── */

.nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  z-index: 1000;
  background: rgba(14, 14, 17, 0.8);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid transparent;
  transition: border-color 0.3s;
}

.nav.scrolled {
  border-bottom-color: var(--border);
}

.nav-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 1.5rem;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.nav-logo {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 1.25rem;
  color: var(--text);
  letter-spacing: -0.02em;
}

.nav-logo:hover {
  color: var(--accent);
}

.nav-links {
  list-style: none;
  display: flex;
  gap: 2rem;
}

.nav-links a {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  transition: color 0.2s;
  position: relative;
}

.nav-links a::after {
  content: '';
  position: absolute;
  bottom: -4px;
  left: 0;
  width: 100%;
  height: 2px;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: right;
  transition: transform 0.3s ease;
}

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

.nav-links a.active {
  color: var(--accent);
}

.nav-links a.active::after {
  transform: scaleX(1);
  transform-origin: left;
}

.nav-toggle {
  display: none;
  flex-direction: column;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
}

.nav-toggle span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--text-secondary);
  border-radius: 1px;
  transition: all 0.3s;
}

/* ── Hero ─────────────────────────────────────────── */

.hero {
  position: relative;
  min-height: 100vh;
  display: flex;
  align-items: center;
  padding-top: var(--nav-height);
  overflow: hidden;
}

/* ── Cursor glow ──────────────────────────────────── */

#cursor-glow {
  position: fixed;
  width: 500px;
  height: 500px;
  border-radius: 50%;
  pointer-events: none;
  z-index: 1;
  background: radial-gradient(circle, rgba(59, 130, 246, 0.12) 0%, rgba(59, 130, 246, 0.04) 40%, transparent 70%);
  transform: translate(-50%, -50%);
  opacity: 0;
  transition: opacity 0.3s;
}

body.loaded #cursor-glow {
  opacity: 1;
}

/* ── Scroll progress bar ──────────────────────────── */

#scroll-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 2px;
  background: var(--accent);
  z-index: 1001;
  width: 0%;
  transition: none;
}

/* ── Back to top ──────────────────────────────────── */

#back-to-top {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 100;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 0.3s, transform 0.3s, border-color 0.2s, color 0.2s, background 0.2s;
}

#back-to-top.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

#back-to-top:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
}

#particles {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
}

.hero-glow {
  position: absolute;
  top: 20%;
  left: 50%;
  width: 600px;
  height: 600px;
  transform: translate(-50%, -30%);
  background: radial-gradient(circle, rgba(59, 130, 246, 0.07) 0%, transparent 70%);
  pointer-events: none;
}

.hero-img,
.pub-bg {
  border: none;
  outline: none;
  display: block;
}

.hero-img {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 50%;
  max-width: 650px;
  opacity: 0.4;
  pointer-events: none;
  z-index: 0;
  mask-image: radial-gradient(ellipse at 70% 50%, black 40%, transparent 80%);
  -webkit-mask-image: radial-gradient(ellipse at 70% 50%, black 40%, transparent 80%);
}

.hero .container {
  position: relative;
  z-index: 1;
}

/* Hero staggered clip animation */
@keyframes heroReveal {
  from {
    clip-path: inset(100% 0 0 0);
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    clip-path: inset(0 0 0 0);
    opacity: 1;
    transform: translateY(0);
  }
}

.hero-anim {
  opacity: 0;
  animation: heroReveal 0.7s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  animation-delay: calc(0.3s + var(--i) * 0.15s);
}

.hero-greeting {
  font-family: var(--font-mono);
  font-size: 1rem;
  color: var(--accent);
  margin-bottom: 1rem;
}

.hero-name {
  font-size: clamp(2.5rem, 7vw, 4.5rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.1;
  margin-bottom: 0.75rem;
  background: linear-gradient(135deg, var(--text) 0%, var(--text-secondary) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero-title {
  font-size: clamp(1.1rem, 3vw, 1.5rem);
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 1.25rem;
}

.hero-bio {
  font-size: 1.1rem;
  color: var(--text-muted);
  max-width: 540px;
  margin-bottom: 2rem;
}

.hero-links {
  display: flex;
  gap: 1.25rem;
}

.hero-links a {
  color: var(--text-muted);
  transition: color 0.2s, transform 0.2s;
}

.hero-links a:hover {
  color: var(--text);
  transform: translateY(-2px);
}

/* ── Sections ─────────────────────────────────────── */

.section {
  padding: 7rem 0;
}

.section-alt {
  background: var(--surface);
}

.section-label {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 2.5rem;
  letter-spacing: -0.02em;
}

.section-number {
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 500;
  color: var(--accent);
  margin-right: 0.75rem;
}

.section-subtitle {
  color: var(--text-secondary);
  margin-top: -1.5rem;
  margin-bottom: 2.5rem;
  font-size: 0.95rem;
}

/* ── About ────────────────────────────────────────── */

.section-about {
  position: relative;
  overflow: hidden;
}

.section-about .container {
  position: relative;
  z-index: 1;
}

.about-bg {
  position: absolute;
  left: -5%;
  bottom: 0;
  width: 40%;
  max-width: 480px;
  opacity: 0.3;
  pointer-events: none;
  border: none;
  outline: none;
  display: block;
  z-index: 0;
  mask-image: radial-gradient(ellipse at 40% 60%, black 35%, transparent 75%);
  -webkit-mask-image: radial-gradient(ellipse at 40% 60%, black 35%, transparent 75%);
}

.about-content {
  max-width: 680px;
  margin-bottom: 3rem;
}

.about-content p {
  color: var(--text-secondary);
  margin-bottom: 1rem;
  font-size: 1rem;
}

.about-content strong {
  color: var(--text);
  font-weight: 600;
}

.skills-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1.5rem;
}

.skill-group h3 {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.75rem;
}

.skill-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.skill-pill {
  font-size: 0.8rem;
  color: var(--text-secondary);
  padding: 0.3rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 100px;
  background: transparent;
  transition: border-color 0.3s, color 0.3s, background 0.3s, transform 0.3s, opacity 0.5s;
  opacity: 0;
  transform: translateY(10px);
}

.skill-group.visible .skill-pill {
  opacity: 1;
  transform: translateY(0);
}

.skill-group.visible .skill-pill:nth-child(1) { transition-delay: 0.05s; }
.skill-group.visible .skill-pill:nth-child(2) { transition-delay: 0.1s; }
.skill-group.visible .skill-pill:nth-child(3) { transition-delay: 0.15s; }
.skill-group.visible .skill-pill:nth-child(4) { transition-delay: 0.2s; }

.skill-pill:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
  transform: translateY(-2px);
}

/* ── Experience background ────────────────────────── */

.section-exp {
  position: relative;
  overflow: hidden;
}

.section-exp .container {
  position: relative;
  z-index: 1;
}

.exp-bg {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 45%;
  max-width: 550px;
  opacity: 0.25;
  pointer-events: none;
  border: none;
  outline: none;
  display: block;
  z-index: 0;
  mask-image: radial-gradient(ellipse at 60% 70%, black 35%, transparent 75%);
  -webkit-mask-image: radial-gradient(ellipse at 60% 70%, black 35%, transparent 75%);
}

/* ── Timeline (Experience) ────────────────────────── */

.timeline {
  position: relative;
  padding-left: 2rem;
}

.timeline::before {
  content: '';
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 1px;
  background: var(--border);
  transform-origin: top;
  transform: scaleY(0);
  transition: transform 1.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.timeline.drawn::before {
  transform: scaleY(1);
}

.timeline-item {
  position: relative;
  padding-bottom: 2.5rem;
}

.timeline-item:last-child {
  padding-bottom: 0;
}

.timeline-item::before {
  content: '';
  position: absolute;
  left: -2rem;
  top: 8px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--border);
  border: 2px solid var(--surface);
  transform: translateX(-4px) scale(0);
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.timeline-item.visible::before {
  transform: translateX(-4px) scale(1);
}

.timeline-item:first-child::before {
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

@keyframes dotPulse {
  0%, 100% { box-shadow: 0 0 0 3px var(--accent-dim); }
  50% { box-shadow: 0 0 0 8px transparent; }
}

.timeline-item:first-child.visible::before {
  animation: dotPulse 2s ease-out 0.5s;
}

.timeline-date {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.timeline-body h3 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 0.2rem;
}

.timeline-company {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

.timeline-desc {
  font-size: 0.9rem;
  color: var(--text-muted);
  max-width: 600px;
}

/* ── Publications ─────────────────────────────────── */

.section-pub {
  position: relative;
  overflow: hidden;
}

.section-pub .container {
  position: relative;
  z-index: 1;
}

.pub-bg {
  position: absolute;
  right: 5%;
  bottom: 0;
  width: 40%;
  max-width: 500px;
  opacity: 0.3;
  pointer-events: none;
  z-index: 0;
  mask-image: radial-gradient(ellipse at 60% 60%, black 35%, transparent 75%);
  -webkit-mask-image: radial-gradient(ellipse at 60% 60%, black 35%, transparent 75%);
}

.pub-list {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.pub-item {
  display: flex;
  gap: 2rem;
  padding: 1.5rem 1rem;
  border-bottom: 1px solid var(--border);
  border-radius: 8px;
  transition: transform 0.25s ease, box-shadow 0.25s ease, background 0.25s ease;
}

.pub-item:last-child {
  border-bottom: none;
}

.pub-item:hover {
  transform: translateY(-2px);
  background: rgba(59, 130, 246, 0.03);
  box-shadow: 0 4px 20px rgba(59, 130, 246, 0.08);
}

.pub-year {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--text-muted);
  flex-shrink: 0;
  padding-top: 0.15rem;
}

.pub-body h3 {
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.5;
  margin-bottom: 0.3rem;
}

.pub-body h3 a {
  color: var(--text);
  text-decoration: none;
  transition: color 0.2s;
}

.pub-body h3 a::after {
  content: ' \2197';
  font-size: 0.7em;
  opacity: 0;
  transition: opacity 0.2s;
}

.pub-item:hover .pub-body h3 a {
  color: var(--accent);
}

.pub-item:hover .pub-body h3 a::after {
  opacity: 1;
}

.pub-authors {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 0.2rem;
}

.pub-venue {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--accent);
}

/* ── Projects ─────────────────────────────────────── */

.section-projects {
  position: relative;
  overflow: hidden;
}

.section-projects .container {
  position: relative;
  z-index: 1;
}

.projects-bg {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 30%;
  max-width: 380px;
  opacity: 0.3;
  pointer-events: none;
  border: none;
  outline: none;
  display: block;
  z-index: 0;
  mask-image: radial-gradient(ellipse at 40% 50%, black 35%, transparent 75%);
  -webkit-mask-image: radial-gradient(ellipse at 40% 50%, black 35%, transparent 75%);
}

.projects-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.25rem;
}

.project-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  color: var(--text);
  position: relative;
  overflow: hidden;
  transition: border-color 0.3s, box-shadow 0.3s;
  transform-style: preserve-3d;
  will-change: transform;
}

.project-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(
    circle at var(--mx, 50%) var(--my, 50%),
    rgba(59, 130, 246, 0.08) 0%,
    transparent 60%
  );
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}

.project-card:hover {
  border-color: rgba(59, 130, 246, 0.3);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
  color: var(--text);
}

.project-card:hover::before {
  opacity: 1;
}

.project-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  color: var(--text-muted);
}

.project-lang {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
}

.project-card h3 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.project-card p {
  font-size: 0.875rem;
  color: var(--text-secondary);
  line-height: 1.6;
  flex-grow: 1;
}

/* ── Contact ──────────────────────────────────────── */

.section-contact {
  position: relative;
  overflow: hidden;
}

.contact-bg {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  height: 90%;
  opacity: 0.12;
  pointer-events: none;
  border: none;
  outline: none;
  display: block;
  z-index: 0;
  mask-image: radial-gradient(ellipse at 50% 50%, black 30%, transparent 70%);
  -webkit-mask-image: radial-gradient(ellipse at 50% 50%, black 30%, transparent 70%);
}

.contact-container {
  text-align: center;
  max-width: 540px;
  position: relative;
  z-index: 1;
}

.contact-text {
  color: var(--text-secondary);
  margin-bottom: 2rem;
  font-size: 1.05rem;
}

.contact-btn {
  display: inline-block;
  padding: 0.85rem 2.5rem;
  border: 1px solid var(--accent);
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--accent);
  transition: background 0.2s, color 0.2s, transform 0.2s, box-shadow 0.2s;
}

.contact-btn:hover {
  background: var(--accent-dim);
  color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 4px 20px rgba(59, 130, 246, 0.15);
}

/* ── Footer ───────────────────────────────────────── */

.footer {
  padding: 2rem 0;
  text-align: center;
  border-top: 1px solid var(--border);
}

.footer p {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ── Scroll Reveal ────────────────────────────────── */

.reveal {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.6s ease, transform 0.6s ease;
}

.reveal.visible {
  opacity: 1;
  transform: translateY(0);
}

.reveal:nth-child(2) { transition-delay: 0.1s; }
.reveal:nth-child(3) { transition-delay: 0.2s; }
.reveal:nth-child(4) { transition-delay: 0.3s; }
.reveal:nth-child(5) { transition-delay: 0.4s; }

/* ── Responsive ───────────────────────────────────── */

/* ── Touch devices: disable mouse-only effects ────── */

@media (hover: none) {
  #cursor-glow {
    display: none;
  }

  .project-card {
    transform: none !important;
  }

  .project-card::before {
    display: none;
  }
}

@media (max-width: 768px) {
  .nav-toggle {
    display: flex;
  }

  .nav-links {
    position: fixed;
    top: var(--nav-height);
    left: 0;
    right: 0;
    background: rgba(14, 14, 17, 0.97);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    flex-direction: column;
    align-items: center;
    padding: 2rem 0;
    gap: 1.5rem;
    border-bottom: 1px solid var(--border);
    transform: translateY(-100%);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.3s, opacity 0.3s;
  }

  .nav-links.open {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
  }

  .nav-links a {
    font-size: 1rem;
  }

  .nav-toggle.active span:nth-child(1) {
    transform: rotate(45deg) translate(5px, 5px);
  }
  .nav-toggle.active span:nth-child(2) {
    opacity: 0;
  }
  .nav-toggle.active span:nth-child(3) {
    transform: rotate(-45deg) translate(5px, -5px);
  }

  .hero {
    min-height: 85vh;
  }

  .hero-img {
    opacity: 0.08;
    width: 80%;
    right: -20%;
  }

  .hero-links {
    gap: 1.5rem;
  }

  .hero-links a {
    padding: 0.5rem;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .section {
    padding: 4rem 0;
  }

  .skills-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .projects-grid {
    grid-template-columns: 1fr;
  }

  .pub-item {
    flex-direction: column;
    gap: 0.25rem;
    padding: 1.25rem 0.5rem;
  }

  .timeline {
    padding-left: 1.5rem;
  }

  .timeline-item::before {
    left: -1.5rem;
  }

  .about-bg, .exp-bg, .pub-bg, .projects-bg, .contact-bg {
    opacity: 0.1;
  }

  .contact-btn {
    padding: 1rem 3rem;
    font-size: 1rem;
  }

  #back-to-top {
    bottom: 1.25rem;
    right: 1.25rem;
  }
}

@media (max-width: 480px) {
  .hero-name {
    font-size: 2.2rem;
  }

  .hero-bio {
    font-size: 1rem;
  }

  .skills-grid {
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
  }

  .section-label {
    font-size: 1.4rem;
  }
}
