/* The photos carousel and the local map of the gallery on screen. */

.picture-browser {
  --cover-ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --print: #fbfaf6;
  --print-shadow: 0 1px 2px rgb(0 0 0 / 28%), 0 6px 16px rgb(0 0 0 / 20%);
  --print-shadow-up: 0 2px 4px rgb(0 0 0 / 25%), 0 16px 32px rgb(0 0 0 / 30%);
  --print-shadow-big: 0 2px 4px rgb(0 0 0 / 25%), 0 10px 24px rgb(0 0 0 / 25%);
  display: grid;
  grid-template-columns: minmax(0, 1fr) 18rem;
  grid-template-rows: 26rem auto;
  gap: 0.75rem;
  margin-top: 1rem;
  align-items: stretch;
}

/* The gallery row sits under the photo and map on a wide screen, and above the map on a phone. */
.picture-split {
  display: contents;
}

.picture-browser .trending-photos {
  grid-column: 1;
  grid-row: 1;
}

.picture-browser .trending-map {
  grid-column: 2;
  grid-row: 1;
  pointer-events: none;
}

/*
  The gallery row: prints in perspective, the current one facing forward and
  larger, the rest turned away to each side. photos/cover.js sets on each card
  --x (offset in card widths), --s (side: -1, 0, 1), --ad (steps away), and --z.
  Icicles under an ice print are in picture-weather.css.

  The sky (picture-weather.css) and the row share one cell in .picture-row,
  which holds the only edge mask, so one masked layer covers both.
*/
.picture-browser .picture-row {
  position: relative;
  display: grid;
  grid-column: 1 / -1;
  grid-row: 2;
  mask-image: linear-gradient(90deg, transparent, #000 10%, #000 90%, transparent);
}

.picture-row > .picture-sky,
.picture-row > .picture-list {
  grid-area: 1 / 1;
}

.picture-browser .picture-list {
  --card: 7.5rem;
  --center: calc((var(--card) + 0.5rem) * 0.7 + 0.5rem);
  position: relative;
  z-index: 1;
  display: block;
  height: calc(var(--card) * 2.3 + 2rem);
  margin: 0;
  padding: 0;
  overflow: hidden;
  perspective: 50rem;
}

.picture-browser .picture-list > li {
  /* Prints farther from the current one are darker: 5% a step, up to 30%. */
  --dim: calc(min(var(--ad, 0), 6) * 0.05);
  position: absolute;
  top: var(--center);
  left: 50%;
  z-index: var(--z, 0);
  width: var(--card);
  transform:
    translate(-50%, -50%)
    translateX(calc(var(--x, 0) * var(--card) * 0.6 + var(--s, 0) * var(--card) * 0.45))
    rotateY(calc(var(--s, 0) * -55deg))
    scale(0.92);
  transition: transform 450ms var(--cover-ease);
}

.picture-browser .picture-list > li.is-current {
  transform: translate(-50%, -50%) scale(1.4);
}

/* Each photo is a print with a thin white border. */
.picture-browser button.picture-card {
  position: relative;
  display: block;
  box-sizing: border-box;
  padding: 0.125rem;
  border-radius: 0.25rem;
  background: var(--print);
  box-shadow: var(--print-shadow);
  transition: box-shadow 300ms ease, translate 200ms ease;
}

/* The darkening, as a black layer whose opacity the compositor can fade,
   rather than a filter that repaints every print on every step. */
.picture-browser button.picture-card::before {
  content: "";
  position: absolute;
  z-index: 1;
  inset: 0;
  border-radius: inherit;
  background: #000;
  opacity: var(--dim);
  pointer-events: none;
  transition: opacity 300ms ease;
}

/*
  Every print but the current one is reflected almost whole below it: a
  flipped copy of the print (--photo is set on the card), fading away from it.
*/
.picture-browser button.picture-card::after {
  content: "";
  position: absolute;
  top: calc(100% + 0.3rem);
  left: 0;
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  padding: 0.125rem;
  border-radius: 0.25rem;
  background: var(--photo) center / cover no-repeat content-box, var(--print);
  mask-image: linear-gradient(transparent 8%, rgb(0 0 0 / 32%));
  opacity: calc(1 - var(--dim));
  scale: 1 -1;
  pointer-events: none;
  transition: opacity 300ms ease;
}

.picture-browser .is-current button.picture-card::after {
  opacity: 0;
}

.picture-browser .picture-card-image,
.picture-browser .picture-card[aria-pressed="true"] .picture-card-image {
  border-radius: 0.15rem;
  box-shadow: none;
}

.picture-browser .is-current button.picture-card {
  box-shadow: var(--print-shadow-up);
}

/* Previous 20 floats at the left of the gallery row, so it never moves it. */
.picture-browser > .picture-pages {
  z-index: 2;
  grid-column: 1 / -1;
  grid-row: 2;
  align-self: center;
  margin: 0;
  padding-inline: 3%;
  pointer-events: none;
}

.picture-browser > .picture-pages > * {
  pointer-events: auto;
}

/* At the last photo, Load more (or Next 20) takes the next arrow's place. */
.map-photo-more {
  position: absolute;
  z-index: 3;
  top: 50%;
  right: 0.5rem;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.55rem 0.6rem 0.55rem 0.95rem;
  border-radius: 999px;
  background: var(--color-accent);
  color: var(--color-on-accent);
  font-size: 0.9375rem;
  font-weight: 700;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
  box-shadow: 0 2px 6px rgb(0 0 0 / 30%), 0 8px 20px rgb(0 0 0 / 25%);
  translate: 0 -50%;
}

.map-photo-more:hover {
  background: var(--color-accent-strong);
  color: var(--color-on-accent);
  text-decoration: none;
}

.map-photo-more:focus-visible {
  outline: var(--focus-ring);
  outline-offset: 2px;
}

.map-photo-more[hidden] {
  display: none;
}

.map-photo-more svg {
  width: 0.95rem;
  height: 0.95rem;
}

/* All caught up, drawn where the photos are, after the last one. */
.trending-photos [data-photo-end] {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
}

.trending-photos [data-photo-end][hidden] {
  display: none;
}

.trending-photo-end .picture-caught-up {
  box-sizing: border-box;
  justify-content: center;
  width: 100%;
  max-width: none;
  height: 100%;
  margin: 0;
  padding: 1rem;
  background: var(--color-surface);
}

@media (hover: hover) {
  .picture-browser li:not(.is-current) button.picture-card:hover {
    translate: 0 -0.35rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .picture-browser .picture-list > li,
  .picture-browser button.picture-card,
  .picture-browser button.picture-card::before {
    transition: none;
  }
}

.picture-browser .trending-photos,
.picture-browser .trending-map {
  box-sizing: border-box;
  height: 100%;
  margin-top: 0;
}

.picture-browser .trending-photos .trending-photo-frame {
  height: 100%;
}

.trending-photos {
  padding: 0;
  overflow: hidden;
}

.trending-photos .trending-photo-frame {
  height: 26rem;
}

.trending-photos [data-photo-slide] {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
}

.trending-photo-still {
  position: relative;
  display: flex;
  max-width: 100%;
  max-height: 100%;
}

.trending-photo-taken {
  position: absolute;
  z-index: 1;
  top: 0.4rem;
  left: 0.4rem;
  width: max-content;
  padding: 0.15rem 0.4rem;
  border-radius: 0.3rem;
  background: rgb(var(--overlay-rgb) / 72%);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
}

.trending-photos [data-photo-slide][hidden] {
  display: none;
}

.trending-photos .map-photo-frame img {
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: 100%;
  object-fit: contain;
}

.trending-photo-marks {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.trending-photo-marks[hidden] {
  display: none;
}

.trending-photos .map-photo-overlay .picture-mark,
.trending-photos .map-photo-visit {
  border-color: rgb(var(--overlay-rgb) / 18%);
  background: var(--glass);
  color: var(--glass-ink);
}

.trending-photos .map-photo-visit {
  width: 2rem;
  min-width: 2rem;
  height: 2rem;
}

.trending-photos .map-photo-visit svg {
  width: 1rem;
  height: 1rem;
}

.trending-photos .picture-mark.is-pressed,
.trending-photos .picture-mark[aria-pressed="true"] {
  border-color: var(--glass-ink);
  background: var(--glass-strong);
}

.trending-photos .picture-mark-count {
  color: var(--glass-ink);
}

/*
  Photo places on a phone's map: storm report pins (maps.css) with the scene
  icon on the face. The current photo's pin is half again as big and pops up
  with each photo.
*/
.map-tag-pin {
  pointer-events: none;
}

/* The rim and point take the scene color from data-tag on the mark. */
.map-tag-pin .map-report-mark {
  --report-color: var(--tag-color, #334155);
}

.map-tag-pin .map-report-pin-face .tag-icon {
  width: 18px;
  height: 18px;
}

.map-tag-pin-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--report-color);
}

/* --pin-scale comes from TAG_PIN in maps/photos.js. */
.map-tag-pin.is-current .map-report-mark {
  transform-origin: 50% 100%;
  scale: var(--pin-scale, 1.5);
  animation: tag-pin-pop 400ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes tag-pin-pop {
  from { scale: 1; }
  to { scale: var(--pin-scale, 1.5); }
}

@media (prefers-reduced-motion: reduce) {
  .map-tag-pin.is-current .map-report-mark {
    animation: none;
  }
}

/* The menu is fixed at the top right, so the sort tabs stop before it. */
.picture-top > .auth-tabs {
  width: auto;
  margin-right: max(
    0px,
    calc(var(--app-bar-clearance) - var(--page-gutter) - (100vw - min(100vw, var(--auth-max))) / 2)
  );
}

/*
  A phone gets one screen in fixed parts, top to bottom: the local map with the
  sort and Near buttons over it (30%), the photo (50%), and the gallery row
  with its sky (20%). The parts keep their size from photo to photo. The map
  runs on behind the photo's half, which is clear, so space a wide or tall
  photo leaves around itself shows map. svh is the height with the browser
  bars showing.
*/
@media (max-width: 40rem) {
  .picture-index {
    --top-h: 30svh;
    --photo-h: 50svh;
    --row-h: 20svh;
    position: relative;
    padding-top: 0.5rem;
    padding-bottom: 0;
  }

  /* The selected sort tab names the page. */
  .picture-index > h1 {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  .picture-top {
    position: relative;
    z-index: 1;
    box-sizing: border-box;
    height: calc(var(--top-h) - 0.5rem);
  }

  .picture-top > .auth-tabs {
    margin-bottom: 0.4rem;
  }

  .picture-top .picture-galleries {
    margin-top: 0;
  }

  /* Small and frosted like the map buttons, so the map shows through. */
  .picture-top .auth-tabs a,
  .picture-top .picture-gallery-group .button {
    min-height: 1.9rem;
    padding: 0.25rem 0.5rem;
    border-color: var(--frost-border);
    background: var(--frost-surface);
    -webkit-backdrop-filter: var(--frost-blur);
    backdrop-filter: var(--frost-blur);
    color: var(--color-ink);
    font-size: 0.8125rem;
    white-space: nowrap;
    box-shadow: none;
  }

  .picture-top .auth-tabs a[aria-current="page"],
  .picture-top .picture-gallery-group .button-primary {
    border-color: var(--frost-accent-border);
    background: var(--frost-accent-busy);
    color: var(--color-on-accent);
  }

  .picture-browser {
    display: block;
    margin-top: 0;
  }

  /* A container, so the overlay can sit on the photo's bottom edge in cqw. */
  .picture-browser .trending-photos .trending-photo-frame {
    height: var(--photo-h);
    container-type: inline-size;
  }

  .picture-browser .trending-photos {
    position: relative;
    z-index: 1;
    border: 0;
    border-radius: 0;
    background: transparent;
  }

  /* The photo takes 90% of the width; the map shows in the 5% each side and
     the same strip below. Percent padding is of the width, so all three match. */
  .picture-browser .trending-photos :is([data-photo-slide], [data-photo-end]) {
    box-sizing: border-box;
    padding-inline: 5%;
    padding-bottom: 5%;
  }

  /* All caught up looks like a print in the photo's place. */
  .trending-photo-end .picture-caught-up {
    border: 0.25rem solid var(--print);
    border-radius: 0.75rem;
    box-shadow: var(--print-shadow-big);
  }

  .trending-photo-end .picture-caught-up-mark {
    width: 5rem;
    height: 5rem;
  }

  .trending-photo-end .picture-caught-up-mark .tag-icon {
    width: 3.5rem;
    height: 3.5rem;
  }

  /*
    Every photo fills the same space, whatever its shape, cropped to fit and
    centered. View full image shows the whole photo. A print border sets it
    apart from the map around it.
  */
  .trending-photos .trending-photo-still {
    width: 100%;
    height: 100%;
  }

  .trending-photos .map-photo-frame img {
    width: 100%;
    max-width: none;
    height: 100%;
    max-height: none;
    object-fit: cover;
    object-position: center;
    box-sizing: border-box;
    border: 0.25rem solid var(--print);
    border-radius: 0.75rem;
    box-shadow: var(--print-shadow-big);
  }

  /*
    The place, caption, and reaction buttons sit inside the photo's border,
    with no dark fade over it. A shadow keeps the words readable.
  */
  .picture-browser .map-photo-overlay {
    top: 0.25rem;
    right: 0.25rem;
    bottom: calc(5cqw + 0.25rem);
    left: 0.25rem;
    justify-content: flex-end;
    padding-top: 1.5rem;
    background: none;
  }

  /* The reaction buttons stay on one row. View full image moves to the top right. */
  .picture-browser .map-photo-actions,
  .picture-browser .trending-photo-marks,
  .picture-browser .picture-marks {
    flex-wrap: nowrap;
  }

  .picture-browser .picture-marks {
    margin-top: 0;
  }

  .picture-browser .trending-photo-marks .map-photo-visit {
    position: absolute;
    top: 0.4rem;
    right: 0.4rem;
  }

  .picture-browser .map-photo-label,
  .picture-browser .map-photo-caption {
    text-shadow: 0 1px 2px rgb(0 0 0 / 80%), 0 0 8px rgb(0 0 0 / 50%);
  }

  /* The gallery row is the bottom of the page, so Previous 20 floats in its band. */
  .picture-browser > .picture-pages {
    position: absolute;
    right: 0;
    bottom: 0;
    left: 0;
    height: var(--row-h);
    align-items: center;
  }

  .picture-split {
    display: grid;
    margin-inline: calc(-1 * var(--page-gutter));
  }

  .picture-browser .picture-row {
    grid-area: 1 / 1;
  }

  body .picture-split .page-bleed {
    margin-inline: 0;
  }

  /* The reflection may run off the bottom; it has faded by then. */
  .picture-browser .picture-list {
    --card: clamp(3rem, calc((var(--row-h) - 1rem) / 2), 6rem);
    height: var(--row-h);
  }

  /* The map fills the top 30% behind the buttons and runs on behind the photo. */
  .picture-split .trending-map {
    position: absolute;
    z-index: 0;
    top: 0;
    right: 0;
    left: 0;
    height: calc(var(--top-h) + var(--photo-h));
    margin: 0;
    border-radius: 0;
  }
}
