.system-country[data-gallery-country] {
  position: relative;
  cursor: pointer;
  outline: 0;
  transition: box-shadow .2s ease, transform .2s ease;
}

.system-country[data-gallery-country]:hover,
.system-country[data-gallery-country]:focus-visible {
  z-index: 1;
  box-shadow: inset 0 0 0 2px var(--rb-blue);
  transform: translateY(-2px);
}

body.system-gallery-open {
  overflow: hidden;
}

.system-gallery-modal {
  position: fixed;
  z-index: 1000;
  inset: 0;
  display: grid;
  padding: clamp(.75rem, 3vw, 2.5rem);
  place-items: center;
  pointer-events: none;
}

.system-gallery-modal[hidden] {
  display: none;
}

.system-gallery-modal__backdrop {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: rgb(7 23 32 / 78%);
  opacity: 0;
  cursor: default;
  pointer-events: auto;
  backdrop-filter: blur(.28rem);
  transition: opacity .28s ease;
}

.system-gallery-modal__panel {
  position: relative;
  width: min(92vw, 82rem);
  max-height: min(84dvh, 54rem);
  display: grid;
  grid-template-columns: clamp(16rem, 24vw, 20rem) minmax(0, 1fr);
  overflow: hidden;
  border: 1px solid var(--rb-line);
  background: var(--rb-paper);
  box-shadow: 0 2rem 6rem rgb(0 15 24 / 42%);
  opacity: 0;
  pointer-events: auto;
  transform: scale(.84) translateY(1.5rem);
  transform-origin: center;
  transition: opacity .24s ease, transform .28s cubic-bezier(.2, .8, .2, 1);
}

.system-gallery-modal.is-open .system-gallery-modal__backdrop,
.system-gallery-modal.is-open .system-gallery-modal__panel {
  opacity: 1;
}

.system-gallery-modal.is-open .system-gallery-modal__panel {
  transform: scale(1) translateY(0);
}

.system-gallery-modal__panel.has-expanded-image {
  height: min(84dvh, 54rem);
}

.system-gallery-modal__close {
  position: absolute;
  z-index: 3;
  top: .75rem;
  right: .75rem;
  width: 1.75rem;
  height: 1.75rem;
  border: 0;
  background: var(--rb-deep);
  cursor: pointer;
  transition: background .2s ease, transform .2s ease;
}

.system-gallery-modal__close:hover,
.system-gallery-modal__close:focus-visible {
  background: var(--rb-blue);
  transform: rotate(4deg);
}

.system-gallery-modal__close span::before,
.system-gallery-modal__close span::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 1rem;
  height: 2px;
  background: #fff;
}

.system-gallery-modal__close span::before {
  transform: translate(-50%, -50%) rotate(45deg);
}

.system-gallery-modal__close span::after {
  transform: translate(-50%, -50%) rotate(-45deg);
}

.system-gallery-modal__summary {
  min-width: 0;
  min-height: 0;
  max-height: min(84dvh, 54rem);
  overflow-y: auto;
  border-right: 1px solid var(--rb-line);
  background: #fff;
}

.system-gallery-modal__summary header {
  min-height: 8.5rem;
  padding: 2rem;
  display: flex;
  align-items: center;
  gap: 1.1rem;
  border-bottom: 1px solid var(--rb-line);
}

.system-gallery-modal__summary header img {
  width: 4.6rem;
  height: 3.05rem;
  object-fit: cover;
  border: 1px solid var(--rb-line);
}

.system-gallery-modal__summary header span {
  color: var(--rb-blue);
  font: 700 .65rem/1 'DM Sans', sans-serif;
  letter-spacing: .12em;
}

.system-gallery-modal__summary h3 {
  margin: .4rem 0 0;
  font: 600 1.3rem/1.1 'Manrope', sans-serif;
}

.system-gallery-modal__summary ul {
  margin: 0;
  padding: 2rem;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: .6rem;
  list-style: none;
}

.system-gallery-modal__summary li {
  padding: .6rem .75rem;
  border: 1px solid var(--rb-line);
  color: var(--rb-steel);
  font: 600 .7rem/1 'DM Sans', sans-serif;
  letter-spacing: .04em;
  outline: 0;
  transition: border-color .18s ease, background .18s ease, color .18s ease;
}

.system-gallery-modal__summary li.is-highlighted,
.system-gallery-modal__summary li:focus-visible {
  border-color: var(--rb-blue);
  background: var(--rb-sky);
  color: var(--rb-ink);
}

.system-gallery-modal__media {
  position: relative;
  min-width: 0;
  min-height: 0;
  max-height: min(84dvh, 54rem);
  padding: clamp(2rem, 4vw, 4rem);
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-auto-rows: max-content;
  gap: 1rem;
  align-content: start;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.system-gallery-modal__media figure {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  border: 2px solid transparent;
  background: #fff;
  box-shadow: 0 .5rem 1.5rem rgb(18 52 69 / 8%);
  cursor: zoom-in;
  outline: 0;
  transition: border-color .18s ease, box-shadow .18s ease, transform .18s ease;
}

.system-gallery-modal__media figure.is-highlighted,
.system-gallery-modal__media figure:focus-visible {
  z-index: 1;
  border-color: var(--rb-blue);
  box-shadow: 0 .9rem 2rem rgb(25 120 182 / 22%);
  transform: translateY(-.2rem);
}

.system-gallery-modal__media.has-expanded-item {
  overflow: hidden;
}

.system-gallery-modal__media.has-expanded-item figure:not(.is-expanded) {
  visibility: hidden;
}

.system-gallery-modal__media figure.is-expanded {
  --gallery-expanded-inset: clamp(1rem, 3vw, 2.5rem);

  position: absolute;
  z-index: 2;
  top: calc(var(--gallery-expanded-inset) + var(--gallery-scroll-offset, 0px));
  right: var(--gallery-expanded-inset);
  bottom: calc(var(--gallery-expanded-inset) - var(--gallery-scroll-offset, 0px));
  left: var(--gallery-expanded-inset);
  width: auto;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  border-color: var(--rb-blue);
  box-shadow: 0 1.25rem 3rem rgb(18 52 69 / 20%);
  cursor: zoom-out;
  transform: none;
}

.system-gallery-modal__media figure.is-expanded img {
  width: 100%;
  height: 100%;
  min-height: 0;
  aspect-ratio: auto;
  object-fit: contain;
  background: var(--rb-paper);
}

.system-gallery-modal__media figure.is-expanded figcaption {
  background: #fff;
}

@media (min-width: 721px) {
  .system-gallery-modal__media figure.is-expanded {
    right: calc(var(--gallery-expanded-inset) + .75rem);
  }
}

.system-gallery-modal__media img {
  width: 100%;
  aspect-ratio: 4 / 3;
  display: block;
  object-fit: cover;
  border-radius: 0;
}

.system-gallery-modal__media figcaption {
  padding: 1rem;
  color: var(--rb-ink);
  font: 700 .68rem/1.3 'DM Sans', sans-serif;
  letter-spacing: .08em;
  text-transform: uppercase;
}

@media (max-width: 1050px) {
  .system-gallery-modal__media {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .system-gallery-modal {
    padding: .5rem;
  }

  .system-gallery-modal__panel {
    width: 100%;
    max-height: min(92dvh, 52rem);
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
    transform: scale(.9) translateY(1rem);
  }

  .system-gallery-modal__panel.has-expanded-image {
    height: min(92dvh, 52rem);
  }

  .system-gallery-modal__summary {
    max-height: none;
    overflow: visible;
    border-right: 0;
    border-bottom: 1px solid var(--rb-line);
  }

  .system-gallery-modal__summary header {
    min-height: 6.5rem;
    padding: 1.25rem 4.75rem 1.25rem 1.25rem;
    border-bottom: 0;
  }

  .system-gallery-modal__summary header img {
    width: 3.7rem;
    height: 2.45rem;
  }

  .system-gallery-modal__summary ul {
    display: none;
  }

  .system-gallery-modal__media {
    max-height: calc(min(92dvh, 52rem) - 6.5rem);
    padding: 1.25rem;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-auto-rows: max-content;
    gap: .85rem;
    overflow-x: hidden;
    overflow-y: auto;
    scroll-snap-type: y proximity;
    scroll-padding-block: 1.25rem;
  }

  .system-gallery-modal__media figure {
    width: 100%;
    scroll-snap-align: start;
  }

  .system-gallery-modal__media img {
    aspect-ratio: 4 / 3;
  }
}

@media (prefers-reduced-motion: reduce) {
  .system-country[data-gallery-country],
  .system-gallery-modal__backdrop,
  .system-gallery-modal__panel,
  .system-gallery-modal__close,
  .system-gallery-modal__summary li,
  .system-gallery-modal__media figure {
    transition-duration: .01ms !important;
  }
}
