/*
 * KK-Mall public product gallery, pinch-zoom lightbox, character counter and sticky CTA.
 * Pairs with js/public.js (see the DOM contract at the top of that file).
 * Without JS (no html.kk-js) the gallery is a plain CSS scroll-snap strip and the JS-only
 * controls stay hidden. Design tokens come from base.css; every var() has a fallback.
 */

/* ---------------------------------------------------------------------------------------------
   Gallery
   ------------------------------------------------------------------------------------------- */
.kk-gallery {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr); /* lets the overflowing track shrink to the column */
}

.kk-gallery-track {
  grid-area: 1 / 1;
  position: relative;
  display: flex;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  background: #0c0a09;
  border-radius: calc(var(--kk-radius, 16px) + 4px);
  box-shadow: var(--kk-shadow, 0 1px 3px rgba(232, 120, 110, 0.06), 0 10px 28px rgba(61, 47, 42, 0.05));
  outline: none;
}

.kk-gallery-slide {
  flex: 0 0 100%;
  width: 100%;
  margin: 0;
  aspect-ratio: 3 / 4;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #0c0a09;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  scroll-margin-top: calc(var(--kk-header-h, 0px) + 0.75rem); /* no-JS #slide-k jump lands below the sticky header */
}

.kk-gallery-slide img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
}

/* With JS: hide the native scrollbar (controls take over) and hint that a tap zooms. */
.kk-js .kk-gallery-track { scrollbar-width: none; }
.kk-js .kk-gallery-track::-webkit-scrollbar { display: none; }
.kk-js .kk-gallery-slide img { cursor: zoom-in; }
.kk-gallery-track.is-dragging {
  scroll-snap-type: none;
  cursor: grabbing;
}
.kk-gallery-track.is-dragging img { cursor: grabbing; }

.kk-gallery-track:focus-visible {
  outline: 3px solid var(--kk-focus-ring, #b3443b);
  outline-offset: 3px;
}

/* Prev / next: hidden without JS, >= 44px targets, shown on hover/focus with a mouse and always on touch. */
.kk-gallery-nav { display: none; }

.kk-js .kk-gallery-nav {
  grid-area: 1 / 1;          /* same cell as the track, vertically centred on it */
  align-self: center;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--kk-touch, 44px);
  height: var(--kk-touch, 44px);
  min-width: 44px;
  min-height: 44px;
  margin: 0 0.6rem;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
  color: var(--kk-ink, #3d2f2a);
  font-size: 1.6rem;
  line-height: 1;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s var(--kk-ease, ease), transform 0.15s var(--kk-ease, ease);
}
.kk-js .kk-gallery-prev { justify-self: start; }
.kk-js .kk-gallery-next { justify-self: end; }

.kk-js .kk-gallery:hover .kk-gallery-nav,
.kk-js .kk-gallery:focus-within .kk-gallery-nav { opacity: 1; }

@media (hover: none), (pointer: coarse) {
  .kk-js .kk-gallery-nav { opacity: 0.88; }
}

.kk-js .kk-gallery-nav:hover { transform: scale(1.06); }
.kk-js .kk-gallery-nav:active { transform: scale(0.96); }
.kk-js .kk-gallery-nav:disabled {
  visibility: hidden;        /* not focusable, keeps the grid stable */
  pointer-events: none;
}

.kk-gallery-nav:focus-visible,
.kk-gallery-dot:focus-visible {
  outline: 3px solid var(--kk-focus-ring, #b3443b);
  outline-offset: 2px;
  opacity: 1;
}

/* Dots: 24px hit area (WCAG 2.2 target size), small visual dot inside. */
.kk-gallery-dots { display: none; }
.kk-js .kk-gallery-dots {
  grid-row: 2;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 2px;
  box-sizing: border-box;
  min-height: calc(24px + 0.5rem); /* reserved before JS adds the dot buttons: no layout shift */
  padding-top: 0.5rem;
}

.kk-gallery-dot {
  position: relative;
  width: 24px;
  height: 24px;
  padding: 0;
  border: none;
  border-radius: 12px;
  background: transparent;
  cursor: pointer;
  transition: width 0.2s var(--kk-ease, ease);
}
.kk-gallery-dot::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 8px;
  height: 8px;
  border-radius: 4px;
  background: #8c7f79;        /* 3.9:1 on white (3.7:1 on the page background) */
  transform: translate(-50%, -50%);
  transition: width 0.2s var(--kk-ease, ease), background-color 0.2s;
}
.kk-gallery-dot:hover::before { background: #6b5e58; }
.kk-gallery-dot[aria-current="true"] { width: 32px; }
.kk-gallery-dot[aria-current="true"]::before {
  width: 22px;
  background: var(--kk-cta-bg, #c0493f); /* 4.9:1; the accent #e8786e is only 2.9:1 */
}

/* Counter: only meaningful once JS keeps it in sync. */
.kk-gallery-counter { display: none; }
.kk-js .kk-gallery-counter {
  grid-row: 3;
  display: block;
  margin-top: 0.25rem;
  text-align: center;
  font-size: 0.8rem;
  color: var(--kk-text-secondary, #6b5e58);
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
}

/* Rev 7 B09: thumbnail grid under the gallery; with JS each cell opens the fullscreen viewer at that photo, without
   JS it is a #slide-k link that scrolls the strip to that photo. Cells are at least 56 x 75 px (44px target size). */
.kk-gallery-thumbs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(56px, 1fr));
  gap: 6px;
  list-style: none;
  margin: 0.75rem 0 0;
  padding: 0;
  min-width: 0;
}
.kk-js .kk-gallery-thumbs { grid-row: 4; }
.kk-gallery-thumbs > li { min-width: 0; }
.kk-gallery-thumb {
  display: block;
  width: 100%;
  min-height: 44px;
  aspect-ratio: 3 / 4;
  padding: 0;
  border: 2px solid transparent;
  border-radius: var(--kk-radius-sm, 10px);
  overflow: hidden;
  background: #0c0a09;
  transition: border-color 0.15s;
}
.kk-js .kk-gallery-thumb { cursor: zoom-in; }
.kk-gallery-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
}
.kk-gallery-thumb:hover { border-color: var(--kk-line-strong, rgba(232, 120, 110, 0.22)); }
.kk-gallery-thumb[aria-current="true"] { border-color: var(--kk-cta-bg, #c0493f); }
.kk-gallery-thumb:focus-visible {
  outline: 3px solid var(--kk-focus-ring, #b3443b);
  outline-offset: 2px;
}

.kk-gallery--single .kk-gallery-nav,
.kk-gallery--single .kk-gallery-dots,
.kk-gallery--single .kk-gallery-counter,
.kk-gallery--no-dots .kk-gallery-dots { display: none !important; }
/* Same, derived from the markup so nothing flashes before public.js has run. */
.kk-gallery:not(:has(.kk-gallery-slide + .kk-gallery-slide)) .kk-gallery-nav,
.kk-gallery:not(:has(.kk-gallery-slide + .kk-gallery-slide)) .kk-gallery-dots,
.kk-gallery:not(:has(.kk-gallery-slide + .kk-gallery-slide)) .kk-gallery-counter { display: none !important; }
.kk-gallery:has(.kk-gallery-slide:nth-child(11)) .kk-gallery-dots { display: none !important; }

/* ---------------------------------------------------------------------------------------------
   Lightbox (created by public.js on open)
   ------------------------------------------------------------------------------------------- */
html.kk-lightbox-open,
html.kk-lightbox-open body {
  overflow: hidden;
  overscroll-behavior: none;
}

.kk-lightbox {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(10, 8, 7, 0.96);
  color: #fff;
  touch-action: none;
  overscroll-behavior: contain;
  -webkit-tap-highlight-color: transparent;
  opacity: 0;
  transition: opacity 0.2s var(--kk-ease, ease);
  outline: none;
}
.kk-lightbox.is-open { opacity: 1; }

.kk-lightbox-viewport {
  position: absolute;
  top: env(safe-area-inset-top, 0px);
  right: env(safe-area-inset-right, 0px);
  bottom: env(safe-area-inset-bottom, 0px);
  left: env(safe-area-inset-left, 0px);
  overflow: hidden;
  touch-action: none;
  cursor: zoom-in;
}
.kk-lightbox.is-zoomed .kk-lightbox-viewport { cursor: grab; }
.kk-lightbox.is-panning .kk-lightbox-viewport { cursor: grabbing; }

.kk-lightbox-img {
  position: absolute;
  top: 50%;
  left: 50%;
  max-width: none;
  max-height: none;
  transform-origin: 50% 50%;
  will-change: transform;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
  pointer-events: none;      /* gestures are handled on the viewport */
}
.kk-lightbox.is-animating .kk-lightbox-img {
  transition: transform 0.22s var(--kk-ease, cubic-bezier(0.22, 1, 0.36, 1));
}
.kk-lightbox.is-error .kk-lightbox-img,
.kk-lightbox.is-loading .kk-lightbox-img { visibility: hidden; }

.kk-lightbox-spinner {
  display: none;
  position: absolute;
  top: 50%;
  left: 50%;
  width: 36px;
  height: 36px;
  margin: -18px 0 0 -18px;
  border: 3px solid rgba(255, 255, 255, 0.25);
  border-top-color: #fff;
  border-radius: 50%;
  animation: kk-spin 0.8s linear infinite;
}
.kk-lightbox.is-loading .kk-lightbox-spinner { display: block; }

.kk-lightbox-error {
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  margin: 0;
  padding: 0 1rem;
  transform: translateY(-50%);
  text-align: center;
  font-size: 0.95rem;
  color: rgba(255, 255, 255, 0.85);
}

@keyframes kk-spin { to { transform: rotate(360deg); } }

.kk-lightbox-top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding:
    calc(env(safe-area-inset-top, 0px) + 0.5rem)
    calc(env(safe-area-inset-right, 0px) + 0.5rem)
    1.25rem
    calc(env(safe-area-inset-left, 0px) + 1rem);
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.55), rgba(0, 0, 0, 0));
  pointer-events: none;
}
.kk-lightbox-top > * { pointer-events: auto; }

.kk-lightbox-counter {
  font-size: 0.9rem;
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
  color: rgba(255, 255, 255, 0.9);
}

.kk-lightbox-tools {
  display: flex;
  gap: 0.5rem;
  margin-left: auto;
}

.kk-lightbox-btn,
.kk-lightbox-nav {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  width: var(--kk-touch, 44px);
  height: var(--kk-touch, 44px);
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  transition: background-color 0.15s, opacity 0.15s;
}
.kk-lightbox-btn:hover,
.kk-lightbox-nav:hover { background: rgba(255, 255, 255, 0.26); }
.kk-lightbox-btn:disabled { opacity: 0.35; cursor: default; }
.kk-lightbox-btn:focus-visible,
.kk-lightbox-nav:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 2px;
}

.kk-lightbox-nav {
  position: absolute;
  top: 50%;
  width: 48px;
  height: 48px;
  margin-top: -24px;
  font-size: 2rem;
  background: rgba(0, 0, 0, 0.35);
}
.kk-lightbox-prev { left: calc(env(safe-area-inset-left, 0px) + 0.5rem); }
.kk-lightbox-next { right: calc(env(safe-area-inset-right, 0px) + 0.5rem); }
.kk-lightbox-nav:disabled { visibility: hidden; }
.kk-lightbox-nav[hidden],
.kk-lightbox-counter[hidden] { display: none; }
/* While zoomed the arrows would cover the photo; keyboard (+ / - / 0) and buttons still work. */
.kk-lightbox.is-zoomed .kk-lightbox-nav { opacity: 0; pointer-events: none; }
.kk-lightbox.is-zoomed .kk-lightbox-nav:focus-visible { opacity: 1; pointer-events: auto; }

.kk-sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* ---------------------------------------------------------------------------------------------
   Character counter output ([data-kk-count] target)
   ------------------------------------------------------------------------------------------- */
.kk-count--near { color: #8a5a12; }                   /* 5.9:1 on white, 5.6:1 on #fff8f5 */
.kk-count--full { color: #b3261e; font-weight: 600; } /* 6.5:1 on white, 6.2:1 on #fff8f5 */

/* ---------------------------------------------------------------------------------------------
   Sticky 문의하기 CTA (mobile only)
   ------------------------------------------------------------------------------------------- */
.kk-sticky-cta { display: none; }

@media (max-width: 767.98px) {
  .kk-sticky-cta {
    position: fixed;
    left: calc(env(safe-area-inset-left, 0px) + 12px);
    right: calc(env(safe-area-inset-right, 0px) + 12px);
    bottom: calc(env(safe-area-inset-bottom, 0px) + 12px);
    z-index: 1030;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 52px;
    padding: 0 1.25rem;
    border-radius: var(--kk-radius-pill, 999px);
    background: var(--kk-cta-bg, #c0493f); /* 4.9:1 with white text (accent #e8786e is only 2.9:1) */
    color: #fff;
    font-weight: 700;
    font-size: 1rem;
    text-decoration: none;
    box-shadow: 0 8px 24px rgba(61, 47, 42, 0.22);
    transition: transform 0.25s var(--kk-ease, ease), opacity 0.25s var(--kk-ease, ease), visibility 0s linear 0s;
  }
  .kk-sticky-cta:hover,
  .kk-sticky-cta:focus { color: #fff; }
  .kk-sticky-cta:focus-visible {
    outline: 3px solid var(--kk-ink, #3d2f2a);
    outline-offset: 3px;
  }
  .kk-sticky-cta.is-hidden {
    transform: translateY(calc(100% + 24px));
    opacity: 0;
    visibility: hidden;      /* also removes it from the tab order */
    pointer-events: none;
    transition: transform 0.25s var(--kk-ease, ease), opacity 0.25s var(--kk-ease, ease), visibility 0s linear 0.25s;
  }
  /* Soft keyboard open on a form field: get out of the way. */
  body:has(input:focus, textarea:focus, select:focus) .kk-sticky-cta {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
  }
  /* Without JS the CTA never hides, so keep the end of the page reachable. */
  html:not(.kk-js) body:has(.kk-sticky-cta) {
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 76px);
  }
}

/* ---------------------------------------------------------------------------------------------
   Reduced motion
   ------------------------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  html,
  .kk-gallery-track { scroll-behavior: auto; }
  .kk-gallery-nav,
  .kk-gallery-dot,
  .kk-gallery-dot::before,
  .kk-gallery-thumb,
  .kk-lightbox,
  .kk-lightbox.is-animating .kk-lightbox-img,
  .kk-lightbox-btn,
  .kk-lightbox-nav,
  .kk-sticky-cta,
  .kk-sticky-cta.is-hidden {
    transition: none !important;
  }
  .kk-lightbox-spinner { animation-duration: 2.4s; }
}
