/* Local Sphinx image viewer. All rules are scoped to avoid theme overrides. */
.didww-image-frame {
  position: relative;
  display: inline-grid;
  max-width: 100%;
  vertical-align: middle;
  line-height: 0;
}

.didww-image-frame > img,
.didww-image-frame > a,
.didww-image-frame > a > img {
  max-width: 100%;
  min-width: 0;
}

.didww-image-frame > a {
  width: 100%;
}

/* PyData centers direct figure children; the viewer replaces that child. */
.bd-article figure > .didww-image-frame,
.bd-article .figure > .didww-image-frame {
  display: grid;
  width: fit-content;
  margin-inline: auto;
}

.bd-article figure.align-left > .didww-image-frame,
.bd-article .figure.align-left > .didww-image-frame,
.didww-image-frame.didww-image-align-left {
  display: grid;
  width: fit-content;
  margin-left: 0;
  margin-right: auto;
}

.bd-article figure.align-right > .didww-image-frame,
.bd-article .figure.align-right > .didww-image-frame,
.didww-image-frame.didww-image-align-right {
  display: grid;
  width: fit-content;
  margin-left: auto;
  margin-right: 0;
}

.didww-image-frame.didww-image-align-center {
  display: grid;
  width: fit-content;
  margin-inline: auto;
}

.didww-image-frame img {
  cursor: zoom-in;
}

.didww-image-expand {
  position: absolute;
  top: 10px;
  right: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 44px;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: rgb(255 255 255 / 96%);
  color: #1e293b;
  font: 500 13px/1.2 var(--pst-font-family-base, system-ui, sans-serif);
  cursor: pointer;
  box-shadow: 0 2px 8px rgb(15 23 42 / 10%);
  opacity: 0;
  transition: opacity 120ms ease;
}

.didww-image-frame:hover .didww-image-expand,
.didww-image-frame:focus-within .didww-image-expand {
  opacity: 1;
}

.didww-image-expand svg,
.didww-image-control svg {
  width: 20px;
  height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

html[data-theme="dark"] .didww-image-expand {
  color: #e2e8f0;
  background: rgb(15 23 42 / 96%);
  border-color: #475569;
}

dialog.didww-image-viewer {
  --viewer-surface: #fff;
  --viewer-text: #1e293b;
  --viewer-muted: #475569;
  --viewer-border: #cbd5e1;
  --viewer-hover: #e2e8f0;
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  overflow: hidden;
  background: transparent;
  color: var(--viewer-text);
  font-family: var(--pst-font-family-base, system-ui, sans-serif);
  overscroll-behavior: contain;
}

dialog.didww-image-viewer::backdrop {
  background: rgb(148 163 184 / 78%);
  backdrop-filter: blur(3px);
}

html[data-theme="dark"] dialog.didww-image-viewer {
  --viewer-surface: #111827;
  --viewer-text: #f1f5f9;
  --viewer-muted: #cbd5e1;
  --viewer-border: #475569;
  --viewer-hover: #334155;
  color-scheme: dark;
}

html[data-theme="dark"] dialog.didww-image-viewer::backdrop {
  background: rgb(2 6 23 / 88%);
}

.didww-image-toolbar {
  position: absolute;
  z-index: 2;
  top: max(16px, env(safe-area-inset-top));
  right: max(16px, env(safe-area-inset-right));
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--viewer-surface);
  border: 1px solid var(--viewer-border);
  border-radius: 12px;
  box-shadow: 0 4px 20px rgb(0 0 0 / 15%);
}

.didww-image-viewer .didww-image-control {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  flex: none;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--viewer-text);
  text-decoration: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.didww-image-control:hover:not(:disabled) {
  background: var(--viewer-hover);
}

.didww-image-control:disabled {
  opacity: 0.35;
  cursor: default;
}

.didww-image-expand:focus-visible,
.didww-image-viewer .didww-image-control:focus-visible {
  outline: 3px solid #0072ce;
  outline-offset: 3px;
}

.didww-image-stage {
  position: absolute;
  inset: max(80px, calc(env(safe-area-inset-top) + 64px))
    max(24px, env(safe-area-inset-right))
    max(96px, calc(env(safe-area-inset-bottom) + 80px))
    max(24px, env(safe-area-inset-left));
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.didww-image-stage .didww-image-full {
  position: absolute;
  left: 50%;
  top: 50%;
  display: block;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: #fff;
  /* The theme dims article images in dark mode; inspection keeps true colors. */
  filter: none !important;
  box-shadow: 0 6px 32px rgb(0 0 0 / 18%);
  transform-origin: center;
  cursor: zoom-in;
  -webkit-user-drag: none;
}

.didww-image-stage.is-zoomed .didww-image-full {
  cursor: grab;
}

.didww-image-stage.is-dragging .didww-image-full {
  cursor: grabbing;
}

.didww-image-caption {
  position: absolute;
  z-index: 2;
  bottom: max(16px, env(safe-area-inset-bottom));
  left: 50%;
  width: max-content;
  max-width: calc(100% - 152px);
  max-height: 72px;
  transform: translateX(-50%);
  overflow: auto;
  padding: 8px 14px;
  border-radius: 10px;
  background: var(--viewer-surface);
  color: var(--viewer-text);
  font-size: 14px;
  line-height: 1.4;
  text-align: center;
  overflow-wrap: anywhere;
}

.didww-image-caption:empty {
  display: none;
}

.didww-image-counter {
  display: block;
  color: var(--viewer-muted);
  font-size: 12px;
}

.didww-image-navigation {
  position: absolute;
  z-index: 2;
  bottom: max(16px, env(safe-area-inset-bottom));
  left: max(16px, env(safe-area-inset-left));
  right: max(16px, env(safe-area-inset-right));
  display: flex;
  justify-content: space-between;
  pointer-events: none;
}

.didww-image-navigation .didww-image-control {
  background: var(--viewer-surface);
  pointer-events: auto;
}

.didww-image-viewer [hidden] {
  display: none !important;
}

.didww-image-status {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--viewer-text);
  text-align: center;
}

@media (hover: none), (pointer: coarse), (max-width: 575.98px) {
  .didww-image-expand {
    opacity: 1;
    top: 6px;
    right: 6px;
    padding: 8px;
  }

  .didww-image-expand span {
    display: none;
  }

  .didww-image-stage {
    inset: max(80px, calc(env(safe-area-inset-top) + 64px))
      max(12px, env(safe-area-inset-right))
      max(96px, calc(env(safe-area-inset-bottom) + 80px))
      max(12px, env(safe-area-inset-left));
  }

  .didww-image-caption {
    max-width: calc(100% - 136px);
    font-size: 13px;
  }
}

@media (max-height: 480px) {
  .didww-image-stage {
    top: 72px;
    bottom: 72px;
  }

  .didww-image-caption {
    max-height: 48px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .didww-image-expand {
    transition: none;
  }
}
