/* =========================================================
   CASE STUDY LAYOUT
   Long-form editorial layout for individual case studies.
   Builds on the design tokens from styles.css.

   Most rules below are scoped to the .case-study ancestor so
   they only apply to pages that use <main class="case-study">
   (Pinch, Viewpost). meta-design-systems.html does not use
   that class and keeps its own inline structural styles.

   The .cs-nav-next-* rules are deliberately unscoped so the
   "Next case study" block can be shared across all case
   studies, including meta-design-systems.html.
   ========================================================= */

/* Disable scroll-snap on any page that loads this stylesheet.
   styles.css sets `html { scroll-snap-type: y mandatory }`
   globally, and `.contact { scroll-snap-align: end }` adds
   a snap point at the page footer. On a long-form case study
   that's the only snap point on the page, so the browser
   force-snaps to it on load and the page lands partway down.
   Setting snap-type to none here cancels the global rule. */
html {
  scroll-snap-type: none;
}

/* =========================================================
   LAYOUT CONTAINERS
   Text content uses .cs-container (narrow, comfortable reading width).
   Visual modules use .cs-container--wide (wider for impact).
   Full-bleed elements skip containers entirely.
   ========================================================= */

.case-study {
  padding-top: var(--header-h);
  padding-bottom: var(--space-9);
}

.case-study .cs-container {
  max-width: 720px;
  margin-left: auto;
  margin-right: auto;
  padding-left: var(--gutter);
  padding-right: var(--gutter);
}

.case-study .cs-container--wide {
  max-width: 1200px;
  margin-left: auto;
  margin-right: auto;
  padding-left: var(--gutter);
  padding-right: var(--gutter);
}

/* =========================================================
   BACK LINK
   ========================================================= */

.case-study .cs-back {
  padding-top: var(--space-7);
  padding-bottom: var(--space-5);
}

.case-study .cs-back a {
  font-size: var(--fs-meta);
  font-weight: 500;
  letter-spacing: var(--ls-wide);
  text-transform: uppercase;
  color: var(--color-text-muted);
}

.case-study .cs-back a:hover {
  color: var(--color-text);
  opacity: 1;
}

/* =========================================================
   HERO
   Label, title, tagline. Centered or left-aligned (default left).
   ========================================================= */

.case-study .cs-hero {
  padding-top: var(--space-7);
  padding-bottom: var(--space-8);
}

.case-study .cs-hero-label {
  font-size: var(--fs-label);
  font-weight: 500;
  letter-spacing: var(--ls-wide);
  text-transform: uppercase;
  color: var(--color-text-muted);
  margin-bottom: var(--space-5);
}

.case-study .cs-hero-title {
  font-family: var(--font-display);
  font-size: clamp(2.5rem, 6vw, 5rem);
  font-weight: 400;
  line-height: var(--lh-tight);
  letter-spacing: var(--ls-tight);
  margin-bottom: var(--space-5);
  max-width: 18ch;
}

.case-study .cs-hero-tagline {
  font-size: clamp(1.25rem, 2vw, 1.5rem);
  line-height: var(--lh-snug);
  color: var(--color-text-muted);
  max-width: 50ch;
}

.case-study .cs-hero-image {
  margin-top: var(--space-6);
  margin-bottom: var(--space-8);
}

/* =========================================================
   METADATA
   ========================================================= */

.case-study .cs-meta {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: var(--space-3) var(--space-5);
  padding-top: var(--space-6);
  padding-bottom: var(--space-6);
  border-top: 1px solid var(--color-rule);
  border-bottom: 1px solid var(--color-rule);
  margin-bottom: var(--space-8);
}

.case-study .cs-meta dt {
  font-size: var(--fs-meta);
  font-weight: 500;
  letter-spacing: var(--ls-wide);
  text-transform: uppercase;
  color: var(--color-text-muted);
}

.case-study .cs-meta dd {
  font-size: var(--fs-body);
  color: var(--color-text);
  margin: 0;
}

/* =========================================================
   SECTIONS & TYPOGRAPHY
   ========================================================= */

.case-study .cs-section {
  padding-top: var(--space-8);
  padding-bottom: var(--space-6);
}

.case-study .cs-section + .cs-section {
  padding-top: 0;
}

.case-study .cs-section h2 {
  font-family: var(--font-display);
  font-size: clamp(1.875rem, 3vw, 2.5rem);
  font-weight: 400;
  line-height: var(--lh-tight);
  letter-spacing: var(--ls-tight);
  margin-bottom: var(--space-5);
}

.case-study .cs-section h3 {
  font-family: var(--font-display);
  font-size: clamp(1.25rem, 2vw, 1.5rem);
  font-weight: 500;
  line-height: var(--lh-snug);
  letter-spacing: var(--ls-tight);
  margin-top: var(--space-6);
  margin-bottom: var(--space-4);
}

.case-study .cs-section p {
  font-size: 1.125rem;
  line-height: var(--lh-relaxed);
  color: var(--color-text);
  margin-bottom: var(--space-4);
}

.case-study .cs-section p:last-child {
  margin-bottom: 0;
}

.case-study .cs-section ul,
.case-study .cs-section ol {
  font-size: 1.125rem;
  line-height: var(--lh-relaxed);
  padding-left: var(--space-5);
  margin-bottom: var(--space-4);
}

.case-study .cs-section li + li {
  margin-top: var(--space-3);
}

/* Lead paragraph: slightly larger opening summary */
.case-study .cs-lead {
  font-size: clamp(1.25rem, 1.6vw, 1.5rem);
  line-height: var(--lh-snug);
  color: var(--color-text);
  font-weight: 400;
  letter-spacing: var(--ls-tight);
  margin-bottom: var(--space-6);
}

/* =========================================================
   IMAGE MODULES
   ========================================================= */

.case-study .cs-image {
  margin-top: var(--space-7);
  margin-bottom: var(--space-7);
}

.case-study .cs-image img,
.case-study .cs-image-placeholder {
  width: 100%;
  display: block;
}

.case-study .cs-image img {
  border-radius: var(--radius-lg);
}

.case-study .cs-image figcaption,
.case-study .cs-image-grid figcaption {
  margin-top: var(--space-3);
  font-size: var(--fs-meta);
  line-height: var(--lh-normal);
  color: var(--color-text-muted);
  padding-left: var(--gutter);
  padding-right: var(--gutter);
}

.case-study .cs-image-grid figcaption {
  padding-left: 0;
  padding-right: 0;
}

/* Image grids */
.case-study .cs-image-grid {
  display: grid;
  gap: var(--space-5);
  margin-top: var(--space-7);
  margin-bottom: var(--space-7);
}

.case-study .cs-image-grid--two {
  grid-template-columns: 1fr 1fr;
}

.case-study .cs-image-grid--three {
  grid-template-columns: repeat(3, 1fr);
}

.case-study .cs-image-grid figure {
  margin: 0;
}

.case-study .cs-image-grid img,
.case-study .cs-image-grid .cs-image-placeholder {
  width: 100%;
  display: block;
}

.case-study .cs-image-grid img {
  border-radius: var(--radius-lg);
}

/* Placeholder visual */
.case-study .cs-image-placeholder {
  aspect-ratio: 16 / 9;
  background-color: var(--color-surface-secondary);
  border: 1px dashed var(--color-rule);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
  font-size: var(--fs-meta);
  font-weight: 500;
  letter-spacing: var(--ls-wide);
  text-transform: uppercase;
  text-align: center;
  padding: var(--space-4);
}

.case-study .cs-image-placeholder--portrait {
  aspect-ratio: 3 / 4;
}

.case-study .cs-image-placeholder--square {
  aspect-ratio: 1;
}

.case-study .cs-image-placeholder--hero {
  aspect-ratio: 16 / 9;
}

/* =========================================================
   SPLIT MODULE: text and image side by side
   Use source order to control which side is which:
   put text first for text-left/image-right, or image
   first for image-left/text-right. Stacks on mobile.
   ========================================================= */

.case-study .cs-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-6);
  align-items: start;
  margin-top: var(--space-7);
  margin-bottom: var(--space-7);
}

.case-study .cs-split > figure {
  margin: 0;
}

.case-study .cs-split-text h3 {
  margin-top: 0;
  font-family: var(--font-display);
  font-size: clamp(1.25rem, 2vw, 1.5rem);
  font-weight: 500;
  line-height: var(--lh-snug);
  letter-spacing: var(--ls-tight);
  margin-bottom: var(--space-4);
}

.case-study .cs-split-text p {
  font-size: 1.0625rem;
  line-height: var(--lh-relaxed);
  color: var(--color-text);
  margin-bottom: var(--space-3);
}

.case-study .cs-split-text p:last-child {
  margin-bottom: 0;
}

.case-study .cs-split-image img,
.case-study .cs-split-image .cs-image-placeholder {
  width: 100%;
  display: block;
  border-radius: var(--radius-lg);
}

.case-study .cs-split-image figcaption {
  margin-top: var(--space-3);
  font-size: var(--fs-meta);
  line-height: var(--lh-normal);
  color: var(--color-text-muted);
}

/* =========================================================
   PULL QUOTE
   ========================================================= */

.case-study .cs-quote {
  padding-top: var(--space-8);
  padding-bottom: var(--space-8);
  text-align: center;
  margin: 0;
}

.case-study .cs-quote p {
  font-family: var(--font-display);
  font-size: clamp(1.5rem, 2.75vw, 2.25rem);
  line-height: var(--lh-snug);
  letter-spacing: var(--ls-tight);
  font-weight: 400;
  font-style: italic;
  color: var(--color-text);
  margin: 0 auto;
  max-width: 22ch;
}

.case-study .cs-quote-attribution {
  display: block;
  margin-top: var(--space-5);
  font-family: var(--font-sans);
  font-style: normal;
  font-size: var(--fs-meta);
  font-weight: 500;
  color: var(--color-text-muted);
  letter-spacing: var(--ls-wide);
  text-transform: uppercase;
}

/* =========================================================
   STATS / METRICS
   ========================================================= */

.case-study .cs-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-6);
  padding-top: var(--space-8);
  padding-bottom: var(--space-8);
  text-align: center;
}

.case-study .cs-stat-number {
  font-family: var(--font-display);
  font-size: clamp(2.5rem, 5vw, 4rem);
  font-weight: 500;
  line-height: 1;
  letter-spacing: var(--ls-tight);
  color: var(--color-text);
  margin-bottom: var(--space-3);
}

.case-study .cs-stat-label {
  font-size: var(--fs-meta);
  color: var(--color-text-muted);
  line-height: var(--lh-normal);
  max-width: 30ch;
  margin: 0 auto;
}

/* =========================================================
   NEXT CASE STUDY LINK
   Self-contained narrow container (matches the body text
   width) so the markup is just <nav class="cs-nav-next">
   with no separate container class needed. These rules are
   intentionally UNSCOPED so the same block can be reused
   from meta-design-systems.html, which doesn't carry the
   .case-study class on its <main>.

   Left-aligned label + display title, with the "→" arrow
   appended inline on the title text. Padding lives on the
   link itself so the whole row is a comfortable hit target.
   ========================================================= */

.cs-nav-next {
  max-width: 720px;
  margin-left: auto;
  margin-right: auto;
  padding-left: var(--gutter);
  padding-right: var(--gutter);
  margin-top: var(--space-9);
  border-top: 1px solid var(--color-rule);
}

.cs-nav-next-link {
  display: block;
  padding-top: var(--space-6);
  padding-bottom: var(--space-6);
}

.cs-nav-next-label {
  display: block;
  font-size: var(--fs-label);
  font-weight: 500;
  letter-spacing: var(--ls-wide);
  text-transform: uppercase;
  color: var(--color-text-muted);
}

.cs-nav-next-title {
  display: block;
  font-family: var(--font-display);
  font-size: var(--fs-h2-section);
  font-weight: 500;
  line-height: var(--lh-snug);
  letter-spacing: var(--ls-tight);
  color: var(--color-text);
  margin-top: var(--space-2);
  transition: opacity 0.2s ease;
}

.cs-nav-next-link:hover .cs-nav-next-title {
  opacity: 0.6;
}

/* =========================================================
   RESPONSIVE
   ========================================================= */

@media (max-width: 768px) {
  .case-study .cs-hero {
    padding-top: var(--space-5);
    padding-bottom: var(--space-6);
  }

  .case-study .cs-meta {
    grid-template-columns: 100px 1fr;
  }

  .case-study .cs-section {
    padding-top: var(--space-7);
  }

  .case-study .cs-image-grid--two,
  .case-study .cs-image-grid--three {
    grid-template-columns: 1fr;
  }

  .case-study .cs-split {
    grid-template-columns: 1fr;
    gap: var(--space-5);
  }

  .case-study .cs-stats {
    grid-template-columns: 1fr;
    gap: var(--space-7);
  }

  .case-study .cs-image-grid figcaption {
    padding-left: 0;
    padding-right: 0;
  }

  .case-study .cs-image figcaption {
    padding-left: var(--gutter);
    padding-right: var(--gutter);
  }
}

/* =========================================================
   IMAGE LIGHTBOX
   Click any case study image to view it at full size in a
   focused overlay. Closes via X button, backdrop click, or
   the Escape key.
   ========================================================= */

.case-study img {
  cursor: zoom-in;
  transition: opacity 0.2s ease;
}

.case-study img:hover {
  opacity: 0.88;
}

.case-study img:focus-visible {
  outline: 2px solid var(--color-text);
  outline-offset: 4px;
}

.cs-lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.88);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(1rem, 4vw, 3rem);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
  cursor: zoom-out;
}

.cs-lightbox.open {
  opacity: 1;
  visibility: visible;
}

.cs-lightbox-image {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: var(--radius-lg);
  cursor: default;
  transform: scale(0.97);
  transition: transform 0.25s ease;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}

.cs-lightbox.open .cs-lightbox-image {
  transform: scale(1);
}

.cs-lightbox-close {
  position: absolute;
  top: clamp(1rem, 3vw, 2rem);
  right: clamp(1rem, 3vw, 2rem);
  width: 44px;
  height: 44px;
  border: none;
  background: rgba(255, 255, 255, 0.12);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  color: white;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s ease, transform 0.2s ease;
}

.cs-lightbox-close:hover {
  background: rgba(255, 255, 255, 0.22);
  transform: scale(1.05);
}

.cs-lightbox-close:focus-visible {
  outline: 2px solid white;
  outline-offset: 2px;
}

.cs-lightbox-close svg {
  width: 20px;
  height: 20px;
}

@media (prefers-reduced-motion: reduce) {
  .case-study img,
  .cs-lightbox,
  .cs-lightbox-image,
  .cs-lightbox-close {
    transition: none;
  }
  .cs-lightbox.open .cs-lightbox-image {
    transform: none;
  }
}

/* =========================================================
   COMPONENT SPEC CAROUSEL
   Horizontal-scroll carousel for showing multiple
   annotated component specs side by side. Native swipe
   on touch, button controls on desktop, dot indicators
   for position. Used in deep dives where a single image
   would undersell the breadth of the work.
   ========================================================= */

.cs-carousel {
  margin-top: var(--space-7);
  margin-bottom: var(--space-7);
  /* Break out of parent's gutter padding so the carousel
     can extend to (and overflow past) the viewport edge,
     letting slides peek in from the right on desktop. */
  margin-left: calc(var(--gutter) * -1);
  margin-right: calc(var(--gutter) * -1);
}

.cs-carousel-eyebrow {
  font-size: var(--fs-label);
  font-weight: 500;
  letter-spacing: var(--ls-wide);
  text-transform: uppercase;
  color: var(--color-text-muted);
  margin: 0 var(--gutter) var(--space-4);
}

.cs-carousel-viewport {
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scroll-padding-left: var(--gutter);
  -webkit-overflow-scrolling: touch;
  /* Hide native scrollbar across browsers */
  scrollbar-width: none;
}

.cs-carousel-viewport::-webkit-scrollbar {
  display: none;
}

.cs-carousel-track {
  list-style: none;
  margin: 0;
  padding: 0 var(--gutter);
  display: flex;
  gap: var(--space-5);
}

.cs-carousel-slide {
  flex: 0 0 min(85vw, 360px);
  scroll-snap-align: start;
}

@media (min-width: 768px) {
  .cs-carousel-slide {
    flex: 0 0 420px;
  }
}

/* ----- Spec card (slide contents) ----- */

.spec-card {
  background-color: var(--color-surface-secondary);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  height: 100%;
}

.spec-card-header {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.spec-card-eyebrow {
  font-size: var(--fs-label);
  font-weight: 500;
  letter-spacing: var(--ls-wide);
  text-transform: uppercase;
  color: var(--color-text-muted);
}

.spec-card-title {
  font-family: var(--font-display);
  font-size: var(--fs-h2-section);
  font-weight: 500;
  line-height: var(--lh-snug);
  letter-spacing: var(--ls-tight);
  color: var(--color-text);
  margin: 0;
}

.spec-card-sub {
  font-weight: 400;
  color: var(--color-text-muted);
  font-style: italic;
}

.spec-card-visual {
  aspect-ratio: 4 / 3;
  border: 1px dashed var(--color-rule);
  border-radius: var(--radius-md);
  background-color: var(--color-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.spec-card-visual img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.spec-card-placeholder {
  font-size: var(--fs-meta);
  font-weight: 500;
  letter-spacing: var(--ls-wide);
  text-transform: uppercase;
  color: var(--color-text-muted);
  text-align: center;
  padding: var(--space-4);
}

.spec-card-annotations {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  margin: 0;
}

.spec-card-annotations > div {
  display: grid;
  grid-template-columns: 100px 1fr;
  gap: var(--space-3);
  align-items: baseline;
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--color-rule);
}

.spec-card-annotations > div:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.spec-card-annotations dt {
  font-size: var(--fs-meta);
  font-weight: 500;
  letter-spacing: var(--ls-wide);
  text-transform: uppercase;
  color: var(--color-text-muted);
}

.spec-card-annotations dd {
  margin: 0;
  font-size: var(--fs-body);
  color: var(--color-text);
  line-height: var(--lh-normal);
}

/* ----- Controls (prev / next / dots) ----- */

.cs-carousel-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  margin: var(--space-5) var(--gutter) 0;
}

.cs-carousel-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--color-rule);
  background-color: transparent;
  color: var(--color-text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s ease, border-color 0.2s ease, opacity 0.2s ease;
}

.cs-carousel-btn:hover:not(:disabled) {
  background-color: var(--color-surface-secondary);
  border-color: var(--color-text-muted);
}

.cs-carousel-btn:focus-visible {
  outline: 2px solid var(--color-text);
  outline-offset: 2px;
}

.cs-carousel-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

.cs-carousel-btn svg {
  width: 18px;
  height: 18px;
}

.cs-carousel-dots {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  gap: var(--space-3);
}

.cs-carousel-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: none;
  background-color: var(--color-rule);
  padding: 0;
  cursor: pointer;
  transition: background-color 0.2s ease, transform 0.2s ease;
}

.cs-carousel-dot:hover {
  background-color: var(--color-text-muted);
}

.cs-carousel-dot.is-active {
  background-color: var(--color-text);
  transform: scale(1.25);
}

.cs-carousel-dot:focus-visible {
  outline: 2px solid var(--color-text);
  outline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {
  .cs-carousel-viewport {
    scroll-behavior: auto;
  }
  .cs-carousel-btn,
  .cs-carousel-dot {
    transition: none;
  }
}
