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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: #333;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
}

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

header {
    text-align: center;
    margin-bottom: 40px;
    color: white;
}

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

header p {
    font-size: 1.1rem;
    opacity: 0.9;
}

main {
    background: white;
    border-radius: 15px;
    padding: 30px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}

.upload-section {
    text-align: center;
    margin-bottom: 30px;
}

.file-input-wrapper {
    position: relative;
    display: inline-block;
}

.file-input {
    position: absolute;
    opacity: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
}

.file-label {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 15px 30px;
    background: linear-gradient(45deg, #4CAF50, #45a049);
    color: white;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.1rem;
    font-weight: 600;
    transition: all 0.3s ease;
    border: 2px solid transparent;
}

.file-label:hover {
    background: linear-gradient(45deg, #45a049, #4CAF50);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(76, 175, 80, 0.3);
}

.upload-icon {
    font-size: 1.2rem;
}

.controls-section {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 10px;
    margin-bottom: 30px;
}

.grid-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    flex-wrap: wrap;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.control-group label {
    font-weight: 600;
    color: #555;
}

.control-group input {
    width: 80px;
    padding: 8px;
    border: 2px solid #ddd;
    border-radius: 5px;
    font-size: 1rem;
    text-align: center;
}

.control-group input:focus {
    outline: none;
    border-color: #667eea;
}

.cut-button {
    padding: 10px 25px;
    background: linear-gradient(45deg, #667eea, #764ba2);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.cut-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.3);
}

.preview-section {
    margin-bottom: 30px;
}

.preview-section h3 {
    margin-bottom: 15px;
    color: #333;
    font-size: 1.3rem;
}

.image-preview {
    position: relative;
    display: inline-block;
    max-width: 100%;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}

#originalImage {
    max-width: 100%;
    max-height: 400px;
    display: block;
}

.grid-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.grid-line {
    position: absolute;
    background: rgba(255, 255, 255, 0.8);
    box-shadow: 0 0 2px rgba(0,0,0,0.3);
}

.grid-line.horizontal {
    width: 100%;
    height: 2px;
}

.grid-line.vertical {
    width: 2px;
    height: 100%;
}

.results-section {
    margin-top: 30px;
}

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

.results-header h3 {
    color: #333;
    font-size: 1.3rem;
}

.download-all-button {
    padding: 10px 20px;
    background: linear-gradient(45deg, #ff6b6b, #ee5a52);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.download-all-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(255, 107, 107, 0.3);
}

.result-grid {
    display: grid;
    gap: 15px;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
}

.grid-piece {
    background: #f8f9fa;
    border-radius: 8px;
    overflow: hidden;
    transition: transform 0.3s ease;
    box-shadow: 0 3px 10px rgba(0,0,0,0.1);
}

.grid-piece:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 25px rgba(0,0,0,0.15);
}

.grid-piece img {
    width: 100%;
    height: auto;
    display: block;
}

.piece-info {
    padding: 10px;
    text-align: center;
}

.piece-label {
    font-size: 0.9rem;
    color: #666;
    margin-bottom: 8px;
}

.download-button {
    padding: 6px 12px;
    background: #28a745;
    color: white;
    border: none;
    border-radius: 5px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: background 0.3s ease;
}

.download-button:hover {
    background: #218838;
}

footer {
    text-align: center;
    margin-top: 40px;
    color: white;
    opacity: 0.8;
}

@media (max-width: 768px) {
    .container {
        padding: 15px;
    }
    
    header h1 {
        font-size: 2rem;
    }
    
    main {
        padding: 20px;
    }
    
    .grid-controls {
        flex-direction: column;
        gap: 15px;
    }
    
    .results-header {
        flex-direction: column;
        align-items: stretch;
    }
    
    .result-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 10px;
    }
}

/* Image Stitcher Styles */
.section-divider {
    text-align: center;
    margin: 50px 0 30px 0;
    padding: 30px 0;
    border-top: 2px solid #e9ecef;
}

.section-divider h2 {
    font-size: 2rem;
    color: #333;
    margin-bottom: 10px;
    background: linear-gradient(45deg, #667eea, #764ba2);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.section-divider p {
    color: #666;
    font-size: 1.1rem;
}

.stitcher-section {
    margin-top: 30px;
}

.stitcher-controls {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 10px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    flex-wrap: wrap;
}

.create-grid-button {
    padding: 10px 25px;
    background: linear-gradient(45deg, #28a745, #20c997);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.create-grid-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(40, 167, 69, 0.3);
}

.clear-grid-button {
    padding: 10px 20px;
    background: linear-gradient(45deg, #dc3545, #c82333);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.clear-grid-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(220, 53, 69, 0.3);
}

.drop-grid-container {
    margin: 20px 0;
}

.drop-grid {
    display: grid;
    gap: 10px;
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 10px;
    border: 2px dashed #dee2e6;
}

.drop-slot {
    aspect-ratio: 1;
    min-height: 120px;
    background: white;
    border: 2px dashed #ced4da;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: all 0.3s ease;
    cursor: pointer;
}

.drop-slot:hover {
    border-color: #667eea;
    background: #f8f9ff;
}

.drop-slot.drag-over {
    border-color: #28a745;
    background: #f8fff8;
    transform: scale(1.02);
}

.drop-slot.filled {
    border-color: #28a745;
    border-style: solid;
}

.drop-slot-content {
    text-align: center;
    color: #6c757d;
    font-size: 0.9rem;
}

.drop-slot-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 6px;
}

.remove-image {
    position: absolute;
    top: 5px;
    right: 5px;
    background: rgba(220, 53, 69, 0.9);
    color: white;
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    font-size: 12px;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
}

.drop-slot.filled:hover .remove-image {
    display: flex;
}

.stitcher-actions {
    text-align: center;
    margin-top: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

.stitch-button {
    padding: 12px 30px;
    background: linear-gradient(45deg, #667eea, #764ba2);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.stitch-button:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.3);
}

.stitch-button:disabled {
    background: #6c757d;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.stitch-options {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    color: #666;
}

.stitch-options input[type="checkbox"] {
    margin-right: 5px;
}

.stitched-result {
    margin-top: 30px;
    text-align: center;
}

.stitched-result h3 {
    margin-bottom: 20px;
    color: #333;
    font-size: 1.3rem;
}

.stitched-image-container {
    background: white;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
    display: inline-block;
}

#stitchedImage {
    max-width: 100%;
    max-height: 600px;
    border-radius: 8px;
    margin-bottom: 15px;
    box-shadow: 0 3px 10px rgba(0,0,0,0.1);
}

.download-stitched-button {
    padding: 10px 25px;
    background: linear-gradient(45deg, #ff6b6b, #ee5a52);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.download-stitched-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(255, 107, 107, 0.3);
}

@media (max-width: 768px) {
    .section-divider h2 {
        font-size: 1.5rem;
    }
    
    .stitcher-controls {
        flex-direction: column;
        gap: 15px;
    }
    
    .drop-grid {
        padding: 15px;
    }
    
    .drop-slot {
        min-height: 80px;
    }
    
    .stitcher-actions {
        flex-direction: column;
    }
}
