@charset "utf-8";

/* =========================================================
   photo-gallery : 記事本文内の横並び写真＋クリックで全画面表示
   記事本文（DB内の生HTML）に以下の形で書く：
   <div class="photo-gallery">
     <figure><img src="20260804/02.webp" alt="" width="1000" height="667"><figcaption>キャプション</figcaption></figure>
     ...（2〜4枚）
   </div>
   ========================================================= */

.photo-gallery {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  width: calc(100% + 25%);
  margin: 6% -12.5% 4%;
}

.photo-gallery figure {
  margin: 0;
  min-width: 0;
}

.photo-gallery img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 3 / 2;
  object-fit: cover;
}

.photo-gallery figcaption {
  font-size: 1.4rem;
  color: #333;
  line-height: 1.6;
  margin-top: .4em;
}

/* JSで生成される拡大用ボタン（対応環境のみ） */
.photo-gallery__btn {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: none;
  overflow: hidden;
  cursor: zoom-in;
  -webkit-appearance: none;
  appearance: none;
}

.photo-gallery__btn img {
  transition: transform .4s ease, filter .4s ease;
}

.photo-gallery__btn:hover img,
.photo-gallery__btn:focus-visible img {
  transform: scale(1.06);
  filter: brightness(1.05);
}

.photo-gallery__btn:focus-visible {
  outline: 2px solid #ff7e00;
  outline-offset: 2px;
}

/* --- 拡大表示ダイアログ --- */

.photo-dialog {
  width: 100%;
  max-width: 100%;
  height: 100%;
  max-height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  overflow: hidden;
}

.photo-dialog__inner {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 12px;
  padding: 5vh 4vw;
  box-sizing: border-box;
}

.photo-dialog__next {
  display: block;
  line-height: 0;
  max-width: 92vw;
  max-height: 80vh;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

.photo-dialog__next:disabled {
  cursor: default;
}

.photo-dialog__next:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 4px;
}

.photo-dialog__img {
  max-width: 92vw;
  max-height: 80vh;
  width: auto;
  height: auto;
  object-fit: contain;
}

.photo-dialog__caption {
  max-width: 92vw;
  font-size: 1.4rem;
  line-height: 1.6;
  color: #fff;
  text-align: center;
}

.photo-dialog__caption:empty {
  display: none;
}

.photo-dialog__count {
  font-size: 1.3rem;
  letter-spacing: .08em;
  color: rgba(255, 255, 255, .7);
}

.photo-dialog__count:empty {
  display: none;
}

.photo-dialog__close {
  position: fixed;
  top: 16px;
  right: 16px;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, .15);
  color: #fff;
  font-size: 2.0rem;
  line-height: 1;
  cursor: pointer;
  transition: background .2s ease;
}

.photo-dialog__close:hover {
  background: rgba(255, 255, 255, .35);
}

/* 表示／非表示のアニメーション（View Transition非対応環境のフォールバックも兼ねる） */
.photo-dialog {
  opacity: 0;
  transform: scale(.94);
  transition-property: opacity, transform, display, overlay;
  transition-duration: .3s;
  transition-timing-function: ease-out;
  transition-behavior: allow-discrete;
}

.photo-dialog[open] {
  opacity: 1;
  transform: scale(1);

  @starting-style {
    opacity: 0;
    transform: scale(.94);
  }
}

.photo-dialog::backdrop {
  background-color: rgba(0, 0, 0, 0);
  transition:
    display .3s allow-discrete,
    overlay .3s allow-discrete,
    background-color .3s ease-out;
}

.photo-dialog[open]::backdrop {
  background-color: rgba(0, 0, 0, .88);

  @starting-style {
    background-color: rgba(0, 0, 0, 0);
  }
}

/* View Transitionでサムネイル→全画面へモーフィングさせる */
.photo-gallery__btn.is-zooming img,
.photo-dialog.is-zooming .photo-dialog__img {
  view-transition-name: photo-zoom;
}

::view-transition-old(photo-zoom),
::view-transition-new(photo-zoom) {
  width: 100%;
  height: 100%;
  object-fit: cover;
  animation-duration: .38s;
}

/* View Transition中はダイアログ自体のtransitionは不要 */
.photo-dialog.is-zooming {
  transition: none;
}

@media (prefers-reduced-motion: reduce) {

  .photo-dialog,
  .photo-dialog[open] {
    transform: none;
    transition-duration: .1s;
  }

  .photo-gallery__btn:hover img,
  .photo-gallery__btn:focus-visible img {
    transform: none;
  }
}

/* --- SP：スワイプできることを示すインジケーター --- */

.photo-gallery-nav {
  display: none;
}

@media screen and (max-width: 768px) {

  .photo-gallery-nav {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    margin: -3% 0 6%;
  }

  .photo-gallery-nav__dots {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
  }

  .photo-gallery-nav__dot {
    width: 8px;
    height: 8px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: #c8c8c8;
    transition: background .3s ease, transform .3s ease;
    -webkit-appearance: none;
    appearance: none;
  }

  .photo-gallery-nav__dot.is-current {
    background: #222;
    transform: scale(1.3);
  }

  .photo-gallery-nav__hint {
    font-size: 1.2rem;
    letter-spacing: .06em;
    color: #666;
    transition: opacity .4s ease;
  }

  .photo-gallery-nav__hint::after {
    content: '→';
    display: inline-block;
    margin-left: .4em;
    animation: photo-gallery-nudge 1.6s ease-in-out infinite;
  }

  .photo-gallery-nav.is-scrolled .photo-gallery-nav__hint {
    opacity: 0;
  }
}

@keyframes photo-gallery-nudge {

  0%,
  100% {
    transform: translateX(0);
  }

  50% {
    transform: translateX(5px);
  }
}

@media (prefers-reduced-motion: reduce) {

  .photo-gallery-nav__hint::after {
    animation: none;
  }
}

/* --- SP：拡大表示はせず、画面幅いっぱいのスワイプ式カルーセルにする --- */

@media screen and (max-width: 768px) {

  .photo-gallery {
    display: flex;
    gap: 0;
    width: 100vw;
    margin: 8% 0 6%;
    margin-inline: calc(50% - 50vw);
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .photo-gallery::-webkit-scrollbar {
    display: none;
  }

  .photo-gallery figure {
    flex: 0 0 100%;
    scroll-snap-align: center;
  }

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

  .photo-gallery figcaption {
    padding: 0 6%;
  }
}
