@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
    --bg-deep: #030305;
    --bg-surface: #0a0a0c;
    --glass-bg: rgba(20, 20, 25, 0.7);
    --glass-border: rgba(255, 255, 255, 0.08);
    --glass-highlight: rgba(255, 255, 255, 0.15);

    --primary-glow: #3b82f6;
    --secondary-glow: #8b5cf6;
    --accent-cyan: #06b6d4;

    --text-main: #ffffff;
    --text-muted: #94a3b8;

    --font-display: 'Outfit', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;

    --radius-lg: 24px;
    --radius-md: 16px;
    --radius-sm: 8px;
}

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

body {
    background-color: var(--bg-deep);
    /* Tech Grid Background */
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px),
        radial-gradient(circle at 50% 0%, rgba(59, 130, 246, 0.15), transparent 60%);
    background-size: 40px 40px, 40px 40px, 100% 100%;
    color: var(--text-main);
    font-family: var(--font-display);
    min-height: 100vh;
    padding-bottom: 60px;
    -webkit-font-smoothing: antialiased;
}

.app-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 30px;
}

/* Header */
.app-header {
    height: 100px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--glass-border);
    margin-bottom: 40px;
    position: relative;
}

.app-header::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    width: 20%;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--primary-glow), transparent);
}

.logo {
    display: flex;
    align-items: center;
    gap: 16px;
}

.logo i {
    color: var(--primary-glow);
    font-size: 1.8rem;
    filter: drop-shadow(0 0 10px rgba(59, 130, 246, 0.5));
}

.brand-text {
    font-family: var(--font-display);
    font-weight: 800;
    font-size: 1.4rem;
    letter-spacing: -0.02em;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 0.4em;
    /* Responsive gap */
}

.brand-accent {
    font-family: var(--font-mono);
    color: var(--primary-glow);
    font-weight: 300;
    position: relative;
    top: -1px;
}

.brand-tag {
    font-family: var(--font-mono);
    font-weight: 500;
    font-size: 0.75rem;
    color: var(--accent-cyan);
    background: rgba(6, 182, 212, 0.1);
    border: 1px solid rgba(6, 182, 212, 0.2);
    padding: 3px 8px;
    border-radius: 4px;
    letter-spacing: 0.1em;
    margin-left: 4px;
    box-shadow: 0 0 10px rgba(6, 182, 212, 0.1);
}

.controls {
    display: flex;
    gap: 16px;
}

/* Tech Buttons */
.btn-secondary {
    padding: 0 20px;
    height: 42px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--glass-border);
    background: rgba(255, 255, 255, 0.02);
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
    display: flex;
    align-items: center;
    gap: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    position: relative;
    overflow: hidden;
    white-space: nowrap;
    /* Prevent text wrapping */
}

/* ... existing styles ... */

/* Floating Labels - Tech Style */
.slider-handle .label {
    position: absolute;
    /* Move to vertical center */
    top: 50%;
    /* Offset upwards so it sits just above the handle circle. 
       Handle circle is ~50px tall. We want to be above it. */
    transform: translateY(-250%);

    font-family: var(--font-mono);
    font-size: 0.75rem;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.9);
    pointer-events: none;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8);
    background: rgba(0, 0, 0, 0.6);
    padding: 4px 8px;
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(4px);
    text-transform: uppercase;
    letter-spacing: 1px;

    transition: all 0.2s ease;
    white-space: nowrap;
    /* Prevent vertical text */
}

/* ... existing styles ... */

/* Mobile */
@media (max-width: 768px) {
    .upload-section {
        grid-template-columns: 1fr;
    }

    .app-header {
        flex-direction: column;
        height: auto;
        padding: 15px 0;
        gap: 15px;
        align-items: flex-start;
        /* Align left */
    }

    .controls {
        width: 100%;
        overflow-x: auto;
        /* Allow horizontal scroll if buttons too wide */
        padding-bottom: 5px;
        /* Space for scrollbar if any */
        justify-content: flex-start;
        -webkit-overflow-scrolling: touch;
        gap: 10px;
    }

    .controls::-webkit-scrollbar {
        display: none;
        /* Hide scrollbar for cleaner look */
    }

    .btn-secondary {
        padding: 0 12px;
        font-size: 0.75rem;
        height: 36px;
    }

    .slider-handle .label {
        font-size: 10px;
        padding: 2px 6px;
    }

    .label-before {
        right: 24px;
    }

    .label-after {
        left: 24px;
    }
}

.btn-secondary::before {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--primary-glow);
    opacity: 0;
    transition: opacity 0.3s;
    z-index: -1;
}

.btn-secondary:hover {
    border-color: var(--primary-glow);
    color: #fff;
    box-shadow: 0 0 20px rgba(59, 130, 246, 0.2);
    transform: translateY(-1px);
}

.btn-secondary:hover::before {
    opacity: 0.1;
}

.btn-text {
    background: none;
    border: 1px solid transparent;
    color: var(--accent-cyan);
    cursor: pointer;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    transition: all 0.3s;
}

.btn-text:hover {
    background: rgba(6, 182, 212, 0.1);
    border-color: rgba(6, 182, 212, 0.3);
    box-shadow: 0 0 15px rgba(6, 182, 212, 0.2);
}

/* Upload Section */
.upload-section {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 32px;
    margin-bottom: 60px;
}

.upload-card {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 4px;
}

.card-header h3 {
    font-family: var(--font-mono);
    font-size: 0.9rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.drop-zone {
    position: relative;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    aspect-ratio: 16/9;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
    overflow: hidden;
    backdrop-filter: blur(20px);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
}

.drop-zone::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: var(--radius-md);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05);
    pointer-events: none;
}

.drop-zone:hover,
.drop-zone.drag-over {
    border-color: var(--primary-glow);
    box-shadow: 0 0 30px rgba(59, 130, 246, 0.15);
    transform: translateY(-2px) scale(1.005);
}

.zone-content {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    pointer-events: none;
    z-index: 2;
    transition: all 0.3s;
}

.icon-box {
    width: 64px;
    height: 64px;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.01));
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 20px;
    font-size: 24px;
    color: var(--text-muted);
    transition: all 0.3s;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
}

.drop-zone:hover .icon-box {
    color: #fff;
    border-color: var(--primary-glow);
    background: rgba(59, 130, 246, 0.1);
    box-shadow: 0 0 20px rgba(59, 130, 246, 0.3);
    transform: scale(1.1);
}

.drop-zone p {
    font-family: var(--font-display);
    font-size: 1rem;
    color: var(--text-muted);
    letter-spacing: 0.5px;
}

/* Image State in Drop Zone */
.drop-zone.has-image .zone-content {
    opacity: 0;
}

.drop-zone:hover.has-image .zone-content {
    opacity: 1;
    background: rgba(3, 3, 5, 0.85);
    /* Darker overlay */
    backdrop-filter: blur(8px);
}

.preview-img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: radial-gradient(circle at center, #1a1a1e, #000);
    z-index: 1;
}

.remove-img-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.6);
    color: var(--text-main);
    border: 1px solid rgba(255, 255, 255, 0.1);
    cursor: pointer;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: all 0.2s;
    backdrop-filter: blur(4px);
}

.remove-img-btn:hover {
    background: #ef4444;
    border-color: #ef4444;
    box-shadow: 0 0 15px rgba(239, 68, 68, 0.4);
}


/* Result Section */
.result-section {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* Result Header Redesign */
.result-header-modern {
    display: flex;
    align-items: center;
    gap: 20px;
    margin-bottom: 20px;
    position: relative;
    padding: 0 10px;
}

.header-line {
    flex: 1;
    height: 1px;
    background: linear-gradient(90deg,
            transparent 0%,
            rgba(59, 130, 246, 0.5) 50%,
            transparent 100%);
    opacity: 0.3;
}

.header-title-group {
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(0, 0, 0, 0.4);
    padding: 8px 24px;
    border-radius: 30px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(10px);
}

.header-icon-glow {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(59, 130, 246, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary-glow);
    box-shadow: 0 0 10px rgba(59, 130, 246, 0.2);
    font-size: 1rem;
}

.result-header-modern h2 {
    font-size: 1.2rem;
    color: #fff;
    font-weight: 700;
    letter-spacing: 0.5px;
    margin: 0;
}

.tech-badge {
    font-family: var(--font-mono);
    font-size: 0.65rem;
    color: var(--accent-cyan);
    background: rgba(6, 182, 212, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid rgba(6, 182, 212, 0.2);
    letter-spacing: 1px;
}

.header-tools {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
}

.btn-icon-text {
    background: none;
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    transition: all 0.3s;
    background: rgba(0, 0, 0, 0.3);
}

.btn-icon-text:hover {
    color: var(--accent-cyan);
    border-color: var(--accent-cyan);
    background: rgba(6, 182, 212, 0.1);
    box-shadow: 0 0 15px rgba(6, 182, 212, 0.1);
}

/* Mobile adjust for header tools */
@media (max-width: 768px) {
    .result-header-modern {
        flex-direction: column;
        gap: 15px;
        align-items: stretch;
    }

    .header-line {
        display: none;
    }

    .header-title-group {
        justify-content: center;
    }

    .header-tools {
        position: relative;
        right: auto;
        top: auto;
        transform: none;
        display: flex;
        justify-content: center;
        /* Center button on mobile */
    }
}

/* Comparison Viewer container */
.comparison-wrapper {
    width: 100%;
    /* Default height for placeholder state */
    min-height: 400px;
    background: #000;
    border-radius: var(--radius-lg);
    position: relative;
    overflow: hidden;
    border: 1px solid var(--glass-border);
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.02), 0 30px 60px rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    transition: min-height 0.3s ease;
}

/* When images are loaded, shrink wrapper to fit image exactly */
.comparison-wrapper.has-image {
    min-height: 0;
    height: auto;
    width: fit-content;
    max-width: 100%;
    margin: 0 auto;
    display: block;
    background: transparent;
    box-shadow: 0 30px 60px rgba(0, 0, 0, 0.5);
}

/* Fullscreen Scroll Fix */
.comparison-wrapper:fullscreen,
.comparison-wrapper:-webkit-full-screen {
    overflow-y: auto;
    display: flex;
    /* Flex handles centering better for smaller imgs */
    flex-direction: column;
    align-items: center;
    /* Center horizontally */
    justify-content: flex-start;
    /* Start from top to allow scroll */
    background: #000;
    padding: 20px 0;
    /* Add spacer */
}

.comparison-wrapper:fullscreen .slider-container,
.comparison-wrapper:-webkit-full-screen .slider-container {
    margin: auto;
    /* Center in available space */
    flex-shrink: 0;
    /* Prevent shrinking */
}

/* Critical: Force Alignment (Object-Fit) */
.comparison-wrapper .slider-container .before-image img {
    max-width: none !important;
    /* Width must come from JS to match the FULL container width, not the masked parents width */
    height: 100% !important;
    object-fit: fill !important;
    /* Force stretch to match the container (After image size) perfectly */
}

.placeholder-state {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    color: var(--text-muted);
    background:
        radial-gradient(circle at center, rgba(20, 20, 30, 0.8) 0%, #000 100%),
        repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.01) 0px, rgba(255, 255, 255, 0.01) 1px, transparent 1px, transparent 20px);
    z-index: 5;
    pointer-events: none;
    font-family: var(--font-mono);
    font-size: 0.9rem;
    letter-spacing: 1px;
}

.placeholder-state::after {
    content: 'Waiting for Input...';
    opacity: 0.5;
}

/* Slider CSS Logic (PRESERVED) */
.slider-container {
    position: relative;
    opacity: 0;
    transition: opacity 0.5s ease;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
    /* user-select handled via JS/events */
}

.slider-container.active {
    opacity: 1;
}

.image-wrapper {
    position: relative;
    overflow: hidden;
}

.image-wrapper img {
    display: block;
    max-width: 100%;
    /* Default for container-driven images */
    pointer-events: none;
    user-select: none;
}

/* CRITICAL: Before Image Logic from previous fix */
.comparison-wrapper .slider-container .before-image {
    position: absolute;
    top: 0;
    left: 0;
    width: 50%;
    /* Resizable */
    height: 100%;
    z-index: 10;
    border-right: 1px solid rgba(255, 255, 255, 0.2);
    background: #000;
    overflow: hidden;
    box-shadow: 5px 0 20px rgba(0, 0, 0, 0.3);
    /* Shadow on the cut line */
}

.comparison-wrapper .slider-container .before-image img {
    max-width: none !important;
    /* Fixes squashing */
}

.comparison-wrapper .slider-container .after-image {
    position: relative;
    width: 100%;
    height: 100%;
    z-index: 1;
}

/* Handle Design - TECH STYLE */
.slider-handle {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    width: 40px;
    /* Wider hit area for mouse processing */
    transform: translateX(-50%);
    z-index: 30;
    cursor: col-resize;
    /* Or move? */
    pointer-events: none;
    /* Let container catch events, visual only */
}

/* The continuous vertical line */
.handle-line-full {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    width: 2px;
    transform: translateX(-50%);
    background: linear-gradient(to bottom,
            rgba(255, 255, 255, 0) 0%,
            var(--accent-cyan) 20%,
            #fff 50%,
            var(--accent-cyan) 80%,
            rgba(255, 255, 255, 0) 100%);
    box-shadow: 0 0 8px var(--accent-cyan);
    opacity: 0.8;
}

/* Moving Thumb Group (Circle + Labels) */
.slider-thumb {
    position: absolute;
    top: 50%;
    /* JS will update this */
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 0;
    /* Wrapper shouldn't take space */
    height: 0;
}

/* The Button Controller */
.handle-circle {
    width: 48px;
    height: 48px;
    /* Hexagon-ish or circle with border */
    background: rgba(10, 10, 15, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow:
        0 0 0 4px rgba(6, 182, 212, 0.1),
        0 0 20px rgba(6, 182, 212, 0.4),
        inset 0 0 20px rgba(0, 0, 0, 0.8);
    font-size: 14px;
    backdrop-filter: blur(10px);
    z-index: 35;
    position: relative;
    flex-shrink: 0;
}

.handle-circle::after {
    content: '';
    position: absolute;
    inset: -2px;
    border-radius: 50%;
    border: 1px solid var(--accent-cyan);
    opacity: 0.5;
    animation: pulse 2s infinite;
}

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

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

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

.handle-circle i {
    font-size: 12px;
    color: var(--accent-cyan);
    text-shadow: 0 0 5px var(--accent-cyan);
}


/* Floating Labels - Updated for Thumb */
.slider-handle .label {
    position: absolute;
    /* Vertically centered to the thumb div */
    top: 50%;
    transform: translateY(-50%);

    font-family: var(--font-mono);
    font-size: 0.75rem;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.9);
    white-space: nowrap;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8);
    background: rgba(0, 0, 0, 0.6);
    padding: 4px 8px;
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(4px);
    text-transform: uppercase;
    letter-spacing: 1px;
    transition: all 0.2s ease;
}

.label-before {
    right: 40px;
    /* Distance from center circle */
    text-align: right;
    border-right: 2px solid var(--primary-glow);
}

.label-after {
    left: 40px;
    /* Distance from center circle */
    text-align: left;
    border-left: 2px solid var(--accent-cyan);
}