/* ============================================================
   BBP Gallery — Phone Frame Gallery + Fullscreen Popup
   ============================================================ */

/* --- Gallery Grid --- */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 28px;
  padding: 24px 0 40px;
  justify-items: center;
}

.gallery-grid.gallery-collapsed {
  grid-template-columns: repeat(3, auto);
  justify-content: center;
  gap: 60px;
}

/* --- Individual Gallery Item --- */
.gallery-item {
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  /* perspective lets the child tilt in 3D on hover */
  perspective: 600px;
}

.gallery-item:active .phone-wrapper {
  transform: scale(0.96);
}

/* --- Phone Wrapper (transparent — image has its own frame) --- */
.phone-wrapper {
  position: relative;
  display: block;
  flex-shrink: 0;
  /* Static base shadow — cheap, never animated */
  filter:
    drop-shadow(0 2px  6px  rgba(0,0,0,0.12))
    drop-shadow(0 8px  24px rgba(0,0,0,0.18))
    drop-shadow(0 20px 48px rgba(0,0,0,0.14));
  border-radius: 12px; /* just enough to soften the shadow edges */
  transition: transform 0.35s cubic-bezier(0.34, 1.4, 0.64, 1);
  will-change: transform;
}

/* Faster, non-spring transition while a pointer is actively tilting it */
.phone-wrapper.tilting {
  transition: transform 0.12s ease-out;
}

/* Hover shadow lives on a pseudo-element behind the image so only
   `opacity` is animated on hover — no per-frame filter recompute. A
   slightly inset rounded rect approximates the phone silhouette
   (the PNGs have transparent bezel margins around the device). */
.phone-wrapper::after {
  content: "";
  position: absolute;
  inset: 10px;
  border-radius: 28px;
  z-index: -1;
  opacity: 0;
  box-shadow:
    0 16px 40px rgba(0,0,0,0.20),
    0 36px 72px rgba(0,0,0,0.18),
    0 60px 100px rgba(0,0,0,0.12);
  transition: opacity 0.35s ease;
  pointer-events: none;
}

.gallery-item:hover .phone-wrapper {
  transform: translateY(-8px) rotateX(4deg) rotateY(-3deg) scale(1.04);
}

.gallery-item:hover .phone-wrapper::after {
  opacity: 1;
}

.phone-wrapper img {
  display: block;
  width: 140px;   /* set your preferred thumbnail width */
  height: auto;
  border-radius: 12px; /* match wrapper so shadow clips cleanly */
}

/* --- Item Label --- */
.gallery-item-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary, #888);
  text-align: center;
  max-width: 140px;
  line-height: 1.3;
}

/* --- Scroll-reveal (IntersectionObserver-driven, one-shot) --- */
.gallery-reveal-item {
  transition: opacity 0.5s ease, transform 0.5s cubic-bezier(0.34, 1.4, 0.64, 1);
}

.gallery-reveal-hidden {
  opacity: 0;
  transform: translateY(18px);
}

/* --- Stack Card --- */
.gallery-stack-card {
  position: relative;
  width: 140px;
  height: 290px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.25s ease;

  padding-bottom: 36px;

}

.gallery-stack-card:hover {
  transform: translateY(-6px) scale(1.03);
}

.gallery-stack-card:active {
  transform: scale(0.97);
}

.gallery-stack-img {
  position: absolute;
  width: 140px;
  border-radius: 4px;
  filter: drop-shadow(0 4px 12px rgba(0,0,0,0.18));
  transition: transform 0.3s ease;

  align-self: start;
  overflow: visible;
}

/* Fan the three images out */
.gallery-stack-img--0 {
  transform: rotate(-8deg) translateY(6px);
  z-index: 1;
}
.gallery-stack-img--1 {
  transform: rotate(0deg);
  z-index: 2;
}
.gallery-stack-img--2 {
  transform: rotate(8deg) translateY(6px);
  z-index: 1;
}

.gallery-stack-card:hover .gallery-stack-img--0 {
  transform: rotate(-12deg) translateX(-8px) translateY(4px);
}
.gallery-stack-card:hover .gallery-stack-img--2 {
  transform: rotate(12deg) translateX(8px) translateY(4px);
}

/* Count badge */
.gallery-stack-badge {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  font-size: 13px;
  font-weight: 700;
  color: var(--text-color-secondary, #888);
  background: rgba(128,128,128,0.12);
  padding: 3px 10px;
  border-radius: 99px;
  white-space: nowrap;
  z-index: 10;
}

/* --- Show Less Button --- */
.gallery-show-less-btn {
  position: absolute;
  top: -8px;
  right: 0;

  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 14px;
  border: none;
  border-radius: 99px;
  background: rgba(128,128,128,0.12);
  color: var(--text-color-secondary, #888);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.3s ease, background 0.2s ease, transform 0.2s ease;
}

.gallery-show-less-btn:hover {
  background: rgba(128,128,128,0.22);
  transform: scale(1.05);
}

.gallery-show-less-icon {
  font-family: 'Material Symbols Outlined';
  font-size: 16px;
  line-height: 1;
}


/* ============================================================
   Fullscreen Popup / Modal
   ============================================================ */

.gallery-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  opacity: 0;
  /* Entry timing — exit gets its own faster, non-bouncy timing below */
  transition: opacity 0.35s ease;
}

.gallery-overlay.is-open {
  pointer-events: all;
  opacity: 1;
}

/* Exit: faster, no overshoot (iOS sheet dismiss curve) */
.gallery-overlay.is-closing {
  transition: opacity 0.2s cubic-bezier(0.32, 0.72, 0, 1);
}

/* Backdrop */
.gallery-overlay-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 10, 12, 0.72);
  backdrop-filter: blur(18px) saturate(0.7);
  -webkit-backdrop-filter: blur(18px) saturate(0.7);
  cursor: pointer;
}

@media (prefers-color-scheme: light) {
  .gallery-overlay-backdrop {
    background: rgba(200, 200, 210, 0.72);
  }
}

/* Modal Card */
.gallery-modal {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 56px;
  width: min(92vw, 900px);
  height: 620px;
  box-sizing: border-box;
  padding: 48px;
  border-radius: 28px;
  background: var(--popup-background);
  border: 1px solid rgba(128,128,128,0.15);
  box-shadow:
    0 8px 24px rgba(0,0,0,0.12),
    0 24px 64px rgba(0,0,0,0.18),
    0 48px 120px rgba(0,0,0,0.22);
}

@media (prefers-color-scheme: dark) {
  .gallery-modal {
    box-shadow:
      0 8px 24px rgba(0,0,0,0.30),
      0 24px 64px rgba(0,0,0,0.40),
      0 48px 120px rgba(0,0,0,0.50);
  }
}

/* Entry animation — bouncy "pop", reserved for the open moment.
   Used as a fallback when a FLIP morph isn't possible (item hidden in
   the collapsed stack, or reduced-motion). */
.gallery-modal {
  transform: scale(0.88) translateY(24px);
  opacity: 0;
  transition:
    transform 0.45s cubic-bezier(0.34, 1.4, 0.64, 1),
    opacity 0.35s ease;
}

.gallery-overlay.is-open .gallery-modal {
  transform: scale(1) translateY(0);
  opacity: 1;
}

/* Exit for the fallback (non-FLIP) path — fast, no overshoot */
.gallery-overlay.is-closing .gallery-modal {
  transition:
    transform 0.2s cubic-bezier(0.32, 0.72, 0, 1),
    opacity 0.2s cubic-bezier(0.32, 0.72, 0, 1);
}

/* FLIP-morph path: the modal box itself only fades — the "pop" motion
   is carried by the flying ghost image (see JS), not the whole card. */
.gallery-modal.no-pop {
  transform: none;
  opacity: 0;
  transition: opacity 0.28s ease-out;
}

.gallery-overlay.is-open .gallery-modal.no-pop {
  transform: none;
  opacity: 1;
}

.gallery-overlay.is-closing .gallery-modal.no-pop {
  transition: opacity 0.2s cubic-bezier(0.32, 0.72, 0, 1);
}

/* Floating "ghost" image used to morph a thumbnail into the modal
   image position and back (FLIP). Lives outside the modal, in
   document.body, positioned `fixed`. */
.gallery-morph-ghost {
  position: fixed;
  object-fit: cover;
  margin: 0;
  z-index: 10000;
  pointer-events: none;
  will-change: transform;
  box-shadow: 0 20px 60px rgba(0,0,0,0.30);
}

/* Close button */
.gallery-close-btn {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 36px;
  height: 36px;
  border: none;
  background: rgba(128,128,128,0.15);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-color-primary);
  font-size: 20px;
  font-family: 'Material Symbols Outlined', sans-serif;
  transition: background 0.2s, transform 0.2s;
  line-height: 1;
}

.gallery-close-btn:hover {
  background: rgba(128,128,128,0.28);
  transform: scale(1.1);
}

/* Phone in modal — bigger, no bezel chrome */
.gallery-modal .phone-wrapper {
  flex-shrink: 0;
  filter:
    drop-shadow(0 4px  12px rgba(0,0,0,0.20))
    drop-shadow(0 20px 60px rgba(0,0,0,0.30))
    drop-shadow(0 48px 100px rgba(0,0,0,0.22));
  transform: none;
  transition: none;
}

/* Height-based sizing (not width-based) keeps every mockup the same
   visual height regardless of its native aspect ratio, which is what
   keeps the modal's own height perfectly stable across navigation. */
.gallery-modal .phone-wrapper img {
  height: 516px;
  width: auto;
  max-width: 100%;
}

/* Text side */
.gallery-modal-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-width: 0;
  height: 100%;
  min-height: 0;
  gap: 0;
}

.gallery-modal-text-top {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  flex: 1 1 auto;
  overflow: hidden;
  will-change: transform, opacity, filter;
}

.gallery-modal-title {
  font-size: 26px;
  font-weight: 700;
  color: var(--text-color-primary);
  line-height: 1.2;
  margin: 0;
  flex-shrink: 0;
}

/* Long descriptions scroll internally instead of resizing the modal */
.gallery-modal-description {
  font-size: 16px;
  font-weight: 400;
  color: var(--text-color-secondary);
  line-height: 1.7;
  margin: 0;

  text-align: start;

  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
  padding-right: 8px;

  scrollbar-width: thin;
  scrollbar-color: gray transparent;
}

/* Navigation arrows */
.gallery-nav {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}

.gallery-nav-btn {
  width: 42px;
  height: 42px;
  border: 1px solid rgba(128,128,128,0.25);
  background: rgba(128,128,128,0.10);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-color-primary);
  font-size: 22px;
  font-family: 'Material Symbols Outlined', sans-serif;
  transition: background 0.2s, transform 0.2s, border-color 0.2s;
  line-height: 1;
}

.gallery-nav-btn:hover {
  background: rgba(128,128,128,0.22);
  border-color: rgba(128,128,128,0.45);
  transform: scale(1.08);
}

.gallery-nav-btn:disabled {
  opacity: 0.25;
  cursor: default;
  transform: none;
}

/* Dot indicators */
.gallery-dots {
  display: flex;
  gap: 7px;
  align-items: center;
  margin-left: 4px;
}

.gallery-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(128,128,128,0.35);
  transition: background 0.2s, transform 0.2s;
  cursor: pointer;
}

.gallery-dot.active {
  background: var(--text-color-primary);
  transform: scale(1.3);
}

@keyframes dot-pulse {
  0%   { transform: scale(1.3); }
  50%  { transform: scale(1.9); }
  100% { transform: scale(1.3); }
}

.gallery-dot.active {
  animation: dot-pulse 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}


/* ============================================================
   Responsive — Mobile
   ============================================================ */

@media (max-width: 680px) {
  .gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 18px;
  }

  .phone-wrapper img {
    width: 110px;
  }

  /* Modal becomes vertical on mobile and scrolls as a whole
     (max-height 90vh) rather than scrolling the description
     internally — undo the desktop fixed-height/scroll-area setup. */
  .gallery-modal {
    flex-direction: column;
    gap: 28px;
    padding: 40px 24px 32px;
    height: auto;
    max-height: 90vh;
    overflow-y: auto;
    width: calc(100% - 32px);
    box-sizing: border-box;
  }
  .gallery-modal .phone-wrapper img {
    height: auto;
    width: 150px;
    max-width: 60vw;
  }

  .gallery-modal-text {
    height: auto;
  }

  .gallery-modal-text-top {
    overflow: visible;
    flex: none;
  }

  .gallery-modal-description {
    overflow-y: visible;
    flex: none;
    max-height: none;
    padding-right: 0;
  }

  .gallery-modal-title {
    font-size: 20px;
  }

  .gallery-modal-description {
    font-size: 15px;
  }

  .gallery-stack-img {
    width: 110px;
  }

  .gallery-stack-card {
    height: auto;
    min-height: 225px; /* enough to contain the fanned images */
    padding-bottom: 28px;
  }

  .gallery-grid.gallery-collapsed {
    grid-template-columns: repeat(2, auto);
  }
}


/* ============================================================
   Reduced motion — quick opacity fades only, no transforms/FLIP
   ============================================================ */

@media (prefers-reduced-motion: reduce) {
  .phone-wrapper,
  .gallery-item:hover .phone-wrapper,
  .gallery-stack-card,
  .gallery-stack-card:hover,
  .gallery-stack-card:active,
  .gallery-stack-img,
  .gallery-modal,
  .gallery-modal.no-pop,
  .gallery-reveal-item {
    transition-property: opacity !important;
    transition-duration: 0.15s !important;
    transform: none !important;
    animation: none !important;
  }

  .phone-wrapper::after {
    transition-duration: 0.15s !important;
  }

  .gallery-morph-ghost {
    transition: none !important;
  }

  .gallery-dot.active {
    animation: none !important;
  }
}
