/* Reset and Base Styles */
* {
    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;
}

.app-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header Styles */
.app-header {
    text-align: center;
    margin-bottom: 40px;
    color: white;
}

.app-header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 10px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.app-header p {
    font-size: 1.1rem;
    opacity: 0.9;
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 30px;
}

/* Upload Section */
.upload-section {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 400px;
}

.upload-area {
    background: rgba(255, 255, 255, 0.95);
    border: 3px dashed #ccc;
    border-radius: 20px;
    padding: 60px 40px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    max-width: 500px;
    width: 100%;
    margin: 0 auto; /* Ensure centering */
}

.upload-area:hover {
    border-color: #667eea;
    background: rgba(255, 255, 255, 1);
    transform: translateY(-2px);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
}

.upload-area.drag-over {
    border-color: #667eea;
    background: rgba(102, 126, 234, 0.1);
    transform: scale(1.02);
}

.upload-content .upload-icon {
    font-size: 4rem;
    margin-bottom: 20px;
    display: block;
}

.upload-content h2 {
    font-size: 1.5rem;
    margin-bottom: 10px;
    color: #333;
}

.upload-content p {
    color: #666;
    margin-bottom: 30px;
    font-size: 1rem;
}

.upload-button {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 15px 30px;
    border-radius: 50px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.upload-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

/* Preview Section */
.preview-section {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 20px;
    padding: 30px;
    text-align: center;
}

.preview-section h2 {
    margin-bottom: 20px;
    color: #333;
}

.preview-canvas-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 300px;
    background: #f8f9fa;
    border-radius: 10px;
    padding: 20px;
}

#previewCanvas {
    max-width: 100%;
    max-height: 500px;
    border-radius: 10px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
}

/* Controls Section */
.controls-section {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 20px;
    padding: 30px;
}

.gradient-controls {
    margin-bottom: 30px;
}

.gradient-controls h3 {
    margin-bottom: 20px;
    color: #333;
    text-align: center;
}

.gradient-options {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 15px;
    margin-bottom: 20px;
}

.gradient-option {
    height: 80px;
    border: 3px solid transparent;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.gradient-option:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

.gradient-option.active {
    border-color: #667eea;
    transform: scale(1.05);
}

/* Removed gradient text overlay - showing only gradient preview */

/* Action Controls */
.action-controls {
    display: flex;
    gap: 15px;
    justify-content: center;
    flex-wrap: wrap;
}

.download-button,
.reset-button {
    padding: 15px 30px;
    border: none;
    border-radius: 50px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 10px;
}

.download-button {
    background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
    color: white;
}

.download-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(40, 167, 69, 0.4);
}

.reset-button {
    background: linear-gradient(135deg, #6c757d 0%, #495057 100%);
    color: white;
}

.reset-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(108, 117, 125, 0.4);
}

/* Enhanced Error Message System */
.error-message {
    position: fixed;
    top: 20px;
    right: 20px;
    background: #dc3545;
    color: white;
    padding: 15px 20px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 5px 15px rgba(220, 53, 69, 0.3);
    z-index: 1000;
    max-width: 400px;
    transition: all 0.3s ease;
    transform: translateY(0);
    opacity: 1;
}

/* Error type variations */
.error-message.error-upload {
    background: #fd7e14;
    box-shadow: 0 5px 15px rgba(253, 126, 20, 0.3);
}

.error-message.error-processing {
    background: #6f42c1;
    box-shadow: 0 5px 15px rgba(111, 66, 193, 0.3);
}

.error-message.error-validation {
    background: #ffc107;
    color: #212529;
    box-shadow: 0 5px 15px rgba(255, 193, 7, 0.3);
}

.error-message.error-network {
    background: #dc3545;
    border-left: 4px solid #721c24;
}

.error-message.error-clipboard {
    background: #17a2b8;
    box-shadow: 0 5px 15px rgba(23, 162, 184, 0.3);
}

.error-retry {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 5px 10px;
    border-radius: 5px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 5px;
}

.error-retry:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-1px);
}

.error-close {
    background: none;
    border: none;
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
    margin-left: auto;
    padding: 5px;
    border-radius: 3px;
    transition: background-color 0.2s ease;
}

.error-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Error animation states */
.error-message.error-entering {
    opacity: 0;
    transform: translateY(-20px);
}

.error-message.error-leaving {
    opacity: 0;
    transform: translateY(-20px);
}

/* Enhanced Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    color: white;
    transition: opacity 0.3s ease;
}

.loading-spinner {
    width: 60px;
    height: 60px;
    border: 4px solid rgba(255, 255, 255, 0.2);
    border-top: 4px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 25px;
}

.loading-overlay p {
    font-size: 1.1rem;
    margin-bottom: 20px;
    text-align: center;
    max-width: 300px;
}

/* Loading Progress Bar */
.loading-progress {
    width: 250px;
    margin: 15px 0;
}

.loading-progress-bar {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
    overflow: hidden;
}

.loading-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #667eea, #764ba2);
    border-radius: 3px;
    transition: width 0.3s ease;
    width: 0%;
}

/* Loading Cancel Button */
.loading-cancel {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-top: 15px;
}

.loading-cancel:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-1px);
}

/* Success Message System */
.success-message {
    position: fixed;
    background: #28a745;
    color: white;
    padding: 12px 20px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 4px 12px rgba(40, 167, 69, 0.3);
    z-index: 1500;
    opacity: 0;
    transform: translateY(-20px);
    transition: all 0.3s ease;
    font-size: 0.9rem;
}

.success-message.success-top-right {
    top: 20px;
    right: 20px;
}

.success-message.success-top-center {
    top: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(-20px);
}

.success-message.success-bottom-right {
    bottom: 20px;
    right: 20px;
    transform: translateY(20px);
}

.success-icon {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: bold;
}

.success-text {
    font-weight: 500;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* Enhanced loading animations */
@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

.loading-overlay .loading-spinner {
    animation: spin 1s linear infinite, pulse 2s ease-in-out infinite;
}

/* Loading state for different operations */
.loading-overlay.upload-loading .loading-spinner {
    border-top-color: #fd7e14;
}

.loading-overlay.processing-loading .loading-spinner {
    border-top-color: #6f42c1;
}

.loading-overlay.download-loading .loading-spinner {
    border-top-color: #28a745;
}

/* Mobile-specific loading optimizations */
@media (max-width: 768px) {
    .loading-overlay {
        padding: 20px;
    }

    .loading-spinner {
        width: 50px;
        height: 50px;
        margin-bottom: 20px;
    }

    .loading-overlay p {
        font-size: 1rem;
        max-width: 250px;
    }

    .loading-progress {
        width: 200px;
    }

    .loading-cancel {
        padding: 10px 20px;
        font-size: 0.9rem;
        min-height: 44px;
        /* Touch-friendly */
    }

    .success-message {
        left: 10px;
        right: 10px;
        max-width: none;
        font-size: 0.85rem;
    }

    .success-message.success-top-center {
        left: 10px;
        right: 10px;
        transform: translateY(-20px);
    }
}

@media (max-width: 480px) {
    .loading-overlay p {
        font-size: 0.9rem;
        max-width: 200px;
    }

    .loading-progress {
        width: 180px;
    }

    .loading-progress-bar {
        height: 4px;
    }

    .success-message {
        padding: 10px 15px;
        font-size: 0.8rem;
    }

    .success-icon {
        width: 18px;
        height: 18px;
        font-size: 0.7rem;
    }
}

/* Reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
    .loading-spinner {
        animation: spin 2s linear infinite;
    }

    .loading-overlay,
    .success-message,
    .error-message {
        transition: none;
    }

    .loading-progress-fill {
        transition: width 0.1s ease;
    }
}

/* Enhanced Responsive Design */

/* Tablet styles */
@media (max-width: 1024px) {
    .app-container {
        padding: 15px;
    }

    .preview-canvas-container {
        min-height: 250px;
    }

    #previewCanvas {
        max-height: 400px;
    }
}

/* Mobile landscape and small tablet */
@media (max-width: 768px) {
    .app-container {
        padding: 15px;
    }

    .app-header {
        margin-bottom: 30px;
    }

    .app-header h1 {
        font-size: 2rem;
    }

    .app-header p {
        font-size: 1rem;
    }

    .main-content {
        gap: 20px;
    }

    .upload-area {
        padding: 40px 20px;
        max-width: 90%;
        margin: 0 auto; /* Maintain centering on mobile */
    }

    .upload-content h2 {
        font-size: 1.4rem;
    }

    .upload-content p {
        font-size: 0.9rem;
    }

    .preview-section,
    .controls-section {
        padding: 20px;
        margin: 0 10px;
    }

    .preview-canvas-container {
        min-height: 200px;
        padding: 15px;
    }

    #previewCanvas {
        max-height: 300px;
    }

    .gradient-options {
        grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
        gap: 10px;
    }

    .gradient-option {
        height: 70px;
    }

    /* Removed gradient text overlay for mobile */

    .action-controls {
        flex-direction: column;
        align-items: center;
        gap: 10px;
    }

    .download-button,
    .reset-button {
        width: 100%;
        max-width: 300px;
        padding: 12px 25px;
    }

    /* Touch-friendly error message */
    .error-message {
        position: fixed;
        top: 10px;
        left: 10px;
        right: 10px;
        max-width: none;
        font-size: 0.9rem;
    }

    .error-close {
        font-size: 1.5rem;
        padding: 5px;
        min-width: 30px;
        min-height: 30px;
    }
}

/* Mobile portrait */
@media (max-width: 480px) {
    .app-container {
        padding: 10px;
    }

    .app-header {
        margin-bottom: 20px;
    }

    .app-header h1 {
        font-size: 1.8rem;
    }

    .app-header p {
        font-size: 0.9rem;
    }

    .main-content {
        gap: 15px;
    }

    .upload-area {
        padding: 30px 15px;
        border-radius: 15px;
        max-width: 95%;
        margin: 0 auto; /* Maintain centering on small mobile */
    }

    .upload-content .upload-icon {
        font-size: 3rem;
    }

    .upload-content h2 {
        font-size: 1.3rem;
        margin-bottom: 8px;
    }

    .upload-content p {
        font-size: 0.85rem;
        margin-bottom: 20px;
    }

    .upload-button {
        padding: 12px 25px;
        font-size: 0.9rem;
    }

    .preview-section,
    .controls-section {
        padding: 15px;
        margin: 0 5px;
        border-radius: 15px;
    }

    .preview-section h2,
    .gradient-controls h3 {
        font-size: 1.2rem;
        margin-bottom: 15px;
    }

    .preview-canvas-container {
        min-height: 150px;
        padding: 10px;
    }

    #previewCanvas {
        max-height: 250px;
    }

    .gradient-options {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }

    .gradient-option {
        height: 60px;
        border-radius: 8px;
    }

    /* Removed gradient text overlay for small screens */

    .action-controls {
        gap: 8px;
    }

    .download-button,
    .reset-button {
        padding: 10px 20px;
        font-size: 0.9rem;
        border-radius: 25px;
    }

    /* Mobile loading overlay */
    .loading-overlay {
        padding: 20px;
    }

    .loading-overlay p {
        font-size: 0.9rem;
        text-align: center;
    }
}

/* Very small screens */
@media (max-width: 320px) {
    .app-header h1 {
        font-size: 1.6rem;
    }

    .upload-area {
        padding: 25px 10px;
    }

    .upload-content .upload-icon {
        font-size: 2.5rem;
    }

    .upload-content h2 {
        font-size: 1.2rem;
    }

    .gradient-options {
        grid-template-columns: 1fr 1fr;
    }

    .gradient-option {
        height: 50px;
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {

    /* Remove hover effects on touch devices */
    .upload-area:hover {
        transform: none;
        box-shadow: none;
        border-color: #ccc;
        background: rgba(255, 255, 255, 0.95);
    }

    .upload-button:hover,
    .download-button:hover,
    .reset-button:hover {
        transform: none;
        box-shadow: none;
    }

    .gradient-option:hover {
        transform: none;
        box-shadow: none;
    }

    /* Increase touch targets */
    .gradient-option {
        min-height: 60px;
    }

    .upload-button,
    .download-button,
    .reset-button {
        min-height: 48px;
        padding: 15px 30px;
    }

    .error-close {
        min-width: 44px;
        min-height: 44px;
    }

    /* Add active states for touch feedback */
    .upload-button:active,
    .download-button:active,
    .reset-button:active {
        transform: scale(0.98);
        opacity: 0.8;
    }

    .gradient-option:active {
        transform: scale(0.95);
        opacity: 0.8;
    }
}

/* Sta
te-specific styling */
.app-container.state-upload {
    /* Upload state specific styles */
}

.app-container.state-processing {
    /* Processing state specific styles */
    pointer-events: none;
    /* Prevent interactions during processing */
}

.app-container.state-processing .main-content {
    opacity: 0.7;
    transition: opacity 0.3s ease;
}

.app-container.state-preview {
    /* Preview state specific styles */
}

.app-container.state-error {
    /* Error state specific styles */
}

.app-container.state-error .error-message {
    animation: errorPulse 0.5s ease-in-out;
}

@keyframes errorPulse {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.05);
    }

    100% {
        transform: scale(1);
    }
}

/* Enhanced transitions for state changes */
.upload-section,
.preview-section,
.controls-section {
    transition: opacity 0.3s ease, transform 0.3s ease;
}

/* Loading state enhancements */
.app-container.state-processing .loading-overlay {
    backdrop-filter: blur(5px);
}

/* Touch-sp
ecific upload area styles */
.upload-area.touch-device {
    /* Enhanced touch target */
    min-height: 120px;
}

.upload-area.touch-active {
    background: rgba(102, 126, 234, 0.1);
    border-color: #667eea;
    transform: scale(1.02);
}

.upload-area.touch-over {
    background: rgba(102, 126, 234, 0.2);
    border-color: #667eea;
}

/* Touch feedback for gradient options */
.gradient-option.touch-active {
    transform: scale(0.95);
    opacity: 0.8;
}

/* Enhanced touch targets for mobile */
@media (max-width: 768px) {
    .upload-area.touch-device {
        min-height: 140px;
        padding: 50px 20px;
    }

    .upload-button {
        min-height: 48px;
        min-width: 120px;
    }

    .gradient-option {
        min-height: 60px;
        min-width: 60px;
    }

    .download-button,
    .reset-button {
        min-height: 48px;
        min-width: 120px;
    }
}

/* Mobi
le device optimizations */
.mobile-device .app-container {
    /* Use actual viewport height instead of 100vh */
    min-height: calc(var(--vh, 1vh) * 100);
}

.mobile-device.landscape .app-container {
    padding: 10px;
}

.mobile-device.landscape .app-header {
    margin-bottom: 15px;
}

.mobile-device.landscape .app-header h1 {
    font-size: 1.8rem;
}

.mobile-device.landscape .main-content {
    gap: 15px;
}

.mobile-device.landscape .upload-area {
    padding: 30px 20px;
}

.mobile-device.landscape .preview-canvas-container {
    min-height: 200px;
}

.mobile-device.landscape #previewCanvas {
    max-height: 250px;
}

/* Prevent text selection on touch elements */
.mobile-device .gradient-option,
.mobile-device .upload-button,
.mobile-device .download-button,
.mobile-device .reset-button {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

/* Improve touch scrolling */
.mobile-device .main-content {
    -webkit-overflow-scrolling: touch;
    overflow-y: auto;
}

/* Fix for iOS Safari bottom bar */
@supports (-webkit-touch-callout: none) {
    .mobile-device .app-container {
        min-height: -webkit-fill-available;
    }
}

/* Accessibility improvements for mobile */
@media (max-width: 768px) {

    /* Larger touch targets */
    .gradient-option {
        min-height: 60px;
        min-width: 60px;
    }

    .upload-button,
    .download-button,
    .reset-button {
        min-height: 48px;
        min-width: 120px;
        font-size: 16px;
        /* Prevent zoom on iOS */
    }

    /* Better contrast for mobile */
    .upload-content p {
        color: #555;
    }

    .gradient-controls h3 {
        color: #222;
    }
}