/* ============================================
   FULLSCREEN GALLERY VIEW
   ============================================ */

.fs-overlay {
  position: fixed;
  inset: 0;
  z-index: 2147483647 !important;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(234, 234, 234, 0.55);
  -webkit-backdrop-filter: blur(18px) saturate(1.1);
  backdrop-filter: blur(18px) saturate(1.1);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.28s ease, visibility 0.28s ease;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: contain;
  /* Abilita pinch-zoom nativo (iOS) sull'overlay.
     Lo scroll del body è già bloccato da body.fs-open { position: fixed }. */
  touch-action: pinch-zoom;
}

.fs-overlay.active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

/* Immagine principale */
.fs-image-wrap {
  position: relative;
  width: 90vw;
  height: 90vh;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.fs-image {
  display: block;
  max-width: 90vw;
  max-height: 90vh;
  width: auto;
  height: auto;
  object-fit: contain;
  opacity: 1 !important;
  transform: scale(1);
  /* Solo opacità: nessuna animazione di scala durante il cambio immagine.
     Questo elimina il "pulse" quando si naviga con le frecce. */
  transition: opacity 0.28s ease;
  pointer-events: auto;
  user-select: none;
  -webkit-user-drag: none;
  border-radius: 2px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.18);
  /* Abilita pinch-zoom anche sul singolo elemento immagine */
  touch-action: pinch-zoom;
}

/* Stato di fade: solo opacità, nessuna variazione di scala. */
.fs-image.fs-fading {
  opacity: 0;
}

/* ============================================
   FRECCE DI NAVIGAZIONE
   ============================================ */
.fs-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 64px;
  height: 64px;
  border: none;
  background: transparent;
  color: var(--text-main);
  cursor: pointer;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.55;
  transition: opacity 0.25s ease, transform 0.25s ease, color 0.25s ease;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

.fs-arrow:hover {
  opacity: 1;
  color: var(--accent-lime);
}

.fs-arrow:active {
  transform: translateY(-50%) scale(0.94);
}

.fs-arrow svg {
  width: 34px;
  height: 34px;
  display: block;
  pointer-events: none;
}

.fs-arrow-prev { left: 2.5vw; }
.fs-arrow-next { right: 2.5vw; }

/* ============================================
   TASTO CHIUSURA (X)
   ============================================ */
.fs-close {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 2vh);
  right: 2.5vw;
  width: 44px;
  height: 44px;
  border: none;
  background: transparent;
  cursor: pointer;
  z-index: 11;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.75;
  transition: opacity 0.25s ease, transform 0.25s ease, color 0.25s ease;
  color: var(--text-main);
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

.fs-close:hover {
  opacity: 1;
  color: var(--accent-lime);
  transform: rotate(90deg);
}

.fs-close svg {
  width: 26px;
  height: 26px;
  display: block;
  pointer-events: none;
}

/* ============================================
   BOTTONE "APRI A SCHERMO INTERO"
   ============================================ */
.fs-open-btn {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 1000;
  width: 44px;
  height: 44px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--text-main);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.55;
  transition: opacity 0.25s ease, color 0.25s ease, transform 0.25s ease;
  -webkit-tap-highlight-color: transparent;
  pointer-events: auto;
}

.fs-open-btn:hover {
  opacity: 1;
  color: var(--accent-lime);
  transform: scale(1.08);
}

.fs-open-btn svg {
  width: 20px;
  height: 20px;
  display: block;
  pointer-events: none;
}

/* ============================================
   BODY LOCK quando il fullscreen è aperto
   ============================================ */
body.fs-open {
  overflow: hidden !important;
  height: 100% !important;
  position: fixed !important;
  width: 100% !important;
  top: 0 !important;
  left: 0 !important;
  touch-action: none !important;
}

/* Nascondi tutto il sito dietro l'overlay */
body.fs-open > *:not(.fs-overlay):not(.footer-title):not(.footer-menu):not(.site-credit-wrapper):not(.header-blur-band):not(script):not(style):not(link):not(meta):not(title) {
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

/* Whitelist: questi restano visibili dietro l'overlay blurrato */
body.fs-open > .footer-title,
body.fs-open > .footer-menu,
body.fs-open > .site-credit-wrapper,
body.fs-open > .header-blur-band {
  visibility: visible !important;
  opacity: 1 !important;
  pointer-events: none !important;
}

/* Nascondi elementi specifici (ridondante ma sicuro) */
body.fs-open #gridToggleBtn.grid-toggle-btn,
body.fs-open .grid-toggle-btn,
body.fs-open #gridView,
body.fs-open .grid-view {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

body.fs-open .fs-open-btn {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

body.fs-open .thumbnail-stack,
body.fs-open .thumbnail-stack *,
body.fs-open .thumbnail-item,
body.fs-open .thumbnail-item *,
body.fs-open .project-info-panel,
body.fs-open .project-info-panel * {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

body.fs-open #works-textbox::before,
body.fs-open #works-textbox::after,
body.fs-open .text-box::before,
body.fs-open .personal-works-box::before {
  display: none !important;
}

body.fs-open .project-gallery-close-btn,
body.fs-open .gallery-back-button,
body.fs-open .project-back-button,
body.fs-open #worksBackButton {
  display: none !important;
}

body.fs-open .photo-name,
body.fs-open .progress-bar-container,
body.fs-open .project-slide-desc,
body.fs-open .gallery-nav-arrow {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
}

/* ============================================
   MOBILE
   ============================================ */
@media (max-width: 768px) {
  .fs-arrow {
    width: 52px;
    height: 52px;
  }
  .fs-arrow svg { width: 28px; height: 28px; }
  .fs-arrow-prev { left: 1vw; }
  .fs-arrow-next { right: 1vw; }

  .fs-close {
    top: calc(env(safe-area-inset-top) + 1.5vh);
    right: 3vw;
    width: 40px;
    height: 40px;
  }

  .fs-image-wrap {
    width: 96vw;
    height: 90vh;
  }

  .fs-image {
    max-width: 96vw;
    max-height: 90vh;
  }

  /* Foto orizzontali ("large") ruotate di 90° su mobile.
     Lo scale-up forzato ×1.4 ingrandisce l'immagine oltre i
     limiti del contenitore, in modo che la rotazione non la
     rimpicciolisca visivamente.
     Nessun ulteriore scale su .fs-fading: il cambio immagine
     è solo un fade di opacità. */
  .fs-image.fs-rotated {
    max-width: 90vh;
    max-height: 96vw;
    transform: rotate(90deg) scale(1.4);
  }

  .fs-open-btn {
    width: 38px;
    height: 38px;
  }
  .fs-open-btn svg { width: 18px; height: 18px; }
}

/* ============================================
   HOVER: NONE — reset effetti hover su touch
   ============================================ */
@media (hover: none) {
  .fs-arrow:hover,
  .fs-close:hover,
  .fs-open-btn:hover {
    color: var(--text-main);
  }
  .fs-close:hover { transform: none; }
  .fs-open-btn:hover { transform: none; }
}