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

body {
    font-family: Arial, sans-serif;
    background-color: #f0f0f0;
    color: #333;
    line-height: 1.6;
    overflow: hidden;
}

.puzzle-piece.snap-effect {
    animation: snapGlow 0.3s ease-out;
}

@keyframes snapGlow {
    0% {
        filter: drop-shadow(0 0 3px rgba(255, 255, 255, 0.5)) brightness(1.1);
    }

    50% {
        filter: drop-shadow(0 0 8px rgba(255, 255, 255, 0.8)) brightness(1.3);
    }

    100% {
        filter: drop-shadow(0 0 3px rgba(0, 0, 0, 0.2)) brightness(1);
    }
}

.audio-container {
    display: none;
}

.game-container {
    position: relative;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
}

.controls-bar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 40px;
    display: flex;
    align-items: center;
    padding: 0 10px;
    background-color: rgba(0, 0, 0, 0.5);
    color: white;
    z-index: 200;
}

.icon-button {
    background: none;
    border: none;
    color: white;
    font-size: 22px;
    cursor: pointer;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 5px;
    transition: transform 0.2s, color 0.2s;
}

.icon-button:hover {
    transform: scale(1.1);
    color: #3498db;
}

.center-preview-container {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 3000;
    pointer-events: none;
    display: none;
}

.center-preview-container.visible {
    display: block;
}

.center-preview-image {
    opacity: 1;
    border: 2px solid rgba(255, 255, 255, 0.5);
    border-radius: 8px;
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.2);
}

.spacer {
    flex-grow: 1;
}

.timer {
    font-size: 20px;
    font-weight: bold;
    margin-right: 15px;
    font-variant-numeric: tabular-nums;
}

.puzzle-area {
    position: absolute;
    left: 0;
    width: 100%;
    background-image: url('https://www.transparenttextures.com/patterns/subtle-grey.png');
    background-size: auto;
    background-position: center;
    transition: width 0.3s ease-in-out, height 0.3s ease-in-out;
}

.puzzle-container {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.menu-panel {
    position: absolute;
    top: 40px;
    left: -300px;
    width: 300px;
    height: calc(100vh - 40px);
    background-color: rgba(255, 255, 255, 0.95);
    padding: 20px;
    transition: left 0.3s ease-in-out;
    overflow-y: auto;
    z-index: 150;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.3);
}

.menu-panel.open {
    left: 0;
}

h1,
h2 {
    margin-bottom: 20px;
    color: #2c3e50;
    text-align: center;
    font-size: 1.4em;
}

.setting-group {
    margin-bottom: 15px;
}

label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
    color: #555;
}

select {
    width: 100%;
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    background-color: #fff;
    font-size: 1em;
}

.primary-button {
    display: block;
    width: 100%;
    padding: 10px;
    background-color: #3498db;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1em;
    margin: 20px 0;
    transition: background-color 0.3s, transform 0.1s;
}

.primary-button:hover {
    background-color: #2980b9;
}

.primary-button:active {
    transform: scale(0.98);
}

.stats {
    margin: 15px 0;
    font-size: 1em;
    text-align: center;
    color: #444;
}

.moves-container {
    font-weight: bold;
}

.preview-container {
    text-align: center;
    margin-top: 20px;
    border-top: 1px solid #ddd;
    padding-top: 15px;
}

.preview-container h3 {
    margin-bottom: 10px;
    color: #2c3e50;
}

#preview-image {
    max-width: 100%;
    max-height: 150px;
    border: 2px solid #aaa;
    border-radius: 4px;
    background-color: #eee;
}

.puzzle-description {
    margin: 10px 0 15px 0;
    padding: 12px;
    background-color: #f8f9fa;
    border-left: 4px solid #3498db;
    border-radius: 4px;
    font-size: 14px;
    line-height: 1.5;
    color: #555;
    font-style: italic;
}

.puzzle-piece {
    position: absolute;
    top: 0;
    left: 0;
    cursor: grab;
    filter: drop-shadow(0 0 3px rgba(0, 0, 0, 0.3));
    transition: filter 0.2s ease-out;
    clip-path: var(--puzzle-shape);
    transform-origin: center center;
    touch-action: none;
}

.puzzle-piece.in-tray {
    position: relative;
    transform: none;
    left: 0;
    top: 0;
    margin-bottom: 5px;
    z-index: 0;
    flex-shrink: 0;
    touch-action: auto;
}

.puzzle-piece.dragging {
    cursor: grabbing;
    filter: drop-shadow(0 0 8px rgba(0, 0, 0, 0.5));
}

.puzzle-piece.completed {
    filter: drop-shadow(0 0 2px rgba(0, 0, 0, 0.1));
    cursor: default;
}

.puzzle-piece.dragging-globally {
    position: absolute;
    z-index: 2000;
    pointer-events: none;
    opacity: 0.85;
    filter: drop-shadow(0 0 12px rgba(0, 0, 0, 0.6)) brightness(1.1);
}

.piece-tray-panel {
    position: absolute;
    top: 40px;
    right: -300px;
    width: 150px;
    height: calc(100vh - 40px);
    background-color: rgba(70, 70, 70, 0.85);
    box-shadow: -3px 0 12px rgba(0, 0, 0, 0.4);
    overflow-y: auto;
    overflow-x: hidden;
    transition: right 0.3s ease-in-out, width 0.3s ease-in-out, bottom 0.3s ease-in-out, height 0.3s ease-in-out;
    z-index: 140;
    padding: 10px 0;
    touch-action: pan-x;
}

.piece-tray-panel.visible {
    right: 0;
}

.piece-tray-content {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.puzzle-piece-placeholder {
    height: 50px;
    width: 90%;
    background-color: rgba(255, 255, 255, 0.1);
    border: 2px dashed rgba(255, 255, 255, 0.4);
    border-radius: 4px;
    margin: 5px auto;
    flex-shrink: 0;
}

@media (max-width: 768px) {
    .menu-panel {
        width: 250px;
        left: -260px;
    }

    .timer {
        font-size: 18px;
    }

    .piece-tray-panel {
        top: auto;
        right: auto;
        left: 0;
        bottom: -150px;
        width: 100vw;
        box-shadow: 0 -3px 12px rgba(0, 0, 0, 0.4);
        overflow-y: hidden;
        overflow-x: auto;
        padding: 0 10px;
        -webkit-overflow-scrolling: touch;
    }

    .piece-tray-panel.visible {
        bottom: 0;
    }

    .piece-tray-content {
        flex-direction: row;
        align-items: center;
        justify-content: flex-start;
        height: 100%;
        min-width: max-content;
    }

    .puzzle-piece.in-tray {
        margin-bottom: 0;
        margin-right: 5px;
    }

    .puzzle-piece-placeholder {
        margin: auto 2.5px;
    }
}

@media (max-width: 480px) {
    .controls-bar {
        height: 48px;
        padding: 0 5px;
    }

    .icon-button {
        font-size: 20px;
        width: 35px;
        height: 35px;
        margin: 0 2px;
    }

    .timer {
        font-size: 16px;
        margin-right: 10px;
    }

    .menu-panel {
        width: 100%;
        left: -100%;
        padding: 15px;
    }

    .menu-panel.open {
        left: 0;
    }

    h2 {
        font-size: 1.2em;
    }

    .primary-button {
        font-size: 0.9em;
        padding: 8px;
    }

    select {
        padding: 6px;
        font-size: 0.9em;
    }

    .stats {
        font-size: 0.9em;
    }
}