/* =========================================
   Horizontal Scroll Gallery — Frontend CSS
   ========================================= */

/* ---- Root variables ---- */
.hsg-wrapper {
    --hsg-bg: #000;
    --hsg-fg: #fff;
    --hsg-overlay-bg: rgba(0,0,0,0.55);
    --hsg-accent: rgba(255,255,255,0.15);
    --hsg-thumb-opacity: 1;
    --hsg-transition: 0.45s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    --hsg-item-min-w: 420px;
    --hsg-item-max-w: 900px;
    --hsg-aspect: 16/9;
    --hsg-controls-h: 52px;
    --hsg-gap-color: transparent;
    --hsg-item-shadow: none;
    --hsg-hint-color: #ffffff;
    --hsg-hint-size: 32px;

    position: relative;
    width: 100%;
    background-color: var(--hsg-gap-color);
    overflow: hidden;
    font-family: inherit;
    box-sizing: border-box;
}

.hsg-wrapper.hsg-light {
    --hsg-fg: #111;
    --hsg-overlay-bg: rgba(255,255,255,0.55);
}

/* Il tema dark/light ora controlla solo il colore dei testi/overlay,
   non il background del wrapper (quello è --hsg-gap-color) */
.hsg-dark .hsg-track-container { background: transparent; }
.hsg-light .hsg-track-container { background: transparent; }

*, *::before, *::after {
    box-sizing: inherit;
}

/* ---- Track ---- */
.hsg-track-container {
    width: 100%;
    overflow: hidden;
    cursor: ew-resize; /* indica scroll orizzontale */
    user-select: none;
    outline: none;
}

.hsg-track-container:active {
    cursor: grabbing;
}

/* Quando in focus (tastiera), nessun outline visibile sulla gallery stessa */
.hsg-track-container:focus {
    outline: none;
}

.hsg-track {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: stretch;
    /* Altezza: usa --hsg-item-height se impostata, altrimenti aspect-ratio */
    height: var(--hsg-item-height, calc(100vw / (var(--hsg-aspect)) * 0.6));
    min-height: 300px;
    max-height: 85vh;
    will-change: transform;
    transition: transform var(--hsg-transition);
}

/* ---- Items ---- */
.hsg-item {
    position: relative;
    flex: 0 0 auto;
    width: var(--hsg-item-min-w);
    max-width: var(--hsg-item-max-w);
    height: 100%;
    overflow: hidden;
    outline: none;
    cursor: pointer;
    pointer-events: auto;
    transition: width var(--hsg-transition), flex-basis var(--hsg-transition);
    box-shadow: var(--hsg-item-shadow);
}

/* Hover expand */
.hsg-item:hover,
.hsg-item:focus-visible {
    z-index: 2;
}

/* ---- Thumbnail (background image) ---- */
.hsg-item__thumb {
    position: absolute;
    inset: 0;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    opacity: var(--hsg-thumb-opacity);
    transition: opacity var(--hsg-transition), transform var(--hsg-transition);
    will-change: opacity, transform;
}

/* Se l'item ha un video, la thumbnail è usata solo come poster — nascondila subito */
.hsg-item--video .hsg-item__thumb {
    opacity: 0;
}

/* ---- Video ---- */
.hsg-item__video {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 1;           /* sempre visibile — parte al caricamento */
    transition: opacity var(--hsg-transition);
    will-change: opacity;
    pointer-events: none;
}

/* ---- Static image (for image type) ---- */
.hsg-item__image {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform var(--hsg-transition);
    will-change: transform;
}

.hsg-item:hover .hsg-item__image,
.hsg-item:focus-visible .hsg-item__image {
    transform: scale(1.04);
}

/* Tutti i figli dell'item non intercettano click né avviano drag nativo sul browser */
.hsg-item * {
    user-select: none;
    -webkit-user-drag: none;
}

/* Solo video e thumb non intercettano click */
.hsg-item__video,
.hsg-item__thumb {
    pointer-events: none;
}

/* L'item stesso deve ricevere i click */
.hsg-item {
    cursor: pointer;
}

/* ---- Overlay ---- */
.hsg-item__overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-end;
    padding: 28px 24px;
    background: linear-gradient(to top, rgba(0,0,0,0.7) 0%, transparent 55%);
    opacity: 0;
    transition: opacity var(--hsg-transition);
}

.hsg-item:hover .hsg-item__overlay,
.hsg-item:focus-visible .hsg-item__overlay {
    opacity: 1;
}

.hsg-item__title {
    color: #fff;
    font-size: clamp(14px, 1.4vw, 22px);
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    margin: 0;
    line-height: 1.2;
    text-shadow: 0 1px 6px rgba(0,0,0,0.6);
}

.hsg-light .hsg-item__title {
    color: #fff; /* keep white for readability on overlay gradient */
}

/* ---- Play icon (lightbox items) ---- */
.hsg-play-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 60px;
    height: 60px;
    opacity: 0.9;
    transition: opacity 0.2s, transform 0.2s;
    pointer-events: none;
}

.hsg-item:hover .hsg-play-icon {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.1);
}

/* ---- Controls bar (nascosta — opzionale) ---- */
.hsg-controls {
    display: none !important;
}
.hsg-controls-UNUSED {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
    height: var(--hsg-controls-h);
    color: var(--hsg-fg);
}

.hsg-dark .hsg-controls {
    background: #000;
}

.hsg-light .hsg-controls {
    background: #f5f5f5;
}

.hsg-counter {
    font-size: 12px;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--hsg-fg);
    opacity: 0.8;
    display: flex;
    align-items: center;
    gap: 6px;
}

.hsg-counter .hsg-sep { opacity: 0.5; }

.hsg-counter .hsg-name {
    margin-left: 10px;
    font-weight: 600;
    opacity: 1;
    transition: opacity 0.3s;
}

/* Nav buttons */
.hsg-nav {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--hsg-fg);
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    padding: 6px 12px;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.hsg-nav:hover { opacity: 1; }

.hsg-nav svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.hsg-nav:disabled {
    opacity: 0.2;
    cursor: default;
}

/* =========================================
   LIGHTBOX
   ========================================= */
.hsg-lightbox {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 99999;
    background: var(--hsg-lightbox-bg, rgba(0,0,0,0.92));
    align-items: center;
    justify-content: center;
    animation: hsgFadeIn 0.25s ease;
}

.hsg-lightbox.is-open {
    display: flex;
}

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

.hsg-lightbox-inner {
    position: relative;
    width: 90vw;
    max-width: 1100px;
}

.hsg-lightbox-content {
    position: relative;
    width: 100%;
    /* L'aspect-ratio viene forzato solo per video/iframe; per le immagini il contenuto determina le dimensioni */
}

.hsg-lightbox-content iframe,
.hsg-lightbox-content video {
    width: 100%;
    aspect-ratio: 16/9;
    height: auto;
    border: none;
    border-radius: 4px;
    display: block;
}

.hsg-lightbox-content img {
    max-width: 100%;
    max-height: 88vh;
    width: auto;
    height: auto;
    object-fit: contain;
    display: block;
    margin: auto;
    border-radius: 4px;
}

.hsg-lightbox-close {
    position: absolute;
    top: -44px;
    right: 0;
    background: none;
    border: none;
    cursor: pointer;
    color: #fff;
    width: 36px;
    height: 36px;
    padding: 4px;
    opacity: 0.8;
    transition: opacity 0.2s, transform 0.2s;
}

.hsg-lightbox-close:hover {
    opacity: 1;
    transform: rotate(90deg);
}

.hsg-lightbox-close svg {
    width: 100%;
    height: 100%;
}

/* Progress line rimossa — loop infinito non ha inizio/fine */

/* =========================================
   SCROLL HINT — frecce lampeggianti destra
   ========================================= */
.hsg-scroll-hint {
    position: absolute;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 10;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0;
    pointer-events: none;
    /* visibile di default, nascosto via JS dopo primo scroll */
}

/* Le 3 frecce sono sfasate nell'animazione per creare l'effetto "cascata" */
.hsg-scroll-hint__arrow {
    width: var(--hsg-hint-size);
    height: var(--hsg-hint-size);
    color: var(--hsg-hint-color);
    opacity: 0;
    animation: hsgHintPulse 2s ease-in-out infinite;
    flex-shrink: 0;
    margin-left: calc(var(--hsg-hint-size) * -0.35); /* sovrapposizione leggera */
}

.hsg-scroll-hint__arrow:first-child {
    margin-left: 0;
    animation-delay: 0s;
}
.hsg-scroll-hint__arrow:nth-child(2) {
    animation-delay: 0.15s;
}
.hsg-scroll-hint__arrow:nth-child(3) {
    animation-delay: 0.30s;
}

/*
 * Il lampeggio: 2 volte in 2s
 * 0%      → opacità 0  (invisibile)
 * 12.5%   → opacità 1  (primo flash ON)
 * 25%     → opacità 0  (primo flash OFF)
 * 37.5%   → opacità 1  (secondo flash ON)
 * 50%     → opacità 0  (secondo flash OFF)
 * 100%    → opacità 0  (pausa fino al ciclo successivo)
 */
@keyframes hsgHintPulse {
    0%    { opacity: 0;   transform: translateX(0); }
    12.5% { opacity: 1;   transform: translateX(4px); }
    25%   { opacity: 0;   transform: translateX(0); }
    37.5% { opacity: 0.9; transform: translateX(4px); }
    50%   { opacity: 0;   transform: translateX(0); }
    100%  { opacity: 0;   transform: translateX(0); }
}

/* Stato nascosto — aggiunto via JS */
.hsg-scroll-hint.is-hidden {
    opacity: 0;
    transition: opacity 0.4s ease;
    pointer-events: none;
}

/* Riappare (idle) */
.hsg-scroll-hint.is-visible {
    opacity: 1;
    transition: opacity 0.6s ease;
}

/* =========================================
   RESPONSIVE
   ========================================= */
@media (max-width: 768px) {
    .hsg-item {
        width: 75vw;
        min-width: 240px;
        max-width: none;
    }

    .hsg-item__title {
        font-size: 13px;
    }

    .hsg-play-icon {
        width: 48px;
        height: 48px;
    }

    /* On touch: always show overlay slightly */
    .hsg-item__overlay {
        opacity: 0.6;
    }

    .hsg-item:hover .hsg-item__overlay {
        opacity: 1;
    }
}

@media (max-width: 480px) {
    .hsg-item {
        width: 85vw;
    }

    .hsg-controls {
        padding: 8px 12px;
    }

    .hsg-nav span {
        display: none; /* hide scroll text, keep arrow */
    }
}

/* ---- Empty state ---- */
.hsg-empty {
    padding: 40px;
    text-align: center;
    color: #999;
    font-style: italic;
}
