/* ============================================================================
   SPICA HOME V6 · DEMOS, primitivas de las escenas "app viva" (30-ago r2)
   Sistema extraído del análisis frame a frame de ManyChat: teléfono barato
   que funciona, burbujas con overshoot, caret humano, tap circles, cursor
   multiplayer, labels de progreso tipo stories. Colores SIEMPRE por tokens.
   ========================================================================== */

/* ---- stage ----------------------------------------------------------------- */
.demo {
  position: relative;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 0.9rem;
  min-height: 420px;
  transition: opacity 0.4s var(--ease);
}
.demo.is-fading { opacity: 0; }
.demo.is-instant *, .demo.is-instant *::before, .demo.is-instant *::after {
  transition: none !important;
  animation: none !important;
}

/* ---- teléfono --------------------------------------------------------------- */
.dm-phone {
  width: 300px;
  max-width: 100%;
  background: #0d0d0c;
  border-radius: 30px;
  padding: 0.85rem 0.85rem 1rem;
  box-shadow: 0 24px 60px rgba(17, 17, 16, 0.28);
  display: grid;
  gap: 0.7rem;
}
.dm-phone__head {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.15rem 0.2rem 0;
  min-width: 0; /* el header nunca ensancha el marco: el texto se trunca */
}
.dm-phone__id { min-width: 0; }
.dm-phone__id b, .dm-phone__id small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dm-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--dm-hue, var(--violet));
  color: #fff;
  font-size: 0.72rem;
  font-weight: 640;
  display: grid;
  place-items: center;
  flex: none;
}
.dm-phone__id { display: grid; line-height: 1.25; }
.dm-phone__id b { color: #fff; font-size: 0.8rem; font-weight: 600; }
.dm-phone__id small {
  font-family: var(--font-mono);
  font-size: 0.56rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.45);
}
.dm-phone__icons { margin-left: auto; display: flex; gap: 0.35rem; }
.dm-phone__icons i {
  width: 14px; height: 14px;
  border: 1.5px solid rgba(255, 255, 255, 0.35);
  border-radius: 4px;
}
.dm-phone__screen {
  background: #171716;
  border-radius: 20px;
  min-height: 300px;
  min-width: 0;
  padding: 0.8rem 0.7rem;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 0.5rem;
  overflow: hidden;
}

/* ---- burbujas --------------------------------------------------------------- */
/* default r2 APROBADO: crece con overshoot suave. NO cambiar: las escenas
   restauradas (find/choice/ops/billboard y el motion firmado) dependen de esto. */
.dm-bubble {
  --dm-accent: var(--violet);
  max-width: 86%;
  border-radius: 16px;
  padding: 0.6rem 0.75rem;
  font-size: 0.78rem;
  line-height: 1.45;
  display: grid;
  gap: 0.45rem;
  opacity: 0;
  transform: scale(0.6);
  transition: opacity 0.32s var(--ease-out), transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}
.dm-bubble.is-on { opacity: 1; transform: scale(1); }
/* r3 OPT-IN (spec MOTION-R3 2.2): reveal anclado con clip, alto constante.
   Solo lo usan las escenas nuevas que agregan la clase .dm-bubble--anchored. */
.dm-bubble--anchored {
  transform: scale(0.92);
  clip-path: inset(0 22% 0 0 round 16px);
  transition: opacity 0.28s var(--ease-out), transform 0.6s var(--ease-out),
    clip-path 0.6s var(--ease-out);
}
.dm-bubble--anchored.dm-bubble--out { clip-path: inset(0 0 0 22% round 16px); }
.dm-bubble--anchored.is-on { transform: scale(1); clip-path: inset(0 0 0 0 round 16px); }
.dm-bubble--in {
  background: #2c2c2a;
  color: rgba(255, 255, 255, 0.92);
  align-self: flex-start;
  border-bottom-left-radius: 5px;
  transform-origin: bottom left;
}
.dm-bubble--out {
  background: var(--dm-accent);
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 5px;
  transform-origin: bottom right;
}
.dm-bubble__btn {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 10px;
  padding: 0.45rem 0.6rem;
  font-weight: 560;
  font-size: 0.74rem;
  text-align: center;
  position: relative;
  transition: transform 0.14s var(--ease), background 0.14s var(--ease);
}
.dm-bubble--in .dm-bubble__btn { background: rgba(255, 255, 255, 0.12); }
.dm-bubble__btn.is-pressed { transform: translateY(2px) scale(0.97); background: rgba(255, 255, 255, 0.34); }

/* palabras que se revelan (sistema) */
.dm-word {
  display: inline-block;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.3s var(--ease-out), transform 0.3s var(--ease-out);
  transition-delay: inherit;
}
.is-revealed .dm-word, .dm-bubble__text.is-revealed .dm-word { opacity: 1; transform: none; }

/* caret humano */
.dm-caret {
  display: inline-block;
  width: 2px;
  height: 0.95em;
  margin-left: 1px;
  vertical-align: text-bottom;
  background: currentColor;
  animation: dm-caret-blink 1s steps(2) infinite;
}
@keyframes dm-caret-blink { 50% { opacity: 0; } }

/* typing indicator */
.dm-typing {
  --dm-accent: var(--violet);
  align-self: flex-end;
  background: var(--dm-accent);
  border-radius: 999px;
  padding: 0.42rem 0.6rem;
  display: inline-flex;
  gap: 4px;
  opacity: 0;
  transform: scale(0.7);
  transition: opacity 0.24s var(--ease-out), transform 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.dm-typing.is-on { opacity: 1; transform: scale(1); }
.dm-typing i {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.85);
  animation: dm-typing-bounce 0.6s var(--ease) infinite;
}
.dm-typing i:nth-child(2) { animation-delay: 0.12s; }
.dm-typing i:nth-child(3) { animation-delay: 0.24s; }
@keyframes dm-typing-bounce { 50% { transform: translateY(-3px); } }

/* ---- tap circle ------------------------------------------------------------- */
.dm-tap {
  position: absolute;
  inset: 50% auto auto 50%;
  width: 40px; height: 40px;
  margin: -20px 0 0 -20px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.35);
  backdrop-filter: blur(2px);
  pointer-events: none;
  z-index: 3;
  opacity: 0;
  transform: scale(0.4);
}
.dm-tap.is-on { animation: dm-tap-pop 0.42s var(--ease-out) forwards; }
@keyframes dm-tap-pop {
  0% { opacity: 0; transform: scale(0.4); }
  30% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.18); }
}

/* ---- cursor multiplayer ------------------------------------------------------ */
.dm-cursor {
  position: absolute;
  left: 0; top: 0;
  z-index: 4;
  width: 20px; height: 20px;
  pointer-events: none;
  opacity: 0;
  transition: transform 0.9s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.25s var(--ease);
}
.dm-cursor.is-on { opacity: 1; }
.dm-cursor.is-click svg { transform: scale(0.82); }
.dm-cursor svg {
  width: 100%; height: 100%;
  fill: var(--ink);
  stroke: #fff;
  stroke-width: 1.6;
  transition: transform 0.13s var(--ease);
  filter: drop-shadow(0 2px 5px rgba(17, 17, 16, 0.3));
}

/* ---- label de progreso (stories) --------------------------------------------- */
.dm-progress {
  --dm-accent: var(--violet);
  background: var(--dm-accent);
  color: #fff;
  border-radius: 12px;
  padding: 0.55rem 0.8rem 0.6rem;
  display: grid;
  gap: 0.4rem;
  width: min(300px, 82%);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.35s var(--ease-out), transform 0.35s var(--ease-out);
}
.dm-progress.is-on { opacity: 1; transform: none; }
.dm-progress__text {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  font-weight: 520;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}
.dm-progress__bar {
  height: 3px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.28);
  overflow: hidden;
  display: block;
}
.dm-progress__bar i {
  display: block;
  height: 100%;
  width: 0%;
  background: #fff;
  border-radius: 3px;
}

/* ---- tarjeta de notificación -------------------------------------------------- */
.dm-note {
  --dm-accent: var(--violet);
  background: var(--paper-raised);
  color: var(--ink);
  border: 1px solid var(--line);
  border-left: 3px solid var(--dm-accent);
  border-radius: 14px;
  box-shadow: var(--shadow-lift);
  padding: 0.65rem 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  opacity: 0;
  transform: translateY(10px) scale(0.94);
  transition: opacity 0.32s var(--ease-out), transform 0.38s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.dm-note.is-on { opacity: 1; transform: none; }
.dm-note__icon {
  width: 30px; height: 30px;
  border-radius: 9px;
  background: color-mix(in srgb, var(--dm-accent) 14%, transparent);
  color: var(--dm-accent);
  display: grid;
  place-items: center;
}
.dm-note__icon svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.dm-note__copy { display: grid; line-height: 1.3; }
.dm-note__copy b { font-size: 0.8rem; font-weight: 600; }
.dm-note__copy small { font-size: 0.7rem; color: var(--ink-soft); }

/* pressed genérico (botones de UI simulada fuera de burbujas) */
.is-pressed { transform: translateY(2px) scale(0.97); }

/* ============================================================================
   PRIMITIVAS R3 (spec MOTION-R3)
   ========================================================================== */

/* salida acelerada + fade (spec 1.3: deltas crecientes, ease-in, siempre fade) */
.dm-exit {
  animation: dm-exit var(--dm-exit-dur, 380ms) cubic-bezier(0.55, 0, 0.85, 0.36) forwards !important;
  pointer-events: none;
}
@keyframes dm-exit {
  to { opacity: 0; transform: translateY(var(--dm-exit-dy, -14px)); }
}

/* foto ultrarealista en slot: base cuadrada redondeada; variantes por clase */
.dm-photo {
  display: inline-block;
  overflow: hidden;
  border-radius: 10px;
  background: color-mix(in srgb, var(--ink) 8%, transparent);
  opacity: 0;
  transform: translateY(8px) scale(0.96);
  transition: opacity 0.34s var(--ease-out), transform 0.5s var(--ease-out);
  flex: none;
}
.dm-photo.is-on { opacity: 1; transform: none; }
.dm-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.dm-photo--avatar { width: 28px; height: 28px; border-radius: 50%; }
.dm-photo--avatar-lg { width: 38px; height: 38px; border-radius: 50%; }

/* pildora mono generica */
.dm-chip {
  --dm-accent: var(--violet);
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-family: var(--font-mono);
  font-size: 0.56rem;
  font-weight: 560;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--dm-accent);
  background: color-mix(in srgb, var(--dm-accent) 12%, transparent);
  border-radius: 999px;
  padding: 0.2rem 0.55rem;
  opacity: 0;
  transform: translateY(6px) scale(0.9);
  transition: opacity 0.28s var(--ease-out), transform 0.32s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.dm-chip.is-on { opacity: 1; transform: none; }
.dm-chip--solid { color: #fff; background: var(--dm-accent); }

/* barras que crecen (bottom-anchored, stagger por delay inline) */
.dm-bars {
  --dm-accent: var(--violet);
  display: inline-flex;
  align-items: flex-end;
  gap: 4px;
  height: 44px;
}
.dm-bars i {
  display: block;
  width: 9px;
  height: 100%;
  border-radius: 3px 3px 1px 1px;
  background: var(--dm-accent);
  transform: scaleY(0);
  transform-origin: bottom;
  transition: transform 0.55s var(--ease-out);
  transition-delay: inherit;
}
.dm-bars i { height: var(--dm-bar-h, 100%); }
.dm-bars.is-on i { transform: scaleY(1); }

/* sparkline que se dibuja (draw-on por dashoffset, ENTER largo) */
.dm-spark {
  --dm-accent: var(--violet);
  display: inline-block;
}
.dm-spark svg { display: block; width: 100%; height: 100%; overflow: visible; }
.dm-spark path {
  fill: none;
  stroke: var(--dm-accent);
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 100;
  stroke-dashoffset: 100;
  transition: stroke-dashoffset 1.1s var(--ease-out);
}
.dm-spark.is-on path { stroke-dashoffset: 0; }

/* ---- layout común de cluster (teléfono + notas flotantes) -------------------- */
.demo__cluster {
  position: relative;
  display: grid;
  justify-items: center;
  padding: 2rem 3rem;
}
.demo__cluster .dm-note { position: absolute; z-index: 2; max-width: 15rem; }

/* (r3: los estilos de la escena "answer" se fueron con js a parked/;
   la escena viva de 2.2 es followup) */

@media (max-width: 720px) {
  .demo { min-height: 380px; }
  .demo__cluster { padding: 2.6rem 0.6rem 1.4rem; }
  .demo__cluster .dm-note { max-width: 12rem; }
}

/* ============================================================================
   r13 · GATE DE PAUSA DE LAS ESCENAS
   Scene._halt() marca el stage con .is-halted. Sin esto, una escena que sale de
   pantalla deja corriendo para siempre sus animaciones CSS infinite (shimmer de
   los esqueletos, pulso del boton, anillo de step-goal, que ademas anima
   box-shadow y repinta cada frame). En el Home el pin lo tapaba con display:none;
   Servicios y el media kit corren en flujo y no tienen esa red.
   ========================================================================== */
.demo.is-halted *,
.demo.is-halted *::before,
.demo.is-halted *::after { animation-play-state: paused !important; }
