/*
 * MyMappi v671 interaction polish.
 * One contextual Home capture invitation, a keyboard-safe mobile editor,
 * and a restrained four-action Memory Capsule dock.
 */

/* On phones, an empty Today card already owns the capture invitation. */
@media (max-width: 699px) {
  html body .app-shell .map-stage.home-focus #homeDashboard:has(#homeMemoryOfDay .today-memory-card.is-empty-today) .home-quick-actions,
  html body main.app-shell section.map-stage.home-focus #homeDashboard:has(#homeMemoryOfDay .today-memory-card.is-empty-today) .home-quick-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    width: min(100%, 360px) !important;
  }

  html body .app-shell .map-stage.home-focus #homeDashboard:has(#homeMemoryOfDay .today-memory-card.is-empty-today) .home-action-card[data-home-action="create"],
  html body main.app-shell section.map-stage.home-focus #homeDashboard:has(#homeMemoryOfDay .today-memory-card.is-empty-today) .home-action-card[data-home-action="create"] {
    display: none !important;
  }

  html body .app-shell .map-stage.home-focus #homeDashboard:has(#homeMemoryOfDay .today-memory-card.is-empty-today) .home-action-card:not(.primary),
  html body main.app-shell section.map-stage.home-focus #homeDashboard:has(#homeMemoryOfDay .today-memory-card.is-empty-today) .home-action-card:not(.primary) {
    grid-column: auto !important;
    width: 100% !important;
    min-height: 82px !important;
  }
}

/*
 * iPhone Safari may pan the visual viewport while its keyboard animates.
 * Anchor the editor to that visible viewport, not the taller layout viewport.
 */
@media (max-width: 760px) {
  html body.keyboard-open .app-shell .memory-editor.open,
  html body.keyboard-open main.app-shell .memory-editor.open {
    position: fixed !important;
    top: max(8px, env(safe-area-inset-top)) !important;
    right: max(8px, env(safe-area-inset-right)) !important;
    bottom: auto !important;
    left: max(8px, env(safe-area-inset-left)) !important;
    box-sizing: border-box !important;
    width: auto !important;
    min-width: 0 !important;
    max-width: none !important;
    height: calc(var(--mymappi-visible-height, 100dvh) - max(16px, env(safe-area-inset-top)) - max(8px, env(safe-area-inset-bottom))) !important;
    min-height: 0 !important;
    max-height: calc(var(--mymappi-visible-height, 100dvh) - max(16px, env(safe-area-inset-top)) - max(8px, env(safe-area-inset-bottom))) !important;
    margin: 0 !important;
    padding-bottom: 24px !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    scroll-padding-block: 24px !important;
    overscroll-behavior: contain !important;
    transform: translate3d(0, var(--mymappi-visual-offset-top, 0px), 0) !important;
    translate: none !important;
    background: #fffdf8 !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    -webkit-overflow-scrolling: auto !important;
  }

  html body.keyboard-open .app-shell .memory-editor.open .editor-header,
  html body.keyboard-open main.app-shell .memory-editor.open .editor-header {
    background: #fffdf8 !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
  }

  html body.keyboard-open .app-shell .memory-editor.open :is(input, textarea, select, [contenteditable="true"]):focus,
  html body.keyboard-open main.app-shell .memory-editor.open :is(input, textarea, select, [contenteditable="true"]):focus {
    scroll-margin-block: 24px !important;
  }
}

/*
 * Pinch zoom changes visualViewport.height without changing the underlying
 * photo theater. Keep the decoded image on its own WebKit compositor layer
 * and suspend scroll snapping while the user is magnifying it.
 */
html body.photo-lightbox-open .app-shell .photo-lightbox:not(.video-mode) .photo-lightbox-gallery,
html body.photo-lightbox-open main.app-shell .photo-lightbox:not(.video-mode) .photo-lightbox-gallery {
  touch-action: pan-y pinch-zoom !important;
  -webkit-overflow-scrolling: auto !important;
}

html body.photo-lightbox-open .app-shell .photo-lightbox:not(.video-mode) .photo-lightbox-gallery-item,
html body.photo-lightbox-open main.app-shell .photo-lightbox:not(.video-mode) .photo-lightbox-gallery-item {
  content-visibility: visible !important;
}

html body.photo-lightbox-open .app-shell .photo-lightbox:not(.video-mode) .photo-lightbox-gallery-item > img,
html body.photo-lightbox-open main.app-shell .photo-lightbox:not(.video-mode) .photo-lightbox-gallery-item > img {
  visibility: visible !important;
  opacity: 1 !important;
  /*
   * Keep the image itself in the gallery's vertical pan chain. Restricting
   * this node to pinch-zoom made iPhone Safari ignore a one-finger drag that
   * began over the middle of the photo; the same drag only worked from the
   * padding below it. Two-finger pinch zoom remains available.
   */
  touch-action: pan-y pinch-zoom !important;
  transform: none !important;
  -webkit-transform: none !important;
  backface-visibility: visible !important;
  -webkit-backface-visibility: visible !important;
  will-change: auto !important;
}

html body.photo-lightbox-open.visual-viewport-zoomed .app-shell .photo-lightbox:not(.video-mode),
html body.photo-lightbox-open.visual-viewport-zoomed main.app-shell .photo-lightbox:not(.video-mode),
html body.photo-lightbox-open.visual-viewport-zoomed .app-shell .photo-lightbox:not(.video-mode) .photo-lightbox-frame,
html body.photo-lightbox-open.visual-viewport-zoomed main.app-shell .photo-lightbox:not(.video-mode) .photo-lightbox-frame {
  height: var(--mymappi-visible-height, 100dvh) !important;
  min-height: var(--mymappi-visible-height, 100dvh) !important;
  max-height: var(--mymappi-visible-height, 100dvh) !important;
}

html body.photo-lightbox-open.visual-viewport-zoomed .app-shell .photo-lightbox:not(.video-mode) .photo-lightbox-gallery,
html body.photo-lightbox-open.visual-viewport-zoomed main.app-shell .photo-lightbox:not(.video-mode) .photo-lightbox-gallery {
  scroll-snap-type: none !important;
  scroll-behavior: auto !important;
}

/* The capsule is already the Relive experience: keep one calm utility row. */
html body .app-shell .full-memory-capsule .memory-capsule-action-dock,
html body main.app-shell .full-memory-capsule .memory-capsule-action-dock {
  display: grid !important;
  grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
  align-items: stretch !important;
  width: 100% !important;
  padding: 12px clamp(12px, 3vw, 22px) max(14px, env(safe-area-inset-bottom)) !important;
  gap: clamp(7px, 1.2vw, 10px) !important;
  background: rgba(255, 253, 248, 0.95) !important;
  box-shadow: 0 -10px 30px rgba(7, 63, 82, 0.055) !important;
}

html body .app-shell .full-memory-capsule .memory-capsule-action-dock > .memory-capsule-dock-action,
html body main.app-shell .full-memory-capsule .memory-capsule-action-dock > .memory-capsule-dock-action,
html body .app-shell .full-memory-capsule .memory-capsule-action-dock > .memory-capsule-more,
html body main.app-shell .full-memory-capsule .memory-capsule-action-dock > .memory-capsule-more {
  grid-column: auto !important;
  grid-row: auto !important;
  width: 100% !important;
  min-width: 0 !important;
  margin: 0 !important;
}

html body .app-shell .full-memory-capsule .memory-capsule-action-dock .memory-capsule-dock-action,
html body main.app-shell .full-memory-capsule .memory-capsule-action-dock .memory-capsule-dock-action {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) !important;
  grid-template-rows: 22px auto !important;
  width: 100% !important;
  min-width: 0 !important;
  min-height: 58px !important;
  height: 100% !important;
  padding: 8px 6px !important;
  place-items: center !important;
  align-content: center !important;
  gap: 5px !important;
  border: 1px solid rgba(10, 88, 91, 0.1) !important;
  border-radius: 16px !important;
  color: #285b62 !important;
  background:
    radial-gradient(circle at 20% 0%, rgba(255, 255, 255, 0.94), transparent 44%),
    linear-gradient(145deg, rgba(255, 255, 255, 0.82), rgba(235, 247, 243, 0.72)) !important;
  box-shadow:
    0 8px 18px rgba(7, 63, 82, 0.055),
    inset 0 1px 0 rgba(255, 255, 255, 0.92) !important;
  font-size: 0.68rem !important;
  font-weight: 820 !important;
  line-height: 1 !important;
  text-align: center !important;
  transform: none !important;
}

html body .app-shell .full-memory-capsule .memory-capsule-action-dock .memory-capsule-dock-icon,
html body main.app-shell .full-memory-capsule .memory-capsule-action-dock .memory-capsule-dock-icon {
  display: grid !important;
  width: 22px !important;
  min-width: 22px !important;
  height: 22px !important;
  min-height: 22px !important;
  margin: 0 !important;
  padding: 0 !important;
  place-items: center !important;
  color: currentColor !important;
  background: transparent !important;
  box-shadow: none !important;
}

html body .app-shell .full-memory-capsule .memory-capsule-action-dock .memory-capsule-dock-icon svg,
html body main.app-shell .full-memory-capsule .memory-capsule-action-dock .memory-capsule-dock-icon svg {
  display: block !important;
  width: 19px !important;
  height: 19px !important;
  stroke-width: 2 !important;
}

html body .app-shell .full-memory-capsule .memory-capsule-action-dock .memory-capsule-dock-label,
html body main.app-shell .full-memory-capsule .memory-capsule-action-dock .memory-capsule-dock-label {
  position: static !important;
  display: block !important;
  width: 100% !important;
  height: auto !important;
  min-width: 0 !important;
  margin: 0 !important;
  overflow: hidden !important;
  color: inherit !important;
  font: inherit !important;
  line-height: 1.1 !important;
  text-align: center !important;
  text-overflow: ellipsis !important;
  white-space: nowrap !important;
  clip: auto !important;
}

html body .app-shell .full-memory-capsule .memory-capsule-action-dock .memory-capsule-route-action,
html body main.app-shell .full-memory-capsule .memory-capsule-action-dock .memory-capsule-route-action {
  border-color: rgba(20, 151, 130, 0.2) !important;
  color: #08736d !important;
  background:
    radial-gradient(circle at 20% 0%, rgba(255, 255, 255, 0.94), transparent 44%),
    linear-gradient(145deg, rgba(229, 249, 241, 0.96), rgba(216, 243, 237, 0.82)) !important;
  box-shadow:
    0 9px 20px rgba(9, 119, 107, 0.09),
    inset 0 1px 0 rgba(255, 255, 255, 0.9) !important;
}

html body .app-shell .full-memory-capsule .memory-capsule-action-dock .memory-capsule-heart-action.is-hearted,
html body main.app-shell .full-memory-capsule .memory-capsule-action-dock .memory-capsule-heart-action.is-hearted {
  border-color: rgba(226, 87, 105, 0.2) !important;
  color: #b54459 !important;
  background:
    radial-gradient(circle at 20% 0%, rgba(255, 255, 255, 0.94), transparent 44%),
    linear-gradient(145deg, rgba(255, 241, 242, 0.96), rgba(250, 226, 231, 0.8)) !important;
}

html body .app-shell .full-memory-capsule .memory-capsule-action-dock .memory-capsule-more-action::after,
html body main.app-shell .full-memory-capsule .memory-capsule-action-dock .memory-capsule-more-action::after {
  display: none !important;
  content: none !important;
}

@media (hover: hover) and (pointer: fine) {
  html body .app-shell .full-memory-capsule .memory-capsule-action-dock .memory-capsule-dock-action:hover,
  html body main.app-shell .full-memory-capsule .memory-capsule-action-dock .memory-capsule-dock-action:hover {
    border-color: rgba(9, 120, 111, 0.2) !important;
    box-shadow:
      0 12px 24px rgba(7, 63, 82, 0.09),
      inset 0 1px 0 rgba(255, 255, 255, 0.94) !important;
    transform: translateY(-1px) !important;
  }
}

@media (max-width: 420px) {
  html body .app-shell .full-memory-capsule .memory-capsule-action-dock,
  html body main.app-shell .full-memory-capsule .memory-capsule-action-dock {
    padding-right: 9px !important;
    padding-left: 9px !important;
    gap: 6px !important;
  }

  html body .app-shell .full-memory-capsule .memory-capsule-action-dock .memory-capsule-dock-action,
  html body main.app-shell .full-memory-capsule .memory-capsule-action-dock .memory-capsule-dock-action {
    min-height: 56px !important;
    padding-right: 3px !important;
    padding-left: 3px !important;
    border-radius: 14px !important;
    font-size: 0.62rem !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  html body .app-shell .full-memory-capsule .memory-capsule-action-dock .memory-capsule-dock-action,
  html body main.app-shell .full-memory-capsule .memory-capsule-action-dock .memory-capsule-dock-action {
    transition: none !important;
    transform: none !important;
  }
}
