:root {
  --bg: #fdf7ef;
  --surface: #ffffff;
  --text: #2f2a25;
  --muted: #6b5f53;
  --accent: #b8662a;
  --accent-dark: #9c5422;
  --board: #bbada0;
  --cell: rgba(238, 228, 218, 0.35);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  color: var(--text);
  background: linear-gradient(180deg, #fffaf2 0%, var(--bg) 55%, #fff4e6 100%);
  min-height: 100vh;
}

.container {
  max-width: 620px;
  margin: 0 auto;
  padding: 20px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  gap: 12px;
}

.topbar h1 {
  margin: 0;
  font-size: 2.3rem;
}

.nav-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 700;
}

.score-panel {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr)) auto;
  gap: 10px;
  margin-bottom: 14px;
}

.score-box {
  background: var(--surface);
  border: 1px solid #ead9c7;
  border-radius: 10px;
  padding: 10px;
  text-align: center;
}

.label {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.value {
  margin: 4px 0 0;
  font-size: 1.4rem;
  font-weight: 800;
}

#newGameBtn,
#playAgainBtn {
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-weight: 700;
  padding: 10px 14px;
}

#newGameBtn:hover,
#playAgainBtn:hover {
  background: var(--accent-dark);
}

.game-wrap {
  position: relative;
}

.board {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  background: var(--board);
  border-radius: 12px;
  padding: 10px;
  touch-action: none;
}

.tile {
  aspect-ratio: 1 / 1;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 1.55rem;
  background: var(--cell);
  color: #776e65;
}

.tile-0 { background: var(--cell); color: transparent; }
.tile-2 { background: #eee4da; }
.tile-4 { background: #ede0c8; }
.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: 1.35rem; }
.tile-256 { background: #edcc61; color: #fff; font-size: 1.35rem; }
.tile-512 { background: #edc850; color: #fff; font-size: 1.35rem; }
.tile-1024 { background: #edc53f; color: #fff; font-size: 1.1rem; }
.tile-2048 { background: #edc22e; color: #fff; font-size: 1.1rem; }
.tile-super { background: #3c3a32; color: #fff; font-size: 1.05rem; }

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.72);
  display: grid;
  place-items: center;
  border-radius: 12px;
}

.hidden {
  display: none;
}

.overlay-card {
  background: #fff;
  border: 1px solid #ead9c7;
  border-radius: 12px;
  padding: 16px;
  text-align: center;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08);
}

.overlay-card p {
  margin: 0 0 10px;
  font-size: 1.1rem;
  font-weight: 700;
}

.tips {
  margin-top: 14px;
  background: var(--surface);
  border: 1px solid #ead9c7;
  border-radius: 10px;
  padding: 12px;
}

.tips p {
  margin: 0;
}

.help {
  margin-top: 6px;
  color: var(--muted);
}

@media (max-width: 520px) {
  .topbar h1 {
    font-size: 1.8rem;
  }

  .score-panel {
    grid-template-columns: 1fr 1fr;
  }

  #newGameBtn {
    grid-column: span 2;
  }

  .tile {
    font-size: 1.25rem;
  }

  .tile-1024,
  .tile-2048,
  .tile-super {
    font-size: 0.95rem;
  }
}
