.structure-gallery-page {
  --structure-ease-out: cubic-bezier(.23, 1, .32, 1);
  --structure-press: 140ms;
}

.structure-gallery-page :is(.structure-gallery-intro nav, .structure-chapter) {
  scroll-margin-top: clamp(74px, 11vh, 112px);
}

.structure-gallery-intro nav a[aria-current="location"] {
  color: #035f53;
  border-bottom-color: currentColor;
}

.structure-gallery-intro nav a[aria-current="location"] small { color: inherit; }

.structure-chapter-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px 24px;
  margin-top: clamp(24px, 4vw, 48px);
  padding-top: 12px;
  border-top: 1px solid #0f172a20;
}

.structure-chapter-actions .structure-back-index { margin-top: 0; }

.structure-next-chapter {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  font-size: .875rem;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: .24em;
}

.structure-gallery-page :is(.structure-next-chapter, .structure-back-index, .structure-top-link) .club-icon {
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
}

@media (min-width: 1100px) {
  .structure-chapter:not(#chales) .structure-gallery {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 40px clamp(20px, 2.6vw, 40px);
  }

  .structure-chapter:not(#chales) .structure-gallery__figure:not(.structure-gallery__figure--wide) img {
    height: clamp(230px, 22vw, 360px);
  }
}

.structure-gallery-page .structure-gallery__figure > a img {
  transition: none;
  transform: none;
}

.structure-gallery-page :is(.structure-gallery__figure > a, .structure-gallery-intro nav a, .structure-next-chapter):focus-visible {
  outline: 2px solid #006b5c;
  outline-offset: 4px;
}

.structure-gallery-page .structure-gallery__expand {
  transition: transform var(--structure-press) var(--structure-ease-out);
}

@media (hover: hover) and (pointer: fine) {
  .structure-gallery-page .structure-gallery__figure a:hover .structure-gallery__expand,
  .structure-gallery-page .structure-photo-control[aria-disabled="false"]:hover,
  .structure-gallery-page .structure-photo-close:hover {
    color: #0f172a;
    background: #fb8500;
    border-color: #fb8500;
  }
}

.structure-gallery-page #structure-photo-dialog {
  --structure-photo-gutter: clamp(12px, 2.4vw, 24px);
  --structure-dialog-duration: 200ms;
  --structure-dialog-travel: scale(.97);
  margin: auto;
  padding: var(--structure-photo-gutter);
  max-height: calc(100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  overscroll-behavior: contain;
  opacity: 1;
  transform: none;
  transition: opacity var(--structure-dialog-duration) var(--structure-ease-out),
              transform var(--structure-dialog-duration) var(--structure-ease-out);
}

.structure-gallery-page #structure-photo-dialog::backdrop {
  opacity: 1;
  transition: opacity 200ms var(--structure-ease-out);
}

.structure-gallery-page #structure-photo-dialog.is-closing {
  --structure-dialog-duration: 140ms;
  visibility: visible;
  opacity: 0;
  transform: var(--structure-dialog-travel);
  pointer-events: auto;
}

.structure-gallery-page #structure-photo-dialog.is-closing::backdrop {
  visibility: visible;
  opacity: 0;
  transition-duration: 140ms;
}

.structure-gallery-page #structure-photo-dialog[data-instant],
.structure-gallery-page #structure-photo-dialog[data-instant]::backdrop {
  transition: none;
}

@starting-style {
  .structure-gallery-page #structure-photo-dialog[open]:not([data-instant]) {
    opacity: 0;
    transform: var(--structure-dialog-travel);
  }

  .structure-gallery-page #structure-photo-dialog[open]:not([data-instant])::backdrop { opacity: 0; }
}

.structure-gallery-page .structure-photo-dialog__top {
  min-height: 44px;
  margin-bottom: 10px;
  padding: 0;
}

.structure-gallery-page .structure-photo-dialog__media {
  display: grid;
  place-items: center;
  margin-inline: 0;
  block-size: clamp(100px, 60svh, 620px);
  min-height: 0;
  isolation: isolate;
  touch-action: pan-y pinch-zoom;
}

.structure-gallery-page .structure-photo-dialog__image {
  position: absolute;
  inset: 0;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  margin: auto;
  border-radius: 8px;
  pointer-events: none;
}

.structure-gallery-page .structure-photo-dialog__media [role="status"] {
  z-index: 1;
  inset: auto max(8px, 4%) 8px;
  margin: 0;
  padding: 10px 12px;
  border-radius: 6px;
  text-align: center;
  pointer-events: none;
}

.structure-gallery-page #structure-photo-caption {
  display: grid;
  place-items: center;
  text-align: center;
  margin: 10px 0 6px;
  min-height: 2.6em;
  line-height: 1.3;
}

.structure-photo-dialog__controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.structure-photo-count {
  color: #e1eee8;
  text-align: center;
  font-size: .8rem;
  font-variant-numeric: tabular-nums;
  min-width: 6ch;
}

.structure-photo-control {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  color: #fff;
  background: #123c32;
  border: 1px solid #ffffff59;
  border-radius: 50%;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform var(--structure-press) var(--structure-ease-out);
}

.structure-photo-control .club-icon {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.55;
}

.structure-photo-control[aria-disabled="true"] {
  color: #adc1b9;
  background: transparent;
  border-color: #ffffff30;
  cursor: default;
}

.structure-gallery-page #structure-photo-dialog :focus:not(:focus-visible) { outline: none; }

.structure-gallery-page #structure-photo-dialog :focus-visible {
  outline: 2px solid #ffb85e;
  outline-offset: 4px;
}

.structure-gallery-page #structure-photo-dialog > a {
  display: flex;
  width: fit-content;
  margin: 2px auto 0;
  max-width: 100%;
}

@media (prefers-reduced-motion: no-preference) {
  .structure-gallery-page .structure-photo-control:not([aria-disabled="true"]):is(.is-touch-pressed, :active:not(:focus-visible)),
  .structure-gallery-page [data-structure-photo]:is(.is-touch-pressed, :active:not(:focus-visible)) .structure-gallery__expand {
    transform: scale(.97);
  }
}

@media (max-width: 799px), (max-height: 500px) {
  .structure-gallery-page #structure-photo-dialog { --structure-dialog-travel: translateY(8px); }

  .structure-gallery-page .structure-photo-dialog__media {
    block-size: min(88vw, 52svh, max(84px, calc(100dvh - 260px - env(safe-area-inset-top) - env(safe-area-inset-bottom))));
  }
}

@media (max-width: 360px) {
  .structure-chapter-actions { column-gap: 14px; }
  .structure-next-chapter, .structure-chapter-actions .structure-back-index { font-size: .8rem; }
}

@media (prefers-reduced-motion: reduce) {
  .structure-gallery-page #structure-photo-dialog,
  .structure-gallery-page #structure-photo-dialog::backdrop,
  .structure-gallery-page .structure-photo-control,
  .structure-gallery-page .structure-gallery__expand {
    transition: none;
    transform: none;
  }
}
