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

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

html,
body {
  margin: 0;
  height: 100%;
}

body {
  font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: #faf8ef;
  color: var(--text-dark);
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 16px;
  touch-action: none;
}

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

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

h1 {
  font-size: 48px;
  margin: 0;
  font-weight: 800;
}

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

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

.score-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  opacity: 0.85;
}

.score-value {
  font-size: 22px;
  font-weight: 700;
}

.controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin: 16px 0;
}

.hint {
  margin: 0;
  font-size: 13px;
  line-height: 1.4;
  color: var(--text-dark);
}

.btn {
  background: #8f7a66;
  color: var(--text-light);
  border: none;
  border-radius: 6px;
  padding: 10px 18px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s ease;
  flex-shrink: 0;
}

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

.btn-ghost {
  background: transparent;
  color: #8f7a66;
  border: 2px solid #8f7a66;
}

.btn-ghost:hover {
  background: rgba(143, 122, 102, 0.1);
}

.board-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
}

.board {
  position: absolute;
  inset: 0;
  background: var(--board-bg);
  border-radius: 8px;
  padding: 12px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 12px;
}

.cell {
  background: var(--cell-bg);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tile {
  width: 100%;
  height: 100%;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: clamp(20px, 7vw, 36px);
  color: var(--text-dark);
  animation: pop 0.12s ease;
  transition: background 0.1s ease;
}

.tile[data-value="2"] { background: #eee4da; }
.tile[data-value="4"] { background: #ede0c8; }
.tile[data-value="8"] { background: #f2b179; color: var(--text-light); }
.tile[data-value="16"] { background: #f59563; color: var(--text-light); }
.tile[data-value="32"] { background: #f67c5f; color: var(--text-light); }
.tile[data-value="64"] { background: #f65e3b; color: var(--text-light); }
.tile[data-value="128"] { background: #edcf72; color: var(--text-light); }
.tile[data-value="256"] { background: #edcc61; color: var(--text-light); }
.tile[data-value="512"] { background: #edc850; color: var(--text-light); }
.tile[data-value="1024"] { background: #edc53f; color: var(--text-light); }
.tile[data-value="2048"] { background: #edc22e; color: var(--text-light); }
.tile[data-value="4096"] { background: #3c3a32; color: var(--text-light); }
.tile[data-value="8192"] { background: #2e2c26; color: var(--text-light); }

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

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

.tile.new {
  animation: appear 0.14s ease;
}

.overlay {
  position: absolute;
  inset: 0;
  border-radius: 8px;
  background: rgba(238, 228, 218, 0.75);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  z-index: 10;
  animation: fade 0.2s ease;
}

.overlay.hidden {
  display: none;
}

.overlay-text {
  font-size: 40px;
  font-weight: 800;
  margin: 0;
}

.overlay-actions {
  display: flex;
  gap: 10px;
}

@keyframes fade {
  from { opacity: 0; }
  to { opacity: 1; }
}
