/* CASE STUDY PAGES (case-studies/*.html). Loads after base.css. */

.page-case-study {
  background-color: var(--linen);
}

.cs {
  --cs-radius: clamp(1.25rem, 2.5vw, 2.25rem);

  padding-top: 80px;
  color: var(--charcoal);
}

/* Rounded media box. An optional --ratio crops the photo or video to the
   mockup's shape; without it the file keeps its own ratio. */
.cs-media {
  position: relative;
  overflow: hidden;
  aspect-ratio: var(--ratio, auto);
  border-radius: var(--cs-radius);
}

.cs-media > img,
.cs-media > video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.cs-hero .row {
  display: grid;
  gap: clamp(1.75rem, 3vw, 2.25rem);
  padding-top: clamp(3rem, 7vw, 6rem);
}

.cs-hero__header {
  display: grid;
  justify-items: center;
  gap: clamp(1.25rem, 2.5vw, 1.75rem);
  text-align: center;
}

.cs-hero__title {
  font-size: clamp(2.25rem, 5.2vw, 4.5rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.05;
}

.cs-tags {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.75rem clamp(0.75rem, 1.4vw, 1.25rem);
}

.cs-tag {
  padding: 0.45rem clamp(1rem, 2.2vw, 2rem);
  font-size: clamp(0.8rem, 1.2vw, 1.05rem);
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border: 1px solid var(--charcoal);
  border-radius: 999px;
}

/* Twelve-column story grid: text runs wider than the media and crosses the
   middle. Strategy and Experience overlap rows so their media stagger. */
.cs-story .row {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  column-gap: clamp(1rem, 2vw, 1.5rem);
  row-gap: clamp(2rem, 3vw, 2.5rem);
  padding-top: clamp(3rem, 6vw, 4.5rem);
  padding-bottom: clamp(3rem, 6vw, 4.5rem);
}

.cs-block--opportunity {
  grid-column: 1 / 8;
  grid-row: 1;
  align-self: center;
}

.cs-block--video {
  grid-column: 9 / 13;
  grid-row: 1;
  justify-self: center;
  width: min(100%, 22rem);
}

/* Pages without a video put a photo in its place (marked with
   --photo on the grid). The text narrows to make room; --wide suits
   landscape photos. */
:where(.cs-story__grid--photo) .cs-block--opportunity {
  grid-column: 1 / 7;
}

.cs-block--opportunity-media {
  grid-column: 8 / 13;
  grid-row: 1;
  align-self: center;
}

.cs-block--opportunity-media--wide {
  grid-column: 7 / 13;
}

/* Beside a wide photo, pad the text so the two read as equal columns. */
:where(.cs-story__grid--wide-photo) .cs-block--opportunity {
  padding-right: clamp(1.5rem, 3.5vw, 3rem);
}

.cs-block--strategy-media {
  grid-column: 1 / 6;
  grid-row: 2 / 4;
  margin-top: clamp(1.5rem, 4vw, 3.5rem);
}

.cs-block--strategy {
  grid-column: 7 / 13;
  grid-row: 2;
  padding-top: clamp(2rem, 4.5vw, 4rem);
}

.cs-block--experience-media {
  grid-column: 8 / 13;
  grid-row: 3 / 5;
  margin-top: clamp(1rem, 2.5vw, 2.25rem);
}

.cs-block--experience {
  grid-column: 1 / 7;
  grid-row: 4;
  align-self: end;
  padding-left: 0.75rem;
}

.cs-heading {
  color: var(--clementine);
  font-size: clamp(1.75rem, 2.8vw, 2.5rem);
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1.1;
  text-transform: uppercase;
}

.cs-copy {
  margin-top: clamp(1rem, 2vw, 1.5rem);
  font-size: clamp(1.125rem, 1.6vw, 1.5rem);
  line-height: 1.5;
  text-align: justify;
}

.cs-copy strong {
  font-weight: 700;
}

.cs-goals {
  margin-top: clamp(1.75rem, 3vw, 2.5rem);
  padding: clamp(1.25rem, 2.5vw, 1.75rem) clamp(1.5rem, 3vw, 3rem);
  border: 1px solid var(--charcoal);
  border-radius: clamp(1.25rem, 2.5vw, 2rem);
}

.cs-goals__title {
  margin: 0 0 0.5rem;
  color: var(--clementine);
  font-size: clamp(1.25rem, 1.8vw, 1.6rem);
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.cs-goals__list {
  display: grid;
  gap: 0.35rem;
  font-size: clamp(1.05rem, 1.5vw, 1.4rem);
  line-height: 1.4;
}

.cs-goals__list li::before {
  content: "\2022\00a0";
}

/* PLAN (Bubba's): two photos side by side, each with a handwritten caption.
   The handwriting face comes from the shared Typekit kit (wuu3hcx). */
.cs-plan__grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(0.5rem, 1vw, 0.75rem);
  padding-top: clamp(1rem, 2vw, 1.5rem);
  padding-bottom: clamp(1rem, 2vw, 1.5rem);
}

.cs-caption {
  margin-top: clamp(0.75rem, 1.5vw, 1.25rem);
  font-family: "adobe-handwriting-ernie", sans-serif;
  font-size: clamp(1.75rem, 3.2vw, 2.75rem);
  font-weight: 400;
  font-style: normal;
  line-height: 1.2;
  text-align: center;
}

/* COLUMNS (Bubba's): two equal-width text blocks. */
.cs-columns__grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(2rem, 4vw, 3.5rem);
  padding-top: clamp(3rem, 6vw, 4.5rem);
  padding-bottom: clamp(3rem, 6vw, 4.5rem);
}

/* REALITY (Bubba's): phone video on the left, captioned photo on the right. */
.cs-reality__grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  column-gap: clamp(1rem, 2vw, 1.5rem);
  row-gap: clamp(2rem, 3vw, 2.5rem);
  align-items: center;
  padding-top: clamp(1.5rem, 3vw, 2.5rem);
  padding-bottom: clamp(3rem, 6vw, 4.5rem);
}

.cs-reality__video {
  grid-column: 1 / 5;
  justify-self: start;
  width: min(100%, 22rem);
}

.cs-reality__photo {
  grid-column: 5 / 13;
}

/* VIDEO: paused and muted on load (see index.js). Every .cs-video is shown
   inside an iPhone frame. The insets below are the screen's position in
   iphone-mockup.svg (viewBox 182.56 x 370.88), as percentages of the frame. */
.cs-video {
  --screen-top: 1.906%;
  --screen-right: 4.519%;
  --screen-bottom: 1.906%;
  --screen-left: 4.875%;

  isolation: isolate;
  overflow: visible;
  aspect-ratio: 182.56 / 370.88;
  border-radius: 0;
}

/* Bezel and dynamic island sit above the video; clicks pass through. */
.cs-video::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 2;
  background: url("../assets/images/case-studies/iphone-mockup.svg") center / 100% 100% no-repeat;
  pointer-events: none;
}

.cs-video > .cs-video__player {
  position: absolute;
  top: var(--screen-top);
  left: var(--screen-left);
  z-index: 1;
  width: calc(100% - var(--screen-left) - var(--screen-right));
  height: calc(100% - var(--screen-top) - var(--screen-bottom));
  border-radius: 16.6% / 7.7%;
  cursor: pointer;
}

.cs-video__play,
.cs-video__mute {
  position: absolute;
  z-index: 3;
  display: grid;
  place-items: center;
  color: var(--linen);
  background-color: rgb(51 51 51 / 0.55);
  border: 0;
  border-radius: 50%;
  transition:
    opacity 200ms ease,
    background-color 180ms ease,
    transform 220ms ease-out;
}

.cs-video__play {
  top: 50%;
  left: 50%;
  width: clamp(3.5rem, 6vw, 4.5rem);
  height: clamp(3.5rem, 6vw, 4.5rem);
  transform: translate(-50%, -50%);
}

.cs-video__mute {
  right: calc(var(--screen-right) + 0.85rem);
  bottom: calc(var(--screen-bottom) + 0.85rem);
  width: 2.75rem;
  height: 2.75rem;
}

.cs-video__play:hover,
.cs-video__play:focus-visible,
.cs-video__mute:hover,
.cs-video__mute:focus-visible {
  background-color: rgb(241 129 34 / 0.9);
}

.cs-video__play:focus-visible,
.cs-video__mute:focus-visible {
  outline: 3px solid var(--linen);
  outline-offset: 2px;
}

.cs-video__icon {
  width: 55%;
  height: 55%;
  fill: currentColor;
}

/* Show the icon for the action each button will take. */
.cs-video.is-playing .cs-video__icon--play,
.cs-video:not(.is-playing) .cs-video__icon--pause,
.cs-video.is-muted .cs-video__icon--sound,
.cs-video:not(.is-muted) .cs-video__icon--muted {
  display: none;
}

/* While playing, the pause button hides until the video is hovered or focused. */
.cs-video.is-playing .cs-video__play {
  opacity: 0;
}

.cs-video.is-playing:hover .cs-video__play,
.cs-video.is-playing .cs-video__play:focus-visible {
  opacity: 1;
}

/* IMPACT: linen circles with a soft clementine glow outside each one. */
.cs-impact .row {
  display: grid;
  justify-items: center;
  gap: clamp(2.5rem, 5vw, 4rem);
  padding-top: clamp(2.5rem, 5vw, 4rem);
  padding-bottom: clamp(2.5rem, 5vw, 4rem);
}

/* One row of five on desktop (5 circles + 4 gaps always fit the width);
   3 + 2 on tablet and mobile (see the 1080px and 600px blocks). */
.cs-stats {
  --stat-size: clamp(8.75rem, 14.5vw, 13.5rem);
  --stat-gap: clamp(1.25rem, 2.6vw, 2rem);

  display: flex;
  justify-content: center;
  gap: var(--stat-gap);
  width: min(100vw - 2rem, 76rem);
  padding-bottom: clamp(1rem, 2vw, 1.5rem);
}

.cs-stat {
  display: grid;
  flex: none;
  place-content: center;
  width: var(--stat-size);
  aspect-ratio: 1;
  padding: 1rem;
  font-size: clamp(0.85rem, 1.25vw, 1.15rem);
  font-weight: 700;
  line-height: 1.25;
  text-align: center;
  text-transform: uppercase;
  background-color: var(--linen);
  border: 1px solid var(--charcoal);
  border-radius: 50%;
  box-shadow:
    0 0.75rem 1.75rem rgb(241 129 34 / 0.3),
    0 0 2.5rem 0.25rem rgb(241 129 34 / 0.18);
}

.cs-stat__number {
  display: block;
}

/* Circles grow and pop in one at a time once the row scrolls into view.
   index.js adds .is-visible to the .reveal list; the list itself stays put
   so only the circles move. Reduced motion shows them at once (see below). */
.cs-stats.reveal {
  opacity: 1;
  transform: none;
}

.cs-stats.reveal .cs-stat {
  opacity: 0;
  transform: scale(0.3);
}

.cs-stats.reveal.is-visible .cs-stat {
  animation: cs-stat-pop 650ms cubic-bezier(0.34, 1.56, 0.64, 1) both;
  animation-delay: calc(var(--pop-order, 0) * 160ms);
}

.cs-stat:nth-child(2) { --pop-order: 1; }
.cs-stat:nth-child(3) { --pop-order: 2; }
.cs-stat:nth-child(4) { --pop-order: 3; }
.cs-stat:nth-child(5) { --pop-order: 4; }

@keyframes cs-stat-pop {
  from {
    opacity: 0;
    transform: scale(0.3);
  }

  60% {
    opacity: 1;
  }

  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* GALLERY: full-width strip that scrolls like the About page brands
   (see .autoscroll in base.css). */
.cs-gallery {
  --autoscroll-gap: clamp(0.5rem, 1vw, 0.75rem);
  /* Long list: ~180s keeps the pace close to the About brands strip. */
  --autoscroll-duration: 180s;
  --gallery-height: clamp(14rem, 28vw, 26rem);

  padding-top: clamp(1.5rem, 3vw, 2.5rem);
  padding-bottom: clamp(1.5rem, 3vw, 2.5rem);
}

/* Every photo shares the strip height; its width follows its own ratio. */
.cs-gallery__item {
  flex: none;
  height: var(--gallery-height);
  overflow: hidden;
  border-radius: clamp(0.75rem, 1.5vw, 1.25rem);
}

.cs-gallery__item > img {
  display: block;
  width: auto;
  height: 100%;
}

/* NEXT PROJECT: the bottom padding clears the marquee's top half. */
.cs-next .row {
  display: grid;
  justify-items: center;
  padding-top: clamp(3rem, 6vw, 5rem);
  padding-bottom: calc(clamp(2.5rem, 5vw, 4rem) + var(--marquee-overlap));
}

/* Larger Next Project pill. Scales up with the screen; phones keep the
   standard .btn--gradient size. */
.cs-next .btn {
  padding: clamp(0.75rem, 1.2vw, 1.1rem) clamp(1.75rem, 3.4vw, 3rem);
  font-size: clamp(1rem, 1.7vw, 1.6rem);
}

/* Safari before 15 has no aspect-ratio. Percentage top padding on a
   pseudo-element gives the same box (padding % follows the width), and the
   media is laid over it. Modern browsers skip this block. */
@supports not (aspect-ratio: 1) {
  .cs-media[style*="--ratio"]::before {
    content: "";
    display: block;
    padding-top: calc(100% / (var(--ratio)));
  }

  .cs-media[style*="--ratio"] > img,
  .cs-media[style*="--ratio"] > video {
    position: absolute;
    top: 0;
    left: 0;
  }

  .cs-video::before {
    content: "";
    display: block;
    padding-top: calc(370.88 / 182.56 * 100%);
  }

  .cs-stat {
    height: var(--stat-size);
  }
}

/* Navbar collapses, 1080px and below */
@media (max-width: 1080px) {

  /* Tablet: wrap to 3 + 2 by capping the list at three circles wide. */
  .cs-stats {
    flex-wrap: wrap;
    max-width: calc(var(--stat-size) * 3 + var(--stat-gap) * 2);
  }
}

/* Large tablets, 768px and below */
@media (max-width: 768px) {

  /* Case study: one column, each heading and its text before its media. */
  .cs-story .row {
    grid-template-columns: minmax(0, 1fr);
  }

  .cs-story .row > * {
    grid-column: 1;
    grid-row: auto;
    align-self: auto;
    margin-top: 0;
    padding: 0;
  }

  .cs-block--video {
    width: min(100%, 16rem);
  }

  /* Bubba's rows stack: plan photos, then text, then photo above phone. */
  .cs-plan__grid,
  .cs-columns__grid,
  .cs-reality__grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .cs-plan__grid {
    gap: clamp(1.5rem, 5vw, 2rem);
  }

  .cs-reality__video,
  .cs-reality__photo {
    grid-column: 1;
    grid-row: auto;
  }

  .cs-reality__video {
    order: 1;
    justify-self: center;
    width: min(100%, 16rem);
  }

  .cs-block--opportunity-media,
  .cs-block--strategy-media,
  .cs-block--experience-media {
    justify-self: center;
    width: min(100%, 30rem);
  }
}

/* Phones, 600px and below */
@media (max-width: 600px) {

  /* Narrow justified lines leave wide gaps, so phones align left. */
  .cs-copy {
    text-align: left;
  }

  /* Phones: shrink the circles so three fit across the screen. */
  .cs-stats {
    --stat-gap: 0.75rem;
    --stat-size: min(8.75rem, (100vw - 2rem - 2 * var(--stat-gap)) / 3);
  }

  .cs-stat {
    padding: 0.5rem;
    font-size: clamp(0.66rem, 2.9vw, 0.85rem);
  }
}

/* Prefers reduced motion */
@media (prefers-reduced-motion: reduce) {
  /* Case study photos: a still strip visitors can swipe or scroll instead. */
  .cs-gallery__viewport {
    overflow-x: auto;
  }

  .cs-video__play,
  .cs-video__mute {
    transition: none;
  }

  .cs-stats.reveal .cs-stat,
  .cs-stats.reveal.is-visible .cs-stat {
    opacity: 1;
    transform: none;
    animation: none;
  }
}

/* Safari 14.0 ignores gap on flex containers (see the matching block in
   base.css). Modern browsers skip this block. */
@supports not (inset: 0) {
  /* Wrapping tags: half-gap margins on each tag, offset on the list. */
  .cs-tags {
    margin: -0.375rem calc(clamp(0.75rem, 1.4vw, 1.25rem) / -2);
  }

  .cs-tag {
    margin: 0.375rem calc(clamp(0.75rem, 1.4vw, 1.25rem) / 2);
  }

  .cs-stat + .cs-stat {
    margin-left: var(--stat-gap);
  }

  /* Tablet and phone: 3 + 2, so the third and fifth circles end a row. */
  @media (max-width: 1080px) {
    .cs-stat + .cs-stat {
      margin-left: 0;
    }

    .cs-stat {
      margin-right: var(--stat-gap);
    }

    .cs-stat:nth-child(3n),
    .cs-stat:last-child {
      margin-right: 0;
    }

    .cs-stat:nth-child(n + 4) {
      margin-top: var(--stat-gap);
    }
  }
}
