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

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
    background: var(--bg);
    color: var(--text-dark);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 16px;
}

.container {
    width: 100%;
    max-width: 480px;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

h1 {
    font-size: 56px;
    font-weight: 800;
    color: var(--text-dark);
}

.scores {
    display: flex;
    gap: 8px;
}

.score-box {
    background: var(--board-bg);
    border-radius: 6px;
    padding: 8px 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 72px;
}

.score-label {
    font-size: 11px;
    font-weight: 700;
    color: #eee4da;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.score-value {
    font-size: 22px;
    font-weight: 800;
    color: #fff;
}

.sub-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.intro {
    font-size: 14px;
    line-height: 1.4;
}

.intro b {
    color: var(--text-dark);
}

.new-game-btn {
    background: var(--btn-bg);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 10px 18px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.2s;
    white-space: nowrap;
}

.new-game-btn:hover {
    background: #7f6c58;
}

.board {
    position: relative;
    background: var(--board-bg);
    border-radius: 8px;
    padding: 12px;
    width: 100%;
    aspect-ratio: 1 / 1;
    user-select: none;
    touch-action: none;
}

.grid-container {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 12px;
    width: 100%;
    height: 100%;
}

.grid-cell {
    background: var(--cell-bg);
    border-radius: 6px;
}

.tile-container {
    position: absolute;
    top: 12px;
    left: 12px;
    right: 12px;
    bottom: 12px;
    pointer-events: none;
}

.tile {
    position: absolute;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 6px;
    font-weight: 800;
    font-size: 32px;
    transition: top 0.12s ease, left 0.12s ease;
    will-change: top, left;
}

.tile .tile-inner {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 6px;
}

.tile-new .tile-inner {
    animation: appear 0.18s ease;
}

.tile-merged .tile-inner {
    animation: pop 0.18s ease;
}

@keyframes appear {
    0% { transform: scale(0); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

@keyframes pop {
    0% { transform: scale(1); }
    50% { transform: scale(1.18); }
    100% { transform: scale(1); }
}

/* 方块配色 */
.tile-2    { background: #eee4da; color: var(--text-dark); }
.tile-4    { background: #ede0c8; color: var(--text-dark); }
.tile-8    { background: #f2b179; color: var(--text-light); }
.tile-16   { background: #f59563; color: var(--text-light); }
.tile-32   { background: #f67c5f; color: var(--text-light); }
.tile-64   { background: #f65e3b; color: var(--text-light); }
.tile-128  { background: #edcf72; color: var(--text-light); font-size: 28px; }
.tile-256  { background: #edcc61; color: var(--text-light); font-size: 28px; }
.tile-512  { background: #edc850; color: var(--text-light); font-size: 28px; }
.tile-1024 { background: #edc53f; color: var(--text-light); font-size: 22px; }
.tile-2048 { background: #edc22e; color: var(--text-light); font-size: 22px; }
.tile-super { background: #3c3a32; color: var(--text-light); font-size: 22px; }

.game-over,
.game-win {
    position: absolute;
    inset: 0;
    background: rgba(250, 248, 239, 0.75);
    display: none;
    justify-content: center;
    align-items: center;
    border-radius: 8px;
    z-index: 10;
}

.game-over.show,
.game-win.show {
    display: flex;
    animation: appear 0.3s ease;
}

.game-over-content {
    text-align: center;
}

.go-title {
    font-size: 42px;
    font-weight: 800;
    color: var(--text-dark);
    margin-bottom: 12px;
}

.go-title.win { color: #edc22e; }

.go-score {
    font-size: 18px;
    margin-bottom: 20px;
    color: var(--text-dark);
}

footer {
    margin-top: 20px;
    text-align: center;
    font-size: 13px;
    line-height: 1.8;
    color: #a89a8c;
}

footer b { color: var(--text-dark); }

.tip { font-size: 12px; }

@media (max-width: 400px) {
    h1 { font-size: 44px; }
    .tile { font-size: 26px; }
    .tile-128, .tile-256, .tile-512 { font-size: 22px; }
    .tile-1024, .tile-2048, .tile-super { font-size: 18px; }
}
.home-btn {
  display: inline-block;
  padding: 8px 16px;
  background: #8f7a66;
  color: #f9f6f2;
  text-decoration: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: bold;
  margin-left: 12px;
  vertical-align: middle;
}

.home-btn:hover {
  background: #9f8b77;
}