/* Network-wide mobile contract. Viewport-centred columns prevent nested theme
 * padding from accumulating. Portraits, icons and list indentation stay semantic.
 * The :root scope and most-specific selector in :is() override legacy template
 * rules even when WordPress prints block styles later in the document.
 * Home service cards are an explicit exception: home-blocks.css owns their
 * widths, padding, borders and grids. :where() keeps the existing specificity
 * for other templates, including the later TOC override. */
@media (max-width: 767px) {
    /* Root query units measure the available page width without the scrollbar.
     * 100vw includes a classic scrollbar and shifts centred columns offscreen. */
    :root { container-type: inline-size; }
    :root body.fase-mobile-layout {
        --fase-mobile-gutter: 8px;
        --wp--style--root--padding-left: 8px;
        --wp--style--root--padding-right: 8px;
        margin-inline: 0;
        overflow-x: clip;
    }

    :root body.fase-mobile-layout :is(
        main, .site-main, .page-header, .page-content, .entry-content,
        .wp-block-post-content, .fase-page-opening, .fase-page-excerpt,
        .fase-single-post.has-global-padding .wp-block-post-title,
        .wp-block-post-title, .fase-post-header-meta, .fase-author-byline,
        .wp-block-post-excerpt, .wp-block-post-terms, .wp-block-comments,
        .fase-index-heading, .fase-category-intro, .fase-tag-intro,
        .fase-magazine-fallback, main > .wp-block-query,
        .fase-related-posts, .fase-youtube-video-section,
        .fase-author-card__heading, .fase-post-breadcrumbs,
        .wp-block-yoast-seo-breadcrumbs, .fase-home-hero__content,
        .fase-home-services__inner, .fase-magazine-embed, .fase-shell
    ):where(:not(.fase-home-services, .fase-home-services *)) {
        box-sizing: border-box !important;
        width: calc(100cqw - 16px) !important;
        max-width: none !important;
        margin-left: calc(50% - 50cqw + 8px) !important;
        margin-right: calc(50% - 50cqw + 8px) !important;
        padding-inline: 0 !important;
    }

    /* Panels retain their backgrounds and vertical rhythm. Their text aligns
     * with the same 8px reading edge instead of adding a second outer gutter. */
    :root body.fase-mobile-layout :is(
        .fase-single-post.has-global-padding .fase-author-card,
        .fase-author-card, .fase-author-archive-profile, .fase-linkedin-contact,
        .fase-post-toc, .fase-legal-summary, .fase-legal-toc, .fase-legal-section,
        .fase-contact-intro, .fase-contact-card, .fase-contact-form,
        .fase-home-services__feature-content, .fase-home-service-card__body,
        .fase-home-services__value, .fase-home-value-card,
        .fase-home-step, .fase-home-services__cta
    ):where(:not(.fase-home-services, .fase-home-services *)) {
        box-sizing: border-box !important;
        width: 100cqw !important;
        max-width: none !important;
        margin-left: calc(50% - 50cqw) !important;
        margin-right: calc(50% - 50cqw) !important;
        padding-inline: 8px !important;
        border-inline-width: 0;
    }

    :root body.fase-mobile-layout :is(
        .fase-home-services__grid, .fase-home-services__value-grid,
        .fase-home-services__steps, .fase-home-services__intro,
        .fase-home-services__process-header, .fase-home-services__cta,
        .fase-contact-actions, .fase-related-posts ul
    ):where(:not(.fase-home-services, .fase-home-services *)) { grid-template-columns: minmax(0, 1fr); }

    /* Inset the TOC border by 4px. Border (1px) + padding (3px) keep its
     * text on the existing 8px reading edge. Specificity matches panel rules. */
    :root body.fase-mobile-layout :is(.fase-single-post.has-global-padding .fase-post-toc, .fase-post-toc, .fase-legal-toc) {
        width: calc(100cqw - 8px) !important;
        margin-left: calc(50% - 50cqw + 4px) !important;
        margin-right: calc(50% - 50cqw + 4px) !important;
        padding-inline: 3px !important;
        border-inline-width: 1px !important;
    }

    /* Reduce the theme's 40px table opening without adding a second margin
     * to the table inside a Gutenberg figure. Cell spacing is unchanged. */
    :root body.fase-mobile-layout:is(.single-post, .page) :is(.wp-block-post-content, .page-content, .entry-content) figure.wp-block-table,
    :root body.fase-mobile-layout:is(.single-post, .page) :is(.wp-block-post-content, .page-content, .entry-content) > table {
        margin-block-start: 16px !important;
    }

    /* Editorial media bleeds to both viewport edges, including reading pages
     * whose former specific rule constrained images to the reading column. */
    :root body.fase-mobile-layout :is(
        .fase-single-post.has-global-padding .wp-block-post-featured-image,
        .wp-block-post-featured-image, .fase-page-featured-image,
        figure.wp-block-image, .fase-legal-hero, .fase-related-image,
        .fase-magazine-card__image, .fase-category-intro__image,
        .fase-tag-description-image, .fase-home-service-card__media,
        .fase-home-services__feature-media, .fase-home-services__process-media,
        .fase-youtube-video, .fase-share-bar
    ):where(:not(.fase-home-services, .fase-home-services *)) {
        box-sizing: border-box !important;
        width: 100cqw !important;
        max-width: none !important;
        margin-left: calc(50% - 50cqw) !important;
        margin-right: calc(50% - 50cqw) !important;
        padding-inline: 0 !important;
        border-inline-width: 0;
        border-radius: 0 !important;
    }
    :root body.fase-mobile-layout :is(
        .wp-block-post-featured-image, .fase-page-featured-image,
        figure.wp-block-image, .fase-legal-hero, .fase-tag-description-image
    ):where(:not(.fase-home-services, .fase-home-services *)) img {
        display: block;
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
    }
    :root body.fase-mobile-layout :is(.fase-home-services__feature, .fase-home-service-card):where(:not(.fase-home-services, .fase-home-services *)) { overflow: visible; }
    :root body.fase-mobile-layout figure.wp-block-image figcaption:where(:not(.fase-home-services, .fase-home-services *)) { padding-inline: 8px; }
    :root body.fase-mobile-layout .fase-share-bar { padding-inline: 8px !important; }
    :root body.fase-mobile-layout .fase-mobile-menu :is(nav, .fase-mobile-search) { padding-inline: 8px; }
    :root body.fase-mobile-layout .fase-mobile-menu nav a { padding-inline: 0; }

    /* One mobile H1 rhythm. The banner and post breadcrumb already provide
     * opening space, so their H1 must not add a second top margin. */
    :root body.fase-mobile-layout :is(h1.wp-block-post-title, h1.fase-index-heading, .fase-home-hero__content h1, h1) {
        text-align: center !important;
        margin-block: 24px 16px !important;
        max-width: none !important;
    }
    :root body.fase-mobile-layout.single-post h1,
    :root body.fase-mobile-layout .fase-home-hero__content h1 {
        margin-block-start: 0 !important;
    }
    :root body.fase-mobile-layout:is(.archive, .blog, .search, .error404) main {
        padding-block-start: 24px !important;
    }
    :root body.fase-mobile-layout:is(.archive, .blog, .search, .error404) h1 {
        margin-block-start: 0 !important;
    }

    /* The H1 owns the 16px gap. Rich taxonomy intros contain an extra div;
     * its first paragraph's default margin otherwise adds another 16px. */
    :root body.fase-mobile-layout:is(.category, .tag) .fase-index-heading + :is(.fase-category-intro, .fase-tag-intro),
    :root body.fase-mobile-layout:is(.category, .tag) :is(.fase-category-intro__description, .fase-tag-intro__description) > :first-child,
    :root body.fase-mobile-layout:is(.category, .tag) .fase-category-intro--columns > .fase-category-intro__description:first-child > div:first-child > :first-child {
        margin-block-start: 0 !important;
    }

    /* Editorial H2 only: ordinary pages and taxonomy headings keep alignment. */
    :root body.fase-mobile-layout.single-post :is(.wp-block-post-content, .fase-single-post) h2,
    :root body.fase-mobile-layout.fase-network-page.fase-pillar-page :is(.page-content, .entry-content, .wp-block-post-content) h2 {
        text-align: center !important;
    }
}
