@import url('https://fonts.googleapis.com/css2?family=Fredoka+One&display=swap');

:root {
    --color-cesped: #4CAF50;
    --color-lineas: #FFFFFF;
    --color-oscuro: #388E3C;
    --color-texto: #FFFFFF;
    --sombra-boton: 3px 3px 5px rgba(0, 0, 0, 0.3);
    --borde-fino: 1px solid #9E9E9E;
    --borde-grueso: 3px solid #000000;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
}

body {
    font-family: 'Fredoka One', cursive;
    color: var(--color-texto);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    text-align: center;
    background-image: url('fondo.png');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    background-attachment: fixed;
    padding: 80px 0;
}

#touch-ghost {
    position: absolute;
    pointer-events: none;
    z-index: 1000;
    opacity: 0.8;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
}

.hidden {
    display: none !important;
}

h1 {
    font-size: 3rem;
    text-shadow: 4px 4px 0px rgba(0, 0, 0, 0.2);
    margin-bottom: 20px;
}

#menu-container {
    background-color: rgba(0, 0, 0, 0.3);
    padding: 30px;
    border-radius: 20px;
}

.btn {
    font-family: 'Fredoka One', cursive;
    font-size: 1.5rem;
    padding: 15px 30px;
    margin: 10px;
    border: 4px solid var(--color-lineas);
    border-radius: 50px;
    background-color: var(--color-oscuro);
    color: var(--color-texto);
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    box-shadow: var(--sombra-boton);
}

.btn:hover {
    transform: scale(1.05);
    background-color: #45a049;
}

#game-container {
    width: 98%;
    max-width: 500px;
    background-color: rgba(0, 0, 0, 0.4);
    padding: 15px;
    border-radius: 20px;
    border: 3px solid var(--color-lineas);
}

.game-header {
    text-align: left;
    margin-bottom: 10px;
}

#back-to-menu {
    font-size: 1rem;
    padding: 10px 15px;
    margin: 0;
}

#level-title {
    text-align: center;
    font-size: 1.8rem;
    text-shadow: 2px 2px 0px var(--color-oscuro);
    margin-bottom: 15px;
}

#game-board-area {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 15px;
}

#sudoku-board {
    display: grid;
    border: var(--borde-grueso);
    background-color: rgba(255, 255, 255, 0.8);
    width: 100%;
}

#sudoku-board.size-4x4 {
    grid-template-columns: repeat(4, 1fr);
    max-width: 320px;
    aspect-ratio: 1 / 1;
}

#sudoku-board.size-9x9 {
    grid-template-columns: repeat(9, 1fr);
    max-width: 450px;
    aspect-ratio: 1 / 1;
}

.cell {
    border: var(--borde-fino);
    cursor: pointer;
    transition: background-color 0.2s;
    background-size: 90%;
    background-repeat: no-repeat;
    background-position: center;
}

.cell.border-right {
    border-right: var(--borde-grueso);
}

.cell.border-bottom {
    border-bottom: var(--borde-grueso);
}

.cell.locked {
    cursor: not-allowed;
    background-color: rgba(224, 224, 224, 0.7);
}

.cell:not(.locked).drag-over {
    background-color: #c8e6c9;
}

/* --- NUEVO: Animación y clase para el error --- */
@keyframes shake {

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

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

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

.cell.shake-error {
    animation: shake 0.5s;
}


/* --- Clases para el feedback visual --- */
.cell.correct-placement {
    background-color: #c8e6c9 !important;
    /* Verde para correcto */
}

.cell.incorrect-placement {
    background-color: #ffcdd2 !important;
    /* Rojo para incorrecto */
}

#crest-palette {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 5px;
    background-color: var(--color-oscuro);
    padding: 10px;
    border-radius: 10px;
}

.crest {
    width: 45px;
    height: 45px;
    cursor: grab;
    border-radius: 50%;
    transition: all 0.2s;
    background-size: contain;
    background-position: center;
    background-repeat: no-repeat;
    border: 3px solid transparent;
}

.crest:active {
    cursor: grabbing;
}

.crest:hover {
    border-color: white;
    transform: scale(1.1);
}

.crest.selected {
    border-color: #FFD700;
    transform: scale(1.15);
}

#check-solution-btn {
    margin-top: 15px;
    background-color: #007bff;
}

#check-solution-btn:disabled {
    background-color: #9E9E9E;
    cursor: not-allowed;
    opacity: 0.7;
}

#win-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

#win-screen h2 {
    font-size: 5rem;
    color: #FFD700;
    text-shadow: 5px 5px 0px #c00;
    animation: bounce 1s infinite;
}

@keyframes bounce {

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

    40% {
        transform: translateY(-30px);
    }

    60% {
        transform: translateY(-15px);
    }
}

#logo-container {
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 999;
}

#logo-container img {
    width: 120px;
    height: auto;
    filter: drop-shadow(2px 2px 4px rgba(0, 0, 0, 0.5));
}

#footer-link-container {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 999;
}

.explora-btn {
    font-size: 1.2rem;
    padding: 10px 20px;
    background-color: #007bff;
    text-decoration: none;
}

@media (min-width: 768px) {
    h1 {
        font-size: 4.5rem;
    }

    #game-container {
        max-width: 900px;
    }

    #sudoku-board.size-4x4 {
        max-width: 440px;
    }

    #sudoku-board.size-9x9 {
        max-width: 630px;
    }

    .crest {
        width: 60px;
        height: 60px;
    }

    #logo-container img {
        width: 150px;
    }
}