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

:root {
    --primary-color: #6366f1;
    --secondary-color: #8b5cf6;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --error-color: #ef4444;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    --white: #ffffff;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.6;
    color: var(--gray-700);
    min-height: 100vh;
}

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

/* Header */
header {
    text-align: center;
    padding: 2rem 0;
    background: var(--white);
    margin-bottom: 2rem;
    border-radius: 12px;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
}

header h1 i {
    margin-right: 0.5rem;
}

header p {
    color: var(--gray-600);
    font-size: 1.1rem;
}

/* Upload Section */
.upload-section {
    background: var(--white);
    border-radius: 12px;
    padding: 2rem;
    margin-bottom: 2rem;
}

.upload-area {
    border: 2px dashed var(--gray-300);
    border-radius: 8px;
    padding: 3rem 2rem;
    text-align: center;
    transition: all 0.3s ease;
    cursor: pointer;
}

.upload-area:hover {
    border-color: var(--primary-color);
    background: var(--gray-50);
}

.upload-area.drag-over {
    border-color: var(--primary-color);
    background: var(--primary-color);
    background-opacity: 0.1;
}

.upload-content i {
    font-size: 3rem;
    color: var(--primary-color);
    margin-bottom: 1rem;
}

.upload-content h3 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
    color: var(--gray-700);
}

.upload-content p {
    color: var(--gray-600);
    margin-bottom: 0.5rem;
}

.browse-link {
    color: var(--primary-color);
    text-decoration: underline;
    cursor: pointer;
}

.file-info {
    font-size: 0.9rem;
    color: var(--gray-400);
}

.upload-progress {
    display: none;
    margin-top: 1rem;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: var(--gray-200);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 0.5rem;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
    transition: width 0.3s ease;
    width: 0%;
}

.progress-text {
    font-size: 0.9rem;
    color: var(--gray-600);
}

/* Editor Section */
.editor-section {
    background: var(--white);
    border-radius: 12px;
    padding: 2rem;
    margin-bottom: 2rem;
}

.editor-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.control-group {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

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

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

.btn-primary:hover:not(:disabled) {
    background: var(--secondary-color);
}

.btn-secondary {
    background: var(--gray-200);
    color: var(--gray-700);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--gray-300);
}

.btn-success {
    background: var(--success-color);
    color: var(--white);
}

.btn-success:hover:not(:disabled) {
    background: #059669;
}

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

.btn-outline:hover:not(:disabled) {
    background: var(--primary-color);
    color: var(--white);
}

.aspect-ratio-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    user-select: none;
}

.aspect-ratio-toggle input {
    margin: 0;
}

/* Editor Workspace */
.editor-workspace {
    margin-bottom: 2rem;
}

.canvas-container {
    position: relative;
    display: flex;
    justify-content: center;
    background: var(--gray-100);
    border-radius: 8px;
    overflow: hidden;
    min-height: 400px;
}

#mainCanvas, #previewCanvas {
    max-width: 100%;
    max-height: 600px;
    border-radius: 8px;
}

#previewCanvas {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
    opacity: 0.8;
}

/* Crop Overlay */
.crop-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.crop-selection {
    position: absolute;
    border: 2px solid var(--primary-color);
    background: rgba(99, 102, 241, 0.1);
    cursor: move;
    pointer-events: all;
}

.crop-handle {
    position: absolute;
    width: 10px;
    height: 10px;
    background: var(--primary-color);
    border: 2px solid var(--white);
    border-radius: 50%;
    cursor: pointer;
}

.crop-handle.top-left { top: -5px; left: -5px; cursor: nw-resize; }
.crop-handle.top-right { top: -5px; right: -5px; cursor: ne-resize; }
.crop-handle.bottom-left { bottom: -5px; left: -5px; cursor: sw-resize; }
.crop-handle.bottom-right { bottom: -5px; right: -5px; cursor: se-resize; }
.crop-handle.top { top: -5px; left: 50%; transform: translateX(-50%); cursor: n-resize; }
.crop-handle.bottom { bottom: -5px; left: 50%; transform: translateX(-50%); cursor: s-resize; }
.crop-handle.left { left: -5px; top: 50%; transform: translateY(-50%); cursor: w-resize; }
.crop-handle.right { right: -5px; top: 50%; transform: translateY(-50%); cursor: e-resize; }

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

/* Loading Section */
.loading-section {
    background: var(--white);
    border-radius: 12px;
    padding: 3rem 2rem;
    text-align: center;
    margin-bottom: 2rem;
}

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

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Error Section */
.error-section {
    background: var(--white);
    border-radius: 12px;
    padding: 3rem 2rem;
    text-align: center;
    margin-bottom: 2rem;
}

.error-content i {
    font-size: 3rem;
    color: var(--error-color);
    margin-bottom: 1rem;
}

.error-content h3 {
    font-size: 1.5rem;
    margin-bottom: 1rem;
    color: var(--gray-700);
}

.error-content p {
    color: var(--gray-600);
    margin-bottom: 2rem;
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
}

.toast {
    background: var(--white);
    border-radius: 8px;
    padding: 1rem 1.5rem;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 300px;
    animation: slideIn 0.3s ease;
}

.toast.success {
    border-left: 4px solid var(--success-color);
}

.toast.error {
    border-left: 4px solid var(--error-color);
}

.toast.warning {
    border-left: 4px solid var(--warning-color);
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Footer */
footer {
    text-align: center;
    padding: 2rem 0;
    color: var(--gray-600);
    font-size: 0.9rem;
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 0 0.5rem;
    }
    
    header h1 {
        font-size: 2rem;
    }
    
    .editor-controls {
        flex-direction: column;
        align-items: stretch;
    }
    
    .control-group {
        justify-content: center;
    }
    
    .btn {
        padding: 0.5rem 1rem;
        font-size: 0.8rem;
    }
    
    .canvas-container {
        min-height: 300px;
    }
    
    .crop-handle {
        width: 15px;
        height: 15px;
    }
    
    .toast {
        min-width: 250px;
    }
}

@media (max-width: 480px) {
    .upload-area {
        padding: 2rem 1rem;
    }
    
    .upload-content i {
        font-size: 2rem;
    }
    
    .upload-content h3 {
        font-size: 1.2rem;
    }
    
    .editor-section {
        padding: 1rem;
    }
    
    .editor-actions {
        flex-direction: column;
    }
    
    .btn {
        width: 100%;
        justify-content: center;
    }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Focus styles */
.btn:focus,
.upload-area:focus,
.aspect-ratio-toggle:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* High contrast mode */
@media (prefers-contrast: high) {
    :root {
        --primary-color: #0000ff;
        --secondary-color: #800080;
        --success-color: #008000;
        --error-color: #ff0000;
        --gray-700: #000000;
        --gray-600: #333333;
    }
}
