/* ==========================================================================
   Work index (M07): the best case study first, then everything else, with
   filters for the two lanes, a grid/list toggle, a floating preview in the
   list, and a lightbox for pieces without a case study.
   ========================================================================== */

.index-head {
  display: grid;
  gap: clamp(2.5rem, 7vw, 4rem);
  padding: clamp(8rem, 20vh, 12rem) var(--gutter) clamp(3.5rem, 8vw, 7rem);
}
.index-head__eyebrow {
  margin-bottom: clamp(1.25rem, 3vh, 2rem);
  color: var(--soft);
}
.index-head__title {
  font-size: var(--step-4);
  max-width: 9ch;
}

/* ---------- the opening book ----------
   A cover you can pick up. Drag it and it turns with some weight; the back is
   black cloth with the seal; by the time it comes round again it is the next
   cover. Without the script it is the first cover, standing still. */

.spinner {
  --book: min(56vw, 17rem);
  display: grid;
  justify-items: center;
  gap: clamp(2.25rem, 5vw, 3rem);
}
.spinner__zone {
  width: var(--book);
}
.motion .spinner__zone {
  cursor: grab;
  touch-action: pan-y;
  -webkit-user-select: none;
  user-select: none;
}
.spinner__zone.is-held {
  cursor: grabbing;
}
.spinner__zone img {
  pointer-events: none;
}
.spinner__meta {
  display: grid;
  justify-items: center;
  gap: 0.5rem;
  text-align: center;
}
.spinner__count {
  color: var(--soft);
}
.spinner__name {
  display: grid;
  gap: 0.15rem;
}
.spinner__title {
  font-size: var(--step-2);
  line-height: 1.02;
  text-wrap: balance;
}
.spinner__who {
  color: var(--soft);
}
.spinner__next {
  margin-top: 0.6rem;
  padding: 0 0 0.3em;
  color: inherit;
  cursor: pointer;
}
.spinner__hint {
  display: none;
  color: var(--soft);
}
html:not(.js) .spinner__next {
  display: none;
}
@media (min-width: 900px) {
  .index-head {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    align-items: end;
    min-height: 100vh;
    min-height: 100svh;
    padding-bottom: clamp(3rem, 8vh, 5rem);
  }
  .index-head__copy {
    align-self: start;
  }
  .spinner {
    --book: min(24vw, 42vh, 23rem);
    grid-template-columns: minmax(0, 1fr) var(--book);
    align-items: end;
    justify-items: start;
    gap: clamp(1.5rem, 3vw, 3rem);
    /* the book stands clear of the page edge, with room for its shadow */
    padding: 0 clamp(0rem, 4vw, 4rem) 1.5rem 0;
  }
  .spinner__zone {
    grid-column: 2;
    grid-row: 1;
  }
  .spinner__meta {
    grid-column: 1;
    grid-row: 1;
    justify-items: end;
    justify-self: end;
    text-align: right;
    padding-bottom: 0.5rem;
  }
}
@media (hover: hover) and (pointer: fine) {
  .motion .spinner__hint {
    display: block;
    margin-top: 0.4rem;
  }
}

/* ---------- featured ---------- */

.feature {
  padding: 0 var(--gutter) clamp(4rem, 9vw, 8rem);
}
.feature__link {
  display: grid;
  gap: clamp(1.5rem, 3vw, 2.5rem);
  text-decoration: none;
}
.feature__media {
  overflow: hidden;
}
.feature__media img {
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  transition: scale 1.2s var(--ease-out);
}
.feature__meta {
  display: grid;
  gap: 1rem;
  align-content: end;
  justify-items: start;
}
.feature__meta .eyebrow {
  color: var(--soft);
}
.feature__title {
  font-size: var(--step-3);
  max-width: 12ch;
}
.feature__dek {
  max-width: 30ch;
}
@media (hover: hover) and (pointer: fine) {
  .feature__link:hover .feature__media img {
    scale: 1.03;
  }
}
@media (min-width: 900px) {
  .feature__link {
    grid-template-columns: minmax(0, 8fr) minmax(0, 4fr);
    column-gap: clamp(2rem, 4vw, 4rem);
  }
}

/* ---------- the bar: filters and layout ---------- */

.index {
  padding: 0 var(--gutter) var(--section);
}
.index__bar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem clamp(1rem, 3vw, 2.5rem);
  padding: 1rem 0;
  margin-bottom: clamp(1.5rem, 3vw, 2.5rem);
  border-bottom: 1px solid var(--rule);
  background: var(--bg);
}
.index__title {
  margin-right: auto;
}
.index__count {
  color: var(--soft);
  margin-left: 0.5em;
}
.index__filters,
.index__views {
  display: flex;
  gap: 0.4rem;
}
.index__views {
  padding-left: clamp(0.75rem, 2vw, 1.5rem);
  border-left: 1px solid var(--rule);
}
/* chips: plain text that becomes a full moon (a filled pill would be a rounded rectangle) */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.5em;
  padding: 0.45rem 0.35rem;
  border: 0;
  background: none;
  color: var(--soft);
  cursor: pointer;
  transition: color var(--dur-ui) linear;
}
.chip::before {
  content: "";
  width: 0.55em;
  height: 0.55em;
  border-radius: 50%;
  border: 1px solid currentColor;
  transition: background-color var(--dur-ui) linear;
}
.chip[aria-pressed="true"] {
  color: var(--fg);
}
.chip[aria-pressed="true"]::before {
  background: currentColor;
}
@media (hover: hover) and (pointer: fine) {
  .chip:hover {
    color: var(--fg);
  }
}
/* the toggle only matters once the script can act on it */
html:not(.js) .index__filters,
html:not(.js) .index__views {
  display: none;
}

/* ---------- pieces: grid ---------- */

.pieces {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 17rem), 1fr));
  gap: clamp(2rem, 4vw, 3.5rem) clamp(1rem, 2.5vw, 2.25rem);
}
.piece[hidden] {
  display: none;
}
.piece__link {
  display: grid;
  gap: 0.35rem;
  text-decoration: none;
}
.piece__media {
  position: relative;
  overflow: hidden;
  margin-bottom: 0.65rem;
  aspect-ratio: 4 / 5;
  background: color-mix(in srgb, var(--fg) 5%, transparent);
}
.piece__media[style*="--tile"] {
  background: var(--tile);
}
.piece__media > img {
  width: 100%;
  height: 100%;
  object-fit: var(--fit, cover);
  mix-blend-mode: var(--blend, normal);
  object-position: var(--pos, 50% 50%);
  transition: scale 1s var(--ease-out);
}
/* a cover is never cropped: it stands in its frame as the book, whole */
.piece__media--book {
  display: grid;
  place-items: center;
  overflow: visible;
  background: color-mix(in srgb, var(--fg) 3.5%, transparent);
}
.piece__media--book .book {
  width: 58%;
  --ry: 15;
  --rx: -3;
}
.piece__media--book .book--wide {
  width: 82%;
}
/* a covers case study: the final between two of the comps it beat */
.piece__media--trio {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5%;
}
.piece__media--trio .book {
  width: 21%;
  --ry: 12;
}
.piece__media--trio .book:nth-child(2) {
  width: 27%;
}
/* the record stands whole in its tile, like the books */
.piece__media--sleeve {
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--fg) 3.5%, transparent);
}
.piece__media--sleeve .sleeve {
  width: 78%;
}
/* case studies get a wide tile, the height of their neighbours */
@media (min-width: 700px) {
  .pieces[data-view="grid"] .piece--case {
    grid-column: span 2;
  }
  .pieces[data-view="grid"] .piece--case .piece__media {
    aspect-ratio: 1.69 / 1;
  }
  .pieces[data-view="grid"] .piece--case .piece__media--sleeve .sleeve {
    width: 62%;
  }
}
.piece__no {
  display: none;
}
.piece__title {
  font-size: var(--step-1);
  line-height: 1.1;
}
.piece__title {
  transition: translate 0.6s var(--ease-out);
}
@media (hover: hover) and (pointer: fine) {
  .pieces[data-view="grid"] .piece__link:hover .piece__title {
    translate: 0.2em 0;
  }
}
.piece__who {
  color: var(--soft);
}
.piece__kind {
  color: var(--soft);
}
@media (hover: hover) and (pointer: fine) {
  .piece__link:hover .piece__media > img {
    scale: 1.04;
  }
}

/* ---------- pieces: list ---------- */

.pieces[data-view="list"] {
  display: block;
  border-top: 1px solid var(--rule);
}
.pieces[data-view="list"] .piece__link {
  grid-template-columns: 3rem minmax(0, 1fr);
  align-items: baseline;
  gap: 0.2rem 1rem;
  padding: clamp(0.9rem, 1.8vw, 1.4rem) 0;
  border-bottom: 1px solid var(--rule);
}
.pieces[data-view="list"] .piece__media {
  display: none;
}
.pieces[data-view="list"] .piece__no {
  display: block;
  grid-row: span 3;
  color: var(--soft);
}
.pieces[data-view="list"] .piece__title {
  font-size: var(--step-2);
  transition: translate 0.5s var(--ease-out);
}
@media (min-width: 900px) {
  .pieces[data-view="list"] .piece__link {
    grid-template-columns: 4rem minmax(0, 6fr) minmax(0, 3fr) minmax(0, 3fr);
  }
  .pieces[data-view="list"] .piece__no {
    grid-row: auto;
  }
}
@media (hover: hover) and (pointer: fine) {
  .pieces[data-view="list"] .piece__link:hover .piece__title {
    translate: 0.4em 0;
  }
}

/* the picture that follows the pointer down the list */
.float-preview {
  display: none;
}
.motion .float-preview {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 30;
  display: block;
  width: clamp(14rem, 22vw, 20rem);
  pointer-events: none;
  opacity: 0;
  scale: 0.85;
  transition: opacity var(--dur-ui) linear, scale 0.5s var(--ease-out);
}
.motion .float-preview.is-on {
  opacity: 1;
  scale: 1;
}
.float-preview img {
  width: 100%;
  aspect-ratio: 2 / 3;
  object-fit: cover;
}

/* ---------- lightbox ---------- */

.lightbox {
  width: 100vw;
  max-width: none;
  height: 100vh;
  height: 100dvh;
  max-height: none;
  margin: 0;
  padding: clamp(3.5rem, 7vh, 5rem) var(--gutter) clamp(4.5rem, 9vh, 6rem);
  border: 0;
  background: var(--black);
  color: var(--white);
}
.lightbox::backdrop {
  background: var(--black);
}
.lightbox[open] {
  display: grid;
  place-items: center;
}
.lightbox__figure {
  display: grid;
  justify-items: center;
  gap: 1rem;
  max-height: 100%;
}
.lightbox__img {
  max-width: 100%;
  max-height: calc(100dvh - 12rem);
  width: auto;
  object-fit: contain;
}
/* a cover opens as the book itself, to turn in the hand */
.lightbox__book {
  width: min(var(--lw, 62vw), calc((100dvh - 15rem) * var(--lar, 0.6)));
  margin: 1rem 0 1.5rem;
}
.motion .lightbox__book {
  cursor: grab;
  touch-action: pan-y;
  -webkit-user-select: none;
  user-select: none;
}
.lightbox__book.is-held {
  cursor: grabbing;
}
.lightbox__book[hidden],
.lightbox__img[hidden] {
  display: none;
}
.lightbox__book img {
  pointer-events: none;
}
.lightbox__book .book__shadow {
  display: none;
}
/* on black the volume needs an edge: a thin light along the boards */
.lightbox__book .book__front,
.lightbox__book .book__back,
.lightbox__book .book__spine {
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.14);
}
.lightbox__caption {
  display: grid;
  justify-items: center;
  gap: 0.3rem;
  text-align: center;
}
.lightbox__title {
  font-size: var(--step-1);
}
.lightbox__who {
  color: color-mix(in srgb, var(--white) 60%, transparent);
}
.lightbox__btn {
  position: absolute;
  padding: 0.75rem;
  border: 0;
  background: none;
  color: var(--white);
  cursor: pointer;
}
.lightbox__prev {
  left: calc(var(--gutter) - 0.75rem);
  bottom: 1.25rem;
}
.lightbox__next {
  right: calc(var(--gutter) - 0.75rem);
  bottom: 1.25rem;
}
.lightbox__close {
  right: calc(var(--gutter) - 0.75rem);
  top: 1rem;
}
.lightbox[open] .lightbox__img {
  animation: lightbox-in 0.6s var(--ease-out);
}
@keyframes lightbox-in {
  from {
    opacity: 0;
    scale: 0.97;
  }
}
@media (prefers-reduced-motion: reduce) {
  .lightbox[open] .lightbox__img {
    animation: none;
  }
}
