/* 2048 (js/games/game-2048.js). Kit styles: css/game.css.
 * Sizes come from the layout in JS: --cell, --gap, --step on .g2-board; --key, --kg on .g2-pad.
 * Tiles are puzzle art: toy-palette colours graded from pale blue (2) through mint and butter
 * to pink (2048), the same in both themes, numbers always #111 (AA on every tile). */

.g2-room {
  position: absolute; inset: 0; overflow: hidden; background: var(--surface-100);
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}

/* score and best above the board */
.g2-scores { position: absolute; display: flex; gap: var(--space-3); }
.g2-score {
  flex: 1; display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  padding: 0 var(--space-4); border-radius: var(--radius-md); background: var(--surface-200); border: 1px solid var(--line);
}
.g2-score-label { font-size: .85rem; color: var(--ink-muted); }
.g2-score-value { font: 600 1.3rem/1 var(--font-sans); font-variant-numeric: tabular-nums; color: var(--ink); }

/* the board: a dark tray with soft empty squares */
.g2-board {
  --cell: 80px; --gap: 10px; --step: 90px;
  position: absolute; border-radius: calc(var(--gap) * 1.6); background: #34302C;
  box-shadow: var(--shadow-card);
}
:root[data-theme="light"] .g2-board { background: #BDB6AA; }
.g2-cells {
  position: absolute; inset: 0; display: grid; padding: var(--gap); gap: var(--gap);
  grid-template-columns: repeat(var(--n, 4), 1fr); grid-template-rows: repeat(var(--n, 4), 1fr);
}
.g2-cell { border-radius: calc(var(--cell) * .12); background: rgba(255, 255, 255, .07); }
:root[data-theme="light"] .g2-cell { background: rgba(255, 255, 255, .38); }

.g2-tile {
  position: absolute; left: var(--gap); top: var(--gap); width: var(--cell); height: var(--cell); z-index: 2;
  transform: translate(calc(var(--c) * var(--step)), calc(var(--r) * var(--step)));
  transition: transform .11s ease-out;
}
.g2-tile.is-dying { z-index: 1; }
.g2-tile.is-joined { z-index: 3; }
.g2-num {
  display: grid; place-items: center; width: 100%; height: 100%; border-radius: calc(var(--cell) * .12);
  background: var(--bg, #EAF0FC); color: #111; box-shadow: 0 2px 0 rgba(0, 0, 0, .14), inset 0 -3px 0 rgba(0, 0, 0, .06);
  font: 600 calc(var(--cell) * .44)/1 var(--font-sans); font-variant-numeric: tabular-nums; letter-spacing: -.02em;
}
.g2-tile[data-len="3"] .g2-num { font-size: calc(var(--cell) * .36); }
.g2-tile[data-len="4"] .g2-num { font-size: calc(var(--cell) * .29); }
.g2-tile[data-len="5"] .g2-num { font-size: calc(var(--cell) * .24); }
.g2-tile[data-len="6"] .g2-num { font-size: calc(var(--cell) * .2); }
/* the goal tile and beyond: a soft glow */
.g2-tile[data-e="11"] .g2-num, .g2-tile[data-e="12"] .g2-num, .g2-tile[data-e="13"] .g2-num, .g2-tile[data-e="14"] .g2-num {
  box-shadow: 0 0 0 3px rgba(255, 255, 255, .55), 0 0 18px 2px var(--bg), 0 2px 0 rgba(0, 0, 0, .14);
}
.g2-tile.is-new .g2-num { animation: g2-appear .16s ease-out .09s backwards; }
.g2-tile.is-joined .g2-num { animation: g2-pop .2s ease-out .09s backwards; }
@keyframes g2-appear { 0% { transform: scale(.2); opacity: 0; } 100% { transform: none; opacity: 1; } }
@keyframes g2-pop { 0% { transform: scale(.6); opacity: 0; } 55% { transform: scale(1.1); opacity: 1; } 100% { transform: none; } }

/* a new move finishes the last one at once */
.g2-instant .g2-tile { transition: none; }
.g2-instant .g2-num { animation: none; }

/* nothing moved: a tiny shake */
.g2-board.is-nope { animation: g2-shake .32s ease; }
@keyframes g2-shake { 0%, 100% { translate: 0 0; } 25% { translate: -5px 0; } 50% { translate: 5px 0; } 75% { translate: -2px 0; } }

/* hint: a big soft arrow over the board, and the matching arrow button glows */
.g2-hint-arrow {
  position: absolute; inset: 0; z-index: 5; display: grid; place-items: center; pointer-events: none;
  opacity: 0; transition: opacity .25s ease;
}
.g2-hint-arrow.is-on { opacity: 1; }
.g2-hint-svg {
  width: 38%; height: 38%; padding: 6%; border-radius: 50%; background: var(--surface-200); box-shadow: var(--shadow-float);
  fill: none; stroke: var(--accent); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round;
}

/* arrow buttons: an inverted T, like a keyboard's arrow keys */
.g2-pad {
  --key: 60px; --kg: 8px;
  position: absolute; display: grid; gap: var(--kg);
  grid-template-columns: repeat(3, var(--key)); grid-template-rows: repeat(2, var(--key));
  grid-template-areas: ". up ." "left down right";
}
.g2-pad[hidden] { display: none; }
.g2-key {
  display: grid; place-items: center; width: var(--key); height: var(--key); padding: 0; margin: 0;
  border: 1.5px solid var(--line-strong); border-radius: var(--radius-md); background: var(--surface-200); color: var(--ink);
  cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent;
  transition: background-color .12s ease, transform .08s ease;
}
.g2-key .icon { width: 45%; height: 45%; stroke-width: 2.2; }
.g2-key:hover { background: var(--fill-strong); }
.g2-key:active { transform: scale(.95); background: var(--fill-strong); }
.g2-key:focus { outline: none; }
.g2-key:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 2px; }
.g2-key.is-hint { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent); }
.g2-key-up { grid-area: up; } .g2-key-left { grid-area: left; } .g2-key-down { grid-area: down; } .g2-key-right { grid-area: right; }

/* goal reached / no moves left: a calm card over the middle of the board (placed by the layout) */
.g2-panel {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 8;
  width: min(30rem, calc(100% - 24px)); display: flex; flex-direction: column; gap: var(--space-3);
  padding: var(--space-4) var(--space-5); border-radius: var(--radius-lg);
  background: var(--surface-200); border: 1.5px solid var(--accent); box-shadow: var(--shadow-float); color: var(--ink);
}
.g2-panel[hidden] { display: none; }
.g2-panel-text { margin: 0; font-size: .95rem; line-height: 1.4; }
.g2-panel-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.g2-panel .icon { width: 1.1rem; height: 1.1rem; }

@media (prefers-reduced-motion: reduce) {
  .g2-tile, .g2-key, .g2-hint-arrow { transition: none; }
  .g2-num, .g2-board.is-nope { animation: none !important; }
}
