/* ==========================================
   Case page — intro (info 1/3 + sticky cover 2/3), then a gallery of rows.
   Base reset, body, tiles and the lightbox come from styles.css.
   ========================================== */
.case {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 32px 32px 80px;
}

.back {
  display: flex;
  align-items: center;
  justify-content: center;
  align-self: flex-start;
  width: 36px;
  height: 36px;
  border-radius: 28px;
  background-color: #2c2c2c;
  box-shadow: 0 4px 4px rgba(0, 0, 0, 0.2);
  transition: background-color 0.2s;
}

.back:hover {
  background-color: #3a3a3a;
}

.back img {
  width: 12.833px;
  height: 12.833px;
}

/* ==========================================
   Intro
   ========================================== */
.case-intro {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 2fr);
  align-items: start;
  gap: 20px;
}

.case-info {
  display: flex;
  flex-direction: column;
  gap: 24px;
  max-width: 420px;
  padding: 20px 8px 0;
}

.case-title {
  font-family: 'Roboto Condensed', sans-serif;
  font-weight: 500;
  font-size: 36px;
  line-height: 1.1;
}

.case-description {
  font-family: 'Roboto Condensed', sans-serif;
  font-weight: 300;
  font-size: 16px;
  line-height: 1.55;
}

.case-facts {
  display: flex;
  flex-direction: column;
}

.case-fact {
  position: relative;
  display: flex;
  gap: 16px;
  padding: 10px 0;
  font-family: 'Roboto Condensed', sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

/* The divider is a pseudo-element so it can draw in from the left */
.case-fact::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background-color: #3a3a3a;
  transform-origin: left;
}

.case-description p + p {
  margin-top: 1em;
}

.case-facts--credits .case-fact {
  flex-direction: column;
  gap: 2px;
}

.case-facts--credits .case-fact dt {
  width: auto;
}

.case-fact dt {
  flex-shrink: 0;
  width: 96px;
  font-family: 'Kode Mono', monospace;
  font-weight: 600;
  font-size: 13px;
  line-height: 24px;
  text-transform: uppercase;
  color: #808080;
}

.case-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  list-style: none;
}

.case-tags li {
  padding: 4px 12px;
  border: 1px solid #3a3a3a;
  border-radius: 20px;
  font-family: 'Roboto Condensed', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: #ccc;
}

/* Stays in view while the info column scrolls past */
.case-cover {
  position: sticky;
  top: 32px;
}

.case-cover img {
  width: 100%;
  height: auto;
  border-radius: 4px;
}

/* ==========================================
   Gallery — images in a row share one height and keep their proportions:
   each grows in proportion to its aspect ratio (--ar)
   ========================================== */
.case-gallery {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.case-row {
  display: flex;
  gap: 20px;
}

.case-row .tile {
  flex: calc(var(--ar)) 1 0;
  min-width: 0;
  gap: 0;
}

/* Stop motion — the frames sit on top of each other and each one shows for a
   third of the loop; the negative delays put them in order (01, 02, 03).
   With reduced motion only the first frame shows. */
.tile-media--stop img + img {
  opacity: 0;
}

@media (prefers-reduced-motion: no-preference) {
  .tile-media--stop img {
    animation: stop-frame 1.2s steps(1) infinite;
  }

  .tile-media--stop img:nth-child(2) { animation-delay: -0.8s; }
  .tile-media--stop img:nth-child(3) { animation-delay: -0.4s; }
}

@keyframes stop-frame {
  0%       { opacity: 1; }
  33.333%  { opacity: 0; }
  100%     { opacity: 0; }
}

/* ==========================================
   Footer
   ========================================== */
.case-footer {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 60px;
  padding-top: 16px;
  border-top: 1px solid #3a3a3a;
}

.case-link {
  font-family: 'Roboto Condensed', sans-serif;
  font-weight: 500;
  font-size: 18px;
  line-height: 1.5;
  color: #808080;
  transition: color 0.2s;
}

.case-link:hover,
.case-link:focus-visible {
  color: #fff;
}

/* ==========================================
   Animations — the hidden states only apply when JS runs (html.js, set in
   the page head) and motion is allowed; case.js adds .is-in to play them.
   Intro: words slide up, text fades in, dividers draw, cover unveils.
   Gallery: each image is unveiled by a clip-path whose direction depends on
   its place in the row (like the reference: up, down, or left to right).
   ========================================== */
@media (prefers-reduced-motion: no-preference) {
  .js .case-title .word {
    display: inline-block;
    overflow: hidden;
    padding-bottom: 0.12em;
    margin-bottom: -0.12em;
    vertical-align: top;
  }

  .js .case-title .word > span {
    display: inline-block;
    opacity: 0;
    transform: translateY(100%);
    transition: transform 1.2s cubic-bezier(0.4, 0.15, 0, 1), opacity 1.2s cubic-bezier(0.4, 0.15, 0, 1);
    transition-delay: calc(var(--i) * 32ms);
  }

  .js .case-description,
  .js .case-tags {
    opacity: 0;
    transition: opacity 0.6s ease-in-out 0.4s;
  }

  .js .case-tags {
    transition-delay: 0.8s;
  }

  .js .case-fact::before {
    transform: scaleX(0);
    transition: transform 0.8s cubic-bezier(0.4, 0.15, 0, 1) 0.5s;
  }

  .js .case-fact dt,
  .js .case-fact dd {
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.6s cubic-bezier(0.4, 0.15, 0, 1) 0.6s, transform 0.6s cubic-bezier(0.4, 0.15, 0, 1) 0.6s;
  }

  .js .case-fact dd {
    transition-delay: 0.7s;
  }

  .js .case-fact:nth-child(2)::before { transition-delay: 0.55s; }
  .js .case-fact:nth-child(2) dt { transition-delay: 0.65s; }
  .js .case-fact:nth-child(2) dd { transition-delay: 0.75s; }
  .js .case-fact:nth-child(3)::before { transition-delay: 0.6s; }
  .js .case-fact:nth-child(3) dt { transition-delay: 0.7s; }
  .js .case-fact:nth-child(3) dd { transition-delay: 0.8s; }

  .js .case-cover img {
    clip-path: inset(100% 0 0 0 round 4px);
    transition: clip-path 1s cubic-bezier(0.6, 0.35, 0.15, 1) 0.3s;
  }

  .js .case-intro.is-in .case-title .word > span,
  .js .case-intro.is-in .case-fact dt,
  .js .case-intro.is-in .case-fact dd {
    opacity: 1;
    transform: none;
  }

  .js .case-intro.is-in .case-description,
  .js .case-intro.is-in .case-tags {
    opacity: 1;
  }

  .js .case-intro.is-in .case-fact::before {
    transform: none;
  }

  .js .case-intro.is-in .case-cover img {
    clip-path: inset(0 0 0 0 round 4px);
  }

  /* Gallery — the start clip and delay are variables on the tile, so the
     position rules never outrank the .is-in rule that opens the clip.
     Default (single image, or the first of three): from the bottom */
  .js .case-gallery .tile-media {
    clip-path: var(--from, inset(100% 0 0 0 round 4px));
    transition: clip-path 1s cubic-bezier(0.6, 0.35, 0.15, 1) var(--delay, 0s);
  }

  /* Two side by side: the first from the top, the second left to right */
  .case-gallery .tile:first-child:nth-last-child(2) {
    --from: inset(0 0 100% 0 round 4px);
  }

  .case-gallery .tile:nth-child(2):last-child {
    --from: inset(0 100% 0 0 round 4px);
    --delay: 0.3s;
  }

  /* Three side by side: bottom, left to right, top */
  .case-gallery .tile:nth-child(2):nth-last-child(2) {
    --from: inset(0 100% 0 0 round 4px);
    --delay: 0.1s;
  }

  .case-gallery .tile:nth-child(3):last-child {
    --from: inset(0 0 100% 0 round 4px);
    --delay: 0.2s;
  }

  .js .case-gallery .tile.is-in .tile-media {
    clip-path: inset(0 0 0 0 round 4px);
  }
}

/* ==========================================
   Mobile — cover first, then the info, then every image stacked
   ========================================== */
@media (max-width: 899px) {
  .case {
    padding: 24px 12px 60px;
  }

  .case-intro {
    grid-template-columns: minmax(0, 1fr);
  }

  .case-cover {
    position: static;
    order: -1;
  }

  .case-info {
    padding: 8px 4px 0;
  }

  .case-title {
    font-size: 28px;
  }

  .case-gallery {
    gap: 12px;
    margin-top: 40px;
  }

  .case-row {
    flex-direction: column;
    gap: 12px;
  }

  .case-row .tile {
    flex: none;
  }

  .case-footer {
    margin-top: 40px;
  }

  .case-link {
    font-size: 16px;
  }
}
