:root {
  --bg: #faf8ef;
  --panel: #bbada0;
  --cell: rgba(238, 228, 218, 0.35);
  --text: #776e65;
  --light: #f9f6f2;
  --accent: #8f7a66;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0;
  min-height: 100%;
  background: linear-gradient(180deg, #faf8ef 0%, #f5efe6 100%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}
body {
  display: flex;
  justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) 14px max(18px, env(safe-area-inset-bottom));
}
.app {
  width: min(100%, 480px);
}
.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.topbar h1 {
  margin: 0;
  font-size: 56px;
  line-height: 1;
  color: #776e65;
}
.topbar p {
  margin: 6px 0 0;
  font-size: 15px;
}
.scoreboard {
  display: flex;
  gap: 8px;
}
.card {
  min-width: 80px;
  padding: 10px 12px;
  border-radius: 12px;
  background: #bbada0;
  color: var(--light);
  text-align: center;
}
.card span {
  display: block;
  font-size: 12px;
  opacity: 0.9;
}
.card strong {
  display: block;
  margin-top: 4px;
  font-size: 22px;
}
.actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}
button {
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: var(--light);
  font-weight: 700;
  font-size: 15px;
  padding: 12px 16px;
  cursor: pointer;
}
button:active { transform: scale(0.98); }
.actions button {
  flex: 1;
}
.tips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 12px 0 14px;
}
.tips span {
  font-size: 12px;
  background: rgba(143, 122, 102, 0.12);
  color: #7a6a5d;
  padding: 6px 10px;
  border-radius: 999px;
}
.board-wrap {
  position: relative;
}
.board {
  position: relative;
  background: var(--panel);
  border-radius: 18px;
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  touch-action: none;
  user-select: none;
}
.cell {
  aspect-ratio: 1 / 1;
  border-radius: 12px;
  background: var(--cell);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: clamp(24px, 6.5vw, 36px);
  color: #776e65;
  transition: transform 0.12s ease, background 0.12s ease;
}
.cell.empty {
  color: transparent;
}
.cell.v2 { background: #eee4da; }
.cell.v4 { background: #ede0c8; }
.cell.v8 { background: #f2b179; color: #f9f6f2; }
.cell.v16 { background: #f59563; color: #f9f6f2; }
.cell.v32 { background: #f67c5f; color: #f9f6f2; }
.cell.v64 { background: #f65e3b; color: #f9f6f2; }
.cell.v128 { background: #edcf72; color: #f9f6f2; font-size: clamp(20px, 5.6vw, 32px); }
.cell.v256 { background: #edcc61; color: #f9f6f2; font-size: clamp(20px, 5.6vw, 32px); }
.cell.v512 { background: #edc850; color: #f9f6f2; font-size: clamp(20px, 5.6vw, 32px); }
.cell.v1024 { background: #edc53f; color: #f9f6f2; font-size: clamp(18px, 5vw, 28px); }
.cell.v2048 { background: #edc22e; color: #f9f6f2; font-size: clamp(18px, 5vw, 28px); }
.cell.vbig { background: #3c3a32; color: #f9f6f2; font-size: clamp(16px, 4.2vw, 24px); }
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(250, 248, 239, 0.78);
  border-radius: 18px;
}
.overlay.hidden { display: none; }
.overlay-card {
  width: min(88%, 280px);
  padding: 22px 18px;
  background: rgba(255,255,255,0.95);
  border-radius: 16px;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0,0,0,0.08);
}
.overlay-card h2 {
  margin: 0 0 8px;
  font-size: 28px;
}
.overlay-card p {
  margin: 0 0 16px;
  font-size: 15px;
  color: #7a6a5d;
}
@media (max-width: 420px) {
  .topbar { flex-direction: column; }
  .scoreboard { width: 100%; }
  .card { flex: 1; }
  .topbar h1 { font-size: 48px; }
}
