/* ================================
   Face Morph Pro - Snapchat Style UI
   ================================ */

:root {
    /* Snapchat Color Palette */
    --bg-primary: #000000;
    --bg-secondary: #1c1c1e;
    --bg-tertiary: #2c2c2e;
    --bg-glass: rgba(28, 28, 30, 0.9);
    --bg-glass-light: rgba(60, 60, 67, 0.6);

    --accent-yellow: #FFFC00;
    --accent-blue: #00AEFF;
    --accent-pink: #FF6B9D;
    --accent-purple: #A855F7;

    --text-primary: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.7);
    --text-muted: rgba(255, 255, 255, 0.4);

    --success: #34C759;
    --danger: #FF3B30;
    --warning: #FF9500;

    --border-color: rgba(255, 255, 255, 0.1);

    /* Sizing */
    --bottom-nav-height: 60px;
    --border-radius: 16px;
    --border-radius-sm: 12px;
    --border-radius-full: 9999px;

    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-bounce: 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

/* ================================
   Base Styles
   ================================ */

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

html,
body {
    height: 100%;
    overflow: hidden;
    touch-action: manipulation;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.4;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    user-select: none;
}

/* ================================
   App Container
   ================================ */

.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    width: 100vw;
    overflow: hidden;
    background: transparent;
    position: relative;
}

/* ================================
   Camera View (Full Screen)
   ================================ */

.camera-view {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000;
    overflow: hidden;
}

#video {
    position: absolute;
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0;
}

#outputCanvas {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* ================================
   Top Bar
   ================================ */

.top-bar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    padding: 12px 16px;
    padding-top: max(12px, env(safe-area-inset-top));
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 50;
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0.5) 0%, transparent 100%);
}

.top-left,
.top-right {
    display: flex;
    gap: 10px;
    align-items: center;
}

.user-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.icon-btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: none;
    border-radius: var(--border-radius-full);
    color: var(--text-primary);
    cursor: pointer;
    transition: all var(--transition-fast);
    position: relative;
}

.icon-btn svg {
    width: 22px;
    height: 22px;
}

.icon-btn:hover {
    transform: scale(1.05);
    background: var(--bg-glass-light);
}

.icon-btn:active {
    transform: scale(0.95);
}

.profile-btn {
    background: linear-gradient(135deg, var(--accent-purple), var(--accent-pink));
}

.scan-btn-top.scanning {
    animation: pulse-glow 1s infinite;
}

@keyframes pulse-glow {

    0%,
    100% {
        box-shadow: 0 0 10px rgba(255, 252, 0, 0.5);
    }

    50% {
        box-shadow: 0 0 25px rgba(255, 252, 0, 0.8);
    }
}

.scan-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    background: var(--accent-yellow);
    color: #000;
    font-size: 10px;
    font-weight: 700;
    border-radius: var(--border-radius-full);
    display: none;
    align-items: center;
    justify-content: center;
}

.scan-badge.visible {
    display: flex;
}

/* ================================
   Morph Slider (Top)
   ================================ */

.morph-slider-container {
    position: absolute;
    top: 70px;
    left: 16px;
    right: 16px;
    padding: 12px 16px;
    background: transparent;
    z-index: 40;
}

.slider-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.slider-label {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 1px;
    color: var(--text-secondary);
}

.slider-value {
    font-size: 14px;
    font-weight: 700;
    color: var(--accent-yellow);
}

.morph-slider {
    width: 100%;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--bg-tertiary);
    border-radius: 3px;
    outline: none;
    cursor: pointer;
}

.morph-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 24px;
    height: 24px;
    background: linear-gradient(135deg, var(--accent-yellow), #FFD700);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 10px rgba(255, 252, 0, 0.4);
    transition: transform var(--transition-fast);
}

.morph-slider::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

.morph-slider::-moz-range-thumb {
    width: 24px;
    height: 24px;
    background: linear-gradient(135deg, var(--accent-yellow), #FFD700);
    border-radius: 50%;
    border: none;
    cursor: pointer;
    box-shadow: 0 2px 10px rgba(255, 252, 0, 0.4);
}

/* ================================
   Right Side Tools
   ================================ */

.right-tools {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: 12px;
    z-index: 50;
}

.tool-btn {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: none;
    border-radius: var(--border-radius-sm);
    color: var(--text-primary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.tool-btn svg {
    width: 24px;
    height: 24px;
}

.tool-btn:hover {
    background: var(--bg-glass-light);
    transform: scale(1.05);
}

.tool-btn:active {
    transform: scale(0.95);
}

.tool-btn.active {
    background: var(--accent-yellow);
    color: #000;
}

/* ================================
   Effects Panel
   ================================ */

.effects-panel {
    position: absolute;
    right: 70px;
    top: 50%;
    transform: translateY(-50%);
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: var(--border-radius);
    padding: 12px;
    z-index: 45;
    transition: all var(--transition-normal);
}

.effects-panel.hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateY(-50%) translateX(20px);
}

.effects-header {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.effects-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.effect-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    color: var(--text-primary);
    cursor: pointer;
    transition: all var(--transition-fast);
    min-width: 120px;
}

.effect-btn:hover {
    background: var(--bg-glass-light);
    border-color: var(--text-muted);
}

.effect-btn.active {
    background: var(--accent-yellow);
    color: #000;
    border-color: var(--accent-yellow);
}

.effect-preview {
    width: 24px;
    height: 24px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
}

.none-preview {
    background: linear-gradient(135deg, #333 50%, #666 50%);
}

.purple-preview {
    background: linear-gradient(135deg, #6B21A8, #A855F7, #C084FC);
}

.bw-preview {
    background: linear-gradient(135deg, #000, #888, #fff);
}

/* ================================
   Status Overlay
   ================================ */

.status-overlay {
    position: absolute;
    bottom: 120px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 50;
    opacity: 0;
    transition: opacity var(--transition-fast);
    pointer-events: none;
}

.status-overlay.visible {
    opacity: 1;
}

.status-text {
    display: inline-block;
    padding: 10px 20px;
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: var(--border-radius-full);
    font-size: 14px;
    font-weight: 500;
    color: var(--success);
    border: 1px solid rgba(52, 199, 89, 0.3);
}

.status-text.error {
    color: var(--danger);
    border-color: rgba(255, 59, 48, 0.3);
}

/* ================================
   Loading Overlay
   ================================ */

.loading-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    background: var(--bg-primary);
    z-index: 100;
    transition: opacity var(--transition-normal);
}

.loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.loader {
    width: 48px;
    height: 48px;
    border: 3px solid var(--bg-tertiary);
    border-top-color: var(--accent-yellow);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.loading-overlay span {
    color: var(--text-secondary);
    font-size: 14px;
}

/* ================================
   No Face Warning
   ================================ */

.no-face-warning {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    padding: 12px 24px;
    background: rgba(255, 149, 0, 0.15);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--warning);
    border-radius: var(--border-radius-full);
    color: var(--warning);
    font-size: 14px;
    font-weight: 500;
    opacity: 0;
    transition: opacity var(--transition-normal);
    pointer-events: none;
}

.no-face-warning.visible {
    opacity: 1;
}

/* ================================
   Scan Result Display
   ================================ */

.scan-result-display {
    position: absolute;
    top: 140px;
    left: 50%;
    transform: translateX(-50%);
    padding: 10px 20px;
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: var(--border-radius-full);
    z-index: 45;
    transition: all var(--transition-normal);
}

.scan-result-display.hidden {
    opacity: 0;
    pointer-events: none;
}

.scan-result-content {
    display: flex;
    gap: 15px;
    align-items: center;
}

.scan-gender {
    font-size: 20px;
    font-weight: 700;
    color: var(--accent-yellow);
}

.scan-age {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
}

/* ================================
   Bottom Section
   ================================ */

.bottom-section {
    position: absolute;
    bottom: 60px;
    left: 0;
    right: 0;
    background: transparent;
    padding: 12px 0 8px 0;
    z-index: 30;
}

/* ================================
   Filter Carousel
   ================================ */

.filter-carousel-container {
    padding: 0 12px;
}

.filter-carousel {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    scroll-behavior: smooth;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    padding: 4px;
}

.filter-carousel::-webkit-scrollbar {
    display: none;
}

.filter-item {
    flex-shrink: 0;
    width: 60px;
    height: 60px;
    border-radius: var(--border-radius-full);
    overflow: hidden;
    cursor: pointer;
    border: 3px solid transparent;
    transition: all var(--transition-bounce);
    background: var(--bg-tertiary);
    position: relative;
}

.filter-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform var(--transition-normal);
}

.filter-item:hover {
    transform: scale(1.05);
    border-color: var(--text-muted);
}

.filter-item:active {
    transform: scale(0.95);
}

.filter-item.active {
    border-color: var(--accent-yellow);
    box-shadow: 0 0 20px rgba(255, 252, 0, 0.5);
    transform: scale(1.1);
}

.filter-item.recording {
    border-color: var(--danger);
    box-shadow: 0 0 20px rgba(255, 59, 48, 0.6);
    animation: recording-pulse 1s infinite;
}

.filter-item.addon-item::after {
    content: '✨';
    position: absolute;
    bottom: 2px;
    right: 2px;
    font-size: 12px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

@keyframes recording-pulse {

    0%,
    100% {
        box-shadow: 0 0 15px rgba(255, 59, 48, 0.5);
    }

    50% {
        box-shadow: 0 0 30px rgba(255, 59, 48, 0.8);
    }
}

/* ================================
   Capture Hint
   ================================ */

.capture-hint {
    text-align: center;
    padding: 8px 0 4px 0;
    font-size: 11px;
    color: var(--text-muted);
}

/* ================================
   Bottom Navigation
   ================================ */

.bottom-nav {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-around;
    align-items: center;
    height: var(--bottom-nav-height);
    background: transparent;
    padding: 0 8px;
    padding-bottom: max(4px, env(safe-area-inset-bottom));
    z-index: 30;
}

.nav-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 6px 4px;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.nav-icon {
    font-size: 22px;
    line-height: 1;
}

.nav-label {
    font-size: 9px;
    font-weight: 500;
    letter-spacing: 0.3px;
}

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

.nav-btn.active {
    color: var(--text-primary);
}

.nav-btn.active .nav-label {
    color: var(--accent-yellow);
}

/* ================================
   Profile Modal
   ================================ */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 20px;
    transition: all var(--transition-normal);
}

.modal-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: var(--border-radius);
    width: 100%;
    max-width: 360px;
    overflow: hidden;
    transform: scale(1);
    transition: transform var(--transition-normal);
}

.modal-overlay.hidden .modal-content {
    transform: scale(0.9);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
    font-size: 18px;
    font-weight: 600;
}

.modal-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
    border: none;
    border-radius: var(--border-radius-full);
    color: var(--text-secondary);
    font-size: 20px;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.modal-close:hover {
    background: var(--bg-glass-light);
    color: var(--text-primary);
}

.modal-body {
    padding: 20px;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.form-group input {
    width: 100%;
    padding: 12px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    transition: all var(--transition-fast);
}

.form-group input:focus {
    outline: none;
    border-color: var(--accent-yellow);
    box-shadow: 0 0 0 3px rgba(255, 252, 0, 0.1);
}

.form-group input::placeholder {
    color: var(--text-muted);
}

.profile-avatar {
    width: 80px;
    height: 80px;
    margin: 20px auto 0;
    border-radius: var(--border-radius-full);
    background: linear-gradient(135deg, var(--accent-purple), var(--accent-pink));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    font-weight: 700;
    color: white;
}

.modal-footer {
    display: flex;
    gap: 10px;
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
}

.btn-primary,
.btn-secondary {
    flex: 1;
    padding: 12px 16px;
    border: none;
    border-radius: var(--border-radius-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-primary {
    background: var(--accent-yellow);
    color: #000;
}

.btn-primary:hover {
    background: #FFD700;
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

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

/* ================================
   Gallery Button & Badge
   ================================ */

.gallery-btn {
    background: var(--bg-glass);
}

.gallery-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    background: var(--accent-yellow);
    color: #000;
    font-size: 10px;
    font-weight: 700;
    border-radius: var(--border-radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
}

.gallery-badge:empty,
.gallery-badge[data-count="0"] {
    display: none;
}

/* ================================
   Gallery Modal
   ================================ */

.gallery-modal-content {
    max-width: 500px;
    max-height: 80vh;
}

.gallery-body {
    min-height: 200px;
    max-height: 400px;
    overflow-y: auto;
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.gallery-item {
    aspect-ratio: 1;
    border-radius: var(--border-radius-sm);
    overflow: hidden;
    position: relative;
    background: var(--bg-tertiary);
    cursor: pointer;
}

.gallery-item img,
.gallery-item video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.gallery-item .video-badge {
    position: absolute;
    bottom: 4px;
    right: 4px;
    background: var(--bg-glass);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 10px;
    color: white;
}

.gallery-item .delete-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 24px;
    height: 24px;
    background: rgba(255, 59, 48, 0.9);
    border: none;
    border-radius: 50%;
    color: white;
    font-size: 14px;
    cursor: pointer;
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.gallery-item:hover .delete-btn {
    opacity: 1;
}

.gallery-empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

.gallery-empty span {
    font-size: 48px;
    display: block;
    margin-bottom: 10px;
}

.gallery-empty p {
    margin: 5px 0;
}

.gallery-hint {
    font-size: 12px;
}

/* ================================
   Utility Classes
   ================================ */

.hidden {
    display: none !important;
}

/* ================================
   Responsive
   ================================ */

@media (max-width: 360px) {
    .filter-item {
        width: 52px;
        height: 52px;
    }

    .morph-slider-container {
        left: 12px;
        right: 12px;
        padding: 10px 14px;
    }
}

@media (max-height: 600px) {
    .morph-slider-container {
        top: 60px;
        padding: 8px 14px;
    }

    .slider-header {
        margin-bottom: 4px;
    }
}