/* Case study template (Waysorted · Adaapt · Medwiki). Desktop 1280 / mobile 390.
   Per project: set --accent and --accent-soft on .case--<project> (see waysorted.css).
   Desktop grid at 1280: 40 | TOC 140 | content 840 | 40 | details 180 | 40. */

.case-page {
  --accent: var(--text);
  --accent-soft: var(--surface);
  --case-ink: rgba(0, 0, 0, 0.72);
  --case-muted: #6b6b6b;
  --case-line: rgba(0, 0, 0, 0.08);
}

/* ------------------------------------------------------------------
   Layout: sticky TOC rail · content · sticky project details
   ------------------------------------------------------------------ */
.case {
  display: grid;
  grid-template-columns: 140px minmax(0, 840px) 220px;
  justify-content: center;
  align-items: start;
  padding: 170px 40px 0;   /* ends at the last line (the footer margin is the gap) */
}
.case-main { grid-column: 2; display: flex; flex-direction: column; gap: 80px; min-width: 0; }
.case-toc { grid-column: 1; grid-row: 1; position: sticky; top: 120px; }
.case-details { grid-column: 3; grid-row: 1; margin-left: 40px; position: sticky; top: 120px; }
.case-main > [id], .case-sec[id] { scroll-margin-top: 120px; }

/* 768–1279: base.css zooms the whole 1280 layout (tablet = desktop scaled), so no tablet rules here. */
@media (max-width: 767px) {
  .case { display: block; padding: 88px var(--gutter) 0; }
  .case-main { gap: 48px; }
  .case-main > [id], .case-sec[id] { scroll-margin-top: 88px; }
}

/* ------------------------------------------------------------------
   Desktop TOC rail
   ------------------------------------------------------------------ */
.case-toc ol { display: flex; flex-direction: column; align-items: flex-start; gap: 14px; }
.case-toc a {
  display: flex; align-items: center; gap: 6px;
  padding: 2px 0;
  font-size: 12px; line-height: 15px;
  color: rgba(18, 18, 18, 0.4);
  white-space: nowrap;
  transition: color 160ms;
}
.case-toc a:hover { color: var(--text); }
.case-toc svg {
  display: none; flex: none;
  width: 9px; height: 8.4px; margin-right: 0; overflow: visible; margin-top: -0.6px;
  fill: none; stroke: currentColor; stroke-width: 1.4; stroke-linecap: round; stroke-linejoin: round;
}
.case-toc a[aria-current] { color: var(--accent); font-weight: 500; }
.case-toc a[aria-current] svg { display: block; }
/* passed sections keep a check mark (accent) next to their muted label */
.case-toc a.is-done svg { display: block; color: var(--accent); }
.case-toc a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* ------------------------------------------------------------------
   Project details (right rail)
   ------------------------------------------------------------------ */
.case-details { display: flex; flex-direction: column; gap: 48px; width: 180px; }
.case-details__label { font-size: 20px; line-height: 22px; color: var(--muted); letter-spacing: 0; }
.case-details p { margin-top: 12px; font-size: 13px; line-height: 20px; color: #000; }
.case-details__list { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; font-size: 13px; line-height: 18px; color: #000; }
.case-details .abtn { align-self: flex-start; }

/* ------------------------------------------------------------------
   Hero
   ------------------------------------------------------------------ */
.case-hero { display: flex; flex-direction: column; gap: 20px; max-width: 640px; margin-top: 144px; }
.case-hero__title { font-size: 40px; line-height: 40px; letter-spacing: -0.015em; color: #000; }
.case-hero__intro { font-size: 14px; line-height: 21px; color: var(--case-ink); }
.case-hero__intro, .case-sub { position: relative; top: 1px; }
.case-figures b { position: relative; top: 1px; }
.case-hero__intro em { font-style: normal; color: var(--accent); }
.case-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.case-chips li {
  min-width: var(--w, 0); text-align: center;
  padding: 6px 12px; border-radius: 999px; background: var(--surface);
  font-size: 12px; line-height: 18px; color: #000;
}
.case-meta { display: flex; gap: 20px; padding-top: 12px; margin: 0; }
.case-meta > div { width: 136px; display: flex; flex-direction: column; gap: 4px; }
.case-meta dt { font-size: 11px; line-height: 17px; color: var(--case-muted); }
.case-meta dd { margin: 0; font-size: 12px; line-height: 18px; color: #000; }

@media (max-width: 767px) {
  .case-hero { max-width: none; margin-top: 0; }
  .case-hero__title { font-size: 32px; line-height: 32px; }
  .case-hero__intro { font-size: 15px; line-height: 23px; }
  .case-chips li { font-size: 13px; line-height: 20px; }
  .case-meta { display: grid; grid-template-columns: repeat(2, minmax(0, 159px)); gap: 20px 16px; }
  .case-meta > div { width: auto; }
  .case-meta dt { font-size: 12px; line-height: 18px; }
  .case-meta dd { font-size: 13px; line-height: 20px; }
}

/* ------------------------------------------------------------------
   Section text blocks
   ------------------------------------------------------------------ */
.case-sec { display: flex; flex-direction: column; gap: 32px; }
.case-text { display: flex; flex-direction: column; gap: 16px; max-width: 640px; }
.case-eyebrow { font-size: 11px; line-height: 17px; color: var(--accent); }
.case-h2 { font-family: var(--serif); font-weight: 500; font-size: 28px; line-height: 31px; letter-spacing: -0.01em; color: #000; }
.case-p { font-size: 13px; line-height: 20px; color: var(--case-ink); }
.case-sub { font-size: 14px; line-height: 21px; font-weight: 500; color: #000; margin-top: 24px; }
.case-text > .case-sub:first-child { margin-top: 0; }
.case-sub--icon { display: flex; align-items: center; gap: 10px; min-height: 32px; top: 0; }
.case-sub--icon span { position: relative; top: 2px; }
.case-sub--icon svg {
  flex: none; width: 32px; height: 32px; border-radius: 8px; background: var(--accent-soft);
  fill: none; stroke: var(--accent); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round;
}
.case-list { display: flex; flex-direction: column; gap: 10px; }
.case-list li { display: grid; grid-template-columns: 8px minmax(0, 1fr); gap: 12px; font-size: 13px; line-height: 20px; color: var(--case-ink); }
.case-list li::before { content: '–'; color: rgba(0, 0, 0, 0.4); }

/* numbered phases (Process) */
.case-phases { display: flex; flex-direction: column; }
.case-phases li {
  display: flex; align-items: center; gap: 16px;
  padding: 14px 0; border-top: 1px solid var(--case-line);
  font-size: 12px; line-height: 18px; color: var(--case-muted);
}
.case-phases li:last-child { border-bottom: 1px solid var(--case-line); }
.case-phases li > span { width: var(--w, auto); white-space: nowrap; flex: none; }
.case-phases b { flex: 1; font-weight: 400; font-size: 13px; line-height: 20px; color: #000; }

/* inline survey figures (Synthesis) */
.case-figures { display: flex; flex-wrap: wrap; }
.case-figures li { width: 160px; display: flex; flex-direction: column; gap: 4px; }
.case-figures b { font-weight: 500; font-size: 26px; line-height: 29px; letter-spacing: -0.03em; color: #000; }
.case-figures span { width: 150px; font-size: 12px; line-height: 18px; color: var(--case-muted); }

@media (max-width: 767px) {
  .case-text { max-width: none; }
  .case-eyebrow { font-size: 12px; line-height: 18px; }
  .case-h2 { font-size: 24px; line-height: 27px; }
  .case-p { font-size: 14px; line-height: 21px; }
  .case-sub { font-size: 15px; line-height: 21px; }
  .case-hero__intro, .case-sub, .case-sub--icon span, .case-figures b { top: 0; }
  /* Chrome vs Figma baseline: 14px Instrument Sans sits 1px high, 12px sits 1px low */
  .case-p, .case-list li, .case-phases b { position: relative; top: 1px; }
  .case-eyebrow, .case-fig figcaption { position: relative; top: -1px; }
  .case-chips li { min-width: var(--wm, 0); }
  .case-phases li > span { width: var(--wm, auto); }
  .case-list li { grid-template-columns: 9px minmax(0, 314px); font-size: 14px; line-height: 21px; }
  .case-phases li { font-size: 13px; line-height: 20px; }
  .case-phases b { font-size: 14px; line-height: 21px; }
  .case-figures { gap: 24px 16px; }
  .case-figures li { width: 159px; }
  .case-figures b { font-size: 24px; line-height: 26px; }
  .case-figures span { font-size: 13px; line-height: 20px; }
}

/* ------------------------------------------------------------------
   Impact card (pattern backdrop + stat cards with pixel meters)
   ------------------------------------------------------------------ */
.case-impact { position: relative; padding: 28px 40px; border-radius: 32px; background: #fff; overflow: hidden; isolation: isolate; }
.case-impact__pattern { position: absolute; left: 0; top: -8.08px; width: 100%; height: 540.16px; max-width: none; z-index: -1; }
.case-impact__card { display: flex; flex-direction: column; gap: 16px; padding: 36px; border-radius: 24px; background: #fff; }
.case-stats { display: flex; align-items: flex-start; gap: 16px; }
.case-stat {
  flex: 1 1 0; min-width: 0;
  display: flex; flex-direction: column; gap: 8px;
  padding: 21px; border-radius: 20px; box-shadow: inset 0 0 0 1px var(--case-line);
}
.case-stat b { font-weight: 500; font-size: 36px; line-height: 40px; letter-spacing: -0.03em; color: var(--accent); }
.case-stat strong { font-weight: 500; font-size: 12px; line-height: 18px; color: #000; }
.case-stat span:last-child { font-size: 12px; line-height: 18px; color: var(--case-muted); }
.case-stat b.is-counting { font-variant-numeric: tabular-nums; }   /* only while the count-up runs (case.js) */
.case-meter { display: flex; gap: 3px; }
.case-meter i { width: 10px; height: 10px; border-radius: 1.5px; background: var(--accent-soft); }
.case-meter i.on { background: var(--accent); }

@media (max-width: 767px) {
  .case-impact { padding: 12px; border-radius: 24px; }
  .case-impact__pattern { top: 0; height: 100%; }
  .case-impact__card { padding: 20px; border-radius: 18px; }
  .case-stats { flex-direction: column; align-items: stretch; gap: 12px; }
  .case-stat { padding: 17px; border-radius: 16px; }
  .case-stat b { font-size: 30px; line-height: 33px; }
  .case-stat strong, .case-stat span:last-child { font-size: 13px; line-height: 20px; }
  .case-impact__card > .case-p { margin-top: 0; }
}

/* ------------------------------------------------------------------
   Figures: fixed-size Figma diagrams (.fc, generated by figgen.py) zoomed to the column
   ------------------------------------------------------------------ */
.case-fig { display: flex; flex-direction: column; gap: 12px; }
.case-fig > img { width: 100%; height: auto; }
.case-fig figcaption { font-size: 11px; line-height: 17px; color: var(--case-muted); }
@media (max-width: 767px) { .case-fig figcaption { font-size: 12px; line-height: 18px; } }

.fc { position: relative; overflow: hidden; flex: none; font-family: var(--sans); color: #000; }
.fc div, .fc img { position: absolute; margin: 0; max-width: none; }
.fc img { display: block; }
.fc-li { display: block; white-space: pre-wrap; }
.fc-li.is-b { position: relative; padding-left: 1.45em; }
.fc-li.is-b::before { content: '•'; position: absolute; left: 0.5em; }

/* ------------------------------------------------------------------
   Shipped gallery (stage + caption + prev/next + thumbnails, optional Desktop/Mobile view toggle)
   Designed at 960 (desktop, zoomed by case.js to the column) and 342 (mobile).
   ------------------------------------------------------------------ */
@media (min-width: 768px) { .case .gallery[data-fit] { zoom: calc(840 / 960); } }
.gallery { --thumb-w: 92px; --thumb-h: 58px; width: 960px; display: flex; flex-direction: column; align-items: center; gap: 24px; }
.gallery:focus-visible { outline: none; }
.gallery__views { align-self: stretch; display: flex; gap: 28px; }
.gallery__view { display: flex; align-items: center; gap: 14px; font-size: 18px; line-height: 22px; font-weight: 500; color: rgba(18, 18, 18, 0.4); }
.gallery__view > span:first-child { width: 40px; height: 40px; border-radius: 8px; background: #ededed; display: grid; place-items: center; color: var(--text); }
.gallery__view[aria-pressed="true"] { color: var(--text); }
.gallery__view[aria-pressed="true"] > span:first-child { background: var(--text); color: #fff; }
.gallery__stage {
  position: relative; width: 100%; aspect-ratio: 960 / 486;
  border-radius: 16px; overflow: hidden;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.07);
}
.gallery__stage::after { content: ''; position: absolute; inset: 0; border-radius: inherit; box-shadow: inset 0 0 0 1px rgba(18, 18, 18, 0.08); pointer-events: none; }
.gallery__stage img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.gallery__stage img.is-entering { animation: gallery-in 360ms var(--ease) both; }
@keyframes gallery-in { from { opacity: 0; } }
.gallery__caption { min-height: 18.29px; position: relative; top: 1.15px; align-self: stretch; font-size: 13px; line-height: 18px; color: var(--case-muted); white-space: pre-wrap; }
.gallery [hidden] { display: none !important; }
.gallery__controls { display: flex; align-items: center; gap: 24px; }
.gallery__arrow {
  flex: none; width: 48px; height: 48px; border-radius: 999px; background: #ededed; color: #121212;
  transition: background-color 160ms, transform 160ms var(--ease);
}
.gallery__arrow:hover { background: #e2e2e2; }
.gallery__arrow:active { transform: scale(0.95); }
.gallery__arrow svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.gallery__thumbs { display: flex; gap: 12px; }
.gallery__thumb {
  position: relative; flex: none; width: var(--thumb-w); height: var(--thumb-h);
  border-radius: 6px; overflow: hidden; opacity: 0.7;
  transition: opacity 160ms;
}
.gallery__thumb img { width: 100%; height: 100%; object-fit: cover; }
.gallery__thumb::after { content: ''; position: absolute; inset: 0; border-radius: inherit; box-shadow: inset 0 0 0 1px rgba(18, 18, 18, 0.1); }
.gallery__thumb:hover { opacity: 0.9; }
.gallery__thumb[aria-current="true"] { opacity: 1; }
.gallery__thumb[aria-current="true"]::after { box-shadow: inset 0 0 0 2px #121212; }
.gallery__arrow:focus-visible, .gallery__thumb:focus-visible, .gallery__view:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

@media (max-width: 767px) {
  .gallery { --thumb-w: 16px; --thumb-h: 34px; width: 342px; gap: 16px; }
  .gallery__stage { aspect-ratio: 342 / 173; border-radius: 8px; }
  .gallery__caption { min-height: 0; top: 0; }
  .gallery__controls { gap: 8px; }
  .gallery__arrow { width: 32px; height: 32px; }
  .gallery__thumbs { gap: 5px; }
  .gallery__thumb { border-radius: 3px; }
  .gallery__stage { cursor: zoom-in; }   /* tap → full-screen Piece viewer (case.js) */
}

/* ------------------------------------------------------------------
   Mobile TOC: floating button bottom-left → popover
   ------------------------------------------------------------------ */
.case-mtoc { position: fixed; left: 16px; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); z-index: 40; width: 260px; height: 56px; pointer-events: none; }
.case-mtoc__btn {
  position: absolute; left: 0; bottom: 0; pointer-events: auto;
  width: 56px; height: 56px; border-radius: 16px; background: var(--accent);
  box-shadow: 0 8px 20px color-mix(in srgb, var(--accent) 30%, transparent);
  transition: transform 160ms var(--ease);
}
.case-mtoc__btn:active { transform: scale(0.96); }
.case-mtoc__btn i { position: absolute; left: 17px; height: 2.4px; border-radius: 2px; background: #fff; }
.case-mtoc__btn i:nth-child(1) { top: 21px; width: 22px; }
.case-mtoc__btn i:nth-child(2) { top: 27px; width: 16px; }
.case-mtoc__btn i:nth-child(3) { top: 33px; width: 10px; }
.case-mtoc__btn:focus-visible { outline: 2px solid var(--text); outline-offset: 3px; }
.case-mtoc__pop {
  position: absolute; left: 0; bottom: 68px; width: 260px;
  padding: 14px 20px; border-radius: 16px; background: #f3f3f3;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.1);
  opacity: 0; transform: translateY(10px); visibility: hidden;
  transition: opacity 200ms var(--ease), transform 240ms var(--ease), visibility 0s 240ms;
}
.case-mtoc.is-open .case-mtoc__pop { opacity: 1; transform: none; visibility: visible; pointer-events: auto; transition: opacity 200ms var(--ease), transform 240ms var(--ease); }
.case-mtoc__pop a {
  display: flex; align-items: center; gap: 10px; height: 36px;
  font-size: 16px; line-height: 20px; letter-spacing: -0.01em; color: #7a7a7a;
}
.case-mtoc__pop svg { flex: none; width: 14px; height: 14px; fill: none; stroke: var(--accent); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; visibility: hidden; }
.case-mtoc__pop a.is-done { color: #161616; font-weight: 500; }
.case-mtoc__pop a.is-done svg { visibility: visible; }
.case-mtoc__pop a[aria-current]::after {
  content: ''; width: 10px; height: 10px; border-radius: 50%; background: var(--accent);
  box-shadow: 0 0 12px 2px color-mix(in srgb, var(--accent) 55%, transparent);
}
.case-mtoc__pop a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
@media (max-width: 767px) { .case-impact .case-eyebrow { top: 0; } }

/* ------------------------------------------------------------------
   Gallery with Desktop/Mobile view toggle (component "Shipped gallery" View=Desktop|Mobile, used by
   Adaapt and Medwiki). Only applies to galleries carrying [data-view]; Waysorted's gallery is untouched.
   Design: 960 × stage 600 (desktop) · 342 × stage 214 / 380 (mobile). Mobile-view slides are
   .gallery__phone[data-slide] wrappers holding a phone screenshot centred on a #f5f5f5 stage.
   ------------------------------------------------------------------ */
.gallery__view svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.gallery[data-view] .gallery__stage { aspect-ratio: 960 / 600; }
.gallery[data-view="mobile"] { --thumb-w: 30px; --thumb-h: 64px; }
.gallery[data-view="mobile"] .gallery__stage { background: #f5f5f5; }
.gallery__phone { position: absolute; inset: 0; }
.gallery .gallery__phone img {
  inset: auto; left: calc(50% - 123.5px); top: 32px; width: 247px; height: 536px;
  border-radius: 24px; object-fit: cover; object-position: top;
}
.gallery__phone::after { content: ''; position: absolute; left: calc(50% - 123.5px); top: 32px; width: 247px; height: 536px; border-radius: 24px; box-shadow: inset 0 0 0 1px rgba(18, 18, 18, 0.1); pointer-events: none; }
@media (max-width: 767px) {
  .gallery[data-view] { --thumb-w: 32px; --thumb-h: 20px; }
  .gallery[data-view="mobile"] { --thumb-w: 16px; --thumb-h: 34px; }
  .gallery[data-view] .gallery__views { gap: 16px; }
  .gallery[data-view] .gallery__view { gap: 10px; font-size: 15px; line-height: 18px; }
  .gallery[data-view] .gallery__view > span:first-child { width: 32px; height: 32px; border-radius: 7px; }
  .gallery[data-view] .gallery__view svg { width: 32px; height: 32px; }
  .gallery[data-view] .gallery__stage { aspect-ratio: 342 / 214; border-radius: 10px; }
  .gallery[data-view="mobile"] .gallery__stage { aspect-ratio: 342 / 380; }
  .gallery .gallery__phone img, .gallery__phone::after { left: calc(50% - 80.5px); top: 16px; width: 161px; height: 348px; border-radius: 16px; }
}
