.popups-root {
  position: relative;
  z-index: 3000;
}
/* 팝업이 떠 있는 동안 배경 페이지 스크롤 잠금(이중 스크롤 방지) */
html.popup-open,
html.popup-open body {
  overflow: hidden;
}
.popup-item {
  position: fixed;
  z-index: 3000;
}
.pos-center {
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.5);
}

/* 좌표 배치용 */
.popup-item.xy {
}

/* 나열(가로/세로) - 상단 고정 버튼 바 + 스크롤 본문 (데스크톱 전용) */
@media (min-width: 1025px) {
  .popups-root.is-flow {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    overflow: hidden; /* 스크롤은 본문(.popups-flow-body)에서만 */
    z-index: 3000;
  }
  .popups-root.is-flow .popup-item {
    position: relative;
    inset: auto;
  }
  /* 버튼 바: 스크롤 영역 밖 최상단 → 팝업이 절대 가리지 않음 */
  .popups-root.is-flow .popups-controls-row {
    flex-shrink: 0;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: rgba(0, 0, 0, 0.45);
    z-index: 2;
  }
  /* 팝업 목록 본문: 여기서만 스크롤 */
  .popups-root.is-flow .popups-flow-body {
    flex: 1;
    min-height: 0;
    overflow: auto;
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
    align-items: flex-start;
    gap: var(--pop-gap, 30px);
    padding: var(--pop-y, 20px) 20px 20px var(--pop-x, 20px);
  }
  .popups-root.is-flow.dir-v .popups-flow-body {
    flex-direction: column;
  }
}

/* 나열 모드: 그룹 통합 컨트롤(오늘 하루 보지 않기 + 닫기) */
.popups-controls-row {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
}
.popups-hide-today {
  border: 0;
  cursor: pointer;
  border-radius: 9999px;
  padding: 11px 18px;
  font-size: 14px;
  font-weight: 600;
  color: #111;
  background: rgba(255, 255, 255, 0.95);
}
.popups-hide-today:hover {
  background: #fff;
}
.popups-closeall {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 0;
  cursor: pointer;
  border-radius: 9999px;
  padding: 11px 20px;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  background: var(--color-sub, #02b8b8);
  transition: background 0.15s ease, transform 0.1s ease;
}
.popups-closeall::after {
  content: "×";
  font-size: 18px;
  line-height: 1;
}
.popups-closeall:hover {
  background: color-mix(in srgb, var(--color-sub, #02b8b8) 88%, #000);
}
.popups-closeall:active {
  transform: translateY(1px);
}
/* 데스크톱 나열: 개별 팝업 컨트롤은 숨기고 그룹 통합 컨트롤만 사용 */
@media (min-width: 1025px) {
  .popups-root.is-flow .popup-controls {
    display: none;
  }
}
/* 모바일: 팝업 하나만 중앙 표시 → 그룹 컨트롤 숨기고 개별 컨트롤 사용 */
@media (max-width: 1024px) {
  .popups-controls-row {
    display: none;
  }
}

/* 팝업 박스 */
.popup-box {
  position: relative;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
  padding: 0;
  max-width: 500px;
  width: 100%;
  overflow: hidden;
}
.popup-box img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

/* 나열 모드: 박스 너비를 이미지 크기에 맞춤 */
.popup-item.xy .popup-box {
  width: fit-content;
  max-width: 500px;
}
.popup-item.xy .popup-box img {
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: 80vh;
  object-fit: contain;
}

/* 상단 컨트롤 영역 */
.popup-controls {
  position: absolute;
  top: 8px;
  right: 0;
  padding: 0 8px;
  width: 100%;
  display: flex;
  justify-content: space-between;
  gap: 6px;
  align-items: center;
  z-index: 2;
}
.popup-controls button {
  border: 0;
  cursor: pointer;
  border-radius: 9999px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  background: rgba(0, 0, 0, 0.75);
}
.popup-controls .popup-close {
  width: 32px;
  height: 32px;
  padding: 0;
  display: grid;
  place-items: center;
  font-size: 18px;
  line-height: 1;
  background: rgba(0, 0, 0, 0.78);
}
.popup-controls .popup-close:hover {
  background: rgba(0, 0, 0, 0.9);
}
.popup-controls .popup-hide-today:hover {
  background: rgba(0, 0, 0, 0.55);
}

/* 슬라이더 */
.popup-slider {
  position: relative;
  overflow: hidden;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  isolation: isolate;
  transform: translateZ(0);
}
.popup-slider {
  cursor: grab;
  touch-action: pan-y;
}
.popup-slider.grabbing {
  cursor: grabbing;
}
.popup-slider .slides {
  display: flex;
  will-change: transform;
}
.popup-slider .slide {
  flex: 0 0 auto;
  box-sizing: border-box;
  overflow: hidden;
}
.popup-slider .slide img {
  display: block;
  width: 100%;
  height: auto;
  -webkit-user-drag: none;
  user-select: none;
  pointer-events: auto;
}
.slide-prev,
.slide-next {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  border: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 20px;
  cursor: pointer;
  z-index: 2;
}
.slide-prev {
  left: 8px;
}
.slide-next {
  right: 8px;
}

.dots {
  display: flex;
  gap: 6px;
  justify-content: center;
  padding: 10px;
}
.dots button {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 0;
  background: #d1d5db;
  cursor: pointer;
}
.dots button.active {
  background: #0b6fb5;
}

/* 랩탑 이하(1024px): 나열 모드 중앙 정렬, 모달(딤드) 없음 */
@media (max-width: 1024px) {
  .popups-root {
    position: fixed;
    inset: 0;
    z-index: 3000;
    pointer-events: none;
  }

  .popups-root .popup-item.xy {
    pointer-events: auto;
  }

  .popup-item.xy {
    inset: 0 !important;
    left: 0 !important;
    right: 0 !important;
    top: 0 !important;
    bottom: 0 !important;
    display: grid !important;
    place-items: center !important;
    transform: none !important;
    max-width: none;
    background: transparent;
  }

  .popup-item.xy .popup-box {
    width: fit-content;
    max-width: min(500px, calc(100vw - 32px));
    max-height: 85vh;
    margin: 16px;
  }

  .popup-item.xy .popup-box img {
    width: auto;
    max-width: 100%;
    height: auto;
    max-height: 75vh;
    object-fit: contain;
  }

  /* 첫 팝업만 표시(앞선 팝업이 있는 팝업은 숨김) — 그룹 컨트롤 바가 첫 자식이어도 안전 */
  .popup-item.xy ~ .popup-item.xy {
    display: none;
  }
}

/* 가로(랜드스케이프) 화면: 흰색 배경/박스 안 보이게 */
@media (max-width: 1024px) and (orientation: landscape) {
  .popup-item.xy .popup-box {
    background: transparent;
    box-shadow: none;
    border-radius: 0;
  }
}

@media (max-width: 640px) {
  .popup-box {
    max-width: calc(100vw - 32px);
  }

  .popup-item.xy .popup-box {
    max-width: calc(100vw - 32px);
    max-height: 88vh;
  }

  .popup-item.xy .popup-box img {
    max-height: 78vh;
  }
}

@media (max-width: 640px) and (orientation: landscape) {
  .popup-item.xy .popup-box {
    background: transparent;
    box-shadow: none;
    border-radius: 0;
  }
}
