/* ==========================================================================
   download.css — QR 스캔 고객이 보는 사진 다운로드 페이지 전용 스타일
   공통 디자인 시스템(lm.css)을 먼저 불러온 뒤 적용된다.
   DESIGN_SPEC §6.1 — 밝은 종이 톤 · 인화지(.lm-print) · iOS 감성.
   색·모서리·그림자는 전부 lm.css 토큰을 쓴다(자체 색 상수 금지).
   ========================================================================== */

/* hidden 속성이 flex/grid 표시값에 밀리지 않도록 강제한다. */
[hidden] {
  display: none !important;
}

.dl-body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  /* 좌우 여백 16px 고정 (360px 폭에서도 가로 스크롤 없음) */
  padding:
    calc(var(--lm-gap) + env(safe-area-inset-top)) calc(var(--lm-gap) + env(safe-area-inset-right))
    calc(var(--lm-gap-lg) + env(safe-area-inset-bottom)) calc(var(--lm-gap) + env(safe-area-inset-left));
  background: var(--lm-bg);
  color: var(--lm-text);
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

/* --------------------------------------------------------------------------
   레이아웃
   -------------------------------------------------------------------------- */
.dl-shell {
  position: relative;
  width: 100%;
  max-width: 460px;
  display: flex;
  flex-direction: column;
  gap: var(--lm-gap-lg);
  animation: dl-rise .42s var(--lm-ease) both;
}

@keyframes dl-rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

/* 브랜드 행 */
.dl-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 2px;
}

.dl-logo {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  /* 로고는 원형. 틴트 단색 — 그라디언트 금지. */
  border-radius: var(--lm-r-pill);
  background: var(--lm-primary);
  color: var(--lm-text-inv);
  font-size: 14.5px;
  font-weight: 800;
  letter-spacing: -.02em;
  box-shadow: var(--lm-shadow-sm);
}

.dl-head__text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  gap: 1px;
}

.dl-brand {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

/* 사진 블록 — 카드가 아니라 종이 배경 위에 그대로 놓는다(흰색 중첩 방지). */
.dl-card {
  display: flex;
  flex-direction: column;
  gap: var(--lm-gap);
}

.dl-body[data-state="error"] .dl-card,
.dl-body[data-state="error"] .dl-strip {
  display: none;
}

/* --------------------------------------------------------------------------
   사진 영역 — 흰 인화지 프레임(.lm-print) 안쪽
   -------------------------------------------------------------------------- */
.dl-print {
  transition: opacity var(--lm-dur) var(--lm-ease), transform var(--lm-dur) var(--lm-ease);
}

.dl-print__caption {
  /* 아래 캡션 띠 — 촬영 일시가 들어간다. */
  font-variant-numeric: tabular-nums;
}

.dl-photo {
  position: relative;
  /*
   * 실제 비율을 알기 전에는 세로형 기본값을 쓰되 사진은 contain 으로 넣어
   * 절대 잘리지 않게 한다. 로드 후 naturalWidth/naturalHeight 로 JS 가
   * --dl-ratio 를 갱신하면 레터박스 없이 프레임에 꼭 맞는다.
   */
  aspect-ratio: var(--dl-ratio, 3 / 4);
  transition:
    aspect-ratio .4s var(--lm-ease),
    opacity var(--lm-dur) var(--lm-ease);
}

.dl-photo.is-swapping {
  opacity: .4;
}

.dl-skeleton {
  position: absolute;
  inset: 0;
  display: block;
  border-radius: inherit;
}

.dl-photo.is-full .dl-skeleton,
.dl-photo.is-thumb .dl-skeleton {
  opacity: 0;
  transition: opacity var(--lm-dur) var(--lm-ease);
}

/* lm.css 의 .lm-print__window > img 는 cover 이지만, 고객 사진은 절대 잘리면 안 된다. */
.dl-photo > .dl-img {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0;
  transition:
    opacity .5s var(--lm-ease),
    filter .5s var(--lm-ease),
    transform .5s var(--lm-ease);
}

/* 비율을 알아낸 뒤에는 프레임에 꼭 맞으므로 cover 로 바꿔도 잘리지 않는다. */
.dl-photo.has-ratio > .dl-img {
  object-fit: cover;
}

/* 썸네일은 블러 상태로 먼저 보여 준다. */
.dl-img--thumb {
  filter: blur(14px);
  transform: scale(1.05);
}

.dl-photo.is-thumb .dl-img--thumb {
  opacity: 1;
}

.dl-photo.is-full .dl-img--thumb {
  opacity: 0;
  filter: blur(4px);
}

.dl-photo.is-full .dl-img--full {
  opacity: 1;
}

/* 사진 위 탭 버튼(전체화면) */
.dl-photo__tap {
  position: absolute;
  inset: 0;
  width: 100%;
  min-height: 44px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: zoom-in;
  display: block;
}

.dl-photo__tap[disabled] {
  cursor: default;
}

.dl-photo__zoom {
  position: absolute;
  right: 8px;
  bottom: 8px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 11px;
  border-radius: var(--lm-r-pill);
  font-size: 11.5px;
  font-weight: 700;
  color: var(--lm-text);
  /* iOS 머티리얼 — 사진 위에 얹는 반투명 흰 알약 */
  background: var(--lm-material);
  -webkit-backdrop-filter: var(--lm-material-blur);
  backdrop-filter: var(--lm-material-blur);
  box-shadow: var(--lm-shadow-sm);
  opacity: 0;
  transform: translateY(4px);
  transition: opacity var(--lm-dur) var(--lm-ease), transform var(--lm-dur) var(--lm-ease);
  pointer-events: none;
}

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .dl-photo__zoom {
    background: var(--lm-surface);
  }
}

.dl-photo.is-full .dl-photo__zoom,
.dl-photo.is-thumb .dl-photo__zoom {
  opacity: 1;
  transform: none;
}

.dl-photo__zoom-ico {
  font-size: 12.5px;
}

/* --------------------------------------------------------------------------
   상태 문구
   -------------------------------------------------------------------------- */
.dl-status {
  margin: 0;
  min-height: 18px;
  text-align: center;
  transition: color var(--lm-dur) var(--lm-ease);
}

.dl-status.is-ok {
  color: var(--lm-ok);
}

.dl-status.is-warn {
  color: color-mix(in srgb, var(--lm-warn) 80%, #7a5300);
}

.dl-status.is-danger {
  color: var(--lm-danger);
}

/* --------------------------------------------------------------------------
   액션 버튼 — 저장은 큰 primary 단색, 공유는 ghost
   -------------------------------------------------------------------------- */
.dl-actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--lm-gap-sm);
}

.dl-save {
  position: relative;
  overflow: hidden;
  width: 100%;
  font-weight: 700;
  --dl-progress: 0%;
}

.dl-save[disabled] {
  opacity: .4;
}

/* 진행률은 버튼 안쪽을 채우는 밝은 막대로 표시한다. */
.dl-save__bar {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: var(--dl-progress, 0%);
  background: rgba(255, 255, 255, .28);
  transition: width .2s linear;
  pointer-events: none;
}

.dl-save__label {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
}

.dl-save__ico {
  font-size: 15px;
  transform: translateY(1px);
}

.dl-save.is-busy .dl-save__ico {
  animation: dl-bounce .9s var(--lm-ease) infinite;
}

@keyframes dl-bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(3px); }
}

.dl-save.is-done {
  background: var(--lm-ok);
  color: var(--lm-text-inv);
}

.dl-save.is-done .dl-save__bar {
  width: 100%;
  background: transparent;
}

.dl-share {
  min-width: 96px;
  padding: 12px 18px;
  font-size: 15.5px;
  gap: 6px;
}

.dl-share[disabled] {
  opacity: .4;
}

/* --------------------------------------------------------------------------
   메타 정보 — .lm-list 그룹 목록 (한글 라벨이 잘리지 않는다)
   -------------------------------------------------------------------------- */
.dl-meta:empty {
  display: none;
}

.dl-meta__row {
  /* .lm-list__row 가 레이아웃을 맡는다. dl/dt/dd 기본 여백만 지운다. */
  margin: 0;
}

.dl-meta__key {
  margin: 0;
}

.dl-meta__val {
  margin: 0;
  font-variant-numeric: tabular-nums;
}

/* --------------------------------------------------------------------------
   보관 안내 / iOS 안내 — 한 줄 배지 톤
   -------------------------------------------------------------------------- */
.dl-retention,
.dl-hint {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 0;
  padding: 11px 14px;
  border-radius: var(--lm-r-sm);
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.55;
  background: var(--lm-surface);
  border: 1px solid var(--lm-border);
  color: var(--lm-text-2);
}

.dl-retention.is-warn {
  color: color-mix(in srgb, var(--lm-warn) 80%, #7a5300);
  background: var(--lm-warn-weak);
  border-color: transparent;
}

.dl-retention.is-danger {
  color: var(--lm-danger);
  background: var(--lm-danger-weak);
  border-color: transparent;
}

.dl-hint b {
  color: var(--lm-text);
}

/* --------------------------------------------------------------------------
   썸네일 스트립 — 흰 필름 스트립(.lm-strip--row)
   -------------------------------------------------------------------------- */
.dl-strip {
  display: flex;
  flex-direction: column;
  gap: var(--lm-gap-sm);
}

.dl-strip__title {
  margin: 0 2px;
  font-weight: 700;
}

.dl-strip__track {
  /* .lm-strip--row 가 흰 여백·가로 스크롤을 맡는다. */
  scrollbar-width: none;
}

.dl-strip__track::-webkit-scrollbar {
  display: none;
}

.dl-thumb {
  position: relative;
  flex: 0 0 auto;
  width: 60px;
  height: 76px;
  padding: 0;
  border: 0;
  cursor: pointer;
  background: var(--lm-surface-sunken);
  transition:
    transform var(--lm-dur-fast) var(--lm-ease),
    box-shadow var(--lm-dur) var(--lm-ease);
}

.dl-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  opacity: .58;
  transition: opacity var(--lm-dur) var(--lm-ease);
}

.dl-thumb:active {
  transform: scale(.95);
}

/* 선택 표시는 사진 위에 얹는다(.lm-strip > * 의 overflow:hidden 때문에 inset 그림자는 가려진다). */
.dl-thumb.is-active::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  border: 2.5px solid var(--lm-primary);
  pointer-events: none;
}

.dl-thumb.is-active img {
  opacity: 1;
}

/* --------------------------------------------------------------------------
   오류 / 빈 상태 카드
   -------------------------------------------------------------------------- */
.dl-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--lm-gap-sm);
  padding: 32px 22px 26px;
  text-align: center;
  border-radius: var(--lm-r-lg);
  animation: dl-rise .35s var(--lm-ease) both;
}

.dl-error__ico {
  width: 60px;
  height: 60px;
  display: grid;
  place-items: center;
  border-radius: var(--lm-r-pill);
  font-size: 26px;
  background: var(--lm-surface-2);
  border: 1px solid var(--lm-border);
}

.dl-error__title {
  margin: 4px 0 0;
  font-size: 22px;
  font-weight: 750;
  letter-spacing: -.015em;
}

.dl-error__body {
  margin: 0;
  max-width: 320px;
  font-size: 14.5px;
  line-height: 1.7;
  color: var(--lm-text-2);
  white-space: pre-line;
}

.dl-error__countdown {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--lm-text-3);
  font-variant-numeric: tabular-nums;
}

.dl-error__retry {
  margin-top: 6px;
  padding: 12px 26px;
}

/* --------------------------------------------------------------------------
   홍보 블록 — 맨 아래 흰 카드
   -------------------------------------------------------------------------- */
.dl-promo__card {
  display: flex;
  flex-direction: column;
  gap: var(--lm-gap-sm);
  padding: var(--lm-pad);
  border-radius: var(--lm-r);
  background: var(--lm-surface);
  border: 1px solid var(--lm-border);
  box-shadow: var(--lm-shadow-sm);
}

.dl-promo__tag {
  align-self: flex-start;
  padding: 3px 10px;
  border-radius: var(--lm-r-pill);
  font-size: 11.5px;
  font-weight: 700;
  color: var(--lm-primary);
  background: var(--lm-primary-weak);
}

.dl-promo__title {
  margin: 0;
  font-size: 19px;
  font-weight: 750;
  letter-spacing: -.015em;
}

.dl-promo__body {
  margin: 0;
  font-size: 14.5px;
  line-height: 1.65;
  color: var(--lm-text-2);
  white-space: pre-line;
}

.dl-promo__links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

/* 홍보 버튼은 iOS tinted 버튼 톤. */
.dl-promo__btn {
  flex: 1 1 140px;
  min-height: 44px;
  padding: 10px 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: var(--lm-r-pill);
  font-size: 14.5px;
  font-weight: 650;
  text-decoration: none;
  color: var(--lm-primary);
  background: var(--lm-primary-weak);
  border: 1px solid transparent;
  transition: transform var(--lm-dur-fast) var(--lm-ease), background-color var(--lm-dur) var(--lm-ease);
}

.dl-promo__btn:active {
  transform: scale(.96);
}

.dl-promo__btn--main {
  flex-basis: 100%;
  color: var(--lm-text-inv);
  background: var(--lm-primary);
  box-shadow: var(--lm-shadow-sm);
}

/* --------------------------------------------------------------------------
   푸터
   -------------------------------------------------------------------------- */
.dl-foot {
  margin-top: 2px;
  text-align: center;
}

.dl-foot__line {
  margin: 2px 0;
}

.dl-foot__line--dim {
  letter-spacing: .06em;
}

.dl-foot b {
  color: var(--lm-text-2);
  font-weight: 700;
}

/* --------------------------------------------------------------------------
   자체 라이트박스 (lm.js 의 lightbox 가 동작하지 않을 때만 쓰는 폴백)
   배경도 밝은 반투명으로 — 어두운 오버레이 금지.
   -------------------------------------------------------------------------- */
.dl-lb {
  position: fixed;
  inset: 0;
  z-index: var(--lm-z-lightbox);
  display: grid;
  place-items: center;
  padding: var(--lm-gap);
  background: rgba(246, 244, 240, .92);
  -webkit-backdrop-filter: saturate(160%) blur(18px);
  backdrop-filter: saturate(160%) blur(18px);
  animation: dl-fade .2s var(--lm-ease) both;
  border: 0;
}

@keyframes dl-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

.dl-lb__img {
  max-width: 100%;
  max-height: calc(100dvh - 120px);
  object-fit: contain;
  border-radius: 6px;
  /* 폴백 뷰어에서도 흰 인화지 여백을 유지한다. */
  background: #fff;
  padding: 8px;
  box-shadow: var(--lm-shadow-print);
  animation: dl-zoom-in .26s var(--lm-ease-spring) both;
}

@keyframes dl-zoom-in {
  from { opacity: 0; transform: scale(.96); }
  to { opacity: 1; transform: none; }
}

.dl-lb__close {
  position: absolute;
  top: calc(14px + env(safe-area-inset-top));
  right: 14px;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: var(--lm-r-pill);
  font-size: 17px;
  color: var(--lm-text);
  background: var(--lm-surface);
  border: 1px solid var(--lm-border);
  box-shadow: var(--lm-shadow-sm);
  cursor: pointer;
}

/* --------------------------------------------------------------------------
   넓은 화면 / 접근성 / 모션
   -------------------------------------------------------------------------- */
@media (min-width: 560px) {
  .dl-body {
    padding-top: 36px;
    padding-bottom: 36px;
    align-items: flex-start;
  }

  .dl-thumb {
    width: 66px;
    height: 84px;
  }
}

@media (max-width: 359px) {
  .dl-actions {
    grid-template-columns: 1fr;
  }

  .dl-share {
    min-width: 0;
  }
}

:where(.dl-save, .dl-share, .dl-thumb, .dl-photo__tap, .dl-promo__btn, .dl-error__retry, .dl-lb__close):focus-visible {
  outline: 2px solid var(--lm-primary);
  outline-offset: 2px;
}

.dl-photo__tap:focus-visible {
  outline-offset: -4px;
}

@media (prefers-reduced-motion: reduce) {
  .dl-shell,
  .dl-strip,
  .dl-error,
  .dl-promo,
  .dl-lb,
  .dl-lb__img,
  .dl-save.is-busy .dl-save__ico {
    animation: none !important;
  }

  .dl-img,
  .dl-photo,
  .dl-print,
  .dl-save,
  .dl-thumb,
  .dl-promo__btn {
    transition-duration: .01ms !important;
  }
}
