:root {
  --hero-height: clamp(20rem, 50vh, 25rem);
  --house-max-width: 8rem;
  /* How long each house segment and its text stay in the spotlight */
  --house-step: 6s;
}

/* Hero */
/* The hero opens <main> flush under the header: main's top padding goes below it instead */
main:has(> .hero) {
  padding-top: 0;
}

.hero {
  margin-bottom: var(--main-padding);
  position: relative;
  height: var(--hero-height);
  overflow: hidden;
  view-timeline: --hero block;
}

/* The translation is relative to .hero-bg (154% of the hero): 17% of it stays
   within the 27% overflow above and below, so the image never shows an edge */
@keyframes hero-parallax {
  from { transform: translateY(-17%); }
  to   { transform: translateY(17%); }
}

.hero-bg {
  position: absolute;
  inset: -27% 0;
  z-index: 0;
  will-change: transform;
  animation: hero-parallax linear both;
  animation-timeline: --hero;
  animation-range: cover 0% exit 100%;
}

/* No scroll-linked motion: the image stays still and just fills the hero */
@media (prefers-reduced-motion: reduce) {
  .hero-bg {
    inset: 0;
    will-change: auto;
    animation: none;
  }
}

.hero-bg img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
}

.hero::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, var(--color-overlay-light), var(--color-overlay-dark));
  z-index: 1;
}

.hero-content {
  padding: var(--space-sm);
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: var(--space-md);
  color: var(--color-bg);
  z-index: 2;
}

.hero-content h1 {
  width: clamp(15rem, 85%, 45rem);
}

.hero-content img {
  width: 100%;
  height: auto;
  /* text-shadow does not apply to images: drop-shadow follows the SVG shape */
  filter: drop-shadow(0 0.125rem 0.75rem var(--color-shadow-strong));
}

.hero-content p {
  font-size: var(--font-size-hero);
  text-shadow: 0 0.0625rem 0.25rem var(--color-overlay);
}

/* Keep the tagline off the screen edges once there is room to spare */
@media (min-width: 760px) {
  .hero-content p {
    padding-inline: var(--space-lg);
  }
}

/* Main CTA with the contact line underneath */
.hero-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-sm);
}

.hero-content .cta {
  display: inline-block;
  /* <button> does not inherit the page font by default */
  font-family: inherit;
  line-height: inherit;
  cursor: pointer;
  padding: var(--space-sm) var(--space-md);
  background-color: var(--color-primary);
  color: var(--color-bg);
  border: 2px solid var(--color-bg);
  border-radius: var(--radius-pill);
  font-weight: 600;
  letter-spacing: 0.06rem;
  text-decoration: none;
  text-transform: uppercase;
  font-size: var(--font-size-cta);
  transition: background-color 0.2s ease, color 0.2s ease;
}

.hero-content .cta:hover,
.hero-content .cta:focus-visible {
  background-color: var(--color-bg);
  color: var(--color-primary);
}

/* Contact line on a frosted strip, readable whatever the photo behind it.
   Overrides the tagline's size, padding and shadow (.hero-content p) */
.hero-content .hero-contact-line {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  column-gap: var(--space-sm);
  padding-inline: var(--space-gutter);
  font-size: var(--font-size-base);
  text-shadow: none;
  border-radius: var(--radius-pill);
  background-color: var(--color-ghost-bg);
  backdrop-filter: blur(4px);
}

.hero-contact-line a {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  min-height: var(--tap-target);
  color: inherit;
  /* Reserve the hover underline of base.css so the line does not shift */
  border-bottom: .1rem solid transparent;
}

.hero-contact-line a:focus-visible {
  border-bottom-color: currentColor;
}

#about p,
#about li {
  margin-bottom: var(--space-sm);
  /* Readable line length: wider lines open large gaps once justified */
  max-width: 70ch;
  font-size: var(--font-size-lead);
}

/* Justify only where lines are long enough to avoid word gaps */
@media (min-width: 760px) {
  #about p,
  #about li {
    text-align: justify;
    hyphens: auto;
  }
}

/* Interactive house: full-width tinted band, a little taller than the other sections */
#house {
  background-color: var(--color-bg-tint);
  padding-block: var(--space-lg);
}

/* Mobile: outline above the texts; from 760px: outline in the left half, texts in the right half */
.house-layout {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-md);
}

@media (min-width: 760px) {
  .house-layout {
    flex-direction: row;
  }

  .house-figure,
  .house-layout .house-texts {
    flex: 1 1 50%;
  }
}

.house-figure {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  align-self: stretch;
}

/* Mobile: a third of the section width, capped so wide phones/small tablets
   don't get a huge outline; from 760px: a third of its half, i.e. a sixth */
.house {
  display: block;
  width: 33%;
  max-width: var(--house-max-width);
}

@media (min-width: 760px) {
  .house {
    max-width: none;
  }
}

/* The fill set on each <use> is inherited by its polygon in img/house.svg */
.house-segment {
  fill: var(--color-text);
  cursor: pointer;
  transition: fill 0.2s ease;
  animation: house-cycle-segment ease-in-out infinite;
}

/* Stacks the texts on top of each other; only the active one is visible */
.house-texts {
  display: grid;
  pointer-events: none;
}

.house-texts .house-text {
  grid-area: 1 / 1;
}

/* Texts can live anywhere on the page: they follow their segment through data-segment */
.house-text {
  opacity: 0;
  transition: opacity 0.2s ease;
  animation: house-cycle-text ease-in-out infinite;
}

.house-text h3 {
  margin-bottom: var(--space-sm);
  font-size: var(--font-size-lead);
  color: var(--color-primary);
}

/* Short measure: a compact block that stays clear of the frame's right edge */
.house-text p {
  max-width: 40ch;
}

/* Each segment and its text get the spotlight for one --house-step, from the roof down to the floor.
   5 segments: the cycle lasts 5 steps, and each one is lit for 20% of it (see the keyframes).
   Adding a segment means changing the 5 here and the percentages below */
.house-segment,
.house-text {
  animation-duration: calc(5 * var(--house-step));
  animation-delay: calc(var(--segment-order, 0) * var(--house-step));
}

:is(.house-segment, .house-text)[data-segment="2"] { --segment-order: 1; }
:is(.house-segment, .house-text)[data-segment="3"] { --segment-order: 2; }
:is(.house-segment, .house-text)[data-segment="4"] { --segment-order: 3; }
:is(.house-segment, .house-text)[data-segment="5"] { --segment-order: 4; }

@keyframes house-cycle-segment {
  0%, 20%, 100% { fill: var(--color-text); }
  2%, 18%       { fill: var(--color-primary); }
}

@keyframes house-cycle-text {
  0%, 20%, 100% { opacity: 0; }
  2%, 18%       { opacity: 1; }
}

/* Hovering the outline pauses the cycle where it is; it resumes from there once the pointer leaves */
body:has(.house:hover) :is(.house-segment, .house-text) {
  animation-play-state: paused;
}

/* A hovered segment takes the spotlight from the paused one.
   !important: even paused, an animation overrides normal declarations */
body:has(.house-segment:hover) .house-segment {
  fill: var(--color-text) !important;
}

body:has(.house-segment:hover) .house-segment:hover {
  fill: var(--color-primary) !important;
}

body:has(.house-segment:hover) .house-text {
  opacity: 0 !important;
}

body:has(.house-segment[data-segment="1"]:hover) .house-text[data-segment="1"],
body:has(.house-segment[data-segment="2"]:hover) .house-text[data-segment="2"],
body:has(.house-segment[data-segment="3"]:hover) .house-text[data-segment="3"],
body:has(.house-segment[data-segment="4"]:hover) .house-text[data-segment="4"],
body:has(.house-segment[data-segment="5"]:hover) .house-text[data-segment="5"] {
  opacity: 1 !important;
}

/* Same cycle, one text at a time, but each segment and text switches instantly instead of fading */
@media (prefers-reduced-motion: reduce) {
  .house-segment,
  .house-text {
    animation-timing-function: step-end;
    transition: none;
  }
}

/* Skills carousel: swipe / scroll-snap everywhere, wrap-around arrows from js/carousel.js, dots where ::scroll-marker is supported */
:root {
  /* Width of one slide, relative to the wrapper (cqi) so the track padding does not shrink it; neighbours peek in on both sides */
  --slide-width: 80cqi;
  --marker-size: 0.625rem;
  /* Inactive dot diameter and width of its tap area (WCAG 2.5.8 minimum: 24px) */
  --marker-dot-size: 0.375rem;
  --marker-slot: 1.5rem;
}

@media (min-width: 560px) {
  :root {
    --slide-width: calc((100cqi - var(--space-gutter)) / 2);
  }
}

@media (min-width: 760px) {
  :root {
    --slide-width: calc((100cqi - 2 * var(--space-gutter)) / 3);
  }
}

/* Light breathing room before the contact section */
#skills {
  margin-bottom: var(--space-md);
}

/* Containing block of the arrows, and size reference for the slides */
#skills .wrapper {
  position: relative;
  container-type: inline-size;
}

/* Carousel track: one row of slides, the current one snapped to the centre */
.skills-carousel {
  anchor-name: --skills-carousel;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: var(--slide-width);
  gap: var(--space-gutter);
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  /* Room for the card shadows, which overflow would clip otherwise */
  padding-block: var(--space-sm) var(--space-md);
  /* Lets the first and last slides reach the centre too */
  padding-inline: calc((100cqi - var(--slide-width)) / 2);
  scroll-marker-group: after;
}

.skill-slide {
  scroll-snap-align: center;
  position: relative;
  aspect-ratio: 4 / 3;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card-strong);
  overflow: hidden;
  color: var(--color-bg);
}

.skill-slide img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.4s ease;
}

/* Darkens the bottom of the picture so the label stays readable */
.skill-slide::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, var(--color-overlay-light) 40%, var(--color-overlay-dark));
}

.skill-slide p {
  position: absolute;
  inset-inline: 0;
  bottom: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-gutter);
  font-size: var(--font-size-lead);
  font-weight: 600;
}

.skill-slide .icon {
  font-size: var(--font-size-icon);
}

.skill-slide:hover img {
  transform: scale(1.05);
}

/* Several slides fit side by side: start-aligned so the carousel opens on a full row of the first skills */
@media (min-width: 560px) {
  .skills-carousel {
    padding-inline: 0;
  }

  .skill-slide {
    scroll-snap-align: start;
  }
}

/* Previous / next arrows: real buttons revealed by js/carousel.js, which wraps around at both ends
   (native ::scroll-button arrows can't: they are disabled on the first and last slides) */
.carousel-button {
  position: absolute;
  position-anchor: --skills-carousel;
  /* Vertically centred on the slides: the track centre, shifted by half the padding-block difference */
  top: calc(anchor(center) - (var(--space-md) - var(--space-sm)) / 2 - var(--tap-target) / 2);
  z-index: 2;
  display: grid;
  place-items: center;
  width: var(--tap-target);
  height: var(--tap-target);
  border: none;
  border-radius: 50%;
  /* Dark translucent disc with a white chevron, in tune with the darkened photos */
  background-color: var(--color-overlay);
  color: var(--color-white);
  font-size: var(--font-size-icon);
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

/* Without JS the buttons would do nothing: they stay hidden */
.carousel-button[hidden] {
  display: none;
}

.carousel-button:hover,
.carousel-button:focus-visible {
  background-color: var(--color-primary);
}

.carousel-button--previous {
  left: calc(anchor(left) + var(--space-sm));
}

.carousel-button--next {
  right: calc(anchor(right) + var(--space-sm));
}

/* Dots: browsers without ::scroll-marker keep a plain swipeable row with its scrollbar */
@supports selector(::scroll-marker) {
  .skills-carousel {
    scrollbar-width: none;
  }

  .skills-carousel::scroll-marker-group {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
  }

  /* Inactive dots stay small and narrow so the row stays compact; each still keeps a minimum tap target */
  .skill-slide::scroll-marker {
    content: '';
    width: var(--marker-slot);
    height: var(--tap-target);
    background: radial-gradient(circle, var(--color-muted) calc(var(--marker-dot-size) / 2), transparent calc(var(--marker-dot-size) / 2 + 1px));
    cursor: pointer;
  }

  .skill-slide::scroll-marker:target-current {
    background: radial-gradient(circle, var(--color-primary) var(--marker-size), transparent calc(var(--marker-size) + 1px));
  }
}

@media (prefers-reduced-motion: reduce) {
  .skills-carousel {
    scroll-behavior: auto;
  }

  .skill-slide img {
    transition: none;
  }
}

/* Contact */
#contact ul {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

/* Same height for every row, whether it holds a link or plain text */
#contact li {
  display: flex;
  align-items: center;
  min-height: var(--tap-target);
  font-size: var(--font-size-lead);
  .icon {
    margin-inline-end: var(--space-sm);
  }
}

#contact a {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap-target);
}