/* 2048. Functional layout before the design pass; existing tokens only (spec D1).
   Our own look, not the original's: the board is the cobalt swatch's deep tone in both themes,
   empty squares a lighter mix of it, and each tile value takes a poster swatch's light tone, then
   its field tone from 128 (board-view.js). All derived colors are listed for design review in
   docs/follow-ups.md. Tiles are placed with transforms from --x and --y and slide 100 ms (D6). */

.g-2048 { padding-block: var(--s3) var(--s7); }
.g-2048__intro { margin-bottom: var(--s3); }
.g-2048__intro h1 { font-size: 24px; }
.g-2048__intro p { margin-top: var(--s1); max-width: 60ch; }
.g-2048__note { margin-bottom: var(--s3); }

/* ---------- game card ---------- */
.g-2048__game { max-width: 520px; display: grid; gap: var(--s3); padding: var(--s3); }
@media (min-width: 400px) { .g-2048__game { padding: var(--s4); } }
.g-2048__game:focus { outline: none; }
.g-2048__bar { display: flex; flex-wrap: wrap; align-items: end; gap: var(--s2) var(--s4); }
.g-2048__bar .stat { min-width: 64px; }
.g-2048__chip { align-self: center; }
.g-2048__bar-actions { margin-left: auto; display: flex; gap: var(--s2); }
.g-2048__bar-actions .btn { touch-action: manipulation; }
.g-2048__tools { display: flex; justify-content: center; gap: var(--s2); }

/* ---------- board ---------- */
.g-2048__stage { position: relative; }
.g-2048__board {
  --gap: clamp(6px, 2.6cqi, 12px);
  container-type: inline-size; position: relative; width: 100%; aspect-ratio: 1;
  border-radius: 12px; background: var(--deep);
  /* D3: swipes on the board never scroll or pull to refresh. The board only; the page still zooms. */
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent; cursor: grab;
}
.g-2048__board:focus { outline: none; }
.g-2048__board:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }
.g-2048__cells {
  position: absolute; inset: 0; padding: var(--gap); gap: var(--gap);
  display: grid; grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(4, 1fr);
}
.g-2048__cells span { border-radius: 8px; background: color-mix(in srgb, var(--deep) 82%, #FFFFFF); }
.g-2048__tiles { position: absolute; inset: 0; }

.g-2048__tile {
  --tile: calc((100cqi - 5 * var(--gap)) / 4);
  position: absolute; left: var(--gap); top: var(--gap); width: var(--tile); height: var(--tile);
  transform: translate(calc(var(--x) * (100% + var(--gap))), calc(var(--y) * (100% + var(--gap))));
  transition: transform 100ms ease-in-out;
  display: grid; place-items: center; border-radius: 8px;
  font-weight: 800; font-stretch: 100%; line-height: 1; font-variant-numeric: tabular-nums;
  font-size: calc(var(--tile) * 0.48);
}
.g-2048__tile.is-light { background: var(--light); color: var(--deep); }
.g-2048__tile.is-field { background: var(--field); color: var(--on); }
.g-2048__tile.is-ink { background: var(--ink); color: var(--on-ink); }
.g-2048__tile.is-d3 { font-size: calc(var(--tile) * 0.4); }
.g-2048__tile.is-d4 { font-size: calc(var(--tile) * 0.34); font-stretch: 87.5%; }
.g-2048__tile.is-d5 { font-size: calc(var(--tile) * 0.28); font-stretch: 75%; }

/* D6: merged tiles pop, new tiles fade in (scale is its own property, so the transform keeps the place) */
.g-2048__tile.is-merged { z-index: 1; animation: g-2048-pop 160ms ease-out; }
.g-2048__tile.is-new { animation: g-2048-appear 140ms ease-out both; }
@keyframes g-2048-pop { 0% { scale: 1; } 45% { scale: 1.14; } 100% { scale: 1; } }
@keyframes g-2048-appear { from { opacity: 0; scale: 0.4; } to { opacity: 1; scale: 1; } }
/* Reduced motion: the device's preference unless the Animations setting says On (is-motion);
   the setting Off (is-still) always */
.g-2048__board.is-still .g-2048__tile { transition: none; animation: none; }
@media (prefers-reduced-motion: reduce) {
  .g-2048__board:not(.is-motion) .g-2048__tile { transition: none; animation: none; }
}

/* ---------- win and game-over panels, over the board ---------- */
.g-2048__panel { inset: 0; align-content: center; padding: var(--s5); }
.g-2048__panel[hidden] { display: none; }
.g-2048__over { justify-items: stretch; text-align: left; }
.g-2048__over .fig dd { font-size: 24px; }
.g-2048__over .figs { grid-template-columns: repeat(3, minmax(0, 1fr)); margin-top: var(--s3); }
.g-2048__over h2:focus { outline: none; }
.g-2048__over p { font-size: 15px; font-weight: 500; font-stretch: 100%; margin-top: var(--s3); }

/* ---------- dialogs ---------- */
.g-2048__dlg .fig dd { font-size: 22px; }
.g-2048__stats { grid-template-columns: repeat(3, minmax(0, 1fr)); margin-bottom: var(--s3); }
.g-2048__reset { margin-top: var(--s5); }
.g-2048__reset p { font-weight: 600; }
.g-2048__settings { display: grid; }
.g-2048__settings label { display: flex; align-items: center; gap: var(--s3); min-height: 44px; cursor: pointer; }
.g-2048__settings input { flex: none; width: 20px; height: 20px; accent-color: var(--ink); margin: 0; }
.g-2048__hint { display: block; font-size: 14px; }
.g-2048__choice { border: 0; padding: 0; margin: var(--s3) 0 0; }
.g-2048__choice legend { font-weight: 600; padding: 0; }

/* ---------- text below the game ---------- */
.g-2048__about { max-width: 62ch; margin-top: var(--s6); }
.g-2048__about h2 { margin: var(--s6) 0 var(--s3); }
.g-2048__about h2:first-child { margin-top: 0; }
.g-2048__about h3 { margin: var(--s5) 0 var(--s2); }
.g-2048__about ol { padding-left: 1.25em; margin: var(--s3) 0; }
.g-2048__about li + li { margin-top: 6px; }
.g-2048__keys { border-collapse: collapse; font-size: 15px; }
.g-2048__keys th, .g-2048__keys td { text-align: left; padding: 6px var(--s4) 6px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.g-2048__keys th { font-weight: 600; white-space: nowrap; }
