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

html, body {
  width: 100%;
  height: 100%;
  background: #0C0D14;
  font-family: 'Segoe UI', system-ui, -apple-system, Arial, sans-serif;
  color: #eee;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: none;
}

.container {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 16px;
  max-width: 500px;
  width: 100%;
}

/* ── Header ───────────────────────────────────────────── */

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 420px;
}

.title {
  font-size: 52px;
  font-weight: 800;
  letter-spacing: -2px;
  background: linear-gradient(135deg, #f7c948, #f59e0b);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

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

.score-box {
  background: #1a1b26;
  border: 1px solid #2a2b3a;
  border-radius: 8px;
  padding: 6px 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 72px;
}

.score-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #888;
}

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

/* ── New Game Button ──────────────────────────────────── */

.new-game-btn {
  align-self: flex-end;
  max-width: 420px;
  width: auto;
  padding: 8px 20px;
  border: none;
  border-radius: 8px;
  background: #f59e0b;
  color: #0C0D14;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.new-game-btn:hover {
  background: #f7c948;
}

.new-game-btn:active {
  transform: scale(0.96);
}

/* ── Board ────────────────────────────────────────────── */

.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  padding: 10px;
  background: #1a1b26;
  border-radius: 12px;
  width: 100%;
  max-width: 420px;
  aspect-ratio: 1;
}

.cell {
  background: #262736;
  border-radius: 8px;
}

/* ── Tiles ────────────────────────────────────────────── */

.tile {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  font-weight: 800;
  transition: top 0.12s ease, left 0.12s ease;
  z-index: 1;
  user-select: none;
}

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

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

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

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

/* ── Tile Colors ──────────────────────────────────────── */

.tile-2    { background: #3b3d54; color: #e0e0e0; }
.tile-4    { background: #4a4c6a; color: #e8e8e8; }
.tile-8    { background: #e67e22; color: #fff; }
.tile-16   { background: #e74c3c; color: #fff; }
.tile-32   { background: #e84393; color: #fff; }
.tile-64   { background: #d63031; color: #fff; }
.tile-128  { background: #f7c948; color: #1a1a2e; }
.tile-256  { background: #f5b731; color: #1a1a2e; }
.tile-512  { background: #f59e0b; color: #1a1a2e; }
.tile-1024 { background: #6c5ce7; color: #fff; }
.tile-2048 { background: #00cec9; color: #1a1a2e; }
.tile-super { background: #0984e3; color: #fff; }

/* ── Overlay ──────────────────────────────────────────── */

.overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(12, 13, 20, 0.75);
  border-radius: 12px;
  z-index: 100;
  gap: 20px;
  animation: fadeIn 0.25s ease;
}

.overlay.hidden {
  display: none;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.overlay-text {
  font-size: 38px;
  font-weight: 800;
  text-align: center;
  letter-spacing: -1px;
}

.overlay-btn {
  padding: 10px 28px;
  border: none;
  border-radius: 8px;
  background: #f59e0b;
  color: #0C0D14;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.overlay-btn:hover {
  background: #f7c948;
}

.overlay-btn:active {
  transform: scale(0.96);
}

/* ── Responsive ───────────────────────────────────────── */

@media (max-width: 460px) {
  .board {
    gap: 8px;
    padding: 8px;
    border-radius: 10px;
  }
  .cell, .tile {
    border-radius: 6px;
  }
  .title {
    font-size: 40px;
  }
  .score-box {
    padding: 4px 12px;
    min-width: 60px;
  }
  .score-value {
    font-size: 18px;
  }
}
