/*
 * Global accessibility UI
 * - Universal JS-driven tooltip bubble
 * - Accessibility options launcher and panel
 * - Page and section audio reader controls
 * - Visual accessibility mode helpers
 */

/* Orphan-line reduction for frontend typography.
   Scoped to headings and intro/subtitle copy so compact UI labels keep existing nowrap behavior. */
h1,
h2,
h3,
h4,
h5,
h6 {
    text-wrap: balance;
}

:where(
    .hero-subtitle,
    .pet-story-subtitle,
    .story-subtitle,
    .fpa-guide__subtitle,
    .fpa-guide__section-intro,
    .fpa-userdash__section-intro,
    .fpa-userdash__subsection-header > p,
    .fpa-userdash__pet-dialog-intro,
    .fpa-success-subtitle,
    .section-header > p,
    .story-solution-header > p,
    p[class*="subtitle"],
    p[class*="intro"]
) {
    text-wrap: pretty;
}

/* Footer contact heading: keep short title phrases together. */
.site-footer #footer-contact h1,
.site-footer #footer-contact h2,
.site-footer #footer-contact h3,
.site-footer #footer-contact h4,
.site-footer #footer-contact h5,
.site-footer #footer-contact h6,
.site-footer #footer-contact .widget-title {
    white-space: nowrap;
}

/* Optional donation/support links */
.site-footer .fpa-support-links {
    margin-top: 16px;
}

.site-footer .fpa-support-links__label {
    margin: 0 0 10px;
    color: rgba(236, 240, 241, 0.82);
    font-size: 0.84rem;
    line-height: 1.45;
}

.site-footer .fpa-support-links__buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.site-footer .fpa-support-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.22);
    background: rgba(255, 255, 255, 0.08);
    color: #ffffff;
    font-size: 0.82rem;
    font-weight: 600;
    text-decoration: none;
    transition: background-color 0.16s ease, border-color 0.16s ease, transform 0.16s ease;
}

.site-footer .fpa-support-link:hover,
.site-footer .fpa-support-link:focus-visible {
    background: rgba(255, 255, 255, 0.16);
    border-color: rgba(255, 255, 255, 0.4);
    color: #ffffff;
    transform: translateY(-1px);
}

.site-footer .fpa-footer-support-link {
    text-decoration: underline;
    text-underline-offset: 0.16em;
}

.fpa-support-inline-note {
    margin: 14px auto 0;
    max-width: 720px;
    color: inherit;
    font-size: 0.92rem;
    line-height: 1.5;
    opacity: 0.9;
}

.fpa-support-inline-note a {
    color: inherit;
    font-weight: 700;
    text-decoration: underline;
    text-underline-offset: 0.14em;
}

.fpa-support-inline-note a:hover,
.fpa-support-inline-note a:focus-visible {
    opacity: 0.88;
}

.fpa-a11y-tooltip-bubble {
    position: absolute;
    z-index: 1090;
    max-width: 320px;
    padding: 8px 10px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.16);
    background: #1e293b;
    color: #ffffff;
    font-size: 12px;
    line-height: 1.45;
    box-shadow: 0 10px 22px rgba(15, 23, 42, 0.28);
    pointer-events: none;
    opacity: 0;
    transform: translateY(4px);
    transition: opacity 0.16s ease, transform 0.16s ease;
}

.fpa-a11y-tooltip-bubble::after {
    content: '';
    position: absolute;
    left: 50%;
    width: 8px;
    height: 8px;
    margin-left: -4px;
    background: #1e293b;
    border-left: 1px solid rgba(255, 255, 255, 0.16);
    border-bottom: 1px solid rgba(255, 255, 255, 0.16);
    transform: rotate(-45deg);
}

.fpa-a11y-tooltip-bubble[data-placement="top"]::after {
    bottom: -5px;
}

.fpa-a11y-tooltip-bubble[data-placement="bottom"] {
    transform: translateY(-4px);
}

.fpa-a11y-tooltip-bubble[data-placement="bottom"]::after {
    top: -5px;
    transform: rotate(135deg);
}

.fpa-a11y-tooltip-bubble.is-visible {
    opacity: 1;
    transform: translateY(0);
}

.fpa-a11y-reader {
    position: fixed;
    right: 30px;
    bottom: 90px;
    z-index: 1080;
    width: min(380px, calc(100% - 60px));
    border-radius: 14px;
    border: 1px solid rgba(74, 144, 226, 0.3);
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(8px);
    box-shadow: 0 14px 32px rgba(15, 23, 42, 0.2);
    padding: 10px;
}

.fpa-a11y-reader__controls {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.fpa-a11y-reader__btn {
    appearance: none;
    border: 1px solid rgba(53, 122, 189, 0.28);
    background: #f8fbff;
    color: #1f3556;
    border-radius: 10px;
    padding: 7px 10px;
    font-size: 12px;
    font-weight: 700;
    line-height: 1.2;
    cursor: pointer;
    transition: background-color 0.16s ease, border-color 0.16s ease, transform 0.16s ease;
}

.fpa-a11y-reader__btn:hover {
    background: #edf5ff;
    border-color: rgba(53, 122, 189, 0.46);
    transform: translateY(-1px);
}

.fpa-a11y-reader__btn:focus-visible,
.fpa-a11y-block-read-btn:focus-visible {
    outline: 3px solid #4a90e2;
    outline-offset: 2px;
}

.fpa-a11y-reader__btn:disabled {
    opacity: 0.56;
    cursor: not-allowed;
    transform: none;
}

.fpa-a11y-reader__status {
    margin: 8px 0 0;
    color: #2f4f73;
    font-size: 12px;
    line-height: 1.4;
}

.fpa-a11y-launcher {
    position: fixed;
    right: 30px;
    bottom: 30px;
    z-index: 1084;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
}

.fpa-a11y-launcher__btn {
    appearance: none;
    width: 48px;
    height: 48px;
    border: none;
    background: linear-gradient(135deg, #4A90E2 0%, #357ABD 100%);
    color: #ffffff;
    border-radius: 50%;
    padding: 0;
    font-size: 11px;
    font-weight: 700;
    line-height: 1.2;
    cursor: pointer;
    position: relative;
    overflow: visible;
    box-shadow: 0 4px 15px rgba(74, 144, 226, 0.35);
    transition: background 0.3s ease, transform 0.3s ease, box-shadow 0.3s ease;
}

.fpa-a11y-launcher__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    font-size: 23px;
}

.fpa-a11y-launcher__icon i {
    line-height: 1;
}

.fpa-a11y-launcher__btn:hover {
    background: linear-gradient(135deg, #FF8A65 0%, #FF7043 100%);
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(255, 138, 101, 0.4);
}

.fpa-a11y-launcher__btn:focus-visible {
    outline: 3px solid #4a90e2;
    outline-offset: 2px;
}

.fpa-a11y-panel {
    width: min(320px, calc(100vw - 40px));
    border-radius: 14px;
    border: 1px solid rgba(53, 122, 189, 0.34);
    background: rgba(255, 255, 255, 0.98);
    box-shadow: 0 16px 36px rgba(15, 23, 42, 0.24);
    padding: 12px;
}

.fpa-a11y-panel__title {
    margin: 0 0 10px;
    color: #1f3556;
    font-size: 13px;
    font-weight: 700;
    line-height: 1.2;
}

.fpa-a11y-panel__list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.fpa-a11y-panel__toggle {
    appearance: none;
    width: 100%;
    border: 1px solid rgba(53, 122, 189, 0.24);
    background: #f8fbff;
    color: #1f3556;
    border-radius: 10px;
    padding: 8px 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.25;
    text-align: left;
    cursor: pointer;
    transition: background-color 0.16s ease, border-color 0.16s ease, transform 0.16s ease;
}

.fpa-a11y-panel__toggle:hover {
    background: #edf5ff;
    border-color: rgba(53, 122, 189, 0.44);
}

.fpa-a11y-panel__toggle[data-enabled="1"] {
    background: #e5f2ff;
    border-color: rgba(53, 122, 189, 0.62);
}

.fpa-a11y-panel__toggle-state {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    border-radius: 999px;
    background: #dceaf8;
    color: #18406b;
    font-size: 11px;
    font-weight: 700;
    padding: 4px 8px;
    text-transform: uppercase;
}

.fpa-a11y-panel__toggle[data-enabled="1"] .fpa-a11y-panel__toggle-state {
    background: #4a90e2;
    color: #ffffff;
}

.fpa-a11y-panel__action {
    appearance: none;
    width: 100%;
    margin-top: 10px;
    border: 1px solid rgba(53, 122, 189, 0.4);
    border-radius: 10px;
    background: #ffffff;
    color: #1f3556;
    padding: 8px 10px;
    font-size: 12px;
    font-weight: 700;
    line-height: 1.2;
    cursor: pointer;
}

.fpa-a11y-panel__action:hover {
    background: #edf5ff;
}

.fpa-a11y-panel__toggle:focus-visible,
.fpa-a11y-panel__action:focus-visible {
    outline: 3px solid #4a90e2;
    outline-offset: 2px;
}

.fpa-a11y-panel__text-size-controls {
    margin-top: 10px;
    padding: 10px;
    border: 1px solid rgba(53, 122, 189, 0.24);
    border-radius: 10px;
    background: #f8fbff;
}

.fpa-a11y-panel__text-size-label {
    display: block;
    margin-bottom: 8px;
    color: #1f3556;
    font-size: 12px;
    font-weight: 700;
}

.fpa-a11y-panel__text-size-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.fpa-a11y-panel__text-size-btn {
    appearance: none;
    width: 34px;
    height: 34px;
    border: 1px solid rgba(53, 122, 189, 0.34);
    border-radius: 8px;
    background: #ffffff;
    color: #1f3556;
    font-size: 18px;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
}

.fpa-a11y-panel__text-size-btn:hover {
    background: #edf5ff;
}

.fpa-a11y-panel__text-size-btn:disabled {
    opacity: 0.56;
    cursor: not-allowed;
}

.fpa-a11y-panel__text-size-value {
    min-width: 64px;
    text-align: center;
    color: #1f3556;
    font-size: 12px;
    font-weight: 700;
}

.fpa-a11y-panel__text-size-btn:focus-visible {
    outline: 3px solid #4a90e2;
    outline-offset: 2px;
}

.fpa-a11y-block-read-btn {
    appearance: none;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: fit-content;
    margin: 0 auto 10px;
    border: 1px solid rgba(74, 144, 226, 0.34);
    border-radius: 999px;
    background: rgba(232, 244, 253, 0.88);
    color: #1f3556;
    font-size: 12px;
    font-weight: 700;
    line-height: 1.2;
    padding: 6px 10px;
    cursor: pointer;
}

.fpa-a11y-block-read-btn:hover {
    background: rgba(213, 234, 251, 0.95);
}

main .hero-section > .fpa-a11y-block-read-btn {
    position: absolute;
    top: 14px;
    left: 50%;
    transform: translateX(-50%);
    margin: 0;
    z-index: 4;
}

body.fpa-a11y-high-contrast {
    background: #ffffff;
    color: #111111;
}

body.fpa-a11y-high-contrast a {
    color: #0037a8 !important;
}

body.fpa-a11y-high-contrast .site-footer {
    background: #ffffff !important;
    background-image: none !important;
    color: #111111 !important;
    border-top-color: #111111 !important;
}

body.fpa-a11y-high-contrast .site-footer::before {
    display: none !important;
}

body.fpa-a11y-high-contrast .site-footer,
body.fpa-a11y-high-contrast .site-footer * {
    color: #111111 !important;
    text-shadow: none !important;
    box-shadow: none !important;
}

body.fpa-a11y-high-contrast .site-footer a,
body.fpa-a11y-high-contrast .footer-links a,
body.fpa-a11y-high-contrast .footer-column a {
    color: #0037a8 !important;
    text-decoration: underline !important;
    text-underline-offset: 0.14em;
}

body.fpa-a11y-high-contrast .site-footer .pet-tips,
body.fpa-a11y-high-contrast .site-footer .tips-header,
body.fpa-a11y-high-contrast .site-footer .newsletter-input,
body.fpa-a11y-high-contrast .site-footer .fpa-support-link {
    background: #ffffff !important;
    border-color: #111111 !important;
}

body.fpa-a11y-high-contrast .site-footer .newsletter-input {
    border-width: 2px !important;
}

body.fpa-a11y-high-contrast .site-footer .newsletter-input::placeholder {
    color: #333333 !important;
    opacity: 1 !important;
}

body.fpa-a11y-high-contrast .site-footer .newsletter-btn,
body.fpa-a11y-high-contrast .site-footer .social-link {
    background: #111111 !important;
    color: #ffffff !important;
    border-color: #111111 !important;
}

body.fpa-a11y-high-contrast :focus-visible {
    outline: 3px solid #111111 !important;
    outline-offset: 2px;
}

body.fpa-a11y-large-text {
    font-size: 100%;
}

body.fpa-a11y-large-text p,
body.fpa-a11y-large-text li,
body.fpa-a11y-large-text label,
body.fpa-a11y-large-text input,
body.fpa-a11y-large-text select,
body.fpa-a11y-large-text textarea,
body.fpa-a11y-large-text button {
    line-height: 1.65;
}

body.fpa-a11y-underline-links a {
    text-decoration: underline !important;
    text-underline-offset: 0.16em;
    text-decoration-thickness: 1.5px;
}

body.fpa-a11y-reduce-motion *,
body.fpa-a11y-reduce-motion *::before,
body.fpa-a11y-reduce-motion *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
}

html.fpa-a11y-reduce-motion {
    scroll-behavior: auto !important;
}

@media (max-width: 640px) {
    .fpa-a11y-reader {
        right: 10px;
        left: 10px;
        width: auto;
        bottom: 78px;
    }

    .fpa-a11y-launcher {
        right: 20px;
        bottom: 20px;
        left: auto;
    }

    .fpa-a11y-launcher__btn {
        width: 44px;
        height: 44px;
        font-size: 10px;
    }

    .fpa-a11y-launcher__icon {
        font-size: 20px;
    }

    .fpa-a11y-panel {
        width: min(320px, calc(100vw - 24px));
    }

    .fpa-a11y-reader__btn {
        flex: 1 1 calc(50% - 8px);
        text-align: center;
    }

    .site-footer .fpa-support-links__buttons {
        justify-content: center;
    }
}

@media (prefers-reduced-motion: reduce) {
    .fpa-a11y-tooltip-bubble,
    .fpa-a11y-reader__btn,
    .fpa-a11y-launcher__btn,
    .fpa-a11y-panel__toggle,
    .fpa-a11y-panel__action {
        transition: none;
    }
}

@media (forced-colors: active) {
    .fpa-a11y-reader,
    .fpa-a11y-launcher,
    .fpa-a11y-panel,
    .fpa-a11y-tooltip-bubble,
    .fpa-a11y-reader__btn,
    .fpa-a11y-launcher__btn,
    .fpa-a11y-panel__toggle,
    .fpa-a11y-panel__toggle-state,
    .fpa-a11y-panel__action,
    .fpa-a11y-block-read-btn {
        forced-color-adjust: none;
    }

    .fpa-a11y-reader,
    .fpa-a11y-reader__btn,
    .fpa-a11y-launcher__btn,
    .fpa-a11y-panel,
    .fpa-a11y-panel__toggle,
    .fpa-a11y-panel__toggle-state,
    .fpa-a11y-panel__action,
    .fpa-a11y-block-read-btn {
        background: Canvas;
        border-color: CanvasText;
        color: CanvasText;
    }

    .fpa-a11y-tooltip-bubble {
        background: CanvasText;
        color: Canvas;
        border-color: Canvas;
    }
}
