:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #818cf8;
    --secondary: #8b5cf6;
    --background: #0f172a;
    --surface: #1e293b;
    --surface-hover: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --border: #334155;
    --success: #10b981;
    --error: #ef4444;
    --shadow: rgba(0, 0, 0, 0.3);
    --gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --gradient-alt: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Splash Screen */
.splash-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    animation: fadeIn 0.3s ease;
}

.splash-content {
    text-align: center;
    animation: slideUp 0.6s ease;
}

.logo-container {
    margin-bottom: 2rem;
    animation: pulse 2s ease-in-out infinite;
}

.logo {
    width: 100px;
    height: 100px;
    filter: drop-shadow(0 10px 30px rgba(0, 0, 0, 0.3));
}

.splash-title {
    font-size: 2.5rem;
    font-weight: 700;
    color: white;
    margin-bottom: 0.5rem;
    letter-spacing: -0.02em;
}

.splash-subtitle {
    font-size: 1rem;
    color: rgba(255, 255, 255, 0.9);
    margin-bottom: 2rem;
}

.loader {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    margin: 0 auto;
    animation: spin 0.8s linear infinite;
}

/* Auth Screen */
.auth-container {
    max-width: 400px;
    margin: 0 auto;
    padding: 2rem;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    animation: fadeIn 0.5s ease;
}

.auth-header {
    text-align: center;
    margin-bottom: 2rem;
}

.auth-logo {
    width: 80px;
    height: 80px;
    margin-bottom: 1.5rem;
    filter: drop-shadow(0 4px 12px rgba(102, 126, 234, 0.4));
}

.auth-title {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    background: var(--gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.auth-subtitle {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.auth-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 2rem;
    background: var(--surface);
    padding: 0.25rem;
    border-radius: 12px;
}

.auth-tab {
    flex: 1;
    padding: 0.75rem;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.95rem;
    font-weight: 500;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.auth-tab.active {
    background: var(--gradient);
    color: white;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.auth-form {
    animation: fadeIn 0.3s ease;
}

.input-group {
    margin-bottom: 1.5rem;
}

.input-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-primary);
}

.input-group input {
    width: 100%;
    padding: 0.875rem 1rem;
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: 12px;
    color: var(--text-primary);
    font-size: 1rem;
    transition: all 0.3s ease;
}

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

/* Buttons */
.btn {
    padding: 0.875rem 1.5rem;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
}

.btn svg {
    width: 20px;
    height: 20px;
}

.btn-primary {
    background: var(--gradient);
    color: white;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background: var(--surface);
    color: var(--text-primary);
    border: 2px solid var(--border);
}

.btn-secondary:hover {
    background: var(--surface-hover);
    border-color: var(--primary);
}

.btn-outline {
    background: transparent;
    color: var(--text-primary);
    border: 2px solid var(--border);
}

.btn-outline:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.btn-large {
    padding: 1rem 2rem;
    font-size: 1.1rem;
}

.btn-full {
    width: 100%;
}

/* App Screen */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(10px);
}

.header-title {
    font-size: 1.5rem;
    font-weight: 700;
    background: var(--gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.icon-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: var(--background);
    color: var(--text-primary);
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.icon-btn:hover {
    background: var(--primary);
    color: white;
}

.icon-btn svg {
    width: 22px;
    height: 22px;
}

/* Main Content */
.app-main {
    padding: 2rem 1.5rem;
    max-width: 1200px;
    margin: 0 auto;
}

.section {
    margin-bottom: 3rem;
}

.section-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
    color: var(--text-primary);
}

/* Upload Section */
.upload-container {
    text-align: center;
    padding: 3rem 2rem;
    background: var(--surface);
    border-radius: 20px;
    border: 2px dashed var(--border);
    transition: all 0.3s ease;
}

.upload-container:hover {
    border-color: var(--primary);
    background: var(--surface-hover);
}

.upload-icon {
    width: 80px;
    height: 80px;
    margin: 0 auto 1.5rem;
    background: var(--gradient);
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: float 3s ease-in-out infinite;
}

.upload-icon svg {
    width: 40px;
    height: 40px;
    color: white;
}

.upload-title {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.upload-description {
    color: var(--text-secondary);
    margin-bottom: 2rem;
}

/* Processing Section */
.processing-container {
    background: var(--surface);
    border-radius: 20px;
    padding: 2rem;
    animation: fadeIn 0.5s ease;
}

.image-preview-wrapper {
    position: relative;
    margin-bottom: 2rem;
    border-radius: 16px;
    overflow: hidden;
    background: repeating-conic-gradient(#1e293b 0% 25%, #334155 0% 50%) 50% / 20px 20px;
    min-height: 300px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#preview-canvas {
    max-width: 100%;
    max-height: 60vh;
    display: block;
    margin: 0 auto;
    border-radius: 12px;
}

.controls {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.controls .btn {
    flex: 1;
    min-width: 150px;
}

.processing-status {
    text-align: center;
    padding: 2rem;
    background: var(--background);
    border-radius: 12px;
    animation: fadeIn 0.3s ease;
}

.status-loader {
    width: 50px;
    height: 50px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    margin: 0 auto 1rem;
    animation: spin 0.8s linear infinite;
}

.status-text {
    color: var(--text-secondary);
    font-weight: 500;
}

/* History */
.history-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 1rem;
}

.history-item {
    aspect-ratio: 1;
    border-radius: 12px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    background: var(--surface);
}

.history-item:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px var(--shadow);
}

.history-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.history-item-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 0.5rem;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.8), transparent);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.history-item:hover .history-item-overlay {
    opacity: 1;
}

.history-item-date {
    font-size: 0.75rem;
    color: white;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(4px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s ease;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--surface);
    border-radius: 20px;
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    animation: slideUp 0.3s ease;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.5rem;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    font-size: 1.25rem;
    font-weight: 600;
}

.modal-close {
    width: 32px;
    height: 32px;
    border: none;
    background: var(--background);
    color: var(--text-primary);
    border-radius: 8px;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    transition: all 0.3s ease;
}

.modal-close:hover {
    background: var(--primary);
    color: white;
}

.modal-body {
    padding: 1.5rem;
}

/* Profile */
.profile-info {
    text-align: center;
    margin-bottom: 2rem;
}

.profile-avatar {
    width: 80px;
    height: 80px;
    margin: 0 auto 1rem;
    background: var(--gradient);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

.profile-avatar svg {
    width: 50px;
    height: 50px;
}

.profile-name {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.profile-email {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.profile-stats {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat {
    text-align: center;
    padding: 1.5rem;
    background: var(--background);
    border-radius: 12px;
}

.stat-value {
    display: block;
    font-size: 2rem;
    font-weight: 700;
    background: var(--gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 0.25rem;
}

.stat-label {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

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

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

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

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}

@keyframes float {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-10px);
    }
}

/* Editor Toolbar */
.editor-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    padding: 1rem;
    background: var(--background);
    border-radius: 12px;
    margin-bottom: 1.5rem;
    align-items: center;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem;
    background: var(--surface);
    border-radius: 10px;
}

.tool-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    color: var(--text-primary);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    position: relative;
}

.tool-btn svg {
    width: 20px;
    height: 20px;
}

.tool-btn:hover {
    background: var(--surface-hover);
}

.tool-btn.active {
    background: var(--primary);
    color: white;
}

.tool-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.tool-btn-primary {
    background: var(--gradient);
    color: white;
}

.tool-btn-primary:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

.tool-separator {
    width: 1px;
    height: 30px;
    background: var(--border);
}

.tool-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.zoom-level {
    min-width: 50px;
    text-align: center;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
}

.slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100px;
    height: 6px;
    border-radius: 3px;
    background: var(--border);
    outline: none;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--gradient);
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.4);
}

.slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--gradient);
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.4);
}

/* Progress Bar */
.progress-bar-container {
    width: 100%;
    height: 8px;
    background: var(--border);
    border-radius: 4px;
    overflow: hidden;
    margin: 1rem 0 0.5rem;
}

.progress-bar {
    height: 100%;
    background: var(--gradient);
    transition: width 0.3s ease;
    border-radius: 4px;
}

.progress-percent {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-top: 0.5rem;
}

/* Background Controls */
.bg-controls {
    margin-top: 2rem;
    padding: 1.5rem;
    background: var(--background);
    border-radius: 12px;
}

.controls-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 1rem;
}

.bg-buttons {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 0.75rem;
}

.bg-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem;
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.bg-btn:hover {
    border-color: var(--primary);
    background: var(--surface-hover);
    color: var(--text-primary);
}

.bg-preview {
    width: 50px;
    height: 50px;
    border-radius: 8px;
    border: 2px solid var(--border);
}

.bg-transparent {
    background:
        repeating-conic-gradient(#1e293b 0% 25%, #334155 0% 50%) 50% / 10px 10px;
}

/* Settings Modal */
.setting-item {
    margin-bottom: 2rem;
}

.setting-label {
    display: block;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.75rem;
}

.setting-hint {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 0.5rem;
}

.setting-item .slider {
    width: 100%;
}

/* Export Modal */
.export-format-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.export-format-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1rem;
    background: var(--background);
    border: 2px solid var(--border);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    color: var(--text-primary);
}

.export-format-btn:hover {
    border-color: var(--primary);
    background: var(--surface);
}

.export-format-btn.active {
    border-color: var(--primary);
    background: var(--primary);
    color: white;
}

.export-format-btn strong {
    font-size: 1.1rem;
    margin-bottom: 0.25rem;
}

.export-format-btn small {
    font-size: 0.75rem;
    opacity: 0.8;
}

/* Canvas Enhancements */
#preview-canvas {
    transition: transform 0.2s ease;
    transform-origin: center center;
}

.image-preview-wrapper {
    touch-action: none;
    user-select: none;
}

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

    .controls {
        flex-direction: column;
    }

    .controls .btn {
        width: 100%;
    }

    .history-list {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    }

    .editor-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .toolbar-group {
        justify-content: space-between;
    }

    .slider {
        flex: 1;
    }

    .bg-buttons {
        grid-template-columns: repeat(2, 1fr);
    }

    .export-format-grid {
        grid-template-columns: 1fr;
    }
}

/* Utility classes */
.screen {
    min-height: 100vh;
}

.hidden {
    display: none !important;
}
