body {
    font-family: 'Arial', sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 0;
    padding: 20px;
    background-color: pink;/*#f0f0f0;*/
    color: #333;
}

h1, h2 {
    text-align: center;
    color: red;/*#333;*/
}

.game-container {
    display: flex;
    flex-wrap: wrap; /* Allow wrapping on smaller screens */
    gap: 30px;
    justify-content: center;
    align-items: flex-start; /* Align items to the top */
    max-width: 1200px;
    width: 100%;
}

.puzzle-area, .pieces-area, .reference-area {
    background-color: #fff;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.puzzle-area {
    order: 1; /* Board first */
}

.pieces-area {
    order: 2; /* Pieces tray second */
    display: flex;
    flex-direction: column;
    align-items: center;
}

.reference-area {
    order: 3; /* Reference image last */
    text-align: center;
}

#reference-image {
    max-width: 200px; /* Adjust as needed */
    height: auto;
    border: 1px solid #ccc;
    border-radius: 4px;
}

#puzzle-board {
    display: grid;
    grid-template-columns: repeat(3, 100px); /* 3 columns, each 100px wide */
    grid-template-rows: repeat(3, 100px);    /* 3 rows, each 100px high */
    gap: 2px; /* Small gap to see borders */
    border: 2px solid #555;
    background-color: #ddd; /* Background for empty board */
    width: 304px; /* 3*100 + 2*2 (gaps) + 2*2 (border) - adjust based on piece size and gap */
    height: 304px;
    margin: 0 auto; /* Center the board */
}

.puzzle-slot {
    width: 100px;
    height: 100px;
    background-color: #e0e0e0;
    border: 1px dashed #aaa;
    display: flex;
    justify-content: center;
    align-items: center;
    box-sizing: border-box; /* Important for consistent sizing */
}

#pieces-container {
    display: flex;
    flex-wrap: wrap; /* Allow pieces to wrap if many */
    justify-content: center;
    align-items: center;
    gap: 10px;
    min-height: 110px; /* To accommodate at least one row of pieces */
    padding: 10px;
    margin-bottom: 20px;
    border: 1px solid #ccc;
    border-radius: 4px;
    width: 320px; /* Slightly wider than board to fit pieces */
    background-color: #f9f9f9;
}

.puzzle-piece {
    width: 100px;
    height: 100px;
    border: 1px solid #333;
    box-sizing: border-box;
    cursor: grab;
    background-size: 300% 300%; /* Image is 3x3 times the piece size */
    transition: transform 0.1s ease-out, box-shadow 0.1s ease-out;
    user-select: none; /* Prevents text selection when dragging */
}

.puzzle-piece:active {
    cursor: grabbing;
    transform: scale(1.05);
    box-shadow: 0 0 10px rgba(0,0,0,0.3);
    z-index: 1000; /* Bring to front when dragging */
}

/* Dragging feedback */
.dragging {
    opacity: 0.5;
}

.drag-over-slot {
    background-color: #c8e6c9 !important; /* Light green highlight */
    border-style: solid;
}

.controls {
    margin-top: 10px;
    text-align: center;
}

button {
    padding: 10px 20px;
    font-size: 16px;
    background-color: #007bff;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    margin: 5px;
    transition: background-color 0.2s;
}

button:hover {
    background-color: #0056b3;
}

button:disabled {
    background-color: #ccc;
    cursor: not-allowed;
}

#message {
    margin-top: 15px;
    font-size: 1.2em;
    font-weight: bold;
    color: green;
    min-height: 1.5em; /* Reserve space for message */
}
/* ... (your existing CSS) ... */

/* Modal Styles */
.modal {
    display: none; /* Hidden by default */
    position: fixed; /* Stay in place */
    z-index: 1001; /* Sit on top of everything else */
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto; /* Enable scroll if needed, though not expected for this simple modal */
    background-color: rgba(0,0,0,0.5); /* Black w/ opacity for backdrop */
    justify-content: center; /* For flex centering */
    align-items: center;     /* For flex centering */
}

.modal-open { /* Class to toggle modal visibility */
    display: flex;
}

.modal-content {
    background-color: #fff;
    margin: auto;
    padding: 25px 30px;
    border: 1px solid #ddd;
    border-radius: 8px;
    width: 80%;
    max-width: 450px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    text-align: center;
    animation: fadeInModal 0.3s ease-out;
    position: relative; /* For positioning close button */
}

@keyframes fadeInModal {
    from { opacity: 0; transform: translateY(-20px) scale(0.95); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.close-button {
    color: #aaa;
    position: absolute; /* Changed from float */
    top: 10px;
    right: 15px;
    font-size: 28px;
    font-weight: bold;
    line-height: 1;
}

.close-button:hover,
.close-button:focus {
    color: #333;
    text-decoration: none;
    cursor: pointer;
}

#modalMessageText {
    font-size: 1.4em;
    margin-bottom: 20px;
    color: #333;
}

#modalPlayAgainButton {
    /* Inherits general button styles, can add specifics */
    background-color: #28a745; /* Green */
    padding: 12px 25px;
}
#modalPlayAgainButton:hover {
    background-color: #218838;
}
