/* Buttons.
   Filled buttons (primary, danger) carry layered depth: top highlight, bottom depth line, contact shadow and a glow in
   the button's own colour, under a faint sheen. Outlined buttons carry a lighter version. Text buttons, toggles and
   anything with data-elevation="flat" stay flat: depth means "this is an action", not "this is selected".
   Every value is a btn-* token (tokens/tokens.css). */
@layer components {
  /* Depth recipes, declared once for every raised control. --btn-color is the control's own colour:
     it fills filled buttons, tints their glow and colours the focus ring. */
  :where(.c-button, .c-share__link, .c-lightbox__btn, .blk-embed__play) {
    --btn-color: var(--brand);
    --btn-raise: inset 0 1px 0 var(--btn-highlight), inset 0 -2px 0 var(--btn-depth-line), var(--btn-contact), var(--btn-glow-rest) color-mix(in srgb, var(--btn-color) var(--btn-glow-strength), transparent);
    --btn-raise-hover: inset 0 1px 0 var(--btn-highlight), inset 0 -2px 0 var(--btn-depth-line), var(--btn-contact-hover), var(--btn-glow-hover) color-mix(in srgb, var(--btn-color) var(--btn-glow-strength-hover), transparent);
    --btn-raise-quiet: inset 0 1px 0 var(--btn-quiet-highlight), var(--btn-quiet-contact);
    --btn-raise-quiet-hover: inset 0 1px 0 var(--btn-quiet-highlight), var(--btn-quiet-hover);
  }

  /* On dark grounds the same recipes read the -on-dark values. A dark theme assigns those values to the base tokens instead. */
  :where(.c-footer, .c-preview, .c-lightbox, .is-on-dark) :where(.c-button, .c-share__link, .c-lightbox__btn, .blk-embed__play) {
    --btn-highlight: var(--btn-highlight-on-dark);
    --btn-depth-line: var(--btn-depth-line-on-dark);
    --btn-contact: var(--btn-contact-on-dark);
    --btn-contact-hover: var(--btn-contact-hover-on-dark);
    --btn-pressed: var(--btn-pressed-on-dark);
    --btn-glow-strength: var(--btn-glow-strength-on-dark);
    --btn-glow-strength-hover: var(--btn-glow-strength-hover-on-dark);
    --btn-hover-brightness: var(--btn-hover-brightness-on-dark);
    --btn-quiet-highlight: var(--btn-quiet-highlight-on-dark);
    --btn-quiet-contact: var(--btn-quiet-contact-on-dark);
    --btn-quiet-hover: var(--btn-quiet-hover-on-dark);
    --btn-quiet-pressed: var(--btn-quiet-pressed-on-dark);
    --btn-focus: var(--focus-on-dark);
  }
  :where(.c-footer, .c-preview, .c-lightbox, .is-on-dark) .c-button--text { --btn-color: var(--accent-on-brand); --btn-color-hover: var(--on-inverse); }

  /* Outlined (default) button: lighter depth, no movement, no sheen. */
  .c-button { display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2); min-height: var(--tap); padding: var(--space-2) var(--space-4); border: 1px solid var(--border-strong); border-radius: var(--radius-md); background-color: var(--surface); color: var(--btn-color); font-family: var(--font-sans); font-size: var(--fs-md); font-weight: var(--fw-semibold); line-height: var(--lh-snug); text-decoration: none; text-align: center; box-shadow: var(--btn-raise-quiet); transition: background-color var(--dur-2), border-color var(--dur-2), color var(--dur-2), box-shadow var(--dur-2), filter var(--dur-2), translate var(--dur-2); }
  .c-button:focus-visible, .c-button.is-focus { outline: var(--focus-width) solid var(--btn-focus, var(--btn-color)); outline-offset: var(--focus-offset); }

  /* Filled buttons: layered depth. */
  .c-button--primary, .c-button--danger { border-color: var(--btn-color); background-color: var(--btn-color); background-image: linear-gradient(to bottom, var(--btn-sheen), transparent); color: var(--on-brand); box-shadow: var(--btn-raise); }
  .c-button--danger { --btn-color: var(--danger); }

  /* Text button: flat. */
  .c-button--text { padding-inline: 0; border-color: transparent; background: none; box-shadow: none; text-decoration: underline; }
  .c-button--block { display: flex; width: 100%; }

  /* Hover, only where a pointer can hover, so a tap does not leave a button lifted. .is-hover forces the state for documentation. */
  @media (hover: hover) {
    .c-button:hover { background-color: var(--surface-alt); border-color: var(--btn-color); color: var(--btn-color-hover, var(--brand-strong)); box-shadow: var(--btn-raise-quiet-hover); }
    .c-button--primary:hover, .c-button--danger:hover { background-color: var(--btn-color); color: var(--on-brand); box-shadow: var(--btn-raise-hover); filter: brightness(var(--btn-hover-brightness)); translate: 0 calc(-1 * var(--btn-lift)); }
    .c-button--text:hover { background: none; border-color: transparent; box-shadow: none; }
  }
  .c-button.is-hover { background-color: var(--surface-alt); border-color: var(--btn-color); color: var(--btn-color-hover, var(--brand-strong)); box-shadow: var(--btn-raise-quiet-hover); }
  .c-button--primary.is-hover, .c-button--danger.is-hover { background-color: var(--btn-color); color: var(--on-brand); box-shadow: var(--btn-raise-hover); filter: brightness(var(--btn-hover-brightness)); translate: 0 calc(-1 * var(--btn-lift)); }
  .c-button--text.is-hover { background: none; border-color: transparent; box-shadow: none; }

  /* Pressed: the outer shadows give way to an inner one; filled buttons sink and the sheen turns into a darkening. */
  .c-button:active, .c-button.is-active { background-color: var(--sponsored-bg); box-shadow: var(--btn-quiet-pressed); }
  .c-button--primary:active, .c-button--primary.is-active, .c-button--danger:active, .c-button--danger.is-active { background-color: var(--btn-color); background-image: linear-gradient(to bottom, var(--btn-sheen-pressed), transparent); box-shadow: var(--btn-pressed); filter: none; translate: 0 var(--btn-lift); }
  .c-button--text:active, .c-button--text.is-active { background: none; box-shadow: none; }

  /* Flat on request, and flat for anything that shows a selected state. */
  .c-button:is([data-elevation="flat"], [aria-pressed], [aria-selected], [aria-current], [aria-checked], [role="tab"], [role="switch"]) { background-image: none; box-shadow: none; filter: none; translate: none; }

  /* Disabled: flat, no glow, sheen or movement. */
  .c-button[aria-disabled="true"], .c-button:disabled { border-color: var(--border); background-color: var(--surface-alt); background-image: none; color: var(--ink-muted); box-shadow: none; filter: none; translate: none; cursor: not-allowed; }
}
