* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: #fafafa;
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 100vw;
}

.header {
    background: white;
    padding: 16px 24px;
    border-bottom: 1px solid #e8e8e8;
    flex-shrink: 0;
}

.header h1 {
    font-size: 18px;
    font-weight: 600;
    color: #1a1a1a;
    margin-bottom: 12px;
    letter-spacing: -0.3px;
}

.controls {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.controls select,
.controls button {
    padding: 8px 16px;
    font-size: 13px;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    cursor: pointer;
    background: white;
    color: #1a1a1a;
    transition: all 0.2s;
    font-weight: 500;
}

.controls button {
    background: #1a1a1a;
    color: white;
    border: none;
}

.controls button:hover {
    background: #333;
    transform: translateY(-1px);
}

.controls select:hover {
    border-color: #999;
}

.stats {
    display: flex;
    gap: 20px;
    font-size: 13px;
    color: #666;
    margin-left: auto;
    font-weight: 500;
}

.game-area {
    display: flex;
    gap: 16px;
    flex: 1;
    overflow: hidden;
    padding: 16px;
    background: #fafafa;
}

.canvas-container {
    flex: 1;
    background: white;
    border-radius: 8px;
    border: 1px solid #e8e8e8;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    padding: 16px;
    position: relative;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.glitter {
    position: absolute;
    width: 8px;
    height: 8px;
    background: linear-gradient(45deg, #ffd700, #ffed4e);
    border-radius: 50%;
    pointer-events: none;
    animation: glitterPop 0.6s ease-out forwards;
    box-shadow: 0 0 8px rgba(255, 215, 0, 0.8);
}

@keyframes glitterPop {
    0% {
        transform: translate(0, 0) scale(0);
        opacity: 1;
    }
    50% {
        transform: translate(var(--tx), var(--ty)) scale(1.2);
        opacity: 1;
    }
    100% {
        transform: translate(var(--tx), var(--ty)) scale(0);
        opacity: 0;
    }
}

#puzzleCanvas {
    border: 1px solid #e8e8e8;
    cursor: pointer;
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 4px;
}

.pieces-panel {
    width: 280px;
    background: white;
    border-radius: 8px;
    border: 1px solid #e8e8e8;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-shrink: 0;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.pieces-panel h3 {
    font-size: 13px;
    font-weight: 600;
    color: #1a1a1a;
    padding: 14px 16px;
    border-bottom: 1px solid #e8e8e8;
    flex-shrink: 0;
    letter-spacing: -0.2px;
}

#piecesContainer {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    padding: 12px;
    overflow-y: auto;
    flex: 1;
}

.puzzle-piece {
    width: 100%;
    aspect-ratio: 1;
    cursor: grab;
    border: 1px solid #e8e8e8;
    border-radius: 4px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}

.puzzle-piece:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    border-color: #1a1a1a;
}

.puzzle-piece.dragging {
    opacity: 0.5;
    cursor: grabbing;
}

.puzzle-piece.placed {
    display: none;
}

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal.show {
    display: flex;
}

.modal-content {
    background: white;
    padding: 40px;
    border-radius: 12px;
    text-align: center;
    box-shadow: 0 8px 32px rgba(0,0,0,0.12);
}

.modal-content h2 {
    color: #1a1a1a;
    margin-bottom: 16px;
    font-size: 24px;
    font-weight: 600;
    letter-spacing: -0.5px;
}

.modal-content p {
    font-size: 15px;
    margin-bottom: 24px;
    color: #666;
}

#playAgain {
    padding: 12px 32px;
    font-size: 14px;
    background: #1a1a1a;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
}

#playAgain:hover {
    background: #333;
    transform: translateY(-1px);
}

@media (max-width: 1024px) {
    .game-area {
        flex-direction: column;
    }
    
    .pieces-panel {
        width: 100%;
        height: 250px;
    }
    
    #piecesContainer {
        grid-template-columns: repeat(6, 1fr);
    }
}
