/* Gallery page — grid, lightbox, upload tray. Shared card/badge/button styles
   live in social.css / components.css; this file is page-specific layout only.
   See docs/post-wedding/04-gallery.md. */

.gallery-section {
  max-width: var(--container-max);
  margin: 0 auto;
  padding: var(--spacing-lg) var(--spacing-md) var(--spacing-xl);
}

.gallery-title {
  text-align: center;
  margin-bottom: var(--spacing-md);
}

/* --- Section switcher (tablist) --- */

.gallery-switcher {
  display: flex;
  flex-wrap: wrap;
  gap: var(--spacing-sm) var(--spacing-md);
  justify-content: center;
  margin-bottom: var(--spacing-lg);
}

.gallery-tab {
  appearance: none;
  border: 1px solid var(--color-border);
  background: var(--color-card-bg);
  color: var(--color-text);
  font: inherit;
  padding: var(--spacing-sm) var(--spacing-lg);
  border-radius: var(--radius-full);
  cursor: pointer;
}

.gallery-tab[aria-selected="true"] {
  background: var(--color-primary);
  color: var(--color-on-primary);
  border-color: var(--color-primary);
}

.gallery-tab-count {
  opacity: 0.8;
  font-size: 0.9em;
}

.gallery-guest-cta {
  display: flex;
  justify-content: center;
  margin-bottom: var(--spacing-lg);
}

/* Breathing room between the stacked grids in the "All" view: the gap sits
   before the honeymoon grid when it shows, then before the contributors strip
   when it has content, else before the guest grid itself. `~` rather than `+`
   because the honeymoon grid (hidden while empty) sits between official and
   the strip. */
#grid-official:not([hidden]) + #grid-honeymoon:not([hidden]) {
  margin-top: var(--spacing-xl);
}

#grid-official:not([hidden]) ~ .gallery-contributors:not([hidden]) {
  margin-top: var(--spacing-xl);
}

#grid-official:not([hidden]) ~ .gallery-contributors[hidden] + #grid-guest {
  margin-top: var(--spacing-xl);
}

/* --- Grid --- */

.media-grid {
  list-style: none;
  margin: 0 0 2px;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 2px;
}

@media (min-width: 768px) {
  .media-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  }
}

/* The virtualization mechanism: offscreen batches cost ~0 layout/paint.
   --batch-est is set per batch in grid.js from measured columns × row height. */
.media-page {
  content-visibility: auto;
  contain-intrinsic-size: auto var(--batch-est, 900px);
}

.media-cell {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 1;
  padding: 0;
  border: none;
  background: var(--color-primary-faint);
  cursor: pointer;
  overflow: hidden;
}

.media-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.media-placeholder {
  display: flex;
  width: 100%;
  height: 100%;
  align-items: center;
  justify-content: center;
  background: var(--color-primary-faint);
}

.media-placeholder::before {
  content: "📷";
  font-size: 1.6rem;
  opacity: 0.5;
}

/* First-paint skeleton: 12 shimmer cells while the first page loads (04 §4).
   Shares the grid so it reserves the same footprint the real cells will. */
.gallery-skeleton {
  pointer-events: none;
}

.media-skeleton {
  aspect-ratio: 1;
  background: var(--color-primary-faint);
  background-image: linear-gradient(
    100deg,
    transparent 30%,
    color-mix(in srgb, var(--color-primary) 8%, transparent) 50%,
    transparent 70%
  );
  background-size: 200% 100%;
  animation: media-skeleton-shimmer 1.4s ease-in-out infinite;
}

@keyframes media-skeleton-shimmer {
  to {
    background-position: -200% 0;
  }
}

.media-chip {
  position: absolute;
  bottom: 4px;
  right: 4px;
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-size: 0.72rem;
  line-height: 1.4;
}

.media-chip.status-pending {
  top: 4px;
  left: 4px;
  bottom: auto;
  right: auto;
  background: var(--color-status-pending-bg);
  color: var(--color-status-pending-text);
}

.media-play {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 12px 0 12px 20px;
  border-color: transparent transparent transparent rgba(255, 255, 255, 0.9);
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.6));
  pointer-events: none;
}

.grid-sentinel {
  width: 100%;
  height: 1px;
}

.gallery-loadmore-wrap {
  margin-top: var(--spacing-lg);
}

.gallery-grid-container.drag-over {
  outline: 3px dashed var(--color-primary);
  outline-offset: 4px;
}

/* --- Lightbox --- */

.lightbox {
  --color-lightbox-stage: #0b0810;
  color-scheme: dark;
  width: 100vw;
  height: 100vh;
  height: 100dvh; /* keep the bottom panel above mobile browser chrome */
  max-width: 100vw;
  max-height: 100vh;
  max-height: 100dvh;
  margin: 0;
  padding: 0;
  border: none;
  background: var(--color-lightbox-stage);
  color: #f0eaf0;
  overflow: hidden;
}

.lightbox::backdrop {
  background: rgba(0, 0, 0, 0.9);
}

.lightbox-topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  padding: var(--spacing-sm) var(--spacing-md);
  background: linear-gradient(rgba(0, 0, 0, 0.55), transparent);
  z-index: 2;
}

.lightbox-close,
.lightbox-copy {
  appearance: none;
  border: none;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.lightbox-close {
  font-size: 1.8rem;
  line-height: 1;
}

.lightbox-counter {
  font-variant-numeric: tabular-nums;
}

.lightbox-meta {
  margin-left: auto;
  text-align: right;
  font-size: 0.85rem;
  line-height: 1.2;
  display: flex;
  flex-direction: column;
}

.lightbox-time {
  opacity: 0.7;
}

.lightbox-copy {
  text-decoration: underline;
}

.lightbox-stage {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: pan-y;
}

.lightbox-media {
  max-width: 100vw;
  max-height: 100vh;
  max-height: 100dvh;
  object-fit: contain;
}

/* While the full display image loads, the stage shows the already-loaded thumb
   (scaled up → soft) plus a spinner, so a cold open never flashes empty black. */
.lightbox-stage.is-loading {
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
}

.lightbox-stage.is-loading::after {
  content: "";
  position: absolute;
  width: 40px;
  height: 40px;
  border: 3px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: lightbox-spin 0.8s linear infinite;
}

@keyframes lightbox-spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .lightbox-stage.is-loading::after {
    animation: none;
  }
}

.lightbox-missing {
  padding: var(--spacing-lg);
  text-align: center;
  opacity: 0.8;
}

.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 2;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: var(--radius-full);
  background: rgba(0, 0, 0, 0.4);
  color: #fff;
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
}

.lightbox-prev {
  left: var(--spacing-sm);
}
.lightbox-next {
  right: var(--spacing-sm);
}

.lightbox-panel {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: var(--spacing-md);
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.6));
  z-index: 2;
}

.lightbox-caption {
  margin: 0 0 var(--spacing-xs);
}

.lightbox-report a {
  color: #cdbfe0;
  font-size: 0.8rem;
}

/* Uploader-only self-delete: quiet text button on the dark stage, mirrors the
   Report link's weight but reads as destructive. */
.lightbox-owner {
  margin: var(--spacing-2xs) 0 0;
}

.lightbox-delete {
  border: none;
  background: none;
  padding: 0;
  color: #f0b4b4;
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
}

.lightbox-delete:hover {
  text-decoration: underline;
}

@media (min-width: 1024px) {
  /* The full-height side panel shares the topbar's z-index and comes later in
     the DOM, so without this it sat over the topbar's right end and swallowed
     clicks on Share / Copy link and the slideshow button. */
  .lightbox-topbar {
    z-index: 3;
  }
  .lightbox-panel {
    top: 0;
    left: auto;
    width: 360px;
    /* Clear the topbar, which now overlaps the panel's top edge. */
    padding-top: calc(var(--spacing-xl) + var(--spacing-md));
    background: rgba(0, 0, 0, 0.35);
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
  }
  .lightbox-stage {
    right: 360px;
  }
}

/* --- Upload FAB + tray --- */

.upload-fab {
  position: fixed;
  right: var(--spacing-md);
  bottom: calc(var(--spacing-md) + 56px);
  z-index: calc(var(--z-mobile-nav) - 1);
  width: 56px;
  height: 56px;
  border: none;
  border-radius: var(--radius-full);
  background: var(--color-primary);
  color: var(--color-on-primary);
  font-size: 2rem;
  line-height: 1;
  box-shadow: var(--shadow-lg);
  cursor: pointer;
}

@media (min-width: 768px) {
  .upload-fab {
    display: none;
  }
}

.upload-tray {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  z-index: var(--z-mobile-nav);
  width: min(560px, 100%);
  max-height: 45vh;
  overflow-y: auto;
  background: var(--color-card-bg);
  border: 1px solid var(--color-border);
  border-bottom: none;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--shadow-lg);
  padding: var(--spacing-sm) var(--spacing-md);
}

.upload-tray-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--spacing-sm);
  padding-bottom: var(--spacing-xs);
}

.upload-tray-cancel {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--color-primary);
  font: inherit;
  cursor: pointer;
}

.upload-tray-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.upload-row {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  padding: var(--spacing-xs) 0;
  border-top: 1px solid var(--color-border);
}

.upload-thumb {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  background: var(--color-primary-faint);
}

.upload-row-main {
  flex: 1;
  min-width: 0;
}

.upload-name {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 0.85rem;
}

.upload-row-state {
  font-size: 0.78rem;
  color: var(--color-text-muted);
}

.upload-row-state.is-error {
  color: var(--color-danger);
}

.upload-bar {
  height: 4px;
  margin-top: 3px;
  background: var(--color-primary-faint);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.upload-bar-fill {
  height: 100%;
  background: var(--color-primary);
  transition: width 0.2s ease;
}

.upload-caption {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 4px 7px;
  font: inherit;
  font-size: 0.8rem;
  color: var(--color-text);
  background: var(--color-card-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
}

.upload-caption[hidden] {
  display: none;
}

.upload-caption-error {
  display: block;
  margin-top: 3px;
  font-size: 0.72rem;
  color: var(--color-danger);
}

.upload-caption-error[hidden] {
  display: none;
}

.upload-caption-count {
  display: block;
  margin-top: 2px;
  text-align: right;
}

.upload-caption-count[hidden] {
  display: none;
}

.upload-action {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--color-primary);
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
}

@media (prefers-reduced-motion: reduce) {
  .upload-bar-fill {
    transition: none;
  }
  .lightbox-stage {
    transition: none !important;
  }
  /* Static placeholder cells — no shimmer sweep. */
  .media-skeleton {
    animation: none;
    background-image: none;
  }
}

/* ============ Photo glint (reuses the frame-glint effect) ============ */
/* One faint specular sweep when any photo is hovered or keyboard-focused: the
   same gradient + @keyframes frame-glint the frame-glint effect (effects.css)
   uses on thank-you polaroids, here triggered by :hover / :focus-visible instead
   of a JS timer, so it fires once per interaction and never loops. */
.gallery-grid-container .media-cell::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  opacity: 0;
  background: linear-gradient(
    22deg,
    transparent 42%,
    rgba(255, 255, 255, 0.12) 50%,
    transparent 58%
  );
  background-size: 250% 250%;
  background-position: 0% 0%;
  mix-blend-mode: screen;
}

.gallery-grid-container .media-cell:hover::after,
.gallery-grid-container .media-cell:focus-visible::after {
  animation: frame-glint 1200ms ease-in-out;
}

@media (prefers-reduced-motion: reduce) {
  .gallery-grid-container .media-cell::after {
    display: none;
  }
}

/* ============ Contributors strip ("Shared by …") ============ */
.gallery-contributors {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  flex-wrap: wrap;
  margin: 0 auto var(--spacing-md);
  padding: var(--spacing-xs) var(--spacing-sm);
  max-width: max-content;
}

.gallery-contrib-chips {
  display: inline-flex;
  align-items: center;
  /* Overlap the monogram chips into a friendly cluster. */
  padding-left: 8px;
}

.gallery-contrib-chips .monogram,
.gallery-contrib-more {
  margin-left: -8px;
  border: 2px solid var(--color-surface);
  box-sizing: border-box;
}

.gallery-contrib-chip {
  display: inline-flex;
}

.gallery-contrib-more {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: var(--radius-full);
  background: var(--color-surface-alt, var(--color-surface));
  color: var(--color-text-muted, inherit);
  font-size: 0.7rem;
  font-weight: 600;
}

.gallery-contrib-text {
  font-size: 0.9rem;
  color: var(--color-text-muted, inherit);
}

/* ============ Colour ⇄ black and white (a photo with a twin) ============ */
/* A pill with a half-filled circle: hollow-ish in colour, filled light while the
   black-and-white copy is showing. aria-pressed carries the state. */
.lightbox-tone {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 3px 11px 3px 8px;
  border: 1px solid rgba(240, 234, 240, 0.55);
  border-radius: 999px;
  background: rgba(11, 8, 16, 0.35);
  color: inherit;
  font: inherit;
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  cursor: pointer;
}

.lightbox-tone[hidden] {
  display: none;
}

.lightbox-tone-glyph {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1.5px solid currentColor;
  background: linear-gradient(90deg, currentColor 50%, transparent 50%);
}

.lightbox-tone[aria-pressed="true"] {
  background: #f0eaf0;
  border-color: #f0eaf0;
  color: #0b0810;
}

.lightbox-tone:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* ============ Slideshow ("Memories" ambient mode) ============ */
.lightbox-play {
  appearance: none;
  border: none;
  background: transparent;
  color: inherit;
  cursor: pointer;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

/* ▶ play triangle; becomes ‖ pause bars while running. */
.lightbox-play-glyph {
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 8px 0 8px 13px;
  border-color: transparent transparent transparent currentColor;
}

.lightbox-play.is-playing .lightbox-play-glyph {
  width: 12px;
  height: 15px;
  border: none;
  border-left: 4px solid currentColor;
  border-right: 4px solid currentColor;
  box-sizing: border-box;
}

/* Ken Burns slow pan/zoom + soft fade-in for a playing slideshow image. */
.lightbox-media.slideshow-anim {
  animation:
    slideshow-fade 700ms ease-out,
    slideshow-kenburns 8s ease-in-out forwards;
  transform-origin: center;
}

@keyframes slideshow-fade {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes slideshow-kenburns {
  from {
    transform: scale(1) translate(0, 0);
  }
  to {
    transform: scale(1.08) translate(-1.5%, 1%);
  }
}

@media (prefers-reduced-motion: reduce) {
  /* Reduced motion: the slideshow still advances on its timer, but no Ken
     Burns / crossfade — the class isn't added by JS, and this guards any race. */
  .lightbox-media.slideshow-anim {
    animation: none;
    transform: none;
  }
}

/* ============ Pinch-zoom ============ */
/* Own the touch gestures on the image so the browser doesn't hijack pinch as a
   page zoom or two-finger pan. Video keeps default touch-action for controls. */
.lightbox-stage img.lightbox-media {
  touch-action: none;
}

.lightbox-stage.stage-zoomed {
  /* A zoomed image is panned by dragging; hint it and suppress swipe-nav. */
  cursor: grab;
}
