/* CSS Reset & Variables */
:root {
    --bg-dark: #0f172a;
    --bg-darker: #020617;
    --card-bg: rgba(30, 41, 59, 0.7);
    --card-border: rgba(148, 163, 184, 0.1);

    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --primary-glow: rgba(99, 102, 241, 0.5);

    --accent: #deb887;
    /* Soft gold for highlights */
    --text-main: #f8fafc;
    --text-muted: #94a3b8;

    --font-main: 'Outfit', sans-serif;
    --radius-lg: 16px;
    --radius-md: 12px;
    --radius-sm: 8px;

    --glass-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --glass-backdrop: blur(12px);
}

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

body {
    font-family: var(--font-main);
    background-color: var(--bg-dark);
    background-image:
        radial-gradient(at 0% 0%, hsla(253, 16%, 7%, 1) 0, transparent 50%),
        radial-gradient(at 50% 0%, hsla(225, 39%, 30%, 1) 0, transparent 50%),
        radial-gradient(at 100% 0%, hsla(339, 49%, 30%, 1) 0, transparent 50%);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
    user-select: none;
}

/* Layout */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* Header */
.glass-header {
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: var(--glass-backdrop);
    border-bottom: 1px solid var(--card-border);
    z-index: 10;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 1.25rem;
    font-weight: 600;
}

.logo-icon {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, var(--primary), #ec4899);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 15px var(--primary-glow);
}

.logo-icon i {
    width: 18px;
    height: 18px;
}

.highlight {
    color: var(--primary);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-weight: 500;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    outline: none;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    filter: grayscale(1);
}

.secondary {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
    border: 1px solid var(--card-border);
}

.secondary:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.1);
}

.primary {
    background: var(--primary);
    color: white;
    box-shadow: 0 0 0 0 var(--primary-glow);
}

.primary:hover:not(:disabled) {
    background: var(--primary-hover);
    box-shadow: 0 2px 12px var(--primary-glow);
    transform: translateY(-1px);
}

.magic-btn {
    width: 100%;
    justify-content: center;
    padding: 12px;
    font-size: 1rem;
    background: linear-gradient(135deg, var(--primary), #ec4899);
    color: white;
    margin-top: 10px;
}

.magic-btn:hover:not(:disabled) {
    background: linear-gradient(135deg, #4f46e5, #db2777);
    box-shadow: 0 4px 20px rgba(236, 72, 153, 0.4);
}

/* Workspace */
.workspace {
    flex: 1;
    display: flex;
    overflow: hidden;
    position: relative;
    background: rgba(0, 0, 0, 0.2);
}

/* Toolbar */
.glass-panel {
    background: var(--card-bg);
    backdrop-filter: var(--glass-backdrop);
    border: 1px solid var(--card-border);
}

.toolbar {
    width: 280px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    border-right: 1px solid var(--card-border);
    z-index: 5;
}

.tool-group,
.action-group {
    display: flex;
    gap: 10px;
}

.tool-btn {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--card-border);
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

.tool-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-main);
}

.tool-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    box-shadow: 0 2px 8px var(--primary-glow);
}

.separator {
    height: 1px;
    background: var(--card-border);
    width: 100%;
}

.setting-label {
    display: block;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 10px;
}

/* Sliders */
.slider-container {
    display: flex;
    align-items: center;
    gap: 12px;
}

input[type=range] {
    appearance: none;
    -webkit-appearance: none;
    width: 100%;
    background: transparent;
}

input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 16px;
    width: 16px;
    border-radius: 50%;
    background: white;
    cursor: pointer;
    margin-top: -6px;
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
}

input[type=range]::-webkit-slider-runnable-track {
    width: 100%;
    height: 4px;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
}

#brushSizeVal {
    font-size: 0.85rem;
    width: 40px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* Canvas Viewport */
.canvas-viewport {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    background-image:
        linear-gradient(45deg, #1e293b 25%, transparent 25%),
        linear-gradient(-45deg, #1e293b 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #1e293b 75%),
        linear-gradient(-45deg, transparent 75%, #1e293b 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
    overflow: hidden;
}

.empty-state {
    text-align: center;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    border: 2px dashed var(--card-border);
    padding: 60px;
    border-radius: var(--radius-lg);
    background: rgba(15, 23, 42, 0.8);
    transition: all 0.3s;
}

.empty-state.drag-over {
    border-color: var(--primary);
    background: rgba(99, 102, 241, 0.1);
    transform: scale(1.02);
}

.icon-pulse {
    animation: pulse 3s infinite;
    color: var(--primary);
}

@keyframes pulse {
    0% {
        transform: scale(1);
        opacity: 1;
    }

    50% {
        transform: scale(1.1);
        opacity: 0.7;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.canvas-wrapper {
    position: absolute;
    top: 0;
    left: 0;
    /* Removed box-shadow as it might look weird if full size, but keeping per design */
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    /* No max-width/height here, controlled by JS scaling */
    cursor: none;
    /* We use custom cursor */
    transform-origin: 0 0;
    /* Required for correct coordinate calculation */
}

canvas {
    display: block;
    position: absolute;
    top: 0;
    left: 0;
}

#mainCanvas {
    z-index: 1;
}

#maskCanvas {
    z-index: 2;
    opacity: 0.6;
    /* Semi-transparent mask red */
}

/* Custom Cursor */
.cursor-ring {
    position: absolute;
    border: 2px solid white;
    border-radius: 50%;
    pointer-events: none;
    z-index: 100;
    transform: translate(-50%, -50%);
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
    backdrop-filter: invert(1);
    /* High contrast */
    display: none;
}

/* Compare Button */
.compare-fab {
    position: absolute;
    bottom: 30px;
    right: 30px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: white;
    color: var(--bg-dark);
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    z-index: 20;
    transition: transform 0.2s;
}

.compare-fab:active {
    transform: scale(0.9);
}

/* Actions Panel */
.actions-panel {
    position: absolute;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    padding: 16px;
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 300px;
    z-index: 20;
}

.status-indicator {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.loader {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Responsive */
@media (max-width: 768px) {
    .glass-header {
        padding: 0 16px;
    }

    .toolbar {
        display: none;
        /* Hide standard toolbar for mobile, create bottom drawer later */
    }

    .actions-panel {
        bottom: 20px;
        width: 90%;
    }
}

/* Zoom Controls */
.zoom-controls {
    position: absolute;
    bottom: 30px;
    left: 30px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: var(--radius-md);
    z-index: 20;
    font-size: 0.85rem;
    font-variant-numeric: tabular-nums;
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-main);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.icon-btn:hover {
    opacity: 1;
}

.icon-btn i {
    width: 16px;
    height: 16px;
}

/* Tool cursor states */
.cursor-grab {
    cursor: grab;
}

.cursor-grabbing {
    cursor: grabbing;
}