@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap');

#game-wrapper {
  text-align: center;
  margin: 20px auto;
  max-width: 100%;
  width: 600px;
  font-family: 'Roboto', sans-serif;
  background: linear-gradient(135deg, #f5f7fa, #c3cfe2);
  padding: 30px;
  border-radius: 15px;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
}

#game-wrapper h2 {
  color: #333;
  font-size: 36px;
  font-weight: 700;
  margin-bottom: 25px;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.1);
}

#scoreboard {
  display: flex;
  justify-content: space-between;
  background: #ffffff;
  padding: 15px;
  border-radius: 10px;
  margin-bottom: 20px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

#scoreboard p {
  margin: 0;
  font-size: 22px;
  color: #333;
}

#scoreboard span {
  font-weight: 700;
  color: #e67e22;
}

#game-container {
  display: grid;
  grid-template-rows: repeat(4, 1fr);
  gap: 12px;
  background: #bbada0;
  padding: 12px;
  border-radius: 10px;
  touch-action: none;
  width: 528px;
  margin: 0 auto;
}

.grid-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.grid-cell {
  width: 120px;
  height: 120px;
  background: #cdc1b4;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 32px;
  font-weight: bold;
  color: #776e65;
  border-radius: 8px;
  transition: all 0.2s ease;
}

/* Màu sắc cho các ô số */
.grid-cell:not(:empty) {
  background: #eee4da;
}
.grid-cell:empty {
  background: #cdc1b4;
}
.grid-cell[data-value="2"] { background: #eee4da; }
.grid-cell[data-value="4"] { background: #ede0c8; }
.grid-cell[data-value="8"] { background: #f2b179; color: #f9f6f2; }
.grid-cell[data-value="16"] { background: #f59563; color: #f9f6f2; }
.grid-cell[data-value="32"] { background: #f67c5f; color: #f9f6f2; }
.grid-cell[data-value="64"] { background: #f65e3b; color: #f9f6f2; }
.grid-cell[data-value="128"] { background: #edcf72; color: #f9f6f2; }
.grid-cell[data-value="256"] { background: #edcc61; color: #f9f6f2; }
.grid-cell[data-value="512"] { background: #edc850; color: #f9f6f2; }
.grid-cell[data-value="1024"] { background: #edc53f; color: #f9f6f2; }
.grid-cell[data-value="2048"] { background: #edc22e; color: #f9f6f2; }

/* Animation cho ô mới và hợp nhất */
.tile-new {
  animation: appear 0.2s ease;
}
.tile-merged {
  animation: pop 0.2s ease;
}

@keyframes appear {
  from { transform: scale(0); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

@keyframes pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

#game-over {
  margin-top: 20px;
  text-align: center;
  display: none;
  z-index: 10;
  background: rgba(255, 255, 255, 0.9);
  padding: 20px;
  border-radius: 10px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
  animation: fadeIn 0.3s ease;
}

#game-over p {
  color: #e74c3c;
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 15px;
}

#button-container {
  margin-top: 20px;
  display: flex;
  justify-content: center;
  gap: 20px;
}

#playAgainBtn, #endGameBtn, #restartGameBtn {
  padding: 12px 24px;
  background: linear-gradient(135deg, #e67e22, #d35400);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 18px;
  font-weight: 700;
  transition: transform 0.2s, box-shadow 0.2s;
}

#playAgainBtn:hover, #endGameBtn:hover, #restartGameBtn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

#playAgainBtn:active, #endGameBtn:active, #restartGameBtn:active {
  transform: translateY(0);
  box-shadow: none;
}

#game-instructions {
  margin-top: 20px;
  background: rgba(255, 255, 255, 0.9);
  padding: 20px;
  border-radius: 10px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
  animation: fadeIn 0.3s ease;
}

#game-instructions p {
  color: #333;
  font-size: 18px;
  font-weight: 400;
  margin: 0;
}

#new-highscore {
  margin-top: 20px;
  background: rgba(255, 255, 255, 0.9);
  padding: 20px;
  border-radius: 10px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
  animation: fadeIn 0.3s ease;
}

#new-highscore p {
  color: #27ae60;
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 15px;
}

#new-highscore input {
  padding: 10px;
  border: 1px solid #ccc;
  border-radius: 5px;
  font-size: 18px;
  margin-right: 15px;
}

#new-highscore button {
  padding: 10px 20px;
  background: linear-gradient(135deg, #27ae60, #219653);
  color: white;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-size: 18px;
  font-weight: 700;
  transition: transform 0.2s, box-shadow 0.2s;
}

#new-highscore button:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

#new-highscore button:active {
  transform: translateY(0);
  box-shadow: none;
}

#leaderboard {
  margin-top: 25px;
  text-align: left;
  background: #ffffff;
  padding: 20px;
  border-radius: 10px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
  width: 100%;
  max-width: 600px;
  margin-left: auto;
  margin-right: auto;
}

#leaderboard h3 {
  text-align: center;
  color: #333;
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 20px;
}

.table-container {
  overflow-x: auto;
  max-width: 100%;
  -webkit-overflow-scrolling: touch;
}

#top-scores-table {
  width: 100%;
  min-width: 400px;
  border-collapse: collapse;
  background: #ffffff;
  border-radius: 8px;
  overflow: hidden;
}

#top-scores-table th,
#top-scores-table td {
  padding: 12px;
  text-align: left;
  border-bottom: 1px solid #eee;
}

#top-scores-table th {
  background: linear-gradient(135deg, #34495e, #2c3e50);
  color: white;
  font-weight: 700;
}

#top-scores-table tr {
  transition: background 0.2s ease;
}

#top-scores-table tr:hover {
  background: #f1f1f1;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 600px) {
  #game-wrapper {
    padding: 15px;
    width: 100%;
  }

  #game-container {
    gap: 8px;
    padding: 8px;
    width: 100%;
    max-width: 360px;
    margin: 0 auto;
  }

  .grid-cell {
    width: 80px;
    height: 80px;
    font-size: 24px;
  }

  #scoreboard {
    flex-direction: column;
    gap: 15px;
  }

  #scoreboard p {
    font-size: 18px;
  }

  #game-over p {
    font-size: 20px;
  }

  #game-instructions p {
    font-size: 16px;
  }

  #playAgainBtn, #endGameBtn, #restartGameBtn {
    font-size: 16px;
    padding: 10px 20px;
  }

  #new-highscore input {
    font-size: 16px;
    padding: 8px;
  }

  #new-highscore button {
    font-size: 16px;
    padding: 8px 16px;
  }

  #top-scores-table {
    font-size: 14px;
    min-width: 300px;
  }

  #top-scores-table th,
  #top-scores-table td {
    padding: 8px;
  }

  #leaderboard {
    max-width: 100%;
  }

  #leaderboard h3 {
    font-size: 22px;
  }
}