/* ==========================================================================
   Section 2 — 몬티홀 게임
   단일 수직 flex 컨테이너. 상자 내부 장식과 dim 오버레이만 absolute 사용.
   JS(monty.js)가 상태 클래스를 토글합니다.
   .monty--step-0 : 상자 선택 전 (2-1)
   .monty--spotlight : 최종 결과 (2-5), 뒤 요소 dim
   ========================================================================== */
.monty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 24px 40px;
  background: var(--grey-black);
  text-align: center;
}

.monty__title {
  max-width: 600px;
  font-size: clamp(22px, 3.6vw, 30px);
  font-weight: 800;
  line-height: 1.4;
  color: var(--grey-white);
}

/* 모바일에서만 줄바꿈 (640px 이상에서는 숨김) */
.br-mobile {
  display: inline;
}

/* ---- 안내 문구 슬롯 ---- */
.monty__message {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  margin-bottom: 8px;
}

.monty__title,
.monty__message,
.monty__boxes {
  transition: opacity 0.5s ease, filter 0.5s ease;
}

.monty--spotlight .monty__title,
.monty--spotlight .monty__message,
.monty--spotlight .monty__boxes {
  opacity: 0.38;
}

/* ---- 상자 3개 ---- */
.monty__boxes {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

/* ---- 하단 액션 슬롯 (선택 버튼 / 결과 CTA) ---- */
.monty__action {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 14px;
  min-height: 96px;
  transition: margin-top 0.4s ease;
}

.monty__action--choice { margin-top: 12px; }
.monty__action--result { margin-top: 12px; }

.monty__panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.monty__panel-text {
  font-size: 15px;
  font-weight: var(--weight-semibold);
  color: var(--grey-300);
}

.monty__panel-text--result {
  font-size: 18px;
  font-weight: var(--weight-bold);
  color: var(--grey-white);
}

.monty__choices {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

/* ---- Dim 오버레이 (2-2, 2-4) ---- */
.monty__dim {
  position: absolute;
  inset: 0;
  z-index: var(--z-overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 48px; /* 모바일: 우측 도트 인디케이터와 겹치지 않도록 여백 확보 */
  background: rgba(0, 0, 0, 0.5);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

.monty__dim.is-visible {
  opacity: 1;
  pointer-events: all;
}

.monty__dim-text {
  max-width: 420px;
  padding: 22px 26px;
  border: 1.5px solid var(--brand-lime);
  border-radius: 20px;
  background: var(--grey-800);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
  color: var(--grey-white);
  font-size: clamp(17px, 2.8vw, 22px);
  font-weight: 800;
  line-height: 1.4;
  opacity: 0;
  transform: scale(0.82);
  transition: opacity 0.35s ease, transform 0.35s var(--ease-pop);
}

.monty__dim.is-visible .monty__dim-text {
  opacity: 1;
  transform: scale(1);
}


/* ==========================================================================
   Gift box — 히어로의 3D 상자 이미지(닫힘/열림)를 재사용
   .gift-box 는 140×190 영역을 --s 배율로 축소합니다. (모바일)
   라벨류(내 픽, 말풍선, 번호)는 역배율로 원래 글자 크기를 유지합니다.
   --hue 로 상자 3개의 색을 구분합니다. (라임 / 보라 / 민트)
   ========================================================================== */
.gift-box {
  --s: 0.62;
  --hue: 0deg;
  --bubble-w: 150px;
  position: relative;
  flex: none;
  width: 140px;
  height: 186px; /* 번호 라벨 하단과 일치 (위아래 여백 계산용) */
  margin: calc((var(--s) - 1) * 93px) calc((var(--s) - 1) * 70px);
  transform: scale(var(--s));
}

.gift-box--2 { --hue: 185deg; }
.gift-box--3 { --hue: 75deg; }

.gift-box__shadow {
  position: absolute;
  top: 156px;
  left: 50%;
  width: 104px;
  height: 22px;
  margin-left: -52px;
  background: radial-gradient(ellipse, rgba(0, 0, 0, 0.6), transparent 72%);
  filter: blur(2px);
}

.gift-box__front {
  position: absolute;
  inset: 0;
  z-index: 4;
  cursor: default;
}

.gift-box__art {
  position: absolute;
  top: 0;
  left: 50%;
  width: 190px;
  max-width: none;
  filter: hue-rotate(var(--hue)) drop-shadow(0 10px 14px rgba(0, 0, 0, 0.5));
  pointer-events: none;
  transform: translateX(-50%);
  transition: opacity 0.4s ease, transform 0.5s var(--ease-pop), filter 0.3s ease;
}

.gift-box__art--open {
  opacity: 0;
  transform: translateX(-50%) scale(0.9);
}

.gift-box__label {
  position: absolute;
  top: 172px;
  left: 50%;
  padding: 3px 12px;
  border-radius: var(--radius-full);
  background: rgba(0, 0, 0, 0.6);
  color: rgba(255, 255, 255, 0.95);
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 0.5px;
  white-space: nowrap;
  transform: translate(-50%, -50%) scale(calc(1 / var(--s)));
  transition: opacity 0.3s ease;
}

.gift-box__pick-tag {
  position: absolute;
  top: 36px;
  right: -6px;
  z-index: 13;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  background: var(--brand-lime);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  color: var(--grey-black);
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
  transform-origin: top right;
  transform: scale(calc(1 / var(--s)));
}

.gift-box__bubble {
  position: absolute;
  bottom: 166px;
  left: 50%;
  z-index: 12;
  width: var(--bubble-w);
  padding: 9px 12px;
  border-radius: var(--radius-md);
  background: var(--grey-white);
  box-shadow: var(--shadow-menu);
  color: var(--status-red);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.35;
  text-align: center;
  transform-origin: bottom center;
  transform: translateX(-50%) scale(calc(1 / var(--s)));
}

/* 모바일: 3번 상자 말풍선은 우측 정렬 (도트 인디케이터와 겹침 방지) */
.gift-box--3 .gift-box__bubble {
  right: 0;
  left: auto;
  transform-origin: bottom right;
  transform: scale(calc(1 / var(--s)));
}

/* ---- 상태 ---- */
.monty--step-0 .gift-box__front {
  cursor: pointer;
  animation: gift-bob 2.6s ease-in-out infinite;
  animation-delay: var(--delay, 0s);
}

.gift-box--2 { --delay: 0.3s; }
.gift-box--3 { --delay: 0.6s; }

.gift-box--picked .gift-box__art {
  filter: hue-rotate(var(--hue)) drop-shadow(0 0 12px rgba(128, 255, 0, 0.85)) drop-shadow(0 10px 14px rgba(0, 0, 0, 0.5));
}

.gift-box--open .gift-box__art--closed {
  opacity: 0;
  transform: translateX(-50%) scale(0.9);
}

.gift-box--open .gift-box__art--open {
  opacity: 1;
  transform: translateX(-50%) scale(1);
}

.gift-box--open .gift-box__label {
  opacity: 0.5;
}

.gift-box--dimmed .gift-box__art,
.gift-box--dimmed .gift-box__label {
  opacity: 0.35;
}

.gift-box--dimmed .gift-box__art--closed {
  opacity: 0;
}

/* ==========================================================================
   Media queries
   ========================================================================== */
/* 380 ~ 479: 390, 412 */
@media (min-width: 380px) {
  .gift-box { --s: 0.68; }
  .monty__boxes { gap: 12px; }
}

/* 400 ~ 479: iPhone Pro 계열 (402×874 기준), 412 */
@media (min-width: 400px) {
  .gift-box { --s: 0.7; }
  .monty__boxes { gap: 10px; }
}

/* 480 ~ 639 */
@media (min-width: 480px) {
  .gift-box { --s: 0.8; --bubble-w: 160px; }
  .monty__boxes { gap: 20px; }
}

/* 640+: 원본 값 (상자 100%, gap 44px) */
@media (min-width: 640px) {
  .monty {
    gap: 32px;
    padding: 24px 20px;
  }

  .br-mobile { display: none; }
  .monty__dim { padding: 0 24px; }
  .monty__message {
    min-height: 64px; /* 2줄 말풍선(안내/결과) 높이: 문구가 바뀌어도 레이아웃이 흔들리지 않게 */
    margin-bottom: 12px;
  }
  .monty__boxes { gap: 44px; }
  .monty__action--choice { margin-top: 40px; }
  .monty__action--result { margin-top: 48px; }

  .gift-box {
    --s: 1;
    --bubble-w: 204px; /* PC: '이미 집에 있는 다이어리예요.' 가 한 줄에 들어가는 폭 */
  }

  .gift-box--3 .gift-box__bubble {
    right: auto;
    left: 50%;
    transform-origin: bottom center;
    transform: translateX(-50%) scale(calc(1 / var(--s)));
  }
}

/* 짧은 모바일 화면 (예: 360×640) */
@media (max-height: 700px) and (max-width: 639px) {
  .monty {
    gap: 12px;
    padding-top: 16px;
    padding-bottom: 16px;
  }

  .monty__message { min-height: 40px; margin-bottom: 0; }
  .monty__action { min-height: 84px; }
  .monty__action--choice,
  .monty__action--result { margin-top: 4px; }
}

/* ==========================================================================
   세로 균형 (모바일·PC 공통)
   - 상단 기준선 = 우측 상단 App Store 버튼 하단(--top-ref).
     콘텐츠를 "기준선 ~ 화면 하단" 사이 가운데에 두어 위아래 여백을 같게 합니다.
   - 하단 액션(선택 버튼 / 결과 CTA)은 높이를 미리 확보해 두고(레이아웃 고정),
     콘텐츠 전체를 transform 으로 부드럽게 올려 여백을 맞춥니다.
     (레이아웃 애니메이션은 iOS Safari 에서 잔상이 생김)
   ========================================================================== */
@keyframes panel-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.monty {
  --monty-gap: 32px;
  --action-reserve: 96px;   /* 하단 액션 영역 예약 높이 */
  --choice-h: 82px;         /* 선택 버튼 패널 높이 (버튼 한 줄) */
  --result-h: 91px;         /* 결과 CTA 패널 높이 */
  --monty-shift: calc((var(--action-reserve) + var(--monty-gap)) / 2);
  gap: var(--monty-gap);
  padding: var(--top-ref) 20px 0;
}

.monty--choice { --monty-shift: calc((var(--action-reserve) - var(--choice-h)) / 2); }
.monty--spotlight { --monty-shift: calc((var(--action-reserve) - var(--result-h)) / 2); }

.monty > :not(.monty__dim) {
  transform: translateY(var(--monty-shift));
  transition: transform 0.5s ease, opacity 0.5s ease;
}

.monty__action {
  min-height: var(--action-reserve);
  margin-top: 0;
  transition: transform 0.5s ease;
}

.monty__action--choice,
.monty__action--result { margin-top: 0; }

.monty__panel { animation: panel-in 0.5s ease both; }
.monty__panel[data-role="final"] { animation-delay: 0.35s; } /* 위로 올라간 뒤 CTA가 나타남 */

/* 안내/결과 문구는 부드럽게 나타남 */
.monty__message [data-role="hint"]:not([hidden]),
.monty__message [data-role="result"]:not([hidden]) {
  animation: panel-in 0.4s ease both;
}

@media (max-width: 639px) {
  .monty {
    --monty-gap: 20px;
    --action-reserve: 140px;
    --choice-h: 140px;   /* 버튼이 세로로 쌓였을 때 */
    --result-h: 94px;
    padding: var(--top-ref) 40px 0;
  }

  .monty__title { margin-bottom: 14px; }

  .monty__message {
    min-height: 64px; /* 2줄 말풍선 높이: 문구가 바뀌어도 레이아웃이 흔들리지 않게 */
    margin-bottom: 0;
  }

  /* dim 오버레이: 뒤 요소가 비쳐 보이지 않도록 더 어둡게 */
  .monty__dim {
    background: rgba(0, 0, 0, 0.88);
    -webkit-backdrop-filter: none;
    backdrop-filter: none; /* iOS Safari 에서 blur + opacity 전환 시 잔상 방지 */
  }
}

@media (min-width: 480px) and (max-width: 639px) {
  .monty { --choice-h: 84px; } /* 이 폭에서는 선택 버튼 2개가 한 줄 */
}

@media (max-width: 639px) and (max-height: 700px) {
  .monty { --monty-gap: 12px; }
  .monty__title { margin-bottom: 14px; }
}