/* ============================================
   VARIABLES & RESET
   ============================================ */
:root {
  --bg-dark: #eaeaea;
  --bg-secondary: #cdd6d7;
  --text-main: #2e261d;
  --text-dim: #504030;
  --accent-lime: #a14c17;
  --text-main-rgb: 46, 38, 29;
}

html, body {
  margin: 0;
  padding: 0;
  background-color: var(--bg-dark);
  color: var(--text-main);
  font-family: Helvetica Neue, sans-serif;
  min-height: 100vh;
  overflow-x: hidden;
  overflow-y: auto !important;
  height: auto !important;
}

*, *::before, *::after {
  outline: none !important;
  -webkit-tap-highlight-color: transparent;
}

/* ============================================
   BASE ELEMENTS
   ============================================ */
a {
  color: var(--text-main);
  text-decoration: none;
  position: relative;
  display: inline;
  overflow: hidden;
  transition: color 0.3s ease;
  z-index: 1;
}

a::before {
  content: '';
  position: absolute;
  left: 0;
  bottom: 0;
  width: 0;
  height: 100%;
  background-color: var(--accent-lime);
  transition: width 0.3s ease;
  z-index: -1;
}

img {
  -webkit-user-drag: none;
  -khtml-user-drag: none;
  -moz-user-drag: none;
  -o-user-drag: none;
  opacity: 0;
  transition: opacity 0.8s cubic-bezier(0.23, 1, 0.32, 1);
}

img.img-loaded {
  opacity: 1 !important;
}

body, .text-box, .personal-works-box {
  transition: background-color 0.5s ease, color 0.5s ease, border-color 0.5s ease;
}

/* ============================================
   BACK BUTTON
   ============================================ */
.text-box-back {
  position: fixed !important;
  top: calc(env(safe-area-inset-top) + 2vh) !important;
  left: 5vw !important;
  font-size: 2vh !important;
  font-weight: 300 !important;
  color: var(--text-main) !important;
  text-decoration: none !important;
  z-index: 99999 !important;
  cursor: pointer !important;
  display: flex !important;
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  align-items: center;
  transition: opacity 0.3s ease, visibility 0.3s ease, color 0.3s ease !important;
  transform: translateZ(0);
}

.text-box-back::before {
  content: none !important;
}

.text-box.active .text-box-back,
.personal-works-box.active .text-box-back {
  visibility: visible !important;
  opacity: 1 !important;
  pointer-events: auto !important;
}

.text-box-back:hover {
  color: var(--accent-lime) !important;
}

/* ============================================
   MOBILE MENU
   ============================================ */
.mobile-menu-toggle {
  display: none;
}

/* ============================================
   FOOTER LAYOUT
   ============================================ */
.footer-menu {
  position: absolute;
  bottom: 20%;
  left: 6%;
  display: flex;
  flex-direction: column;
  gap: 0.8vh;
  font-size: 1.8vh;
  font-weight: 300;
  z-index: 10;
  transition: transform 0.8s cubic-bezier(0.23, 1, 0.32, 1);
  align-items: flex-start; /* Evita che i bottoni si allunghino a tutta larghezza */
  background: transparent !important; /* Nessuno sfondo al contenitore */
  padding: 0;
}

.footer-menu a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: fit-content;
  max-width: 100%;
  white-space: nowrap;
  text-decoration: none;
  background-color: transparent;
  color: var(--text-main);
  
  /* Bordo scuro e angoli pillola come nello screenshot */
  border: 1px solid var(--text-main);
  border-radius: 999px;
  
  /* Spaziatura interna stretta e calibrata */
  padding: 0.15em 0.55em; /* il 1° valore è sopra/sotto, il 2° è a destra/sinistra */
  line-height: 1.0;

  transition: background-color 0.25s ease, border-color 0.25s ease, color 0.25s ease;
}

/* Disabilita la vecchia animazione della tendina di sfondo */
.footer-menu a::before {
  content: none !important;
  display: none !important;
}

.footer-menu a.active-link {
  color: var(--bg-dark) !important;
  font-weight: 500;
}

.footer-menu a.active-link::before {
  width: 100%;
}

.footer-menu a:hover,
.footer-menu a.active-link {
  background-color: var(--accent-lime) !important;
  border-color: var(--accent-lime) !important;
  color: #ffffff !important;
  font-weight: 300; /* Mantiene il testo pulito senza sbalzi di larghezza */
}

.footer-title {
  position: absolute;
  bottom: 18%;
  left: 3%;
  font-size: 4vh;
  font-weight: 400;
  line-height: 1;
  letter-spacing: -0.05vw;
  margin: 0;
  z-index: 10;
  transition: transform 0.8s cubic-bezier(0.23, 1, 0.32, 1);
  color: var(--text-main);
}

.footer-subtitle {
  position: absolute;
  bottom: 14%;
  left: 6%;
  font-size: 2.7vh;
  font-weight: 300;
  margin: 0;
  z-index: 10;
  transition: transform 0.8s cubic-bezier(0.23, 1, 0.32, 1);
  color: var(--text-main);
}

/* ============================================
   PROFILE BOX
   ============================================ */
.home-profile-box {
  position: fixed;
  left: 4%;
  top: 18vh;
  width: 22vh;
  height: 22vh;
  z-index: 50;
  display: none;
  opacity: 0;
  pointer-events: none;
}

.home-profile-box.active {
  display: block;
  opacity: 1;
}

.home-profile-box img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* ============================================
   PANELS (TEXT BOXES)
   ============================================ */
.text-box, .personal-works-box {
  position: fixed;
  left: 22vw;
  bottom: 28.5%;
  top: auto;
  right: auto;
  width: 42vw;
  max-height: 60vh;
  background: transparent;
  padding: 0;
  box-sizing: border-box;
  overflow-y: hidden;
  overflow-x: hidden;
  z-index: 100;
  display: none;
  opacity: 0;
  transform: none !important;
  transition: none !important;
}

.text-box.active, .personal-works-box.active {
  display: block;
  opacity: 1;
}

.text-box-content, .personal-works-content {
  height: auto;
  max-height: 60vh;
  padding-right: 1.5vw;
  overflow-y: auto;
  -ms-overflow-style: none;
  scrollbar-width: none;
}

.text-box-content::-webkit-scrollbar,
.personal-works-content::-webkit-scrollbar {
  display: none !important;
  width: 0 !important;
  height: 0 !important;
  background: transparent !important;
}

.text-box h2, .personal-works-box h2 {
  margin-top: 0;
  font-size: 3vh;
  font-weight: 400;
  text-transform: lowercase;
  color: var(--accent-lime);
}

.text-box p, .personal-works-box p {
  line-height: 1.5em;
  margin-bottom: 1.2em;
  max-width: 100%;
  font-size: 1.7vh;
  font-weight: 300;
  color: var(--text-main);
}

/* ============================================
   WORK ITEMS
   ============================================ */
.personal-work-item {
  margin-bottom: 1.2em;
}

.personal-work-item .work-link {
  font-size: 2vh;
  display: inline-block;
  margin-bottom: -0.3em;
  font-weight: 300;
  color: var(--text-main);
  letter-spacing: -0.01em;
  cursor: pointer;
  text-decoration: none;
  position: relative;
  overflow: hidden;
  padding: 0.02em 0.2vw;
  line-height: 1.15;
  z-index: 1;
  transition: color 0.3s ease;
}

.personal-work-item .work-link::before {
  content: '';
  position: absolute;
  left: 0;
  bottom: 0;
  width: 0;
  height: 100%;
  background-color: var(--accent-lime);
  transition: width 0.3s ease;
  z-index: -1;
}

.personal-work-item .work-link:hover,
.personal-work-item .work-link.active-project {
  color: var(--bg-dark);
  font-weight: 300;
}

.personal-work-item .work-link:hover::before,
.personal-work-item .work-link.active-project::before {
  width: 100%;
}

.personal-work-item p {
  font-size: 1.8vh;
  font-weight: 300;
  line-height: 1.4;
  color: var(--text-dim);
  margin-top: 0;
  margin-bottom: 0.4em;
  margin-left: 0.7vw !important;
  font-style: italic !important;
}

/* ============================================
   DOWNLOAD LINK
   ============================================ */
.cv-download-link {
  display: inline-block;
  color: var(--accent-lime) !important;
  font-size: 1.7vh;
  font-weight: 500;
  margin-top: 1.5vh;
  margin-left: 0 !important;
  text-decoration: none !important;
}

.cv-download-link::before {
  content: none !important;
}

.cv-download-link:hover {
  opacity: 0.6;
}

/* ============================================
   UTILITIES
   ============================================ */
.active, .visible {
  z-index: 9999 !important;
}

/* ============================================
   MOBILE HEADER BLUR BAND
   ============================================ */
.header-blur-band {
  display: none;
}

/* ============================================
   DESKTOP (min-width: 769px)
   ============================================ */
@media (min-width: 769px) {
  body {
    overflow: hidden;
  }
  
  /* Nascondi completamente il tasto back in modalita' desktop */
  .text-box-back {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
  }

  .footer-menu {
    bottom: 20%;
    left: 6%;
    flex-direction: column;
    gap: 0.8vh;
    font-size: 2vh;
    width: auto;
    padding: 0;
    margin: 0;
    align-items: flex-start;
  }

  .footer-title {
    bottom: 14%;
    left: 3%;
    font-size: 5.5vh;
    text-align: left;
    padding: 0;
    margin: 0;
  }

  .footer-subtitle {
    bottom: 14%;
    left: 6%;
    font-size: 2.7vh;
    text-align: left;
    margin: 0;
  }

.text-box, .personal-works-box {
    left: 17vw;
    width: 30vw;
  }

  .text-box-content, .personal-works-content {
    padding-right: 2vw;
    overflow-x: visible;
  }

/* Aumenta l'altezza e aggiusta la posizione SOLO per il pannello about me su desktop */
  #about-textbox {
    max-height: 75vh !important;
    bottom: 15% !important; 
  }

  #about-textbox .text-box-content {
    max-height: 75vh !important;
    padding-bottom: 10vh; /* Dà un po' di respiro alla fine per non tagliare il link */
  }
  
  .text-box p, .personal-works-box p {
    margin-left: 0;
    font-size: 1.8vh;
  }

  .text-box h2, .personal-works-box h2 {
    font-size: 3.2vh;
  }

  #gallery-textbox .text-box-back {
    display: none !important;
  }

  #gallery-textbox {
    bottom: 22.3% !important;
  }

  #gallery-textbox .personal-work-item {
    margin-bottom: 0.7em !important; 
  }

  #contacts-textbox {
  bottom: 18vh; /* Dynamically calculated to match footer link bottom */
  top: auto;
  position: fixed;
}
}

/* ============================================
   TABLET (481px - 768px)
   ============================================ */
@media (min-width: 481px) and (max-width: 768px) {
  .cv-download-link {
    display: inline-block !important;
    position: relative !important;
    z-index: 9999 !important;
    margin-top: 3vh !important;
    margin-bottom: 10vh !important; /* Dà spazio extra per permettere uno scorrimento comodo */
  }

  .footer-menu {
    bottom: auto !important;
  }

  .footer-title {
    bottom: auto !important;
  }

  body.gallery-menu-open #gallery-textbox {
    position: relative !important;
    top: auto !important;
    left: auto !important;
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    max-height: none !important;
    padding: 10vh 5vw 0 5vw !important;
    display: block !important;
    background: transparent !important;
    z-index: 10;
    overflow: visible !important;
    transform: none !important;
  }

  body.gallery-menu-open #gallery-textbox .personal-works-content {
    overflow: visible !important;
    max-height: none !important;
    padding: 0 !important;
    -webkit-mask-image: none !important;
    mask-image: none !important;
  }

  body.gallery-menu-open .gallery-container {
    position: relative !important;
    top: auto !important;
    left: auto !important;
    transform: none !important;
    width: 100% !important;
    height: auto !important;
    max-height: none !important;
    margin: 0 auto !important;
    display: block !important;
    padding: 2vh 5vw 5vh 5vw !important;
  }

  body.gallery-menu-open .footer-title {
    z-index: 200 !important;
    position: fixed !important;
    top: calc(env(safe-area-inset-top) + 1.5vh) !important;
    left: 5vw !important;
  }

  body.gallery-menu-open #gallery-textbox .text-box-back {
    visibility: visible !important;
    opacity: 1 !important;
    pointer-events: auto !important;
    position: fixed !important;
    top: calc(env(safe-area-inset-top) + 2.5vh) !important;
    right: 5vw !important;
    left: auto !important;
  }

body.gallery-menu-open.category-active {
    overflow-y: auto !important;
    height: auto !important;
  }
}

/* ============================================
   MOBILE (max-width: 768px)
   ============================================ */
@media (max-width: 768px) {
  
  /* 1. La banda globale resta a 30 (serve per sfocare il footer-menu) */
  .header-blur-band {
    display: block;
    position: fixed;
    top: 0; left: 0; width: 100vw;
    height: calc(env(safe-area-inset-top) + 6vh); /* <-- RIDOTTO da 8.5vh a 6vh */
    background: linear-gradient(to bottom, rgba(234, 234, 234, 0.98) 0%, rgba(234, 234, 234, 0.65) 50%, rgba(234, 234, 234, 0) 100%);
    backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
    mask-image: linear-gradient(to bottom, black 0%, black 25%, transparent 100%);
    -webkit-mask-image: linear-gradient(to bottom, black 0%, black 25%, transparent 100%);
    z-index: 30 !important;
    pointer-events: none;
  }

  .footer-title {
    position: fixed !important;
    top: calc(env(safe-area-inset-top) + 1.5vh) !important;
    bottom: auto !important;
    left: 5vw !important;
    font-size: 3.8vh !important;
    
    /* FIX: Portiamo il titolo sopra il livello 9999 dei pannelli .active */
    z-index: 10000 !important; 
    
    /* Lo isoliamo dalla sfocatura sottostante per evitare bug visivi (come il tasto back) */
    isolation: isolate; 
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
  }

  .footer-subtitle {
    display: none !important;
  }

  .footer-menu {
    position: relative !important;
    top: calc(env(safe-area-inset-top) + 6.5vh) !important;
    margin-top: -4.5vh !important;
    bottom: auto !important;
    left: 8vw !important;
    font-size: 2.4vh !important;
    gap: 0.5vh !important;
    z-index: 10 !important;
    align-items: flex-start;
  }

  /* 2. Portiamo i pannelli a 40 (scavalcano la banda globale) */
  .text-box, .personal-works-box:not(#gallery-textbox) {
    left: 0 !important;
    top: calc(env(safe-area-inset-top) + 24vh) !important;
    bottom: 0 !important;
    width: 100vw !important;
    max-width: 100vw !important;
    max-height: 76vh !important;
    padding: 0vh 5vw 0vh 5vw !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
    background: transparent !important;
    z-index: 40 !important;
  }

  #gallery-textbox {
    top: calc(env(safe-area-inset-top) + 5vh) !important; /* Prima era + 6.5vh */
    left: 45vw !important;
    width: 50vw !important;
    max-width: 50vw !important;
    padding: 0 !important;
    background: transparent !important;
    min-height: auto !important;
    z-index: 40 !important;
  }

  #gallery-textbox .work-link {
    font-size: 1.9vh !important; /* Prima era 2.4vh */
  }

  /* 3. Banda sfocata LOCALE dentro ai pannelli per sfocare i contenuti in scorrimento */
  .text-box::before, .personal-works-box::before {
    content: '';
    position: fixed;
    top: 0; left: 0; width: 100vw;
    height: calc(env(safe-area-inset-top) + 8.5vh);
    background: linear-gradient(to bottom, rgba(234, 234, 234, 0.98) 0%, rgba(234, 234, 234, 0.65) 50%, rgba(234, 234, 234, 0) 100%);
    backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
    mask-image: linear-gradient(to bottom, black 0%, black 35%, transparent 100%);
    -webkit-mask-image: linear-gradient(to bottom, black 0%, black 35%, transparent 100%);
    z-index: 20 !important; /* SOPRA il testo, SOTTO il tasto back */
    pointer-events: none;
  }

  /* 4. Il testo scorre a livello 10 (sotto la banda locale) */
  .text-box-content, .personal-works-content {
    width: 100% !important;
    max-width: 100% !important;
    height: 100% !important;
    max-height: 100% !important;
    padding-right: 3vw !important;
    padding-bottom: 12vh !important;
    box-sizing: border-box !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    position: relative !important;
    z-index: 10 !important;
  }

  /* 5. Tasto back a livello 50 (Sopra la banda locale e perfettamente intatto) */
  .text-box-back {
    position: fixed !important;
    top: calc(env(safe-area-inset-top) + 1.5vh) !important;
    right: 16vw !important;
    left: auto !important;
    font-size: 2.2vh !important;
    z-index: 1000 !important;
  }
  
  #gallery-textbox .personal-works-content {
    padding: 0 !important;
    overflow: visible !important;
    height: auto !important;
    max-height: none !important;
  }

  #gallery-textbox .personal-work-item {
    margin-bottom: 0.5vh !important;
  }

  #gallery-textbox .work-link {
    font-size: 2.4vh !important;
  }

  /* WORKS TEXTBOX — Mobile side-panel (specificità alta per sovrascrivere .personal-works-box) */
  body.panel-open #works-textbox,
  body.panel-open #works-textbox.active {
    top: calc(env(safe-area-inset-top) + 7.5vh) !important;
    left: 45vw !important;
    width: 50vw !important;
    max-width: 50vw !important;
    max-height: 18vh !important;
    padding: 0 !important;
    background: transparent !important;
    min-height: auto !important;
    z-index: 40 !important;
    overflow: visible !important;
  }

  body.panel-open #works-textbox::before {
    display: none !important;
  }

  body.panel-open #works-textbox .personal-works-content {
    max-height: 20vh !important;
    padding: 0 3vw 0 0 !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    text-align: right !important;
  }

  body.panel-open #works-textbox .personal-work-item {
    margin-bottom: 0.2vh !important;
    text-align: right !important;
    transform-origin: right center !important;
  }

  body.panel-open #works-textbox .work-link {
    font-size: 1.9vh !important;
    padding: 0.02em 0 !important;
  }

  /* IMPORTANTE: non nascondere le categorie sotto i titoli */
  body.panel-open #works-textbox .personal-work-item p {
display: none !important;
  }

  html, body {
    overflow-x: hidden !important;
    overflow-y: auto !important;
    height: auto !important;
    position: relative !important;
  }

body.panel-open:not(.project-gallery-active) {
    overflow: hidden !important;
    height: 100% !important;
    position: fixed !important;
    width: 100% !important;
    top: 0;
    left: 0;
}

body.panel-open.project-gallery-active #works-textbox,
body.panel-open.project-gallery-active #works-textbox.active {
  position: absolute !important;
}

  body {
    padding-top: calc(env(safe-area-inset-top) + 6vh);
    padding-bottom: env(safe-area-inset-bottom) !important;
  }

  .text-box.active,
  .personal-works-box.active {
    overflow: hidden !important;
    max-height: 17vh !important;
  }

  img {
    max-width: 100% !important;
    height: auto !important;
  }

  * {
    max-width: 100vw !important;
    box-sizing: border-box !important;
  }

  .home-profile-box {
    display: none !important;
  }

  #gallery-textbox,
  #gallery-textbox .personal-works-content,
  #gallery-textbox .personal-work-item {
    pointer-events: none !important;
  }

  /* Riattiva i tap SOLO sui testi delle categorie e sul tasto back */
  #gallery-textbox .work-link,
  #gallery-textbox .text-box-back {
    pointer-events: auto !important;
  }

  #about-textbox.active {
    max-height: 70vh !important; /* Prima era forzato a 17vh, aumentalo quanto ti serve (es. 40vh, 50vh) */
  }

/* Blocca lo scroll del pannello genitore */
  #about-textbox,
  #contacts-textbox {
    overflow: hidden !important;
    touch-action: none !important;
    overscroll-behavior: none !important;
  }

  /* Sblocca lo scroll per permettere di leggere il testo e vedere il link in fondo */
  #about-textbox .text-box-content,
  #contacts-textbox .text-box-content {
    overflow-y: auto !important;
    touch-action: auto !important;
    -webkit-overflow-scrolling: touch !important; 
    overscroll-behavior: contain !important;
  }

/* ============================================
   BLOCK BACKGROUND SCROLL (GRID ACTIVE) - GLOBAL
   ============================================ */
body.grid-active .text-box,
body.grid-active .personal-works-box,
body.grid-active .text-box-content,
body.grid-active .personal-works-content,
body.grid-active .gallery-scroll {
  overflow: hidden !important;
  overflow-y: hidden !important;
  touch-action: none !important;
}

body.grid-active > *:not(#gridView):not(#gridToggleBtn):not(script) {
  opacity: 0 !important;
  pointer-events: none !important;
}

.grid-view {
  background-color: var(--bg-dark) !important;
  height: 100dvh !important; /* Usa i viewport dinamici per coprire la barra di Safari */
  overscroll-behavior: none !important; /* Tenta di disabilitare il rimbalzo sui browser supportati */
}

body.panel-open .gallery-container,
body.panel-open .home-profile-box,
body.panel-open .footer-title,
body.panel-open .footer-subtitle,
body.panel-open .header-blur-band,
body.panel-open .mobile-menu-toggle,
body.gallery-menu-open .gallery-container,
body.gallery-menu-open .home-profile-box,
body.gallery-menu-open .footer-title,
body.gallery-menu-open .footer-subtitle,
body.gallery-menu-open .header-blur-band,
body.gallery-menu-open .mobile-menu-toggle {
    touch-action: none !important;
}

/* Sblocca lo scroll (touch) sullo spazio della galleria quando un progetto è aperto */
body.panel-open.project-gallery-active .gallery-container {
    touch-action: auto !important;
}

}

/* ============================================
   EXTRA SMALL (max-width: 480px)
   ============================================ */
@media (max-width: 480px) {
  .cv-download-link {
    margin-left: 0vw !important;
  }

  .footer-title {
    font-size: 3.4vh !important;
    top: calc(env(safe-area-inset-top) + 1vh) !important;
    z-index: 10000 !important;
  }

  .footer-menu {
    top: calc(env(safe-area-inset-top) + 5.5vh) !important;
    left: 8vw !important;
    font-size: 2.2vh !important;
    gap: 0.5vh !important;
  }

  #gallery-textbox {
    top: calc(env(safe-area-inset-top) + 4.2vh) !important; /* Prima era + 5.5vh */
    left: 48vw !important;
  }

  /* Font size compatto uguale a personal works */
  #gallery-textbox .work-link {
    font-size: 1.9vh !important; /* Prima era 2.2vh */
  }

  body.panel-open #works-textbox,
  body.panel-open #works-textbox.active {
    top: calc(env(safe-area-inset-top) + 6.5vh) !important;
    left: 48vw !important;
    width: 50vw !important;
    max-width: 50vw !important;
    max-height: 18vh !important;
    overflow: visible !important;
  }

  body.panel-open #works-textbox .personal-works-content {
    max-height: 18vh !important;
    text-align: right !important;
  }

  body.panel-open #works-textbox .personal-work-item {
    margin-bottom: 0.2vh !important;
    text-align: right !important;
    transform-origin: right center !important;
  }

  body.panel-open #works-textbox .work-link {
    font-size: 1.9vh !important;
  }

  body.panel-open #works-textbox .personal-work-item p {
    display: none !important;
  }

  body.gallery-menu-open #gallery-textbox {
    position: relative !important;
    top: auto !important;
    left: auto !important;
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    max-height: none !important;
    padding: 0 5vw !important;
    background: transparent !important;
    z-index: 40 !important;
    overflow: visible !important;
    transform: none !important;
    display: block !important;
    margin-top: -7.2vh !important;
  }

  body.gallery-menu-open #gallery-textbox .personal-works-content {
    padding: 0 !important;
    overflow: visible !important;
    height: auto !important;
    max-height: none !important;
    text-align: right !important;
  }

  body.gallery-menu-open #gallery-textbox .personal-work-item {
    text-align: right !important;
  }

  body.gallery-menu-open .gallery-container {
    position: relative !important;
    top: auto !important;
    left: auto !important;
    transform: none !important;
    width: 100% !important;
    height: auto !important;
    max-height: none !important;
    margin: 0 auto !important;
    display: block !important;
    padding: 2vh 5vw 5vh 5vw !important;
    overflow: visible !important;
  }

  body.gallery-menu-open .footer-title {
    position: fixed !important;
    z-index: 1000 !important;
  }

  body.gallery-menu-open #gallery-textbox .text-box-back {
    position: fixed !important;
    top: calc(env(safe-area-inset-top) + 1.5vh) !important;
    right: 16vw !important;
    left: auto !important;
    visibility: visible !important;
    opacity: 1 !important;
    pointer-events: auto !important;
    z-index: 1000 !important;
  }
}

/* ============================================
   FIX DEFINITIVO SCROLL GRID VIEW (ANTI-CHAINING)
   ============================================ */
html.grid-active {
    overflow: hidden !important;
}


/* Nasconde fisicamente tutti i pannelli e i testi di background quando la griglia è aperta */
body.grid-active .footer-menu,
body.grid-active .footer-title,
body.grid-active .footer-subtitle,
body.grid-active .header-blur-band,
body.grid-active .text-box,
body.grid-active .personal-works-box,
body.grid-active .gallery-container,
body.grid-active .text-box-back,
body.grid-active .mobile-menu-toggle,
body.grid-active #mobileMenuToggle,
body.grid-active .home-profile-box,
body.grid-active #urban\ volumes-textbox,
body.grid-active #urban\ surfaces-textbox,
body.grid-active #inhabitants-textbox,
body.grid-active #product-textbox,
body.grid-active #miscellaneous-textbox {
    display: none !important;
}

/* ============================================
   PROJECT GALLERY (OVERLAY ATTIVO)
   ============================================ */
/* Riporta la galleria in primo piano, superando l'opacity: 0.2 di base */
body.project-gallery-active .gallery-container {
  opacity: 1 !important;
  pointer-events: auto !important;
  z-index: 99999 !important; 
}

/* Tasto back per chiudere la galleria e tornare alla lista */
.project-gallery-close-btn {
  position: fixed !important;
  top: calc(env(safe-area-inset-top) + 2vh) !important;
  left: 5vw !important;
  font-size: 2vh !important;
  font-weight: 300 !important;
  color: var(--text-main) !important;
  text-decoration: none !important;
  z-index: 100000 !important;
  cursor: pointer !important;
  display: none;
  transition: color 0.3s ease;
}

.project-gallery-close-btn:hover {
  color: var(--accent-lime) !important;
}

body.project-gallery-active .project-gallery-close-btn {
  display: block;
}

/* Stile per la descrizione sotto la foto */
.project-slide-desc {
  width: 100%;
  text-align: left;
  font-size: 1.6vh !important; /* Allineato alla grandezza del titolo foto (photo-name) */
  font-weight: 300;
  margin-top: 0.5vh !important; /* Riduce drasticamente lo spazio vuoto sopra, avvicinandola al titolo/foto */
  margin-left: 1vw;
  color: var(--text-main) !important;
  line-height: 1.4;
}

@media (max-width: 768px) {
.project-slide-desc {
    width: 90%;
    font-size: 1.6vh !important;
    margin-left: 1vw;
    margin-top: 0.5vh !important;
  }
}

strong, b {
  font-weight: 600 !important; 
}

@media (min-width: 769px) {
  .project-gallery-close-btn {
    display: none !important;
  }
}

body, 
.text-box p, 
.personal-works-box p,
.project-slide-desc {
  letter-spacing: -0.02em !important; 
}

@media (hover: none) {
  /* 1. Annulla l'hover finto che rimane incastrato dopo il tap */
  .gallery-nav-arrow:hover,
  .nav-arrow:hover {
    background: transparent !important;
  }
  
  /* 2. Dà un feedback visivo immediato SOLO mentre il dito preme lo schermo */
  .gallery-nav-arrow:active,
  .nav-arrow:active {
    background: rgba(255, 255, 255, 0.05) !important;
  }
}
