/* YouTube embed inside the original video-block shell */
/* YouTube embeds break when any ancestor uses transform (settings menu misaligns). */
.page-wrapper[data-namespace='video'] .videos-wrapper {
  transform: none !important;
  height: auto !important;
  overflow: visible !important;
}

.videos-wrapper:has(.video-block.is-youtube) {
  transform: none !important;
}

.video-block.is-youtube:not(.is-ready) .embed {
  background: #000;
}

.video-block.is-youtube:not(.is-ready) .sps-yt-host,
.video-block.is-youtube:not(.is-ready) iframe {
  position: absolute !important;
  inset: 0 !important;
  width: 100% !important;
  height: 100% !important;
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  z-index: 2;
}

.video-block.is-youtube.is-ready .sps-yt-poster,
.video-block.is-youtube.is-ready .sps-yt-poster-play {
  display: none !important;
}

.video-block.is-youtube:not(.is-ready) .embed > video {
  display: none !important;
}

body:has([data-namespace='video']) .video-block.is-youtube:not(.is-ready) .sps-yt-poster,
.video-block.is-youtube:not(.is-ready) .sps-yt-poster {
  display: block !important;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 1;
  pointer-events: none;
}

.video-block.is-youtube.is-ready .sps-yt-host,
.video-block.is-youtube.is-ready iframe {
  opacity: 1;
  visibility: visible;
}

/* A late onError can re-add the fallback link after onReady already fired —
   never let it sit on top of a working player and block clicks. */
.video-block.is-youtube.is-ready .sps-yt-fallback {
  display: none !important;
  pointer-events: none !important;
}

.video-block.is-youtube {
  position: relative;
  width: calc(53vh * 16 / 9) !important;
  max-width: calc(100vw - 4rem) !important;
  height: auto !important;
  margin-left: auto;
  margin-right: auto;
}

/* Taller than strict 16:9 so YT chrome + full video fit without side crop. */
.video-block.is-youtube .embed {
  position: relative;
  background: #000;
  overflow: hidden;
  width: 100% !important;
  height: auto !important;
  padding-top: 0 !important;
  aspect-ratio: 16 / 9;
}

.video-block.is-youtube .sps-yt-poster-play {
  display: none !important;
  pointer-events: none !important;
}

.video-block.is-youtube .sps-yt-poster-play svg {
  width: 1.65rem;
  height: 1.65rem;
  margin-left: 0.15rem;
}

.video-block.is-youtube .sps-yt-poster-play.is-loading {
  opacity: 0.72;
}

.video-block.is-youtube .sps-yt-stage {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

.video-block.is-youtube .sps-yt-host,
.video-block.is-youtube iframe.sps-yt-host {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
  border: 0;
}

.video-block.is-youtube .work-control-grid {
  display: none !important;
}

.video-block.is-youtube.orient-portrait {
  width: auto !important;
  max-width: calc(100vw - 4rem) !important;
}

.video-block.is-youtube.orient-portrait .embed {
  width: auto !important;
  max-width: calc(100vw - 4rem) !important;
  padding-top: 0 !important;
  height: min(53vh, 680px) !important;
  aspect-ratio: 9 / 16 !important;
}

.video-block.is-youtube .sps-yt-fallback {
  position: absolute;
  z-index: 6;
  color: #fff;
  background: rgba(0, 0, 0, 0.72);
  padding: 0.65rem 1rem;
  text-decoration: none;
  font-size: 0.85rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  pointer-events: auto;
}

/* Desktop error link — centered */
@media screen and (min-width: 992px) and (hover: hover) and (pointer: fine) {
  .video-block.is-youtube .sps-yt-fallback {
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
  }
}

/* Desktop / laptop — restore original layout, no scroll, native YT fullscreen */
@media screen and (min-width: 992px) and (hover: hover) and (pointer: fine) {
  html:has([data-namespace='video']),
  html:has([data-namespace='video']) body {
    overflow: hidden !important;
    height: 100% !important;
    max-height: 100vh !important;
    overscroll-behavior: none;
    scrollbar-width: none;
  }

  html:has([data-namespace='video']).lenis,
  html:has([data-namespace='video']).lenis body {
    height: 100% !important;
    overflow: hidden !important;
  }

  html:has([data-namespace='video'])::-webkit-scrollbar {
    display: none;
    width: 0;
    height: 0;
  }

  body:has([data-namespace='video']) .page-wrapper,
  body:has([data-namespace='video']) .videos-grid {
    overflow: hidden !important;
    max-height: 100svh;
  }

  .video-block.is-youtube .sps-yt-mobile-controls {
    display: none !important;
  }

  .videos-wrapper:has(.video-block.is-youtube) {
    overflow: hidden !important;
    transform: none !important;
  }

  .video-block.is-youtube {
    height: 53vh !important;
    width: calc(53vh * 16 / 9) !important;
    max-width: calc(100vw - 4rem) !important;
    margin-left: auto;
    margin-right: auto;
  }

  /* Portrait / Shorts — fit inside shell without clipping */
  .video-block.is-youtube.orient-portrait,
  .video-block.is-youtube[data-youtube-orient='portrait'] {
    height: 53vh !important;
    width: calc(53vh * 9 / 16) !important;
    max-width: calc(100vw - 4rem) !important;
  }

  .video-block.is-youtube.orient-portrait .embed,
  .video-block.is-youtube[data-youtube-orient='portrait'] .embed {
    height: 100% !important;
    width: 100% !important;
    max-width: 100% !important;
    aspect-ratio: 9 / 16 !important;
  }

  /* Fit inside 53vh shell — exact 16:9 so YT menus anchor to controls */
  .video-block.is-youtube:not(.orient-portrait):not([data-youtube-orient='portrait']) .embed {
    height: 100% !important;
    padding-top: 0 !important;
    aspect-ratio: auto !important;
  }

  .video-block.is-youtube .scroll-to-view {
    display: none !important;
  }

  .video-block.is-youtube:fullscreen,
  .video-block.is-youtube:-webkit-full-screen {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 100vw !important;
    height: 100vh !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 0 !important;
    background: #000 !important;
    position: static !important;
    inset: auto !important;
    z-index: auto !important;
  }

  .video-block.is-youtube:fullscreen .embed,
  .video-block.is-youtube:-webkit-full-screen .embed {
    position: relative !important;
    width: 100% !important;
    height: 100% !important;
    padding-top: 0 !important;
  }

  .video-block.is-youtube:fullscreen .sps-yt-stage,
  .video-block.is-youtube:-webkit-full-screen .sps-yt-stage,
  .video-block.is-youtube:fullscreen iframe,
  .video-block.is-youtube:-webkit-full-screen iframe {
    position: absolute !important;
    inset: 0 !important;
    width: 100% !important;
    height: 100% !important;
    transform: none !important;
  }

  /* Never apply mobile wrapper-fs on desktop (only when not in native fullscreen) */
  .video-block.is-youtube.is-fs-active:not(:fullscreen):not(:-webkit-full-screen) {
    position: static !important;
    inset: auto !important;
    width: auto !important;
    height: 53vh !important;
    z-index: auto !important;
  }
}

/* Mobile + touch tablet only (never laptops/desktops with mouse) */
@media screen and (max-width: 991px), screen and (max-width: 1366px) and (hover: none) and (pointer: coarse) {
  body.sps-yt-fs-open {
    overflow: hidden !important;
  }

  .video-block.is-youtube:fullscreen,
  .video-block.is-youtube:-webkit-full-screen,
  .video-block.is-youtube.is-fs-active {
    position: fixed !important;
    inset: 0 !important;
    z-index: 2147483646 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 100vw !important;
    height: 100vh !important;
    max-width: none !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 0 !important;
    background: #000 !important;
    overflow: hidden !important;
  }

  .video-block.is-youtube.is-fs-active .embed,
  .video-block.is-youtube:fullscreen .embed,
  .video-block.is-youtube:-webkit-full-screen .embed {
    position: absolute !important;
    inset: 0 !important;
    width: 100% !important;
    height: 100% !important;
    padding-top: 0 !important;
    max-width: none !important;
    max-height: none !important;
    overflow: hidden !important;
  }

  /* Portrait FS — full viewport width */
  .video-block.is-youtube.is-fs-active:not(.sps-yt-fs-landscape-view) .sps-yt-stage {
    position: absolute !important;
    left: 50% !important;
    top: 50% !important;
    transform: translate(-50%, -50%) !important;
    width: var(--sps-vw, 100vw) !important;
    height: min(var(--sps-vh, 100vh), calc(var(--sps-vw, 100vw) * 0.61)) !important;
    max-width: var(--sps-vw, 100vw) !important;
    max-height: var(--sps-vh, 100vh) !important;
  }

  .video-block.is-youtube.orient-portrait.is-fs-active:not(.sps-yt-fs-landscape-view) .sps-yt-stage,
  .video-block.is-youtube[data-youtube-orient='portrait'].is-fs-active:not(.sps-yt-fs-landscape-view) .sps-yt-stage {
    width: var(--sps-vw, 100vw) !important;
    height: min(var(--sps-vh, 100vh), calc(var(--sps-vw, 100vw) * 16 / 9)) !important;
  }

  /* Landscape FS — full viewport width */
  .video-block.is-youtube.is-fs-active.sps-yt-fs-landscape-view:not(.sps-yt-fs-rotated) .sps-yt-stage {
    position: absolute !important;
    left: 50% !important;
    top: 50% !important;
    transform: translate(-50%, -50%) !important;
    width: var(--sps-vw, 100vw) !important;
    height: min(var(--sps-vh, 100vh), calc(var(--sps-vw, 100vw) * 9 / 16)) !important;
    max-width: var(--sps-vw, 100vw) !important;
    max-height: var(--sps-vh, 100vh) !important;
  }

  /* Landscape FS on portrait device — rotate stage */
  .video-block.is-youtube.is-fs-active.sps-yt-fs-landscape-view.sps-yt-fs-rotated .embed {
    position: absolute !important;
    inset: 0 !important;
    width: 100% !important;
    height: 100% !important;
    padding-top: 0 !important;
    transform: none !important;
  }

  .video-block.is-youtube.is-fs-active.sps-yt-fs-landscape-view.sps-yt-fs-rotated .sps-yt-stage {
    position: absolute !important;
    left: 50% !important;
    top: 50% !important;
    width: var(--sps-vh, 100vh) !important;
    height: var(--sps-vw, 100vw) !important;
    transform: translate(-50%, -50%) rotate(90deg) !important;
    -webkit-transform: translate(-50%, -50%) rotate(90deg) !important;
    transform-origin: center center !important;
  }

  .video-block.is-youtube.is-fs-active .sps-yt-stage iframe,
  .video-block.is-youtube.is-fs-active iframe {
    position: absolute !important;
    inset: 0 !important;
    width: 100% !important;
    height: 100% !important;
  }
  .video-block.is-youtube {
    --sps-yt-btn: 32px;
    --sps-yt-btn-fs-h: 26px;
    --sps-yt-btn-pad: 5px;
    --sps-yt-btn-gap: 6px;
    --sps-yt-btn-bg: rgba(0, 0, 0, 0.58);
    --sps-yt-btn-radius: 4px;
    --sps-yt-fs-bottom: 58px;
    --sps-yt-inline-fs-top: 8px;
    --sps-yt-inline-btn: 24px;
    --sps-yt-inline-btn-h: 18px;
    --sps-yt-fs-right: 4px;
  }

  .video-block.is-youtube .sps-yt-fallback {
    top: auto;
    left: auto;
    bottom: max(8px, env(safe-area-inset-bottom, 0px));
    right: max(8px, env(safe-area-inset-right, 0px));
    transform: none;
    font-size: 0.7rem;
    padding: 0.45rem 0.65rem;
  }

  /* Inline: no custom toolbar — YouTube native controls only */
  .video-block.is-youtube .sps-yt-mobile-toolbar,
  .video-block.is-youtube .sps-yt-fullscreen-btn,
  .video-block.is-youtube .sps-yt-rotate-btn {
    display: none !important;
    visibility: hidden !important;
    pointer-events: none !important;
  }

  .video-block.is-youtube .embed > .sps-yt-fullscreen-btn,
  .video-block.is-youtube .embed > .sps-yt-rotate-btn,
  .video-block.is-youtube .embed > .sps-yt-mobile-toolbar {
    display: none !important;
  }

  .video-block.is-youtube .sps-yt-mobile-controls {
    display: none !important;
  }

  /* iOS: pass touches through wrappers — only iframe receives taps */
  .video-block.is-youtube .embed,
  .video-block.is-youtube .sps-yt-stage,
  .video-block.is-youtube div.sps-yt-host {
    pointer-events: none;
    touch-action: auto;
  }

  .video-block.is-youtube .sps-yt-stage iframe,
  .video-block.is-youtube iframe,
  .video-block.is-youtube .sps-yt-iframe {
    pointer-events: auto !important;
    touch-action: manipulation;
  }

  .video-block.is-youtube .sps-yt-fullscreen-btn svg,
  .video-block.is-youtube .sps-yt-rotate-btn svg {
    display: block;
    width: 100%;
    height: 100%;
    fill: currentColor;
    overflow: visible;
  }

  .video-block.is-youtube .sps-yt-stage iframe,
  .video-block.is-youtube iframe.sps-yt-host {
    position: absolute !important;
    inset: 0 !important;
    width: 100% !important;
    height: 100% !important;
  }

  .video-block.is-youtube.is-fs-active .sps-yt-stage iframe,
  .video-block.is-youtube.is-fs-active iframe,
  .video-block.is-youtube:fullscreen iframe,
  .video-block.is-youtube:-webkit-full-screen iframe {
    pointer-events: auto !important;
    touch-action: manipulation;
  }

  .videos-grid .videos-wrapper:has(.video-block.is-youtube) {
    grid-column: 1 / -1 !important;
    grid-row: 2 !important;
    width: 100% !important;
    max-width: 100% !important;
    justify-self: center !important;
    transform: none !important;
  }

  .video-block.is-youtube {
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    margin-left: auto;
    margin-right: auto;
  }

  .video-block.is-youtube.orient-portrait,
  .video-block.is-youtube[data-youtube-orient='portrait'] {
    width: min(100%, calc(100vw - 8vw)) !important;
    max-width: min(100%, calc(100vw - 8vw)) !important;
    height: auto !important;
    margin-left: auto !important;
    margin-right: auto !important;
  }

  .video-block.is-youtube .embed {
    width: 100% !important;
    height: auto !important;
    padding-top: 0 !important;
    aspect-ratio: auto !important;
    max-width: 100% !important;
    min-height: 270px !important;
    overflow: visible !important;
  }

  .video-block.is-youtube:not(.orient-portrait):not([data-youtube-orient='portrait']) .embed {
    height: max(270px, calc((100vw - 8vw) * 9 / 16)) !important;
    min-height: 270px !important;
  }

  .video-block.is-youtube.orient-portrait .embed,
  .video-block.is-youtube[data-youtube-orient='portrait'] .embed {
    width: 100% !important;
    height: auto !important;
    padding-top: 0 !important;
    aspect-ratio: 9 / 16 !important;
    max-width: 100% !important;
    max-height: min(72vh, 620px) !important;
    min-height: 270px !important;
    overflow: visible !important;
  }
}

@media screen and (max-width: 479px) {
  .video-block.is-youtube {
    --sps-yt-btn: 30px;
    --sps-yt-btn-fs-h: 24px;
    --sps-yt-fs-bottom: 56px;
    --sps-yt-inline-fs-top: 6px;
    --sps-yt-inline-btn: 26px;
    --sps-yt-inline-btn-h: 20px;
  }
}

/* Mobile detail: name top, playback centered, prev/next snug below */
@media screen and (max-width: 991px) {
  .page-wrapper[data-namespace='video'] .videos-grid {
    display: grid !important;
    grid-template-columns: 1fr auto 1fr !important;
    grid-template-rows: auto auto auto !important;
    align-content: start !important;
    align-items: center !important;
    justify-items: stretch !important;
    position: relative !important;
    width: 100% !important;
    min-height: calc(100svh - 5rem) !important;
    height: auto !important;
    padding: 7.5rem 4vw 1.25rem 4vw !important;
    gap: 0.45rem 0 !important;
    box-sizing: border-box !important;
  }

  .page-wrapper[data-namespace='video'] .name-clock__stage.video,
  .page-wrapper[data-namespace='video'] #w-node-b6f4ab0c-9796-fd25-4784-f455bed1f28f-a9fd274a {
    position: relative !important;
    top: auto !important;
    left: auto !important;
    right: auto !important;
    grid-column: 1 / -1 !important;
    grid-row: 1 !important;
    align-self: start !important;
    z-index: 5 !important;
    width: auto !important;
    margin: 0 !important;
    padding-top: 0 !important;
    pointer-events: auto !important;
  }

  .page-wrapper[data-namespace='video'] .name-clock__stage.video .name-clock__line {
    pointer-events: auto !important;
  }

  .page-wrapper[data-namespace='video'] .videos-wrapper,
  .page-wrapper[data-namespace='video'] #w-node-_35cdff82-a509-5c24-ce83-542f52bb439d-a9fd274a {
    grid-column: 1 / -1 !important;
    grid-row: 2 !important;
    width: 100% !important;
    max-width: 100% !important;
    justify-self: center !important;
    align-self: center !important;
    transform: none !important;
    height: auto !important;
    max-height: 100% !important;
    overflow: visible !important;
    position: relative !important;
    z-index: 4 !important;
    margin: 0 !important;
  }

  .page-wrapper[data-namespace='video'] .video-block {
    margin-left: auto !important;
    margin-right: auto !important;
  }

  .page-wrapper[data-namespace='video'] .ctl-btn-wrap:has(.prev),
  .page-wrapper[data-namespace='video'] #w-node-_27c4fd5a-6b56-aa1b-bd0c-53e6db92901e-a9fd274a {
    grid-column: 1 !important;
    grid-row: 3 !important;
    justify-self: start !important;
    align-self: start !important;
    margin-top: 0.15rem !important;
  }

  .page-wrapper[data-namespace='video'] .video-details-indicator,
  .page-wrapper[data-namespace='video'] #w-node-_0d287ff0-bb6d-9e74-cd28-f845024284ab-a9fd274a {
    grid-column: 2 !important;
    grid-row: 3 !important;
    justify-self: center !important;
    align-self: start !important;
    margin-top: 0.15rem !important;
    max-width: none !important;
  }

  .page-wrapper[data-namespace='video'] .ctl-btn-wrap:has(.next),
  .page-wrapper[data-namespace='video'] #w-node-ced9f7e1-4658-bd4b-10d7-9fce5c3c003f-a9fd274a {
    grid-column: 3 !important;
    grid-row: 3 !important;
    justify-self: end !important;
    align-self: start !important;
    margin-top: 0.15rem !important;
  }

  .page-wrapper[data-namespace='video'] .vid-spacer,
  .page-wrapper[data-namespace='video'] #w-node-_4e2c9554-c270-8dc3-be61-575623b6849d-a9fd274a {
    display: none !important;
  }
}

/* Lenis disables iframe taps — always allow YouTube on video detail pages */
html.lenis .page-wrapper[data-namespace='video'] .video-block.is-youtube iframe,
html.lenis.lenis-smooth .page-wrapper[data-namespace='video'] .video-block.is-youtube iframe,
html.sps-native-scroll .page-wrapper[data-namespace='video'] .video-block.is-youtube iframe {
  pointer-events: auto !important;
  touch-action: manipulation;
}
