/* Base optimization for all cells */
.cell {
  backface-visibility: hidden;
  transform: translate3d(0, 0, 0);
  will-change: auto;
  position: relative;
  box-sizing: border-box;
  overflow: hidden;
  contain: layout style paint;
  transition: opacity 0.03s ease, transform 0.03s ease;
}

/* Tile animations for 2048 - Super responsive and fast */

@keyframes cell-move-smooth {
  from {
    transform: translate3d(
      clamp(-222px, var(--from-x, 0), 222px), 
      clamp(-222px, var(--from-y, 0), 222px), 
      0
    );
    opacity: 0.98;
  }
  to {
    transform: translate3d(0, 0, 0);
    opacity: 1;
  }
}

/* Removed cell-appear animation - new tiles appear instantly */

@keyframes cell-merge-boom {
  0% {
    transform: scale(1);
  }
  60% {
    transform: scale(1.05);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes cell-stuck {
  0%, 100% {
    transform: translateX(0);
  }
  50% {
    transform: translateX(-0.5px);
  }
}

@keyframes overlay-fade-in {
  0% {
    background: rgba(0, 0, 0, 0);
    backdrop-filter: blur(0px);
  }
  50% {
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(4px);
  }
  100% {
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(4px);
  }
}

@keyframes message-appear {
  0% {
    opacity: 0;
    transform: scale(0.5) translateY(20px);
  }
  50% {
    opacity: 0;
    transform: scale(0.5) translateY(20px);
  }
  100% {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

@keyframes win-gradient-text {
  0% {
    background: linear-gradient(45deg, #ffd700, #ffd700);
    background-clip: text;
    -webkit-background-clip: text;
    color: transparent;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.3);
  }
  50% {
    background: linear-gradient(45deg, #ffd700, #ffed4a, #ffd700);
    background-clip: text;
    -webkit-background-clip: text;
    color: transparent;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 0 20px rgba(255, 215, 0, 0.6);
  }
  100% {
    background: linear-gradient(45deg, #ffd700, #ffed4a, #fff59d, #ffd700);
    background-clip: text;
    -webkit-background-clip: text;
    color: transparent;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 0 30px rgba(255, 215, 0, 0.8);
  }
}

@keyframes lose-gradient-text {
  0% {
    background: linear-gradient(45deg, #ff6b6b, #ff6b6b);
    background-clip: text;
    -webkit-background-clip: text;
    color: transparent;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 0 10px rgba(255, 107, 107, 0.3);
  }
  50% {
    background: linear-gradient(45deg, #ff6b6b, #ff5252, #ff6b6b);
    background-clip: text;
    -webkit-background-clip: text;
    color: transparent;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 0 20px rgba(255, 107, 107, 0.6);
  }
  100% {
    background: linear-gradient(45deg, #ff6b6b, #ff5252, #ff8a80, #ff6b6b);
    background-clip: text;
    -webkit-background-clip: text;
    color: transparent;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 0 30px rgba(255, 107, 107, 0.8);
  }
}

.cell.move {
  animation: cell-move-smooth 0.08s ease-out;
  will-change: transform;
  z-index: 2;
  overflow: hidden;
  contain: layout;
  clip-path: inset(0);
}

/* Removed .cell.new animation */

.cell.merge {
  animation: cell-merge-boom 0.06s ease-out;
  will-change: transform;
}

.cell.stuck {
  animation: cell-stuck 0.06s ease-out;
  will-change: transform;
}

.you-win-message {
  position: absolute !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  width: 100% !important;
  height: 100% !important;
  background: rgba(0, 0, 0, 0) !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  z-index: 100 !important;
  pointer-events: auto !important;
  margin: 0 !important;
  padding: 0 !important;
  border: none !important;
  outline: none !important;
  box-sizing: border-box !important;
  border-radius: 12px !important;
  animation: overlay-fade-in 2s ease-out forwards;
}

.you-win-message > div {
  font-size: 2.5rem !important;
  font-weight: bold !important;
  background: linear-gradient(45deg, #ffd700, #ffd700);
  background-clip: text;
  -webkit-background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
  animation: message-appear 2s ease-out forwards, win-gradient-text 3s ease-in-out infinite;
  text-align: center;
  filter: drop-shadow(0 0 10px rgba(255, 215, 0, 0.5));
}

.game-over-message {
  position: absolute !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  width: 100% !important;
  height: 100% !important;
  background: rgba(0, 0, 0, 0) !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  z-index: 100 !important;
  pointer-events: auto !important;
  margin: 0 !important;
  padding: 0 !important;
  border: none !important;
  outline: none !important;
  box-sizing: border-box !important;
  border-radius: 12px !important;
  animation: overlay-fade-in 2s ease-out forwards;
}

.game-over-message > div {
  font-size: 2.5rem !important;
  font-weight: bold !important;
  background: linear-gradient(45deg, #ff6b6b, #ff6b6b);
  background-clip: text;
  -webkit-background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
  animation: message-appear 2s ease-out forwards, lose-gradient-text 3s ease-in-out infinite;
  text-align: center;
  filter: drop-shadow(0 0 10px rgba(255, 107, 107, 0.5));
}

/* Responsive adjustments */
@media (max-width: 400px) {
  .you-win-message, .game-over-message {
    font-size: 2rem;
  }
}
