/* The helper character of the guest pages (views/layouts/_assistant.php).
   It sits above the feedback button and moves with it, 84px higher in
   every state of the table of positions in layout.css. At rest it sits on
   an oak twig that grows out of the right edge of the screen (.assistant-twig
   below). While it talks it grows a little beside its speech bubble, centred
   on the column of the round buttons below it. */
.assistant
{
    --assistant-size: 96px;
    /* How far the grown character reaches past the column of 64px buttons on each side. */
    --assistant-reach: calc((var(--assistant-size) - 64px) / 2);
    position: fixed;
    right: 40px;
    bottom: 124px;
    z-index: 996;
    transform-origin: 50% 100%;
    transition: bottom 0.3s ease;
}
.assistant.is-big
{
    --assistant-size: 96px;
}
.assistant.is-open
{
    --assistant-size: 124px;
}
body.is-scrolled .assistant
{
    bottom: 208px;
}
body.has-visible-sticky-bar .assistant
{
    bottom: 204px;
}
body.has-visible-sticky-bar.is-scrolled .assistant
{
    bottom: 288px;
}

/* The selector is this long to outweigh the round buttons in layout.css. The button is only
   the box of the bird: no circle, no ring, and nothing of the bird is cut off. */
.assistant .btn.btn-xl.assistant-avatar,
.assistant .btn.btn-xl.assistant-avatar:hover,
.assistant .btn.btn-xl.assistant-avatar:active
{
    display: block;
    width: var(--assistant-size);
    min-width: var(--assistant-size);
    height: var(--assistant-size);
    margin-left: auto;
    margin-right: calc(var(--assistant-reach) * -1);
    padding: 0;
    overflow: visible;
    cursor: pointer;
    border-radius: 0;
    background-color: transparent;
    background-image: none;
    border-color: transparent;
    box-shadow: none;
    transform-origin: 50% 100%;
    transition: width 0.5s cubic-bezier(0.22, 1, 0.36, 1), min-width 0.5s cubic-bezier(0.22, 1, 0.36, 1),
        height 0.5s cubic-bezier(0.22, 1, 0.36, 1), margin 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}
.assistant .btn.btn-xl.assistant-avatar:focus-visible
{
    outline: 2px solid var(--color-action-primary-bg);
    outline-offset: 2px;
    border-radius: 16px;
}
.assistant .assistant-avatar::before,
.assistant .assistant-avatar::after
{
    opacity: 0;
}
/* Now and then the bird hops on its twig, to say that it can be pressed. */
.assistant.is-nudging .assistant-avatar
{
    animation: assistant-pulse 0.8s ease-in-out 2;
}

/* A soft shadow on whatever the bird stands on. --feet-x and --feet-y come from the rig. */
.assistant-figure
{
    position: relative;
}
.assistant-figure::before
{
    content: '';
    position: absolute;
    left: calc(var(--feet-x, 0.5) * 100%);
    top: calc(var(--feet-y, 0.96) * 100%);
    width: 70%;
    height: 16%;
    border-radius: 50%;
    background: radial-gradient(closest-side, rgba(0, 0, 0, 0.49), rgba(0, 0, 0, 0.25) 55%, rgba(0, 0, 0, 0));
    transform: translate(-50%, -38%);
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}
.assistant.is-perched:not(.is-flying) .assistant-figure::before
{
    opacity: 1;
}

/* Sitting on a button of the page to show it (assistant.js puts it there):
   the whole character, carried along with the page, pointing down at the
   button with its wing, while the button glows. */
/* Out on the page the button no longer reaches past a column, and it must not slide while landing. */
.assistant.is-perched .btn.btn-xl.assistant-avatar
{
    transition: none;
}
.assistant.is-perched
{
    --assistant-reach: 0px;
    position: absolute;
    z-index: 20;
    transition: none;
}
/* Out on the page the character says its line to the right of itself, where it fits. */
.assistant.is-perched:not(.is-saying-left) .assistant-bubble
{
    right: auto;
    left: calc(100% + 12px);
    bottom: 20px;
    width: min(260px, calc(100vw - 32px));
    transform-origin: 0 85%;
}
.assistant.is-perched:not(.is-saying-left) .assistant-bubble::after
{
    right: auto;
    left: -8px;
    bottom: 24px;
    transform: rotate(-135deg);
}
.assistant.is-perched .assistant-bubble::after
{
    bottom: 24px;
}
/* The script turns the wing towards what the bird shows (--aim) and it taps there. */
.assistant.is-pointing .puppet .pp-arm-r
{
    animation: pp-raise 0.5s ease-out, pp-point 0.9s ease-in-out 0.5s infinite;
}
/* In flight the folded wings give way to the spread ones, which beat, the tail
   steers and the head keeps still. The spread wings are hidden the rest of the time. */
.puppet .pp-wing-l,
.puppet .pp-wing-r
{
    opacity: 0;
}
.assistant.is-flying .puppet .pp-wing-l,
.assistant.is-flying .puppet .pp-wing-r
{
    opacity: 1;
}
.assistant.is-flying .puppet .pp-arm-l,
.assistant.is-flying .puppet .pp-arm-r
{
    opacity: 0;
    animation: none;
}
/* The beat starts once the script has spread the wings (SPREAD in assistant.js),
   from the raised wing where the spreading ends. */
.assistant.is-flying .puppet .pp-wing-l
{
    animation: pp-flap-l 0.34s ease-in-out 0.22s infinite;
}
.assistant.is-flying .puppet .pp-wing-r
{
    animation: pp-flap-r 0.34s ease-in-out 0.22s infinite;
}
.assistant.is-flying .puppet .pp-tail
{
    animation: pp-sway 0.48s ease-in-out infinite;
}
.assistant.is-flying .puppet .pg-head,
.assistant.is-flying .puppet .pg-all
{
    animation: none;
}
.assistant-target
{
    animation: assistant-glow 1.6s ease-out infinite;
}
.assistant-figure
{
    display: block;
    width: 100%;
    height: 100%;
}
/* The twig the bird rests on. It lies behind the bird, its thick end past the right edge of the
   screen, and stays there while the bird flies about the page. --twig-x, -y, -w and -h are its
   place in the box of the resting bird (from the rig), --rest the size of that box, --edge the
   room between the box and the edge of the screen, --base the bottom of the box. */
.assistant-twig
{
    --rest: 96px;
    --edge: 24px;
    --base: 124px;
    position: fixed;
    right: 0;
    bottom: calc(var(--base) + var(--rest) * (1 - var(--twig-y) - var(--twig-h)));
    width: calc(var(--edge) + var(--rest) * (1 - var(--twig-x)));
    height: calc(var(--rest) * var(--twig-h));
    z-index: 995;
    pointer-events: none;
    /* It bends about the edge of the screen, where it grows from. */
    transform-origin: 100% 50%;
    transition: bottom 0.3s ease;
}
body.is-scrolled .assistant-twig
{
    --base: 208px;
}
body.has-visible-sticky-bar .assistant-twig
{
    --base: 204px;
}
body.has-visible-sticky-bar.is-scrolled .assistant-twig
{
    --base: 288px;
}
.assistant-twig img
{
    display: block;
    width: 100%;
    height: auto;
}
.assistant-twig-art
{
    position: absolute;
    left: 0;
    top: 0;
    width: calc(var(--rest) * var(--twig-w));
}
/* A leaf sways by itself (the span) and shivers when the twig is shaken (the picture, from the script). */
.assistant-leaf
{
    position: absolute;
    animation: twig-leaf 3.6s ease-in-out infinite;
}
.assistant-leaf + .assistant-leaf
{
    animation-duration: 4.4s;
    animation-delay: -1.3s;
}
/* The twig dips when the bird lands on it in a hop. */
.assistant.is-nudging + .assistant-twig
{
    animation: twig-dip 0.8s ease-in-out 2;
}

/* The gripping feet hold the twig, the standing feet carry the bird everywhere else. */
.assistant .puppet .pp[data-v="grip"],
.assistant.is-flying .puppet .pp[data-v="stand"],
.assistant.is-perched .puppet .pp[data-v="stand"]
{
    opacity: 1;
}
.assistant.is-flying .puppet .pp[data-v="grip"],
.assistant.is-perched .puppet .pp[data-v="grip"]
{
    opacity: 0;
}

/* The speech bubble, to the left of the character, with a tail towards it. */
.assistant-bubble
{
    position: absolute;
    right: calc(var(--assistant-size) - var(--assistant-reach) + 14px);
    bottom: 0;
    width: min(330px, calc(100vw - var(--assistant-size) + var(--assistant-reach) - 70px));
    padding: 16px 18px 14px;
    background: var(--color-bg-surface-elevated);
    color: var(--color-text-primary);
    border: 1px solid var(--color-border-default);
    /* The same smooth corners as the buttons of the site (layout.css). */
    border-radius: 24px;
    corner-shape: superellipse(1.25);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.18);
    transform-origin: 100% 85%;
    animation: assistant-pop 0.22s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
.assistant-bubble[hidden]
{
    display: none;
}
.assistant-bubble::after
{
    content: '';
    position: absolute;
    right: -8px;
    bottom: 24px;
    width: 14px;
    height: 14px;
    background: inherit;
    border-right: 1px solid var(--color-border-default);
    border-top: 1px solid var(--color-border-default);
    transform: rotate(45deg);
}
.assistant.is-open .assistant-bubble::after
{
    bottom: 58px;
}
.assistant-bubble.is-tease
{
    cursor: pointer;
}

.assistant-text
{
    margin: 0 18px 0 0;
    font-size: 0.95rem;
    line-height: 1.45;
    min-height: 1.45em;
    white-space: pre-line;
}
.assistant-rest
{
    visibility: hidden;
}
.assistant-options
{
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 14px;
}
/* Once the text is typed the options rise into view one after another (--i is their place). */
.assistant-options > .btn
{
    animation: assistant-rise 0.6s ease-out both;
    animation-delay: calc(var(--i, 0) * 350ms);
}
/* The options keep their place while the text is typed, so the bubble does not grow. */
.assistant-options.is-waiting
{
    visibility: hidden;
}
.assistant-options.is-waiting > .btn
{
    animation: none;
}
.assistant-options:empty
{
    display: none;
}
/* A chosen option bounces, the others fade out gently, and the chosen one fades after its
   bounce unless it stays to show that the next page is loading. */
.assistant-options.is-leaving > .btn
{
    animation: assistant-fade 0.45s ease-in both;
    pointer-events: none;
}
.assistant-options.is-leaving > .btn.is-chosen
{
    animation: assistant-pick 0.6s ease-out both;
}
.assistant-options.is-leaving > .btn.is-chosen.is-staying
{
    animation: assistant-bounce 0.45s ease-out both;
}
@keyframes assistant-fade
{
    from { opacity: 1; }
    to { opacity: 0; }
}
@keyframes assistant-bounce
{
    0% { transform: scale(1); }
    35% { transform: scale(1.12); }
    65% { transform: scale(0.96); }
    100% { transform: scale(1); }
}
@keyframes assistant-pick
{
    0% { transform: scale(1); opacity: 1; }
    25% { transform: scale(1.12); opacity: 1; }
    45% { transform: scale(0.96); opacity: 1; }
    60% { transform: scale(1.02); opacity: 1; }
    100% { transform: scale(1); opacity: 0; }
}
.assistant-close
{
    position: absolute;
    top: 6px;
    right: 8px;
    padding: 2px 8px;
    border: 0;
    background: none;
    color: var(--color-text-muted);
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
}
.assistant-close:hover
{
    color: var(--color-text-primary);
}

/* A little hop: up, down onto the twig with a squash as the twig gives way (twig-dip), and back. */
@keyframes assistant-pulse
{
    0%, 100% { transform: none; }
    30% { transform: translateY(-9%) scale(0.97, 1.04); }
    55% { transform: translateY(2px) scale(1.04, 0.95); }
    75% { transform: translateY(-1px) scale(0.99, 1.01); }
}
@keyframes twig-dip
{
    0%, 45%, 100% { transform: none; }
    55% { transform: rotate(-1.8deg); }
    75% { transform: rotate(0.8deg); }
    88% { transform: rotate(-0.3deg); }
}
@keyframes twig-leaf
{
    0%, 100% { transform: rotate(-4deg); }
    50% { transform: rotate(5deg); }
}
@keyframes assistant-glow
{
    from { box-shadow: 0 0 0 0 color-mix(in srgb, var(--color-action-primary-bg) 70%, transparent); }
    to { box-shadow: 0 0 0 14px color-mix(in srgb, var(--color-action-primary-bg) 0%, transparent); }
}
@keyframes assistant-pop
{
    from { opacity: 0; transform: scale(0.85) translateX(8px); }
    to { opacity: 1; transform: none; }
}
@keyframes assistant-rise
{
    from { opacity: 0; transform: translateY(14px) scale(0.92); }
    to { opacity: 1; transform: none; }
}
/* The character is a cut-out puppet (data/assistant): every part is its own
   picture, placed in percent of the stage, so the puppet scales with its box.
   .pg is a group of parts that moves as one, .pp is one part. */
.puppet
{
    position: relative;
    width: 100%;
}
/* The pictures were drawn looking to the right. */
.puppet.is-flipped
{
    transform: scaleX(-1);
}
.puppet .pg
{
    position: absolute;
    inset: 0;
}
.puppet .pp
{
    position: absolute;
}
.puppet .pp img
{
    display: block;
    width: 100%;
    height: auto;
    pointer-events: none;
}

/* Eyes: one pair shows at a time. Every part with a kind (eyes, mouth) is hidden until its look is on. */
.puppet .pp[data-kind]
{
    opacity: 0;
}
.puppet[data-eyes="open"] .pp[data-v="open"],
.puppet[data-eyes="closed"] .pp[data-v="closed"],
.puppet[data-eyes="wide"] .pp[data-v="wide"],
.puppet[data-eyes="up"] .pp[data-v="up"]
{
    opacity: 1;
}

/* Calm life: breathing, a slow nod, a tail, a crest and a wing that never quite stand still. */
.puppet .pg-all
{
    animation: pp-breathe 3.4s ease-in-out infinite;
}
.puppet .pg-head
{
    animation: pp-nod 5.2s ease-in-out infinite;
}
.puppet .pp-tail
{
    animation: pp-sway 3.8s ease-in-out infinite;
}
.puppet .pp-crest
{
    animation: pp-sway 3.2s ease-in-out infinite;
}
.puppet .pp-arm-l
{
    animation: pp-arm-rest 3.4s ease-in-out infinite;
}
/* The wing the bird greets and points with rests folded along its body and rises only to wave or to point. */
.puppet .pp-arm-r
{
    transform: rotate(72deg);
}

/* Mouth: the beak is drawn whole in four shapes, and one shows at a time. */
.puppet[data-mouth="smile"] .pp[data-v="closed"],
.puppet[data-mouth="small"] .pp[data-v="small"],
.puppet[data-mouth="o"] .pp[data-v="o"],
.puppet[data-mouth="wide"] .pp[data-v="wide"]
{
    opacity: 1;
}

/* Talking: the head keeps time and the folded wing gestures. */
.puppet.is-talking .pg-head
{
    animation: pp-talk 0.62s ease-in-out infinite;
}
.puppet.is-talking .pp-arm-l
{
    animation: pp-gesture 1.3s ease-in-out infinite;
}
.puppet.is-talking .pp-crest
{
    animation: pp-crest-talk 0.55s ease-in-out infinite;
}

.puppet.is-waving .pp-arm-r
{
    animation: pp-wave 2.2s ease-in-out;
}
.puppet.is-waving .pg-head
{
    animation: pp-tilt 1.1s ease-in-out 2;
}

/* One glad hop. Every part ends it where it rests, and it is over before the next words
   (PICK in assistant.js), so talking never cuts it off halfway. */
.puppet.is-happy .pg-all
{
    animation: pp-jump 0.55s cubic-bezier(0.3, 1.6, 0.5, 1);
}
.puppet.is-happy .pp-tail,
.puppet.is-happy .pp-crest
{
    animation: pp-sway 0.275s ease-in-out 2;
}
.puppet.is-happy .pp-arm-l
{
    animation: pp-cheer 0.55s ease-in-out;
}
.puppet.is-happy .pp-arm-r
{
    animation: pp-cheer-r 0.55s ease-in-out;
}

@keyframes pp-breathe
{
    0%, 100% { transform: scale(1, 1); }
    50% { transform: scale(1.012, 0.985); }
}
@keyframes pp-nod
{
    0%, 100% { transform: rotate(0); }
    30% { transform: rotate(1.6deg); }
    70% { transform: rotate(-1.4deg); }
}
/* Talking starts and ends each beat where the head and the crest rest, so it begins without a jerk. */
@keyframes pp-talk
{
    0%, 100% { transform: rotate(0) translateY(0); }
    25% { transform: rotate(-1.5deg) translateY(-0.6%); }
    75% { transform: rotate(1.5deg) translateY(-1.2%); }
}
/* While talking the crest bobs up and down. */
@keyframes pp-crest-talk
{
    0%, 100% { transform: rotate(0); }
    25% { transform: rotate(-14deg); }
    75% { transform: rotate(20deg); }
}
@keyframes pp-tilt
{
    0%, 100% { transform: rotate(0); }
    50% { transform: rotate(6deg); }
}
@keyframes pp-sway
{
    0%, 100% { transform: rotate(-5deg); }
    50% { transform: rotate(6deg); }
}
@keyframes pp-arm-rest
{
    0%, 100% { transform: rotate(0); }
    50% { transform: rotate(3deg); }
}
@keyframes pp-gesture
{
    0%, 100% { transform: rotate(0); }
    40% { transform: rotate(18deg); }
    70% { transform: rotate(8deg); }
}
/* The wing rises out of its folded place, waves and folds back to the same place, so the end does not jump. */
@keyframes pp-wave
{
    0%, 100% { transform: rotate(72deg); }
    16% { transform: rotate(-12deg); }
    30% { transform: rotate(16deg); }
    44% { transform: rotate(-12deg); }
    58% { transform: rotate(16deg); }
    72% { transform: rotate(-12deg); }
    84% { transform: rotate(12deg); }
}
/* First the wing goes up high, then it comes down to point. */
@keyframes pp-raise
{
    0% { transform: rotate(72deg); }
    45% { transform: rotate(-62deg); }
    100% { transform: rotate(calc(var(--aim, 50deg) - 6deg)); }
}
@keyframes pp-point
{
    0%, 100% { transform: rotate(calc(var(--aim, 50deg) - 6deg)); }
    50% { transform: rotate(calc(var(--aim, 50deg) + 6deg)); }
}
/* Each spread wing turns about its shoulder: up high, then down past level. */
@keyframes pp-flap-l
{
    0%, 100% { transform: rotate(70deg); }
    50% { transform: rotate(-90deg); }
}
@keyframes pp-flap-r
{
    0%, 100% { transform: rotate(-70deg); }
    50% { transform: rotate(90deg); }
}
@keyframes pp-cheer
{
    0%, 100% { transform: rotate(0); }
    50% { transform: rotate(-24deg); }
}
@keyframes pp-cheer-r
{
    0%, 100% { transform: rotate(72deg); }
    50% { transform: rotate(40deg); }
}
@keyframes pp-jump
{
    0%, 100% { transform: translateY(0) scale(1, 1); }
    40% { transform: translateY(-9%) scale(0.98, 1.03); }
    80% { transform: translateY(0) scale(1.03, 0.96); }
}

/* <= 768px (SM) */
@media (max-width: 768px)
{
    .assistant
    {
        right: 16px;
    }
    .assistant-twig
    {
        --edge: 0px;
    }
    .assistant-bubble
    {
        width: min(330px, calc(100vw - var(--assistant-size) + var(--assistant-reach) - 46px));
    }
}

/* <= 576px (XS) */
@media (max-width: 576px)
{
    .assistant
    {
        right: 12px;
    }
    .assistant,
    .assistant.is-big
    {
        --assistant-size: 80px;
    }
    .assistant-twig
    {
        --rest: 80px;
        --edge: 4px;
    }
    .assistant.is-open
    {
        --assistant-size: 84px;
    }
    .assistant-bubble
    {
        width: calc(100vw - var(--assistant-size) + var(--assistant-reach) - 38px);
    }
    .assistant.is-open .assistant-bubble::after
    {
        bottom: 36px;
    }
}

@media (prefers-reduced-motion: reduce)
{
    .assistant,
    .assistant .btn.btn-xl.assistant-avatar,
    .assistant-figure,
    .assistant-twig
    {
        transition: none;
    }
    .assistant-bubble,
    .assistant-options,
    .assistant.is-nudging .assistant-avatar,
    .assistant-target,
    .assistant-options > .btn,
    .assistant-twig,
    .assistant-twig *,
    .puppet *
    {
        animation: none !important;
        transition: none !important;
    }
}
