/* ==========================================================================
   SPLIT LAYOUT — 상단 50% 스크롤월드 / 하단 50% 일반 컨텐츠
   --------------------------------------------------------------------------
   스크롤월드(scrub-engine)는 화면 상단 절반만 차지하고, 하단 절반에는 갤러리부터
   시작되는 일반 컨텐츠가 최초 로딩 시점부터 그대로 노출된다. 스크롤을 내리면
   상단에서 스크롤월드가 마지막 씬까지 재생되고, 그 이후부터는 마지막 씬 + 하단
   컨텐츠가 하나의 일반 페이지처럼 함께 위로 스크롤된다.

   기하 구조는 --sw-split (스크롤월드 패널의 아래쪽 경계, px) 하나로 제어된다.
   이 값은 js/split-layout.js 가 SPLIT 비율 × window.innerHeight 로 매 layout 시
   :root 에 써 넣는다. (여기 적힌 50vh 는 JS 실행 전 초기값)

   ROLLBACK: index.html 에서 이 파일의 <link> 와 js/split-layout.js 의 <script>,
   그리고 mount 설정의 trackTail / SW_SPLIT.attach() 두 줄만 제거하면 원래
   풀스크린 스크롤월드로 즉시 되돌아간다. (.backup/ 스냅샷도 참고)
   ========================================================================== */

:root {
  --sw-split: 50vh;   /* 스크롤월드 패널 하단 경계 = 화면 상단 50% */
  --sw-head: 76px;    /* 엔진 상단 헤더(topbar) 높이 */
  --sw-panel-gap: 12px; /* 패널 카드와 하단 컨텐츠 사이 여백 */
  --sw-margin: 3rem;  /* 무대 좌우 여백 합(js/scrub-engine.js 의 width: calc(100% - Npx)와 동일) */
}

/* --------------------------------------------------------------------------
   1) 스크롤월드 무대를 화면 상단 절반으로 축소
   (.sw-root 접두사로 엔진이 주입하는 !important 규칙보다 우선순위 확보)
   -------------------------------------------------------------------------- */
.sw-root .sw-stage,
.sw-root .sw-copylayer {
  top: var(--sw-head) !important;
  /* [16:10] 가로는 항상 컨테이너를 꽉 채우고(엔진의 width/max-width 그대로 유지),
     세로는 "패널 높이(--sw-split 기준)" 와 "너비 ÷ 1.6" 중 더 큰 값을 쓴다 — 화면이
     16:10보다 납작해질 때만 세로가 그만큼 늘어나 16:10을 지키고, 평소에는 패널
     높이 쪽이 더 크므로 지금까지와 동일하게 동작한다. */
  height: max(
    calc(var(--sw-split) - var(--sw-head) - var(--sw-panel-gap)),
    calc(min(calc(100vw - var(--sw-margin)), 1280px) / 1.6)
  ) !important;
  min-height: 0 !important;
}

.sw-root .sw-stage {
  box-shadow: 0 8px 24px -4px rgba(0, 0, 0, 0.1), 0 0 0 1px rgba(0, 0, 0, 0.05) !important;
}

/* 무대 내부 씬 및 영상/이미지 카드 맞춤 */
.sw-root .sw-scene {
  position: absolute !important;
  inset: 0 !important;
  width: 100% !important;
  height: 100% !important;
  border-radius: inherit !important;
  overflow: hidden !important;
}

.sw-root .sw-scene__still,
.sw-root .sw-scene__video {
  position: absolute !important;
  top: 0 !important;
  left: 0 !important;
  width: 100% !important;
  height: 100% !important;
  max-width: none !important;
  object-fit: cover !important;
  object-position: center center !important;
  transform: none !important;
  border-radius: inherit !important;
  box-shadow: none !important;
}

/* 배경 스카이가 하단에서 칼같이 잘리지 않고 자연스럽게 전체 페이지 배경과 일체화 */
.sw-root .sw-sky {
  height: 100vh !important;
  background: transparent !important;
}

/* 우측 씬 인디케이터: 축소된 패널의 수직 중앙 */
.sw-root .sw-route {
  top: calc(var(--sw-head) + (var(--sw-split) - var(--sw-head) - var(--sw-panel-gap)) / 2) !important;
}

/* 스크롤 힌트: 패널이 짧아져 하단은 카피(제목/본문/태그)가 쓰므로,
   비어 있는 패널 우측 상단으로 옮기고 칩 형태로 가독성을 확보한다.
   (페이드아웃은 엔진이 inline opacity 로 계속 제어) */
.sw-root .sw-hint {
  left: auto !important;
  right: calc(max(1.5rem, (100vw - 1280px) / 2) + 20px) !important;
  top: calc(var(--sw-head) + 18px) !important;
  bottom: auto !important;
  transform: none !important;
  flex-direction: row !important;
  align-items: center !important;
  gap: 10px !important;
  padding: 8px 16px !important;
  border-radius: 999px !important;
  background: rgba(15, 23, 42, 0.42) !important;
  backdrop-filter: blur(8px) !important;
  -webkit-backdrop-filter: blur(8px) !important;
  color: #ffffff !important;
  text-transform: none !important;
  letter-spacing: -0.01em !important;
  font-size: 0.78rem !important;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.45) !important;
  max-width: calc(100% - 3rem) !important;
}
.sw-root .sw-hint i {
  width: 16px !important;
  height: 25px !important;
  border-radius: 9px !important;
  border-color: rgba(255, 255, 255, 0.75) !important;
  flex: 0 0 auto !important;
}
.sw-root .sw-hint i::after {
  background: #ffffff !important;
}

/* 짧아진 패널에서도 흰 카피가 읽히도록 스크림 강화.
   엔진의 .sw-stage::after(z-index:5)는 활성 씬(z-index:120) 아래에 깔려 실제로는
   보이지 않으므로, 카피 레이어(z-index:20 = 씬보다 위) 자체에 그라디언트를 깐다. */
.sw-root .sw-copylayer::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  border-radius: inherit;
  background: linear-gradient(to top,
              rgba(20, 20, 20, 0.7) 0%,
              rgba(50, 50, 50, 0.3) 40%,
              rgba(50, 50, 50, 0.16) 72%,
              rgba(0, 0, 0, 0) 100%) !important;
}

/* 축소된 패널에 맞춘 타이포 스케일 다운 */
.sw-root .sw-copy {
  padding: 32px 44px !important;
}
.sw-root .sw-copy__title {
  font-size: clamp(1.5rem, 2.4vw, 2.1rem) !important;
  margin: 2px 0 8px 0 !important;
}
.sw-root .sw-copy__body {
  font-size: clamp(0.92rem, 1vw, 1rem) !important;
  line-height: 1.65 !important;
  max-width: 720px !important;
}
.sw-root .sw-copy__tags {
  margin-top: 10px !important;
}

/* 월드가 지나간 뒤 헤더가 컨텐츠 위에 떠 있을 때도 투명하고 깔끔하게 유지 */
.sw-root .sw-topbar.is-scrolled {
  backdrop-filter: blur(12px) !important;
  -webkit-backdrop-filter: blur(12px) !important;
}

/* --------------------------------------------------------------------------
   2) 하단 일반 컨텐츠 래퍼 (CSS sticky 고정)
   #page-flow 의 문서상 위치 = --sw-split (= .sw-track 높이) 이므로 sticky top 과
   같아 최초 로딩부터 화면 하단 절반에 놓인다. 스크롤을 내리면 sticky 가 그 자리에
   붙잡아 두고(1단계), #flow-tail 이 만들어 둔 여유(=월드 스크롤 길이)를 다 쓰면
   고정이 풀려 일반 스크롤로 이어진다(2단계).
   * 고정을 컴포지터가 처리하므로 스크롤 중 JS 위치 보정이 없어 떨림이 없다.
   * transform 을 쓰지 않는다 — 쓰면 내부 position:fixed 가 깨지고 다시 흔들린다.
   -------------------------------------------------------------------------- */
#page-flow {
  position: sticky;
  top: var(--sw-split);
  z-index: 40;                /* 무대(10)·카피(20)·인디케이터(30) 위, 헤더(50) 아래 */
  background: transparent;
}

/* sticky 고정 구간 길이 = 월드 스크롤 길이(exitStart). 높이는 js/split-layout.js 가
   레이아웃 시점에 써 넣는다. 화면에는 보이지 않는 스페이서다. */
#flow-tail {
  height: 0;
  pointer-events: none;
}

/* 앵커 점프(#gallery-section 등) 시 상단 고정 헤더에 제목이 가려지지 않도록 오프셋 */
#page-flow > section,
#page-flow > footer {
  scroll-margin-top: calc(var(--sw-head) + 8px);
}

/* sticky 안전장치: body 에 overflow-x:hidden 이 걸리면 브라우저에 따라 body 가
   스크롤 컨테이너가 되어 sticky 가 동작하지 않을 수 있다. clip 은 스크롤 컨테이너를
   만들지 않으므로 지원 브라우저에서는 이 값이 쓰이고, 미지원이면 hidden 이 남는다. */
body {
  overflow-x: clip;
}

/* 상단 패널 아래로 자연스럽게 이어지도록 경계선 없음 & 포토갤러리 배경 투명 */
#page-flow > section:first-child,
.gallery-section {
  border-top: none !important;
  background: transparent !important;
}

/* --------------------------------------------------------------------------
   3) 모바일: 헤더 + 스크롤월드 무대 + 글 영역 = 화면 100% (글을 영상 밖으로 분리)
   -------------------------------------------------------------------------- */
@media (max-width: 1024px) {
  :root {
    --sw-head: 112px;
    --sw-panel-gap: 12px;
    --sw-margin: 2rem;  /* 모바일 무대 좌우 여백 */
    --sw-stage-h: clamp(200px, 34vh, 270px);
  }

  /* 1) 스크롤월드 무대 (영상/이미지 카드) */
  .sw-root .sw-stage {
    top: var(--sw-head) !important;
    left: 50% !important;
    transform: translateX(-50%) translateY(var(--sw-exit-y, 0px)) !important;
    width: calc(100% - var(--sw-margin)) !important;
    height: var(--sw-stage-h) !important;
    min-height: 0 !important;
    border-radius: 16px !important;
    overflow: hidden !important;
    box-shadow: 0 6px 20px -3px rgba(0, 0, 0, 0.12), 0 0 0 1px rgba(0, 0, 0, 0.06) !important;
  }

  .sw-root .sw-scene__video,
  .sw-root .sw-scene__still {
    border-radius: 16px !important;
  }

  /* 2) 글 레이어: 영상 영역 아래로 완전히 분리 배치 */
  .sw-root .sw-copylayer {
    top: calc(var(--sw-head) + var(--sw-stage-h) + var(--sw-panel-gap)) !important;
    left: 50% !important;
    transform: translateX(-50%) translateY(var(--sw-exit-y, 0px)) !important;
    width: calc(100% - var(--sw-margin)) !important;
    height: calc(100vh - var(--sw-head) - var(--sw-stage-h) - var(--sw-panel-gap) * 2) !important;
    min-height: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    pointer-events: auto !important;
    z-index: 20 !important;
  }

  /* 영상 위의 어두운 스크림 그라데이션 제거 (글이 밖으로 나왔으므로 영상 원본 그대로 노출) */
  .sw-root .sw-copylayer::before {
    display: none !important;
  }

  /* 3) 개별 씬 설명글: 상단 정렬 및 검정색/다크 폰트 테마 */
  .sw-root .sw-copy {
    position: absolute !important;
    inset: 0 !important;
    padding: 8px 4px 16px 4px !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: flex-start !important;
    align-items: flex-start !important;
    text-align: left !important;
    background: transparent !important;
    color: #0f172a !important;
  }

  .sw-root .sw-copy__title {
    color: #0f172a !important;
    font-size: clamp(1.2rem, 5vw, 1.45rem) !important;
    font-weight: 800 !important;
    letter-spacing: -0.025em !important;
    margin: 0 0 8px 0 !important;
    text-shadow: none !important;
    line-height: 1.35 !important;
  }

  .sw-root .sw-copy__body {
    color: #334155 !important;
    font-size: 0.9rem !important;
    line-height: 1.6 !important;
    text-shadow: none !important;
    max-height: calc(100vh - var(--sw-head) - var(--sw-stage-h) - 105px) !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  .sw-root .sw-copy__tags {
    margin-top: 12px !important;
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 6px !important;
  }

  .sw-root .sw-copy__tags li {
    background: rgba(15, 23, 42, 0.06) !important;
    color: #475569 !important;
    border: 1px solid rgba(15, 23, 42, 0.1) !important;
    text-shadow: none !important;
    font-size: 0.8rem !important;
    font-weight: 600 !important;
    padding: 4px 10px !important;
    border-radius: 999px !important;
  }

  /* 4) 우측 씬 인디케이터 점: 영상 카드 내부 수직 중앙 */
  .sw-root .sw-route {
    right: calc(1rem + 10px) !important;
    top: calc(var(--sw-head) + var(--sw-stage-h) / 2) !important;
    transform: translateY(calc(-50% + var(--sw-exit-y, 0px))) !important;
    gap: 8px !important;
    padding: 4px 0 !important;
    z-index: 35 !important;
  }

  .sw-root .sw-route::before {
    display: none !important;
  }

  .sw-root .sw-route__dot {
    width: 12px !important;
    height: 12px !important;
  }

  .sw-root .sw-route__dot i {
    width: 5px !important;
    height: 5px !important;
    background: rgba(255, 255, 255, 0.55) !important;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5) !important;
  }

  .sw-root .sw-route__dot.is-active i {
    background: #ffffff !important;
    transform: scale(1.6) !important;
    box-shadow: 0 0 6px rgba(255, 255, 255, 0.95), 0 1px 3px rgba(0, 0, 0, 0.5) !important;
  }

  .sw-root .sw-route__label {
    display: none !important;
  }

  /* 모바일에서는 터치 환경이므로 마우스 힌트 숨김 */
  .sw-root .sw-hint {
    display: none !important;
  }
}
