/**
 * StoryConfessions Pro — Universal Compatibility Layer
 *
 * This sheet intentionally does not restyle third-party plugins. It exposes a
 * stable color contract and supports the runtime Contrast Guardian, which only
 * corrects elements whose computed foreground/background contrast is broken.
 */

:root {
  /* Stable semantic aliases for first-party and third-party integrations. */
  --sc-color-text: var(--sc-ink);
  --sc-color-muted: var(--sc-muted);
  --sc-color-canvas: var(--sc-paper);
  --sc-color-surface: var(--sc-surface);
  --sc-color-surface-raised: var(--sc-surface-2);
  --sc-color-border: var(--sc-border);
  --sc-color-primary: var(--sc-brand);

  /* Integration aliases: plugins may consume these without knowing theme internals. */
  --storyconfessions-text: var(--sc-ink);
  --storyconfessions-muted: var(--sc-muted);
  --storyconfessions-background: var(--sc-paper);
  --storyconfessions-surface: var(--sc-surface);
  --storyconfessions-border: var(--sc-border);
  --storyconfessions-primary: var(--sc-brand);
}

/* WordPress core background utility classes establish a matching foreground. */
#primary :where(.has-white-background-color) {
  color: #172033;
  color-scheme: light;
}
#primary :where(.has-black-background-color) {
  color: #f7f9ff;
  color-scheme: dark;
}

/* Runtime surface hints. These affect native form control rendering only. */
#primary .sc-auto-surface-light { color-scheme: light; }
#primary .sc-auto-surface-dark { color-scheme: dark; }

/* Runtime contrast repair. The actual foreground is computed in JavaScript. */
html body #primary .sc-auto-contrast {
  color: var(--sc-auto-contrast-fg) !important;
  -webkit-text-fill-color: var(--sc-auto-contrast-fg) !important;
  text-decoration-color: currentColor;
}

html body #primary :where(input, textarea, select).sc-auto-contrast {
  caret-color: var(--sc-auto-contrast-fg) !important;
}

html body #primary :where(input, textarea).sc-auto-contrast::placeholder {
  color: var(--sc-auto-contrast-fg) !important;
  opacity: .62;
  -webkit-text-fill-color: var(--sc-auto-contrast-fg) !important;
}

/* Explicit opt-out for plugin authors or intentionally artistic text. */
#primary [data-sc-contrast-lock],
#primary .sc-contrast-lock {
  /* marker only */
}

@media (forced-colors: active) {
  html body #primary .sc-auto-contrast {
    color: CanvasText !important;
    -webkit-text-fill-color: CanvasText !important;
  }
}

/* 2.2.2 layout safety: readable text without character-by-character wrapping. */
#primary :where(h1,h2,h3,h4,h5,h6,button,label,summary) {
  word-break: normal;
  overflow-wrap: break-word;
}
#primary :where(button,[role="button"]) {
  writing-mode: horizontal-tb;
  text-orientation: mixed;
}

/* 2.2.2 universal text-flow safety. Never split ordinary headings or controls
 * character-by-character when nested inside application/shortcode output. */
#primary :where(h1,h2,h3,h4,h5,h6,button,label,summary) {
  word-break: normal;
  overflow-wrap: break-word;
}
#primary :where(button,[role="button"]) {
  writing-mode: horizontal-tb;
  text-orientation: mixed;
}

/* First-party application shells are interface surfaces, not long-form prose. */
#primary .entry-content :where(.sft2,.stw-ultimate-wrap,.stw-tool-page,[data-sft2-tool],[data-current-tool],[class*="converter-hub" i],[class*="tool-app" i],[class*="game-app" i]) {
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 1rem;
  line-height: 1.6;
}
#primary .sft2-tool-head > :first-child { flex: 1 1 auto; min-width: 0; }
#primary .sft2-tool-head .sft2-fav-large { flex: 0 0 auto; white-space: nowrap; min-width: max-content; }
#primary .sft2-tool-head h1 { max-width: 18ch; }
@media (max-width: 700px) {
  #primary .sft2-tool-head h1 { max-width: none; }
  #primary .sft2-tool-head .sft2-fav-large { min-width: 0; }
}
