/* ==========================================================================
   case-study.css : case-study hero, project details, table of contents,
   long-form content, figures, callouts, lightbox
   ========================================================================== */

/* 1. Hero ------------------------------------------------------------------- */
.cs-hero { padding-top: 24px; }

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--t-small);
  color: var(--muted);
  margin-bottom: 28px;
  transition: color var(--dur) var(--ease);
}

.back-link svg { width: 14px; height: 14px; transition: transform var(--dur) var(--ease); }
.back-link:hover { color: var(--ink); }
.back-link:hover svg { transform: translateX(-3px); }

.cs-hero__title { margin-bottom: 14px; max-width: 16ch; }
.cs-hero__lead { max-width: 54ch; }

.cs-hero__media {
  margin-top: 36px;
  border-radius: var(--radius-lg);
  overflow: hidden;
  height: 260px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 24px 24px 0;
}

.cs-hero__media img {
  width: auto;
  max-width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center bottom;
}

@media (min-width: 768px) {
  .cs-hero { padding-top: 36px; }
  .cs-hero__media { height: 460px; margin-top: 44px; padding: 48px 48px 0; }
  .cs-hero__media--tall { height: 600px; padding: 40px 40px 0; }
}

/* a composed header image that brings its own background */
.cs-hero__media--image { height: auto; padding: 0; border-radius: 0; background: transparent; display: block; }
.cs-hero__media--image img { width: 100%; height: auto; }

/* 2. Project details -------------------------------------------------------- */
.cs-info { margin-top: 40px; }

.cs-info__grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 28px 32px;
  padding: 28px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.cs-info__grid dt { font-size: var(--t-small); color: var(--muted); margin-bottom: 6px; }
.cs-info__grid dd { margin: 0; line-height: 1.55; }
.cs-info__grid dd ul { list-style: none; padding: 0; margin: 0; }
.cs-info__grid dd li + li { margin-top: 4px; }
.cs-info__grid dd li span { color: var(--muted); }

@media (min-width: 768px) {
  .cs-info__grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 32px 40px; padding: 36px 0; }
  .cs-info__grid .span-2 { grid-column: span 2; }
}

/* summary boards directly under the details share their rules */
.cs-info .steps { border-bottom: 1px solid var(--line); }
.cs-info .info { border-top: 0; }

/* 3. Layout: contents rail + body ------------------------------------------ */
.cs-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 40px;
  margin-top: 48px;
  padding-bottom: var(--section);
}

.cs-body { min-width: 0; max-width: 720px; }

@media (min-width: 1024px) {
  .cs-layout { grid-template-columns: 220px minmax(0, 720px); column-gap: 80px; margin-top: 72px; }
  .cs-toc { position: sticky; top: 88px; align-self: start; }
}

.toc__title { font-size: var(--t-small); color: var(--muted); margin-bottom: 12px; }

.toc__list { position: relative; list-style: none; margin: 0; padding: 0; }

.toc__list::before {
  content: "";
  position: absolute;
  left: 0;
  top: 4px;
  bottom: 4px;
  width: 1px;
  background: var(--line);
}

.toc__indicator {
  position: absolute;
  left: -0.5px;
  top: 4px;
  width: 2px;
  height: 0;
  border-radius: 2px;
  background: var(--blue);
  opacity: 0;
  transition: top 0.4s var(--ease), height 0.4s var(--ease), opacity 0.3s var(--ease);
}

.toc__list.has-active .toc__indicator { opacity: 1; }

.toc__list a {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 6px 0 6px 18px;
  font-size: var(--t-ui);
  line-height: 1.45;
  color: var(--muted);
  transition: color var(--dur) var(--ease);
}

.toc__num { min-width: 18px; font-variant-numeric: tabular-nums; }
.toc__list a:hover, .toc__list a.is-active { color: var(--ink); }
.toc__list a.is-active { font-weight: 600; }
.toc__list a.is-active .toc__num { color: var(--blue); }

@media (max-width: 1023px) {
  .cs-toc { padding: 24px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
  .toc__list::before, .toc__indicator { display: none; }
  .toc__list a { padding-left: 0; }
}

@media (min-width: 600px) and (max-width: 1023px) {
  .toc__list { display: grid; grid-template-columns: 1fr 1fr; column-gap: 40px; }
}

/* mobile sticky bar (built by toc.js) */
.toc-bar {
  position: fixed;
  left: 0;
  right: 0;
  top: var(--header-current, 60px);
  z-index: 55;
  background: #fff;
  border-bottom: 1px solid var(--line);
  transform: translateY(-8px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.3s var(--ease), opacity 0.25s var(--ease), top 0.35s var(--ease);
}

.toc-bar.is-visible { transform: none; opacity: 1; pointer-events: auto; }

.toc-bar__toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 12px 0;
  text-align: left;
  font-size: var(--t-ui);
}

.toc-bar__num { color: var(--blue); font-variant-numeric: tabular-nums; }
.toc-bar__label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.toc-bar__chevron { width: 16px; height: 16px; color: var(--muted); transition: transform 0.3s var(--ease); }
.toc-bar__toggle[aria-expanded="true"] .toc-bar__chevron { transform: rotate(180deg); }

.toc-bar__panel { max-height: 0; overflow: hidden; transition: max-height 0.4s var(--ease); }
.toc-bar__toggle[aria-expanded="true"] + .toc-bar__panel { max-height: 60vh; overflow-y: auto; }
.toc-bar__panel .toc__list { padding-bottom: 12px; }
.toc-bar__panel .toc__list::before, .toc-bar__panel .toc__indicator { display: none; }
.toc-bar__panel .toc__list a { padding-left: 0; }

.toc-bar__progress {
  position: absolute;
  left: 0;
  bottom: -1px;
  height: 2px;
  width: 100%;
  background: var(--blue);
  transform: scaleX(0);
  transform-origin: left;
}

@media (min-width: 1024px) { .toc-bar { display: none; } }

/* 4. Long-form content ------------------------------------------------------ */
.cs-section { scroll-margin-top: 104px; padding-top: 80px; }
.cs-section:first-child { padding-top: 0; }

.cs-body h2 {
  font-size: var(--t-h2);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.2;
  margin-bottom: 24px;
  max-width: 24ch;
}

.cs-body h3 {
  font-size: var(--t-h3);
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.35;
  margin: 48px 0 12px;
  scroll-margin-top: 104px;
}

.cs-body h4 { font-weight: 600; margin: 32px 0 8px; }
.cs-body h2:focus, .cs-body h3:focus, .work:focus { outline: none; }
.cs-body h2 + h3 { margin-top: 8px; }

.cs-body p { max-width: 66ch; }
.cs-body p + p { margin-top: 1.25em; }

.cs-body a:not(.back-link) {
  color: var(--blue);
  background-image: linear-gradient(currentColor, currentColor);
  background-repeat: no-repeat;
  background-size: 100% 1px;
  background-position: 0 100%;
}

.cs-body .cs-meta { font-size: var(--t-small); color: var(--muted); margin: -14px 0 20px; }

.cs-body ul,
.cs-body ol { margin: 16px 0 0; padding: 0; list-style: none; max-width: 66ch; }
.cs-body ol { counter-reset: item; }

.cs-body li { position: relative; padding-left: 28px; line-height: 1.65; }
.cs-body li + li { margin-top: 10px; }

.cs-body ol > li::before {
  counter-increment: item;
  content: counter(item);
  position: absolute;
  left: 0;
  top: 0;
  color: var(--muted);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.cs-body ul > li::before {
  content: "";
  position: absolute;
  left: 9px;
  top: 0.72em;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
}

.cs-body ul + p, .cs-body ol + p { margin-top: 24px; }

/* callouts */
.callout {
  margin: 28px 0;
  padding: 22px 24px 24px;
  background: var(--blue-tint);
  border-radius: var(--radius);
  max-width: 66ch;
}

.callout p.callout__label { font-size: var(--t-small); color: var(--muted); margin: 0 0 6px; }
.callout--quote p:not(.callout__label) { font-size: var(--t-h3); font-weight: 500; line-height: 1.45; letter-spacing: -0.01em; }

/* infographic blocks inside the body */
.cs-body .info { margin: 28px 0 8px; }
.cs-body .info + h3 { margin-top: 40px; }
.cs-body .info + p { margin-top: 32px; }
.cs-body .learning { max-width: 30ch; }
.cs-body .compare { margin-top: 28px; }
.cs-body .steps { margin: 24px 0 8px; border-top: 1px solid var(--line); }
.cs-body .steps + p { margin-top: 28px; }
.cs-body .learning__heading { margin-bottom: 6px; }

/* figures */
.figure { margin: 36px 0 8px; }
.figure + .figure { margin-top: 28px; }
.figure + p, .figure + h3, .figure + h4, .figure + .callout { margin-top: 36px; }
.figure--narrow { max-width: 340px; }
.figure--medium { max-width: 540px; }

.figure__grid { display: grid; grid-template-columns: 1fr; gap: 14px; }
.figure__grid--2 { grid-template-columns: repeat(2, 1fr); }
.figure__grid--3 { grid-template-columns: repeat(3, 1fr); }
.figure__grid--4 { grid-template-columns: repeat(2, 1fr); }

@media (min-width: 640px) { .figure__grid--4 { grid-template-columns: repeat(4, 1fr); } }
@media (max-width: 520px) { .figure__grid--2, .figure__grid--3 { grid-template-columns: 1fr; } }

.figure img {
  width: 100%;
  height: auto;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  cursor: zoom-in;
  transition: border-color var(--dur) var(--ease);
}

.figure img:hover { border-color: var(--blue); }
.figure--plain img { border: 0; background: transparent; }

.figure figcaption { margin-top: 12px; font-size: var(--t-small); line-height: 1.5; color: var(--muted); }

.cs-body table { width: 100%; border-collapse: collapse; margin: 24px 0; }
.cs-body th, .cs-body td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--line); }
.cs-body th { font-weight: 600; }

/* 5. Lightbox ---------------------------------------------------------------- */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(17, 19, 26, 0.88);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s var(--ease), visibility 0s linear 0.3s;
}

.lightbox.is-open { opacity: 1; visibility: visible; transition-delay: 0s; }

.lightbox__img {
  max-width: min(92vw, 1400px);
  max-height: 86vh;
  width: auto;
  height: auto;
  border-radius: 10px;
  transform: scale(0.97);
  transition: transform 0.35s var(--ease), opacity 0.2s var(--ease);
}

.lightbox.is-open .lightbox__img { transform: none; }
.lightbox__img.is-swapping { opacity: 0; }

.lightbox__btn {
  position: absolute;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
  transition: background-color var(--dur) var(--ease);
}

.lightbox__btn:hover { background: rgba(255, 255, 255, 0.24); }
.lightbox__btn svg { width: 18px; height: 18px; }
.lightbox__close { top: 20px; right: 20px; }
.lightbox__prev { left: 20px; top: 50%; transform: translateY(-50%); }
.lightbox__next { right: 20px; top: 50%; transform: translateY(-50%); }

.lightbox__count {
  position: absolute;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  font-size: var(--t-small);
  color: rgba(255, 255, 255, 0.7);
  font-variant-numeric: tabular-nums;
}

.lightbox.is-single .lightbox__prev,
.lightbox.is-single .lightbox__next,
.lightbox.is-single .lightbox__count { display: none; }

body.lightbox-open { overflow: hidden; }

@media (max-width: 640px) {
  .lightbox { padding: 12px; }
  .lightbox__prev, .lightbox__next { top: auto; bottom: 16px; transform: none; }
  .lightbox__prev { left: 16px; }
  .lightbox__next { right: 16px; }
  .lightbox__count { bottom: 30px; }
}
