/* ------------------------------------------------------------------ *
 * CC.demo — the animated explainer (public/js/demo.js builds the DOM).
 *
 * Everything moves with transform/opacity only, driven by CSS keyframes
 * that are switched on by the .is-live class on a scene. JS only decides
 * which scene is live and when, so pausing is a single class:
 *   .ccdemo.is-paused → animation-play-state: paused on the whole stage.
 *
 * The stage is a fixed-ratio box; its contents are laid out on a
 * 20em × 12em canvas and the em is sized from the stage width, so the
 * drawing scales as one piece and never shifts the page while running.
 * Direction: positions use logical insets, movement uses --dirx (1 / -1).
 * ------------------------------------------------------------------ */

.ccdemo {
  --dirx: 1;
  --d1: 4000ms; --d2: 3400ms; --d3: 3600ms; --d4: 4400ms;
  --card-bg: #3E2316;
  --card-ink: #FFF8EB;
  --card-strip: #5A3825;
  --gold: #E6B866;
  --beam: #57D69B;
  margin: 0;
}
.ccdemo[dir="rtl"] { --dirx: -1; }

/* ---------------------------------------------------------- the stage */
.ccdemo-frame {
  container-type: inline-size;
  width: 100%;
  max-width: 33rem;
  margin-inline: auto;
}
.ccdemo-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 5 / 3;
  overflow: hidden;
  border: 1.5px solid var(--hair);
  border-radius: 14px;
  background:
    radial-gradient(120% 90% at 50% 0%, #FFFDF8 0%, #F5F1E8 100%);
  font-size: 13px;                       /* fallback: no container units */
  font-size: clamp(10px, 5cqw, 26px);
}
.ccdemo-stage::after {          /* counter line, for a sense of a room */
  content: '';
  position: absolute; inset-inline: 0; bottom: 14%;
  border-bottom: 1px solid rgba(27, 26, 23, .07);
}

.dscene {
  position: absolute; inset: 0;
  opacity: 0;
  transition: opacity .3s linear;
}
.dscene.is-live, .dscene.is-still { opacity: 1; }

.dcanvas {
  position: absolute; inset-inline: 0; top: 50%;
  width: 20em; height: 12em;
  margin-inline: auto;
  transform: translateY(-50%);
}

/* Pause: one class freezes every keyframe in place. */
.ccdemo.is-paused .ccdemo-stage,
.ccdemo.is-paused .ccdemo-stage * { animation-play-state: paused !important; }

/* ------------------------------------------------------------- pieces */
/* A loyalty card. Sized in em, so a slot's font-size scales the whole
   thing (a small one flies into the phone in beat 1). */
.dslot { position: absolute; }
.dcard {
  position: relative;
  width: 10.4em; height: 6.4em;
  padding: .5em .55em;
  display: flex; flex-direction: column; justify-content: space-between;
  background: var(--card-bg); color: var(--card-ink);
  border-radius: .7em;
  box-shadow: 0 .5em 1em -.45em rgba(27, 26, 23, .5);
}
.dcard-top { display: flex; align-items: flex-start; justify-content: space-between; gap: .4em; }
.dcard-name {
  font: 700 .62em/1.1 var(--display);
  max-width: 8em; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.dcard .dqr { width: 1.5em; height: 1.5em; border-radius: .12em; background: #fff; padding: .1em; }
.dcard-body { display: flex; align-items: center; gap: .55em; }

.dnum {
  position: relative;
  width: 1.55em; height: 1em;
  font-size: 2.4em; line-height: 1;
  overflow: hidden;
  flex: none;
}
.droll { display: block; }
.droll b {
  display: block; height: 1em;
  font: 800 1em/1 var(--display);
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.droll .dfree {
  color: var(--gold);
  font-size: 1em;
  white-space: nowrap;
  transform: scale(.42);            /* a word, shrunk to a digit's slot */
  transform-origin: 50% 50%;
  letter-spacing: -.01em;
}

.dcups { display: flex; gap: .22em; align-items: flex-end; }
.dcup {
  position: relative;
  width: .78em; height: 1.02em;
  border: .11em solid var(--card-ink);
  border-radius: .08em .08em .3em .3em;
  clip-path: polygon(0 0, 100% 0, 86% 100%, 14% 100%);
  overflow: hidden;
}
.dcup i {
  position: absolute; inset: 0;
  background: var(--card-ink);
  transform: scaleY(0); transform-origin: 50% 100%;
  opacity: 0;
}
.dglow {
  position: absolute; inset: -.35em;
  border-radius: 1em;
  box-shadow: 0 0 0 .18em var(--gold);
  opacity: 0;
}

/* A phone. */
.dphone {
  position: relative;
  width: 4.8em; height: 8.4em;
  background: #23211D;
  border-radius: .9em;
  padding: .3em;
  box-shadow: 0 .6em 1.2em -.5em rgba(27, 26, 23, .55);
}
.dnotch {
  position: absolute; top: .16em; left: 50%; transform: translateX(-50%);
  width: 1.5em; height: .16em; border-radius: .1em; background: #46423A;
}
.dscreen {
  position: relative; width: 100%; height: 100%;
  border-radius: .7em; overflow: hidden;
  background: #F6F2EA;
}

/* Beat 1: the phone's wallet, and the poster on the wall. */
.dwallet {
  position: absolute; inset-inline: 12%;
  height: .5em; border-radius: .3em .3em 0 0;
  background: #D9D2C6;
}
.dwallet.w1 { bottom: .5em; }
.dwallet.w2 { bottom: .9em; inset-inline: 18%; background: #C9C1B3; }

.dposter {
  position: relative;
  width: 7.2em; height: 9.2em;
  background: #fff;
  border: .12em solid var(--hair);
  border-radius: .35em;
  padding: .7em .6em;
  display: flex; flex-direction: column; align-items: center; gap: .45em;
  box-shadow: 0 .5em .9em -.5em rgba(27, 26, 23, .3);
}
.dposter .dqr { width: 4.4em; height: 4.4em; }
.dposter-strip { width: 100%; height: .55em; border-radius: .3em; background: var(--stamp); opacity: .85; }
.dbar { height: .34em; border-radius: .2em; background: #E3DDD2; }
.dbar.b1 { width: 80%; }
.dbar.b2 { width: 55%; }
.dscan {
  position: absolute; inset-inline: .5em; top: 1.9em;
  height: .28em; border-radius: .2em;
  background: linear-gradient(90deg, transparent, var(--beam), transparent);
  box-shadow: 0 0 .7em .1em rgba(87, 214, 155, .8);
  opacity: 0;
}
.dbadge {
  position: absolute; width: 1.7em; height: 1.7em;
  opacity: 0;
}
.dbadge svg { width: 100%; height: 100%; display: block; }

/* The scanner's viewfinder on the staff phone. */
.dview { position: absolute; inset: 14% 10%; }
.dview span {
  position: absolute; width: .7em; height: .7em;
  border: .16em solid var(--beam);
}
.dview span:nth-child(1) { top: 0; left: 0; border-width: .16em 0 0 .16em; }
.dview span:nth-child(2) { top: 0; right: 0; border-width: .16em .16em 0 0; }
.dview span:nth-child(3) { bottom: 0; left: 0; border-width: 0 0 .16em .16em; }
.dview span:nth-child(4) { bottom: 0; right: 0; border-width: 0 .16em .16em 0; }
.dscreen.dark { background: #2E2B26; }
.dflash { position: absolute; inset: 0; background: var(--beam); opacity: 0; }

/* The sweep that reads the card. */
.dbeam {
  position: absolute; inset-block: -.15em; inset-inline-start: 0;
  width: .45em;
  background: linear-gradient(180deg, transparent, var(--beam), transparent);
  box-shadow: 0 0 .8em .08em rgba(87, 214, 155, .75);
  opacity: 0;
}

/* The reward. */
.dreward {
  position: absolute;
  display: flex; flex-direction: column; align-items: center; gap: .3em;
  opacity: 0;
}
.dmug {
  position: relative;
  width: 2.4em; height: 2.5em;
  background: var(--card-bg);
  border-radius: .2em .2em .9em .9em;
  clip-path: polygon(0 0, 100% 0, 88% 100%, 12% 100%);
}
.dmug::after {          /* the coffee */
  content: ''; position: absolute; inset: .28em .3em auto; height: .5em;
  border-radius: .2em; background: var(--gold);
}
.dsteam { position: absolute; inset-inline: 0; top: -1.1em; height: 1em; display: flex; justify-content: center; gap: .35em; }
.dsteam i { width: .18em; height: 100%; border-radius: .1em; background: rgba(27, 26, 23, .18); opacity: 0; }
.dribbon {
  font: 800 .72em/1 var(--display);
  color: #3E2316; background: var(--gold);
  padding: .3em .55em; border-radius: .4em;
  white-space: nowrap;
}

/* --------------------------------------------------- scene 1: sign-up */
.ds1 .dposter-slot { inset-inline-start: 3.5%; top: 11%; }
.ds1 .dphone-slot { inset-inline-end: 3%; top: 3%; font-size: 1.3em; }
.ds1 .dfly { inset-inline-start: 10.5%; top: 35%; font-size: .42em; z-index: 2; }
.ds1 .dbadge { inset-inline-end: 6%; top: 7%; z-index: 3; }

.ds1.is-live .dposter-slot { animation: d1-poster var(--d1) both; }
.ds1.is-live .dphone-slot { animation: d1-phone var(--d1) both; }
.ds1.is-live .dscan { animation: d1-scan var(--d1) both; }
.ds1.is-live .dfly { animation: d1-fly var(--d1) both; }
.ds1.is-live .dbadge { animation: d1-badge var(--d1) both; }

@keyframes d1-poster {
  0% { opacity: 0; transform: translateY(.6em) scale(.96); }
  9%, 100% { opacity: 1; transform: none; }
}
@keyframes d1-phone {
  0%, 5% { opacity: 0; transform: translateY(1em); }
  17%, 100% { opacity: 1; transform: none; }
}
@keyframes d1-scan {
  0%, 18% { opacity: 0; transform: translateY(0); }
  22% { opacity: 1; transform: translateY(0); }
  38% { opacity: 1; transform: translateY(4.2em); }
  42%, 100% { opacity: 0; transform: translateY(4.2em); }
}
@keyframes d1-fly {
  0%, 38% { opacity: 0; transform: translate(0, 0) scale(.86); }
  44% { opacity: 1; transform: translate(0, 0) scale(1); }
  70% { opacity: 1; transform: translate(calc(var(--dirx) * 268%), 74%) scale(.82) rotate(calc(var(--dirx) * -5deg)); }
  78%, 100% { opacity: 1; transform: translate(calc(var(--dirx) * 268%), 74%) scale(.82) rotate(0deg); }
}
@keyframes d1-badge {
  0%, 76% { opacity: 0; transform: scale(.3); }
  84% { opacity: 1; transform: scale(1.12); }
  90%, 100% { opacity: 1; transform: scale(1); }
}

.ds1.is-still .dfly { transform: translate(calc(var(--dirx) * 268%), 74%) scale(.82); }
.ds1.is-still .dbadge { opacity: 1; }

/* ------------------------------------------------ scene 2: first scan */
.ds2 .dcard-slot { inset-inline-start: 4%; top: 23%; }
.ds2 .dphone-slot { inset-inline-end: 3.5%; top: 13%; transform: rotate(calc(var(--dirx) * -7deg)); }

.ds2.is-live .dcard-slot { animation: d2-card var(--d2) both; }
.ds2.is-live .dphone { animation: d2-phone var(--d2) both; }
.ds2.is-live .dbeam { animation: d2-beam var(--d2) both; }
.ds2.is-live .dflash { animation: d2-flash var(--d2) both; }
.ds2.is-live .droll { animation: d2-roll var(--d2) both; }
.ds2.is-live .dcup:nth-child(1) i { animation: d-fill .34s cubic-bezier(.2, .8, .2, 1) 1900ms both; }

@keyframes d2-card {
  0% { opacity: 0; transform: translateY(.5em); }
  12%, 100% { opacity: 1; transform: none; }
}
@keyframes d2-phone {
  0%, 6% { opacity: 0; transform: translate(calc(var(--dirx) * 1.2em), .8em); }
  24%, 100% { opacity: 1; transform: none; }
}
@keyframes d2-beam {
  0%, 30% { opacity: 0; transform: translateX(0); }
  34% { opacity: 1; transform: translateX(0); }
  50% { opacity: 1; transform: translateX(calc(var(--dirx) * 10em)); }
  54%, 100% { opacity: 0; transform: translateX(calc(var(--dirx) * 10em)); }
}
@keyframes d2-flash {
  0%, 46% { opacity: 0; }
  50% { opacity: .35; }
  58%, 100% { opacity: 0; }
}
@keyframes d2-roll {
  0%, 52% { transform: translateY(0); }
  62%, 100% { transform: translateY(-1em); }
}
@keyframes d-fill {
  from { transform: scaleY(0); opacity: 0; }
  to { transform: scaleY(1); opacity: 1; }
}

.ds2.is-still .droll { transform: translateY(-1em); }
.ds2.is-still .dcup:nth-child(1) i { transform: scaleY(1); opacity: 1; }

/* ------------------------------------------ scene 3: 3 → 2 → 1 → free */
.ds3 .dcard-slot { inset-inline-start: 21%; top: 19%; font-size: 1.12em; }

.ds3 .dcup:nth-child(1) i { transform: scaleY(1); opacity: 1; }
.ds3.is-live .droll { animation: d3-roll var(--d3) both; }
.ds3.is-live .dcard { animation: d3-pulse var(--d3) both; }
.ds3.is-live .dglow { animation: d3-glow var(--d3) both; }
.ds3.is-live .dcup:nth-child(2) i { animation: d-fill .3s cubic-bezier(.2, .8, .2, 1) 600ms both; }
.ds3.is-live .dcup:nth-child(3) i { animation: d-fill .3s cubic-bezier(.2, .8, .2, 1) 1390ms both; }
.ds3.is-live .dcup:nth-child(4) i { animation: d-fill .3s cubic-bezier(.2, .8, .2, 1) 2180ms both; }
.ds3.is-live .dcup:nth-child(5) i { animation: d-fill .3s cubic-bezier(.2, .8, .2, 1) 2970ms both; }

@keyframes d3-roll {
  0%, 10% { transform: translateY(-1em); }         /* 4 */
  17%, 32% { transform: translateY(-2em); }        /* 3 */
  39%, 54% { transform: translateY(-3em); }        /* 2 */
  61%, 76% { transform: translateY(-4em); }        /* 1 */
  83%, 100% { transform: translateY(-5em); }       /* free */
}
@keyframes d3-pulse {
  0%, 12% { transform: scale(1); }
  19% { transform: scale(1.025); }
  25%, 34% { transform: scale(1); }
  41% { transform: scale(1.025); }
  47%, 56% { transform: scale(1); }
  63% { transform: scale(1.025); }
  69%, 78% { transform: scale(1); }
  86% { transform: scale(1.05); }
  94%, 100% { transform: scale(1); }
}
@keyframes d3-glow {
  0%, 82% { opacity: 0; }
  88% { opacity: 1; }
  100% { opacity: .75; }
}

.ds3.is-still .droll { transform: translateY(-5em); }
.ds3.is-still .dcup i { transform: scaleY(1); opacity: 1; }
.ds3.is-still .dglow { opacity: .75; }

/* ------------------------------------------- scene 4: the free visit */
.ds4 .dcard-slot { inset-inline-start: 4%; top: 44%; font-size: .9em; }
.ds4 .dphone-slot { inset-inline-end: 3.5%; top: 12%; transform: rotate(calc(var(--dirx) * -7deg)); }
.ds4 .dreward { inset-inline-start: 7%; top: 10%; font-size: .9em; }

.ds4 .droll { transform: translateY(-5em); }
.ds4 .dcup i { transform: scaleY(1); opacity: 1; }

.ds4.is-live .dbeam { animation: d4-beam var(--d4) both; }
.ds4.is-live .dflash { animation: d4-flash var(--d4) both; }
.ds4.is-live .dreward { animation: d4-reward var(--d4) both; }
.ds4.is-live .dsteam i { animation: d4-steam 1.6s ease-in-out 1500ms infinite both; }
.ds4.is-live .dsteam i:nth-child(2) { animation-delay: 1750ms; }
.ds4.is-live .dsteam i:nth-child(3) { animation-delay: 2000ms; }
.ds4.is-live .droll { animation: d4-roll var(--d4) both; }
.ds4.is-live .dcup i { animation: d4-drain var(--d4) both; }
.ds4.is-live .dglow { animation: d4-glow var(--d4) both; }

@keyframes d4-beam {
  0%, 10% { opacity: 0; transform: translateX(0); }
  14% { opacity: 1; transform: translateX(0); }
  30% { opacity: 1; transform: translateX(calc(var(--dirx) * 10em)); }
  34%, 100% { opacity: 0; transform: translateX(calc(var(--dirx) * 10em)); }
}
@keyframes d4-flash {
  0%, 26% { opacity: 0; }
  30% { opacity: .35; }
  38%, 100% { opacity: 0; }
}
@keyframes d4-reward {
  0%, 32% { opacity: 0; transform: translateY(.9em) scale(.7); }
  42% { opacity: 1; transform: translateY(0) scale(1.06); }
  48%, 74% { opacity: 1; transform: translateY(0) scale(1); }
  86%, 100% { opacity: 0; transform: translateY(-.7em) scale(.95); }
}
@keyframes d4-steam {
  0% { opacity: 0; transform: translateY(.35em) scaleY(.6); }
  40% { opacity: .9; }
  100% { opacity: 0; transform: translateY(-.5em) scaleY(1); }
}
@keyframes d4-roll {
  0%, 66% { transform: translateY(-5em); }
  80%, 100% { transform: translateY(0); }
}
@keyframes d4-drain {
  0%, 68% { transform: scaleY(1); opacity: 1; }
  78%, 100% { transform: scaleY(0); opacity: 0; }
}
@keyframes d4-glow {
  0% { opacity: .75; }
  30% { opacity: .75; }
  44%, 100% { opacity: 0; }
}

.ds4.is-still .droll { transform: translateY(0); }
.ds4.is-still .dcup i { transform: scaleY(0); opacity: 0; }
.ds4.is-still .dreward { opacity: 1; }

/* -------------------------------------------------- caption + controls */
.ccdemo-cap {
  margin: .85rem auto 0;
  max-width: 33rem;
  min-height: 4.3em;
  color: var(--muted);
  font-size: .98rem;
  line-height: 1.45;
  text-align: start;
}
.ccdemo-step {
  display: inline-block;
  font: 600 .74rem/1 var(--display);
  color: var(--stamp-ink);
  background: var(--stamp-wash);
  border-radius: 999px;
  padding: .3em .6em;
  margin-inline-end: .5rem;
  vertical-align: .05em;
  white-space: nowrap;
}

.ccdemo-bar {
  display: flex; align-items: center; gap: .5rem;
  max-width: 33rem; margin: .7rem auto 0;
}
.ccdemo-btn {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .42rem .8rem;
  font: 500 .9rem var(--text);
  color: var(--ink); background: #fff;
  border: 1.5px solid var(--hair); border-radius: 999px;
  cursor: pointer;
}
.ccdemo-btn:hover { border-color: var(--ink); }
.ccdemo-btn:focus-visible { outline: 2px solid var(--stamp); outline-offset: 2px; }
.ccdemo-btn svg { width: 1em; height: 1em; display: block; fill: currentColor; }
.ccdemo-btn[data-act="replay"] svg { transform: scaleX(var(--dirx)); }

.ccdemo-dots { display: flex; gap: .35rem; margin: 0; margin-inline-start: auto; padding: 0; list-style: none; }
.ccdemo-dots li {
  width: .45rem; height: .45rem; border-radius: 50%;
  background: var(--hair);
  transition: background-color .2s linear, transform .2s linear;
}
.ccdemo-dots li.on { background: var(--stamp); transform: scale(1.35); }

.ccdemo-sr {
  position: absolute; width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}

/* ------------------------------------------- reduced motion: four stills */
.ccdemo-static { list-style: none; margin: 0; padding: 0; display: grid; gap: 1.5rem; }
.ccdemo-static > li { display: grid; gap: .6rem; }
.ccdemo-static .ccdemo-frame { max-width: 26rem; margin-inline: 0; }
.ccdemo-static .ccdemo-cap { margin: 0; min-height: 0; max-width: 26rem; }

@media (min-width: 720px) {
  .ccdemo-static { grid-template-columns: 1fr 1fr; gap: 1.8rem 2rem; }
}

@media (max-width: 420px) {
  .ccdemo-cap { min-height: 5.8em; font-size: .94rem; }
  .ccdemo-btn { padding: .4rem .7rem; font-size: .86rem; }
}

/* Play and replay are tapped mid-animation; keep them thumb-sized. */
@media (max-width: 40rem), (pointer: coarse) {
  .ccdemo-btn { min-height: 44px; min-width: 44px; justify-content: center; }
}
