:root {
  --bg: #f7f3ff;
  --panel: rgba(255, 255, 255, 0.82);
  --panel-2: rgba(255, 255, 255, 0.5);
  --text: #231f42;
  --muted: #645d88;
  --accent: #8d63ff;
  --accent-dark: #5e38d8;
  --shadow: 0 20px 50px rgba(61, 46, 119, 0.16);
  --radius: 28px;
  --board-size: min(88vw, 640px);
  --gap: 10px;
  --padding: 10px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(122, 83, 255, 0.22), transparent 30%),
    radial-gradient(circle at bottom right, rgba(0, 214, 255, 0.14), transparent 28%),
    linear-gradient(180deg, #f8f6ff 0%, #eee8ff 45%, #e6f7ff 100%);
}
body {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px 16px;
}
.page-shell { width: 100%; display: flex; justify-content: center; }
.game-card {
  width: min(100%, 900px);
  background: var(--panel);
  backdrop-filter: blur(14px);
  border: 1px solid rgba(255,255,255,0.45);
  border-radius: 36px;
  padding: 24px;
  box-shadow: var(--shadow);
}
.game-header, .toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.eyebrow, .label {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
}
h1 {
  margin: 6px 0 8px;
  font-size: clamp(2rem, 5vw, 3.4rem);
  line-height: 0.95;
}
.subtitle {
  margin: 0;
  max-width: 42rem;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.45;
}
.score-panel { display: flex; gap: 12px; }
.score-box, .goal-box, .mode-picker {
  min-width: 100px;
  background: var(--panel-2);
  border-radius: 18px;
  padding: 12px 16px;
  text-align: center;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.6);
}
.score-box strong, .goal-box strong {
  display: block;
  margin-top: 4px;
  font-size: 1.6rem;
}
.toolbar { margin: 22px 0 18px; }
.controls-copy {
  flex: 1;
  min-width: 220px;
  color: var(--muted);
}
.mode-picker {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 170px;
}
.mode-picker select {
  border: 0;
  outline: 0;
  border-radius: 12px;
  padding: 10px 12px;
  font: inherit;
  font-weight: 700;
  background: rgba(255,255,255,0.95);
  color: var(--text);
}
button {
  border: 0;
  cursor: pointer;
  border-radius: 999px;
  font: inherit;
  transition: transform 0.15s ease, opacity 0.15s ease, background 0.15s ease;
}
button:hover { transform: translateY(-1px); }
button:active { transform: translateY(1px); }
.primary-btn, .ghost-btn { padding: 12px 18px; font-weight: 700; }
.primary-btn {
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: white;
  box-shadow: 0 10px 24px rgba(94, 56, 216, 0.28);
}
.ghost-btn { background: rgba(141, 99, 255, 0.12); color: var(--accent-dark); }
.board-wrap {
  position: relative;
  width: var(--board-size);
  height: var(--board-size);
  margin: 0 auto;
  border-radius: var(--radius);
  background:
    radial-gradient(circle at 20% 18%, rgba(255,255,255,0.2), transparent 22%),
    linear-gradient(180deg, #8b79cc 0%, #7460bf 100%);
  padding: var(--padding);
  overflow: hidden;
  touch-action: none;
  user-select: none;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.35), 0 18px 40px rgba(77, 62, 130, 0.24);
}
.board-background,
.tile-layer {
  position: absolute;
  inset: var(--padding);
}
.board-background {
  display: grid;
  gap: var(--gap);
}
.bg-cell {
  border-radius: 999px;
  background: radial-gradient(circle at 30% 28%, rgba(255,255,255,0.22), rgba(255,255,255,0.08) 45%, rgba(255,255,255,0.03) 72%);
  box-shadow: inset 0 -10px 20px rgba(40, 24, 94, 0.12), inset 0 2px 8px rgba(255,255,255,0.08);
}
.tile {
  position: absolute;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  line-height: 1;
  color: white;
  transition: left 150ms ease-in-out, top 150ms ease-in-out, transform 160ms ease-in-out;
  box-shadow: 0 14px 24px rgba(45, 28, 99, 0.22), inset 0 3px 10px rgba(255,255,255,0.36);
  text-shadow: 0 1px 2px rgba(0,0,0,0.18);
  overflow: hidden;
}
.tile::before {
  content: "";
  position: absolute;
  inset: 7% 14% auto 14%;
  height: 34%;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(255,255,255,0.58), rgba(255,255,255,0.06));
  pointer-events: none;
}
.tile::after {
  content: "";
  position: absolute;
  inset: -8%;
  border-radius: 999px;
  border: 2px solid rgba(255,255,255,0.18);
  pointer-events: none;
}
.tile > span { position: relative; z-index: 1; }
.tile.new-tile { animation: pop-in 170ms ease; }
.tile.merge-tile { animation: merge-bounce 210ms ease; }
.tile-value-2 { background: radial-gradient(circle at 30% 30%, #8cf1ff, #38c8ff 62%, #12a6ff 100%); }
.tile-value-4 { background: radial-gradient(circle at 30% 30%, #8fffd9, #3be8b0 62%, #18c786 100%); }
.tile-value-8 { background: radial-gradient(circle at 30% 30%, #fff38f, #ffd24c 62%, #ffae19 100%); }
.tile-value-16 { background: radial-gradient(circle at 30% 30%, #ffb88f, #ff7f6a 62%, #ff4f77 100%); }
.tile-value-32 { background: radial-gradient(circle at 30% 30%, #ffa7da, #f45dcb 62%, #c93bff 100%); }
.tile-value-64 { background: radial-gradient(circle at 30% 30%, #d6a5ff, #9669ff 62%, #6431ff 100%); }
.tile-value-128 { background: radial-gradient(circle at 30% 30%, #b0f4ff, #53d8ff 40%, #008cff 100%); }
.tile-value-256 { background: radial-gradient(circle at 30% 30%, #c8ffd2, #6ff78b 42%, #0dc76a 100%); }
.tile-value-512 { background: radial-gradient(circle at 30% 30%, #fff3af, #ffd95a 42%, #ff9d00 100%); }
.tile-value-1024 { background: radial-gradient(circle at 30% 30%, #ffc1f0, #ff75c8 40%, #de2cff 100%); }
.tile-value-2048 { background: radial-gradient(circle at 30% 30%, #ffffff, #c6f5ff 24%, #84cbff 45%, #8f6bff 75%, #4c22ff 100%); }
.tile-value-super { background: radial-gradient(circle at 30% 30%, #ffffff, #ffb6d9 20%, #8d63ff 55%, #1f114f 100%); }
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(244, 239, 255, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 25;
}
.hidden { display: none; }
.overlay-card {
  width: min(90%, 360px);
  background: rgba(255, 255, 255, 0.94);
  border-radius: 24px;
  padding: 24px;
  text-align: center;
  box-shadow: var(--shadow);
}
.overlay-card h2 { margin: 0 0 8px; font-size: 2rem; }
.overlay-card p { margin: 0; color: var(--muted); line-height: 1.45; }
.overlay-actions {
  margin-top: 18px;
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}
.help-text { margin-top: 18px; text-align: center; color: var(--muted); }
@keyframes pop-in {
  0% { transform: scale(0.35); filter: saturate(1.6) blur(1px); }
  100% { transform: scale(1); filter: saturate(1) blur(0); }
}
@keyframes merge-bounce {
  0% { transform: scale(1); }
  35% { transform: scale(1.18); }
  65% { transform: scale(0.94); }
  100% { transform: scale(1); }
}
@media (max-width: 720px) {
  :root {
    --board-size: min(92vw, 560px);
    --gap: 8px;
    --padding: 8px;
  }
  .game-card { padding: 18px; border-radius: 28px; }
  .score-box, .goal-box, .mode-picker { min-width: 0; }
}
