/*
 * WordPress 7 compatibility for the CMA theme.
 *
 * The site moved from WordPress 5.5 (AWS/Bedrock) to WordPress 7.1 (WP Engine). Core block markup and
 * CSS changed in between, and the theme's app.css still targets the 5.5 output. These rules restore the
 * 5.5 rendering where the client noticed a difference. Item numbers refer to the WP Engine migration
 * review triage doc. Keep each rule scoped to the new core markup.
 *
 * Hand-written on purpose: app.css is a Tailwind/PurgeCSS build that purges against the Genesis parent
 * theme, which isn't in this repo, so rebuilding it can drop classes the site uses.
 * Loaded after cma-css on the front end, and inside the block editor canvas (see inc/gutenberg.php).
 */

/* Item 1 (tables). WP 6+ moved table borders and padding from the opt-in theme.css into the block's base
   style: `.wp-block-table td, th { border: 1px solid; padding: .5em }`. That out-specifies the theme's
   `td, th { padding: .5rem 1rem }`, so cells lost their horizontal padding. */
.wp-block-table td,
.wp-block-table th {
    padding: 0.5rem 1rem;
}

/* Item 1 (tables). New in WP 6+: a 3px rule under the header row and above the footer row.
   The theme's tables never had them. */
.wp-block-table thead {
    border-bottom-width: 0;
}

.wp-block-table tfoot {
    border-top-width: 0;
}

/* Item 1 (tables). WP 5.5 broke long words in fixed-layout tables; WP 7 dropped the rule. */
.wp-block-table .has-fixed-layout td,
.wp-block-table .has-fixed-layout th {
    word-break: break-word;
}

/* Item 2 (YouTube size). Older posts store embeds as `core-embed/youtube`, a block name WP 7 no longer
   registers. WP 7 loads block CSS only for the registered blocks on each page, so the embed block's
   styles (relative wrapper and 16:9 sizing) never load and the player falls back to the oEmbed's fixed
   width/height. These are core's own embed rules, copied from wp-includes/blocks/embed/style.css. */
.wp-block-embed {
    margin-bottom: 1em;
    overflow-wrap: break-word;
}

.wp-block-embed iframe {
    max-width: 100%;
}

.wp-block-embed__wrapper {
    position: relative;
}

.wp-embed-responsive .wp-has-aspect-ratio .wp-block-embed__wrapper::before {
    content: "";
    display: block;
    padding-top: 50%;
}

.wp-embed-responsive .wp-has-aspect-ratio iframe {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.wp-embed-responsive .wp-embed-aspect-21-9 .wp-block-embed__wrapper::before { padding-top: 42.85%; }
.wp-embed-responsive .wp-embed-aspect-18-9 .wp-block-embed__wrapper::before { padding-top: 50%; }
.wp-embed-responsive .wp-embed-aspect-16-9 .wp-block-embed__wrapper::before { padding-top: 56.25%; }
.wp-embed-responsive .wp-embed-aspect-4-3 .wp-block-embed__wrapper::before { padding-top: 75%; }
.wp-embed-responsive .wp-embed-aspect-1-1 .wp-block-embed__wrapper::before { padding-top: 100%; }
.wp-embed-responsive .wp-embed-aspect-9-16 .wp-block-embed__wrapper::before { padding-top: 177.77%; }
.wp-embed-responsive .wp-embed-aspect-1-2 .wp-block-embed__wrapper::before { padding-top: 200%; }

/* Item 5 (Pinniped Pier button not centred). WP 6+ renders a Buttons block as a flex row
   (`is-layout-flex`). Older content marks a centred row with `aligncenter`, which only sets text-align and
   has no effect on a flex row. New content uses `is-content-justification-center`, which core handles. */
.wp-block-buttons.aligncenter.is-layout-flex {
    justify-content: center;
}

/* Item 5. The theme spaces buttons with `margin-right: 1rem` and relied on WP 5.5's `:last-child` reset,
   which WP 7 dropped. Without it the last button carries 1rem on its right and sits off centre. Core's flex
   `gap` would also add to the theme margin, so turn it off to keep the 5.5 spacing. */
.wp-block-buttons.is-layout-flex {
    gap: 0;
}

.wp-block-buttons.is-layout-flex > .wp-block-button:last-child {
    margin-right: 0;
}

/* Item 6 (Pinniped Pier "harbor seals" link white instead of dark blue). A link in a paragraph that has a
   text colour should take that colour. WP 5.5 did this with `p.has-text-color a` (specificity 0,1,2),
   which beat the theme's `.is-style-experience-group a` (white). WP 7 wraps it in :where() (specificity 0),
   so the theme's white wins. Same specificity as 5.5; paragraphs with their own link colour are excluded. */
p.has-text-color:where(:not(.has-link-color)) a {
    color: inherit;
}

/* Items 6 and 9: the same fix in the block editor, where gutenberg.css scopes the white link colour as
   `.editor-styles-wrapper .is-style-experience-group a` (0,2,2). Equal specificity, loaded later, so it wins.
   Has no effect on the front end, which has no .editor-styles-wrapper. */
.editor-styles-wrapper p.has-text-color:where(:not(.has-link-color)) a {
    color: inherit;
}

/* Item 6, related (not in the triage list; found while checking the harbor seals paragraph). WP 6+ prints
   global styles that force the editor font-size presets with !important:
   `.has-large-font-size { font-size: var(--wp--preset--font-size--large) !important }`, with the values
   from inc/gutenberg.php (Large 24px, XL 36px). On WP 5.5 those values were only used in the editor, and
   the front end used the theme's responsive sizes (Large 18/20px, XL 20/24px). Point the presets at the
   theme's sizes so text with a font-size class renders as before. Small (12px) and Normal (16px) already match. */
body {
    --wp--preset--font-size--large: 1.125rem;
    --wp--preset--font-size--xlarge: 1.25rem;
}

@media (min-width: 768px) {
    body {
        --wp--preset--font-size--large: 1.25rem;
        --wp--preset--font-size--xlarge: 1.5rem;
    }
}

/* Item 6, related: the same global-styles override for colours. The theme's `.has-white-color` and
   `.has-black-color` (and background versions) were pure #fff / #000 on the 5.5 front end. The palette in
   inc/gutenberg.php defines them as #f9f8f6 / #1A202C, which WP 7 now forces on the front end. Every other
   palette colour already matches. Not on admin pages (body.wp-admin), so the editor's swatches are unchanged;
   the editor canvas body has no .wp-admin, so it matches the front end. */
body:not(.wp-admin) {
    --wp--preset--color--white: #fff;
    --wp--preset--color--black: #000;
}

/* Columns (not in the triage list; found by the style-parity suite on /visit/visit-info/ and /my-day/).
   WP 6+ lays out Columns as a flex row with `gap: 2em` (32px). The theme already spaces columns with
   `.wp-block-column:not(:first-child) { margin-left: 1.5rem }`, so the gaps doubled (56px vs 24px) and every
   column got narrower. Drop the core gap to keep the 5.5 spacing. */
.wp-block-columns.is-layout-flex {
    gap: 0;
}
