/*
 * MOVIMIENTO — animaciones de toda la web. Igual para todos los negocios.
 *
 * Reglas (ver MOVIMIENTO.md):
 * - Solo se anima transform y opacity (las hace la placa de video, no traban el celular).
 * - Las animaciones avanzadas (transición entre páginas, efectos ligados al scroll) son una
 *   mejora: si el navegador no las tiene, la web funciona igual con una entrada simple.
 * - Con "reducir movimiento" activado en el sistema, casi todo se apaga.
 *
 * Recetas adaptadas de Magic UI (sin React): Blur Fade, Text Animate (blurInUp),
 * Ripple Button, Shiny Button y Pulsating Button.
 */
:root {
  --sale: cubic-bezier(.22, 1, .36, 1);       /* frena suave al llegar */
  --entra-sale: cubic-bezier(.65, 0, .35, 1);
  /* Resorte con un pequeño rebote, para toques (aprox. rigidez 300, amortiguación 18) */
  --resorte: linear(0, .257 5.6%, .611 12%, .86 18.6%, .966 23.4%, 1.04 28.6%, 1.07 33.4%, 1.068 38.6%, 1.03 47.4%, 1.006 57.4%, .997 69.4%, 1);
  --t-toque: 140ms;
  --t-pagina: 300ms;
  --t-revelar: 450ms;
}

/*
 * Para que no se pisen, cada efecto usa su propia propiedad:
 *   toque → scale · entradas y salidas → translate + opacity · scroll → transform
 */

/* ---------- 1. Respuesta al toque: todo lo tocable se hunde un poco ---------- */
.boton, .boton-blanco, .tarjeta, .carta-item, .categoria-chip, .novedad, .pregunta button,
.enlaces a, .cabecera a, #accion a, .pie a {
  transition: scale 260ms var(--resorte);
  -webkit-user-select: none; user-select: none;
}
.boton:active, .boton-blanco:active, #accion a:active { scale: .96; transition-duration: var(--t-toque); transition-timing-function: ease-out; }
.tarjeta:active, .novedad:active { scale: .97; transition-duration: var(--t-toque); transition-timing-function: ease-out; }
.carta-item:active, .categoria-chip:active, .cabecera a:active { scale: .92; transition-duration: var(--t-toque); transition-timing-function: ease-out; }
.pregunta button:active, .enlaces a:active, .pie a:active { scale: .985; transition-duration: var(--t-toque); }

@media (hover: hover) {
  .tarjeta { transition: scale 260ms var(--resorte), translate 260ms var(--sale), box-shadow 260ms var(--sale), opacity var(--t-revelar) ease-out; }
  .tarjeta:hover { translate: 0 -3px; box-shadow: 0 14px 24px rgba(41, 41, 41, .18); }
  .tarjeta .foto img { transition: transform 500ms var(--sale); }
  .tarjeta:hover .foto img { transform: scale(1.05); }
  .boton:hover, #accion a:hover { filter: brightness(1.04); }
}

/* ---------- 2. Onda al tocar (Ripple Button de Magic UI) ---------- */
.con-onda { position: relative; overflow: hidden; isolation: isolate; }
.onda {
  position: absolute; border-radius: 50%; pointer-events: none; z-index: -1;
  background: currentColor; opacity: .16; transform: scale(0);
  animation: onda 600ms var(--sale) forwards;
}
@keyframes onda { to { transform: scale(1); opacity: 0; } }

/* ---------- 3. Barra inferior ---------- */
#barra a { position: relative; }
#barra svg { transition: scale 300ms var(--resorte), color 200ms ease; }
#barra a:active svg { scale: .8; transition-duration: 120ms; transition-timing-function: ease-out; }
#barra .salta svg { animation: salta 520ms var(--resorte); }
@keyframes salta { from { transform: scale(.7); } to { transform: scale(1); } }
#barra span { transition: color 200ms ease; }

/* ---------- 4. Entrada del contenido (Blur Fade de Magic UI) ---------- */
/* Se aplica solo cuando el JS confirmó que puede revelarlo (clase en <html>). */
.mov [data-revelar] { opacity: 0; translate: 0 16px; }
.mov [data-revelar].visible {
  opacity: 1; translate: none;
  transition: opacity var(--t-revelar) ease-out, translate var(--t-revelar) var(--sale), scale 260ms var(--resorte);
  transition-delay: calc(var(--i, 0) * 45ms), calc(var(--i, 0) * 45ms), 0ms;
}
.mov [data-revelar].visible.listo { transition-delay: 0ms; }

/* Título de portada palabra por palabra (Text Animate "blurInUp").
   Con relleno "backwards": al terminar quedan sin animación, así el toque funciona. */
.palabra { display: inline-block; white-space: pre; }
.mov .portada h1 .palabra { animation: palabra 520ms var(--sale) backwards; animation-delay: calc(120ms + var(--i) * 55ms); }
@keyframes palabra { from { opacity: 0; translate: 0 14px; filter: blur(6px); } }
.mov .portada-botones > * { animation: aparece 480ms var(--sale) backwards; animation-delay: calc(380ms + var(--i, 0) * 70ms); }
.mov .encabezado > * { animation: aparece-arriba 420ms var(--sale) backwards; animation-delay: calc(40ms + var(--i, 0) * 60ms); }
/* "Ver carta" de la portada: cada 3 s se sacude y se agranda un poquito, para llamar la atención.
   Usa transform (la entrada usa translate y el toque, scale). */
.mov .encabezado > .boton {
  animation: aparece-arriba 420ms var(--sale) backwards, sacude 3s ease-in-out infinite;
  animation-delay: calc(40ms + var(--i, 0) * 60ms), 1.2s;
}
@keyframes sacude {
  0%, 76%, 100% { transform: none; }
  79% { transform: rotate(-5deg) scale(1.05); }
  82% { transform: rotate(5deg) scale(1.08); }
  85% { transform: rotate(-4deg) scale(1.08); }
  88% { transform: rotate(3deg) scale(1.07); }
  91% { transform: rotate(-2deg) scale(1.05); }
  94% { transform: rotate(1deg) scale(1.02); }
}
@keyframes aparece { from { opacity: 0; translate: 0 10px; } }
@keyframes aparece-arriba { from { opacity: 0; translate: 0 -6px; } }

/* Fotos: aparecen suave cuando terminan de cargar */
img[data-suave] { opacity: 0; transition: opacity 450ms ease-out; }
img[data-suave].cargada { opacity: 1; }

/* ---------- 5. Preguntas: abrir y cerrar con altura animada ---------- */
.pregunta .respuesta-caja { display: grid; grid-template-rows: 0fr; transition: grid-template-rows 320ms var(--sale); }
.pregunta.abierta .respuesta-caja { grid-template-rows: 1fr; }
.pregunta .respuesta-caja > div { overflow: hidden; }
.pregunta .respuesta { opacity: 0; transform: translateY(-4px); transition: opacity 240ms ease, transform 320ms var(--sale); }
.pregunta.abierta .respuesta { opacity: 1; transform: none; transition-delay: 60ms; }
.pregunta svg { transition: transform 320ms var(--resorte); }

/* ---------- 6. Botón "Pedir por WhatsApp" ---------- */
#accion a { position: relative; overflow: hidden; isolation: isolate; }
/* Brillo que cruza el botón cada tanto (Shiny Button de Magic UI) */
#accion a::after {
  content: ''; position: absolute; inset: 0; z-index: -1; pointer-events: none;
  background: linear-gradient(105deg, transparent 35%, rgba(255, 255, 255, .45) 50%, transparent 65%);
  transform: translateX(-100%);
  animation: brillo 3.6s var(--entra-sale) 1.2s infinite;
}
@keyframes brillo { 0% { transform: translateX(-100%); } 35%, 100% { transform: translateX(100%); } }
.mov #accion.entra a { animation: sube 420ms var(--sale) backwards; }
@keyframes sube { from { translate: 0 100%; } }

/* ---------- 7. "Abierto ahora": punto que late (Pulsating Button de Magic UI) ---------- */
.estado.abierto { position: relative; }
.estado.abierto::after {
  content: ''; position: absolute; left: 0; top: 50%; width: 8px; height: 8px; margin-top: -4px;
  border-radius: 50%; background: #2e9e4f; animation: late 1.8s ease-out infinite;
}
@keyframes late { from { transform: scale(1); opacity: .5; } to { transform: scale(3); opacity: 0; } }

/* Portada: las fotos se turnan con un fundido y derivan muy despacio todo el tiempo
   (zoom y desplazamiento mínimos). La deriva usa scale + translate; el scroll, transform. */
.portada-fotos img { transition: opacity 1.2s ease-in-out; }
.mov .portada-fotos { animation: deriva 9s ease-in-out infinite alternate; }
@keyframes deriva {
  from { scale: 1.04; translate: .8% .5%; }
  to { scale: 1.1; translate: -.8% -.5%; }
}

/* ---------- 8. Efectos ligados al scroll (solo navegadores que los soportan) ---------- */
@supports (animation-timeline: scroll()) {
  /* Portada: la foto baja más lento que la página y el texto se desvanece */
  .portada > .portada-fotos, .portada > .hueco {
    animation: paralaje linear both; animation-timeline: scroll(root); animation-range: 0 320px;
  }
  .mov .portada > .portada-fotos {
    animation: paralaje linear both, deriva 9s ease-in-out infinite alternate;
    animation-timeline: scroll(root), auto; animation-range: 0 320px, normal;
  }
  @keyframes paralaje { to { transform: translateY(110px) scale(1.08); } }
  .portada-contenido { animation: se-va linear both; animation-timeline: scroll(root); animation-range: 0 260px; }
  @keyframes se-va { to { opacity: .1; transform: translateY(-24px); } }

  /* Encabezado del producto: aparece la línea al bajar */
  .cabecera { animation: linea linear both; animation-timeline: scroll(root); animation-range: 0 32px; }
  @keyframes linea { from { box-shadow: 0 1px 0 transparent; } to { box-shadow: 0 1px 0 var(--linea); } }
}
@supports (animation-timeline: view()) {
  /* Carrusel de novedades: la del centro en foco, las de los costados más chicas */
  .novedad { animation: foco linear both; animation-timeline: view(inline); }
  @keyframes foco {
    0% { transform: scale(.9); opacity: .55; }
    50% { transform: scale(1); opacity: 1; }
    100% { transform: scale(.9); opacity: .55; }
  }

  /* Galería en perspectiva (tipo coverflow): la foto del centro de frente; las de los costados
     más chicas y giradas, con el borde de afuera hacia el fondo. Sigue al dedo, no se mueve sola. */
  .galeria-foto { view-timeline: --foto inline; }
  .galeria-foto > * { animation: giro linear both; animation-timeline: --foto; }
  @keyframes giro {
    0% { transform: perspective(700px) translateX(-15%) rotateY(42deg) scale(.82); }
    50% { transform: perspective(700px) translateX(0) rotateY(0) scale(1); }
    100% { transform: perspective(700px) translateX(15%) rotateY(-42deg) scale(.82); }
  }
}

/* ---------- 9. Transición entre páginas (View Transitions del navegador) ---------- */
@view-transition { navigation: none; }
#barra { view-transition-name: barra; }
#accion { view-transition-name: accion; }
.raya { view-transition-name: raya; }
.producto-foto { view-transition-name: foto-producto; }

::view-transition-old(root), ::view-transition-new(root) { animation-duration: var(--t-pagina); animation-timing-function: var(--sale); }
/* Más adentro (carta → categoría → producto): entra desde la derecha */
html[data-dir="adelante"]::view-transition-old(root) { animation-name: sale-izq; }
html[data-dir="adelante"]::view-transition-new(root) { animation-name: entra-der; }
/* Hacia atrás: al revés */
html[data-dir="atras"]::view-transition-old(root) { animation-name: sale-der; }
html[data-dir="atras"]::view-transition-new(root) { animation-name: entra-izq; }
/* Entre secciones de la barra: fundido con una subida corta */
html[data-dir="lado"]::view-transition-old(root) { animation-name: desvanece; animation-duration: 160ms; }
html[data-dir="lado"]::view-transition-new(root) { animation-name: entra-arriba; }

@keyframes sale-izq { to { opacity: 0; transform: translateX(-40px); } }
@keyframes entra-der { from { opacity: 0; transform: translateX(40px); } }
@keyframes sale-der { to { opacity: 0; transform: translateX(40px); } }
@keyframes entra-izq { from { opacity: 0; transform: translateX(-40px); } }
@keyframes desvanece { to { opacity: 0; } }
@keyframes entra-arriba { from { opacity: 0; transform: translateY(12px); } }

/* La foto del producto "viaja" de la tarjeta a la ficha */
::view-transition-group(foto-producto) { animation-duration: 420ms; animation-timing-function: var(--sale); }
::view-transition-old(foto-producto), ::view-transition-new(foto-producto) { height: 100%; object-fit: cover; }
/* La raya de la categoría activa se desliza */
::view-transition-group(raya) { animation-duration: 380ms; animation-timing-function: var(--resorte); }
/* La barra y el botón de pedir no se mueven con la página */
::view-transition-group(barra) { animation-duration: 200ms; }
::view-transition-new(accion):only-child { animation: sube-vt 420ms var(--sale) both; }
::view-transition-old(accion):only-child { animation: baja-vt 220ms ease-in both; }
@keyframes sube-vt { from { transform: translateY(100%); } }
@keyframes baja-vt { to { transform: translateY(100%); } }

/* Navegadores sin View Transitions: entrada simple */
.mov #pagina.entrando { animation: entra-arriba 280ms var(--sale); }

/* ---------- 10. PC (desde 768 px) ---------- */
#arriba { view-transition-name: arriba; }
.raya-arriba { view-transition-name: raya-arriba; }
::view-transition-group(arriba) { animation-duration: 250ms; }
::view-transition-group(raya-arriba) { animation-duration: 380ms; animation-timing-function: var(--resorte); }

/* El botón de pedir de la ficha también brilla en PC */
.pedir-en-linea { position: relative; overflow: hidden; isolation: isolate; }
.pedir-en-linea::after {
  content: ''; position: absolute; inset: 0; z-index: -1; pointer-events: none;
  background: linear-gradient(105deg, transparent 35%, rgba(255, 255, 255, .45) 50%, transparent 65%);
  transform: translateX(-100%); animation: brillo 3.6s var(--entra-sale) 1.2s infinite;
}

@media (min-width: 768px) {
  /* La portada es más alta: el efecto de scroll dura más */
  @supports (animation-timeline: scroll()) {
    .portada > .portada-fotos, .portada > .hueco { animation-range: 0 552px; }
    .mov .portada > .portada-fotos { animation-range: 0 552px, normal; }
    .portada-contenido { animation-range: 0 440px; }
  }
}

/* Con mouse: cada elemento reacciona al pasar por encima */
@media (hover: hover) and (min-width: 768px) {
  #arriba nav a::after {
    content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: var(--acento);
    scale: 0 1; transform-origin: left; transition: scale 300ms var(--sale);
  }
  #arriba nav a:not([aria-current]):hover::after { scale: 1 1; opacity: .35; }
  .boton, .boton-blanco { transition: scale 260ms var(--resorte), translate 260ms var(--sale), box-shadow 260ms var(--sale); }
  .boton:hover, .boton-blanco:hover { translate: 0 -2px; box-shadow: 0 6px 14px rgba(41, 41, 41, .18); }
  .categoria-chip .foto, .carta-item .foto { transition: translate 300ms var(--resorte); }
  .categoria-chip:hover .foto, .carta-item:hover .foto { translate: 0 -4px; }
  .novedad .foto img, .historia .foto img, .destacado .foto img { transition: transform 600ms var(--sale); }
  .novedad:hover .foto img { transform: scale(1.04); }
  .pregunta button { transition: color 200ms ease, scale 260ms var(--resorte); }
  .pregunta button:hover { color: var(--texto-2); }
  .pregunta button:hover svg { translate: 3px 0; transition: translate 260ms var(--resorte); }
  .enlaces a:hover svg { translate: 3px 0; transition: translate 260ms var(--resorte); }
  .pie a { transition: color 200ms ease; }
  .pie a:hover { color: var(--texto-2); }
  .cabecera a:hover svg { translate: -3px 0; transition: translate 260ms var(--resorte); }
}

/* ---------- Reducir movimiento ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after, ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) {
    animation: none !important; transition: none !important;
  }
  .mov [data-revelar], img[data-suave] { opacity: 1 !important; translate: none !important; }
}
