/*
 * KHADIS responsive two-column showcase, version 1.0.0
 * Designed for the existing Gutenberg block classes on Homepage #27.
 * Leaves the desktop design, original fonts, and product-page CSS intact.
 * Works even if the earlier stacked mobile experiment has not been removed,
 * although removing that experiment is recommended for maintainability.
 */

/* JS selection controls all image fades once initialization succeeds.
   Inactive images stay in the overlapping grid, so the opacity can animate. */
body .khadis-showcase-shopify-v2.khadis--enhanced > .khadis-stage {
  position: relative !important;
  overflow: hidden !important;
  touch-action: pan-y;
}

body .khadis-showcase-shopify-v2.khadis--enhanced > .khadis-stage > .wp-block-image {
  position: relative;
  grid-column: 1 !important;
  grid-row: 1 !important;
  margin: 0 !important;
  min-width: 0 !important;
  opacity: 0 !important;
  pointer-events: none !important;
  transition: opacity 350ms ease !important;
}

body .khadis-showcase-shopify-v2.khadis--enhanced > .khadis-stage > .wp-block-image.is-selected {
  opacity: 1 !important;
}

body .khadis-showcase-shopify-v2.khadis--enhanced .khadis-watch-trigger h3 a {
  color: inherit !important;
  text-decoration: none !important;
  display: inline-block;
  max-width: 100%;
}

body .khadis-showcase-shopify-v2.khadis--enhanced .khadis-watch-trigger h3 a:focus-visible,
body .khadis-showcase-shopify-v2.khadis--enhanced .khadis-stage-view-link:focus-visible,
body .khadis-showcase-shopify-v2.khadis--enhanced .khadis-stage-control:focus-visible {
  outline: 3px solid #96764b !important;
  outline-offset: 3px;
}

/* The stage link opens the currently displayed watch product page.
   Controls sit above the link so they remain independently operable. */
body .khadis-showcase-shopify-v2.khadis--enhanced > .khadis-stage > .khadis-stage-view-link {
  position: absolute;
  z-index: 10;
  inset: 0;
  display: block;
  cursor: pointer;
  background: transparent;
}

body .khadis-showcase-shopify-v2.khadis--enhanced .khadis-stage-nav {
  position: absolute;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  left: 10px;
  right: 10px;
  bottom: 10px;
  pointer-events: none;
}

body .khadis-showcase-shopify-v2.khadis--enhanced .khadis-stage-control {
  pointer-events: auto;
  width: 44px;
  height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.65);
  border-radius: 50%;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font: 600 24px/1 system-ui, sans-serif;
  color: #111;
  background: rgba(250, 249, 246, 0.90);
  box-shadow: 0 1px 5px rgba(0,0,0,0.1);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

body .khadis-showcase-shopify-v2.khadis--enhanced .khadis-stage-control:hover {
  background: #fff;
}

body .khadis-showcase-shopify-v2.khadis--enhanced .khadis-stage-status {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* Navigational controls are useful for touch devices and smaller windows;
   desktop continues to use the original hover-to-preview interaction. */
@media (min-width: 1025px) and (hover: hover) and (pointer: fine) {
  body .khadis-showcase-shopify-v2.khadis--enhanced .khadis-stage-nav {
    display: none;
  }
}

/* Tablet: preserve headings-left / image-right, but size both tracks safely. */
@media (max-width: 1024px) {
  body .khadis-showcase-shopify-v2 {
    display: grid !important;
    grid-template-columns: minmax(0, 44fr) minmax(0, 56fr) !important;
    grid-template-rows: repeat(4, auto) !important;
    grid-auto-rows: auto !important;
    align-items: stretch !important;
    column-gap: 0 !important;
    row-gap: 0 !important;
    padding: 0 20px 72px !important;
    min-width: 0;
  }

  body .khadis-showcase-shopify-v2 > .khadis-watch-trigger {
    display: flex !important;
    grid-column: 1 !important;
    min-width: 0 !important;
    min-height: 98px !important;
    justify-content: center !important;
    align-items: center !important;
    text-align: center !important;
    padding: 14px 6px !important;
    box-sizing: border-box;
    border-bottom: 1px solid #D9D7D1;
    overflow: visible;
  }

  body .khadis-showcase-shopify-v2 > .khadis-trigger-vanguard { grid-row: 1 !important; }
  body .khadis-showcase-shopify-v2 > .khadis-trigger-chairman { grid-row: 2 !important; }
  body .khadis-showcase-shopify-v2 > .khadis-trigger-architect { grid-row: 3 !important; }
  body .khadis-showcase-shopify-v2 > .khadis-trigger-navigator { grid-row: 4 !important; }

  body .khadis-showcase-shopify-v2 .khadis-watch-trigger h3 {
    width: 100%;
    max-width: 100%;
    margin: 0 0 7px !important;
    font-size: clamp(23px, 3.65vw, 40px) !important;
    line-height: 1.1 !important;
    overflow-wrap: normal;
    word-break: normal;
    text-wrap: balance;
  }

  body .khadis-showcase-shopify-v2 .khadis-watch-trigger p {
    font-size: clamp(9px, 1.15vw, 12px) !important;
    letter-spacing: 0.07em !important;
    line-height: 1.35 !important;
  }

  body .khadis-showcase-shopify-v2 .khadis-watch-trigger:hover h3 {
    transform: none;
  }

  body .khadis-showcase-shopify-v2 > .khadis-stage {
    display: grid !important;  /* Overrides the previous 'display: contents' experiment. */
    grid-column: 2 !important;
    grid-row: 1 / span 4 !important;
    grid-template-columns: minmax(0, 1fr) !important;
    grid-template-rows: minmax(0, 1fr) !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    height: auto !important;
    aspect-ratio: 1 / 1 !important;
    align-self: center !important;
    justify-self: stretch !important;
    overflow: hidden !important;
  }

  body .khadis-showcase-shopify-v2 > .khadis-stage > .wp-block-image {
    display: block !important;
    grid-column: 1 !important;
    grid-row: 1 !important;
    width: 100% !important;
    height: 100% !important;
    min-width: 0 !important;
    margin: 0 !important;
    box-sizing: border-box;
  }

  body .khadis-showcase-shopify-v2 > .khadis-stage > .wp-block-image img {
    display: block !important;
    width: 100% !important;
    height: 100% !important;
    max-width: 100% !important;
    aspect-ratio: 1 / 1 !important;
    object-fit: cover !important;
  }

  body .khadis-showcase-shopify-v2.khadis--enhanced > .khadis-stage > .wp-block-image:not(.is-selected) {
    opacity: 0 !important;
    pointer-events: none !important;
    transition: opacity 350ms ease !important;
  }

  body .khadis-showcase-shopify-v2.khadis--enhanced > .khadis-stage > .wp-block-image.is-selected {
    opacity: 1 !important;
    pointer-events: none !important;
    transition: opacity 350ms ease !important;
  }

  body .khadis-showcase-shopify-v2.khadis--enhanced > .khadis-stage {
    touch-action: pan-y;
  }
}

/* Phone: same composition, smaller labels and a larger image share. */
@media (max-width: 600px) {
  body .khadis-showcase-shopify-v2 {
    grid-template-columns: minmax(0, 45fr) minmax(0, 55fr) !important;
    padding: 0 10px 54px !important;
  }

  body .khadis-showcase-shopify-v2 > .khadis-watch-trigger {
    min-height: 76px !important;
    padding: 9px 4px !important;
  }

  body .khadis-showcase-shopify-v2 .khadis-watch-trigger h3 {
    font-size: clamp(19px, 5.0vw, 27px) !important;
    margin-bottom: 5px !important;
    line-height: 1.13 !important;
    letter-spacing: -0.025em !important;
  }

  body .khadis-showcase-shopify-v2 .khadis-watch-trigger p {
    font-size: clamp(8px, 2.35vw, 10px) !important;
    letter-spacing: 0.045em !important;
  }

  body .khadis-showcase-shopify-v2 .khadis-stage-nav {
    left: 6px;
    right: 6px;
    bottom: 6px;
  }

  body .khadis-showcase-shopify-v2 .khadis-stage-control {
    width: 40px;
    height: 40px;
  }
}

@media (prefers-reduced-motion: reduce) {
  body .khadis-showcase-shopify-v2.khadis--enhanced > .khadis-stage > .wp-block-image,
  body .khadis-showcase-shopify-v2.khadis--enhanced .khadis-watch-trigger h3 {
    transition: none !important;
    animation: none !important;
  }
}
