.game-2048-stage {
  width: min(620px, 100%);
  margin: 0 auto;
  aspect-ratio: 1;
  position: relative;
}

.board-2048 {
  --move-distance: 7px;
  position: relative;
  isolation: isolate;
  contain: layout paint;
  width: 100%;
  height: 100%;
  padding: 14px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  overflow: hidden;
  border: 1px solid rgba(145, 190, 202, 0.22);
  border-radius: 26px;
  background:
    radial-gradient(circle at 50% -8%, rgba(104, 208, 223, .13), transparent 43%),
    radial-gradient(circle at 94% 90%, rgba(139, 207, 155, .055), transparent 36%),
    linear-gradient(145deg, #0a2028, #07151b 70%);
  box-shadow:
    inset 0 1px rgba(255, 255, 255, .055),
    inset 0 -1px rgba(0, 0, 0, .2),
    0 28px 58px rgba(0, 0, 0, .3);
  touch-action: none;
  transform: translateZ(0);
}

.board-2048::before {
  content: "";
  position: absolute;
  inset: -55%;
  z-index: -1;
  pointer-events: none;
  background: conic-gradient(from 0deg, transparent, rgba(104, 208, 223, .05), transparent 30%, rgba(242, 199, 92, .035), transparent 66%);
  animation: boardGlow 20s linear infinite;
}

.tile-2048 {
  position: relative;
  isolation: isolate;
  display: grid;
  place-items: center;
  min-width: 0;
  overflow: hidden;
  border: 1px solid rgba(145, 190, 202, .12);
  border-radius: 17px;
  color: rgba(245, 250, 251, .22);
  background: rgba(255, 255, 255, .035);
  box-shadow:
    inset 0 1px rgba(255, 255, 255, .05),
    inset 0 -1px rgba(0, 0, 0, .12);
  font-size: clamp(1.3rem, 5vw, 2.85rem);
  font-weight: 900;
  letter-spacing: -.045em;
  line-height: 1;
  transform: translateZ(0);
  transition:
    background .22s ease,
    border-color .22s ease,
    box-shadow .22s ease,
    filter .22s ease;
}

.tile-2048::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: linear-gradient(145deg, rgba(255, 255, 255, .2), transparent 38%, rgba(255, 255, 255, .025));
  opacity: .65;
}

.tile-2048.is-new { animation: tileSpawn .38s cubic-bezier(.16, 1.08, .28, 1) both; }
.tile-2048.is-merged { animation: tileMerge .46s cubic-bezier(.16, 1.14, .28, 1) both; z-index: 3; }
.tile-2048.is-merged::before {
  content: "";
  position: absolute;
  inset: -25%;
  z-index: -2;
  border: 2px solid rgba(255, 255, 255, .5);
  border-radius: 50%;
  animation: mergeRing .46s ease-out both;
}

.tile-2048[data-value="2"] { color: #0a171c; background: #c9f1f3; }
.tile-2048[data-value="4"] { color: #0a171c; background: #9de0e8; }
.tile-2048[data-value="8"] { color: #102019; background: #9bd8a8; }
.tile-2048[data-value="16"] { color: #261d08; background: #f4d47a; }
.tile-2048[data-value="32"] { color: #251309; background: #ef9e61; }
.tile-2048[data-value="64"] { color: #fff; background: #df6d67; }
.tile-2048[data-value="128"] { color: #071219; background: #79d8e4; box-shadow: 0 0 28px rgba(104, 208, 223, .22), inset 0 1px rgba(255, 255, 255, .28); }
.tile-2048[data-value="256"] { color: #071219; background: #63c7d9; box-shadow: 0 0 32px rgba(104, 208, 223, .3), inset 0 1px rgba(255, 255, 255, .28); }
.tile-2048[data-value="512"] { color: #102019; background: #7fc990; box-shadow: 0 0 34px rgba(139, 207, 155, .29), inset 0 1px rgba(255, 255, 255, .28); }
.tile-2048[data-value="1024"] { color: #241b08; background: #f2c75c; box-shadow: 0 0 36px rgba(242, 199, 92, .31), inset 0 1px rgba(255, 255, 255, .3); font-size: clamp(1rem, 4vw, 2.25rem); }
.tile-2048[data-value="2048"] { color: #fff; background: linear-gradient(145deg, #f0a14b, #d75f5c); box-shadow: 0 0 42px rgba(237, 139, 69, .4), inset 0 1px rgba(255, 255, 255, .28); font-size: clamp(1rem, 4vw, 2.25rem); }
.tile-2048[data-large="true"] { color: #fff; background: linear-gradient(145deg, #4f7fd2, #7959ba); font-size: clamp(.86rem, 3.4vw, 1.8rem); box-shadow: 0 0 42px rgba(111, 91, 190, .34), inset 0 1px rgba(255, 255, 255, .25); }

.board-2048.is-moving.move-left { animation: boardMoveLeft .18s cubic-bezier(.2, .75, .25, 1); }
.board-2048.is-moving.move-right { animation: boardMoveRight .18s cubic-bezier(.2, .75, .25, 1); }
.board-2048.is-moving.move-up { animation: boardMoveUp .18s cubic-bezier(.2, .75, .25, 1); }
.board-2048.is-moving.move-down { animation: boardMoveDown .18s cubic-bezier(.2, .75, .25, 1); }
.board-2048.is-moving .tile-2048:not([data-value="0"]) { filter: saturate(1.06) brightness(1.025); }

.board-2048.is-blocked.move-left { animation: blockedLeft .23s ease; }
.board-2048.is-blocked.move-right { animation: blockedRight .23s ease; }
.board-2048.is-blocked.move-up { animation: blockedUp .23s ease; }
.board-2048.is-blocked.move-down { animation: blockedDown .23s ease; }
.board-2048.is-undoing { animation: undoBoard .28s cubic-bezier(.2, .8, .2, 1); }

.score-chip { position: relative; overflow: visible; }
.score-chip strong.score-bump { animation: scoreBump .34s cubic-bezier(.2, .9, .24, 1); }
.score-gain {
  position: absolute;
  left: 50%;
  top: -4px;
  z-index: 3;
  pointer-events: none;
  color: #f4d47a;
  font-size: .78rem;
  font-weight: 800;
  white-space: nowrap;
  text-shadow: 0 4px 12px rgba(0, 0, 0, .35);
  animation: scoreGain .72s cubic-bezier(.2, .8, .2, 1) both;
}

.overlay-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 18px; }
.game-message:not(.hidden) > div { animation: messageIn .42s cubic-bezier(.2, .82, .2, 1) both; }
.game-message.hidden { display: none; }
.direction-pad { width: min(250px, 100%); margin: 20px auto 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.direction-pad button:nth-child(1) { grid-column: 2; }
.direction-pad button:nth-child(2) { grid-column: 1; }
.direction-pad button:nth-child(3) { grid-column: 2; }
.direction-pad button:nth-child(4) { grid-column: 3; }
.direction-pad .touch-button { transition: transform .16s ease, border-color .16s ease, background .16s ease, box-shadow .16s ease; }
.direction-pad .touch-button:active { transform: translateY(1px) scale(.94); }

@keyframes boardGlow { to { transform: rotate(360deg); } }
@keyframes tileSpawn { from { opacity: 0; transform: scale(.52) rotate(-4deg); } 68% { transform: scale(1.08) rotate(1deg); } to { opacity: 1; transform: scale(1) rotate(0); } }
@keyframes tileMerge { 0% { transform: scale(.82); } 48% { transform: scale(1.16); filter: brightness(1.12); } 100% { transform: scale(1); } }
@keyframes mergeRing { from { opacity: .65; transform: scale(.4); } to { opacity: 0; transform: scale(1.2); } }
@keyframes boardMoveLeft { 45% { transform: translateX(calc(var(--move-distance) * -1)); } }
@keyframes boardMoveRight { 45% { transform: translateX(var(--move-distance)); } }
@keyframes boardMoveUp { 45% { transform: translateY(calc(var(--move-distance) * -1)); } }
@keyframes boardMoveDown { 45% { transform: translateY(var(--move-distance)); } }
@keyframes blockedLeft { 35% { transform: translateX(-4px); } 70% { transform: translateX(2px); } }
@keyframes blockedRight { 35% { transform: translateX(4px); } 70% { transform: translateX(-2px); } }
@keyframes blockedUp { 35% { transform: translateY(-4px); } 70% { transform: translateY(2px); } }
@keyframes blockedDown { 35% { transform: translateY(4px); } 70% { transform: translateY(-2px); } }
@keyframes undoBoard { 45% { transform: scale(.985); filter: brightness(.94); } }
@keyframes scoreBump { 45% { transform: translateY(-2px) scale(1.12); } }
@keyframes scoreGain { from { opacity: 0; transform: translate(-50%, 8px) scale(.85); } 20% { opacity: 1; } to { opacity: 0; transform: translate(-50%, -23px) scale(1.08); } }
@keyframes messageIn { from { opacity: 0; transform: translateY(12px) scale(.97); } to { opacity: 1; transform: translateY(0) scale(1); } }

@media (hover: hover) and (pointer: fine) {
  .direction-pad .touch-button:hover { transform: translateY(-2px); box-shadow: 0 10px 20px rgba(0, 0, 0, .2); }
}

@media (max-width: 620px) {
  .board-2048 { --move-distance: 5px; padding: 9px; gap: 7px; border-radius: 19px; }
  .tile-2048 { border-radius: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .board-2048::before,
  .board-2048.is-moving,
  .board-2048.is-blocked,
  .board-2048.is-undoing,
  .tile-2048.is-new,
  .tile-2048.is-merged,
  .tile-2048.is-merged::before,
  .score-chip strong.score-bump,
  .score-gain,
  .game-message:not(.hidden) > div { animation: none; }

  .tile-2048,
  .direction-pad .touch-button { transition: none; }
}
