/* Estilos básicos y reset */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* Colores de Bluey - Azul principal (#0288d1), Amarillo/Naranja (#ffca28), Rosa (#ff80ab) */

body {
    background: linear-gradient(135deg, #e0f7fa 0%, #b3e5fc 100%);
    font-family: Arial, sans-serif;
    margin: 0;
    padding: 20px;
    min-height: 100vh;
    color: #333;
    overscroll-behavior: none; /* Prevenir scroll no deseado en móviles */
}

/* Contenedor principal */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 15px;
}

/* Encabezado */
header {
    text-align: center;
    padding: 20px 0;
    margin-bottom: 30px;
    position: relative;
}

header::after {
    content: "";
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 80%;
    height: 6px;
    background: linear-gradient(90deg, #0288d1, #ff80ab, #ffca28, #0288d1);
    border-radius: 3px;
}

h1, h2 {
    font-family: 'Chewy', cursive;
    color: #0288d1;
    text-shadow: 2px 2px #ffca28;
    margin-bottom: 1rem;
    letter-spacing: 1px;
}

h1 {
    font-size: clamp(2.5rem, 8vw, 4rem);
    animation: bounce 2s infinite alternate;
}

h2 {
    font-size: clamp(1.8rem, 5vw, 2.5rem);
}

@keyframes bounce {
    0% {
        transform: translateY(0);
    }
    100% {
        transform: translateY(-10px);
    }
}

header p {
    font-size: clamp(1.1rem, 3vw, 1.4rem);
    margin-bottom: 1.5rem;
    color: #0277bd;
    max-width: 800px;
    margin-left: auto;
    margin-right: auto;
}

/* Grid de juegos */
.game-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 25px;
    margin-bottom: 3rem;
}

/* Tarjetas de juegos */
.game-card {
    border: 4px solid #4caf50;
    padding: 1.5rem;
    background-color: #fff;
    border-radius: 20px;
    transition: all 0.3s ease;
    box-shadow: 0 6px 12px rgba(0,0,0,0.15);
    position: relative;
    overflow: hidden;
    text-align: center;
}

.game-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.5), transparent);
    transition: left 0.5s ease;
    z-index: 1;
}

.game-card:hover::before {
    left: 100%;
}

.game-card:hover {
    transform: translateY(-12px) scale(1.02);
    box-shadow: 0 15px 30px rgba(0,0,0,0.2);
    border-color: #ffca28;
}

.game-card:nth-child(3n+1) {
    border-color: #0288d1;
}

.game-card:nth-child(3n+2) {
    border-color: #ff80ab;
}

.game-card:nth-child(3n+3) {
    border-color: #ffca28;
}

.game-card img {
    width: 100%;
    height: 150px;
    object-fit: cover;
    border-radius: 12px;
    margin-bottom: 1rem;
    transition: transform 0.3s ease;
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.game-card:hover img {
    transform: scale(1.05);
}

.game-card h3 {
    font-family: 'Chewy', cursive;
    font-size: 1.5rem;
    margin: 0.8rem 0;
    color: #0288d1;
}

.game-card p {
    font-size: 1rem;
    color: #555;
    margin-bottom: 1.2rem;
    line-height: 1.4;
}

/* Botones */
button {
    padding: 12px 24px;
    background: linear-gradient(45deg, #ffca28, #ffb300);
    border: none;
    border-radius: 25px;
    cursor: pointer;
    font-weight: bold;
    font-size: 1.1rem;
    transition: all 0.3s ease;
    color: #333;
    min-width: 140px;
    box-shadow: 0 4px 0 #e69c00;
    position: relative;
    overflow: hidden;
    touch-action: manipulation; /* Mejorar interacción táctil */
}

button::after {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: rgba(255,255,255,0.2);
    transform: rotate(45deg);
    transition: all 0.3s ease;
    opacity: 0;
}

button:hover {
    background: linear-gradient(45deg, #ffb300, #ff8f00);
    transform: translateY(-3px);
    box-shadow: 0 7px 0 #e69c00;
}

button:hover::after {
    opacity: 1;
    top: -20%;
    left: -20%;
}

button:active {
    transform: translateY(4px);
    box-shadow: 0 0 0 #e69c00;
}

footer {
    text-align: center;
    padding: 20px 0;
    margin-top: 30px;
    border-top: 2px dashed #0288d1;
    color: #0277bd;
    font-style: italic;
}

/* Estilos específicos para los juegos */
#memory-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
    max-width: 600px;
    margin: 20px auto;
}

.card {
    position: relative;
    aspect-ratio: 1;
    transform-style: preserve-3d;
    transition: transform 0.6s;
    cursor: pointer;
}

.card.flipped {
    transform: rotateY(180deg);
}

.card.matched {
    opacity: 0.7;
    pointer-events: none;
}

.front, .back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.front {
    transform: rotateY(180deg);
    background: #fff;
    padding: 5px;
}

.front img {
    width: 90%;
    height: 90%;
    object-fit: contain;
    border-radius: 8px;
}

.back {
    background: linear-gradient(45deg, #0288d1, #29b6f6);
    color: white;
    font-size: 2rem;
    font-weight: bold;
    font-family: 'Chewy', cursive;
}

/* Estilos para el juego de colorear */
#coloring-canvas {
    border: 4px solid #0288d1;
    background-color: #fff;
    max-width: 100%;
    width: 100%;
    height: auto;
    aspect-ratio: 3/2; /* Mantener proporción */
    border-radius: 15px;
    margin: 1.5rem auto;
    display: block;
    box-shadow: 0 8px 16px rgba(0,0,0,0.15);
    touch-action: none; /* Prevenir zoom/scroll en canvas */
}

#color-palette {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    justify-content: center;
    margin: 20px auto;
    padding: 15px;
    background: rgba(255,255,255,0.7);
    border-radius: 15px;
    max-width: 600px;
}

#color-palette button {
    width: 60px;
    height: 60px;
    padding: 0;
    border: 3px solid #333;
    border-radius: 50%;
    min-width: auto;
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
    transition: all 0.2s ease;
}

#color-palette button:hover,
#color-palette button:active {
    transform: scale(1.2) translateY(-5px);
}

/* Controles */
.controls {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    justify-content: center;
    margin-bottom: 1.5rem;
    padding: 15px;
    background: rgba(255,255,255,0.7);
    border-radius: 15px;
}

.controls select,
.controls input[type="color"],
.controls input[type="range"],
.controls button {
    padding: 12px;
    font-size: 1.1rem;
    border-radius: 10px;
    border: none;
    background: #fff;
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    touch-action: manipulation; /* Mejorar interacción táctil */
}

.controls input[type="range"] {
    width: 150px;
}

.controls button {
    background: linear-gradient(45deg, #ffca28, #ffb300);
    color: #333;
    min-width: 100px;
    cursor: pointer;
}

.controls button:hover {
    background: linear-gradient(45deg, #ffb300, #ff8f00);
    transform: translateY(-3px);
}

.controls button:active {
    transform: translateY(0);
}

/* Estilos para el Quiz */
#quiz-container {
    max-width: 700px;
    margin: 0 auto;
    text-align: left;
    padding: 20px;
    background: rgba(255,255,255,0.7);
    border-radius: 20px;
    box-shadow: 0 8px 16px rgba(0,0,0,0.15);
}

#quiz-container .question {
    background: white;
    padding: 1.5rem;
    border-radius: 15px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    margin-bottom: 1.5rem;
    border: 3px solid #0288d1;
}

#quiz-container label {
    display: block;
    margin: 12px 0;
    padding: 12px 15px;
    background: #f0f7fb;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    border-left: 5px solid #b3e5fc;
}

#quiz-container label:hover {
    background: #e1f5fe;
    transform: translateX(5px);
    border-left-color: #29b6f6;
}

#quiz-container input[type="radio"] {
    margin-right: 10px;
    transform: scale(1.2);
}

/* Estilos para el rompecabezas */
#puzzle-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    max-width: 400px;
    margin: 20px auto;
    background: rgba(255,255,255,0.7);
    padding: 15px;
    border-radius: 15px;
    box-shadow: 0 8px 16px rgba(0,0,0,0.15);
}

.puzzle-piece {
    aspect-ratio: 1;
    background-size: 300px 300px;
    border: 3px solid #0288d1;
    border-radius: 8px;
    cursor: grab;
    transition: all 0.2s ease;
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.puzzle-piece:hover {
    transform: scale(1.08);
    z-index: 5;
    box-shadow: 0 8px 16px rgba(0,0,0,0.2);
}

.puzzle-piece:active {
    cursor: grabbing;
    transform: scale(1.12);
}

/* Estilos para juegos con canvas */
#maze-canvas, #obstacle-canvas, #treasure-canvas {
    border: 4px solid #0288d1;
    border-radius: 15px;
    max-width: 100%;
    height: auto;
    margin: 1.5rem auto;
    display: block;
    background: #fff;
    box-shadow: 0 8px 16px rgba(0,0,0,0.15);
}

/* Estilos de instrucciones y mensajes */
.game-instructions {
    background: rgba(255,255,255,0.8);
    padding: 1.5rem;
    border-radius: 15px;
    margin: 1.5rem auto;
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    max-width: 800px;
    border-left: 6px solid #ffca28;
    font-size: 1.1rem;
    line-height: 1.5;
}

.game-stats {
    background: linear-gradient(45deg, #ffca28, #ffb300);
    padding: 0.8rem 1.5rem;
    border-radius: 30px;
    display: inline-block;
    margin: 1rem;
    font-weight: bold;
    font-size: 1.1rem;
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.success-message {
    background: linear-gradient(45deg, #4caf50, #43a047);
    color: white;
    padding: 1.5rem;
    border-radius: 15px;
    margin: 1.5rem auto;
    font-size: 1.2rem;
    max-width: 700px;
    box-shadow: 0 6px 12px rgba(0,0,0,0.2);
    text-align: center;
    animation: pulse 2s infinite;
}

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

/* Botón para volver */
.back-button {
    background: linear-gradient(45deg, #f44336, #e53935);
    color: white;
    margin: 1.5rem auto;
    box-shadow: 0 4px 0 #c62828;
    display: block;
    text-align: center;
    padding: 12px 24px;
    font-size: 1.2rem;
}

.back-button:hover {
    background: linear-gradient(45deg, #e53935, #d32f2f);
    box-shadow: 0 7px 0 #c62828;
}

/* Responsive para tabletas */
@media (max-width: 992px) {
    .game-grid {
        grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
        gap: 20px;
    }
    
    header::after {
        width: 90%;
    }
}

/* Responsive para móviles */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }
    
    .container {
        padding: 0 10px;
    }
    
    .game-grid {
        grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
        gap: 15px;
    }
    
    header {
        padding: 15px 0;
        margin-bottom: 20px;
    }
    
    header::after {
        width: 95%;
        height: 4px;
    }
    
    .game-card {
        padding: 1.2rem;
        border-width: 3px;
    }
    
    .game-card img {
        height: 120px;
    }
    
    #memory-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 10px;
        max-width: 400px;
    }
    
    #coloring-canvas {
        max-width: 100%;
        width: 100%;
        height: auto;
    }
    
    #color-palette button {
        width: 50px;
        height: 50px;
    }
    
    .controls {
        gap: 10px;
        padding: 10px;
    }
    
    .controls select,
    .controls input[type="color"],
    .controls input[type="range"],
    .controls button {
        padding: 10px;
        font-size: 1rem;
        min-width: 80px;
    }
    
    .controls input[type="range"] {
        width: 120px;
    }
    
    .back-button {
        padding: 10px 20px;
        font-size: 1rem;
    }
    
    header p {
        font-size: 1rem;
    }
    
    .game-instructions {
        font-size: 0.95rem;
        padding: 1rem;
    }
}

/* Responsive para móviles pequeños */
@media (max-width: 480px) {
    .game-grid {
        grid-template-columns: 1fr;
        max-width: 300px;
        margin-left: auto;
        margin-right: auto;
    }
    
    .game-card {
        padding: 1rem;
    }
    
    .game-card h3 {
        font-size: 1.3rem;
    }
    
    #memory-grid {
        grid-template-columns: repeat(2, 1fr);
        max-width: 280px;
    }
    
    #puzzle-grid {
        grid-template-columns: repeat(2, 1fr);
        max-width: 280px;
    }
    
    #color-palette button {
        width: 45px;
        height: 45px;
    }
    
    .controls {
        flex-direction: column;
        align-items: center;
        gap: 8px;
    }
    
    .controls select,
    .controls input[type="color"],
    .controls input[type="range"],
    .controls button {
        width: 100%;
        max-width: 200px;
        padding: 8px;
        font-size: 0.9rem;
    }
    
    .controls input[type="range"] {
        width: 100%;
    }
    
    button {
        padding: 10px 20px;
        font-size: 1rem;
        min-width: 120px;
    }
    
    .game-instructions {
        padding: 1rem;
        font-size: 0.95rem;
    }
    
    .back-button {
        padding: 8px 16px;
        font-size: 0.9rem;
    }
}