/* ============================================================
   ASIN - Compatibilidad con celular y tableta
   (se carga al final para ajustar lo anterior sin tocarlo)
   ============================================================ */

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;          /* evita el zoom por doble toque */
    overscroll-behavior-y: none;         /* evita el "jalón" de recarga al saltar */
}
button, .btn { touch-action: manipulation; }

/* --- Área de juego: nunca más alta que la pantalla ---------------
   El lienzo siempre mide 800×480 (proporción 5:3) y se escala.
   Ancho máximo = alto disponible × 800/480, así cabe en horizontal. */
.m1-platformer-container {
    width: min(100%, calc((100vh - 24px) * 1.6667));
    width: min(100%, calc((100dvh - 24px) * 1.6667));
    max-width: 800px;
    container-type: inline-size;
    touch-action: none;                  /* el dedo juega, no desplaza la página */
    -webkit-user-select: none; user-select: none;
}

/* --- Controles táctiles: ◄ ► juntos a la izquierda, ▲ a la derecha --- */
.m1-touch-controls {
    align-items: flex-end;
    padding-left: max(14px, env(safe-area-inset-left));
    padding-right: max(14px, env(safe-area-inset-right));
    bottom: 10px;
}
.m1-touch-dir { display: flex; gap: 14px; }
.m1-touch-btn {
    width: 64px; height: 64px;                       /* respaldo */
    width: clamp(48px, 10cqw, 76px);
    height: clamp(48px, 10cqw, 76px);
    font-size: clamp(1.2rem, 4cqw, 1.8rem);
    -webkit-user-select: none; user-select: none;
    -webkit-touch-callout: none;
}
.m1-touch-jump {
    width: 72px; height: 72px;
    width: clamp(56px, 12cqw, 88px);
    height: clamp(56px, 12cqw, 88px);
}
/* Con ratón y teclado los botones en pantalla estorban */
@media (hover: hover) and (pointer: fine) {
    .m1-touch-controls { display: none; }
}

/* --- Aviso "gira tu dispositivo" (celular en vertical durante los niveles) --- */
.rotate-notice {
    display: none;
    position: fixed; inset: 0; z-index: 9999;
    background: rgba(11, 18, 32, 0.96);
    color: #fff; text-align: center;
    flex-direction: column; align-items: center; justify-content: center;
    padding: 2rem; font-family: inherit;
}
.rotate-notice.show { display: flex; }
.rotate-notice .rotate-icon {
    font-size: 4rem; margin-bottom: 1rem;
    animation: rotate-hint 2s ease-in-out infinite;
}
.rotate-notice p { font-size: 1.2rem; max-width: 22rem; line-height: 1.4; }
@keyframes rotate-hint {
    0%, 20% { transform: rotate(0deg); }
    60%, 100% { transform: rotate(-90deg); }
}
@media (prefers-reduced-motion: reduce) {
    .rotate-notice .rotate-icon { animation: none; }
}

/* --- Celular en horizontal (poca altura): compactar --- */
@media (max-height: 480px) and (orientation: landscape) {
    .m1-question-box { max-height: 92vh; overflow-y: auto; padding: 1rem; }
}

/* --- Pantallas muy angostas --- */
@media (max-width: 400px) {
    .btn { font-size: 1rem; }
}

/* --- Celular en horizontal: el nivel debe caber completo en la pantalla ---
   mobile.js pone la clase modo-juego en <body> mientras hay un nivel activo. */
@media (max-height: 520px) and (orientation: landscape) {
    body.modo-juego .mission-header { display: none; }
    body.modo-juego .screen.active { padding: 4px; min-height: 100vh; min-height: 100dvh; }
    body.modo-juego .mission-content { padding: 4px; max-height: none; border-radius: 8px; }
    body.modo-juego .m1-platformer-container {
        width: min(100%, calc((100vh - 14px) * 1.6667));
        width: min(100%, calc((100dvh - 14px) * 1.6667));
    }
    /* Misión 2: línea de ayuda bajo el lienzo */
    body.modo-juego #mission-2-game .m1-platformer-container {
        width: min(100%, calc((100dvh - 44px) * 1.6667));
    }
    /* Misión 3: cronómetro arriba y tablero de gemas abajo, en una fila cada uno */
    body.modo-juego #m3-phase-game .m1-platformer-container {
        width: min(100%, calc((100dvh - 70px) * 1.6667));
    }
    /* Los botones flotantes (escudo, pausa, sonido) quedan en las esquinas: dejarles espacio */
    body.modo-juego .m3-game-header { padding: 3px 112px 3px 56px; margin-bottom: 4px; gap: 0.6rem; }
    body.modo-juego .m3-board { padding: 4px 8px; margin-top: 4px !important; }
    body.modo-juego .m3-board .board-label { display: none; }
    body.modo-juego .m3-board-slots { flex-direction: row; gap: 6px; }
}

/* --- Diálogos: que nada se salga de la pantalla en celular --- */
.dialogue-box { min-width: 0; max-width: 100%; box-sizing: border-box; overflow-wrap: anywhere; }
.character-dialogue { max-width: 100%; }
.m2-intro-controls, .narration-controls { flex-wrap: wrap; justify-content: center; }
@media (max-width: 600px) {
    .dialogue-box { padding: var(--spacing-sm); }
    .mission-content { padding: var(--spacing-md); }
    .m2-intro-controls .btn, .narration-controls .btn { flex: 1 1 40%; min-width: 0; }
}
.dialogue-box .btn, .dialogue-box button { overflow-wrap: normal; word-break: normal; white-space: nowrap; }
@media (max-width: 600px) {
    .m2-intro-controls .btn, .narration-controls .btn { padding-left: 0.6rem; padding-right: 0.6rem; flex: 1 1 auto; }
}

/* --- Celular en vertical: pantallas de registro y menú más compactas ---
   Menos margen y relleno para que el formulario aproveche el ancho y no
   haya que desplazarse tanto; Ebro centrado y más pequeño. */
@media (max-width: 600px) {
    .screen.active { padding: 8px; }
    .create-content { padding: 3.4rem 0.9rem 1rem; max-height: none; border-radius: 14px; }  /* espacio arriba: botones flotantes */
    .create-content h2 { font-size: 1.45rem; margin-bottom: 0.6rem; }
    .ebro-message { font-size: 0.95rem; padding: 0.7rem 0.8rem; margin-bottom: 0.8rem; }
    .create-content .character-portrait {
        display: block; width: 110px; height: 110px; margin: 0 auto 0.8rem;
    }
    .create-content .form-group { margin-bottom: 0.8rem; }
    .create-content .form-group label { font-size: 1rem; margin-bottom: 0.3rem; }
    .create-content input[type="text"], .create-content select { font-size: 1rem; padding: 0.6rem 0.75rem; }
    .create-content .form-row { gap: 0.6rem; }
    .create-content .form-row .form-group { flex: 1 1 130px; }
}
@media (max-width: 600px) {
    .create-content > .btn, .create-content #btn-start-game { width: 100%; }
}

/* --- Escenas con imagen + narración (introducción y briefings) ---
   Equilibrio computadora / celular: la imagen se ajusta a la altura de la
   ventana para que el texto y el botón «Continuar» queden siempre a la vista,
   sin depender del desplazamiento. En computadora conserva su tamaño grande. */
.intro-scene { --txt-alto: clamp(90px, 18dvh, 220px); }
.intro-scene .text-window { max-height: var(--txt-alto); }
.scene-images .scene-image {
    height: clamp(110px, calc(100vh - 300px - var(--txt-alto)), 552px);
    height: clamp(110px, calc(100dvh - 300px - var(--txt-alto)), 552px);
}
.scene-images.dos-imagenes .scene-image {
    height: clamp(110px, calc(100vh - 300px - var(--txt-alto)), 504px);
    height: clamp(110px, calc(100dvh - 300px - var(--txt-alto)), 504px);
}
@media (max-width: 720px) {
    .scene-images .scene-image { height: clamp(150px, calc(100dvh - 260px - var(--txt-alto)), 360px); }
    .scene-images.dos-imagenes .scene-image { height: clamp(110px, calc((100dvh - 260px - var(--txt-alto)) / 2), 220px); }
}
/* Celular acostado (poca altura): imagen a la izquierda y texto a la derecha */
@media (max-height: 520px) and (orientation: landscape) {
    #intro-screen.active { padding: 6px; align-items: flex-start; }
    .intro-scene { display: flex; flex-direction: row; align-items: stretch; --txt-alto: calc(100dvh - 150px); }
    .intro-scene .scene-images { flex: 0 0 46%; flex-direction: column; border-radius: 8px 0 0 8px; }
    .intro-scene .scene-images .scene-image,
    .intro-scene .scene-images.dos-imagenes .scene-image { height: auto; flex: 1 1 0; min-height: 0; max-height: calc(100dvh - 12px); }
    .intro-scene .narration-box { flex: 1 1 auto; min-width: 0; padding: 0.7rem 1rem; display: flex; flex-direction: column; }
    .intro-scene .text-window { flex: 1 1 auto; max-height: none; min-height: 60px; }
}

/* --- Una sola barra de scroll (la del navegador) ---------------------
   El recuadro blanco de las misiones tenía su propia barra interna
   (max-height 90vh + overflow auto) además de la de la página, y con el
   mouse costaba arrastrarla. Ahora el recuadro crece y la página se
   desplaza con su barra normal o la rueda del mouse. */
.mission-content {
    max-height: none;
    overflow: visible;
}

/* --- Scroll de la página: un solo desplazamiento, el del navegador --------
   <html> hace el scroll de toda la página (rueda, touchpad, barra lateral y
   teclado). <body> ya no es un segundo contenedor con scroll. */
html { overflow-y: auto !important; overflow-x: hidden !important; }
body { overflow: visible !important; }

/* Las cajas de narración recortan sus esquinas sin volverse contenedores de scroll.
   Los botones de continuar van al final del contenido (se llega con la rueda o la barra). */
.intro-scene, .story-dialogue { overflow: hidden; overflow: clip; }
.story-controls, .narration-controls, .m2-intro-controls {
    position: static;
    box-shadow: none;
}

/* Aviso de privacidad */
.privacy-text { font-size: 0.95rem; line-height: 1.5; margin-bottom: 12px; max-height: 50vh; overflow-y: auto; padding-right: 6px; }
.privacy-text p { margin: 0 0 10px; }
.privacy-date { color: #666; font-size: 0.85rem; }
.privacy-check { display: flex; gap: 10px; align-items: flex-start; margin: 8px 0 14px; font-weight: 600; cursor: pointer; }
.privacy-check input { width: 22px; height: 22px; flex: 0 0 auto; margin-top: 2px; }
.privacy-buttons { display: flex; gap: 12px; justify-content: space-between; flex-wrap: wrap; }
.privacy-buttons .btn { flex: 1 1 140px; }
