.note-image-link {
  display: inline-block;
  max-width: 100%;
  border-radius: 6px;
  vertical-align: middle;
  cursor: zoom-in;
}
.note-media > .note-image-link { display: block; }
.note-image-link:focus-visible { outline: 2px solid var(--accent-text); outline-offset: 4px; }
html.note-image-open { overflow: hidden; }

.note-image-viewer:not([open]) { display: none; }
.note-image-viewer {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  box-sizing: border-box;
  margin: 0;
  padding: 12px;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  border: 0;
  background: transparent;
  color: #fff;
}
.note-image-viewer[open] {
  display: grid;
  grid-template: minmax(0, 1fr) / minmax(0, 1fr);
  place-items: center;
}
.note-image-viewer::backdrop { background: rgba(12, 14, 16, .9); }
.note-image-viewer__frame {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  justify-items: end;
  gap: 8px;
  min-width: 0;
  max-width: 100%;
  max-height: 100%;
}
.note-image-viewer__frame img {
  display: block;
  justify-self: center;
  max-width: 100%;
  max-height: 100%;
  min-height: 0;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 8px;
}
.note-image-viewer__tools {
  display: flex;
  align-items: center;
  gap: 8px;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.note-image-viewer__zoom {
  display: flex;
  align-items: center;
  border-radius: 24px;
  background: #232629;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .35);
}
.note-image-viewer__level {
  min-width: 4ch;
  color: #e6e8ea;
  font: 500 .75rem / 1 var(--font);
  font-variant-numeric: tabular-nums;
  text-align: center;
}
.note-image-viewer__viewport { display: contents; }
.note-image-viewer__viewport.is-zoomed {
  display: block;
  justify-self: center;
  min-width: 0;
  min-height: 0;
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  cursor: grab;
}
.note-image-viewer__viewport.is-zoomed:active { cursor: grabbing; }
.note-image-viewer__viewport.is-zoomed img { justify-self: start; max-width: none; max-height: none; border-radius: 0; user-select: none; }
.note-image-viewer__caption {
  justify-self: center;
  max-width: 52ch;
  max-height: 24vh;
  margin: 0;
  overflow: auto;
  overflow-wrap: anywhere;
  color: #e6e8ea;
  font: 400 .875rem / 1.45 var(--font);
  text-align: center;
}
.note-image-viewer button {
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, .35);
  border-radius: 50%;
  background: #232629;
  color: inherit;
  font: 400 1.65rem / 1 system-ui, sans-serif;
  cursor: pointer;
}
.note-image-viewer__zoom button {
  position: relative;
  border: 0;
  background: transparent;
}
.note-image-viewer .note-image-viewer__close { position: relative; font-size: 0; }
.note-image-viewer__close::before,
.note-image-viewer__close::after,
.note-image-viewer__zoom button::before,
.note-image-viewer__zoom-in::after {
  content: "";
  position: absolute;
  inset: 0;
  width: 16px;
  height: 2px;
  margin: auto;
  border-radius: 1px;
  background: currentColor;
}
.note-image-viewer__close::before { transform: rotate(45deg); }
.note-image-viewer__close::after { transform: rotate(-45deg); }
.note-image-viewer__zoom-in::after { transform: rotate(90deg); }
.note-image-viewer.has-photoswipe { overflow: hidden; }
.note-image-viewer.has-photoswipe .note-image-viewer__frame {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  height: 100%;
  position: relative;
  z-index: 1;
  pointer-events: none;
  animation: none;
}
.has-photoswipe .note-image-viewer__tools { align-self: flex-end; pointer-events: auto; }
.has-photoswipe .note-image-viewer__caption { max-width: min(100%, 52ch); pointer-events: auto; }
.has-photoswipe .note-image-viewer__viewport { display: none; }
.note-image-viewer .note-image-viewer__photoswipe.pswp {
  --pswp-root-z-index: 0;
  position: absolute;
  clip-path: inset(var(--note-photo-inset, 0px));
}
.note-image-viewer :focus-visible { outline: 2px solid #fff; outline-offset: 3px; box-shadow: none; }
.note-image-viewer .note-image-viewer__zoom button:focus-visible { outline-offset: -4px; }
.note-image-viewer:focus,
.note-image-viewer .note-image-viewer__frame:focus { outline: none; box-shadow: none; }
.note-image-viewer button[aria-disabled="true"] { opacity: .45; cursor: default; }
@media (hover: hover) {
  .note-image-viewer button:not([aria-disabled="true"]):hover { background: #34383b; }
}
@media (prefers-reduced-motion: no-preference) and (min-width: 321px) {
  html:not([data-lightweight]) .note-image-viewer[open] .note-image-viewer__frame {
    animation: note-image-in 150ms ease-out;
  }
  @keyframes note-image-in {
    from { opacity: 0; transform: translateY(4px); }
  }
}
