:root{
  --bg0:#05060a;
  --bg1:#0b0f18;
  --glass: rgba(255,255,255,.08);
  --stroke: rgba(255,255,255,.14);
  --text: rgba(255,255,255,.92);
  --muted: rgba(255,255,255,.62);
  --green: 140 75% 45%;
}

*{ box-sizing:border-box; margin:0; padding:0; }
html,body{ height:100%; }

body{
  font-family: "Poppins", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1000px 600px at 15% 10%, rgba(120,180,255,.10), transparent 60%),
    radial-gradient(900px 700px at 90% 20%, rgba(255,120,220,.10), transparent 55%),
    radial-gradient(1200px 800px at 50% 100%, rgba(60,255,170,.08), transparent 60%),
    linear-gradient(180deg, var(--bg0), var(--bg1));
  overflow-x:hidden;
}

/* Top bar */
.topbar{
  max-width: 1100px;
  margin: 22px auto 0;
  padding: 0 18px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:14px;
  flex-wrap:wrap;
}

.title{
  text-align:center;
  flex: 1 1 260px;
}
.title h1{
  font-size: 22px;
  font-weight: 800;
}
.title p{
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

.pill{
  display:inline-flex;
  align-items:center;
  gap:10px;
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.14);
  text-decoration:none;
  color: var(--text);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: transform .2s ease, background .2s ease, border-color .2s ease;
}
.pill:hover{
  transform: translateY(-1px);
  background: rgba(255,255,255,.09);
  border-color: rgba(255,255,255,.22);
}

.cta{
  display:inline-flex;
  align-items:center;
  gap:10px;
  padding: 12px 16px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.16);
  background: radial-gradient(600px 220px at 20% 0%, hsl(var(--green)/.35), rgba(255,255,255,.06) 55%);
  color: var(--text);
  cursor:pointer;
  box-shadow: 0 12px 40px rgba(0,0,0,.35);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: transform .2s ease, border-color .2s ease, background .2s ease;
}
.cta:hover{
  transform: translateY(-1px);
  border-color: rgba(255,255,255,.25);
  background: radial-gradient(700px 260px at 30% 0%, hsl(var(--green)/.45), rgba(255,255,255,.08) 58%);
}

/* Contenitore pulsante+toggle (nel tuo gallery.html) */
.actions{
  display:flex;
  align-items:center;
  gap: 12px;
  flex: 0 0 auto;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.wrap{
  max-width: 1100px;
  margin: 18px auto 40px;
  padding: 0 18px;
}

.hint{
  margin-top: 14px;
  padding: 14px 16px;
  border-radius: 16px;
  background: rgba(255,255,255,.05);
  border: 1px solid rgba(255,255,255,.10);
  color: rgba(255,255,255,.70);
  font-size: 13px;
}
code{
  background: rgba(255,255,255,.08);
  padding: 2px 7px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,.10);
}

/* Section */
.grid-section{
  margin-top: 18px;
  padding: 16px;
  border-radius: 18px;
  background: rgba(255,255,255,.05);
  border: 1px solid rgba(255,255,255,.10);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.grid-head{
  display:flex;
  align-items:baseline;
  justify-content:space-between;
  gap:12px;
  margin-bottom: 12px;
}
.grid-head h2{
  font-size: 18px;
  font-weight: 800;
}
.meta{
  color: var(--muted);
  font-size: 13px;
}

/* =========================================================
   CAROUSEL (CSS-tricks style) + responsive
   ========================================================= */
.carousel{
  margin: 10px 0 18px;
}

.carousel__wrap{
  display:grid;
  grid-template-columns: 150px 1fr;
  gap: 14px;
  align-items: start;
}

@media (max-width: 820px){
  .carousel__wrap{
    grid-template-columns: 1fr;
  }
}

/* Miniature */
.lil-nav{
  border-radius: 16px;
  border: 1px solid rgba(255,255,255,.10);
  background: rgba(255,255,255,.05);
  padding: 10px;
  overflow-y: auto;
  max-height: clamp(240px, 58vh, 520px);
  display:flex;
  flex-direction: column;
  gap: 10px;
}

@media (max-width: 820px){
  .lil-nav{
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    max-height: none;
    padding: 10px;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
  }
  .lil-nav::-webkit-scrollbar{ height: 10px; }
}

.lil-nav a{
  display:block;
  border-radius: 14px;
  overflow:hidden;
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(0,0,0,.25);
  flex: 0 0 auto;
  width: 100%;
  height: 92px;
  transition: transform .16s ease, border-color .16s ease;
}

@media (max-width: 820px){
  .lil-nav a{
    width: 120px;
    height: 80px;
    scroll-snap-align: start;
  }
}

.lil-nav__img{
  width:100%;
  height:100%;
  object-fit: cover;
  display:block;
  transform: scale(1.05);
  transition: transform .25s ease, filter .25s ease;
  filter: saturate(1.1) contrast(1.05);
}
.lil-nav a:hover{
  transform: translateY(-1px);
  border-color: rgba(255,255,255,.22);
}
.lil-nav a:hover .lil-nav__img{
  transform: scale(1.12);
  filter: saturate(1.25) contrast(1.1);
}
.lil-nav a[aria-current="true"]{
  outline: 2px solid rgba(255,255,255,.35);
  outline-offset: 2px;
  border-color: rgba(255,255,255,.25);
}

/* Area grande */
.gallery{
  border-radius: 18px;
  border: 1px solid rgba(255,255,255,.10);
  background: rgba(255,255,255,.04);
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  display:flex;
  gap: 0;
  height: clamp(280px, 58vh, 520px);
}
.gallery::-webkit-scrollbar{ height: 10px; }

.gallery__item{
  scroll-snap-align: start;
  flex: 0 0 100%;
  height: 100%;
  position: relative;
}

.gallery__img{
  width:100%;
  height:100%;
  object-fit: cover;
  display:block;
  cursor: zoom-in;
}

/* Badge: titolo + fiera + bottone */
.gallery__badge{
  position:absolute;
  left: 12px;
  bottom: 12px;
  right: 12px;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(0,0,0,.35);
  border: 1px solid rgba(255,255,255,.14);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display:grid;
  gap: 6px;
}

.badge__title{
  font-weight: 700;
  font-size: 13px;
  opacity: .95;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.badge__sub{
  font-size: 12px;
  opacity: .78;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.badge__btn{
  justify-self: start;
  margin-top: 2px;
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,.18);
  background: rgba(255,255,255,.08);
  color: rgba(255,255,255,.92);
  cursor: pointer;
  font-size: 12px;
  transition: transform .15s ease, background .15s ease, border-color .15s ease;
}
.badge__btn:hover{
  transform: translateY(-1px);
  background: rgba(255,255,255,.12);
  border-color: rgba(255,255,255,.26);
}

/* =========================================================
   GROUPS (album per fiera)
   ========================================================= */
#grid.grid{ display:block; }

.group{
  margin-top: 18px;
  scroll-margin-top: 90px;
}

.group-head{
  display:flex;
  justify-content:space-between;
  align-items:baseline;
  gap:12px;
  margin-bottom:10px;
}
.group-title{
  margin:0;
  font-size:18px;
  font-weight:800;
}
.group-meta{
  opacity:.75;
  font-size:13px;
}

/* flash quando arrivi all’album */
.group.album-flash{
  animation: albumFlash .9s ease;
  outline: 3px solid rgba(255,255,255,.18);
  outline-offset: 6px;
  border-radius: 18px;
}
@keyframes albumFlash{
  0%{ outline-color: rgba(255,255,255,0); transform: translateY(0); }
  35%{ outline-color: rgba(255,255,255,.35); transform: translateY(-1px); }
  100%{ outline-color: rgba(255,255,255,0); transform: translateY(0); }
}

.group-grid{
  display:grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 12px;
}
@media (max-width: 420px){
  .group-grid{ grid-template-columns: repeat(2, 1fr); }
}

/* Thumbs */
.thumb{
  position:relative;
  border-radius: 16px;
  overflow:hidden;
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(0,0,0,.25);
  cursor:pointer;
  box-shadow: 0 10px 30px rgba(0,0,0,.25);
  transition: transform .2s ease, border-color .2s ease;
  aspect-ratio: 1 / 1;
  width:100%;
}
.thumb:hover{
  transform: translateY(-2px);
  border-color: rgba(255,255,255,.24);
}
.thumb img{
  width:100%;
  height:100%;
  object-fit:cover;
  display:block;
  transform: scale(1.06);
  transition: transform .6s cubic-bezier(.2,.8,.2,1), filter .25s ease;
  filter: saturate(1.05) contrast(1.05);
}
.thumb:hover img{
  transform: scale(1.12);
  filter: saturate(1.2) contrast(1.1);
}
.thumb .label{
  position:absolute;
  left:10px; right:10px; bottom:10px;
  padding: 8px 10px;
  border-radius: 12px;
  background: rgba(0,0,0,.35);
  border: 1px solid rgba(255,255,255,.14);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  font-size: 12px;
  color: rgba(255,255,255,.82);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Empty state */
.empty{
  margin: 18px auto 8px;
  padding: 22px 14px;
  text-align:center;
  border-radius: 16px;
  border: 1px dashed rgba(255,255,255,.18);
  color: rgba(255,255,255,.70);
}
.empty i{
  font-size: 34px;
  opacity:.8;
  margin-bottom: 10px;
  display:block;
}

/* Lightbox */
.lightbox{
  position:fixed; inset:0;
  background: rgba(0,0,0,.72);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display:grid;
  place-items:center;
  padding: 18px;
  z-index: 50;
}
/* IMPORTANTISSIMO: quando hidden deve sparire davvero */
.lightbox[hidden]{ display:none !important; }

.lightbox img{
  max-width: min(980px, 92vw);
  max-height: 78vh;
  border-radius: 18px;
  border: 1px solid rgba(255,255,255,.18);
  box-shadow: 0 18px 70px rgba(0,0,0,.5);
  background: rgba(255,255,255,.06);
}
.lb-close{
  position:absolute;
  top: 14px; right: 14px;
  width: 44px; height: 44px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.18);
  background: rgba(255,255,255,.08);
  color: var(--text);
  cursor:pointer;
  z-index: 5;
}
.lb-close:hover{
  background: rgba(255,255,255,.12);
  border-color: rgba(255,255,255,.26);
}
.lb-caption{
  margin-top: 12px;
  color: rgba(255,255,255,.78);
  font-size: 13px;
  text-align:center;
  max-width: min(980px, 92vw);
}

/* Loader */
.loader{
  position:fixed; inset:0;
  display:grid;
  place-items:center;
  background:
    radial-gradient(900px 500px at 20% 10%, rgba(120,180,255,.14), transparent 60%),
    radial-gradient(900px 700px at 85% 30%, rgba(255,120,220,.12), transparent 60%),
    linear-gradient(180deg, #05060a, #070b12);
  z-index: 100;
}
.loader-card{
  width: min(460px, 90vw);
  padding: 22px 18px;
  border-radius: 20px;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.12);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 18px 70px rgba(0,0,0,.45);
  display:grid;
  grid-template-columns: 90px 1fr;
  gap: 16px;
  align-items:center;
}
.orb{
  width: 76px; height: 76px;
  border-radius: 999px;
  background: radial-gradient(circle at 30% 30%, rgba(255,255,255,.95), rgba(120,180,255,.25));
  box-shadow: 0 0 30px rgba(120,180,255,.35);
  position: relative;
  margin: 0 auto;
}
.rings{
  position:absolute;
  inset: -18px;
  display:grid;
  place-items:center;
}
.rings span{
  position:absolute;
  width: 130px; height: 130px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.14);
  box-shadow: inset 0 0 22px rgba(120,180,255,.12);
  animation: spin 1.6s linear infinite;
}
.rings span:nth-child(2){
  width: 100px; height: 100px;
  animation-duration: 1.15s;
  opacity:.8;
}
.rings span:nth-child(3){
  width: 70px; height: 70px;
  animation-duration: .85s;
  opacity:.7;
}
@keyframes spin{ to { transform: rotate(360deg); } }

.loading-text strong{
  display:block;
  font-size: 16px;
  font-weight: 800;
}
.loading-text span{
  display:block;
  margin-top: 6px;
  color: rgba(255,255,255,.70);
  font-size: 13px;
}

.loader.hide{
  opacity:0;
  pointer-events:none;
  transition: opacity .35s ease;
}

/* =========================================================
   GHOST TOGGLE (tema) - stile preso dall’effetto “ghost”
   ========================================================= */
.theme-toggle{
  display:flex;
  align-items:center;
  gap:10px;
  padding: 8px 10px;
  border-radius: 999px;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.14);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

.theme-ico{
  width: 18px;
  height: 18px;
  display:grid;
  place-items:center;
  opacity: .85;
  font-size: 14px;
}

.switch{
  position: relative;
  display: inline-block;
  width: 96px;
  height: 26px;
}

.switch input{
  opacity: 0;
  width: 0;
  height: 0;
}

.slider{
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: rgba(255,255,255,.18);
  border: 1px solid rgba(255,255,255,.18);
  transition: .4s;
  border-radius: 999px;
}

.switch input:checked + .slider{
  background-color: #459def;
  border-color: rgba(69,157,239,.65);
}

.slider .knob{
  position:absolute;
  top: 50%;
  left: 6px;
  transform: translate(0, -50%);
  transition: transform .4s;
  width: 40px;
  height: 40px;
}

.switch input:checked + .slider .knob{
  transform: translate(58px, -50%);
}

.ghost{
  position: absolute;
  left: 0;
  top: 0;
  width: 40px;
  height: 40px;
  background-color: white;
  border-radius: 100px;
  animation: bobble 4.3s infinite;
  filter: drop-shadow(0px 5px 12px rgba(255, 255, 255, 0.55));
}

@keyframes bobble{
  0%{ transform: translateY(0); }
  50%{ transform: translateY(15%); }
  100%{ transform: translateY(0); }
}

@keyframes sway{
  0%{ transform: translateX(-2px); }
  50%{ transform: translateX(2px); }
  100%{ transform: translateX(-2px); }
}

@keyframes sway-more{
  0%{ transform: translateX(-4px); }
  50%{ transform: translateX(4px); }
  100%{ transform: translateX(-4px); }
}

@keyframes blink{
  0%{ top: 16px; height: 8px; }
  39%{ top: 16px; height: 8px; }
  40%{ top: 20px; height: 2px; }
  50%{ top: 20px; height: 2px; }
  51%{ top: 16px; height: 8px; }
  100%{ top: 16px; height: 8px; }
}

.ghost:after{
  content:"";
  position:absolute;
  left: calc(50% - 7px);
  top: 16px;
  width: 10px;
  height: 8px;
  border-right: 3px solid black;
  border-left: 3px solid black;
  animation: bobble 2s infinite, sway-more 2s infinite 1s, blink 4.25s infinite;
}

.ghost:before{
  content:"";
  position:absolute;
  top: calc(50% - 6px);
  left: -10%;
  width: 120%;
  height: 12px;
  border-radius: 100px;
  background-color: white;
  animation: sway 2s infinite;
}

/* =========================================================
   LIGHT MODE overrides (gallery)
   ========================================================= */
html[data-theme="light"]{
  --bg0:#f6f8ff;
  --bg1:#ffffff;
  --glass: rgba(0,0,0,.04);
  --stroke: rgba(0,0,0,.10);
  --text: rgba(10,12,16,.92);
  --muted: rgba(10,12,16,.55);
}

html[data-theme="light"] body{
  color: var(--text);
  background:
    radial-gradient(1000px 600px at 15% 10%, rgba(120,180,255,.22), transparent 60%),
    radial-gradient(900px 700px at 90% 20%, rgba(255,120,220,.18), transparent 55%),
    radial-gradient(1200px 800px at 50% 100%, rgba(60,255,170,.14), transparent 60%),
    linear-gradient(180deg, var(--bg0), var(--bg1));
}

/* vetri principali */
html[data-theme="light"] .pill,
html[data-theme="light"] .cta,
html[data-theme="light"] .hint,
html[data-theme="light"] .grid-section,
html[data-theme="light"] .lil-nav,
html[data-theme="light"] .gallery,
html[data-theme="light"] .theme-toggle{
  border-color: rgba(0,0,0,.10) !important;
}

html[data-theme="light"] .pill{
  background: rgba(0,0,0,.04);
  color: var(--text);
}

html[data-theme="light"] .cta{
  background: radial-gradient(600px 220px at 20% 0%, hsl(var(--green)/.20), rgba(0,0,0,.02) 55%);
  box-shadow: 0 12px 40px rgba(0,0,0,.18);
  color: var(--text);
}

html[data-theme="light"] .hint,
html[data-theme="light"] .grid-section{
  background: rgba(255,255,255,.65);
  color: rgba(10,12,16,.70);
}

html[data-theme="light"] code{
  background: rgba(0,0,0,.04);
  border-color: rgba(0,0,0,.10);
}

/* thumbs/nav */
html[data-theme="light"] .lil-nav a,
html[data-theme="light"] .thumb{
  background: rgba(255,255,255,.70);
  border-color: rgba(0,0,0,.10);
  box-shadow: 0 10px 30px rgba(0,0,0,.12);
}

html[data-theme="light"] .lil-nav a:hover{
  border-color: rgba(0,0,0,.18);
}

/* badge e label (da scuro -> chiaro) */
html[data-theme="light"] .gallery__badge,
html[data-theme="light"] .thumb .label{
  background: rgba(255,255,255,.70);
  border-color: rgba(0,0,0,.10);
  color: rgba(10,12,16,.88);
}

html[data-theme="light"] .badge__btn{
  background: rgba(0,0,0,.04);
  border-color: rgba(0,0,0,.12);
  color: rgba(10,12,16,.90);
}
html[data-theme="light"] .badge__btn:hover{
  background: rgba(0,0,0,.07);
  border-color: rgba(0,0,0,.18);
}

/* empty */
html[data-theme="light"] .empty{
  border-color: rgba(0,0,0,.16);
  color: rgba(10,12,16,.70);
}

/* slider base in light */
html[data-theme="light"] .slider{
  background-color: rgba(0,0,0,.08);
  border-color: rgba(0,0,0,.12);
}

/* lightbox (resta dark, ma bilanciato) */
html[data-theme="light"] .lightbox{
  background: rgba(0,0,0,.68);
}

/* loader più "day" */
html[data-theme="light"] .loader{
  background:
    radial-gradient(900px 500px at 20% 10%, rgba(120,180,255,.18), transparent 60%),
    radial-gradient(900px 700px at 85% 30%, rgba(255,120,220,.14), transparent 60%),
    linear-gradient(180deg, #f6f8ff, #ffffff);
}
html[data-theme="light"] .loader-card{
  background: rgba(255,255,255,.75);
  border-color: rgba(0,0,0,.10);
  box-shadow: 0 18px 70px rgba(0,0,0,.18);
}
html[data-theme="light"] .rings span{
  border-color: rgba(0,0,0,.10);
  box-shadow: inset 0 0 22px rgba(120,180,255,.10);
}
html[data-theme="light"] .loading-text span{
  color: rgba(10,12,16,.62);
}
