/* ==========================================================
   Matemix · Números mágicos (Estilo Ligadix)
   ========================================================== */

@font-face {
  font-family: "Playwrite CL";
  src: local("Playwrite CL"),
       local("PlaywriteCL"),
       url("../fonts/PlaywriteCL-VariableFont_wght.ttf") format("truetype");
  font-weight: 100 400;
  font-display: block;
}

:root {
  --bg-1: hsl(252 58% 12%);
  --bg-2: hsl(266 52% 22%);
  --bg-3: hsl(222 62% 18%);
  --glass: hsl(250 60% 96% / 0.07);
  --glass-strong: hsl(250 60% 96% / 0.12);
  --glass-border: hsl(250 70% 90% / 0.16);
  --text: hsl(240 40% 97%);
  --muted: hsl(245 25% 76%);

  --pink: hsl(330 90% 66%);
  --violet: hsl(268 85% 70%);
  --sky: hsl(195 90% 62%);
  --gold: hsl(44 100% 62%);
  --mint: hsl(150 65% 60%);
  --orange: hsl(24 95% 65%);
  --red: hsl(355 85% 64%);

  --paper: hsl(45 75% 97%);
  --paper-line: hsl(205 70% 76%);
  --paper-base: hsl(215 70% 56%);

  --ink-gradient: linear-gradient(90deg, hsl(330 90% 58%), hsl(275 80% 58%) 50%, hsl(205 90% 52%));

  --ui: "Baloo 2", "Nunito", "Segoe UI", system-ui, sans-serif;
  --cur: "Playwrite CL", "Segoe Script", cursive;

  --radius: 24px;
  --ease: cubic-bezier(.3, .7, .3, 1);
  --k: clamp(40px, min(7.8vw, 7.8vh), 68px);
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: var(--ui);
  color: var(--text);
  background:
    radial-gradient(1200px 700px at 15% -10%, hsl(285 70% 35% / .55), transparent 60%),
    radial-gradient(900px 600px at 110% 20%, hsl(210 80% 35% / .45), transparent 60%),
    radial-gradient(800px 500px at 50% 120%, hsl(330 70% 35% / .35), transparent 60%),
    linear-gradient(160deg, var(--bg-1), var(--bg-2) 55%, var(--bg-3));
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

button { font-family: inherit; color: inherit; cursor: pointer; }

/* ---------- Cielo estrellado ---------- */
.sky, .sky::before, .sky::after {
  position: fixed;
  inset: 0;
  pointer-events: none;
}
.sky {
  background-image:
    radial-gradient(1.5px 1.5px at 20px 30px, #fff, transparent),
    radial-gradient(1px 1px at 90px 120px, #fff, transparent),
    radial-gradient(1.5px 1.5px at 160px 60px, hsl(50 100% 85%), transparent),
    radial-gradient(1px 1px at 210px 180px, #fff, transparent);
  background-size: 240px 220px;
  opacity: .35;
}
.sky::before {
  content: "";
  background-image:
    radial-gradient(2px 2px at 60px 80px, #fff, transparent),
    radial-gradient(1.5px 1.5px at 300px 40px, hsl(190 100% 85%), transparent),
    radial-gradient(1px 1px at 180px 260px, #fff, transparent);
  background-size: 380px 320px;
  animation: twinkle 4s ease-in-out infinite alternate;
}
@keyframes twinkle { from { opacity: .2; } to { opacity: .8; } }

/* ---------- Pantallas ---------- */
.screen {
  position: fixed;
  inset: 0;
  opacity: 0;
  visibility: hidden;
  transition: opacity .45s ease, visibility 0s linear .45s;
}
.screen.active {
  opacity: 1;
  visibility: visible;
  transition: opacity .45s ease, visibility 0s;
}

/* ==========================================================
   INICIO
   ========================================================== */
#screen-home {
  overflow-y: auto;
  padding: clamp(20px, 3.5vh, 42px) clamp(16px, 5vw, 72px) 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.hero {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(12px, 3vw, 40px);
  flex-wrap: wrap;
  margin-bottom: clamp(12px, 3vh, 32px);
}

.cuncu-wrap {
  width: clamp(160px, 20vw, 250px);
  background: none;
  border: 0;
  padding: 0;
  filter: drop-shadow(0 18px 30px hsl(150 80% 40% / .3));
  transition: transform .3s var(--ease);
}
.cuncu-wrap:hover { transform: scale(1.04) rotate(-2deg); }

.hero-text { text-align: center; }

.logo {
  position: relative;
  display: inline-block;
  margin: 0;
  font-family: var(--cur);
  font-weight: 400;
  font-size: clamp(58px, 9.5vw, 130px);
  line-height: 1.5;
  white-space: nowrap;
}
.logo-guide { color: hsl(255 60% 96% / .1); }
.logo-ink {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, var(--pink), var(--gold) 35%, var(--sky) 70%, var(--mint));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 6px 22px hsl(300 90% 60% / .45));
  animation: write 2.6s var(--ease) .4s both;
}
@keyframes write {
  from { clip-path: inset(-30% 100% -30% -10%); }
  to   { clip-path: inset(-30% -10% -30% -10%); }
}

.tagline {
  margin: clamp(8px, 1.5vw, 18px) auto 0;
  max-width: 720px;
  font-size: clamp(15px, 1.4vw, 19px);
  color: var(--muted);
  font-weight: 500;
  line-height: 1.45;
  animation: fadeUp .8s ease 1.4s both;
}
.tagline-lead {
  display: block;
  color: hsl(250 60% 92%);
  font-weight: 700;
  margin-bottom: 4px;
}
.tagline-sub {
  display: block;
  font-size: 0.92em;
  color: var(--muted);
}

.section-title {
  font-size: clamp(17px, 1.7vw, 23px);
  font-weight: 700;
  letter-spacing: .02em;
  margin: 0 0 16px;
  color: hsl(250 60% 92%);
  text-align: center;
}
.spark { color: var(--gold); display: inline-block; animation: spin 6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.levels {
  width: min(1160px, 100%);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(175px, 1fr));
  gap: 16px;
}

.level-card {
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 20px 18px 16px;
  text-align: left;
  border-radius: var(--radius);
  background: linear-gradient(160deg, var(--glass-strong), var(--glass));
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(14px);
  box-shadow: 0 10px 30px hsl(250 60% 5% / .35);
  transition: transform .3s var(--ease), box-shadow .3s ease, border-color .3s ease;
  animation: fadeUp .6s var(--ease) both;
  animation-delay: calc(0.8s + var(--d));
}
.level-card::before {
  content: "";
  position: absolute;
  inset: -40% -20% auto auto;
  width: 170px;
  height: 170px;
  border-radius: 50%;
  background: var(--accent);
  filter: blur(50px);
  opacity: .35;
  transition: opacity .3s ease;
}
.level-card:hover, .level-card:focus-visible {
  transform: translateY(-6px);
  border-color: var(--accent);
  box-shadow: 0 18px 40px hsl(250 60% 5% / .5), 0 0 0 1px var(--accent);
  outline: none;
}
.level-card:hover::before { opacity: .6; }
.level-card:hover .lc-emoji { transform: scale(1.15) rotate(-8deg); }

.lc-emoji { font-size: 42px; line-height: 1.1; transition: transform .35s var(--ease); }
.lc-grade {
  margin-top: 4px;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--accent);
}
.lc-name { font-size: 20px; font-weight: 800; line-height: 1.15; }
.lc-sample {
  font-family: var(--ui);
  font-size: 18px;
  font-weight: 700;
  line-height: 1.6;
  color: hsl(250 60% 90%);
  background: hsl(250 50% 12% / 0.45);
  padding: 2px 10px;
  border-radius: 10px;
  margin: 2px 0;
}
.lc-stars { font-size: 20px; letter-spacing: 2px; margin-top: auto; }
.lc-stars i, .res-stars i { font-style: normal; color: hsl(250 25% 40%); }
.lc-stars i.on { color: var(--gold); text-shadow: 0 0 12px hsl(44 100% 60% / .6); }

.home-footer {
  margin-top: auto;
  padding-top: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-align: center;
}
.developer-credit {
  font-size: clamp(14px, 1.4vw, 16px);
  font-weight: 700;
  color: hsl(250 50% 90%);
}
.developer-credit a {
  color: var(--gold);
  text-decoration: none;
  font-weight: 800;
  border-bottom: 2px solid hsl(44 100% 62% / .4);
  transition: color .2s, border-color .2s, text-shadow .2s;
}
.developer-credit a:hover {
  color: #fff;
  border-bottom-color: var(--gold);
  text-shadow: 0 0 12px hsl(44 100% 60% / .8);
}
.font-credit {
  font-size: 13px;
  color: hsl(245 20% 62%);
}

/* ==========================================================
   CUNCU (mascota)
   ========================================================== */
.cuncu svg { display: block; width: 100%; height: auto; overflow: visible; }
.cuncu .seg {
  transform-box: fill-box;
  transform-origin: center bottom;
  animation: bob 1.1s ease-in-out infinite alternate;
}
.cuncu .head {
  transform-box: fill-box;
  transform-origin: center bottom;
  animation: bob 1.1s ease-in-out infinite alternate;
  animation-delay: -.6s;
}
.cuncu .eye {
  transform-box: fill-box;
  transform-origin: center;
  animation: blink 4.5s infinite;
}
@keyframes bob { from { transform: translateY(0); } to { transform: translateY(-6px); } }
@keyframes blink { 0%, 94%, 100% { transform: scaleY(1); } 97% { transform: scaleY(.1); } }

.cuncu.happy { animation: hop .7s var(--ease); }
.cuncu.oops  { animation: tilt .5s ease; }
@keyframes hop { 0%, 100% { transform: translateY(0); } 40% { transform: translateY(-18px) rotate(-4deg); } 70% { transform: translateY(0) scale(1.05, .95); } }
@keyframes tilt { 0%, 100% { transform: rotate(0); } 30% { transform: rotate(-7deg); } 65% { transform: rotate(5deg); } }

/* ==========================================================
   JUEGO
   ========================================================== */
#screen-game {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  gap: clamp(8px, 1.5vh, 14px);
  padding: clamp(10px, 2vh, 18px) clamp(12px, 2.5vw, 32px) clamp(10px, 2vh, 20px);
}

/* Barra superior */
.game-bar {
  display: flex;
  align-items: center;
  gap: 14px;
}
.icon-btn {
  flex: none;
  width: 46px;
  height: 46px;
  border-radius: 14px;
  font-size: 20px;
  font-weight: 800;
  background: var(--glass-strong);
  border: 1px solid var(--glass-border);
  transition: transform .2s var(--ease), background .2s;
}
.icon-btn:hover { background: hsl(250 60% 96% / .2); transform: translateY(-2px); }

.level-title {
  font-size: clamp(17px, 1.8vw, 22px);
  font-weight: 800;
  white-space: nowrap;
}
.level-title small {
  margin-left: 6px;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  background: hsl(250 60% 96% / .12);
  color: var(--muted);
}

.progress {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 6px;
}
.progress i {
  width: 24px;
  height: 24px;
  margin-left: -5px;
  border-radius: 50%;
  background: hsl(250 30% 32%);
  border: 2px solid hsl(250 35% 46%);
  transition: background .4s, border-color .4s, transform .4s var(--ease);
}
.progress i.current { border-color: var(--gold); transform: scale(1.12); box-shadow: 0 0 12px hsl(44 100% 60% / .6); }
.progress i.done {
  background: radial-gradient(circle at 35% 30%, hsl(110 80% 80%), hsl(140 60% 48%));
  border-color: hsl(145 60% 35%);
  animation: popIn .5s var(--ease);
}
.progress .p-head {
  position: relative;
  width: 34px;
  height: 34px;
  margin-left: -6px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, hsl(100 85% 78%), hsl(140 60% 46%));
  border: 2px solid hsl(145 60% 35%);
}
.progress .p-head::before, .progress .p-head::after {
  content: "";
  position: absolute;
  top: 10px;
  width: 7px;
  height: 8px;
  border-radius: 50%;
  background: hsl(250 50% 15%);
}
.progress .p-head::before { left: 8px; }
.progress .p-head::after { right: 8px; }

/* Tablero */
.board {
  display: grid;
  grid-template-columns: clamp(200px, 24%, 310px) minmax(0, 1fr);
  gap: clamp(10px, 1.6vw, 20px);
  min-height: 0;
}

.picture-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(4px, 1vh, 10px);
  padding: 16px;
  border-radius: var(--radius);
  background: linear-gradient(160deg, var(--glass-strong), var(--glass));
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(14px);
  min-height: 0;
  text-align: center;
}
.picture {
  font-size: clamp(52px, 11vh, 110px);
  line-height: 1.1;
  filter: drop-shadow(0 12px 20px hsl(250 60% 5% / .5));
  animation: float 3s ease-in-out infinite;
}
.picture.enter { animation: popIn .55s var(--ease), float 3s ease-in-out .55s infinite; }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }

.print-word {
  font-size: clamp(22px, 3.6vh, 36px);
  font-weight: 800;
  letter-spacing: .03em;
  line-height: 1.15;
  color: hsl(250 40% 96%);
}
.print-word .target-digits {
  display: inline-flex;
  gap: 3px;
  margin-left: 6px;
  padding: 2px 10px;
  border-radius: 12px;
  background: hsl(250 50% 15% / .55);
  border: 1px solid var(--glass-border);
}
.print-word span.digit {
  display: inline-block;
  padding: 0 2px;
  color: hsl(250 40% 92%);
  border-bottom: 4px solid transparent;
  transition: color .25s, border-color .25s, transform .25s var(--ease);
}
.print-word span.digit.done { color: var(--mint); }
.print-word span.digit.current { color: var(--gold); border-bottom-color: var(--gold); transform: translateY(-2px); }

.hint-word {
  font-size: clamp(14px, 2vh, 18px);
  color: var(--gold);
  font-weight: 700;
  min-height: 1.2em;
  background: hsl(44 100% 50% / 0.12);
  padding: 4px 12px;
  border-radius: 999px;
}

.pill-btn {
  margin-top: 4px;
  padding: 8px 18px;
  border-radius: 999px;
  border: 1px solid var(--glass-border);
  background: hsl(250 60% 96% / .1);
  font-size: 16px;
  font-weight: 700;
  transition: background .2s, transform .2s var(--ease);
}
.pill-btn:hover { background: hsl(250 60% 96% / .2); transform: translateY(-2px); }

/* Pizarra: hoja de cuaderno cuadriculado de matemáticas */
.pizarra {
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: clamp(12px, 2.2vh, 24px) clamp(16px, 2.8vw, 36px);
  border-radius: var(--radius);
  background:
    linear-gradient(90deg, transparent 48px, hsl(350 80% 78% / .85) 48px 50px, transparent 50px),
    radial-gradient(120% 90% at 50% 0%, hsl(45 90% 99%), var(--paper));
  box-shadow:
    0 20px 50px hsl(250 70% 5% / .5),
    inset 0 0 0 1px hsl(40 40% 85%),
    inset 0 -30px 60px hsl(40 50% 88% / .5);
  min-height: 0;
}

.math-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(to right, hsl(205 65% 84% / .65) 1px, transparent 1px),
    linear-gradient(to bottom, hsl(205 65% 84% / .65) 1px, transparent 1px);
  background-size: 28px 28px;
  pointer-events: none;
}

.pizarra-content {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  gap: clamp(6px, 1.4vh, 14px);
  min-height: 0;
}

/* Representación visual (Bloques Base 10, Conteo y Grupos) */
.visual-stage {
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  display: flex;
   flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: clamp(6px, 1.2vw, 14px);
  padding: 4px 8px;
  overflow-y: auto;
}

/* Conteo de objetos en marcos de 5/10 */
.ten-frame {
  display: grid;
  grid-template-columns: repeat(5, auto);
  gap: 6px;
  padding: 8px 12px;
  border-radius: 16px;
  background: hsl(215 70% 94% / .85);
  border: 2px solid hsl(215 65% 74%);
  box-shadow: 0 4px 12px hsl(215 50% 20% / .08);
  animation: popIn .45s var(--ease) both;
}
.count-item {
  font-size: clamp(22px, 3.6vh, 36px);
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform .2s var(--ease);
}
.count-item.crossed {
  opacity: 0.32;
  filter: grayscale(0.8);
  position: relative;
}
.count-item.crossed::after {
  content: "✕";
  position: absolute;
  color: hsl(355 85% 52%);
  font-size: 1.1em;
  font-weight: 900;
}

/* Bloques Base 10 (Barras de Decenas = 10 y Cubos de Unidades = 1) */
.base10-wrap {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: center;
  gap: clamp(8px, 1.5vw, 18px);
}
.tens-zone, .ones-zone {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 16px;
  background: hsl(220 60% 95% / .85);
  border: 2px dashed hsl(215 60% 76%);
}
.zone-badge {
  width: 100%;
  text-align: center;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: hsl(225 45% 38%);
  margin-bottom: 2px;
}
.ten-rod {
  display: flex;
  flex-direction: column;
  width: clamp(16px, 2.2vw, 22px);
  border-radius: 5px;
  overflow: hidden;
  border: 1.5px solid hsl(215 80% 38%);
  background: linear-gradient(180deg, hsl(200 90% 62%), hsl(215 85% 50%));
  box-shadow: 0 3px 8px hsl(215 70% 30% / .25);
  animation: popIn .4s var(--ease) both;
}
.ten-rod i {
  display: block;
  height: clamp(5px, 0.72vh, 7px);
  border-bottom: 1px solid hsl(215 80% 35% / .45);
}
.ten-rod i:last-child { border-bottom: 0; }
.ten-rod.sub-crossed, .unit-cube.sub-crossed {
  opacity: 0.3;
  filter: grayscale(0.7);
  position: relative;
}

.ones-grid {
  display: grid;
  grid-template-columns: repeat(5, auto);
  gap: 4px;
}
.unit-cube {
  width: clamp(16px, 2.2vw, 22px);
  height: clamp(16px, 2.2vw, 22px);
  border-radius: 5px;
  background: linear-gradient(145deg, hsl(44 100% 65%), hsl(32 95% 52%));
  border: 1.5px solid hsl(28 85% 38%);
  box-shadow: 0 2px 5px hsl(30 70% 30% / .25);
  animation: popIn .4s var(--ease) both;
}

/* Grupos para Multiplicación y División */
.groups-wrap {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.math-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 3px;
  max-width: 120px;
  padding: 6px 10px;
  border-radius: 14px;
  background: hsl(265 70% 95% / .9);
  border: 2px solid hsl(265 65% 74%);
  box-shadow: 0 3px 10px hsl(260 50% 25% / .1);
  animation: popIn .4s var(--ease) both;
}
.math-group span {
  font-size: clamp(16px, 2.4vh, 24px);
  line-height: 1.1;
}
.math-group small {
  width: 100%;
  text-align: center;
  font-size: 11px;
  font-weight: 800;
  color: hsl(265 55% 40%);
}

/* Visualizador de Fracciones */
.frac-wrap {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: clamp(12px, 2vw, 24px);
  padding: 8px 16px;
  border-radius: 18px;
  background: hsl(345 75% 96% / .9);
  border: 2px solid hsl(345 65% 78%);
  animation: popIn .45s var(--ease) both;
}
.frac-pie {
  width: clamp(72px, 11vh, 104px);
  height: clamp(72px, 11vh, 104px);
  filter: drop-shadow(0 4px 10px hsl(340 50% 25% / .2));
}
.frac-details {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.frac-bar {
  display: grid;
  gap: 3px;
  min-width: clamp(160px, 26vw, 280px);
  padding: 4px;
  border-radius: 10px;
  background: hsl(240 40% 25%);
}
.frac-seg {
  height: clamp(26px, 4vh, 36px);
  border-radius: 6px;
  background: hsl(220 45% 94%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 800;
  color: #fff;
}
.frac-seg.on {
  background: linear-gradient(180deg, hsl(340 90% 66%), hsl(350 82% 52%));
}

/* Visualizador de Números Decimales */
.dec-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 18px;
  background: hsl(180 65% 95% / .9);
  border: 2px solid hsl(175 55% 72%);
  animation: popIn .45s var(--ease) both;
}
.dec-bars-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 12px;
}
.dec-unit-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  animation: popIn .4s var(--ease) both;
}
.dec-unit-col small {
  font-size: 12px;
  font-weight: 800;
  color: hsl(180 65% 26%);
}
.dec-bar {
  display: grid;
  grid-template-columns: repeat(10, clamp(13px, 1.8vw, 20px));
  gap: 2px;
  padding: 4px;
  border-radius: 9px;
  background: hsl(200 45% 24%);
}
.dec-bar i {
  display: block;
  height: clamp(22px, 3.6vh, 32px);
  border-radius: 4px;
  background: hsl(200 35% 92%);
}
.dec-bar.whole i.on {
  background: linear-gradient(180deg, hsl(175 80% 52%), hsl(185 75% 38%));
}
.dec-bar.tenths i.on {
  background: linear-gradient(180deg, hsl(44 100% 62%), hsl(32 95% 50%));
}

/* Ecuación principal en la pizarra */
.equation-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(10px, 1.8vw, 22px);
  font-weight: 800;
  font-size: clamp(34px, 6.2vh, 72px);
  line-height: 1.1;
  color: hsl(245 45% 22%);
  background: hsl(0 0% 100% / .85);
  padding: 6px 24px;
  border-radius: 22px;
  border: 2px solid hsl(215 55% 80%);
  box-shadow: 0 8px 24px hsl(220 50% 20% / .08);
}
.eq-prompt {
  color: hsl(245 45% 24%);
  letter-spacing: .02em;
}
.eq-answer {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.6em;
  padding: 2px 14px;
  border-radius: 16px;
  background: hsl(45 80% 94%);
  border: 3px dashed hsl(215 65% 65%);
}
.guide {
  color: hsl(225 28% 82%);
  font-weight: 800;
  letter-spacing: .04em;
}
.ink {
  position: absolute;
  inset: 2px 14px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  background: var(--ink-gradient);
  background-size: 100% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  font-weight: 800;
  letter-spacing: .04em;
  clip-path: inset(-20% 100% -20% -10%);
  transition: clip-path .35s var(--ease);
  filter: drop-shadow(0 3px 8px hsl(300 80% 55% / .3));
}

/* Opciones rápidas interactivas en la pizarra */
.choices-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.choice-pill {
  padding: 6px 20px;
  border-radius: 999px;
  font-size: clamp(18px, 2.8vh, 24px);
  font-weight: 800;
  color: hsl(250 45% 20%);
  background: linear-gradient(180deg, #ffffff, hsl(220 50% 94%));
  border: 2px solid hsl(215 55% 76%);
  border-bottom: 4px solid hsl(215 55% 62%);
  box-shadow: 0 4px 12px hsl(220 50% 20% / .12);
  transition: transform .15s var(--ease), border-color .2s, background .2s;
}
.choice-pill:hover {
  transform: translateY(-3px);
  border-color: var(--violet);
  border-bottom-color: var(--violet);
}
.choice-pill.correct {
  background: linear-gradient(180deg, hsl(140 80% 78%), hsl(145 65% 52%));
  color: hsl(150 60% 12%);
  border-color: hsl(145 65% 38%);
}
.choice-pill.wrong {
  animation: shake .4s ease;
  background: linear-gradient(180deg, hsl(355 90% 82%), hsl(355 80% 62%));
  color: #fff;
  border-color: hsl(355 75% 45%);
}

.pen {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 2;
  width: 22px;
  height: 22px;
  margin: -11px 0 0 -11px;
  border-radius: 50%;
  background: radial-gradient(circle, #fff 0 20%, hsl(44 100% 70%) 35%, hsl(330 100% 70% / 0) 70%);
  box-shadow: 0 0 18px 6px hsl(44 100% 65% / .55);
  transition: transform .4s var(--ease), opacity .3s;
  animation: penGlow 1.2s ease-in-out infinite alternate;
  pointer-events: none;
  opacity: 0;
}
@keyframes penGlow { from { filter: brightness(1); } to { filter: brightness(1.4); } }

.no-anim { transition: none !important; }

.pizarra.win .ink {
  background: linear-gradient(90deg, hsl(330 90% 58%), hsl(275 80% 58%), hsl(205 90% 52%), hsl(150 70% 45%), hsl(330 90% 58%));
  background-size: 200% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  animation: shimmer 1.4s linear infinite;
}
.pizarra.win .eq-answer {
  border-style: solid;
  border-color: var(--mint);
  background: hsl(145 80% 94%);
}
.pizarra.win { animation: glowPaper 1.2s ease; }
@keyframes shimmer { to { background-position: -200% 0; } }
@keyframes glowPaper {
  40% { box-shadow: 0 0 0 4px var(--gold), 0 0 60px hsl(44 100% 60% / .6), inset 0 0 0 1px hsl(40 40% 85%); }
}

/* Fila inferior: Cuncu + puente matemático */
.bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.helper { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.cuncu-small { flex: none; width: clamp(90px, 10vw, 130px); }

.bubble {
  position: relative;
  min-width: 0;
  max-width: 540px;
  padding: 10px 18px;
  border-radius: 18px;
  background: hsl(0 0% 100%);
  color: hsl(250 40% 20%);
  font-size: clamp(15px, 2.2vh, 19px);
  font-weight: 600;
  line-height: 1.3;
  box-shadow: 0 10px 30px hsl(250 70% 5% / .35);
}
.bubble::before {
  content: "";
  position: absolute;
  left: -8px;
  top: 50%;
  width: 16px;
  height: 16px;
  background: inherit;
  transform: translateY(-50%) rotate(45deg);
  border-radius: 3px;
}
.bubble.pop { animation: bubblePop .4s var(--ease); }
.bubble b { color: hsl(275 70% 50%); }
.bubble .cur { font-weight: 800; font-size: 1.15em; color: hsl(330 80% 52%); }
@keyframes bubblePop { from { transform: scale(.85); opacity: .3; } to { transform: scale(1); opacity: 1; } }

.bridge {
  flex: none;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 18px;
  border-radius: 20px;
  background: linear-gradient(160deg, var(--glass-strong), var(--glass));
  border: 1px solid var(--glass-border);
  transition: opacity .3s;
}
.bridge.hidden { opacity: .25; }
.bridge.swap .b-cell { animation: popIn .4s var(--ease) both; }
.bridge.swap .b-cell:nth-child(3) { animation-delay: .06s; }
.bridge.swap .b-cell:nth-child(5) { animation-delay: .12s; }
.b-cell { display: flex; flex-direction: column; align-items: center; min-width: 52px; }
.b-cell small {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
}
.b-key {
  display: grid;
  place-items: center;
  min-width: 44px;
  height: 42px;
  padding: 0 8px;
  border-radius: 10px;
  font-size: 22px;
  font-weight: 800;
  color: hsl(250 50% 15%);
  background: linear-gradient(180deg, hsl(48 100% 75%), var(--gold));
  border-bottom: 4px solid hsl(36 90% 45%);
}
.b-print { font-size: 26px; font-weight: 800; line-height: 42px; color: var(--sky); }
.b-cursive {
  font-size: 26px;
  font-weight: 800;
  line-height: 42px;
  padding: 0 6px;
  background: linear-gradient(90deg, var(--pink), var(--gold));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.b-arrow { font-size: 20px; color: var(--muted); }
.b-note { font-size: 13px; font-weight: 700; color: var(--gold); max-width: 110px; line-height: 1.15; }
.b-note:empty { display: none; }

/* Teclado numérico en pantalla */
.keyboard {
  justify-self: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: calc(var(--k) * .14);
}
.keyboard[hidden],
.keyboard.hidden {
  display: none;
}
.kb-row { display: flex; gap: calc(var(--k) * .16); justify-content: center; }

.key {
  --f: var(--muted);
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: calc(var(--k) * 1.12);
  height: calc(var(--k) * 0.96);
  padding: 0;
  border-radius: calc(var(--k) * .22);
  background: linear-gradient(180deg, hsl(250 32% 32%), hsl(250 34% 23%));
  border: 1px solid hsl(250 50% 60% / .3);
  border-bottom: 4px solid var(--f);
  box-shadow: 0 4px 10px hsl(250 70% 5% / .4);
  transition: transform .12s ease, background .2s, box-shadow .2s;
  touch-action: manipulation;
}
.key:active { transform: translateY(2px); }
.k-up { font-size: calc(var(--k) * .42); font-weight: 800; line-height: 1; }
.k-cur {
  font-size: calc(var(--k) * .22);
  font-weight: 700;
  line-height: 1.2;
  color: hsl(250 60% 85%);
  letter-spacing: .04em;
}

/* Colores por dígito */
.f-p  { --f: var(--pink); }
.f-r  { --f: var(--orange); }
.f-m  { --f: var(--gold); }
.f-il { --f: var(--mint); }
.f-ir { --f: var(--sky); }

.key.next {
  background: linear-gradient(180deg, hsl(48 100% 76%), var(--gold));
  color: hsl(250 50% 15%);
  animation: pulse 1.1s ease-in-out infinite;
  z-index: 1;
}
.key.next .k-cur { color: hsl(330 70% 40%); }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 hsl(44 100% 60% / .7), 0 4px 10px hsl(250 70% 5% / .4); transform: translateY(-2px); }
  50% { box-shadow: 0 0 0 10px hsl(44 100% 60% / 0), 0 4px 10px hsl(250 70% 5% / .4); transform: translateY(-4px); }
}
.key.hit { animation: press .35s var(--ease); background: linear-gradient(180deg, hsl(140 70% 70%), hsl(145 60% 46%)); }
.key.miss { animation: shake .4s ease; background: linear-gradient(180deg, hsl(355 85% 72%), var(--red)); }
@keyframes press { 40% { transform: translateY(3px) scale(.94); } }
@keyframes shake {
  20% { transform: translateX(-5px); } 40% { transform: translateX(5px); }
  60% { transform: translateX(-3px); } 80% { transform: translateX(3px); }
}

/* ==========================================================
   RESULTADOS
   ========================================================== */
#screen-results { display: grid; place-items: center; padding: 20px; overflow-y: auto; }
.results-card {
  width: min(640px, 100%);
  padding: 28px clamp(20px, 4vw, 44px) 32px;
  text-align: center;
  border-radius: 32px;
  background: linear-gradient(160deg, var(--glass-strong), var(--glass));
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(16px);
  box-shadow: 0 30px 80px hsl(250 70% 5% / .5);
}
#screen-results.active .results-card { animation: popIn .6s var(--ease); }
.res-cuncu { width: 170px; margin: 0 auto -6px; }
.res-title { margin: 0; font-size: clamp(32px, 5vw, 48px); font-weight: 800; }
.res-stars { font-size: clamp(54px, 9vw, 76px); letter-spacing: 6px; line-height: 1.1; }
.res-stars i { display: inline-block; animation: starIn .6s var(--ease) both; animation-delay: var(--d); }
.res-stars i.on { color: var(--gold); text-shadow: 0 0 24px hsl(44 100% 60% / .8); }
@keyframes starIn { from { transform: scale(0) rotate(-90deg); opacity: 0; } to { transform: scale(1) rotate(0); opacity: 1; } }
.res-text { margin: 6px 0 12px; font-size: 19px; color: var(--muted); font-weight: 600; }
.res-words { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-bottom: 24px; }
.res-words span {
  padding: 4px 16px;
  border-radius: 14px;
  background: var(--paper);
  font-family: var(--ui);
  font-size: 20px;
  font-weight: 800;
  line-height: 1.8;
  color: hsl(265 65% 42%);
  animation: fadeUp .5s var(--ease) both;
  animation-delay: var(--d);
}
.res-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; }
.btn {
  padding: 12px 24px;
  border-radius: 999px;
  font-size: 18px;
  font-weight: 800;
  border: 1px solid var(--glass-border);
  transition: transform .2s var(--ease), box-shadow .2s, background .2s;
}
.btn:hover { transform: translateY(-3px); }
.btn.ghost { background: hsl(250 60% 96% / .1); }
.btn.ghost:hover { background: hsl(250 60% 96% / .2); }
.btn.primary {
  border: 0;
  background: linear-gradient(90deg, var(--pink), var(--violet));
  box-shadow: 0 10px 30px hsl(310 90% 55% / .4);
}
.btn.primary:hover { box-shadow: 0 14px 40px hsl(310 90% 55% / .6); }
.btn[hidden] { display: none; }

/* ---------- Confeti ---------- */
#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 50; }

/* ---------- Animaciones comunes ---------- */
@keyframes fadeUp { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
@keyframes popIn { 0% { transform: scale(.6); opacity: 0; } 70% { transform: scale(1.08); opacity: 1; } 100% { transform: scale(1); } }

/* ==========================================================
   DISEÑO COMPLETAMENTE RESPONSIVO Y FLUIDO (Móviles, Tablets y Pantallas Compactas ≤ 900px)
   ========================================================== */
@media (max-width: 900px) {
  *, *::before, *::after {
    box-sizing: border-box !important;
  }

  html, body {
    width: 100% !important;
    max-width: 100vw !important;
    overflow: hidden !important;
    height: 100% !important;
  }

  main {
    width: 100% !important;
    max-width: 100vw !important;
    height: 100% !important;
    overflow: hidden !important;
  }

  .screen {
    width: 100% !important;
    max-width: 100vw !important;
    height: 100% !important;
    overflow: hidden !important;
  }

  /* ------------------- INICIO / HOME ------------------- */
  #screen-home {
    padding: clamp(12px, 2.5vh, 22px) clamp(10px, 3vw, 20px) 24px !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    width: 100% !important;
  }
  .hero {
    gap: 10px !important;
    margin-bottom: 12px !important;
  }
  .cuncu-wrap {
    width: clamp(95px, 20vw, 140px) !important;
    margin: 0 auto !important;
  }
  .logo {
    font-size: clamp(34px, 9vw, 54px) !important;
    line-height: 1.25 !important;
  }
  .tagline {
    font-size: clamp(12px, 3vw, 15px) !important;
    margin-top: 6px !important;
    line-height: 1.35 !important;
    max-width: 520px !important;
  }
  .section-title {
    font-size: clamp(14px, 3.5vw, 18px) !important;
    margin: 10px 0 10px !important;
  }
  .levels {
    display: flex !important;
    flex-direction: column !important;
    width: 100% !important;
    max-width: 580px !important;
    gap: 8px !important;
    margin: 0 auto !important;
  }
  .level-card {
    min-width: 0 !important;
    max-width: 100% !important;
    width: 100% !important;
    flex: none !important;
    padding: 10px 14px !important;
    display: grid !important;
    grid-template-columns: 38px 1fr auto !important;
    align-items: center !important;
    gap: 10px !important;
    border-radius: 14px !important;
  }
  .lc-emoji {
    font-size: 30px !important;
    grid-row: 1 / span 2 !important;
  }
  .lc-grade {
    margin-top: 0 !important;
    font-size: 11px !important;
  }
  .lc-name {
    font-size: clamp(14px, 3.5vw, 16px) !important;
    font-weight: 700 !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }
  .lc-sample {
    display: none !important;
  }
  .lc-stars {
    font-size: 15px !important;
    grid-column: 3 !important;
    grid-row: 1 / span 2 !important;
  }

  /* ------------------- JUEGO PRINCIPAL ------------------- */
  #screen-game {
    display: flex !important;
    flex-direction: column !important;
    justify-content: space-between !important;
    width: 100% !important;
    max-width: 100vw !important;
    height: 100% !important;
    max-height: 100vh !important;
    padding: clamp(6px, 1.2vh, 10px) clamp(8px, 2.5vw, 14px) !important;
    gap: clamp(4px, 0.8vh, 8px) !important;
    overflow: hidden !important;
  }

  .game-bar {
    width: 100% !important;
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
    flex: 0 0 auto !important;
  }
  .icon-btn {
    width: 36px !important;
    height: 36px !important;
    min-width: 36px !important;
    border-radius: 10px !important;
    font-size: 16px !important;
  }
  .level-title {
    font-size: clamp(13px, 3.5vw, 16px) !important;
    font-weight: 700 !important;
    white-space: nowrap !important;
  }
  .level-title small { display: none !important; }
  .progress {
    flex: 1 !important;
    min-width: 0 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: flex-end !important;
    padding-right: 2px !important;
    overflow: hidden !important;
  }
  .progress i {
    width: clamp(11px, 2.2vw, 16px) !important;
    height: clamp(11px, 2.2vw, 16px) !important;
    margin-left: -3px !important;
    border-width: 1.5px !important;
  }
  .progress .p-head {
    width: clamp(17px, 3.5vw, 24px) !important;
    height: clamp(17px, 3.5vw, 24px) !important;
    margin-left: -4px !important;
  }

  /* Tablero / Pizarra */
  .board {
    display: flex !important;
    flex-direction: column !important;
    width: 100% !important;
    gap: 6px !important;
    min-height: 0 !important;
    flex: 1 1 auto !important;
  }
  .picture-card {
    flex: 0 0 auto !important;
    width: 100% !important;
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    justify-content: space-between !important;
    padding: 4px 10px !important;
    gap: 6px !important;
    min-height: 40px !important;
    border-radius: 12px !important;
  }
  .picture {
    font-size: clamp(24px, 5.5vw, 32px) !important;
    line-height: 1 !important;
    margin: 0 !important;
    flex-shrink: 0 !important;
  }
  .print-word {
    font-size: clamp(15px, 4vw, 20px) !important;
    line-height: 1.1 !important;
    margin: 0 !important;
  }
  .hint-word {
    font-size: clamp(10px, 2.6vw, 13px) !important;
    padding: 2px 8px !important;
  }
  .pill-btn {
    margin-top: 0 !important;
    padding: 4px 10px !important;
    font-size: clamp(11px, 2.8vw, 13px) !important;
    white-space: nowrap !important;
    flex-shrink: 0 !important;
    border-radius: 14px !important;
  }
  .pizarra {
    width: 100% !important;
    flex: 1 1 auto !important;
    min-height: 120px !important;
    padding: 8px 10px !important;
    border-radius: 14px !important;
    background:
      linear-gradient(90deg, transparent 22px, hsl(350 80% 78% / .8) 22px 24px, transparent 24px),
      radial-gradient(120% 90% at 50% 0%, hsl(45 90% 99%), var(--paper)) !important;
  }
  .equation-stage {
    font-size: clamp(24px, 5.5vw, 36px) !important;
    padding: 4px 14px !important;
    border-radius: 14px !important;
  }
  .choice-pill {
    padding: 4px 14px !important;
    font-size: clamp(14px, 3.8vw, 18px) !important;
  }
  .ten-rod {
    width: 14px !important;
  }
  .ten-rod i {
    height: 4px !important;
  }
  .unit-cube {
    width: 14px !important;
    height: 14px !important;
  }

  /* Fila inferior: Cuncu y Puente */
  .bottom {
    width: 100% !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    gap: 4px !important;
    flex: 0 0 auto !important;
  }
  .helper {
    width: 100% !important;
    display: flex !important;
    align-items: center !important;
    justify-content: flex-start !important;
    gap: 8px !important;
  }
  .cuncu-small {
    width: 36px !important;
    flex: 0 0 36px !important;
  }
  .bubble {
    flex: 1 1 auto !important;
    padding: 5px 12px !important;
    font-size: clamp(11px, 2.8vw, 13px) !important;
    line-height: 1.25 !important;
    border-radius: 12px !important;
  }
  .bridge {
    width: 100% !important;
    max-width: 380px !important;
    padding: 3px 8px !important;
    gap: 6px !important;
    border-radius: 12px !important;
  }
  .b-cell small { font-size: 8px !important; }
  .b-key {
    min-width: 28px !important;
    height: 24px !important;
    font-size: 14px !important;
    border-radius: 6px !important;
  }
  .b-print, .b-cursive {
    font-size: 16px !important;
    line-height: 24px !important;
  }

  /* Teclado numérico en móvil */
  .keyboard {
    width: 100% !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    gap: 4px !important;
    padding: 2px 0 !important;
    flex: 0 0 auto !important;
  }
  .kb-row {
    width: 100% !important;
    display: flex !important;
    justify-content: center !important;
    gap: 3px !important;
  }
  .key {
    flex: 1 1 0 !important;
    max-width: 46px !important;
    min-width: 22px !important;
    height: 40px !important;
    border-radius: 8px !important;
    border-bottom-width: 3px !important;
  }
  .k-up { font-size: 15px !important; }
  .k-cur { font-size: 8.5px !important; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
