/**
 * 画像ポップアップ (Lightbox) - フェードインアニメーション
 * HTMLモーダルと画像モーダルを分離（ネスト対応）
 */

/* HTMLモーダル */
#popup-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
}

#popup-modal.is-loading,
#popup-modal.is-active,
#popup-modal.is-closing {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* 画像モーダル（HTMLモーダルより上に表示） */
#popup-modal-image {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 10000;
}

#popup-modal-image.is-loading,
#popup-modal-image.is-active,
#popup-modal-image.is-closing {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* オーバーレイ（背景） */
.popup-overlay {
  position: absolute;
  inset: 0;
  background: rgba(90, 70, 55, 0.7);
  opacity: 0;
  transition: opacity 0.3s ease;
}

#popup-modal.is-active .popup-overlay,
#popup-modal-image.is-active .popup-overlay {
  opacity: 1;
}

#popup-modal.is-closing .popup-overlay,
#popup-modal-image.is-closing .popup-overlay {
  opacity: 0;
}

/* コンテンツ - フェードイン */
.popup-content {
  position: relative;
  opacity: 0;
  transform: scale(0.95);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

#popup-modal.is-loading .popup-content,
#popup-modal-image.is-loading .popup-content {
  opacity: 0;
  transform: scale(0.95);
}

#popup-modal.is-active .popup-content,
#popup-modal-image.is-active .popup-content {
  opacity: 1;
  transform: scale(1);
}

#popup-modal.is-closing .popup-content,
#popup-modal-image.is-closing .popup-content {
  opacity: 0;
  transform: scale(0.95);
}

/* 画像 */
.popup-image {
  display: block;
  max-width: 95vw;
  max-height: 90vh;
  object-fit: contain;
  cursor: pointer;
  border-radius: 4px;
  /* パイプ型立体枠線 */
  border: 6px solid #ece9e3;
  box-shadow:
    /* 内側の影（パイプの凹み） */
    inset 2px 2px 4px rgba(99, 99, 99, 0.4),
    inset -2px -2px 4px rgba(255, 255, 255, 0.6),
    /* 外側の影（パイプの立体感） */
    3px 3px 6px rgba(99, 99, 99, 0.5),
    -2px -2px 4px rgba(255, 255, 255, 0.3),
    /* 浮遊感 */
    0 8px 32px rgba(0, 0, 0, 0.5);
}

/* HTMLコンテンツ表示用 */
.popup-html {
  display: none;
  width: 95vw;
  height: 90vh;
  padding: 20px 30px;
  background: #fff;
  border-radius: 4px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  overflow-y: auto;
  box-sizing: border-box;
}

#popup-modal.is-html {
  align-items: flex-end;
  padding-bottom: 2vh;
}

#popup-modal.is-html .popup-content {
  width: 95vw;
  height: 90vh;
}

#popup-modal.is-html .popup-html {
  display: block;
  width: 100%;
  height: 100%;
}

.popup-loading,
.popup-error {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: #666;
  font-size: 16px;
}

.popup-error {
  color: #c00;
}

/* 閉じるボタン */
.popup-close {
  position: absolute;
  top: -44px;
  right: 0;
  width: 40px;
  height: 40px;
  padding: 0;
  border: none;
  background: rgba(255, 255, 255, 0.95);
  color: #333;
  font-size: 30px;
  line-height: 1;
  border-radius: 50%;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s ease 0.15s, background 0.15s ease;
}

#popup-modal.is-active .popup-close,
#popup-modal-image.is-active .popup-close {
  opacity: 1;
}

#popup-modal.is-closing .popup-close,
#popup-modal-image.is-closing .popup-close {
  opacity: 0;
  transition-delay: 0s;
}

.popup-close:hover {
  background: #fff;
}

.popup-close:focus {
  outline: 2px solid #e07145;
  outline-offset: 2px;
}

/* モバイル調整 */
@media (max-width: 768px) {
  .popup-close {
    top: -50px;
    width: 44px;
    height: 44px;
    font-size: 34px;
  }

  .popup-image {
    max-height: 85vh;
  }
}

/* サムネイル */
a.popup,
a[rel="colorbox"] {
  display: inline-block;
  cursor: pointer;
}

a.popup:hover img,
a[rel="colorbox"]:hover img {
  outline: 1px solid #e07145;
}
