/* =========================================
   1. FUENTES Y CONFIGURACIÓN BÁSICA
   ========================================= */
@font-face {
    font-family: "Interlope";
    src: local("Interlope"), url("Interlope-Regular.woff2") format(woff2);
}
@font-face {
    font-family: "JetBrains";
    src: local("JetBrains"), url("JetBrainsMono-VariableFont_wght.ttf") format(truetype);
}

@font-face {
    font-family: "Baskervville";
    src: local("Baskervville-Italic"), url("Baskervville-Italic.woff2") format(truetype);
}

:root {
    color-scheme: light; /* Fuerza modo claro */
}

html {
    background-color: #ffffff;
    /* ESTO ES LA MAGIA DEL TIKTOK: */
    scroll-snap-type: y mandatory; 
    scroll-behavior: smooth;
}
html.no-snap {
    scroll-snap-type: none !important;
}
body {
    margin: 0;
    overflow-x: hidden;
    overflow-y: auto !important;
    background: #ffffff !important;
    font-family: 'JetBrains', monospace;
    color: black;
    height: 100dvh;
}

/* =========================================
   2. ANIMACIONES
   ========================================= */
/* Delays más agresivos y rápidos */
#logo.fade-in-item { animation-delay: 0.1s; }
.fade-in-item:nth-child(1) { animation-delay: 0.2s; }
.fade-in-item:nth-child(2) { animation-delay: 0.4s; }
.fade-in-item:nth-child(3) { animation-delay: 0.6s; }
.fade-in-item:nth-child(4) { animation-delay: 0.8s; }
.fade-in-item:nth-child(5) { animation-delay: 1.0s; }
.fade-in-item:nth-child(6) { animation-delay: 1.2s; }

/* Hacer la animación un poco más rápida (de 0.3s a 0.5s) 
   pero que el movimiento sea más corto (10px en lugar de 20px) */
@keyframes aparecerSuave {
    from { 
        opacity: 0; 
        transform: translateY(10px); 
    }
    to { 
        opacity: 1; 
        transform: translateY(0); 
    }
}

.fade-in-item {
    opacity: 0;
    animation: aparecerSuave 0.5s ease-out forwards;
    will-change: opacity, transform; /* Ayuda a Safari a renderizar más rápido */
    transition: transform 0.1s ease-out, opacity 0.5s ease;

}

/* =========================================
   3. SECCIÓN DE TEXTO (INTRO)
   ========================================= */
#fondo {
    background: #ffffff;
    background: linear-gradient(180deg, rgba(255, 255, 255, 1) 0%, rgba(235, 225, 163, 1) 89%, #EEE6B2 100%);
    width: 100%;
    
    /* Para que funcione como una "slide" de TikTok, debe medir al menos el alto de la pantalla */
    min-height: 100dvh; 
    padding-bottom: 50px;
    
    /* PUNTO DE IMÁN 1: El inicio */
    scroll-snap-align: start; 
    
    /* Opcional: Centra el contenido verticalmente si sobra espacio */
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.intro-text {
    /* Padding reducido en móvil para ganar espacio */
    padding: 20px 20px 0px 20px; 
    color: black !important; /* Vital para ver el texto */
    text-align: center;
    max-width: 800px;
    margin: 10px auto 0px auto;
    font-size: 1rem; /* Letra base más pequeña en móvil */
    line-height: 1.5;
}

#logo-wrapper {
    display: flex;
    width: 100%;
    align-content: center;
    justify-content: center; /* Centrado en móvil */
}

#logo {
    width: auto;
    margin: 10px auto 30px auto;
    font-family: 'JetBrains';
    font-size: 30px; /* Logo ajustado para móvil */
    line-height: 0.9;
    font-weight: bold;
    font-style: italic;
    text-align: left;
    transition: opacity 0.3s ease;
}

/* UTILIDADES FLEX (Móvil y Desktop) */
.flex {
    width: 100%;
    display: flex;
    margin-bottom: 15px; /* Separación entre bloques */
}

.j-center { justify-content: center; }
.j-end { justify-content: flex-end; }
.text-left { text-align: left; }
.text-justify { text-align: justify; }
.texto-azul { color: #3B53C9; font-style: italic; margin-bottom: 15px; }

/* REGLA DE ANCHOS MÓVIL: 
   En celular, casi todo ocupa el 90-100% para poder leerse,
   pero respetando la alineación flex (izq/der/centro) */
.w-7, .w-6, .w-2, .w-3{
    width: 90%; 
}
.w-4{
    width:50%;
}
/* =========================================
   4. CONTENEDOR FÍSICO
   ========================================= */
canvas {
    display: block;
    z-index: 0; 
}

#caidaContainer {
    z-index: 10;
    width: 100vw;
   height: calc(var(--vh, 1vh) * 100);
    position: relative;
    overflow: hidden;
    background: linear-gradient(#EEE6B2 0%, #EEE6B2 20%,#E0CE51 50%, #3B53C9 65%, #BF425D 100%);
    overflow: hidden;
    touch-action: pan-y; /* Permite scroll en móvil */
    /* PUNTO DE IMÁN 2: El juego */
    scroll-snap-align: start; 
    
    /* Esto fuerza que el navegador se detenga aquí sí o sí */
    scroll-snap-stop: always;
    padding-bottom: env(safe-area-inset-bottom);
    padding-top: env(safe-area-inset-top);
}

/* =========================================
   5. BLOQUE CENTRAL (Formulario)
   ========================================= */
#bloqueCentral {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 45%; /* Más ancho en móvil */
    max-width: 400px;
    display: flex;
    flex-direction: column;
    align-items: center;
    background: transparent;
    z-index: 9999 !important;
    pointer-events: auto !important;
}

#formPublicar {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 0 !important;
    padding: 0 !important;
    gap: 0 !important;
}

#inputRespuesta {
    font-family: 'Baskervville', serif;
    width: 100%;
    height: 100px;
    background: #ffffff;
    border: 2px solid #555;
    color: black;
    resize: none;
    box-sizing: border-box;
    font-size: 16px !important; /* Mínimo 16px para evitar que iOS haga zoom y mueva todo */
    line-height: 1.2 !important;
    
    margin: 0 !important;         /* Elimina márgenes naranjas del navegador */
    display: block;
    vertical-align: top;
    
    /* === 2. RESETEO NATIVO DE iOS === */
   -webkit-appearance: none;
    appearance: none;
    margin: 0;
    /* Asegúrate de que el box-sizing sea border-box para que el padding no lo infle */
    box-sizing: border-box;
    /* === 4. HABILITAR ESCRITURA EN MÓVIL === */
    user-select: text !important;
    -webkit-user-select: text !important;
    -webkit-transform: translateZ(0);
    pointer-events: auto !important;
    z-index: 99999; 
    position: relative;
}
#charCount {
    width: 100%;
    text-align: right;
    padding-top: 5px;
    margin-bottom: 15px;
    color: #00000080;
    font-size: 10px;
    user-select: none;
}

#formPublicar button {
    font-family: 'JetBrains', monospace;
    font-size: 12pt;
    background: #000000;
    color: #ffffff;
    font-weight: bold;
    border: 2px solid #000000;
    padding: 10px 25px;
    width: fit-content;
    transition: 0.3s;
    
    pointer-events: auto !important;
    touch-action: manipulation;
    z-index: 999999;
    position: relative;
    user-select: none;
}

#formPublicar button:hover {
    background: #ffffff;
    color: #000000;
}

/* =========================================
   6. BOLAS (PALABRAS)
   ========================================= */
.falling-ball {
    position: absolute;
    top: 0;
    left: 0;
    padding: 6px 10px;
    line-height: 1em;
    color: white;
    max-width: 20vw;
    overflow-wrap: break-word;
    user-select: none;
    will-change: transform;
    transition: font-size 0.2s ease;
}}
#caidaContainer, #bloqueCentral, #inputRespuesta, button {
    /* Esto le dice a iOS: "No esperes un segundo toque para hacer zoom, solo procesa el click" */
    touch-action: manipulation; 
}
/* Colores y Fuentes */
.falling-ball:nth-child(4n + 1) { background: #3B53C9; }
.falling-ball:nth-child(4n + 2) { background: #E0CE51; color: black; }
.falling-ball:nth-child(4n + 3) { background: #BF425D; }
.falling-ball:nth-child(4n + 4) { background: #ffffff; color: black; }
.falling-ball:nth-child(2n + 1) { font-family: 'Baskervville';}
.falling-ball:nth-child(2n + 2) { font-family: 'JetBrains'; }
.falling-ball:active { cursor: grabbing; background: #000000 !important; color: white !important; }

/* =========================================
   CONTROLES / DOCK (ESTILO PAPEL / FLAT)
   ========================================= */
.controles {
    position: fixed;
    top: 30px; /* Se queda arriba pegada */
    left: 0;
    width: 100%;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    
    /* Estado inicial: Invisible */
    opacity: 0;
    pointer-events: none;
    transform: translateY(-10px); /* Un pequeño desplazamiento para el efecto */
    transition: opacity 0.4s ease, transform 0.4s ease;
}

.controles.visible {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}
.dock-container {
    border-radius: 6px; /* Apenas redondeado, como una tarjeta */
    pointer-events: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0; /* Sin espacio, los bordes separan */
    
    /* ESTÉTICA PAPEL PLANO */
    background: #ffffff; /* Papel sólido */
    padding: 0; /* El padding lo darán los botones */
    
    /* Borde fino y definido */
    border: 1px solid #000000;
    
    
    /* Sin sombra difusa. Opcional: Sombra dura muy pequeña para separarlo del fondo */
    box-shadow: 2px 2px 0px rgba(0,0,0,0.15); 
}

/* GRUPO DE TAMAÑO */
.dock-group {
    display: flex;
    align-items: center;
    border-right: 1px solid #000; /* Línea divisoria de tinta */
}

/* BOTONES PLANOS */
.dock-container button {
    width: 40px;
    height: 34px; /* Un poco más rectangulares */
    
    background: transparent;
    border: none;
    border-radius: 0; /* Cuadrados para encajar en la grilla */
    color: #000;
    
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.2s ease;
    
    /* Líneas divisorias entre botones */
    border-right: 1px solid #000;
}

/* El último botón no lleva línea a la derecha */
.dock-container button:last-child {
    border-right: none;
}
/* Arreglo para el borde del botón dentro del grupo */
.dock-group button:last-child {
    border-right: none; 
}

/* INTERACCIÓN TIPO "RESALTADOR" */
.dock-container button:hover {
    background: #eeeeee; /* Gris papel suave */
}

.dock-container button:active {
    background: #000; /* Inversión total (Tinta sólida) */
    color: #fff;
}

/* Botón Primary (Subir) */
.dock-container button.btn-primary {
    /* Si quieres que destaque, puede ser negro sólido siempre */
    /* O mantenerlo igual para uniformidad total */
    font-weight: bold;
    background: #fff; 
}
.dock-container button.btn-primary:hover {
    background: #000;
    color: #fff;
}

/* Instrucciones: Estilo "Nota al pie" */
.instrucciones {
    font-family: 'JetBrains', monospace;
    font-size: 10px;
    text-transform: lowercase; /* Más casual */
    color: #000;
    background: #fff;
    padding: 2px 5px;
    border: 1px solid #000; /* Otra etiquetita pequeña */
    border-radius: 4px;
    margin-top: 5px;
    box-shadow: 1px 1px 0px rgba(0,0,0,0.1);
}
/* Estilo cuando el giroscopio está ON */
#agitar.activo {
    background: #000 !important; /* Negro sólido */
    color: #fff !important;
    animation: none; /* Quitamos animaciones si las hubiera */
    box-shadow: inset 0 0 5px rgba(255,255,255,0.5); /* Efecto de botón hundido */
}
/* =========================================
   8. MEDIA QUERIES (DESKTOP)
   ========================================= */
@media (min-width: 768px) {
    /* Restaurar padding y tamaños grandes */
    .intro-text {
        padding: 20px 100px 0px 100px;
        font-size: 1.2rem;
    }
    
    #logo { font-size: 80px; }
    #agitar{
        display: none;
    }
    /* AQUÍ SE RESTAURAN TUS POSICIONES ORIGINALES */
    .w-7 { width: 70%; }
    .w-6 { width: 60%; }
    .w-2 { width: 50%; }
    .w-3 { width: 30%; }
    .w-4 { width: 25%; }

    #bloqueCentral { width: 40%; }
    #inputRespuesta { height: 200px; font-size: 20pt!important; padding: 15px !important; }
    #formPublicar button { font-size: 14pt; }
    
    
    
}
@media (max-height: 500px) {
    html {
        scroll-snap-type: none; /* Desactivamos el imán cuando el teclado reduce el espacio */
    }
}
/* =========================================
   9. UTILIDADES
   ========================================= */
#toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.85);
    color: white;
    padding: 10px 16px;
    font-family: 'JetBrains', monospace;
    font-size: 10pt;
    letter-spacing: 0.5px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease, transform 0.4s ease;
    z-index: 100000;
}

#toast.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(-5px);
}
.logos-flotantes {
    position: fixed;
    bottom: 20px;
    width: 100%;
    display: flex;
    justify-content: space-between; /* Uno a la izquierda, otro a la derecha */
    /*padding: 0 30px;*/
    pointer-events: none; /* Permite que el mouse pase a través y toque las letras */
    z-index: 9999; /* Por encima de todo */
}

.logo-item {
    object-fit: contain;
    max-height: 40px;
    max-width: 80px; /* Ajusta el tamaño según necesites */
    opacity: 0.8;
    filter: drop-shadow(0px 5px 15px rgba(0,0,0,0.3));
    animation: flotarLogo 3s ease-in-out infinite;
    pointer-events: auto; /* Para que el logo sí sea clickable si quieres ponerle un link */
    transition: transform 0.3s ease, opacity 0.3s ease;
    padding:0px 100px!important;
    
}

.logo-item:hover {
    transform: scale(1.1);
    opacity: 1;
}

/* Efecto de flotación suave */
@keyframes flotarLogo {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

/* Ajuste para móviles */
@media (max-width: 768px) {
    .logo-item {
        width: 50px;
    }
    .logos-flotantes {
        bottom: 20px; /* Para que no tapen el Dock de controles en móvil */
    }
    .logo-item{
        padding:0px 20px!important;
    }
}