/* --- Global Styles & Variables --- */
:root {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --accent-color: #6366f1;
    --accent-hover: #4f46e5;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --border-color: #334155;
    --success-color: #10b981;
    --shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.3);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background: linear-gradient(135deg, var(--bg-primary) 0%, #1e1b4b 100%);
    color: var(--text-primary);
    line-height: 1.6;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1rem;
}

/* --- Main App Container --- */
.app-container {
    width: 100%;
    max-width: 900px;
    background-color: var(--bg-secondary);
    border-radius: 24px;
    box-shadow: var(--shadow);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

header {
    padding: 2rem;
    background: linear-gradient(135deg, var(--accent-color) 0%, #8b5cf6 100%);
    text-align: center;
}

header h1 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    color: white;
    font-weight: 700;
}

header p {
    color: rgba(255, 255, 255, 0.9);
    font-size: 1rem;
}

main {
    padding: 2.5rem;
}

/* --- Section Management --- */
.app-section {
    display: none;
}

.app-section.active {
    display: block;
}

/* --- Upload Section --- */
#uploadArea {
    border: 3px dashed var(--border-color);
    border-radius: 20px;
    padding: 4rem 2rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    background: rgba(99, 102, 241, 0.05);
}

#uploadArea:hover,
#uploadArea.drag-over {
    background: rgba(99, 102, 241, 0.15);
    border-color: var(--accent-color);
    transform: translateY(-2px);
}

#uploadArea .upload-icon {
    font-size: 4rem;
    margin-bottom: 1.5rem;
    filter: grayscale(0.3);
}

#uploadArea h3 {
    font-size: 1.5rem;
    margin-bottom: 0.75rem;
    color: var(--text-primary);
}

#uploadArea p {
    color: var(--text-secondary);
    font-size: 1rem;
    line-height: 1.8;
}

#fileInput {
    display: none;
}

/* --- Comparison Slider --- */
.comparison-container {
    width: 100%;
    margin-bottom: 2rem;
}

.image-comparison-slider {
    position: relative;
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    overflow: hidden;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    background: 
        linear-gradient(45deg, #808080 25%, transparent 25%),
        linear-gradient(-45deg, #808080 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #808080 75%),
        linear-gradient(-45deg, transparent 75%, #808080 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
    background-color: #404040;
    aspect-ratio: 16 / 9;
}

.image-wrapper {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.image-wrapper.overlay-image {
    background: 
        linear-gradient(45deg, #808080 25%, transparent 25%),
        linear-gradient(-45deg, #808080 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #808080 75%),
        linear-gradient(-45deg, transparent 75%, #808080 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
    background-color: #404040;
}

.comparison-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    user-select: none;
    -webkit-user-drag: none;
}

.overlay-image {
    clip-path: inset(0 0 0 50%);
}

.image-label {
    position: absolute;
    top: 1rem;
    padding: 0.5rem 1rem;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(10px);
    color: white;
    font-size: 0.875rem;
    font-weight: 600;
    border-radius: 8px;
    z-index: 2;
}

.original-label {
    left: 1rem;
}

.processed-label {
    right: 1rem;
}

.slider-handle {
    position: absolute;
    top: 0;
    left: 50%;
    width: 4px;
    height: 100%;
    transform: translateX(-50%);
    cursor: ew-resize;
    z-index: 3;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.slider-line {
    flex: 1;
    width: 4px;
    background: white;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
}

.slider-button {
    width: 48px;
    height: 48px;
    background: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    margin: 0;
    gap: 2px;
}

.slider-button svg {
    color: var(--accent-color);
    width: 20px;
    height: 20px;
}

/* --- Action Buttons --- */
.action-buttons {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-top: 1.5rem;
}

.btn {
    padding: 1rem 1.5rem;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
}

.btn:active {
    transform: translateY(0);
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent-color) 0%, #8b5cf6 100%);
    color: white;
}

.btn-primary:hover {
    background: linear-gradient(135deg, var(--accent-hover) 0%, #7c3aed 100%);
}

.btn-secondary {
    background-color: var(--border-color);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background-color: #475569;
}

.btn svg {
    width: 20px;
    height: 20px;
}

/* --- Loading Overlay --- */
#loadingOverlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    color: white;
    text-align: center;
}

#loadingOverlay.active {
    display: flex;
}

.spinner {
    border: 4px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    border-top: 4px solid var(--accent-color);
    width: 60px;
    height: 60px;
    animation: spin 1s linear infinite;
    margin: 0 auto 1.5rem;
}

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

#loadingText {
    font-size: 1.1rem;
    font-weight: 500;
}

/* --- Footer --- */
footer {
    text-align: center;
    padding: 1.5rem;
    font-size: 0.9rem;
    color: var(--text-secondary);
    border-top: 1px solid var(--border-color);
}

footer a {
    color: var(--accent-color);
    text-decoration: none;
    font-weight: 600;
    transition: color 0.3s ease;
}

footer a:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}

/* --- Mobile Responsiveness --- */
@media (max-width: 768px) {
    body {
        padding: 0;
    }

    .app-container {
        border-radius: 0;
        min-height: 100vh;
    }

    main {
        padding: 1.5rem;
    }

    header {
        padding: 1.5rem;
    }

    header h1 {
        font-size: 1.5rem;
    }

    header p {
        font-size: 0.9rem;
    }

    #uploadArea {
        padding: 3rem 1.5rem;
    }

    #uploadArea .upload-icon {
        font-size: 3rem;
    }

    #uploadArea h3 {
        font-size: 1.25rem;
    }

    .action-buttons {
        grid-template-columns: 1fr;
    }

    .slider-button {
        width: 40px;
        height: 40px;
    }

    .slider-button svg {
        width: 16px;
        height: 16px;
    }

    .image-label {
        font-size: 0.75rem;
        padding: 0.4rem 0.8rem;
    }
}

@media (max-width: 480px) {
    .image-comparison-slider {
        aspect-ratio: 4 / 3;
    }
}
