/* ==========================================================================
   SOUND ALCHEMISTS — Works (Sound Design): filtri, griglia di card, lightbox
   Il markup della sezione sta in sound-design.html; le schede e le card le
   crea assets/js/works.js. Solo variabili di tokens.css: il tema (espresso /
   petrolio) arriva dalla classe sul <body> e, per il lightbox, copiata sul
   <dialog> (che sta fuori da <main>).
   ========================================================================== */

/* --- Filtri --------------------------------------------------------------- */
.works { display: block; }

.works__filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 32px;
  border-bottom: 1px solid var(--line);
}

/* La scheda attiva scende di 1px (margin-bottom negativo) per coprire il
   filetto del contenitore con la propria sottolineatura sabbia. */
.works__tab {
  margin: 0 0 -1px;
  padding: 8px 0 12px;
  border: 0;
  border-bottom: 1px solid transparent;
  background: none;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  letter-spacing: .1em;
  text-transform: lowercase;
  white-space: nowrap;
  color: var(--muted);
  transition: color .3s;
}
.works__tab:hover { color: var(--sand); }
.works__tab.is-active {
  color: var(--sand);
  border-bottom-color: var(--sand);
}

/* --- Griglia -------------------------------------------------------------- */
.works__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr));
  gap: 40px 28px;
  margin-top: 12px;
}

/* La card è UN bottone: tutta cliccabile e raggiungibile da tastiera. */
.work {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  font: inherit;
  text-align: left;
  color: inherit;
}

.work__media {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: var(--card);
  overflow: hidden;
}
.work__zoom {
  position: absolute;
  inset: 0;
  display: block;
  transition: transform .8s var(--ease-soft);
}
.work__zoom img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.work:hover .work__zoom,
.work:focus-visible .work__zoom { transform: scale(1.04); }

/* Velo con "watch" e il cerchio play: appare su hover E su focus da tastiera */
.work__veil {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: 16px;
  pointer-events: none;
  background: linear-gradient(to top, rgba(20, 16, 12, .7), transparent 55%);
  opacity: 0;
  transition: opacity .4s ease;
}
.work:hover .work__veil,
.work:focus-visible .work__veil { opacity: 1; }

.work__watch {
  font-size: 11px;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--sand);
}
.work__play {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--sand);
  color: var(--sand);
}
/* Il triangolo ha il baricentro a sinistra: 2px a destra lo centrano otticamente */
.work__play svg { margin-left: 2px; }

.work__title {
  margin-top: 6px;
  font-size: 13px;
  letter-spacing: .08em;
  overflow-wrap: anywhere;
}
.work__cat {
  font-size: 15px;
  font-weight: 300;
  color: var(--muted);
}

/* --- Lightbox ------------------------------------------------------------- */
/* Pagina sotto ferma mentre il lightbox è aperto (classe messa da works.js) */
html.has-lightbox { overflow: hidden; }

.lightbox {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  color: var(--sand);
  background: var(--bg);
  /* ~96% di opacità: la pagina sotto si intuisce appena. Il ripiego a tinta
     piena è per i browser senza color-mix. */
  background: color-mix(in srgb, var(--bg) 96%, transparent);
}
.lightbox:focus-visible { outline: none; }
.lightbox[open] {
  display: flex;
  animation: lightbox-in .35s ease;
}
.lightbox::backdrop { background: rgba(20, 16, 12, .85); }
.lightbox[open]::backdrop { animation: lightbox-in .35s ease; }

/* La cornice è centrata sia in orizzontale sia in verticale; se il contenuto
   è più alto dello schermo il margine automatico si azzera e si scorre. Su
   schermi bassi il video si restringe (in 16:9) per lasciare spazio al testo. */
.lightbox__frame {
  --lb-media: min(1100px, max(280px, calc((100vh - 250px) * 16 / 9)));
  width: min(100%, calc(var(--lb-media) + 2 * var(--gutter)));
  margin: auto;
  padding: 20px var(--gutter) 40px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.lightbox[open] .lightbox__frame { animation: lightbox-rise .45s var(--ease) both; }

@keyframes lightbox-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes lightbox-rise {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: none; }
}

.lightbox__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.lightbox__count {
  font-size: 12px;
  letter-spacing: .14em;
  color: var(--faint);
}
.lightbox__ctrls { display: flex; gap: 8px; margin-left: auto; }
.lightbox__btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--sand);
  background: transparent;
  color: var(--sand);
  cursor: pointer;
  transition: background .3s, color .3s;
}
.lightbox__btn:hover { background: var(--sand); color: var(--on-sand); }
.lightbox__btn svg { width: 18px; height: 18px; }

/* Il palco resta 16:9 qualunque cosa ci sia dentro e non sfora mai la cornice */
.lightbox__stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: var(--card);
  overflow: hidden;
}
.lightbox__stage > video,
.lightbox__stage > img,
.lightbox__stage > iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}
/* Un filmato non esattamente 16:9 (o verticale) lascia bande: con lo sfondo
   della pagina si fondono, col colore --card sembrerebbero un difetto. */
.lightbox__stage > video,
.lightbox__stage > img {
  object-fit: contain;
  background: var(--bg);
}
.lightbox__error {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  font-size: 15px;
  font-weight: 300;
  color: var(--muted);
}

.lightbox__info { display: flex; flex-direction: column; gap: 10px; }
.lightbox__title {
  font-size: clamp(20px, 2.4vw, 28px);
  font-weight: 400;
  letter-spacing: -.015em;
  line-height: 1.2;
  overflow-wrap: anywhere;
}
.lightbox__meta {
  font-size: 12px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--sand-dark);
}
.lightbox__desc {
  max-width: 680px;
  margin-top: 6px;
  font-size: 15px;
  font-weight: 300;
  line-height: 1.6;
  color: var(--muted);
  text-wrap: pretty;
}

/* Niente animazione di apertura per chi chiede meno movimento */
@media (prefers-reduced-motion: reduce) {
  .lightbox[open],
  .lightbox[open]::backdrop,
  .lightbox[open] .lightbox__frame { animation: none; }
  .work__zoom { transition: none; }
}
