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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

header {
    text-align: center;
    margin-bottom: 30px;
}

header h1 {
    color: white;
    font-size: 2.5rem;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
    margin-bottom: 10px;
}

.upload-section {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 15px;
    padding: 30px;
    margin-bottom: 30px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.1);
    backdrop-filter: blur(10px);
}

#imageUpload {
    display: none;
}

.upload-button {
    display: inline-block;
    background: linear-gradient(45deg, #4CAF50, #45a049);
    color: white;
    padding: 15px 30px;
    border-radius: 25px;
    cursor: pointer;
    font-size: 1.1rem;
    font-weight: bold;
    text-decoration: none;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(76, 175, 80, 0.3);
    margin-bottom: 20px;
}

.upload-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(76, 175, 80, 0.4);
}

.image-preview {
    margin: 20px 0;
    padding: 20px;
    background: rgba(248, 249, 250, 0.8);
    border-radius: 12px;
    border: 2px solid #e9ecef;
    width: 100%;
    align-self: stretch;
}

.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.preview-header h3 {
    color: #495057;
    font-size: 1.2rem;
    margin: 0;
}

.toggle-button {
    background: linear-gradient(45deg, #6f42c1, #5a32a3);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 15px;
    font-size: 0.9rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(111, 66, 193, 0.3);
}

.toggle-button:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(111, 66, 193, 0.4);
}

.preview-container {
    text-align: center;
    border-radius: 8px;
    overflow: hidden;
    background: white;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

#previewImage {
    max-width: 100%;
    max-height: 300px;
    width: auto;
    height: auto;
    display: block;
    margin: 0 auto;
    border-radius: 8px;
}

.puzzle-config {
    display: flex;
    gap: 20px;
    align-items: stretch;
    margin-top: 20px;
    flex-direction: column;
}

.puzzle-config .config-row {
    display: flex;
    gap: 20px;
    align-items: center;
    flex-wrap: wrap;
    width: 100%;
}

.config-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.config-group label {
    font-weight: bold;
    color: #555;
    font-size: 0.9rem;
}

.config-group select {
    padding: 10px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 1rem;
    background: white;
    cursor: pointer;
    transition: border-color 0.3s ease;
}

.config-group select:focus {
    outline: none;
    border-color: #4CAF50;
}

#generatePuzzle {
    background: linear-gradient(45deg, #FF6B6B, #FF5252);
    color: white;
    border: none;
    padding: 12px 25px;
    border-radius: 20px;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(255, 107, 107, 0.3);
}

#generatePuzzle:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(255, 107, 107, 0.4);
}

#generatePuzzle:disabled {
    background: #ccc;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

.game-area {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 15px;
    padding: 20px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.1);
    backdrop-filter: blur(10px);
}

.game-layout {
    display: flex;
    gap: 30px;
    justify-content: center;
    align-items: flex-start;
    flex-wrap: wrap;
}

.puzzle-board {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.puzzle-board h3 {
    color: #555;
    margin-bottom: 15px;
    font-size: 1.3rem;
}

#puzzleCanvas {
    border: 3px solid #333;
    border-radius: 10px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
    cursor: pointer;
    background: #f9f9f9;
    touch-action: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}

.pieces-area {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.pieces-area h3 {
    color: #555;
    margin-bottom: 15px;
    font-size: 1.3rem;
}

#piecesCanvas {
    border: 3px solid #666;
    border-radius: 10px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    cursor: pointer;
    background: rgba(240, 240, 240, 0.8);
    touch-action: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}

@media (max-width: 768px) {
    .container {
        padding: 10px;
    }

    header h1 {
        font-size: 2rem;
    }

    .upload-section {
        padding: 20px;
    }

    .puzzle-config {
        flex-direction: column;
        align-items: stretch;
    }

    .puzzle-config .config-row {
        flex-direction: column;
        align-items: stretch;
    }

    .config-group {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }

    .game-layout {
        flex-direction: column;
        gap: 20px;
    }

    #puzzleCanvas,
    #piecesCanvas {
        max-width: 100%;
        height: auto;
    }
}

.puzzle-piece {
    cursor: grab;
    transition: transform 0.1s ease;
}

.puzzle-piece:hover {
    transform: scale(1.05);
}

.puzzle-piece.dragging {
    cursor: grabbing;
    transform: scale(1.1);
    z-index: 1000;
}

.puzzle-piece.placed {
    cursor: default;
    filter: brightness(1.1);
}

.success-message {
    background: linear-gradient(45deg, #4CAF50, #45a049);
    color: white;
    padding: 20px;
    border-radius: 10px;
    text-align: center;
    margin-top: 20px;
    font-size: 1.2rem;
    font-weight: bold;
    animation: celebration 0.5s ease-in-out;
}

@keyframes celebration {
    0% { transform: scale(0.8); opacity: 0; }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); opacity: 1; }
}

.completion-message {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    animation: fadeIn 0.5s ease-in-out;
}

.completion-content {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 40px;
    border-radius: 20px;
    text-align: center;
    box-shadow: 0 20px 40px rgba(0,0,0,0.3);
    animation: bounceIn 0.8s ease-out;
    max-width: 500px;
    margin: 20px;
}

.completion-content h2 {
    font-size: 2.5rem;
    margin-bottom: 20px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

.completion-content p {
    font-size: 1.3rem;
    margin: 0;
    opacity: 0.9;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes bounceIn {
    0% {
        transform: scale(0.3);
        opacity: 0;
    }
    50% {
        transform: scale(1.1);
        opacity: 0.8;
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}