/* "Créations graphiques": infinite scroll gallery with a fullscreen preview.
   Adapted from Surya Aditya's Codrops demo "Infinite Scroll Gallery and Flip Transitions
   in GSAP" (MIT), restyled with the portfolio's grid, fonts and buttons. */

*,
*::after,
*::before {
  box-sizing: border-box;
}

:root {
  --page-padding: 24px;
  --color-text: #000;
  --color-muted: #6b6b6b;
}

/* The slider drives the gallery, so the document itself never scrolls. */
html,
body {
  height: 100%;
  overflow: hidden;
}

/* Same 18px grid as the home page. */
body {
  margin: 0;
  background-color: #f8f8f8;
  background-image:
    linear-gradient(to right, rgba(0, 0, 0, 0.12) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(0, 0, 0, 0.12) 1px, transparent 1px);
  background-size: 18px 18px;
  color: var(--color-text);
  font-family: "Work Sans", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overscroll-behavior: none;
  touch-action: none;
}

h1, h2, p, figure, dl, dd {
  margin: 0;
}

img {
  display: block;
}

/* Loader while the thumbnails decode. */
.loading::before,
.loading::after {
  content: "";
  position: fixed;
  z-index: 10000;
}

.loading::before {
  inset: 0;
  background: #f8f8f8;
}

.loading::after {
  top: 50%;
  left: 50%;
  width: 100px;
  height: 1px;
  margin-left: -50px;
  background: #000;
  animation: loader 1.5s ease-in-out infinite alternate;
}

@keyframes loader {
  0% { transform: scaleX(0); transform-origin: 0 50%; }
  50% { transform: scaleX(1); transform-origin: 0 50%; }
  50.1% { transform: scaleX(1); transform-origin: 100% 50%; }
  100% { transform: scaleX(0); transform-origin: 100% 50%; }
}

/* ---------- Fixed frame: title, back link, counter, hint ---------- */

.frame {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-start;
  padding: var(--page-padding);
  bottom: auto;
  pointer-events: none;
}

.frame a,
.frame button { pointer-events: auto; }

/* Back link, then the title in a white box, then the filters. */
.frame__head {
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: flex-start;
}

.frame__title {
  padding: 10px 14px;
  border: 1px solid #000;
  background: #fff;
  font-family: "Intel One Mono", ui-monospace, monospace;
  font-weight: 400;
  font-size: 36px;
  line-height: 42px;
  letter-spacing: -0.05em;
}

/* Category filters, under the back link. */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-width: 560px;
}

.filter {
  padding: 6px 12px;
  border: 1px solid #000;
  border-radius: 100px;
  background: #fff;
  color: #000;
  font-family: "Intel One Mono", ui-monospace, monospace;
  font-size: 14px;
  line-height: 18px;
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.filter:hover { background: #ececec; }

.filter.is-active {
  background: #000;
  color: #fff;
}

.filter:focus-visible {
  outline: 2px solid #000;
  outline-offset: 3px;
}

.filter__count { opacity: 0.6; }

.gallery__slide.is-filtered { display: none; }

/* ---------- Scroll hint: centred, in front of the images, gone after the first scroll ---------- */

.scroll-hint {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 50;
  width: max-content;
  max-width: 90vw;
  margin: 0;
  padding: 8px 16px;
  background: rgba(248, 248, 248, 0.9);
  transform: translate(-50%, -50%);
  color: #6b6b6b;
  font-family: "Work Sans", system-ui, sans-serif;
  font-weight: 300;
  font-size: clamp(17px, 1.8vw, 24px);
  line-height: 1.4;
  text-align: center;
  pointer-events: none;
}

/* ---------- Gallery ---------- */

.gallery {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5.5vh;
  width: 100%;
  padding-top: 26vh;
}

/* The slide is as wide as its image; the caption wraps under it. */
.gallery__slide {
  flex-shrink: 0;
  width: clamp(150px, calc(var(--img-w, 18vw) * 1.35), 540px);
  padding: 0;
  transform: translateX(calc(var(--stagger, 0vw) * 1.15));
  outline: none;
}

.gallery__slide:focus-visible .gallery__img-wrapper {
  outline: 2px solid #000;
  outline-offset: 4px;
}

.gallery__img-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: var(--ratio, 0.8);
  overflow: hidden;
  border: 1px solid rgba(0, 0, 0, 0.15);
  background: #fff;
  pointer-events: none;
  user-select: none;
}

.gallery__img-wrapper img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Logos sit on a white card with breathing room, the KLAP one on a dark card. */
.gallery__slide--logo .gallery__img-wrapper img,
.content.is-logo .content__preview-img img {
  object-fit: contain;
  padding: 10%;
}

.gallery__slide--dark .gallery__img-wrapper,
.content.is-dark .content__preview-img {
  background: #1e1e2a;
}

.gallery__slide figcaption {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 10px;
  align-items: baseline;
  margin-top: 8px;
  font-size: 13px;
  line-height: 18px;
}

.gallery__title { font-weight: 500; }

.gallery__kind {
  color: var(--color-muted);
  font-family: "Intel One Mono", ui-monospace, monospace;
  font-size: 12px;
}

/* ---------- Fullscreen preview ---------- */

/* Clicking anywhere outside the image closes the preview. */
.content {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  cursor: zoom-out;
}

.content__preview-img,
.content__back { cursor: default; }

/* Position and size are set by script to fit the image in the left part of the screen. */
.content__preview-img {
  position: fixed;
  overflow: hidden;
  margin: 0;
  border: 1px solid rgba(0, 0, 0, 0.15);
  background: #fff;
}

.content__preview-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.content__group-list {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding: var(--page-padding) var(--page-padding) var(--page-padding) 60vw;
}

.content__back {
  align-self: flex-start;
  padding: 6px 12px;
  border: 1px solid #000;
  background: #fff;
  color: #000;
  font-family: "Intel One Mono", ui-monospace, monospace;
  font-size: 14px;
  line-height: 20px;
  cursor: pointer;
}

.content__back:hover {
  background: #000;
  color: #fff;
}

.content__back:focus-visible {
  outline: 2px solid #000;
  outline-offset: 3px;
}

.content__group { display: none; }
.content__group.active { display: block; }

.content__title {
  margin-top: 38vh;
  margin-bottom: 24px;
  font-family: "Intel One Mono", ui-monospace, monospace;
  font-weight: 400;
  font-size: clamp(32px, 4.4vw, 60px);
  line-height: 1.1;
  letter-spacing: -0.05em;
}

.content__meta {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 16px;
  font-size: 17px;
  line-height: 24px;
}

.content__meta dt {
  color: var(--color-muted);
  font-family: "Intel One Mono", ui-monospace, monospace;
  font-size: 13px;
  line-height: 24px;
  text-transform: uppercase;
}

/* ---------- Small screens ---------- */

@media (max-width: 767px) {
  :root { --page-padding: 16px; }

  .frame__title { font-size: 26px; line-height: 32px; }
  .filters { max-width: 100%; }
  .filter { padding: 5px 10px; font-size: 13px; }

  .gallery { gap: 7vh; padding-top: 26vh; }

  /* Half the horizontal scatter and larger thumbnails on a narrow screen. */
  .gallery__slide { transform: translateX(calc(var(--stagger, 0vw) * 0.5)); }
  .gallery__slide { width: clamp(150px, calc(var(--img-w, 18vw) * 2.8), 330px); }

  /* Preview on top, text under it. */
  .content__group-list { padding: var(--page-padding); padding-top: 64vh; }
  .content__back { position: fixed; top: var(--page-padding); right: var(--page-padding); }
  .content__title { margin-top: 0; margin-bottom: 12px; }
}
