/* =====================================================
   REPSOL GBC - ANIMATIONS & TRANSITIONS
   Advanced Animation System for Game Interactions
   ===================================================== */

/* === LOADING ANIMATIONS === */
.loading-dots {
  display: inline-block;
  position: relative;
  width: 80px;
  height: 80px;
}

.loading-dots div {
  position: absolute;
  top: 33px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--repsol-white);
  animation-timing-function: cubic-bezier(0, 1, 1, 0);
}

.loading-dots div:nth-child(1) {
  left: 8px;
  animation: loading-dots1 0.6s infinite;
}

.loading-dots div:nth-child(2) {
  left: 8px;
  animation: loading-dots2 0.6s infinite;
}

.loading-dots div:nth-child(3) {
  left: 32px;
  animation: loading-dots2 0.6s infinite;
}

.loading-dots div:nth-child(4) {
  left: 56px;
  animation: loading-dots3 0.6s infinite;
}

@keyframes loading-dots1 {
  0% { transform: scale(0); }
  100% { transform: scale(1); }
}

@keyframes loading-dots3 {
  0% { transform: scale(1); }
  100% { transform: scale(0); }
}

@keyframes loading-dots2 {
  0% { transform: translate(0, 0); }
  100% { transform: translate(24px, 0); }
}

/* === STATION ENTRANCE ANIMATIONS === */
.station-enter {
  animation: stationEnter 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes stationEnter {
  0% {
    opacity: 0;
    transform: translateY(100px) scale(0.8);
  }
  60% {
    opacity: 0.8;
    transform: translateY(-10px) scale(1.05);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* === SUCCESS ANIMATIONS === */
.success-animation {
  position: relative;
  overflow: hidden;
}

.success-animation::after {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(40, 167, 69, 0.4), transparent);
  animation: successSweep 0.8s ease-out;
}

@keyframes successSweep {
  0% { left: -100%; }
  100% { left: 100%; }
}

.success-bounce {
  animation: successBounce 0.6s ease;
}

@keyframes successBounce {
  0%, 20%, 53%, 80%, 100% {
    transform: translate3d(0, 0, 0);
  }
  40%, 43% {
    transform: translate3d(0, -20px, 0);
  }
  70% {
    transform: translate3d(0, -10px, 0);
  }
  90% {
    transform: translate3d(0, -4px, 0);
  }
}

/* === ERROR ANIMATIONS === */
.error-shake {
  animation: errorShake 0.5s ease-in-out;
}

@keyframes errorShake {
  0%, 100% { transform: translateX(0); }
  10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
  20%, 40%, 60%, 80% { transform: translateX(5px); }
}

.error-pulse {
  animation: errorPulse 0.5s ease-in-out;
}

@keyframes errorPulse {
  0% { 
    background-color: var(--error-red);
    transform: scale(1);
  }
  50% { 
    background-color: #ff6b6b;
    transform: scale(1.05);
  }
  100% { 
    background-color: var(--error-red);
    transform: scale(1);
  }
}

/* === HINT ANIMATIONS === */
.hint-glow {
  position: relative;
  animation: hintGlow 2s ease-in-out infinite;
}

@keyframes hintGlow {
  0%, 100% {
    box-shadow: 0 0 10px rgba(255, 107, 53, 0.3);
  }
  50% {
    box-shadow: 0 0 25px rgba(255, 107, 53, 0.8), 0 0 35px rgba(255, 107, 53, 0.4);
  }
}

.hint-bounce {
  animation: hintBounce 1s ease-in-out infinite;
}

@keyframes hintBounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

/* === SCORE ANIMATIONS === */
.score-popup {
  position: absolute;
  color: var(--success-green);
  font-weight: bold;
  font-size: var(--font-size-lg);
  pointer-events: none;
  z-index: 1000;
  animation: scorePopup 1.5s ease-out forwards;
}

@keyframes scorePopup {
  0% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  50% {
    opacity: 1;
    transform: translateY(-30px) scale(1.2);
  }
  100% {
    opacity: 0;
    transform: translateY(-60px) scale(0.8);
  }
}

.score-counter {
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.score-increase {
  animation: scoreIncrease 0.6s ease;
}

@keyframes scoreIncrease {
  0% { transform: scale(1); }
  50% { transform: scale(1.3); color: var(--success-green); }
  100% { transform: scale(1); }
}

/* === TIMER ANIMATIONS === */
.timer-warning {
  animation: timerWarning 0.5s ease-in-out infinite;
}

@keyframes timerWarning {
  0%, 100% { background: var(--gradient-primary); }
  50% { background: var(--gradient-warning); }
}

.timer-critical {
  animation: timerCritical 0.3s ease-in-out infinite;
}

@keyframes timerCritical {
  0%, 100% { 
    background: var(--gradient-primary);
    transform: scale(1);
  }
  50% { 
    background: linear-gradient(135deg, var(--error-red) 0%, #ff6b6b 100%);
    transform: scale(1.05);
  }
}

/* === PROGRESS ANIMATIONS === */
.progress-fill-animated {
  background: linear-gradient(90deg, var(--repsol-orange), var(--repsol-light-blue), var(--repsol-orange));
  background-size: 200% 100%;
  animation: progressFlow 2s linear infinite;
}

@keyframes progressFlow {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.level-complete {
  animation: levelComplete 1s ease-in-out;
}

@keyframes levelComplete {
  0% { transform: scale(1) rotate(0deg); }
  25% { transform: scale(1.1) rotate(5deg); }
  75% { transform: scale(1.1) rotate(-5deg); }
  100% { transform: scale(1) rotate(0deg); }
}

/* === DRAG & DROP ANIMATIONS === */
.draggable {
  transition: all 0.2s ease;
  cursor: grab;
}

.draggable:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.dragging {
  cursor: grabbing;
  transform: rotate(5deg) scale(1.05);
  z-index: 1000;
  opacity: 0.8;
}

.drop-zone {
  transition: all 0.3s ease;
  border: 2px dashed transparent;
}

.drop-zone.drag-over {
  border-color: var(--repsol-orange);
  background: rgba(255, 107, 53, 0.1);
  transform: scale(1.02);
}

.drop-zone.correct-drop {
  animation: correctDrop 0.6s ease;
}

@keyframes correctDrop {
  0% { 
    background: rgba(40, 167, 69, 0.2);
    transform: scale(1);
  }
  50% { 
    background: rgba(40, 167, 69, 0.4);
    transform: scale(1.05);
  }
  100% { 
    background: rgba(40, 167, 69, 0.1);
    transform: scale(1);
  }
}

.drop-zone.incorrect-drop {
  animation: incorrectDrop 0.6s ease;
}

@keyframes incorrectDrop {
  0% { 
    background: rgba(220, 53, 69, 0.2);
    transform: scale(1);
  }
  50% { 
    background: rgba(220, 53, 69, 0.4);
    transform: scale(1.05);
  }
  100% { 
    background: transparent;
    transform: scale(1);
  }
}

/* === BUTTON ANIMATIONS === */
.btn-pulse {
  animation: btnPulse 2s infinite;
}

@keyframes btnPulse {
  0% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(255, 107, 53, 0.7);
  }
  70% {
    transform: scale(1);
    box-shadow: 0 0 0 10px rgba(255, 107, 53, 0);
  }
  100% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(255, 107, 53, 0);
  }
}

.btn-loading {
  position: relative;
  color: transparent !important;
}

.btn-loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border: 2px solid transparent;
  border-top: 2px solid currentColor;
  border-radius: 50%;
  animation: btnSpin 1s linear infinite;
  color: var(--repsol-white);
}

@keyframes btnSpin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* === CARD FLIP ANIMATIONS === */
.card-flip {
  perspective: 1000px;
}

.card-flip-inner {
  position: relative;
  width: 100%;
  height: 100%;
  text-align: center;
  transition: transform 0.6s;
  transform-style: preserve-3d;
}

.card-flip.flipped .card-flip-inner {
  transform: rotateY(180deg);
}

.card-flip-front, .card-flip-back {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  border-radius: var(--radius-lg);
}

.card-flip-back {
  transform: rotateY(180deg);
}

/* === REVEAL ANIMATIONS === */
.reveal-text {
  overflow: hidden;
}

.reveal-text span {
  display: inline-block;
  opacity: 0;
  animation: revealText 0.8s ease forwards;
}

@keyframes revealText {
  0% {
    opacity: 0;
    transform: translateY(100%);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Stagger the animation for multiple spans */
.reveal-text span:nth-child(1) { animation-delay: 0.1s; }
.reveal-text span:nth-child(2) { animation-delay: 0.2s; }
.reveal-text span:nth-child(3) { animation-delay: 0.3s; }
.reveal-text span:nth-child(4) { animation-delay: 0.4s; }
.reveal-text span:nth-child(5) { animation-delay: 0.5s; }

/* === PARTICLE EFFECTS === */
.particles {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: hidden;
}

.particle {
  position: absolute;
  width: 4px;
  height: 4px;
  background: var(--repsol-orange);
  border-radius: 50%;
  animation: particleFloat 3s ease-in-out infinite;
}

@keyframes particleFloat {
  0% {
    opacity: 0;
    transform: translateY(100vh) scale(0);
  }
  10% {
    opacity: 1;
    transform: translateY(90vh) scale(1);
  }
  90% {
    opacity: 1;
    transform: translateY(10vh) scale(1);
  }
  100% {
    opacity: 0;
    transform: translateY(0) scale(0);
  }
}

/* Random delays and positions for particles */
.particle:nth-child(1) { left: 10%; animation-delay: 0s; }
.particle:nth-child(2) { left: 20%; animation-delay: 0.5s; }
.particle:nth-child(3) { left: 30%; animation-delay: 1s; }
.particle:nth-child(4) { left: 40%; animation-delay: 1.5s; }
.particle:nth-child(5) { left: 50%; animation-delay: 2s; }
.particle:nth-child(6) { left: 60%; animation-delay: 2.5s; }
.particle:nth-child(7) { left: 70%; animation-delay: 3s; }
.particle:nth-child(8) { left: 80%; animation-delay: 3.5s; }
.particle:nth-child(9) { left: 90%; animation-delay: 4s; }

/* === MORPHING BACKGROUND === */
.morphing-bg {
  background: linear-gradient(45deg, #ff6b35, #003f7f, #4a90e2, #ff6b35);
  background-size: 400% 400%;
  animation: morphingGradient 8s ease infinite;
}

@keyframes morphingGradient {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

/* === TYPEWRITER EFFECT === */
.typewriter {
  overflow: hidden;
  border-right: 2px solid var(--repsol-orange);
  white-space: nowrap;
  animation: 
    typing 3.5s steps(40, end),
    blink-caret 0.75s step-end infinite;
}

@keyframes typing {
  from { width: 0; }
  to { width: 100%; }
}

@keyframes blink-caret {
  from, to { border-color: transparent; }
  50% { border-color: var(--repsol-orange); }
}

/* === RESPONSIVE ANIMATIONS === */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media (max-width: 768px) {
  .station-enter {
    animation-duration: 0.6s;
  }
  
  .success-bounce {
    animation-duration: 0.4s;
  }
  
  .card-flip-inner {
    transition-duration: 0.4s;
  }
}
