/* ========================================
   HERO
======================================== */

/* Clip, not hidden: a scroll container would hold the sticky scroll cue */
.hero {
  overflow: clip;
}

/* Portrait in the label column, name and intro in the reading column */
.hero-content {
  align-items: start;
}

.hero-portrait {
  grid-row: span 2;
  align-self: center;
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 50%;
  background-color: var(--border-color);
  box-shadow: var(--portrait-shadow);
}

.hero-display {
  font-size: clamp(2.5rem, 5.5vw, 4.5rem);
  line-height: 1;
  letter-spacing: -0.025em;
  margin-bottom: 2rem;
  white-space: nowrap;
  /* Holds both lines while the intro types the name */
  min-height: 2lh;
}

.hero-name-part.has-caret {
  padding-right: 0.15em;
  border-right: 0.08em solid color-mix(in srgb, currentColor 60%, transparent);
  /* Cancels the caret's width so the centred name doesn't shift */
  margin-right: -0.23em;
  animation: hero-caret-blink 1.2s steps(1) infinite;
}

@keyframes hero-caret-blink {
  50% {
    border-right-color: transparent;
  }
}

.hero-meta {
  display: grid;
  row-gap: 0.75rem;
}

.hero-subtitle {
  font-size: var(--font-size-h5);
  color: var(--muted);
}

.hero-description {
  line-height: 1.7;
}

/* Scroll cue: compact screens only */
.hero-scroll {
  display: none;
}

/* Intro, in two stages flagged by motion.js: .intro-start (portrait, typed
   name) and .intro-typed (the rest) */
.js:not(.intro-start) :is(.hero-portrait, .hero-display, .hero-scroll),
.js:not(.intro-typed) :is(.hero-subtitle, .hero-description, aside.rail, #about) {
  opacity: 0;
}

/* The scroll cue waits behind the menu button */
.intro-start:not(.intro-typed) .hero-scroll {
  translate: var(--cue-x, 0) 0;
}

@media (prefers-reduced-motion: no-preference) {
  .intro-start .hero-portrait {
    animation: intro-fade 0.9s var(--ease-out-quad) 0.15s backwards;
  }

  .intro-typed .hero-subtitle {
    animation: intro-rise 0.5s var(--ease-out-cubic) backwards;
  }

  .intro-typed .hero-description {
    animation: intro-rise 0.5s var(--ease-out-cubic) 0.2s backwards;
  }

  /* Index and About come in once the intro has been read */
  .intro-typed aside.rail {
    animation: intro-fade 0.6s var(--ease-out-quad) 0.7s backwards;
  }

  .intro-typed #about {
    animation: intro-rise 0.6s var(--ease-out-cubic) 0.7s backwards;
  }

  .intro-typed .hero-scroll {
    animation: intro-cue 0.8s var(--ease-out-cubic) 0.7s backwards;
  }
}

@keyframes intro-fade {
  from {
    opacity: 0;
  }
}

@keyframes intro-rise {
  from {
    opacity: 0;
    translate: 0 1.5rem;
  }
}

@keyframes intro-cue {
  from {
    translate: var(--cue-x, 0) 0;
  }
}

@media (max-width: 56.25rem) {
  .hero {
    container-type: inline-size;
  }

  .hero-content {
    margin-block: auto;
  }

  /* Level with the menu button: at the foot of the hero, or of the screen
     when the hero runs taller. Centred without transforms: the intro
     animates translate */
  .hero-scroll {
    /* To the menu button: half the hero, less its inset and half its size */
    --cue-x: calc(50cqi - 2.875rem);
    position: sticky;
    bottom: 1.5rem;
    margin: 1rem auto 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.75rem;
    height: 2.75rem;
    border: 0.0625rem solid var(--border-color);
    border-radius: 50%;
    background: var(--background-color);
    color: var(--text-color);
    text-decoration: none;
  }

  .hero-scroll svg {
    width: 1.25rem;
    height: 1.25rem;
  }

  .hero-portrait {
    grid-row: auto;
    align-self: start;
    justify-self: center;
    /* Shrinks on short screens too */
    width: clamp(6rem, min(36vw, 18svh), 10rem);
    margin-bottom: 1.75rem;
  }

  /* Stacked: header centred, intro left-aligned */
  .hero-display,
  .hero-subtitle {
    text-align: center;
  }

  .hero-display {
    /* "Alonso-Fernandez" is ~8.15em: fills the column without wrapping */
    font-size: clamp(1.75rem, calc((100vw - 3rem) / 8.6), 3.5rem);
    line-height: 1.05;
    /* Wraps at the hyphen if a font renders wider */
    white-space: normal;
    margin-bottom: 0.625rem;
  }

  .hero-meta {
    display: contents;
  }

  .hero-description {
    grid-column: 1 / -1;
    margin-top: 1.75rem;
  }

  .hero-subtitle {
    font-size: var(--font-size-body);
  }
}

/* ========================================
   ABOUT
======================================== */

.subsection-title {
  margin-bottom: 1rem;
}

.timeline-section {
  margin-bottom: 3.75rem;
}

.timeline-item {
  margin-bottom: 2rem;
}

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

.timeline-content {
  margin-bottom: 2rem;
}

.timeline-header {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.25rem;
  margin-bottom: 0.5rem;
}

.timeline-header .timeline-title {
  margin: 0 0 0.25rem;
}

/* Handwritten notes: MSc aside and project badge */
.msc-note,
.badge-nuevo {
  font-family: 'Caveat', cursive;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--hci-color);
}

.msc-note {
  display: inline-block;
  font-size: 1.25em;
  line-height: 1;
  white-space: nowrap;
}

.timeline-period,
.role-period,
.achievement-year,
.project-date {
  font-variant-numeric: tabular-nums;
  font-size: var(--font-size-secondary);
  color: var(--muted);
}

.timeline-organization {
  margin-bottom: 0.5rem;
}

.achievements-grid {
  display: flex;
  flex-direction: column;
}

.achievement-item {
  padding: 1rem 0;
  border-bottom: 0.0625rem solid var(--border-color);
}

.achievement-item:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.achievement-item .achievement-content {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
}

.achievement-item .achievement-content .achievement-title {
  grid-column: 1 / -1;
  margin-bottom: 0.5rem;
}

.achievement-item .achievement-content .achievement-issuer {
  grid-column: 1;
  align-self: center;
}

.achievement-item .achievement-content .achievement-year {
  grid-column: 2;
  align-self: center;
  padding: 0.25rem 0 0.25rem 0.75rem;
}

.timeline-roles {
  margin-top: 1.5rem;
}

.timeline-roles,
.timeline.timeline-track {
  padding-left: 1.5rem;
  border-left: 0.0625rem solid var(--border-color);
}

.role-item {
  margin-bottom: 2rem;
}

.role-item,
.timeline-track > .timeline-item {
  position: relative;
}

.role-item::before,
.timeline-track > .timeline-item::before {
  content: '';
  position: absolute;
  left: -1.5rem;
  top: 1rem;
  width: 1rem;
  height: 0.0625rem;
  background-color: var(--border-color);
}

.role-item:last-child {
  margin-bottom: 0;
}

.role-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.role-title {
  margin: 0;
}

@media (max-width: 56.25rem) {
  /* Narrower indent */
  .timeline-roles,
  .timeline.timeline-track {
    padding-left: 1rem;
  }

  .role-item::before,
  .timeline-track > .timeline-item::before {
    left: -1rem;
    width: 0.625rem;
  }

  .role-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.25rem;
  }

  .timeline-section {
    margin-bottom: 3rem;
  }

  .achievement-item {
    padding: 0.75rem 0;
  }

  .achievement-item .achievement-content .achievement-year {
    margin-top: 0.25rem;
    padding: 0.125rem 0;
  }
}

/* LaTeX logo, TeX's kerns eased for Lora */
.latex {
  letter-spacing: 0;
  white-space: nowrap;
}

.latex-a,
.latex-e {
  position: relative;
}

.latex-a {
  top: -0.22em;
  margin: 0 -0.1em 0 -0.26em;
  font-size: 0.75em;
}

.latex-e {
  top: 0.22em;
  margin: 0 -0.08em 0 -0.1em;
}

/* ========================================
   PROJECTS
======================================== */

.projects-grid {
  display: flex;
  flex-direction: column;
}

.project-card:first-child {
  padding-top: 0;
}

.project-card {
  position: relative;
  padding: 1.75rem 0;
  border-bottom: 0.0625rem solid var(--border-color);
}

.project-card:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.badge-nuevo {
  position: absolute;
  top: 1.75rem;
  right: 0;
  font-size: 1.4rem;
  line-height: 1.4;
  transform: rotate(-8deg);
  pointer-events: none;
}

.project-title {
  margin-bottom: 0.25rem;
  line-height: 1.3;
}

.project-title-link {
  color: inherit;
}

.project-meta {
  margin-bottom: 0.75rem;
}

@media (max-width: 56.25rem) {
  /* Keeps the title clear of the badge */
  .project-card:has(.badge-nuevo) .project-title {
    padding-right: 7rem;
  }
}

/* ========================================
   SKILLS
======================================== */

.skills-block {
  margin-bottom: 3rem;
}

.skills-block:last-child {
  margin-bottom: 0;
}

.skills-block-title {
  margin-bottom: 1.25rem;
}

.skills-areas {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.skill-area-title {
  margin-bottom: 0.75rem;
}

@media (max-width: 56.25rem) {
  .skills-block {
    margin-bottom: 2.5rem;
  }
}

/* ========================================
   CONTACT
======================================== */

.contact-description {
  margin-bottom: 3rem;
}

.social-links {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  font-size: var(--font-size-secondary);
  font-style: normal;
}

.social-link {
  display: inline-flex;
  padding: 0.15rem 0;
}

.social-divider {
  user-select: none;
}

.contact-label,
.contact-value {
  letter-spacing: 0.03125rem;
}

/* Brand colours adjusted for contrast: light, dark */
.social-link.linkedin {
  color: light-dark(#0077b5, #4db8e8); /* 4.57:1, 9.4:1 */
}

.social-link.github {
  color: light-dark(#333333, #ffffff);
}

.social-link.bluesky {
  color: light-dark(#006d7a, #00bcd4); /* 5.82:1, 9.2:1 */
}

.social-link.orcid {
  color: light-dark(#1e7d3a, #3ac267); /* 4.94:1, 9.1:1 */
}

.social-link.scholar {
  color: light-dark(#3949ab, #80a4f3); /* 5.27:1, 8.5:1 */
}

@media (max-width: 56.25rem) {
  .contact-description {
    margin-bottom: 2.5rem;
  }

  .social-links {
    gap: 0.5rem;
  }
}
