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

:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --secondary-color: #8b5cf6;
    --background: #0f172a;
    --surface: #1e293b;
    --surface-light: #334155;
    --text-primary: #f8fafc;
    --text-secondary: #cbd5e1;
    --success: #10b981;
    --error: #ef4444;
    --border: #475569;
    --shadow: rgba(0, 0, 0, 0.3);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, var(--background) 0%, #1e1b4b 100%);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
}

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

/* Header */
.header {
    text-align: center;
    margin-bottom: 2rem;
    animation: fadeInDown 0.6s ease-out;
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 1rem;
}

.logo-icon {
    width: 40px;
    height: 40px;
    color: var(--primary-color);
    filter: drop-shadow(0 0 20px rgba(99, 102, 241, 0.5));
}

.header h1 {
    font-size: 2rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.tagline {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

/* Main Content */
.main-content {
    animation: fadeInUp 0.6s ease-out;
}

/* Upload Section */
.upload-section {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.upload-card {
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: 16px;
    padding: 1.5rem;
    text-align: center;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.upload-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.upload-card:hover {
    border-color: var(--primary-color);
    transform: translateY(-5px);
    box-shadow: 0 10px 40px var(--shadow);
}

.upload-card:hover::before {
    opacity: 1;
}

.upload-icon {
    width: 48px;
    height: 48px;
    margin: 0 auto 0.75rem;
    color: var(--primary-color);
}

.upload-icon svg {
    width: 100%;
    height: 100%;
}

.upload-card h2 {
    font-size: 1.25rem;
    margin-bottom: 0.25rem;
    color: var(--text-primary);
}

.upload-card p {
    color: var(--text-secondary);
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.upload-button {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.875rem 1.5rem;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
}

.upload-button:hover {
    transform: scale(1.05);
    box-shadow: 0 8px 25px rgba(99, 102, 241, 0.4);
}

.upload-button svg {
    width: 20px;
    height: 20px;
}

/* Prompt Section */
.prompt-section {
    max-width: 800px;
    margin: 0 auto 1.5rem;
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: 16px;
    padding: 1.5rem;
    transition: all 0.3s ease;
}

.prompt-section:focus-within {
    border-color: var(--primary-color);
    box-shadow: 0 10px 40px var(--shadow);
}

.prompt-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: var(--text-primary);
}

.prompt-label svg {
    width: 20px;
    height: 20px;
    color: var(--primary-color);
}

.prompt-input {
    width: 100%;
    padding: 0.875rem;
    background: var(--surface-light);
    border: 2px solid var(--border);
    border-radius: 12px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.95rem;
    line-height: 1.5;
    resize: vertical;
    transition: all 0.3s ease;
}

.prompt-input:focus {
    outline: none;
    border-color: var(--primary-color);
    background: var(--surface);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.prompt-input::placeholder {
    color: var(--text-secondary);
    opacity: 0.7;
}

/* Preview */
.preview {
    margin-top: 1rem;
    min-height: 150px;
    border-radius: 12px;
    overflow: hidden;
    background: var(--surface-light);
    display: flex;
    align-items: center;
    justify-content: center;
}

.preview img {
    max-width: 100%;
    max-height: 200px;
    object-fit: contain;
    border-radius: 8px;
}

.preview.empty::after {
    content: 'Nessuna immagine caricata';
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* Generate Button */
.generate-button {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    width: 100%;
    max-width: 450px;
    margin: 0 auto 2rem;
    padding: 1rem 1.75rem;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: white;
    border: none;
    border-radius: 14px;
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 10px 40px rgba(99, 102, 241, 0.3);
}

.generate-button:not(:disabled):hover {
    transform: translateY(-3px);
    box-shadow: 0 15px 50px rgba(99, 102, 241, 0.5);
}

.generate-button:disabled {
    background: var(--surface-light);
    cursor: not-allowed;
    box-shadow: none;
    opacity: 0.5;
}

.generate-button svg {
    width: 24px;
    height: 24px;
}

/* Result Section */
.result-section {
    margin-top: 2rem;
    text-align: center;
    animation: fadeInUp 0.6s ease-out;
}

.result-section h2 {
    font-size: 1.75rem;
    margin-bottom: 1.5rem;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.result-container {
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: 16px;
    padding: 1.5rem;
    max-width: 800px;
    margin: 0 auto;
}

.result-image-wrapper {
    position: relative;
}

.result-image-wrapper img {
    width: 100%;
    max-height: 500px;
    object-fit: contain;
    border-radius: 12px;
    margin-bottom: 1.25rem;
}

.result-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

.download-button,
.reset-button {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.875rem 1.5rem;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.download-button {
    background: linear-gradient(135deg, var(--success) 0%, #059669 100%);
    color: white;
}

.download-button:hover {
    transform: scale(1.05);
    box-shadow: 0 8px 25px rgba(16, 185, 129, 0.4);
}

.reset-button {
    background: var(--surface-light);
    color: var(--text-primary);
    border: 2px solid var(--border);
}

.reset-button:hover {
    background: var(--surface);
    border-color: var(--primary-color);
}

.download-button svg,
.reset-button svg {
    width: 20px;
    height: 20px;
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(8px);
}

.loading-content {
    text-align: center;
    padding: 2rem;
}

.spinner {
    width: 64px;
    height: 64px;
    margin: 0 auto 1.5rem;
    border: 4px solid var(--surface-light);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.loading-content p {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.loading-subtext {
    color: var(--text-secondary);
    font-size: 1rem;
    font-weight: 400;
}

/* Error Message */
.error-message {
    max-width: 600px;
    margin: 2rem auto;
    padding: 1rem 1.5rem;
    background: rgba(239, 68, 68, 0.1);
    border: 2px solid var(--error);
    border-radius: 12px;
    color: var(--error);
    text-align: center;
    font-weight: 600;
    animation: shake 0.5s ease-out;
}

/* Footer */
.footer {
    text-align: center;
    margin-top: 3rem;
    padding: 1.5rem 0;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

/* Animations */
@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
    20%, 40%, 60%, 80% { transform: translateX(5px); }
}

/* Responsive */
@media (max-width: 768px) {
    .container {
        padding: 1rem;
    }

    .header h1 {
        font-size: 2rem;
    }

    .upload-section {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }

    .generate-button {
        font-size: 1rem;
        padding: 1rem 1.5rem;
    }

    .result-actions {
        flex-direction: column;
    }

    .download-button,
    .reset-button {
        width: 100%;
    }
}
