[data-highlight-carousel] {
  touch-action: pan-y pinch-zoom;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
}

[data-highlight-carousel][data-dragging] {
  cursor: grabbing;
}

[data-highlight-carousel] [role="button"]:focus-visible {
  outline: 3px solid #faf2e6;
  outline-offset: -6px;
}

[data-intro-painting] {
  cursor: zoom-in;
}

[data-intro-painting]:focus-visible {
  outline: 3px solid #897b66;
  outline-offset: 4px;
}

.highlight-viewer {
  /* Leave part of the native backdrop reachable on every edge. */
  --gutter-x: max(clamp(12px, 2vw, 32px), env(safe-area-inset-left), env(safe-area-inset-right));
  --gutter-y: max(clamp(8px, 2vh, 24px), env(safe-area-inset-top), env(safe-area-inset-bottom));
  --control-size: 44px;
  --arrow-inset: clamp(14px, 3.5vw, 56px);
  --viewer-gap: 6px;
  box-sizing: border-box;
  width: min(1280px, calc(100vw - 2 * var(--gutter-x)));
  max-width: none;
  height: calc(100dvh - 2 * var(--gutter-y));
  max-height: none;
  margin: auto;
  padding: 0;
  border: 0;
  font: 1rem/1.4 "Hedvig Letters Sans", sans-serif;
  overflow: hidden auto;
  overscroll-behavior: contain;
}

.highlight-viewer[open] {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: safe center;
  gap: var(--viewer-gap);
}

.highlight-viewer:not([data-magnified]),
.highlight-viewer:not([data-magnified])::backdrop {
  touch-action: pan-y pinch-zoom;
}

.highlight-viewer button,
.highlight-viewer-controls a {
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--control-size);
  min-height: var(--control-size);
  margin: 0;
  padding: 0 16px;
  font: inherit;
  font-size: 0.9375rem;
  cursor: pointer;
}

.highlight-viewer button {
  border: 0;
  background: transparent;
  color: inherit;
}

.highlight-viewer button:not([data-retry]) {
  width: var(--control-size);
  padding: 0;
}

.highlight-viewer button[data-retry] {
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

.highlight-viewer-controls a {
  padding-inline: 4px;
  color: #eeece7;
  text-decoration: none;
  text-underline-offset: 0.2em;
}

@media (hover: hover) {
  .highlight-viewer button:enabled:hover {
    color: #fff;
  }

  .highlight-viewer-controls a:hover {
    color: #fff;
    text-decoration: underline;
  }
}

.highlight-viewer button:enabled:active {
  color: #bfbcb7;
}

.highlight-viewer button:disabled {
  opacity: 0.55;
  cursor: default;
}

.highlight-viewer :focus-visible {
  outline: 2px solid currentColor;
  outline-offset: -5px;
}

.highlight-viewer-controls a:focus-visible {
  outline-offset: -2px;
  text-decoration: underline;
}

.highlight-viewer-close {
  position: absolute;
  z-index: 2;
  inset-block-start: 0;
  inset-inline-end: 0;
}

.highlight-viewer-image {
  flex: none;
  /* Leave black space for both edge arrows, including on a notched screen. */
  --arrow-gutter: calc(32px + var(--arrow-inset) + max(env(safe-area-inset-left), env(safe-area-inset-right)));
  width: min(100%, calc(100vw - 2 * var(--arrow-gutter)));
  max-height: calc(100% - 2 * (var(--control-size) + var(--viewer-gap)));
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 0;
  /* Keep a painting visible when the caption and buttons need to scroll. */
  min-height: min(64px, 30vh);
  touch-action: pan-y pinch-zoom;
}

.highlight-viewer-painting {
  position: absolute;
  aspect-ratio: inherit;
  max-width: 100%;
  max-height: 100%;
  background: center / contain no-repeat;
  pointer-events: none;
}

.highlight-viewer-bitmap {
  position: absolute;
  inset: 0;
  background: center / contain no-repeat;
}

.highlight-viewer-painting img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.highlight-viewer-neighbor {
  position: absolute;
  background: center / contain no-repeat;
  pointer-events: none;
}

.highlight-viewer[data-sliding] .highlight-viewer-painting::after {
  visibility: hidden;
}

.highlight-viewer[data-zone] {
  background: transparent;
  cursor: pointer;
}

.highlight-viewer[data-zone]::backdrop {
  background-color: #000;
  background-repeat: no-repeat;
  background-size: var(--side-width, 33.333vw) 100%;
  cursor: pointer;
}

.highlight-viewer[data-zone="previous"]::backdrop {
  background-image: linear-gradient(to right, #1b1b1b, #000);
  background-position: left;
}

.highlight-viewer[data-zone="next"]::backdrop {
  background-image: linear-gradient(to left, #1b1b1b, #000);
  background-position: right;
}

.highlight-viewer[data-zone] .highlight-viewer-painting::after {
  content: "";
  position: absolute;
  inset-block: 0;
  width: calc(100% / 3);
  background: linear-gradient(var(--wash-direction), rgb(255 255 255 / 20%), rgb(255 255 255 / 0%) 94%);
}

.highlight-viewer [data-previous],
.highlight-viewer [data-next] {
  position: fixed;
  z-index: 2;
  top: 50%;
  transform: translateY(-50%);
  color: white;
}

.highlight-viewer [data-previous] {
  left: calc(env(safe-area-inset-left) + var(--arrow-inset));
}

.highlight-viewer [data-next] {
  right: calc(env(safe-area-inset-right) + var(--arrow-inset));
}

.highlight-viewer[data-zone="previous"] .highlight-viewer-painting::after {
  --wash-direction: to right;
  left: 0;
}

.highlight-viewer[data-zone="next"] .highlight-viewer-painting::after {
  --wash-direction: to left;
  right: 0;
}

.highlight-viewer-status {
  position: relative;
  margin: 0;
  padding: 4px 10px;
  background: #000;
  color: #d0ccc6;
  text-align: center;
  overflow-wrap: anywhere;
}

.highlight-viewer-image[data-state="loading"] .highlight-viewer-status::before {
  content: "";
  display: block;
  width: 20px;
  height: 20px;
  margin: 0 auto 8px;
  border: 2px solid #595651;
  border-top-color: currentColor;
  border-radius: 50%;
}

/* Keep the live region mounted without reserving space beside a ready image. */
.highlight-viewer-status:empty {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
}

.highlight-viewer [hidden],
.highlight-viewer-image:not([data-state="error"]) [data-retry] {
  display: none;
}

.highlight-viewer-caption {
  flex: none;
  display: grid;
  align-items: center;
  justify-items: center;
  box-sizing: border-box;
  width: 100%;
  min-height: var(--control-size);
  padding-inline: max(4.5rem, var(--control-size));
  text-align: center;
}

.highlight-viewer-caption h2 {
  margin: 0;
  font: inherit;
  font-size: clamp(1rem, 2vw, 1.25rem);
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.highlight-viewer-caption h2:focus {
  outline: none;
}

.highlight-viewer-count {
  position: absolute;
  inset-block-start: 0;
  inset-inline-start: 0;
  line-height: var(--control-size);
  color: #bfbbb5;
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.highlight-viewer-controls {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(8px, 2vw, 20px);
}

.highlight-viewer button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.highlight-viewer-controls button svg {
  width: clamp(32px, 4.5vw, 40px);
  height: auto;
}

.highlight-viewer-controls button path {
  stroke-width: 1.5px;
  vector-effect: non-scaling-stroke;
}

@media (prefers-reduced-motion: no-preference) {
  .highlight-viewer-image[data-state="loading"] .highlight-viewer-status::before {
    animation: highlight-viewer-spin 900ms linear infinite;
  }
}

@keyframes highlight-viewer-spin {
  to { transform: rotate(1turn); }
}
