:root {
    --bg-color: #f4f4f9;
    --surface-color: #ffffff;
    --text-color: #333333;
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --border-color: #e5e7eb;
    --toolbar-bg: #ffffff;
}

[data-theme="dark"] {
    --bg-color: #111827;
    --surface-color: #1f2937;
    --text-color: #f9fafb;
    --primary-color: #818cf8;
    --primary-hover: #6366f1;
    --border-color: #374151;
    --toolbar-bg: #1f2937;
}

* { margin: 0; padding: 0; box-sizing: border-box; font-family: system-ui, -apple-system, sans-serif; }

body { background-color: var(--bg-color); color: var(--text-color); transition: background 0.3s; display: flex; flex-direction: column; min-height: 100vh; }

header { display: flex; justify-content: space-between; align-items: center; padding: 1rem 2rem; background: var(--surface-color); box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
.logo { font-size: 1.25rem; font-weight: bold; display: flex; align-items: center; gap: 0.5rem; color: var(--primary-color); }
.icon-btn { background: none; border: none; font-size: 1.2rem; color: var(--text-color); cursor: pointer; }

main { flex: 1; display: flex; justify-content: center; align-items: center; padding: 1rem; position: relative; }
.screen { display: none; width: 100%; height: 100%; justify-content: center; align-items: center; }
.screen.active { display: flex; }

/* Upload Area */
.upload-area { background: var(--surface-color); border: 2px dashed var(--border-color); border-radius: 12px; padding: 3rem 2rem; text-align: center; width: 100%; max-width: 500px; transition: border-color 0.3s; }
.upload-area.dragover { border-color: var(--primary-color); background: rgba(99, 102, 241, 0.05); }
.upload-area h3 { margin: 1rem 0 0.5rem; }
.upload-buttons { display: flex; gap: 1rem; justify-content: center; margin-top: 1rem; flex-wrap: wrap; }
.btn { padding: 0.75rem 1.5rem; border-radius: 8px; cursor: pointer; font-weight: 600; border: none; display: flex; align-items: center; gap: 0.5rem; }
.btn.primary { background: var(--primary-color); color: white; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.secondary { background: var(--border-color); color: var(--text-color); }
.file-limits { margin-top: 1rem; font-size: 0.85rem; opacity: 0.7; }
@media (min-width: 768px) { .mobile-only { display: none; } }

/* Workspace & Canvas */
.workspace { position: relative; width: 100%; max-width: 800px; aspect-ratio: 4/3; background: #e5e5f7; opacity: 1; background-image: radial-gradient(#cbd5e1 1px, transparent 1px); background-size: 20px 20px; border-radius: 8px; overflow: hidden; box-shadow: 0 4px 6px rgba(0,0,0,0.1); }
.canvas-container { position: relative; width: 100%; height: 100%; }
canvas { display: block; width: 100%; height: 100%; object-fit: contain; }
#bgCanvas { position: absolute; top: 0; left: 0; }
.slider-overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; overflow: hidden; pointer-events: none; border-right: 2px solid white; box-shadow: 2px 0 4px rgba(0,0,0,0.2); }
#fgCanvas { position: absolute; top: 0; left: 0; width: 100%; height: 100%; object-fit: contain; }

/* Before/After Slider */
.compare-slider { position: absolute; top: 50%; left: 0; width: 100%; transform: translateY(-50%); z-index: 10; opacity: 0; cursor: ew-resize; height: 100%; }

/* Loading Overlay */
.loading-overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.7); display: flex; flex-direction: column; justify-content: center; align-items: center; color: white; border-radius: 8px; z-index: 20; }
.loading-overlay.hidden { display: none; }
.spinner { border: 4px solid rgba(255,255,255,0.3); border-top: 4px solid white; border-radius: 50%; width: 40px; height: 40px; animation: spin 1s linear infinite; margin-bottom: 1rem; }
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* =========================================
   Advanced Premium Toolbar (Mobile First)
========================================= */
.toolbar { 
    position: fixed; 
    bottom: 0; left: 0; width: 100%; 
    background: rgba(255, 255, 255, 0.85); /* Glassmorphism Effect */
    backdrop-filter: blur(16px); 
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid rgba(0,0,0,0.08); 
    z-index: 100; 
    box-shadow: 0 -4px 25px rgba(0,0,0,0.05);
}

[data-theme="dark"] .toolbar {
    background: rgba(31, 41, 55, 0.85);
    border-top: 1px solid rgba(255,255,255,0.08);
}

.toolbar.hidden { display: none; }

/* The Secret to Perfect Mobile Scrolling */
.toolbar-scroll-area {
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    gap: 0.5rem;
    overflow-x: auto; /* Enable horizontal scroll */
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch; /* Smooth scroll on iOS */
    scroll-behavior: smooth;
    scrollbar-width: none; /* Hide scrollbar Firefox */
}
.toolbar-scroll-area::-webkit-scrollbar { display: none; /* Hide scrollbar Chrome/Safari */ }

.tool-group { 
    display: flex; 
    gap: 0.75rem; 
    flex: 0 0 auto; /* PREVENTS SQUISHING - Forces items to stay their size */
}

.tool-separator { 
    width: 2px; height: 35px; 
    background: var(--border-color); 
    flex: 0 0 auto; 
    margin: 0 0.5rem;
    border-radius: 2px;
}

/* App-like Button Design */
.tool-btn { 
    background: transparent; border: none; 
    color: var(--text-color); 
    display: flex; flex-direction: column; align-items: center; gap: 0.4rem; 
    font-size: 0.75rem; font-weight: 600;
    cursor: pointer; 
    flex: 0 0 auto;
    min-width: 65px;
}

.icon-wrapper {
    width: 48px; height: 48px;
    display: flex; justify-content: center; align-items: center;
    border-radius: 14px; /* Modern squircle shape */
    background: var(--bg-color);
    font-size: 1.25rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: inset 0 0 0 1px var(--border-color);
}

/* Hover & Active States */
.tool-btn:hover .icon-wrapper, .tool-btn.active .icon-wrapper { 
    background: var(--primary-color); 
    color: white; 
    box-shadow: 0 6px 15px rgba(99, 102, 241, 0.4);
    transform: translateY(-3px); /* Smooth lift effect */
}

/* Call to Action Buttons (Downloads) */
.action-btn .icon-wrapper {
    background: var(--text-color);
    color: var(--bg-color);
}
.action-btn:hover .icon-wrapper {
    background: var(--primary-hover);
    color: white;
}

/* =========================================
   Desktop Media Query for Sidebar
========================================= */
@media (min-width: 1024px) {
    body { flex-direction: row; flex-wrap: wrap; }
    header { width: 100%; }
    main { width: calc(100% - 110px); padding: 2rem; }
    
    .toolbar { 
        position: static; 
        width: 110px; height: calc(100vh - 70px); 
        border-top: none; border-left: 1px solid var(--border-color); 
        box-shadow: -4px 0 25px rgba(0,0,0,0.05);
    }
    
    .toolbar-scroll-area {
        flex-direction: column; 
        padding-top: 2rem;
        height: 100%;
        overflow-y: auto; overflow-x: hidden;
    }
    
    .tool-group { flex-direction: column; }
    .tool-separator { width: 40px; height: 2px; margin: 1rem 0; }
}
