/* Riang! Betang 4.1 — festival motion layer (js/festive.js).
   Living background, Si Tingang the hornbill mascot, confetti, entrance and
   reaction animations. Everything stops when the ✦ animation toggle is off
   (body.low-motion) or the device asks for reduced motion. */

/* ---------- Living background behind the workspace ---------- */
#fx-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}
.workspace {
  position: relative;
  z-index: 1;
}
.fx-blob {
  position: absolute;
  width: 46vmax;
  height: 46vmax;
  border-radius: 50%;
  opacity: 0.55;
  animation: fxDrift 26s ease-in-out infinite alternate;
}
.fx-blob:nth-child(1) { left: -12vmax; top: -14vmax; background: radial-gradient(circle, #ffd6f0 0%, transparent 65%); }
.fx-blob:nth-child(2) { right: -14vmax; top: 8vh; background: radial-gradient(circle, #d4ecff 0%, transparent 65%); animation-duration: 31s; }
.fx-blob:nth-child(3) { left: 20vw; bottom: -20vmax; background: radial-gradient(circle, #fff1c2 0%, transparent 65%); animation-duration: 36s; }
.fx-blob:nth-child(4) { right: 10vw; bottom: -16vmax; background: radial-gradient(circle, #d9f7e6 0%, transparent 65%); animation-duration: 29s; }
@keyframes fxDrift {
  0% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(5vw, 4vh) scale(1.12); }
  100% { transform: translate(-4vw, -3vh) scale(0.95); }
}
.fx-orn {
  position: absolute;
  bottom: -40px;
  left: var(--x);
  font-size: var(--s);
  color: var(--c);
  opacity: 0;
  animation: fxRise var(--d) linear infinite;
  animation-delay: var(--w);
}
@keyframes fxRise {
  0% { opacity: 0; transform: translateY(0) rotate(0deg); }
  10% { opacity: 0.55; }
  85% { opacity: 0.4; }
  100% { opacity: 0; transform: translateY(-110vh) rotate(var(--r)); }
}

/* ---------- Si Tingang, the hornbill mascot ---------- */
.fx-mascot {
  position: relative;
  display: inline-grid;
  justify-items: center;
  width: 118px;
  flex: none;
}
.fx-mascot svg {
  width: 100%;
  height: auto;
  overflow: visible;
  filter: drop-shadow(0 10px 14px rgba(72, 32, 128, 0.25));
}
.fx-mascot .tg-all { animation: tgBob 2.6s ease-in-out infinite; transform-origin: 60px 112px; }
.fx-mascot .tg-wing { animation: tgFlap 2.6s ease-in-out infinite; transform-origin: 46px 66px; }
.fx-mascot .tg-eye { animation: tgBlink 4.2s infinite; transform-origin: 69px 43px; }
.fx-mascot.cheer .tg-all { animation: tgJump 0.55s cubic-bezier(0.3, 1.6, 0.5, 1) 3; }
.fx-mascot.cheer .tg-wing { animation: tgFlap 0.28s ease-in-out infinite; }
.fx-mascot.comfort .tg-all { animation: tgTilt 1.6s ease-in-out 1; }
@keyframes tgBob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
@keyframes tgFlap { 0%, 100% { transform: rotate(0deg); } 50% { transform: rotate(-22deg); } }
@keyframes tgBlink { 0%, 92%, 100% { transform: scaleY(1); } 95% { transform: scaleY(0.1); } }
@keyframes tgJump { 0%, 100% { transform: translateY(0) scale(1); } 40% { transform: translateY(-22px) scale(1.05, 0.95); } }
@keyframes tgTilt { 0%, 100% { transform: rotate(0); } 30% { transform: rotate(-9deg); } 65% { transform: rotate(6deg); } }
.fx-bubble {
  position: absolute;
  right: 92%;
  top: 8px;
  max-width: 190px;
  padding: 9px 13px;
  border-radius: 16px 16px 4px 16px;
  background: #fff;
  color: #3b2470;
  font: 700 13px/1.3 "Segoe UI", system-ui, sans-serif;
  white-space: nowrap;
  box-shadow: 0 8px 22px rgba(72, 32, 128, 0.18);
  animation: fxBubble 0.45s cubic-bezier(0.3, 1.6, 0.5, 1);
}
@keyframes fxBubble { from { opacity: 0; transform: scale(0.4) translateY(10px); } to { opacity: 1; transform: none; } }
.dashboard-intro .fx-mascot { margin-left: auto; margin-right: 12px; }
/* A reaction pop during play: the mascot hops in from a corner, then leaves. */
.fx-react {
  position: fixed;
  left: 18px;
  bottom: 84px;
  z-index: 70;
  width: 96px;
  pointer-events: none;
  animation: fxReact 2.2s cubic-bezier(0.2, 0.9, 0.3, 1.2) forwards;
}
.fx-react .fx-bubble { left: 88%; right: auto; border-radius: 16px 16px 16px 4px; }
@keyframes fxReact {
  0% { opacity: 0; transform: translateY(120%) rotate(-12deg); }
  14% { opacity: 1; transform: translateY(0) rotate(0); }
  82% { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(120%); }
}

/* ---------- Combo banner ---------- */
.fx-combo {
  position: fixed;
  left: 50%;
  top: 22%;
  z-index: 75;
  pointer-events: none;
  padding: 10px 26px;
  border-radius: 999px;
  background: linear-gradient(90deg, #ff6b3d, #ffb230, #ff4f8b);
  color: #fff;
  font: 900 clamp(22px, 4vw, 38px) "Segoe UI", system-ui, sans-serif;
  text-shadow: 0 3px 0 rgba(120, 30, 10, 0.35);
  box-shadow: 0 14px 40px rgba(255, 90, 40, 0.45);
  transform: translateX(-50%);
  animation: fxCombo 1.9s cubic-bezier(0.2, 0.9, 0.3, 1.3) forwards;
}
@keyframes fxCombo {
  0% { opacity: 0; transform: translateX(-50%) scale(0.3) rotate(-8deg); }
  18% { opacity: 1; transform: translateX(-50%) scale(1.15) rotate(3deg); }
  30% { transform: translateX(-50%) scale(1) rotate(0); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translateX(-50%) translateY(-30px) scale(0.9); }
}

/* ---------- Confetti canvas ---------- */
#fx-confetti {
  position: fixed;
  inset: 0;
  z-index: 80;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* ---------- Micro-interactions ---------- */
.fx-ripple-host {
  position: relative;
  overflow: hidden;
}
.fx-ripple {
  position: absolute;
  width: 12px;
  height: 12px;
  margin: -6px 0 0 -6px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.55);
  pointer-events: none;
  animation: fxRipple 0.6s ease-out forwards;
}
@keyframes fxRipple { to { transform: scale(26); opacity: 0; } }
.quick-game,
.quiz-card,
.mode,
.dash-stat {
  transition: transform 0.28s cubic-bezier(0.2, 0.9, 0.3, 1.4), box-shadow 0.28s;
}
@media (hover: hover) {
  .quick-game:hover { transform: translateY(-6px) rotate(-1deg); }
  .quiz-card:hover { transform: translateY(-6px); box-shadow: 0 18px 40px rgba(72, 32, 128, 0.2); }
  .mode:hover, .dash-stat:hover { transform: translateY(-4px) scale(1.02); }
  .quick-game:hover .quick-emoji, .dash-stat:hover .joy-icon { animation: fxWiggle 0.6s ease-in-out; }
}
.btn:active,
.answer:active,
.quick-game:active,
.mode:active {
  transform: scale(0.95);
}
@keyframes fxWiggle {
  0%, 100% { transform: rotate(0); }
  25% { transform: rotate(-14deg) scale(1.1); }
  60% { transform: rotate(10deg) scale(1.1); }
}

/* ---------- Play: answers, feedback, timer, countdown ---------- */
.answer.fx-pop { animation: fxAnswerIn 0.5s cubic-bezier(0.3, 1.5, 0.5, 1) backwards; }
@keyframes fxAnswerIn { from { opacity: 0; transform: translateY(24px) scale(0.85); } }
.answer-feedback.is-correct { animation: fxGood 0.7s cubic-bezier(0.3, 1.5, 0.5, 1); }
.answer-feedback.is-wrong { animation: fxShake 0.55s ease-in-out; }
@keyframes fxGood { 0% { transform: scale(0.85); } 60% { transform: scale(1.04); } 100% { transform: scale(1); } }
@keyframes fxShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-10px); }
  40% { transform: translateX(9px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(4px); }
}
.clock.urgent { animation: fxUrgent 0.5s ease-in-out infinite alternate; }
@keyframes fxUrgent { from { transform: scale(1); } to { transform: scale(1.14); filter: drop-shadow(0 0 10px rgba(255, 60, 60, 0.7)); } }
.countdown-number { text-shadow: 0 0 40px rgba(255, 210, 90, 0.7); }
.result-title .celebration { display: inline-block; animation: fxSpinIn 1.2s cubic-bezier(0.2, 0.9, 0.3, 1.3); }
@keyframes fxSpinIn { from { opacity: 0; transform: rotate(-200deg) scale(0.2); } to { opacity: 1; transform: none; } }
.kpi.fx-kpi { animation: fxPopIn 0.6s cubic-bezier(0.3, 1.5, 0.5, 1) backwards; }
@keyframes fxPopIn { from { opacity: 0; transform: scale(0.6) translateY(20px); } }
.player.fx-join { animation: fxPopIn 0.55s cubic-bezier(0.3, 1.6, 0.5, 1); }

/* ---------- Motion off ---------- */
body.low-motion #fx-bg,
body.low-motion .fx-react,
body.low-motion .fx-combo,
body.low-motion #fx-confetti {
  display: none;
}
body.low-motion .fx-mascot *,
body.low-motion .fx-orn,
body.low-motion .fx-blob,
body.low-motion .answer,
body.low-motion .answer-feedback,
body.low-motion .clock.urgent,
body.low-motion .kpi,
body.low-motion .celebration {
  animation: none !important;
}
@media (prefers-reduced-motion: reduce) {
  #fx-bg, .fx-react, .fx-combo, #fx-confetti { display: none; }
  .fx-mascot *, .answer, .answer-feedback, .clock.urgent, .kpi, .celebration { animation: none !important; }
}
@media (max-width: 760px) {
  .dashboard-intro .fx-mascot { width: 84px; margin-right: 0; }
  .fx-bubble { font-size: 12px; max-width: 150px; white-space: normal; }
  .fx-react { width: 74px; left: 10px; bottom: 80px; }
}
