/* ========================================
   CSS Reset & Base Styles
   ======================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Colors */
    --primary: #2563eb;
    --primary-dark: #1e40af;
    --secondary: #6b7280;
    --success: #10b981;
    --danger: #ef4444;
    --background: #f3f4f6;
    --surface: #ffffff;
    --border: #e5e7eb;
    --text: #1f2937;
    --text-light: #6b7280;
    
    /* Spacing */
    --space-xs: 0.5rem;
    --space-sm: 1rem;
    --space-md: 1.5rem;
    --space-lg: 2rem;
    --space-xl: 3rem;
    
    /* Border radius */
    --radius: 0.5rem;
    --radius-lg: 1rem;
    
    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
    
    /* Transitions */
    --transition: 200ms ease;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--background);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

/* ========================================
   Container & Layout
   ======================================== */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: var(--space-md);
}

.header {
    text-align: center;
    margin-bottom: var(--space-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-md);
}

.header-top {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-md);
}

.header-logo {
    height: 60px;
    width: auto;
    object-fit: contain;
}

.header-text {
    text-align: left;
}

.header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: var(--space-xs);
}

.subtitle {
    font-size: 1.125rem;
    color: var(--text-light);
}

.main-content {
    display: grid;
    grid-template-columns: 380px 1fr;
    gap: var(--space-lg);
    align-items: start;
}

/* ========================================
   Control Panel
   ======================================== */
.control-panel {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    box-shadow: var(--shadow-md);
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
}

.control-panel h2 {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: var(--space-sm);
    color: var(--text);
}

/* Upload Section */
.upload-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: var(--space-lg);
    text-align: center;
    transition: all var(--transition);
    cursor: pointer;
    background: var(--background);
}

.upload-zone:hover,
.upload-zone.drag-over {
    border-color: var(--primary);
    background: rgba(37, 99, 235, 0.05);
}

.upload-label {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-sm);
    cursor: pointer;
}

.upload-icon {
    width: 48px;
    height: 48px;
    color: var(--primary);
}

.upload-text {
    font-weight: 500;
    color: var(--text);
}

.upload-hint {
    font-size: 0.875rem;
    color: var(--text-light);
}

/* Overlay Gallery */
.overlay-gallery {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-sm);
    margin-bottom: var(--space-sm);
}

.overlay-item {
    aspect-ratio: 1;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
    overflow: hidden;
    background: var(--background);
    position: relative;
}

.overlay-item img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: var(--space-xs);
}

.overlay-item:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.overlay-item.active {
    border-color: var(--primary);
    border-width: 3px;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.overlay-item.active::after {
    content: '✓';
    position: absolute;
    top: 4px;
    right: 4px;
    background: var(--primary);
    color: white;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
    font-weight: bold;
}

/* Transform Controls */
.control-group {
    margin-bottom: var(--space-md);
}

.control-group label {
    display: block;
    font-weight: 500;
    margin-bottom: var(--space-xs);
    color: var(--text);
}

.control-group input[type="range"] {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: var(--border);
    outline: none;
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
}

.control-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    transition: all var(--transition);
}

.control-group input[type="range"]::-webkit-slider-thumb:hover {
    background: var(--primary-dark);
    transform: scale(1.1);
}

.control-group input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    border: none;
    transition: all var(--transition);
}

.control-group input[type="range"]::-moz-range-thumb:hover {
    background: var(--primary-dark);
    transform: scale(1.1);
}

/* Buttons */
.btn {
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-xs);
    min-height: 44px;
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
}

.btn:focus-visible {
    outline: 3px solid rgba(37, 99, 235, 0.5);
    outline-offset: 2px;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background: var(--background);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--border);
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
}

.button-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-sm);
}

/* ========================================
   Preview Panel
   ======================================== */
.preview-panel {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    box-shadow: var(--shadow-md);
    position: sticky;
    top: var(--space-md);
}

.canvas-container {
    position: relative;
    width: 100%;
    aspect-ratio: 1;
    background: var(--background);
    border-radius: var(--radius);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

#canvas {
    max-width: 100%;
    max-height: 100%;
    display: block;
    cursor: grab;
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

#canvas.dragging {
    cursor: grabbing;
}

.canvas-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-md);
    color: var(--text-light);
    pointer-events: none;
}

.canvas-placeholder.hidden {
    display: none;
}

.placeholder-icon {
    width: 80px;
    height: 80px;
    opacity: 0.5;
}

.canvas-hint {
    position: absolute;
    bottom: var(--space-md);
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: var(--space-xs) var(--space-md);
    border-radius: var(--radius);
    font-size: 0.875rem;
    pointer-events: none;
    animation: fadeInOut 3s ease-in-out;
}

@keyframes fadeInOut {
    0%, 100% { opacity: 0; }
    10%, 90% { opacity: 1; }
}

.canvas-info {
    margin-top: var(--space-md);
    font-size: 0.875rem;
    color: var(--text-light);
    text-align: center;
}

/* ========================================
   Toast Notification
   ======================================== */
.toast {
    position: fixed;
    top: var(--space-md);
    right: var(--space-md);
    background: var(--text);
    color: white;
    padding: var(--space-md);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    opacity: 0;
    transform: translateY(-20px);
    transition: all var(--transition);
    pointer-events: none;
    z-index: 1000;
    max-width: 400px;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

.toast.success {
    background: var(--success);
}

.toast.error {
    background: var(--danger);
}

/* ========================================
   Responsive Design
   ======================================== */
@media (max-width: 1024px) {
    .main-content {
        grid-template-columns: 1fr;
    }
    
    .preview-panel {
        position: static;
    }
    
    .control-panel {
        order: 2;
    }
}

@media (max-width: 768px) {
    .header-top {
        flex-direction: column;
        gap: var(--space-sm);
    }
    
    .header-logo {
        height: 50px;
    }
    
    .header-text {
        text-align: center;
    }
    
    .header h1 {
        font-size: 1.75rem;
    }
    
    .subtitle {
        font-size: 0.95rem;
    }
    
    .control-panel {
        padding: var(--space-md);
    }
    
    .control-panel h2 {
        font-size: 1rem;
    }
    
    .btn {
        padding: var(--space-sm) var(--space-md);
        font-size: 0.95rem;
    }
    
    .canvas-container {
        min-height: 300px;
    }
}

@media (max-width: 640px) {
    .container {
        padding: var(--space-sm);
    }
    
    .header h1 {
        font-size: 1.5rem;
    }
    
    .subtitle {
        font-size: 0.85rem;
    }
    
    .overlay-gallery {
        grid-template-columns: repeat(2, 1fr);
        gap: var(--space-xs);
    }
    
    .overlay-item {
        aspect-ratio: 1;
    }
    
    .button-group {
        grid-template-columns: 1fr;
    }
    
    .btn {
        width: 100%;
        padding: 0.75rem var(--space-sm);
        font-size: 0.9rem;
    }
    
    .control-group {
        margin-bottom: var(--space-sm);
    }
    
    .control-group label {
        font-size: 0.9rem;
    }
    
    .canvas-container {
        min-height: 250px;
        max-height: 80vw;
    }
    
    #canvas {
        max-width: 100%;
        max-height: 100%;
    }
    
    .control-panel {
        padding: var(--space-md) var(--space-sm);
    }
}

/* ========================================
   Accessibility
   ======================================== */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ========================================
   Footer
   ======================================== */
.footer {
    text-align: center;
    margin-top: var(--space-xl);
    padding-top: var(--space-lg);
    border-top: 1px solid var(--border);
    color: var(--text-light);
    font-size: 0.875rem;
}

.footer strong {
    color: var(--primary);
    font-weight: 600;
}
