/* KLIKS — "Don't cut. Carry." shared-element transitions (preview)
   1. The card becomes the page   2. Back goes back   3. Menus start at their button */

/* ---------- 1 + 2: cross-document view transitions ---------- */
@view-transition { navigation: auto; }

:root { --vt-dur: 400ms; --vt-ease: cubic-bezier(.22,.8,.18,1); }

/* the header stays put while pages change underneath it */
.hd { view-transition-name: site-header; }
::view-transition-group(site-header) { animation: none; }
::view-transition-old(site-header) { display: none; }
::view-transition-new(site-header) { animation: none; }

/* everything that is NOT carried: old page sinks to grey, new page fades in after the card lands */
::view-transition-old(root) { animation: vt-sink 180ms ease-out both; }
::view-transition-new(root) { animation: vt-rise 240ms 60ms ease-out both; }
@keyframes vt-sink { to { opacity: 0; filter: grayscale(1) brightness(.55); } }
@keyframes vt-rise { from { opacity: 0; transform: translateY(8px); } }

/* the carried elements: card media -> page hero, card name -> page title */
::view-transition-group(*) { animation-duration: var(--vt-dur); animation-timing-function: var(--vt-ease); }
::view-transition-old(*), ::view-transition-new(*) { height: 100%; object-fit: cover; overflow: clip; animation-duration: var(--vt-dur); animation-timing-function: var(--vt-ease); }
.vt-title { display: inline-block; }

/* arrival safety: carried targets must be visible in the first frame */
.vt-in .case.fade, .vt-in .case.fade * { opacity: 1 !important; transform: none !important; transition: none !important; }

/* case-study preview pages: hero image moved to the top, like the reel's product page */
.cs-media.vt-hero { margin-top: calc(var(--hd, 72px) + 44px); width: 100%; aspect-ratio: 16 / 10; height: auto; max-height: calc(100svh - var(--hd, 72px) - 120px); min-height: 240px; overflow: hidden; border-top: 1px solid var(--line, #2a2d24); border-bottom: 1px solid var(--line, #2a2d24); }
.cs-media.vt-hero img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 35%; display: block; }
.cs-media.vt-hero + .ph, .vt-hero ~ .ph { padding-top: 64px; }

/* ---------- older case-study blocks restyled for the dark site ---------- */
.legacy .cmp { border-radius: 0; }
.legacy .cmp--muted { background: rgba(243,245,234,.03) !important; border: 1px solid var(--line, rgba(243,245,234,.12)) !important; color: var(--ink-2, rgba(243,245,234,.62)) !important; }
.legacy .cmp--muted h3 { color: var(--ink, #f3f5ea); }
.legacy .cmp--focus { background: rgba(200,255,0,.05) !important; border: 1px solid rgba(200,255,0,.35) !important; color: var(--ink, #f3f5ea) !important; }
.legacy .cmp--focus h3 { color: var(--lime, #c8ff00) !important; }
.legacy .cmp li { border-top-color: var(--line, rgba(243,245,234,.12)) !important; padding-left: 26px !important; }
.legacy .cmp li:first-of-type { border-top: 0 !important; }
.legacy .cmp--muted li::before { content: "" !important; left: 2px !important; top: 1.25em !important; width: 10px !important; height: 2px !important; background: rgba(243,245,234,.35) !important; border: 0 !important; transform: none !important; }
.legacy .cmp--focus li::before { content: "" !important; left: 2px !important; top: 1.05em !important; width: 7px !important; height: 7px !important; background: var(--lime, #c8ff00) !important; border: 0 !important; transform: none !important; }
.legacy ul.tagset { gap: 8px; padding: 0; list-style: none; }
.legacy ul.tagset li { padding: 8px 12px !important; border: 1px solid var(--line-2, rgba(243,245,234,.22)) !important; border-radius: 0 !important; font: 400 11px/1 var(--mono, 'IBM Plex Mono', monospace) !important; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-2, rgba(243,245,234,.62)) !important; }
.legacy ul.tagset li::before { content: none !important; display: none !important; }

/* the 'Sound familiar?' CTA stays in place instead of riding over the cards */
.rail:has(> .kl-fam-cta) { position: static !important; top: auto !important; padding-right: 0 !important; margin-bottom: 28px; }
.rail > .kl-fam-cta { margin: 0 !important; }

/* case-study stats: five figures sit on one line instead of wrapping one onto a second row */
@media (min-width: 900px) {
  .stats.strip2:has(> .stat:nth-child(5)):not(:has(> .stat:nth-child(6))) { grid-template-columns: repeat(5, minmax(0, 1fr)) !important; }
  .stats.strip2:has(> .stat:nth-child(5)):not(:has(> .stat:nth-child(6))) .stat b { font-size: clamp(36px, 3.6vw, 62px) !important; }
}

/* ---------- 3: the menu grows out of its button ---------- */
@media (max-width: 980px) {
  .hd.open .hd-nav {
    top: calc(var(--hd, 72px) - 6px) !important; bottom: auto !important;
    left: auto !important; right: 14px !important;
    width: min(calc(100vw - 28px), 420px) !important; height: auto !important; max-height: calc(100dvh - var(--hd, 72px) - 20px);
    background: #0c0d0a !important; border: 1px solid rgba(243,245,234,.12);
    padding: 18px 24px 24px !important; box-shadow: 0 30px 80px rgba(0,0,0,.55);
    transform-origin: var(--mx, 100%) var(--my, 0);
    animation: vt-menu-in 520ms var(--vt-ease) both;
  }
  html[dir=rtl] .hd.open .hd-nav { right: auto !important; left: 14px !important; }
  .hd.open .hd-nav a { animation: vt-item 420ms var(--vt-ease) both; animation-delay: calc(140ms + var(--i, 0) * 55ms); }
  .hd.open.vt-closing .hd-nav { animation: vt-menu-out 300ms cubic-bezier(.5,0,.75,0) both; }
  .hd.open.vt-closing .hd-nav a { animation: vt-item-out 160ms ease-in both; }
  .vt-scrim { position: fixed; inset: 0; z-index: 40; background: rgba(5,6,4,.55); backdrop-filter: grayscale(1) blur(2px); -webkit-backdrop-filter: grayscale(1) blur(2px); opacity: 0; pointer-events: none; transition: opacity 360ms ease; }
  .vt-scrim.on { opacity: 1; pointer-events: auto; }
  .hd { z-index: 50; }
}
@keyframes vt-menu-in  { from { clip-path: circle(0 at var(--mx, 100%) var(--my, 0)); } to { clip-path: circle(160% at var(--mx, 100%) var(--my, 0)); } }
@keyframes vt-menu-out { from { clip-path: circle(160% at var(--mx, 100%) var(--my, 0)); } to { clip-path: circle(0 at var(--mx, 100%) var(--my, 0)); } }
@keyframes vt-item { from { opacity: 0; transform: translateY(10px); } }
@keyframes vt-item-out { to { opacity: 0; } }

/* ---------- reduced motion: no carrying, no growing ---------- */
@media (prefers-reduced-motion: reduce) {
  @view-transition { navigation: none; }
  .hd.open .hd-nav, .hd.open .hd-nav a, .hd.open.vt-closing .hd-nav, .hd.open.vt-closing .hd-nav a { animation: none !important; }
  .vt-scrim { transition: none; }
}
