:root {
  --bg: #FFF8F3;
  --primary: #FF6B9D;
  --primary-dark: #E85585;
  --card: #FFFFFF;
  --text: #2D3142;
  --text-light: #6C7293;
  --board-bg: #FFE8DD;
  --cell-empty: #FFF0E6;
  --shadow: 0 8px 24px rgba(45, 49, 66, 0.12);

  /* Tile palette */
  --t2:    #FFF8F3;
  --t4:    #FFE8DD;
  --t8:    #FFD2C2;
  --t16:   #FFB3A0;
  --t32:   #FFB3D1;
  --t64:   #FF6B9D;
  --t128:  #FFD93D;
  --t256:  #FFB400;
  --t512:  #5EC9F2;
  --t1024: #6BCB77;
  --t2048: #FF6B9D;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Nunito', system-ui, -apple-system, sans-serif;
  overflow: hidden;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

#game-container {
  position: relative;
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  padding: 64px 16px 16px;
}

#ui-overlay {
  position: absolute;
  top: 12px; left: 12px; right: 12px;
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px;
  z-index: 5;
}
.ui-row { display: flex; gap: 8px; }
.ui-pill {
  background: rgba(255,255,255,0.92);
  padding: 6px 14px;
  border-radius: 999px;
  font-weight: 800;
  box-shadow: 0 2px 8px rgba(45,49,66,0.08);
  font-size: 0.9rem;
}
.ui-label { font-weight: 600; color: var(--text-light); margin-right: 4px; font-size: 0.8rem; }
#undo-btn, #pause-btn, #mute-btn {
  background: rgba(255,255,255,0.92);
  border: 0;
  width: 40px; height: 40px;
  border-radius: 50%;
  font-size: 1.1rem;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(45,49,66,0.08);
}
#undo-btn:disabled { opacity: 0.4; cursor: not-allowed; }

#board {
  position: relative;
  width: 100%;
  max-width: 360px;
  aspect-ratio: 1 / 1;
  background: var(--board-bg);
  border-radius: 16px;
  padding: 8px;
  box-shadow: var(--shadow);
}
.cell {
  position: absolute;
  width: calc(25% - 12px);
  aspect-ratio: 1 / 1;
  background: var(--cell-empty);
  border-radius: 8px;
}
.tile {
  position: absolute;
  width: calc(25% - 12px);
  aspect-ratio: 1 / 1;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800;
  font-size: 1.5rem;
  color: var(--text);
  transition: transform 0.13s ease, background 0.13s ease;
  box-shadow: 0 2px 6px rgba(0,0,0,0.05);
}
.tile--new { animation: pop 0.18s ease-out; }
.tile--merge { animation: merge 0.22s ease-out; }
@keyframes pop {
  from { transform: scale(0.2); }
  to   { transform: scale(1); }
}
@keyframes merge {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.18); }
  100% { transform: scale(1); }
}

.tile-2    { background: var(--t2); }
.tile-4    { background: var(--t4); }
.tile-8    { background: var(--t8); color: #fff; }
.tile-16   { background: var(--t16); color: #fff; }
.tile-32   { background: var(--t32); color: #fff; }
.tile-64   { background: var(--t64); color: #fff; }
.tile-128  { background: var(--t128); color: #2D3142; font-size: 1.3rem; }
.tile-256  { background: var(--t256); color: #fff; font-size: 1.3rem; }
.tile-512  { background: var(--t512); color: #fff; font-size: 1.3rem; }
.tile-1024 { background: var(--t1024); color: #fff; font-size: 1.1rem; }
.tile-2048 { background: var(--t2048); color: #fff; font-size: 1.1rem; box-shadow: 0 0 24px rgba(255,107,157,0.5); }
.tile-4096, .tile-8192, .tile-16384 {
  background: linear-gradient(135deg, #FF6B9D, #FFD93D); color: #fff; font-size: 1rem;
}

.modal {
  position: absolute; inset: 0;
  background: rgba(45,49,66,0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 10; padding: 20px;
}
.modal.hidden { display: none; }
.modal__inner {
  background: var(--card);
  border-radius: 24px;
  padding: 28px 24px;
  text-align: center;
  max-width: 320px; width: 100%;
  box-shadow: var(--shadow);
}
.modal__inner h2 { margin: 0 0 8px; font-size: 1.6rem; }
.modal__inner p { margin: 0 0 16px; color: var(--text-light); }
.big-score { font-size: 1.4rem !important; color: var(--text) !important; font-weight: 800; margin: 4px 0 !important; }
.sub-score { font-size: 0.95rem; }

.btn {
  background: var(--primary); color: #fff;
  border: 0;
  padding: 12px 28px;
  border-radius: 999px;
  font-size: 1rem; font-weight: 800;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(255,107,157,0.4);
}
.btn:hover { background: var(--primary-dark); }

.ad-slot {
  margin-top: 16px;
  min-height: 100px;
}
