body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f0f2f5;
    margin: 0;
    display: flex;
    justify-content: center;
    /* align-items: center;  Removed to fix mobile scrolling issues with long content */
    min-height: 100vh;
    /* touch-action: none; Removed to allow scrolling on mobile */
    overflow-y: auto; /* Ensure vertical scrolling is enabled */
}

.container {
    text-align: center;
    width: 100%;
    max-width: 600px;
    padding: 20px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
}

.game-area {
    width: 100%;
}

.sidebar {
    width: 100%;
}

h1 {
    color: #333;
    margin-bottom: 10px;
}

#level-info {
    font-size: 1.2em;
    margin-bottom: 15px;
    color: #555;
}

#game-board {
    position: relative;
    width: 100%;
    height: 0; /* Will be set by JS */
    background-color: #ddd;
    border-radius: 10px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    margin: 0 auto 20px;
    /* touch-action: none; Removed to allow scrolling on background */
}

.puzzle-piece {
    position: absolute;
    background-size: cover;
    border-radius: 10px;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.2), 0 2px 4px rgba(0,0,0,0.2);
    cursor: grab;
    transition: left 0.2s ease-out, top 0.2s ease-out;
    z-index: 10;
    box-sizing: border-box; 
    transform: scale(0.96);
}

.puzzle-piece.dragging {
    cursor: grabbing;
    z-index: 100;
    box-shadow: 0 10px 20px rgba(0,0,0,0.3);
    transition: none;
    transform: scale(1.02);
}

.puzzle-piece.merged {
    border-radius: 0;
    transform: scale(1);
    box-shadow: none;
    z-index: 5;
}

.controls {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

button {
    padding: 10px 20px;
    font-size: 16px;
    cursor: pointer;
    background-color: #4CAF50;
    color: white;
    border: none;
    border-radius: 5px;
    transition: background-color 0.3s;
}

button:hover {
    background-color: #45a049;
}

button:disabled {
    background-color: #cccccc;
    cursor: not-allowed;
}

#message {
    height: 20px;
    color: #d9534f;
    font-weight: bold;
}

/* PC Layout: Side-by-side */
@media (min-width: 768px) {
    body {
        align-items: center; /* Center vertically on PC */
    }

    .container {
        flex-direction: row;
        max-width: 1200px; /* Increased max-width for side-by-side */
        align-items: flex-start; /* Align top */
        gap: 40px;
    }

    .game-area {
        flex: 2; /* Takes more space */
        min-width: 600px; /* Minimum width for game board on PC */
    }

    .sidebar {
        flex: 1; /* Takes less space */
        text-align: left;
        padding-top: 20px;
    }

    .controls {
        justify-content: flex-start; /* Align buttons to left on PC */
    }
}

/* Modal Styles */
.modal {
    display: none; /* Hidden by default */
    position: fixed;
    z-index: 200; /* Sit on top */
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}

.modal-content {
    background-color: #fefefe;
    margin: 15% auto; /* 15% from the top and centered */
    padding: 20px;
    border: 1px solid #888;
    width: 80%;
    max-width: 500px;
    border-radius: 10px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
    position: relative;
}

.close-modal {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    position: absolute;
    right: 15px;
    top: 10px;
}

.close-modal:hover,
.close-modal:focus {
    color: black;
    text-decoration: none;
    cursor: pointer;
}

.categories-container {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin: 15px 0;
    max-height: 300px;
    overflow-y: auto;
    justify-content: space-between;
}

.category-item {
    display: flex;
    align-items: center;
    width: 48%; /* Two columns */
    margin-bottom: 8px;
    background: #f9f9f9;
    padding: 8px;
    border-radius: 5px;
    box-sizing: border-box;
}

.category-item:hover {
    background: #eee;
}

.category-item input {
    margin-right: 10px;
    transform: scale(1.2);
    cursor: pointer;
}

.category-item label {
    cursor: pointer;
    text-transform: capitalize;
    font-size: 14px;
    user-select: none;
    flex: 1;
}

.modal-footer {
    text-align: right;
    margin-top: 20px;
    padding-top: 10px;
    border-top: 1px solid #eee;
}

#save-settings-btn {
    background-color: #2196F3;
}

#save-settings-btn:hover {
    background-color: #0b7dda;
}

/* Mobile Layout Optimizations */
@media (max-width: 767px) {
    .container {
        padding-bottom: 80px; /* Ensure space for scrolling to bottom */
    }
    
    .game-area {
        margin-bottom: 30px;
    }
}