:root {
  --bg: #faf8ef;
  --text: #776e65;
  --muted: #9b9288;
  --board: #bbada0;
  --cell: rgba(238, 228, 218, .35);
  --gap: clamp(8px, 2.4vw, 14px);
  --radius: clamp(10px, 2.5vw, 16px);
  --board-size: min(92vw, 520px);
  --tile-size: calc((var(--board-size) - 5 * var(--gap)) / 4);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: radial-gradient(circle at top, #fffdf7 0, var(--bg) 42%, #f1eadc 100%); color: var(--text); }
body { display: flex; justify-content: center; align-items: flex-start; padding: max(16px, env(safe-area-inset-top)) 12px 24px; overscroll-behavior: none; }
.app { width: var(--board-size); max-width: 100%; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 6px 0 12px; }
h1 { margin: 0; font-size: clamp(42px, 13vw, 76px); line-height: .9; letter-spacing: -4px; color: #776e65; }
.subtitle { margin: 8px 0 0; color: var(--muted); font-size: clamp(13px, 3.5vw, 16px); }
.scores { display: flex; gap: 8px; flex-shrink: 0; }
.score-card { min-width: clamp(70px, 20vw, 96px); padding: 8px 10px; border-radius: 12px; background: #bbada0; color: #fff; text-align: center; box-shadow: 0 6px 18px rgba(119,110,101,.12); }
.score-card span { display: block; font-size: clamp(11px, 2.9vw, 13px); opacity: .85; }
.score-card strong { display: block; font-size: clamp(18px, 5vw, 26px); line-height: 1.15; }
.controls { display: flex; justify-content: flex-end; margin-bottom: 12px; }
button { border: 0; cursor: pointer; border-radius: 12px; background: #8f7a66; color: #fff; font-weight: 800; font-size: clamp(14px, 3.8vw, 16px); padding: 11px 16px; box-shadow: 0 7px 16px rgba(143,122,102,.22); transition: transform .08s ease, filter .15s ease; }
button:active { transform: translateY(1px) scale(.99); }
button:hover { filter: brightness(1.04); }
.board { position: relative; width: var(--board-size); height: var(--board-size); padding: var(--gap); border-radius: calc(var(--radius) + 4px); background: var(--board); box-shadow: 0 14px 32px rgba(119,110,101,.22); touch-action: none; outline: none; overflow: hidden; isolation: isolate; contain: layout paint; }
.grid-bg { position: absolute; inset: var(--gap); z-index: 0; pointer-events: none; overflow: visible; }
/* 背景格固定由 JS 生成 16 个，并显式用 x/y 定位，避免移动端 WebView 对 absolute+grid/gap 的首项渲染兼容问题。 */
.grid-bg > .cell-bg { position: absolute; left: calc(var(--x) * (var(--tile-size) + var(--gap))); top: calc(var(--y) * (var(--tile-size) + var(--gap))); width: var(--tile-size); height: var(--tile-size); border-radius: var(--radius); background: var(--cell); overflow: hidden; transform: translateZ(0); z-index: 0; }
.tiles { position: absolute; inset: var(--gap); z-index: 1; pointer-events: none; overflow: visible; }
.tile { position: absolute; z-index: 2; width: var(--tile-size); height: var(--tile-size); border-radius: var(--radius); display: flex; justify-content: center; align-items: center; line-height: 1; font-weight: 900; font-size: clamp(24px, 8vw, 54px); color: #776e65; box-shadow: inset 0 -4px 0 rgba(0,0,0,.04); transform: translate3d(calc(var(--x) * (var(--tile-size) + var(--gap))), calc(var(--y) * (var(--tile-size) + var(--gap))), 0); transition: transform .12s ease, opacity .12s ease; animation: pop .14s ease; backface-visibility: hidden; overflow: hidden; }
.tile.big { font-size: clamp(20px, 6.4vw, 44px); }
.tile.huge { font-size: clamp(17px, 5.3vw, 35px); }
@keyframes pop { from { transform: translate3d(calc(var(--x) * (var(--tile-size) + var(--gap))), calc(var(--y) * (var(--tile-size) + var(--gap))), 0) scale(.72); opacity: .55; } to { transform: translate3d(calc(var(--x) * (var(--tile-size) + var(--gap))), calc(var(--y) * (var(--tile-size) + var(--gap))), 0) scale(1); opacity: 1; } }
.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; } .tile-256 { background: #edcc61; color:#fff; }
.tile-512 { background: #edc850; color:#fff; } .tile-1024 { background: #edc53f; color:#fff; }
.tile-2048 { background: #edc22e; color:#fff; box-shadow: 0 0 20px rgba(237,194,46,.45), inset 0 -4px 0 rgba(0,0,0,.04); }
.tile-super { background: #3c3a32; color:#fff; }
.overlay { position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 18px; background: rgba(250,248,239,.78); backdrop-filter: blur(2px); text-align: center; z-index: 5; }
.overlay.hidden { display: none; }
.message { font-size: clamp(32px, 10vw, 56px); font-weight: 900; color: #776e65; }
.hint { text-align: center; margin: 16px 0 0; color: var(--muted); font-size: clamp(13px, 3.5vw, 15px); }
@media (max-width: 420px) { .topbar { align-items: flex-start; } .scores { flex-direction: column; gap: 6px; } .score-card { padding: 7px 9px; } }
