/* ==========================================================================
   2048 - adaptacion visual Readingg
   Motor original: 2048 de Gabriele Cirulli (MIT). Ver LICENSE.txt y README.md.
   Fondo, superficies, textos y controles usan los tokens --rg-* compartidos.
   Los colores de las fichas se conservan clasicos.
   ========================================================================== */

.rg-app.rg-2048 {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  gap: 14px;
  justify-content: center;
}

.rg-2048 .brand {
  min-width: 0;
}

.rg-2048 .rg-title {
  font-size: 28px;
  line-height: 1.05;
  letter-spacing: -0.04em;
}

.rg-2048 .rg-subtitle {
  margin-top: 3px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.rg-2048 .restart-button {
  flex: 0 0 auto;
  min-width: 136px;
  padding: 0 16px;
  border-color: var(--rg-primary-strong);
  background: linear-gradient(180deg, var(--rg-primary), var(--rg-primary-strong));
  box-shadow: 0 6px 16px rgba(76, 109, 240, 0.28);
}

.rg-2048 .rg-btn:focus-visible {
  outline: 2px solid var(--rg-accent);
  outline-offset: 2px;
}

/* --------------------------------------------------------------- marcador */

.scores-container {
  display: flex;
  flex-wrap: nowrap;
  gap: 10px;
}

.score-container,
.best-container {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  min-height: 54px;
  justify-content: space-between;
  gap: 8px;
  padding: 0 14px;
  border-radius: var(--rg-radius-sm);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--rg-muted);
}

.stat-value {
  overflow: hidden;
  color: var(--rg-text);
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score-addition {
  position: absolute;
  top: 8px;
  right: 14px;
  color: var(--rg-accent);
  font-size: 14px;
  font-weight: 800;
  pointer-events: none;
  animation: rg-score-up 700ms ease-out both;
}

@keyframes rg-score-up {
  from {
    opacity: 1;
    transform: translateY(0);
  }
  to {
    opacity: 0;
    transform: translateY(-24px);
  }
}

/* ---------------------------------------------------------------- tablero */

.game-container {
  --rg-gap: clamp(8px, 2.6vw, 12px);
  --rg-pad: clamp(8px, 2.6vw, 12px);
  --rg-cell: calc((100% - (3 * var(--rg-gap))) / 4);
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  padding: var(--rg-pad);
  border: 1px solid var(--rg-border);
  border-radius: var(--rg-radius);
  background: linear-gradient(180deg, var(--rg-surface), var(--rg-bg));
  box-shadow: var(--rg-shadow);
  overflow: hidden;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  cursor: default;
}

.grid-container {
  position: absolute;
  inset: var(--rg-pad);
}

.grid-row {
  display: flex;
  gap: var(--rg-gap);
}

.grid-row + .grid-row {
  margin-top: var(--rg-gap);
}

.grid-cell {
  flex: 1 1 0;
  min-width: 0;
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  background: var(--rg-surface-2);
  box-shadow: inset 0 0 0 1px var(--rg-border);
}

.tile-container {
  position: absolute;
  inset: var(--rg-pad);
  z-index: 2;
}

.tile {
  --rg-col: 0;
  --rg-row: 0;
  position: absolute;
  top: 0;
  left: 0;
  width: var(--rg-cell);
  height: var(--rg-cell);
  transform: translate(
    calc(var(--rg-col) * (100% + var(--rg-gap))),
    calc(var(--rg-row) * (100% + var(--rg-gap)))
  );
  transition: transform 110ms ease-in-out;
  will-change: transform;
}

.tile-position-1-1 { --rg-col: 0; --rg-row: 0; }
.tile-position-1-2 { --rg-col: 0; --rg-row: 1; }
.tile-position-1-3 { --rg-col: 0; --rg-row: 2; }
.tile-position-1-4 { --rg-col: 0; --rg-row: 3; }
.tile-position-2-1 { --rg-col: 1; --rg-row: 0; }
.tile-position-2-2 { --rg-col: 1; --rg-row: 1; }
.tile-position-2-3 { --rg-col: 1; --rg-row: 2; }
.tile-position-2-4 { --rg-col: 1; --rg-row: 3; }
.tile-position-3-1 { --rg-col: 2; --rg-row: 0; }
.tile-position-3-2 { --rg-col: 2; --rg-row: 1; }
.tile-position-3-3 { --rg-col: 2; --rg-row: 2; }
.tile-position-3-4 { --rg-col: 2; --rg-row: 3; }
.tile-position-4-1 { --rg-col: 3; --rg-row: 0; }
.tile-position-4-2 { --rg-col: 3; --rg-row: 1; }
.tile-position-4-3 { --rg-col: 3; --rg-row: 2; }
.tile-position-4-4 { --rg-col: 3; --rg-row: 3; }

.tile .tile-inner {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  border-radius: 10px;
  background: #eee4da;
  color: #776e65;
  font-size: clamp(24px, 9vw, 44px);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.03em;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.2);
  transition: background 120ms ease, color 120ms ease;
}

.tile.tile-2 .tile-inner { background: #eee4da; }
.tile.tile-4 .tile-inner { background: #ede0c8; }
.tile.tile-8 .tile-inner {
  background: #f2b179;
  color: #f9f6f2;
}
.tile.tile-16 .tile-inner {
  background: #f59563;
  color: #f9f6f2;
}
.tile.tile-32 .tile-inner {
  background: #f67c5f;
  color: #f9f6f2;
}
.tile.tile-64 .tile-inner {
  background: #f65e3b;
  color: #f9f6f2;
}
.tile.tile-128 .tile-inner {
  background: #edcf72;
  color: #f9f6f2;
  font-size: clamp(20px, 7.2vw, 36px);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.24);
}
.tile.tile-256 .tile-inner {
  background: #edcc61;
  color: #f9f6f2;
  font-size: clamp(20px, 7.2vw, 36px);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.28);
}
.tile.tile-512 .tile-inner {
  background: #edc850;
  color: #f9f6f2;
  font-size: clamp(20px, 7.2vw, 36px);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.32);
}
.tile.tile-1024 .tile-inner {
  background: #edc53f;
  color: #f9f6f2;
  font-size: clamp(15px, 5.4vw, 27px);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.34);
}
.tile.tile-2048 .tile-inner {
  background: #edc22e;
  color: #f9f6f2;
  font-size: clamp(15px, 5.4vw, 27px);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.38);
}
.tile.tile-super .tile-inner {
  background: #3c3a32;
  color: #f9f6f2;
  font-size: clamp(12px, 4.4vw, 22px);
}

/* ------------------------------------------------------------- animaciones */

@keyframes rg-appear {
  from {
    opacity: 0;
    transform: scale(0);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes rg-pop {
  0% { transform: scale(0); }
  50% { transform: scale(1.18); }
  100% { transform: scale(1); }
}

.tile-new .tile-inner {
  animation: rg-appear 200ms ease 100ms backwards;
}

.tile-merged .tile-inner {
  z-index: 20;
  animation: rg-pop 200ms ease 100ms backwards;
}

/* -------------------------------------------------------- fin / victoria */

.game-container .game-message {
  position: absolute;
  inset: 0;
  z-index: 100;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 22px;
  border-radius: inherit;
  background: rgba(9, 11, 17, 0.82);
  backdrop-filter: blur(6px);
  text-align: center;
  animation: rg-fade-in 220ms ease 300ms both;
}

.game-container .game-message.game-won,
.game-container .game-message.game-over {
  display: flex;
}

.game-container .game-message.game-won {
  background: rgba(237, 194, 46, 0.9);
  color: #14100a;
}

.game-container .game-message p {
  margin: 0;
  color: #ffffff;
  font-size: clamp(24px, 7.6vw, 34px);
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.03em;
}

.game-container .game-message.game-won p {
  color: #14100a;
}

.game-container .game-message .lower {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.game-container .game-message .rg-btn {
  min-width: 132px;
}

.game-container .game-message .keep-playing-button {
  display: none;
}

.game-container .game-message.game-won .keep-playing-button {
  display: inline-flex;
}

/* Al perder, "Reintentar" es la accion principal. */
.game-container .game-message.game-over .retry-button {
  border-color: var(--rg-primary);
  background: var(--rg-primary);
  color: #ffffff;
}

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

/* ----------------------------------------------------------------- ayuda */

.game-explanation {
  margin: 0;
  padding: 0 4px;
  color: var(--rg-muted);
  font-size: 12.5px;
  line-height: 1.5;
  text-align: center;
}

/* ------------------------------------------------------ pausa de la shell */

.rg-paused .tile,
.rg-paused .tile-inner,
.rg-paused .score-addition,
.rg-paused .game-message {
  animation-play-state: paused !important;
}

.rg-paused .tile {
  transition: none;
}

/* --------------------------------------------------------- modo compacto */

@media (max-width: 359px) {
  .rg-2048 .rg-title {
    font-size: 24px;
  }

  .rg-2048 .restart-button {
    min-width: 116px;
    padding: 0 12px;
    font-size: 13px;
  }

  .score-container,
  .best-container {
    min-height: 48px;
    padding: 0 10px;
  }

  .stat-value {
    font-size: 19px;
  }
}
