:root {
  --bg: #ffffff;
  --alt: #f8fafc;
  --hero-bg: #060a13;
  --ink: #0f172a;
  --muted: #64748b;
  --accent: #3b82f6;
  --accent-dim: rgba(59, 130, 246, 0.08);
  --accent-border: rgba(59, 130, 246, 0.18);
  --line: #e2e8f0;
  --mono: 'IBM Plex Mono', 'Courier New', monospace;
  --serif: 'IBM Plex Serif', Georgia, serif;
  --sans: 'Inter', system-ui, -apple-system, sans-serif;
}

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

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

h1, h2, h3, p { margin: 0; }

ul { margin: 0; padding-left: 1.2em; }

li { margin-bottom: 3px; }


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

.nav {
  position: fixed;
  z-index: 100;
  inset: 0 0 auto 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 0 clamp(20px, 5vw, 64px);
  height: 60px;
  transition: background 0.3s, box-shadow 0.3s;
}

.nav-logo {
  font-family: var(--mono);
  font-weight: 600;
  font-size: 0.88rem;
  letter-spacing: 0.1em;
  color: rgba(248, 250, 252, 0.8);
  transition: color 0.3s;
}

.nav nav {
  display: flex;
  gap: clamp(16px, 3vw, 36px);
}

.nav nav a {
  font-size: 0.875rem;
  font-weight: 500;
  color: rgba(248, 250, 252, 0.55);
  transition: color 0.2s;
}

.nav nav a:hover { color: rgba(248, 250, 252, 1); }

.nav.scrolled {
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 1px 0 var(--line);
}

.nav.scrolled .nav-logo { color: var(--ink); }

.nav.scrolled nav a { color: var(--muted); }

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


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

.hero {
  position: relative;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--hero-bg);
  overflow: hidden;
}

#wave-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.hero-inner {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 80px 24px 64px;
  max-width: 900px;
}

.hero-label {
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: rgba(148, 163, 184, 0.45);
  margin-bottom: 28px;
}

.hero-inner h1 {
  font-family: var(--serif);
  font-weight: 300;
  font-size: clamp(5rem, 13vw, 11rem);
  line-height: 0.88;
  color: #f1f5f9;
  letter-spacing: -0.02em;
  margin-bottom: 36px;
}

.hero-sub {
  font-size: clamp(0.9rem, 1.8vw, 1.15rem);
  font-weight: 400;
  color: rgba(148, 163, 184, 0.75);
  letter-spacing: 0.07em;
  margin-bottom: 10px;
}

.hero-meta {
  font-family: var(--mono);
  font-size: 0.73rem;
  color: rgba(96, 165, 250, 0.6);
  letter-spacing: 0.06em;
  margin-bottom: 44px;
}

.hero-links {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

.pill-primary,
.pill-ghost {
  display: inline-flex;
  align-items: center;
  height: 44px;
  padding: 0 22px;
  border-radius: 999px;
  font-size: 0.84rem;
  font-weight: 600;
  transition: opacity 0.2s, transform 0.2s;
}

.pill-primary {
  background: #f1f5f9;
  color: var(--ink);
}

.pill-ghost {
  border: 1px solid rgba(248, 250, 252, 0.2);
  color: rgba(248, 250, 252, 0.8);
}

.pill-primary:hover,
.pill-ghost:hover {
  opacity: 0.8;
  transform: translateY(-1px);
}



/* ── Hero physics equations ───────────────────── */

.hero-physics {
  position: absolute;
  inset: 0;
  pointer-events: none;
  user-select: none;
  overflow: hidden;
}

/* Outer element: positioned by JS, handles the floating drift */
.hp {
  position: absolute;
  --dx: 0px;
  --dy: 0px;
  --dr: 0deg;
  animation: hp-drift var(--dur, 20s) ease-in-out var(--delay, 0s) infinite;
  will-change: transform;
}

/* Inner element: holds the KaTeX render or diagram, handles hover grow + glow */
.hp-inner {
  display: inline-block;
  transform-origin: center center;
  font-size: var(--size, 1rem);
  color: rgba(96, 165, 250, var(--op, 0.2));
  text-shadow: 0 0 26px rgba(96, 165, 250, calc(var(--op, 0.2) * 0.6));
  pointer-events: auto;
  cursor: default;
  transition: color 0.35s ease, transform 0.35s cubic-bezier(0.2, 0.7, 0.2, 1.4), text-shadow 0.35s ease, filter 0.35s ease;
}

/* KaTeX inherits text colour so the dim/bright states carry through */
.hp-inner .katex { color: inherit; font-size: inherit; }

/* Diagrams: stroke follows colour, soft glow via drop-shadow */
.hp-diagram {
  line-height: 0;
  filter: drop-shadow(0 0 14px rgba(96, 165, 250, calc(var(--op, 0.2) * 0.7)));
}

.hp-inner:hover {
  color: rgba(191, 219, 254, 0.95);
  transform: scale(1.28);
  text-shadow: 0 0 16px rgba(96, 165, 250, 0.8), 0 0 44px rgba(96, 165, 250, 0.4);
}

.hp-diagram:hover {
  filter: drop-shadow(0 0 16px rgba(96, 165, 250, 0.75));
}

/* Wandering loop — passes through several offsets so each item roams the hero */
@keyframes hp-drift {
  0%   { transform: translate(0, 0) rotate(0deg); }
  20%  { transform: translate(var(--dx), var(--dy)) rotate(var(--dr)); }
  40%  { transform: translate(calc(var(--dx) * -0.45), calc(var(--dy) * 0.85)) rotate(calc(var(--dr) * -0.7)); }
  60%  { transform: translate(calc(var(--dx) * 0.75), calc(var(--dy) * -0.6)) rotate(calc(var(--dr) * 0.5)); }
  80%  { transform: translate(calc(var(--dx) * -0.8), calc(var(--dy) * -0.25)) rotate(calc(var(--dr) * -0.4)); }
  100% { transform: translate(0, 0) rotate(0deg); }
}

@media (prefers-reduced-motion: reduce) {
  .hp { animation: none; }
}

/* Thin the floating layer on smaller screens to avoid clutter */
@media (max-width: 900px) {
  .hp:nth-child(n+11) { display: none; }
}

@media (max-width: 600px) {
  .hp:nth-child(n+7) { display: none; }
}


/* ── Feynman diagram (about section) ──────────── */

#about {
  position: relative;
  overflow: hidden;
}

.about-feynman {
  position: absolute;
  top: 50%;
  right: 4%;
  transform: translateY(-50%);
  width: min(42%, 340px);
  pointer-events: none;
  user-select: none;
  color: var(--ink);
  opacity: 0.06;
}

.about-feynman svg { width: 100%; height: auto; }

.about-feynman .fd {
  stroke-dasharray: 400;
  stroke-dashoffset: 400;
  transition: stroke-dashoffset 1.2s ease;
}

.about-feynman .fv,
.about-feynman .fl {
  opacity: 0;
  transition: opacity 0.4s ease 1s;
}

.about-feynman.drawn .fd   { stroke-dashoffset: 0; }
.about-feynman.drawn .fv,
.about-feynman.drawn .fl   { opacity: 1; }

.about-feynman .fd:nth-child(2) { transition-delay: 0.15s; }
.about-feynman .fd:nth-child(3) { transition-delay: 0.35s; }
.about-feynman .fd:nth-child(4) { transition-delay: 0.6s;  }
.about-feynman .fd:nth-child(5) { transition-delay: 0.75s; }

@media (max-width: 900px) {
  .about-feynman { display: none; }
}


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

.sec {
  padding: clamp(64px, 9vw, 120px) clamp(20px, 5vw, 64px);
}

.sec-alt { background: var(--alt); }

.wrap {
  max-width: 1080px;
  margin: 0 auto;
}

.sec-label {
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 44px;
}


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

.about-grid {
  display: grid;
  grid-template-columns: minmax(220px, 0.82fr) minmax(0, 1.18fr);
  gap: clamp(28px, 5vw, 64px);
  align-items: center;
}

.about-grid h2 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(1.8rem, 3.2vw, 2.7rem);
  line-height: 1.18;
  color: var(--ink);
  margin-bottom: 22px;
}

.about-text p {
  color: var(--muted);
  font-size: 1.02rem;
  line-height: 1.75;
}

.about-text p + p { margin-top: 16px; }

/* Duotone portrait */
.about-portrait {
  position: relative;
  isolation: isolate;          /* keep the blend confined to the photo */
  overflow: hidden;
  margin: 0;
  aspect-ratio: 4 / 5;
  border-radius: 14px;
  border: 1px solid var(--accent-border);
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.16);
  background: #0a1733;          /* fallback / placeholder before the image loads */
}

.about-portrait img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: grayscale(100%) contrast(1.08) brightness(1.02);
  transition: filter 0.5s ease, transform 0.6s ease;
}

/* shadows → deep navy */
.about-portrait::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  background: #0a1a44;
  mix-blend-mode: lighten;
  pointer-events: none;
  transition: opacity 0.5s ease;
}

/* highlights → pale blue */
.about-portrait::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  background: #bcd4ff;
  mix-blend-mode: darken;
  pointer-events: none;
  transition: opacity 0.5s ease;
}

/* lift to full colour on hover */
.about-portrait:hover img {
  filter: grayscale(0%) contrast(1) brightness(1);
  transform: scale(1.03);
}

.about-portrait:hover::before,
.about-portrait:hover::after {
  opacity: 0;
}


/* ── Timeline ─────────────────────────────────── */

.tl-item {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 0 40px;
  padding: 32px 0;
  border-top: 1px solid var(--line);
}

.tl-item:last-child { border-bottom: 1px solid var(--line); }

.tl-meta {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding-top: 3px;
}

.tl-date {
  font-family: var(--mono);
  font-size: 0.73rem;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.04em;
}

.tl-place {
  font-family: var(--mono);
  font-size: 0.68rem;
  color: var(--muted);
  letter-spacing: 0.04em;
}

.tl-body h3 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 1.22rem;
  color: var(--ink);
  margin-bottom: 4px;
}

.tl-role {
  font-size: 0.875rem;
  font-style: italic;
  color: var(--muted);
  margin-bottom: 12px;
}

.tl-desc {
  font-size: 0.9rem;
  color: var(--muted);
  font-style: italic;
  margin-bottom: 10px;
}

.tl-link {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.tl-body ul {
  font-size: 0.9rem;
  color: #334155;
  line-height: 1.65;
}


/* ── Skills ───────────────────────────────────── */

.skills-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: 4px;
  overflow: hidden;
}

.skill-card {
  background: var(--bg);
  padding: clamp(20px, 3vw, 32px);
}

.sec-alt .skill-card { background: var(--bg); }

.skill-cat {
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 14px;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tags span {
  font-size: 0.79rem;
  font-weight: 500;
  padding: 4px 10px;
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid var(--accent-border);
  border-radius: 4px;
}


/* ── Hobbies ──────────────────────────────────── */

.sec-dark {
  background: var(--ink);
}

.sec-dark .sec-label {
  color: rgba(148, 163, 184, 0.38);
}

.hobbies-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 4px;
  overflow: hidden;
}

.hobby-card {
  background: var(--ink);
  padding: 36px 16px 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  transition: background 0.25s;
  cursor: default;
}

.hobby-card:hover {
  background: rgba(255, 255, 255, 0.04);
}

.hobby-svg {
  width: 64px;
  height: 52px;
  color: #60a5fa;
  stroke: #60a5fa;
  overflow: visible;
  filter: drop-shadow(0 0 7px rgba(96, 165, 250, 0.4));
}

.hobby-name {
  font-family: var(--mono);
  font-size: 0.6rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(148, 163, 184, 0.45);
}


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

.contact-wrap { max-width: 680px; }

.contact-h {
  font-family: var(--serif);
  font-weight: 300;
  font-size: clamp(3rem, 7vw, 5.5rem);
  line-height: 1;
  color: var(--ink);
  margin-bottom: 16px;
}

.contact-sub {
  color: var(--muted);
  font-size: 1.02rem;
  margin-bottom: 48px;
}

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

.contact-row {
  display: flex;
  align-items: baseline;
  gap: 24px;
  padding: 18px 0;
  border-top: 1px solid var(--line);
  transition: gap 0.2s;
}

.contact-list li:last-child .contact-row {
  border-bottom: 1px solid var(--line);
}

.contact-row:hover .contact-val { color: var(--accent); }

.contact-key {
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  min-width: 72px;
  flex-shrink: 0;
}

.contact-val {
  font-size: 1rem;
  font-weight: 500;
  color: var(--ink);
  transition: color 0.2s;
}


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

.footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 24px clamp(20px, 5vw, 64px);
  border-top: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--muted);
}

.footer-eq { color: rgba(148, 163, 184, 0.45); }


/* ── Reveal animation ─────────────────────────── */

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

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

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


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

@media (max-width: 900px) {
  .about-grid { grid-template-columns: 1fr; }

  .about-portrait {
    max-width: 280px;
    aspect-ratio: 1 / 1;
  }

  .tl-item {
    grid-template-columns: 120px 1fr;
    gap: 0 24px;
  }

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

  .hobbies-grid { grid-template-columns: repeat(4, 1fr); }
}

@media (max-width: 640px) {
  .tl-item {
    grid-template-columns: 1fr;
    gap: 6px 0;
  }

  .tl-meta {
    flex-direction: row;
    gap: 14px;
  }

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

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

  .hero-inner h1 { font-size: clamp(3.6rem, 20vw, 5.5rem); }

  .footer { flex-direction: column; gap: 8px; text-align: center; }
}
