body {
  background: #faf8ef;
  font-family: "Clear Sans", "Helvetica Neue", Arial, sans-serif;
  margin: 0;
  padding: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
}

.game-container {
  background: #bbada0;
  border-radius: 10px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.2);
  padding: 30px 20px 20px 20px;
  position: relative;
  width: 480px;
  max-width: 98vw;
}

.header {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 20px;
}

.header h1 {
  margin: 0 0 10px 0;
  font-size: 48px;
  color: #776e65;
  letter-spacing: 2px;
}

.scores {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
}

.score-box {
  background: #eee4da;
  color: #776e65;
  border-radius: 5px;
  padding: 6px 16px;
  font-size: 18px;
  font-weight: bold;
  min-width: 80px;
  text-align: center;
}

#new-game-btn,
#try-again-btn {
  background: #8f7a66;
  color: #fff;
  border: none;
  border-radius: 5px;
  padding: 10px 24px;
  font-size: 18px;
  font-weight: bold;
  cursor: pointer;
  margin-top: 10px;
  transition: background 0.2s;
}
#new-game-btn:hover,
#try-again-btn:hover {
  background: #a39489;
}

.grid-bg {
  position: relative;
  width: 440px;
  height: 440px;
  margin: 0 auto;
}

.grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 10px;
  width: 100%;
  height: 100%;
  position: relative;
  z-index: 1;
}
.grid-cell[data-bg] {
  background: #cdc1b4;
  border-radius: 5px;
  width: 100%;
  height: 100%;
  position: relative;
}

.tile {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  margin: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  font-weight: bold;
  color: #776e65;
  background: #eee4da;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  border-radius: 5px;
  user-select: none;
  width: 100%;
  height: 100%;
  z-index: 2;
  transition: background 0.2s, color 0.2s;
  transform-origin: center;
}

.tile-2 {
  background: #eee4da;
  color: #776e65;
}
.tile-4 {
  background: #ede0c8;
  color: #776e65;
}
.tile-8 {
  background: #f2b179;
  color: #f9f6f2;
}
.tile-16 {
  background: #f59563;
  color: #f9f6f2;
}
.tile-32 {
  background: #f67c5f;
  color: #f9f6f2;
}
.tile-64 {
  background: #f65e3b;
  color: #f9f6f2;
}
.tile-128 {
  background: #edcf72;
  color: #f9f6f2;
  font-size: 32px;
}
.tile-256 {
  background: #edcc61;
  color: #f9f6f2;
  font-size: 32px;
}
.tile-512 {
  background: #edc850;
  color: #f9f6f2;
  font-size: 32px;
}
.tile-1024 {
  background: #edc53f;
  color: #f9f6f2;
  font-size: 28px;
}
.tile-2048 {
  background: #edc22e;
  color: #f9f6f2;
  font-size: 28px;
}

@media (max-width: 520px) {
  .game-container {
    width: 320px;
    padding: 10px 2px 10px 2px;
  }
  .grid-bg {
    width: 288px;
    height: 288px;
  }
  .grid {
    gap: 8px;
  }
  .tile,
  .grid-cell[data-bg] {
    font-size: 22px;
  }
  .tile-128,
  .tile-256,
  .tile-512 {
    font-size: 18px;
  }
  .tile-1024,
  .tile-2048 {
    font-size: 16px;
  }
}

/* Animations */
@keyframes appear {
  0% {
    transform: scale(0.2);
    opacity: 0;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}
@keyframes merge {
  0% {
    transform: scale(1);
    opacity: 1;
  }
  40% {
    transform: scale(1.18);
    opacity: 0.92;
  }
  60% {
    transform: scale(0.98);
    opacity: 1;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}
@keyframes scoreFloat {
  0% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -120%) scale(1.5);
  }
}
@keyframes shake {
  0% {
    transform: translateX(0);
  }
  20% {
    transform: translateX(-10px);
  }
  40% {
    transform: translateX(10px);
  }
  60% {
    transform: translateX(-10px);
  }
  80% {
    transform: translateX(10px);
  }
  100% {
    transform: translateX(0);
  }
}

.game-message {
  display: none;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(238, 228, 218, 0.95);
  border-radius: 10px;
  padding: 40px 30px 30px 30px;
  z-index: 10;
  text-align: center;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
}
.game-message.show {
  display: block;
}
#message-text {
  font-size: 32px;
  color: #776e65;
  margin-bottom: 20px;
}

.tile.merge {
  animation: merge 0.28s cubic-bezier(0.68, -0.55, 0.27, 1.55);
  z-index: 3;
}
