/* Viewer: one shoot full screen over the page (js/viewer.js). */
.viewer {
  /* Height of the round arrows; the cursor one is bigger. */
  --button: 3.25rem;
  --cursor: 5.5rem;
  /* Text and buttons; swapped on a deep photo backdrop (.viewer__stage[data-tone="dark"]). */
  --ink: var(--color-text);
  --paper: var(--color-bg);
  --muted: var(--color-muted);
  --accent: var(--color-accent);

  position: fixed;
  z-index: 1000;
  inset: 0;
  pointer-events: none;
}

.viewer__stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
  /* The photo's softened colour (js/lib/backdrop.js), else the paper. */
  background: var(--backdrop, var(--color-bg));
  color: var(--ink);
  visibility: hidden;
  touch-action: pinch-zoom;
}

.viewer__stage[data-tone="dark"] {
  --ink: var(--color-bg);
  --paper: var(--color-text);
  --muted: color-mix(in srgb, var(--color-bg) 62%, transparent);
  /* The deep red would disappear on a deep backdrop. */
  --accent: color-mix(in srgb, var(--color-accent), var(--color-bg) 45%);
}

.viewer[data-open] .viewer__stage {
  visibility: visible;
  pointer-events: auto;
}

/* Phones: room for Back above the photo and the title and arrows below it. */
.viewer__photo {
  position: absolute;
  top: calc(var(--gutter) + var(--space-7));
  bottom: calc(var(--gutter) + var(--space-9) + var(--space-5));
  inset-inline: var(--gutter);
}

.viewer__layer {
  position: absolute;
  inset: 0;
  opacity: 0;
}

.viewer__layer[data-current] {
  opacity: 1;
}

.viewer__image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* Each half of the screen steps that way. */
.viewer__half {
  position: absolute;
  z-index: 1;
  top: 0;
  bottom: 0;
  width: 50%;
}

.viewer__prev {
  left: 0;
}

.viewer__next {
  right: 0;
}

.viewer__back {
  position: absolute;
  z-index: 3;
  top: var(--gutter);
  left: var(--gutter);
  font-family: var(--font-heading);
  font-size: var(--text-xl);
  font-weight: 500;
  line-height: 1;
  color: var(--ink);
  text-decoration: none;
}

.viewer__back:hover {
  color: var(--accent);
}

.viewer__caption {
  position: absolute;
  z-index: 2;
  bottom: var(--gutter);
  left: var(--gutter);
  right: calc(var(--gutter) + 2 * var(--button) + var(--space-5));
  pointer-events: none;
}

.viewer__counter {
  margin-bottom: var(--space-2);
  font-size: var(--text-xs);
  font-weight: 500;
  letter-spacing: var(--tracking-caps);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.viewer__current {
  color: var(--accent);
}

.viewer__title {
  font-size: var(--text-2xl);
  line-height: var(--leading-tight);
  letter-spacing: -0.02em;
}

.viewer__arrows {
  position: absolute;
  z-index: 3;
  right: var(--gutter);
  bottom: var(--gutter);
  display: flex;
  gap: var(--space-2);
}

.viewer__button {
  display: grid;
  place-items: center;
  width: var(--button);
  height: var(--button);
  border-radius: 50%;
  background: var(--ink);
  color: var(--paper);
  transition: background-color var(--duration) var(--ease);
}

.viewer__button:hover {
  background: var(--accent);
}

.viewer__arrow {
  width: 40%;
}

[data-side="-1"] > .viewer__arrow {
  rotate: 180deg;
}

/* Moved by GSAP (x, y); its look and scale live on .viewer__dot, which GSAP never touches. */
.viewer__cursor {
  position: fixed;
  z-index: 4;
  top: 0;
  left: 0;
  width: var(--cursor);
  height: var(--cursor);
  margin: calc(var(--cursor) / -2) 0 0 calc(var(--cursor) / -2);
  pointer-events: none;
}

.viewer__dot {
  display: none;
  place-items: center;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: var(--ink);
  color: var(--paper);
  opacity: 0;
  scale: 0.5;
  transition:
    opacity var(--duration) var(--ease),
    scale 400ms var(--ease);
}

.viewer__flash {
  position: absolute;
  z-index: 10;
  inset: 0;
  background: var(--color-flash);
  opacity: 0;
  visibility: hidden;
}

@media (hover: hover) and (pointer: fine) {
  .viewer__half {
    cursor: none;
  }

  .viewer__dot {
    display: grid;
  }

  .viewer__half:hover ~ .viewer__cursor .viewer__dot {
    opacity: 1;
    scale: 1;
  }

  /* With a mouse the cursor is the arrow; these stay for the keyboard. */
  .viewer__arrows:not(:focus-within) {
    opacity: 0;
    pointer-events: none;
  }
}

@media (min-width: 64rem) {
  .viewer__photo {
    top: var(--gutter);
    bottom: var(--gutter);
    inset-inline: 16vw;
  }

  .viewer__back {
    font-size: var(--text-2xl);
  }

  .viewer__caption {
    right: auto;
    max-width: calc(16vw - var(--gutter) + 10rem);
  }

  .viewer__title {
    font-size: var(--text-3xl);
  }
}
