/* Keep these rules scoped, but more specific than the theme's .prose rules. */
:is(.bagat-gallery, .entry-content .bagat-gallery) {
  box-sizing: border-box;
  clear: both;
  width: 100%;
  max-width: 650px;
  min-width: 0;
  margin: 1.4rem 0 1.6rem;
  padding: 0;
  border: 0;
}

:is(.bagat-gallery, .entry-content .bagat-gallery) *,
:is(.bagat-gallery, .entry-content .bagat-gallery) *::before,
:is(.bagat-gallery, .entry-content .bagat-gallery) *::after {
  box-sizing: border-box;
}

:is(.bagat-gallery, .entry-content .bagat-gallery) .bagat-gallery-track {
  position: relative;
  display: flex;
  flex-flow: row nowrap;
  align-items: stretch;
  gap: 12px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  margin: 0;
  padding: 0 0 8px;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  scroll-padding-inline: 0;
  overscroll-behavior-inline: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: #888 transparent;
}

:is(.bagat-gallery, .entry-content .bagat-gallery) .bagat-gallery-item {
  position: relative;
  display: flex;
  flex: 0 0 calc((100% - 24px) / 3);
  align-items: center;
  justify-content: center;
  width: auto;
  max-width: none;
  min-width: 0;
  height: 140px;
  margin: 0;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 0;
  background: rgba(0, 0, 0, 0.025);
  color: inherit;
  box-shadow: none;
  text-decoration: none;
  scroll-snap-align: start;
}

:is(.bagat-gallery, .entry-content .bagat-gallery) .bagat-gallery-item::before,
:is(.bagat-gallery, .entry-content .bagat-gallery) .bagat-gallery-item::after {
  display: none;
  content: none;
}

:is(.bagat-gallery, .entry-content .bagat-gallery) .bagat-gallery-item img {
  display: block;
  flex: 0 1 auto;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  height: 100%;
  max-height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  object-fit: contain;
  object-position: center;
  vertical-align: middle;
}

:is(.bagat-gallery, .entry-content .bagat-gallery) .bagat-gallery-controls {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  margin: 6px 0 0;
  padding: 0;
}

:is(.bagat-gallery, .entry-content .bagat-gallery).bagat-gallery-ready .bagat-gallery-controls {
  display: flex;
}

:is(.bagat-gallery, .entry-content .bagat-gallery) .bagat-gallery-position {
  display: inline-block;
  min-width: 4em;
  margin: 0;
  padding: 0;
  color: #767676;
  font-size: 11px;
  font-weight: 400;
  line-height: 1.4;
  text-align: center;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

:is(.bagat-gallery, .entry-content .bagat-gallery) button {
  appearance: none;
  position: static;
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  float: none;
  width: 36px;
  min-width: 0;
  height: 36px;
  min-height: 0;
  margin: 0;
  padding: 0;
  border: 1px solid currentColor;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  box-shadow: none;
  font-family: inherit;
  font-size: 21px;
  font-style: normal;
  font-weight: 400;
  line-height: 1;
  letter-spacing: 0;
  text-align: center;
  text-decoration: none;
  text-transform: none;
  white-space: nowrap;
  transform: none;
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color 150ms ease, opacity 150ms ease;
}

:is(.bagat-gallery, .entry-content .bagat-gallery) button::before,
:is(.bagat-gallery, .entry-content .bagat-gallery) button::after {
  display: none;
  content: none;
}

:is(.bagat-gallery, .entry-content .bagat-gallery) .bagat-gallery-controls button {
  border: 0;
  border-radius: 0;
  background: transparent;
}

:is(.bagat-gallery, .entry-content .bagat-gallery) .bagat-gallery-controls button:hover:not(:disabled) {
  background: transparent;
  color: #767676;
}

:is(.bagat-gallery, .entry-content .bagat-gallery) button:disabled {
  opacity: 0.3;
  cursor: default;
}

:is(.bagat-gallery, .entry-content .bagat-gallery) button:focus-visible,
:is(.bagat-gallery, .entry-content .bagat-gallery) .bagat-gallery-track:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 3px;
}

:is(.bagat-gallery, .entry-content .bagat-gallery) .bagat-gallery-item:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: -3px;
}

/* Never turn a closed native dialog into a visible element. */
:is(.bagat-gallery, .entry-content .bagat-gallery) .bagat-gallery-dialog:not([open]) {
  display: none !important;
}

:is(.bagat-gallery, .entry-content .bagat-gallery) .bagat-gallery-dialog {
  position: fixed;
  inset: 0;
  z-index: 100000;
  width: 100%;
  max-width: none;
  min-width: 0;
  height: 100vh;
  height: 100dvh;
  max-height: none;
  min-height: 0;
  margin: 0;
  padding: calc(64px + env(safe-area-inset-top, 0px))
    calc(24px + env(safe-area-inset-right, 0px))
    calc(20px + env(safe-area-inset-bottom, 0px))
    calc(24px + env(safe-area-inset-left, 0px));
  overflow: auto;
  border: 0;
  border-radius: 0;
  background: rgba(9, 10, 12, 0.97);
  color: #fff;
  box-shadow: none;
  overscroll-behavior: contain;
}

:is(.bagat-gallery, .entry-content .bagat-gallery) .bagat-gallery-dialog[open] {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  grid-template-rows: minmax(0, 1fr);
  align-items: center;
  gap: 16px;
}

:is(.bagat-gallery, .entry-content .bagat-gallery) .bagat-gallery-dialog-single[open] {
  grid-template-columns: minmax(0, 1fr);
}

:is(.bagat-gallery, .entry-content .bagat-gallery) .bagat-gallery-dialog::backdrop {
  background: rgba(0, 0, 0, 0.88);
}

:is(.bagat-gallery, .entry-content .bagat-gallery) .bagat-gallery-figure {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) auto;
  align-self: stretch;
  align-items: center;
  justify-items: center;
  gap: 12px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  height: 100%;
  max-height: 100%;
  min-height: 0;
  margin: 0;
  padding: 0;
  overflow: hidden;
  border: 0;
  background: transparent;
  color: #fff;
}

:is(.bagat-gallery, .entry-content .bagat-gallery) .bagat-gallery-full {
  display: block;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  height: 100%;
  max-height: 100%;
  min-height: 0;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  object-fit: contain;
  object-position: center;
}

:is(.bagat-gallery, .entry-content .bagat-gallery) .bagat-gallery-caption {
  display: block;
  width: auto;
  max-width: 85ch;
  max-height: min(25vh, 8rem);
  min-width: 0;
  margin: 0;
  padding: 0;
  overflow-x: hidden;
  overflow-y: auto;
  background: transparent;
  color: #fff;
  font-family: inherit;
  font-size: 14px;
  font-style: normal;
  font-weight: 400;
  line-height: 1.45;
  letter-spacing: 0;
  text-align: center;
  text-transform: none;
  overflow-wrap: anywhere;
}

:is(.bagat-gallery, .entry-content .bagat-gallery) .bagat-gallery-caption:empty {
  display: none;
}

:is(.bagat-gallery, .entry-content .bagat-gallery) .bagat-gallery-dialog button {
  width: 44px;
  height: 44px;
  border-color: rgba(255, 255, 255, 0.65);
  background: rgba(0, 0, 0, 0.3);
  color: #fff;
  font-size: 25px;
}

:is(.bagat-gallery, .entry-content .bagat-gallery) .bagat-gallery-dialog button:hover {
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
}

:is(.bagat-gallery, .entry-content .bagat-gallery) .bagat-gallery-dialog .bagat-gallery-close {
  position: absolute;
  top: calc(10px + env(safe-area-inset-top, 0px));
  right: calc(16px + env(safe-area-inset-right, 0px));
  z-index: 2;
  font-size: 30px;
}

:is(.bagat-gallery, .entry-content .bagat-gallery) [hidden] {
  display: none !important;
}

@media (max-width: 600px) {
  :is(.bagat-gallery, .entry-content .bagat-gallery) .bagat-gallery-track {
    gap: 8px;
  }

  :is(.bagat-gallery, .entry-content .bagat-gallery) .bagat-gallery-item {
    flex-basis: calc((100% - 8px) / 2);
    height: 110px;
  }

  :is(.bagat-gallery, .entry-content .bagat-gallery) .bagat-gallery-dialog {
    padding: calc(64px + env(safe-area-inset-top, 0px))
      calc(8px + env(safe-area-inset-right, 0px))
      calc(16px + env(safe-area-inset-bottom, 0px))
      calc(8px + env(safe-area-inset-left, 0px));
  }

  :is(.bagat-gallery, .entry-content .bagat-gallery) .bagat-gallery-dialog[open] {
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
  }

  :is(.bagat-gallery, .entry-content .bagat-gallery) .bagat-gallery-figure {
    gap: 10px;
  }

  :is(.bagat-gallery, .entry-content .bagat-gallery) .bagat-gallery-caption {
    max-width: 100%;
    font-size: 13px;
  }

  :is(.bagat-gallery, .entry-content .bagat-gallery) .bagat-gallery-lightbox-prev,
  :is(.bagat-gallery, .entry-content .bagat-gallery) .bagat-gallery-lightbox-next {
    position: absolute;
    top: 50%;
    z-index: 1;
    transform: translateY(-50%);
  }

  :is(.bagat-gallery, .entry-content .bagat-gallery) .bagat-gallery-lightbox-prev {
    left: calc(8px + env(safe-area-inset-left, 0px));
  }

  :is(.bagat-gallery, .entry-content .bagat-gallery) .bagat-gallery-lightbox-next {
    right: calc(8px + env(safe-area-inset-right, 0px));
  }
}

@media (prefers-reduced-motion: reduce) {
  :is(.bagat-gallery, .entry-content .bagat-gallery) .bagat-gallery-track {
    scroll-behavior: auto;
  }

  :is(.bagat-gallery, .entry-content .bagat-gallery) button {
    transition: none;
  }
}

@media print {
  :is(.bagat-gallery, .entry-content .bagat-gallery) .bagat-gallery-track {
    overflow: hidden;
  }

  :is(.bagat-gallery, .entry-content .bagat-gallery) .bagat-gallery-controls,
  :is(.bagat-gallery, .entry-content .bagat-gallery) .bagat-gallery-dialog {
    display: none !important;
  }
}
