*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #1a1a2e;
  --grid-bg: #0f1628;
  --cell-bg: #16213e;
  --text: #e0e6f0;
  --accent: #20b2aa;
  --pink: #e07090;
  --font: "SF Pro Display", "Segoe UI", system-ui, -apple-system, sans-serif;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  overflow: hidden;
}

body {
  display: flex;
  justify-content: center;
  align-items: center;
}

.container {
  width: 100%;
  max-width: 420px;
  padding: 16px;
}

/* ── Header ───────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.title {
  font-size: 3rem;
  font-weight: 900;
  letter-spacing: -2px;
  background: linear-gradient(135deg, #20b2aa, #ff6eb4);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

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

.score-box {
  background: var(--cell-bg);
  border: 1px solid #20b2aa40;
  border-radius: 6px;
  padding: 6px 14px;
  text-align: center;
  min-width: 70px;
}

.score-box .label {
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--accent);
}

.score-box .value {
  font-size: 1.2rem;
  font-weight: 700;
}

/* ── Subtitle & Button ────────────────────── */
.sub-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.subtitle {
  font-size: 0.8rem;
  color: #8892a4;
}

.new-game {
  background: var(--pink);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 8px 16px;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
}

.new-game:hover {
  background: #d94f8a;
}

/* ── Grid ─────────────────────────────────── */
.grid-wrapper {
  position: relative;
  background: var(--grid-bg);
  border-radius: 10px;
  padding: 8px;
  aspect-ratio: 1;
}

.grid-bg {
  display: grid;
  grid-template: repeat(4, 1fr) / repeat(4, 1fr);
  gap: 8px;
  width: 100%;
  height: 100%;
}

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

.tile-layer {
  position: absolute;
  inset: 8px;
}

/* ── Tiles ────────────────────────────────── */
.tile {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  border-radius: 6px;
  transition: top 0.13s ease, left 0.13s ease;
  /* size set by JS via CSS custom properties */
  width: calc((100% - 24px) / 4);
  height: calc((100% - 24px) / 4);
}

.tile.new {
  animation: pop-in 0.2s ease;
}

.tile.merged {
  animation: pulse 0.2s ease;
}

@keyframes pop-in {
  0%   { transform: scale(0); opacity: 0; }
  60%  { transform: scale(1.1); }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes pulse {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.15); }
  100% { transform: scale(1); }
}

/* ── Tile colors ──────────────────────────── */
.tile[data-value="3"]    { background: #2a3a5c; color: #e0e6f0; font-size: calc(min(12vw, 48px)); }
.tile[data-value="6"]    { background: #3a5a7c; color: #f0f4fa; font-size: calc(min(12vw, 48px)); }
.tile[data-value="12"]   { background: #2e8b8b; color: #ffffff; font-size: calc(min(11vw, 44px)); }
.tile[data-value="24"]   { background: #20b2aa; color: #ffffff; font-size: calc(min(11vw, 44px)); }
.tile[data-value="48"]   { background: #e07090; color: #ffffff; font-size: calc(min(11vw, 44px)); }
.tile[data-value="96"]   { background: #d94f8a; color: #ffffff; font-size: calc(min(11vw, 44px)); }
.tile[data-value="192"]  { background: #c040a0; color: #ffffff; font-size: calc(min(10vw, 38px)); }
.tile[data-value="384"]  { background: #9b59b6; color: #ffffff; font-size: calc(min(10vw, 38px)); }
.tile[data-value="768"]  { background: #f0a050; color: #ffffff; font-size: calc(min(10vw, 38px)); }
.tile[data-value="1536"] { background: #e8704a; color: #ffffff; font-size: calc(min(9vw, 34px)); }
.tile[data-value="3072"] { background: #ff6eb4; color: #ffffff; font-size: calc(min(9vw, 34px));
  box-shadow: 0 0 20px #ff6eb480, 0 0 40px #ff6eb440;
}

/* ── Overlays ─────────────────────────────── */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: #1a1a2ee0;
  z-index: 10;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

.overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.overlay .msg {
  font-size: 2rem;
  font-weight: 800;
  margin-bottom: 16px;
}

.overlay.win .msg {
  background: linear-gradient(135deg, #20b2aa, #ff6eb4);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.overlay .retry {
  background: var(--pink);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 10px 24px;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
}

.overlay .keep-going {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 10px 24px;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  margin-bottom: 8px;
}
