/* ==========================================================================
   Case study pages — built on css/tokens.css + css/site.css.
   Follow STYLE_GUIDE.md: tokens only, square images, red as a mark.
   ========================================================================== */

/* ---------- Layout: sticky sidebar + reading column ---------- */
.cs-layout {
  display: grid;
  grid-template-columns: repeat(var(--columns), minmax(0, 1fr));
  column-gap: var(--gutter);
  align-items: start;
  padding: var(--space-8) var(--panel-pad) var(--panel-pad-end);
}

/* Sidebar: left quarter (cols 1–3). Content starts at col 4, up to 900px wide */
.cs-content {
  grid-column: 4 / -1;
  min-width: 0;
  width: 100%;
  max-width: 900px;   /* left aligned; wider screens leave the right side empty */
}

/* ---------- Sidebar: back link + section index ---------- */
.cs-sidebar {
  /* Sticks below the nav once scrolled; at rest it sits level with the hero.
     It's as tall as the viewport minus equal margins, so the section index
     (pushed off the back link by auto margins) lands mid-screen. */
  --side-top: calc(var(--nav-h) + var(--space-6));
  position: sticky;
  top: var(--side-top);
  grid-column: 1 / span 3;
  height: calc(100vh - 2 * var(--side-top));
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.cs-sidebar-back + a { margin-top: auto; }
.cs-sidebar a:last-child { margin-bottom: auto; }

.cs-sidebar a {
  position: relative;
  padding-left: var(--space-4);
  font-size: var(--text-small);
  color: var(--fg-muted);
  transition: color var(--dur-fast) ease;
}

.cs-sidebar a:hover { color: var(--fg); }

/* Active section: ink text + scarlet dot */
.cs-sidebar a.is-active { color: var(--fg); }

.cs-sidebar a.is-active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0.62em;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
}

/* Back link: first item in the sidebar on desktop, a floating pill on mobile */
.cs-sidebar a.cs-sidebar-back,
.cs-back {
  font-family: var(--font-label);
  font-size: var(--text-label);
  font-weight: 500;
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
}

.cs-sidebar a.cs-sidebar-back {
  padding-left: 0;
  margin-bottom: var(--space-7);
  line-height: 1;          /* caps sit flush with the top of the hero */
  color: var(--fg);
  transition: color var(--dur-fast) ease, transform var(--dur-base) var(--ease-out);
}

.cs-sidebar a.cs-sidebar-back:hover {
  color: var(--accent-text);
  transform: translateX(-3px);
}

.cs-back-row { display: none; }

/* ---------- Title block ---------- */
.cs-eyebrow {
  font-family: var(--font-label);
  font-size: var(--text-label);
  font-weight: 500;
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--fg-muted);
  margin-bottom: var(--space-4);
}

.cs-title {
  font-size: var(--text-h1);
  font-weight: 700;
  line-height: var(--leading-heading);
  letter-spacing: var(--tracking-h1);
}

.cs-hero {
  margin-top: var(--space-7);
  aspect-ratio: 16 / 10;
  overflow: hidden;
  background: var(--surface);
}

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

/* ---------- Facts: columns on desktop, rows on mobile ---------- */
.cs-meta {
  margin-top: var(--space-7);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--gutter);
}

.cs-meta-item {
  border-top: var(--hairline) solid var(--border-strong);
  padding-top: var(--space-3);
}

.cs-meta-item h3 {
  font-family: var(--font-label);
  font-size: var(--text-label);
  font-weight: 500;
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--fg-muted);
  margin-bottom: var(--space-2);
}

.cs-meta-item p {
  font-size: var(--text-small);
  line-height: 1.45;
}

/* ---------- Sections ---------- */
.cs-section {
  margin-top: var(--space-9);
  scroll-margin-top: calc(var(--nav-h) + var(--space-6));
}

.cs-section-label {
  font-family: var(--font-label);
  font-size: var(--text-label);
  font-weight: 500;
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--fg-muted);
  border-top: var(--hairline) solid var(--border-strong);
  padding-top: var(--space-3);
  margin-bottom: var(--space-6);
}

.cs-section-heading {
  font-size: var(--text-h2);
  font-weight: 700;
  line-height: var(--leading-heading);
  letter-spacing: var(--tracking-h2);
  margin-bottom: var(--space-5);
}

/* Body text runs the full width of the content column, flush with the media */
.cs-section p,
.cs-section li {
  max-width: none;
}

.cs-section p + p { margin-top: var(--space-4); }

/* Text after any block (media, cards, callouts) gets real breathing room */
.cs-section > :not(p, .cs-section-label, .cs-section-heading) + p,
.cs-section > :not(p, .cs-section-label, .cs-section-heading) + ul,
.cs-section > :not(p, .cs-section-label, .cs-section-heading) + ol,
.cs-section > :not(p, .cs-section-label, .cs-section-heading) + .cs-subhead {
  margin-top: var(--space-7);
}

.cs-section ul,
.cs-section ol {
  margin-top: var(--space-4);
  padding-left: var(--space-5);
}

.cs-section li { margin-bottom: var(--space-2); }

.cs-section li::marker { color: var(--fg-muted); }

.cs-subhead {
  font-family: var(--font-label);
  font-size: var(--text-label);
  font-weight: 500;
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  margin-top: var(--space-6);
  margin-bottom: var(--space-3);
}

/* Pull quote: paper panel with a scarlet edge */
.cs-callout {
  margin-top: var(--space-5);
  padding: var(--space-5) var(--space-5);
  border-left: 2px solid var(--accent);
  background: var(--surface);
  font-size: var(--text-h3);
  line-height: var(--leading-h3);
}

/* ---------- Media ---------- */
.cs-image,
.cs-overlay-pair {
  position: relative;
  margin-top: var(--space-6);
}

.cs-overlay-pair { overflow: hidden; }

/* The paper well sits behind the media only, never behind captions */
.cs-image img,
.cs-image video {
  width: 100%;
  display: block;
  background: var(--surface);
}

/* Caption: small mono label under a short rule */
.cs-section .cs-image-caption {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-top: var(--space-3);
  max-width: none;
  font-family: var(--font-label);
  font-size: var(--text-label);
  font-weight: 500;
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--fg-muted);
}

.cs-image-caption::before {
  content: '';
  flex: none;
  width: var(--space-5);
  height: var(--hairline);
  background: var(--fg-muted);
}

.cs-image-row {
  margin-top: var(--space-6);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
}

.cs-image-row .cs-image { margin-top: 0; }

/* Full-page designs: equal-height thumbnails cropped from the top; the lightbox shows the full page */
.cs-pages {
  margin-top: var(--space-6);
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: var(--space-3);
}

.cs-pages .cs-image { margin-top: 0; }

.cs-pages .cs-image img {
  aspect-ratio: 1280 / 1341;
  object-fit: cover;
  object-position: top;
}

/* Video controls (injected by js/case-study.js) */
.cs-video-controls {
  position: absolute;
  top: var(--space-3);
  right: var(--space-3);
  z-index: 2;
  display: flex;
  gap: var(--space-2);
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity var(--dur-fast) ease, transform var(--dur-fast) ease;
}

.cs-image:hover .cs-video-controls,
.cs-video-controls:focus-within {
  opacity: 1;
  transform: none;
}

.cs-video-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 50%;
  background: var(--bg);
  color: var(--fg);
  cursor: pointer;
  transition: background var(--dur-fast) ease, color var(--dur-fast) ease;
}

.cs-video-btn:hover {
  background: var(--fg);
  color: var(--bg);
}

.cs-video-btn svg {
  width: 15px;
  height: 15px;
  fill: currentColor;
}

/* Second image fades in over the first on scroll */
.cs-overlay-base {
  width: 100%;
  display: block;
}

.cs-overlay-top {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity var(--dur-slow) ease;
}

.cs-overlay-pair.is-visible .cs-overlay-top { opacity: 1; }

/* ---------- Cards (pain points, takeaways) ---------- */
.cs-card-grid {
  margin-top: var(--space-6);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gutter);
}

.cs-card {
  border-top: var(--hairline) solid var(--border-strong);
  padding-top: var(--space-4);
}

.cs-card-number {
  font-family: var(--font-label);
  font-size: var(--text-label);
  font-weight: 500;
  letter-spacing: var(--tracking-label);
  color: var(--fg-muted);
  margin-bottom: var(--space-3);
}

.cs-card-icon {
  width: 24px;
  height: 24px;
  margin-bottom: var(--space-3);
  color: var(--fg);
}

.cs-card-icon svg {
  width: 100%;
  height: 100%;
}

.cs-card h4 {
  font-size: var(--text-body);
  font-weight: 600;
  line-height: 1.3;
  margin-bottom: var(--space-2);
}

.cs-card p {
  font-size: var(--text-small);
  color: var(--fg-muted);
}

/* Three-up card row */
.cs-card-grid--3 { grid-template-columns: repeat(3, 1fr); }

/* Icon + reference tag share the card's top line, e.g. icon … (1) */
.cs-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

.cs-card-top .cs-card-icon { margin-bottom: 0; }

.cs-card-ref {
  font-family: var(--font-label);
  font-size: var(--text-label);
  font-weight: 500;
  letter-spacing: var(--tracking-label);
  font-variant-numeric: tabular-nums;
  color: var(--fg-muted);
}

/* ---------- Impact stats ---------- */
.cs-stats {
  margin: var(--space-6) 0;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-7);
}

.cs-stat-value {
  font-size: var(--text-impact);
  font-weight: 700;
  line-height: 1;
  letter-spacing: var(--tracking-h1);
  font-variant-numeric: tabular-nums;
}

.cs-stat-label {
  margin-top: var(--space-2);
  max-width: 22ch;
  font-size: var(--text-small);
  color: var(--fg-muted);
}

/* ---------- Next project panel ---------- */
/* Interim styling on the new system; the layout is being redesigned */
.cs-next {
  display: flex;
  flex-direction: column;
  gap: var(--panel-pad-end);
  padding-bottom: var(--space-8);
}

.cs-next a { display: block; }

.cs-next-label {
  font-family: var(--font-head);
  font-size: var(--text-head);
  line-height: var(--leading-head);
  letter-spacing: var(--tracking-head);
  text-transform: uppercase;
}

.cs-next-title {
  font-size: var(--text-h1);
  font-weight: 700;
  line-height: var(--leading-heading);
  letter-spacing: var(--tracking-h1);
  transition: color var(--dur-fast) ease;
}

.cs-next a:hover .cs-next-title { color: var(--accent-text); }

.cs-next-desc {
  margin-top: var(--space-3);
  color: var(--fg-muted);
}

/* ==========================================================================
   Deck components — panels, tags, frames. They read --client-* tokens
   (see tokens.css) and fall back to site tokens on pages without a palette.
   ========================================================================== */

/* Intro: hero media first, then eyebrow, title and a short lead */
.cs-intro { margin-top: 0; }

.cs-hero--lead {
  margin: 0 0 var(--space-6);
  aspect-ratio: 2512 / 1448;
}

/* First block on every case study: hero image above the eyebrow and title */
.cs-hero--top { margin: 0 0 var(--space-6); }

.cs-hero .cs-image { margin-top: 0; }

/* Pages whose images carry dark text on transparency (FotoLab) get white wells */
.cs-media-white .cs-content :is(.cs-hero, .cs-image) img { background: var(--white); }
.cs-media-white .cs-hero { background: var(--white); }

.cs-intro > .cs-title + .cs-lead {
  margin-top: var(--space-5);
  font-size: var(--text-body);
}

/* Overview: problem + outcome (2 cols) beside the stacked facts (1 col) */
.cs-overview {
  margin-top: var(--space-6);
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-4);
  align-items: start;
}

.cs-overview-main { grid-column: span 2; }

.cs-overview-main,
.cs-overview-facts {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

.cs-fact {
  border-top: var(--hairline) solid var(--border-strong);
  padding-top: var(--space-3);
}

.cs-label,
.cs-fact h3 {
  font-family: var(--font-label);
  font-size: var(--text-label);
  font-weight: 500;
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--fg-muted);
}

.cs-fact h3 { margin-bottom: var(--space-2); }

.cs-overview-facts .cs-fact p {
  font-size: var(--text-small);
  line-height: 1.45;
}

.cs-section .cs-fact ul { margin-top: 0; }
.cs-section .cs-fact li { margin-bottom: 0; }

/* Panel: flat client-gray block, square corners */
.cs-panel {
  background: var(--client-panel, var(--surface));
  padding: var(--space-5);
}

/* Label row: number/priority tag + mono label */
.cs-tag-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

.cs-num-tag {
  display: inline-block;
  padding: 2px 6px;
  font-family: var(--font-label);
  font-size: var(--text-label);
  font-weight: 500;
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  font-variant-numeric: tabular-nums;
  line-height: 1.4;
  background: var(--client-hi, var(--fg));
  color: var(--client-hi-ink, var(--bg));
}

.cs-num-tag--quiet {
  background: var(--bg);
  color: var(--client-hi-ink, var(--fg));
}

.cs-panel-title {
  font-size: var(--text-h3);
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.01em;
  margin-bottom: var(--space-3);
}

.cs-section .cs-panel p:not(.cs-panel-title, .cs-label, .cs-list-head) {
  font-size: var(--text-small);
  color: var(--fg-muted);
}

/* 2x2 block grid (Starting point) and two-up rows (roadmap) */
.cs-block-grid {
  margin-top: var(--space-6);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-4);
}

/* Pull quote on a panel */
.cs-quote {
  margin-top: var(--space-6);
  padding: var(--space-6);
}

.cs-quote .cs-label {
  color: var(--fg-muted);
  margin-bottom: var(--space-5);
}

.cs-section .cs-panel.cs-quote p:not(.cs-label) {
  font-size: var(--text-body);
  color: var(--fg);
}

.cs-section .cs-panel.cs-quote .cs-quote-text {
  font-size: var(--text-h3);
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: var(--tracking-h2);
  color: var(--fg);
  margin-bottom: var(--space-4);
}

/* Media frame: client color around a demo video or screenshot */
/* Device frame: ink bezel around a screen recording or screenshot */
.cs-device {
  background: var(--ink);
  padding: var(--space-2);
  border-radius: 12px;
}

.cs-device video,
.cs-device img {
  border-radius: var(--client-media-radius, 0);
}

/* Hero variant: the frame sets the size, not a fixed crop */
.cs-hero--lead:has(.cs-device) {
  aspect-ratio: auto;
  overflow: visible;
  background: none;
}

.cs-hero--lead .cs-device video {
  width: 100%;
  display: block;
}

/* Client panels keep their brand color in both themes, so their text
   switches to the palette's on-panel ink instead of following --fg */
.cs-client-furi :is(.cs-panel, .cs-fact--panel, .cs-card--panel) {
  --fg: var(--client-on-panel);
  --fg-muted: var(--client-on-panel-muted);
  --border-strong: var(--client-on-panel);
  --bg: var(--white);
  color: var(--fg);
}

/* Facts on a panel (problem, outcome) */
.cs-fact--panel {
  border-top: 0;
  padding: var(--space-5);
  background: var(--client-panel, var(--surface));
}

.cs-fact--panel h3 { margin-bottom: var(--space-3); }

/* Impact numbers inside a fact panel */
.cs-impact {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-5);
  margin-top: var(--space-2);
}

.cs-impact-value {
  font-size: var(--text-impact);
  font-weight: 700;
  line-height: 1;
  letter-spacing: var(--tracking-h2);
  font-variant-numeric: tabular-nums;
  margin-bottom: var(--space-3);
}

.cs-section .cs-impact p:not(.cs-impact-value) {
  font-size: var(--text-small);
  color: var(--fg-muted);
}

/* Steps: text beside media, alternating sides */
.cs-steps {
  margin-top: var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-7);
}

.cs-step {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3);
  align-items: start;
}

.cs-step--wide { grid-template-columns: 1fr; }

.cs-step .cs-image { margin-top: 0; }

.cs-step-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top;
}

.cs-step-media--crop { aspect-ratio: 875 / 553; overflow: hidden; }

.cs-step--media-left .cs-step-media { order: -1; align-self: stretch; }

/* Handoff: body text beside a small document thumbnail (opens full size in the lightbox) */
.cs-handoff {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 140px;
  gap: var(--space-5);
  align-items: start;
}

.cs-handoff .cs-image { margin-top: 0; }

.cs-step-title {
  font-size: var(--text-h3);
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.01em;
  margin-bottom: var(--space-3);
}

.cs-section .cs-step-text p:not(.cs-step-title) {
  font-size: var(--text-small);
  color: var(--fg-muted);
}

.cs-section .cs-quote p strong { font-weight: 700; }

/* Sub-heading inside a section (sentence case, not a mono label) */
.cs-section .cs-subtitle {
  margin-top: var(--space-7);
  font-size: var(--text-h3);
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.01em;
}

.cs-section .cs-subtitle + p { margin-top: var(--space-3); }

/* Three-up thumbnails with a 12-column grid drawn over each */
.cs-instances {
  margin-top: var(--space-6);
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-4);
}

.cs-instance-view {
  position: relative;
  aspect-ratio: 1280 / 820;
  overflow: hidden;
  border: var(--hairline) solid var(--border-strong);
  background: var(--surface);
  margin-bottom: var(--space-3);
}

.cs-instance-view img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top left;
  display: block;
}

.cs-instance-view::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.5;
  background: repeating-linear-gradient(
    to right,
    var(--client-deep, var(--fg)) 0 1px,
    transparent 1px calc(100% / 12)
  );
}

.cs-instance .cs-label {
  display: block;
  color: var(--fg);
  margin-bottom: var(--space-1);
}

.cs-section .cs-instance p:not(.cs-label) {
  font-size: var(--text-small);
  color: var(--fg-muted);
}

/* Pipeline: two cards joined by an arrow */
.cs-pipeline {
  margin-top: var(--space-6);
  display: flex;
  align-items: stretch;
  gap: var(--space-2);
}

.cs-pipeline > .cs-panel {
  flex: 1 1 0;
  min-width: 0;
  padding: var(--space-5) var(--space-4);
}

.cs-pipeline img {
  width: 100%;
  display: block;
  aspect-ratio: 1335 / 730;
  object-fit: cover;
  border-radius: var(--client-media-radius, 0);
  margin-bottom: var(--space-3);
}

.cs-pipeline-arrow {
  align-self: center;
  font-size: var(--text-h3);
  font-weight: 700;
}

.cs-panel--deep {
  background: var(--client-deep, var(--fg));
  color: var(--client-on-deep, var(--bg));
}

.cs-panel--deep .cs-label,
.cs-panel--deep .cs-panel-title { color: var(--client-hi, var(--bg)); }

.cs-section .cs-panel--deep p:not(.cs-panel-title, .cs-label) {
  color: var(--client-on-deep, var(--bg));
}

/* Roadmap lists inside panels */
.cs-section .cs-panel ol,
.cs-section .cs-panel ul {
  margin-top: var(--space-2);
  padding-left: var(--space-5);
}

.cs-section .cs-panel li {
  font-size: var(--text-small);
  margin-bottom: var(--space-1);
}

.cs-section .cs-panel .cs-list-head {
  font-size: var(--text-small);
  color: var(--fg);
}

/* Cards on a panel instead of a top rule */
.cs-card--panel {
  border-top: 0;
  background: var(--client-panel, var(--surface));
  padding: var(--space-4);
}

/* Highlight cards: the client's accent color (FURI yellow), same in both themes */
.cs-card--hi { background: var(--client-hi, var(--surface)); }

/* ---------- Responsive ---------- */
@media (max-width: 960px) {
  .cs-meta { grid-template-columns: repeat(2, 1fr); }

  .cs-card-grid,
  .cs-card-grid--3,
  .cs-block-grid,
  .cs-step,
  .cs-instances,
  .cs-image-row { grid-template-columns: 1fr; }

  .cs-overview { grid-template-columns: 1fr; }
  .cs-overview-main { grid-column: auto; }

  .cs-step--media-left .cs-step-media { order: 0; }
  .cs-pages { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .cs-handoff { grid-template-columns: minmax(0, 1fr) 96px; gap: var(--space-4); }

  .cs-pipeline { flex-direction: column; }
  .cs-pipeline-arrow { transform: rotate(90deg); }

  /* Rows with inline 3-column overrides collapse too */
  .cs-image-row[style] { grid-template-columns: 1fr !important; }
}

@media (max-width: 860px) {
  .cs-layout { padding-top: var(--space-8); }

  .cs-content { grid-column: 1 / -1; }

  .cs-sidebar { display: none; }

  /* Facts stack into label | value rows */
  .cs-meta {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .cs-meta-item {
    display: grid;
    grid-template-columns: 38% 1fr;
    gap: var(--space-4);
    padding: var(--space-3) 0;
  }

  .cs-meta-item h3 { margin-bottom: 0; }

  .cs-meta-item:last-child { border-bottom: var(--hairline) solid var(--border-strong); }

  /* Back link floats as a pill */
  .cs-back-row {
    display: block;
    position: fixed;
    left: var(--space-4);
    bottom: var(--space-5);
    z-index: 40;
  }

  .cs-back {
    display: inline-flex;
    align-items: center;
    height: 44px;
    padding: 0 var(--space-5);
    border-radius: var(--radius-pill);
    background: var(--fg);
    color: var(--bg);
  }
}
