/* Demo video dialog (js/video.js): a dimmed backdrop and the video on the darkroom stage, in both themes.
   The dialog itself covers the viewport (transparent), so a click outside the stage lands on it and closes it. */

/* no page scroll under the open dialog; keep the scrollbar's gutter so the page behind does not shift,
   and paint that gutter (the root background) in the backdrop's colour as composited over the page */
html:has(.video-dialog[open]) {
  overflow: hidden; scrollbar-gutter: stable;
  background: color-mix(in srgb, #05070a 86%, var(--bg));
}

.video-dialog {
  --pad-y: 24px;
  --pad-x: 32px;
  --bar: 52px;        /* close button (40) + gap (12) above the stage */
  --frame: 22px;      /* stage padding + border, both sides */
  position: fixed; inset: 0; width: 100%; height: 100%; max-width: none; max-height: none; margin: 0; border: 0;
  padding: max(var(--pad-y), env(safe-area-inset-top, 0px)) max(var(--pad-x), env(safe-area-inset-right, 0px))
           max(var(--pad-y), env(safe-area-inset-bottom, 0px)) max(var(--pad-x), env(safe-area-inset-left, 0px));
  background: transparent; color: var(--stage-fg); overflow: hidden; overscroll-behavior: contain;
}
.video-dialog[open] { display: grid; place-items: center; }
.video-dialog::backdrop {
  background: rgba(5, 7, 10, .86);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}

/* 16:9 up to 1200 px of video, and never taller than the viewport */
.video-box {
  width: min(1200px + var(--frame), 100%, (100vh - 2 * var(--pad-y) - var(--bar) - var(--frame)) * 16 / 9 + var(--frame));
  width: min(1200px + var(--frame), 100%, (100dvh - 2 * var(--pad-y) - var(--bar) - var(--frame)) * 16 / 9 + var(--frame));
  display: grid; gap: 12px;
  pointer-events: none; /* only the stage and the button take clicks; the rest is backdrop */
}
.video-stage {
  position: relative; pointer-events: auto; background: var(--stage); border: 1px solid var(--stage-line); border-radius: 14px; padding: 10px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, .55);
}
.video-stage video {
  display: block; width: 100%; height: auto; aspect-ratio: 16 / 9; object-fit: contain;
  background: #000; border-radius: 8px;
}

.video-close {
  pointer-events: auto; justify-self: end; width: 40px; height: 40px; padding: 0; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer;
  color: #fff; background: rgba(255, 255, 255, .1); border: 1px solid rgba(255, 255, 255, .3);
  transition: background .15s, border-color .15s;
}
.video-close:hover { background: rgba(255, 255, 255, .2); border-color: rgba(255, 255, 255, .6); }
.video-close svg { width: 18px; height: 18px; }
.video-dialog :focus-visible { outline: 2px solid #fdae61; outline-offset: 3px; }

@media (prefers-reduced-motion: no-preference) {
  .video-dialog[open]::backdrop { animation: video-fade .24s ease-out; }
  .video-dialog[open] .video-stage { animation: video-in .34s cubic-bezier(.2, .8, .2, 1); }
  .video-dialog[open] .video-close { animation: video-fade .34s ease-out; }
}
@keyframes video-fade { from { opacity: 0; } }
@keyframes video-in { from { opacity: 0; transform: translateY(14px) scale(.97); } }

/* phones: the video spans the width, no frame */
@media (max-width: 720px) {
  .video-dialog { --pad-x: 0px; --frame: 0px; }
  .video-close { margin-right: var(--gutter-r); }
  .video-stage { padding: 0; border: 0; border-radius: 0; background: #000; }
  .video-stage video { border-radius: 0; }
  .video-stage video:focus-visible { outline-offset: -3px; } /* edge to edge: draw the ring inside */
}

/* phones held sideways: the video takes the full height, × sits in the corner beside it */
@media (max-height: 520px) and (orientation: landscape) {
  .video-dialog { --pad-y: 8px; --pad-x: 64px; --bar: 0px; --frame: 0px; }
  .video-close { position: absolute; top: max(10px, env(safe-area-inset-top, 0px)); right: max(10px, env(safe-area-inset-right, 0px)); margin: 0; }
  .video-stage { padding: 0; border: 0; border-radius: 8px; background: #000; }
  .video-stage video { border-radius: 8px; }
}

/* shown only when the browser cannot play the MP4 */
.video-fallback { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 1; white-space: nowrap;
  font: 600 15px/1 var(--font); color: #fff; background: rgba(5, 7, 10, .78); padding: 12px 18px; border-radius: 999px; text-decoration: none; }
.video-fallback:hover { color: #fff; text-decoration: underline; }
