/* puzzle-common.css - CSS corregido para puzzles */

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Comic Neue', cursive;
    background: #f0f2f5;
}

.puzzle-page {
    padding: 1rem;
    max-width: 1200px;
    margin: 0 auto;
    min-height: 100vh;
}

h1 {
    text-align: center;
    color: #333;
    margin-bottom: 0.5rem;
    font-size: clamp(1.5rem, 4vw, 2.5rem);
}

.puzzle-page > p {
    text-align: center;
    color: #666;
    margin-bottom: 2rem;
    font-size: clamp(1rem, 3vw, 1.2rem);
}

/* ÁREA DEL PUZZLE - CORREGIDO */
.puzzle-area {
    margin: 2rem auto;
    max-width: 500px;
}

.puzzle-container {
    background: white;
    border-radius: 15px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.1);
    padding: 1.5rem;
    margin: 0 auto;
    text-align: center;
    min-height: 400px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.puzzle-board {
    border: 3px solid #4a90e2;
    border-radius: 10px;
    display: grid;
    grid-template-columns: repeat(var(--puzzle-cols, 2), 1fr);
    grid-template-rows: repeat(var(--puzzle-rows, 2), 1fr);
    gap: 2px; /* Añadido gap para separar piezas */
    background: #f0f0f0;
    position: relative;
    width: var(--puzzle-size, 350px);
    height: var(--puzzle-size, 350px);
    overflow: hidden; /* Importante para que no se salgan las piezas */
}

.puzzle-piece {
    /* Fuerza el background-size dinámico */
    background-size: calc(var(--puzzle-cols, 2) * 100%) calc(var(--puzzle-rows, 2) * 100%);
    border: 2px solid white;
    cursor: move;
    transition: transform 0.2s;
    background-repeat: no-repeat;
    width: 100%;
    height: 100%;
}

.puzzle-piece:hover {
    transform: scale(1.02);
    z-index: 5; /* Para que se vea por encima al hover */
}

.puzzle-piece.dragging {
    z-index: 10;
    opacity: 0.8;
    transform: scale(1.05);
}

/* SELECTOR DE ANIMALES */
.animal-selector {
    margin: 3rem 0 2rem 0;
    text-align: center;
}

.animal-buttons {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 0.8rem;
    margin-bottom: 1.5rem;
    max-width: 800px;
    margin-left: auto;
    margin-right: auto;
    padding: 0 1rem;
    display: none !important;
}

.animal-btn {
    padding: 1rem 0.5rem;
    background: #4a90e2;
    color: white;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-size: clamp(0.9rem, 2.5vw, 1.1rem);
    font-weight: bold;
    transition: all 0.3s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3rem;
    min-height: 80px;
}

.animal-btn:hover {
    background: #3a7bc8;
    transform: scale(1.05);
}

.animal-btn.active {
    background: #2e7d32;
    transform: scale(1.05);
}

.animal-emoji {
    font-size: 1.8rem;
}

.current-animal {
    font-size: clamp(1.2rem, 4vw, 1.8rem);
    font-weight: bold;
    color: #333;
    margin-top: 1rem;
    text-align: center;
    min-height: 2.5rem;
}

.speak-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.2em;
    margin-left: 6px;
    transition: transform 0.2s;
}

.speak-btn:hover {
    transform: scale(1.2);
}

/* MENSAJES */
.puzzle-message {
    text-align: center;
    color: #666;
    padding: 2rem;
    font-size: 1.1rem;
}

.puzzle-error {
    text-align: center;
    color: #d32f2f;
    padding: 2rem;
    font-weight: bold;
}

.puzzle-congratulations {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
    padding: 1rem;
}

.congrats-content {
    background: white;
    padding: 2rem;
    border-radius: 15px;
    text-align: center;
    max-width: 300px;
    width: 90%;
    animation: bounceIn 0.5s;
}

@keyframes bounceIn {
    0% { transform: scale(0.3); opacity: 0; }
    50% { transform: scale(1.05); opacity: 1; }
    100% { transform: scale(1); }
}

.close-congrats {
    padding: 0.8rem 1.5rem;
    background: #ff6b6b;
    color: white;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    margin-top: 1rem;
    font-size: 1rem;
    font-weight: bold;
}

/* NAVEGACIÓN */
.navigation-links {
    text-align: center;
    margin-top: 2rem;
    padding: 1rem;
}

.back-link {
    display: inline-block;
    padding: 0.8rem 1.5rem;
    background: #6c757d;
    color: white;
    text-decoration: none;
    border-radius: 8px;
    transition: background 0.3s;
    font-size: 1rem;
}

.back-link:hover {
    background: #5a6268;
}

/* RESPONSIVE */
@media (max-width: 480px) {
    .puzzle-page {
        padding: 0.5rem;
    }
    
    .animal-buttons {
        grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
        gap: 0.5rem;
        padding: 0 0.5rem;
    }
    
    .animal-btn {
        padding: 0.8rem 0.3rem;
        min-height: 70px;
        font-size: 0.8rem;
    }
    
    .animal-emoji {
        font-size: 1.5rem;
    }
    
    .puzzle-container {
        padding: 1rem;
    }
    
    /* Ajustar tamaño del puzzle en móviles */
    .puzzle-board {
        width: 300px !important;
        height: 300px !important;
    }
}