/* Game-specific tokens (shared tokens from design-tokens.css) */
:root {
  --grid-bg: #141414;
  --cell-bg: #1e1e1e;
}

[data-theme="light"] {
  --grid-bg: #cdc1b4;
  --cell-bg: #d6ccc0;
}

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

body {
  font-family: var(--font-main);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: center;
}

#app {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 20px;
  width: 100%;
  max-width: 500px;
}


/* ===== Header ===== */
.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
}

.game-title {
  font-size: 2.4rem;
  font-weight: 800;
  color: var(--color-primary);
}

.score-box {
  display: flex;
  gap: 8px;
}

.score-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 6px 14px;
  text-align: center;
  min-width: 70px;
}

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

.score-value {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-primary);
}

/* ===== Grid ===== */
.grid-container {
  position: relative;
  background: var(--grid-bg);
  border-radius: var(--radius);
  padding: 10px;
  width: 100%;
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

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

.tile {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  font-weight: 800;
  transition: top 0.12s ease, left 0.12s ease;
  z-index: 1;
}

.tile.new {
  animation: tileAppear 0.2s ease;
}

.tile.merged {
  animation: tileMerge 0.2s ease;
  z-index: 2;
}

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

@keyframes tileMerge {
  0% { transform: scale(1); }
  50% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

/* Tile colors — neon gradient progression */
.tile-2    { background: #1e1e1e; color: #ff2d7b; }
.tile-4    { background: #2a1a24; color: #ff4d8f; }
.tile-8    { background: #4a2800; color: #ffb800; }
.tile-16   { background: #5a3000; color: #ffc830; }
.tile-32   { background: #6a3500; color: #ff9100; }
.tile-64   { background: #6a1530; color: #ff2d7b; }
.tile-128  { background: #8b1a4a; color: #ff5ca0; font-size: 0.85em; }
.tile-256  { background: #a01a5c; color: #ff7ab8; font-size: 0.85em; }
.tile-512  { background: #0a4a0a; color: #39ff14; font-size: 0.85em; }
.tile-1024 { background: #2a0a4a; color: #bf5af2; font-size: 0.75em; }
.tile-2048 { background: #1a3a1a; color: #39ff14; font-size: 0.75em; border: 1px solid #39ff14; }
.tile-super { background: #1a1a1a; color: #bf5af2; font-size: 0.65em; border: 1px solid #bf5af2; }

/* ===== Controls ===== */
.controls {
  display: flex;
  gap: 8px;
}

/* ===== Overlay ===== */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: rgba(0, 0, 0, 0.6);
  border-radius: var(--radius);
  z-index: 10;
  animation: fadeIn 0.3s ease;
}

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

.overlay h2 {
  font-size: 2rem;
  font-weight: 800;
}

.overlay .final-score {
  font-size: 1.2rem;
  color: var(--text-secondary);
}

/* ===== Cinematic Game Over ===== */
.overlay-cinematic {
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(6px);
  gap: 12px;
}

.final-score-animated {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.final-score-number {
  font-size: 2.4rem;
  font-weight: 800;
  color: var(--color-warning);
}

.final-highscore {
  font-size: 0.85rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.new-record-badge {
  display: inline-block;
  padding: 2px 8px;
  background: var(--color-warning);
  color: #0a0a0a;
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  border-radius: var(--radius);
}

.rank-badge {
  display: flex;
  align-items: baseline;
  gap: 6px;
  animation: rankReveal 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes rankReveal {
  from { transform: scale(0); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.rank-position {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--color-warning);
}

.rank-label {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ===== Landing ===== */
.landing {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding-top: 40px;
}

.landing h1 {
  font-size: 3rem;
  font-weight: 800;
  color: var(--color-primary);
}

.landing p {
  color: var(--text-secondary);
  max-width: 340px;
  line-height: 1.5;
}

.instructions {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 16px 20px;
  text-align: left;
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

/* ===== Mobile D-pad ===== */
.dpad {
  display: none;
  grid-template-columns: repeat(3, 56px);
  grid-template-rows: repeat(3, 56px);
  gap: 4px;
  margin-top: 8px;
}

.dpad-btn {
  width: 56px;
  height: 56px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.dpad-btn:active { background: var(--bg-tertiary); }
.dpad-spacer { visibility: hidden; }

@media (max-width: 600px) {
  .dpad { display: grid; }
}

@media (max-width: 400px) {
  .game-title { font-size: 1.8rem; }
  .grid-container { padding: 8px; gap: 8px; }
}
