:root {
    --background-dark: #2C2E3B;
    --background-darker: #252830;
    --card-background: rgba(255, 255, 255, 0.05);
    --accent-blue: #3b82f6;
    --accent-blue-light: #93c5fd;
    --accent-blue-dark: #1e40af;
    --accent-red: #ef4444;
    --text-primary: #ffffff;
    --text-secondary: #9ca3af;

    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.1);

    --radius-sm: 0.5rem;
    --radius: 0.75rem;
    --radius-lg: 1rem;
    --radius-xl: 1.5rem;

    --spacing-2: 0.5rem;
    --spacing-4: 1rem;
    --spacing-6: 1.5rem;
    --spacing-8: 2rem;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
    'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
    sans-serif;
    background: var(--background-dark);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
    display: flex;
    flex-direction: column;
    margin: 0;
    padding: 0;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: var(--spacing-4);
    flex: 1;
    width: 100%;
}

.header {
    text-align: center;
    margin-bottom: var(--spacing-8);
}

h1 {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--accent-blue-light);
    margin-bottom: var(--spacing-2);
    letter-spacing: -0.025em;
}

.subtitle {
    font-size: 1.125rem;
    color: var(--text-secondary);
}

.camera-section {
    background: var(--card-background);
    border-radius: 16px;
    padding: var(--spacing-6);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.1);
    margin-bottom: var(--spacing-6);
}

.video-container {
    position: relative;
    text-align: center;
    margin-bottom: var(--spacing-6);
    width: 100%;
    max-width: 640px;
    margin-left: auto;
    margin-right: auto;
    padding: 0 var(--spacing-4);
}

@media (max-width: 768px) {
    .video-container {
        padding: 0 var(--spacing-2);
        max-width: 100%;
    }
}

#video {
    width: 100%;
    max-width: 640px;
    height: auto;
    border-radius: var(--radius);
    background: var(--background-darker);
}

.controls {
    display: flex;
    gap: var(--spacing-4);
    justify-content: center;
    flex-wrap: wrap;
    margin-bottom: var(--spacing-6);
}

@media (max-width: 768px) {
    .controls {
        gap: var(--spacing-2);
        padding: 0 var(--spacing-2);
    }
}

.btn {
    padding: 0.875rem 2rem;
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

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

.btn-primary:hover {
    background: #2563eb;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.btn-secondary {
    background: var(--accent-blue-dark);
    color: white;
}

.btn-secondary:hover {
    background: #1e3a8a;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(30, 64, 175, 0.3);
}

.btn-danger {
    background: var(--accent-red);
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.photos-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: var(--spacing-4);
    margin-top: var(--spacing-6);
}

.photo-item {
    background: var(--card-background);
    border-radius: var(--radius);
    padding: var(--spacing-4);
    text-align: center;
    transition: transform 0.3s ease;
}

.photo-item:hover {
    transform: translateY(-2px);
}

.photo-item img {
    width: 100%;
    height: 120px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    margin-bottom: var(--spacing-2);
}

.photo-item .timestamp {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: var(--spacing-2);
}

/* Toast Container */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    pointer-events: none;
    width: 320px;
}

@media (max-width: 768px) {
    .toast-container {
        top: 10px;
        right: 10px;
        left: 10px;
        width: auto;
    }
}

/* Toast Styles */
.toast {
    background: var(--card-background);
    border-radius: var(--radius);
    padding: var(--spacing-4);
    margin-bottom: var(--spacing-2);
    box-shadow: var(--shadow-lg);
    border-left: 4px solid;
    pointer-events: auto;
    position: relative;
    overflow: hidden;
    transform: translateX(100%);
    opacity: 0;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    font-weight: 500;
    font-size: 0.9rem;
    line-height: 1.4;
    max-width: 100%;
    word-wrap: break-word;
}

.toast.show {
    transform: translateX(0);
    opacity: 1;
}

.toast.hide {
    transform: translateX(100%);
    opacity: 0;
}

.toast.success {
    border-left-color: var(--accent-blue);
    color: var(--text-primary);
}

.toast.success::before {
    content: '✅';
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 1.1rem;
}

.toast.error {
    border-left-color: var(--accent-red);
    color: var(--text-primary);
}

.toast.error::before {
    content: '❌';
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 1.1rem;
}

.toast-content {
    margin-left: 28px;
    padding-right: 20px;
}

.toast-close {
    position: absolute;
    top: 8px;
    right: 8px;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1.2rem;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
}

.toast-close:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

/* Progress bar for auto-dismiss */
.toast-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 3px;
    background: var(--accent-blue);
    border-radius: 0 0 var(--radius) var(--radius);
    transition: width linear;
    opacity: 0.7;
}

.toast.success .toast-progress {
    background: var(--accent-blue);
}

.toast.error .toast-progress {
    background: var(--accent-red);
}

/* Legacy status styles for backward compatibility */
.status {
    display: none;
}

.hidden {
    display: none;
}

#canvas {
    display: block;
    width: 100%;
    max-width: 640px;
    height: auto;
    border-radius: var(--radius);
    margin: 0 auto;
    position: relative;
}

#canvas.hidden {
    display: none;
}

.filter-section {
    background: var(--card-background);
    border-radius: 16px;
    padding: var(--spacing-6);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.1);
    margin-bottom: var(--spacing-6);
}

/* Filter Dropdown */
.filter-dropdown-container {
    margin-bottom: var(--spacing-4);
    position: relative;
}

.filter-dropdown-container label {
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    display: block;
    font-size: 0.9rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.filter-dropdown {
    width: 100%;
    padding: var(--spacing-4) var(--spacing-6);
    background: linear-gradient(135deg, var(--card-background), var(--background-darker));
    border: 2px solid transparent;
    border-radius: var(--radius-lg);
    color: var(--text-primary);
    font-size: 1rem;
    font-family: inherit;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    appearance: none;
    box-shadow: var(--shadow);
    position: relative;
    background-image: 
        linear-gradient(135deg, var(--card-background), var(--background-darker)),
        url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="%23688db1" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="6,9 12,15 18,9"></polyline></svg>');
    background-repeat: no-repeat, no-repeat;
    background-position: 0 0, right var(--spacing-4) center;
    background-size: 100% 100%, 18px;
    padding-right: calc(var(--spacing-6) + 28px);
}

.filter-dropdown:hover {
    border-color: var(--accent-blue);
    box-shadow: var(--shadow-lg);
    transform: translateY(-1px);
    background-image: 
        linear-gradient(135deg, var(--accent-blue), var(--card-background)),
        url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="%23ffffff" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="6,9 12,15 18,9"></polyline></svg>');
}

.filter-dropdown:focus {
    outline: none;
    border-color: var(--accent-green);
    box-shadow: 
        var(--shadow-lg),
        0 0 0 4px rgba(156, 182, 143, 0.3);
    transform: translateY(-1px);
}

.filter-dropdown:active {
    transform: translateY(0);
    box-shadow: var(--shadow);
}

.filter-dropdown option {
    background: var(--background-dark);
    color: var(--text-primary);
    padding: var(--spacing-3) var(--spacing-4);
    font-size: 1rem;
    font-weight: 500;
    border: none;
    margin: 2px 0;
}

.filter-dropdown option:hover,
.filter-dropdown option:focus {
    background: var(--accent-blue);
    color: white;
}

.filter-dropdown option:checked {
    background: var(--accent-green);
    color: white;
    font-weight: 600;
}

/* Custom dropdown arrow animation */
.filter-dropdown:focus {
    background-image: 
        linear-gradient(135deg, var(--accent-green), var(--card-background)),
        url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="%23ffffff" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="6,15 12,9 18,15"></polyline></svg>');
}

/* Mobile optimizations */
@media (max-width: 768px) {
    .filter-dropdown {
        font-size: 1.1rem;
        padding: var(--spacing-5) var(--spacing-6);
        padding-right: calc(var(--spacing-6) + 32px);
        background-size: 100% 100%, 20px;
    }
    
    .filter-dropdown-container label {
        font-size: 1rem;
    }
}

/* Dark theme enhancements */
@media (prefers-color-scheme: dark) {
    .filter-dropdown {
        background-image: 
            linear-gradient(135deg, rgba(52, 56, 69, 0.9), rgba(37, 40, 48, 0.9)),
            url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="%23688db1" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="6,9 12,15 18,9"></polyline></svg>');
    }
}

/* Filter Target Toggle */
.filter-target-container {
    margin-bottom: var(--spacing-4);
    padding: var(--spacing-4);
    background: rgba(255, 255, 255, 0.02);
    border-radius: var(--radius);
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: all 0.3s ease;
}

.filter-target-container.disabled {
    opacity: 0.4;
    pointer-events: none;
    background: rgba(255, 255, 255, 0.01);
}

.filter-target-label {
    color: var(--text-secondary);
    margin-bottom: var(--spacing-3);
    display: block;
    font-size: 0.9rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.filter-target-toggle {
    position: relative;
}

.toggle-radio {
    display: none;
}

.toggle-labels {
    display: flex;
    background: var(--background-darker);
    border-radius: var(--radius-lg);
    padding: 4px;
    position: relative;
    border: 2px solid transparent;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.toggle-labels:hover {
    background: var(--card-background);
    border-color: var(--accent-blue);
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}

.toggle-option {
    flex: 1;
    text-align: center;
    padding: var(--spacing-3) var(--spacing-2);
    cursor: pointer;
    position: relative;
    z-index: 2;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: var(--radius);
    user-select: none;
}

.toggle-text {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: block;
}

.toggle-slider {
    position: absolute;
    top: 4px;
    left: 4px;
    width: calc(33.33% - 4px);
    height: calc(100% - 8px);
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-blue-light));
    border-radius: var(--radius);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow);
    z-index: 1;
}

/* Active states for each radio button */
.toggle-radio:nth-of-type(1):checked ~ .toggle-labels .toggle-slider {
    left: 4px;
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-blue-light));
}

.toggle-radio:nth-of-type(2):checked ~ .toggle-labels .toggle-slider {
    left: calc(33.33% + 2px);
    background: linear-gradient(135deg, var(--accent-blue-dark), var(--accent-blue));
}

.toggle-radio:nth-of-type(3):checked ~ .toggle-labels .toggle-slider {
    left: calc(66.66% + 2px);
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-red));
}

/* Text color changes for active states */
.toggle-radio:nth-of-type(1):checked ~ .toggle-labels .toggle-option[data-target="person"] .toggle-text,
.toggle-radio:nth-of-type(2):checked ~ .toggle-labels .toggle-option[data-target="background"] .toggle-text,
.toggle-radio:nth-of-type(3):checked ~ .toggle-labels .toggle-option[data-target="whole"] .toggle-text {
    color: white;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

/* Glowing effect based on active state */
.toggle-radio:nth-of-type(1):checked ~ .toggle-labels {
    box-shadow: 0 0 20px rgba(104, 141, 177, 0.3);
}

.toggle-radio:nth-of-type(2):checked ~ .toggle-labels {
    box-shadow: 0 0 20px rgba(156, 182, 143, 0.3);
}

.toggle-radio:nth-of-type(3):checked ~ .toggle-labels {
    box-shadow: 0 0 20px rgba(225, 97, 98, 0.3);
}

/* Mobile optimization */
@media (max-width: 768px) {
    .filter-target-toggle {
        margin-top: var(--spacing-2);
    }
    
    .toggle-label {
        padding: var(--spacing-4);
    }
    
    .toggle-text-person,
    .toggle-text-all {
        font-size: 1rem;
        padding: var(--spacing-3);
    }
}

.filter-controls {
    margin-top: var(--spacing-4);
    display: grid;
    gap: var(--spacing-4);
    grid-template-columns: 1fr;
}

/* Desktop: 2-column layout for compact GUI */
@media (min-width: 769px) {
    .filter-controls {
        grid-template-columns: 1fr 1fr;
        gap: var(--spacing-4) var(--spacing-6);
    }
}

/* Mobile: single column with better spacing */
@media (max-width: 768px) {
    .filter-controls {
        gap: var(--spacing-5);
        padding: 0 var(--spacing-2);
    }
}

.filter-control {
    margin-bottom: var(--spacing-4);
}

.filter-control label {
    display: block;
    margin-bottom: var(--spacing-2);
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.filter-slider {
    width: 100%;
    height: 6px;
    background: var(--background-darker);
    border-radius: 3px;
    outline: none;
    -webkit-appearance: none;
}

.filter-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    background: var(--accent-blue);
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.3s ease;
}

.filter-slider::-webkit-slider-thumb:hover {
    background: #2563eb;
}

.filter-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background: var(--accent-blue);
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

/* Mobile: Larger touch targets for sliders */
@media (max-width: 768px) {
    .filter-slider {
        height: 10px;
        margin: var(--spacing-3) 0;
    }
    
    .filter-slider::-webkit-slider-thumb {
        width: 26px;
        height: 26px;
    }
    
    .filter-slider::-moz-range-thumb {
        width: 26px;
        height: 26px;
    }
    
    .filter-control {
        margin-bottom: var(--spacing-5);
    }
    
    .filter-control label {
        font-size: 1rem;
        margin-bottom: var(--spacing-2);
        display: block;
    }
}

.filter-value {
    display: inline-block;
    margin-left: var(--spacing-2);
    color: var(--accent-blue);
    font-weight: 600;
    min-width: 40px;
}

.background-section {
    background: var(--card-background);
    border-radius: 16px;
    padding: var(--spacing-6);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.1);
    margin-bottom: var(--spacing-6);
}

.background-options {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: var(--spacing-4);
    margin-bottom: var(--spacing-4);
}

@media (max-width: 768px) {
    .background-options {
        grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
        gap: var(--spacing-2);
        padding: 0 var(--spacing-2);
    }
}

.background-option {
    background: var(--background-darker);
    border: 2px solid transparent;
    border-radius: var(--radius);
    padding: var(--spacing-4);
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
}

.background-option:hover {
    border-color: var(--accent-blue);
    transform: translateY(-2px);
}

.background-option.active {
    border-color: var(--accent-blue);
    background: rgba(59, 130, 246, 0.2);
}

.background-option-icon {
    font-size: 2rem;
    margin-bottom: var(--spacing-2);
}

.upload-section {
    margin-top: var(--spacing-4);
    padding: var(--spacing-4);
    background: var(--background-darker);
    border-radius: var(--radius);
    text-align: center;
}

#backgroundUpload {
    display: none;
}

.upload-btn {
    display: inline-flex;
    align-items: center;
    gap: var(--spacing-2);
    padding: 0.75rem 1.5rem;
    background: var(--accent-blue);
    color: white;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.2);
}

.upload-btn:hover {
    background: #2563eb;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.background-presets {
    margin-bottom: var(--spacing-4);
}

.preset-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: var(--spacing-3);
    margin-bottom: var(--spacing-4);
}

.preset-item {
    background: var(--surface);
    border-radius: var(--radius);
    padding: var(--spacing-2);
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 2px solid transparent;
}

.preset-item:hover {
    background: var(--surface-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.preset-item.active {
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.2);
}

.preset-item img {
    width: 100%;
    height: 60px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    margin-bottom: var(--spacing-2);
}

.preset-item span {
    font-size: 0.875rem;
    color: var(--text-secondary);
    display: block;
}

.custom-upload {
    margin-bottom: var(--spacing-4);
    padding-top: var(--spacing-4);
    border-top: 1px solid var(--border);
}

.background-preview {
    margin-top: var(--spacing-4);
    display: none;
}

.background-preview img {
    max-width: 200px;
    max-height: 150px;
    border-radius: var(--radius);
    border: 2px solid var(--accent-blue);
}

#hiddenVideo {
    display: none;
}

@media (max-width: 768px) {
    .container {
        padding: var(--spacing-2);
    }

    h1 {
        font-size: 2rem;
    }

    .controls {
        flex-direction: column;
        align-items: center;
    }

    .btn {
        width: 100%;
        max-width: 300px;
    }
}

/* Footer */
.footer {
    text-align: center;
    padding: var(--spacing-4);
    background: var(--background-darker);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    width: 100%;
    position: sticky;
    bottom: 0;
    margin-top: auto;
}

.footer p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin: 0;
    font-weight: 500;
}

@keyframes heartbeat {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}