body {
    font-family: Arial, sans-serif;
    background-color: #f0f0f0;
    margin: 0;
    padding: 20px;
    touch-action: manipulation;
    box-sizing: border-box;
    overflow-x: hidden;
}

*,
*::before,
*::after {
    box-sizing: inherit;
}

.container {
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    text-align: center;
}

h1 {
    color: #333;
    font-size: 24px;
}

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

button {
    padding: 12px 24px;
    margin: 0;
    background-color: #4CAF50;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 16px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

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

button:active {
    background-color: #3d8b40;
}

.puzzle-container {
    width: min(400px, calc(100vw - 40px));
    max-width: 100%;
    aspect-ratio: 1 / 1;
    margin: 0 auto;
    position: relative;
    border: 2px solid #333;
    background-color: #fff;
    touch-action: none;
    overflow: hidden;
    isolation: isolate;
    transition: border-color 600ms ease 500ms;
}

.puzzle-container::after {
    content: "";
    position: absolute;
    top: -30%;
    left: -45%;
    z-index: 10000;
    width: 22%;
    height: 160%;
    pointer-events: none;
    opacity: 0;
    transform: translateX(-120%) rotate(18deg);
    background:
        linear-gradient(
            90deg,
            transparent 0%,
            rgba(255,255,255,0.25) 30%,
            rgba(255,255,255,0.9) 50%,
            rgba(255,255,255,0.25) 70%,
            transparent 100%
        );
    filter: blur(2px);
    mix-blend-mode: screen;
}

.puzzle-container.celebrating::after {
    animation: solvedSweep 1.05s ease-out forwards;
}

.puzzle-container.solved {
    border-color: transparent;
}

.tile {
    position: absolute;
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
    transition: transform 0.2s, border-color 600ms ease 450ms;
    touch-action: none;
    background-repeat: no-repeat;
    box-sizing: border-box;
    border: 1px solid rgba(0,0,0,0.1);
    will-change: left, top, transform;
}

.tile.dragging {
    cursor: grabbing;
    z-index: 10;
    box-shadow: 0 0 10px rgba(0,0,0,0.5);
    transform: scale(1.05);
}

.tile.joined {
    border-color: rgba(76, 175, 80, 0.35);
}

.puzzle-container.solved .tile {
    border-color: transparent;
}

.status {
    margin-top: 20px;
    font-weight: bold;
    color: #666;
    font-size: 18px;
}

@media (max-width: 450px) {
    h1 {
        font-size: 20px;
    }
    button {
        padding: 10px 16px;
        font-size: 14px;
    }
}

@keyframes solvedSweep {
    0% {
        opacity: 0;
        transform: translateX(-120%) rotate(18deg);
    }
    18% {
        opacity: 0.95;
    }
    100% {
        opacity: 0;
        transform: translateX(720%) rotate(18deg);
    }
}
