/* 2048 数字合成 · DaoBox 家族 */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #faf8ef;
  --board: #bbada0;
  --cell: rgba(238, 228, 218, 0.35);
  --text: #776e65;
  --text-light: #f9f6f2;
  --accent: #edc22e;
}

html, body { height: 100%; }
body {
  font-family: -apple-system, 'PingFang SC', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- 顶栏 ---------- */
.topbar {
  background: #fff;
  border-bottom: 1px solid rgba(0,0,0,.06);
  position: sticky; top: 0; z-index: 50;
}
.topbar-inner {
  max-width: 520px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
}
.brand { font-size: 17px; font-weight: 700; }

/* ---------- 主体 ---------- */
.page {
  max-width: 520px; width: 100%;
  margin: 0 auto; padding: 16px 16px 32px;
  flex: 1;
}

.hud {
  display: flex; gap: 10px; align-items: stretch; margin-bottom: 12px;
}
.score-box {
  flex: 1;
  background: var(--board);
  color: var(--text-light);
  border-radius: 10px;
  padding: 8px 12px;
  text-align: center;
}
.score-label { font-size: 12px; opacity: .85; }
.score-value { font-size: 24px; font-weight: 800; line-height: 1.2; }
.btn-col { display: flex; flex-direction: column; gap: 6px; justify-content: center; }
.btn {
  border: none; border-radius: 8px;
  padding: 8px 14px; font-size: 14px; font-weight: 700;
  background: #8f7a66; color: #fff; cursor: pointer;
}
.btn.primary { background: #ed8936; }
.btn:disabled { opacity: .45; cursor: default; }

.hint { font-size: 13px; margin-bottom: 14px; text-align: center; opacity: .85; }
.hint b { color: #ed8936; }

/* ---------- 棋盘 ---------- */
.board {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  background: var(--board);
  border-radius: 12px;
  padding: 8px;
  touch-action: none;
  user-select: none;
}
.cells {
  position: absolute; inset: 8px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 8px;
}
.cell { background: var(--cell); border-radius: 8px; }
.tiles { position: absolute; inset: 8px; }

.tile {
  position: absolute;
  width: calc((100% - 24px) / 4);
  height: calc((100% - 24px) / 4);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800;
  color: var(--text-light);
  transition: transform .12s ease-in-out;
  will-change: transform;
  z-index: 10;
}
.tile.new { animation: tile-pop .18s ease .06s backwards; z-index: 20; }
.tile.merged { animation: tile-merge .18s ease .06s backwards; z-index: 20; }

@keyframes tile-pop {
  0% { transform: scale(0); }
  100% { transform: scale(1); }
}
@keyframes tile-merge {
  0% { transform: scale(1); }
  50% { transform: scale(1.22); }
  100% { transform: scale(1); }
}

/* 数字块配色（经典 2048 色板） */
.tile[data-v="2"]    { background: #eee4da; color: #776e65; }
.tile[data-v="4"]    { background: #ede0c8; color: #776e65; }
.tile[data-v="8"]    { background: #f2b179; }
.tile[data-v="16"]   { background: #f59563; }
.tile[data-v="32"]   { background: #f67c5f; }
.tile[data-v="64"]   { background: #f65e3b; }
.tile[data-v="128"]  { background: #edcf72; }
.tile[data-v="256"]  { background: #edcc61; }
.tile[data-v="512"]  { background: #edc850; }
.tile[data-v="1024"] { background: #edc53f; }
.tile[data-v="2048"] { background: #edc22e; box-shadow: 0 0 18px rgba(237,194,46,.65); }
.tile[data-v="4096"], .tile[data-v="8192"] { background: #3c3a32; }

/* ---------- 说明 ---------- */
.tips {
  margin-top: 22px;
  background: #fff;
  border-radius: 12px;
  padding: 16px;
  border: 1px solid rgba(0,0,0,.05);
}
.tips h2 { font-size: 15px; margin-bottom: 8px; }
.tips ul { padding-left: 18px; }
.tips li { font-size: 13px; line-height: 1.8; }

/* ---------- 弹窗 ---------- */
.modal-mask {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(2,6,23,.6);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal-mask.hidden { display: none; }
.modal-card {
  width: 100%; max-width: 340px;
  background: #fff; border-radius: 16px;
  padding: 26px 22px; text-align: center;
}
.modal-card .win-emoji { font-size: 42px; line-height: 1; }
.modal-card h3 { font-size: 19px; margin: 12px 0 6px; color: #111827; }
.modal-card p { font-size: 14px; color: #6b7280; line-height: 1.6; }
.modal-btns { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
.primary-btn, .secondary-btn {
  display: block; width: 100%;
  padding: 11px 0; border-radius: 10px;
  font-size: 15px; font-weight: 700;
  text-decoration: none; text-align: center;
  border: none; cursor: pointer;
}
.primary-btn { background: #ed8936; color: #fff; }
.secondary-btn { background: #f3f4f6; color: #374151; }

/* ---------- 底部 ---------- */
.footer {
  max-width: 520px; width: 100%; margin: 0 auto;
  padding: 16px; text-align: center;
  font-size: 13px; color: #9ca3af;
}
.footer a { color: #9ca3af; text-decoration: none; }
.footer .dot { margin: 0 6px; }

@media (max-width: 380px) {
  .score-value { font-size: 20px; }
  .btn { padding: 7px 10px; font-size: 13px; }
}
