/* Start custom CSS for html, class: .elementor-element-b601409 */// Función para cargar un modelo 3D en la escena de Realidad Virtual
function loadVRModel() {
    const fileInput = document.getElementById('vr-model-upload');
    const sceneNameInput = document.getElementById('vr-scene-name');
    const file = fileInput.files[0];
    const sceneName = sceneNameInput.value.trim();

    if (!file) {
        alert('Por favor, selecciona un archivo GLB/GLTF para tu escena de RV.');
        return;
    }
    if (!sceneName) {
        alert('Por favor, ingresa un nombre para tu escena de RV.');
        return;
    }

    const reader = new FileReader();
    reader.onload = function(e) {
        const modelUrl = e.target.result; // Data URL del archivo
        const vrScene = document.getElementById('vr-scene-container');

        // Eliminar cualquier modelo 3D previamente cargado
        const oldModel = vrScene.querySelector('a-entity[gltf-model]');
        if (oldModel) {
            oldModel.parentNode.removeChild(oldModel);
        }

        // Crear un nuevo elemento para el modelo GLTF
        const newModel = document.createElement('a-entity');
        newModel.setAttribute('gltf-model', modelUrl);
        // Ajusta la posición y escala según sea necesario para que el modelo sea visible
        newModel.setAttribute('position', '0 1 -3');
        newModel.setAttribute('scale', '1 1 1');

        vrScene.appendChild(newModel);
        console.log(`Escena RV "${sceneName}" cargada con modelo:`, modelUrl);
        alert(`¡Tu escena de RV "${sceneName}" está lista para previsualizar!`);

        // En un sitio real, aquí guardarías la escena y el modelo en una base de datos
        // y podrías añadirla a la galería.
    };
    reader.readAsDataURL(file); // Lee el archivo como una URL de datos
}

// Función para simular la generación de una experiencia de Realidad Aumentada
function generateARExperience() {
    const markerFileInput = document.getElementById('ar-marker-upload');
    const modelFileInput = document.getElementById('ar-model-upload');
    const artworkNameInput = document.getElementById('ar-artwork-name');

    const markerFile = markerFileInput.files[0];
    const modelFile = modelFileInput.files[0];
    const artworkName = artworkNameInput.value.trim();

    if (!markerFile) {
        alert('Por favor, sube una imagen para el marcador AR.');
        return;
    }
    if (!modelFile) {
        alert('Por favor, sube un modelo 3D para tu obra AR.');
        return;
    }
    if (!artworkName) {
        alert('Por favor, dale un nombre a tu obra AR.');
        return;
    }

    // --- Aquí es donde la LÓGICA DE BACKEND sería CRÍTICA ---
    // En un sitio real, los archivos (imagen marcador y modelo 3D) se enviarían a un servidor.
    // 1. El servidor procesaría la imagen del marcador para generar un archivo de patrón AR.js (.patt).
    // 2. El servidor almacenaría el modelo 3D y el archivo .patt.
    // 3. El servidor devolvería las URLs de estos archivos al cliente.
    // --------------------------------------------------------

    alert(`Simulando la generación de "${artworkName}". En un sitio real, esta acción se procesaría en el servidor.`);

    const arScene = document.getElementById('ar-scene-container');
    const arMarkerDisplay = document.getElementById('ar-marker-display');

    // Simular la carga del marcador y el modelo en la escena AR.js
    const readerMarker = new FileReader();
    readerMarker.onload = function(eMarker) {
        const markerImgUrl = eMarker.target.result; // URL de la imagen del marcador

        // Mostrar la imagen del marcador para que el usuario pueda escanearla
        arMarkerDisplay.innerHTML = `
            <h4>Escanea este marcador con la cámara de tu celular:</h4>
            <img src="${markerImgUrl}" alt="Marcador AR" style="max-width: 250px; border: 2px solid #1abc9c; border-radius: 8px; margin-top: 15px;">
            <p>Asegúrate de que tu cámara apunte al marcador y permite el acceso a la cámara si se te pide.</p>
        `;

        const readerModel = new FileReader();
        readerModel.onload = function(eModel) {
            const modelUrl = eModel.target.result; // URL del modelo 3D

            // Remover cualquier marcador y modelo previos en la escena AR
            const oldMarker = arScene.querySelector('a-marker');
            if (oldMarker) {
                oldMarker.parentNode.removeChild(oldMarker);
            }

            // Crear un nuevo marcador dinámicamente
            const newMarker = document.createElement('a-marker');
            // Para un marcador personalizado, necesitarías 'type: pattern' y 'url: [URL_DEL_PATRON.patt]'
            // Aquí usamos 'preset: hiro' como ejemplo, ya que generar un .patt requiere backend.
            newMarker.setAttribute('preset', 'hiro'); // Necesitarías que tu backend genere un patrón real

            // Crear el modelo 3D para la RA
            const newModel = document.createElement('a-entity');
            newModel.setAttribute('gltf-model', modelUrl);
            newModel.setAttribute('position', '0 0.5 0'); // Posición sobre el marcador
            newModel.setAttribute('scale', '0.5 0.5 0.5'); // Escala del modelo

            newMarker.appendChild(newModel);
            arScene.appendChild(newMarker);

            console.log(`Obra AR "${artworkName}" preparada.`);
            alert(`¡Obra AR "${artworkName}" generada! Ahora escanea la imagen del marcador con tu celular.`);
        };
        readerModel.readAsDataURL(modelFile);
    };
    readerMarker.readAsDataURL(markerFile);

    // En un sitio real, después de que el backend procese,
    // añadirías la obra a la galería si aplica.
}

// Lógica para el smooth scroll de la navegación
document.querySelectorAll('nav a').forEach(anchor => {
    anchor.addEventListener('click', function (e) {
        e.preventDefault();

        document.querySelector(this.getAttribute('href')).scrollIntoView({
            behavior: 'smooth'
        });
    });
});

// Puedes añadir más funciones aquí para la galería, guardar proyectos, etc./* General Body Styles */
body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    margin: 0;
    padding: 0;
    background-color: #eef2f7; /* Light blue-grey background */
    color: #333;
    line-height: 1.6;
}

/* Header Styles */
header {
    background-color: #2c3e50; /* Dark blue-grey */
    color: white;
    padding: 1.5rem 0;
    text-align: center;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

header h1 {
    margin: 0;
    font-size: 2.8em;
    letter-spacing: 1.5px;
}

header p {
    font-size: 1.1em;
    margin-top: 5px;
    opacity: 0.9;
}

/* Navigation Styles */
nav {
    background-color: #34495e; /* Slightly lighter dark blue-grey */
    text-align: center;
    padding: 0.8rem 0;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    position: sticky;
    top: 0;
    z-index: 1000;
}

nav a {
    color: white;
    text-decoration: none;
    padding: 0.8rem 1.5rem;
    display: inline-block;
    transition: background-color 0.3s ease, color 0.3s ease;
    font-weight: bold;
}

nav a:hover {
    background-color: #1abc9c; /* Teal */
    color: white;
}

/* Container for Main Content */
.container {
    max-width: 1200px;
    margin: 30px auto;
    padding: 20px;
    background-color: white;
    border-radius: 10px;
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.1);
}

/* Section Styling */
.section-content {
    padding: 40px 0;
    border-bottom: 1px solid #eee;
}

.section-content:last-child {
    border-bottom: none;
}

.section-content h2 {
    color: #2c3e50; /* Dark blue-grey */
    font-size: 2.2em;
    margin-bottom: 20px;
    text-align: center;
    position: relative;
    padding-bottom: 10px;
}

.section-content h2::after {
    content: '';
    position: absolute;
    left: 50%;
    bottom: 0;
    transform: translateX(-50%);
    width: 80px;
    height: 3px;
    background-color: #1abc9c; /* Teal */
    border-radius: 2px;
}

/* Hero Section */
.hero {
    text-align: center;
    background-color: #f7f9fb;
    border-radius: 8px;
    padding: 50px 20px;
    margin-bottom: 30px;
}

.hero h2 {
    color: #1abc9c; /* Teal */
    font-size: 2.8em;
}

.hero p {
    font-size: 1.2em;
    max-width: 800px;
    margin: 20px auto 30px auto;
}

.call-to-action .button {
    margin: 0 15px;
}

/* Button Styles */
.button {
    display: inline-block;
    background-color: #1abc9c; /* Teal */
    color: white;
    padding: 12px 25px;
    border: none;
    border-radius: 5px;
    text-decoration: none;
    font-size: 1.1em;
    cursor: pointer;
    transition: background-color 0.3s ease, transform 0.2s ease;
}

.button:hover {
    background-color: #16a085; /* Darker teal */
    transform: translateY(-2px);
}

.button.small {
    padding: 8px 15px;
    font-size: 0.9em;
}

/* Form Styles */
.creation-form, .contact-form {
    display: flex;
    flex-direction: column;
    gap: 15px;
    max-width: 600px;
    margin: 30px auto;
    padding: 25px;
    background-color: #fcfcfc;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
}

.creation-form label, .contact-form label {
    font-weight: bold;
    color: #555;
    margin-bottom: 5px;
}

.creation-form input[type="file"],
.creation-form input[type="text"],
.creation-form textarea,
.contact-form input[type="text"],
.contact-form input[type="email"],
.contact-form textarea {
    padding: 12px;
    border: 1px solid #ccc;
    border-radius: 5px;
    font-size: 1em;
    width: calc(100% - 24px); /* Account for padding */
}

.creation-form button, .contact-form button {
    align-self: flex-start; /* Align button to the left */
    margin-top: 10px;
}

/* VR/AR Scene Containers */
#vr-scene-container, #ar-scene-container {
    width: 100%;
    height: 500px; /* Adjust height as needed */
    background-color: #eee;
    border: 1px solid #ccc;
    border-radius: 8px;
    margin-top: 25px;
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.05);
}

#vr-preview, #ar-preview {
    margin-top: 40px;
    text-align: center;
}

#vr-preview h3, #ar-preview h3 {
    color: #2c3e50;
    margin-bottom: 15px;
}

.hint {
    font-style: italic;
    color: #777;
    margin-top: 15px;
    font-size: 0.9em;
}

/* Gallery Grid */
.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 30px;
    padding: 20px;
}

.gallery-item {
    background-color: #fefefe;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    text-align: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.gallery-item:hover {
    transform: translateY(-5px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.15);
}

.gallery-item img {
    width: 100%;
    height: 180px;
    object-fit: cover;
    border-bottom: 1px solid #eee;
}

.gallery-item h3 {
    color: #2c3e50;
    font-size: 1.4em;
    margin: 15px 10px 5px 10px;
}

.gallery-item p {
    color: #666;
    font-size: 0.9em;
    margin: 0 10px 15px 10px;
}

.gallery-item .button {
    margin-bottom: 15px;
}

/* Footer Styles */
footer {
    background-color: #2c3e50;
    color: white;
    text-align: center;
    padding: 1.5rem 0;
    margin-top: 50px;
    font-size: 0.9em;
}

/* Responsive Design */
@media (max-width: 768px) {
    header h1 {
        font-size: 2em;
    }

    nav a {
        padding: 0.6rem 1rem;
        font-size: 0.9em;
    }

    .container {
        margin: 20px auto;
        padding: 15px;
    }

    .section-content {
        padding: 30px 0;
    }

    .section-content h2 {
        font-size: 1.8em;
    }

    .hero h2 {
        font-size: 2em;
    }

    .hero p {
        font-size: 1em;
    }

    .call-to-action .button {
        display: block;
        margin: 10px auto;
        width: 80%;
    }

    .creation-form, .contact-form {
        padding: 15px;
    }

    #vr-scene-container, #ar-scene-container {
        height: 350px;
    }

    .gallery-grid {
        grid-template-columns: 1fr;
    }
}/* End custom CSS */