* {
  box-sizing: border-box;
}

html,
body {
  margin-top: 2%;
  padding: 0;
  width: 100%;
  overflow-x: hidden;
}

body {
  min-height: 100svh;
  font-family: Arial, sans-serif;
  background: #121213;
  color: white;
  display: flex;
  justify-content: center;
  padding: 20px 14px;
}

.game-page {
  width: 100%;
  max-width: 460px;
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.top-bar h1 {
  margin: 0;
  font-size: 2rem;
  text-align: center;
  flex: 1;
}

.back-link,
.restart-btn {
  background: #2f2f31;
  color: white;
  text-decoration: none;
  border: none;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease;
}

.restart-btn:hover,
.back-link:hover {
  background: #3a3a3c;
  transform: translateY(-1px);
}

.score-row {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}

.score-box {
  flex: 1;
  background: #2f2f31;
  border-radius: 12px;
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.score-label {
  font-size: 12px;
  opacity: 0.8;
  margin-bottom: 4px;
}

#score,
#moves,
#bestScore {
  font-size: 1.4rem;
  font-weight: 700;
}

.game-wrapper {
  position: relative;
}

.board {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  background: #1f2023;
  padding: 8px;
  border-radius: 18px;
}

.tile {
  aspect-ratio: 1 / 1;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  font-weight: 700;
  color: white;
  transition: transform 0.16s ease, background 0.16s ease, color 0.16s ease;
  border: 2px solid #3a3a3c;
}

.tile.empty {
  background: #121213;
}

.tile.new {
  animation: pop 0.18s ease;
}

@keyframes pop {
  0% {
    transform: scale(0.72);
    opacity: 0.65;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.tile.value-2 { background: #eee4da; color: #1a1a1a; border-color: #eee4da; }
.tile.value-4 { background: #ede0c8; color: #1a1a1a; border-color: #ede0c8; }
.tile.value-8 { background: #f2b179; border-color: #f2b179; }
.tile.value-16 { background: #f59563; border-color: #f59563; }
.tile.value-32 { background: #f67c5f; border-color: #f67c5f; }
.tile.value-64 { background: #f65e3b; border-color: #f65e3b; }
.tile.value-128 { background: #edcf72; color: #1a1a1a; border-color: #edcf72; font-size: 1.8rem; }
.tile.value-256 { background: #edcc61; color: #1a1a1a; border-color: #edcc61; font-size: 1.8rem; }
.tile.value-512 { background: #edc850; color: #1a1a1a; border-color: #edc850; font-size: 1.8rem; }
.tile.value-1024 { background: #edc53f; color: #1a1a1a; border-color: #edc53f; font-size: 1.4rem; }
.tile.value-2048 { background: #edc22e; color: #1a1a1a; border-color: #edc22e; font-size: 1.4rem; }
.tile.value-super { background: #3c3a32; border-color: #3c3a32; font-size: 1.2rem; }

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(18, 18, 19, 0.82);
  border-radius: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
}

.overlay.hidden {
  display: none;
}

.overlay-box {
  background: #1f2023;
  border: 1px solid #3a3a3c;
  border-radius: 16px;
  padding: 22px 18px;
  text-align: center;
  width: calc(100% - 40px);
  max-width: 320px;
}

.overlay-box h2 {
  margin: 0 0 14px;
  font-size: 1.4rem;
}

.overlay-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 10px;
  flex-wrap: wrap;
}

.share-btn {
  background: #538d4e;
  border: none;
  border-radius: 10px;
  padding: 10px 14px;
  color: white;
  font-weight: bold;
  cursor: pointer;
  transition: filter 0.15s ease, transform 0.15s ease;
}

.share-btn:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.copy-toast {
  margin-top: 10px;
  text-align: center;
  background: #2f2f31;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 14px;
}

.hint {
  margin-top: 14px;
  text-align: center;
  color: #c7c7c7;
  font-size: 14px;
}

.hidden {
  display: none !important;
}

@media (max-width: 480px) {
  body {
    padding: 14px 10px;
  }

  .top-bar {
    gap: 8px;
    margin-bottom: 14px;
  }

  .top-bar h1 {
    font-size: 1.6rem;
  }

  .back-link,
  .restart-btn,
  .share-btn {
    font-size: 13px;
    padding: 9px 12px;
  }

  .score-row {
    gap: 8px;
    margin-bottom: 14px;
  }

  .score-box {
    padding: 9px 6px;
  }

  #score,
  #moves,
  #bestScore {
    font-size: 1.15rem;
  }

  .board {
    gap: 6px;
    padding: 6px;
    border-radius: 16px;
  }

  .tile {
    font-size: 1.7rem;
    border-radius: 10px;
  }

  .tile.value-128,
  .tile.value-256,
  .tile.value-512 {
    font-size: 1.4rem;
  }

  .tile.value-1024,
  .tile.value-2048 {
    font-size: 1.1rem;
  }

  .tile.value-super {
    font-size: 1rem;
  }

  .overlay-box {
    width: calc(100% - 24px);
    padding: 18px 14px;
  }

  .overlay-actions {
    gap: 8px;
  }
}