/* ==========================================================================
   Portraits: the photography corner. One template for every gallery:
   the public one at /portraits/ and the unlisted ones Stephen shares by
   link (/g/<token>/, a quieter head and no way further in). A masonry grid,
   a viewer on black, and the optional password step in front of a shared
   gallery (.door).
   ========================================================================== */

/* the row height the grid aims for; registered so the script can read it in pixels */

/* ---------- head ---------- */

.gallery-head {
  display: grid;
  gap: clamp(1.5rem, 4vw, 2.5rem);
  padding: clamp(8rem, 20vh, 12rem) var(--gutter) clamp(2.5rem, 5vw, 4.5rem);
}
.gallery-head__eyebrow {
  color: var(--soft);
}
.gallery-head__title {
  font-size: var(--step-4);
}
.gallery-head__side {
  display: grid;
  gap: clamp(1rem, 2vw, 1.5rem);
  align-content: end;
}
.gallery-head__dek {
  max-width: 26ch;
  font-size: var(--step-1);
  line-height: 1.35;
}
.gallery-head__count {
  color: var(--soft);
}
@media (min-width: 900px) {
  .gallery-head {
    grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr);
    column-gap: clamp(3rem, 6vw, 7rem);
    align-items: end;
  }
  .gallery-head__eyebrow {
    grid-column: 1 / -1;
  }
  .gallery-head__side {
    padding-bottom: clamp(0.5rem, 1.4vw, 1.5rem);
  }
}

/* a shared gallery: its own name, smaller, and who sent it */
.gallery-head--shared {
  padding-top: clamp(7.5rem, 17vh, 10rem);
}
.gallery-head--shared .gallery-head__title {
  font-size: var(--step-3);
}
.gallery-head--shared {
  grid-template-columns: minmax(0, 1fr);
  gap: clamp(1rem, 2vw, 1.5rem);
}
.gallery-head--shared .gallery-head__side {
  padding-bottom: 0;
}

/* ---------- the grid ----------
   Masonry: equal-width columns, each picture at its own shape, nothing
   cropped, the bottoms staggered. As many columns as fit at about --size
   wide, never fewer than two. The stylesheet does this by itself with CSS
   columns (which run down each column); js/masonry.js then places the pictures
   so the sequence runs across instead, each into the shortest column. */

.photos-wrap {
  padding: 0 var(--gutter) clamp(3rem, 7vw, 6rem);
}
.photos {
  /* the column width to aim for, and the spacing; a gallery can set its own in /admin */
  --size: 540px;
  --gap: 4px;
  columns: 2;
  column-gap: var(--gap);
  position: relative;
}
@media (min-width: 1200px) {
  .photos { columns: var(--size); }
}
.photo {
  display: block;
  break-inside: avoid;
  margin-bottom: var(--gap);
  width: 100%;
  aspect-ratio: var(--ar);
  /* a tone to hold the place until the picture is in */
  background: color-mix(in srgb, var(--fg) 7%, var(--bg));
}
/* placed by the script: exact positions, the order running across */
.photos.is-masonry {
  columns: auto;
}
.photos.is-masonry .photo {
  position: absolute;
  margin: 0;
}
.photo__link {
  display: block;
  width: 100%;
  height: 100%;
  overflow: hidden;
}
.photo__link:focus-visible {
  position: relative;
  z-index: 1;
  outline: 3px solid var(--fg);
  outline-offset: 2px;
}
.photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: scale 0.9s var(--ease-out);
}
@media (hover: hover) and (pointer: fine) and (prefers-reduced-motion: no-preference) {
  .photo__link:hover img {
    scale: 1.035;
  }
}

.gallery-end {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 1rem 2rem;
  padding: 0 var(--gutter) clamp(4rem, 9vw, 8rem);
}

/* ---------- the viewer: one picture, large, on black ---------- */

.viewer {
  --pad: clamp(0.5rem, 1.6vw, 1.5rem);
  width: 100vw;
  max-width: none;
  height: 100vh;
  height: 100dvh;
  max-height: none;
  margin: 0;
  padding: 0 var(--pad);
  border: 0;
  background: var(--black);
  color: var(--white);
  overflow: hidden;
}
.viewer::backdrop {
  background: var(--black);
}
.viewer:focus {
  outline: none;
}
.viewer[open] {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  grid-template-areas:
    "where where close"
    "stage stage stage"
    "caption caption caption"
    "count play steps";
  align-items: center;
}
.viewer__where {
  grid-area: where;
  padding: 0.75rem;
  color: color-mix(in srgb, var(--white) 60%, transparent);
}
.viewer__close {
  grid-area: close;
  justify-self: end;
}
.viewer__stage {
  grid-area: stage;
  position: relative;
  align-self: stretch;
  min-height: 0;
  margin: 0 calc(-1 * var(--pad));
  overflow: hidden;
  /* a sideways drag turns the page; up and down, and a pinch, stay the browser's */
  touch-action: pan-y pinch-zoom;
  -webkit-user-select: none;
  user-select: none;
  cursor: e-resize;
}
.viewer__stage.is-back {
  cursor: w-resize;
}
.viewer__img {
  position: absolute;
  left: 50%;
  top: 50%;
  max-width: none;
  translate: -50% -50%;
  /* the small picture from the grid stands in until the large one arrives */
  background: center / cover no-repeat;
  opacity: 0;
  pointer-events: none;
  -webkit-user-drag: none;
}
.viewer__img.is-on {
  opacity: 1;
}
.viewer__caption {
  grid-area: caption;
  justify-self: center;
  max-width: 60ch;
  padding: 0.75rem 0.75rem 0;
  font-size: var(--step-0);
  line-height: 1.4;
  text-align: center;
  text-wrap: balance;
}
.viewer__count {
  grid-area: count;
  padding: 0.75rem;
  font-variant-numeric: tabular-nums;
  color: color-mix(in srgb, var(--white) 60%, transparent);
}
.viewer__count span {
  color: var(--white);
}
.viewer__btn {
  padding: 0.9rem 0.75rem;
  border: 0;
  background: none;
  color: var(--white);
  white-space: nowrap;
  cursor: pointer;
}
@media (max-width: 480px) {
  .viewer__btn,
  .viewer__count,
  .viewer__where {
    padding-inline: 0.55rem;
  }
}
.viewer__btn:focus-visible {
  outline-offset: -2px;
}
.viewer__play {
  grid-area: play;
  min-width: 5.5em;
}
.viewer__steps {
  grid-area: steps;
  display: flex;
  justify-self: end;
}
/* the slideshow's clock: a hairline along the foot that draws in from the left */
.viewer__progress {
  position: absolute;
  inset: auto 0 0 0;
  height: 2px;
  background: var(--white);
  transform: scaleX(0);
  transform-origin: 0 50%;
}

/* ---------- the door: the optional password in front of a shared gallery ---------- */

.door {
  display: grid;
  justify-items: center;
  align-content: center;
  gap: clamp(1rem, 2.4vh, 1.6rem);
  min-height: 100vh;
  min-height: 100svh;
  padding: clamp(7rem, 15vh, 9rem) var(--gutter) clamp(3rem, 8vh, 6rem);
  text-align: center;
}
.door__moon {
  width: clamp(3.5rem, 7vw, 5.5rem);
  margin-bottom: clamp(0.5rem, 2vh, 1.5rem);
  overflow: visible;
}
.door__eyebrow {
  color: var(--soft);
}
.door__title {
  font-size: var(--step-4);
}
.door__text {
  max-width: 28ch;
  font-size: var(--step-1);
  line-height: 1.35;
  color: color-mix(in srgb, var(--fg) 82%, transparent);
}
.door__form {
  display: grid;
  justify-items: center;
  gap: clamp(1.25rem, 3vh, 2rem);
  width: min(100%, 24rem);
  margin-top: clamp(0.75rem, 2vh, 1.5rem);
}
.door__field {
  display: grid;
  gap: 0.5rem;
  width: 100%;
  text-align: left;
  color: var(--soft);
}
.door__field input {
  width: 100%;
  padding: 0.5rem 0 0.6rem;
  border: 0;
  border-bottom: 1px solid var(--fg);
  border-radius: 0;
  background: none;
  color: var(--fg);
  font-family: var(--font-mono);
  font-size: var(--step-1);
  letter-spacing: 0.2em;
  text-align: center;
}
.door__field input:focus-visible {
  outline: none;
  border-bottom-width: 3px;
  padding-bottom: calc(0.6rem - 2px);
}
.door__note {
  font-family: var(--font-display);
  font-style: italic;
  font-size: var(--step-1);
  line-height: 1.2;
}
.door__note[hidden] {
  display: none;
}
.door__btn {
  --size: clamp(8rem, 11vw, 9.5rem);
  border: 0;
  cursor: pointer;
}
.door__help {
  margin-top: clamp(0.5rem, 2vh, 1.25rem);
  font-size: var(--step-0);
  color: var(--soft);
}
.door__help a {
  color: var(--fg);
}
/* a wrong password: the field shakes its head */
@keyframes door-no {
  20%, 60% { translate: -0.5rem 0; }
  40%, 80% { translate: 0.5rem 0; }
}
@media (prefers-reduced-motion: no-preference) {
  .door__form.is-wrong .door__field {
    animation: door-no 0.45s var(--ease-out);
  }
}

/* night throughout, like the 404: no white limb before the footer */
.night .moonset {
  display: none;
}
.night .site-footer {
  margin-top: 0;
  padding-top: clamp(4rem, 10vh, 7rem);
}
