/* Swiper core fallback for stable layout */
.swiper {
  position: relative;
  overflow: hidden;
  min-height: 0;
  min-width: 0;
}

.swiper-wrapper {
  display: flex;
  flex-wrap: nowrap;
  width: 100%;
  height: 100%;
  box-sizing: content-box;
  transition-property: transform !important;
  will-change: transform;
}

.swiper-slide {
  flex-shrink: 0;
  min-width: 0;
  min-height: 0;
}

/* 전체 갤러리 래퍼 */
.gallery-wrapper {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100dvh;
  background-color: #fff;
  display: flex;
  overflow: hidden;
}

/* --- 1. 메인 슬라이더 스타일 --- */
.is-gallery-main {
  width: 100%;
  height: 100%;
  order: 1;
}

.is-gallery-main .swiper-slide {
  width: 100%;
  flex: 0 0 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.is-gallery-main .swiper-slide img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* --- 2. 썸네일 슬라이더 공통 스타일 --- */
.is-gallery-thumbs {
  -webkit-user-select: none;
  user-select: none;
  min-height: 0;
  min-width: 0;
}

.is-gallery-thumbs .swiper-slide {
  cursor: pointer;
  opacity: 1;
  filter: grayscale(100%);
  transition: opacity 0.3s ease, filter 0.3s ease;
}

.is-gallery-thumbs .swiper-slide-thumb-active {
  opacity: 1;
  filter: grayscale(0%);
}

/* --- 3. 하단 정보 영역 스타일 --- */
.gallery-info {
  width: 100%;
  text-align: center;
  padding: 1rem;
  order: 3;
  background-color: #fff;
}

/* --- 4. 데스크탑 (1024px 이상) - CSS 변수 사용 --- */
@media screen and (min-width: 1024px) {
  :root {
    --thumb-width: 280px;
    --thumb-gap: 15px;
    --gallery-padding: 40px;
    --info-bottom: 30px;
    --info-left-offset: 5px;
  }

  .gallery-wrapper {
    flex-direction: row;
    gap: var(--thumb-gap);
    padding: var(--gallery-padding);
  }

  .is-gallery-main {
    width: calc(100% - var(--thumb-width) - var(--thumb-gap));
    order: 2;
    flex: 1;
  }

  .is-gallery-thumbs {
    width: var(--thumb-width);
    height: 100%;
    order: 1;
    flex-shrink: 0;
    overflow-y: auto;
  }

  .is-gallery-thumbs .swiper-wrapper {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: repeat(8, 1fr);
    gap: 10px;
    height: 100% !important;
  }

  .is-gallery-thumbs .swiper-slide {
    width: 100% !important;
    height: 100% !important;
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: transparent;
  }

  .is-gallery-thumbs .swiper-slide img {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
  }

  .gallery-info {
    position: absolute;
    bottom: var(--info-bottom);
    left: calc(var(--thumb-width) + var(--thumb-gap) + var(--info-left-offset));
    width: calc(100% - var(--thumb-width) - var(--thumb-gap) - var(--info-left-offset) - var(--info-bottom));
    z-index: 10;
    color: #000;
  }
}

/* --- 5. 태블릿 & 모바일 (1023px 이하) - 안정화된 버전 --- */
@media screen and (max-width: 1023px) {
  :root {
    --mobile-hpad: 0.4rem;
    --mobile-hpad-2: calc(var(--mobile-hpad) * 2);
    --mobile-thumb-height: 80px;
    /* 썸네일 간격(조절 가능) - JS에서 읽어 spaceBetween으로 사용 */
    --mobile-thumb-gap: 8px;
    --mobile-thumb-padding: 1rem;
  }

  .gallery-wrapper {
    flex-direction: column;
    gap: 0;
    padding: 0;
    height: 100dvh;
  }

  .is-gallery-main {
    order: 1;
    margin-top: 2.6rem;
    margin-left: var(--mobile-hpad);
    margin-right: var(--mobile-hpad);
    width: calc(100% - var(--mobile-hpad-2));
    height: auto;
    flex: 1 1 auto;
    min-height: 0;
    position: relative;
    z-index: 1;
    overflow: hidden;
    /* 미세한 서브픽셀 이웃 노출 차단 */
  }

  /* 메인 래퍼/슬라이드 간격 0으로 고정 (옆 슬라이드 노출 방지) */
  .is-gallery-main .swiper-wrapper {
    gap: 0 !important;
    backface-visibility: hidden;
    transform: translateZ(0);
  }

  .is-gallery-main .swiper-slide {
    margin: 0 !important;
    backface-visibility: hidden;
    transform: translateZ(0);
  }

  /* 모바일 썸네일 - 안정화된 버전 */
  .swiper.is-gallery-thumbs {
    height: var(--mobile-thumb-height) !important;
    padding: 5px var(--mobile-hpad);
    order: 2;
    flex-shrink: 0;
    overflow: hidden !important;
    box-sizing: border-box;
    position: relative;
    z-index: 2;
    min-height: var(--mobile-thumb-height);
    min-width: 0;
    /* 배경 없음 (실서비스) */
    background-color: transparent;
  }

  .swiper.is-gallery-thumbs .swiper-wrapper {
    height: calc(var(--mobile-thumb-height) - 10px) !important;
    align-items: center !important;
    display: flex !important;
    flex-wrap: nowrap !important;
    justify-content: flex-start !important;
    gap: 0 !important;
    min-height: calc(var(--mobile-thumb-height) - 10px);
    min-width: 0;
  }

  .swiper.is-gallery-thumbs .swiper-slide {
    height: calc(var(--mobile-thumb-height) - 10px) !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    background-color: transparent;
    width: auto;
    flex: 0 0 auto;
    /* Swiper의 spaceBetween을 적용하기 위해 margin 강제 제거를 하지 않습니다. */
    box-sizing: border-box;
    min-width: 0;
    min-height: 0;
    /* 테두리 없음 (실서비스) */
    border: 0;
  }

  .swiper.is-gallery-thumbs .swiper-slide img {
    max-width: 100% !important;
    max-height: 100% !important;
    width: auto !important;
    height: auto !important;
    object-fit: contain !important;
  }

  .gallery-info {
    height: 60px;
    order: 3;
    flex-shrink: 0;
    padding: 10px 1rem;
  }
}

/* 터치 제스처 충돌 감소 */
.is-gallery-main {
  touch-action: pan-x pinch-zoom;
}

.is-gallery-thumbs {
  touch-action: pan-x pinch-zoom;
}
