:root {
  --pink: #ff8fbf;
  --pink-d: #e8679f;
  --blue: #6b8fc7;
  --blue-d: #47689e;
  --cream: #fff8fc;
  --yellow: #ffe066;
  --yellow-d: #f5a623;
  --font: "Baloo 2", "Nunito", "Varela Round", "Comic Sans MS", system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

button, input, select, textarea {
  font-family: inherit;
}

html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: #9fd3ff;
  font-family: var(--font);
  color: #4b5f8f;
  touch-action: manipulation;
  user-select: none; -webkit-user-select: none;
  overscroll-behavior: none;
}

.hidden { display: none !important; }

/* ---------- PRELOADER INSTANTÁNEO ---------- */
.app-preloader {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, #e3f2fd 0%, #fff0f5 50%, #f3e5f5 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 99999;
  transition: opacity 0.35s ease, visibility 0.35s ease;
}

.app-preloader.fade-out {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.preloader-content {
  text-align: center;
  padding: 24px;
}

.preloader-mascot {
  font-size: 56px;
  animation: preloaderBounce 1s infinite alternate ease-in-out;
  display: inline-block;
}

@keyframes preloaderBounce {
  0% { transform: translateY(0) scale(1); }
  100% { transform: translateY(-16px) scale(1.1); }
}

.preloader-title {
  font-size: 32px;
  font-weight: 800;
  color: #47689e;
  margin: 12px 0 14px;
  text-shadow: 0 2px 4px rgba(71, 104, 158, 0.12);
}

.preloader-bar {
  width: 220px;
  height: 10px;
  background: rgba(255, 255, 255, 0.9);
  border: 2px solid #bcd7ff;
  border-radius: 999px;
  margin: 0 auto 14px;
  overflow: hidden;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.06);
}

.preloader-bar-fill {
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, #ff8fbf, #ffe066, #6b8fc7);
  background-size: 200% 100%;
  border-radius: 999px;
  animation: preloaderShimmer 1.2s infinite linear;
}

@keyframes preloaderShimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

.preloader-sub {
  font-size: 16px;
  font-weight: 700;
  color: #7b8fb2;
}



/* ---------- BARRA SUPERIOR UNIVERSAL ---------- */
#globalTopBar {
  position: fixed; top: 0; left: 0; right: 0;
  height: 60px;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(8px);
  border-bottom: 3px solid rgba(255, 255, 255, 0.95);
  box-shadow: 0 4px 12px rgba(107, 143, 199, 0.15);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  z-index: 999;
}

.top-brand {
  font-size: 22px; font-weight: 800; color: var(--blue);
  letter-spacing: 0.5px;
}

.top-nav-btn {
  background: #ffffff;
  border: 3px solid #d9e6ff;
  border-radius: 999px;
  padding: 6px 16px;
  color: var(--blue);
  font: 800 18px var(--font);
  cursor: pointer;
  display: inline-flex; align-items: center; gap: 8px;
  box-shadow: 0 3px 0 #cadbfb;
  transition: transform 0.15s, background 0.15s;
}

.top-nav-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #cadbfb;
}

.music-btn.playing {
  border-color: #ffb6d2;
  background: #fff0f5;
  color: var(--pink-d);
}

.track-btn {
  background: #fff8e7;
  border-color: #ffe082;
  color: #f57f17;
  box-shadow: 0 3px 0 #ffd54f;
  font-size: 15px;
  padding: 5px 14px;
}

.top-right-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ---------- GESTOR DE PANTALLAS ---------- */
#appContainer {
  position: fixed; inset: 60px 0 0 0;
  overflow: hidden;
}

.screen {
  display: none;
  width: 100%; height: 100%;
  position: absolute; inset: 0;
  overflow-y: auto;
  overflow-x: hidden;
}

.screen.active {
  display: flex;
  flex-direction: column;
}

#screen-flight.active { display: block; }
#screen-platformer.active { display: flex; }
#screen-doom.active { display: flex; }

#doom-mount, #platformer-mount, #math-mount, #coloring-mount, #memory-mount, #writing-mount, #puzzle-mount {
  width: 100%; height: 100%;
  display: flex; flex-direction: column;
}

/* ============================================================
   PANTALLA 1: HUB CENTRAL (Selector de 6 Juegos)
   ============================================================ */
#screen-hub {
  background: linear-gradient(180deg, #9fd3ff 0%, #e2f0ff 40%, #ffeaf4 100%);
  align-items: center;
  justify-content: flex-start;
  padding: 20px 16px 50px;
}

.hub-header {
  text-align: center;
  margin-bottom: 20px;
}

.cinna-mascot-box {
  width: 160px; height: 90px;
  margin: 0 auto 4px;
  animation: floatMascot 2.4s ease-in-out infinite;
}

.cinna-mascot-img {
  width: 100%; height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 8px 12px rgba(107, 143, 199, 0.3));
}

@keyframes floatMascot {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.hub-header h1 {
  margin: 0; font-size: clamp(28px, 4.5vw, 44px);
  color: var(--blue-d); line-height: 1.1;
  text-shadow: 0 2px 0 #ffffff;
}

.hub-header .subtitle {
  margin: 6px 0 0; font-size: clamp(15px, 2.2vw, 19px);
  color: #637ea6; font-weight: 700;
}

.game-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 320px));
  gap: 20px;
  justify-content: center;
  width: 100%;
  max-width: 1080px;
}

.game-card {
  background: rgba(255, 255, 255, 0.95);
  border: 5px solid #ffffff;
  border-radius: 30px;
  padding: 20px 18px 16px;
  text-align: center;
  box-shadow: 0 8px 0 rgba(107, 143, 199, 0.22), 0 16px 30px rgba(75, 95, 143, 0.14);
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  display: flex; flex-direction: column; align-items: center;
  position: relative;
}

.game-card:hover {
  transform: translateY(-4px) scale(1.02);
  box-shadow: 0 12px 0 rgba(107, 143, 199, 0.25), 0 20px 36px rgba(75, 95, 143, 0.2);
}

.game-card:active {
  transform: translateY(4px);
  box-shadow: 0 4px 0 rgba(107, 143, 199, 0.25);
}

.card-badge {
  position: absolute; top: 12px; left: 16px;
  background: #f0f5ff; border: 2px solid #d5e4ff;
  border-radius: 999px; padding: 2px 10px;
  font-size: 13px; font-weight: 800; color: var(--blue);
}

.card-illustration {
  width: 100px; height: 100px; border-radius: 50%;
  margin: 10px auto 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 48px;
  position: relative;
}

.card-flight .card-illustration { background: linear-gradient(135deg, #cbe5ff, #8ec2ff); }
.card-math .card-illustration { background: linear-gradient(135deg, #ffe2ee, #ffb3d2); }
.card-coloring .card-illustration { background: linear-gradient(135deg, #fff3c4, #ffe082); }
.card-memory .card-illustration { background: linear-gradient(135deg, #e1d5ff, #c4b5fd); }
.card-platformer .card-illustration { background: linear-gradient(135deg, #dcfce7, #86efac); }
.card-doom .card-illustration { background: linear-gradient(135deg, #fed7aa, #fb923c); }
.card-writing .card-illustration { background: linear-gradient(135deg, #ffd1e8, #f472b6); }
.card-puzzle .card-illustration { background: linear-gradient(135deg, #bae6fd, #38bdf8); }

.card-deco { position: absolute; font-size: 24px; }
.deco-star { top: -6px; right: -4px; animation: pulse 1.6s infinite; }
.deco-cloud { bottom: -4px; left: -8px; }
.deco-cookie { top: -4px; right: -4px; }
.deco-milk { bottom: -2px; left: -6px; }
.deco-sparkle { top: -6px; right: -4px; }
.deco-flower { bottom: -2px; left: -6px; }

@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.2); } }

.game-card h2 {
  margin: 0; font-size: 24px; font-weight: 800; color: var(--blue-d);
}

.game-card p {
  margin: 6px 0 14px; font-size: 14px; font-weight: 600; color: #7284a8;
  line-height: 1.3; min-height: 38px;
}

.card-play-tag {
  background: linear-gradient(135deg, #ff9ec4, var(--pink-d));
  color: #ffffff;
  border-radius: 999px;
  padding: 7px 22px;
  font-size: 17px; font-weight: 800;
  box-shadow: 0 4px 0 #cc4d83;
}

/* ============================================================
   PANTALLA 2: JUEGO DE VUELO
   ============================================================ */
canvas#game { display: block; position: fixed; inset: 60px 0 0 0; }

#hud {
  position: fixed; top: 72px; left: 16px; right: 90px;
  display: flex; align-items: center; gap: 16px; pointer-events: none;
  z-index: 10;
}
.pill {
  background: rgba(255, 255, 255, .88);
  border: 4px solid #fff;
  box-shadow: 0 4px 0 rgba(107, 143, 199, .35);
  border-radius: 999px; padding: 2px 22px 2px 14px;
  font-size: 38px; font-weight: 800; line-height: 1.1;
  display: flex; align-items: center; gap: 8px;
}
.star-ico { color: #ffcc33; text-shadow: 0 2px 0 #f0a500; }

#progress { display: flex; gap: clamp(3px, 0.8vw, 6px); flex-wrap: nowrap; }
#progress span {
  width: clamp(14px, 3.4vw, 24px); height: clamp(14px, 3.4vw, 24px); border-radius: 50%; flex: none;
  background: rgba(255, 255, 255, .55); border: 3px solid #fff;
  transition: transform .2s;
}
#progress span.on {
  background: radial-gradient(circle at 35% 35%, #fff6b0, #ffcc33 60%, #f0a500);
  animation: pop .35s ease-out;
}
@keyframes pop { 0% { transform: scale(.4); } 60% { transform: scale(1.35); } 100% { transform: scale(1); } }

#topbtns { position: fixed; top: 72px; right: 16px; z-index: 10; }
.round {
  width: 58px; height: 58px; border-radius: 50%;
  border: 4px solid #fff; background: rgba(255, 255, 255, .88);
  color: var(--blue); font: 800 20px var(--font); cursor: pointer;
  box-shadow: 0 4px 0 rgba(107, 143, 199, .35);
}

#micmeter {
  position: fixed; left: 14px; bottom: 20%; width: 18px; height: 35%;
  background: rgba(255, 255, 255, .5); border: 3px solid #fff; border-radius: 12px; overflow: hidden;
  z-index: 10;
}
#micfill { position: absolute; bottom: 0; left: 0; right: 0; height: 0%; background: linear-gradient(#bfe6ff, #6fb8ff); }

#heard {
  position: fixed; bottom: max(14px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  background: rgba(255, 255, 255, .94); border: 3px solid #b3e5fc; border-radius: 999px; padding: 6px 20px;
  font-size: 20px; font-weight: 800; color: #0288d1; pointer-events: none; max-width: 85vw;
  box-shadow: 0 4px 12px rgba(2, 136, 209, 0.25); z-index: 10;
}

#cheer {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: min(18vw, 130px); font-weight: 800; color: #fff; pointer-events: none;
  text-shadow: 0 6px 0 var(--pink-d), 0 0 30px rgba(255, 143, 191, .8);
  animation: cheer 2.4s ease-out forwards; z-index: 20;
}
@keyframes cheer {
  0% { transform: scale(.2) rotate(-10deg); opacity: 0; }
  15% { transform: scale(1.15) rotate(3deg); opacity: 1; }
  25% { transform: scale(1) rotate(0); }
  80% { opacity: 1; }
  100% { transform: scale(1.1) translateY(-40px); opacity: 0; }
}

.overlay {
  position: fixed; inset: 60px 0 0 0; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 45%, rgba(255,255,255,.94), rgba(159, 211, 255, .92));
  backdrop-filter: blur(4px); z-index: 30;
}
.card {
  background: #fff; border: 6px solid #fff; border-radius: 40px;
  box-shadow: 0 10px 0 rgba(107, 143, 199, .35), 0 20px 40px rgba(75, 95, 143, .25);
  padding: 24px 28px; text-align: center; width: min(92vw, 440px);
}
.card canvas { width: 100%; height: 160px; display: block; margin: -10px 0 0; }
.card h1 { font-size: 32px; font-weight: 800; color: var(--blue-d); margin: 0 0 14px; }
.card h1 span { color: var(--pink-d); display: block; font-size: 22px; }

.big-btn {
  width: 96px; height: 96px; border-radius: 50%; border: 6px solid #fff;
  background: radial-gradient(circle at 35% 35%, #ffb6d5, var(--pink-d));
  color: #fff; cursor: pointer;
  box-shadow: 0 8px 0 #cc4d83, 0 12px 24px rgba(232, 103, 159, .4);
  margin: 4px auto 14px; display: flex; align-items: center; justify-content: center;
  transition: transform .1s;
}
.big-btn:active { transform: translateY(4px); box-shadow: 0 4px 0 #cc4d83; }
.tri { font-size: 40px; margin-left: 6px; }

.howto { display: flex; justify-content: space-around; margin: 10px 0 14px; }
.hint { font-size: 26px; }
.hint small { display: block; font-size: 11px; font-weight: 800; color: #8fa2c4; line-height: 1.1; margin-top: 2px; }
.hint.off { opacity: .28; filter: grayscale(1); }

.parents { text-align: left; margin-top: 10px; border-top: 2px dashed #e2ebf8; padding-top: 10px; }
.parents summary { font-size: 13px; font-weight: 800; color: #8fa2c4; cursor: pointer; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip {
  background: #f0f5ff; border: 2px solid #d5e4ff; border-radius: 999px;
  padding: 4px 10px; font: 700 12px var(--font); color: var(--blue-d); cursor: pointer;
}
.chip.on { background: #e8f7ee; border-color: #8be0a4; color: #237b42; }
.chip.err { background: #ffe8ec; border-color: #ff9fb0; color: #b3263e; }
.chip.na { opacity: .35; pointer-events: none; }
.status { font-size: 12px; color: var(--blue-d); min-height: 16px; margin: 6px 0 0; }

/* ============================================================
   PANTALLA 3: PASTELERÍA DE NÚMEROS (Sumas y Restas con Milk)
   ============================================================ */
#screen-math {
  background: linear-gradient(180deg, #fff0f7 0%, #eef5ff 100%);
  align-items: center;
  justify-content: flex-start;
  padding: 16px;
}

.math-wrap {
  width: 100%; max-width: 720px;
  display: flex; flex-direction: column; align-items: center;
}

.math-top-bar {
  display: flex; justify-content: space-between; align-items: center;
  width: 100%; margin-bottom: 12px; flex-wrap: wrap; gap: 10px;
}

.math-age-tier-row {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
}
.math-tier-title {
  font-size: 13px; font-weight: 800; color: #475569;
}
.math-tier-btn {
  background: #ffffff; border: 2.5px solid #cbd5e1; border-radius: 999px;
  padding: 4px 12px; font: 800 13px var(--font); color: #475569; cursor: pointer;
  box-shadow: 0 2px 0 #94a3b8; transition: transform 0.15s, background-color 0.15s, border-color 0.15s;
}
.math-tier-btn:hover {
  transform: translateY(-1px);
}
.math-tier-btn.active {
  background: #3b82f6; color: #ffffff; border-color: #2563eb;
  box-shadow: 0 2px 0 #1d4ed8;
}

.mode-toggles { display: flex; gap: 8px; flex-wrap: wrap; }
.mode-btn {
  background: #ffffff; border: 3px solid #ffd1e3; border-radius: 999px;
  padding: 5px 14px; font: 800 15px var(--font); color: var(--pink-d);
  cursor: pointer; box-shadow: 0 3px 0 #ffb6d2;
}
.mode-btn.active {
  background: var(--pink-d); color: #ffffff; border-color: #ffffff;
  box-shadow: 0 3px 0 #cc4d83;
}

.math-progress-pills { display: flex; gap: 6px; }
.math-star-pill {
  font-size: 24px; opacity: 0.35; transition: transform 0.2s, opacity 0.2s;
}
.math-star-pill.done { opacity: 1; transform: scale(1.2); }

.bakery-stage {
  background: rgba(255, 255, 255, 0.95);
  border: 5px solid #ffffff; border-radius: 36px;
  box-shadow: 0 8px 0 rgba(232, 103, 159, 0.15), 0 16px 36px rgba(75, 95, 143, 0.12);
  width: 100%; padding: 18px 16px;
  display: flex; align-items: center; justify-content: space-around;
  margin-bottom: 16px; position: relative;
}

.baker-char {
  display: flex; flex-direction: column; align-items: center;
  width: 140px; text-align: center;
}

.cinna-avatar-wrap { width: 120px; height: 95px; }
.milk-avatar-wrap { width: 120px; height: 95px; }
.official-baker-img {
  width: 100%; height: 100%; object-fit: contain;
  filter: drop-shadow(0 4px 6px rgba(0,0,0,0.1));
}

.char-bubble {
  background: #ffffff; border: 3px solid #ffb6d2; border-radius: 16px;
  padding: 4px 10px; font-size: 14px; font-weight: 800; color: var(--pink-d);
  box-shadow: 0 3px 0 #ffd6e5; margin-top: 6px; white-space: nowrap;
  transition: transform 0.2s, background-color 0.2s;
}

.char-bubble.highlight-speech {
  background: #fff9c4; border-color: #fbc02d; color: #e65100;
  transform: scale(1.1);
}

.curious-tilt {
  animation: milkCurious 1.8s ease-in-out;
}
@keyframes milkCurious {
  0%, 100% { transform: rotate(0); }
  25% { transform: rotate(-12deg) scale(1.08); }
  75% { transform: rotate(10deg) scale(1.08); }
}

.party-jump {
  animation: partyJump 0.8s ease-in-out infinite alternate;
}
@keyframes partyJump {
  0% { transform: translateY(0); }
  100% { transform: translateY(-16px); }
}

.bakery-tray-container {
  background: #fff3e0; border: 4px dashed #ffb74d; border-radius: 28px;
  padding: 12px 16px; display: flex; flex-direction: column; align-items: center;
  box-shadow: inset 0 2px 6px rgba(255, 183, 77, 0.2);
}
.tray-hint {
  font-size: 13px; font-weight: 800; color: #e65100; margin-bottom: 6px;
}
.treat-cluster { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; max-width: 220px; }
.treat-cluster.group-mult { max-width: 380px; gap: 10px; }
.mult-group-box {
  background: rgba(255, 255, 255, 0.85);
  border: 2px dashed #f59e0b;
  border-radius: 18px;
  padding: 6px;
  display: flex;
  gap: 6px;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(245, 158, 11, 0.15);
}
.extra-count-badge {
  background: #ef4444; color: #ffffff;
  font-size: 13px; font-weight: 800;
  padding: 3px 9px; border-radius: 999px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.15);
  display: inline-flex; align-items: center; align-self: center;
}
.math-sign-symbol { font-size: 26px; color: #ff9800; font-weight: 800; }

.treat-btn {
  background: #ffffff; border: 3px solid #ffe0b2; border-radius: 50%;
  width: 54px; height: 54px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 30px; box-shadow: 0 4px 0 #ffe0b2; position: relative;
  transition: transform 0.15s;
}
.treat-btn:active, .treat-btn.pop-counted { transform: scale(1.22); }
.treat-btn.glow-count {
  border-color: #ff4081; box-shadow: 0 0 16px #ff4081; transform: scale(1.25);
}

.treat-count {
  position: absolute; top: -6px; right: -6px;
  background: var(--pink-d); color: #fff;
  border-radius: 50%; width: 22px; height: 22px;
  font-size: 13px; font-weight: 800; display: flex; align-items: center; justify-content: center;
  border: 2px solid #fff;
}

.eaten-item { opacity: 0.45; filter: grayscale(0.5); pointer-events: none; }
.eaten-badge { position: absolute; font-size: 16px; top: -4px; right: -4px; }

.math-question-panel { text-align: center; width: 100%; max-width: 520px; margin: 0 auto; }
.math-question-panel h2 {
  font-family: var(--font);
  margin: 0 0 14px;
  font-size: clamp(20px, 4.5vw, 28px);
  color: #5d4037;
  font-weight: 800;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.8);
}
.options-grid {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  width: 100%;
}
.math-ans-btn {
  background: #ffffff;
  border: 4px solid #b3e5fc;
  border-radius: 26px;
  min-width: 82px;
  max-width: 110px;
  flex: 1 1 82px;
  height: 96px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 0 #81d4fa, 0 10px 20px rgba(129, 212, 250, 0.25);
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
  font-family: var(--font);
}
.math-ans-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #81d4fa; }
.math-ans-btn.correct { background: #e8f5e9; border-color: #81c784; box-shadow: 0 6px 0 #66bb6a; }
.math-ans-number {
  font-family: "Baloo 2", "Nunito", cursive, sans-serif !important;
  font-size: 42px;
  font-weight: 800;
  color: #0288d1;
  line-height: 1;
  letter-spacing: -0.5px;
}
.math-ans-number.double-digit {
  font-size: 34px;
  letter-spacing: -1px;
}
.math-ans-dots {
  font-family: var(--font);
  font-size: 13px;
  font-weight: 700;
  margin-top: 4px;
  color: #64748b;
}

.wobble-friendly {
  animation: wobbleFriend 0.5s ease-in-out;
}
@keyframes wobbleFriend {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px) rotate(-4deg); }
  75% { transform: translateX(8px) rotate(4deg); }
}

.math-victory-box {
  background: #ffffff; border: 6px solid #ffb6d2; border-radius: 36px;
  padding: 26px; text-align: center; max-width: 520px;
  box-shadow: 0 12px 0 #ffd6e5, 0 20px 40px rgba(0,0,0,0.1); margin-top: 24px;
}
.victory-confetti-badge { font-size: 24px; font-weight: 800; color: var(--pink-d); }
.victory-bakers-row { display: flex; align-items: center; justify-content: center; gap: 20px; margin: 16px 0; }
.victory-mascot-cinna img, .victory-mascot-milk img { width: 120px; height: 90px; object-fit: contain; }
.giant-cake { font-size: 60px; }
.btn-math-replay {
  background: linear-gradient(135deg, #ff8fbf, #e8679f);
  color: #fff; border: 4px solid #fff; border-radius: 999px;
  padding: 12px 36px; font: 800 22px var(--font); cursor: pointer;
  box-shadow: 0 6px 0 #d0538a;
}

/* ============================================================
   PANTALLA 4: TALLER DE DIBUJO (coloring.js)
   ============================================================ */
#screen-coloring {
  background: linear-gradient(180deg, #f4f8ff 0%, #fff0f7 100%);
  align-items: center;
  justify-content: flex-start;
  padding: 12px;
}

.color-studio-wrap {
  width: 100%; max-width: 760px;
  display: flex; flex-direction: column; align-items: center;
}

.templates-scroll-bar {
  display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; justify-content: center;
}
.sheet-tab-btn {
  background: #ffffff; border: 3px solid #d9e6ff; border-radius: 999px;
  padding: 5px 18px; font: 800 16px var(--font); color: var(--blue);
  cursor: pointer; box-shadow: 0 3px 0 #cadbfb;
  transition: transform 0.15s, background 0.15s;
}
.sheet-tab-btn.active {
  background: var(--pink); border-color: #ffffff; color: #ffffff;
  box-shadow: 0 4px 0 var(--pink-d);
}

.coloring-board-stage {
  background: #ffffff; border: 6px solid #ffffff; border-radius: 32px;
  box-shadow: 0 8px 0 rgba(107, 143, 199, 0.18), 0 16px 36px rgba(75, 95, 143, 0.12);
  width: 100%; max-width: 600px;
  display: flex; flex-direction: column; align-items: center;
  position: relative; overflow: hidden; padding-bottom: 10px;
}
.sheet-title-tag {
  font-size: 15px; font-weight: 800; color: #5c3d2e; padding: 6px 0 2px;
}

.interactive-canvas-box {
  width: 100%; aspect-ratio: 6 / 5; position: relative;
  background: #ffffff;
  border-radius: 20px;
  overflow: hidden;
  isolation: isolate;
  touch-action: none;
  cursor: none;
}
.freehand-draw-canvas {
  position: absolute; inset: 0; width: 100%; height: 100%;
  touch-action: none; cursor: none; z-index: 1;
}
.bw-sheet-overlay, .bw-sheet-img {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: contain; pointer-events: none; z-index: 2;
  mix-blend-mode: multiply;
}
.brush-cursor-indicator {
  position: absolute;
  top: 0; left: 0;
  pointer-events: none;
  z-index: 20;
  transform: translate(-50%, -50%);
  display: none;
  box-sizing: border-box;
  transition: width 0.08s ease-out, height 0.08s ease-out, border-color 0.1s ease-out;
}
.stamp-pop-particle {
  position: absolute;
  pointer-events: none;
  font-size: 24px;
  transform: translate(-50%, -50%);
  animation: stampParticlePop 0.6s cubic-bezier(0.1, 0.8, 0.3, 1) forwards;
  z-index: 30;
  user-select: none;
}
@keyframes stampParticlePop {
  0% { transform: translate(-50%, -50%) scale(0.3); opacity: 1; }
  100% { transform: translate(calc(-50% + var(--tx)), calc(-50% + var(--ty))) scale(1.4); opacity: 0; }
}

.coloring-controls-bar {
  background: rgba(255, 255, 255, 0.95); border: 4px solid #ffffff;
  border-radius: 28px; box-shadow: 0 6px 0 rgba(107, 143, 199, 0.15);
  padding: 10px 16px; margin-top: 10px; width: 100%; max-width: 600px;
  display: flex; flex-direction: column; gap: 8px; align-items: center;
}

.tools-selector, .brush-size-selector, .stamps-picker, .aux-actions-row {
  display: flex; gap: 8px; justify-content: center; flex-wrap: wrap;
}

.tool-btn, .size-pill, .stamp-opt-btn, .aux-btn {
  background: #f0f5ff; border: 3px solid #d5e4ff; border-radius: 999px;
  padding: 5px 14px; font: 800 14px var(--font); color: var(--blue-d);
  cursor: pointer; box-shadow: 0 3px 0 #cadbfb;
}
.tool-btn.active, .size-pill.active, .stamp-opt-btn.active {
  background: #fff0f5; border-color: #ffb6d2; color: var(--pink-d);
  box-shadow: 0 3px 0 #ffd6e5;
}
.aux-btn.special {
  background: #e8f5e9; border-color: #a5d6a7; color: #2e7d32;
}

.color-swatches-row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.swatch-btn {
  width: 40px; height: 40px; border-radius: 50%;
  border: 4px solid #ffffff; cursor: pointer;
  box-shadow: 0 3px 6px rgba(0,0,0,0.15);
  transition: transform 0.15s;
}
.swatch-btn.active {
  transform: scale(1.24); border-color: #5c3d2e;
  box-shadow: 0 0 0 3px #ffffff, 0 4px 10px rgba(0,0,0,0.25);
}

/* ============================================================
   PANTALLA 5: MEMORICE DE SANRIO (memory.js)
   ============================================================ */
#screen-memory {
  background: linear-gradient(180deg, #f0e6ff 0%, #fff0f7 100%);
  align-items: center;
  justify-content: flex-start;
  padding: 16px;
}

.memory-wrap {
  width: 100%; max-width: 680px;
  display: flex; flex-direction: column; align-items: center;
}

.memory-top-bar {
  display: flex; justify-content: space-between; align-items: center;
  width: 100%; margin-bottom: 14px; flex-wrap: wrap; gap: 8px;
}
.diff-selector { display: flex; gap: 8px; }
.diff-btn {
  background: #ffffff; border: 3px solid #d8b4fe; border-radius: 999px;
  padding: 5px 14px; font: 800 14px var(--font); color: #7e22ce;
  cursor: pointer; box-shadow: 0 3px 0 #c084fc;
}
.diff-btn.active {
  background: #7e22ce; color: #ffffff; border-color: #ffffff;
}

.memory-stats-pill {
  background: #ffffff; border: 3px solid #ffb6d2; border-radius: 999px;
  padding: 4px 16px; font-size: 16px; font-weight: 800; color: var(--pink-d);
}

.memory-grid {
  display: grid; gap: 14px; width: 100%; justify-content: center;
  perspective: 1000px;
}
.grid-size-6 { grid-template-columns: repeat(3, minmax(90px, 140px)); }
.grid-size-8 { grid-template-columns: repeat(4, minmax(80px, 130px)); }
.grid-size-12 { grid-template-columns: repeat(4, minmax(75px, 120px)); }
.grid-size-16 { grid-template-columns: repeat(4, minmax(65px, 110px)); }

.memory-card-slot {
  aspect-ratio: 3 / 4; cursor: pointer; perspective: 1000px;
}

.card-inner {
  position: relative; width: 100%; height: 100%;
  text-align: center; transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  transform-style: preserve-3d;
}

.memory-card-slot.flipped .card-inner,
.memory-card-slot.matched .card-inner {
  transform: rotateY(180deg);
}

.card-back, .card-front {
  position: absolute; inset: 0; width: 100%; height: 100%;
  -webkit-backface-visibility: hidden; backface-visibility: hidden;
  border-radius: 24px; border: 4px solid #ffffff;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  box-shadow: 0 6px 0 rgba(107, 143, 199, 0.2), 0 10px 20px rgba(0,0,0,0.08);
}

.card-back {
  background: linear-gradient(135deg, #ffd1dc, #b3e5fc);
  font-size: 38px; color: #ffffff;
}
.card-back-sparkle { font-size: 16px; position: absolute; top: 8px; right: 8px; }

.card-front {
  transform: rotateY(180deg);
  padding: 6px;
}
.card-art-box {
  width: 90px; height: 75px; display: flex; align-items: center; justify-content: center;
}
.memory-char-sprite {
  max-width: 100%; max-height: 100%; object-fit: contain;
  filter: drop-shadow(0 4px 6px rgba(0,0,0,0.12));
}

.card-char-name { font-size: 14px; font-weight: 800; color: #5c3d2e; margin-top: 4px; }
.card-char-emoji { font-size: 18px; margin-top: 2px; }

.memory-card-slot.matched .card-front {
  border-color: #ffe066; box-shadow: 0 0 16px rgba(255, 224, 102, 0.8);
}

.memory-victory-modal {
  background: #ffffff; border: 6px solid #d8b4fe; border-radius: 36px;
  padding: 26px; text-align: center; max-width: 500px;
  box-shadow: 0 12px 0 #c084fc, 0 20px 40px rgba(0,0,0,0.12); margin-top: 24px;
}
.victory-ribbon { font-size: 22px; font-weight: 800; color: #7e22ce; }
.victory-mascot-row { display: flex; align-items: center; justify-content: center; gap: 16px; margin: 16px 0; }
.victory-bounce-cinna { width: 110px; height: 85px; object-fit: contain; }
.trophy-badge { font-size: 54px; }
.victory-action-buttons { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 16px; }
.btn-play-again-mem {
  background: #7e22ce; color: #fff; border: 3px solid #fff; border-radius: 999px;
  padding: 8px 20px; font: 800 16px var(--font); cursor: pointer;
  box-shadow: 0 4px 0 #581c87;
}

/* ============================================================
   PANTALLA 6: SUPER CINNAMOROLL RUN (platformer.js)
   ============================================================ */
#screen-platformer {
  overflow: hidden; background: #9fd3ff;
  align-items: center; justify-content: center;
}
/* Sólo visible cuando está activa (antes forzaba display:flex y tapaba el hub) */
#screen-platformer.active { display: flex; }
.platformer-wrapper {
  width: 100%; height: 100%; position: relative;
  display: flex; align-items: center; justify-content: center;
}
#platformerCanvas {
  max-width: 100%; max-height: 100%;
  aspect-ratio: 16 / 9;
  object-fit: contain; display: block;
}

.plat-hud {
  position: absolute; top: 12px; left: 14px; right: 14px;
  display: flex; justify-content: space-between; align-items: center;
  pointer-events: none; z-index: 10;
  gap: 8px;
}
.plat-score-pill {
  background: rgba(255, 255, 255, 0.94); border: 3px solid #fff; border-radius: 999px;
  padding: 4px 16px; font-size: 20px; font-weight: 800; color: #e91e63;
  display: flex; align-items: center; gap: 8px; box-shadow: 0 4px 0 rgba(0,0,0,0.1);
  pointer-events: auto;
}
.plat-progress-bar-wrap {
  display: flex; align-items: center; gap: 8px;
  background: rgba(255, 255, 255, 0.94); border: 2.5px solid #fff; border-radius: 999px;
  padding: 4px 12px; box-shadow: 0 4px 0 rgba(0,0,0,0.08); pointer-events: auto;
  flex: 1; max-width: 240px;
}
.plat-progress-track {
  position: relative; flex: 1; height: 10px;
  background: #e2e8f0; border-radius: 999px; overflow: visible;
}
.plat-progress-fill {
  height: 100%; background: linear-gradient(90deg, #ff9ec4, #f472b6, #38bdf8);
  border-radius: 999px; transition: width 0.1s linear;
}
.plat-progress-avatar {
  position: absolute; top: -8px; width: 26px; height: 22px;
  object-fit: contain; transition: left 0.1s linear;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,0.25));
}
.plat-prog-flag, .plat-prog-meta {
  font-size: 16px; line-height: 1;
}
.plat-hero-pill {
  background: rgba(255, 255, 255, 0.94); border: 3px solid #fff; border-radius: 999px;
  padding: 4px 14px; font-size: 15px; font-weight: 800; color: #47689e;
  display: flex; align-items: center; gap: 8px; box-shadow: 0 4px 0 rgba(0,0,0,0.1);
  pointer-events: auto; cursor: pointer; user-select: none; -webkit-user-select: none;
  transition: transform 0.12s, box-shadow 0.12s;
}
.plat-hero-pill:active {
  transform: scale(0.96); box-shadow: 0 1px 0 rgba(0,0,0,0.1);
}
.plat-hud-avatar {
  width: 32px; height: 26px; object-fit: contain;
}
.btn-plat-switch-hero {
  background: #f0f7ff; border: 2px solid #bcd7ff; border-radius: 999px;
  padding: 3px 10px; font: 800 13px var(--font); color: #0288d1;
  cursor: pointer; box-shadow: 0 2px 0 #90caf9; pointer-events: none;
}
.plat-hint-tag {
  background: rgba(255, 255, 255, 0.9); border: 2px solid #fff; border-radius: 999px;
  padding: 4px 14px; font-size: 13px; font-weight: 800; color: #0288d1;
  box-shadow: 0 3px 0 rgba(0,0,0,0.08);
}

.plat-touch-controls {
  position: absolute; bottom: 20px; left: 16px; right: 16px;
  display: flex; justify-content: space-between; align-items: flex-end;
  pointer-events: none; z-index: 20;
}
.plat-dpad, .plat-actions { pointer-events: auto; display: flex; gap: 14px; }

.plat-btn {
  background: rgba(255, 255, 255, 0.88); border: 4px solid #ffffff;
  border-radius: 50%; width: 72px; height: 72px;
  display: flex; align-items: center; justify-content: center;
  font-size: 32px; color: var(--blue-d); cursor: pointer;
  box-shadow: 0 6px 0 rgba(107, 143, 199, 0.35); touch-action: none;
}
.plat-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(107, 143, 199, 0.35); }

.plat-btn.btn-jump {
  width: 90px; height: 90px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #ffb6d5, var(--pink-d));
  color: #fff; flex-direction: column; font-size: 28px;
  box-shadow: 0 8px 0 #cc4d83;
}
.jump-txt { font-size: 12px; font-weight: 800; margin-top: -2px; }

/* Modal de selección de personaje para Platformer */
.plat-char-modal {
  position: fixed; inset: 0;
  background: rgba(30, 41, 59, 0.75);
  backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  z-index: 9999; padding: 12px;
  touch-action: pan-y;
}
.plat-char-modal-box {
  background: #ffffff; border: 5px solid #ffffff; border-radius: 28px;
  box-shadow: 0 16px 40px rgba(0,0,0,0.3);
  padding: 16px 14px; text-align: center; max-width: 680px; width: 100%;
  max-height: 88vh; overflow-y: auto; -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}
.plat-modal-header h2 {
  margin: 6px 0 12px; font-size: clamp(18px, 3.5vw, 26px);
  color: var(--blue-d); font-weight: 800;
}
.plat-modal-badge {
  background: #fff0f5; border: 2px solid #ffb6d2; border-radius: 999px;
  padding: 3px 14px; font-size: 13px; font-weight: 800; color: var(--pink-d);
  display: inline-block;
}
.btn-plat-modal-close {
  background: #f1f5f9; border: 2px solid #cbd5e1; border-radius: 999px;
  padding: 4px 14px; font: 800 13px var(--font); color: #475569;
  cursor: pointer; margin-left: 8px; transition: transform 0.15s, background 0.15s, color 0.15s;
  display: inline-block; vertical-align: middle;
}
.btn-plat-modal-close:hover {
  background: #fee2e2; border-color: #fca5a5; color: #b91c1c; transform: scale(1.05);
}
.plat-heroes-select-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px; width: 100%; margin-top: 10px;
}
.plat-hero-option {
  background: #f8fbff; border: 3px solid #d9e6ff; border-radius: 20px;
  padding: 10px 8px; width: auto; cursor: pointer;
  display: flex; flex-direction: column; align-items: center;
  position: relative; transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
  box-shadow: 0 4px 0 rgba(107, 143, 199, 0.15);
  user-select: none; -webkit-user-select: none;
}
.plat-hero-option:hover, .plat-hero-option.active {
  transform: translateY(-2px);
  border-color: #ff8fbf; background: #fff8fc;
  box-shadow: 0 6px 0 rgba(232, 103, 159, 0.25);
}
.plat-opt-badge {
  position: absolute; top: 6px; left: 6px;
  background: #ffffff; border: 1.5px solid #ffb6d2; border-radius: 999px;
  padding: 2px 6px; font-size: 10px; font-weight: 800; color: var(--pink-d);
}
.plat-opt-img-box {
  width: 76px; height: 60px; display: flex; align-items: center; justify-content: center;
  margin: 10px 0 4px;
}
.plat-opt-img-box img {
  max-width: 100%; max-height: 100%; object-fit: contain;
  filter: drop-shadow(0 3px 5px rgba(0,0,0,0.1));
}
.plat-hero-option h3 {
  margin: 2px 0 2px; font-size: 15px; font-weight: 800; color: var(--blue-d);
}
.plat-hero-option p {
  font-size: 11px; color: #64748b; font-weight: 600; line-height: 1.2;
  margin: 0 0 6px; min-height: 26px;
}
.btn-pick-plat-hero {
  background: linear-gradient(135deg, #ff9ec4, var(--pink-d));
  color: #fff; border: 2px solid #fff; border-radius: 999px;
  padding: 4px 12px; font: 800 12px var(--font); cursor: pointer;
  box-shadow: 0 2px 0 #cc4d83; width: 100%; margin-top: auto;
}

.plat-city-pill {
  background: rgba(255, 255, 255, 0.94); border: 2.5px solid #fff; border-radius: 999px;
  padding: 3px 12px; font-size: 14px; font-weight: 800; color: #0284c7;
  display: flex; align-items: center; gap: 6px; box-shadow: 0 4px 0 rgba(0,0,0,0.1);
  pointer-events: auto; cursor: pointer; user-select: none; -webkit-user-select: none;
  transition: transform 0.12s, box-shadow 0.12s;
}
.plat-city-pill:active {
  transform: scale(0.96); box-shadow: 0 1px 0 rgba(0,0,0,0.1);
}
.plat-city-badge {
  font-size: 16px;
}
.btn-plat-switch-city {
  background: #f0f9ff; border: 2px solid #bae6fd; border-radius: 999px;
  padding: 3px 8px; font: 800 12px var(--font); color: #0284c7;
  cursor: pointer; box-shadow: 0 2px 0 #7dd3fc; pointer-events: none;
}

/* Modal de Pasaporte / Selección de Ciudad */
.plat-city-modal {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  z-index: 9999; padding: 12px;
  touch-action: pan-y;
}
.plat-city-modal-box {
  background: #ffffff; border: 5px solid #ffffff; border-radius: 28px;
  box-shadow: 0 16px 40px rgba(0,0,0,0.3);
  padding: 16px 14px; text-align: center; max-width: 720px; width: 100%;
  max-height: 88vh; overflow-y: auto; -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}
.plat-cities-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px; width: 100%; margin-top: 10px;
}
.plat-city-card {
  background: #f0f9ff; border: 3px solid #bae6fd; border-radius: 20px;
  padding: 10px 8px; width: auto; cursor: pointer;
  display: flex; flex-direction: column; align-items: center;
  position: relative; transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
  box-shadow: 0 4px 0 #7dd3fc;
}
.plat-city-card:hover, .plat-city-card.active {
  transform: translateY(-2px); border-color: #0284c7; background: #e0f2fe;
  box-shadow: 0 6px 0 rgba(14, 165, 233, 0.25);
}
.plat-city-card-badge {
  background: #ffffff; border: 2px solid #cbd5e1; border-radius: 999px;
  padding: 2px 10px; font-size: 11px; font-weight: 800; color: #475569; margin-bottom: 6px;
}
.plat-city-card.active .plat-city-card-badge {
  border-color: #38bdf8; color: #0284c7; background: #e0f2fe;
}
.plat-city-card-icon {
  font-size: 38px; line-height: 1; margin: 4px 0 6px;
}
.plat-city-card h3 {
  margin: 2px 0 2px; font-size: 18px; font-weight: 800; color: #1e293b;
}
.plat-city-card h4 {
  margin: 0 0 6px; font-size: 12px; font-weight: 700; color: #0284c7;
}
.plat-city-card p {
  font-size: 11px; color: #64748b; font-weight: 600; line-height: 1.25;
  margin: 0 0 10px; min-height: 38px; text-align: center;
}
.btn-travel-city {
  background: linear-gradient(135deg, #38bdf8, #0284c7);
  color: #fff; border: 2px solid #fff; border-radius: 999px;
  padding: 6px 14px; font: 800 13px var(--font); cursor: pointer;
  box-shadow: 0 3px 0 #0369a1; width: 100%; margin-top: auto;
}

.plat-victory-overlay {
  position: absolute; inset: 0; background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center; z-index: 30;
  padding: 16px;
}
.plat-victory-card {
  background: #fff; border: 6px solid #fff; border-radius: 36px;
  padding: 24px; text-align: center; max-width: 560px; width: 100%;
  box-shadow: 0 16px 40px rgba(0,0,0,0.25);
}
.plat-victory-stars {
  font-size: 24px; margin: 6px 0; letter-spacing: 4px; color: #f59e0b; font-weight: 800;
}
.plat-passport-stamp {
  background: #fdf2f8; border: 2.5px dashed #f472b6; border-radius: 14px;
  padding: 6px 16px; margin: 8px auto 12px; display: inline-flex; flex-direction: column;
  color: #be185d; font-size: 11px; font-weight: 800;
}
.plat-passport-stamp strong {
  font-size: 15px; color: #9d174d;
}
.picnic-friends-stage {
  display: flex; align-items: center; justify-content: center; gap: 10px; margin: 14px 0;
  flex-wrap: wrap;
}
.picnic-char { width: 75px; height: 62px; object-fit: contain; }
.plat-victory-actions {
  display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 16px;
}
.btn-plat-next-city {
  background: linear-gradient(135deg, #10b981, #059669);
  color: #fff; border: 3px solid #fff; border-radius: 999px;
  padding: 10px 22px; font: 800 17px var(--font); cursor: pointer;
  box-shadow: 0 5px 0 #047857; transition: transform 0.15s;
}
.btn-plat-next-city:active { transform: translateY(2px); box-shadow: 0 2px 0 #047857; }
.btn-plat-repeat-city {
  background: linear-gradient(135deg, #38bdf8, #0284c7);
  color: #fff; border: 3px solid #fff; border-radius: 999px;
  padding: 10px 18px; font: 800 15px var(--font); cursor: pointer;
  box-shadow: 0 4px 0 #0369a1; transition: transform 0.15s;
}
.btn-plat-repeat-city:active { transform: translateY(2px); box-shadow: 0 2px 0 #0369a1; }
.btn-plat-choose-city {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #fff; border: 3px solid #fff; border-radius: 999px;
  padding: 10px 18px; font: 800 15px var(--font); cursor: pointer;
  box-shadow: 0 4px 0 #b45309; transition: transform 0.15s;
}
.btn-plat-choose-city:active { transform: translateY(2px); box-shadow: 0 2px 0 #b45309; }

/* ============================================================
   PANTALLA 7: REPARTIDOR DE ROLLITOS 3D (doom.js)
   ============================================================ */
#screen-doom {
  overflow: hidden; background: #9fd3ff;
  align-items: center; justify-content: center;
}
/* Sólo visible cuando está activa (antes forzaba display:flex y tapaba el hub) */
#screen-doom.active { display: flex; }

/* Pantalla de Selección de Personaje */
.doom-char-select-wrap {
  width: 100%; max-width: 900px; margin: auto; padding: 20px; text-align: center;
}
.char-select-header h1 {
  margin: 6px 0; font-size: clamp(26px, 4vw, 38px); color: var(--blue-d);
}
.char-select-header p {
  margin: 0 0 20px; font-size: 16px; color: #637ea6; font-weight: 700;
}
.select-badge {
  background: #fff0f5; border: 2px solid #ffb6d2; border-radius: 999px;
  padding: 4px 16px; font-size: 14px; font-weight: 800; color: var(--pink-d);
}
.char-heroes-grid, .char-select-cards-row {
  display: flex; gap: 20px; justify-content: center; flex-wrap: wrap;
  align-items: stretch; margin-top: 10px;
}
.char-hero-card {
  background: #ffffff; border: 5px solid #ffffff; border-radius: 32px;
  box-shadow: 0 8px 0 rgba(107, 143, 199, 0.2), 0 16px 30px rgba(0,0,0,0.08);
  padding: 20px 16px; width: 260px; max-width: 100%; display: flex; flex-direction: column;
  align-items: center; cursor: pointer; transition: transform 0.2s, border-color 0.2s;
  position: relative;
}
.char-hero-card:hover {
  transform: translateY(-6px) scale(1.02); border-color: #ffb6d2;
}
.hero-card-badge, .hero-badge {
  position: absolute; top: 12px; left: 14px; background: #f0f5ff;
  border-radius: 999px; padding: 2px 10px; font-size: 12px; font-weight: 800; color: var(--blue);
}
.hero-card-avatar, .hero-img-box {
  width: 140px; height: 110px; display: flex; align-items: center; justify-content: center;
  margin: 14px 0 8px; overflow: hidden;
}
.hero-card-avatar img, .hero-img-box img {
  max-width: 100%; max-height: 100%; object-fit: contain; display: block;
}
.char-hero-card h2 { margin: 4px 0; font-size: 24px; color: var(--blue-d); font-weight: 800; }
.hero-card-weapon, .hero-treat-tag {
  background: #fff8e1; border: 2px solid #ffe082; border-radius: 999px;
  padding: 3px 12px; font-size: 13px; font-weight: 800; color: #f57f17; margin-bottom: 8px;
}
.weapon-pill { display: inline-block; }
.hero-card-desc, .char-hero-card p {
  font-size: 13px; color: #7284a8; font-weight: 600; min-height: 38px; line-height: 1.3;
  margin: 0 0 12px;
}
.btn-select-hero, .btn-pick-hero {
  background: linear-gradient(135deg, #ff9ec4, var(--pink-d));
  color: #fff; border: 3px solid #fff; border-radius: 999px;
  padding: 8px 18px; font: 800 15px var(--font); cursor: pointer;
  box-shadow: 0 4px 0 #cc4d83; width: 100%; margin-top: auto;
}

/* Pantalla de Juego 3D */
.doom-wrapper {
  width: 100%; height: 100%; position: relative;
  display: flex; align-items: center; justify-content: center;
}
#doomCanvas {
  max-width: 100%; max-height: 100%;
  aspect-ratio: 16 / 10;
  object-fit: contain; display: block;
}

.doom-hud {
  position: absolute; top: 12px; left: 16px; right: 16px;
  display: flex; justify-content: space-between; align-items: center;
  z-index: 10; pointer-events: none;
}
.doom-score-pill, .doom-hero-pill {
  background: rgba(255, 255, 255, 0.94); border: 3px solid #fff; border-radius: 999px;
  padding: 4px 16px; font-size: 16px; font-weight: 800; color: #e91e63;
  box-shadow: 0 4px 0 rgba(0,0,0,0.1);
}
.btn-change-hero {
  pointer-events: auto; background: #ffffff; border: 3px solid #b3e5fc;
  border-radius: 999px; padding: 4px 14px; font: 800 13px var(--font);
  color: #0288d1; cursor: pointer; box-shadow: 0 3px 0 #81d4fa;
}

.doom-radar-canvas {
  position: absolute; top: 58px; right: 16px; border-radius: 16px;
  border: 3px solid #ffffff; box-shadow: 0 4px 10px rgba(0,0,0,0.15); z-index: 10;
}

.cinna-firstperson-tray {
  position: absolute; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 240px; height: 130px; display: flex; justify-content: center; align-items: flex-end;
  pointer-events: none; z-index: 15; transition: transform 0.15s ease-out;
}
.tray-treat-display {
  font-size: 64px; filter: drop-shadow(0 6px 8px rgba(0,0,0,0.25));
  animation: treatFloat 1.6s ease-in-out infinite alternate;
}
@keyframes treatFloat { 0% { transform: translateY(0); } 100% { transform: translateY(-6px); } }

.hero-firstperson-paw {
  font-size: 36px; position: absolute; bottom: 6px;
  border-radius: 50%; padding: 4px; box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}
.paw-left { left: 30px; transform: rotate(-25deg); }
.paw-right { right: 30px; transform: rotate(25deg); }

.launch-recoil {
  transform: translateX(-50%) translateY(20px) scale(0.92) !important;
}

.doom-touch-controls {
  position: absolute; bottom: 16px; left: 16px; right: 16px;
  display: flex; justify-content: space-between; align-items: flex-end;
  pointer-events: none; z-index: 20;
}
.doom-dpad { pointer-events: auto; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.dpad-row { display: flex; gap: 8px; }

.doom-touch-btn {
  background: rgba(255, 255, 255, 0.88); border: 3px solid #ffffff; border-radius: 16px;
  width: 54px; height: 54px; font-size: 24px; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 0 rgba(0,0,0,0.15); cursor: pointer; touch-action: none;
}
.doom-touch-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,0.15); }

.doom-launch-big-btn {
  pointer-events: auto; width: 96px; height: 96px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #ffb6d5, #e91e63);
  color: #fff; border: 5px solid #fff; display: flex; flex-direction: column;
  align-items: center; justify-content: center; box-shadow: 0 8px 0 #ad1457;
  cursor: pointer; touch-action: none;
}
.doom-launch-big-btn:active { transform: translateY(4px); box-shadow: 0 4px 0 #ad1457; }
.launch-ico { font-size: 36px; }
.launch-label { font-size: 11px; font-weight: 800; line-height: 1; }

.doom-victory-overlay {
  position: absolute; inset: 0; background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center; z-index: 30;
}
.doom-victory-box {
  background: #fff; border: 6px solid #fff; border-radius: 36px;
  padding: 26px; text-align: center; max-width: 480px; box-shadow: 0 12px 0 rgba(0,0,0,0.2);
}
.victory-hero-celebrate img { width: 120px; height: 90px; object-fit: contain; }
.btn-doom-replay {
  background: linear-gradient(135deg, #ff9800, #f57c00);
  color: #fff; border: 4px solid #fff; border-radius: 999px;
  padding: 10px 30px; font: 800 20px var(--font); cursor: pointer;
  box-shadow: 0 6px 0 #e65100;
}

/* ============================================================
   PANTALLA 8: PALABRAS MÁGICAS (writing.js) - Taller Waldorf
   ============================================================ */
#screen-writing {
  background: linear-gradient(180deg, #fff0f5 0%, #f0f7ff 100%);
  align-items: center;
  justify-content: flex-start;
  padding: 16px;
}

.writing-wrap {
  width: 100%; max-width: 820px;
  display: flex; flex-direction: column; align-items: center;
  margin: 0 auto;
}

.writing-top-bar {
  width: 100%; display: flex; flex-direction: column; gap: 10px;
  margin-bottom: 12px;
}

.word-selector-pills {
  display: flex; gap: 8px; overflow-x: auto; padding: 4px 2px 8px;
  scrollbar-width: none;
}
.word-selector-pills::-webkit-scrollbar { display: none; }

.writing-age-tier-row {
  display: flex; gap: 8px; justify-content: center; align-items: center; flex-wrap: wrap; margin-bottom: 8px;
}
.tier-label-title {
  font-size: 13px; font-weight: 800; color: #475569;
}
.tier-chip-btn {
  background: #ffffff; border: 2.5px solid #cbd5e1; border-radius: 999px;
  padding: 4px 14px; font: 800 13px var(--font); color: #475569;
  cursor: pointer; box-shadow: 0 2px 0 #94a3b8; transition: transform 0.15s;
}
.tier-chip-btn.active {
  background: #ec4899; color: #ffffff; border-color: #ffffff;
  box-shadow: 0 3px 0 #be185d; transform: scale(1.05);
}

.sentence-chip-btn {
  background: #ffffff; border: 3px solid #c7d2fe; border-radius: 999px;
  padding: 5px 14px; font: 800 13px var(--font); color: #4338ca;
  cursor: pointer; box-shadow: 0 3px 0 #a5b4fc; white-space: nowrap;
  transition: transform 0.15s, background 0.15s; flex-shrink: 0;
}
.sentence-chip-btn.active {
  background: #4f46e5; color: #ffffff; border-color: #ffffff;
  box-shadow: 0 3px 0 #3730a3; transform: scale(1.05);
}

.distractor-badge {
  font-size: 12px; font-weight: 800; color: #db2777; background: #fdf2f8;
  padding: 2px 8px; border-radius: 999px; border: 1.5px solid #fbcfe8;
}

/* Modo Frases Mágicas */
.sentences-workshop-container {
  display: flex; flex-direction: column; align-items: center; gap: 14px; width: 100%;
}
.sentence-slots-row {
  display: flex; gap: 10px; justify-content: center; flex-wrap: wrap;
  padding: 14px 16px; background: rgba(255, 255, 255, 0.75);
  border: 3px dashed #818cf8; border-radius: 26px; min-height: 84px;
  width: 100%; max-width: 720px; align-items: center;
}
.sentence-slot {
  min-width: 90px; height: 60px; padding: 0 14px; border-radius: 20px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  position: relative; transition: transform 0.2s; cursor: pointer;
}
.sentence-slot.empty {
  background: #f8fafc; border: 3px dashed #94a3b8;
}
.sentence-slot.empty .slot-word-preview {
  font-size: 15px; font-weight: 800; color: #cbd5e1;
}
.sentence-slot.filled {
  background: #eef2ff; border: 3px solid #6366f1;
  box-shadow: 0 4px 0 #4f46e5, 0 6px 14px rgba(99, 102, 241, 0.25);
  animation: popLetter 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.sentence-slot.filled .slot-word-preview {
  font-size: 17px; font-weight: 800; color: #3730a3;
}
.sentence-slot.slot-magnet-hover {
  transform: scale(1.08); border-color: #60a5fa !important; background: #eff6ff !important;
}
.sentence-slot.slot-magnet-match {
  transform: scale(1.12); border-color: #ec4899 !important; background: #fdf2f8 !important;
  box-shadow: 0 0 22px rgba(236, 72, 153, 0.7); animation: magnetPulse 0.4s infinite alternate;
}

.sentence-bank-tray {
  width: 100%; max-width: 720px; display: flex; flex-direction: column; align-items: center; gap: 8px;
  touch-action: none;
}
.sentence-words-bank {
  display: flex; gap: 10px; justify-content: center; flex-wrap: wrap;
  padding: 12px 16px; background: rgba(238, 242, 255, 0.9);
  border: 4px solid #c7d2fe; border-radius: 28px; width: 100%;
  touch-action: none;
}
.sentence-pill-btn {
  background: radial-gradient(circle at 35% 35%, #ffffff, #e0e7ff);
  border: 3px solid #6366f1; border-radius: 20px;
  padding: 8px 18px; cursor: grab;
  display: flex; align-items: center; gap: 8px;
  box-shadow: 0 5px 0 #4338ca, 0 8px 16px rgba(99, 102, 241, 0.2);
  transition: transform 0.15s, opacity 0.2s; position: relative;
  user-select: none; -webkit-user-select: none;
  touch-action: none;
}
.sentence-pill-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 #4338ca; cursor: grabbing; }
.sentence-pill-btn.used { opacity: 0.22; pointer-events: none; filter: grayscale(0.85); box-shadow: none; }
.sentence-pill-btn.pill-dragging-origin { opacity: 0.35; transform: scale(0.92); }
.pill-word-text { font-size: 16px; font-weight: 800; color: #3730a3; pointer-events: none; }
.pill-deco { font-size: 12px; pointer-events: none; }

.sentence-pill-drag-clone {
  position: fixed; pointer-events: none; z-index: 99999;
  background: radial-gradient(circle at 35% 35%, #ffffff, #e0e7ff);
  border: 3.5px solid #6366f1; border-radius: 22px;
  padding: 10px 22px;
  box-shadow: 0 16px 32px rgba(99, 102, 241, 0.4), 0 0 16px rgba(129, 140, 248, 0.8);
  display: flex; align-items: center; gap: 8px;
  transform: translate(-50%, -50%) scale(1.15); cursor: grabbing;
  touch-action: none;
  will-change: left, top, transform;
}
.sentence-pill-drag-clone .pill-word-text { font-size: 18px; font-weight: 800; color: #3730a3; }

.word-chip-btn {
  background: #ffffff; border: 3px solid #ffd1e8; border-radius: 999px;
  padding: 5px 14px; font: 800 14px var(--font); color: var(--pink-d);
  cursor: pointer; box-shadow: 0 3px 0 #ffb6d2; white-space: nowrap;
  transition: transform 0.15s, background 0.15s; flex-shrink: 0;
}
.word-chip-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #ffb6d2; }
.word-chip-btn.active {
  background: var(--pink-d); color: #ffffff; border-color: #ffffff;
  box-shadow: 0 3px 0 #cc4d83; transform: scale(1.05);
}

.writing-modes-bar {
  display: flex; gap: 8px; justify-content: center; flex-wrap: wrap;
}
.wmode-btn {
  background: #ffffff; border: 3px solid #d9e6ff; border-radius: 999px;
  padding: 5px 16px; font: 800 14px var(--font); color: var(--blue-d);
  cursor: pointer; box-shadow: 0 3px 0 #cadbfb;
  transition: transform 0.15s, background 0.15s;
}
.wmode-btn.active {
  background: #4f46e5; color: #ffffff; border-color: #ffffff;
  box-shadow: 0 3px 0 #3730a3;
}

.writing-stage-card {
  border: 5px solid #ffffff; border-radius: 36px;
  box-shadow: 0 8px 0 rgba(107, 143, 199, 0.2), 0 16px 36px rgba(75, 95, 143, 0.12);
  width: 100%; padding: 20px;
  display: flex; flex-direction: column; align-items: center;
  position: relative;
}

.word-card-header {
  width: 100%; display: flex; align-items: center; justify-content: space-between;
  gap: 14px; margin-bottom: 16px; flex-wrap: wrap;
}
.word-mascot-badge {
  width: 85px; height: 70px; display: flex; align-items: center; justify-content: center;
}
.w-mascot-img {
  max-width: 100%; max-height: 100%; object-fit: contain;
  filter: drop-shadow(0 4px 6px rgba(0,0,0,0.12));
}
.word-info-box { flex: 1; min-width: 180px; }
.w-cat-tag {
  background: rgba(255, 255, 255, 0.9); border-radius: 999px;
  padding: 2px 10px; font-size: 12px; font-weight: 800; color: #7c3aed;
  display: inline-block;
}
.w-main-word {
  margin: 2px 0; font-size: clamp(28px, 5vw, 42px); font-weight: 800;
  letter-spacing: 2px; line-height: 1.1; text-shadow: 0 2px 0 rgba(255,255,255,0.8);
}
.w-desc-text {
  margin: 0; font-size: 13px; font-weight: 700; color: #64748b;
}

.btn-hear-word {
  background: #ffffff; border: 3px solid #bbf7d0; border-radius: 999px;
  padding: 6px 16px; font: 800 15px var(--font); color: #16a34a;
  cursor: pointer; box-shadow: 0 3px 0 #86efac; display: flex; align-items: center; gap: 6px;
}
.btn-hear-word:active { transform: translateY(2px); box-shadow: 0 1px 0 #86efac; }

.w-mode-stage-content { width: 100%; }

/* --- Modo 1: Alfabeto Móvil Montessori --- */
.montessori-tray-container {
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  width: 100%;
}
.tray-instructions {
  font-size: 14px; font-weight: 800; color: #475569; text-align: center;
}

.letter-slots-row {
  display: flex; gap: 10px; justify-content: center; flex-wrap: wrap;
  padding: 12px 16px; background: rgba(255, 255, 255, 0.7);
  border: 3px dashed #cbd5e1; border-radius: 26px; min-height: 84px;
  width: 100%; max-width: 680px; align-items: center;
  touch-action: none;
}
.letter-slot {
  width: 58px; height: 68px; border-radius: 18px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  position: relative; transition: transform 0.2s;
  touch-action: none;
}
.letter-slot.empty {
  background: #f8fafc; border: 3px dashed #94a3b8;
}
.letter-slot.empty .slot-letter-preview {
  font-size: 32px; font-weight: 800; color: #cbd5e1;
}
.letter-slot.filled {
  background: #fdf4ff; border: 3px solid #ec4899;
  box-shadow: 0 4px 0 #db2777, 0 6px 12px rgba(236, 72, 153, 0.2);
  animation: popLetter 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
@keyframes popLetter {
  0% { transform: scale(0.6); }
  70% { transform: scale(1.15); }
  100% { transform: scale(1); }
}
.letter-slot.filled .slot-letter-preview {
  font-size: 36px; font-weight: 800; color: #db2777;
}
.slot-placed-sparkle {
  position: absolute; top: -6px; right: -6px; font-size: 14px;
}

.letter-slot.slot-magnet-hover {
  transform: scale(1.08);
  border-color: #60a5fa !important;
  background: #eff6ff !important;
  box-shadow: 0 0 16px rgba(96, 165, 250, 0.5);
}
.letter-slot.slot-magnet-match {
  transform: scale(1.12);
  border-color: #ec4899 !important;
  background: #fdf2f8 !important;
  box-shadow: 0 0 22px rgba(236, 72, 153, 0.7);
  animation: magnetPulse 0.4s infinite alternate;
}
@keyframes magnetPulse {
  0% { transform: scale(1.08); }
  100% { transform: scale(1.14); }
}

.cookie-tray-frame {
  width: 100%; max-width: 680px; display: flex; flex-direction: column; align-items: center; gap: 6px;
  touch-action: none;
}
.tray-sub-heading {
  font-size: 13px; font-weight: 800; color: #78350f; text-shadow: 0 1px 0 rgba(255,255,255,0.8);
}
.cookie-letters-bank {
  display: flex; gap: 10px; justify-content: center; flex-wrap: wrap;
  padding: 12px 14px; background: rgba(254, 243, 199, 0.9);
  border: 4px solid #fde68a; border-radius: 28px; width: 100%;
  box-shadow: inset 0 2px 6px rgba(0,0,0,0.05), 0 4px 12px rgba(245, 158, 11, 0.15);
  touch-action: none;
}
.letter-cookie-btn {
  background: radial-gradient(circle at 35% 35%, #fffbeb, #fed7aa);
  border: 3px solid #f59e0b; border-radius: 20px;
  width: 60px; height: 64px; cursor: grab;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  box-shadow: 0 5px 0 #d97706, 0 8px 16px rgba(217, 119, 6, 0.2);
  transition: transform 0.15s, opacity 0.2s; position: relative;
  user-select: none; -webkit-user-select: none;
  touch-action: none;
}
.letter-cookie-btn:active {
  transform: translateY(3px); box-shadow: 0 2px 0 #d97706; cursor: grabbing;
}
.letter-cookie-btn.used {
  opacity: 0.22; pointer-events: none; filter: grayscale(0.85);
  box-shadow: none; border-color: #cbd5e1;
}
.letter-cookie-btn.cookie-dragging-origin {
  opacity: 0.35; transform: scale(0.92); filter: grayscale(0.5);
}
.cookie-char {
  font-size: 32px; font-weight: 800; color: #92400e; line-height: 1; pointer-events: none;
}
.cookie-deco {
  font-size: 11px; margin-top: -2px; pointer-events: none;
}

/* Clon flotante de galleta para arrastrar con el dedo */
.letter-cookie-drag-clone {
  position: fixed; pointer-events: none; z-index: 99999;
  width: 68px; height: 72px; border-radius: 22px;
  background: radial-gradient(circle at 35% 35%, #fffbeb, #fed7aa);
  border: 3.5px solid #f59e0b;
  box-shadow: 0 16px 32px rgba(217, 119, 6, 0.4), 0 0 16px rgba(253, 224, 71, 0.8);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  transform: translate(-50%, -50%) scale(1.15);
  cursor: grabbing;
  touch-action: none;
  will-change: left, top, transform;
}
.letter-cookie-drag-clone .cookie-char {
  font-size: 34px; font-weight: 800; color: #92400e; line-height: 1;
}
.letter-cookie-drag-clone .cookie-deco {
  font-size: 13px;
}

.slot-star-sparkle {
  position: fixed; pointer-events: none; z-index: 100000;
  font-size: 22px; transform: translate(-50%, -50%);
  animation: starBurst 0.65s ease-out forwards;
}
@keyframes starBurst {
  0% { transform: translate(-50%, -50%) scale(0.3); opacity: 1; }
  100% { transform: translate(calc(-50% + var(--tx)), calc(-50% + var(--ty))) scale(1.3); opacity: 0; }
}

/* --- Modo 2: Trazado Sensorial --- */
.trace-sensory-container {
  display: flex; flex-direction: column; align-items: center; gap: 10px; width: 100%;
}
.trace-letters-selector {
  display: flex; flex-direction: column; align-items: center; gap: 8px; width: 100%; max-width: 580px;
}
.trace-word-context {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: center;
  font-size: 13px; font-weight: 800; color: #475569;
}
.trace-letters-row { display: flex; gap: 6px; }
.trace-pick-btn {
  background: #ffffff; border: 2px solid #cbd5e1; border-radius: 12px;
  width: 36px; height: 40px; font: 800 18px var(--font); color: #334155;
  cursor: pointer; box-shadow: 0 2px 0 #94a3b8; transition: transform 0.12s;
}
.trace-pick-btn:hover { transform: translateY(-2px); }
.trace-pick-btn.active {
  background: #ec4899; color: #ffffff; border-color: #ffffff;
  box-shadow: 0 2px 0 #be185d; transform: scale(1.08);
}

.trace-alphabet-wrap {
  width: 100%; display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.trace-alpha-label {
  font-size: 12px; font-weight: 800; color: #64748b; text-align: center;
}
.trace-alpha-row {
  display: flex; gap: 4px; overflow-x: auto; max-width: 100%; padding: 4px 6px 8px;
  scrollbar-width: thin; -webkit-overflow-scrolling: touch;
}
.trace-alpha-row::-webkit-scrollbar { height: 4px; }
.trace-alpha-row::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }
.trace-alpha-btn {
  background: #ffffff; border: 2px solid #cbd5e1; border-radius: 10px;
  min-width: 32px; height: 34px; padding: 0 4px; font: 800 14px var(--font); color: #334155;
  cursor: pointer; box-shadow: 0 2px 0 #94a3b8; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.12s, background 0.12s;
}
.trace-alpha-btn:hover { transform: translateY(-2px); border-color: #f472b6; }
.trace-alpha-btn.active {
  background: #db2777; color: #ffffff; border-color: #ffffff;
  box-shadow: 0 2px 0 #9d174d; transform: scale(1.1);
}

.trace-stats-bar {
  display: flex; justify-content: space-between; align-items: center;
  width: 100%; max-width: 460px; margin-bottom: 4px; gap: 8px; flex-wrap: wrap;
}
.trace-accuracy-pill {
  background: rgba(255, 255, 255, 0.95);
  border: 2.5px solid #ffccd5;
  border-radius: 999px;
  padding: 4px 14px;
  font: 800 14px var(--font);
  color: #db2777;
  display: flex; align-items: center; gap: 6px;
  box-shadow: 0 2px 6px rgba(219, 39, 119, 0.15);
}
.trace-guide-hint {
  font-size: 13px; font-weight: 700; color: #475569;
}

.trace-board-stage {
  position: relative; border-radius: 28px; overflow: hidden;
  box-shadow: 0 8px 24px rgba(0,0,0,0.18); max-width: 100%;
}
.trace-canvas {
  display: block; width: 100%; max-width: 460px; height: auto;
  touch-action: none; cursor: crosshair;
}
.trace-celebration-banner {
  position: absolute; bottom: 12px; left: 12px; right: 12px;
  background: linear-gradient(135deg, rgba(236, 72, 153, 0.96), rgba(219, 39, 119, 0.96));
  backdrop-filter: blur(8px);
  display: flex; flex-direction: row; align-items: center; justify-content: space-between; gap: 10px;
  color: #ffffff; padding: 10px 16px; border-radius: 20px;
  box-shadow: 0 8px 24px rgba(219, 39, 119, 0.35), 0 0 0 2px rgba(255, 255, 255, 0.3);
  animation: slideUpToast 0.28s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  z-index: 15; pointer-events: auto;
}
@keyframes slideUpToast {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.trace-celebration-banner.hidden { display: none !important; }
.banner-text-box { text-align: left; }
.banner-title { font-size: 14px; font-weight: 800; line-height: 1.2; }
.banner-sub { font-size: 12px; font-weight: 700; opacity: 0.92; }
.btn-banner-next {
  background: #ffffff; color: #be185d; border: none; border-radius: 999px;
  padding: 6px 14px; font: 800 13px var(--font); cursor: pointer;
  box-shadow: 0 2px 0 #fda4af; white-space: nowrap; transition: transform 0.12s;
}
.btn-banner-next:active { transform: translateY(2px); }

/* --- Modo 3: Pizarra Libre --- */
.free-board-container {
  display: flex; flex-direction: column; align-items: center; gap: 12px; width: 100%;
}
.free-tools-bar {
  display: flex; gap: 14px; align-items: center; justify-content: center;
  flex-wrap: wrap; background: rgba(255,255,255,0.85); padding: 8px 16px;
  border-radius: 999px; border: 3px solid #ffffff; box-shadow: 0 4px 10px rgba(0,0,0,0.06);
}
.chalk-colors-row { display: flex; gap: 6px; }
.chalk-color-dot {
  width: 28px; height: 28px; border-radius: 50%; border: 3px solid #fff;
  cursor: pointer; box-shadow: 0 2px 4px rgba(0,0,0,0.15); transition: transform 0.15s;
}
.chalk-color-dot.active { transform: scale(1.25); border-color: #475569; }
.chalk-size-row { display: flex; gap: 6px; }
.chalk-size-btn {
  background: #f1f5f9; border: 2px solid #cbd5e1; border-radius: 999px;
  padding: 3px 10px; font: 800 12px var(--font); color: #475569; cursor: pointer;
}
.chalk-size-btn.active { background: #475569; color: #fff; border-color: #fff; }
.btn-sponge-erase {
  background: #fed7aa; border: 2px solid #fb923c; border-radius: 999px;
  padding: 4px 12px; font: 800 13px var(--font); color: #9a3412; cursor: pointer;
}

.chalkboard-frame {
  border-radius: 24px; overflow: hidden; box-shadow: 0 8px 24px rgba(0,0,0,0.2);
  max-width: 100%;
}
.chalk-canvas {
  display: block; width: 100%; max-width: 560px; height: auto;
  touch-action: none; cursor: crosshair;
}

.btn-w-reset {
  background: #f1f5f9; border: 2px solid #cbd5e1; border-radius: 999px;
  padding: 6px 18px; font: 800 14px var(--font); color: #475569;
  cursor: pointer; box-shadow: 0 2px 0 #94a3b8;
}

/* Modal de Victoria de Escritura y Puzzles */
.w-victory-modal-overlay {
  position: absolute; inset: 0; background: rgba(30, 41, 59, 0.6);
  backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center;
  z-index: 60; padding: 16px; border-radius: 36px;
}
.w-victory-card {
  background: #ffffff; border: 6px solid #ffffff; border-radius: 36px;
  box-shadow: 0 16px 40px rgba(0,0,0,0.25); padding: 26px 20px;
  text-align: center; max-width: 460px; width: 100%;
}
.w-victory-badge {
  background: #fdf2f8; border: 2px solid #fbcfe8; border-radius: 999px;
  padding: 4px 16px; font-size: 14px; font-weight: 800; color: #db2777;
  display: inline-block;
}
.w-victory-card h2 {
  margin: 8px 0; font-size: 38px; font-weight: 800; letter-spacing: 2px;
}
.w-victory-img-box {
  width: 130px; height: 100px; margin: 10px auto;
  display: flex; align-items: center; justify-content: center;
}
.w-victory-img-box img {
  max-width: 100%; max-height: 100%; object-fit: contain;
  filter: drop-shadow(0 6px 10px rgba(0,0,0,0.15));
}
.w-victory-actions {
  display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 16px;
}
.btn-w-next {
  background: linear-gradient(135deg, #10b981, #059669);
  color: #fff; border: 3px solid #fff; border-radius: 999px;
  padding: 8px 24px; font: 800 16px var(--font); cursor: pointer;
  box-shadow: 0 4px 0 #047857;
}
.btn-w-repeat {
  background: #f1f5f9; border: 2px solid #cbd5e1; border-radius: 999px;
  padding: 8px 20px; font: 800 14px var(--font); color: #475569; cursor: pointer;
}

/* ============================================================
   PANTALLA 9: PUZZLES DE LÓGICA Y FORMAS (puzzle.js)
   ============================================================ */
#screen-puzzle {
  background: linear-gradient(180deg, #f0fdf4 0%, #eff6ff 100%);
  align-items: center;
  justify-content: flex-start;
  padding: 16px;
}

.puzzle-wrap {
  width: 100%; max-width: 860px;
  display: flex; flex-direction: column; align-items: center;
  margin: 0 auto;
}

.puzzle-top-bar {
  width: 100%; margin-bottom: 12px; display: flex; flex-direction: column; gap: 8px; align-items: center;
}
.puzzle-pills-row {
  display: flex; gap: 8px; overflow-x: auto; padding: 4px 2px;
  scrollbar-width: none; justify-content: center; flex-wrap: wrap;
}
.puzzle-tab-btn {
  background: #ffffff; border: 3px solid #bbf7d0; border-radius: 999px;
  padding: 5px 16px; font: 800 14px var(--font); color: #15803d;
  cursor: pointer; box-shadow: 0 3px 0 #86efac; transition: transform 0.15s;
}
.puzzle-tab-btn.active {
  background: #16a34a; color: #ffffff; border-color: #ffffff;
  box-shadow: 0 3px 0 #15803d; transform: scale(1.05);
}

.puzzle-difficulty-row {
  display: flex; gap: 8px; justify-content: center; align-items: center; flex-wrap: wrap;
}
.diff-title-tag {
  font-size: 13px; font-weight: 800; color: #475569;
}
.puz-diff-btn {
  background: #f8fafc; border: 2.5px solid #cbd5e1; border-radius: 999px;
  padding: 4px 12px; font: 800 12px var(--font); color: #475569;
  cursor: pointer; box-shadow: 0 2px 0 #94a3b8; transition: transform 0.15s;
}
.puz-diff-btn.active {
  background: #ec4899; color: #ffffff; border-color: #ffffff;
  box-shadow: 0 3px 0 #be185d; transform: scale(1.05);
}

.puzzle-badges-top-line {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 4px;
}
.puzzle-timer-pill {
  background: #fef08a; border: 2px solid #facc15; border-radius: 999px;
  padding: 2px 10px; font-size: 13px; font-weight: 800; color: #854d0e;
}
.btn-ghost-toggle {
  background: #ffffff; border: 2.5px solid #cbd5e1; border-radius: 999px;
  padding: 6px 14px; font: 800 13px var(--font); color: #334155;
  cursor: pointer; box-shadow: 0 2px 0 #94a3b8; transition: transform 0.15s;
}
.btn-ghost-toggle:active { transform: translateY(2px); }
.btn-ghost-toggle.active {
  background: #dbeafe; border-color: #3b82f6; color: #1d4ed8; box-shadow: 0 2px 0 #2563eb;
}

.puzzle-stage-card {
  border: 5px solid #ffffff; border-radius: 36px;
  box-shadow: 0 8px 0 rgba(74, 222, 128, 0.2), 0 16px 36px rgba(75, 95, 143, 0.12);
  width: 100%; padding: 18px 20px;
  display: flex; flex-direction: column; align-items: center; position: relative;
  transition: box-shadow 0.3s;
}
.puzzle-completed-glow {
  animation: rainbowGlow 2.5s infinite alternate;
}
@keyframes rainbowGlow {
  0% { box-shadow: 0 0 22px rgba(236, 72, 153, 0.45), 0 8px 0 rgba(74, 222, 128, 0.25); }
  50% { box-shadow: 0 0 30px rgba(59, 130, 246, 0.55), 0 8px 0 rgba(236, 72, 153, 0.35); }
  100% { box-shadow: 0 0 36px rgba(234, 179, 8, 0.65), 0 8px 0 rgba(168, 85, 247, 0.35); }
}

.puzzle-header-info {
  width: 100%; display: flex; align-items: center; justify-content: space-between;
  gap: 14px; margin-bottom: 14px; flex-wrap: wrap;
}
.puzzle-mascot-avatar {
  width: 78px; height: 65px; display: flex; align-items: center; justify-content: center;
}
.puzzle-mascot-avatar img {
  max-width: 100%; max-height: 100%; object-fit: contain;
}
.puzzle-title-box { flex: 1; min-width: 200px; }
.puzzle-badge-pill {
  background: rgba(255, 255, 255, 0.9); border-radius: 999px;
  padding: 2px 10px; font-size: 12px; font-weight: 800; color: #16a34a;
}
.puzzle-title-box h1 {
  margin: 2px 0; font-size: clamp(22px, 3.8vw, 32px); font-weight: 800; line-height: 1.1;
}
.puzzle-title-box p {
  margin: 0; font-size: 13px; font-weight: 700; color: #475569;
}

.puzzle-gameplay-stage {
  display: flex; flex-direction: column; gap: 14px; justify-content: center; align-items: center;
  width: 100%; margin-bottom: 14px;
}

/* Marco de madera de alta fidelidad */
.puzzle-board-frame {
  background: linear-gradient(135deg, #fffbeb, #fed7aa);
  border: 6px solid #fde68a; border-radius: 28px;
  box-shadow: 0 10px 24px rgba(217, 119, 6, 0.15), inset 0 2px 4px rgba(255, 255, 255, 0.8);
  padding: 10px; display: flex; justify-content: center; align-items: center;
  max-width: 100%; overflow: hidden;
}
.puzzle-board-box {
  position: relative; border-radius: 20px; overflow: hidden;
  background: #fbf7ee linear-gradient(135deg, #fffdfa 0%, #fef3e2 100%);
  box-shadow: inset 0 2px 10px rgba(0,0,0,0.08);
  touch-action: none;
}
/* Silueta guía en Marca de Agua (Watermark Guide) */
.puzzle-board-box::before {
  content: ''; position: absolute; inset: 0;
  background-image: var(--guide-bg);
  background-size: 100% 100%;
  background-position: center;
  background-repeat: no-repeat;
  opacity: 0;
  filter: grayscale(0.2) contrast(0.9) brightness(1.08);
  z-index: 1; pointer-events: none; transition: opacity 0.3s ease;
}
.puzzle-board-box.no-ghost::before {
  opacity: 0 !important;
}
.puzzle-board-box.with-ghost::before {
  opacity: 0.16 !important;
}

.puzzle-board-slot {
  position: absolute; z-index: 2; box-sizing: border-box; cursor: pointer;
  transition: transform 0.15s, background-color 0.15s;
  touch-action: none;
}
.puzzle-board-slot.empty {
  border: 2px dashed rgba(255, 255, 255, 0.75);
  background: rgba(255, 255, 255, 0.12);
}
.puzzle-board-slot.empty:hover {
  background: rgba(255, 255, 255, 0.28);
}
.slot-ghost-guide {
  width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
}
.slot-coord-guide {
  font-size: 13px; font-weight: 800; color: rgba(255, 255, 255, 0.7);
  text-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.puzzle-board-slot.slot-magnet-match {
  border-color: #ec4899 !important;
  background: rgba(244, 114, 182, 0.35) !important;
  box-shadow: 0 0 24px rgba(236, 72, 153, 0.8), inset 0 0 12px rgba(255,255,255,0.8);
  animation: magnetPulse 0.4s infinite alternate;
}
.puzzle-board-slot.placed {
  border: none; z-index: 3;
}
.placed-piece-fill {
  width: 100%; height: 100%; background-repeat: no-repeat;
  animation: popPiece 0.32s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.3);
}
@keyframes popPiece {
  0% { transform: scale(0.7); opacity: 0.5; }
  70% { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

/* Bandeja Inferior de Piezas de Madera */
.puzzle-pieces-tray {
  background: rgba(255, 255, 255, 0.94); border: 4px solid #ffffff;
  border-radius: 28px; padding: 12px 16px;
  box-shadow: 0 8px 20px rgba(0,0,0,0.06); display: flex; flex-direction: column;
  align-items: center; gap: 8px; width: 100%; max-width: 680px;
  touch-action: none;
}
.tray-title-tag {
  font-size: 13px; font-weight: 800; color: #475569; text-align: center;
}
.pieces-bank-list {
  display: flex; gap: 12px; flex-wrap: wrap; justify-content: center;
  align-items: center; min-height: 80px; width: 100%;
  touch-action: none;
}
.puzzle-tray-piece-token {
  border-radius: 16px; overflow: hidden; position: relative; cursor: grab;
  border: 3.5px solid #ffffff;
  box-shadow: 0 6px 14px rgba(0,0,0,0.14), 0 2px 0 rgba(0,0,0,0.08);
  transition: transform 0.15s, box-shadow 0.15s, opacity 0.2s;
  user-select: none; -webkit-user-select: none;
  touch-action: none;
}
.puzzle-tray-piece-token:hover {
  transform: translateY(-3px) scale(1.03); box-shadow: 0 10px 20px rgba(0,0,0,0.18);
}
.puzzle-tray-piece-token:active {
  transform: translateY(2px); cursor: grabbing;
}
.puzzle-tray-piece-token.tray-token-dragging {
  opacity: 0.25; filter: grayscale(0.6);
}
.tray-piece-inner {
  width: 100%; height: 100%; background-repeat: no-repeat; pointer-events: none;
}
.tray-piece-bevel {
  position: absolute; inset: 0; border: 1.5px solid rgba(255, 255, 255, 0.6);
  border-radius: 13px; pointer-events: none;
  box-shadow: inset 0 2px 4px rgba(255, 255, 255, 0.7);
}

/* Clon de arrastre flotante de la pieza */
.puzzle-piece-drag-clone {
  position: fixed; pointer-events: none; z-index: 99999;
  border-radius: 18px; overflow: hidden; border: 4px solid #ffffff;
  box-shadow: 0 16px 36px rgba(0,0,0,0.35), 0 0 20px rgba(236, 72, 153, 0.5);
  transform: translate(-50%, -50%) scale(1.08); cursor: grabbing;
  touch-action: none;
  will-change: left, top, transform;
}
.drag-clone-inner {
  width: 100%; height: 100%; background-repeat: no-repeat;
}
.drag-clone-shine {
  position: absolute; inset: 0; border: 2px solid rgba(255, 255, 255, 0.8);
  border-radius: 14px; box-shadow: inset 0 3px 6px rgba(255,255,255,0.7);
}

.puzzle-tray-complete-badge {
  font-size: 15px; font-weight: 800; color: #16a34a; text-align: center; padding: 10px 0;
}

.btn-puzzle-reset {
  background: #f1f5f9; border: 2px solid #cbd5e1; border-radius: 999px;
  padding: 6px 18px; font: 800 14px var(--font); color: #475569;
  cursor: pointer; box-shadow: 0 2px 0 #94a3b8;
}

/* ============================================================
   RESPONSIVE DESIGN & CENTRADO MULTI-DISPOSITIVO (PC & SMARTPHONE)
   ============================================================ */

/* Asegurar centrado flex en todos los mounts de juegos */
#screen-hub,
#screen-flight,
#screen-math,
#screen-coloring,
#screen-memory,
#screen-platformer,
#screen-doom,
#screen-writing,
#screen-puzzle {
  align-items: center;
  justify-content: center;
}

#screen-hub {
  justify-content: flex-start;
}

/* Teléfonos y pantallas medianas (<= 768px) */
@media (max-width: 768px) {
  #globalTopBar {
    height: 56px;
    padding: 0 10px;
  }
  .top-brand {
    font-size: 18px;
  }
  .top-nav-btn {
    padding: 5px 12px;
    font-size: 15px;
    gap: 4px;
  }
  .track-btn {
    font-size: 13px;
    padding: 4px 10px;
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  #appContainer {
    inset: 56px 0 0 0;
  }

  /* Hub */
  .game-cards-grid {
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 14px;
    padding: 0 4px;
  }

  /* Math Bakery */
  .bakery-stage {
    padding: 12px 8px;
    gap: 4px;
  }
  .baker-char {
    width: 90px;
  }
  .cinna-avatar-wrap, .milk-avatar-wrap {
    width: 80px; height: 65px;
  }
  .bakery-tray-container {
    padding: 8px 10px;
  }
  .treat-cluster {
    max-width: 120px;
    gap: 4px;
  }
  .treat-btn {
    width: 44px; height: 44px; font-size: 24px;
  }
  .options-grid {
    gap: 10px;
  }
  .math-ans-btn {
    width: 72px; height: 82px;
  }
  .math-ans-number {
    font-size: 34px;
  }

  /* Platformer HUD */
  .plat-hud {
    top: 6px; left: 6px; right: 6px;
    gap: 4px;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    max-width: 100%;
  }
  .plat-hint-tag {
    display: none;
  }
  .plat-score-pill {
    padding: 2px 8px;
    font-size: 14px;
    order: 1;
    white-space: nowrap;
    height: 30px;
  }
  .plat-progress-bar-wrap {
    order: 2;
    max-width: 130px;
    padding: 2px 8px;
    height: 28px;
  }
  .plat-hero-pill {
    padding: 2px 8px;
    font-size: 12px;
    order: 3;
    white-space: nowrap;
    height: 30px;
    display: flex;
    align-items: center;
    gap: 4px;
  }
  .plat-hud-avatar {
    width: 24px; height: 20px;
  }
  .plat-hero-pill span {
    font-size: 12px;
  }
  .plat-city-pill {
    padding: 2px 8px;
    font-size: 12px;
    order: 4;
    width: 100%;
    justify-content: center;
    margin-top: 2px;
    height: 28px;
  }
  .btn-plat-switch-hero, .btn-plat-switch-city {
    padding: 2px 6px;
    font-size: 11px;
  }
  .plat-cities-grid, .plat-heroes-select-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
  }
  .plat-city-card p, .plat-hero-option p {
    display: none;
  }
  .plat-city-card h4 {
    font-size: 10px; margin-bottom: 2px;
  }
  .plat-city-card h3, .plat-hero-option h3 {
    font-size: 13px;
  }
  .plat-city-card-icon {
    font-size: 26px; margin: 2px 0;
  }
  .btn-travel-city, .btn-pick-plat-hero {
    padding: 4px 8px; font-size: 11px;
  }
  .plat-btn {
    width: 60px; height: 60px; font-size: 24px;
  }
  .plat-btn.btn-jump {
    width: 74px; height: 74px; font-size: 22px;
  }
  .plat-touch-controls {
    bottom: 10px; left: 8px; right: 8px;
  }

  /* Doom HUD */
  .doom-hud {
    top: 8px; left: 8px; right: 8px;
  }
  .doom-score-pill, .doom-hero-pill {
    padding: 3px 12px; font-size: 14px;
  }
  .doom-radar-canvas {
    top: 48px; right: 8px;
    width: 65px !important; height: 65px !important;
  }
  .doom-touch-btn {
    width: 46px; height: 46px; font-size: 20px;
  }
  .doom-launch-big-btn {
    width: 80px; height: 80px;
  }
  .launch-ico { font-size: 30px; }
  .cinna-firstperson-tray {
    width: 180px; height: 100px;
  }
  .tray-treat-display { font-size: 48px; }
  .hero-firstperson-paw { font-size: 28px; }

  /* Coloring Studio */
  .coloring-board-stage {
    border-width: 4px;
    border-radius: 20px;
  }
  .coloring-controls-bar {
    padding: 8px;
  }
  .swatch-btn {
    width: 34px; height: 34px;
  }
  .tool-btn, .size-pill, .stamp-opt-btn, .aux-btn {
    padding: 4px 10px; font-size: 13px;
  }
}

/* Pantallas estrechas (<= 620px): botones compactos con emoticones */
@media (max-width: 620px) {
  .top-right-actions {
    gap: 6px;
  }
  .top-nav-btn {
    padding: 5px 9px;
    font-size: 14px;
    gap: 3px;
  }
  .fullscreen-btn .btn-text,
  .gamepad-btn .btn-text,
  .music-btn .btn-text {
    display: none;
  }
}

/* Teléfonos muy angostos (<= 420px) */
@media (max-width: 420px) {
  .top-brand {
    font-size: 16px;
    white-space: nowrap;
  }
  .top-nav-btn {
    padding: 4px 8px;
    font-size: 13px;
  }
  .track-btn {
    font-size: 12px;
    padding: 3px 8px;
    max-width: 100px;
  }
  .baker-char {
    width: 70px;
  }
  .cinna-avatar-wrap, .milk-avatar-wrap {
    width: 65px; height: 50px;
  }
  .char-bubble {
    font-size: 11px;
    padding: 2px 6px;
  }
  .treat-btn {
    width: 38px; height: 38px; font-size: 20px;
  }
  .math-sign-symbol {
    font-size: 18px;
  }
  .math-ans-btn {
    width: 64px; height: 72px;
  }
  .math-ans-number {
    font-size: 28px;
  }
  .memory-grid.grid-size-8,
  .memory-grid.grid-size-12,
  .memory-grid.grid-size-16 {
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
  }
  .card-art-box {
    width: 60px; height: 50px;
  }
  .card-char-name {
    font-size: 11px;
  }
  .card-char-emoji {
    font-size: 14px;
  }
}

/* Orientación horizontal en smartphones (ej. 844x390) */
@media (max-height: 520px) and (orientation: landscape) {
  #globalTopBar {
    height: 44px;
  }
  #appContainer {
    inset: 44px 0 0 0;
  }
  .plat-hud {
    top: 4px;
  }
  .plat-touch-controls {
    bottom: 6px;
  }
  .plat-btn {
    width: 52px; height: 52px; font-size: 22px;
  }
  .plat-btn.btn-jump {
    width: 64px; height: 64px; font-size: 22px;
  }
  .doom-touch-controls {
    bottom: 6px;
  }
  .doom-touch-btn {
    width: 42px; height: 42px; font-size: 18px;
  }
  .doom-launch-big-btn {
    width: 68px; height: 68px;
  }
}

/* ============================================================
   MODAL DE MANDO KAWAII / CELULAR & NOTIFICACIONES
   ============================================================ */
.gamepad-btn {
  background: linear-gradient(135deg, #e0f2fe 0%, #bae6fd 100%) !important;
  color: #0369a1 !important;
  border-color: #38bdf8 !important;
}
.gamepad-btn:hover {
  background: linear-gradient(135deg, #bae6fd 0%, #7dd3fc 100%) !important;
  transform: translateY(-2px) scale(1.04);
}

.fullscreen-btn {
  background: linear-gradient(135deg, #fdf4ff 0%, #fae8ff 100%) !important;
  color: #a21caf !important;
  border-color: #f0abfc !important;
  box-shadow: 0 3px 0 #e879f9 !important;
}
.fullscreen-btn:hover {
  background: linear-gradient(135deg, #fae8ff 0%, #f5d0fe 100%) !important;
  transform: translateY(-2px) scale(1.04);
}
.fullscreen-btn.active-fullscreen {
  background: linear-gradient(135deg, #dcfce7 0%, #bbf7d0 100%) !important;
  color: #15803d !important;
  border-color: #86efac !important;
  box-shadow: 0 3px 0 #4ade80 !important;
}

.cinna-modal-overlay {
  position: fixed; inset: 0; z-index: 100010;
  background: rgba(45, 20, 40, 0.6);
  backdrop-filter: blur(8px);
  display: flex; justify-content: center; align-items: center;
  padding: 16px;
  animation: modalFadeIn 0.25s ease-out;
}
.cinna-modal-overlay.hidden { display: none !important; }

.cinna-modal-card {
  background: #ffffff;
  border-radius: 28px;
  max-width: 440px; width: 100%;
  padding: 24px 20px;
  position: relative;
  text-align: center;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.25), 0 0 0 6px #ffeef8;
  border: 4px solid #ffb6d2;
}
.modal-close-btn {
  position: absolute; top: 14px; right: 14px;
  width: 38px; height: 38px; border-radius: 50%;
  background: #fee2e2; border: 2px solid #f87171;
  color: #b91c1c; font-size: 18px; font-weight: 800;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 6px rgba(0,0,0,0.1);
  transition: transform 0.15s;
}
.modal-close-btn:hover { transform: scale(1.1); }

.cinna-modal-card .modal-header {
  display: flex; align-items: center; justify-content: center; gap: 8px; margin-bottom: 8px;
}
.cinna-modal-card .modal-header h2 {
  font-size: 20px; font-weight: 800; color: #5c3d2e;
}
.cinna-modal-card .modal-icon { font-size: 28px; }
.cinna-modal-card .modal-desc {
  font-size: 14px; color: #7a523a; margin-bottom: 14px; line-height: 1.35;
}

.qr-container-box {
  background: #fff8fc;
  border: 3px dashed #ffccd5;
  border-radius: 20px;
  padding: 16px;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  margin-bottom: 14px;
}
.qr-code-canvas {
  width: 170px; height: 170px;
  display: flex; justify-content: center; align-items: center;
  background: #ffffff;
  border-radius: 12px;
  padding: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}
.qr-code-canvas img, .qr-code-canvas canvas {
  width: 100% !important; height: 100% !important; object-fit: contain;
}
.room-code-tag {
  font-size: 14px; font-weight: 700; color: #5c3d2e;
}
.room-code-tag strong {
  background: #ffb6d2; color: #ffffff;
  padding: 2px 10px; border-radius: 8px; font-size: 16px; letter-spacing: 2px;
}

.gamepad-status-pill {
  font-size: 14px; font-weight: 800; padding: 6px 14px; border-radius: 999px;
  display: inline-block; margin-bottom: 12px;
  background: #fef3c7; color: #b45309; border: 2px solid #fde68a;
  transition: all 0.3s ease;
}
.gamepad-status-pill.connected {
  background: #dcfce7; color: #15803d; border-color: #86efac;
}

.physical-gamepad-hint {
  font-size: 12px; color: #64748b; background: #f8fafc;
  padding: 8px 12px; border-radius: 12px; border: 1px solid #e2e8f0;
  line-height: 1.35; text-align: left;
}

.cinna-gamepad-toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(40px);
  background: rgba(92, 61, 46, 0.95); color: #ffffff;
  padding: 10px 22px; border-radius: 999px; font-size: 15px; font-weight: 800;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  border: 2px solid #ffccd5;
  pointer-events: none; z-index: 10000;
  opacity: 0; transition: all 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.cinna-gamepad-toast.visible {
  transform: translateX(-50%) translateY(0); opacity: 1;
}

/* ============================================================
   COORDINADOR INTELIGENTE DE MODO DE ENTRADA (MANDO TV vs TOUCH)
   ============================================================ */
.input-mode-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  background: #f1f5f9;
  color: #475569;
  border: 2px solid #cbd5e1;
  transition: all 0.25s ease;
}
.input-mode-badge.mode-remote {
  background: linear-gradient(135deg, #dcfce7 0%, #bbf7d0 100%);
  color: #15803d;
  border-color: #4ade80;
  box-shadow: 0 2px 8px rgba(34, 197, 94, 0.25);
}
.input-mode-badge.mode-touch {
  background: linear-gradient(135deg, #fdf2f8 0%, #fce7f3 100%);
  color: #be185d;
  border-color: #f472b6;
}

/* Cuando el Mando Remoto está activo en la TV, ocultar los botones táctiles gigantes de pantalla
   para que la TV luzca limpia como una consola profesional (se reactivan al tocar la pantalla) */
body.remote-controller-active .plat-touch-controls,
body.remote-controller-active .doom-touch-controls,
body.remote-controller-active .flight-touch-controls {
  opacity: 0.12;
  pointer-events: auto;
  transition: opacity 0.35s ease;
}
body.touch-input-active .plat-touch-controls,
body.touch-input-active .doom-touch-controls,
body.touch-input-active .flight-touch-controls {
  opacity: 1;
}

/* ============================================================
   JUEGO 9: CINNAMOROLL WORLD · CASA DE SUEÑOS (AVATAR WORLD)
   ============================================================ */
#screen-avatar {
  align-items: center;
  justify-content: center;
}
#avatar-mount {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 14px;
}

.card-avatar {
  background: linear-gradient(145deg, #fff1f2 0%, #fae8ff 50%, #e0f2fe 100%) !important;
  border-color: #f472b6 !important;
}

.avatar-world-shell {
  width: 100%;
  max-width: 1080px;
  height: 100%;
  max-height: 650px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.aw-hud-top {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.92);
  border: 3px solid #ffffff;
  border-radius: 22px;
  padding: 6px 12px;
  box-shadow: 0 6px 18px rgba(236, 72, 153, 0.14);
}

.aw-room-tabs, .aw-action-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.aw-room-btn, .aw-pill-btn {
  border: 2.5px solid #e2e8f0;
  background: #ffffff;
  color: #475569;
  font-family: inherit;
  font-size: 13px;
  font-weight: 800;
  padding: 5px 12px;
  border-radius: 16px;
  cursor: pointer;
  box-shadow: 0 3px 0 #cbd5e1;
  transition: transform 0.1s, background 0.15s;
}
.aw-room-btn:active, .aw-pill-btn:active {
  transform: translateY(2px);
}
.aw-room-btn.active {
  background: linear-gradient(135deg, #f472b6 0%, #ec4899 100%);
  color: #ffffff;
  border-color: #ffffff;
  box-shadow: 0 3px 0 #be185d;
}
.aw-btn-wardrobe {
  background: linear-gradient(135deg, #fdf2f8 0%, #fbcfe8 100%);
  color: #be185d;
  border-color: #f472b6;
}
.aw-btn-decor.active {
  background: linear-gradient(135deg, #38bdf8 0%, #0284c7 100%);
  color: #ffffff;
  border-color: #ffffff;
}

.aw-canvas-stage {
  flex: 1;
  position: relative;
  background: #fffdf9;
  border: 5px solid #ffffff;
  border-radius: 28px;
  box-shadow: 0 14px 36px rgba(92, 61, 46, 0.14);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

#avatarWorldCanvas {
  width: 100%;
  height: 100%;
  object-fit: contain;
  touch-action: none;
  cursor: pointer;
}

/* Catálogo Inferior de Decoración */
.aw-decor-Catalog {
  position: absolute;
  bottom: 10px;
  left: 14px;
  right: 14px;
  background: rgba(255, 255, 255, 0.95);
  border: 3px solid #bae6fd;
  border-radius: 22px;
  padding: 8px 14px;
  box-shadow: 0 10px 26px rgba(2, 132, 199, 0.22);
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 20;
}
.aw-drawer-title {
  font-size: 12px;
  font-weight: 800;
  color: #0369a1;
  text-align: center;
}
.aw-decor-items {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  justify-content: center;
  padding-bottom: 2px;
}
.aw-decor-chip {
  border: 2px solid #e0f2fe;
  background: #f8fafc;
  border-radius: 14px;
  padding: 4px 10px;
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 800;
  font-size: 12px;
  color: #334155;
  box-shadow: 0 2px 0 #cbd5e1;
  white-space: nowrap;
}
.aw-decor-chip:hover {
  background: #e0f2fe;
  border-color: #38bdf8;
}

/* Modal de Vestidor Kawaii */
.aw-wardrobe-modal {
  position: absolute;
  inset: 0;
  background: rgba(45, 20, 40, 0.45);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  z-index: 30;
}
.aw-wardrobe-card {
  background: #ffffff;
  border: 4px solid #fbcfe8;
  border-radius: 26px;
  padding: 16px 18px;
  width: 100%;
  max-width: 620px;
  box-shadow: 0 16px 40px rgba(236, 72, 153, 0.28);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.aw-wardrobe-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.aw-wardrobe-header h3 {
  font-size: 17px;
  font-weight: 800;
  color: #db2777;
}
.aw-wardrobe-player-tabs {
  display: flex;
  gap: 4px;
}
.aw-p-tab {
  border: 2px solid #cbd5e1;
  background: #f8fafc;
  border-radius: 12px;
  padding: 3px 10px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}
.aw-p-tab.active {
  background: #ec4899;
  color: #ffffff;
  border-color: #be185d;
}
.aw-wardrobe-close {
  background: linear-gradient(135deg, #4ade80 0%, #16a34a 100%);
  color: #ffffff;
  border: 2px solid #ffffff;
  border-radius: 14px;
  padding: 4px 14px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 3px 0 #15803d;
}
.aw-wardrobe-cats {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
}
.aw-cat-btn {
  border: 2px solid #e2e8f0;
  background: #f8fafc;
  border-radius: 14px;
  padding: 4px 11px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 800;
  color: #475569;
  cursor: pointer;
}
.aw-cat-btn.active {
  background: #fdf2f8;
  border-color: #ec4899;
  color: #db2777;
}
.aw-wardrobe-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(105px, 1fr));
  gap: 8px;
  max-height: 220px;
  overflow-y: auto;
  padding: 4px;
}
.aw-opt-card {
  border: 2.5px solid #e2e8f0;
  background: #ffffff;
  border-radius: 16px;
  padding: 8px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.08s;
}
.aw-opt-card.active {
  border-color: #ec4899;
  background: #fdf2f8;
  box-shadow: 0 3px 0 #db2777;
}
.aw-opt-ico, .aw-opt-swatch {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  border: 2px solid #f1f5f9;
}
.aw-opt-name {
  font-size: 11px;
  font-weight: 800;
  color: #334155;
}

/* ============================================================
   CONTROLES TÁCTILES INTEGRADOS PARA VUELO (A VOLAR)
   ============================================================ */
.flight-touch-controls {
  position: absolute;
  inset: auto 16px 20px 16px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  pointer-events: none;
  z-index: 15;
  user-select: none;
  -webkit-user-select: none;
}
.flight-touch-controls.hidden {
  display: none !important;
}
.flight-dpad-col,
.flight-actions-col {
  display: flex;
  flex-direction: column;
  gap: 12px;
  pointer-events: auto;
}
.flight-touch-btn {
  width: 72px;
  height: 72px;
  border-radius: 26px;
  background: rgba(255, 255, 255, 0.9);
  border: 3.5px solid #b3e5fc;
  box-shadow: 0 6px 0 #7dd3fc, 0 10px 20px rgba(125, 211, 252, 0.35);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  touch-action: none;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: transform 0.08s, box-shadow 0.08s, background-color 0.1s;
}
.flight-touch-btn:active,
.flight-touch-btn.active {
  transform: scale(0.92) translateY(4px);
  box-shadow: 0 2px 0 #7dd3fc, 0 4px 10px rgba(125, 211, 252, 0.35);
  background: #e0f2fe;
}
.flight-btn-icon {
  font-size: 24px;
  line-height: 1;
}
.flight-btn-text {
  font-size: 11px;
  font-weight: 800;
  color: #0284c7;
  letter-spacing: 0.5px;
}
.btn-flight-up {
  border-color: #7dd3fc;
}
.btn-flight-down {
  border-color: #7dd3fc;
}
.btn-flight-spin {
  border-color: #fbcfe8;
  box-shadow: 0 6px 0 #f472b6, 0 10px 20px rgba(244, 114, 182, 0.35);
}
.btn-flight-spin:active,
.btn-flight-spin.active {
  box-shadow: 0 2px 0 #f472b6;
  background: #fdf2f8;
}
.btn-flight-spin .flight-btn-text {
  color: #db2777;
}
.btn-flight-hello {
  border-color: #fed7aa;
  box-shadow: 0 6px 0 #fb923c, 0 10px 20px rgba(251, 146, 60, 0.35);
}
.btn-flight-hello:active,
.btn-flight-hello.active {
  box-shadow: 0 2px 0 #fb923c;
  background: #fff7ed;
}
.btn-flight-hello .flight-btn-text {
  color: #ea580c;
}

@media (max-width: 600px) {
  .flight-touch-btn {
    width: 60px;
    height: 60px;
    border-radius: 20px;
  }
  .flight-btn-icon {
    font-size: 20px;
  }
  .flight-btn-text {
    font-size: 10px;
  }
}

/* ---------- Matemáticas: nivel automático y progreso para papás ---------- */
.math-level-badge {
  background: #eff6ff; border: 2.5px solid #93c5fd; border-radius: 999px;
  padding: 4px 12px; font: 800 13px var(--font); color: #1d4ed8;
}
.math-level-up {
  background: #fef9c3; border: 2.5px solid #facc15; border-radius: 999px;
  padding: 4px 12px; font: 800 13px var(--font); color: #a16207;
  animation: mathLevelPop 0.6s ease-out;
}
@keyframes mathLevelPop {
  0% { transform: scale(0.6); opacity: 0; }
  70% { transform: scale(1.1); opacity: 1; }
  100% { transform: scale(1); }
}
.math-parents { width: 100%; margin-top: 16px; }
.math-parents-body { display: flex; flex-direction: column; gap: 10px; padding-top: 10px; }
.math-progress-table-wrap { width: 100%; overflow-x: auto; }
.math-progress-table {
  width: 100%; border-collapse: collapse; font: 700 13px var(--font); color: #475569;
  background: #ffffff; border-radius: 12px; overflow: hidden;
}
.math-progress-table th, .math-progress-table td {
  padding: 6px 8px; text-align: left; border-bottom: 1px solid #e2ebf8; white-space: nowrap;
}
.math-progress-table th { background: #f1f5fb; color: #64748b; font-size: 12px; }
.math-progress-table small { color: #94a3b8; font-weight: 700; }
.math-parents-note { margin: 0; font: 600 12px var(--font); color: #8fa2c4; }
.math-auto-toggle { display: flex; align-items: center; gap: 8px; font: 800 13px var(--font); color: #475569; cursor: pointer; }
.math-auto-toggle input { width: 18px; height: 18px; accent-color: #3b82f6; }
.math-reset-btn {
  align-self: flex-start; background: #ffffff; border: 2px solid #fecaca; border-radius: 999px;
  padding: 4px 12px; font: 800 12px var(--font); color: #dc2626; cursor: pointer;
}

/* ---------- Aceptar mando nuevo (celular que escribió el código a mano) ---------- */
.cinna-accept-controller {
  position: fixed; inset: 0; z-index: 100020;
  display: flex; align-items: center; justify-content: center;
  background: rgba(40, 30, 60, .45); padding: 16px;
}
.cinna-accept-card {
  background: #fff; border-radius: 24px; padding: 22px 20px; max-width: 360px; width: 100%;
  text-align: center; box-shadow: 0 12px 40px rgba(0,0,0,.25); font-family: inherit;
}
.cinna-accept-title { font-size: 20px; font-weight: 800; color: #4a5a80; margin-bottom: 6px; }
.cinna-accept-desc { font-size: 15px; color: #4a5a80; margin-bottom: 16px; }
.cinna-accept-actions { display: flex; gap: 12px; justify-content: center; }
.cinna-accept-actions button {
  min-height: 52px; min-width: 120px; border: 0; border-radius: 16px;
  font: inherit; font-size: 17px; font-weight: 800; cursor: pointer;
}
.cinna-accept-yes { background: #34d399; color: #064e3b; }
.cinna-accept-no { background: #fecdd3; color: #881337; }

/* Botón para volver a escuchar la pregunta (niños que aún no leen) */
.math-hear-btn {
  vertical-align: middle; margin-right: 8px;
  min-width: 48px; min-height: 48px; border-radius: 50%;
  border: 3px solid #bae6fd; background: #f0f9ff; font-size: 22px; cursor: pointer;
  box-shadow: 0 3px 0 #bae6fd;
}
.math-hear-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #bae6fd; }

/* Puzzle: pieza elegida con un toque (luego se toca su lugar) */
.puzzle-tray-piece-token.tray-token-selected {
  outline: 4px solid #f472b6; outline-offset: 3px;
  transform: scale(1.08); box-shadow: 0 0 0 6px rgba(244, 114, 182, .25);
}
