/* Shared project-gallery styles — the approved horizontal photo scroller
   (arrows, seamless loop, thumbnail strip) used by every project gallery.
   Selectors are prefixed with `body .hscroll-wrap` so they outrank the
   per-page gallery CSS (e.g. body.<page>-page .project-photo.gallery-item)
   that these scroller slides must override. */

/* Existing-conditions ("Before") galleries: keep the Before badge on the
   top-right corner of each photo, matching the approved before-gallery style. */
body .hscroll-wrap .hscroll-gallery :is(.photo-badge--before, .kp-badge--before, .fb-badge--before) {
  left: auto !important;
  right: 0.75rem !important;
}

/* Finished-photo gallery: a horizontal scroller that keeps every photo's
   natural proportions — landscape and portrait photos sit side by side
   at full height with no cropping, stretching, or forced frames. */
.hscroll-wrap { position: relative; border-radius: 14px; overflow: hidden; }
body .hscroll-wrap .hscroll-gallery {
  display: flex;
  align-items: stretch;
  gap: var(--project-gap, 18px);
  overflow-x: auto;
  padding: 2px 2px 2px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
body .hscroll-wrap .hscroll-gallery::-webkit-scrollbar { display: none; }
body .hscroll-wrap .hscroll-gallery :is(.project-photo, .fb-photo, .kp-photo).gallery-item {
  flex: 0 0 auto;
  width: auto !important;
  min-width: 0 !important;
  height: clamp(320px, 52vh, 540px) !important;
  min-height: 0 !important;
  max-width: none !important;
  aspect-ratio: 2 / 3;
  border-radius: 14px;
  overflow: hidden;
}
/* Loop clones match the real slides exactly: same frame, same 14px corners. */
body .hscroll-wrap .hscroll-gallery :is(.project-photo, .fb-photo, .kp-photo).gallery-item-clone {
  flex: 0 0 auto;
  width: auto !important;
  min-width: 0 !important;
  height: clamp(320px, 52vh, 540px) !important;
  min-height: 0 !important;
  max-width: none !important;
  border-radius: 14px;
  overflow: hidden;
}
body .hscroll-wrap .hscroll-gallery :is(.project-photo, .fb-photo, .kp-photo).gallery-item .project-photo-block,
body .hscroll-wrap .hscroll-gallery :is(.project-photo, .fb-photo, .kp-photo).gallery-item-clone .project-photo-block {
  height: 100% !important;
  width: 100% !important;
  max-width: none !important;
  min-width: 0 !important;
}
body .hscroll-wrap .hscroll-gallery :is(.photo-media, .fb-photo-media, .kp-photo-media) {
  height: 100% !important;
  width: 100% !important;
  aspect-ratio: auto !important;
  border-radius: 14px;
}
body .hscroll-wrap .hscroll-gallery :is(.photo-media, .fb-photo-media, .kp-photo-media) img {
  width: 100% !important;
  height: 100% !important;
  max-width: none !important;
  /* Fit, never crop: landscape and portrait photos both scale down to sit
     fully inside the frame on every device. Letterbox areas stay white. */
  object-fit: contain !important;
  object-position: center;
  background: #ffffff;
}
body .hscroll-wrap .hscroll-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  padding: 0 0 3px;
  border: 1px solid rgba(23, 24, 21, 0.14);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.78);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  color: #171815;
  font-size: 1.7rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 8px 22px rgba(23, 24, 21, 0.16);
  transition: background 0.2s ease, opacity 0.2s ease;
}
body .hscroll-wrap .hscroll-arrow:hover { background: rgba(255, 255, 255, 0.95); }
body .hscroll-wrap .hscroll-arrow--prev { left: 14px; }
body .hscroll-wrap .hscroll-arrow--next { right: 14px; }
body .hscroll-wrap .hscroll-arrow[disabled] { opacity: 0.35; cursor: default; }
/* Thumbnail navigation strip below the main gallery: one small photo per
   gallery image; the photo currently in view is highlighted. */
.hscroll-thumbs {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 14px;
  padding: 0;
}
.hscroll-thumb {
  flex: 0 0 auto;
  width: 64px;
  height: 64px;
  padding: 0;
  border: 2px solid rgba(23, 24, 21, 0.14);
  border-radius: 10px;
  background: #ded8ce;
  opacity: 0.65;
  cursor: pointer;
  overflow: hidden;
  transition: opacity 0.2s ease, border-color 0.2s ease;
}
.hscroll-thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
.hscroll-thumb:hover { opacity: 1; }
.hscroll-thumb.is-active {
  opacity: 1;
  border-color: #1b3a5c;
}
.hscroll-thumb:focus-visible { outline: 3px solid rgba(14, 110, 107, 0.35); outline-offset: 2px; }
@media (max-width: 640px) {
  .hscroll-thumb { width: 52px; height: 52px; }
  body .hscroll-wrap .hscroll-gallery :is(.photo-title, .fb-photo-title, .kp-photo-title) {
    max-width: 100% !important;
    white-space: normal;
    overflow-wrap: anywhere;
  }
  body .hscroll-wrap .hscroll-gallery :is(.photo-title, .fb-photo-title, .kp-photo-title) strong {
    white-space: normal;
    overflow-wrap: anywhere;
  }
  body .hscroll-wrap .hscroll-arrow { width: 40px; height: 40px; font-size: 1.4rem; }
  body .hscroll-wrap .hscroll-arrow--prev { left: 8px; }
  body .hscroll-wrap .hscroll-arrow--next { right: 8px; }
}

/* Phones and small tablets: the gallery keeps the original
   one-image-at-a-time horizontal carousel — a horizontal track, one
   slide at 100% of the available container width, and visible,
   tappable previous/next arrows that page through the gallery one
   photo at a time (the script's seamless loop and wrap-around logic
   work unchanged). Each slide and its inner media wrappers stay at
   width:100% / max-width:100% / min-width:0; images stay fully
   contained with width:100% and height:auto (object-fit: contain,
   letterbox areas white), and captions wrap inside their slide.
   The wrap clips its own track, so the carousel never extends past
   the 25.392px content gutter and never creates page-level horizontal
   scrolling. The thumbnail strip stays hidden on phones; the arrows
   are the paging controls. */
@media (max-width: 780px) {
  body .hscroll-wrap {
    overflow: hidden;
    border-radius: 14px;
  }
  body .hscroll-wrap .hscroll-gallery {
    display: flex !important;
    align-items: stretch;
    overflow-x: auto !important;
    gap: 0;
    padding: 0;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
  }
  body .hscroll-wrap .hscroll-gallery :is(.project-photo, .fb-photo, .kp-photo).gallery-item,
  body .hscroll-wrap .hscroll-gallery :is(.project-photo, .fb-photo, .kp-photo).gallery-item-clone {
    flex: 0 0 100% !important;
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    height: auto !important;
    min-height: 0 !important;
    margin: 0 !important;
    aspect-ratio: auto !important;
    scroll-snap-align: center;
    overflow: hidden;
    border-radius: 14px;
  }
  .hscroll-thumbs { display: none !important; }
  body .hscroll-wrap .hscroll-gallery :is(.photo-media, .fb-photo-media, .kp-photo-media) {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    height: auto !important;
    aspect-ratio: auto !important;
    background: #ffffff;
  }
  /* Fit, never crop on phones: object-fit: contain sits directly on the
     image (width 100%, height auto), so portrait and landscape photos
     alike stay 100% visible with no edge cropped and no stretched
     background. The script's inline aspect-ratio sizes the slide frame
     to the photo's real proportions. */
  body .hscroll-wrap .hscroll-gallery :is(.photo-media, .fb-photo-media, .kp-photo-media) img {
    display: block;
    object-fit: contain !important;
    object-position: center !important;
    width: 100% !important;
    height: auto !important;
    max-width: 100% !important;
    max-height: none !important;
    background: #ffffff;
  }
  body .hscroll-wrap .hscroll-gallery :is(.photo-title, .fb-photo-title, .kp-photo-title) {
    max-width: 100% !important;
    white-space: normal;
    overflow-wrap: anywhere;
  }
  /* Arrows stay visible and tappable on phones — they page the carousel
     one photo at a time and sit inside the clipped wrap, over the photo. */
  body .hscroll-wrap .hscroll-arrow { display: flex !important; }
}

/* Phone stacked slider: when project-gallery.js adds .phone-stack (phones
   only), the track stops scrolling and shows exactly ONE slide at a time.
   Every other slide and all loop clones are removed from the layout with
   display:none, so no off-screen photo, badge, or caption can ever extend
   past the screen edge. Desktop (> 780px) never receives .phone-stack. */
@media (max-width: 780px) {
  body .hscroll-wrap .hscroll-gallery.phone-stack {
    display: block !important;
    overflow: hidden !important;
    scroll-snap-type: none;
  }
  body .hscroll-wrap .hscroll-gallery.phone-stack .gallery-item,
  body .hscroll-wrap .hscroll-gallery.phone-stack .gallery-item-clone {
    display: none !important;
  }
  body .hscroll-wrap .hscroll-gallery.phone-stack :is(.project-photo, .fb-photo, .kp-photo).gallery-item,
  body .hscroll-wrap .hscroll-gallery.phone-stack :is(.project-photo, .fb-photo, .kp-photo).gallery-item-clone {
    display: none !important;
  }
  body .hscroll-wrap .hscroll-gallery.phone-stack .gallery-item.is-phone-active,
  body .hscroll-wrap .hscroll-gallery.phone-stack :is(.project-photo, .fb-photo, .kp-photo).gallery-item.is-phone-active {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
  }
}

/* Pre-enhancement safety net (phones): before project-gallery.js wraps a
   [data-hscroll-gallery] container, it is a plain block — force every raw
   figure to a single full-width column with contained images so the raw
   markup can never run past the screen edge. Once the script adds the
   .hscroll-gallery class these rules stop applying and the slider above
   takes over. */
@media (max-width: 780px) {
  [data-hscroll-gallery]:not(.hscroll-gallery) {
    display: block;
    width: 100%;
    max-width: 100%;
    overflow: hidden;
  }
  [data-hscroll-gallery]:not(.hscroll-gallery) > .gallery-item {
    display: block;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    height: auto !important;
    min-height: 0 !important;
    aspect-ratio: auto !important;
    margin: 0 0 18px;
  }
  [data-hscroll-gallery]:not(.hscroll-gallery) .gallery-item:last-child {
    margin-bottom: 0;
  }
  [data-hscroll-gallery]:not(.hscroll-gallery) :is(.photo-media, .fb-photo-media, .kp-photo-media) {
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    aspect-ratio: auto !important;
  }
  [data-hscroll-gallery]:not(.hscroll-gallery) :is(.photo-media, .fb-photo-media, .kp-photo-media) img {
    display: block;
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    object-fit: contain !important;
    background: #ffffff;
  }
  [data-hscroll-gallery]:not(.hscroll-gallery) :is(.photo-title, .fb-photo-title, .kp-photo-title) {
    max-width: 100% !important;
    white-space: normal;
    overflow-wrap: anywhere;
  }
}

/* Fit, never crop — every device: gallery photos scale down to sit fully
   inside their frame (landscape and portrait alike). This rule outranks the
   page-level cover rules (e.g. summary-grid, before-slideshow frames) so no
   gallery photo is ever cropped on phone, tablet, or desktop. Letterbox
   areas stay white. */
body .hscroll-wrap .hscroll-gallery :is(.project-photo, .fb-photo, .kp-photo):is(.gallery-item, .gallery-item-clone) :is(.photo-media, .fb-photo-media, .kp-photo-media) img {
  object-fit: contain !important;
  object-position: center !important;
  background: #ffffff !important;
}

/* ===== Center-stage focus =====
   The centered photo is fully clear and bright; the previous/next side
   previews (and the loop clones at the edges) sit behind a subtle dark veil
   so the eye stays on the active photo. Desktop only — below 781px the
   scroller stacks vertically and every photo shows at full strength. */
@media (min-width: 781px) {
  body .hscroll-wrap .hscroll-gallery :is(.project-photo, .fb-photo, .kp-photo).gallery-item,
  body .hscroll-wrap .hscroll-gallery :is(.project-photo, .fb-photo, .kp-photo).gallery-item-clone {
    opacity: 0.55;
    filter: saturate(0.85) brightness(0.82);
    transition: opacity 0.45s ease, filter 0.45s ease;
  }
  body .hscroll-wrap .hscroll-gallery :is(.photo-media, .fb-photo-media, .kp-photo-media) {
    position: relative;
  }
  body .hscroll-wrap .hscroll-gallery :is(.project-photo, .fb-photo, .kp-photo) :is(.photo-media, .fb-photo-media, .kp-photo-media)::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: rgba(9, 11, 10, 0.28);
    pointer-events: none;
    transition: opacity 0.45s ease;
  }
  body .hscroll-wrap .hscroll-gallery :is(.project-photo, .fb-photo, .kp-photo).gallery-item.is-center {
    opacity: 1;
    filter: none;
  }
  body .hscroll-wrap .hscroll-gallery :is(.project-photo, .fb-photo, .kp-photo).gallery-item.is-center :is(.photo-media, .fb-photo-media, .kp-photo-media)::after {
    opacity: 0;
  }
}

/* ============================================================
   MOBILE-ONLY LAYOUT PASS (max-width: 780px) — FINAL CASCADE WORD
   This file loads last on every project page, so this block is the
   final word in the cascade on phones and small tablets. Desktop
   (>780px) is untouched.
   ============================================================ */
@media (max-width: 780px) {
  /* --- 1. Final mobile gutter: 25.392px per side --- */
  body {
    --skylit-gutter: 25.392px;
  }
  body.project-detail-page {
    --project-polish-gutter: 25.392px;
    --project-story-gutter: 25.392px;
  }
  body:is(.bellevue-full-home-page, .kirkland-full-home-page) {
    --bellevue-gutter: 25.392px;
  }
  body .container,
  body.home-page .container,
  body .nav-container,
  body .hero-content,
  body .page-hero-content {
    padding-left: 25.392px !important;
    padding-right: 25.392px !important;
  }

  /* --- 2. Every image container fits the available content width ---
     Releases fixed/partial mobile widths (330px photo floors, capped
     media frames). Object-fit is NOT changed here, so deliberately
     cropped card thumbnails keep their approved presentation while
     contained gallery and plan images stay fully visible. */
  body.project-detail-page {
    --project-photo-width: 100%;
  }
  body.project-detail-page :is(.project-photo, .fb-photo, .kp-photo, .project-shot, .project-photo-block, .project-natural-photo, .gallery-item, .photo-media, .fb-photo-media, .kp-photo-media, .shot-media, .project-natural-media) {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
  }

  /* --- 3. One full-width active image per mobile slideshow ---
     Replaces the old 82vw / fixed-ratio slide widths so the active
     photo spans the content rail exactly; neighbor slides sit fully
     off-screen inside the track instead of peeking past the edge. */
  body.project-detail-page .luxe-slideshow--carousel,
  body.project-detail-page .luxe-slideshow--carousel.luxe-slideshow--before {
    --bs-img-w: 100% !important;
    --bs-media-w: 100% !important;
    --bs-img-h: auto !important;
  }
  body.project-detail-page .luxe-slideshow--carousel .luxe-slide {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box;
  }
  body.project-detail-page :is(.luxe-slideshow, .luxe-slideshow-track, .luxe-slideshow-viewport, .kp-ss-track, .kp-ss-viewport) {
    overflow-x: hidden;
  }

  /* --- 4. Captions wrap inside their containers --- */
  body :is(figcaption, .photo-title, .fb-photo-title, .kp-photo-title, .photo-caption, .kp-photo-caption, .kp-source-label) {
    max-width: 100% !important;
    white-space: normal !important;
    overflow-wrap: break-word;
  }

  /* --- 5. No horizontal page scrolling on phones --- */
  html,
  body {
    overflow-x: clip;
  }
}

/* Final phone reinforcement (runs last in the file so it wins every
   same-specificity tie): every gallery slide, its media box, and its
   image stay at 100% of the container with contained photos, and the
   wrap clips its own track. This holds even if scripts or page-level
   styles try to give slides a fixed pixel width or height. */
@media (max-width: 780px) {
  body .hscroll-wrap {
    width: 100%;
    max-width: 100%;
    overflow: hidden;
  }
  body .hscroll-wrap .hscroll-gallery {
    width: 100%;
    max-width: 100%;
    overflow-x: auto !important;
  }
  body .hscroll-wrap .hscroll-gallery :is(.project-photo, .fb-photo, .kp-photo) {
    flex: 0 0 100% !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    height: auto !important;
    min-height: 0 !important;
  }
  body .hscroll-wrap .hscroll-gallery :is(.project-photo, .fb-photo, .kp-photo) :is(.photo-media, .fb-photo-media, .kp-photo-media) {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    height: auto !important;
    min-height: 0 !important;
  }
  body .hscroll-wrap .hscroll-gallery :is(.project-photo, .fb-photo, .kp-photo) :is(.photo-media, .fb-photo-media, .kp-photo-media) img {
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    object-fit: contain !important;
  }
  body .hscroll-wrap .hscroll-gallery :is(.photo-badge, .photo-title) {
    max-width: 100%;
  }
}
