:root {
  --background: #faf8ef;
  --board: #bbada0;
  --empty: rgba(238, 228, 218, 0.35);
  --text: #776e65;
  --accent: #8f7a66;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--background);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
}

button {
  border: 0;
  border-radius: 4px;
  background: var(--accent);
  color: #f9f6f2;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  padding: 10px 16px;
}

button:focus-visible, .board:focus-visible {
  outline: 3px solid #edc53f;
  outline-offset: 3px;
}

.game { width: min(92vw, 500px); margin: 0 auto; padding: 28px 0; }
.game-header, .intro { display: flex; align-items: center; justify-content: space-between; }
h1 { margin: 0; color: #776e65; font-size: clamp(58px, 16vw, 80px); letter-spacing: -4px; line-height: 1; }
.scores { display: flex; gap: 7px; }
.score-box { min-width: 78px; padding: 7px 12px; border-radius: 3px; background: #bbada0; color: #eee4da; text-align: center; text-transform: uppercase; }
.score-box span { display: block; font-size: 11px; font-weight: 700; }
.score-box strong { display: block; color: #fff; font-size: 24px; line-height: 1.25; }
.intro { margin-top: 16px; gap: 14px; }
.intro p { margin: 0; font-size: 17px; line-height: 1.45; }
.intro button { white-space: nowrap; }
.instructions { margin: 18px 0 10px; font-size: 14px; }
.board { position: relative; width: 100%; aspect-ratio: 1; padding: 2.5%; border-radius: 6px; background: var(--board); touch-action: none; user-select: none; }
.grid-background, .tiles { position: absolute; inset: 2.5%; display: grid; grid-template-columns: repeat(4, 1fr); gap: 2.5%; }
.grid-background i { display: block; border-radius: 5px; background: var(--empty); }
.tiles { z-index: 1; }
.tile { display: flex; align-items: center; justify-content: center; border-radius: 5px; color: #776e65; font-size: clamp(27px, 8vw, 47px); font-weight: 700; line-height: 1; animation: appear 150ms ease-out both; }
.tile[data-value="2"] { background: #eee4da; }
.tile[data-value="4"] { background: #ede0c8; }
.tile[data-value="8"] { background: #f2b179; color: #f9f6f2; }
.tile[data-value="16"] { background: #f59563; color: #f9f6f2; }
.tile[data-value="32"] { background: #f67c5f; color: #f9f6f2; }
.tile[data-value="64"] { background: #f65e3b; color: #f9f6f2; }
.tile[data-value="128"], .tile[data-value="256"], .tile[data-value="512"] { background: #edcf72; color: #f9f6f2; font-size: clamp(23px, 7vw, 38px); }
.tile[data-value="1024"], .tile[data-value="2048"] { background: #edc53f; color: #f9f6f2; font-size: clamp(19px, 6vw, 31px); }
.tile[data-value="merged"] { animation: merge 180ms ease-out both; }
.message { position: absolute; inset: 0; z-index: 3; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; border-radius: 6px; background: rgba(238, 228, 218, 0.73); text-align: center; }
.message[hidden] { display: none; }
.message p { margin: 0 0 5px; color: #776e65; font-size: 42px; font-weight: 700; }
.message button { margin: 0 3px; }
footer { margin-top: 22px; border-top: 1px solid #d8d4cc; font-size: 13px; }
footer p { margin: 16px 0; }
@keyframes appear { from { opacity: 0; transform: scale(0); } to { opacity: 1; transform: scale(1); } }
@keyframes merge { 50% { transform: scale(1.13); } }
@media (max-width: 380px) { .game { padding-top: 18px; } .score-box { min-width: 68px; padding-inline: 7px; } .intro p { font-size: 15px; } }
