.tav-gallery,
.tav-lightbox {
  --tav-gallery-paper: #e7dfc8;
  --tav-gallery-ink: #181512;
  --tav-gallery-line: #6a5b4c;
  color: var(--tav-gallery-paper);
  background: var(--tav-gallery-ink);
  font-family: var(--tavernetta-mono);
}

.tav-gallery [hidden] { display: none !important; }
.tav-gallery-dialog {
  width: min(96vw, 1550px);
  max-width: none;
  max-height: 92dvh;
  margin: auto;
  padding: 0;
  border: 1px solid var(--tav-gallery-line);
  overscroll-behavior: contain;
}

.tav-gallery-dialog[open] { animation: tav-gallery-in .25s ease-out; }
.tav-gallery-dialog::backdrop, .tav-lightbox::backdrop { background: #110e0de6; }
.tav-gallery-content { width: min(100%, 1500px); margin-inline: auto; container-type: inline-size; }

.tav-gallery-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: .85rem 1.5rem;
  align-items: center;
  padding: clamp(1.25rem, 3vw, 2.7rem) clamp(1rem, 3.3vw, 3rem) 1rem;
  background: var(--tav-gallery-ink);
  border-bottom: 1px solid var(--tav-gallery-line);
}

.tav-gallery-dialog .tav-gallery-header { position: sticky; top: 0; z-index: 2; }
body.tavernetta .tav-gallery-header :is(h1, h2) {
  font: 800 clamp(2.5rem, 6vw, 5.2rem)/.94 var(--tavernetta-mono);
  letter-spacing: -.055em;
  text-transform: uppercase;
}

.tav-gallery-icon {
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--tav-gallery-line);
  border-radius: 0;
  color: inherit;
  background: transparent;
  cursor: pointer;
}

.tav-gallery-icon:hover {
  color: var(--tav-gallery-ink);
  background: var(--tav-gallery-paper);
  border-color: var(--tav-gallery-paper);
}

.tav-gallery-icon { width: 44px; height: 44px; padding: 0; font: 400 1.65rem/1 var(--tavernetta-mono); }
.tav-gallery-grid {
  --tav-gallery-gap: clamp(.5rem, 1.35vw, 1.15rem);
  --tav-gallery-columns: 4;
  --tav-gallery-padding: clamp(.75rem, 3.3vw, 3rem);
  --tav-gallery-cell: calc((100cqw - 2 * var(--tav-gallery-padding) - (var(--tav-gallery-columns) - 1) * var(--tav-gallery-gap)) / var(--tav-gallery-columns));
  display: grid;
  grid-template-columns: repeat(var(--tav-gallery-columns), minmax(0, 1fr));
  grid-auto-rows: var(--tav-gallery-cell);
  grid-auto-flow: row dense;
  gap: var(--tav-gallery-gap);
  align-items: stretch;
  padding: clamp(.75rem, 2.8vw, 2.5rem) var(--tav-gallery-padding) clamp(1rem, 3.3vw, 3rem);
}

body.tavernetta .tav-gallery-tile {
  display: block;
  position: relative;
  width: 100%;
  min-width: 0;
  min-height: 0;
  height: 100%;
  margin: 0;
  vertical-align: top;
  break-inside: avoid;
  isolation: isolate;
  background: #2e231d;
}

.tav-gallery-tile a { position: relative; display: block; overflow: hidden; width: 100%; height: 100%; }
.tav-gallery-tile a:focus-visible { z-index: 1; outline-offset: -3px; }
body.tavernetta .tav-gallery-thumb {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  transition: transform .35s ease;
}

.tav-gallery-tile a:hover .tav-gallery-thumb { transform: scale(1.05); }
.tav-gallery-zoom {
  position: absolute;
  z-index: 1;
  inset: .6rem .6rem auto auto;
  display: grid;
  place-items: center;
  width: 1.95rem;
  height: 1.95rem;
  border: 1px solid #e7dfc892;
  background: #211915a6;
  font-weight: 700;
}

.tav-lightbox {
  width: min(96vw, 1450px);
  max-width: none;
  max-height: 96dvh;
  margin: auto;
  padding: 0;
  border: 1px solid var(--tav-gallery-line);
}

.tav-lightbox-inner {
  position: relative;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  align-items: center;
  gap: .6rem;
  padding: 3.2rem .6rem .75rem;
}

.tav-lightbox-close { position: absolute; inset: .35rem .6rem auto auto; }
.tav-lightbox-stage { min-width: 0; touch-action: pan-y; }
.tav-lightbox-stage img {
  display: block;
  width: 100%;
  height: min(68dvh, 61vw);
  object-fit: contain;
}

.tav-lightbox-stage figcaption { margin-top: .5rem; text-align: end; font-size: .78rem; }


/* Mosaico: moduli 2x1, 1x2 e 1x1. Ogni blocco si chiude su 4 e 2 colonne. */
.tav-gallery-grid > .tav-gallery-tile:nth-child(36n + 2),
.tav-gallery-grid > .tav-gallery-tile:nth-child(36n + 3),
.tav-gallery-grid > .tav-gallery-tile:nth-child(36n + 4),
.tav-gallery-grid > .tav-gallery-tile:nth-child(36n + 5),
.tav-gallery-grid > .tav-gallery-tile:nth-child(36n + 21),
.tav-gallery-grid > .tav-gallery-tile:nth-child(36n + 23),
.tav-gallery-grid > .tav-gallery-tile:nth-child(36n + 25),
.tav-gallery-grid > .tav-gallery-tile:nth-child(36n + 29),
.tav-gallery-grid > .tav-gallery-tile:nth-child(36n + 32),
.tav-gallery-grid > .tav-gallery-tile:nth-child(36n + 35),
.tav-gallery-grid > .tav-gallery-tile:nth-child(36n + 36) { grid-column: span 2; }

.tav-gallery-grid > .tav-gallery-tile:nth-child(36n + 6),
.tav-gallery-grid > .tav-gallery-tile:nth-child(36n + 7),
.tav-gallery-grid > .tav-gallery-tile:nth-child(36n + 9),
.tav-gallery-grid > .tav-gallery-tile:nth-child(36n + 10),
.tav-gallery-grid > .tav-gallery-tile:nth-child(36n + 13),
.tav-gallery-grid > .tav-gallery-tile:nth-child(36n + 14),
.tav-gallery-grid > .tav-gallery-tile:nth-child(36n + 15),
.tav-gallery-grid > .tav-gallery-tile:nth-child(36n + 17),
.tav-gallery-grid > .tav-gallery-tile:nth-child(36n + 22),
.tav-gallery-grid > .tav-gallery-tile:nth-child(36n + 24),
.tav-gallery-grid > .tav-gallery-tile:nth-child(36n + 27),
.tav-gallery-grid > .tav-gallery-tile:nth-child(36n + 33),
.tav-gallery-grid > .tav-gallery-tile:nth-child(36n + 34) { grid-row: span 2; }

@media (max-width: 900px) {
  .tav-gallery-grid { --tav-gallery-columns: 2; }
}

@keyframes tav-gallery-in {
  from { opacity: .5; transform: translateY(.6rem); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 640px) {
  .tav-gallery-dialog { width: 100%; max-height: 100dvh; border-inline: 0; }
  .tav-gallery-header { padding-top: max(1rem, env(safe-area-inset-top, 0px)); }
  .tav-gallery-zoom { width: 1.5rem; height: 1.5rem; inset: .4rem .4rem auto auto; font-size: .78rem; }
  .tav-lightbox-inner { grid-template-columns: 1fr 1fr; }
  .tav-lightbox-stage { grid-area: 1 / 1 / 2 / 3; }
  .tav-lightbox-stage img { height: min(58dvh, 105vw); }
  .tav-lightbox-prev { grid-area: 2 / 1; }
  .tav-lightbox-next { grid-area: 2 / 2; justify-self: end; }
}
