/* --- RESET & LAYOUT GENERALE --- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Helvetica Neue', Arial, sans-serif;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--gradient-background);
    color: var(--text-primary);
}

/* --- LOADER --- */
#loader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    /* The dark gradient is good, we add an image on top */
    background: var(--gradient-background); 
    
    /* NUOVA AGGIUNTA (opzionale): cambia 'leaf_texture.png' con una tua immagine */
    background-image: linear-gradient(rgba(0,0,0,0.7), rgba(0,0,0,0.7)), url('img/logo.png');
    background-size: cover;

    z-index: 2000;
    color: var(--text-primary);
}

.spinner {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    
    /* Sostituiamo il bordo con un'ombra per un effetto "glow" */
    border: 3px solid rgba(28, 167, 69, 0.2); /* Un anello verde scuro e debole */
    box-shadow: 0 0 20px rgba(40, 167, 69, 0.7); /* L'aura verde che pulsa */

    /* Applichiamo una nuova animazione più lenta e organica */
    animation: spin-grow 1.5s ease-in-out infinite;
}

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

@keyframes spin-grow {
    0% {
        transform: rotate(0deg) scale(1);
        box-shadow: 0 0 20px rgba(40, 167, 69, 0.7);
    }
    50% {
        transform: rotate(180deg) scale(1.1);
        box-shadow: 0 0 35px rgba(40, 167, 69, 1); /* Aumenta il bagliore a metà animazione */
    }
    100% {
        transform: rotate(360deg) scale(1);
        box-shadow: 0 0 20px rgba(40, 167, 69, 0.7);
    }
}

#loader p {
    font-size: 1.1em;
    color: var(--text-secondary);
    text-align: center;

    /* NUOVE AGGIUNTE */
    font-family: Georgia, 'Times New Roman', Times, serif; /* Un font più classico/narrativo */
    text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.5); /* Ombra leggera per leggibilità */
}

/* --- START SCREEN --- */
#start-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

#home-video {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    object-fit: cover;
    z-index: -1;
}

.start-content {
    position: relative;
    z-index: 1;
    background: rgba(0, 0, 0, var(--overlay-opacity));
    padding: 20px;
    border-radius: var(--border-radius-medium);
    backdrop-filter: var(--backdrop-blur);
    max-width: var(--max-width);
    width: var(--container-width);
    text-align: center;
    animation: fadeIn var(--fade-duration) ease-out;
}

.start-content img {
    max-width: 400px;
    width: 100%;
    height: auto;

    /* Sposta visivamente il logo verso l'alto di metà della sua altezza */
    transform: translateY(-50%);

    /* Tira su il testo sottostante per compensare lo spazio lasciato dal logo.
       Questo impedisce al contenitore di diventare troppo alto.
       Puoi aggiustare questo valore se necessario. */
    margin-bottom: -200px; 
}

#start-screen h1 {
    font-size: 2.5em;
    margin-bottom: 20px;
    color: var(--text-primary);
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

#start-screen p {
    font-size: 1.2em;
    margin-bottom: 30px;
    color: var(--text-secondary);
    line-height: 1.6;
}

#start-button {
    background: var(--gradient-primary);
    color: white;
    border: none;
    padding: 15px 40px;
    font-size: 1.2em;
    border-radius: 30px;
    cursor: pointer;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    box-shadow: var(--button-shadow);
}

#start-button:hover {
    transform: translateY(var(--button-hover-translate, -2px));
    box-shadow: var(--button-shadow-hover);
}

#start-button:active {
    transform: translateY(1px);
}

/* --- VIDEO OVERLAY --- */
#video-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100vh;
    background: #000;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 99;
}

#blurred-background {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    filter: blur(var(--background-blur)) brightness(var(--background-brightness));
    z-index: 0;
    opacity: 1;
    pointer-events: none;
}

#interlude-video {
    position: relative;
    max-height: 100vh;
    width: auto;
    height: auto;
    object-fit: contain;
    z-index: 1;
}

#scrolling-text {
    position: absolute;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    width: 80%;
    max-width: 800px;
    color: white;
    font-size: 24px;
    line-height: 1.6;
    text-align: center;
    z-index: 2;
    opacity: 0;
    animation: fadeIn var(--text-appear-duration) ease-in forwards;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
    font-family: 'Georgia', serif;
    background: rgba(0, 0, 0, var(--overlay-opacity));
    padding: 20px;
    border-radius: var(--border-radius-small);
}

#video-overlay button {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    padding: 12px 30px;
    font-size: 16px;
    cursor: pointer;
    background: var(--gradient-primary);
    color: white;
    border: none;
    border-radius: var(--border-radius-large);
    z-index: 10000;
    opacity: 0;
    animation: fadeIn var(--text-appear-duration) ease-in forwards;
    box-shadow: var(--button-shadow);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

#video-overlay button:hover {
    transform: translateX(-50%) translateY(var(--button-hover-translate, -2px));
    box-shadow: var(--button-shadow-hover);
}

#video-overlay button:active {
    transform: translateX(-50%) translateY(1px);
}

.footer-banner {
    position: absolute;
    bottom: 30px; /* Distanza dal fondo */
    left: 50%;
    transform: translateX(-50%); /* Centra orizzontalmente */
    padding: 10px 20px;
    background: rgba(0, 0, 0, var(--overlay-opacity)); /* Stile simile al box centrale */
    border-radius: var(--border-radius-small);
    backdrop-filter: var(--backdrop-blur);
    z-index: 10;
}

.kinoa-link {
    font-size: 14px;
    color: white;
    text-decoration: none; /* Rimuove la sottolineatura */
    opacity: 0.7;
    transition: opacity 0.3s ease;
}

.kinoa-link:hover {
    opacity: 1;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* --- AVATAR SELECTION SCREEN (NUOVI STILI) --- */
#avatar-selection-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    display: none; /* Gestito da JS */
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn var(--fade-duration) ease-out;
}

/* Stile per il video di sfondo della selezione avatar, simile a blurred-background */
#avatar-selection-background-video {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    filter: blur(var(--background-blur)) brightness(var(--background-brightness));
    z-index: 0;
    opacity: 1;
    pointer-events: none; /* Non deve interferire con i click */
}


.avatar-selection-content {
    position: relative;
    z-index: 1;
    background: rgba(0, 0, 0, var(--overlay-opacity));
    padding: 40px;
    border-radius: var(--border-radius-medium);
    backdrop-filter: var(--backdrop-blur);
    max-width: var(--max-width);
    width: var(--container-width);
    text-align: center;
    /* Permette lo scorrimento del contenuto della griglia se troppi avatar */
    overflow-y: auto; 
    max-height: 80vh; /* Limita l'altezza del content per non coprire il pulsante fisso */
    padding-bottom: 80px; /* Spazio per il pulsante fisso */
}

#avatar-selection-title {
    font-size: 2.5em;
    margin-bottom: 15px;
    color: var(--text-primary);
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

#avatar-selection-subtitle {
    font-size: 1.2em;
    margin-bottom: 30px;
    color: var(--text-secondary);
    line-height: 1.6;
}

#avatar-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); /* 120px min size, espandere */
    gap: 30px;
    justify-content: center;
    padding: 20px 0;
    max-width: 900px; /* Limita larghezza griglia */
    margin: 0 auto; /* Centra la griglia */
}

.avatar-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    padding: 10px;
    border-radius: var(--border-radius-medium);
}

.avatar-item img {
    width: 140px; /* Dimensione base dell'avatar */
    height: 140px;
    border-radius: var(--border-radius-full);
    object-fit: cover;
    border: 4px solid transparent; /* Bordo predefinito trasparente */
    transition: border 0.3s ease, transform 0.3s ease;
    box-shadow: var(--avatar-shadow);
}

.avatar-item:hover img {
    transform: scale(var(--avatar-hover-scale));
}

.avatar-item.selected img {
    border: var(--avatar-selected-border); /* Bordo per l'avatar selezionato */
    transform: scale(var(--avatar-hover-scale)); /* Mantiene la scala anche quando selezionato */
}

.avatar-item span {
    margin-top: 10px;
    color: var(--text-primary);
    font-size: 0.9em;
    text-align: center;
}

/* Stili per il pulsante di conferma fisso */
#confirm-avatar-button {
    position: fixed; /* Posizionamento fisso */
    bottom: 20px; /* A 20px dal fondo */
    left: 50%; /* Centrato orizzontalmente */
    transform: translateX(-50%); /* Correzione per il centraggio */
    padding: 15px 40px;
    font-size: 1.2em;
    border-radius: 30px;
    cursor: pointer;
    background: var(--gradient-primary);
    color: white;
    border: none;
    z-index: 1001; /* Sopra la schermata di selezione */
    box-shadow: var(--button-shadow);
    transition: transform 0.3s ease, box-shadow 0.3s ease, opacity 0.5s ease; /* Transizione per l'opacità */
}

#confirm-avatar-button:hover:not(:disabled) {
    transform: translateX(-50%) translateY(var(--button-hover-translate, -2px));
    box-shadow: var(--button-shadow-hover);
}

#confirm-avatar-button:active:not(:disabled) {
    transform: translateX(-50%) translateY(1px);
}

#confirm-avatar-button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    background: gray; /* Colore per il bottone disabilitato */
    box-shadow: none;
}


/* --- APP CONTAINER --- */
#app-container {
    width: 100%;
    display: none;
    flex-direction: column;
    align-items: center;
    background-size: cover;
    min-height: 100vh;
    position: relative;
}

#app-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, var(--overlay-opacity));
    z-index: 1;
}

/* --- TYPEFORM EMBED --- */
#typeform-embed-container {
    width: 100%;
    height: 90vh;
    margin-bottom: 20px;
    position: relative;
    z-index: 2;
}

#typeform-embed-container iframe,
#typeform-embed-container > div {
    width: 100%;
    height: 100%;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    border-radius: var(--border-radius-small);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    backdrop-filter: var(--backdrop-blur);
}

/* --- TIMELINE --- */
#timeline-container {
    position: fixed;
    left: 0;
    bottom: 0;
    width: 100%;
    padding: 15px 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: var(--timeline-backdrop);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    overflow: hidden;
    z-index: 50;
    display: flex;
    /*justify-content: center;*/
    align-items: center;
}

#timeline-steps {
    display: flex;
    gap: var(--step-gap);
    list-style: none;
    padding: 0;
    margin: 0;
    transition: transform 0.3s ease;
    position: relative;
    /* ASSICURARSI CHE NON CI SIA width: 100%; QUI */
}

/* Modifiche per accomodare l'avatar come icona centrale */
.timeline-center-icon {
    width: var(--avatar-timeline-size); /* Nuova dimensione dall'avatar */
    height: var(--avatar-timeline-size); /* Nuova dimensione dall'avatar */
    background: var(--gradient-primary); /* Fallback */
    border-radius: var(--border-radius-full);
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-primary);
    font-weight: bold;
    pointer-events: none;
    box-shadow: var(--step-shadow);
    /* Nuovi stili per l'immagine avatar */
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    border: 3px solid var(--primary-light); /* Bordo intorno all'avatar */
    font-size: 0;
}

/* Rimuovi il testo se c'è un'immagine di sfondo (sarà gestito da JS) */
.timeline-center-icon.has-avatar {
    font-size: 0; /* Nasconde il carattere "→" */
}

.step {
    min-width: var(--step-size);
    height: var(--step-size);
    background: rgba(255, 255, 255, 0.2);
    border-radius: var(--border-radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-primary);
    font-weight: bold;
    flex-shrink: 0;
    opacity: 1;
    transition: all 0.3s ease;
}

.step.active {
    background: var(--gradient-primary);
    transform: scale(1.2);
    box-shadow: var(--step-shadow);
}

.step.completed {
    background: var(--gradient-secondary);
    box-shadow: var(--completed-shadow);
}

/* Scrollbar leggera (opzionale) */
#timeline-container::-webkit-scrollbar {
    height: 6px;
}

#timeline-container::-webkit-scrollbar-thumb {
    background: var(--primary-color);
    border-radius: 3px;
}

#mute-button {
    position: fixed; /* O 'absolute' se preferisci */
    top: 25px;
    left: 25px;
    width: 40px;
    height: 40px;
    background-color: rgba(0, 0, 0, 0.4);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    z-index: 10001; /* Assicura che sia sempre sopra a tutto */
    transition: background-color 0.3s ease;
}

#mute-button:hover {
    background-color: rgba(0, 0, 0, 0.6);
}

/* Stile per le icone SVG all'interno del pulsante */
#mute-button svg {
    width: 24px;
    height: 24px;
    color: white;
}

.top-right-logo-container {
    position: absolute;
    top: 30px;
    right: 30px;
    z-index: 10; /* Assicura che sia visibile */
}

.usl-logo {
    height: 60px; /* Puoi aggiustare l'altezza come preferisci */
    width: auto;
    opacity: 0.9;
    transition: opacity 0.3s ease;
}

.usl-logo:hover {
    opacity: 1;
}

/* --- RESPONSIVE DESIGN --- */
@media (max-width: 768px) {
    .start-content, .avatar-selection-content {
        padding: 20px;
        width: 95%;
    }
    
    .start-content img {
        max-width: 300px;
    }
    
    #start-screen h1, #avatar-selection-title {
        font-size: 2em;
    }
    
    #start-screen p, #avatar-selection-subtitle {
        font-size: 1em;
    }
    
    #scrolling-text {
        font-size: 18px;
        width: 90%;
        bottom: 80px;
    }

    #avatar-grid {
        grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); /* Meno colonne su schermi più piccoli */
        gap: 20px;
    }
    .avatar-item img {
        width: 80px;
        height: 80px;
    }
    #confirm-avatar-button {
        padding: 10px 25px;
        font-size: 1em;
    }
}

@media (max-width: 480px) {
    .start-content, .avatar-selection-content {
        padding: 15px;
    }
    
    .start-content img {
        max-width: 250px;
    }
    
    #start-screen h1, #avatar-selection-title {
        font-size: 1.8em;
    }
    
    #scrolling-text {
        font-size: 16px;
        bottom: 60px;
    }

    #avatar-grid {
        grid-template-columns: repeat(auto-fit, minmax(70px, 1fr)); /* Ancora meno colonne */
        gap: 15px;
    }
    .avatar-item img {
        width: 60px;
        height: 60px;
    }
    #confirm-avatar-button {
        padding: 8px 20px;
        font-size: 0.9em;
    }
}