/* ============================================================
   fx.css — interactive layer (DN Creative brand)
   Kinetic hero · stats · coffee · before/after · view transitions
   · case-study progress · magnetic CTAs · cursor label
   Every effect degrades to a static, readable page and honours
   prefers-reduced-motion.
   ============================================================ */

/* ---------- Cross-document view transitions ---------- */
@view-transition { navigation: auto; }

.nav { view-transition-name: site-nav; }
/* Case-study H1 is the morph target. Named in CSS (not fx.js) so it's set before
   the first paint, even when the deferred script arrives late over the network. */
:root:has(.cs-body) .page-hero__title { view-transition-name: cs-title; }

::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: 0.45s;
  animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1);
}
::view-transition-group(cs-title) {
  animation-duration: 0.7s;
  animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1);
}
::view-transition-old(cs-title),
::view-transition-new(cs-title) {
  height: 100%;
  object-fit: none;
  overflow: clip;
}

@media (prefers-reduced-motion: reduce) {
  @view-transition { navigation: none; }
}

/* ---------- Kinetic hero: "FIXER." decode ---------- */
[data-scramble] .scramble-char {
  display: inline-block;
  color: var(--orange-light);
  opacity: 0.85;
}

/* ---------- Stats: number, label, proof ---------- */
[data-stats] .stat-cell { gap: 0; padding: clamp(28px, 3vw, 40px) 16px; justify-content: center; }
[data-stats] .stat-number-wrap { margin-bottom: 18px; position: relative; } /* air between number and text */
/* The "+" hangs outside the digits so the number itself sits dead centre */
[data-stats] .stat-suffix { position: absolute; left: 100%; top: 0.06em; margin-left: 2px; }
.stat-text {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;                                                       /* label + proof read as one unit */
}
[data-stats] .stat-label { line-height: 1.35; }
.stat-proof {
  font-family: var(--font-body);
  font-size: 12px;
  line-height: 1.35;
  letter-spacing: 0.01em;
  color: rgba(245,243,238,0.5);
  text-align: center;
  margin: 0;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.6s var(--ease);
}
[data-stats].is-counted .stat-proof { opacity: 1; }
[data-stats] .stat-cell:nth-child(2) .stat-proof { transition-delay: 0.1s; }
[data-stats] .stat-cell:nth-child(3) .stat-proof { transition-delay: 0.2s; }
.counter { font-variant-numeric: tabular-nums; }
@media (max-width: 480px) { .stat-proof { white-space: normal; text-wrap: balance; max-width: 16ch; } }

/* Last-digit flash when the coffee counter ticks up */
.digit-flash { display: inline-block; animation: digitFlash 1.2s var(--ease); }
@keyframes digitFlash {
  0%   { color: var(--blaze-orange); transform: translateY(-0.12em); }
  60%  { color: var(--blaze-orange); transform: none; }
  100% { color: var(--warm-white); }
}

/* ---------- Coffee panel: pour fills the cell, then drains ---------- */
.stat-cell--coffee { position: relative; padding: 0 !important; overflow: hidden; }
.stat-coffee {
  --coffee: #3B2314;        /* espresso */
  --crema:  #8A5634;
  position: relative;
  width: 100%;
  height: 100%;
  display: block;
  padding: clamp(28px, 3vw, 40px) 16px;
  background: none;
  border: 0;
  color: inherit;
  font: inherit;
  cursor: pointer;
  overflow: hidden;
  isolation: isolate;
}
.stat-coffee:focus-visible { outline: 1px solid var(--warm-white); outline-offset: -6px; }
.stat-coffee {
  display: flex;
  align-items: center;
  justify-content: center;
}
.stat-coffee__content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
}
/* Number and "Pour one" share one centred row */
.stat-coffee__row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-bottom: 18px;
}
.stat-coffee .stat-number-wrap { margin-bottom: 0; }
.stat-coffee__cta {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding-left: 14px;
  border-left: 0.5px solid rgba(245,243,238,0.18);
  color: var(--warm-white);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.02em;
  line-height: 1.3;
  white-space: nowrap;
  transition: opacity 0.3s var(--ease);
}
#coffee-counter { white-space: nowrap; }
/* Phones: the 2x2 cell is too narrow for a side-by-side row, so the CTA tucks under the number */
@media (max-width: 480px) {
  .stat-coffee__row { flex-direction: column; gap: 10px; }
  .stat-coffee__cta { flex-direction: row; gap: 6px; padding-left: 0; border-left: 0; }
  .stat-coffee__icon { width: 18px; height: 18px; }
}
.stat-coffee__icon { transition: transform 0.4s var(--ease); }
.stat-coffee:hover .stat-coffee__icon { transform: rotate(-12deg) translateY(-1px); }
.stat-coffee__steam { animation: steamDrift 2.8s ease-in-out infinite; transform-origin: center bottom; }
@keyframes steamDrift {
  0%, 100% { opacity: 0.35; transform: translateY(0); }
  50%      { opacity: 1;    transform: translateY(-1.5px); }
}

/* The liquid: sits behind the content, rises from the bottom, wave on top */
.stat-coffee__liquid {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 100%;
  z-index: 0;
  background: var(--coffee);
  transform: translateY(calc(100% + 18px));
  pointer-events: none;
}
.stat-coffee__wave {
  position: absolute;
  left: 0; top: -15px;
  width: 200%;
  height: 16px;
  fill: var(--crema);
  animation: waveSlide 1.6s linear infinite;
}
.stat-coffee__liquid::after {        /* crema band just under the wave */
  content: '';
  position: absolute;
  left: 0; right: 0; top: 0;
  height: 10px;
  background: var(--crema);
  opacity: 0.55;
}
@keyframes waveSlide { to { transform: translateX(-50%); } }

.stat-coffee.is-pouring .stat-coffee__liquid { animation: coffeeFillDrain 2.6s cubic-bezier(0.16, 1, 0.3, 1) forwards; }
@keyframes coffeeFillDrain {
  0%   { transform: translateY(calc(100% + 18px)); }
  38%  { transform: translateY(0%); }
  62%  { transform: translateY(0%); }
  100% { transform: translateY(calc(100% + 18px)); }
}
.stat-coffee.is-pouring .stat-coffee__cta { opacity: 0.85; }
.stat-coffee.is-pouring { cursor: progress; }

/* ---------- Before / after slider ---------- */
.ba-section {
  padding: var(--sec-pad) var(--pad-x) 0;
  max-width: var(--max-w);
  margin: 0 auto;
}
.ba-section__header { margin-bottom: clamp(32px, 4vw, 48px); max-width: 760px; }
.ba-section__sub {
  font-family: var(--font-body);
  font-size: clamp(16px, 1.3vw, 18px);
  line-height: 1.6;
  color: rgba(245,243,238,0.78);
  margin-top: 20px;
}
.ba-section__link { display: inline-block; margin-top: 28px; }

.ba {
  --pos: 50%;
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border: 0.5px solid var(--gray-mid);
  background: var(--surface-dark);
  user-select: none;
  touch-action: pan-y;
  cursor: ew-resize;
}
.ba__img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
}
.ba__before {
  position: absolute;
  inset: 0;
  clip-path: inset(0 calc(100% - var(--pos)) 0 0);
}
.ba__handle {
  position: absolute;
  top: 0; bottom: 0;
  left: var(--pos);
  width: 0;
  pointer-events: none;
}
.ba__handle::before {
  content: '';
  position: absolute;
  top: 0; bottom: 0;
  left: -0.5px;
  width: 1px;
  background: var(--warm-white);
}
.ba__knob {
  position: absolute;
  top: 50%; left: 0;
  width: 48px; height: 48px;
  margin: -24px 0 0 -24px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: var(--blaze-orange);
  color: var(--pitch-black);
  transition: transform 0.3s var(--ease);
}
.ba.is-dragging .ba__knob,
.ba:hover .ba__knob { transform: scale(1.08); }
.ba__tag {
  position: absolute;
  top: 16px;
  padding: 6px 10px;
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--warm-white);
  background: rgba(10,10,10,0.78);
  border: 0.5px solid rgba(245,243,238,0.2);
  pointer-events: none;
  transition: opacity 0.3s var(--ease);
}
.ba__tag--before { left: 16px; }
.ba__tag--after  { right: 16px; }
.ba[data-side="after"]  .ba__tag--before,
.ba[data-side="before"] .ba__tag--after { opacity: 0.35; }
/* Native range input on top: keyboard + screen reader support for free */
.ba__range {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: ew-resize;
  -webkit-appearance: none;
  appearance: none;
}
.ba__range:focus-visible ~ .ba__handle .ba__knob,
.ba:focus-within .ba__knob { outline: 1px solid var(--warm-white); outline-offset: 4px; }
@media (max-width: 767px) {
  .ba { aspect-ratio: 4 / 3; }
  .ba__tag { top: 10px; font-size: 10px; padding: 5px 8px; }
  .ba__tag--before { left: 10px; }
  .ba__tag--after  { right: 10px; }
  .ba__tag-detail { display: none; }
  .ba__knob { width: 44px; height: 44px; margin: -22px 0 0 -22px; }
}

/* ---------- Case-study reading progress + chapter chip ---------- */
.read-progress {
  position: fixed;
  top: var(--nav-h);
  left: 0; right: 0;
  height: 2px;
  z-index: 999;
  pointer-events: none;
  background: transparent;
}
.read-progress__bar {
  display: block;
  height: 100%;
  background: var(--blaze-orange);
  transform: scaleX(var(--read, 0));
  transform-origin: left;
}
.chapter-chip {
  position: fixed;
  left: var(--pad-x);
  bottom: 24px;
  z-index: 998;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--warm-white);
  background: rgba(20,20,20,0.88);
  border: 0.5px solid var(--gray-mid);
  backdrop-filter: blur(6px);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.4s var(--ease), transform 0.4s var(--ease);
  pointer-events: none;
}
.chapter-chip.is-visible { opacity: 1; transform: none; }
.chapter-chip__num { color: var(--text-muted); font-variant-numeric: tabular-nums; }
@media (max-width: 767px) { .chapter-chip { display: none; } }

/* Active chapter label in the sticky left column */
.cs-section__eyebrow { transition: color 0.4s var(--ease); }
.cs-section.is-current .cs-section__eyebrow { color: var(--warm-white); }

/* ---------- Magnetic CTA ---------- */
.is-magnetic {
  transition: transform 0.5s var(--ease), background 0.2s, box-shadow 0.3s var(--ease);
  will-change: transform;
}

/* ---------- Cursor label over work cards ---------- */
.cursor-label {
  position: fixed;
  top: 0; left: 0;
  z-index: 1001;
  padding: 10px 16px;
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--pitch-black);
  background: var(--warm-white);
  border-radius: 999px;
  pointer-events: none;
  opacity: 0;
  transform: translate3d(var(--cx, 0), var(--cy, 0), 0) translate(-50%, -50%) scale(0.6);
  transition: opacity 0.25s var(--ease), transform 0.25s var(--ease);
  white-space: nowrap;
}
.cursor-label.is-visible {
  opacity: 1;
  transform: translate3d(var(--cx, 0), var(--cy, 0), 0) translate(-50%, -50%) scale(1);
}
.has-cursor-label,
.has-cursor-label * { cursor: none; }

/* ---------- Workflow diagram placement (homepage AI section) ---------- */
.ai-callout__diagram {
  max-width: var(--max-w);
  margin: clamp(48px, 6vw, 72px) auto 0;
  padding: 0 var(--pad-x);
}

/* ---------- Reduced motion: everything static ---------- */
@media (prefers-reduced-motion: reduce) {
  .line { transform: none; animation: none; }
  .stat-proof { opacity: 1; transition: none; }
  .digit-flash { animation: none; }
  .stat-coffee__steam, .stat-coffee__wave { animation: none; }
  .stat-coffee.is-pouring .stat-coffee__liquid { animation: coffeeFlat 1.4s steps(1) forwards; }
  @keyframes coffeeFlat { 0% { transform: none; } 100% { transform: translateY(calc(100% + 18px)); } }
  .is-magnetic { transition: none; }
  .cursor-label { display: none; }
  .has-cursor-label, .has-cursor-label * { cursor: pointer; }
  .chapter-chip { transition: none; }
}
