/* --- General Body & Font Styles --- */
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    text-align: center;
    background-color: #eaf5ff;
    margin: 0;
    padding: 16px;
    box-sizing: border-box;
    color: #333;
    perspective: 1000px;
}
h1 {
    font-size: 2.5em;
    color: #2c3e50;
    margin-bottom: 20px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.1);
    transform: perspective(300px) rotateX(5deg);
}
hr {
    border: 1px solid #d0eaff;
    margin: 20px 0;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

/* --- Header and Dropdown Styles --- */
#game-info {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    align-items: center;
    margin-bottom: 20px;
    padding: 20px;
    background: linear-gradient(145deg, #ffffff, #f0f5ff);
    border-radius: 12px;
    box-shadow:
        0 10px 20px rgba(0, 0, 0, 0.1),
        0 5px 15px rgba(0, 0, 0, 0.05);
    max-width: 800px;
    margin-left: auto;
    margin-right: auto;
    gap: 20px;
    transform: perspective(500px) rotateX(2deg);
    border: 1px solid rgba(255, 255, 255, 0.3);
    transition: transform 0.3s ease;
}

#game-info:hover {
    transform: perspective(500px) rotateX(5deg);
}

.category-selector { display: flex; justify-content: center; }
#category-select, #difficulty-select {
    font-size: 1.1em;
    padding: 8px 12px;
    border-radius: 8px;
    border: none;
    background: linear-gradient(145deg, #ecf0f1, #dfe6e9);
    min-width: 180px;
    cursor: pointer;
    box-shadow:
        3px 3px 5px rgba(0, 0, 0, 0.1),
        -1px -1px 3px rgba(255, 255, 255, 0.8);
    transition: all 0.2s ease;
    transform: perspective(100px) rotateX(1deg);
}

#category-select:focus, #difficulty-select:focus {
    outline: none;
    box-shadow:
        2px 2px 5px rgba(0, 0, 0, 0.2),
        -1px -1px 3px rgba(255, 255, 255, 0.8),
        inset 1px 1px 3px rgba(0, 0, 0, 0.1);
}

#category-select:disabled {
    background: linear-gradient(145deg, #e0e0e0, #d0d0d0);
    cursor: not-allowed;
    color: #95a5a6;
}
.stats-container {
    text-align: center;
    background: rgba(255,255,255,0.7);
    padding: 10px;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}
.stats-container p, .stats-container h2 { margin: 0; }
.stats-container p { font-size: 1em; color: #7f8c8d; }
.stats-container h2 {
    font-size: 1.4em;
    color: #2c3e50;
    margin-top: 5px;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.1);
}

@media (max-width: 640px) {
    #game-info {
        grid-template-columns: 1fr;
        gap: 20px;
        transform: none;
    }
    #game-info:hover {
        transform: none;
    }
}

/* --- Puzzle and Piece Styles --- */
#puzzle-container {
    position: relative;
    display: grid;
    border: 2px solid #bde0fe;
    border-radius: 12px;
    margin: 20px auto;
    max-width: 90%;
    box-sizing: border-box;
    box-shadow:
        0 10px 30px rgba(0, 80, 150, 0.15),
        0 5px 15px rgba(0, 0, 0, 0.1);
    background-color: #ffffff;
    transform: perspective(800px) rotateX(3deg);
    transition: transform 0.3s ease;
}

#puzzle-container:hover {
    transform: perspective(800px) rotateX(5deg);
}

#pieces-container {
    display: flex;
    align-items: center;
    overflow-x: auto;
    overflow-y: hidden;
    flex-wrap: nowrap;
    gap: 15px;
    margin: 15px auto;
    padding: 10px;
    min-height: 100px;
    background: linear-gradient(145deg, #2c3e50, #34495e);
    border-radius: 12px;
    border: 1px solid #4a6582;
    box-shadow:
        inset 0 0 10px rgba(0,0,0,0.5),
        0 5px 15px rgba(0,0,0,0.2);
    -webkit-mask-image: linear-gradient(to right, transparent, black 5%, black 95%, transparent);
    mask-image: linear-gradient(to right, transparent, black 5%, black 95%, transparent);
    -webkit-overflow-scrolling: touch;
    transform: perspective(300px) rotateX(1deg);
}
#pieces-container::-webkit-scrollbar { height: 12px; }
#pieces-container::-webkit-scrollbar-track { background: #4a6582; border-radius: 10px; }
#pieces-container::-webkit-scrollbar-thumb { background: #888; border-radius: 10px; }
#pieces-container::-webkit-scrollbar-thumb:hover { background: #555; }
.puzzle-slot {
    box-sizing: border-box;
    border: 1px dotted #d0eaff;
    background: rgba(210, 234, 255, 0.2);
}
.puzzle-piece {
    border: 1px solid #fff;
    box-sizing: border-box;
    flex-shrink: 0;
    cursor: grab;
    box-shadow:
        3px 3px 5px rgba(0,0,0,0.3),
        1px 1px 3px rgba(255,255,255,0.8) inset;
    transition: all 0.2s ease;
    background-repeat: no-repeat;
    transform-style: preserve-3d;
    /* Added for performance optimization during drag */
    will-change: transform, left, top;
}
.puzzle-piece:active, .puzzle-piece.dragging {
    transform: scale(1.1) rotateZ(2deg);
    box-shadow:
        5px 5px 10px rgba(0,0,0,0.4),
        2px 2px 5px rgba(255,255,255,0.8) inset;
    z-index: 100;
}
.piece-placed {
    border: 1px solid limegreen;
    opacity: 1;
    cursor: default;
    animation: piecePlacedAnim 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28);
    box-shadow:
        0 0 10px rgba(50, 205, 50, 0.5),
        1px 1px 3px rgba(255,255,255,0.8) inset;
}
@keyframes piecePlacedAnim {
    0% { transform: scale(1.2) rotateZ(5deg); opacity: 0.5; }
    100% { transform: scale(1) rotateZ(0); opacity: 1; }
}

/* --- Custom Alert Box --- */
#custom-alert-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.1); /* Reduced opacity for better visibility of background */
    z-index: 2000;
    opacity: 1;
    transition: opacity 0.3s ease-in-out;
    /* REMOVED: backdrop-filter: blur(3px); */
}
#custom-alert-box {
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%) perspective(500px) rotateX(5deg);
    background: linear-gradient(145deg, #ffffff, #f5f5f5);
    padding: 25px 40px;
    border-radius: 10px;
    box-shadow:
        0 15px 35px rgba(0,0,0,0.3),
        0 5px 15px rgba(0,0,0,0.2);
    text-align: center;
    z-index: 2001;
    cursor: move;
    user-select: none;
    opacity: 1;
    transition: all 0.3s ease-in-out;
    border: 1px solid rgba(255, 255, 255, 0.5);
    /* Added for performance optimization during drag */
    will-change: transform, left, top;
}
#custom-alert-message {
    margin: 0;
    font-size: 1.5em;
    color: #333;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.1);
}
#custom-alert-button {
    margin-top: 20px;
    padding: 10px 25px;
    font-size: 1.1em;
    font-weight: 600;
    color: white;
    background: linear-gradient(145deg, #27ae60, #2ecc71);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow:
        3px 3px 5px rgba(0, 0, 0, 0.2),
        -1px -1px 3px rgba(255, 255, 255, 0.5);
    transform: perspective(100px) rotateX(1deg);
}
#custom-alert-button:hover {
    background: linear-gradient(145deg, #2ecc71, #27ae60);
    box-shadow:
        2px 2px 5px rgba(0, 0, 0, 0.3),
        -1px -1px 3px rgba(255, 255, 255, 0.5);
    transform: perspective(100px) rotateX(2deg);
}
#custom-alert-button:active {
    box-shadow:
        1px 1px 3px rgba(0, 0, 0, 0.3) inset,
        -1px -1px 3px rgba(255, 255, 255, 0.5) inset;
    transform: perspective(100px) rotateX(1deg) translateY(1px);
}

/* Hidden class */
.hidden {
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, -50%) scale(0.8);
    display: none !important;
    visibility: hidden !important;
}
#custom-alert-overlay.hidden { transform: none; }

/* --- Loading Indicator --- */
#loader {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 60px;
    height: 60px;
    border: 6px solid #bde0fe;
    border-top: 6px solid #2c3e50;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    transform: translate(-50%, -50%);
    opacity: 1;
    transition: opacity 0.3s;
    box-shadow: 0 0 15px rgba(0,0,0,0.2);
}
#loader.hidden { opacity: 0; pointer-events: none; }
@keyframes spin {
    0% { transform: translate(-50%, -50%) rotate(0deg); }
    100% { transform: translate(-50%, -50%) rotate(360deg); }
}