/* The photograph is the whole tile. Its aperture changes shape during
   arrival, while the image keeps its architectural lines straight. */
.project-glass {
  --radius: clamp(14px, 1.5vw, 24px);
  --look-x: 0;
  --look-y: 0;
  aspect-ratio: 1.6;
  position: relative;
  overflow: hidden;
  border-radius: var(--radius);
  background: #dce4e9;
}
.project-glass img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
@media (prefers-reduced-motion:no-preference) {
  [data-gallery-motion] .project-feature:not([data-entered]) :is(.project-glass,.project-story,.project-details) {
    opacity: 0;
  }
  [data-gallery-motion] .project-feature[data-entered] .project-glass {
    animation: aperture-arrival 980ms both;
    animation-delay: var(--stagger,0ms);
  }
  [data-gallery-motion] .project-feature[data-entered] :is(.project-story,.project-details) {
    animation: caption-arrival 540ms cubic-bezier(.2,.76,.2,1) both;
    animation-delay: calc(270ms + var(--stagger,0ms));
  }
  [data-gallery-motion] .project-feature[data-entered] .project-details { animation-delay: calc(340ms + var(--stagger,0ms)); }
  @keyframes aperture-arrival {
    0% {
      opacity: 0;
      clip-path: inset(33% 40% 33% 40% round 50%);
      transform: translate(calc(var(--side) * 20px),24px) rotate(calc(var(--side) * 3deg));
      animation-timing-function: cubic-bezier(.34,.11,.67,1);
    }
    16% {
      opacity: 1;
      clip-path: inset(26% 34% 26% 34% round 49% 46% 50% 48%);
      transform: translate(calc(var(--side) * 14px),18px) rotate(calc(var(--side) * 2.6deg));
      animation-timing-function: cubic-bezier(.17,.63,.26,1);
    }
    63% {
      opacity: 1;
      clip-path: inset(0 1% .7% 0 round 12% 8% 13% 9% / 19% 12% 24% 14%);
      transform: translate(calc(var(--side) * -3px),-2px) rotate(calc(var(--side) * -.42deg));
      animation-timing-function: cubic-bezier(.25,.15,.18,1);
    }
    100% {
      opacity: 1;
      clip-path: inset(0 round var(--radius));
      transform: none;
    }
  }
  @keyframes caption-arrival {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: none; }
  }
  .project-feature:focus-within :is(.project-glass,.project-story,.project-details) {
    animation: none !important; opacity: 1 !important; clip-path: none; transform: none;
  }
}
@media (hover:hover) and (pointer:fine) and (prefers-reduced-motion:no-preference) {
  .project-glass {
    rotate: calc(var(--look-x) * .5deg);
    translate: calc(var(--look-x) * 1.8px) calc(var(--look-y) * 1.2px);
    transition: rotate .5s ease-out, translate .5s ease-out;
  }
  .project-glass img { transition: transform .55s cubic-bezier(.2,.75,.3,1); }
  .project-link:is(:hover,:focus-visible) img {
    transform: scale(1.055) translate(calc(var(--look-x) * -1.5%),calc(var(--look-y) * -1.5%));
  }
  /* Re-sample just the area under the fingertip-sized lens. It travels with
     the pointer and refracts the same photograph through its softened edge. */
  .project-glass::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: var(--lens-image, none) center / cover no-repeat;
    filter: brightness(1.10) saturate(1.08);
    mask-image: radial-gradient(ellipse, black 38%, #000d 61%, transparent 75%);
    mask-repeat: no-repeat;
    mask-size: clamp(110px, 26%, 190px) clamp(100px, 38%, 168px);
    mask-position: calc(50% + var(--look-x) * 58%) calc(50% + var(--look-y) * 62%);
    opacity: 0;
    transform: scale(1.105) translate(calc(var(--look-x) * -1.8%),calc(var(--look-y) * -1.8%));
    transition: opacity 270ms ease, mask-position 150ms ease-out, transform .5s ease-out;
  }
  .project-glass:hover::after { opacity: .96; }
}
/* Native scroll timelines keep the same shape reveal with JavaScript off.
   Browsers without them start with the complete portfolio in document flow. */
@supports (animation-timeline:view()) {
  @media (prefers-reduced-motion:no-preference) {
    html:has(.static-drive) #projects {
      animation-name: gallery-visible;
      animation-range: contain 71% contain 99.5%;
    }
    html:has(.static-drive) .project-glass {
      animation: aperture-arrival linear both;
      animation-timeline: view();
      animation-range: entry 0% entry 65%;
    }
    html:has(.static-drive) .project-gallery .project-feature:first-child .project-glass {
      animation-timeline: --shop-travel;
      animation-range: contain 71% contain 99.5%;
    }
    @keyframes gallery-visible { from { visibility: hidden; } .1%, to { visibility: visible; } }
  }
  @media (min-width:701px) and (prefers-reduced-motion:no-preference) {
    html:has(.static-drive) .project-feature:nth-child(2) .project-glass {
      animation-timeline: --shop-travel;
      animation-range: contain 74% contain 100%;
    }
  }
}
