:root {
    --bg-color: #fdf6e3;
    /* Crema suave */
    --primary-color: #ff6b6b;
    /* Rojo coral */
    --secondary-color: #4ecdc4;
    /* Turquesa */
    --accent-color: #ffe66d;
    /* Amarillo */
    --text-color: #2c3e50;
    --success-color: #2ecc71;
    --error-color: #e74c3c;
    --font-main: 'Nunito', sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    touch-action: manipulation;
    /* Mejora respuesta en táctil y desactiva doble-tap zoom */
    -webkit-tap-highlight-color: transparent;
    /* Elimina el recuadro gris al tapear en iOS */
    -webkit-touch-callout: none;
    /* Desactiva el menú emergente */
    user-select: none;
    /* Evita seleccionar texto por error al tapear rápido */
    -webkit-user-select: none;
}

body {
    font-family: var(--font-main);
    background-color: var(--bg-color);
    color: var(--text-color);
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    /* Evitar scroll en app tipo kiosco */
}

/* Back Button */
.back-button {
    position: absolute;
    top: 16px;
    left: 16px;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
    color: #2F3542;
    font-size: 1.2rem;
    font-family: 'Nunito', sans-serif;
    font-weight: 800;
    background: rgba(255, 255, 255, 0.6);
    padding: 0.5rem 1rem;
    border-radius: 50px;
    backdrop-filter: blur(5px);
    transition: all 0.3s;
    z-index: 10;
}

.back-button:active {
    transform: scale(0.95);
}

.back-button.disabled {
    opacity: 0.8;
    background: rgba(220, 220, 220, 0.4);
    color: #747d8c;
    box-shadow: none;
}

/* Score Display */
.score-display {
    position: absolute;
    top: 16px;
    right: 16px;
    display: flex;
    gap: 4px;
    align-items: center;
    min-height: 36px;
    flex-wrap: wrap;
    max-width: 60%;
    justify-content: flex-end;
    z-index: 10;
}

.star {
    font-size: 1.6rem;
    animation: star-pop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) both;
    line-height: 1;
}

@keyframes star-pop {
    0% { transform: scale(0) rotate(-20deg); opacity: 0; }
    70% { transform: scale(1.3) rotate(10deg); opacity: 1; }
    100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

.game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    /* Centrado vertical */
    gap: 3rem;
    /* Espaciado entre elementos */
    width: 100%;
    max-width: 600px;
    height: 100%;
    padding: 20px;
}

/* Emoji Display */
.emoji-display {
    font-size: 8rem;
    margin-top: 2rem;
    filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.1));
    animation: float 3s ease-in-out infinite;
    min-height: 160px;
    /* Evita saltos */
}

@keyframes float {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-10px);
    }
}

/* Word Display */
.word-display {
    display: flex;
    gap: 10px;
    margin: 20px 0;
    min-height: 80px;
    flex-wrap: wrap;
    justify-content: center;
    position: relative;
}

.letter-slot {
    width: 60px;
    height: 80px;
    border-bottom: 4px solid #bdc3c7;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    font-weight: 900;
    color: #dcdcdc;
    /* Color gris claro para "Fantasma" */
    text-transform: uppercase;
    transition: all 0.3s ease;
}

.letter-slot.filled.correct {
    color: var(--success-color);
    /* Color visible al acertar */
    border-bottom-color: var(--success-color);
    animation: pop-in 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.letter-slot.slot-hide {
    opacity: 0;
    transform: scale(0.8);
    transition: all 0.4s ease-in;
}

.merged-word {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.5);
    background: #fff;
    border: 4px solid var(--success-color);
    border-radius: 24px;
    padding: 10px 30px;
    font-size: 3.5rem;
    font-weight: 900;
    color: var(--success-color);
    box-shadow: 0 8px 0 #27ae60, 0 10px 25px rgba(0,0,0,0.2);
    letter-spacing: 4px;
    text-transform: uppercase;
    opacity: 0;
    pointer-events: none;
    z-index: 10;
}

.merged-word.show {
    animation: 
        merge-pop 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards,
        glow-pulse 1s ease-in-out 0.6s infinite alternate;
}

@keyframes merge-pop {
    0% { transform: translate(-50%, -50%) scale(0.5); opacity: 0; box-shadow: 0 8px 0 #27ae60, 0 10px 25px rgba(0,0,0,0.2); }
    60% { transform: translate(-50%, -50%) scale(1.15); opacity: 1; box-shadow: 0 8px 0 #27ae60, 0 10px 25px rgba(0,0,0,0.2), 0 0 45px var(--accent-color); text-shadow: 0 0 15px var(--accent-color); }
    100% { transform: translate(-50%, -50%) scale(1); opacity: 1; box-shadow: 0 8px 0 #27ae60, 0 10px 25px rgba(0,0,0,0.2), 0 0 20px var(--accent-color); }
}

@keyframes glow-pulse {
    0% { 
        box-shadow: 0 8px 0 #27ae60, 0 10px 25px rgba(0,0,0,0.2), 0 0 20px var(--accent-color);
        text-shadow: 0 0 4px var(--accent-color);
        transform: translate(-50%, -50%) scale(1);
    }
    100% { 
        box-shadow: 0 8px 0 #27ae60, 0 10px 25px rgba(0,0,0,0.2), 0 0 60px var(--accent-color), 0 0 90px var(--accent-color);
        text-shadow: 0 0 15px var(--accent-color), 0 0 22px #ffffff;
        transform: translate(-50%, -50%) scale(1.06);
    }
}

@keyframes pop-in {
    0% {
        transform: scale(0.8);
        opacity: 0.5;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-5px);
    }

    75% {
        transform: translateX(5px);
    }
}

.shake {
    animation: shake 0.4s ease-in-out;
    color: var(--error-color);
}

/* Keyboard */
.keyboard {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    /* Ajustar según quepan */
    gap: 8px;
    width: 100%;
    margin-bottom: 20px;
}

.key {
    background-color: white;
    border: 2px solid #ecf0f1;
    border-radius: 10px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 4px 0 #bdc3c7;
    transition: all 0.1s;
    user-select: none;
}

.key:active {
    transform: translateY(4px);
    box-shadow: 0 0 0 #bdc3c7;
}

/* Feedback Visual de Tecla */
.key.correct-press {
    background-color: var(--success-color);
    color: white;
    border-color: var(--success-color);
    box-shadow: 0 4px 0 #27ae60;
}

.key.wrong-press {
    background-color: var(--error-color);
    color: white;
    border-color: var(--error-color);
    box-shadow: 0 4px 0 #c0392b;
}

/* Responsividad básica */
@media (max-width: 480px) {
    .game-container {
        gap: 1rem; /* Reduce distancias largas verticales */
        padding: 5px 10px;
        justify-content: flex-start; /* Evita que el contenedor flote empujado */
        margin-top: 3rem; /* Espacio mínimo para el back button */
    }

    .emoji-display {
        font-size: 6rem;
        margin-top: 0.5rem;
        min-height: 100px;
    }

    .word-display {
        margin: 0.5rem 0;
        min-height: 60px;
        gap: 6px;
    }

    .letter-slot {
        width: 40px;
        height: 50px;
        font-size: 2rem;
    }
    
    .hint-display {
        font-size: 4.5rem;
        min-height: 70px;
        margin-bottom: 0.5rem;
    }

    .keyboard {
        gap: 4px;
        grid-template-columns: repeat(5, 1fr);
        margin-bottom: 5px;
    }

    .key {
        height: 45px;
        font-size: 1.2rem;
    }

    .back-button {
        font-size: 1rem;
        padding: 0.4rem 0.8rem;
        top: 12px;
        left: 12px;
    }
    
    .score-display {
        top: 12px;
        right: 12px;
    }

    .star {
        font-size: 1.2rem;
    }
}

.hidden {
    display: none !important;
}

/* Confetti */
.confetti {
    position: absolute;
    width: 10px;
    height: 10px;
    background-color: #f00;
    animation: fall 4s linear forwards;
    z-index: 100;
    top: -10px;
}

@keyframes fall {
    0% {
        transform: translateY(-10px) rotate(0deg);
        opacity: 1;
    }

    100% {
        transform: translateY(100vh) rotate(720deg);
        opacity: 0;
    }
}

/* Hint Display */
.hint-display {
    font-size: 6rem;
    /* aprox 3x keyboard letter size or near emoji size */
    min-height: 120px;
    margin-bottom: 1rem;
    font-weight: 900;
    color: var(--secondary-color);
    cursor: pointer;
    /* Indicar que es interactivo */
    user-select: none;

    /* Reutilizar animación float del emoji */
    animation: float 3s ease-in-out infinite;
    transition: all 0.2s;
    /* Para hover/active básicos */
}

/* Estado de salida: Zoom y Desvanecer */
.hint-display.hint-exit {
    animation: hint-exit-anim 0.3s ease-out forwards;
}

@keyframes hint-exit-anim {
    0% {
        transform: scale(1);
        opacity: 1;
    }

    100% {
        transform: scale(3);
        /* Zoom 3x request */
        opacity: 0;
    }
}

/* Optimizaciones para pantallas horizontales (iPad Landscape) */
@media (max-height: 850px) and (orientation: landscape) {
    .game-container {
        gap: 1rem;
        padding: 5px;
    }

    .emoji-display {
        font-size: 5rem;
        margin-top: 5px;
        min-height: 100px;
    }

    .word-display {
        margin: 5px 0;
        min-height: 60px;
    }

    .letter-slot {
        width: 45px;
        height: 60px;
        font-size: 2.2rem;
    }

    .hint-display {
        font-size: 3.5rem;
        min-height: 70px;
        margin-bottom: 5px;
    }

    .keyboard {
        margin-bottom: 5px;
        gap: 5px;
    }

    .key {
        height: 45px;
        font-size: 1.3rem;
    }

    .score-display { top: 6px; }
    .back-button { top: 6px; left: 6px; }
}