/* Colorines — juegos (#juegos, #juegos/colores, #juegos/numeros, #juegos/letras, #juegos/memoria). Todo bajo .screen--juegos. */

.screen--juegos {
  background:
    radial-gradient(110% 70% at 50% 0%, #fffaf0 0%, rgba(255, 250, 240, 0) 60%),
    radial-gradient(90% 70% at 0% 100%, #d9f3ff 0%, rgba(217, 243, 255, 0) 70%),
    var(--bg);
}
.screen--juegos .jg-bar { position: relative; z-index: 1; }
.screen--juegos .jg-title {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-size: 1.55rem;
  font-weight: 700;
  white-space: nowrap;
}
.screen--juegos .jg-title .icon { width: 46px; height: 46px; flex: 0 0 auto; }
@media (max-width: 420px) {
  .screen--juegos .jg-home { display: none; }
  .screen--juegos .jg-title { font-size: 1.3rem; }
}

/* ---------- Menú: cuatro tarjetas grandes (2 × 2; en una pantalla muy ancha, en fila; muy alta, en columna) ---------- */
.screen--juegos .jg-menu {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 4px clamp(10px, 3vmin, 28px) clamp(14px, 4vmin, 32px);
  container-type: size;
}
.screen--juegos .jg-menu-in {
  --g: clamp(12px, 3.5cqmin, 36px);
  --nc: 2;
  --nr: 2;
  --cw: min(calc((100cqw - (var(--nc) - 1) * var(--g)) / var(--nc)), calc((100cqh - (var(--nr) - 1) * var(--g)) / var(--nr) * 1.15), 440px);
  --ch: min(calc((100cqh - (var(--nr) - 1) * var(--g)) / var(--nr)), calc(var(--cw) * 1.02));
  display: grid;
  grid-template-columns: repeat(var(--nc), var(--cw));
  grid-template-rows: repeat(var(--nr), var(--ch));
  gap: var(--g);
}
@container (min-aspect-ratio: 9 / 4) { .screen--juegos .jg-menu-in { --nc: 4; --nr: 1; } }
@container (max-aspect-ratio: 1 / 2) { .screen--juegos .jg-menu-in { --nc: 1; --nr: 4; } }
.screen--juegos .jg-card {
  --c1: #ffe07a;
  --c2: #ffb938;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3%;
  min-width: 0;
  min-height: 0;
  padding: 7% 6% 6%;
  border: 4px solid var(--ink);
  border-radius: 32px;
  background:
    radial-gradient(circle at 22% 18%, rgba(255, 255, 255, 0.55) 0 14%, rgba(255, 255, 255, 0) 45%),
    radial-gradient(rgba(255, 255, 255, 0.22) 18%, transparent 20%) 0 0 / 26px 26px,
    linear-gradient(160deg, var(--c1), var(--c2));
  box-shadow: 0 7px 0 rgba(43, 34, 64, 0.22), 0 14px 26px rgba(43, 34, 64, 0.14);
  cursor: pointer;
  outline: none;
  overflow: hidden;
  touch-action: manipulation;
  transition: transform 0.14s ease, box-shadow 0.14s ease;
  animation: jg-pop 0.5s cubic-bezier(0.2, 1.5, 0.4, 1) backwards;
}
.screen--juegos .jg-card--colores { --c1: #ffd0e6; --c2: #ff8fc2; }
.screen--juegos .jg-card--numeros { --c1: #c9f5c1; --c2: #6fd88f; }
.screen--juegos .jg-card--letras { --c1: #d6e6ff; --c2: #8fb6ff; }
.screen--juegos .jg-card--memoria { --c1: #fff0b0; --c2: #ffc23d; }
.screen--juegos .jg-card:active { transform: translateY(5px) scale(0.97); box-shadow: 0 2px 0 rgba(43, 34, 64, 0.22); }
.screen--juegos .jg-card:focus-visible { box-shadow: 0 0 0 5px var(--blue), 0 7px 0 rgba(43, 34, 64, 0.22); }
@media (hover: hover) { .screen--juegos .jg-card:hover { transform: translateY(-4px) rotate(-1deg); } }
.screen--juegos .jg-art { flex: 1 1 auto; width: 100%; min-height: 0; }
.screen--juegos .jg-card-label {
  flex: 0 0 auto;
  padding: 0.18em 0.9em 0.22em;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 3px 0 rgba(43, 34, 64, 0.16);
  font-size: clamp(18px, 4.2vmin, 30px);
  font-weight: 600;
  line-height: 1.1;
}

/* ---------- Grillas de los juegos: entran enteras, sin scroll ---------- */
.screen--juegos .jg-grid {
  --cols: 3;
  --rows: 4;
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  grid-template-rows: repeat(var(--rows), minmax(0, 1fr));
  gap: clamp(8px, 2vmin, 18px);
  padding: 2px clamp(10px, 2.5vmin, 24px) clamp(12px, 3vmin, 26px);
}
@media (min-aspect-ratio: 1 / 1) { .screen--juegos .jg-grid { --cols: 4; --rows: 3; } }
@media (min-aspect-ratio: 16 / 9) { .screen--juegos .jg-grid { --cols: 6; --rows: 2; } }
/* Celular parado: en 3 columnas las diez cosas del 10 quedan diminutas; mejor 2 columnas que se deslizan. */
@media (orientation: portrait) and (max-width: 520px) {
  .screen--juegos .jg-nums { --cols: 2; grid-template-rows: none; grid-auto-rows: 150px; }
}

/* Colores: gotita con carita + nombre */
.screen--juegos .jg-color {
  container-type: size;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3cqh;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  outline: none;
  touch-action: manipulation;
}
.screen--juegos .jg-drop {
  width: min(78cqw, 68cqh);
  height: min(78cqw, 68cqh);
  flex: 0 0 auto;
  overflow: visible;
  filter: drop-shadow(0 5px 0 rgba(43, 34, 64, 0.18));
  transform-origin: 50% 90%;
  transition: transform 0.12s ease;
}
.screen--juegos .jg-name {
  padding: 0.14em 0.6em 0.2em;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 3px 0 rgba(43, 34, 64, 0.14);
  font-size: min(12.5cqh, 12.5cqw);
  font-weight: 700;
  letter-spacing: 0.05em;
  line-height: 1.05;
  white-space: nowrap;
}
.screen--juegos .jg-color:active .jg-drop { transform: scale(0.92); }
.screen--juegos .jg-color:focus-visible .jg-name { box-shadow: 0 0 0 4px var(--blue); }
.screen--juegos .jg-color.jg-talk .jg-drop { animation: jg-jelly 0.65s ease; }
.screen--juegos .jg-color.jg-talk .jg-name { animation: jg-name 0.65s ease; }

/* Números: tarjeta con el número grande y las cosas para contar */
.screen--juegos .jg-num {
  container-type: size;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2cqh;
  min-width: 0;
  min-height: 0;
  padding: 10px 8px;
  border: 4px solid var(--ink);
  border-radius: 24px;
  background: #fff;
  box-shadow: 0 6px 0 rgba(43, 34, 64, 0.2);
  cursor: pointer;
  outline: none;
  touch-action: manipulation;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.screen--juegos .jg-num:active { transform: translateY(4px) scale(0.97); box-shadow: 0 2px 0 rgba(43, 34, 64, 0.2); }
.screen--juegos .jg-num:focus-visible { box-shadow: 0 0 0 4px var(--blue), 0 6px 0 rgba(43, 34, 64, 0.2); }
.screen--juegos .jg-digit {
  font-size: min(36cqh, 46cqw);
  font-weight: 700;
  line-height: 0.95;
  color: var(--c);
  -webkit-text-stroke: 0.05em var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 0.06em 0 rgba(43, 34, 64, 0.2);
}
.screen--juegos .jg-tray {
  /* Lado de cada cosa: que entren --per por fila y --rows filas; el ancho máximo fuerza --per por fila. */
  --s: min(calc(92cqw / var(--per) - 2.5cqw), calc(50cqh / var(--rows) - 2cqh), 44cqw);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-content: center;
  gap: 2cqh 2.5cqw;
  width: 100%;
  max-width: calc(var(--per) * (var(--s) + 2.5cqw));
  height: 52cqh;
}
.screen--juegos .jg-item {
  width: var(--s);
  height: var(--s);
  flex: 0 0 auto;
}
.screen--juegos .jg-empty {
  width: min(56cqw, 60cqh);
  height: min(28cqw, 30cqh);
  align-self: center;
  border: 4px dashed rgba(43, 34, 64, 0.28);
  border-radius: 50%;
}
.screen--juegos .jg-num.jg-talk .jg-digit { animation: jg-name 0.6s ease; }
.screen--juegos .jg-num.jg-talk .jg-item { animation: jg-count 0.45s calc(var(--k) * 0.14s) cubic-bezier(0.2, 1.6, 0.4, 1) both; }
.screen--juegos .jg-num.jg-talk .jg-empty { animation: jg-name 0.6s ease; }

/* Interruptor de opciones (Letras: Mayúsculas | Minúsculas; Memoria: 8 | 12 | 16): una burbuja que se desliza
   hasta la opción elegida. --n opciones, --i la elegida. */
.screen--juegos .jg-switch-row {
  flex: 0 0 auto;
  display: flex;
  justify-content: center;
  padding: 0 clamp(10px, 2.5vmin, 24px) clamp(10px, 2vmin, 16px);
}
.screen--juegos .jg-switch {
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
  padding: 5px;
  border: 4px solid var(--ink);
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 5px 0 rgba(43, 34, 64, 0.18);
}
.screen--juegos .jg-switch-knob {
  position: absolute;
  top: 5px;
  bottom: 5px;
  left: 5px;
  width: calc((100% - 10px) / var(--n));
  border-radius: 999px;
  background: linear-gradient(160deg, #ffe07a, #ffb938);
  box-shadow: inset 0 0 0 3px var(--ink);
  transform: translateX(calc(var(--i) * 100%));
  transition: transform 0.38s cubic-bezier(0.3, 1.45, 0.5, 1);
}
.screen--juegos .jg-switch-opt {
  position: relative; /* por encima de la burbuja */
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.45em;
  min-height: 50px;
  padding: 6px clamp(14px, 2.4vmin, 22px);
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--ink);
  font-size: clamp(17px, 2.6vmin, 23px);
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
  outline: none;
  touch-action: manipulation;
  transition: opacity 0.2s ease, transform 0.12s ease;
}
.screen--juegos .jg-switch-opt[aria-checked="false"] { opacity: 0.55; }
.screen--juegos .jg-switch-opt:active { transform: scale(0.95); }
.screen--juegos .jg-switch-opt:focus-visible { box-shadow: 0 0 0 4px var(--blue); }
.screen--juegos .jg-switch-ico {
  display: grid;
  place-items: center;
  min-width: 2.3em;
  height: 1.55em;
  padding: 0 0.3em;
  border: 3px solid var(--ink);
  border-radius: 0.5em;
  background: #fff;
  font-size: 0.86em;
  line-height: 1;
}
.screen--juegos .jg-switch-ico--pic { min-width: 0; width: 1.8em; height: 1.8em; padding: 0; border: 0; background: none; }
.screen--juegos .jg-mini { width: 100%; height: 100%; }

/* Letras: tarjeta con la letra y su dibujo, los dos grandes; la grilla se desliza */
.screen--juegos .jg-letters {
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 270px), 1fr));
  grid-template-rows: none;
  grid-auto-rows: auto;
  align-content: start;
  padding-top: 4px;
}
.screen--juegos .jg-letter {
  container-type: size;
  aspect-ratio: 16 / 9;
  align-self: start;
  display: flex;
  align-items: center;
  justify-content: space-evenly;
  min-width: 0;
  padding: 0;
  border: 4px solid var(--ink);
  border-radius: 24px;
  background: #fff;
  box-shadow: 0 6px 0 rgba(43, 34, 64, 0.2);
  cursor: pointer;
  outline: none;
  touch-action: manipulation;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.screen--juegos .jg-letter:active { transform: translateY(4px) scale(0.97); box-shadow: 0 2px 0 rgba(43, 34, 64, 0.2); }
.screen--juegos .jg-letter:focus-visible { box-shadow: 0 0 0 4px var(--blue), 0 6px 0 rgba(43, 34, 64, 0.2); }
.screen--juegos .jg-glyph {
  flex: 0 0 auto;
  width: 44cqw; /* fija: la W o la M no empujan el dibujo */
  font-size: min(88cqh, 44cqw);
  font-weight: 700;
  line-height: 1;
  text-align: center;
  color: var(--c);
  -webkit-text-stroke: 0.045em var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 0.05em 0 rgba(43, 34, 64, 0.2);
}
.screen--juegos .jg-pic {
  flex: 0 0 auto;
  width: min(86cqh, 46cqw);
  height: min(86cqh, 46cqw);
}
.screen--juegos .jg-letter.jg-talk .jg-glyph { animation: jg-name 0.6s ease; }
.screen--juegos .jg-letter.jg-talk .jg-pic { animation: jg-jelly 0.65s ease; }
.screen--juegos .jg-letters.jg-swap .jg-glyph { animation: jg-swap 0.4s cubic-bezier(0.2, 1.5, 0.4, 1); }

/* Memoria: cartas cuadradas que entran enteras, sin scroll. Siempre filas de 4: 8 → 2 filas, 12 → 3, 16 → 4. */
.screen--juegos .jg-mem {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 2px clamp(10px, 2.5vmin, 24px) clamp(14px, 3vmin, 26px);
  container-type: size;
}
.screen--juegos .jg-mem-grid {
  --c: 4;
  --r: 2;
  --g: clamp(8px, 2.2cqmin, 20px);
  --s: min(calc((100cqw - (var(--c) - 1) * var(--g)) / var(--c)), calc((100cqh - (var(--r) - 1) * var(--g)) / var(--r)), 300px);
  display: grid;
  grid-template-columns: repeat(var(--c), var(--s));
  grid-template-rows: repeat(var(--r), var(--s));
  gap: var(--g);
}
.screen--juegos .jg-mem-grid--12 { --r: 3; }
.screen--juegos .jg-mem-grid--16 { --r: 4; }
.screen--juegos .jg-mc {
  position: relative;
  padding: 0;
  border: 0;
  background: none;
  perspective: 900px;
  cursor: pointer;
  outline: none;
  touch-action: manipulation;
  transition: scale 0.12s ease;
}
.screen--juegos .jg-mc.jg-press { scale: 0.95; }
/* La vuelta: la carta gira sobre su eje; cada cara oculta su revés. */
.screen--juegos .jg-mc-in {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform 0.45s cubic-bezier(0.3, 1.35, 0.5, 1);
  animation: jg-pop 0.45s calc(var(--k) * 0.035s) cubic-bezier(0.2, 1.5, 0.4, 1) backwards;
}
.screen--juegos .jg-mc.is-up .jg-mc-in { transform: rotateY(180deg); }
.screen--juegos .jg-mc-face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border: 4px solid var(--ink);
  border-radius: 16%;
  box-shadow: 0 5px 0 rgba(43, 34, 64, 0.2);
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}
.screen--juegos .jg-mc-back {
  background:
    radial-gradient(circle at 24% 18%, rgba(255, 255, 255, 0.55) 0 12%, rgba(255, 255, 255, 0) 40%),
    radial-gradient(rgba(255, 255, 255, 0.3) 18%, transparent 21%) 0 0 / 22% 22%,
    linear-gradient(160deg, var(--c1), var(--c2));
}
.screen--juegos .jg-mc-front { background: #fff; transform: rotateY(180deg); }
.screen--juegos .jg-mc-mark { width: 62%; height: 62%; overflow: visible; }
.screen--juegos .jg-mc-pic { width: 84%; height: 84%; }
.screen--juegos .jg-mc:focus-visible .jg-mc-face { box-shadow: 0 0 0 4px var(--blue), 0 5px 0 rgba(43, 34, 64, 0.2); }
/* Par encontrado: brilla en amarillo y salta; el animal hace "gelatina". Mal par: un temblorcito. */
.screen--juegos .jg-mc.is-match .jg-mc-front { background: #fff7d1; box-shadow: 0 0 0 5px #ffd23f, 0 5px 0 rgba(43, 34, 64, 0.2); }
.screen--juegos .jg-mc.is-match { animation: jg-hop 0.55s 0.2s ease; }
.screen--juegos .jg-mc.is-match .jg-mc-pic { animation: jg-name 0.6s 0.25s ease; }
.screen--juegos .jg-mc.jg-talk .jg-mc-pic { animation: jg-jelly 0.65s ease; }
.screen--juegos .jg-mc.is-nope { animation: jg-shake 0.4s ease; }

/* Fin de la partida: se hace de noche con fuegos artificiales y aparece "¡Otra vez!" */
.screen--juegos .jg-fw {
  position: absolute;
  inset: 0;
  z-index: 5;
  width: 100%;
  height: 100%;
  pointer-events: none;
  background: radial-gradient(120% 90% at 50% 15%, rgba(46, 32, 102, 0.8), rgba(16, 12, 40, 0.88));
  animation: jg-fade 0.6s ease backwards;
  transition: opacity 0.6s ease;
}
.screen--juegos .jg-fw.out { opacity: 0; }
.screen--juegos .jg-again {
  position: absolute;
  z-index: 6;
  left: 50%;
  top: 55%;
  translate: -50% -50%;
  display: flex;
  align-items: center;
  gap: 0.35em;
  padding: 0.3em 1.1em 0.3em 0.55em;
  border: 4px solid var(--ink);
  border-radius: 999px;
  background: linear-gradient(160deg, #ffe07a, #ffb938);
  box-shadow: 0 6px 0 rgba(43, 34, 64, 0.3), 0 16px 34px rgba(16, 12, 40, 0.35);
  color: var(--ink);
  font: inherit;
  font-size: clamp(24px, 5vmin, 40px);
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
  outline: none;
  touch-action: manipulation;
  transition: scale 0.12s ease;
  animation: jg-pop 0.5s cubic-bezier(0.2, 1.5, 0.4, 1) backwards;
}
.screen--juegos .jg-again .icon { width: 1.5em; height: 1.5em; }
.screen--juegos .jg-again:active { scale: 0.95; }
.screen--juegos .jg-again:focus-visible { box-shadow: 0 0 0 5px var(--blue), 0 6px 0 rgba(43, 34, 64, 0.3); }

@keyframes jg-pop {
  from { opacity: 0; transform: translateY(18px) scale(0.86); }
  to { opacity: 1; transform: none; }
}
@keyframes jg-jelly {
  0% { transform: none; }
  30% { transform: scale(1.18, 0.84); }
  55% { transform: scale(0.9, 1.12); }
  80% { transform: scale(1.05, 0.97); }
  100% { transform: none; }
}
@keyframes jg-name {
  0%, 100% { transform: none; }
  40% { transform: scale(1.18) rotate(-3deg); }
}
@keyframes jg-count {
  0% { transform: scale(1); }
  50% { transform: scale(1.35) translateY(-12%); }
  100% { transform: none; }
}
@keyframes jg-swap {
  from { transform: scale(0.4) rotate(-10deg); opacity: 0.2; }
  to { transform: none; opacity: 1; }
}
@keyframes jg-hop {
  0%, 100% { transform: none; }
  40% { transform: translateY(-10%) scale(1.06); }
}
@keyframes jg-shake {
  0%, 100% { transform: none; }
  20% { transform: translateX(-6%) rotate(-3deg); }
  45% { transform: translateX(5%) rotate(2deg); }
  70% { transform: translateX(-3%); }
}
@keyframes jg-fade { from { opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  .screen--juegos .jg-card,
  .screen--juegos .jg-mc-in,
  .screen--juegos .jg-again { animation-duration: 0.01s; }
  .screen--juegos .jg-switch-knob,
  .screen--juegos .jg-mc-in { transition: none; }
  .screen--juegos .jg-mc.is-match,
  .screen--juegos .jg-mc.is-match .jg-mc-pic,
  .screen--juegos .jg-mc.jg-talk .jg-mc-pic,
  .screen--juegos .jg-mc.is-nope,
  .screen--juegos .jg-color.jg-talk .jg-drop,
  .screen--juegos .jg-color.jg-talk .jg-name,
  .screen--juegos .jg-num.jg-talk .jg-digit,
  .screen--juegos .jg-num.jg-talk .jg-item,
  .screen--juegos .jg-num.jg-talk .jg-empty,
  .screen--juegos .jg-letter.jg-talk .jg-glyph,
  .screen--juegos .jg-letter.jg-talk .jg-pic,
  .screen--juegos .jg-letters.jg-swap .jg-glyph { animation: none; }
}
