/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
    line-height: 1.6;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.header {
    text-align: center;
    margin-bottom: 3rem;
    color: white;
}

.header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    text-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.header h1 i {
    margin-right: 0.5rem;
    color: #ffd700;
}

.header p {
    font-size: 1.1rem;
    opacity: 0.9;
    font-weight: 300;
}

/* Main Content */
.main {
    flex: 1;
    background: white;
    border-radius: 20px;
    padding: 2rem;
    box-shadow: 0 20px 60px rgba(0,0,0,0.1);
    backdrop-filter: blur(10px);
}

/* Steps */
.step {
    margin-bottom: 2rem;
    animation: fadeIn 0.5s ease-in-out;
}

.step-header {
    display: flex;
    align-items: center;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid #f0f2f5;
}

.step-number {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    margin-right: 1rem;
    flex-shrink: 0;
}

.step-header h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-right: 1rem;
    flex-shrink: 0;
}

.step-header p {
    color: #666;
    font-size: 0.9rem;
    margin-left: auto;
}

/* Upload Area */
.upload-area {
    border: 3px dashed #ddd;
    border-radius: 15px;
    padding: 3rem 2rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.4, 0.0, 0.2, 1);
    background: #f8f9fa;
    position: relative;
    overflow: hidden;
}

.upload-area:hover {
    border-color: #667eea;
    background: #f0f4ff;
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.15);
}

.upload-area.dragover {
    border-color: #667eea;
    background: #e8f2ff;
    transform: scale(1.02);
    box-shadow: 0 12px 35px rgba(102, 126, 234, 0.25);
}

.upload-content i {
    font-size: 3rem;
    color: #667eea;
    margin-bottom: 1rem;
    display: block;
}

.upload-content h3 {
    font-size: 1.3rem;
    margin-bottom: 0.5rem;
    color: #333;
}

.upload-content p {
    color: #666;
    font-size: 1rem;
}

.browse-text {
    color: #667eea;
    text-decoration: underline;
    cursor: pointer;
}

#imageInput {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

/* Selected Images */
.selected-images {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 1rem;
    margin-top: 2rem;
}

.image-item {
    position: relative;
    border-radius: 10px;
    overflow: hidden;
    background: #f8f9fa;
    border: 2px solid #e9ecef;
    transition: all 0.4s cubic-bezier(0.4, 0.0, 0.2, 1);
    aspect-ratio: 1;
    transform-origin: center;
}

.image-item:hover {
    transform: translateY(-5px) scale(1.03);
    box-shadow: 0 12px 35px rgba(0,0,0,0.15);
    border-color: #667eea;
}

.image-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.4s cubic-bezier(0.4, 0.0, 0.2, 1);
}

.image-item:hover img {
    transform: scale(1.05);
}

.image-remove {
    position: absolute;
    top: 5px;
    right: 5px;
    background: rgba(255,255,255,0.9);
    border: none;
    border-radius: 50%;
    width: 25px;
    height: 25px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    color: #dc3545;
    transition: all 0.2s ease;
}

.image-remove:hover {
    background: #dc3545;
    color: white;
    transform: scale(1.1);
}

.image-info {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0,0,0,0.7);
    color: white;
    padding: 0.25rem 0.5rem;
    font-size: 0.7rem;
    text-align: center;
}

/* Merge Options */
.merge-options {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.option {
    background: #f8f9fa;
    border: 2px solid #e9ecef;
    border-radius: 15px;
    padding: 1.5rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
}

.option:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    border-color: #667eea;
}

.option.selected {
    border-color: #667eea;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    transform: translateY(-3px);
    box-shadow: 0 10px 30px rgba(102, 126, 234, 0.3);
}

.option-visual {
    margin-bottom: 1rem;
}

.layout-preview {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 60px;
    gap: 4px;
}

.horizontal-preview {
    flex-direction: row;
}

.vertical-preview {
    flex-direction: column;
    height: 80px;
}

.grid-preview {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    width: 60px;
    height: 60px;
    margin: 0 auto;
}

.preview-box {
    background: #667eea;
    border-radius: 4px;
    transition: all 0.3s ease;
}

.horizontal-preview .preview-box {
    width: 25px;
    height: 40px;
}

.vertical-preview .preview-box {
    width: 40px;
    height: 25px;
}

.grid-preview .preview-box {
    width: 100%;
    height: 100%;
}

.option.selected .preview-box {
    background: white;
}

.option h3 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.option p {
    font-size: 0.9rem;
    opacity: 0.8;
}

/* Grid Settings, Border Settings & Quality Settings */
.grid-settings, .border-settings, .quality-settings {
    background: #f8f9fa;
    padding: 1rem;
    border-radius: 10px;
    margin-bottom: 1.5rem;
}

.grid-settings {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.border-settings h4, .quality-settings h4 {
    margin-bottom: 1rem;
    color: #333;
    font-size: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.border-controls, .quality-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    align-items: center;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.control-group label {
    font-weight: 500;
    color: #333;
    font-size: 0.9rem;
}

.slider-container {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.slider-container input[type="range"] {
    flex: 1;
    height: 6px;
    border-radius: 3px;
    background: #ddd;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.slider-container input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #667eea;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

.slider-container input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #667eea;
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

#borderWidthValue, #qualityValue {
    background: #667eea;
    color: white;
    padding: 0.25rem 0.75rem;
    border-radius: 15px;
    font-size: 0.8rem;
    font-weight: 500;
    min-width: 45px;
    text-align: center;
}

.color-input-container {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.color-input-container input[type="color"] {
    width: 50px;
    height: 35px;
    border: 2px solid #ddd;
    border-radius: 8px;
    cursor: pointer;
    background: none;
    padding: 0;
}

.color-input-container input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
}

.color-input-container input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: 6px;
}

.color-preview {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 2px solid #ddd;
    background: var(--preview-color, #ffffff);
}

.grid-settings label {
    font-weight: 500;
    color: #333;
}

.grid-settings select, #outputFormat {
    padding: 0.5rem;
    border: 1px solid #ddd;
    border-radius: 5px;
    background: white;
    font-size: 0.9rem;
    cursor: pointer;
}

#outputFormat {
    width: 100%;
}

.quality-control {
    grid-column: 1 / -1;
}

.file-size-control {
    grid-column: 1 / -1;
    border-top: 1px solid #e0e0e0;
    padding-top: 1rem;
    margin-top: 1rem;
}

.file-size-control label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    cursor: pointer;
}

.file-size-control input[type="checkbox"] {
    transform: scale(1.2);
    accent-color: #667eea;
}

.file-size-container {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.size-presets {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-top: 0.5rem;
}

.preset-btn {
    background: #e9ecef;
    border: 1px solid #ced4da;
    border-radius: 6px;
    padding: 0.25rem 0.75rem;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s ease;
    color: #495057;
}

.preset-btn:hover {
    background: #667eea;
    color: white;
    border-color: #667eea;
}

.preset-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.quality-hint {
    color: #666;
    font-size: 0.8rem;
    margin-top: 0.25rem;
    font-style: italic;
}

/* Format-specific styling */
.quality-settings select option[value="png"] {
    color: #28a745;
}

.quality-settings select option[value="jpeg"] {
    color: #fd7e14;
}

.quality-settings select option[value="webp"] {
    color: #6f42c1;
}

/* Buttons */
.merge-btn, .download-btn, .reset-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 1rem 2rem;
    border-radius: 50px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.4, 0.0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-width: 180px;
    position: relative;
    overflow: hidden;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.merge-btn:before, .download-btn:before, .reset-btn:before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
    transition: left 0.5s;
}

.merge-btn:hover:before, .download-btn:hover:before, .reset-btn:hover:before {
    left: 100%;
}

.merge-btn:hover, .download-btn:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 8px 30px rgba(102, 126, 234, 0.5);
    background: linear-gradient(135deg, #7c8df0 0%, #8a5ab2 100%);
}

.merge-btn:active, .download-btn:active, .reset-btn:active {
    transform: translateY(-1px) scale(0.98);
    transition: all 0.1s ease;
}

.merge-btn:disabled {
    background: linear-gradient(135deg, #e9ecef 0%, #ced4da 100%);
    cursor: not-allowed;
    transform: none;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    color: #6c757d;
}

.merge-btn:disabled:hover {
    transform: none;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    background: linear-gradient(135deg, #e9ecef 0%, #ced4da 100%);
}

.reset-btn {
    background: linear-gradient(135deg, #6c757d 0%, #495057 100%);
    margin-left: 1rem;
    box-shadow: 0 4px 15px rgba(108, 117, 125, 0.3);
}

.reset-btn:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 8px 30px rgba(108, 117, 125, 0.5);
    background: linear-gradient(135deg, #7a8288 0%, #545b62 100%);
}

/* Loading */
.loading-step {
    text-align: center;
    padding: 4rem 0;
}

.loading-content h3 {
    margin: 2rem 0 1rem;
    font-size: 1.4rem;
    color: #333;
    animation: fadeIn 0.6s ease-in-out;
}

.loading-content p {
    color: #666;
    font-size: 1rem;
    animation: fadeIn 0.8s ease-in-out;
}

.spinner {
    width: 60px;
    height: 60px;
    border: 5px solid #f3f3f3;
    border-top: 5px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite, pulse 2s ease-in-out infinite;
    margin: 0 auto;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Result */
.result-container {
    text-align: center;
}

.result-image {
    background: #f8f9fa;
    border-radius: 15px;
    padding: 2rem;
    margin-bottom: 2rem;
    border: 2px solid #e9ecef;
}

#resultCanvas {
    max-width: 100%;
    height: auto;
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
}

.file-info {
    margin-top: 1rem;
    padding: 0.75rem;
    background: #f0f4ff;
    border-radius: 8px;
    text-align: center;
    font-size: 0.9rem;
    color: #667eea;
    font-weight: 500;
}

.result-actions {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

/* Footer */
.footer {
    text-align: center;
    margin-top: 2rem;
    color: white;
    opacity: 0.8;
    font-size: 0.9rem;
}

.designer-credit {
    margin-top: 0.5rem;
    font-size: 0.85rem;
    opacity: 0.7;
}

.designer-credit strong {
    color: #ffd700;
    font-weight: 600;
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(30px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes pulse {
    0%, 100% { 
        transform: scale(1); 
    }
    50% { 
        transform: scale(1.05); 
    }
}

.step {
    animation: fadeIn 0.6s cubic-bezier(0.4, 0.0, 0.2, 1);
}

.selected-images .image-item {
    animation: slideIn 0.4s cubic-bezier(0.4, 0.0, 0.2, 1);
}

.option.selected {
    animation: pulse 0.3s ease-in-out;
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 10px;
    }
    
    .header h1 {
        font-size: 2rem;
    }
    
    .main {
        padding: 1.5rem;
        border-radius: 15px;
    }
    
    .step-header {
        flex-direction: column;
        align-items: flex-start;
        text-align: left;
    }
    
    .step-header p {
        margin: 0.5rem 0 0 0;
    }
    
    .merge-options {
        grid-template-columns: 1fr;
    }
    
    .border-controls, .quality-controls {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .selected-images {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    }
    
    .upload-area {
        padding: 2rem 1rem;
    }
    
    .upload-content h3 {
        font-size: 1.1rem;
    }
    
    .result-actions {
        flex-direction: column;
    }
    
    .merge-btn, .download-btn, .reset-btn {
        width: 100%;
        margin: 0;
    }
    
    .reset-btn {
        margin-top: 0.5rem;
    }
}

@media (max-width: 480px) {
    .header h1 {
        font-size: 1.8rem;
    }
    
    .main {
        padding: 1rem;
    }
    
    .selected-images {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        gap: 0.5rem;
    }
    
    .option {
        padding: 1rem;
    }
    
    .layout-preview {
        height: 50px;
    }
    
    .vertical-preview {
        height: 60px;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    body {
        background: linear-gradient(135deg, #2d3748 0%, #4a5568 100%);
    }
    
    .main {
        background: #1a202c;
        color: #e2e8f0;
    }
    
    .step-header {
        border-bottom-color: #2d3748;
    }
    
    .step-header p {
        color: #a0aec0;
    }
    
    .upload-area {
        background: #2d3748;
        border-color: #4a5568;
        color: #e2e8f0;
    }
    
    .upload-area:hover {
        background: #374151;
        border-color: #667eea;
    }
    
    .option {
        background: #2d3748;
        border-color: #4a5568;
        color: #e2e8f0;
    }
    
    .grid-settings {
        background: #2d3748;
        color: #e2e8f0;
    }
    
    .result-image {
        background: #2d3748;
        border-color: #4a5568;
    }
}
