/* assets/css/sopa-letras.css */

/* --- LAYOUT GENERAL --- */
.container-sopa {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    min-height: 80vh;
    width: 100%;
    position: relative;
    z-index: 5;
    touch-action: pan-y;
}

/* --- FONDO (La Carta) --- */
.game-container {
    width: 100%;
    background-image: url('../img/card.png');
    background-color: transparent;
    background-repeat: no-repeat;
    background-size: 100% 100%;
    background-position: center;
    padding: 40px 30px 50px 30px;
    border: none !important;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 30px;
}

main {
    width: 100%;
    max-width: 600px;
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: auto;
    padding: 10px;
}

/* --- TABLERO --- */
#sopa-board {
    display: grid;
    grid-template-columns: repeat(14, 1fr);
    width: 100%;
    max-width: 530px;
    aspect-ratio: 1 / 1;
    background-color: #f5e6c8 !important;
    border-radius: 4px;
    padding: 15px;
    box-shadow: inset 0 0 30px rgba(62, 39, 35, 0.1), 0 5px 15px rgba(0, 0, 0, 0.2);
    gap: 0 !important;
    margin: 0 auto;
    user-select: none;
    touch-action: none;
    position: relative;
}

/* --- CAPA DE LÍNEAS --- */
#lines-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
    overflow: hidden;
    border-radius: 4px;
}

.word-list-title {
    font-size: 2rem;
    font-weight: bold;
    margin-bottom: 10px;
    color: var(--gold-treasure);
    text-shadow: 1px 1px 0 #3e2723, -1px -1px 0 #3e2723, 1px -1px 0 #3e2723, -1px 1px 0 #3e2723, 1px 1px 0 #3e2723;
}

/* --- ESTILO DE LA PÍLDORA (CORREGIDO) --- */
.highlight-pill {
    position: absolute;
    height: 70%;
    border-radius: 999px;
    transform-origin: center center;
    pointer-events: none;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
}

.highlight-pill.current {
    background-color: rgba(255, 167, 38, 0.7);
    border: 1px solid #ef6c00;
}

/* --- LAS LETRAS --- */
#sopa-board .cell {
    width: 100%;
    height: 100%;
    background-color: transparent !important;
    border: none !important;
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: 'Roboto', sans-serif;
    font-weight: 900;
    color: #3e2723;
    line-height: 1;
    cursor: pointer;
    font-size: clamp(12px, 3.6vw, 24px) !important;
    position: relative;
    z-index: 2;
}

#sopa-board .cell.found-text {
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
}

/* --- LISTA DE PALABRAS (ESTILO CON FONDO) --- */
.word-list-container {
    margin-top: 25px;
    width: 100%;
    max-width: 600px;
    text-align: center;
    border-top: 2px dashed rgba(62, 39, 35, 0.3);
    padding-top: 15px;
}

.word-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    list-style: none;
    padding: 0;
    margin: 0;
}

.word-item {
    background: rgba(255, 255, 255, 0.9);
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: bold;
    color: #3e2723;
    border: 1px solid #8d6e63;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.word-item.found {
    background-color: #ffb300;
    text-decoration: line-through;
    opacity: 0.7;
    border-color: #ff6f00;
    color: #fff;
    box-shadow: none;
}

.hidden {
    display: none !important;
}

@media (max-width: 500px) {
    .game-container {
        padding: 30px 15px 40px 15px;
    }

    .static-step .anim-box {
        width: 100%;
    }

    #sopa-board {
        padding: 8px;
    }

    #sopa-board .cell {
        font-size: clamp(9px, 4.2vw, 16px) !important;
    }
}

/* Feedback visual para el primer click en modo click-click */
.cell.selected-start {
    background-color: rgba(255, 167, 38, 0.4) !important;
    border-radius: 50%;
    animation: pulseSelect 1.5s infinite;
}

@keyframes pulseSelect {
    0% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(255, 167, 38, 0.7);
    }

    70% {
        transform: scale(1.1);
        box-shadow: 0 0 0 5px rgba(255, 167, 38, 0);
    }

    100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(255, 167, 38, 0);
    }
}

/* =========================================
   --- HEADER & LAYOUT CORRECTIONS ---
   ========================================= */

/* Wrapper para mantener el título centrado y el botón relativo a él */
.subtitle-wrapper {
    position: relative;
    display: inline-block;
}

/* Forzamos que el h1 se comporte bien dentro del wrapper */
.subtitle-wrapper .page-subtitle {
    margin: 0;
    display: inline-block;
    vertical-align: middle;
}

.sopa-subtitle-container {
    flex-direction: column;
    gap: 8px !important;
}

@keyframes popIn {
    from {
        transform: scale(0.8);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* --- TEMPORIZADOR ESTILO BINGO --- */
.sopa-timer-display {
    font-family: "Bangers", cursive;
    font-size: 22px;
    /* Más pequeño para que no estorbe */
    color: #3e2723;
    /* Texto oscuro para contrastar con papiro */
    background: #fff8e1;
    /* Fondo PAPIRO */
    border: 2px solid #8d6e63;
    /* Borde de madera/tierra */
    border-radius: 8px;
    padding: 4px 12px;
    min-width: 80px;
    text-align: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);

    /* Para posicionarlo dentro del header */
    margin: 0 auto;
    margin-top: 10px;
    display: inline-block;
    letter-spacing: 1px;
}

/* Caja de Animación */
.anim-box {
    background: #f5e6c8;
    border: 2px solid #8d6e63;
    border-radius: 8px;
    padding: 0;
    position: relative;
    height: 70px;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.demo-row {
    display: flex;
    gap: 3px;
    position: relative;
    z-index: 1;
}

.d-cell {
    width: 24px;
    height: 24px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: 900;
    color: #3e2723;
    font-size: 14px;
    border: 1px solid rgba(141, 110, 99, 0.3);
    background: rgba(255, 255, 255, 0.3);
    border-radius: 3px;
    transition: background 0.2s;
}

/* Posicionamiento corregido de la mano */
.hand-icon {
    font-size: 32px;
    position: absolute;
    z-index: 10;
    pointer-events: none;
    filter: drop-shadow(2px 2px 2px rgba(0, 0, 0, 0.3));

    /* NUEVA POSICIÓN BASE: CENTRADA */
    left: 50%;
    top: 50%;
    /* Ajuste fino con margen negativo para alinear la punta del dedo
       con la primera celda. El bloque de celdas mide unos 145px.
       Movemos la mano la mitad a la izquierda (-72px) y un poco más por el icono. */
    margin-left: -78px;
    margin-top: -15px;
}

/* --- ANIMACIÓN 1: ARRASTRAR (Drag) --- */
.drag-anim {
    animation: dragHandMove 2.5s infinite ease-in-out;
}

@keyframes dragHandMove {
    0% {
        transform: translate(0px, 0px);
    }

    /* Inicio exacto en la 'L' */
    15% {
        transform: translate(0px, 5px) scale(0.9);
    }

    /* Presiona */
    60% {
        transform: translate(120px, 5px) scale(0.9);
    }

    /* Arrastra hasta la 'Y' (~120px) */
    75% {
        transform: translate(120px, 0px) scale(1);
    }

    /* Suelta */
    85% {
        transform: translate(120px, 0px) scale(1);
        opacity: 1;
    }

    100% {
        transform: translate(0px, 0px);
        opacity: 0;
    }

    /* Reset */
}

/* Iluminar letras LUFFY en secuencia */
.step-card:first-child .d-cell {
    animation: cellLightUp 2.5s infinite;
}

.step-card:first-child .d-cell:nth-child(1) {
    animation-delay: 0.1s;
}

.step-card:first-child .d-cell:nth-child(2) {
    animation-delay: 0.25s;
}

.step-card:first-child .d-cell:nth-child(3) {
    animation-delay: 0.40s;
}

.step-card:first-child .d-cell:nth-child(4) {
    animation-delay: 0.55s;
}

.step-card:first-child .d-cell:nth-child(5) {
    animation-delay: 0.70s;
}

@keyframes cellLightUp {

    0%,
    10% {
        background: rgba(255, 255, 255, 0.3);
        border-color: rgba(141, 110, 99, 0.3);
    }

    15% {
        background: #ffcc80;
        border-color: #ef6c00;
    }

    75% {
        background: #ffcc80;
        border-color: #ef6c00;
    }

    85% {
        background: rgba(255, 255, 255, 0.3);
        border-color: rgba(141, 110, 99, 0.3);
    }
}

/* --- ANIMACIÓN 2: TOCAR (Tap) --- */

.tap-anim {
    /* Mantenemos el inicio en la Z */
    margin-left: -58px !important;
    animation: tapHandMove 2.5s infinite ease-in-out;
}

@keyframes tapHandMove {
    0% {
        transform: translate(0px, 0px);
    }

    /* Inicio en 'Z' */
    10% {
        transform: translate(0px, 5px) scale(0.9);
    }

    /* Click 1 ('Z') */
    20% {
        transform: translate(0px, 0px) scale(1);
    }

    /* Levanta */

    /* VUELO HACIA LA 'O':
       Aumentamos de 82px a 108px para dar ese último salto hasta la O final. */
    40% {
        transform: translate(90px, -20px) scale(1.1);
    }

    60% {
        transform: translate(90px, 0px) scale(1);
    }

    /* Baja sobre 'O' */
    70% {
        transform: translate(90px, 5px) scale(0.9);
    }

    /* Click 2 ('O') */
    80% {
        transform: translate(90px, 0px) scale(1);
        opacity: 1;
    }

    95% {
        transform: translate(90px, 0px);
        opacity: 0;
    }

    100% {
        transform: translate(0px, 0px);
        opacity: 0;
    }
}

/* Highlights para Tap (Z --- O) */
.highlight-start {
    animation: tapHighlightStart 2.5s infinite;
}

.highlight-end {
    animation: tapHighlightEnd 2.5s infinite;
}

@keyframes tapHighlightStart {

    0%,
    10% {
        background: rgba(255, 255, 255, 0.3);
        /* Aseguramos el radio base */
        border-radius: 3px;
    }

    11% {
        background: #ffcc80;
        /* CAMBIO: De 50% a 3px para que sea cuadrado */
        border-radius: 3px;
        box-shadow: 0 0 0 2px #ef6c00;
    }

    90% {
        background: #ffcc80;
        /* CAMBIO: De 50% a 3px */
        border-radius: 3px;
        box-shadow: 0 0 0 2px #ef6c00;
    }

    100% {
        background: rgba(255, 255, 255, 0.3);
        border-radius: 3px;
        box-shadow: none;
    }
}

@keyframes tapHighlightEnd {

    0%,
    69% {
        background: rgba(255, 255, 255, 0.3);
        /* Aseguramos el radio base */
        border-radius: 3px;
    }

    70% {
        background: #ffcc80;
        /* CAMBIO: De 50% a 3px para que sea cuadrado */
        border-radius: 3px;
        box-shadow: 0 0 0 2px #ef6c00;
    }

    90% {
        background: #ffcc80;
        /* CAMBIO: De 50% a 3px */
        border-radius: 3px;
        box-shadow: 0 0 0 2px #ef6c00;
    }

    100% {
        background: rgba(255, 255, 255, 0.3);
        border-radius: 3px;
        box-shadow: none;
    }
}

/* --- CORRECCIÓN FINAL: RELLENAR PALABRA EN MODO TAP --- */

/* Seleccionamos las letras de en medio (2ª y 3ª) de la tarjeta de la derecha (last-child) */
.step-card:last-child .d-cell:nth-child(2),
.step-card:last-child .d-cell:nth-child(3) {
    animation: tapMiddleFill 2.5s infinite;
}

/* Animación para que se enciendan SOLO cuando se hace el segundo click */
@keyframes tapMiddleFill {

    0%,
    69% {
        /* Antes del segundo click: Transparentes */
        background: rgba(255, 255, 255, 0.3);
        border-color: rgba(141, 110, 99, 0.3);
    }

    70% {
        /* ¡CLICK FINAL! Se encienden a la vez que la última letra */
        background: #ffcc80;
        border-color: #ef6c00;
    }

    90% {
        /* Se mantienen encendidas un momento */
        background: #ffcc80;
        border-color: #ef6c00;
    }

    100% {
        /* Reset */
        background: rgba(255, 255, 255, 0.3);
        border-color: rgba(141, 110, 99, 0.3);
    }
}

/* Botón Jugar */
.btn-play {
    margin-top: 15px;
    background: #ffb300;
    color: #3e2723;
    border: 3px solid #3e2723;
    padding: 10px 40px;
    font-family: 'Pirata One', cursive;
    font-size: 1.8rem;
    border-radius: 12px;
    cursor: pointer;
    transition: transform 0.1s;
    box-shadow: 0 5px 0 #3e2723;
    text-transform: uppercase;
    width: 100%;
    max-width: 250px;
}

.btn-play:hover {
    background: #ffca28;
}

.btn-play:active {
    transform: translateY(5px);
    box-shadow: none;
}

/* --- ESTILOS PARA LAS ANIMACIONES EN EL PIE DE PÁGINA --- */

.info-steps-visual {
    display: flex;
    justify-content: space-around;
    align-items: center;
    gap: 10px;
    margin: 20px 0;
    flex-wrap: wrap;
    /* Para que baje en móviles muy pequeños */
}

/* Ajustes de la tarjeta dentro de la info estática */
.static-step {
    background: transparent;
    /* Sin fondo extra */
    box-shadow: none;
    padding: 0;
    max-width: 220px;
    /* Un poco más compactas */
}

/* El separador en la versión estática (color oscuro) */
.static-sep {
    text-shadow: none !important;
    margin-top: 0 !important;
    /* Resetear el margen negativo del modal */
    font-size: 1.5rem;
}

/* Texto debajo de la animación (Estilo limpio) */
.static-text {
    margin-top: 8px;
    text-align: center;
    line-height: 1.2;
}

.static-text strong {
    display: block;
    color: #d84315;
    font-family: 'Pirata One', cursive;
    font-size: 1.2rem;
    margin-bottom: 2px;
}

.static-text span {
    font-size: 0.85rem;
}

/* Reducir un poco la altura de la caja de animación en el pie de página */
.info-game .anim-box {
    height: 60px;
    background: rgba(255, 255, 255, 0.5);
    /* Ligeramente más claro */
    border-color: #a1887f;
}

/* Ajuste Responsive para la info de abajo */
@media (max-width: 480px) {
    .info-steps-visual {
        flex-direction: column;
        gap: 20px;
    }

    .static-sep {
        transform: rotate(90deg);
        /* Rotar el "O" si están uno encima del otro */
    }
}