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

body {
  background: #202124;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  color: #e8eaed;
  user-select: none;
  -webkit-user-select: none;
}

#back-btn {
  position: fixed;
  top: 16px;
  right: 16px;
  color: #fff;
  text-decoration: none;
  font-size: 22px;
  font-weight: 700;
  z-index: 20;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: #5f6368;
  transition: background 0.2s;
  line-height: 1;
}

#back-btn:hover {
  background: #80868b;
}

#game-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  position: relative;
}

#header {
  display: flex;
  justify-content: space-between;
  width: 100%;
  max-width: 420px;
  padding: 0 4px;
  font-size: 18px;
  font-weight: 500;
}

#high-score-display {
  color: #9aa0a6;
}

#board {
  position: relative;
  background: #3c4043;
  border-radius: 12px;
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

.cell-bg {
  width: 90px;
  height: 90px;
  border-radius: 8px;
  background: #292a2d;
}

.tile {
  position: absolute;
  width: 90px;
  height: 90px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 36px;
  transition: top 0.12s ease, left 0.12s ease;
  z-index: 2;
}

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

.tile.merged {
  animation: merge-pop 0.2s ease-out;
  z-index: 3;
}

@keyframes pop-in {
  0% { transform: scale(0); opacity: 0; }
  60% { transform: scale(1.1); }
  100% { transform: scale(1); opacity: 1; }
}

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

/* Tile colors */
.tile-2    { background: #eee4da; color: #776e65; }
.tile-4    { background: #ede0c8; color: #776e65; }
.tile-8    { background: #f2b179; color: #fff; }
.tile-16   { background: #f59563; color: #fff; }
.tile-32   { background: #f67c5f; color: #fff; }
.tile-64   { background: #f65e3b; color: #fff; }
.tile-128  { background: #edcf72; color: #fff; font-size: 30px; }
.tile-256  { background: #edcc61; color: #fff; font-size: 30px; }
.tile-512  { background: #edc850; color: #fff; font-size: 30px; }
.tile-1024 { background: #edc53f; color: #fff; font-size: 24px; }
.tile-2048 { background: #edc22e; color: #fff; font-size: 24px; }
.tile-super { background: #3c3a32; color: #fff; font-size: 20px; }

/* Overlay */
#overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10;
}

#overlay.hidden {
  display: none;
}

#overlay-content {
  text-align: center;
  background: rgba(32, 33, 36, 0.92);
  padding: 48px 56px;
  border-radius: 20px;
  backdrop-filter: blur(8px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

#overlay-content h1 {
  font-size: 44px;
  font-weight: 700;
  margin-bottom: 10px;
  color: #edcf72;
}

#overlay-message {
  font-size: 16px;
  color: #9aa0a6;
  margin-bottom: 28px;
}

#start-btn {
  background: #edcf72;
  color: #776e65;
  border: none;
  padding: 14px 48px;
  font-size: 18px;
  font-weight: 600;
  border-radius: 28px;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

#start-btn:hover {
  background: #edc53f;
  transform: scale(1.04);
}

#start-btn:active {
  transform: scale(0.97);
}

#controls {
  display: flex;
  gap: 12px;
}

#new-game-btn {
  background: #3c4043;
  color: #e8eaed;
  border: none;
  padding: 10px 28px;
  font-size: 15px;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
}

#new-game-btn:hover {
  background: #5f6368;
}

#hint-text {
  font-size: 13px;
  color: #5f6368;
  margin-top: 4px;
}

@media (max-width: 440px) {
  .cell-bg,
  .tile {
    width: 70px;
    height: 70px;
  }

  #board {
    padding: 8px;
    gap: 8px;
  }

  .tile {
    font-size: 28px;
  }

  .tile-128, .tile-256, .tile-512 { font-size: 24px; }
  .tile-1024, .tile-2048 { font-size: 20px; }
  .tile-super { font-size: 16px; }

  #overlay-content {
    padding: 32px 36px;
  }

  #overlay-content h1 {
    font-size: 32px;
  }

  #header {
    font-size: 16px;
  }
}
