/* ─── Variables ─── */
:root {
  --color-game-bg: #fbf8ef;
  --color-board-bg: #bbada0;
  --color-cell-bg: #cdc1b4;
  --color-text-dark: #776e65;
  --color-text-light: #f9f6f2;
}

/* ─── Global Game Page ─── */
body.game-theme {
  background-color: var(--color-game-bg);
  color: var(--color-text-dark);
}

body.game-theme #site-header,
body.game-theme #site-footer {
  background: var(--color-game-bg);
  border-color: #d8d4d0;
  box-shadow: none;
}

body.game-theme .card {
  background: transparent;
  border-color: #d8d4d0;
}

body.game-theme .card-thumb {
  border-radius: 8px;
}

.game-page-wrapper {
  padding-bottom: 80px;
  min-height: 100vh;
}

.game-page {
  padding-top: 24px;
}

/* ─── Header ─── */
.game-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 20px;
  gap: 15px;
}

.game-header h1 {
  font-size: 64px;
  font-weight: bold;
  margin: 0;
  line-height: 1;
  color: #776e65;
  flex: 1;
}

.score-group {
  display: flex;
  gap: 10px;
}

.score-box {
  background: #bbada0;
  border-radius: 6px;
  padding: 10px 25px;
  min-width: 100px;
  text-align: center;
  color: #f9f6f2;
}

.score-label {
  display: block;
  font-size: 13px;
  text-transform: uppercase;
  font-weight: bold;
  color: #eee4da;
  margin-bottom: 2px;
}

.score-value {
  font-size: 25px;
  font-weight: bold;
  display: block;
}

.controls-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.game-tagline {
  font-size: 18px;
  font-weight: bold;
  color: #776e65;
  margin-top: 5px;
}

/* ─── Game Board ─── */
.game-arena {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 40px;
}

#game-board-wrapper {
  position: relative;
  width: min(100%, 500px);
  aspect-ratio: 1/1;
}

#game-board {
  position: relative;
  width: 100%;
  height: 100%;
  background: var(--color-board-bg);
  border-radius: 6px;
  padding: 15px;
  touch-action: none;
  user-select: none;
  box-sizing: border-box;
}

.board-bg {
  position: absolute;
  top: 15px;
  left: 15px;
  right: 15px;
  bottom: 15px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 15px;
}

.board-cell {
  background: var(--color-cell-bg);
  border-radius: 3px;
  width: 100%;
  height: 100%;
}

/* ─── Tiles ─── */
#tile-container {
  position: absolute;
  top: 15px;
  left: 15px;
  right: 15px;
  bottom: 15px;
  z-index: 2;
}

.tile {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 10;
  /* Smooth transform transition for movement */
  transition: transform 100ms cubic-bezier(0.4, 0, 0.2, 1);
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tile-inner {
  width: 100%;
  height: 100%;
  border-radius: 3px;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Clear Sans', 'Helvetica Neue', Arial, sans-serif;
  transition: background 150ms ease;
}

/* Original Color Palette (Applied to inner) */
.tile-inner[data-val="2"]    { background: #eee4da; color: #776e65; font-size: 55px; }
.tile-inner[data-val="4"]    { background: #ede0c8; color: #776e65; font-size: 55px; }
.tile-inner[data-val="8"]    { background: #f2b179; color: #f9f6f2; font-size: 55px; }
.tile-inner[data-val="16"]   { background: #f59563; color: #f9f6f2; font-size: 50px; }
.tile-inner[data-val="32"]   { background: #f67c5f; color: #f9f6f2; font-size: 50px; }
.tile-inner[data-val="64"]   { background: #f65e3b; color: #f9f6f2; font-size: 50px; }
.tile-inner[data-val="128"]  { background: #edcf72; color: #f9f6f2; font-size: 45px; box-shadow: 0 0 30px 10px rgba(243, 215, 116, 0.238), inset 0 0 1px 1px rgba(255, 255, 255, 0.14); }
.tile-inner[data-val="256"]  { background: #edcc61; color: #f9f6f2; font-size: 45px; box-shadow: 0 0 30px 10px rgba(243, 215, 116, 0.317), inset 0 0 1px 1px rgba(255, 255, 255, 0.19); }
.tile-inner[data-val="512"]  { background: #edc850; color: #f9f6f2; font-size: 45px; box-shadow: 0 0 30px 10px rgba(243, 215, 116, 0.397), inset 0 0 1px 1px rgba(255, 255, 255, 0.23); }
.tile-inner[data-val="1024"] { background: #edc53f; color: #f9f6f2; font-size: 35px; box-shadow: 0 0 30px 10px rgba(243, 215, 116, 0.476), inset 0 0 1px 1px rgba(255, 255, 255, 0.28); }
.tile-inner[data-val="2048"] { background: #edc22e; color: #f9f6f2; font-size: 35px; box-shadow: 0 0 30px 10px rgba(243, 215, 116, 0.556), inset 0 0 1px 1px rgba(255, 255, 255, 0.33); }

/* Animations (Applied to inner to avoid conflict with outer translation) */
.tile-new .tile-inner {
  animation: tile-appear 200ms cubic-bezier(0.4, 0, 0.2, 1) 50ms backwards;
}

.tile-merged .tile-inner {
  z-index: 20;
  animation: tile-pop 200ms cubic-bezier(0.4, 0, 0.2, 1) 100ms backwards;
}

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

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

/* ─── Overlays ─── */
#game-overlay {
  position: absolute;
  inset: 0;
  background: rgba(238, 228, 218, 0.73);
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 800ms ease;
  border-radius: 6px;
}

#game-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.overlay-title {
  font-size: 60px;
  font-weight: bold;
  color: #776e65;
  margin: 0;
}

.overlay-actions {
  display: flex;
  gap: 15px;
  margin-top: 20px;
}

/* ─── Bottom Area ─── */
.game-details {
  max-width: 500px;
  margin: 0 auto;
}

.details-grid {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.info-card {
  padding: 20px;
  background: #fbf8ef;
  border-top: 2px solid #d8d4d0;
}

.info-card-title {
  font-size: 18px;
  font-weight: bold;
  color: #776e65;
  margin-bottom: 15px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.how-steps {
  padding-left: 0;
  list-style: none;
  margin: 0;
}

.how-step {
  display: flex;
  gap: 15px;
  margin-bottom: 12px;
  align-items: center;
}

.step-num {
  background: #bbada0;
  color: white;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 14px;
  flex-shrink: 0;
}

.key-display {
  padding: 10px;
}

.key {
  background: #bbada0;
  color: white;
  padding: 5px 15px;
  border-radius: 4px;
  font-weight: bold;
  min-width: 30px;
  text-align: center;
}

.tile-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.swipe-hint {
  text-align: center;
  color: #776e65;
  font-weight: bold;
  margin-top: 15px;
  display: none;
}

/* ─── Responsive ─── */
@media (max-width: 600px) {
  .game-header {
    flex-direction: row;
    align-items: center;
    gap: 10px;
  }
  
  .game-header h1 {
    font-size: 48px;
  }

  .score-box {
    padding: 6px 10px;
    min-width: 70px;
  }
  
  .score-value {
    font-size: 18px;
  }
}

@media (max-width: 420px) {
  .game-header {
    flex-direction: column;
    align-items: stretch;
  }
  
  .score-group {
    justify-content: space-between;
  }

  .game-header h1 {
    font-size: 42px;
    text-align: center;
  }
  
  #game-board {
    padding: 8px;
  }
  
  .board-bg, #tile-container {
    top: 8px; left: 8px; right: 8px; bottom: 8px;
    gap: 8px;
  }
  
  /* Tile font sizes on mobile */
  .tile-inner[data-val="2"], .tile-inner[data-val="4"], .tile-inner[data-val="8"] { font-size: 32px; }
  .tile-inner[data-val="16"], .tile-inner[data-val="32"], .tile-inner[data-val="64"] { font-size: 28px; }
  .tile-inner[data-val="128"], .tile-inner[data-val="256"], .tile-inner[data-val="512"] { font-size: 24px; }
  .tile-inner[data-val="1024"], .tile-inner[data-val="2048"] { font-size: 18px; }
}

@media (pointer: coarse) {
  .swipe-hint { display: block; }
}

/* ─── SEO Section ─── */
.game-description {
  margin-top: 60px;
  padding: 35px;
  background: #fdfaf6;
  border: 1px solid #d8d4d0;
  border-radius: 12px;
  box-shadow: 0 4px 15px rgba(0,0,0,0.02);
}

.game-description h2 {
  font-size: 28px;
  color: #776e65;
  margin-bottom: 15px;
}

.game-description h3 {
  font-size: 22px;
  color: #776e65;
  margin-top: 30px;
  margin-bottom: 15px;
}

.game-description p {
  font-size: 16px;
  line-height: 1.7;
  color: #776e65;
  margin-bottom: 18px;
}

.tips-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.tips-list li {
  display: flex;
  align-items: flex-start;
  gap: 15px;
  margin-bottom: 15px;
  font-size: 15.5px;
  line-height: 1.6;
  background: #fbf8ef;
  padding: 18px;
  border-radius: 10px;
  border: 1px solid #ecdac6;
}

.tip-icon {
  font-size: 22px;
  flex-shrink: 0;
  margin-top: 2px;
}

/* ─── Related Games ─── */
.related-section {
  margin-top: 60px;
  padding-top: 40px;
  border-top: 1px solid #d8d4d0;
}
