/* ============================================================
   2048 – Style Sheet
   ============================================================ */

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

:root {
  --bg:        #0F1117;
  --surface:   #1A1D27;
  --surface2:  #22263A;
  --accent:    #305CDE;
  --accent2:   #4A7AFF;
  --text:      #E8EAF0;
  --text-dim:  #7A7F9A;
  --radius:    10px;
  --gap:       10px;
  --cell-size: clamp(60px, 18vw, 90px);
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, sans-serif;
  overflow: hidden;
  touch-action: none;
}

#app {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 12px;
  min-height: 100vh;
  gap: 12px;
}

/* ---- Header ---- */
header { width: 100%; max-width: 420px; }

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

h1 {
  font-size: clamp(2.4rem, 10vw, 3.6rem);
  font-weight: 900;
  letter-spacing: -2px;
  background: linear-gradient(135deg, #FFD700, #FF8C00);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

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

.score-box {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 6px 14px;
  text-align: center;
  min-width: 70px;
}

.score-label {
  display: block;
  font-size: 0.6rem;
  letter-spacing: 1px;
  color: var(--text-dim);
  font-weight: 700;
}

.score-val {
  display: block;
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1.2;
  transition: transform 0.15s;
}

.score-val.bump {
  transform: scale(1.35);
}

.btn-row {
  display: flex;
  gap: 10px;
  margin-bottom: 6px;
}

.btn {
  flex: 1;
  padding: 9px 16px;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.18s, transform 0.1s;
}

.btn:hover  { background: var(--accent2); }
.btn:active { transform: scale(0.96); }

.btn-ghost {
  background: var(--surface);
  color: var(--text-dim);
  border: 1px solid var(--surface2);
}
.btn-ghost:hover { background: var(--surface2); color: var(--text); }

.hint {
  font-size: 0.72rem;
  color: var(--text-dim);
  text-align: center;
}

/* ---- Board ---- */
#board-wrap {
  position: relative;
  width: calc(4 * var(--cell-size) + 5 * var(--gap));
  max-width: 420px;
}

#board {
  display: grid;
  grid-template-columns: repeat(4, var(--cell-size));
  grid-template-rows:    repeat(4, var(--cell-size));
  gap: var(--gap);
  padding: var(--gap);
  background: var(--surface);
  border-radius: 14px;
  position: relative;
}

/* background cells */
.cell {
  background: var(--surface2);
  border-radius: 8px;
  width:  var(--cell-size);
  height: var(--cell-size);
}

/* ---- Tiles ---- */
.tile {
  position: absolute;
  width:  var(--cell-size);
  height: var(--cell-size);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: clamp(1rem, 4vw, 1.8rem);
  user-select: none;
  will-change: transform, left, top;
  transition: left 0.12s ease, top 0.12s ease;
  /* positioned via JS using left/top */
}

/* pop-in animation for new tiles */
@keyframes pop-in {
  0%   { transform: scale(0);   opacity: 0; }
  60%  { transform: scale(1.12); opacity: 1; }
  100% { transform: scale(1);   opacity: 1; }
}
.tile-new { animation: pop-in 0.2s ease both; }

/* merge pulse */
@keyframes merge-pulse {
  0%   { transform: scale(1);    }
  40%  { transform: scale(1.18); }
  70%  { transform: scale(0.95); }
  100% { transform: scale(1);    }
}
.tile-merged { animation: merge-pulse 0.22s ease both; }

/* ---- Tile Colors ---- */
.tile-2    { background: #EEE4DA; color: #776E65; }
.tile-4    { background: #EDE0C8; color: #776E65; }
.tile-8    { background: #F2B179; color: #fff; }
.tile-16   { background: #F59563; color: #fff; }
.tile-32   { background: #F67C5F; color: #fff; }
.tile-64   { background: #F65E3B; color: #fff; }
.tile-128  { background: #EDCF72; color: #fff; font-size: clamp(0.85rem, 3.5vw, 1.5rem); }
.tile-256  { background: #EDCC61; color: #fff; font-size: clamp(0.85rem, 3.5vw, 1.5rem); }
.tile-512  { background: #9CCC30; color: #fff; font-size: clamp(0.85rem, 3.5vw, 1.5rem); }
.tile-1024 { background: #21A050; color: #fff; font-size: clamp(0.75rem, 3vw, 1.25rem); }
.tile-2048 {
  background: #FFD700;
  color: #7A4F00;
  font-size: clamp(0.75rem, 3vw, 1.25rem);
  box-shadow: 0 0 24px 6px rgba(255,215,0,0.65), 0 0 8px 2px rgba(255,140,0,0.5);
}
.tile-super {
  background: #3D2E6E;
  color: #E0C4FF;
  font-size: clamp(0.6rem, 2.5vw, 1rem);
  box-shadow: 0 0 20px 4px rgba(100,60,200,0.5);
}

/* ---- Score Popup ---- */
#score-popup-layer {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  overflow: hidden;
}

.score-popup {
  position: absolute;
  font-weight: 800;
  font-size: 1rem;
  color: #FFD700;
  text-shadow: 0 1px 4px rgba(0,0,0,0.7);
  pointer-events: none;
  animation: float-up 0.9s ease forwards;
}

@keyframes float-up {
  0%   { opacity: 1; transform: translateY(0)   scale(1); }
  70%  { opacity: 1; transform: translateY(-48px) scale(1.1); }
  100% { opacity: 0; transform: translateY(-72px) scale(0.8); }
}

/* ---- Overlays ---- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 17, 23, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
  animation: fade-in 0.25s ease;
}

.overlay.hidden { display: none; }

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

.overlay-box {
  background: var(--surface);
  border-radius: 18px;
  padding: 36px 32px;
  text-align: center;
  max-width: 320px;
  width: 90%;
  border: 1px solid var(--surface2);
  animation: slide-up 0.28s ease;
}

@keyframes slide-up {
  from { transform: translateY(24px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.overlay-emoji { font-size: 3rem; margin-bottom: 10px; }

.overlay-box h2 {
  font-size: 1.8rem;
  font-weight: 900;
  margin-bottom: 8px;
}

.overlay-box p {
  color: var(--text-dim);
  margin-bottom: 22px;
  font-size: 0.95rem;
}

.overlay-btns {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.overlay-btns .btn { flex: unset; min-width: 110px; }
