
/* /css/2048.css */

:root {
  color-scheme: light;
  --page-bg: #faf8ef;
  --text: #776e65;
  --muted: #a3998c;
  --board-bg: #bbada0;
  --empty-cell: rgba(238, 228, 218, 0.35);
  --accent: #8f7a66;
  --gap: clamp(7px, 2.1vw, 12px);
  --radius: 7px;
}

button {
  font: inherit;
}

button:focus-visible {
  outline: 3px solid #edc22e;
  outline-offset: 3px;
}

.game-shell {
  width: min(100%, 500px);
  margin: 0 auto;
}

.game-header,
.game-toolbar,
.score-area,
.overlay-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.game-header {
  margin-bottom: 22px;
}

.brand h1 {
  margin: 0;
  font-size: clamp(54px, 13vw, 78px);
  line-height: 0.98;
  letter-spacing: -5px;
  font-weight: 850;
  color: #4C4541;
}

.subtitle {
  margin: 9px 0 0;
  font-size: 13px;
  font-weight: 550;
  color: var(--muted);
}

.score-area {
  align-self: flex-start;
  gap: 7px;
}

.score-card {
  min-width: 77px;
  padding: 10px 12px 9px;
  border-radius: 6px;
  background: #bbada0;
  text-align: center;
  color: white;
}

.score-label {
  display: block;
  margin-bottom: 3px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 750;
  color: #eee4da;
}

.score-card strong {
  display: block;
  font-size: clamp(18px, 4.5vw, 24px);
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.game-toolbar {
  margin-bottom: 17px;
}

.game-description {
  margin: 0;
  max-width: 260px;
  font-size: 13px;
  line-height: 1.5;
  color: #8b8177;
}

.btn {
  border: 0;
  border-radius: 6px;
  padding: 11px 15px;
  min-height: 43px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 750;
  transition: transform 120ms ease, filter 120ms ease;
  touch-action: manipulation;
}

.btn:hover {
  filter: brightness(1.06);
}

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

.btn-primary {
  background: #8f7a66;
  color: white;
}

.btn-secondary {
  background: #eee4da;
  color: #776e65;
}

#new-game {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

#new-game span {
  font-size: 19px;
  line-height: 1;
}

.game-section {
  width: 100%;
}

.game-board {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  padding: var(--gap);
  overflow: hidden;
  border-radius: 9px;
  background: var(--board-bg);
  isolation: isolate;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.board-cells,
.tile-layer {
  position: absolute;
  inset: var(--gap);
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-template-rows: repeat(4, minmax(0, 1fr));
  gap: var(--gap);
}

.board-cells {
  z-index: 0;
}

.board-cell {
  min-width: 0;
  min-height: 0;
  border-radius: var(--radius);
  background: var(--empty-cell);
}

.tile-layer {
  z-index: 1;
  pointer-events: none;
}

.tile {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border-radius: var(--radius);
  background: #eee4da;
  color: #776e65;
  font-size: clamp(22px, 7vw, 38px);
  font-weight: 800;
  letter-spacing: -1px;
  font-variant-numeric: tabular-nums;
  will-change: transform;
  transition:
    transform 105ms ease-in-out,
    background-color 120ms ease,
    color 120ms ease;
}

.tile.spawn {
  animation: tile-spawn 150ms cubic-bezier(.2, .8, .3, 1.3);
}

.tile.merge {
  animation: tile-merge 180ms cubic-bezier(.2, .8, .3, 1.4);
  z-index: 2;
}

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

@keyframes tile-merge {
  0% { transform: scale(0.88); }
  60% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

/* Classic 2048 palette */
.tile[data-value="2"] {
  background: #eee4da;
  color: #776e65;
}

.tile[data-value="4"] {
  background: #ede0c8;
  color: #776e65;
}

.tile[data-value="8"] {
  background: #f2b179;
  color: #fffaf2;
}

.tile[data-value="16"] {
  background: #f59563;
  color: #fffaf2;
}

.tile[data-value="32"] {
  background: #f67c5f;
  color: #fffaf2;
}

.tile[data-value="64"] {
  background: #f65e3b;
  color: #fffaf2;
}

.tile[data-value="128"] {
  background: #edcf72;
  color: #fffdf5;
  font-size: clamp(20px, 6vw, 32px);
  box-shadow: 0 0 14px rgba(237, 207, 114, 0.15);
}

.tile[data-value="256"] {
  background: #edcc61;
  color: #fffdf5;
  font-size: clamp(20px, 6vw, 32px);
}

.tile[data-value="512"] {
  background: #edc850;
  color: #fffdf5;
  font-size: clamp(20px, 6vw, 32px);
}

.tile[data-value="1024"] {
  background: #edc53f;
  color: #fffdf5;
  font-size: clamp(17px, 5vw, 27px);
}

.tile[data-value="2048"] {
  background: #edc22e;
  color: #fffdf5;
  font-size: clamp(17px, 5vw, 27px);
  box-shadow: 0 0 18px rgba(237, 194, 46, 0.35);
}

.tile.high-value {
  background: #3c3a32;
  color: #fffdf5;
  font-size: clamp(15px, 4.5vw, 25px);
}

.game-instructions {
  margin: 17px 0 20px;
    text-align: center;
    font-size: 12px;
    line-height: 2.1;
    color: #9b9185;
    display: flex;
    align-items: center;
    justify-content: center;
}

kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 23px;
  height: 23px;
  margin: 0 2px;
  padding: 0 5px;
  border: 1px solid #e3dbd0;
  border-radius: 4px;
  background: #fffdf7;
  color: #776e65;
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
}

.mobile-controls {
  display: none;
  width: fit-content;
  margin: 0 auto 24px;
  flex-direction: column;
  align-items: center;
  gap: 7px;
}

.direction-row {
  display: flex;
  gap: 7px;
}

.direction-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 60px;
  height: 54px;
  border: 1px solid #e3dbd0;
  border-radius: 9px;
  background: #fffdf7;
  color: #776e65;
  font-size: 27px;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 120ms ease, transform 120ms ease;
}

.direction-btn:hover {
  background: #f0e8dc;
}

.direction-btn:active {
  transform: scale(0.94);
  background: #e9dfd1;
}

.game-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  border-top: 1px solid #e8e0d5;
  padding-top: 15px;
}

.game-footer p {
  margin: 0;
  font-size: 11px;
  color: #b0a698;
}

.btn-text {
  border: 0;
  background: transparent;
  padding: 8px 0 8px 8px;
  color: #938779;
  font-size: 0.875rem;
  font-weight: 650;
  cursor: pointer;
}

.btn-text:hover {
  color: #776e65;
  text-decoration: underline;
}

.game-overlay {
  position: absolute;
  z-index: 5;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(250, 248, 239, 0.82);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: overlay-in 180ms ease-out;
}

.game-overlay.hidden,
.hidden {
  display: none !important;
}

.overlay-card {
  width: min(100%, 310px);
  padding: 24px 18px;
  border: 1px solid rgba(187, 173, 160, 0.3);
  border-radius: 12px;
  background: rgba(255, 253, 247, 0.96);
  text-align: center;
  box-shadow: 0 12px 38px rgba(90, 70, 45, 0.1);
}

.overlay-card h2 {
  margin: 0 0 8px;
  color: #776e65;
  font-size: clamp(27px, 7vw, 36px);
  letter-spacing: -1px;
}

.overlay-card p {
  margin: 0 0 20px;
  color: #918579;
  font-size: 13px;
  line-height: 1.6;
}

.overlay-actions {
  flex-wrap: wrap;
  justify-content: center;
}

@keyframes overlay-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@media (max-width: 420px) {
  body {
    padding: max(18px, env(safe-area-inset-top)) 13px
      max(20px, env(safe-area-inset-bottom));
  }

  .game-header {
    gap: 8px;
    margin-bottom: 19px;
  }

  .brand h1 {
    letter-spacing: -3.5px;
  }

  .subtitle {
    font-size: 11px;
  }

  .score-card {
    min-width: 66px;
    padding: 9px 8px;
  }

  .game-toolbar {
    align-items: center;
    gap: 8px;
  }

  .game-description {
    font-size: 12px;
  }

  #new-game {
    padding: 10px 11px;
    font-size: 12px;
  }

  .mobile-controls {
    display: flex;
  }

  .direction-btn {
    width: 64px;
    height: 54px;
  }

  .game-footer p {
    max-width: 150px;
    line-height: 1.5;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}