/*
 * The connection capsule (ConnectionCapsule.razor): what a page shows while
 * its circuit is down. Behaviour in cms-connection.js beside this file, which
 * writes the one attribute everything here reads: data-view.
 *
 * Its own colours rather than anyone's tokens. It is drawn over the
 * dashboard, the owner panel, both sign-in rooms and every site's storefront,
 * in either scheme and whatever palette the site chose; a dark glass capsule
 * reads on all of them. The typeface is the page's own, so on a storefront it
 * speaks in the site's font.
 *
 * The page underneath is never covered: the root takes no pointer events, and
 * only the capsule itself can be clicked.
 */

.cms-link {
    --link-tone: #f5b942;           /* down: amber */
    --link-ink: #ffffff;
    --link-soft: rgba(255, 255, 255, 0.68);
    position: fixed;
    inset: 0;
    z-index: 10000;
    pointer-events: none;
    font-family: inherit;
}

    .cms-link[data-view="dead"] {
        --link-tone: #ff7a70;
    }

    .cms-link[data-view="back"],
    .cms-link[data-view="reloading"] {
        --link-tone: #3ddc97;
    }

/* A thin lit edge round the page: it is still here, but it is not live. */
.cms-link__frame {
    position: absolute;
    inset: 0;
    opacity: 0;
    box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--link-tone) 60%, transparent),
                inset 0 -70px 90px -60px color-mix(in srgb, var(--link-tone) 34%, transparent);
    transition: opacity .35s ease, box-shadow .35s ease;
}

.cms-link:not([data-view="hidden"]) .cms-link__frame {
    opacity: 1;
}

.cms-link[data-view="back"] .cms-link__frame {
    animation: cms-link-frame-out 1.6s ease forwards;
}

.cms-link__capsule {
    position: absolute;
    inset-block-end: calc(18px + env(safe-area-inset-bottom, 0px));
    inset-inline: 0;
    margin-inline: auto;
    width: fit-content;
    max-width: min(560px, calc(100vw - 24px));
    display: flex;
    align-items: center;
    gap: 14px;
    padding-block: 10px;
    padding-inline: 16px 12px;
    border-radius: 999px;
    color: var(--link-ink);
    background: linear-gradient(180deg, rgba(40, 42, 58, 0.92), rgba(20, 21, 31, 0.94));
    -webkit-backdrop-filter: blur(14px) saturate(1.4);
    backdrop-filter: blur(14px) saturate(1.4);
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.10) inset,
                0 1px 0 rgba(255, 255, 255, 0.16) inset,
                0 18px 44px -12px rgba(0, 0, 0, 0.55),
                0 0 0 1px rgba(0, 0, 0, 0.35),
                0 0 34px -10px color-mix(in srgb, var(--link-tone) 70%, transparent);
    pointer-events: auto;
    /* Out of sight below the edge until there is something to say. */
    opacity: 0;
    visibility: hidden;
    translate: 0 28px;
    scale: .94;
    transition: opacity .28s ease, translate .42s cubic-bezier(.2, 1.3, .4, 1), scale .42s cubic-bezier(.2, 1.3, .4, 1),
                visibility 0s linear .42s, box-shadow .35s ease;
}

.cms-link:not([data-view="hidden"]) .cms-link__capsule {
    opacity: 1;
    visibility: visible;
    translate: 0 0;
    scale: 1;
    transition-delay: 0s;
}

/* A click on a dead control: the capsule answers for it. */
.cms-link__capsule.is-nudged {
    animation: cms-link-nudge .5s cubic-bezier(.3, .7, .4, 1);
}

    .cms-link__capsule.is-nudged .cms-link__hint {
        color: var(--link-tone);
    }

/* ---- the scene ---------------------------------------------------------- */

.cms-link__scene {
    flex: none;
    overflow: visible;
}

.cms-link__you {
    fill: var(--link-ink);
}

.cms-link__wire {
    fill: none;
    stroke: var(--link-soft);
    stroke-width: 2;
    stroke-linecap: round;
    transition: stroke .3s ease, opacity .3s ease;
}

.cms-link__wire--mend {
    stroke: var(--link-tone);
    stroke-dasharray: 10;
    stroke-dashoffset: 10;
}

.cms-link__spark {
    fill: none;
    stroke: var(--link-tone);
    stroke-width: 1.6;
    stroke-linecap: round;
    stroke-linejoin: round;
    animation: cms-link-spark 1.4s ease-in-out infinite;
}

.cms-link__packet {
    fill: var(--link-tone);
    opacity: 0;
}

.cms-link__server {
    fill: none;
    stroke: var(--link-ink);
    stroke-width: 1.6;
    transition: stroke .3s ease, opacity .3s ease;
}

.cms-link__lamp {
    fill: var(--link-tone);
    animation: cms-link-lamp 1.4s steps(2, jump-none) infinite;
}

/* An attempt in flight: something sets out along the wire and is lost at the
   break. */
.cms-link[data-view="connecting"] .cms-link__packet,
.cms-link[data-view="restoring"] .cms-link__packet {
    animation: cms-link-send .9s cubic-bezier(.5, 0, .8, .6) infinite;
}

/* Between attempts: nothing is sent; the fault just glows. */
.cms-link[data-view="waiting"] .cms-link__spark,
.cms-link[data-view="paused"] .cms-link__spark {
    animation-duration: 2.4s;
}

/* No network: the fault is on this side, so the near half is the dark one. */
.cms-link[data-view="offline"] .cms-link__wire--near {
    opacity: .25;
    stroke-dasharray: 2 4;
}

.cms-link[data-view="offline"] .cms-link__you {
    fill: none;
    stroke: var(--link-tone);
    stroke-width: 1.8;
    animation: cms-link-lamp 1.4s steps(2, jump-none) infinite;
}

/* No way back: the far side has gone dark. */
.cms-link[data-view="dead"] .cms-link__wire--far,
.cms-link[data-view="dead"] .cms-link__server {
    opacity: .35;
}

.cms-link[data-view="dead"] .cms-link__lamp {
    animation: none;
    opacity: .5;
}

/* Back: the wire closes, and one thing goes all the way across. */
.cms-link[data-view="back"] .cms-link__wire,
.cms-link[data-view="reloading"] .cms-link__wire {
    stroke: var(--link-tone);
}

.cms-link[data-view="back"] .cms-link__wire--mend,
.cms-link[data-view="reloading"] .cms-link__wire--mend {
    animation: cms-link-mend .35s ease-out forwards;
}

.cms-link[data-view="back"] .cms-link__spark,
.cms-link[data-view="reloading"] .cms-link__spark {
    display: none;
}

.cms-link[data-view="back"] .cms-link__packet,
.cms-link[data-view="reloading"] .cms-link__packet {
    animation: cms-link-arrive .7s .25s ease-in-out both;
}

.cms-link[data-view="back"] .cms-link__lamp,
.cms-link[data-view="reloading"] .cms-link__lamp {
    animation: none;
}

/* ---- the words ---------------------------------------------------------- */

.cms-link__words {
    display: grid;
    gap: 1px;
    min-width: 0;
    text-align: start;
    line-height: 1.5;
}

.cms-link__title {
    font-size: 13.5px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cms-link__hint {
    font-size: 12px;
    font-weight: 400;
    color: var(--link-soft);
    transition: color .2s ease;
}

    .cms-link__hint:empty {
        display: none;
    }

.cms-link__action {
    flex: none;
    appearance: none;
    border: 0;
    border-radius: 999px;
    padding: 7px 14px;
    font: inherit;
    font-size: 12.5px;
    font-weight: 600;
    color: #14151f;
    background: var(--link-tone);
    cursor: pointer;
    transition: filter .15s ease, scale .15s ease, background .3s ease;
}

    .cms-link__action[hidden] {
        display: none;
    }

    .cms-link__action:hover {
        filter: brightness(1.08);
    }

    .cms-link__action:active {
        scale: .96;
    }

    .cms-link__action:disabled {
        opacity: .6;
        cursor: progress;
    }

    .cms-link__action:focus-visible {
        outline: 2px solid #ffffff;
        outline-offset: 2px;
    }

/* Narrow screens: a bar from edge to edge rather than a pill, so two lines of
   words have room. */
@media (max-width: 520px) {
    .cms-link__capsule {
        width: auto;
        inset-inline: 10px;
        border-radius: 20px;
        gap: 10px;
    }

    .cms-link__title {
        white-space: normal;
    }

    .cms-link__scene {
        width: 48px;
    }
}

@keyframes cms-link-send {
    0% { translate: 0 0; opacity: 0; }
    15% { opacity: 1; }
    70% { translate: 12px 0; opacity: 1; }
    100% { translate: 15px 5px; opacity: 0; }
}

@keyframes cms-link-arrive {
    0% { translate: 0 0; opacity: 1; }
    85% { translate: 33px 0; opacity: 1; }
    100% { translate: 35px 0; opacity: 0; }
}

@keyframes cms-link-mend {
    to { stroke-dashoffset: 0; }
}

@keyframes cms-link-spark {
    0%, 100% { opacity: .35; }
    45% { opacity: 1; }
    55% { opacity: .5; }
    65% { opacity: 1; }
}

@keyframes cms-link-lamp {
    0% { opacity: 1; }
    100% { opacity: .25; }
}

@keyframes cms-link-nudge {
    0%, 100% { translate: 0 0; }
    20% { translate: -7px 0; }
    45% { translate: 6px 0; }
    70% { translate: -3px 0; }
    85% { translate: 2px 0; }
}

@keyframes cms-link-frame-out {
    0% { opacity: 1; }
    40% { opacity: 1; }
    100% { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
    .cms-link__capsule,
    .cms-link__frame {
        transition-duration: 0s;
    }

    .cms-link *,
    .cms-link__capsule.is-nudged {
        animation: none !important;
    }

    .cms-link[data-view="back"] .cms-link__wire--mend,
    .cms-link[data-view="reloading"] .cms-link__wire--mend {
        stroke-dashoffset: 0;
    }
}
