/* =========================================================
   PTK HOME BLOCKS v1.2.16 — FORUM-REFERENCE TOP RHYTHM
   Removes shortcode line boxes without changing the body.
========================================================= */

/* The final visible gap between every PTK home block. */
:where(.ptk-home-section, .ptk-home-hero) {
  margin-block-start: 0 !important;
  margin-block-end: var(--ptk-home-block-gap, 18px) !important;
}

/* Match PTK Forum Core: the first plugin surface starts at a true zero margin. */
.ptk-home-hero {
  margin-block-start: 0 !important;
}

/*
 * The Forum wrapper has no top padding. Neutralize only the homepage content
 * shell that owns the Hero, so theme spacing cannot add a second top offset.
 * Other pages and every non-PTK content wrapper remain untouched.
 */
body:is(.home, .front-page)
  :is(.entry-content, .page-content, .wp-block-post-content):has(.ptk-home-hero) {
  margin-block-start: 0 !important;
  padding-block-start: 0 !important;
}

/*
 * WordPress and page builders may add an outer shortcode box. Its inherited
 * line box can create extra vertical space even when the section margin is
 * already correct. Apply the proven 0.05 value only to that outer shell.
 */
:where(
  .wp-block-shortcode,
  .ptk-home-shortcode-wrap,
  .elementor-widget-shortcode,
  .elementor-widget-container
):has(:is(.ptk-home-section, .ptk-home-hero)) {
  margin-block-start: 0 !important;
  margin-block-end: 0 !important;
  padding-block-start: 0 !important;
  padding-block-end: 0 !important;
  line-height: 0.05 !important;
}

/* Restore readable text rhythm inside the actual plugin output. */
:where(
  .wp-block-shortcode,
  .ptk-home-shortcode-wrap,
  .elementor-widget-shortcode,
  .elementor-widget-container
):has(:is(.ptk-home-section, .ptk-home-hero))
  :is(.ptk-home-section, .ptk-home-hero) {
  line-height: 1.5;
}

/* Remove Classic Editor line breaks inserted directly between PTK blocks. */
:is(.ptk-home-section, .ptk-home-hero) + br,
br:has(+ :is(.ptk-home-section, .ptk-home-hero)) {
  display: none !important;
}

/* Remove empty paragraphs (including a paragraph containing one BR) only
   when they sit immediately beside a PTK home block. */
:is(.ptk-home-section, .ptk-home-hero) + p:empty,
:is(.ptk-home-section, .ptk-home-hero) + p:has(> br:only-child),
p:empty:has(+ :is(.ptk-home-section, .ptk-home-hero)),
p:has(> br:only-child):has(+ :is(.ptk-home-section, .ptk-home-hero)) {
  display: none !important;
  margin: 0 !important;
  padding: 0 !important;
  line-height: 0.05 !important;
}

@media (max-width: 768px) {
  :where(.ptk-home-section, .ptk-home-hero) {
    margin-block-end: var(--ptk-home-block-gap, 18px) !important;
  }
}
