/* Case study layout — loaded by cs1.html and cs2.html after styles.css. */

/* ==========================================================================
   Two-column layout — left 1/3 (cols 1–4), right 2/3 (cols 5–12) of the
   12-column grid, inside the existing page margins and container max-width.
   Content in both columns is left-aligned.
   ========================================================================== */
:root {
  --cs-col-left: 1 / 2;
  --cs-col-right: 2 / -1;
  /* Twice the site gutter — between the two columns and between gallery images. */
  --cs-gutter: calc(var(--grid-gutter) * 4);
}

/* More generous section padding than the rest of the site (88px vs 64px,
   so 176px between sections). The space before the footer matches. */
main.case-study {
  --section-gap: calc(var(--space-8) + var(--space-3));
  padding-bottom: calc(var(--section-gap) * 2);
}

@media (max-width: 1024px) {
  main.case-study {
    --section-gap: var(--space-8);
  }
}

/* minmax(0, 1fr) keeps wide intrinsic media from stretching columns. */
main.case-study .case-study-headline,
main.case-study .case-study-hero,
main.case-study .cs-intro,
main.case-study .cs-row,
main.case-study .case-study-body {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  column-gap: var(--cs-gutter);
}

/* Default placement: right column. Opt into the left column with .cs-col-left,
   or span both with .cs-col-full. */
main.case-study .case-study-headline > *,
main.case-study .case-study-hero > *,
main.case-study .cs-intro > *,
main.case-study .cs-row > *,
main.case-study .case-study-body > * {
  grid-column: var(--cs-col-right);
  justify-self: stretch;
  width: auto;
  min-width: 0;
  max-width: none;
  margin-inline: 0;
  text-align: left;
}

main.case-study .case-study-headline > .cs-col-left,
main.case-study .case-study-hero > .cs-col-left,
main.case-study .cs-intro > .cs-col-left,
main.case-study .cs-row > .cs-col-left,
main.case-study .case-study-body > .cs-col-left {
  grid-column: var(--cs-col-left);
}

main.case-study .case-study-headline > .cs-col-full,
main.case-study .case-study-hero > .cs-col-full,
main.case-study .cs-intro > .cs-col-full,
main.case-study .cs-row > .cs-col-full,
main.case-study .case-study-body > .cs-col-full {
  grid-column: 1 / -1;
}

/* Media fills its column and sits flush left instead of centering. */
main.case-study .case-study-body img,
main.case-study .case-study-body video {
  margin-inline: 0;
}

main.case-study .case-study-body .case-study-media-center:not(.case-study-collage-media) :is(img, video) {
  width: 100%;
  max-width: 100%;
  max-height: none;
  border-radius: var(--radius-card);
}

main.case-study .case-study-media-caption {
  text-align: left;
}

/* ==========================================================================
   Headline — client name (left), headline + subheader (right).
   ========================================================================== */
.cs-client {
  margin: 0;
  font-family: var(--font-h3);
  font-size: var(--text-h3);
  font-weight: var(--weight-h3);
  line-height: 1.5;
  color: var(--color-text-secondary);
  transition: color 0.3s ease;
}

/* Season has no italic face; let the browser slant it. */
.cs-client em {
  font-synthesis: weight style;
}

.case-study--tidepool .cs-client:hover {
  color: #627cff;
}

.case-study--alpine .cs-client:hover {
  color: #f44b25;
}

.case-study--buildon .cs-client:hover {
  color: #284ff6;
}

.cs-headline-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.cs-headline {
  margin: 0;
  font-family: var(--font-h1);
  font-size: var(--text-h1);
  font-weight: var(--weight-h1);
  line-height: 1.1;
  text-wrap: balance;
  color: var(--color-text-primary);
}

.cs-subhead {
  margin: 0;
  font-family: var(--font-h2);
  font-size: var(--text-h2);
  font-weight: var(--weight-h2);
  line-height: 1.25;
  color: var(--color-text-secondary);
}

/* ==========================================================================
   Fold — title section above the gallery, spaced like any two sections.
   ========================================================================== */
:root {
  --cs-edge: max(var(--page-margin), calc((100% - var(--container-max)) / 2));
}

main.case-study > .cs-fold {
  display: flex;
  flex-direction: column;
  gap: calc(var(--section-gap) * 2);
  /* body already pads the top by --header-height for the fixed header. */
  padding: calc(var(--space-6) * 4) 0 var(--section-gap);
}

main.case-study .cs-fold > .case-study-headline {
  padding: 0 var(--cs-edge);
}

/* ==========================================================================
   Gallery — full-bleed horizontal scroller. Starts on the left margin and
   runs off the right edge; once scrolled, images pass under both edges.
   Scrolls by trackpad, touch, keyboard, or mouse drag (case-study-v2.js).
   ========================================================================== */
.cs-gallery {
  --cs-gallery-height: 35.556vw;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  cursor: grab;
}

.cs-gallery::-webkit-scrollbar {
  display: none;
}

.cs-gallery.is-dragging {
  cursor: grabbing;
  user-select: none;
}

.cs-gallery:focus-visible {
  outline: 2px solid var(--color-accent-blue);
  outline-offset: -2px;
}

.cs-gallery-track {
  display: flex;
  align-items: flex-start;
  gap: var(--space-4);
  width: max-content;
  /* Room for captions below the shared media height. */
  padding: 0 var(--cs-edge) calc(var(--text-body) * 1.4 + var(--space-2));
}

.cs-gallery-item {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin: 0;
}

/* Shared media frame; captions sit outside so they aren't clipped. */
.cs-gallery-media {
  height: var(--cs-gallery-height);
  border-radius: var(--radius-card);
  overflow: hidden;
  box-shadow: var(--shadow-card);
}

.cs-gallery-media img,
.cs-gallery-media video {
  display: block;
  width: auto;
  height: 100%;
  max-width: none;
  pointer-events: none;
}

/* Wireframe placeholders have no intrinsic size, so they keep a 3:2 frame. */
.cs-gallery-item.wf .cs-gallery-media,
.cs-gallery-item.wf,
.cs-gallery-media.wf {
  aspect-ratio: 3 / 2;
}

/* Direct media (Tidepool items without a wrapper) keep the old sizing. */
.cs-gallery-item > img,
.cs-gallery-item > video {
  display: block;
  width: auto;
  height: var(--cs-gallery-height);
  max-width: none;
  border-radius: var(--radius-card);
  pointer-events: none;
}

/* Matted items: cut-out collages sit on a white board with margins. */
.cs-gallery-item--matted .cs-gallery-media,
.cs-gallery-item--matted {
  padding: calc(var(--cs-gallery-height) * 0.08) calc(var(--cs-gallery-height) * 0.1);
  background-color: #ffffff;
  border-radius: var(--radius-card);
  box-sizing: border-box;
}

.cs-gallery-caption {
  margin: 0;
  font-family: var(--font-body);
  font-size: var(--text-body);
  font-weight: var(--weight-body);
  font-style: normal;
  line-height: 1.4;
  color: var(--color-text-secondary);
}

/* ==========================================================================
   Intro — project overview (left) beside a story excerpt (right). The
   excerpt matches the overview height, up to --cs-story-max-height (400px).
   Override per case study if needed:
     .case-study--example { --cs-story-max-height: 28rem; }
   ========================================================================== */
main.case-study .cs-intro,
main.case-study .cs-row {
  display: grid;
  column-gap: var(--cs-gutter);
  row-gap: var(--space-6);
}

main.case-study {
  --cs-story-max-height: 400px;
}

.cs-overview {
  align-self: start;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  margin: 0;
  padding: var(--space-4);
  background: var(--color-bg);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
}

.cs-overview-item {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.cs-overview-item dt {
  font-family: var(--font-h3);
  font-size: var(--text-h3);
  font-weight: var(--weight-h3);
  line-height: 1.5;
  color: var(--color-text-secondary);
}

.cs-overview-item dd {
  margin: 0;
  font-family: var(--font-body);
  font-size: var(--text-body);
  font-weight: var(--weight-body);
  line-height: 1.5;
  color: var(--color-text-primary);
}

/* Right column: excerpt + outcome, so outcome follows the excerpt even
   when the overview is taller than the 400px cap. */
.cs-story-column {
  display: flex;
  flex-direction: column;
  gap: var(--section-gap);
  min-width: 0;
}

/* Height is set in JS to min(overview, --cs-story-max-height). contain:
   size keeps the trimmed excerpt from growing the box. */
.cs-story-preview {
  contain: size;
  box-sizing: border-box;
  flex: none;
  width: 100%;
  max-height: var(--cs-story-max-height);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.cs-story-excerpt {
  position: relative;
  flex: 1 1 0;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  font-family: var(--font-body);
  font-size: var(--text-body);
  font-weight: var(--weight-body);
  line-height: 1.5;
  color: var(--color-text-primary);
}

.cs-story-excerpt p {
  margin: 0;
}

.cs-story-excerpt p:first-child {
  margin-bottom: var(--space-1);
  font-family: var(--font-hero);
  font-size: var(--text-hero);
  font-weight: var(--weight-hero);
  line-height: 1.15;
}

.cs-word {
  opacity: 0.18;
  transition: opacity 0.4s ease;
}

.cs-word.is-on {
  opacity: 1;
}

.cs-story-toggle {
  flex: none;
  align-self: flex-start;
}

/* ==========================================================================
   Outcome — "Where it stands / Where it landed / What's next".
   Lives in .cs-story-column under the excerpt; column gap provides spacing.
   ========================================================================== */
.cs-intro .cs-outcome {
  padding: 0;
}

.cs-outcome-content {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.cs-outcome-title {
  margin: 0;
  font-family: var(--font-h2);
  font-size: var(--text-h2);
  font-weight: var(--weight-h2);
  line-height: 1.2;
  color: var(--color-text-primary);
}

.cs-outcome-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin: 0;
  padding-left: 1em;
  list-style: disc;
  font-family: var(--font-body);
  font-size: var(--text-body);
  font-weight: var(--weight-body);
  line-height: 1.5;
  color: var(--color-text-primary);
}

/* ==========================================================================
   Pager — Go Home (left column), next case study (right column).
   ========================================================================== */
main.case-study .case-study-pager.cs-row {
  display: grid;
  row-gap: var(--space-2);
}

main.case-study .case-study-pager.cs-row > .case-study-pager-link,
main.case-study .case-study-pager.cs-row > .btn {
  grid-row: auto;
  justify-self: start;
  align-self: center;
}

/* ==========================================================================
   Full story — modal window opened by "Read full story". The dialog itself
   is the full-screen scroller and dimmed backdrop; the panel is the window.
   ========================================================================== */
html.has-story-open {
  overflow: hidden;
}

.cs-story-dialog {
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: rgba(10, 10, 10, 0);
  color: var(--color-text-primary);
  transition: background-color 0.4s ease;
}

.cs-story-dialog::backdrop {
  background: transparent;
}

.cs-story-dialog[open] {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: var(--space-8) var(--cs-edge);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.cs-story-dialog.is-open {
  background: rgba(10, 10, 10, 0.45);
}

.cs-story-panel {
  position: relative;
  width: 100%;
  /* 32.5rem ≈ 65 characters of body copy per line. */
  max-width: calc(32.5rem + var(--space-8) * 2);
  padding: var(--space-8);
  background: var(--color-bg);
  border-radius: var(--radius-card);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.18);
  opacity: 0;
  transform: translateY(24px) scale(0.98);
  transition: opacity 0.4s ease, transform 0.5s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.cs-story-dialog.is-open .cs-story-panel {
  opacity: 1;
  transform: none;
}

.cs-story-close {
  position: absolute;
  top: var(--space-3);
  right: var(--space-3);
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: #e4e1e1;
  color: var(--color-text-primary);
  cursor: pointer;
  transition: background-color 0.3s ease, color 0.3s ease;
}

.cs-story-close:hover,
.cs-story-close:focus-visible {
  background: rgba(39, 63, 104, 0.9);
  color: #ffffff;
}

.cs-story-close:focus-visible {
  outline: 2px solid var(--color-accent-blue);
  outline-offset: 2px;
}

.cs-story-meta {
  display: flex;
  flex-direction: column;
  padding-right: var(--space-8);
}

.cs-story-client,
.cs-story-role {
  margin: 0;
  font-family: var(--font-h3);
  font-size: var(--text-h3);
  font-weight: var(--weight-h3);
  line-height: 1.5;
}

.cs-story-heading {
  margin: 0;
  font-family: var(--font-h2);
  font-size: var(--text-h2);
  font-weight: var(--weight-h2);
  line-height: 1.2;
}

.cs-story-client {
  color: var(--color-text-primary);
}

.cs-story-role {
  color: var(--color-text-secondary);
}

.cs-story-hero {
  margin: var(--space-6) 0 0;
  font-family: var(--font-hero);
  font-size: var(--text-hero);
  font-weight: var(--weight-hero);
  line-height: 1.15;
  text-wrap: balance;
}

.cs-story-hero + .cs-story-hero {
  margin-top: var(--space-3);
}

.cs-story-body {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
  margin-top: var(--space-8);
  font-family: var(--font-body);
  font-size: var(--text-body);
  font-weight: var(--weight-body);
  line-height: 1.5;
}

.cs-story-section {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.cs-story-section p {
  margin: 0;
}

.cs-story-list {
  margin: 0;
  padding-left: 1.25em;
  list-style: disc;
}

@media (prefers-reduced-motion: reduce) {
  .cs-story-dialog,
  .cs-story-panel {
    transition: none;
  }
}

/* ==========================================================================
   Wireframe placeholders — temporary, removed once real content is in.
   ========================================================================== */
.wf {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: var(--space-2);
  background: #efefef;
  border-radius: var(--radius-card);
  font-family: var(--font-h3);
  font-size: var(--text-h3);
  font-weight: var(--weight-h3);
  color: #8a8a8a;
}

.wf--heading { min-height: 56px; }
.wf--image { aspect-ratio: 16 / 9; }

.wf-stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.wf-duo {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--grid-gutter);
}

.wf-text {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.wf-text span,
.wf-caption {
  display: block;
  height: 12px;
  background: #efefef;
  border-radius: 4px;
}

.wf-text span:nth-child(2) { width: 96%; }
.wf-text span:nth-child(3) { width: 90%; }
.wf-text span:nth-child(4) { width: 58%; }
.wf-caption { width: 40%; height: 10px; }

/* Phone: single column, stacked in source order. */
@media (max-width: 768px) {
  :root {
    --cs-col-left: 1 / -1;
    --cs-col-right: 1 / -1;
  }

  /* Fold no longer has to fit one screen; slides are a fixed share of width. */
  .cs-gallery {
    --cs-gallery-height: 45.333vw;
  }

  /* Stacked: no box to match, so the excerpt gets a fixed seven lines. */
  .cs-story-preview {
    contain: none;
  }

  .cs-story-excerpt {
    flex: none;
    height: calc(var(--text-hero) * 1.15 * 7 + var(--space-2));
  }

  /* Full story becomes a full-screen sheet. */
  .cs-story-dialog[open] {
    padding: 0;
  }

  .cs-story-panel {
    width: 100%;
    max-width: none;
    min-height: 100%;
    padding: var(--space-8) var(--page-margin) var(--space-6);
    border-radius: 0;
  }
}
