/*
 * Instagram-style Gallery - front-end only
 * WordPress standard Gallery block, custom style: is-style-instagram
 */
.gallery-instagram {
  box-sizing: border-box;
  width: min(100%, 560px);
  margin: 32px auto;
}

.gallery-instagram__frame {
  position: relative;
  width: 100%;
}

/* The Gallery itself becomes the horizontal snap-scrolling area. */
.gallery-instagram .wp-block-gallery.is-style-instagram {
  display: flex !important;
  flex-flow: row nowrap !important;
  align-items: stretch;
  gap: 0 !important;
  width: 100%;
  max-width: none !important;
  padding: 0;
  margin: 0 !important;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.gallery-instagram .wp-block-gallery.is-style-instagram::-webkit-scrollbar {
  display: none;
}

.gallery-instagram .wp-block-gallery.is-style-instagram > figure.wp-block-image {
  position: relative;
  display: block;
  flex: 0 0 100% !important;
  width: 100% !important;
  max-width: 100% !important;
  aspect-ratio: 4 / 5;
  margin: 0 !important;
  overflow: hidden;
  scroll-snap-align: start;
  scroll-snap-stop: always;
}

/* Supports a normal img, a linked img and WordPress' lightbox markup. */
.gallery-instagram .wp-block-gallery.is-style-instagram > figure.wp-block-image > a,
.gallery-instagram .wp-block-gallery.is-style-instagram > figure.wp-block-image > .wp-lightbox-container {
  display: block;
  width: 100%;
  height: 100%;
}

.gallery-instagram .wp-block-gallery.is-style-instagram > figure.wp-block-image img {
  display: block;
  width: 100% !important;
  height: 100% !important;
  max-width: none;
  object-fit: cover;
  border-radius: 0;
}

.gallery-instagram__arrow {
  position: absolute;
  z-index: 3;
  top: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  transform: translateY(-50%);
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, .95);
  box-shadow: 0 1px 8px rgba(0, 0, 0, .18);
  color: #333;
  font-family: Arial, sans-serif;
  font-size: 30px;
  font-weight: 400;
  line-height: 1;
  cursor: pointer;
}

.gallery-instagram__arrow--prev { left: 12px; }
.gallery-instagram__arrow--next { right: 12px; }

.gallery-instagram__arrow:disabled {
  opacity: 0;
  pointer-events: none;
}

.gallery-instagram__arrow:focus-visible,
.gallery-instagram__dot:focus-visible,
.gallery-instagram .wp-block-gallery.is-style-instagram:focus-visible {
  outline: 2px solid #0095f6;
  outline-offset: 3px;
}

.gallery-instagram__counter {
  position: absolute;
  z-index: 2;
  top: 12px;
  right: 12px;
  padding: 5px 10px;
  border-radius: 100px;
  background: rgba(0, 0, 0, .56);
  color: #fff;
  font-family: Arial, sans-serif;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  line-height: 1.4;
  pointer-events: none;
}

.gallery-instagram__dots {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 9px;
  margin: 12px 0 0;
}

.gallery-instagram__dot {
  flex: 0 0 auto;
  width: 6px;
  height: 6px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: #c7c7c7;
  cursor: pointer;
}

.gallery-instagram__dot.is-active {
  background: #0095f6;
}

/* Caption for the entire gallery remains visible below the pagination. */
.gallery-instagram > .blocks-gallery-caption,
.gallery-instagram > .wp-element-caption {
  width: 100%;
  margin: 8px 0 0;
  font-size: 12px;
  text-align: center;
}

@media (max-width: 767px) {
  .gallery-instagram {
    width: 100%;
  }

  /* Touch users swipe naturally; arrows stay available on larger screens. */
  .gallery-instagram__arrow {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .gallery-instagram .wp-block-gallery.is-style-instagram {
    scroll-behavior: auto;
  }
}

/* Pixel-precise SVG chevrons, independent of font metrics. */
.gallery-instagram__arrow svg {
  display: block;
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}


/* =========================================
   Instagram Gallery
   JavaScript実行前のレイアウトを固定
========================================= */

/* 初期表示からInstagram風にする */
.wp-block-gallery.is-style-instagram {
  display: flex !important;
  flex-flow: row nowrap !important;
  align-items: stretch;
  gap: 0 !important;
  width: min(100%, 560px);
  max-width: 100% !important;
  margin: 32px auto !important;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
}

.wp-block-gallery.is-style-instagram::-webkit-scrollbar {
  display: none;
}

/* 画像を1枚ずつ表示 */
.wp-block-gallery.is-style-instagram
> figure.wp-block-image {
  position: relative;
  display: block;
  flex: 0 0 100% !important;
  width: 100% !important;
  max-width: 100% !important;
  aspect-ratio: 4 / 5;
  margin: 0 !important;
  overflow: hidden;
  scroll-snap-align: start;
}

/* リンク・Lightbox対応 */
.wp-block-gallery.is-style-instagram
> figure.wp-block-image > a,
.wp-block-gallery.is-style-instagram
> figure.wp-block-image > .wp-lightbox-container {
  display: block;
  width: 100%;
  height: 100%;
}

/* 画像表示 */
.wp-block-gallery.is-style-instagram
> figure.wp-block-image img {
  display: block;
  width: 100% !important;
  height: 100% !important;
  max-width: none;
  object-fit: cover;
  border-radius: 0;
}