.museum-table img {
  cursor: zoom-in;
}

.lightbox {
  --bar-height: calc(2.75rem + env(safe-area-inset-bottom, 0px));
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  overflow: hidden;
  background: #000;
  color: #fff;
  color-scheme: dark;
  /* Must not depend on [open]. The close transition keeps the dialog visible
     after [open] is removed, and without this the layout would switch to a
     row for the rest of the transition. */
  flex-direction: column;
}

.lightbox::backdrop {
  background: #000;
}

.lightbox[open] {
  display: flex;
}

body:has(.lightbox[open]) {
  overflow: hidden;
}

.lightbox-cue {
  display: none;
}

.lightbox-stage {
  display: flex;
  flex: 1 1 0;
  min-height: 0;
  padding: 1rem 5.5rem;
  overflow: hidden;
  touch-action: none;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.35) transparent;
}

.lightbox.zoomed .lightbox-stage {
  overflow: auto;
}

.lightbox-img {
  display: block;
  flex: none;
  margin: auto;
  max-width: calc(100vw - 11rem);
  max-height: calc(100dvh - var(--bar-height) - 2rem);
  object-fit: contain;
  cursor: zoom-in;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
  -webkit-touch-callout: none; /* no iOS long-press callout mid-gesture */
}

.lightbox.zoomed .lightbox-img {
  max-width: none;
  max-height: none;
  cursor: zoom-out;
}

.lightbox.dragging .lightbox-img {
  cursor: grabbing;
}

.lightbox-close {
  position: fixed;
  top: 0.75rem;
  right: 0.75rem;
  z-index: 1;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  border: 0;
  background: none;
  color: rgba(255, 255, 255, 0.75);
  font-size: 2rem;
  line-height: 1;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.lightbox-close::-moz-focus-inner {
  border: 0;
}

.lightbox-close:hover {
  color: #fff;
}

.lightbox-close:focus {
  outline: none;
}

.lightbox-close:focus-visible {
  color: #fff;
}

.lightbox:focus,
.lightbox:focus-visible {
  outline: none;
}

/* Key hints. The shared styles are in structure.css and museum.css. */
.lightbox-hints {
  position: fixed;
  top: calc((100dvh - var(--bar-height)) / 2);
  left: 1.25rem;
  z-index: 1;
  transform: translateY(-50%);
  font-family:
    -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Helvetica Neue",
    Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.lightbox .key {
  --key-ink: #fff;
  --key-highlight: rgba(255, 255, 255, 0.14);
}

.lightbox .hint-label {
  color: #8e8e93;
}

.lightbox-map {
  --map-w: 14px;
  --map-h: 10px;
  --map-gap: 3px;
  --map-pitch: calc(var(--map-h) + var(--map-gap));
  --map-row: 0;
  position: fixed;
  top: calc((100dvh - var(--bar-height)) / 2);
  right: 1.25rem;
  z-index: 1;
  transform: translateY(-50%);
  width: calc(4 * var(--map-w) + 3 * var(--map-gap));
  height: calc(7 * var(--map-h) + 6 * var(--map-gap));
  overflow: hidden;
  pointer-events: none;
  -webkit-mask-image: linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0.12) 0,
    #000 calc(2 * var(--map-pitch)),
    #000 calc(100% - 2 * var(--map-pitch)),
    rgba(0, 0, 0, 0.12) 100%
  );
  mask-image: linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0.12) 0,
    #000 calc(2 * var(--map-pitch)),
    #000 calc(100% - 2 * var(--map-pitch)),
    rgba(0, 0, 0, 0.12) 100%
  );
}

.lightbox-map-grid {
  display: grid;
  grid-template-columns: repeat(4, var(--map-w));
  grid-auto-rows: var(--map-h);
  gap: var(--map-gap);
  transform: translateY(calc((3 - var(--map-row)) * var(--map-pitch)));
}

.lightbox-map-grid > div {
  position: relative;
  box-sizing: border-box;
  border: 1px solid rgba(255, 255, 255, 0.28);
  pointer-events: auto;
  cursor: pointer;
}

.lightbox-map-grid > div::after {
  content: "";
  position: absolute;
  inset: -1.5px;
}

.lightbox-map-grid > div:hover {
  border-color: rgba(255, 255, 255, 0.7);
}

.lightbox-map-grid > div.current {
  border-color: #fff;
}

.lightbox-bar {
  display: flex;
  flex: none;
  align-items: center;
  text-align: center;
  margin: auto;
  max-width: 100%;
  gap: 0 1.5rem;
  height: var(--bar-height);
  padding-block: 0 env(safe-area-inset-bottom, 0px);
  padding-inline: max(1.5rem, calc((100% - 46rem) / 2));
  overflow: hidden;
  background: #000;
  font-family:
    -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Helvetica Neue",
    Helvetica, Arial, sans-serif;
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.005em;
  line-height: 1.25rem;
  white-space: nowrap;
  -webkit-font-smoothing: antialiased;
}

.lightbox-bar > div {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lightbox-bar > div:empty {
  display: none;
}

.lightbox-title {
  color: #fff;
  font-weight: 600;
}

.lightbox-artist {
  color: #8e8e93;
}

.lightbox-year {
  flex: none;
  color: #8e8e93;
}

.lightbox-kind {
  flex: none;
  margin-left: auto;
  color: #8e8e93;
  /* font-weight: 600; */
  text-align: right;
}

/* Touch layout */
@media (max-width: 700px), (pointer: coarse) {
  .lightbox {
    --map-w: 20px;
    --map-h: 10px;
    --map-gap: 2px;
    --bar-height: calc(3.25rem + env(safe-area-inset-bottom, 0px));
    --top-space: calc(
      7 * var(--map-h) + 6 * var(--map-gap) + 1.5rem +
        env(safe-area-inset-top, 0px)
    );
  }

  .lightbox-hints {
    display: none;
  }

  .lightbox-map {
    top: calc(0.75rem + env(safe-area-inset-top, 0px));
    right: auto;
    left: 50%;
    transform: translateX(-50%);
  }

  .lightbox-bar {
    font-size: 0.9375rem;
    line-height: 1.4rem;
  }

  .lightbox-close {
    top: calc(0.5rem + env(safe-area-inset-top, 0px));
    right: calc(0.5rem + env(safe-area-inset-right, 0px));
    width: 2.75rem;
    height: 2.75rem;
  }

  .lightbox-stage {
    padding: 0.5rem 1rem 0.75rem;
  }

  .lightbox-img {
    max-width: calc(100vw - 2rem);
    max-height: calc(100dvh - var(--bar-height) - var(--top-space) - 0.75rem);
  }
}

@media (max-width: 600px) {
  /* Stacked layout: the title on its own line, with the artist, year and
     kind label centered together on the line below. */
  .lightbox {
    --bar-height: calc(4rem + env(safe-area-inset-bottom, 0px));
  }

  .lightbox-bar {
    flex-wrap: wrap;
    justify-content: center;
    align-content: center;
    width: 100%;
    margin: 0;
    gap: 0.1rem 1rem;
    padding-inline: 1rem;
  }

  .lightbox-title {
    flex: 0 0 100%;
  }

  .lightbox-kind {
    margin-left: 0;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .lightbox {
    opacity: 0;
    transition:
      opacity 0.3s ease,
      overlay 0.3s allow-discrete,
      display 0.3s allow-discrete;
  }

  .lightbox[open] {
    opacity: 1;
  }

  /* The backdrop is drawn separately from the dialog, so fading the dialog
     alone leaves a solid black screen until the very end of the exit. It
     needs its own fade. */
  .lightbox::backdrop {
    opacity: 0;
    transition:
      opacity 0.3s ease,
      overlay 0.3s allow-discrete,
      display 0.3s allow-discrete;
  }

  .lightbox[open]::backdrop {
    opacity: 1;
  }

  .lightbox-img {
    transform: scale(0.97);
    transition: transform 0.3s ease;
  }

  .lightbox[open] .lightbox-img {
    transform: none;
  }

  @starting-style {
    .lightbox[open] {
      opacity: 0;
    }

    .lightbox[open] .lightbox-img {
      transform: scale(0.97);
    }

    .lightbox[open]::backdrop {
      opacity: 0;
    }
  }
}
