/* Aprendi2 — juegos de Matemática (#mate/...). Todo bajo .screen--juegos (las pantallas usan juegos.css y ap.css). */

/* Número grande (Aprender de Números): el número y, abajo, cómo se lee. */
.screen--juegos .ap-bignum {
  container-type: size;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2cqh;
  width: min(100%, 620px);
  height: min(100%, 420px);
  padding: 12px;
  border: 4px solid var(--ink);
  border-radius: 32px;
  background: #fff;
  box-shadow: 0 7px 0 rgba(43, 34, 64, 0.2);
  cursor: pointer;
  outline: none;
  touch-action: manipulation;
}
.screen--juegos .ap-bignum:active { transform: translateY(4px) scale(0.98); }
.screen--juegos .ap-bignum-d,
.screen--juegos .ap-big {
  font-size: min(62cqh, 44cqw);
  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 .ap-big { font-size: min(70cqh, 40cqw); }
.screen--juegos .ap-bignum-w { font-size: min(12cqh, 7.5cqw); font-weight: 700; color: var(--ink-soft); }
.screen--juegos .ap-bignum.jg-talk .ap-bignum-d { animation: jg-name 0.6s ease; }
/* La palabra escrita de un número (¿qué número dice el cartel?). */
.screen--juegos .ap-word {
  font-size: min(26cqh, 9cqw);
  font-weight: 700;
  line-height: 1.1;
  text-align: center;
  color: var(--ink);
}

/* ---------- Decenas y unidades ---------- */
.screen--juegos .ap-dec { display: flex; align-items: center; justify-content: center; gap: clamp(16px, 5cqw, 60px); width: 100%; height: 100%; }
.screen--juegos .ap-mat-box { height: 100%; max-width: 70%; display: grid; place-items: center; padding: 10px 14px; border: 4px solid var(--ink); border-radius: 26px; background: #fff; box-shadow: 0 6px 0 rgba(43, 34, 64, 0.2); cursor: pointer; }
.screen--juegos .ap-mat { height: 100%; max-height: min(64cqh, 320px); width: auto; max-width: 100%; }
.screen--juegos .ap-box .ap-mat { height: min(80cqh, 300px); }
.screen--juegos .ap-dec-num { font-size: min(50cqh, 22cqw); font-weight: 700; color: var(--c); -webkit-text-stroke: 0.05em var(--ink); paint-order: stroke fill; }

/* ---------- Anterior y posterior: el tren ---------- */
.screen--juegos .ap-train { width: 100%; height: auto; max-height: 100%; max-width: 760px; }
.screen--juegos .ap-learn-main .ap-train { cursor: pointer; }

/* ---------- Mayor, menor, igual ---------- */
.screen--juegos .ap-cmp { display: flex; align-items: center; justify-content: center; gap: clamp(10px, 4cqw, 48px); width: 100%; height: 100%; cursor: pointer; }
.screen--juegos .ap-cmp-side { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; min-width: 0; height: 100%; padding: 10px 16px; border: 4px solid var(--ink); border-radius: 26px; background: #fff; box-shadow: 0 6px 0 rgba(43, 34, 64, 0.2); }
.screen--juegos .ap-cmp .ap-big { font-size: min(44cqh, 18cqw); }
.screen--juegos .ap-group { width: min(30cqw, 260px); height: auto; max-height: 34cqh; }
.screen--juegos .ap-cmp-sign { font-size: min(50cqh, 18cqw); font-weight: 700; color: #ffd23f; -webkit-text-stroke: 0.05em var(--ink); paint-order: stroke fill; }
.screen--juegos .ap-cmp-sign.is-q { color: #fff; animation: jg-name 1.2s ease infinite; }

/* ---------- Ordenar: la escalera ---------- */
.screen--juegos .ap-stairs { display: flex; align-items: flex-end; justify-content: center; gap: clamp(6px, 2cqw, 18px); width: min(100%, 760px); height: 100%; }
.screen--juegos .ap-step { flex: 1 1 0; height: var(--h); display: flex; align-items: flex-start; justify-content: center; padding-top: 6%; border: 4px solid var(--ink); border-radius: 18px 18px 6px 6px; background: linear-gradient(180deg, #fff, #f3eefc); box-shadow: 0 6px 0 rgba(43, 34, 64, 0.2); font: inherit; font-size: min(14cqh, 9cqw); font-weight: 700; color: var(--c); -webkit-text-stroke: 0.05em var(--ink); paint-order: stroke fill; cursor: pointer; transition: transform 0.2s, background 0.2s; }
.screen--juegos .ap-step.is-on { background: #fff3c4; transform: translateY(-8px); box-shadow: 0 0 0 5px #ffd23f, 0 6px 0 rgba(43, 34, 64, 0.2); }

/* ---------- Series ---------- */
.screen--juegos .ap-serie { --cw: clamp(46px, min(11cqw, 24cqh), 104px); --cg: clamp(6px, 1.4cqw, 14px); display: flex; flex-wrap: wrap; justify-content: center; gap: var(--cg); max-width: 100%; }
.screen--juegos .ap-serie-c { display: grid; place-items: center; width: var(--cw); aspect-ratio: 1; border: 4px solid var(--ink); border-radius: 20px; background: #fff; box-shadow: 0 5px 0 rgba(43, 34, 64, 0.2); font-size: calc(var(--cw) * 0.46); font-weight: 700; color: var(--c, var(--ink)); -webkit-text-stroke: 0.05em var(--ink); paint-order: stroke fill; transition: transform 0.2s; }
.screen--juegos .ap-serie-c.is-q { border-style: dashed; color: #ff5a5f; animation: jg-name 1.2s ease infinite; }
.screen--juegos .ap-serie-c.is-on { background: #fff3c4; transform: translateY(-10px); box-shadow: 0 0 0 5px #ffd23f; }
.screen--juegos .ap-serie-wrap { --cw: clamp(46px, min(11cqw, 24cqh), 104px); --cg: clamp(6px, 1.4cqw, 14px); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; width: 100%; height: 100%; }
.screen--juegos .ap-serie-wrap .ap-serie { flex-wrap: nowrap; }
.screen--juegos .ap-frog { width: var(--cw); height: var(--cw); translate: calc((var(--x, 0) - 3.5) * (var(--cw) + var(--cg))) 0; transition: translate 0.5s ease; }
.screen--juegos .ap-frog.is-jump { animation: ap-jump 0.55s ease; }
@keyframes ap-jump { 0%, 100% { transform: none; } 45% { transform: translateY(-40%); } }
.screen--juegos .ap-steps .switch-ico { min-width: 1.8em; }
@media (max-width: 700px) { .screen--juegos .ap-steps .switch-label { display: none; } }

/* ---------- Grilla del 0 al 99 ---------- */
.screen--juegos .ap-grid100 {
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  grid-template-rows: repeat(10, minmax(0, 1fr));
  gap: clamp(2px, 0.6vmin, 6px);
  width: min(100%, calc(100cqh * 1.25));
  height: 100%;
  margin: 0 auto;
}
.screen--juegos .jg-quiz.ap-grid100 { --cols: 10; --rows: 10; gap: clamp(2px, 0.6vmin, 6px); width: min(100%, calc(100cqh * 1.3)); }
.screen--juegos .jg-quiz.ap-grid100 > * { animation: none; }
.screen--juegos .ap-cell {
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 2px solid rgba(43, 34, 64, 0.5);
  border-radius: 8px;
  background: color-mix(in srgb, var(--c) 22%, #fff);
  font: inherit;
  font-size: clamp(11px, min(2.6vmin, 2vw), 22px);
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
  touch-action: manipulation;
}
.screen--juegos .ap-cell.is-line { background: color-mix(in srgb, var(--c) 55%, #fff); }
.screen--juegos .ap-cell.jg-talk,
.screen--juegos .ap-cell.is-ok { background: #ffd23f; border-color: var(--ink); animation: jg-name 0.6s ease; }
.screen--juegos .ap-cell.is-off { opacity: 0.4; }
.screen--juegos .ap-frag { display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); gap: 6px; height: 100%; aspect-ratio: 1.3; max-width: 100%; }
.screen--juegos .ap-frag-c { display: grid; place-items: center; border: 3px solid var(--ink); border-radius: 12px; background: color-mix(in srgb, var(--c) 22%, #fff); font-size: min(12cqh, 8cqw); font-weight: 700; }
.screen--juegos .ap-frag-c.is-q { background: #fff; border-style: dashed; color: #ff5a5f; }

/* ---------- Sumas y restas ---------- */
.screen--juegos .ap-cuenta { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; width: 100%; height: 100%; cursor: pointer; }
.screen--juegos .ap-things { width: auto; height: auto; max-width: 100%; max-height: 58cqh; min-height: 0; flex: 1 1 auto; }
.screen--juegos .ap-eq { display: flex; align-items: center; gap: 0.3em; padding: 0.1em 0.5em; border: 4px solid var(--ink); border-radius: 22px; background: #fff; box-shadow: 0 5px 0 rgba(43, 34, 64, 0.2); font-size: clamp(28px, min(14cqh, 8cqw), 72px); font-weight: 700; white-space: nowrap; }
.screen--juegos .ap-box .ap-eq { border: 0; box-shadow: none; padding: 0; font-size: clamp(30px, min(26cqh, 10cqw), 96px); }
.screen--juegos .ap-eq .is-q { color: #ff5a5f; }
.screen--juegos .ap-rev { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 14px; }
.screen--juegos .ap-rev .ap-box .ap-eq { font-size: clamp(24px, min(18cqh, 6.5cqw), 70px); }
.screen--juegos .ap-rev .ap-box:first-child { background: #eafaf2; }

/* ---------- Problemas ---------- */
.screen--juegos .ap-prob { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; width: 100%; height: 100%; max-width: 900px; padding: 10px 16px; border: 4px solid var(--ink); border-radius: 26px; background: #fff; box-shadow: 0 6px 0 rgba(43, 34, 64, 0.2); cursor: pointer; }
.screen--juegos .ap-prob-text { margin: 0; font-size: clamp(17px, min(7cqh, 3.6cqw), 30px); font-weight: 600; line-height: 1.3; text-align: center; }
.screen--juegos .ap-prob-pic { flex: 1 1 auto; min-height: 0; display: flex; align-items: center; justify-content: center; gap: 12px; }
.screen--juegos .ap-prob-pic .ap-things { max-height: 100%; height: 100%; }
.screen--juegos .ap-prob-pic .ap-word { font-size: clamp(26px, 9cqh, 60px); }
.screen--juegos .ap-prob-one { height: 100%; max-height: 120px; width: auto; }

/* ---------- Primero, segundo: la carrera ---------- */
.screen--juegos .ap-race { display: flex; align-items: stretch; justify-content: center; gap: clamp(4px, 1.2cqw, 12px); width: 100%; height: min(100%, 260px); }
.screen--juegos .ap-race-flag { flex: 0 0 auto; width: clamp(40px, 8cqw, 90px); height: auto; align-self: center; }
.screen--juegos .ap-race .ap-runner { flex: 1 1 0; max-width: 150px; }
.screen--juegos .ap-runner > svg { width: 100%; height: 100%; }
.screen--juegos .ap-race .ap-runner.is-ok { background: #fff7d1; box-shadow: 0 0 0 6px #ffd23f, 0 6px 0 rgba(43, 34, 64, 0.2); }
.screen--juegos .ap-race-hint { display: flex; align-items: center; justify-content: center; gap: 20px; height: 100%; }
.screen--juegos .ap-race-hint .ap-race-flag { width: auto; height: min(90%, 150px); }
.screen--juegos .ap-race-hint .ap-word { font-size: clamp(26px, min(20cqh, 7cqw), 64px); }
/* Jugando: la fila de animales en una sola fila, con la bandera al principio. */
.screen--juegos .jg-quiz.ap-race-quiz { --rows: 1; grid-template-columns: repeat(var(--ap-cols), minmax(0, 1fr)); position: relative; padding-left: clamp(50px, 9vmin, 90px); align-items: center; }
.screen--juegos .jg-quiz.ap-race-quiz::before { content: ''; position: absolute; left: clamp(6px, 1vmin, 14px); top: 50%; width: clamp(40px, 8vmin, 76px); height: clamp(60px, 14vmin, 110px); translate: 0 -50%; background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Cpath d='M18 94V8' stroke='%232b2240' stroke-width='6' stroke-linecap='round'/%3E%3Cpath d='M21 10h62v44H21z' fill='%23fff' stroke='%232b2240' stroke-width='3'/%3E%3Cg fill='%232b2240'%3E%3Crect x='21' y='10' width='15.5' height='11'/%3E%3Crect x='52' y='10' width='15.5' height='11'/%3E%3Crect x='36.5' y='21' width='15.5' height='11'/%3E%3Crect x='67.5' y='21' width='15.5' height='11'/%3E%3Crect x='21' y='32' width='15.5' height='11'/%3E%3Crect x='52' y='32' width='15.5' height='11'/%3E%3Crect x='36.5' y='43' width='15.5' height='11'/%3E%3Crect x='67.5' y='43' width='15.5' height='11'/%3E%3C/g%3E%3C/svg%3E") center / contain no-repeat; }
.screen--juegos .ap-race-quiz .ap-runner { max-height: 220px; height: 100%; }
@container (max-aspect-ratio: 1 / 1) { .screen--juegos .jg-quiz.ap-race-quiz { --cols: var(--ap-cols); } }

/* ---------- Figuras, líneas y escenas: grillas para aprender ---------- */
.screen--juegos .jg-grid.ap-figs { --cols: 4; --rows: 2; }
@media (max-aspect-ratio: 1 / 1) { .screen--juegos .jg-grid.ap-figs { --cols: 2; --rows: 4; } }
.screen--juegos .jg-grid.ap-lines { --cols: 4; --rows: 3; }
@media (min-aspect-ratio: 16 / 9) { .screen--juegos .jg-grid.ap-lines { --cols: 6; --rows: 2; } }
@media (max-aspect-ratio: 1 / 1) { .screen--juegos .jg-grid.ap-lines { --cols: 3; --rows: 4; } }
.screen--juegos .jg-grid.ap-scenes { --cols: 4; --rows: 2; }
@media (max-aspect-ratio: 1 / 1) { .screen--juegos .jg-grid.ap-scenes { --cols: 2; --rows: 4; } }
.screen--juegos .ap-learn > .ap-learn-btns + .jg-grid { flex: 1 1 auto; width: 100%; padding-bottom: 0; }
.screen--juegos .ap-fig-big { width: auto; height: 100%; max-height: 260px; }
.screen--juegos .ap-line-svg { overflow: visible; }
.screen--juegos .ap-show > .ap-line-svg { width: auto; height: 100%; max-height: 260px; }
.screen--juegos .ap-line, .screen--juegos .ap-line-ink { stroke-dasharray: 100; stroke-dashoffset: 0; }
.screen--juegos .ap-line--go { animation: ap-draw 1.3s ease both; }
@keyframes ap-draw { from { stroke-dashoffset: 100; } to { stroke-dashoffset: 0; } }
.screen--juegos .ap-scene { overflow: visible; }

/* ---------- Medimos ---------- */
.screen--juegos .ap-measure { width: 100%; height: auto; max-height: 100%; max-width: 820px; }
.screen--juegos .jg-quiz.ap-pencils { gap: 8px; }
.screen--juegos .ap-pencil-card { padding: 4px 10px; }
.screen--juegos .ap-pencil-card > svg { max-width: 100%; height: 100%; }
.screen--juegos .ap-tree-card > svg { height: 100%; }

@media (prefers-reduced-motion: reduce) {
  .screen--juegos .ap-serie-c.is-q,
  .screen--juegos .ap-cmp-sign.is-q,
  .screen--juegos .ap-frog.is-jump,
  .screen--juegos .ap-line--go { animation: none; }
}
