.media-modal {
  cursor: zoom-out;
}


.product-media-modal {
  background-color: rgba(23, 23, 23, 0.94);
  height: 100%;
  position: fixed;
  inset: 0;
  width: 100%;
  overflow: hidden;
  visibility: hidden;
  opacity: 0;
  z-index: -1;
  transition: opacity 200ms ease;
}

.product-media-modal[open] {
  visibility: visible;
  opacity: 1;
  z-index: 101;
}

.product-media-modal__dialog {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  height: 100vh;
  width: 100%;
  padding: 72px 24px 120px;
  box-sizing: border-box;
}

/* Close */
.product-media-modal__toggle {
  position: absolute;
  bottom: calc(100% + 8px);
  right: 0;
  z-index: 4;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background-color: rgba(0, 0, 0, 0.5);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  transition: background-color 150ms ease;
}

.product-media-modal__toggle:hover {
  background-color: rgba(0, 0, 0, 0.7);
}

.product-media-modal__toggle .icon {
  width: 16px;
  height: 16px;
  margin: 0;
}

/* Stage: single centered media */
.product-media-modal__content {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  max-width: 100%;
  max-height: 100%;
  cursor: zoom-out;
  /* 横滑交给 JS 处理,禁止浏览器横向平移(避免滑动后图片/页面偏移) */
  touch-action: pan-y;
}

.product-media-modal__content > [data-media-id] {
  display: none;
  max-width: min(900px, calc(100vw - 220px));
  max-height: calc(100vh - 200px);
  width: auto;
  height: auto;
  margin: 0;
  border-radius: 8px;
  object-fit: contain;
  touch-action: pan-y;
}

.product-media-modal__content > [data-media-id].active {
  display: block;
  animation: pmm-media-enter 280ms cubic-bezier(0.22, 0.61, 0.36, 1);
}

@keyframes pmm-media-enter {
  from {
    opacity: 0;
    transform: scale(0.98);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  .product-media-modal__content > [data-media-id].active {
    animation: none;
  }
}

.product-media-modal__content .media {
  background: none;
}

.product-media-modal__content .deferred-media {
  width: min(900px, 100%);
}

/* Prev / next */
.product-media-modal__nav {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  z-index: 2;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background-color: rgba(255, 255, 255, 0.14);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  transition: background-color 150ms ease;
}

.product-media-modal__nav:hover {
  background-color: rgba(255, 255, 255, 0.26);
}

.product-media-modal__nav svg {
  width: 22px;
  height: 22px;
}

.product-media-modal__prev {
  left: 24px;
}

.product-media-modal__next {
  right: 24px;
}

/* Thumbnails */
.product-media-modal__thumbs {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2;
  display: flex;
  gap: 10px;
  max-width: 90vw;
  overflow-x: auto;
  padding: 4px;
}

.product-media-modal__thumb {
  flex-shrink: 0;
  width: 56px;
  height: 56px;
  border-radius: 8px;
  border: 2px solid transparent;
  padding: 0;
  cursor: pointer;
  overflow: hidden;
  background: #fff;
  opacity: 0.5;
  transition: opacity 150ms ease, border-color 150ms ease;
}

.product-media-modal__thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.product-media-modal__thumb:hover {
  opacity: 0.85;
}

.product-media-modal__thumb--active {
  opacity: 1;
  border-color: #fff;
}

/* Single media: hide nav & thumbnails */
.product-media-modal--single .product-media-modal__nav,
.product-media-modal--single .product-media-modal__thumbs {
  display: none;
}

/* Desktop: arrows sit in-flow, hugging the image instead of pinned to viewport edges */
@media screen and (min-width: 960px) {
  .product-media-modal__nav {
    position: static;
    transform: none;
    flex: 0 0 auto;
  }

  .product-media-modal__prev,
  .product-media-modal__next {
    left: auto;
    right: auto;
  }

  .product-media-modal__content {
    flex: 0 1 auto;
    min-width: 0;
  }
}

@media screen and (max-width: 959px) {
  .product-media-modal__dialog {
    padding: 60px 14px 104px;
  }

  /* 移动端箭头是悬浮的,图片应占满宽度(不再为同排箭头减 220px) */
  .product-media-modal__content > [data-media-id] {
    max-width: 100%;
    max-height: calc(100vh - 180px);
  }

  .product-media-modal__toggle {
    bottom: calc(100% + 6px);
    right: 0;
    width: 34px;
    height: 34px;
  }

  .product-media-modal__nav {
    width: 40px;
    height: 40px;
    background-color: rgba(0, 0, 0, 0.5);
  }

  .product-media-modal__nav:hover {
    background-color: rgba(0, 0, 0, 0.7);
  }

  .product-media-modal__prev {
    left: 10px;
  }

  .product-media-modal__next {
    right: 10px;
  }

  .product-media-modal__thumb {
    width: 48px;
    height: 48px;
  }
}
