/* ==========================================================
   interactions.css — 쇼츠 뷰어 / 장바구니 드로어 / 토스트 (T-003)
   외부 라이브러리 없음
   ========================================================== */

/* display 를 지정하는 컴포넌트들이 hidden 속성을 무시하지 않도록 */
[hidden] {
  display: none !important;
}

body.is-locked {
  overflow: hidden;
}

/* ==========================================================
   0. 카드 상호작용 보조
   ========================================================== */

.shorts[data-short],
.newcard[data-short],
.creator[data-short] {
  cursor: pointer;
}

.shorts[data-short]:focus-visible,
.newcard[data-short]:focus-visible,
.creator[data-short]:focus-visible {
  outline: 3px solid var(--lime);
  outline-offset: 3px;
}

/* 좋아요 on 상태 */
.rail__item.is-on,
.vrail__item.is-on {
  color: var(--red);
}

.rail__item.is-on svg,
.vrail__item.is-on svg {
  fill: var(--red);
  stroke: var(--red);
}

.product__act.is-on svg {
  fill: var(--red);
  stroke: var(--red);
}

.follow-btn.is-on {
  background: var(--lime);
  border-color: var(--lime);
  color: #10130a;
}

.empty-note {
  margin-top: 40px;
  padding: 44px 20px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px dashed var(--line-strong);
  text-align: center;
  color: var(--text-sub);
  font-size: var(--fs-body);
  font-weight: 600;
}

/* ==========================================================
   1. 쇼츠 뷰어 모달
   ========================================================== */

.viewer {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.viewer__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(6, 6, 9, 0.9);
  backdrop-filter: blur(6px);
  opacity: 0;
  transition: opacity 0.22s var(--ease);
}

.viewer.is-open .viewer__backdrop {
  opacity: 1;
}

.viewer__dialog {
  position: relative;
  width: 100%;
  height: 100%;
  max-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transform: scale(0.97);
  transition: opacity 0.22s var(--ease), transform 0.22s var(--ease);
}

.viewer.is-open .viewer__dialog {
  opacity: 1;
  transform: none;
}

/* ---- 세로 scroll-snap 피드 (휠은 네이티브 그대로) ---- */
.viewer__feed {
  position: relative;
  width: 100%;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-snap-type: y mandatory;
  overscroll-behavior: contain;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.viewer__feed::-webkit-scrollbar {
  display: none;
}

.vslide {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  scroll-snap-align: center;
  scroll-snap-stop: always;
  padding: 20px 16px;
}

/* 프레임은 항상 정확히 9:16 (T-007).
   width 를 max-width 로 자르면 height:100% 와 충돌해 세로로 늘어난 프레임이 된다
   (화면이 높을수록 심함 — 1440x1300 에서 실측 0.33). 그래서 "높이"만 확정하고
   너비는 aspect-ratio 가 계산하게 둔다: height = min(슬라이드 높이, 92vh, 폭 상한의 16/9).
   세 항 모두 높이 제약이므로 어떤 항이 이겨도 9:16 이 깨지지 않는다. */
.vslide__frame {
  --frame-w-max: 430px;
  position: relative;
  width: auto;
  height: min(100%, 92vh, calc(var(--frame-w-max) * 16 / 9));
  max-width: 100%;
  aspect-ratio: 9 / 16;
  border-radius: var(--radius-lg);
  overflow: hidden;
  color: #fff;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
  isolation: isolate;
}

.vslide__img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform-origin: center center;
  will-change: transform;
}

.vslide__img.is-failed {
  display: none;
}

/* ---- 켄번즈 (느린 zoom / pan) — "영상" 질감 ---- */
@keyframes kb-a {
  from { transform: scale(1.04) translate3d(0, 0, 0); }
  to   { transform: scale(1.2) translate3d(-2.5%, -3%, 0); }
}
@keyframes kb-b {
  from { transform: scale(1.2) translate3d(2.5%, 2%, 0); }
  to   { transform: scale(1.04) translate3d(-1.5%, -1.5%, 0); }
}
@keyframes kb-c {
  from { transform: scale(1.06) translate3d(2.5%, -2%, 0); }
  to   { transform: scale(1.22) translate3d(-2%, 2.5%, 0); }
}
@keyframes kb-d {
  from { transform: scale(1.18) translate3d(-2%, -2.5%, 0); }
  to   { transform: scale(1.05) translate3d(2%, 2%, 0); }
}

.vslide.is-active .vslide__img {
  animation: kb-a 13s var(--ease) infinite alternate;
}
.vslide.is-active[data-kb="b"] .vslide__img { animation-name: kb-b; animation-duration: 15s; }
.vslide.is-active[data-kb="c"] .vslide__img { animation-name: kb-c; animation-duration: 14s; }
.vslide.is-active[data-kb="d"] .vslide__img { animation-name: kb-d; animation-duration: 16s; }

/* ---- 슬라이드 오버레이 ---- */
.vslide__dur {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 3;
  height: 24px;
  padding: 0 9px;
  border-radius: var(--radius-xs);
  background: rgba(0, 0, 0, 0.62);
  backdrop-filter: blur(4px);
  font-size: var(--fs-2xs);
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.vslide__top {
  position: absolute;
  top: 14px;
  left: 14px;
  right: 74px;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 9px;
}

.vslide__avatar {
  width: 38px;
  height: 38px;
  border: 1.5px solid rgba(255, 255, 255, 0.85);
}

.vslide__who {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.vslide__name {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: var(--fs-body);
  font-weight: 800;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
}

.vslide__handle {
  font-size: var(--fs-2xs);
  color: rgba(255, 255, 255, 0.74);
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.vrail {
  position: absolute;
  right: 12px;
  bottom: 168px;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

.vrail__item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  color: #fff;
  font-size: var(--fs-2xs);
  font-weight: 700;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.55);
  transition: transform var(--dur) var(--ease);
}

.vrail__item:hover {
  transform: scale(1.12);
}

.vrail__item svg {
  filter: drop-shadow(0 2px 5px rgba(0, 0, 0, 0.5));
}

.vslide__foot {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 14px;
  z-index: 3;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.vslide__caption {
  font-size: var(--fs-body);
  font-weight: 700;
  line-height: 1.5;
  text-shadow: 0 1px 5px rgba(0, 0, 0, 0.6);
  padding-right: 56px;
}

.vstrip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(12px);
}

.vstrip__thumb {
  width: 46px;
  height: 46px;
  border-radius: 12px;
}

.vstrip__info {
  display: block;
  min-width: 0;
  flex: 1;
}

.vstrip__name {
  display: block;
  font-size: var(--fs-xs);
  font-weight: 600;
  color: rgba(255, 255, 255, 0.9);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.vstrip__price {
  display: block;
  font-size: var(--fs-body);
  font-weight: 900;
  letter-spacing: -0.02em;
}

.vstrip__cart {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 38px;
  padding: 0 14px;
  border-radius: var(--radius-pill);
  background: var(--lime);
  color: #10130a;
  font-size: var(--fs-sm);
  font-weight: 800;
  transition: transform var(--dur) var(--ease), background var(--dur) var(--ease);
}

.vstrip__cart:hover {
  background: var(--lime-strong);
  transform: translateY(-1px);
}

/* ---- 뷰어 컨트롤 (스크롤을 막지 않도록 pointer-events 분리) ---- */
.viewer__ui {
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
}

.viewer__close,
.viewer__navbtn {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.22);
  backdrop-filter: blur(8px);
  color: #fff;
  transition: background var(--dur) var(--ease), transform var(--dur) var(--ease);
}

.viewer__close:hover,
.viewer__navbtn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.28);
  transform: scale(1.06);
}

.viewer__navbtn:disabled {
  opacity: 0.32;
  cursor: default;
}

.viewer__close {
  position: absolute;
  top: 18px;
  right: 20px;
}

.viewer__nav {
  position: absolute;
  right: 20px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.viewer__indicator {
  pointer-events: none;
  font-size: var(--fs-2xs);
  font-weight: 700;
  color: rgba(255, 255, 255, 0.72);
  letter-spacing: 0.02em;
}

/* ==========================================================
   2. 장바구니 드로어
   ========================================================== */

.drawer {
  position: fixed;
  inset: 0;
  z-index: 1200;
}

.drawer__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 10, 14, 0.5);
  opacity: 0;
  transition: opacity 0.22s var(--ease);
}

.drawer.is-open .drawer__backdrop {
  opacity: 1;
}

.drawer__panel {
  position: absolute;
  top: 0;
  right: 0;
  height: 100%;
  width: min(400px, 100%);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.24s var(--ease);
}

.drawer.is-open .drawer__panel {
  transform: none;
}

.drawer__head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 16px 14px 20px;
  border-bottom: 1px solid var(--line);
}

.drawer__title {
  flex: 1;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.drawer__count {
  min-width: 24px;
  height: 24px;
  padding: 0 7px;
  border-radius: var(--radius-pill);
  background: var(--purple);
  color: #fff;
  font-size: var(--fs-xs);
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.drawer__body {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.cartitem {
  display: flex;
  gap: 12px;
  padding: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface-alt);
}

.cartitem__thumb {
  position: relative;
  width: 64px;
  height: 64px;
  flex: none;
  border-radius: var(--radius-xs);
  overflow: hidden;
  background: linear-gradient(150deg, #eef0f4, #dcdfe5);
}

.cartitem__thumb img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.cartitem__thumb img.is-failed {
  display: none;
}

.cartitem__body {
  min-width: 0;
  flex: 1;
}

.cartitem__name {
  font-size: var(--fs-sm);
  font-weight: 600;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cartitem__price {
  margin-top: 2px;
  font-size: var(--fs-body);
  font-weight: 900;
  letter-spacing: -0.02em;
}

.cartitem__row {
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.qty {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-pill);
  padding: 2px;
  background: var(--surface);
}

.qty__btn {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--text-sub);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}

.qty__btn:hover {
  background: var(--bg-soft);
  color: var(--text);
}

.qty__num {
  min-width: 26px;
  text-align: center;
  font-size: var(--fs-sm);
  font-weight: 800;
}

.cartitem__del {
  margin-left: auto;
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--text-faint);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.cartitem__del:hover {
  color: var(--red);
}

.cart-empty {
  margin: auto 0;
  padding: 40px 16px;
  text-align: center;
  color: var(--text-sub);
  font-size: var(--fs-sm);
  line-height: 1.6;
}

.cart-empty__icon {
  display: grid;
  place-items: center;
  width: 60px;
  height: 60px;
  margin: 0 auto 14px;
  border-radius: 50%;
  background: var(--bg);
  color: var(--text-faint);
}

.drawer__foot {
  border-top: 1px solid var(--line);
  padding: 16px 20px 20px;
}

.drawer__sum {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 12px;
  font-size: var(--fs-sm);
  color: var(--text-sub);
  font-weight: 600;
}

.drawer__sum strong {
  font-size: 21px;
  font-weight: 900;
  letter-spacing: -0.03em;
  color: var(--text);
}

.drawer__order {
  width: 100%;
  height: 48px;
  font-size: 15px;
  font-weight: 800;
}

.drawer__note {
  margin-top: 10px;
  text-align: center;
  font-size: var(--fs-2xs);
  color: var(--text-faint);
}

/* ==========================================================
   3. 토스트
   ========================================================== */

.toasts {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  z-index: 2000;
  display: flex;
  flex-direction: column-reverse;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  width: min(420px, calc(100% - 32px));
}

.toast {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  padding: 11px 18px;
  border-radius: var(--radius-pill);
  background: rgba(17, 17, 22, 0.94);
  color: #fff;
  font-size: var(--fs-sm);
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.22s var(--ease), transform 0.22s var(--ease);
}

.toast.is-in {
  opacity: 1;
  transform: none;
}

.toast__text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ==========================================================
   4. 동작 줄이기 (prefers-reduced-motion)
   켄번즈 반복 애니메이션 정지 + 열림/닫힘 전환 즉시 적용
   ========================================================== */

@media (prefers-reduced-motion: reduce) {
  .vslide.is-active .vslide__img,
  .vslide.is-active[data-kb="b"] .vslide__img,
  .vslide.is-active[data-kb="c"] .vslide__img,
  .vslide.is-active[data-kb="d"] .vslide__img {
    animation: none !important;
    transform: none !important;
  }

  .viewer__backdrop,
  .viewer__dialog,
  .viewer__close,
  .viewer__navbtn,
  .vrail__item,
  .vstrip__cart,
  .drawer__backdrop,
  .drawer__panel,
  .toast {
    transition: none !important;
  }

  .viewer__close:hover,
  .viewer__navbtn:hover:not(:disabled),
  .vrail__item:hover,
  .vstrip__cart:hover {
    transform: none;
  }
}

/* ==========================================================
   5. 반응형
   ========================================================== */

@media (max-width: 720px) {
  .vslide {
    padding: 0;
  }

  .vslide__frame {
    width: 100%;
    height: 100%;
    max-height: none;
    aspect-ratio: auto;
    border-radius: 0;
  }

  /* 좁은 화면에서는 내비게이션이 하단 가로 배치가 되는데, bottom 이 낮으면
     .vslide__foot(캡션 + 상품 스트립) 위에 올라타 담기 버튼 클릭을 가로챈다.
     캡션 상단(뷰포트 하단 기준 최대 121.3px)과 액션 레일 하단(200px) 사이
     안전 구간 [122, 158] 의 가운데 값으로 띄운다. (T-004) */
  .viewer__nav {
    top: auto;
    bottom: 132px;
    right: 14px;
    transform: none;
    flex-direction: row;
  }

  .viewer__close {
    top: 12px;
    right: 12px;
  }

  .vrail {
    bottom: 200px;
  }
}

@media (max-width: 480px) {
  .drawer__panel {
    width: 100%;
  }
}
