/*
 * CIAC Vita Motion · reutilización y adaptación de código abierto (MIT).
 *
 * Transiciones de resultados/feeds derivadas de:
 *   LiveSpark / public/global.css
 *   https://github.com/side-projects-overkill/livespark
 *
 * Movimiento de clasificación/respuestas derivado de:
 *   Quizzle / webui/src/pages/InGameHost/components/Scoreboard/styles.sass
 *   Quizzle / webui/src/pages/InGameClient/styles.sass
 *   https://github.com/gnmyt/Quizzle
 *
 * Giro de tarjetas 3D derivado de:
 *   H5P Memory Game / src/styles/memory-game.css
 *   https://github.com/h5p/h5p-memory-game
 *
 * Los nombres, selectores, colores y velocidades se adaptaron al CIAC.
 * Avisos y condiciones de licencia: THIRD_PARTY_NOTICES.md.
 */

/* LiveSpark @keyframes slideInUp; nombre acotado para evitar colisiones. */
@keyframes ciacSlideInUp {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* LiveSpark: animación del indicador de actividad. */
@keyframes ciacLivePulse {
  0%, 100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.5;
    transform: scale(1.3);
  }
}

/* Quizzle, Scoreboard/styles.sass: rowRisePulse, adaptado de SASS a CSS. */
@keyframes ciacRowRisePulse {
  0% {
    transform: translateX(0);
  }
  30% {
    transform: translateX(0.4rem);
  }
  100% {
    transform: translateX(0);
  }
}

/* Quizzle, Scoreboard/styles.sass: riseBounce, adaptado de SASS a CSS. */
@keyframes ciacRiseBounce {
  0% {
    transform: translateY(0.5rem);
    opacity: 0;
  }
  60% {
    transform: translateY(-0.2rem);
    opacity: 1;
  }
  100% {
    transform: translateY(0);
    opacity: 1;
  }
}

/* Transición global breve y coherente en vez de animar por animar. */
.layout > .hero,
.layout > .section-head,
.card.solo-review,
.card.match-completed,
.card.solo-question {
  animation: ciacSlideInUp 260ms ease-out both;
}
.card.feature {
  transition: transform 210ms ease, box-shadow 210ms ease, border-color 210ms ease;
}
.card.feature:hover {
  transform: translateY(-3px);
  box-shadow: 0 15px 35px #25304a17;
}
.btn:not(:disabled) {
  transition: transform 140ms ease, background-color 160ms ease, box-shadow 180ms ease, border-color 160ms ease;
}
.btn:not(:disabled):active {
  transform: translateY(2px) scale(0.985);
}

/* Quizzle: feedback físico de pulsación en las respuestas del juego. */
.choice-tile:not(:disabled),
.solo-play-choice:not(:disabled),
.mente-poll button:not(:disabled),
.mente-stars button:not(:disabled) {
  transition: transform 150ms ease-in-out, opacity 150ms ease-in-out, border-color 170ms ease, background-color 170ms ease;
}
.choice-tile:not(:disabled):active,
.solo-play-choice:not(:disabled):active,
.mente-poll button:not(:disabled):active,
.mente-stars button:not(:disabled):active {
  transform: scale(0.97);
  opacity: 0.88;
}
.choice-tile.correct,
.solo-play-choice.right,
.solo-answer.good,
.ok {
  animation: ciacRiseBounce 420ms ease both;
}
.leaderboard li:first-child {
  animation: ciacRowRisePulse 600ms ease;
  background: #f1effc;
  border-radius: 15px;
}

/* Quizzle: cronómetro visible y aviso en los últimos segundos. */
.ciac-timer-track {
  width: 100%;
  height: 9px;
  margin: 14px 0 18px;
  border-radius: 20px;
  background: #e5e1f1;
  overflow: hidden;
}
.ciac-timer-fill {
  width: 100%;
  height: 100%;
  border-radius: 20px;
  transform-origin: left center;
  background: linear-gradient(90deg, #7e69e1, #5742c7);
  transition: width 260ms linear, background-color 200ms ease;
}
.ciac-timer-fill.ciac-urgent {
  background: #d34d62;
}
.timer.ciac-urgent {
  background: #ffeded;
  color: #af293a;
  animation: ciacLivePulse 650ms ease-in-out infinite;
}

/* LiveSpark: entrada legible de respuestas abiertas y actualización de nube. */
.mente-entry:last-child {
  animation: ciacSlideInUp 300ms ease forwards;
}
.mente-cloud span {
  transition: transform 250ms ease, color 450ms ease, font-size 350ms ease;
}
.mente-cloud span:hover {
  transform: scale(1.08);
}
.mente-bar span {
  transition: width 600ms cubic-bezier(0.16, 1, 0.3, 1);
}

/* H5P Memory Game: perspectiva y caras giratorias, adaptadas a las tarjetas CIAC. */
.match-memory-card {
  perspective: 25em;
  position: relative;
  overflow: visible;
  background: transparent;
  border: 0;
  box-shadow: none;
  padding: 0;
}
.match-memory-card .match-card-inner {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform 600ms;
}
.match-memory-card.is-flipped .match-card-inner {
  transform: rotateY(180deg);
}
.match-memory-card .match-card-front,
.match-memory-card .match-card-back {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 11px;
  overflow-wrap: anywhere;
  border: 2px solid #e4e0f0;
  border-radius: 20px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  transform-style: preserve-3d;
  user-select: none;
  box-shadow: 0 6px 18px #3033550d;
}
.match-memory-card .match-card-front {
  background: #eae5fa;
  color: #6350cc;
  font-size: 30px;
  font-weight: 800;
}
.match-memory-card .match-card-back {
  background: #fff;
  color: #263250;
  transform: rotateY(180deg);
  font-size: clamp(13px, 2vw, 18px);
  font-weight: 690;
  line-height: 1.3;
  text-align: center;
}
.match-memory-card.matched .match-card-back {
  background: #e5f6ec;
  border-color: #8bcaab;
  color: #276748;
}
.match-memory-card:focus-visible {
  outline: 3px solid #8075ee;
  outline-offset: 3px;
  border-radius: 20px;
}

/* Giro adaptado a Dialogue Cards y al giro del Memory Game de H5P. */
.match-flip {
  perspective: 35em;
  overflow: visible;
  background: transparent;
  box-shadow: none;
  border: 0;
  padding: 0;
}
.match-flip .match-flip-inner {
  position: relative;
  width: 100%;
  min-height: 270px;
  transition: transform 600ms;
  transform-style: preserve-3d;
}
.match-flip.back .match-flip-inner {
  transform: rotateY(180deg);
}
.match-flip .match-face {
  position: absolute;
  inset: 0;
  border: 2px solid #e0ddf0;
  border-radius: 30px;
  box-shadow: 0 14px 32px #181b340a;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 18px;
  padding: 27px 22px;
  overflow-wrap: anywhere;
  background: #fff;
}
.match-flip .match-face-back {
  transform: rotateY(180deg);
  background: #f0edfb;
  border-color: #b9afe4;
}
.match-drop:not(:disabled) {
  transition: border-color 200ms ease, box-shadow 200ms ease, transform 170ms ease;
}
.match-drop:not(:disabled):active,
.match-token:not(:disabled):active {
  transform: scale(0.985);
}
.match-drop.has-match {
  animation: ciacRiseBounce 420ms ease both;
}

/* H5P Drag Question: zonas de acierto y colocación adaptadas a CIACMATCH. */
.match-drop.has-match,
.match-drop:disabled {
  color: #256748;
  border: 2px solid #8bcaa8;
  box-shadow: none;
  background: #e8f8ef;
}
.match-drop.ciac-drop-over {
  border-color: #6e57d8;
  background: #f0ebff;
  box-shadow: 0 0 0 4px #6e57d821;
}

/* Evitar movimientos innecesarios en pantallas pequeñas y accesibilidad. */
/* Quizzle: reuse riseBounce for the podium, preserving rank and score order. */
.theme-ciacchut .leaderboard li:nth-child(2),
.theme-ciacchut .leaderboard li:nth-child(3) {
  animation: ciacRiseBounce 420ms ease both;
}
.theme-ciacchut .leaderboard li:nth-child(2) { animation-delay: 65ms; }
.theme-ciacchut .leaderboard li:nth-child(3) { animation-delay: 130ms; }
.theme-ciacchut .choice-tile.picked .letter {
  animation: ciacRiseBounce 280ms ease both;
}
.theme-ciacchut .choice-tile.picked { box-shadow: inset 0 -4px var(--activity-outline); }
.theme-ciacchut .leaderboard li { gap: 12px; }
.theme-ciacchut .leaderboard li strong { min-width: 0; overflow-wrap: anywhere; }
.theme-ciacchut .leaderboard li strong:last-child { font-variant-numeric: tabular-nums; }
.theme-ciacchut .leaderboard li:first-child { box-shadow: 0 4px 0 var(--activity-outline); }

/* LiveSpark slideInUp: only the changing vote count receives an arrival cue. */
.ciac-vote-arrived { animation: ciacSlideInUp 280ms ease-out both; }

/* H5P Memory: matched cards settle through opacity, keeping text readable. */
.theme-ciacmatch .match-memory-card { transition: opacity 400ms; }
.theme-ciacmatch .match-memory-card.matched { opacity: .72; }
.theme-ciacmatch .match-memory-card .match-card-front {
  box-shadow: 0 4px 0 var(--activity-outline), 0 8px 16px var(--activity-glow);
}
.theme-ciacmatch .match-memory-card .match-card-back {
  transition: background-color 200ms, border-color 200ms, box-shadow 200ms;
}
.theme-ciacmatch .match-memory-card.matched .match-card-back {
  box-shadow: inset 0 -4px #8bcaab;
}
.theme-ciacmatch .match-token.selected { box-shadow: 0 3px 0 var(--activity-outline); }

/* Quizzle response indicator: reuse the existing bounce on the selected icon. */
.theme-ciacquiz .solo-play-choice.selected .ciac-answer-icon {
  animation: ciacRiseBounce 280ms ease both;
  background: var(--activity);
  color: #fff;
}
.theme-ciacquiz .solo-play-choice.selected { box-shadow: inset 4px 0 var(--activity); }
.theme-ciacquiz .solo-answer.bad,
.theme-ciacquiz .solo-answer.partial { animation: ciacSlideInUp 240ms ease-out both; }

/* Cosmic Idle AchievementToast: preserve its x:80 exit without Framer Motion. */
.ciac-achievement-toast.ciac-toast-leaving {
  animation: ciacAchievementEnter 250ms ease-in reverse both;
  pointer-events: none;
}
.theme-ciaccoins .coins-prize { animation: coinsPop 480ms ease-out both; }
.theme-ciaccoins .coins-feedback { animation: ciacSlideInUp 260ms ease-out both; }
.theme-ciaccoins .coins-shop.affordable { box-shadow: inset 0 3px #eacb8b; }

/* Entrance cards reuse existing motion; each activity keeps its own composition. */
.mente-mini, .match-mode, .solo-mode, .coins-tile {
  animation: ciacSlideInUp 320ms ease-out both;
}
.mente-mini:nth-child(2), .match-mode:nth-child(2), .solo-mode:nth-child(2), .coins-tile:nth-child(2) { animation-delay: 50ms; }
.mente-mini:nth-child(3), .match-mode:nth-child(3), .coins-tile:nth-child(3) { animation-delay: 100ms; }
.theme-ciacmente .mente-mini { border-top: 3px solid var(--activity-outline); }
.theme-ciacmatch .match-mode .match-glyph { border-radius: 12px 24px 12px 24px; }
.theme-ciacquiz .solo-mode { border-bottom: 4px solid var(--activity-outline); }
.theme-ciaccoins .coins-tile .coins-icon { border-radius: 50%; box-shadow: inset 0 0 0 3px var(--activity-outline); }
@media (hover: hover) and (pointer: fine) {
  .match-mode:hover .match-glyph { transform: rotate(-6deg); }
  .coins-tile:hover .coins-icon { transform: translateY(-3px); }
  .mente-mini:hover .glyph { transform: translateY(-3px); }
  .solo-mode:hover .solo-symbol { transform: scale(1.06); }
  .match-glyph, .coins-tile .coins-icon, .mente-mini .glyph, .solo-symbol { transition: transform 180ms ease; }
}
@media (max-width: 720px) {
  .match-flip .match-flip-inner { min-height: 240px; }
  .match-memory-card .match-card-front,
  .match-memory-card .match-card-back { border-radius: 15px; }
}
@media (prefers-reduced-motion: reduce) {
  .layout *,
  .layout *::before,
  .layout *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
  .match-memory-card .match-card-inner,
  .match-flip .match-flip-inner { transition: none !important; }
}

