/* ==========================================================================
   JUEGOS MEDIO DE MIEDO — Linear × Apple Arcade Adaptive Studio Shell
   Adapta los 6 minijuegos (y los futuros) a Desktop, Tablet y Mobile:
   - Fondo ambiental obsidian con portada ilustrada
   - Controles HUD glass-specular (Cartoon) y precisión arcade (8-Bit)
   - Banner de portada cinematográfico en pantallas de inicio
   - Selector rápido "Cambiar de juego" estilo Command Palette + Fullscreen
   ========================================================================== */

:root {
  --cmm-ink: #050814;
  --cmm-gold: #FFD166;
  --cmm-cyan: #6FFFE9;
  --cmm-neon: #39FF14;
  --cmm-purple: #A855F7;
  --cmm-coral: #FF4D6D;
  --cmm-hairline: rgba(255, 255, 255, 0.12);
  --cmm-specular: rgba(255, 255, 255, 0.2);
  --cmm-font: 'Plus Jakarta Sans', 'Fredoka', ui-rounded, system-ui, -apple-system, sans-serif;
  --cmm-display: 'Baloo 2', 'Fredoka', ui-rounded, sans-serif;
  --cmm-ease: cubic-bezier(0.22, 1, 0.36, 1);
}

/* Fondo ambiental con la portada ilustrada del juego detrás del escenario */
body.cmm-enhanced {
  position: relative;
  animation: cmmGameFadeIn 0.32s var(--cmm-ease);
}

@keyframes cmmGameFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

body.cmm-enhanced::before {
  content: '';
  position: fixed;
  inset: -28px;
  background-image: var(--cmm-cover-url, none);
  background-size: cover;
  background-position: center;
  filter: blur(30px) brightness(0.26) saturate(1.2);
  transform: scale(1.08);
  z-index: 0;
  pointer-events: none;
}

body.cmm-enhanced::after {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 65% 45% at 18% 8%, rgba(124, 58, 237, 0.18), transparent 60%),
    radial-gradient(ellipse 55% 40% at 82% 92%, rgba(56, 189, 248, 0.12), transparent 62%),
    radial-gradient(circle at 50% 50%, transparent 45%, rgba(3, 5, 14, 0.55) 100%);
  z-index: 0;
  pointer-events: none;
}

body.cmm-enhanced > #app,
body.cmm-enhanced > #cartridge-shell,
body.cmm-enhanced > #arcade-shell {
  position: relative;
  z-index: 2;
}

/* ==================== ADAPTACIÓN FULL-VIEWPORT SIN WRAPPER ==================== */
body.cmm-portrait-game.cmm-enhanced {
  padding: 0;
  gap: 0;
}

body.cmm-portrait-game #cartridge-shell,
body.cmm-portrait-game #arcade-shell {
  width: 100%;
  height: 100dvh;
  max-width: none;
  max-height: none;
  border: none;
  border-radius: 0;
  box-shadow: none;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

/* Juegos widescreen: marco refinado y safe-area */
body.cmm-widescreen-game #app {
  padding-top: max(8px, env(safe-area-inset-top));
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  padding-left: max(10px, env(safe-area-inset-left));
  padding-right: max(10px, env(safe-area-inset-right));
}

body.cmm-widescreen-game #gameCanvas,
body.cmm-widescreen-game #stageCanvas {
  box-shadow:
    0 20px 48px -12px rgba(2, 4, 14, 0.8),
    0 0 0 1px rgba(255, 255, 255, 0.1),
    0 0 42px -10px var(--cmm-accent-glow, rgba(111, 255, 233, 0.22));
}

/* ==================== PANEL LATERAL DELUXE (RESERVADO DESKTOP >= 1060px) ==================== */
#cmm-companion {
  display: none;
  position: relative;
  z-index: 2;
  width: 310px;
  max-height: 92dvh;
  overflow-y: auto;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  border-radius: 20px;
  background: rgba(10, 14, 30, 0.86);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--cmm-hairline);
  box-shadow: inset 0 1px 0 var(--cmm-specular), 0 24px 56px -14px rgba(0, 0, 0, 0.8);
  font-family: var(--cmm-font);
  color: #F8FAFC;
  flex-shrink: 0;
}

@media (min-width: 1060px) {
  body.cmm-portrait-game #cmm-companion {
    display: flex;
  }
}

/* ==================== BOTONES REFINADOS DEL SHELL ==================== */
.cmm-comp-btn {
  font-family: var(--cmm-font);
  font-weight: 700;
  font-size: 0.8rem;
  letter-spacing: -0.005em;
  padding: 8px 13px;
  border-radius: 11px;
  border: 1px solid var(--cmm-hairline);
  background: rgba(255, 255, 255, 0.06);
  color: #F8FAFC;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  line-height: 1;
  transition:
    transform 0.16s var(--cmm-ease),
    background-color 0.16s ease,
    border-color 0.16s ease,
    box-shadow 0.2s ease;
  user-select: none;
}

.cmm-comp-btn:hover {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.11);
  border-color: rgba(255, 255, 255, 0.24);
}

.cmm-comp-btn:active {
  transform: translateY(0.5px) scale(0.98);
}

.cmm-comp-btn.primary {
  font-family: var(--cmm-display);
  font-weight: 800;
  font-size: 0.86rem;
  background: linear-gradient(180deg, #98FF83 0%, #37F21A 100%);
  color: #04110A;
  border-color: rgba(255, 255, 255, 0.4);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.65), 0 8px 20px -6px rgba(57, 255, 20, 0.45);
}

.cmm-comp-btn.primary:hover {
  background: linear-gradient(180deg, #ADFF9C 0%, #48FF29 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.78), 0 10px 24px -5px rgba(57, 255, 20, 0.62);
}

.cmm-comp-btn.purple {
  background: rgba(168, 85, 247, 0.16);
  border-color: rgba(168, 85, 247, 0.38);
  color: #F3E8FF;
}

.cmm-comp-btn.purple:hover {
  background: rgba(168, 85, 247, 0.26);
  border-color: rgba(192, 132, 252, 0.58);
}

.cmm-comp-btn.icon-close {
  width: 34px;
  height: 34px;
  padding: 0;
  color: #B8C6E3;
}

.cmm-comp-btn.icon-close:hover {
  color: #FFF;
}

/* ==================== BANNER DE PORTADA EN MODALES DE INICIO ==================== */
.cmm-start-banner {
  position: relative;
  width: 100%;
  height: 118px;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.24),
    0 14px 32px -12px rgba(2, 4, 14, 0.78);
  margin-bottom: 12px;
}

.cmm-start-banner img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 40%;
  display: block;
}

.cmm-start-banner::after {
  content: '';
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(5, 7, 18, 0.1) 25%, rgba(5, 7, 18, 0.74) 100%);
  pointer-events: none;
}

.cmm-start-banner-pill {
  position: absolute;
  bottom: 9px;
  left: 10px;
  z-index: 2;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(6, 9, 22, 0.76);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: #EBF4FF;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  font-family: var(--cmm-font);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

/* ==================== CONTROLES DE BARRA SUPERIOR COMPARTIDOS ==================== */
.cmm-nav-cluster {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.cmm-back-inline,
.cmm-tool-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  text-decoration: none;
  cursor: pointer;
  flex-shrink: 0;
  line-height: 1;
  white-space: nowrap;
  transition:
    transform 0.16s var(--cmm-ease),
    background-color 0.16s ease,
    border-color 0.16s ease,
    box-shadow 0.2s ease,
    filter 0.16s ease;
  user-select: none;
}

.cmm-back-inline:focus-visible,
.cmm-tool-btn:focus-visible,
.cmm-modal-back-link:focus-visible,
.cmm-drawer-card:focus-visible,
.cmm-comp-btn:focus-visible,
.cmm-tut-dot:focus-visible,
.cmm-tut-skip:focus-visible {
  outline: 2px solid var(--cmm-cyan);
  outline-offset: 2px;
}

.cmm-back-inline:hover,
.cmm-tool-btn:hover {
  transform: translateY(-1px);
}

.cmm-back-inline:active,
.cmm-tool-btn:active {
  transform: translateY(0.5px) scale(0.97);
}

/* Estilo Cartoon — Apple Arcade Glass Specular */
.cmm-cartoon {
  font-family: var(--cmm-font);
  font-weight: 700;
  font-size: clamp(0.74rem, 1.5vw, 0.84rem);
  height: 34px;
  padding: 0 11px;
  background: linear-gradient(180deg, #FFE696 0%, #F7B731 100%);
  color: #161002;
  border: 1px solid rgba(255, 255, 255, 0.36);
  border-radius: 11px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.62),
    0 6px 16px -6px rgba(255, 209, 102, 0.45);
}

.cmm-cartoon:hover {
  filter: brightness(1.06);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.75),
    0 8px 20px -5px rgba(255, 209, 102, 0.6);
}

.cmm-tool-btn.cmm-cartoon {
  background: rgba(13, 18, 38, 0.78);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: #E8F0FF;
  border: 1px solid rgba(255, 255, 255, 0.16);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.14),
    0 6px 16px -6px rgba(2, 4, 14, 0.65);
  width: 34px;
  padding: 0;
}

.cmm-tool-btn.cmm-cartoon:hover {
  background: rgba(26, 34, 68, 0.92);
  border-color: rgba(111, 255, 233, 0.42);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.22),
    0 8px 18px -6px rgba(111, 255, 233, 0.28);
}

/* Estilo 8-Bit — Precisión Arcade */
.cmm-retro {
  font-family: 'Press Start 2P', ui-monospace, monospace;
  font-weight: 700;
  font-size: clamp(0.45rem, 1.5vw, 0.56rem);
  height: 28px;
  padding: 0 8px;
  border-radius: 7px;
  background: linear-gradient(180deg, #FFE48A 0%, #F5B82E 100%);
  color: #050814;
  border: 1px solid rgba(255, 255, 255, 0.35);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.55), 0 3px 10px -2px rgba(0, 0, 0, 0.55);
}

.cmm-tool-btn.cmm-retro {
  width: 28px;
  padding: 0;
  background: rgba(32, 23, 62, 0.88);
  color: #6FFFE9;
  border: 1px solid rgba(111, 255, 233, 0.36);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14), 0 3px 10px -2px rgba(0, 0, 0, 0.55);
}

.cmm-tool-btn.cmm-retro:hover {
  background: rgba(48, 34, 92, 0.96);
  border-color: rgba(111, 255, 233, 0.72);
  box-shadow: 0 0 14px -3px rgba(111, 255, 233, 0.42);
}

/* Enlace en modales de inicio */
.cmm-modal-back-wrap {
  margin-top: 12px;
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.cmm-modal-back-link {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  text-decoration: none;
  font-family: var(--cmm-font);
  font-weight: 600;
  font-size: 0.8rem;
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(8, 12, 28, 0.72);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: #DCE8FF;
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
  cursor: pointer;
  transition:
    transform 0.16s var(--cmm-ease),
    background-color 0.16s ease,
    border-color 0.16s ease,
    color 0.16s ease;
}

.cmm-modal-back-link:hover {
  transform: translateY(-1px);
  background: rgba(20, 28, 58, 0.9);
  border-color: rgba(111, 255, 233, 0.42);
  color: #FFF;
}

/* Fallback flotante si un juego futuro no tiene <header> */
.cmm-back-floating {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  left: max(10px, env(safe-area-inset-left));
  z-index: 9000;
}

/* ==================== CAJÓN RÁPIDO "CAMBIAR DE JUEGO" (COMMAND PALETTE) ==================== */
#cmm-drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(3, 5, 14, 0.74);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  z-index: 9500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.22s ease, visibility 0.22s ease;
}

#cmm-drawer-backdrop.open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.cmm-drawer-panel {
  width: min(94vw, 680px);
  max-height: 88dvh;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
  background: linear-gradient(180deg, rgba(19, 24, 50, 0.96) 0%, rgba(10, 14, 30, 0.98) 100%);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 22px;
  padding: 20px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.2),
    0 32px 74px -16px rgba(0, 0, 0, 0.88),
    0 0 48px -18px rgba(168, 85, 247, 0.3);
  font-family: var(--cmm-font);
  color: #FFF;
  transform: translateY(10px) scale(0.975);
  transition: transform 0.28s var(--cmm-ease);
}

.cmm-drawer-panel::-webkit-scrollbar {
  width: 6px;
}

.cmm-drawer-panel::-webkit-scrollbar-track {
  background: transparent;
}

.cmm-drawer-panel::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.18);
  border-radius: 999px;
}

#cmm-drawer-backdrop.open .cmm-drawer-panel {
  transform: translateY(0) scale(1);
}

.cmm-drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.cmm-drawer-head-left {
  display: inline-flex;
  align-items: center;
  gap: 9px;
}

.cmm-drawer-head h3 {
  margin: 0;
  font-family: var(--cmm-display);
  font-weight: 800;
  letter-spacing: -0.015em;
  font-size: 1.32rem;
  color: #FFF;
}

.cmm-drawer-head-right {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.cmm-esc-hint {
  display: inline-flex;
  align-items: center;
  padding: 3px 7px;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #93A5CC;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.cmm-drawer-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 11px;
}

.cmm-drawer-card {
  position: relative;
  aspect-ratio: 16 / 10;
  border-radius: 15px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.12);
  text-decoration: none;
  display: block;
  background: #0A0F24;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.16), 0 10px 24px -10px rgba(0, 0, 0, 0.72);
  transition:
    transform 0.24s var(--cmm-ease),
    border-color 0.2s ease,
    box-shadow 0.24s ease;
}

.cmm-drawer-card::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(
    220px circle at var(--mx, 50%) var(--my, 50%),
    rgba(255, 255, 255, 0.16),
    transparent 62%
  );
  opacity: 0;
  transition: opacity 0.22s ease;
  pointer-events: none;
  z-index: 2;
}

.cmm-drawer-card:hover::after {
  opacity: 1;
}

.cmm-drawer-card:hover {
  transform: translateY(-3px);
  border-color: rgba(111, 255, 233, 0.55);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.25),
    0 18px 34px -12px rgba(0, 0, 0, 0.85),
    0 0 24px -8px rgba(111, 255, 233, 0.38);
}

.cmm-drawer-card.is-current {
  border-color: rgba(57, 255, 20, 0.65);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.24),
    0 0 24px -6px rgba(57, 255, 20, 0.42);
}

.cmm-drawer-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.45s var(--cmm-ease);
}

.cmm-drawer-card:hover img {
  transform: scale(1.06);
}

.cmm-drawer-badge {
  position: absolute;
  top: 7px;
  left: 7px;
  z-index: 3;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(6, 9, 22, 0.76);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  font-size: 0.56rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #DCE8FF;
}

.cmm-drawer-card.is-current .cmm-drawer-badge {
  background: rgba(16, 46, 26, 0.88);
  border-color: rgba(57, 255, 20, 0.5);
  color: #9CFF8A;
}

.cmm-drawer-title {
  position: absolute;
  inset: auto 0 0 0;
  z-index: 3;
  padding: 18px 9px 7px;
  background: linear-gradient(180deg, transparent 0%, rgba(5, 7, 18, 0.72) 48%, rgba(5, 7, 18, 0.95) 100%);
  font-family: var(--cmm-display);
  font-weight: 800;
  font-size: 0.8rem;
  color: #FFF;
  line-height: 1.12;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.cmm-drawer-prog {
  font-family: var(--cmm-font);
  font-size: 0.62rem;
  font-weight: 600;
  color: #A8B9DC;
  font-variant-numeric: tabular-nums;
}

.cmm-drawer-prog.is-lit {
  color: var(--cmm-cyan);
}

.cmm-drawer-foot {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

/* ==================== TUTORIAL INTERACTIVO PASO A PASO (LINEAR × APPLE ARCADE KIDS) ==================== */
#cmm-tut-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(3, 5, 14, 0.78);
  backdrop-filter: blur(15px);
  -webkit-backdrop-filter: blur(15px);
  z-index: 9600;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.22s ease, visibility 0.22s ease;
}

#cmm-tut-backdrop.open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.cmm-tut-panel {
  width: min(94vw, 520px);
  max-height: 90dvh;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
  background: linear-gradient(180deg, rgba(20, 26, 56, 0.97) 0%, rgba(10, 14, 30, 0.99) 100%);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 24px;
  padding: 20px 22px 18px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.22),
    0 34px 76px -16px rgba(0, 0, 0, 0.9),
    0 0 54px -18px var(--cmm-accent-glow, rgba(111, 255, 233, 0.32));
  font-family: var(--cmm-font);
  color: #F8FAFC;
  transform: translateY(12px) scale(0.97);
  transition: transform 0.28s var(--cmm-ease);
}

#cmm-tut-backdrop.open .cmm-tut-panel {
  transform: translateY(0) scale(1);
}

.cmm-tut-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.cmm-tut-head-left {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.cmm-tut-kicker {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(111, 255, 233, 0.12);
  border: 1px solid rgba(111, 255, 233, 0.34);
  color: var(--cmm-cyan);
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  white-space: nowrap;
}

.cmm-tut-game-name {
  font-family: var(--cmm-display);
  font-weight: 800;
  font-size: 0.98rem;
  color: #E2ECFF;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cmm-tut-stage {
  position: relative;
  border-radius: 18px;
  background:
    radial-gradient(ellipse 80% 70% at 50% 0%, rgba(168, 85, 247, 0.22), transparent 72%),
    linear-gradient(180deg, #0D1533 0%, #080E22 100%);
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14);
  padding: 12px 14px;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 132px;
  overflow: hidden;
}

.cmm-tut-stage svg {
  width: 100%;
  max-width: 310px;
  height: auto;
  display: block;
  filter: drop-shadow(0 8px 16px rgba(0, 0, 0, 0.45));
}

/* Animaciones suaves y divertidas en las ilustraciones SVG (para chicos de 3 a 9 años) */
@keyframes cmmTutBob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

@keyframes cmmTutSway {
  0%, 100% { transform: translateX(-16px); }
  50% { transform: translateX(16px); }
}

@keyframes cmmTutSlideBar {
  0%, 100% { transform: translateX(-46px); }
  50% { transform: translateX(46px); }
}

@keyframes cmmTutRing {
  0%, 100% { transform: rotate(0deg); }
  20% { transform: rotate(-11deg); }
  40% { transform: rotate(11deg); }
  60% { transform: rotate(-7deg); }
  80% { transform: rotate(6deg); }
}

@keyframes cmmTutPulse {
  0%, 100% { transform: scale(1); opacity: 0.92; }
  50% { transform: scale(1.1); opacity: 1; }
}

.cmm-tut-stage .cmm-anim-bob {
  animation: cmmTutBob 1.7s ease-in-out infinite;
  transform-box: fill-box;
  transform-origin: center;
}

.cmm-tut-stage .cmm-anim-sway {
  animation: cmmTutSway 2.1s ease-in-out infinite;
  transform-box: fill-box;
  transform-origin: center;
}

.cmm-tut-stage .cmm-anim-slide {
  animation: cmmTutSlideBar 1.6s ease-in-out infinite;
  transform-box: fill-box;
  transform-origin: center;
}

.cmm-tut-stage .cmm-anim-ring {
  animation: cmmTutRing 1.4s ease-in-out infinite;
  transform-box: fill-box;
  transform-origin: top center;
}

.cmm-tut-stage .cmm-anim-pulse {
  animation: cmmTutPulse 1.5s ease-in-out infinite;
  transform-box: fill-box;
  transform-origin: center;
}

.cmm-tut-voice-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(111, 255, 233, 0.14);
  border: 1px solid rgba(111, 255, 233, 0.44);
  color: var(--cmm-cyan);
  font-family: var(--cmm-display);
  font-weight: 800;
  font-size: 0.82rem;
  cursor: pointer;
  transition: transform 0.16s var(--cmm-ease), background-color 0.16s ease, box-shadow 0.2s ease;
}

.cmm-tut-voice-btn:hover {
  transform: translateY(-1px);
  background: rgba(111, 255, 233, 0.24);
  box-shadow: 0 0 16px -4px rgba(111, 255, 233, 0.5);
}

.cmm-tut-voice-btn.is-speaking {
  background: rgba(57, 255, 20, 0.2);
  border-color: rgba(57, 255, 20, 0.6);
  color: #B4FFA4;
}

.cmm-tut-voice-btn:focus-visible {
  outline: 2px solid var(--cmm-cyan);
  outline-offset: 2px;
}

.cmm-tut-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  animation: cmmTutSlideIn 0.24s var(--cmm-ease);
}

@keyframes cmmTutSlideIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.cmm-tut-step-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.cmm-tut-step-num {
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--cmm-gold);
}

.cmm-tut-title {
  margin: 0;
  font-family: var(--cmm-display);
  font-weight: 800;
  font-size: clamp(1.3rem, 3.4vw, 1.56rem);
  line-height: 1.1;
  letter-spacing: -0.015em;
  color: #FFF;
}

.cmm-tut-desc {
  margin: 0;
  font-family: var(--cmm-display);
  font-size: clamp(0.98rem, 2.3vw, 1.08rem);
  font-weight: 700;
  line-height: 1.38;
  color: #D8E4FF;
}

.cmm-tut-desc strong {
  color: var(--cmm-gold);
  font-weight: 800;
}

.cmm-tut-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 2px;
}

.cmm-tut-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.16);
  font-size: 0.78rem;
  font-weight: 700;
  color: #F2F7FF;
}

.cmm-tut-actions .cmm-comp-btn.primary {
  padding: 10px 18px;
  font-size: 0.96rem;
  border-radius: 13px;
}

.cmm-tut-chip.is-touch {
  background: rgba(111, 255, 233, 0.1);
  border-color: rgba(111, 255, 233, 0.3);
  color: var(--cmm-cyan);
}

.cmm-tut-chip.is-tip {
  background: rgba(255, 209, 102, 0.11);
  border-color: rgba(255, 209, 102, 0.34);
  color: var(--cmm-gold);
}

.cmm-kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(5, 8, 20, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.22);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.6);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.7rem;
  font-weight: 800;
  color: #FFF;
}

.cmm-tut-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.09);
}

@media (max-width: 480px) {
  .cmm-tut-panel {
    padding: 16px 15px 15px;
  }
  .cmm-tut-foot {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  .cmm-tut-dots {
    justify-content: center;
  }
  .cmm-tut-actions {
    width: 100%;
    justify-content: flex-end;
    flex-wrap: wrap;
  }
  .cmm-tut-actions .cmm-comp-btn {
    padding: 8px 11px;
    font-size: 0.78rem;
  }
}

.cmm-tut-dots {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.cmm-tut-dot {
  width: 9px;
  height: 9px;
  padding: 0;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.16);
  cursor: pointer;
  transition: width 0.24s var(--cmm-ease), background-color 0.2s ease, border-color 0.2s ease;
}

.cmm-tut-dot.active {
  width: 24px;
  background: var(--cmm-cyan);
  border-color: rgba(255, 255, 255, 0.55);
}

.cmm-tut-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.cmm-tut-skip {
  background: transparent;
  border: none;
  color: #8CA0C8;
  font-family: var(--cmm-font);
  font-size: 0.76rem;
  font-weight: 600;
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
  transition: color 0.16s ease, background-color 0.16s ease;
}

.cmm-tut-skip:hover {
  color: #FFF;
  background: rgba(255, 255, 255, 0.07);
}

.cmm-tool-btn.is-help-pulse {
  border-color: rgba(255, 209, 102, 0.55);
  color: var(--cmm-gold);
}

/* ==================== PAUSA REAL & GUÍA LIVIANA DE PRIMERA VEZ ==================== */
#cmm-pause-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(3, 5, 14, 0.72);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  z-index: 9450;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

#cmm-pause-backdrop.open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.cmm-pause-panel {
  width: min(92vw, 390px);
  background: linear-gradient(180deg, rgba(20, 26, 56, 0.96) 0%, rgba(10, 14, 30, 0.98) 100%);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 24px;
  padding: 22px 20px;
  text-align: center;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.22), 0 30px 70px -16px rgba(0, 0, 0, 0.9);
  font-family: var(--cmm-font);
  color: #F8FAFC;
  transform: translateY(10px) scale(0.96);
  transition: transform 0.25s var(--cmm-ease);
}

#cmm-pause-backdrop.open .cmm-pause-panel {
  transform: translateY(0) scale(1);
}

.cmm-pause-title {
  margin: 0 0 6px;
  font-family: var(--cmm-display);
  font-weight: 800;
  font-size: 1.55rem;
  color: var(--cmm-gold);
}

.cmm-pause-sub {
  margin: 0 0 16px;
  font-size: 0.86rem;
  color: #C7D6F5;
}

.cmm-pause-actions {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.cmm-pause-actions .cmm-comp-btn {
  width: 100%;
  padding: 11px 16px;
  font-size: 0.92rem;
}

/* Píldora flotante liviana de tutorial (sin tapar la pantalla de inicio al entrar) */
#cmm-guide-toast {
  position: fixed;
  right: max(14px, env(safe-area-inset-right));
  bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 9200;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px 8px 14px;
  border-radius: 999px;
  background: rgba(12, 18, 40, 0.92);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(255, 209, 102, 0.48);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18), 0 16px 36px -8px rgba(0, 0, 0, 0.78);
  font-family: var(--cmm-display);
  font-weight: 800;
  font-size: 0.86rem;
  color: #FFF;
  cursor: pointer;
  animation: cmmToastIn 0.35s var(--cmm-ease);
}

@keyframes cmmToastIn {
  from { opacity: 0; transform: translateY(14px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

#cmm-guide-toast:hover {
  border-color: var(--cmm-gold);
  background: rgba(20, 28, 60, 0.96);
}

#cmm-guide-toast .cmm-toast-open {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--cmm-gold);
}

#cmm-guide-toast .cmm-toast-dismiss {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #DCE8FF;
  border-radius: 999px;
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

/* Chispita táctil sutil en cada toque (cero toques muertos para chicos de 3-9 años) */
.cmm-tap-ripple {
  position: fixed;
  pointer-events: none;
  z-index: 9150;
  width: 26px;
  height: 26px;
  margin-left: -13px;
  margin-top: -13px;
  border-radius: 50%;
  border: 2px solid rgba(111, 255, 233, 0.72);
  box-shadow: 0 0 12px rgba(255, 209, 102, 0.45);
  animation: cmmTapRipple 0.42s var(--cmm-ease) forwards;
}

@keyframes cmmTapRipple {
  0% { transform: scale(0.35); opacity: 0.9; }
  100% { transform: scale(1.75); opacity: 0; }
}

/* ==================== TIP SUAVE DE ROTACIÓN EN MOBILE VERTICAL ==================== */
#cmm-rotate-tip {
  display: none;
  position: fixed;
  left: 50%;
  bottom: max(12px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 9100;
  background: rgba(10, 14, 30, 0.9);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(111, 255, 233, 0.38);
  border-radius: 999px;
  padding: 7px 10px 7px 13px;
  font-family: var(--cmm-font);
  font-size: 0.75rem;
  font-weight: 600;
  color: #EEF4FF;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.16), 0 12px 30px rgba(0, 0, 0, 0.72);
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

#cmm-rotate-tip button {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: #FFF;
  border-radius: 999px;
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

body.cmm-widescreen-game[data-device="mobile"][data-orientation="portrait"] #cmm-rotate-tip:not(.dismissed) {
  display: inline-flex;
}

/* ==================== ADAPTACIONES ESPECÍFICAS MOBILE & TOUCH ==================== */
@media (max-width: 640px) {
  body.cmm-portrait-game.cmm-enhanced {
    padding: 0;
    gap: 0;
  }
  body.cmm-portrait-game #cartridge-shell,
  body.cmm-portrait-game #arcade-shell {
    max-width: 100%;
    max-height: none;
    height: 100dvh;
    border-radius: 0;
    border-width: 0;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .cmm-back-inline .cmm-back-txt {
    display: none;
  }
  .cmm-tool-btn[data-fs-btn] {
    display: none;
  }
  .cmm-esc-hint,
  #cmm-guide-toast {
    display: none;
  }
  #hud,
  #top-bar,
  #utility-bar {
    gap: 4px !important;
  }
  .cmm-start-banner {
    height: 82px;
    margin-bottom: 8px;
  }
  .cmm-drawer-panel {
    padding: 16px;
  }
  .cmm-drawer-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px;
  }
}

/* En celulares horizontales (pantalla baja), ocultar banner del modal para que quepa todo sin scroll */
@media (max-height: 560px) {
  .cmm-start-banner {
    display: none;
  }
}

/* Dispositivos táctiles: ocultar pistas de teclado innecesarias y asegurar targets cómodos */
@media (hover: none) and (pointer: coarse) {
  .ctrl-pad small,
  #bottom-tip {
    display: none !important;
  }
  .ctrl-pad,
  .move-btn {
    min-height: 54px;
  }
}

@media (prefers-reduced-motion: reduce) {
  body.cmm-enhanced,
  #cmm-drawer-backdrop,
  .cmm-drawer-panel,
  .cmm-drawer-card,
  .cmm-drawer-card img,
  #cmm-tut-backdrop,
  .cmm-tut-panel,
  .cmm-tut-body,
  .cmm-tut-stage * {
    animation: none !important;
    transition: none !important;
  }
}
