/*
 * Rich Content Buttons — buttons.css
 *
 * Front-end styles for [wnmu_buttons] (markup: lib/RichContentButtons.php).
 * Also loaded into the WYSIWYG editor so the in-editor preview matches the
 * page. Enqueued only on pages that render a button.
 *
 *   <div class="com-buttons size-medium align-left">
 *     <a class="com-buttons-btn color-purple" href="…">Label</a>          ← one
 *     <ul class="com-buttons-list" role="list"><li><a …>…</a></li>…</ul>  ← group
 *   </div>
 *
 * CSS class prefix: com-buttons-*. The wrapper deliberately does NOT carry the
 * bare `.com` class: it sits inside a Rich Content block, and `.com + .com`
 * is the templates' between-components spacing rule.
 *
 * Every custom property has a fallback because the editor preview runs in an
 * iframe where the theme's :root tokens (style.css) do not exist.
 *
 * ACCESSIBILITY (WCAG 2.1 AA), measured with the WCAG relative-luminance formula
 * ------------------------------------------------------------------------------
 *  Color        Background   Text    Text contrast   Hover bg     Hover contrast
 *  Purple       #442069      white   12.66:1         #32184e      15.25:1
 *  Blue         #253f8e      white    9.65:1         #1b2f69      12.69:1
 *  Navy         #232c75      white   12.44:1         #171d4f      15.85:1
 *  Deep Purple  #2d0f52      white   16.13:1         #442069      12.66:1
 *  Teal         #11a69c      black    6.97:1         lighter      ≥ 6.97:1
 *  Orange       #f26321      black    6.60:1         lighter      ≥ 6.60:1
 *  Yellow       #fcbc31      black   12.34:1         lighter      ≥ 12.34:1
 *
 *  - White on teal (3.01:1) and white on orange (3.18:1) FAIL 4.5:1, so those
 *    two carry black text. Editors choose a color, never a text color, so a
 *    failing pair cannot be produced. (1.4.3)
 *  - Teal/orange/yellow get a darker border (≥ 4.6:1 on white) so the button
 *    shape still reads on a white page. (1.4.11, beyond the minimum)
 *  - Hover changes the background AND underlines the label, so the state
 *    change does not rely on color alone. (1.4.1)
 *  - Focus: a two-tone ring (dark outline + white gap) that stays visible on
 *    light or dark backgrounds and on every button color. (2.4.7)
 *  - Every size is at least 44px tall. (2.5.5 target size, AAA)
 *  - Labels wrap instead of overflowing; min-height (never height) so 200%
 *    text and custom text spacing still fit. (1.4.4, 1.4.10, 1.4.12)
 *  - Windows High Contrast / forced colors: the 2px border becomes the
 *    visible button edge. Motion only when the user has not asked to reduce it.
 */

/* ── Wrapper + group layout ────────────────────────────────────────────── */

.com-buttons {
  --com-buttons-gap:    0.75rem;
  --com-buttons-radius: 8px;
  --com-buttons-focus:  #1a1a1a;  /* outer focus ring  (17.4:1 on white) */
  --com-buttons-halo:   #ffffff;  /* inner gap         (13.3:1 on the dark theme bg) */

  margin-block: var(--p-margin, 1rem);
}

.com-buttons.align-center { text-align: center; }
.com-buttons.align-right  { text-align: right; }

/* Resets the theme's global ul/li rules (margins, list-style-position). */
.com-buttons .com-buttons-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--com-buttons-gap);
  margin: 0;
  padding: 0;
  list-style: none;
}
.com-buttons .com-buttons-list > li {
  min-width: 0;  /* flex items default to min-width:auto and would refuse to shrink below their longest word */
  max-width: 100%;
  margin: 0;
  padding: 0;
  list-style: none;
}

.com-buttons.align-center .com-buttons-list { justify-content: center; }
.com-buttons.align-right  .com-buttons-list { justify-content: flex-end; }

/* ── The button ─────────────────────────────────────────────────────────
   Two classes deep on purpose: `.is-dark-theme a {}` in style.css is (0,1,1)
   and would otherwise repaint the label in link blue. */

.com-buttons .com-buttons-btn {
  /* Color tokens; each .color-* below overrides them. Default = purple. */
  --btn-bg:       var(--color-primary-purple, #442069);
  --btn-fg:       #ffffff;
  --btn-border:   var(--btn-bg);
  --btn-bg-hover: hsl(269deg 53% 20%);

  /* Size tokens; each .size-* below overrides them. Default = medium. */
  --btn-font-size:  1rem;
  --btn-pad-y:      0.65em;
  --btn-pad-x:      1.35em;
  --btn-min-height: 48px;

  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  max-width: 100%;
  min-height: var(--btn-min-height);
  padding: var(--btn-pad-y) var(--btn-pad-x);
  border: 2px solid var(--btn-border);
  border-radius: var(--com-buttons-radius);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-family: inherit;
  font-size: var(--btn-font-size);
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  overflow-wrap: anywhere;  /* long words/URLs wrap even at 200% text on a phone */
  cursor: pointer;
}

.com-buttons .com-buttons-btn:visited { color: var(--btn-fg); }

.com-buttons .com-buttons-btn:hover {
  background: var(--btn-bg-hover);
  color: var(--btn-fg);
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 0.2em;
}

.com-buttons .com-buttons-btn:focus-visible {
  outline: 3px solid var(--com-buttons-focus);
  outline-offset: 2px;
  box-shadow: 0 0 0 2px var(--com-buttons-halo);
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 0.2em;
}

@media (prefers-reduced-motion: no-preference) {
  .com-buttons .com-buttons-btn { transition: background-color 150ms ease-out; }
}

/* ── Sizes (one per group) ─────────────────────────────────────────────── */

.com-buttons.size-small .com-buttons-btn {
  --btn-font-size:  0.88rem;
  --btn-pad-y:      0.5em;
  --btn-pad-x:      1em;
  --btn-min-height: 44px;
}

.com-buttons.size-large .com-buttons-btn {
  --btn-font-size:  1.2rem;
  --btn-pad-y:      0.75em;
  --btn-pad-x:      1.6em;
  --btn-min-height: 56px;
}

/* ── Institutional colors ──────────────────────────────────────────────── */

.com-buttons .com-buttons-btn.color-blue {
  --btn-bg:       var(--color-primary-blue, hsl(225 59% 35%));
  --btn-bg-hover: hsl(225deg 59% 26%);
}

.com-buttons .com-buttons-btn.color-navy {
  --btn-bg:       var(--color-primary-navy, #232c75);
  --btn-bg-hover: hsl(234deg 54% 20%);
}

/* Already the darkest color, so hover steps LIGHTER, to brand purple. */
.com-buttons .com-buttons-btn.color-deep-purple {
  --btn-bg:       var(--color-primary-deep-purple, #2d0f52);
  --btn-bg-hover: var(--color-primary-purple, #442069);
}

/* Light colors: black text, darker border, hover steps LIGHTER so the black
   text gains contrast instead of losing it. */
.com-buttons .com-buttons-btn.color-teal {
  --btn-bg:       var(--color-primary-teal, hsl(176deg 81% 36%));
  --btn-fg:       #000000;
  --btn-border:   hsl(176deg 81% 26%);
  --btn-bg-hover: hsl(176deg 72% 44%);
}

.com-buttons .com-buttons-btn.color-orange {
  --btn-bg:       var(--color-primary-orange, hsl(19deg 89% 54%));
  --btn-fg:       #000000;
  --btn-border:   hsl(19deg 80% 38%);
  --btn-bg-hover: hsl(19deg 89% 62%);
}

.com-buttons .com-buttons-btn.color-yellow {
  --btn-bg:       var(--color-primary-yellow, hsl(41deg 97% 59%));
  --btn-fg:       #000000;
  --btn-border:   hsl(41deg 90% 32%);
  --btn-bg-hover: hsl(41deg 97% 68%);
}

/* ── Screen-reader-only context text ──────────────────────────────────── */

.com-buttons .com-buttons-sr {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ── Narrow screens: a group stacks into full-width buttons ───────────────
   Easier to tap, and no ragged half-filled rows. A single button keeps its
   natural width. */

@media (width <= 480px) {
  .com-buttons .com-buttons-list { flex-direction: column; }
  .com-buttons .com-buttons-list .com-buttons-btn { width: 100%; }
}

/* ── Dark theme (twentytwentyone .is-dark-theme, page bg #28303d) ─────────
   The dark brand colors nearly vanish against the dark page (≈1.1:1), so they
   get a light edge; the focus ring swaps to light-outside / dark-inside. */

.is-dark-theme .com-buttons {
  --com-buttons-focus: #ffffff;
  --com-buttons-halo:  #1a1a1a;
}

.is-dark-theme .com-buttons .com-buttons-btn:is(.color-purple, .color-blue, .color-navy, .color-deep-purple) {
  --btn-border: hsl(0 0% 100% / 0.8);
}

/* ── Forced colors (Windows High Contrast) ─────────────────────────────── */

@media (forced-colors: active) {
  .com-buttons .com-buttons-btn { border-color: LinkText; }
  .com-buttons .com-buttons-btn:focus-visible { outline-color: Highlight; }
}
