/* Full-bleed project slider (front page, portfolio). Fills the first
   screen (100svh, at least 28rem), so the bar at the bottom is always in
   view. Slides cross-fade; the bar at the bottom
   sits on the 12-column grid: counter col 8, title col 10, controls
   right. */

.hero-slider {
  position: relative;
  height: max(100svh, 28rem);
  overflow: hidden;
  color: var(--theme-color-text-inverse);
  background: var(--theme-color-inverse);
}

.hero-slider__slides {
  user-select: none;
  touch-action: pan-y;
}

.hero-slider__slide {
  position: absolute;
  inset: 0;
  opacity: 0;
  transition:
    opacity 0.9s var(--theme-ease-signature),
    scale 1.2s var(--theme-ease-signature);
}

.hero-slider__slide.is-active {
  opacity: 1;
}

/* A change of slide also moves the images a little (10px): the one leaving drifts out
   in the direction of travel while it fades, the one arriving comes in from the
   other side (main.js sets --theme-slide-dir: 1 forward, -1 back, and marks the
   leaving slide). Resting slides have no translate transition, so they snap to
   the new starting side unseen. On the figure, so the image parallax is
   untouched. */
@media (prefers-reduced-motion: no-preference) {
  .hero-slider__slide {
    /* Slightly oversized, so the 10px drift never shows the black behind. */
    scale: 1.03;
    translate: 0 calc(var(--theme-slide-dir, 1) * 10px);
  }

  .hero-slider__slide.is-active,
  .hero-slider__slide.is-leaving {
    transition:
      opacity 0.9s var(--theme-ease-signature),
      scale 1.2s var(--theme-ease-signature),
      translate 1.2s var(--theme-ease-signature);
  }

  .hero-slider__slide.is-active {
    translate: 0 0;
  }

  .hero-slider__slide.is-leaving {
    translate: 0 calc(var(--theme-slide-dir, 1) * -10px);
  }
}

/* Hovering the project title zooms the slide in a little (the figure, so the
   parallax on the image keeps working; the hero clips the overflow). */
@media (hover: hover) and (prefers-reduced-motion: no-preference) {
  .hero-slider:has(.hero-slider__title:hover) .hero-slider__slide {
    scale: 1.07;
  }
}

.hero-slider__slide img {
  width: 100%;
  height: 100%;
  object-fit: cover;

  /* No ghost image when the slider is clicked and dragged. */
  -webkit-user-drag: none;
  user-select: none;
}

/* Film grain over the images: a tile of noise (an SVG turbulence filter as a
   background) blended over them, jumping to a new offset a few times a second.
   Above the slides, below the headline and the bar; clicks pass through. */

.hero-slider::before {
  content: '';
  position: absolute;
  inset: -50%;
  z-index: 1;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 240px 240px;
  mix-blend-mode: overlay;
  opacity: 0.22;
  pointer-events: none;
}

@media (prefers-reduced-motion: no-preference) {
  .hero-slider::before {
    animation: hero-grain 0.9s steps(1) infinite;
  }

  @keyframes hero-grain {
    0% {
      translate: 0 0;
    }

    17% {
      translate: -4% 3%;
    }

    33% {
      translate: 3% -5%;
    }

    50% {
      translate: -6% -2%;
    }

    67% {
      translate: 5% 4%;
    }

    83% {
      translate: -2% 6%;
    }
  }
}

.hero-slider::after {
  content: '';
  position: absolute;
  inset: auto 0 0;
  height: 30%;
  background: linear-gradient(to top, rgb(0 0 0 / 30%), transparent);
  pointer-events: none;
}

.hero-slider__headline {
  pointer-events: none;
  position: absolute;
  inset-block-end: clamp(1rem, 2.6vw, 2.5rem);
  inset-inline-start: var(--theme-margin);
  z-index: 1;
  max-width: 10em;
  font-size: var(--theme-fs-10xl);
  line-height: 1.05;
  letter-spacing: var(--theme-tracking-heading);
}

.hero-slider__bar {
  --theme-hero-edge: clamp(1rem, 2.6vw, 2.5rem);

  pointer-events: none;
  position: absolute;
  inset: auto 0 var(--theme-hero-edge);
  z-index: 1;
  align-items: baseline;
}

.hero-slider__bar :is(a, button) {
  pointer-events: auto;
}

.hero-slider__count {
  grid-column: 8 / span 2;
  font-size: clamp(0.75rem, 0.903vw, 0.8125rem);
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
  display: flex;
  gap: 0.35em;
}

/* The current number rolls: the old one leaves and the new one arrives from
   above or below, depending on the direction (main.js). clip-path rather than
   overflow keeps the baseline of the line intact. Only the top and bottom are clipped:
   a name wider than the new one is not cut short while it leaves. */
.hero-slider__current,
.hero-slider__title-clip {
  position: relative;
  display: inline-block;
  clip-path: inset(0 -100vw);
}

.hero-slider__current > span,
.hero-slider__title-clip > span {
  display: block;
}

.hero-slider__current > .is-leaving,
.hero-slider__title-clip > .is-leaving {
  position: absolute;
  inset: 0;
}

.hero-slider__title {
  grid-column: 10 / span 2;
  font-size: var(--theme-fs-lg);
  line-height: 1.2;
  white-space: nowrap;
}

.hero-slider__controls {
  display: flex;
  grid-column: 12;
  justify-content: flex-end;
  gap: clamp(1rem, 1.944vw, 1.75rem);
  font-size: clamp(0.75rem, 0.903vw, 0.8125rem);
  letter-spacing: 0.02em;
}

.hero-slider__controls button {
  letter-spacing: inherit;
  padding-block: 0.3em;
  transition: opacity var(--theme-duration) var(--theme-ease-signature);
}

.hero-slider__controls button:hover {
  opacity: 0.6;
}

@media (width <= 768px) {
  .hero-slider__headline {
    inset-block-end: 4.5rem;
  }

  .hero-slider__count {
    grid-column: 1 / span 3;
  }

  .hero-slider__title {
    grid-column: 4 / span 6;
  }

  .hero-slider__controls {
    grid-column: 10 / -1;
  }
}
