* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: "Clear Sans", "Helvetica Neue", Arial, sans-serif;
  background: #faf8ef;
  color: #776e65;
  font-size: 18px;
  line-height: 1.65;
}

.container {
  width: 500px;
  margin: 0 auto;
  padding: 20px;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

h1 {
  color: #776e65;
  font-size: 80px;
  font-weight: bold;
  margin: 0;
}

.score-container {
  display: flex;
  gap: 10px;
}

.score-box {
  background: #bbada0;
  padding: 10px 20px;
  border-radius: 3px;
  color: white;
  text-align: center;
  min-width: 70px;
}

.score-label {
  font-size: 13px;
  line-height: 13px;
  text-transform: uppercase;
  margin-bottom: 5px;
}

.score {
  font-size: 25px;
  font-weight: bold;
  line-height: 25px;
  transition: all 0.3s ease;
}

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

@keyframes scoreIncrease {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.1);
    color: #f67c5f;
  }
  100% {
    transform: scale(1);
  }
}

.game-intro {
  margin-bottom: 20px;
  text-align: center;
}

.game-intro p {
  margin-bottom: 10px;
  color: #776e65;
}

.restart-button,
.try-again-button {
  background: #8f7a66;
  color: #f9f6f2;
  border: none;
  border-radius: 3px;
  padding: 10px 20px;
  font-size: 18px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.restart-button:hover,
.try-again-button:hover {
  background: #9f8a76;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.restart-button:active,
.try-again-button:active {
  transform: translateY(0);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}

.game-container {
  position: relative;
  background: #bbada0;
  border-radius: 10px;
  width: 500px;
  height: 500px;
  box-sizing: border-box;
  padding: 15px;
  margin: 0 auto;
}

.grid-container {
  position: absolute;
  top: 15px;
  left: 15px;
  z-index: 1;
}

.grid-row {
  display: flex;
  margin-bottom: 10px;
}

.grid-row:last-child {
  margin-bottom: 0;
}

.grid-cell {
  width: 106.25px;
  height: 106.25px;
  background: rgba(238, 228, 218, 0.35);
  border-radius: 6px;
  margin-right: 11.25px;
}

.grid-cell:last-child {
  margin-right: 0;
}

.tile-container {
  position: absolute;
  top: 15px;
  left: 15px;
  z-index: 2;
}

.tile {
  position: absolute;
  width: 106.25px;
  height: 106.25px;
  background: #eee4da;
  border-radius: 6px;
  font-weight: bold;
  text-align: center;
  line-height: 106.25px;
  font-size: 55px;
  transition: all 0.25s ease-in-out;
  animation: appear 0.2s ease-in-out;
  box-shadow: 0 0 30px 10px rgba(243, 215, 116, 0),
    inset 0 0 0 1px rgba(255, 255, 255, 0);
}

.tile.tile-merged {
  animation: merged 0.15s ease-in-out;
}

.tile.tile-new {
  animation: appear 0.2s ease-in-out;
}

@keyframes merged {
  0% {
    transform: scale(1);
    box-shadow: 0 0 30px 10px rgba(243, 215, 116, 0);
  }
  50% {
    transform: scale(1.1);
    box-shadow: 0 0 30px 10px rgba(243, 215, 116, 0.4);
  }
  100% {
    transform: scale(1);
    box-shadow: 0 0 30px 10px rgba(243, 215, 116, 0);
  }
}

@keyframes appear {
  0% {
    opacity: 0;
    transform: scale(0);
  }
  50% {
    opacity: 1;
    transform: scale(1.1);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

/* 不同数字的颜色 */
.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: 45px;
}
.tile-256 {
  background: #edcc61;
  color: #f9f6f2;
  font-size: 45px;
}
.tile-512 {
  background: #edc850;
  color: #f9f6f2;
  font-size: 45px;
}
.tile-1024 {
  background: #edc53f;
  color: #f9f6f2;
  font-size: 35px;
}
.tile-2048 {
  background: #edc22e;
  color: #f9f6f2;
  font-size: 35px;
}

.game-message {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(238, 228, 218, 0.73);
  z-index: 100;
  text-align: center;
}

.message-content {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: white;
  padding: 30px;
  border-radius: 10px;
  box-shadow: 0 0 30px rgba(0, 0, 0, 0.3);
}

.message-text {
  font-size: 60px;
  font-weight: bold;
  color: #776e65;
  margin-bottom: 20px;
}

.game-message.game-won .message-text {
  color: #f67c5f;
}

.game-message.game-over .message-text {
  color: #776e65;
}

/* 响应式设计 */
@media screen and (max-width: 520px) {
  .container {
    width: 280px;
    padding: 10px;
  }

  .game-container {
    width: 280px;
    height: 280px;
    padding: 8px;
  }

  .grid-container {
    top: 8px;
    left: 8px;
  }

  .tile-container {
    top: 8px;
    left: 8px;
  }

  .grid-cell,
  .tile {
    width: 60px;
    height: 60px;
    line-height: 60px;
    font-size: 32px;
  }

  .grid-row {
    margin-bottom: 8px;
  }

  .grid-cell {
    margin-right: 8px;
  }

  h1 {
    font-size: 50px;
  }

  .score-box {
    padding: 8px 15px;
    min-width: 60px;
  }

  .score-label {
    font-size: 11px;
  }

  .score {
    font-size: 20px;
  }

  .tile-128,
  .tile-256,
  .tile-512 {
    font-size: 25px;
  }

  .tile-1024,
  .tile-2048 {
    font-size: 20px;
  }
}
