* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: #faf8ef;
  color: #776e65;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 20px 12px;
  user-select: none;
}

.container {
  width: 100%;
  max-width: 480px;
}

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

h1 {
  font-size: 56px;
  font-weight: 700;
  color: #776e65;
}

.scores {
  display: flex;
  gap: 8px;
}

.score-box {
  background: #bbada0;
  color: #fff;
  border-radius: 6px;
  padding: 8px 16px;
  text-align: center;
  min-width: 72px;
}

.score-box .label {
  font-size: 12px;
  text-transform: uppercase;
  color: #eee4da;
  letter-spacing: 1px;
}

.score-box .score {
  font-size: 22px;
  font-weight: 700;
  margin-top: 2px;
}

.controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  gap: 12px;
}

.intro {
  font-size: 14px;
  flex: 1;
  line-height: 1.4;
}

#new-game,
.message-button {
  background: #8f7a66;
  color: #f9f6f2;
  border: none;
  padding: 10px 18px;
  border-radius: 6px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s ease;
}

#new-game:hover,
.message-button:hover {
  background: #9f8b77;
}

.board {
  position: relative;
  background: #bbada0;
  border-radius: 8px;
  padding: 12px;
  width: 100%;
  aspect-ratio: 1 / 1;
  touch-action: none;
}

.grid-background {
  position: absolute;
  inset: 12px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 12px;
}

.grid-cell {
  background: rgba(238, 228, 218, 0.35);
  border-radius: 6px;
}

.tile-container {
  position: absolute;
  inset: 12px;
}

.tile {
  position: absolute;
  background: #eee4da;
  color: #776e65;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 36px;
  transition: left 0.15s ease, top 0.15s ease;
}

.tile.new {
  animation: appear 0.2s ease;
  transition: none;
}

.tile.merged {
  animation: pop 0.2s ease;
  z-index: 2;
}

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

@keyframes pop {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.15);
  }
  100% {
    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: 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: 26px; }
.tile-2048 { background: #edc22e; color: #f9f6f2; font-size: 26px; }
.tile-super { background: #3c3a32; color: #f9f6f2; font-size: 22px; }

.game-message {
  position: absolute;
  inset: 0;
  background: rgba(238, 228, 218, 0.73);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  border-radius: 8px;
  z-index: 10;
}

.game-message.win {
  background: rgba(237, 194, 46, 0.5);
}

.game-message.visible {
  display: flex;
}

.message-text {
  font-size: 48px;
  font-weight: 700;
  color: #776e65;
}

.game-message.win .message-text {
  color: #f9f6f2;
}

@media (max-width: 480px) {
  h1 { font-size: 40px; }
  .intro { font-size: 12px; }
  .tile { font-size: 28px; }
  .tile-128, .tile-256, .tile-512 { font-size: 24px; }
  .tile-1024, .tile-2048, .tile-super { font-size: 20px; }
  .message-text { font-size: 36px; }
}
