:root {
    --bg-color: #a0e9ff;
    --grid-bg: rgba(255, 255, 255, 0.8);
    --grid-cell-bg: #89cff0;
    --text-color: #005a8d;
    --shadow-color: #333;
    --border-color: #fff;
    --button-bg: #ff6347;
    --button-hover-bg: #ff4500;
}

body {
    font-family: 'Fredoka One', cursive;
    background-color: var(--bg-color);
    background-image: url('/background.png');
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    margin: 0;
    padding: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    box-sizing: border-box;
    color: var(--text-color);
    -webkit-user-select: none;
    user-select: none;
}

#game-container {
    text-align: center;
    width: 100%;
    max-width: 450px;
    backdrop-filter: blur(5px);
    background-color: rgba(255, 255, 255, 0.3);
    padding: 15px;
    border-radius: 20px;
    box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
}

h1 {
    font-size: clamp(1.8rem, 7vw, 2.5rem);
    text-shadow: 2px 2px 4px rgba(0,0,0,0.2);
    margin: 0 0 15px;
}

#grid-container {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin: 15px auto;
    padding: 10px;
    background-color: var(--grid-bg);
    border-radius: 15px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
    aspect-ratio: 1 / 1;
    max-width: 85vw;
    max-height: 85vw;
}

.grid-cell {
    background-color: var(--grid-cell-bg);
    border-radius: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    border: 3px dashed var(--border-color);
    transition: background-color 0.3s, transform 0.2s;
}

.grid-cell.over {
    background-color: #5ab9ea;
    transform: scale(1.05);
}

.grid-cell img {
    width: 80%;
    height: 80%;
    object-fit: contain;
    pointer-events: none; /* Important for drop event */
}

.grid-cell .shadow-img {
    filter: drop-shadow(2px 2px 2px rgba(0,0,0,0.3));
}

.grid-cell.solved .shadow-img {
    display: none;
}

.grid-cell.solved .color-img {
    display: block;
    animation: pop-in 0.5s ease-out;
}

.grid-cell .color-img {
    display: none;
}

@keyframes pop-in {
    0% { transform: scale(0); }
    70% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

#draggable-container {
    margin-top: 15px;
    min-height: 120px;
}

#draggable-container p {
    font-size: clamp(1rem, 4vw, 1.3rem);
    margin: 0 0 10px 0;
}

#draggable-animal-wrapper {
    width: clamp(80px, 25vw, 120px);
    height: clamp(80px, 25vw, 120px);
    margin: auto;
    display: flex;
    justify-content: center;
    align-items: center;
}

#draggable-animal {
    width: 100%;
    height: 100%;
    object-fit: contain;
    cursor: grab;
    transition: transform 0.2s, opacity 0.2s;
    touch-action: none;
}

#draggable-animal.dragging {
    cursor: grabbing;
    opacity: 0.5;
    transform: scale(1.2);
    position: fixed; /* Allow it to move freely */
    z-index: 1000;
    pointer-events: none;
}

#win-message {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: white;
    z-index: 2000;
}

#win-message h2 {
    font-size: 3rem;
    animation: pop-in 0.5s ease;
}

#play-again-button {
    font-family: 'Fredoka One', cursive;
    font-size: 1.5rem;
    padding: 15px 30px;
    border: none;
    background-color: var(--button-bg);
    color: white;
    border-radius: 50px;
    cursor: pointer;
    box-shadow: 0 4px 6px rgba(0,0,0,0.2);
    transition: background-color 0.2s, transform 0.2s;
}

#play-again-button:hover {
    background-color: var(--button-hover-bg);
    transform: translateY(-2px);
}

.hidden {
    display: none !important;
}

.wobble {
    animation: wobble 0.5s 1;
}

@keyframes wobble {
  16.65% { transform: skew(-12deg); }
  33.3% { transform: skew(10deg); }
  49.95% { transform: skew(-6deg); }
  66.6% { transform: skew(4deg); }
  83.25% { transform: skew(-2deg); }
  100% { transform: skew(0); }
}

/* Media query for larger screens */
@media (min-width: 600px) and (min-height: 600px) {
    #game-container {
        max-width: 500px;
        padding: 20px;
    }
    h1 {
        margin-bottom: 20px;
    }
    #grid-container {
        gap: 15px;
        margin: 20px auto;
    }
    #draggable-container {
        margin-top: 20px;
        min-height: 150px;
    }
    #draggable-animal-wrapper {
        width: 150px;
        height: 150px;
    }
    .grid-cell img {
        width: 75%;
        height: 75%;
    }
}

/* New media query for desktop side-by-side layout */
@media (min-width: 768px) {
    #game-container {
        max-width: 800px;
    }

    #main-game-area {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 20px;
    }

    #grid-container {
        margin: 15px 0;
        flex-shrink: 0;
        width: 400px;
        height: 400px;
        max-width: 400px;
        max-height: 400px;
    }

    #draggable-container {
        margin-top: 0;
    }
}