/* Reset y estilos base */
/* * {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: #000;
    min-height: 100vh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

#app {
    position: relative;
    height: 100vh;
    width: 100vw;
} */

/* Contenedor de video */
#video-container {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 5;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f3ecdf;
    overflow: hidden;
}

#input-video {
    display: none; /* Video fuente oculto */
}

#output-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    z-index: 1;
    transform: scaleX(-1);  /* Espejo horizontal para cámara frontal */
}

#captured-photo-preview {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    pointer-events: none;
    z-index: 3;
    transition: opacity 220ms ease;
}

#captured-photo-preview.is-visible {
    opacity: 1;
}

#video-container.frozen #output-canvas,
#video-container.frozen a-scene {
    opacity: 0 !important;
    visibility: hidden !important;
}

/* A-Frame scene para filtros 3D */
a-scene {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    pointer-events: none !important;
    z-index: 2 !important;
    transform: scaleX(-1) !important;  /* Espejo horizontal para coincidir con canvas */
    transition: opacity 220ms ease;
}

a-scene canvas {
    background: transparent !important;
}

/* Ocultar diálogos y overlays de A-Frame */
.a-dialog,
.a-orientation-modal,
.a-enter-vr-button,
.a-enter-ar-button,
.a-loader-title {
    display: none !important;
}

/* Selector de filtros AR - Derecha */
#filter-selector {
    position: fixed;
    right: 40px;
    top: 12%;
    transform: none;
    display: flex;
    flex-direction: column;
    gap: 15px;
    z-index: 100;
}

#app.filters-hidden #filter-selector {
    opacity: 0;
    pointer-events: none;
}

.filter-btn {
    width: 70px;
    height: 70px;
    /* border-radius: 50%; */ /* QUITADO: Ya no son redondos */
    border: none; /* QUITADO: Sin bordes */
    background: transparent; /* QUITADO: Fondo transparente */
    cursor: pointer;
    transition: all 0.3s ease;
    /* overflow: hidden; */ /* QUITADO: Para que no recorte si la imagen es irregular */
    position: relative;
    box-shadow: none; /* QUITADO: Sin sombra por defecto */
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.filter-btn img {
    /* width: 100%; */
    /* height: 100%; */
    max-width: 100%;
    max-height: 100%;
    object-fit: contain; /* IMPORTANTE: Que la imagen se vea entera sin recortar */
    pointer-events: none; /* Evitar que la imagen capture clicks */
}

.filter-btn:hover {
    transform: scale(1.1);
    /* border-color: rgba(102, 126, 234, 0.8); */
}

.filter-btn.active {
    /* border-color: #667eea; */
    /* border-width: 4px; */
    /* box-shadow: 0 0 20px rgba(102, 126, 234, 0.6); */
    transform: scale(1.2); /* Solo hacer un poco más grande al activar */
}

.filter-btn.none {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 30px;
}

/* Botón de captura - Centro abajo */
.capture-btn {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    width: 80px;
    height: 80px;
    border-radius: 50%;
    border: 4px solid white;
    background: transparent;
    cursor: pointer;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
    transition: all 0.2s ease;
}

.capture-btn .inner-circle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: white;
    transition: all 0.2s ease;
}

.capture-btn:active {
    transform: translateX(-50%) scale(0.95);
}

.capture-btn:active .inner-circle {
    transform: scale(0.85);
}

/* Botón de iniciar cámara */
.btn-primary {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    padding: 20px 40px;
    border: none;
    border-radius: 12px;
    font-size: 18px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
    z-index: 101;
    transition: all 0.3s ease;
}

.btn-primary:hover {
    transform: translate(-50%, -50%) scale(1.05);
}

.btn-primary:active {
    transform: translate(-50%, -50%) scale(0.98);
}

.btn-primary.hidden {
    display: none;
}

.icon {
    font-size: 24px;
}

#toggle-controls:active {
    transform: scale(0.95);
}

#toggle-controls .icon {
    transition: transform 0.3s ease;
}

#toggle-controls.controls-hidden .icon {
    transform: rotate(180deg);
}

/* Panel de controles */
#controls {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    padding: 15px;
    max-height: 40vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.1);
    z-index: 100;
    transition: transform 0.4s ease, opacity 0.3s ease;
    transform: translateY(0);
    opacity: 1;
}

#controls.controls-closed {
    transform: translateY(100%);
    opacity: 0;
    pointer-events: none;
}
.control-group {
    margin-bottom: 15px;
}

.control-group label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: #333;
    margin-bottom: 8px;
}

/* Botones */
.btn {
    width: 100%;
    padding: 14px 20px;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.3s ease;
    -webkit-tap-highlight-color: transparent;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

.btn-primary:active {
    transform: scale(0.98);
    box-shadow: 0 2px 10px rgba(102, 126, 234, 0.4);
}

.btn-primary.active {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

.btn-secondary {
    background: #fff;
    color: #667eea;
    border: 2px solid #667eea;
}

.btn-secondary:active {
    transform: scale(0.98);
    background: #f7f7f7;
}

.icon {
    font-size: 20px;
}

/* Switch toggle */
.switch-label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    user-select: none;
}

.switch-label input[type="checkbox"] {
    width: 50px;
    height: 28px;
    appearance: none;
    background: #ddd;
    border-radius: 14px;
    position: relative;
    cursor: pointer;
    transition: background 0.3s;
}

.switch-label input[type="checkbox"]:checked {
    background: #667eea;
}

.switch-label input[type="checkbox"]::before {
    content: '';
    position: absolute;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: white;
    top: 2px;
    left: 2px;
    transition: left 0.3s;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.switch-label input[type="checkbox"]:checked::before {
    left: 24px;
}

.switch-label span {
    font-size: 14px;
    font-weight: 600;
    color: #333;
}

/* Inputs */
input[type="color"] {
    width: 100%;
    height: 50px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
}

input[type="file"] {
    width: 100%;
    padding: 10px;
    border: 2px dashed #667eea;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    background: #f7f7f7;
}

input[type="file"]::-webkit-file-upload-button {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    background: #667eea;
    color: white;
    cursor: pointer;
    margin-right: 10px;
}

select {
    width: 100%;
    padding: 12px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
    background: white;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 16px;
    padding-right: 40px;
}

select:focus {
    outline: none;
    border-color: #667eea;
}

/* Background options */
#background-options {
    padding: 15px;
    background: #f7f7f7;
    border-radius: 8px;
    margin-top: 10px;
}

#background-options label {
    margin-top: 10px;
}

#background-options label:first-child {
    margin-top: 0;
}

/* Galería de fondos y filtros */
.gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 10px;
    margin-bottom: 15px;
}

.gallery-item {
    position: relative;
    aspect-ratio: 4/3;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    border: 3px solid transparent;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    background: #f0f0f0;
}

.gallery-item:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.gallery-item.active {
    border-color: #667eea;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.3);
}

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

.gallery-item .gradient-preview,
.gallery-item .color-preview {
    width: 100%;
    flex: 1;
}

.gallery-item span {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 4px;
    font-size: 10px;
    text-align: center;
    font-weight: 500;
}


/* Loading indicator */
.loading {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.loading p {
    color: white;
    margin-top: 20px;
    font-size: 16px;
}

.spinner {
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top: 4px solid white;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
}

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

/* Error message */
.error {
    position: absolute;
    top: 20px;
    left: 50%;
    background: rgba(255, 68, 68, 0.95);
    color: white;
    padding: 12px 20px;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    z-index: 1001;
    max-width: 80%;
    text-align: center;
    font-size: 14px;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

/* Responsive */
@media (max-width: 768px) {
    #filter-selector {
        right: 30px;
        top: 24%;
        gap: 10px;
    }
    
    .filter-btn {
        width: 60px;
        height: 60px;
    }
    
    .capture-btn {
        width: 70px;
        height: 70px;
        font-size: 30px;
        bottom: 20px;
    }
    
    .btn-primary {
        font-size: 16px;
        padding: 15px 30px;
    }
}

@media (max-height: 600px) {
    #filter-selector {
        gap: 8px;
    }
    
    .filter-btn {
        width: 50px;
        height: 50px;
    }
}

.loading p {
    margin-top: 20px;
    font-size: 16px;
}

/* Error message */
.error {
    position: fixed;
    bottom: 20px;
    left: 20px;
    right: 20px;
    padding: 15px 20px;
    background: #ff4444;
    color: white;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 4px 20px rgba(255, 68, 68, 0.4);
    z-index: 1001;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        transform: translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Responsive adjustments */
@media (min-width: 768px) {
    #app {
        flex-direction: row;
    }

    #controls {
        max-width: 350px;
        max-height: 100vh;
        box-shadow: -4px 0 20px rgba(0, 0, 0, 0.1);
    }

    #video-container {
        flex: 1;
    }
}

/* Landscape mobile optimization */
@media (max-height: 500px) and (orientation: landscape) {
    #controls {
        max-height: 100vh;
    }

    .control-group {
        margin-bottom: 10px;
    }

    .btn {
        padding: 10px 16px;
        font-size: 14px;
    }
}

/* Estilos para iframe */
body.embedded {
    background: #000;
}

body.embedded #app {
    background: transparent;
}
