/*
 * PBK M1.04C — vertical rhythm and surfaces.
 *
 * Gutenberg owns block spacing through theme.json. This stylesheet only
 * bridges the root flow of the classic theme on the front end and styles PBK
 * surfaces without changing nested Gutenberg layouts or the front page.
 *
 * The same file is loaded on the front end and in the block editor.
 */

:where(.pbk-content:not(.pbk-front-page-content), .editor-styles-wrapper) {
  --pbk-surface-padding: clamp(
    var(--wp--preset--spacing--lg, 1.5rem),
    1.125rem + 1.25vw,
    var(--wp--preset--spacing--xl, 2rem)
  );
  --pbk-nested-surface-padding: var(--wp--preset--spacing--lg, 1.5rem);
}

/*
 * Front-end root flow for this classic/hybrid theme.
 *
 * The editor receives the equivalent flow layout from Gutenberg. WordPress
 * does not consistently emit that root rule for a classic theme front end, so
 * .pbk-content mirrors the native flow model: one block gap before every child
 * after the first and no default end margin. Inline per-block spacing selected
 * by an editor has higher cascade priority and remains authoritative.
 */
.pbk-content:not(.pbk-front-page-content) {
  --wp--style--block-gap: var(--wp--preset--spacing--lg, 1.5rem);
}

.pbk-content:not(.pbk-front-page-content) > * {
  margin-block-start: 0;
  margin-block-end: 0;
}

.pbk-content:not(.pbk-front-page-content) > * + * {
  margin-block-start: var(--wp--style--block-gap);
}

/*
 * Background groups are surfaces, not accidental edge-to-edge color fields.
 * Inline padding means the editor made a choice and always wins. Nested
 * surfaces receive a smaller single padding step; no border or shadow is
 * introduced, which avoids a card-inside-card effect.
 */
.pbk-content:not(.pbk-front-page-content)
  > .wp-block-group.has-background:not([style*="padding"]),
.editor-styles-wrapper .is-root-container
  > .wp-block-group.has-background:not([style*="padding"]) {
  padding: var(--pbk-surface-padding);
}

.pbk-content:not(.pbk-front-page-content)
  > .wp-block-group.has-background
  .wp-block-group.has-background:not([style*="padding"]),
.editor-styles-wrapper .is-root-container
  > .wp-block-group.has-background
  .wp-block-group.has-background:not([style*="padding"]) {
  padding: var(--pbk-nested-surface-padding);
}

/* A light nested surface inside a dark group must return to light-surface text. */
:where(.pbk-content, .editor-styles-wrapper)
  :where(.has-dark-background-color, .pbk-stylebook-dark-surface)
  :where(
    .has-canvas-background-color,
    .has-surface-background-color,
    .has-surface-strong-background-color
  ):not(.has-text-color) {
  color: var(--pbk-content-text);
}

:where(.pbk-content, .editor-styles-wrapper)
  :where(.has-dark-background-color, .pbk-stylebook-dark-surface)
  :where(
    .has-canvas-background-color,
    .has-surface-background-color,
    .has-surface-strong-background-color
  ):not(.has-text-color)
  :where(h1, h2, h3, h4, h5, h6, .wp-block-heading) {
  color: var(--pbk-content-text-strong);
}
