/* 처음으로 가기 버튼 — 소비자 여섯 화면(색인·쿨러 기사·숍·랩·비즈니스·아카이브) 공용.
   2026-09-01 사용자 지시: 「메뉴마다 내려가면 처음으로 가기 버튼이 따라다녀야 한다」.

   짝 파일 scripts/back-to-top.js 가 버튼 DOM 을 만들고 .is-visible 을 토글한다.
   나타나는 스크롤 임계값의 단일 소스는 back-to-top.js 안 THRESHOLD_PX 하나다 —
   여기 CSS 는 그 값을 몰라도 된다(불리언만 받는다).

   색은 tokens.css 변수만 쓴다(리터럴 금지) — theme-matches-canonical ·
   screen-theme-contract 게이트가 리터럴 색을 잡는다. 유채색도 쓰지 않는다
   (사용자 판정 D-38 — 강조는 명도로 한다. 이 버튼은 --st-ok/--st-warn/--st-bad
   같은 상태가 아니다). */

#back-to-top-btn {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 300;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-l, 16px);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  color: var(--text);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px);
  transition: opacity .2s ease, transform .2s ease, visibility 0s linear .2s, bottom .2s ease;
}

#back-to-top-btn.is-visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  transition: opacity .2s ease, transform .2s ease, bottom .2s ease;
}

#back-to-top-btn:hover { border-color: var(--text); }

#back-to-top-btn:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}

#back-to-top-btn svg {
  width: 20px;
  height: 20px;
  pointer-events: none;
}

/* index.html 전용 모바일 하단 독(.mobile-media-nav, media.css 1180 구간)이 화면을
   가로로 덮는다. back-to-top.js 가 그 요소의 존재를 감지해 <html> 에
   data-has-mobile-dock 을 붙이는 것이 이 회피의 단일 소스 — 숫자(72px)는
   media.css 의 독 높이와 같은 값을 여기서도 한 번만 더 쓴다(그 파일이 바뀌면
   같이 본다). 나머지 다섯 화면은 모바일 독이 없다("subpages have no mobile
   dock" — journal-shell.css) 이므로 이 규칙이 적용되지 않는다. */
html[data-has-mobile-dock] #back-to-top-btn {
  bottom: calc(72px + env(safe-area-inset-bottom) + 20px);
}

@media (max-width: 620px) {
  #back-to-top-btn {
    right: 14px;
    bottom: max(14px, env(safe-area-inset-bottom));
    width: 44px;
    height: 44px;
  }
  html[data-has-mobile-dock] #back-to-top-btn {
    bottom: calc(72px + env(safe-area-inset-bottom) + 14px);
  }
}

@media (prefers-reduced-motion: reduce) {
  #back-to-top-btn {
    transition: opacity .01s linear, visibility 0s linear;
  }
  #back-to-top-btn.is-visible {
    transition: opacity .01s linear;
  }
}
