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

body {
  background: #faf8ef;
  font-family: 'Segoe UI', Arial, sans-serif;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: 100vh;
  padding: 24px 16px;
}

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

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

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

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

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

.score-label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  color: #eee4da;
  letter-spacing: 1px;
}

.score-value {
  display: block;
  font-size: 22px;
  font-weight: 800;
  color: #fff;
}

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

.hint {
  font-size: 13px;
  color: #9a8f85;
}

button {
  background: #8f7a66;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
}

button:hover {
  background: #7a6a58;
}

/* Grid wrapper (positioning context for tiles + overlays) */
.grid-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
}

/* Background cells */
.grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  background: #bbada0;
  border-radius: 8px;
  padding: 12px;
  width: 100%;
  height: 100%;
  position: absolute;
  inset: 0;
}

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

/* Tile layer */
.tiles {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* Individual tiles */
.tile {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  font-weight: 800;
  transition: transform 0.1s ease, left 0.1s ease, top 0.1s ease;
  will-change: left, top;
}

.tile.appear {
  animation: appear 0.15s ease forwards;
}

.tile.merge {
  animation: merge-pop 0.15s ease;
}

@keyframes appear {
  from { transform: scale(0); }
  to   { transform: scale(1); }
}

@keyframes merge-pop {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.2); }
  100% { transform: scale(1); }
}

/* Tile colors */
.tile[data-value="2"]    { background: #eee4da; color: #776e65; }
.tile[data-value="4"]    { background: #ede0c8; color: #776e65; }
.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"]  { background: #edcf72; color: #f9f6f2; }
.tile[data-value="256"]  { background: #edcc61; color: #f9f6f2; }
.tile[data-value="512"]  { background: #edc850; color: #f9f6f2; }
.tile[data-value="1024"] { background: #edc53f; color: #f9f6f2; }
.tile[data-value="2048"] { background: #3cc94a; color: #f9f6f2; }
.tile[data-value="4096"] { background: #3b82f6; color: #f9f6f2; }
.tile[data-value="8192"] { background: #8b5cf6; color: #f9f6f2; }

/* Overlays */
.overlay {
  display: none;
  position: absolute;
  inset: 0;
  background: rgba(250, 248, 239, 0.82);
  border-radius: 8px;
  z-index: 10;
  align-items: center;
  justify-content: center;
}

.overlay.active {
  display: flex;
}

.overlay-box {
  text-align: center;
}

.overlay-box h2 {
  font-size: 40px;
  font-weight: 900;
  color: #776e65;
  margin-bottom: 8px;
}

.overlay-box p {
  font-size: 16px;
  color: #9a8f85;
  margin-bottom: 20px;
}

.overlay-box button {
  margin: 0 6px;
}

/* Responsive */
@media (max-width: 420px) {
  h1 { font-size: 40px; }
  .score-value { font-size: 18px; }
}
