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

html, body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: #faf8ef;
  color: #776e65;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 16px 12px 40px;
  min-height: 100vh;
  overflow-x: hidden;
}

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

.header {
  margin-bottom: 16px;
}

.title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.title {
  font-size: 64px;
  font-weight: 800;
  color: #776e65;
  letter-spacing: 1px;
  line-height: 1;
}

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

.score-box {
  background: #bbada0;
  border-radius: 6px;
  padding: 6px 14px;
  text-align: center;
  min-width: 70px;
  position: relative;
  overflow: hidden;
}

.score-label {
  font-size: 12px;
  color: #eee4da;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.score-value {
  font-size: 22px;
  font-weight: 700;
  color: #fff;
  line-height: 1.2;
}

.subtitle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.subtitle {
  font-size: 14px;
  color: #776e65;
  flex: 1;
}

.btn-new {
  background: #8f7a66;
  color: #f9f6f2;
  border: none;
  border-radius: 5px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}

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

.btn-new:active {
  background: #7a6a58;
  transform: scale(0.97);
}

.game-container {
  position: relative;
}

.board {
  position: relative;
  background: #bbada0;
  border-radius: 8px;
  padding: 10px;
  width: 100%;
  aspect-ratio: 1 / 1;
  touch-action: none;
  user-select: none;
}

.cell-bg {
  position: absolute;
  background: rgba(238, 228, 218, 0.35);
  border-radius: 6px;
}

.tile {
  position: absolute;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  color: #f9f6f2;
  transition: transform 120ms ease-in-out;
  will-change: transform;
}

.tile-new {
  animation: appear 180ms ease-in-out;
}

.tile-merged {
  animation: pop 220ms ease-in-out;
}

@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: #776e65; }
.tile-4   { background: #ede0c8; color: #776e65; }
.tile-8   { background: #f2b179; color: #f9f6f2; }
.tile-16  { background: #f59563; color: #f9f6f2; }
.tile-32  { background: #f67c5f; color: #f9f6f2; }
.tile-64  { background: #f65e3b; color: #f9f6f2; }
.tile-128 { background: #edcf72; color: #f9f6f2; }
.tile-256 { background: #edcc61; color: #f9f6f2; }
.tile-512 { background: #edc850; color: #f9f6f2; }
.tile-1024{ background: #edc53f; color: #f9f6f2; }
.tile-2048{ background: #edc22e; color: #f9f6f2; }
.tile-super { background: #3c3a32; color: #f9f6f2; }

.tile-128, .tile-256, .tile-512, .tile-1024, .tile-2048 {
  font-size: 2.4rem;
}

@media (max-width: 400px) {
  .tile-128, .tile-256, .tile-512, .tile-1024, .tile-2048 {
    font-size: 2rem;
  }
}

.message-overlay {
  position: absolute;
  inset: 0;
  background: rgba(238, 228, 218, 0.73);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  animation: fadein 300ms ease-in-out;
}

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

.message-overlay.hidden {
  display: none;
}

.message-box {
  text-align: center;
  padding: 20px;
}

.message-title {
  font-size: 52px;
  font-weight: 800;
  color: #776e65;
  margin-bottom: 8px;
}

.message-subtitle {
  font-size: 16px;
  color: #776e65;
  margin-bottom: 24px;
}

.message-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.btn {
  border: none;
  border-radius: 5px;
  padding: 12px 22px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.btn:active {
  transform: scale(0.96);
}

.btn-keep {
  background: #8f7a66;
  color: #f9f6f2;
}

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

.btn-retry {
  background: #f2b179;
  color: #f9f6f2;
}

.btn-retry:hover {
  background: #f59d5c;
}

.hint {
  text-align: center;
  margin-top: 18px;
  font-size: 13px;
  color: #a9a196;
}

.howto {
  text-align: center;
  margin-top: 8px;
  font-size: 12px;
  line-height: 1.6;
  color: #a9a196;
  max-width: 460px;
  margin-left: auto;
  margin-right: auto;
}
