/* CSS Variables */
:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --secondary-color: #64748b;
    --secondary-hover: #475569;
    --background: #0f172a;
    --surface: #1e293b;
    --surface-light: #334155;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --border-color: #475569;
    --success: #22c55e;
    --error: #ef4444;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -2px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -4px rgba(0, 0, 0, 0.2);
    --radius: 12px;
    --radius-sm: 8px;
    --transition: all 0.2s ease;
}

/* Reset */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.5;
}

/* App Container */
.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Header */
.header {
    text-align: center;
    padding: 2rem 1rem;
    background: linear-gradient(180deg, var(--surface) 0%, transparent 100%);
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.logo-img {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-sm);
}

.logo h1 {
    font-size: 1.75rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary-color), #a855f7);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.tagline {
    color: var(--text-secondary);
    font-size: 1rem;
}

/* Main Content */
.main-content {
    flex: 1;
    padding: 0 1rem 2rem;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
}

/* Upload Section */
.upload-section {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 400px;
}

.upload-area {
    background: var(--surface);
    border: 2px dashed var(--border-color);
    border-radius: var(--radius);
    padding: 3rem 2rem;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    max-width: 500px;
    width: 100%;
}

.upload-area:hover, .upload-area.dragover {
    border-color: var(--primary-color);
    background: rgba(99, 102, 241, 0.1);
}

.upload-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
}

.upload-area h2 {
    font-size: 1.25rem;
    margin-bottom: 0.5rem;
}

.upload-area p {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    font-size: 0.875rem;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
}

.btn-icon {
    font-size: 1rem;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}

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

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

/* Editor Section */
.editor-section {
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.editor-layout {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 1.5rem;
}

/* Canvas Container */
.canvas-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.canvas-wrapper {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1rem;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 400px;
    position: relative;
    overflow: hidden;
}

#imageCanvas {
    max-width: 100%;
    max-height: 70vh;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
}

.canvas-actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    justify-content: center;
}

/* Comparison Container */
.comparison-container {
    position: absolute;
    top: 1rem;
    left: 1rem;
    right: 1rem;
    bottom: 1rem;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border-radius: var(--radius-sm);
}

.comparison-wrapper {
    position: relative;
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.comparison-canvas {
    position: absolute;
    max-width: 100%;
    max-height: 100%;
    border-radius: var(--radius-sm);
}

#beforeCanvas {
    clip-path: inset(0 50% 0 0);
}

#afterCanvas {
    clip-path: inset(0 0 0 50%);
}

.comparison-slider {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    cursor: ew-resize;
    z-index: 10;
    display: flex;
    justify-content: center;
}

.slider-line {
    width: 3px;
    height: 100%;
    background: white;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
}

.slider-handle {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    background: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-lg);
}

.handle-arrows {
    color: var(--background);
    font-size: 0.75rem;
    user-select: none;
}

.comparison-labels {
    display: flex;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
}

/* Controls Panel */
.controls-panel {
    background: var(--surface);
    border-radius: var(--radius);
    overflow: hidden;
    height: fit-content;
    max-height: calc(100vh - 200px);
    display: flex;
    flex-direction: column;
}

/* Tabs */
.tabs {
    display: flex;
    background: var(--surface-light);
}

.tab {
    flex: 1;
    padding: 1rem;
    font-size: 0.875rem;
    font-weight: 600;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
}

.tab:hover {
    color: var(--text-primary);
}

.tab.active {
    background: var(--surface);
    color: var(--primary-color);
}

/* Tab Content */
.tab-content {
    display: none;
    padding: 1rem;
    overflow-y: auto;
    flex: 1;
}

.tab-content.active {
    display: block;
}

/* Control Groups */
.control-group {
    margin-bottom: 1.5rem;
}

.group-title {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

/* Slider Controls */
.slider-control {
    margin-bottom: 1rem;
}

.slider-control:last-child {
    margin-bottom: 0;
}

.slider-control label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.label-text {
    font-size: 0.875rem;
    color: var(--text-primary);
}

.label-value {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--primary-color);
    background: rgba(99, 102, 241, 0.2);
    padding: 0.125rem 0.5rem;
    border-radius: 4px;
    min-width: 40px;
    text-align: center;
}

/* Range Slider */
input[type="range"] {
    width: 100%;
    height: 6px;
    background: var(--surface-light);
    border-radius: 3px;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: var(--shadow);
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.1);
    background: var(--primary-hover);
}

input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    border: none;
    transition: var(--transition);
    box-shadow: var(--shadow);
}

input[type="range"]::-moz-range-thumb:hover {
    transform: scale(1.1);
    background: var(--primary-hover);
}

/* Presets Grid */
.presets-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
}

.preset-btn {
    background: var(--surface-light);
    border: 2px solid transparent;
    border-radius: var(--radius-sm);
    padding: 0.5rem;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.preset-btn:hover {
    border-color: var(--primary-color);
    transform: translateY(-2px);
}

.preset-btn.active {
    border-color: var(--primary-color);
    background: rgba(99, 102, 241, 0.2);
}

.preset-preview {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 6px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.preset-preview.vintage {
    filter: sepia(0.4) contrast(1.1) brightness(0.9);
}

.preset-preview.sepia {
    filter: sepia(1);
}

.preset-preview.grayscale {
    filter: grayscale(1);
}

.preset-preview.cool {
    filter: hue-rotate(-20deg) saturate(1.2);
}

.preset-preview.warm {
    filter: hue-rotate(20deg) saturate(1.3) brightness(1.1);
}

.preset-preview.dramatic {
    filter: contrast(1.5) saturate(1.3);
}

.preset-preview.fade {
    filter: contrast(0.8) brightness(1.1) saturate(0.7);
}

.preset-preview.vibrant {
    filter: saturate(1.8) contrast(1.1);
}

.preset-preview.noir {
    filter: grayscale(1) contrast(1.4) brightness(0.9);
}

.preset-preview.cinematic {
    filter: contrast(1.2) saturate(0.9) sepia(0.1);
}

.preset-preview.polaroid {
    filter: contrast(1.1) brightness(1.1) sepia(0.2) saturate(1.3);
}

.preset-btn span {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Footer */
.footer {
    text-align: center;
    padding: 1.5rem;
    background: var(--surface);
    border-top: 1px solid var(--border-color);
    margin-top: auto;
}

.footer p {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.footer a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 600;
    transition: var(--transition);
}

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

/* Responsive Design */
@media (max-width: 968px) {
    .editor-layout {
        grid-template-columns: 1fr;
    }

    .controls-panel {
        max-height: none;
    }

    .canvas-wrapper {
        min-height: 300px;
    }

    #imageCanvas {
        max-height: 50vh;
    }
}

@media (max-width: 640px) {
    .header {
        padding: 1.5rem 1rem;
    }

    .logo h1 {
        font-size: 1.5rem;
    }

    .logo-img {
        width: 40px;
        height: 40px;
    }

    .upload-area {
        padding: 2rem 1.5rem;
    }

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

    .presets-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .canvas-actions {
        flex-direction: column;
    }

    .canvas-actions .btn {
        width: 100%;
    }

    .comparison-labels {
        font-size: 0.75rem;
    }
}

@media (max-width: 380px) {
    .tabs {
        flex-direction: column;
    }

    .tab {
        border-bottom: 1px solid var(--border-color);
    }

    .tab:last-child {
        border-bottom: none;
    }
}

/* Loading State */
.loading {
    position: relative;
    pointer-events: none;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 30px;
    height: 30px;
    margin: -15px 0 0 -15px;
    border: 3px solid var(--surface-light);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--surface);
}

::-webkit-scrollbar-thumb {
    background: var(--surface-light);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--border-color);
}

/* Focus States */
.btn:focus-visible,
.tab:focus-visible,
.preset-btn:focus-visible,
input[type="range"]:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* Hidden Utility */
[hidden] {
    display: none !important;
}
