:where([data-work-layout="gallery"], [data-work-layout="swiss"]) .home .work {
  --work-copy-width: 21.5rem;
}

:where([data-work-layout="gallery"], [data-work-layout="swiss"]) .card-text {
  max-width: var(--work-copy-width);
}

.home > .work[data-gallery] {
  container-type: inline-size;
  width: calc(100% + 2 * var(--page-pad));
  max-width: none;
  margin-inline: calc(-1 * var(--page-pad));
  /* Leave room below the screenshot for the caption while the gallery is pinned. */
  --project-width: min(var(--measure-home), calc(100cqw - 2 * var(--page-pad)), max(var(--work-copy-width), 62svh));
  --gallery-gutter: calc((100cqw - var(--project-width)) / 2);
}

.work[data-pinned] {
  height: calc(var(--gallery-height) + var(--travel));
  margin-bottom: var(--pin-top);
  scroll-margin-top: var(--pin-top);
  overflow-anchor: none;
}

.work[data-pinned] .work-gallery {
  position: sticky;
  top: var(--pin-top);
}

.work-controls:not([hidden]) {
  display: flex;
  gap: 0.375rem;
  justify-content: flex-end;
  margin: 0 var(--gallery-gutter) 0.75rem;
}

.work-controls button {
  display: grid;
  place-items: center;
  width: 2.625rem;
  height: 2.625rem;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--pill);
  box-shadow: var(--card-ring);
  color: var(--type-ink);
  cursor: pointer;
}

.work-controls button[aria-disabled="true"] {
  color: var(--muted);
  opacity: 0.55;
  cursor: default;
}

.work-controls button:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

.work-controls svg {
  width: 1rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.work[data-gallery] .entries {
  position: relative;
  grid-auto-flow: column;
  grid-auto-columns: max-content;
  gap: clamp(1.5rem, 4vw, 5rem);
  padding: 0.25rem var(--gallery-gutter);
  /* Start the first project's copy at the intro column. */
  padding-inline-start: max(var(--page-pad), (100% - var(--measure-home)) / 2);
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
}

.work[data-gallery] .entries::-webkit-scrollbar {
  display: none;
}

.work[data-pinned] .entries {
  overflow: hidden;
  scroll-snap-type: none;
  touch-action: pan-y pinch-zoom;
}

.work[data-gallery] .entries > li {
  display: grid;
  width: var(--project-width);
  scroll-snap-align: center;
}

.work[data-gallery] .entries > li:has(.work-phone) {
  width: min(var(--project-width), 81cqw, 29rem);
}

.work[data-gallery] .work-phone {
  width: min(92%, 24rem);
  max-width: 21svh;
}

/* Focus the selected study before opening its page or password prompt. */
.work-gallery:has([data-study-focus]) :is(.work-controls, li:not([data-study-focus])),
.home:has([data-study-focus]) > :is(.nav, .headline),
.home:has([data-study-focus]) + .site-footer {
  visibility: hidden;
}

.work-gallery:has([data-study-focus]) {
  pointer-events: none;
}

@media (prefers-reduced-motion: no-preference) {
  .work-gallery:has([data-study-focus]) :is(.work-controls, li:not([data-study-focus])) {
    animation: leave-work-gallery 180ms ease-out both;
  }

  [data-study-focus] > .entry {
    transform-origin: center top;
    animation: focus-study 300ms cubic-bezier(0.22, 1, 0.36, 1) both;
  }
}

@keyframes leave-work-gallery {
  from { opacity: 1; visibility: visible; }
  to { opacity: 0; visibility: hidden; }
}

@keyframes focus-study {
  from { transform: none; }
  to { transform: translateX(var(--focus-pan)) scale(1.1); }
}
