/* Farah scrapbook — balanced mobile photo cards.
   Keep this stylesheet LAST in the gift page's stylesheet list. */

.memory-card {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transform-origin: center center;
  transition: transform 150ms ease, box-shadow 150ms ease !important;
}

@media (max-width: 520px) {
  /* Keep the gallery inside the viewport and center it reliably. */
  .memories-section .section-shell {
    box-sizing: border-box !important;
    width: calc(100% - 24px) !important;
    max-width: 100% !important;
    margin-left: auto !important;
    margin-right: auto !important;
  }

  .memories-section .photo-gallery {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    justify-items: center !important;
    align-items: start;
    box-sizing: border-box !important;
    width: 100% !important;
    max-width: 340px !important;
    padding: 0 4px !important;
    margin-left: auto !important;
    margin-right: auto !important;
    gap: 20px !important;
  }

  .memories-section .photo-gallery > .memory-card,
  .memories-section .photo-gallery > .memory-card:nth-child(3n + 2),
  .memories-section .photo-gallery > .memory-card:nth-child(3n) {
    box-sizing: border-box !important;
    justify-self: center !important;
    width: 100% !important;
    max-width: 310px !important;
    min-width: 0 !important;
    margin: 0 auto !important;
    padding: 10px 10px 14px !important;
    transform: rotate(0deg) !important;
    position: relative;
  }

  .memories-section .memory-image-wrap {
    width: 100%;
    aspect-ratio: 4 / 4.1 !important;
    overflow: hidden;
  }

  .memories-section .memory-image-wrap img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
  }

  .memories-section .memory-caption {
    box-sizing: border-box;
    font-size: 1.18rem !important;
    line-height: 1.25 !important;
    padding: 11px 5px 0 !important;
    overflow-wrap: anywhere;
  }

  /* Scale from the card's center only while the finger is down. */
  @media (hover: none) and (pointer: coarse) {
    .memories-section .photo-gallery > .memory-card:active {
      transform: scale(1.025) !important;
      z-index: 3;
      box-shadow: 0 15px 28px rgba(81, 54, 43, 0.17) !important;
    }

    .memories-section .photo-gallery > .memory-card:hover {
      transform: rotate(0deg) !important;
      box-shadow: 0 8px 20px rgba(74, 48, 37, 0.09) !important;
    }
  }
}

@media (prefers-reduced-motion: reduce) {
  .memory-card,
  .memory-card:active {
    transition: none !important;
    transform: none !important;
  }
}
