:root {
  --bg: #faf8ef;
  --panel: #bbada0;
  --tile-empty: #cdc1b4;
  --text-main: #776e65;
  --white: #f9f6f2;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: linear-gradient(180deg, #fefcf6 0%, #f4efe5 100%);
  color: var(--text-main);
  min-height: 100vh;
  display: grid;
  place-items: center;
  touch-action: manipulation;
}

.game-wrap {
  width: min(92vw, 460px);
}

.top-bar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

h1 {
  margin: 0;
  font-size: 56px;
  line-height: 1;
}

.subtitle {
  margin: 6px 0 0;
  font-size: 14px;
}

.new-game-btn,
#retry-btn {
  border: none;
  background: #8f7a66;
  color: #fff;
  padding: 10px 14px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
}

.new-game-btn:active,
#retry-btn:active {
  transform: translateY(1px);
}

.score-board {
  margin: 14px 0;
  display: flex;
  gap: 10px;
}

.score-card {
  flex: 1;
  background: #bbada0;
  color: var(--white);
  border-radius: 8px;
  padding: 8px 12px;
  text-align: center;
}

.score-card span {
  display: block;
  font-size: 12px;
  opacity: 0.85;
}

.score-card strong {
  font-size: 28px;
}

.game-container {
  position: relative;
}

.grid {
  position: relative;
  background: var(--panel);
  border-radius: 10px;
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  user-select: none;
}

.cell {
  aspect-ratio: 1 / 1;
  border-radius: 8px;
  background: var(--tile-empty);
  display: grid;
  place-items: center;
  font-size: clamp(20px, 6vw, 34px);
  font-weight: 800;
  color: #776e65;
  transition: transform 0.12s ease;
}

.cell[data-value="0"] {
  color: transparent;
}
.cell[data-value="2"] { background: #eee4da; }
.cell[data-value="4"] { background: #ede0c8; }
.cell[data-value="8"] { background: #f2b179; color: var(--white); }
.cell[data-value="16"] { background: #f59563; color: var(--white); }
.cell[data-value="32"] { background: #f67c5f; color: var(--white); }
.cell[data-value="64"] { background: #f65e3b; color: var(--white); }
.cell[data-value="128"] { background: #edcf72; color: var(--white); font-size: clamp(18px, 5vw, 30px); }
.cell[data-value="256"] { background: #edcc61; color: var(--white); font-size: clamp(18px, 5vw, 30px); }
.cell[data-value="512"] { background: #edc850; color: var(--white); font-size: clamp(18px, 5vw, 30px); }
.cell[data-value="1024"] { background: #edc53f; color: var(--white); font-size: clamp(16px, 4.6vw, 26px); }
.cell[data-value="2048"] { background: #edc22e; color: var(--white); font-size: clamp(16px, 4.6vw, 26px); }
.cell[data-value="4096"],
.cell[data-value="8192"] { background: #3c3a32; color: var(--white); font-size: clamp(14px, 4.2vw, 22px); }

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  background: rgba(238, 228, 218, 0.78);
  border-radius: 10px;
  text-align: center;
  backdrop-filter: blur(1px);
}

.overlay p {
  margin: 0;
  font-size: 34px;
  font-weight: 800;
}

.hidden {
  display: none;
}

.hint {
  text-align: center;
  font-size: 14px;
  margin-top: 12px;
}
