/*
 * Longevity World Cup share sheet
 *
 * One way to share an athlete, a result or the site: the sheet grows out of the
 * button that opened it, the link-preview card develops in like a print, the
 * copy action's chain link closes into a check, and the destinations rise in
 * one after another. On narrow screens the same sheet rises from the bottom
 * edge and follows a downward drag.
 *
 * The athlete dialog's own share menu (#athleteShareMenu) borrows the preview,
 * tile and copy motion below, so both read as the same object.
 *
 * Colours come from the shared --lwc-* tokens only. Durations follow
 * motion.css; prefers-reduced-motion leaves every state change instant.
 */

:root {
    --lwc-share-ease-out: var(--lwc-ease-enter, cubic-bezier(0, 0, 0, 1));
    --lwc-share-ease-pop: var(--lwc-ease-pop, cubic-bezier(0.34, 1.4, 0.64, 1));
    --lwc-share-card-dark: #05080b;
    --lwc-share-card-dark-2: #15181b;
}

/* 1) Entry point: a quiet round icon button that sits beside a title or result. */
.lwc-share-trigger {
    position: relative;
    display: inline-grid;
    place-items: center;
    flex: 0 0 auto;
    width: max(44px, 2.5rem);
    height: max(44px, 2.5rem);
    margin: 0;
    padding: 0;
    border: 1px solid var(--lwc-border);
    border-radius: var(--lwc-radius-pill);
    background: var(--lwc-surface);
    color: var(--lwc-muted);
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    box-shadow: var(--lwc-shadow-sm);
    vertical-align: middle;
}

.lwc-share-trigger > i {
    grid-area: 1 / 1;
    transition: opacity var(--lwc-motion-fast, 140ms) ease, transform var(--lwc-motion-base, 200ms) var(--lwc-share-ease-pop);
}

.lwc-share-trigger__done {
    opacity: 0;
    transform: scale(0.4) rotate(-30deg);
    color: var(--lwc-success);
}

.lwc-share-trigger:hover,
.lwc-share-trigger[aria-expanded="true"] {
    border-color: var(--lwc-accent);
    color: var(--lwc-accent);
    background: var(--lwc-surface-accent);
}

.lwc-share-trigger:hover > .lwc-share-trigger__share {
    transform: rotate(-12deg) scale(1.08);
}

.lwc-share-trigger:active {
    transform: scale(var(--lwc-motion-press-scale, 0.97));
}

.lwc-share-trigger:focus-visible {
    outline: 2px solid var(--lwc-accent);
    outline-offset: 2px;
}

.lwc-share-trigger[aria-busy="true"] {
    cursor: progress;
}

.lwc-share-trigger.is-copied {
    border-color: var(--lwc-success);
    background: var(--lwc-success-soft);
}

.lwc-share-trigger.is-copied > .lwc-share-trigger__share {
    opacity: 0;
    transform: scale(0.4) rotate(30deg);
}

.lwc-share-trigger.is-copied > .lwc-share-trigger__done {
    opacity: 1;
    transform: none;
}

/* A title that carries a share button keeps it on its baseline. */
.lwc-share-host {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    column-gap: 0.75rem;
}

.lwc-share-host > .lwc-share-trigger {
    font-size: 1rem;
    font-weight: 400;
    letter-spacing: 0;
    text-transform: none;
}

/* 2) The sheet. */
.lwc-share {
    --lwc-share-origin-x: 50%;
    --lwc-share-drag: 0px;
    position: fixed;
    z-index: 2147483000;
    top: 0;
    left: 0;
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    width: min(23.5rem, calc(100vw - 1.5rem));
    max-height: calc(100dvh - 24px);
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 0.75rem;
    box-sizing: border-box;
    border: 1px solid var(--lwc-border);
    border-radius: var(--lwc-radius-lg);
    background: var(--lwc-surface);
    color: var(--lwc-ink);
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.04) inset, 0 22px 48px rgba(15, 23, 42, 0.22), 0 4px 12px rgba(15, 23, 42, 0.12);
    transform-origin: var(--lwc-share-origin-x) top;
    text-align: left;
    font-size: 1rem;
    line-height: 1.4;
}

.lwc-share.is-above {
    transform-origin: var(--lwc-share-origin-x) bottom;
}

.lwc-share[hidden] {
    display: none;
}

.lwc-share > :is(figure, button, input, div, .lwc-share__handle) {
    flex: 0 0 auto;
}

.lwc-share__handle {
    display: none;
}

/* 3) Preview: the 1200x630 card, waiting as a dark card with a travelling sheen,
 * then developing from left to right with a soft focus pull. */
:is(.lwc-share__preview, #detailsModal .athlete-share-preview) {
    position: relative;
    margin: 0;
    aspect-ratio: 1200 / 630;
    overflow: hidden;
    border: 1px solid var(--lwc-border);
    border-radius: var(--lwc-radius-md);
    background:
        linear-gradient(100deg, transparent 30%, rgba(255, 255, 255, 0.07) 50%, transparent 70%) 0 0 / 220% 100%,
        radial-gradient(120% 90% at 88% 20%, rgba(25, 195, 209, 0.16), transparent 60%),
        linear-gradient(180deg, var(--lwc-share-card-dark), var(--lwc-share-card-dark-2));
    animation: lwc-share-sheen 1.3s linear infinite;
    isolation: isolate;
}

.lwc-share__preview[hidden] {
    display: none;
}

/* The waiting card already shows the card's skeleton: masthead strip and an accent foot. */
:is(.lwc-share__preview, #detailsModal .athlete-share-preview)::before,
:is(.lwc-share__preview, #detailsModal .athlete-share-preview)::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    z-index: 0;
    pointer-events: none;
}

:is(.lwc-share__preview, #detailsModal .athlete-share-preview)::before {
    top: 0;
    height: 15.2%;
    background: rgba(0, 0, 0, 0.35);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

:is(.lwc-share__preview, #detailsModal .athlete-share-preview)::after {
    bottom: 0;
    height: 1.6%;
    background: var(--lwc-accent-bright);
    transform-origin: left;
    animation: lwc-share-foot 1.3s var(--lwc-share-ease-out) infinite;
}

:is(.lwc-share__preview, #detailsModal .athlete-share-preview).is-loaded {
    animation: none;
    background: var(--lwc-share-card-dark);
}

:is(.lwc-share__preview, #detailsModal .athlete-share-preview).is-loaded::after {
    animation: none;
    opacity: 0;
}

:is(.lwc-share__preview, #detailsModal .athlete-share-preview) img {
    position: relative;
    z-index: 1;
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0;
    clip-path: inset(0 100% 0 0);
    filter: blur(6px) saturate(0.6);
    transform: scale(1.04);
}

:is(.lwc-share__preview, #detailsModal .athlete-share-preview).is-loaded img {
    opacity: 1;
    clip-path: inset(0 0 0 0);
    filter: none;
    transform: none;
    transition:
        opacity 120ms linear,
        clip-path 420ms var(--lwc-share-ease-out),
        filter 520ms var(--lwc-share-ease-out),
        transform 620ms var(--lwc-share-ease-out);
}

/* A single glint crosses the finished card, once. */
.lwc-share__glint {
    position: absolute;
    inset: 0;
    z-index: 2;
    pointer-events: none;
    background: linear-gradient(105deg, transparent 35%, rgba(255, 255, 255, 0.22) 50%, transparent 65%) -120% 0 / 60% 100% no-repeat;
    opacity: 0;
}

.lwc-share__preview.is-loaded .lwc-share__glint {
    animation: lwc-share-glint 700ms 380ms var(--lwc-share-ease-out) both;
}

/* 4) Copy: the main action. The chain link closes into a check and the label rolls. */
.lwc-share__copy {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.55rem;
    min-height: 48px;
    margin: 0;
    padding: 0.6rem 1rem;
    overflow: hidden;
    border: 1px solid var(--lwc-border-strong);
    border-radius: var(--lwc-radius-md);
    background: var(--lwc-surface-muted);
    color: var(--lwc-ink);
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.lwc-share__copy:hover {
    border-color: var(--lwc-accent);
    background: var(--lwc-surface-accent);
    color: var(--lwc-accent-hover);
}

.lwc-share__copy:active {
    transform: scale(var(--lwc-motion-press-scale, 0.97));
}

.lwc-share__copy:focus-visible,
.lwc-share__destination:focus-visible {
    outline: 2px solid var(--lwc-accent);
    outline-offset: 2px;
}

/* The ring that spreads from the button when the link lands on the clipboard. */
.lwc-share__copy::after {
    content: "";
    position: absolute;
    left: 50%;
    top: 50%;
    width: 2rem;
    height: 2rem;
    margin: -1rem 0 0 -1rem;
    border-radius: 50%;
    background: var(--lwc-success);
    opacity: 0;
    transform: scale(0);
    pointer-events: none;
}

.lwc-share-glyph {
    width: 1.25rem;
    height: 1.25rem;
    flex: 0 0 auto;
    overflow: visible;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.lwc-share-glyph path {
    transition:
        transform 220ms var(--lwc-share-ease-out),
        opacity 160ms ease,
        stroke-dashoffset 300ms 120ms var(--lwc-share-ease-out);
    transform-box: fill-box;
    transform-origin: center;
}

.lwc-share-glyph__check {
    stroke-dasharray: 1;
    stroke-dashoffset: 1;
    stroke-width: 2.6;
}

.lwc-share__copy-label {
    position: relative;
    display: inline-grid;
    overflow: hidden;
    line-height: 1.4;
}

.lwc-share__copy-label > span {
    grid-area: 1 / 1;
    transition: transform 240ms var(--lwc-share-ease-out), opacity 180ms ease;
}

.lwc-share__copy-label > span + span {
    opacity: 0;
    transform: translateY(110%);
}

.lwc-share.is-copied .lwc-share__copy {
    border-color: var(--lwc-success);
    background: var(--lwc-success-soft);
    color: var(--lwc-success);
}

.lwc-share.is-copied .lwc-share__copy::after {
    animation: lwc-share-ring 520ms var(--lwc-share-ease-out);
}

.lwc-share.is-copied .lwc-share-glyph__link--a {
    opacity: 0;
    transform: translate(-3px, 3px) scale(0.6);
}

.lwc-share.is-copied .lwc-share-glyph__link--b {
    opacity: 0;
    transform: translate(3px, -3px) scale(0.6);
}

.lwc-share.is-copied .lwc-share-glyph__check {
    stroke-dashoffset: 0;
}

.lwc-share.is-copied .lwc-share-glyph {
    animation: lwc-share-pop 420ms 80ms var(--lwc-share-ease-pop);
}

.lwc-share.is-copied .lwc-share__copy-label > span:first-child {
    opacity: 0;
    transform: translateY(-110%);
}

.lwc-share.is-copied .lwc-share__copy-label > span + span {
    opacity: 1;
    transform: none;
}

.lwc-share__manual {
    width: 100%;
    min-height: 44px;
    box-sizing: border-box;
    padding: 0 0.75rem;
    border: 1px solid var(--lwc-border-strong);
    border-radius: var(--lwc-radius-md);
    background: var(--lwc-surface);
    color: var(--lwc-ink);
    font: inherit;
    font-size: 0.875rem;
}

.lwc-share__manual[hidden] {
    display: none;
}

.lwc-share.is-recovering .lwc-share__preview {
    display: none;
}

/* 5) Destinations: four equal tiles; the glyph lifts on hover and the tile gives under a press. */
.lwc-share__destinations {
    display: grid;
    font-size: 0.78rem;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, max(44px, 4.5em)), 1fr));
    gap: 0.45rem;
}

.lwc-share__destination {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    min-height: 68px;
    padding: 0.55rem 0.2em;
    border: 1px solid var(--lwc-border);
    border-radius: var(--lwc-radius-md);
    background: var(--lwc-surface);
    color: var(--lwc-ink);
    font-size: inherit;
    font-weight: 700;
    text-align: center;
    text-decoration: none;
    overflow-wrap: anywhere;
}

.lwc-share .lwc-share__destination,
.lwc-share .lwc-share__destination:hover {
    color: var(--lwc-ink);
    text-decoration: none;
}

.lwc-share__destination-icon {
    display: grid;
    place-items: center;
    width: 2.1rem;
    height: 2.1rem;
    border-radius: 50%;
    background: var(--lwc-surface-muted);
    font-size: 1.05rem;
    transition: transform 220ms var(--lwc-share-ease-pop), background-color 140ms ease, color 140ms ease;
}

.lwc-share__destination:hover {
    border-color: var(--lwc-accent);
    background: var(--lwc-surface-accent);
}

.lwc-share__destination:hover .lwc-share__destination-icon,
.lwc-share__destination:focus-visible .lwc-share__destination-icon {
    background: var(--lwc-accent);
    color: var(--lwc-on-accent);
    transform: translateY(-3px) scale(1.06);
}

.lwc-share__destination:active {
    transform: scale(0.95);
    transition-duration: var(--lwc-motion-press, 90ms);
}

.lwc-share__destination:active .lwc-share__destination-icon {
    transform: translateY(0) scale(0.92);
}

/* 6) Phones: a bottom sheet with a grab handle over a dimmed page. */
.lwc-share.is-sheet {
    top: auto !important;
    left: 0 !important;
    right: 0;
    bottom: 0;
    width: 100%;
    max-height: calc(100dvh - 2rem);
    overflow-y: auto;
    padding: 0.5rem min(1rem, 16px) calc(1rem + env(safe-area-inset-bottom, 0px));
    border-width: 1px 0 0;
    border-radius: 18px 18px 0 0;
    transform: translateY(var(--lwc-share-drag));
    transform-origin: 50% 100%;
    overscroll-behavior: contain;
    touch-action: pan-y;
}

.lwc-share.is-sheet .lwc-share__handle {
    display: block;
    align-self: center;
    width: 2.5rem;
    height: 24px;
    flex: 0 0 24px;
    margin: -0.25rem 0;
    background: linear-gradient(var(--lwc-border-strong), var(--lwc-border-strong)) center / 100% 4px no-repeat;
    opacity: 0.6;
    touch-action: none;
}

.lwc-share.is-sheet.is-dragging {
    transition: none !important;
}

.lwc-share-scrim {
    position: fixed;
    inset: 0;
    z-index: 2147482999;
    background: rgba(8, 12, 16, 0.48);
    touch-action: none;
}

.lwc-share-scrim[hidden] {
    display: none;
}

/* 7) Motion. Everything above settles instantly without it. */
@media (prefers-reduced-motion: no-preference) {
    .lwc-share:not([hidden]) {
        animation: lwc-share-in 240ms var(--lwc-share-ease-out) backwards;
    }

    .lwc-share.is-closing {
        animation: lwc-share-out 160ms var(--lwc-ease-exit, ease-in) both;
        pointer-events: none;
    }

    .lwc-share.is-sheet:not([hidden]) {
        animation: lwc-share-rise 300ms var(--lwc-share-ease-out) backwards;
    }

    .lwc-share.is-sheet.is-closing {
        animation: lwc-share-sink 180ms var(--lwc-ease-exit, ease-in) both;
    }

    .lwc-share.is-sheet:not(.is-closing):not(.is-dragging) {
        transition: transform 220ms var(--lwc-share-ease-out);
    }

    .lwc-share-scrim:not([hidden]) {
        animation: lwc-share-fade 240ms ease both;
    }

    .lwc-share-scrim.is-closing {
        animation: lwc-share-fade 180ms ease reverse both;
    }

    /* The parts arrive in reading order: card, copy, then the tiles left to right. */
    :is(.lwc-share:not([hidden]), #detailsModal .athlete-share-menu:not([hidden])) > :is(figure, button, .lwc-share__destinations, .athlete-share-destinations) {
        animation: lwc-share-part 260ms var(--lwc-share-ease-out) backwards;
    }

    :is(.lwc-share:not([hidden]), #detailsModal .athlete-share-menu:not([hidden])) > button {
        animation-delay: 40ms;
    }

    :is(.lwc-share__destinations, #detailsModal .athlete-share-destinations) > a {
        animation: lwc-share-tile 300ms var(--lwc-share-ease-pop) backwards;
    }

    :is(.lwc-share__destinations, #detailsModal .athlete-share-destinations) > a:nth-child(1) { animation-delay: 70ms; }
    :is(.lwc-share__destinations, #detailsModal .athlete-share-destinations) > a:nth-child(2) { animation-delay: 110ms; }
    :is(.lwc-share__destinations, #detailsModal .athlete-share-destinations) > a:nth-child(3) { animation-delay: 150ms; }
    :is(.lwc-share__destinations, #detailsModal .athlete-share-destinations) > a:nth-child(4) { animation-delay: 190ms; }

    .lwc-share__destination {
        transition: transform var(--lwc-motion-fast, 140ms) var(--lwc-share-ease-out), border-color 140ms ease, background-color 140ms ease;
    }

    /* The athlete dialog's Share button: its share glyph spins away into the check. */
    #detailsModal #shareAthleteProfile.is-copied > i {
        animation: lwc-share-check-in 420ms var(--lwc-share-ease-pop) both;
    }

    .lwc-share-trigger.is-copied {
        animation: lwc-share-pop 420ms var(--lwc-share-ease-pop);
    }
}

@media (prefers-reduced-motion: reduce) {
    :is(.lwc-share__preview, #detailsModal .athlete-share-preview),
    :is(.lwc-share__preview, #detailsModal .athlete-share-preview)::after {
        animation: none;
    }

    :is(.lwc-share__preview, #detailsModal .athlete-share-preview) img,
    :is(.lwc-share__preview, #detailsModal .athlete-share-preview).is-loaded img {
        clip-path: none;
        filter: none;
        transform: none;
        transition: opacity 1ms;
    }

    .lwc-share *,
    .lwc-share-trigger,
    .lwc-share-trigger > i {
        transition-duration: 1ms !important;
        animation: none !important;
    }
}

@keyframes lwc-share-in {
    from { opacity: 0; transform: translateY(-6px) scale(0.94); }
    to { opacity: 1; transform: none; }
}

@keyframes lwc-share-out {
    to { opacity: 0; transform: translateY(-4px) scale(0.97); }
}

@keyframes lwc-share-rise {
    from { transform: translateY(100%); }
    to { transform: translateY(var(--lwc-share-drag)); }
}

@keyframes lwc-share-sink {
    from { transform: translateY(var(--lwc-share-drag)); }
    to { transform: translateY(100%); }
}

@keyframes lwc-share-fade {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes lwc-share-part {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: none; }
}

@keyframes lwc-share-tile {
    from { opacity: 0; transform: translateY(10px) scale(0.9); }
    to { opacity: 1; transform: none; }
}

@keyframes lwc-share-sheen {
    to { background-position: -220% 0, 0 0, 0 0; }
}

@keyframes lwc-share-foot {
    from { transform: scaleX(0); opacity: 0.9; }
    70% { transform: scaleX(1); opacity: 0.9; }
    to { transform: scaleX(1); opacity: 0; }
}

@keyframes lwc-share-glint {
    0% { opacity: 1; background-position: -120% 0; }
    100% { opacity: 1; background-position: 220% 0; }
}

@keyframes lwc-share-ring {
    0% { opacity: 0.35; transform: scale(0); }
    100% { opacity: 0; transform: scale(14); }
}

@keyframes lwc-share-pop {
    0% { transform: scale(1); }
    40% { transform: scale(1.22); }
    100% { transform: scale(1); }
}

@keyframes lwc-share-check-in {
    from { opacity: 0; transform: rotate(-90deg) scale(0.3); }
    to { opacity: 1; transform: none; }
}

/* 8) Calculator outcome: the share button rides the result card's top corner. */
.bioageform:has(> .bioage-result-share) {
    position: relative;
}

.bioageform > .bioage-result-share {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    z-index: 2;
}

body:not(.bioage-result-ready) .bioageform > .bioage-result-share {
    visibility: hidden;
}

@media (prefers-reduced-motion: no-preference) {
    body.bioage-result-ready .bioageform > .bioage-result-share {
        animation: lwc-share-tile 360ms 900ms var(--lwc-share-ease-pop) backwards;
    }
}

/* 9) The athlete dialog's destinations wear the same icon discs and give the same way. */
:root #detailsModal .athlete-share-destinations {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, max(44px, 4.5em)), 1fr));
}

/* The intermediate breakpoint still anchors to the action row. An auto width
   shrinks the sheet to one action there, including at 200% desktop zoom. */
@media (min-width: 481px) and (max-width: 768px) {
    :root #detailsModal .athlete-share-menu {
        width: min(22.5rem, calc(100vw - 2rem));
    }
}

@media (max-width: 360px) {
    :root #detailsModal .athlete-share-menu {
        padding: 12px;
    }

    :root #detailsModal .athlete-share-destinations {
        gap: 7px;
    }
}

:root #detailsModal .athlete-share-menu .athlete-share-destinations a > i {
    display: grid;
    place-items: center;
    width: 2.1rem;
    height: 2.1rem;
    border-radius: 50%;
    background: rgba(127, 127, 127, 0.16);
    font-size: 1.05rem;
    transition: transform 220ms var(--lwc-share-ease-pop), background-color 140ms ease, color 140ms ease;
}

:root #detailsModal .athlete-share-menu .athlete-share-destinations a:is(:hover, :focus-visible) > i {
    background: var(--lwc-accent);
    color: var(--lwc-on-accent);
    transform: translateY(-3px) scale(1.06);
}

:root #detailsModal .athlete-share-menu .athlete-share-destinations a:active {
    transform: scale(0.95);
}

:root #detailsModal .athlete-share-menu .athlete-share-destinations a:active > i {
    transform: scale(0.92);
}

:root #detailsModal .athlete-share-menu #copyAthleteProfileLink:active {
    transform: scale(var(--lwc-motion-press-scale, 0.97));
}
