/*
 * NWNH Sheet Sync: floor plan photo gallery (card thumbnails + lightbox).
 * Loaded only on pages that print a gallery. Plain CSS in the theme's tokens: forest #2F5233,
 * forest-deep #1F3923, cream #F4EFE6, charcoal #1A1F1B, gold #B89A5E, gold-deep #8F7642,
 * mist #E8E5DE; Playfair Display headings, Inter text; 2px radius like the theme's buttons.
 * The theme's Tailwind build is compiled, so nothing here relies on its utility classes.
 */

/* --- On the plan card ------------------------------------------------------------------ */

/* Sits at the bottom of the card body, right above the floor plan link, so the thumbnails line up
   across a row of cards. The note above it already leaves 1.5rem (its mb-6). Hidden unless the
   browser can run the lightbox (see "Shown only where <dialog> works" below). */
.nwnh-gal {
  display: none;
  flex-direction: column;
  gap: 0.75rem;
  margin: auto 0 1.5rem;
  padding-top: 1.25rem;
}
p.mb-6 + .nwnh-gal {
  padding-top: 0;
}
.nwnh-gal:last-child {
  margin-bottom: 0;
}

/* Shown only where <dialog> works, so no browser gets dead buttons. :modal support (every browser
   since 2022) shows it from the first paint, with no jump; older browsers that still have <dialog>
   show it once gallery.js has added html.nwnh-gal-ok. While shown, the gallery takes the free space
   the floor plan link's mt-auto used to; while hidden, the link keeps it. */
@supports selector(:modal) {
  .nwnh-gal {
    display: flex;
  }
  .nwnh-gal + a {
    margin-top: 0;
  }
}
html.nwnh-gal-ok .nwnh-gal {
  display: flex;
}
html.nwnh-gal-ok .nwnh-gal + a {
  margin-top: 0;
}

.nwnh-gal-thumbs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.5rem;
}

.nwnh-gal-thumb,
.nwnh-gal-open {
  -webkit-appearance: none;
  appearance: none;
  margin: 0;
  font: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.nwnh-gal-thumb {
  position: relative;
  display: block;
  width: 100%;
  min-height: 44px;
  aspect-ratio: 4 / 3;
  padding: 0;
  overflow: hidden;
  border: 1px solid #E8E5DE;
  border-radius: 0.125rem;
  background: #F4EFE6;
  cursor: zoom-in;
}
.nwnh-gal-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}
.nwnh-gal-thumb:hover img {
  transform: scale(1.05);
}

.nwnh-gal-open {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.625rem;
  width: 100%;
  min-height: 44px;
  padding: 0.75rem 1rem;
  border: 1px solid #2F5233;
  border-radius: 0.125rem;
  background: transparent;
  color: #2F5233;
  font-family: Inter, system-ui, sans-serif;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  transition: background-color 0.3s cubic-bezier(0.4, 0, 0.2, 1), color 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.nwnh-gal-open:hover {
  background: #2F5233;
  color: #F4EFE6;
}
.nwnh-gal-icon {
  flex: none;
}

.nwnh-gal-thumb:focus-visible,
.nwnh-gal-open:focus-visible {
  outline: 2px solid #8F7642;
  outline-offset: 2px;
}

/* --- Lightbox ---------------------------------------------------------------------------- */

html.nwnh-lb-lock {
  overflow: hidden;
}

.nwnh-lb {
  box-sizing: border-box;
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  overflow: hidden;
  background: rgba(26, 31, 27, 0.97);
  color: #F4EFE6;
  font-family: Inter, system-ui, sans-serif;
}
.nwnh-lb[open] {
  display: flex;
  flex-direction: column;
  animation: nwnh-lb-fade 0.2s ease-out;
}
.nwnh-lb::backdrop {
  background: rgba(26, 31, 27, 0.9);
}
.nwnh-lb *,
.nwnh-lb *::before,
.nwnh-lb *::after {
  box-sizing: border-box;
}

.nwnh-lb-bar {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: max(0.75rem, env(safe-area-inset-top)) max(0.75rem, env(safe-area-inset-right)) 0.75rem max(1rem, env(safe-area-inset-left));
}
.nwnh-lb-head {
  min-width: 0;
}
.nwnh-lb-title {
  margin: 0;
  overflow: hidden;
  color: #F4EFE6;
  font-family: "Playfair Display", Georgia, serif;
  font-size: 1.25rem;
  font-weight: 500;
  line-height: 1.25;
  letter-spacing: -0.01em;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.nwnh-lb-count {
  margin: 0.25rem 0 0;
  color: #B89A5E;
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0.25em;
  font-variant-numeric: tabular-nums;
}

.nwnh-lb-btn {
  -webkit-appearance: none;
  appearance: none;
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  margin: 0;
  padding: 0;
  border: 1px solid rgba(244, 239, 230, 0.22);
  border-radius: 9999px;
  background: rgba(26, 31, 27, 0.6);
  color: #F4EFE6;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}
.nwnh-lb-btn:hover {
  border-color: #2F5233;
  background: #2F5233;
}
.nwnh-lb-btn:focus-visible {
  outline: 2px solid #B89A5E;
  outline-offset: 2px;
}
.nwnh-lb-btn[hidden] {
  display: none;
}

.nwnh-lb-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  touch-action: pan-y pinch-zoom; /* horizontal swipes are ours */
}
.nwnh-lb-slides {
  position: absolute;
  inset: 0 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
/* Sized to the photo, so the dark letterbox around it is the slides element (a click there closes). */
.nwnh-lb-img {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  min-width: 0;
  min-height: 0;
  border-radius: 0.125rem;
  -webkit-user-select: none;
  user-select: none;
  animation: nwnh-lb-fade 0.25s ease-out;
}
.nwnh-lb-img[hidden] {
  display: none;
}
.nwnh-lb-prev,
.nwnh-lb-next {
  position: absolute;
  top: 50%;
  z-index: 1;
  transform: translateY(-50%);
}
.nwnh-lb-prev {
  left: max(0.75rem, env(safe-area-inset-left));
}
.nwnh-lb-next {
  right: max(0.75rem, env(safe-area-inset-right));
}

.nwnh-lb-caption {
  flex: none;
  max-width: 40rem;
  margin: 0 auto;
  padding: 0.875rem 1.25rem max(1rem, env(safe-area-inset-bottom));
  color: rgba(244, 239, 230, 0.78);
  font-size: 0.8125rem;
  line-height: 1.5;
  text-align: center;
}

.nwnh-lb-status {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@keyframes nwnh-lb-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

@media (min-width: 768px) {
  .nwnh-lb-bar {
    padding: 1.25rem 1.5rem 1rem 2rem;
  }
  .nwnh-lb-head {
    display: flex;
    align-items: baseline;
    gap: 1.25rem;
  }
  .nwnh-lb-title {
    font-size: 1.5rem;
  }
  .nwnh-lb-count {
    margin: 0;
  }
  .nwnh-lb-btn {
    width: 48px;
    height: 48px;
  }
  .nwnh-lb-slides {
    inset: 0 6rem;
  }
  .nwnh-lb-prev {
    left: 1.5rem;
  }
  .nwnh-lb-next {
    right: 1.5rem;
  }
  .nwnh-lb-caption {
    padding: 1rem 2rem 1.5rem;
    font-size: 0.875rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .nwnh-gal-thumb img,
  .nwnh-gal-open,
  .nwnh-lb-btn {
    transition: none;
  }
  .nwnh-gal-thumb:hover img {
    transform: none;
  }
  .nwnh-lb[open],
  .nwnh-lb-img {
    animation: none;
  }
}
