/* 2048 — scoped under .g2048 */
.g2048 {
  --gap: clamp(8px, 2.4vw, 12px);
  --board: #CDD3E3;
  --cell: #DFE3EE;
  --size: min(100%, calc(100svh - 230px));
  display: grid; gap: 14px;
  width: 100%; max-width: 500px; margin-inline: auto;
}
:root[data-theme="dark"] .g2048 { --board: #1E2244; --cell: #2A2F56; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .g2048 { --board: #1E2244; --cell: #2A2F56; }
}

.g2048-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.g2048-actions { display: flex; align-items: center; gap: 4px; }

.g2048-board {
  position: relative;
  width: 100%;
  max-width: max(280px, calc(100svh - 240px));
  margin-inline: auto;
  aspect-ratio: 1;
  padding: var(--gap);
  border-radius: var(--r-lg);
  background: var(--board);
  touch-action: none;
  user-select: none; -webkit-user-select: none;
  outline: none;
}
.g2048-board:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }

.g2048-cells, .g2048-tiles {
  position: absolute; inset: var(--gap);
}
.g2048-cells { display: grid; grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(4, 1fr); gap: var(--gap); }
.g2048-cells span { border-radius: calc(var(--r-md) - 2px); background: var(--cell); }

.g2048-tile {
  position: absolute; left: 0; top: 0;
  width: calc((100% - 3 * var(--gap)) / 4);
  height: calc((100% - 3 * var(--gap)) / 4);
  transform: translate(calc(var(--x) * (100% + var(--gap))), calc(var(--y) * (100% + var(--gap))));
  transition: transform 110ms ease-out;
  z-index: 2;
}
.g2048-tile.is-gone { z-index: 1; }
.g2048-tile > span {
  display: grid; place-items: center;
  width: 100%; height: 100%;
  border-radius: calc(var(--r-md) - 2px);
  font-weight: 760; letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
  font-size: clamp(1.5rem, 9vw, 2.75rem);
  background: var(--t-bg); color: var(--t-ink);
  line-height: 1;
}
.g2048-tile[data-d="3"] > span { font-size: clamp(1.25rem, 7.4vw, 2.3rem); }
.g2048-tile[data-d="4"] > span { font-size: clamp(1rem, 5.8vw, 1.85rem); }
.g2048-tile[data-d="5"] > span { font-size: clamp(0.85rem, 4.6vw, 1.5rem); }

.g2048-tile.is-new > span { animation: g2048-in 160ms ease-out 90ms backwards; }
.g2048-tile.is-pop > span { animation: g2048-pop 180ms ease-out 100ms; }
@keyframes g2048-in { from { transform: scale(0.2); opacity: 0; } }
@keyframes g2048-pop { 50% { transform: scale(1.14); } }

/* Tile colours: a warm ramp, so even the 2 and 4 stand clear of the grey-blue empty cells. */
.g2048-tile { --t-bg: #FFFFFF; --t-ink: #1A1D3A; }
.g2048-tile[data-v="4"]    { --t-bg: #FFE6B0; }
.g2048-tile[data-v="8"]    { --t-bg: #FFC75A; }
.g2048-tile[data-v="16"]   { --t-bg: #FFA03C; }
.g2048-tile[data-v="32"]   { --t-bg: #FF7A3D; }
.g2048-tile[data-v="64"]   { --t-bg: #E5484D; --t-ink: #fff; }
.g2048-tile[data-v="128"]  { --t-bg: #1FA97A; --t-ink: #fff; }
.g2048-tile[data-v="256"]  { --t-bg: #13805B; --t-ink: #fff; }
.g2048-tile[data-v="512"]  { --t-bg: #2F5BEA; --t-ink: #fff; }
.g2048-tile[data-v="1024"] { --t-bg: #1F3FB0; --t-ink: #fff; }
.g2048-tile[data-v="2048"] { --t-bg: #1A1D3A; --t-ink: #FFD36B; }
.g2048-tile.is-super       { --t-bg: #7A3FE0; --t-ink: #fff; }
.g2048-tile > span { box-shadow: 0 3px 0 rgb(26 29 58 / .12), 0 8px 16px -10px rgb(26 29 58 / .45); }

/* Dark mode: the tiles keep their colours, only the 2048 tile flips so it doesn't vanish into the board. */
:root[data-theme="dark"] .g2048-tile[data-v="2048"] { --t-bg: #F2B630; --t-ink: #1A1D3A; }
:root[data-theme="dark"] .g2048-tile > span { box-shadow: 0 3px 0 rgb(0 0 0 / .3); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .g2048-tile[data-v="2048"] { --t-bg: #F2B630; --t-ink: #1A1D3A; }
  :root:not([data-theme="light"]) .g2048-tile > span { box-shadow: 0 3px 0 rgb(0 0 0 / .3); }
}

.g2048-hint { text-align: center; color: var(--muted); font-size: var(--t-sm); }
.g2048 .k-overlay { border-radius: var(--r-lg); }

/* The score boxes already show the best score, so hide the duplicate in the top bar. */
body[data-game="2048"] .gamebar-stat { display: none; }

@media (max-width: 340px) {
  .g2048-top { flex-wrap: wrap; justify-content: center; gap: 8px; }
}
