/*
 * Focus ring of choice buttons. A theme sets its colour with
 * --form-focus-ring-color (on :root, and optionally separately under .dark).
 * Without that value: #374151, and white in dark sections.
 */
:where(.form-field-radio-buttons) {
    --form-focus-ring-default: #374151;
}

:where(.dark .form-field-radio-buttons) {
    --form-focus-ring-default: #ffffff;
}

:where(.form-field-radio-buttons) input:focus-visible + .form-radio-button {
    outline: 2px solid var(--form-focus-ring-color, var(--form-focus-ring-default));
    outline-offset: 2px;
}

/*
 * Close button of the form message (message.htm): text on the left, the cross
 * on the right in the text colour. The button of message.htm holds the cross
 * as an SVG; a theme's own copy of message.htm with an empty button gets the
 * same cross, drawn below. Where a rule names both buttons, their selectors
 * weigh the same, so a theme overrides them alike.
 */
:where(.alert-dismissible):has(> .btn-close > svg),
:where(.alert-dismissible):has(> button.btn-close:where(:empty)) {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
}

/* The negative margin keeps a one-line message as high as before. */
:where(.alert-dismissible) > .btn-close:has(> svg),
:where(.alert-dismissible) > button.btn-close:where(:empty) {
    flex-shrink: 0;
    display: flex;
    padding: 0.5rem;
    margin: -0.5rem -0.5rem -0.5rem 0;
    border: 0;
    border-radius: 0.375rem;
    background: transparent;
    color: inherit;
    cursor: pointer;
}

:where(.alert-dismissible) > .btn-close:has(> svg):focus-visible,
:where(.alert-dismissible) > button.btn-close:where(:empty):focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 2px;
}

/*
 * The cross of an empty button: the path of the SVG in message.htm as a mask
 * on a pseudo-element, so the focus ring of the button itself stays whole.
 */
:where(.alert-dismissible) > button.btn-close:where(:empty)::before {
    content: "";
    width: 24px;
    height: 24px;
    background-color: currentColor;
    -webkit-mask-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpath d='M6 18L18 6M6 6l12 12'/%3e%3c/svg%3e");
    mask-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpath d='M6 18L18 6M6 6l12 12'/%3e%3c/svg%3e");
    -webkit-mask-size: 100% 100%;
    mask-size: 100% 100%;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
}

/*
 * Forced colours (Windows high contrast) replace every background colour,
 * which would hide the masked cross; draw it in the button text colour, the
 * colour the SVG cross gets there.
 */
@media (forced-colors: active) {
    :where(.alert-dismissible) > button.btn-close:where(:empty)::before {
        forced-color-adjust: none;
        background-color: ButtonText;
    }
}
