/* ==========================================================================
   Portfolio — Selected Work

   Full-width editorial rows, alternating side to side. Explicitly NOT a
   three-column card grid (§18): with three projects a grid would read as a
   template, and each project has to carry a plate, a description and a link
   out to the live site.
   ========================================================================== */

.work {
  position: relative;
  padding-top: calc(var(--nav-h) + clamp(1.5rem, 5vh, 4rem));
  padding-bottom: var(--section-y);
  overflow: hidden;
}

/* Faint grid, biased to the header so it never sits behind a plate. */
.work::before {
  content: '';
  position: absolute;
  inset: 0 0 auto 0;
  height: min(70vh, 40rem);
  pointer-events: none;
  background-image:
    linear-gradient(to right, var(--grid-line) 1px, transparent 1px),
    linear-gradient(to bottom, var(--grid-line) 1px, transparent 1px);
  background-size: clamp(4rem, 12vw, 9rem) clamp(4rem, 12vw, 9rem);
  mask-image: radial-gradient(
    ellipse 85% 60% at 35% 20%,
    #000 10%,
    transparent 75%
  );
  opacity: var(--grid-opacity);
  z-index: 1;
}

.work__field {
  position: absolute;
  inset: 0 0 auto 0;
  height: min(80vh, 48rem);
  pointer-events: none;
  z-index: 0;
}

.work__field span {
  position: absolute;
  display: block;
  border-radius: 50%;
  will-change: transform;
}

.work__field span:nth-child(1) {
  width: 50vmax;
  height: 50vmax;
  top: -22%;
  left: -14%;
  background: radial-gradient(
    circle closest-side,
    var(--field-a) 0%,
    var(--field-a-mid) 45%,
    transparent 72%
  );
  animation: ss-drift 26s var(--ease-in-out-quart) infinite;
}

.work__field span:nth-child(2) {
  width: 34vmax;
  height: 34vmax;
  right: -8%;
  top: 8%;
  background: radial-gradient(
    circle closest-side,
    var(--field-b) 0%,
    var(--field-b-mid) 48%,
    transparent 74%
  );
  animation: ss-drift 32s var(--ease-in-out-quart) infinite reverse;
}

@media (prefers-reduced-motion: reduce) {
  .work__field span {
    animation: none !important;
    will-change: auto;
  }
}

.work__inner {
  position: relative;
  z-index: 2;
  width: 100%;
}

/* --- Header ------------------------------------------------------------- */
.work__rule {
  display: block;
  height: var(--border-w);
  background: var(--rule);
  margin-block: clamp(var(--s-5), 3vh, var(--s-7));
  transform-origin: left;
}

.work__title {
  font-family: var(--font-display);
  /* Longest word is "IZABRANI"/"SELECTED" — comfortably inside a 10vw ramp
     at every width, and height-capped so a short window keeps the first
     project in view. */
  font-size: clamp(2.5rem, min(10vw, 15vh), 8rem);
  font-weight: 700;
  line-height: var(--lh-tight);
  letter-spacing: var(--track-tight);
  text-transform: uppercase;
  max-width: 14ch;
}

.work__lead {
  font-size: var(--t-md);
  line-height: var(--lh-relaxed);
  font-weight: 300;
  color: var(--fg-muted);
  max-width: 46ch;
  margin-top: clamp(var(--s-4), 2.5vh, var(--s-6));
  text-wrap: pretty;
}

/* ==========================================================================
   Work list
   ========================================================================== */
.work__list {
  display: grid;
  gap: clamp(var(--s-8), 9vw, var(--s-10));
  margin-top: clamp(var(--s-8), 8vw, var(--s-10));
}

.work-item {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s-6) clamp(var(--s-6), 5vw, var(--s-9));
  align-items: center;
  /* No scroll-margin here: `html` already carries `scroll-padding-top` for
     the fixed nav, and the two STACK — together they dropped a deep-linked
     project 224px down instead of 104px. */
}

/* Alternate the plate side so the column never reads as a repeating card:
   row 1 left, row 2 right, row 3 left…

   Targets the direct child, because the plate is wrapped in an <a> once a
   project has a live URL — that wrapper then becomes the grid item, and
   ordering the nested .work-item__visual silently did nothing. */
.work-item:nth-child(even) > .work-item__visual,
.work-item:nth-child(even) > .work-item__hit {
  order: 2;
}

/* --- Plate --------------------------------------------------------------
   Same treatment as the homepage: always the current theme's own surface, so
   it reads as part of the page. Each logo ships a matching per-theme variant
   (see tools/build-logo-variants.py), so no mark is ever lost.
   ------------------------------------------------------------------------ */
.work-item__visual {
  position: relative;
  aspect-ratio: 4 / 3;
  display: grid;
  place-items: center;
  padding: clamp(var(--s-6), 5vw, var(--s-8));
  overflow: hidden;
  border: var(--border-w) solid transparent;
  background: radial-gradient(
    ellipse 72% 64% at 50% 45%,
    var(--plate-core) 0%,
    var(--plate-edge) 100%
  );
  transition: border-color var(--d-slow) var(--ease-out-quart);
}

.work-item:hover .work-item__visual {
  border-color: var(--rule-faint);
}

/* The <img> sits inside a <picture> (WebP + PNG fallback), so the PICTURE is
   the grid item, not the image.

   `align-self: stretch` makes it take the plate's height outright, so the
   image can size against a definite box without relying on percentage-height
   resolution — which is what silently failed before: the picture measured a
   correct 284x153 while the image inside still rendered 284x284 and got
   cropped by the plate's overflow:hidden. */
.work-item__visual picture {
  display: block;
  align-self: stretch;
  justify-self: center;
  width: 100%;
  max-width: 26rem;
  min-height: 0;
}

.work-item__logo {
  /* Fills the picture box and letterboxes inside it. object-fit: contain
     scales the artwork down to fit; it never crops. */
  width: 100%;
  height: 100%;
  object-fit: contain;
  transition: transform var(--d-slower) var(--ease-out-expo);
}

/* A real screenshot fills the plate edge to edge; the logo floats inside it. */
.work-item__visual[data-kind='shot'] {
  padding: 0;
}

.work-item__shot {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top center;
  transition: transform var(--d-slower) var(--ease-out-expo);
}

.work-item:hover .work-item__logo,
.work-item:hover .work-item__shot {
  transform: scale(1.04);
}

/* --- Body --------------------------------------------------------------- */
.work-item__body {
  display: grid;
  gap: var(--s-4);
  align-content: center;
}

.work-item__meta {
  display: flex;
  align-items: center;
  gap: var(--s-4);
}

.work-item__number {
  font-family: var(--font-display);
  font-size: var(--t-xl);
  font-weight: 700;
  line-height: 1;
  color: transparent;
  -webkit-text-stroke: 1px var(--rule-interactive);
  font-variant-numeric: tabular-nums;
  transition:
    -webkit-text-stroke-color var(--d-slow) var(--ease-out-quart),
    transform var(--d-slow) var(--ease-out-expo);
}

.work-item:hover .work-item__number {
  -webkit-text-stroke-color: var(--accent);
  transform: translate3d(0, -0.15em, 0);
}

.work-item__rule {
  flex: 1;
  height: var(--border-w);
  background: var(--rule);
  transform-origin: left;
  transform: scaleX(0.35);
  transition: transform var(--d-slower) var(--ease-out-expo);
}

.work-item:hover .work-item__rule {
  transform: scaleX(1);
}

.work-item__title {
  font-family: var(--font-display);
  font-size: var(--t-xl);
  font-weight: 700;
  line-height: var(--lh-snug);
  letter-spacing: var(--track-tight);
  text-transform: uppercase;
}

.work-item__category {
  font-size: var(--t-sm);
  color: var(--accent-text);
  font-family: var(--font-display);
  font-weight: 500;
  letter-spacing: var(--track-wide);
  text-transform: uppercase;
}

.work-item__description {
  font-size: var(--t-base);
  line-height: var(--lh-relaxed);
  font-weight: 300;
  color: var(--fg-muted);
  max-width: 48ch;
  text-wrap: pretty;
}

/* --- Link out ----------------------------------------------------------- */
/* Plate + title as click targets to the live site.

   Per §5 the client mark is a trademark: no tint, no overlay, no filter on
   hover. Feedback lives on the surrounding composition instead — the title
   underline below, and the plate's own existing hover treatment. */
.work-item__hit {
  display: block;
  color: inherit;
  text-decoration: none;
}

.work-item__title-link {
  color: inherit;
  text-decoration: none;
  background-image: linear-gradient(currentColor, currentColor);
  background-repeat: no-repeat;
  background-position: 0 100%;
  background-size: 0% var(--border-w);
  transition: background-size var(--d-base) var(--ease-out-quart);
}

.work-item__title-link:hover,
.work-item__title-link:focus-visible {
  background-size: 100% var(--border-w);
}

.work-item__link {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--s-3);
  margin-top: var(--s-2);
  padding-bottom: var(--s-2);
  font-family: var(--font-display);
  font-size: var(--t-sm);
  font-weight: 500;
  letter-spacing: var(--track-wide);
  text-transform: uppercase;
  width: fit-content;
  transition: color var(--d-base) var(--ease-out-quart);
}

/* Underline grows from the left, matching the nav and ghost buttons. */
.work-item__link::before {
  content: '';
  position: absolute;
  inset: auto 0 0 0;
  height: var(--border-w);
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform var(--d-base) var(--ease-out-expo);
}

.work-item__link:hover::before,
.work-item__link:focus-visible::before {
  transform: scaleX(1);
}

.work-item__link:hover,
.work-item__link:focus-visible {
  color: var(--accent-text);
}

/* Whole-row target, without nesting interactive elements. */
.work-item__link::after {
  content: '';
  position: absolute;
  inset: 0;
}

.work-item__link svg {
  transition: transform var(--d-base) var(--ease-out-expo);
}

.work-item__link:hover svg {
  transform: translate3d(0.3rem, -0.3rem, 0);
}

.work-item__soon {
  display: inline-flex;
  align-items: center;
  gap: var(--s-3);
  margin-top: var(--s-2);
  font-family: var(--font-display);
  font-size: var(--t-xs);
  font-weight: 500;
  letter-spacing: var(--track-wide);
  text-transform: uppercase;
  color: var(--fg-faint);
}

.work-item__soon::before {
  content: '';
  width: 0.4rem;
  height: 0.4rem;
  border-radius: 50%;
  background: var(--accent);
  flex: none;
}

/* ==========================================================================
   More coming soon

   A dashed outline rather than a filled plate: it must read as an open slot,
   not as a fourth project.
   ========================================================================== */
.work-more {
  display: flex;
  align-items: center;
  gap: clamp(var(--s-5), 4vw, var(--s-7));
  padding: clamp(var(--s-6), 5vw, var(--s-8));
  border: var(--border-w) dashed var(--rule);
}

.work-more__mark {
  font-family: var(--font-display);
  font-size: var(--t-2xl);
  font-weight: 300;
  line-height: 1;
  color: var(--rule-interactive);
  flex: none;
}

.work-more__title {
  font-family: var(--font-display);
  font-size: var(--t-lg);
  font-weight: 600;
  line-height: var(--lh-snug);
  letter-spacing: var(--track-snug);
  text-transform: uppercase;
}

.work-more__body-text {
  font-size: var(--t-sm);
  line-height: var(--lh-relaxed);
  font-weight: 300;
  color: var(--fg-muted);
  max-width: 44ch;
  margin-top: var(--s-2);
}

/* ==========================================================================
   Closing CTA
   ========================================================================== */
.work-cta {
  position: relative;
  text-align: center;
  overflow: hidden;
  border-top: var(--border-w) solid var(--rule-faint);
}

.work-cta__glow {
  position: absolute;
  inset: -10% -20% -40%;
  pointer-events: none;
  background: radial-gradient(
    ellipse 50% 60% at 50% 100%,
    color-mix(in srgb, var(--c-blue) 20%, transparent) 0%,
    color-mix(in srgb, var(--c-blue) 8%, transparent) 40%,
    transparent 72%
  );
}

.work-cta__inner {
  position: relative;
  display: grid;
  justify-items: center;
  gap: var(--s-5);
}

.work-cta__title {
  font-family: var(--font-display);
  /* A step down from the shared --t-3xl. Scaled rather than given its own
     clamp so it keeps the same responsive curve, and so the homepage CTA
     (which uses the token directly) is unaffected. */
  font-size: calc(var(--t-3xl) * 0.85);
  font-weight: 700;
  line-height: var(--lh-tight);
  letter-spacing: var(--track-tight);
  text-transform: uppercase;
  max-width: 16ch;
}

.work-cta__action {
  margin-top: var(--s-4);
}

/* ==========================================================================
   Narrow screens
   ========================================================================== */
@media (max-width: 60rem) {
  .work-item {
    grid-template-columns: 1fr;
    gap: var(--s-5);
  }

  /* The plate always leads, whatever the alternating order says. */
  .work-item:nth-child(even) > .work-item__visual,
  .work-item:nth-child(even) > .work-item__hit {
    order: 0;
  }

  .work-item__visual {
    aspect-ratio: 16 / 10;
  }

  .work-more {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--s-4);
  }
}

@media (hover: none) {
  .work-item:hover .work-item__logo,
  .work-item:hover .work-item__shot,
  .work-item:hover .work-item__number {
    transform: none;
  }

  /* Filled on touch so the composition never looks unfinished. */
  .work-item__rule {
    transform: scaleX(1);
  }
}
