/* Work section. The list below is the reduced-motion / no-JS layout; the
   slider (work--slider, added by JS when motion is allowed) is layered on the
   same elements later. */

.work {
  padding-block: var(--space-9);
}

.work__list {
  display: grid;
  gap: var(--space-9);
  max-width: 80rem;
  margin-inline: auto;
}

.work__slide {
  display: grid;
  gap: var(--space-5);
}

/* Fixed ratio box: the cover fills it whatever its own ratio (no layout shift) */
.work__media {
  overflow: hidden;
  aspect-ratio: 16 / 10;
  border-radius: var(--radius-l);
  background: var(--color-surface);
}

.work__img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.work__text {
  display: grid;
  justify-items: start;
  gap: var(--space-3);
}

.work__title {
  font-size: clamp(2.5rem, 1rem + 6vw, 6rem);
  font-weight: 800;
  line-height: 0.95;
  letter-spacing: var(--tracking-tight);
  text-wrap: balance;
}

.work__title .serif {
  font-weight: 400;
}

.work__meta {
  font-size: var(--step-0);
  color: var(--color-text-muted);
}

.work__link {
  margin-top: var(--space-2);
  font-weight: 600;
  color: var(--color-accent);
  text-underline-offset: 0.25em;
}

@media (min-width: 1024px) {
  /* Wide screens (list layout): text beside the image, alternating sides */
  .work:not(.work--slider) .work__slide {
    grid-template-columns: 3fr 2fr;
    align-items: end;
    gap: var(--space-8);
  }

  .work:not(.work--slider) .work__slide:nth-child(even) {
    grid-template-columns: 2fr 3fr;
  }

  .work:not(.work--slider) .work__slide:nth-child(even) .work__media {
    order: 2;
  }
}

/* --- Slider layout ---------------------------------------------------------
   Added by work.js when motion is allowed: one viewport, slides stacked in
   place, only the current one shown. work-slider.js animates between them. */

.work--slider {
  --plane-w: 88vw;
  --plane-h: 52svh;
  --plane-top: 14svh;
  position: relative;
  height: 100vh;
  height: 100svh;
  min-height: 0;
  padding: 0;
  overflow: hidden;
}

@media (min-width: 768px) {
  .work--slider {
    --plane-w: 62vw;
    --plane-h: 64svh;
    --plane-top: 16svh;
  }
}

.work--slider .work__list {
  position: absolute;
  inset: 0;
  display: block;
  max-width: none;
}

.work--slider .work__slide {
  position: absolute;
  inset: 0;
  display: block;
  visibility: hidden;
}

.work--slider .work__slide.is-current {
  visibility: visible;
}

/* Image plane, centered horizontally */
.work--slider .work__media {
  position: absolute;
  top: var(--plane-top);
  left: calc((100% - var(--plane-w)) / 2);
  width: var(--plane-w);
  height: var(--plane-h);
  aspect-ratio: auto;
}

/* Title overlapping the plane's lower-left edge. Its size is the design size,
   capped so the longest line fits: --chars (whole title) or --chars-split
   (longest of the two lines on phones) come from work.js. 0.6em is a safe
   average glyph width for Inter Tight 800. */
.work--slider .work__text {
  --text-left: calc((100vw - var(--plane-w)) / 2);
  --line-chars: var(--chars-split);
  position: absolute;
  left: var(--text-left);
  right: var(--gutter);
  top: calc(var(--plane-top) + var(--plane-h) - 0.55em);
  font-size: min(clamp(3rem, 1rem + 8vw, 9rem), calc((100vw - var(--text-left) - var(--gutter)) / (var(--line-chars) * 0.6)));
  gap: var(--space-2);
}

.work--slider .work__title {
  font-size: 1em;
  line-height: 0.9;
  white-space: nowrap;
}

/* Phones: the serif word goes on its own line */
.work--slider .work__title .serif {
  display: block;
}

@media (min-width: 768px) {
  .work--slider .work__text {
    --line-chars: var(--chars);
  }

  .work--slider .work__title .serif {
    display: inline;
  }
}

.work--slider .work__meta,
.work--slider .work__link {
  font-size: var(--step-0);
}

@media (min-width: 768px) {
  .work--slider .work__text {
    --text-left: calc((100vw - var(--plane-w)) / 2 - 3vw);
  }
}

/* Chrome: label, counter, progress bar, hint */
.work__chrome {
  position: absolute;
  inset: 0;
  pointer-events: none;
  font-size: var(--step--1);
  color: var(--color-text-muted);
}

.work__label {
  position: absolute;
  top: calc(var(--header-h, 4rem) + var(--space-2));
  left: var(--gutter);
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.work__counter {
  position: absolute;
  left: var(--gutter);
  bottom: var(--space-6);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.08em;
}

.work__current {
  color: var(--color-text);
}

.work__bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  background: var(--color-line);
}

.work__bar-fill {
  height: 100%;
  background: var(--color-accent);
  transform: scaleX(var(--work-progress, 0));
  transform-origin: left;
}

.work__hint {
  position: absolute;
  right: var(--gutter);
  bottom: var(--space-6);
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

.work__hint .icon {
  width: 1em;
  height: 1em;
}

/* --- Motion: everything follows --y, the slide's offset from the progress
   value (one project = one section height), set by work-slider.js. The
   projects move as one column: the current one leaves upward at full opacity
   while the next one rises; at rest the neighbors sit just off screen. */

.work--slider .work__media,
.work--slider .work__text {
  transform: translateY(var(--y, 0px));
}

/* While the slider holds the page, vertical swipes belong to it */
.work--active {
  touch-action: none;
}

/* WebGL planes (plane-renderer.js): the canvas draws the images, so the
   <img> planes keep their layout (it is measured) but are not shown. */
.work__canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.work--webgl .work__media {
  visibility: hidden;
}

/* The "Défiler" hint leaves after the first move */
.work__hint {
  transition: opacity 0.5s ease;
}

.work--moved .work__hint {
  opacity: 0;
}
