/* Force post content to be 100% to support alignwide/alignfull properly */
.entry-content,
.wp-block-post-content {
    max-width: 100%;
}

/* Ensure global padding class actually applies padding if not handled by block supports */
body .wp-block-group.has-global-padding,
body .has-global-padding {
    padding-right: 20px;
    padding-left: 20px;
}

/* Force padding on blocks with background color, overriding potential resets */
body .wp-block-group.has-background,
body .wp-block-column.has-background,
body :where(.wp-block-group.has-background) {
    padding: 1.25em 2.375em;
}

/* Sticky Footer Layout - Ensure footer stays at the bottom */
body .wp-site-blocks {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Make the content area expand to fill space */
body .wp-site-blocks>main {
    flex-grow: 1;
}

/* Add forced gap above footer */
body .wp-site-blocks>footer.wp-block-group,
body .wp-site-blocks>.wp-block-template-part:last-child {
    margin-top: 160px !important;
    width: 100%;
}

/* Mobile Content Padding */
@media screen and (max-width: 768px) {

    /* Target standard constraint blocks to add side margins on mobile */
    body .is-layout-constrained:not(.wp-block-group)> :where(:not(.alignleft):not(.alignright):not(.alignfull)),
    body .wp-block-group.is-layout-constrained.alignfull> :where(:not(.alignleft):not(.alignright):not(.alignfull)),
    body .wp-block-group.is-layout-constrained.alignwide> :where(:not(.alignleft):not(.alignright):not(.alignfull)),
    body main.is-layout-constrained> :where(:not(.alignleft):not(.alignright):not(.alignfull)) {
        margin-left: 20px !important;
        margin-right: 20px !important;
        width: auto !important;
        max-width: calc(100% - 40px) !important;
        box-sizing: border-box !important;
    }

    /* Section Spacing (Mobile) */
    body main.wp-block-group.is-layout-constrained> :where(section, .js-simple-slider) {
        margin-block-end: 60px;
        margin-block-start: 60px;
    }

    /* Adjust background block padding for mobile */
    body .wp-block-group.has-background,
    body .wp-block-column.has-background,
    body :where(.wp-block-group.has-background) {
        padding: 1em 1.25em;
    }

    /* Force Grid to 1 Column on Mobile */
    body .is-layout-grid {
        grid-template-columns: 1fr;
        /* Row gap 1.5em, Column gap 0 */
        margin-left: 0;
        margin-right: 0;
    }

    /* SP Custom Grid Columns */
    body .is-layout-grid.has-sp-grid-columns {
        grid-template-columns: repeat(var(--sp-grid-columns), minmax(0, 1fr)) !important;
    }

    /* SP Custom Grid Gaps */
    body .is-layout-grid.has-sp-grid-column-gap {
        column-gap: var(--sp-grid-column-gap) !important;
    }

    body .is-layout-grid.has-sp-grid-row-gap {
        row-gap: var(--sp-grid-row-gap) !important;
    }

    /* SP Custom Flex Layout */
    body .is-layout-flex.has-sp-justify-content {
        justify-content: var(--sp-justify-content) !important;
    }

    body .is-layout-flex.has-sp-align-items {
        align-items: var(--sp-align-items) !important;
    }

    body .is-layout-flex.has-sp-flex-direction {
        flex-direction: var(--sp-flex-direction) !important;
    }

    /* SP Custom Font Size */
    body .has-sp-font-size {
        font-size: var(--sp-font-size) !important;
    }

    /* Reset absolute position and translate on Mobile if requested */
    body .is-reset-on-sp {
        position: static !important;
        transform: none !important;
        top: auto !important;
        right: auto !important;
        bottom: auto !important;
        left: auto !important;
        margin-top: 0 !important;
        margin-right: 0 !important;
        margin-bottom: 0 !important;
        /* Resetting margins might be safer if translate was used for centering */
        margin-left: 0 !important;
    }
}

/* PC/Tablet Content Padding (Small screens) */
@media screen and (min-width: 769px) {

    /* Ensure content has some buffer (40px side gaps) when screen is narrower than max content width */
    body .is-layout-constrained:not(.wp-block-group)> :where(:not(.alignleft):not(.alignright):not(.alignfull):not(.alignwide)),
    body .wp-block-group.is-layout-constrained.alignfull> :where(:not(.alignleft):not(.alignright):not(.alignfull):not(.alignwide)),
    body .wp-block-group.is-layout-constrained.alignwide> :where(:not(.alignleft):not(.alignright):not(.alignfull):not(.alignwide)),
    body main.is-layout-constrained> :where(:not(.alignleft):not(.alignright):not(.alignfull):not(.alignwide)) {
        max-width: min(1080px, calc(100% - 200px)) !important;
        margin-left: auto !important;
        margin-right: auto !important;
    }

    /* Buffer alignwide blocks if they would touch edges on smaller screens */
    body .is-layout-constrained>.alignwide {
        max-width: min(1280px, calc(100% - 200px)) !important;
        margin-left: auto !important;
        margin-right: auto !important;
    }

    /* Section Spacing (PC/Tablet) - Increase gap */
    body main.wp-block-group.is-layout-constrained> :where(section, .js-simple-slider) {
        margin-block-end: 80px;
        margin-block-start: 80px;
    }
}

/* Alignwide Block Padding */
body .is-layout-constrained>.alignwide {
    padding-left: 20px;
    padding-right: 20px;
    box-sizing: border-box;
}

/* Target alignwide blocks broadly for both PC and SP */
body .is-layout-constrained .alignwide,
body .alignwide {
    padding-left: 20px !important;
    padding-right: 20px !important;
    box-sizing: border-box !important;
}

/* --------------------------
   Display Visibility Utilities
   -------------------------- */

/* PC Only: Hide on SP */
@media screen and (max-width: 768px) {
    .u-visible-pc-only {
        display: none !important;
    }
}

/* SP Only: Hide on PC */
@media screen and (min-width: 769px) {
    .u-visible-sp-only {
        display: none !important;
    }
}