/**
 * @file
 * CKEditor 5 edit-page rendering corrections.
 *
 * Two related fixes for how the editor behaves against the fixed admin toolbar
 * while scrolling. See also the sticky-toolbar viewport-offset fix in
 * js/ckeditor5-viewport-offset.js.
 */

/**
 * 1. Stop the page scroll from getting "stuck" while an image is selected.
 *
 * A selected image pins a balloon toolbar that repositions on every scroll,
 * flipping above/below the image as it crosses the viewport. Near the top (where
 * the admin toolbar sets an ~80px offset) those repositions shift layout just
 * enough that the browser's scroll-anchoring snaps the scroll position back,
 * trapping the user: scrolling slowly bounces in place, while scrolling fast
 * jumps clean past it. Disabling scroll anchoring on the scroll container removes
 * the snap-back; the balloon still repositions, the scroll just no longer fights
 * it. Scoped with :has() to pages that actually contain an editor, so front-end
 * scroll anchoring is untouched. `html` and `body` are both listed because which
 * one is the scroll root varies by theme.
 */
html:has(.ck-editor),
body:has(.ck-editor) {
  overflow-anchor: none;
}

/**
 * 2. Keep the sticky editor toolbar *under* the admin toolbar.
 *
 * CKEditor's sticky toolbar (`.ck-sticky-panel__content`, made position:fixed
 * while pinned, then position:absolute as it scrolls out) carries z-index 1000,
 * well above the Drupal admin toolbar's 502. While pinned flush below the admin
 * toolbar that is invisible, but as the editor scrolls out of view the toolbar
 * passes up through the admin toolbar and — winning on z-index — renders on top
 * of it until it is gone. Dropping it below the admin toolbar makes it slide
 * under, as expected. 400 sits below the admin toolbar (502) and above page
 * content.
 *
 * CKEditor sets the 1000 with `.ck.ck-sticky-panel .ck-sticky-panel__content_sticky
 * { z-index: var(--ck-z-panel) }` from a runtime-injected <style> that loads
 * after this file, so an equal-specificity rule would lose on source order. We
 * repeat the `_sticky` modifier class to raise specificity above CKEditor's and
 * win regardless of order. The element only exists (and only carries z-index)
 * while sticky, so no extra scoping is needed.
 */
.ck.ck-sticky-panel .ck-sticky-panel__content.ck-sticky-panel__content_sticky {
  z-index: 400;
}
