:root {
  --bg-color: #faf8ef;
  --text-dark: #776e65;
  --text-light: #f9f6f2;
  --grid-bg: #bbada0;
  --cell-empty: rgba(238, 228, 218, 0.35);
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

body {
  background-color: var(--bg-color);
  color: var(--text-dark);
  font-family: var(--font-family);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 16px;
}

.container {
  width: 100%;
  max-width: 440px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.top-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.back-link {
  color: var(--text-dark);
  text-decoration: none;
  font-weight: 700;
  font-size: 0.9rem;
  display: inline-flex;
  align-items: center;
  transition: opacity 0.2s;
}

.back-link:hover {
  opacity: 0.7;
}

h1 {
  font-size: 3rem;
  font-weight: 900;
  line-height: 1;
  color: #776e65;
}

.subtitle {
  font-size: 0.85rem;
  color: #8f7a66;
}

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

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

.score-label {
  font-size: 0.7rem;
  font-weight: 700;
  color: #eee4da;
  letter-spacing: 0.05em;
}

.score-value {
  font-size: 1.25rem;
  font-weight: 800;
}

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

.btn {
  background-color: #8f7a66;
  color: var(--text-light);
  border: none;
  padding: 10px 18px;
  font-size: 0.95rem;
  font-weight: 700;
  border-radius: 6px;
  cursor: pointer;
  transition: background-color 0.2s;
}

.btn:hover {
  background-color: #7f6a56;
}

.tip-text {
  font-size: 0.85rem;
  color: #8f7a66;
  font-weight: 600;
}

.game-container {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  background-color: var(--grid-bg);
  border-radius: 8px;
  padding: 12px;
}

.grid-container {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 12px;
  width: 100%;
  height: 100%;
}

.cell {
  background-color: var(--cell-empty);
  border-radius: 6px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-weight: 800;
  font-size: 2rem;
  transition: transform 0.1s ease-in-out;
}

.tile-2 { background-color: #eee4da; color: #776e65; }
.tile-4 { background-color: #ede0c8; color: #776e65; }
.tile-8 { background-color: #f2b179; color: #f9f6f2; }
.tile-16 { background-color: #f59563; color: #f9f6f2; }
.tile-32 { background-color: #f67c5f; color: #f9f6f2; }
.tile-64 { background-color: #f65e3b; color: #f9f6f2; }
.tile-128 { background-color: #edcf72; color: #f9f6f2; font-size: 1.6rem; box-shadow: 0 0 10px rgba(243, 215, 116, 0.4); }
.tile-256 { background-color: #edcc61; color: #f9f6f2; font-size: 1.6rem; box-shadow: 0 0 12px rgba(243, 215, 116, 0.5); }
.tile-512 { background-color: #edc850; color: #f9f6f2; font-size: 1.6rem; box-shadow: 0 0 15px rgba(243, 215, 116, 0.6); }
.tile-1024 { background-color: #edc53f; color: #f9f6f2; font-size: 1.3rem; box-shadow: 0 0 20px rgba(243, 215, 116, 0.7); }
.tile-2048 { background-color: #edc22e; color: #f9f6f2; font-size: 1.3rem; box-shadow: 0 0 25px rgba(243, 215, 116, 0.8); }
.tile-super { background-color: #3c3a32; color: #f9f6f2; font-size: 1.1rem; }

.pop {
  animation: popIn 0.15s ease;
}

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

.game-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(238, 228, 218, 0.85);
  border-radius: 8px;
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 16px;
  animation: fadeIn 0.3s ease;
}

.game-overlay.active {
  display: flex;
}

.game-overlay p {
  font-size: 2.2rem;
  font-weight: 800;
  color: #776e65;
}

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