/* Motion and depth. main.js sets data-anim on #sections: "enter" on the first render, "update" when the
   marketplace, Compare or TV mode changes. A card's marks wait (paused) until the card scrolls into view (.in).
   Without data-anim (no JavaScript observer, reduced motion, print) everything is simply drawn. */
:root { --ease-out: cubic-bezier(0.23, 1, 0.32, 1); --depth: 8px; }

/* ---- depth: extruded waterfall columns. The front face keeps the exact height; top and side are decoration. */
.wf-scroll { padding-top: var(--depth); }
.wf-bar { --bar: var(--ink-muted); background: var(--bar); border-radius: 0; }
.wf-bar--total { --bar: var(--insights); }
.wf-bar::before, .wf-bar::after { content: ''; position: absolute; }
.wf-bar::before {
  left: 0; right: 0; bottom: 100%; height: var(--depth);
  background: color-mix(in srgb, var(--bar) 62%, white);
  transform: skewX(-45deg); transform-origin: bottom left;
}
.wf-bar::after {
  top: 0; bottom: 0; left: 100%; width: var(--depth);
  background: color-mix(in srgb, var(--bar) 74%, black);
  transform: skewY(-45deg); transform-origin: top left;
}
.wf-val { translate: 0 calc(-1 * var(--depth)); }

/* ---- depth: bubbles shaded as spheres (area still carries the value) */
.bubble:not(.bubble--loss) {
  background: radial-gradient(circle at 32% 28%,
    color-mix(in srgb, var(--insights) 12%, var(--surface-raised)),
    color-mix(in srgb, var(--insights) 48%, var(--surface-raised)) 72%);
}

/* ---- depth: the hero tile tilts toward the pointer (main.js sets the transform) */
@media (hover: hover) and (pointer: fine) and (prefers-reduced-motion: no-preference) {
  .hero { transform-style: preserve-3d; transition: transform 240ms var(--ease-out); }
  .hero__value { transform: translateZ(28px); }
  .hero .spark { transform: translateZ(14px); }
  .hero .goal { transform: translateZ(8px); }
}

/* ---- motion */
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
@keyframes grow-y { from { transform: scaleY(0); } }
@keyframes grow-x { from { transform: scaleX(0); } }
@keyframes draw { from { clip-path: inset(0 100% 0 0); } }
@keyframes wipe { from { clip-path: inset(100% 0 0 0); } }
@keyframes pop { from { transform: scale(0.5); } }

@media screen and (prefers-reduced-motion: no-preference) {
  [data-anim] { --d0: 0ms; }
  [data-anim="enter"] { --d0: 180ms; }

  /* First render only: the cards already on screen rise in. Cards further down (.below) are just there. */
  [data-anim="enter"] :is(.card, .hero, .kpi):not(.below) { animation: rise 420ms var(--ease-out) backwards paused; }
  [data-anim="enter"] .headline > :nth-child(2), [data-anim="enter"] .row > :nth-child(2) { animation-delay: 50ms; }
  [data-anim="enter"] .headline > :nth-child(3) { animation-delay: 100ms; }
  [data-anim="enter"] .headline > :nth-child(4) { animation-delay: 150ms; }
  [data-anim="enter"] .headline > :nth-child(5) { animation-delay: 200ms; }

  /* Chart marks: columns and bars grow from their base, lines draw left to right, cells wipe in row by row. */
  [data-anim] .wf-bar { transform-origin: top; animation: grow-y 520ms var(--ease-out) backwards paused; }
  [data-anim] .wf-bar--total { transform-origin: bottom; }
  [data-anim] :is(.wf-val, .wf-conn) { animation: wipe 300ms var(--ease-out) backwards paused; }
  [data-anim] .wf-col .wf-bar { animation-delay: calc(var(--d0) + var(--i, 0) * 60ms); }
  [data-anim] .wf-col :is(.wf-val, .wf-conn) { animation-delay: calc(var(--d0) + var(--i, 0) * 60ms + 260ms); }
  .wf-col:nth-child(2) { --i: 1; } .wf-col:nth-child(3) { --i: 2; } .wf-col:nth-child(4) { --i: 3; }
  .wf-col:nth-child(5) { --i: 4; } .wf-col:nth-child(6) { --i: 5; } .wf-col:nth-child(7) { --i: 6; }

  [data-anim] .wf-hbar, [data-anim] .bridge-bar--up { transform-origin: left; animation: grow-x 480ms var(--ease-out) var(--d0) backwards paused; }
  [data-anim] .bridge-bar--down { transform-origin: right; animation: grow-x 480ms var(--ease-out) var(--d0) backwards paused; }
  [data-anim] :is(.mp-bar, .pay-bar, .goal__fill, .rt-bar__fill) { animation: draw 600ms var(--ease-out) var(--d0) backwards paused; }
  [data-anim] .spark { animation: draw 800ms var(--ease-out) var(--d0) backwards paused; }

  [data-anim] :is(.cal-day, .hm-cell) { animation: wipe 320ms var(--ease-out) backwards paused; animation-delay: calc(var(--d0) + var(--r, 0) * 45ms); }
  :is(.cal, .hm) tbody tr:nth-child(2) { --r: 1; } :is(.cal, .hm) tbody tr:nth-child(3) { --r: 2; }
  :is(.cal, .hm) tbody tr:nth-child(4) { --r: 3; } :is(.cal, .hm) tbody tr:nth-child(5) { --r: 4; }
  :is(.cal, .hm) tbody tr:nth-child(6) { --r: 5; } :is(.cal, .hm) tbody tr:nth-child(7) { --r: 6; }
  :is(.cal, .hm) tbody tr:nth-child(8) { --r: 7; } :is(.cal, .hm) tbody tr:nth-child(9) { --r: 8; }

  /* Bubbles glide on a filter change (patterns.css), so they only pop on the first render. */
  [data-anim="enter"] .bubble { animation: pop 450ms var(--ease-out) var(--d0) backwards paused; }
  [data-anim="enter"] .bubble:nth-child(3n) { animation-delay: calc(var(--d0) + 60ms); }
  [data-anim="enter"] .bubble:nth-child(3n + 1) { animation-delay: calc(var(--d0) + 120ms); }

  [data-anim] :is(.card, .hero, .kpi).in,
  [data-anim] .in :is(.wf-bar, .wf-val, .wf-conn, .wf-hbar, .bridge-bar, .mp-bar, .pay-bar, .goal__fill, .rt-bar__fill, .spark, .cal-day, .hm-cell, .bubble) {
    animation-play-state: running;
  }
}
