.sbaleno-editorial-gallery {
  display: grid;
  gap: clamp(1rem, 2.5vw, 1.5rem);
  margin-block: clamp(0.5rem, 2vw, 1rem);
}

.sbaleno-editorial-gallery__header {
  display: flex;
  max-width: 760px;
  align-items: end;
  justify-content: space-between;
  gap: 1.25rem;
  margin-inline: auto;
}

.sbaleno-editorial-gallery__header > div {
  display: grid;
  gap: 0.45rem;
}

.sbaleno-editorial-gallery__header :is(h2, p),
.sbaleno-editorial-gallery__count {
  margin: 0;
}

.sbaleno-editorial-gallery__header h2 {
  font-size: clamp(2rem, 3.7vw, 3.15rem);
  line-height: 1.05;
}

.sbaleno-editorial-gallery__header p {
  max-width: 60ch;
  color: var(--wp--preset--color--muted);
  line-height: 1.6;
}

.sbaleno-editorial-gallery__count {
  display: inline-grid;
  width: 2.75rem;
  min-width: 2.75rem;
  height: 2.75rem;
  place-items: center;
  border: 1px solid var(--wp--preset--color--border);
  border-radius: 999px;
  color: var(--wp--preset--color--primary-dark);
  font-size: var(--wp--preset--font-size--small);
  font-weight: 760;
}

.sbaleno-editorial-gallery__grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  grid-template-rows: repeat(3, clamp(7rem, 13vw, 12rem));
  gap: clamp(0.45rem, 1vw, 0.8rem);
  margin: 0;
  padding: 0;
}

.sbaleno-editorial-gallery__item {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  margin: 0;
  border-radius: var(--wp--custom--radius--md);
  background: var(--wp--preset--color--surface);
}

.sbaleno-editorial-gallery__item:nth-child(1) {
  grid-column: 1 / 8;
  grid-row: 1 / 4;
}

.sbaleno-editorial-gallery__item:nth-child(2) {
  grid-column: 8 / 13;
  grid-row: 1;
}

.sbaleno-editorial-gallery__item:nth-child(3),
.sbaleno-editorial-gallery__item:nth-child(5) {
  grid-column: 8 / 10;
}

.sbaleno-editorial-gallery__item:nth-child(4),
.sbaleno-editorial-gallery__item:nth-child(6) {
  grid-column: 10 / 13;
}

.sbaleno-editorial-gallery__item:nth-child(3),
.sbaleno-editorial-gallery__item:nth-child(4) {
  grid-row: 2;
}

.sbaleno-editorial-gallery__item:nth-child(5),
.sbaleno-editorial-gallery__item:nth-child(6) {
  grid-row: 3;
}

.sbaleno-editorial-gallery__item:nth-child(n + 7) {
  grid-column: span 4;
  grid-row: auto;
  aspect-ratio: 4 / 3;
}

.sbaleno-editorial-gallery__grid[data-gallery-size="4"],
[data-gallery-size="4"] > .sbaleno-editorial-gallery__grid {
  grid-template-rows: repeat(2, clamp(8rem, 17vw, 15rem));
}

.sbaleno-editorial-gallery__grid[data-gallery-size="5"] .sbaleno-editorial-gallery__item:nth-child(5),
[data-gallery-size="5"] > .sbaleno-editorial-gallery__grid .sbaleno-editorial-gallery__item:nth-child(5) {
  grid-column: 8 / 13;
}

.sbaleno-editorial-gallery__grid[data-gallery-size="1"],
[data-gallery-size="1"] > .sbaleno-editorial-gallery__grid {
  display: block;
}

.sbaleno-editorial-gallery__grid[data-gallery-size="1"] .sbaleno-editorial-gallery__item,
[data-gallery-size="1"] > .sbaleno-editorial-gallery__grid .sbaleno-editorial-gallery__item {
  aspect-ratio: 16 / 9;
}

.sbaleno-editorial-gallery__grid[data-gallery-size="2"],
.sbaleno-editorial-gallery__grid[data-gallery-size="3"],
[data-gallery-size="2"] > .sbaleno-editorial-gallery__grid,
[data-gallery-size="3"] > .sbaleno-editorial-gallery__grid {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 18rem), 1fr));
  grid-template-rows: none;
}

.sbaleno-editorial-gallery__grid[data-gallery-size="2"] .sbaleno-editorial-gallery__item,
.sbaleno-editorial-gallery__grid[data-gallery-size="3"] .sbaleno-editorial-gallery__item,
[data-gallery-size="2"] > .sbaleno-editorial-gallery__grid .sbaleno-editorial-gallery__item,
[data-gallery-size="3"] > .sbaleno-editorial-gallery__grid .sbaleno-editorial-gallery__item {
  grid-column: auto;
  grid-row: auto;
  aspect-ratio: 4 / 3;
}

.sbaleno-editorial-gallery__link {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  color: #fff;
  text-decoration: none;
}

.sbaleno-editorial-gallery__image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 280ms ease, filter 280ms ease;
}

.sbaleno-editorial-gallery__link:is(:hover, :focus-visible) .sbaleno-editorial-gallery__image {
  filter: saturate(1.04);
  transform: scale(1.018);
}

.sbaleno-editorial-gallery__link:focus-visible {
  outline: 3px solid var(--wp--preset--color--warm-accent);
  outline-offset: -3px;
}

.sbaleno-editorial-gallery__more {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgb(19 39 41 / 0.56);
  color: #fff;
  font-family: var(--wp--preset--font-family--body);
  font-size: clamp(1.15rem, 2.3vw, 1.7rem);
  font-weight: 760;
  letter-spacing: 0.02em;
  pointer-events: none;
}

[data-sbaleno-gallery-enhanced="1"] .sbaleno-editorial-gallery__item:nth-child(n + 7) {
  display: none;
}

.sbaleno-editorial-gallery > .sbaleno-gallery-credit {
  width: max-content;
  max-width: 100%;
  margin: 0;
}

/* Native WordPress Gallery blocks join the same visual and viewer contract. */
.sbaleno-article-content__segment .wp-block-gallery[data-sbaleno-media-gallery] {
  position: relative;
  left: 50%;
  display: grid;
  width: min(1180px, calc(100vw - 2rem));
  max-width: none;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  grid-template-rows: repeat(3, clamp(7rem, 13vw, 12rem));
  gap: clamp(0.45rem, 1vw, 0.8rem);
  margin-block: clamp(2rem, 5vw, 3.5rem);
  transform: translateX(-50%);
}

.sbaleno-article-content__segment .wp-block-gallery[data-sbaleno-media-gallery][data-gallery-size="1"] {
  display: block;
}

.sbaleno-article-content__segment .wp-block-gallery[data-sbaleno-media-gallery][data-gallery-size="2"],
.sbaleno-article-content__segment .wp-block-gallery[data-sbaleno-media-gallery][data-gallery-size="3"] {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 18rem), 1fr));
  grid-template-rows: none;
}

.sbaleno-article-content__segment .wp-block-gallery[data-sbaleno-media-gallery][data-gallery-size="4"] {
  grid-template-rows: repeat(2, clamp(8rem, 17vw, 15rem));
}

.sbaleno-article-content__segment .wp-block-gallery[data-sbaleno-media-gallery] > .sbaleno-editorial-gallery__item {
  width: 100%;
}

.sbaleno-gallery-viewer {
  width: min(96vw, 1320px);
  max-width: none;
  height: min(94dvh, 940px);
  max-height: none;
  overflow: hidden;
  border: 0;
  border-radius: var(--wp--custom--radius--lg);
  background: #14272a;
  color: #fff;
  padding: 0;
}

.sbaleno-gallery-viewer::backdrop {
  background: rgb(9 18 20 / 0.84);
  backdrop-filter: blur(4px);
}

.sbaleno-gallery-viewer__shell {
  display: grid;
  height: 100%;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.sbaleno-gallery-viewer__bar {
  z-index: 2;
  display: flex;
  min-height: 4rem;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.65rem clamp(0.75rem, 2vw, 1.25rem);
  background: rgb(9 24 26 / 0.9);
}

.sbaleno-gallery-viewer__count {
  margin: 0;
  color: rgb(255 255 255 / 0.82);
  font-size: var(--wp--preset--font-size--small);
  font-variant-numeric: tabular-nums;
}

.sbaleno-gallery-viewer__close,
.sbaleno-gallery-viewer__nav,
.sbaleno-gallery-viewer__thumb {
  display: inline-grid;
  min-width: 44px;
  min-height: 44px;
  place-items: center;
  border: 1px solid rgb(255 255 255 / 0.3);
  border-radius: 999px;
  background: rgb(9 24 26 / 0.78);
  color: #fff;
  cursor: pointer;
}

.sbaleno-gallery-viewer__close {
  font-size: 1.45rem;
  line-height: 1;
}

.sbaleno-gallery-viewer__stage {
  position: relative;
  display: grid;
  min-height: 0;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: clamp(0.35rem, 1vw, 0.75rem);
  padding: clamp(0.5rem, 1.4vw, 1rem);
  touch-action: pan-y;
}

.sbaleno-gallery-viewer__nav {
  z-index: 1;
  font-size: 1.8rem;
  line-height: 1;
}

.sbaleno-gallery-viewer__figure {
  display: grid;
  min-width: 0;
  max-height: 100%;
  align-content: center;
  justify-items: center;
  gap: 0.65rem;
  margin: 0;
}

.sbaleno-gallery-viewer__image {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: calc(min(94dvh, 940px) - 12rem);
  object-fit: contain;
}

.sbaleno-gallery-viewer__caption {
  max-width: 72ch;
  min-height: 1.35rem;
  margin: 0;
  color: rgb(255 255 255 / 0.84);
  font-size: var(--wp--preset--font-size--small);
  line-height: 1.45;
  text-align: center;
}

.sbaleno-gallery-viewer__caption:empty {
  display: none;
}

.sbaleno-gallery-viewer__thumbs {
  display: flex;
  min-height: 4.9rem;
  gap: 0.45rem;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  padding: 0.55rem clamp(0.75rem, 2vw, 1.25rem) 0.75rem;
  background: rgb(9 24 26 / 0.9);
  scrollbar-width: thin;
}

.sbaleno-gallery-viewer__thumb {
  flex: 0 0 4.2rem;
  min-width: 4.2rem;
  height: 3.6rem;
  min-height: 3.6rem;
  overflow: hidden;
  border-radius: 0.35rem;
  padding: 0;
  opacity: 0.62;
}

.sbaleno-gallery-viewer__thumb[aria-current="true"] {
  border-color: #fff;
  opacity: 1;
}

.sbaleno-gallery-viewer__thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.sbaleno-gallery-viewer :is(button, [href]):focus-visible {
  outline: 3px solid var(--wp--preset--color--warm-accent);
  outline-offset: 2px;
}

body.sbaleno-gallery-viewer-open {
  overflow: hidden;
}

@media (max-width: 780px) {
  .sbaleno-editorial-gallery__header {
    align-items: start;
  }

  .sbaleno-editorial-gallery__grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: none;
  }

  .sbaleno-article-content__segment .wp-block-gallery[data-sbaleno-media-gallery] {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: none;
  }

  .sbaleno-editorial-gallery__item,
  .sbaleno-editorial-gallery__item:nth-child(n) {
    grid-column: auto;
    grid-row: auto;
    aspect-ratio: 4 / 3;
  }

  .sbaleno-editorial-gallery__item:first-child {
    grid-column: 1 / -1;
    aspect-ratio: 16 / 10;
  }

  .sbaleno-gallery-viewer {
    width: 100vw;
    height: 100dvh;
    border-radius: 0;
  }

  .sbaleno-gallery-viewer__stage {
    grid-template-columns: minmax(0, 1fr);
    padding-inline: 0.5rem;
  }

  .sbaleno-gallery-viewer__nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
  }

  .sbaleno-gallery-viewer__nav--prev {
    left: 0.65rem;
  }

  .sbaleno-gallery-viewer__nav--next {
    right: 0.65rem;
  }

  .sbaleno-gallery-viewer__figure {
    padding-inline: 0.2rem;
  }

  .sbaleno-gallery-viewer__image {
    max-height: calc(100dvh - 12.5rem);
  }
}

@media (max-width: 480px) {
  .sbaleno-editorial-gallery__header h2 {
    font-size: clamp(1.8rem, 9vw, 2.35rem);
  }

  .sbaleno-editorial-gallery__count {
    width: 2.5rem;
    min-width: 2.5rem;
    height: 2.5rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sbaleno-editorial-gallery__image {
    transition: none;
  }
}
