:root {
  --gradient-1: linear-gradient(
    90deg,
    #ff6d1b,
    #ffee55,
    #5bff89,
    #4d8aff,
    #6b5fff,
    #ff64f9,
    #ff6565
  );
  --bg-primary: #000;
  --bg-secondary: #0a0a0a;
  --bg-tertiary: #141414;
  --text-primary: #ffffff;
  --text-secondary: #a0a0a0;
  --text-tertiary: #707070;
  --text-bio: #b0b0b0;
  --border-subtle: #1a1a1a;
  --border-hover: #2a2a2a;
  --accent-blue: #4d8aff;
  --accent-green: #5bff89;
  --accent-yellow: #ffee55;
  --accent-purple: #6b5fff;
}

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

body {
  font-family: "Space Grotesk", -apple-system, BlinkMacSystemFont, sans-serif;
  font-weight: 400;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
}

.container {
  max-width: 1000px;
  margin: 0 auto;
  padding: 24px;
}

/*
 * Hero: the photo has no frame; it dissolves into the black page like a
 * speaker under a stage light. The oversized name overlaps the photo's
 * faded lower-left edge.
 */
.hero {
  --name-size: clamp(3.5rem, 11vw, 8rem);
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  align-items: end;
  margin-bottom: 24px;
}

.hero-copy {
  grid-column: 1 / 10;
  grid-row: 1;
  position: relative;
  z-index: 1;
  /* lift the text off the photo's bottom edge */
  padding-bottom: 40px;
}

h1 {
  font-size: var(--name-size);
  font-weight: 500;
  line-height: 0.84;
  letter-spacing: -0.055em;
  /* optical: pull the A's side bearing flush with the text below */
  margin-left: -0.04em;
  margin-bottom: 36px;
  color: var(--text-primary);
}

@keyframes gradient-shift {
  0%,
  100% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
}

.hero-bio {
  font-size: 1.25rem;
  line-height: 1.6;
  color: var(--text-bio);
  text-wrap: pretty;
}

/*
 * Half the width keeps the box close to the portrait photo's own shape,
 * so object-fit: cover shows nearly the whole frame instead of zooming in.
 */
.hero-photo {
  grid-column: 7 / -1;
  grid-row: 1;
  position: relative;
  overflow: hidden;
}

.hero-photo img {
  display: block;
  width: 100%;
  height: min(540px, 70svh);
  object-fit: cover;
  object-position: 50% 10%;
}

/*
 * Fade every edge into the (pure black) page background: strongest on
 * the left, where the name and bio sit on top of the photo. The top and
 * bottom fades have fixed lengths so that a shorter hero crops the photo
 * rather than dimming more of it.
 */
.hero-photo::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(
      to right,
      #000 0%,
      rgb(0 0 0 / 0.85) 20%,
      rgb(0 0 0 / 0.4) 38%,
      transparent 55%
    ),
    linear-gradient(to top, #000 0, rgb(0 0 0 / 0.75) 80px, transparent 200px),
    linear-gradient(to left, #000 0%, transparent 25%),
    linear-gradient(to bottom, #000 0, transparent 72px);
}

/* Links: plain, flat buttons in a single row that wraps on narrow screens */
.hero-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 28px;
}

.hero-links a {
  padding: 8px 14px;
  border-radius: 8px;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
  line-height: 1.3;
  text-decoration: none;
  transition:
    color 0.2s ease,
    background-color 0.2s ease;
}

.hero-links a:hover {
  color: var(--text-primary);
  background: #1f1f1f;
}

.hero-links a:focus-visible {
  outline: 2px solid var(--accent-blue);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: no-preference) {
  .hero-photo img {
    animation: hero-photo-in 1.6s cubic-bezier(0.16, 1, 0.3, 1) both;
  }

  .hero-copy > * {
    animation: hero-rise 1s cubic-bezier(0.16, 1, 0.3, 1) both;
  }

  .hero-copy > :nth-child(2) {
    animation-delay: 0.1s;
  }

  .hero-copy > :nth-child(3) {
    animation-delay: 0.2s;
  }
}

@keyframes hero-photo-in {
  from {
    opacity: 0;
    transform: scale(1.06);
  }
}

@keyframes hero-rise {
  from {
    opacity: 0;
    transform: translateY(0.75rem);
  }
}

/* Intro */
.intro {
  margin-bottom: 48px;
}

.math-equation {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 24px;
  margin: 20px 0;
  font-size: 1.1rem;
  overflow-x: auto;
}

.math-equation .MathJax {
  color: var(--text-primary) !important;
}

.equation-explanation {
  font-size: 1.1rem;
  color: var(--text-secondary);
  margin-top: 16px;
}

/* Projects Section */
.projects-section {
  margin-top: 36px;
}

.section-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: nowrap;
}

h2 {
  font-size: clamp(1.5rem, 4vw, 2rem);
  font-weight: 600;
}

.update-badge {
  background: rgba(77, 138, 255, 0.1);
  color: var(--accent-blue);
  font-size: 0.75rem;
  padding: 4px 12px;
  border-radius: 20px;
  font-weight: 500;
  border: 1px solid rgba(77, 138, 255, 0.2);
  white-space: nowrap;
}

.section-description {
  font-size: 1.1rem;
  color: var(--text-bio);
  margin-bottom: 32px;
}

/* Project Cards Grid */
.projects-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr));
  gap: 24px;
}

.project-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  padding: 24px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 480px;
}

.project-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--gradient-1);
  background-size: 200%;
  animation: gradient-shift 3s ease infinite;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.project-card:hover {
  transform: translateY(-4px);
  border-color: var(--border-hover);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
}

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

/* Project Image */
.project-image-container {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 20px;
  position: relative;
}

.project-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  backface-visibility: hidden;
  transform: translateZ(0);
}

.project-card:hover .project-image {
  transform: scale(1.02);
}

.project-image-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(
    135deg,
    rgba(77, 138, 255, 0.03) 0%,
    rgba(107, 95, 255, 0.03) 25%,
    rgba(91, 255, 137, 0.03) 50%,
    rgba(255, 238, 85, 0.03) 75%,
    rgba(255, 109, 27, 0.03) 100%
  );
  background-size: 400% 400%;
  animation: gradient-shift 8s ease infinite;
  position: relative;
}

.project-image-placeholder::before {
  content: "\221E";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 48px;
  color: var(--text-tertiary);
  opacity: 0.2;
  font-weight: 300;
}

/* Card Content Sections */
.card-top {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.card-bottom {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.project-title {
  font-size: 1.4rem;
  font-weight: 600;
  margin-bottom: 10px;
  color: var(--text-primary);
  line-height: 1.3;
}

.project-description {
  color: var(--text-secondary);
  margin-bottom: 14px;
  font-size: 0.95rem;
  line-height: 1.6;
}

.project-intuition {
  background: var(--bg-tertiary);
  border-left: 3px solid var(--accent-purple);
  padding: 12px 14px;
  border-radius: 8px;
  margin-bottom: 20px;
  font-size: 0.9rem;
  color: var(--text-tertiary);
  line-height: 1.5;
}

.project-section {
  margin: 0;
}

.project-section h4 {
  color: var(--accent-green);
  font-size: 0.8rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 10px;
}

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

.roadmap-list li {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 6px;
  padding-left: 20px;
  position: relative;
  line-height: 1.4;
}

.roadmap-list li:last-child {
  margin-bottom: 0;
}

.roadmap-list li::before {
  content: "\2192";
  position: absolute;
  left: 0;
  color: var(--accent-blue);
  font-weight: 600;
}

.progress-section h4 {
  color: var(--accent-yellow);
}

.progress-status {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.project-links {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.project-link {
  display: inline-flex;
  align-items: center;
  padding: 8px 16px;
  background: rgba(77, 138, 255, 0.08);
  border: 1px solid rgba(77, 138, 255, 0.2);
  border-radius: 8px;
  color: var(--accent-blue);
  font-size: 0.85rem;
  font-weight: 500;
  text-decoration: none;
  transition: all 0.2s ease;
}

.project-link:hover:not(.disabled) {
  background: rgba(77, 138, 255, 0.15);
  border-color: var(--accent-blue);
  transform: translateY(-2px);
}

.project-link.github {
  background: rgba(91, 255, 137, 0.08);
  border-color: rgba(91, 255, 137, 0.2);
  color: var(--accent-green);
}

.project-link.github:hover {
  background: rgba(91, 255, 137, 0.15);
  border-color: var(--accent-green);
}

.project-link.disabled {
  opacity: 0.4;
  cursor: not-allowed;
  border-color: var(--border-subtle);
  color: var(--text-tertiary);
}

.project-link.disabled:hover {
  transform: none;
}

.loading {
  text-align: center;
  color: var(--text-tertiary);
  padding: 40px;
  font-size: 1.1rem;
}

.error {
  text-align: center;
  color: #ff6565;
  padding: 40px;
  background: rgba(255, 101, 101, 0.1);
  border-radius: 12px;
  border: 1px solid rgba(255, 101, 101, 0.2);
}

/* Footer */
footer {
  text-align: center;
  color: var(--text-tertiary);
  font-size: 0.9rem;
  margin: 40px 0 30px 0;
}

/* Mobile */
@media (max-width: 768px) {
  .container {
    padding: 16px;
  }

  /* Stacked: full-bleed photo on top, the name's first line overlapping it */
  .hero {
    --name-size: clamp(3.25rem, 19vw, 6rem);
    grid-template-columns: minmax(0, 1fr);
    margin-bottom: 24px;
  }

  .hero-photo {
    grid-column: 1;
    grid-row: 1;
    /* cancel the container padding so the photo reaches the screen edges */
    margin: -16px -16px 0;
  }

  .hero-photo img {
    height: min(460px, 56svh);
    object-position: 58% 15%;
  }

  .hero-photo::after {
    background:
      linear-gradient(to top, #000 0, rgb(0 0 0 / 0.7) 90px, transparent 200px),
      linear-gradient(to bottom, rgb(0 0 0 / 0.5) 0, transparent 72px);
  }

  .hero-copy {
    grid-column: 1;
    grid-row: 2;
    margin-top: calc(var(--name-size) * -0.9);
    padding-bottom: 0;
  }

  h1 {
    margin-bottom: 24px;
  }

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

  .hero-links {
    margin-top: 24px;
  }

  .intro {
    margin-bottom: 36px;
  }

  .math-equation {
    padding: 16px;
    font-size: 0.9rem;
    margin: 16px -4px;
  }

  .equation-explanation {
    font-size: 0.95rem;
  }

  .projects-section {
    margin-top: 30px;
  }

  h2 {
    font-size: 1.4rem;
  }

  .section-description {
    font-size: 1.08rem;
    margin-bottom: 24px;
  }

  .section-header {
    gap: 8px;
  }

  .update-badge {
    font-size: 0.65rem;
    padding: 3px 8px;
  }

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

  .project-card {
    padding: 20px;
    min-height: auto;
  }

  .project-image-container {
    margin-bottom: 16px;
    border-radius: 10px;
  }

  .project-title {
    font-size: 1.25rem;
  }

  .project-description {
    font-size: 0.9rem;
  }

  .project-intuition {
    font-size: 0.85rem;
    padding: 10px 12px;
  }

  .roadmap-list li {
    font-size: 0.85rem;
  }

  .project-link {
    font-size: 0.8rem;
    padding: 6px 12px;
  }
}

/*
 * Below ~500px the five links no longer fit one row, and free wrapping
 * leaves a lone button. Pin them to two even rows instead: the blogs on
 * a 6-column grid's first row (3 columns each), the profiles on the
 * second (2 columns each).
 */
@media (max-width: 540px) {
  .hero-links {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  .hero-links a {
    grid-column: span 2;
    text-align: center;
  }

  .hero-links a:nth-child(-n + 2) {
    grid-column: span 3;
  }
}

@media (max-width: 480px) {
  .math-equation {
    padding: 12px;
    font-size: 0.8rem;
    border-radius: 8px;
  }

  .equation-explanation {
    font-size: 0.8rem;
    margin-top: 12px;
  }
}

@media (max-width: 400px) {
  .container {
    padding: 12px;
  }

  .hero-photo {
    margin: -12px -12px 0;
  }

  .project-card {
    padding: 16px;
  }

  .project-image-container {
    margin-bottom: 12px;
    border-radius: 8px;
  }

  .project-links {
    flex-direction: column;
    align-items: stretch;
  }

  .project-link {
    text-align: center;
    justify-content: center;
  }
}
