/**
 * WeHow article media captions
 *
 * Scope: core image/gallery captions and preserved core video captions inside
 * single-post content. This file intentionally does not style the custom
 * article gallery, lightbox UI, archive cards, or non-post pages.
 */

/*
 * Support both current Gutenberg markup (`figure.wp-block-image`) and legacy
 * markup (`div.wp-block-image > figure`) without rewriting stored content.
 */
body.single-post .entry-content figure.wp-block-image,
body.single-post .entry-content .wp-block-image > figure {
  position: relative;
}

/* Desktop overlay foundation shared by standalone and gallery images. */
body.single-post .entry-content figure.wp-block-image > figcaption.wp-element-caption,
body.single-post .entry-content .wp-block-image > figure > figcaption.wp-element-caption {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 2;
  display: block;
  box-sizing: border-box;
  width: 100%;
  max-width: 100%;
  margin: 0;
  padding: 2.4em 1em 0.75em;
  overflow-wrap: anywhere;
  color: #fff;
  font-size: 1.1rem;
  line-height: 1.5;
  text-align: center;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.72);
  background: linear-gradient(
    180deg,
    rgba(0, 0, 0, 0) 0%,
    rgba(0, 0, 0, 0.16) 38%,
    rgba(0, 0, 0, 0.54) 100%
  );
  pointer-events: none;
}

/* Avoid stacking WordPress's gallery blur layer with the unified gradient. */
body.single-post .entry-content .wp-block-gallery.has-nested-images figure.wp-block-image:has(> figcaption.wp-element-caption)::before {
  content: none;
}

/* Caption alignment is independent from the image block's own alignment. */
body.single-post .entry-content figure.wp-block-image.is-style-wehow-caption-left > figcaption.wp-element-caption,
body.single-post .entry-content .wp-block-image.is-style-wehow-caption-left > figure > figcaption.wp-element-caption,
body.single-post .entry-content .wp-block-image > figure.is-style-wehow-caption-left > figcaption.wp-element-caption {
  text-align: left;
}

body.single-post .entry-content figure.wp-block-image.is-style-wehow-caption-center > figcaption.wp-element-caption,
body.single-post .entry-content .wp-block-image.is-style-wehow-caption-center > figure > figcaption.wp-element-caption,
body.single-post .entry-content .wp-block-image > figure.is-style-wehow-caption-center > figcaption.wp-element-caption {
  text-align: center;
}

body.single-post .entry-content figure.wp-block-image.is-style-wehow-caption-right > figcaption.wp-element-caption,
body.single-post .entry-content .wp-block-image.is-style-wehow-caption-right > figure > figcaption.wp-element-caption,
body.single-post .entry-content .wp-block-image > figure.is-style-wehow-caption-right > figcaption.wp-element-caption {
  text-align: right;
}

/*
 * Only hover-capable desktop layouts hide captions. Opacity-only animation
 * keeps the gradient bottom permanently aligned with the image bottom edge.
 */
@media (hover: hover) and (pointer: fine) and (min-width: 769px) {
  body.single-post .entry-content figure.wp-block-image > figcaption.wp-element-caption,
  body.single-post .entry-content .wp-block-image > figure > figcaption.wp-element-caption {
    visibility: hidden;
    opacity: 0;
    transition:
      opacity 180ms ease,
      visibility 0s linear 180ms;
  }

  body.single-post .entry-content figure.wp-block-image:hover > figcaption.wp-element-caption,
  body.single-post .entry-content figure.wp-block-image:focus-within > figcaption.wp-element-caption,
  body.single-post .entry-content .wp-block-image > figure:hover > figcaption.wp-element-caption,
  body.single-post .entry-content .wp-block-image > figure:focus-within > figcaption.wp-element-caption {
    visibility: visible;
    opacity: 1;
    transition-delay: 0s;
  }
}

/*
 * Narrow layouts and primary touch pointers restore standalone captions below
 * the image. Gallery captions remain overlays because cropped multi-column
 * tiles do not have a separate vertical caption area in WordPress.
 */
@media (max-width: 768px), (hover: none), (pointer: coarse) {
  body.single-post .entry-content figure.wp-block-image > figcaption.wp-element-caption,
  body.single-post .entry-content .wp-block-image > figure > figcaption.wp-element-caption {
    position: static;
    display: block;
    width: auto;
    max-width: 100%;
    margin: 0.5em 0 0;
    padding: 0;
    color: #8d8d8d;
    font-size: 1.1rem;
    line-height: 1.4;
    text-shadow: none;
    background: none;
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
    transition: none;
  }

  body.single-post .entry-content .wp-block-gallery.has-nested-images figure.wp-block-image > figcaption.wp-element-caption {
    position: absolute;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 2;
    display: block;
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
    margin: 0;
    padding: 2.4em 1em 0.75em;
    color: #fff;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.72);
    background: linear-gradient(
      180deg,
      rgba(0, 0, 0, 0) 0%,
      rgba(0, 0, 0, 0.16) 38%,
      rgba(0, 0, 0, 0.54) 100%
    );
    pointer-events: none;
  }
}

/* Respect reduced-motion preferences without changing caption availability. */
@media (prefers-reduced-motion: reduce) {
  body.single-post .entry-content figure.wp-block-image > figcaption.wp-element-caption,
  body.single-post .entry-content .wp-block-image > figure > figcaption.wp-element-caption {
    transition: none;
  }
}

/*
 * Keep the JustNews player inside the video figure so its caption survives.
 * JustNews applies 16:9 to .wp-block-video itself; move that ratio to the
 * internal player shell so the caption remains in normal document flow.
 */
body.single-post .entry-content figure.wp-block-video {
  height: auto;
  aspect-ratio: auto;
}

body.single-post .entry-content figure.wp-block-video > .wehow-video-player-shell {
  width: 100%;
  aspect-ratio: 16 / 9;
}

body.single-post .entry-content figure.wp-block-video > .wehow-video-player-shell > .art-video-player {
  width: 100%;
  height: 100%;
}

/* Below-media captions share the same typography and muted color. */
body.single-post .entry-content figure.wp-block-video > figcaption.wp-element-caption {
  max-width: 100%;
  color: #8d8d8d;
  font-size: 1.1rem;
  line-height: 1.4;
  overflow-wrap: anywhere;
}
