/**
 * Editorial vertical rhythm
 *
 * Keeps paragraphs, lists, headings and embedded content visually separated
 * inside WordPress-authored content without affecting navigation or UI lists.
 */

:where(.page-content, .prose, .omceo-editorial-content) {
  --omceo-flow-space: 1.5rem;
  --omceo-list-space: 1.25rem;
  --omceo-heading-space: 2.75rem;
  --omceo-heading-follow-space: 0.9rem;
}

/* Reset only the direct children generated by the editor. */
:where(.page-content, .prose, .omceo-editorial-content) > :where(p, ul, ol, blockquote, figure, table, pre, .wp-block-image, .wp-block-table, .wp-block-quote) {
  margin-top: 0;
  margin-bottom: var(--omceo-flow-space);
}

/* A BR is an internal line break, not a new paragraph. */
:where(.page-content, .prose, .omceo-editorial-content) br {
  margin: 0;
}

/* Lists need breathing room and readable items. */
:where(.page-content, .prose, .omceo-editorial-content) > :where(ul, ol) {
  margin-top: var(--omceo-list-space);
  margin-bottom: var(--omceo-list-space);
}

:where(.page-content, .prose, .omceo-editorial-content) :where(ul, ol) > li + li {
  margin-top: 0.55rem;
}

:where(.page-content, .prose, .omceo-editorial-content) li > :where(ul, ol) {
  margin-top: 0.65rem;
  margin-bottom: 0.65rem;
}

/* Headings open a new section: more room above, less below. */
:where(.page-content, .prose, .omceo-editorial-content) > :where(h2, h3, h4, h5, h6) {
  margin-top: var(--omceo-heading-space);
  margin-bottom: var(--omceo-heading-follow-space);
  line-height: 1.2;
}

:where(.page-content, .prose, .omceo-editorial-content) > h3 {
  margin-top: 2.25rem;
}

:where(.page-content, .prose, .omceo-editorial-content) > :where(h4, h5, h6) {
  margin-top: 1.9rem;
}

/* The first element must not create an artificial gap at the top. */
:where(.page-content, .prose, .omceo-editorial-content) > :first-child {
  margin-top: 0;
}

/* The final element must not add empty space below the content area. */
:where(.page-content, .prose, .omceo-editorial-content) > :last-child {
  margin-bottom: 0;
}

/* Explicit relationships prevent paragraphs, lists and headings sticking together. */
:where(.page-content, .prose, .omceo-editorial-content) > p + :where(ul, ol),
:where(.page-content, .prose, .omceo-editorial-content) > :where(ul, ol) + p {
  margin-top: var(--omceo-list-space);
}

:where(.page-content, .prose, .omceo-editorial-content) > :where(ul, ol, blockquote, figure, table, pre, .wp-block-image, .wp-block-table, .wp-block-quote) + :where(h2, h3, h4, h5, h6) {
  margin-top: var(--omceo-heading-space);
}

:where(.page-content, .prose, .omceo-editorial-content) > :where(h2, h3, h4, h5, h6) + p,
:where(.page-content, .prose, .omceo-editorial-content) > :where(h2, h3, h4, h5, h6) + :where(ul, ol) {
  margin-top: 0;
}

@media (max-width: 767px) {
  :where(.page-content, .prose, .omceo-editorial-content) {
    --omceo-flow-space: 1.25rem;
    --omceo-list-space: 1rem;
    --omceo-heading-space: 2.25rem;
    --omceo-heading-follow-space: 0.75rem;
  }
}
