/* === 2048 GAME — CSS === */
:root {
  --bg: #faf8ef;
  --board-bg: #bbada0;
  --cell-bg: rgba(238, 228, 218, 0.35);
  --text-dark: #776e65;
  --text-light: #f9f6f2;
  --font: 'Nunito', sans-serif;
  --board-size: min(480px, calc(100vw - 32px));
  --cell-gap: 12px;
  --cell-size: calc((var(--board-size) - var(--cell-gap) * 5) / 4);
  --radius: 8px;
}

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

body {
  background: var(--bg);
  font-family: var(--font);
  color: var(--text-dark);
  display: flex;
  justify-content: center;
  min-height: 100vh;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  width: var(--board-size);
  max-width: 480px;
  padding: 16px 0;
}

/* Header */
header { margin-bottom: 16px; }

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

h1 {
  font-size: 64px;
  font-weight: 900;
  color: var(--text-dark);
  line-height: 1;
}

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

.score-box {
  background: var(--board-bg);
  color: var(--text-light);
  border-radius: 6px;
  padding: 8px 20px;
  text-align: center;
  min-width: 70px;
}

.score-label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  opacity: 0.7;
}

.score-value {
  display: block;
  font-size: 22px;
  font-weight: 900;
}

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

.tagline {
  font-size: 14px;
  color: #776e65;
}

.buttons { display: flex; gap: 6px; }

.buttons button {
  font-family: var(--font);
  font-size: 14px;
  font-weight: 700;
  padding: 8px 16px;
  background: #8f7a66;
  color: var(--text-light);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
}

.buttons button:hover { background: #9f8b77; }

#undo-btn {
  font-size: 18px;
  padding: 8px 12px;
}

/* Board */
#board-container { position: relative; }

#board {
  width: var(--board-size);
  height: var(--board-size);
  background: var(--board-bg);
  border-radius: 10px;
  padding: var(--cell-gap);
  position: relative;
  overflow: hidden;
}

.grid-bg {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--cell-gap);
  position: absolute;
  inset: var(--cell-gap);
}

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

#tile-container {
  position: absolute;
  inset: var(--cell-gap);
}

/* Tiles */
.tile {
  position: absolute;
  width: var(--cell-size);
  height: var(--cell-size);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 40px;
  transition: top 120ms ease, left 120ms ease;
  z-index: 1;
}

.tile.new {
  animation: appear 200ms ease;
}

.tile.merged {
  animation: pop 200ms ease;
  z-index: 2;
}

@keyframes appear {
  0% { transform: scale(0); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

/* Tile colors */
.tile-2    { background: #eee4da; color: var(--text-dark); }
.tile-4    { background: #ede0c8; color: var(--text-dark); }
.tile-8    { background: #f2b179; color: var(--text-light); }
.tile-16   { background: #f59563; color: var(--text-light); }
.tile-32   { background: #f67c5f; color: var(--text-light); }
.tile-64   { background: #f65e3b; color: var(--text-light); }
.tile-128  { background: #edcf72; color: var(--text-light); font-size: 36px; }
.tile-256  { background: #edcc61; color: var(--text-light); font-size: 36px; }
.tile-512  { background: #edc850; color: var(--text-light); font-size: 36px; }
.tile-1024 { background: #edc53f; color: var(--text-light); font-size: 28px; }
.tile-2048 { background: #edc22e; color: var(--text-light); font-size: 28px; }
.tile-super { background: #3c3a32; color: var(--text-light); font-size: 22px; }

/* 128+ glow */
.tile-128, .tile-256, .tile-512, .tile-1024, .tile-2048, .tile-super {
  box-shadow: 0 0 20px 6px rgba(243, 215, 116, 0.3);
}

/* Game message overlay */
#game-message {
  position: absolute;
  inset: 0;
  background: rgba(238, 228, 218, 0.7);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  z-index: 100;
  animation: fadeIn 300ms ease;
}

#game-message.hidden { display: none; }

#game-message.win { background: rgba(237, 194, 46, 0.5); }

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

#message-text {
  font-size: 48px;
  font-weight: 900;
  color: var(--text-dark);
  margin-bottom: 16px;
}

#message-btn {
  font-family: var(--font);
  font-size: 16px;
  font-weight: 700;
  padding: 12px 32px;
  background: #8f7a66;
  color: var(--text-light);
  border: none;
  border-radius: 6px;
  cursor: pointer;
}

#message-btn:hover { background: #9f8b77; }

/* Footer */
footer {
  margin-top: 16px;
  text-align: center;
  font-size: 13px;
  color: #9e9488;
  line-height: 1.8;
}

footer a { color: var(--text-dark); }

.credits { font-size: 11px; margin-top: 4px; }

/* Responsive */
@media (max-width: 520px) {
  :root {
    --cell-gap: 8px;
  }

  h1 { font-size: 48px; }

  .score-box { padding: 6px 14px; min-width: 60px; }
  .score-value { font-size: 18px; }
  .score-label { font-size: 9px; }

  .tile { font-size: 32px; }
  .tile-128, .tile-256, .tile-512 { font-size: 28px; }
  .tile-1024, .tile-2048 { font-size: 22px; }
  .tile-super { font-size: 18px; }

  .tagline { font-size: 12px; }
  .buttons button { font-size: 12px; padding: 6px 12px; }
}

@media (max-width: 380px) {
  h1 { font-size: 38px; }
  .tile { font-size: 26px; }
  .tile-128, .tile-256, .tile-512 { font-size: 22px; }
  .tile-1024, .tile-2048, .tile-super { font-size: 16px; }
}
