/**
 * Automatic video modal component styles
 */

:root {
  --modal-max-fixed-block-size: 1280px;
  --modal-max-fixed-inline-size: 1280px;
  --modal-close-button-size: 28px;

  /* SVG icons */
  --icon-video: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 640 640'><path d='M448 128L64 128L64 512L448 512L448 128zM608 480L608 160L496 234.7L496 405.4L608 480.1z'/></svg>");
  --icon-modal-close: url("data:image/svg+xml,<svg viewBox='0 0 31 31' width='30' height='30' fill='none' stroke='white' xmlns='http://www.w3.org/2000/svg'><g stroke-linecap='round' stroke-width='4' transform='translate(2 2)'><path d='m0 27 27-27' transform='matrix(-1 0 0 1 27 0)'/><path d='m0 27 27-27'/></g></svg>");
  --icon-video-play: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' fill='white' viewBox='0 0 512 512'><path d='M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512zM384 256L176 384V128L384 256z'/></svg>");
}


/* ---------- Video link ---------- */

/* Icon next to video links */
a.video-modal-link:not(:has(img))::after {
  content: "" / "Play Video";
  position: relative;
  display: inline-block;
  block-size: 1em;
  inline-size: 1em;
  margin-inline-start: 0.25rem;
  margin-inline-end: 0.125rem;
  vertical-align: middle;
  background-color: var(--color-link); /* Support dark mode */
  -webkit-mask: var(--icon-video) no-repeat 0 50% / contain;
  mask: var(--icon-video) no-repeat 0 50% / contain;
}


/* Thumbnail play button */
a.video-modal-link:has(img) {
  position: relative;
  display: block;
  max-inline-size: fit-content;

  /* Icon */
  &::after {
    content: "" / "Play Video";
    display: block;
    position: absolute;
    z-index: 1;
    top: calc(50% - 32px);
    left: calc(50% - 32px);
    block-size: 64px;
    inline-size: 64px;
    background-color: rgb(0 0 0 / 0.15);
    background-image: var(--icon-video-play);
    background-repeat: no-repeat;
    background-size: 100% auto;
    background-position: 50% 50%;
    opacity: 0.85;
    border-radius: 100%;
    box-shadow: 0 0 2px rgb(0 0 0 / 0.1);
    transition: scale 200ms ease-out,
                opacity 200ms ease-out;
  }
  &:hover::after {
    opacity: 0.95;
    scale: 1.15;
  }
}


/* ---------- Video modal ---------- */

#video-modal {
  /* Allow alternate ratio */
  aspect-ratio: var(--aspect-ratio, 16 / 9);

  /* Portrait orientation */
  --modal-max-block-size: min(100dvh - var(--modal-close-button-size, 2rem) * 4, var(--modal-max-fixed-block-size, 1280px));
  --modal-max-inline-size: min(100dvw - 2rem, var(--modal-max-fixed-inline-size, 1280px));

  max-block-size: var(--modal-max-block-size);
  max-inline-size: var(--modal-max-inline-size);
  inline-size: 100%;
  padding: 0;
  border: none;
  background: var(--black, black);
  color: var(--white, white);
  box-shadow: 0 0 0.5rem 0.1rem rgb(0 0 0 / 0.25);
  overflow: visible;
}

@media (orientation: landscape) {
  /* Push away from close button */
  #video-modal {
    --modal-max-block-size: min(100dvh - 2rem, var(--modal-max-fixed-block-size, 1280px));
    --modal-max-inline-size: min(100dvw - var(--modal-close-button-size) * 4, var(--modal-max-fixed-inline-size, 1280px));
  }
}

#video-modal::backdrop {
  background: rgb(0 0 0 / 0.8);
  backdrop-filter: blur(2px);
}


/* Fade animation */
@keyframes modal-video-show {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
@keyframes modal-video-hide {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

@media (prefers-reduced-motion: no-preference) {
  /* Slide animation */
  @keyframes modal-video-show {
    from {
      transform: translateY(20dvh);
      opacity: 0;
    }
    to {
      transform: translateY(0);
      opacity: 1;
    }
  }
  @keyframes modal-video-hide {
    from {
      transform: translateY(0);
      opacity: 1;
    }
    to {
      transform: translateY(20dvh);
      opacity: 0;
    }
  }
}

/* Show dialog */
#video-modal[open] {
  animation: modal-video-show 300ms ease-out;
}
#video-modal[open]::backdrop {
  animation: fadein 300ms ease-out;
}

/* Hide dialog */
#video-modal.modal-close {
  animation: modal-video-hide 200ms ease-in;
}
#video-modal.modal-close::backdrop {
  animation: fadeout 200ms ease-in;
}


/* Stretch iframe */
#video-modal iframe {
  display: block;
  max-inline-size: none;
  block-size: 100%;
  inline-size: 100%;
  margin: 0;
  padding: 0;
  border: none;
}


/* Close button */
#video-modal .video-modal-close {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  position: absolute;

  /* Portrait */
  top: calc(var(--modal-close-button-size) * -1.5);
  right: 0;

  block-size: var(--modal-close-button-size);
  inline-size: var(--modal-close-button-size);
  margin: 0;
  padding: 0;
  border: none;
  cursor: pointer;
  background: transparent;
}

@media (orientation: landscape) {
  #video-modal .video-modal-close{
    /* Move to right edge on landscape */
    top: 0;
    right: calc(var(--modal-close-button-size) * -1.5);
  }
}

#video-modal .video-modal-close::after {
  /* Use ::after so focus ring does not get hidden by mask */
  content: "" / "Close";
  display: block;
  block-size: 100%;
  inline-size: 100%;

  background-color: var(--gray-3); /* Use mask to change color on hover */
  -webkit-mask: var(--icon-modal-close) no-repeat 0 50% / 100% auto;
  mask: var(--icon-modal-close) no-repeat 0 50% / 100% auto;
  transition: background-color 200ms;
}

#video-modal .video-modal-close:is(:hover, :active, :focus-visible)::after {
  background-color: var(--white, white);
}
