/* Reset and Base Styles */
:root {
  --bg-color: #faf8ef;
  --text-color: #776e65;
  --grid-bg: #bbada0;
  --tile-empty: #cdc1b4;
  --text-light: #f9f6f2;
  --primary-color: #8f7a66;
  --accent-color: #edc22e;
}

/* Dark Mode Override per requirements */
@media (prefers-color-scheme: dark) {
  :root {
    --bg-color: #1a1a2e;
    --text-color: #f9f6f2;
    --grid-bg: #bbada0; /* Keep grid same? Or darker? usually 2048 grid is specific color */
    /* Let's keep classic grid colors but change page bg */
  }
}

body {
  margin: 0;
  padding: 0;
  font-family: 'Clear Sans', 'Helvetica Neue', Arial, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-color);
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  overflow-x: hidden; /* Prevent horizontal scroll */
}

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

.header {
  display: flex;
  justify-content: space-between;
  width: 100%;
  margin-bottom: 20px;
}

.title-container h1 {
  font-size: 60px;
  font-weight: 700;
  margin: 0;
  line-height: 1;
}

.subtitle {
  margin: 5px 0 0;
  font-size: 16px;
}

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

.score-box {
  background: var(--grid-bg);
  padding: 10px 20px;
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 60px;
  color: var(--text-light);
}

.score-label {
  font-size: 12px;
  font-weight: bold;
  opacity: 0.7;
  text-transform: uppercase;
}

#score-value, #best-value {
  font-size: 24px;
  font-weight: bold;
}

.controls {
  width: 100%;
  display: flex;
  justify-content: space-between; /* Spread buttons */
  margin-bottom: 20px;
}

.btn {
  background: var(--primary-color);
  color: var(--text-light);
  border: none;
  border-radius: 6px;
  padding: 10px 20px;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  transition: transform 0.1s, background 0.2s;
}

.btn:hover {
  background: #7f6a56; /* Darker shade */
}

.btn:active {
  transform: scale(0.96);
}

.btn.secondary {
  background: #e67e22; /* Orange for undo? Or similar to game style */
}

.game-container {
  width: 100%;
  /* Height will be set by JS via canvas but let's constrain aspect ratio? */
  position: relative;
  background: var(--grid-bg);
  border-radius: 10px;
  /* padding is handled inside canvas usually, but container background shows through gaps */
  box-shadow: 0 10px 30px rgba(0,0,0,0.3);
  touch-action: none; /* Prevent browser handling gestures */
}

canvas {
  display: block;
  width: 100%;
  height: auto; /* Maintain aspect ratio */
  border-radius: 10px;
}

.game-message {
  display: none;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(238, 228, 218, 0.73);
  z-index: 100;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  border-radius: 10px;
  opacity: 0;
  transition: opacity 0.5s;
}

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

.game-message.game-over {
  background: rgba(238, 228, 218, 0.73);
  color: #776e65;
}

/* Dark mode overlay */
@media (prefers-color-scheme: dark) {
  .game-message {
    background: rgba(30, 30, 40, 0.8);
    color: #f9f6f2;
  }
}

.game-message.show {
  display: flex;
  opacity: 1; /* Fade in */
  animation: fade-in 800ms ease 100ms;
  animation-fill-mode: both;
}

.game-message p {
  font-size: 60px;
  font-weight: bold;
  margin: 0 0 20px;
}

.instructions {
  margin-top: 30px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-color);
  opacity: 0.8;
}

@keyframes fade-in {
  0% { opacity: 0; }
  100% { opacity: 1; }
}

/* Responsive adjustments */
@media (max-width: 500px) {
  .title-container h1 {
    font-size: 40px;
  }
  .score-box {
    padding: 5px 10px;
    min-width: 40px;
  }
  #score-value, #best-value {
    font-size: 18px;
  }
}
