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

:root {
    --primary-color: #FFDE00; /* Yellow */
    --secondary-color: #F44336; /* Red */
    --accent-color: #007BFF; /* Blue */
    --text-color: #333;
    --bg-color: #f0f8ff;
    --border-radius: 15px;
    --box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

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

body {
    font-family: 'Fredoka One', cursive;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background-image: url('background.png');
    background-size: cover;
    background-position: center;
    color: var(--text-color);
    overflow: hidden;
}

#game-container {
    width: 100%;
    max-width: 900px;
    height: 95vh;
    max-height: 700px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    padding: 20px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

.screen {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    width: 100%;
    height: 100%;
    animation: fadeIn 0.5s ease-in-out;
    position: relative; /* For positioning children */
}

.screen.active {
    display: flex;
}

@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.welcome-character {
    position: absolute;
    bottom: 0;
    right: 10px;
    height: 50vh;
    max-height: 280px;
    max-width: 30%;
    object-fit: contain;
    pointer-events: none; /* Prevent image from being clickable */
    animation: slideIn 0.7s ease-out;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

h1 {
    color: var(--secondary-color);
    font-size: clamp(2rem, 5vw, 3rem);
    margin-bottom: 20px;
    text-shadow: 2px 2px var(--primary-color);
}

h2 {
    color: var(--accent-color);
    font-size: clamp(1.5rem, 4vw, 2.2rem);
    margin-bottom: 30px;
}

.btn {
    font-family: 'Fredoka One', cursive;
    background-color: var(--secondary-color);
    color: white;
    border: none;
    padding: 15px 30px;
    font-size: 1.2rem;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.2s ease;
    margin: 10px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
    border-bottom: 4px solid #c33025;
}

.btn:hover, .btn:focus {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0,0,0,0.3);
}

.btn:active {
    transform: translateY(2px);
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    border-bottom-width: 2px;
}

.back-btn {
    position: absolute;
    top: 10px;
    left: 10px;
    padding: 10px 20px;
    font-size: 1rem;
    background-color: var(--accent-color);
    border-bottom-color: #0056b3;
}

.difficulty-options, .win-options {
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Puzzle Select Screen */
.puzzle-options {
    display: flex;
    gap: 20px;
    justify-content: center;
    flex-wrap: wrap;
}

.puzzle-option {
    width: 150px;
    height: 150px;
    object-fit: cover;
    border-radius: var(--border-radius);
    cursor: pointer;
    border: 5px solid var(--primary-color);
    transition: transform 0.2s, box-shadow 0.2s;
}

.puzzle-option:hover {
    transform: scale(1.05);
    box-shadow: 0 0 20px var(--primary-color);
}

/* Game Screen */
#game-screen {
    justify-content: flex-start;
}

.game-header {
    width: 100%;
    position: relative;
    text-align: center;
    margin-bottom: 10px;
    flex-shrink: 0;
}

#puzzle-title {
    font-size: 1.5rem;
    color: var(--accent-color);
}

#puzzle-area {
    flex-grow: 1;
    width: 100%;
    display: flex;
    align-items: flex-start; /* Changed from center to flex-start */
    justify-content: center;
    overflow: auto;
    padding-top: 40px; /* Increased padding to push content down more */
}

#puzzle-container {
    display: flex;
    width: 100%;
    max-width: 850px; /* Adjust as needed */
    gap: 20px;
    padding: 10px;
}

#puzzle-board {
    aspect-ratio: 1 / 1;
    display: grid;
    border: 2px dashed #ccc;
    background-color: rgba(255, 255, 255, 0.7);
    border-radius: var(--border-radius);
    box-shadow: inset 0 0 10px rgba(0,0,0,0.1);
    flex-shrink: 0;
    position: relative; /* For pseudo-element positioning */
}

#puzzle-board::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: var(--puzzle-image-url);
    background-size: 100% 100%;
    filter: grayscale(100%);
    opacity: 0.25;
    z-index: 0;
    border-radius: calc(var(--border-radius) - 2px); /* Match parent border-radius */
}

.placeholder {
    border: 1px solid rgba(221, 221, 221, 0.7);
    background-color: transparent;
    z-index: 1;
}

#pieces-container {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-content: flex-start;
    padding: 10px;
    overflow-y: auto;
    min-height: 120px;
    flex-grow: 1;
    border: 1px solid #ddd;
    border-radius: var(--border-radius);
    background: rgba(255, 255, 255, 0.5);
}

.puzzle-piece {
    background-size: 400% 400%; /* Default, will be updated by JS */
    cursor: grab;
    transition: transform 0.1s, box-shadow 0.1s;
    border-radius: 5px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.3);
}

.puzzle-piece.dragging {
    cursor: grabbing;
    transform: scale(1.1);
    box-shadow: 0 5px 15px rgba(0,0,0,0.4);
    z-index: 1000;
    position: absolute; /* Take out of flow */
}

.puzzle-piece.in-place {
    pointer-events: none;
    box-shadow: none;
}


/* Win Screen */
#win-image {
    width: 200px;
    height: 200px;
    object-fit: cover;
    border-radius: var(--border-radius);
    margin: 20px 0;
    border: 5px solid var(--primary-color);
}

/* Responsive Styles */
@media (max-width: 768px) {
    .welcome-character {
        height: 35vh;
        max-height: 180px;
        right: -10px; /* Let Mickey peek from the side */
    }
    #game-container {
        height: 100vh;
        max-height: none;
        border-radius: 0;
        padding: 10px;
    }
    #puzzle-area {
        align-items: flex-start;
        padding-top: 0; /* Reset padding for mobile layout */
    }
    #puzzle-container {
        flex-direction: column;
        width: 100%;
        max-width: none;
        padding: 0;
    }
    #puzzle-board {
        width: 95vw; /* Use viewport width to ensure it fits */
        max-width: 400px; /* Set a reasonable max size */
        height: auto; /* Height will be determined by aspect-ratio */
        margin: 0 auto 10px auto;
    }
    #pieces-container {
        flex-direction: row;
        height: 150px; /* Give a fixed height */
        overflow-y: auto; /* Enable vertical scrolling */
        min-height: 120px;
        flex-grow: 0;
        width: 100%;
        border: none;
        background: transparent;
    }
    .puzzle-piece {
        /* When on board, it will be sized by the grid */
        width: 100%;
        height: 100%;
    }
    #pieces-container .puzzle-piece {
        /* When in the container, have a fixed size to allow wrapping */
        width: 60px; /* Adjust size as needed */
        height: 60px;
        flex-shrink: 0;
    }
    .puzzle-option {
        width: 100px;
        height: 100px;
    }
     h1 { font-size: 1.8rem; }
     h2 { font-size: 1.3rem; }
}