/* =========================================================
   SKYZAI · 모바일 앱 느낌의 공통 모션 (app_motion.js 와 한 쌍)
   - 화면 전환: 앞으로 가면 오른쪽에서 밀려 들어오고, 뒤로 가면 오른쪽으로 빠진다.
     헤더·하단 탭바는 그 자리에 머무른다(네이티브 네비게이션 스택처럼).
   - 누름 피드백: 모든 누를 수 있는 것은 눌리는 동안 살짝 작아지고 어두워진다.
   - 당겨서 새로고침 / 왼쪽 가장자리 스와이프 뒤로가기 표시.
   - 스크롤하면 헤더 아래 그림자.
   모두 768px 이하(모바일 셸)에서만 동작. 움직임 줄이기 설정이면 전부 끈다.
   ========================================================= */

/* ─── 1. 화면 전환 ─── */
@media (max-width: 768px) {
  /* 헤더·탭바는 root 스냅샷에서 분리해 고정. 모달이 열려 display:none 이면 이름이 무시되어 안전. */
  .mobile-header     { view-transition-name: app-header; }
  .mobile-bottom-nav { view-transition-name: app-tabbar; }
  ::view-transition-group(app-header),
  ::view-transition-group(app-tabbar) { animation-duration: 0s; }
  /* 이름 붙인 요소 영역이 겹치지 않도록 root 는 그 아래 */
  ::view-transition-group(root) { z-index: 0; }
  ::view-transition-group(app-header),
  ::view-transition-group(app-tabbar) { z-index: 10; }

  /* 헤더·탭바는 전환 내내 제자리에 있어야 하므로 로드 시 등장 애니메이션을 끈다.
     (켜 두면 방향이 정해지지 않은 전환에서 투명한 첫 프레임이 찍혀 깜빡인다) */
  .mobile-header, .mobile-bottom-nav { animation: none; }
  /* 슬라이드 전환 중에는 본문 등장 페이드도 끈다 — 새 화면이 반투명한 채로 밀려 들어오지 않게 */
  html[data-nav-dir] .main { animation: none; }

  /* 기본값 plus-lighter 블렌딩은 두 화면이 겹칠 때 반투명하게 보이게 하므로 끈다 */
  html[data-nav-dir]::view-transition-old(root),
  html[data-nav-dir]::view-transition-new(root) { mix-blend-mode: normal; }

  @keyframes app-slide-in-right  { from { transform: translateX(100%); } to { transform: translateX(0); } }
  @keyframes app-slide-out-left  { from { transform: translateX(0); } to { transform: translateX(-28%); } }
  @keyframes app-slide-in-left   { from { transform: translateX(-28%); } to { transform: translateX(0); } }
  @keyframes app-slide-out-right { from { transform: translateX(0); } to { transform: translateX(100%); } }
  @keyframes app-dim-in  { from { opacity: 1; } to { opacity: 0.55; } }
  @keyframes app-dim-out { from { opacity: 0.55; } to { opacity: 1; } }
  @keyframes app-fade-in  { from { opacity: 0; } to { opacity: 1; } }
  @keyframes app-fade-out { from { opacity: 1; } to { opacity: 0; } }

  /* 앞으로(push): 새 화면이 오른쪽에서 들어오고 옛 화면은 왼쪽으로 조금 물러나며 어두워짐 */
  html[data-nav-dir="forward"]::view-transition-old(root) {
    animation: 300ms var(--ease-out-toss, cubic-bezier(0.22, 1, 0.36, 1)) both app-slide-out-left,
               300ms linear both app-dim-in;
  }
  html[data-nav-dir="forward"]::view-transition-new(root) {
    animation: 300ms var(--ease-out-toss, cubic-bezier(0.22, 1, 0.36, 1)) both app-slide-in-right;
    box-shadow: -8px 0 24px rgba(0, 0, 0, 0.12);
  }
  html[data-nav-dir="forward"]::view-transition-image-pair(root) { isolation: auto; }
  html[data-nav-dir="forward"]::view-transition-new(root) { z-index: 2; }
  html[data-nav-dir="forward"]::view-transition-old(root) { z-index: 1; }

  /* 뒤로(pop): 옛 화면이 오른쪽으로 빠지고 새(이전) 화면이 왼쪽에서 제자리로 */
  html[data-nav-dir="back"]::view-transition-old(root) {
    animation: 280ms var(--ease-out-toss, cubic-bezier(0.22, 1, 0.36, 1)) both app-slide-out-right;
    box-shadow: -8px 0 24px rgba(0, 0, 0, 0.12);
    z-index: 2;
  }
  html[data-nav-dir="back"]::view-transition-new(root) {
    animation: 280ms var(--ease-out-toss, cubic-bezier(0.22, 1, 0.36, 1)) both app-slide-in-left,
               280ms linear both app-dim-out;
    z-index: 1;
  }
  html[data-nav-dir="back"]::view-transition-image-pair(root) { isolation: auto; }

  /* 탭 전환: 자리를 바꾸는 것이 아니라 내용만 바뀌므로 빠른 크로스페이드 */
  html[data-nav-dir="tab"]::view-transition-old(root) { animation: 140ms linear both app-fade-out; }
  html[data-nav-dir="tab"]::view-transition-new(root) { animation: 140ms linear both app-fade-in; }

  /* 스와이프로 이미 화면을 밀어낸 뒤에는 새 화면만 제자리로 */
  html[data-nav-dir="swipe-back"]::view-transition-old(root) { animation: 1ms linear both app-fade-out; }
  html[data-nav-dir="swipe-back"]::view-transition-new(root) {
    animation: 220ms var(--ease-out-toss, cubic-bezier(0.22, 1, 0.36, 1)) both app-slide-in-left,
               220ms linear both app-dim-out;
  }
}

/* ─── 2. 누름 피드백 (app_motion.js 가 .is-pressed 를 붙인다) ─── */
.is-pressed {
  transition: transform 90ms cubic-bezier(0.22, 1, 0.36, 1), opacity 90ms linear, filter 90ms linear !important;
}
/* 블록 요소(카드·행·버튼·칩)는 살짝 작아지고, 글자 링크(인라인)는 흐려지기만 한다 */
.is-pressed:not(.app-press-inline) { transform: scale(0.98) !important; filter: brightness(0.96); }
.is-pressed.app-press-inline { opacity: 0.55; }
.is-pressed.app-press-row { transform: none !important; filter: none; background-color: var(--surface-2) !important; }
@media (prefers-reduced-motion: reduce) {
  .is-pressed { transform: none !important; filter: none; }
}

/* ─── 3. 헤더 스크롤 그림자 ─── */
@media (max-width: 768px) {
  .mobile-header { transition: box-shadow 200ms linear; }
  .mobile-header.is-scrolled { box-shadow: 0 1px 0 var(--border-strong), 0 6px 16px -10px rgba(0, 0, 0, 0.18); }
}

/* ─── 4. 당겨서 새로고침 ─── */
.app-ptr {
  position: fixed;
  left: 50%;
  top: calc(var(--header-h, 56px) + var(--safe-top, env(safe-area-inset-top, 0px)) + 8px);
  width: 36px; height: 36px;
  margin-left: -18px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.14);
  display: flex; align-items: center; justify-content: center;
  color: var(--primary);
  z-index: 60;
  opacity: 0;
  transform: translateY(-48px) scale(0.6);
  pointer-events: none;
  will-change: transform, opacity;
}
.app-ptr.is-snapping { transition: transform 240ms cubic-bezier(0.22, 1, 0.36, 1), opacity 200ms linear; }
.app-ptr .ico { width: 18px; height: 18px; transition: transform 160ms cubic-bezier(0.22, 1, 0.36, 1); }
.app-ptr.is-armed .ico { transform: rotate(180deg); }
.app-ptr.is-refreshing .ico { animation: app-ptr-spin 800ms linear infinite; }
@keyframes app-ptr-spin { to { transform: rotate(360deg); } }
@media (min-width: 769px) { .app-ptr { display: none; } }

/* ─── 5. 가장자리 스와이프 뒤로가기(모바일 폭·앱 공통) ─── */
/* will-change 는 쓰지 않는다 — 본문 안의 position:fixed 요소(토스트 등)가 본문 기준으로 튀어 버린다 */
body.app-swiping .main { box-shadow: -8px 0 24px rgba(0, 0, 0, 0.12); }
body.app-swiping .main.is-snapping { transition: transform 220ms cubic-bezier(0.22, 1, 0.36, 1); }
.app-swipe-dim {
  position: fixed; inset: 0;
  background: #000;
  opacity: 0;
  pointer-events: none;
  z-index: 40;
}
