/* Page shell uses the wide size; each content block keeps its own reading/alignment choice. */
.journal-page-main {
    max-width: var(--journal-main-width);
    margin: 0 auto;
    padding-block: var(--journal-space-32) 0;
}
.journal-page-main > .journal-title-banner { margin-block-end: var(--journal-space-24); }

.journal-page-main > .journal-page-content { margin: 0; max-width: 100%; line-height: 1.7; }
.journal-page-main + footer { margin-block-start: var(--journal-space-32); }
.journal-page-main + footer .journal-footer { margin-block-start: 0; }

/* Native Post Content layout attributes also produce a flow root in the page editor. */
:is(.journal-page-content, :where(.editor-styles-wrapper.post-type-page .is-root-container.wp-block-post-content.is-layout-flow)) > :where(:not(.alignwide):not(.alignfull):not(.alignleft):not(.alignright)) {
    max-width: var(--journal-reading-width);
    margin-inline: 0;
}
:is(.journal-page-content, :where(.editor-styles-wrapper.post-type-page .is-root-container.wp-block-post-content.is-layout-flow)) > :where(.alignwide, .alignfull) {
    max-width: 100%;
    margin-inline: 0;
}
/* Only default Groups with a requested wide loop may grow; custom constrained sizes stay native. */
:is(.journal-page-content, :where(.editor-styles-wrapper.post-type-page .is-root-container.wp-block-post-content.is-layout-flow)) > .wp-block-group:not([class*='wp-container-core-group-is-layout-']):has(.wp-block-query.alignwide) {
    max-width: var(--wp--style--global--wide-size);
}
:is(.journal-page-content, :where(.editor-styles-wrapper.post-type-page .is-root-container.wp-block-post-content.is-layout-flow)) > :where(h2, h3):not(:first-child) { margin-block-start: var(--journal-space-32); }
:is(.journal-page-content, :where(.editor-styles-wrapper.post-type-page .is-root-container.wp-block-post-content.is-layout-flow)) > :where(p, ul, ol, figure, .wp-block-group, .wp-block-query):not(:first-child) { margin-block-start: var(--journal-space-24); }
:is(.journal-page-content, :where(.editor-styles-wrapper.post-type-page .is-root-container.wp-block-post-content.is-layout-flow)) > :first-child { margin-block-start: 0; }

@media (max-width: 540px) {
    .journal-page-main { padding-block-start: var(--journal-space-24); }
    .journal-page-main + footer { margin-block-start: var(--journal-space-24); }
}

/* Gutenberg's fallback constrained root forces auto margins with !important, even
   for a flow Post Content template. Restore the selected values via editor-only
   variables; this never changes block attributes or nested Group layouts. */
.editor-styles-wrapper.post-type-page .is-root-container > :where(.wp-block:not(.alignleft):not(.alignright)) {
    margin-left: var(--journal-page-margin-left, 0px) !important;
    margin-right: var(--journal-page-margin-right, 0px) !important;
}
.editor-styles-wrapper.post-type-page .is-root-container.wp-block-post-content.is-layout-flow > :where(.journal-editor-align-wide, .journal-editor-align-full) { max-width: 100%; }

/* Mirror the page surface inset in the canvas; owner block widths remain native. */
.editor-styles-wrapper.post-type-page :is(.editor-post-title, .is-root-container) {
    width: var(--journal-main-fluid-width);
    max-width: var(--journal-main-width);
    margin-inline: auto;
}

/* Opt-in prose template: banner and intentionally wide blocks retain the shared shell. */
.journal-page-content.journal-prose-content > :where(:not(.alignwide):not(.alignfull):not(.alignleft):not(.alignright)) {
    max-width: var(--journal-reading-width);
    margin-inline: auto;
}

/* Beat the editor's alignwide-root rule without overriding owner block attributes. */
.editor-styles-wrapper.post-type-page .is-root-container.wp-block-post-content > .wp-block:where(:not(.alignwide):not(.alignfull):not(.journal-editor-align-wide):not(.journal-editor-align-full)) { max-width: var(--journal-reading-width); }
