/* ==========================================================================
   WORKS — Figma: Works grid (24:81), carousel (27:219), list (28:353)
   Intro statement, divider, filter + view bar, then one of three views.
   ========================================================================== */

.works {
  padding-top: calc(var(--header-h) + var(--space-10) + var(--space-40)); /* header + 10 + Figma sp-1100 */
  padding-bottom: var(--section-y);
  display: flex;
  flex-direction: column;
  gap: var(--space-40);
}

.works__title {
  max-width: 48.875rem;              /* 782 */
  font-size: var(--text-xl);         /* 40 at 1440 */
  letter-spacing: var(--tracking-xl);
  line-height: var(--leading-tight);  /* 120% — same as every 40px statement */
  font-weight: var(--weight-regular);
  color: var(--color-text);
}

.works__bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-16);
}

/* Filter → view: 50px (Figma) */
.works__views { margin-top: var(--space-10); }
.works__views [hidden] { display: none !important; }

/* ---------- Grid view (masonry, 3 columns) ---------- */
.works-grid {
  display: grid;                     /* no-JS fallback: a plain 3-up grid */
  grid-template-columns: repeat(var(--works-cols), minmax(0, 1fr));
  align-items: start;
  gap: var(--space-40) var(--space-16);
  --works-cols: 3;
}
.works-grid.is-masonry {
  display: flex;
  align-items: flex-start;
  gap: var(--space-16);              /* Figma: 16 between columns */
}
.works-grid__col {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-40);
}
.works-grid .media { width: 100%; }

.project-card { color: inherit; text-decoration: none; }
.project-card__media { overflow: hidden; border-radius: var(--radius-lg); }
.project-card:focus-visible { outline: 2px solid var(--color-text); outline-offset: 4px; border-radius: var(--radius-lg); }

/* ---------- List view ---------- */
.works-list {
  list-style: none;
  padding: 0;
  margin: 0;
  border-top: 1px solid var(--color-border);
}
.works-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: center;
  padding-block: var(--space-24);    /* 24 + 26 tag + 24 = Figma row */
  border-bottom: 1px solid var(--color-border);
  color: var(--color-text);          /* names are #333 everywhere */
  text-decoration: none;
}
.works-row__name { font-size: var(--text-md); line-height: var(--leading-md); }
.works-row__tags {
  justify-self: center;
  width: min(100%, 13.875rem);       /* 222 — tags start at the same x on every row */
  flex-wrap: nowrap;
}
.works-row__year {
  justify-self: end;
  font-size: var(--text-sm);
  line-height: var(--leading-sm);
  font-variant-numeric: tabular-nums;
}
.works-row:focus-visible { outline: 2px solid var(--color-text); outline-offset: 2px; }

/* ---------- Carousel view ---------- */
.works-carousel {
  --slot-w: 26.833rem;               /* 429 — set from JS */
  --slot-h: 40rem;                   /* 640 */
  display: flex;
  flex-direction: column;
  align-items: center;
}
.carousel__viewport {
  position: relative;
  width: 100%;
  height: var(--slot-h);
  overflow: hidden;
  touch-action: pan-y;
  cursor: grab;
  outline: none;
  user-select: none;
  -webkit-user-select: none;
  /* Side cards fade progressively into the background towards both edges — the same fade
     as the tick ruler below; the centre card stays fully visible */
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 34%, #000 66%, transparent);
  mask-image: linear-gradient(90deg, transparent, #000 34%, #000 66%, transparent);
}
.carousel__viewport.is-dragging { cursor: grabbing; }
.carousel__viewport:focus-visible { outline: 2px solid var(--color-text); outline-offset: 4px; }
.carousel__slide {
  position: absolute;
  top: 0;
  left: 50%;
  width: var(--slot-w);
  height: var(--slot-h);
  margin-left: calc(var(--slot-w) / -2);
  will-change: transform;
  -webkit-user-drag: none;
}
.carousel__slide .media {
  position: absolute;
  inset: 0;                          /* side cards: inset from JS */
  width: auto;
  height: auto;
  aspect-ratio: auto !important;     /* the slot sets the size, not the card ratio */
  border-radius: var(--radius-lg);
}

.carousel__caption {
  position: relative;
  display: grid;
  margin-top: var(--space-24);
  min-height: 3.75rem;
  width: 100%;
}
.carousel__caption-item {
  grid-area: 1 / 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-10);
  text-align: center;
}
.carousel__caption-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-16);
  color: var(--color-text);
}
.carousel__caption-row .t-body,
.carousel__caption-row .t-small { white-space: nowrap; }
.carousel__caption .tag-list { justify-content: center; }

/* Ruler: ticks slide under a fixed needle as the carousel moves */
.carousel__ruler {
  position: relative;
  width: min(100%, 49.25rem);        /* 788 */
  height: 2rem;                      /* 32 */
  margin-top: 2.875rem;              /* Figma: 46 */
  cursor: ew-resize;
  touch-action: pan-y;
}
.carousel__ticks {
  position: absolute;
  inset: auto 0 0;
  height: 1.25rem;                   /* 20 */
  background: linear-gradient(90deg, var(--grey-150) 0 1px, transparent 1px) 0 0 / var(--tick, 23.18px) 100% repeat-x;
  /* Figma: ticks fade out over the outer 271px on each side */
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 34%, #000 66%, transparent);
  mask-image: linear-gradient(90deg, transparent, #000 34%, #000 66%, transparent);
}
.carousel__needle {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 1px;
  height: 2.6875rem;                 /* 43 — rises above the ticks */
  background: var(--color-text-muted);
}

/* ---------- Responsive ---------- */
@media (max-width: 64rem) {
  .works-grid { --works-cols: 2; }
}
@media (max-width: 40rem) {
  .works-grid { --works-cols: 1; }
  .works-row { grid-template-columns: 1fr auto; row-gap: var(--space-8); }
  .works-row__tags { grid-column: 1 / -1; grid-row: 2; justify-self: start; width: auto; flex-wrap: wrap; }
  .works-row__year { grid-column: 2; grid-row: 1; }
  .carousel__ruler { margin-top: var(--space-32); }
}

@media (prefers-reduced-motion: reduce) {
}

/* ---------- List hover: band highlighter + image trail ---------- */
.works-row {
  position: relative;
  isolation: isolate;
}
.works-row__fill {
  position: absolute;
  inset: 0;
  z-index: -1;
  background: var(--color-inverse-bg);
  transform: scaleY(0);
  pointer-events: none;
}
.works-row > :not(.works-row__fill) {
  transition: translate 450ms var(--ease-out), color 250ms var(--ease-out);
}
.works-row.is-active > .works-row__name,
.works-row.is-active > .works-row__tags { translate: var(--space-12) 0; }
.works-row.is-active > .works-row__year { translate: calc(var(--space-12) * -1) 0; }
.works-row.is-active { color: var(--color-bg); } /* reads on the band in both themes */

.list-preview {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 30;                       /* under the fixed header (40) */
  width: 17.5rem;                    /* 280 */
  aspect-ratio: 4 / 3;
  border-radius: var(--radius-md);
  overflow: hidden;
  pointer-events: none;
  opacity: 0;
  scale: 0.6;
  transition: opacity 250ms var(--ease-out), scale 400ms var(--ease-out);
  will-change: transform;
}
.list-preview.is-visible { opacity: 1; scale: 1; }
.list-preview__item {
  position: absolute;
  inset: 0;
  overflow: hidden;
}
.list-preview__item .media {
  width: 100%;
  height: 100%;
  aspect-ratio: auto !important;
  border-radius: 0;
}
@media (hover: none), (prefers-reduced-motion: reduce) {
  .list-preview { display: none; }
}

/* ---------- View morph (grid ↔ list ↔ carousel) — scripts/works.js morphTo() ----------
   Live elements move from their old spot; clipping is lifted while they travel. */
.works__views { position: relative; }
.morph-ghost {
  position: absolute;
  z-index: 0;
  pointer-events: none;
}
.morph-ghost[hidden] { display: none !important; }
.works__views > .is-morphing { position: relative; z-index: 1; }
.is-morphing .project-card__media,
.is-morphing.works-carousel .carousel__viewport,
.is-morphing .carousel__caption .line-mask { overflow: visible; }
