/*
 * M.eins19 – dragonfly welcome screen (homepage only, loaded after site.css)
 *
 * Full-screen first view: the logo centred, the main pages as a swarm of small
 * dragonflies around it. Mobile first: below 48rem wide (or 32rem tall) the
 * swarm is a vertical "flight path" under the logo; from there, and only if the
 * browser supports CSS trig functions, it becomes a ring around the logo.
 * Geometry and reasoning: see README.md, section "Dragonfly welcome screen".
 *
 * No JavaScript needed; all motion is CSS and only runs under
 * prefers-reduced-motion: no-preference. Scrolling away plays the arrival in
 * reverse (the swarm flies off, the logo fades); that part needs scroll-driven
 * animations and is skipped in browsers without them.
 *
 * The keyframes animate only standard properties (transform, rotate, translate,
 * scale, opacity), never custom properties: Safari did not pass animated
 * custom properties on to the transforms that use them, so the dragonflies
 * started stacked on the logo and did not fly away on scroll.
 */

/* ---------- Tokens (scoped to this section, built on the site variables) ---------- */

.m19-hero {
    --m19-color-ink: var(--espresso);
    --m19-color-bg: var(--creme);
    --m19-color-ink-muted: var(--muted-foreground);
    --m19-color-focus: var(--espresso);

    --m19-font-size-label: var(--text-14);
    --m19-font-size-small: var(--text-13);
    --m19-font-weight-label: 500;
    --m19-tracking-label: 0.12em;

    --m19-space-2xs: var(--space-4);
    --m19-space-xs: var(--space-8);
    --m19-space-s: var(--space-12);
    --m19-space-m: var(--space-24);
    --m19-space-l: var(--space-32);
    --m19-space-xl: var(--space-64);

    --m19-tap-size: var(--space-48); /* 48px tap target (min. 44px) */
    --m19-dragonfly-size: var(--space-48);
    --m19-label-gap: var(--space-4); /* dragonfly edge -> label edge */
    --m19-swarm-heading: 70deg; /* 0 = facing outward, 90deg = along the ring (clockwise) */
    --m19-logo-ratio: 913 / 427;

    --m19-ease-out: var(--ease-out);
    --m19-ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
    --m19-duration-fast: var(--duration-fast);
    --m19-duration-base: var(--duration-base);
    --m19-duration-entrance: 720ms;
    --m19-stagger: 60ms;

    background: var(--m19-color-bg);
    color: var(--m19-color-ink);
    font-family: var(--font-sans);
}

/* ---------- Hero ---------- */

.m19-hero {
    --m19-arc-amplitude: var(--space-48);

    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--m19-space-m);
    min-height: 100svh;
    /* Bottom padding keeps the swarm clear of the scroll hint */
    padding: var(--m19-space-l) var(--m19-space-m) calc(var(--m19-space-xl) + var(--m19-space-m));
    overflow: clip;
}

.m19-hero__brand {
    width: min(72vw, var(--space-256));
    margin: 0;
}

.m19-hero__logo {
    width: 100%;
    height: auto;
    aspect-ratio: var(--m19-logo-ratio);
}

/* ---------- Scroll hint ---------- */

.m19-hero__scroll {
    position: absolute;
    bottom: var(--m19-space-s);
    left: 50%;
    translate: -50% 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--m19-space-xs);
    min-width: var(--m19-tap-size);
    min-height: var(--m19-tap-size);
    padding: var(--m19-space-xs) var(--m19-space-s);
    color: var(--m19-color-ink-muted);
    font-size: var(--m19-font-size-small);
    font-weight: var(--m19-font-weight-label);
    letter-spacing: var(--m19-tracking-label);
    text-transform: uppercase;
    text-decoration: none;
    border-radius: var(--space-4);
    transition: color var(--m19-duration-fast) ease;
}

.m19-hero__scroll-line {
    position: relative;
    width: var(--space-1);
    height: var(--space-32);
    overflow: hidden;
    background: color-mix(in oklch, currentColor 35%, transparent);
}

.m19-hero__scroll-line::after {
    content: "";
    position: absolute;
    inset: 0;
    background: currentColor;
    translate: 0 -100%;
}

.m19-hero__scroll:hover {
    color: var(--m19-color-ink);
}

.m19-hero__scroll:focus-visible {
    outline: var(--space-2) solid var(--m19-color-focus);
    outline-offset: var(--space-2);
    color: var(--m19-color-ink);
}

/* ---------- Swarm: shared ---------- */

.m19-swarm__list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.m19-swarm__link {
    color: inherit;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
}

.m19-swarm__icon {
    flex: none;
    width: var(--m19-dragonfly-size);
    height: var(--m19-dragonfly-size);
    rotate: var(--m19-icon-rotate, 0deg);
    transition: scale var(--m19-duration-base) var(--m19-ease-out);
}

.m19-swarm__label {
    position: relative;
    padding: var(--m19-space-2xs) var(--m19-space-xs);
    font-size: var(--m19-font-size-label);
    font-weight: var(--m19-font-weight-label);
    letter-spacing: var(--m19-tracking-label);
    line-height: 1.25;
    text-transform: uppercase;
    white-space: nowrap;
    border-radius: var(--space-2);
    transition: background-color var(--m19-duration-fast) ease,
    color var(--m19-duration-fast) ease;
}

/* Hairline that draws in on hover */
.m19-swarm__label::after {
    content: "";
    position: absolute;
    right: var(--m19-space-xs);
    bottom: var(--space-2);
    left: var(--m19-space-xs);
    height: var(--space-1);
    background: currentColor;
    scale: 0 1;
    transition: scale var(--m19-duration-base) var(--m19-ease-out);
}

.m19-swarm__link:hover .m19-swarm__label::after {
    scale: 1 1;
}

.m19-swarm__link:hover .m19-swarm__icon {
    scale: 1.12;
}

/* Keyboard focus: inverted label + ring around the dragonfly */
.m19-swarm__link:focus-visible {
    outline: none;
}

.m19-swarm__link:focus-visible .m19-swarm__label {
    background: var(--m19-color-ink);
    color: var(--m19-color-bg);
}

.m19-swarm__link:focus-visible .m19-swarm__icon {
    scale: 1.12;
    border-radius: 50%;
    outline: var(--space-2) solid var(--m19-color-focus);
    outline-offset: var(--space-2);
}

/* ---------- Swarm: mobile "flight path" (default) ---------- */

.m19-swarm__list {
    display: flex;
    flex-direction: column;
    gap: var(--m19-space-2xs);
}

.m19-swarm__item {
    /* t runs 0 → 180deg from first to last item; sin(t) bends the column into an arc */
    --m19-t: calc(var(--m19-swarm-index) / (var(--m19-swarm-count) - 1) * 180deg);
    --m19-icon-rotate: calc(90deg - cos(var(--m19-t)) * 28deg);

    transform: translateX(
        calc((sin(var(--m19-t)) - 0.5) * var(--m19-arc-amplitude))
    );
}

.m19-swarm__link {
    display: flex;
    align-items: center;
    gap: var(--m19-space-xs);
    min-height: var(--m19-tap-size);
    padding-inline-end: var(--m19-space-xs);
}

.m19-swarm__icon {
    margin-inline: calc((var(--m19-tap-size) - var(--m19-dragonfly-size)) / 2);
}

/* ---------- Swarm: ring (enhancement) ---------- */

@supports (top: calc(1px * cos(0deg))) {
    @media (min-width: 48rem) and (min-height: 32rem) {
        .m19-hero {
            /* Room beside the ring for the 9 and 3 o'clock labels: dragonfly half, gap and the
               widest side label ("Unser Eventkalender", ~14rem) plus a margin. Too little here
               pushes that label past the left edge of the window. */
            --m19-ring-side: calc(var(--m19-tap-size) / 2 + var(--m19-label-gap) + 15rem);
            /* Ring radius: limited by viewport height (incl. room for the bottom label and the
               scroll hint), by the width the side labels need, and a max */
            --m19-ring-r: min(34svmin, 50svh - var(--space-192), 50vw - var(--m19-ring-side), var(--space-384));
            /* Logo width relative to the ring: its corners sit at ~0.69 r, leaving clear air */
            --m19-logo-width: calc(var(--m19-ring-r) * 1.25);

            display: block;
            min-height: max(100svh, calc(2 * var(--m19-ring-r) + var(--space-192)));
            padding: 0;
        }

        .m19-hero__brand {
            position: absolute;
            top: 50%;
            left: 50%;
            width: var(--m19-logo-width);
            translate: -50% -50%;
        }

        .m19-swarm__list {
            position: absolute;
            top: 50%;
            left: 50%;
            display: block;
            width: 0;
            height: 0;
        }

        .m19-swarm__item {
            /* Angle of item i of N, clockwise from 12 o'clock */
            --m19-a: calc(-90deg + var(--m19-swarm-index) * 360deg / var(--m19-swarm-count));
            --m19-icon-rotate: calc(var(--m19-a) + 90deg + var(--m19-swarm-heading));

            position: absolute;
            top: 0;
            left: 0;
            /* Turn to the angle, step out by the radius, turn back so the content stays
               upright. Written this way (not as cos/sin offsets) so keyframes that change
               angle and radius move the dragonfly along an arc, not a straight line. */
            transform: rotate(var(--m19-a)) translateX(var(--m19-ring-r)) rotate(calc(-1 * var(--m19-a)));
        }

        .m19-swarm__link {
            position: absolute;
            display: grid;
            place-items: center;
            width: var(--m19-tap-size);
            height: var(--m19-tap-size);
            padding: 0;
            translate: -50% -50%;
        }

        .m19-swarm__label {
            /* Distance from the dragonfly centre to the label's nearest edge */
            --m19-label-d: calc(var(--m19-tap-size) / 2 + var(--m19-label-gap));

            position: absolute;
            top: 50%;
            left: 50%;
            /* Shift by -50% (centre on the point), then +50%·cos/sin so the edge facing
               the dragonfly touches it: right side → left-aligned, top → bottom edge, etc. */
            transform: translate(
                calc(-50% + 50% * cos(var(--m19-a)) + var(--m19-label-d) * cos(var(--m19-a))),
                calc(-50% + 50% * sin(var(--m19-a)) + var(--m19-label-d) * sin(var(--m19-a)))
            );
        }
    }
}

/* ---------- Motion (opt-in) ---------- */

@media (prefers-reduced-motion: no-preference) {
    /* Mobile: dragonflies drift in from the right, staggered */
    .m19-swarm__item {
        animation: m19-swarm-drift var(--m19-duration-entrance) var(--m19-ease-out) calc(var(--m19-swarm-index) * var(--m19-stagger)) backwards;
    }

    /* The entrance flap stays first in every animation list below, so adding or
       removing the hover/focus flutter never restarts it. */
    .m19-dragonfly__wings {
        --m19-flap: m19-flap 90ms var(--m19-ease-in-out) var(--m19-flap-delay) 8 alternate;
        --m19-flap-delay: calc(var(--m19-swarm-index) * var(--m19-stagger));
        --m19-flutter-delay: 0ms;

        transform-box: fill-box;
        transform-origin: center;
        animation: var(--m19-flap);
    }

    .m19-dragonfly__wings--hind {
        --m19-flap-delay: calc(var(--m19-swarm-index) * var(--m19-stagger) + 45ms);
        --m19-flutter-delay: 55ms;
    }

    @media (hover: hover) {
        .m19-swarm__link:hover .m19-dragonfly__wings {
            animation: var(--m19-flap),
            m19-flutter 110ms var(--m19-ease-in-out) var(--m19-flutter-delay) 4 alternate;
        }
    }

    .m19-swarm__link:focus-visible .m19-dragonfly__wings {
        animation: var(--m19-flap),
        m19-flutter 110ms var(--m19-ease-in-out) var(--m19-flutter-delay) 4 alternate;
    }

    .m19-hero__scroll {
        animation: m19-fade-in 600ms ease 1100ms backwards;
    }

    .m19-hero__scroll-line::after {
        animation: m19-scroll-cue 1800ms var(--m19-ease-in-out) 1400ms 3;
    }

    @supports (top: calc(1px * cos(0deg))) {
        @media (min-width: 48rem) and (min-height: 32rem) {
            /* Ring: fly in from beyond the edges on a curved path and settle,
               the dragonfly turning with the curve */
            .m19-swarm__item {
                animation-name: m19-swarm-arrive;
            }

            .m19-swarm__icon {
                animation: m19-icon-arrive var(--m19-duration-entrance) var(--m19-ease-out) calc(var(--m19-swarm-index) * var(--m19-stagger)) backwards;
            }
        }
    }

    /* Scrolling away: the dragonflies fly off outward one after another (ring) or
       drift out to the right (flight path), the logo fades and the scroll hint
       goes first. Logo and swarm sink at half the scroll speed, so they fill the
       screen while fading instead of leaving an empty band above the header.
       All of it is done once 80% of the welcome screen has scrolled out;
       scrolling back up plays it in reverse.
       Each element lists its scroll animation first and its entrance second, so
       the entrance wins while it plays and the scroll animation takes over after. */
    @supports (animation-timeline: view()) {
        .m19-hero {
            --m19-leave-stagger: 0.025;

            view-timeline: --m19-hero block;
        }

        /* Each dragonfly gets its own slice of the 0–80% range, staggered by index
           so the last one is gone exactly at 80% */
        .m19-swarm__item {
            --m19-leave-start: calc(var(--m19-swarm-index) * var(--m19-leave-stagger) * 80%);
            --m19-leave-end: calc(
                var(--m19-leave-start) + (1 - (var(--m19-swarm-count) - 1) * var(--m19-leave-stagger)) * 80%
            );

            animation: m19-swarm-leave-path linear both,
            m19-swarm-drift var(--m19-duration-entrance) var(--m19-ease-out) calc(var(--m19-swarm-index) * var(--m19-stagger)) backwards;
            animation-timeline: --m19-hero, auto;
            animation-range: exit var(--m19-leave-start) exit var(--m19-leave-end), normal;
        }

        /* 80% of the screen scrolled, 40svh sunk: half speed */
        .m19-swarm__list {
            animation: m19-sink linear both;
            animation-timeline: --m19-hero;
            animation-range: exit 0% exit 80%;
        }

        .m19-hero__logo {
            animation: m19-logo-leave linear both;
            animation-timeline: --m19-hero;
            animation-range: exit 0% exit 80%;
        }

        /* Gone after a sixth of the way */
        .m19-hero__scroll {
            animation: m19-fade-out linear both,
            m19-fade-in 600ms ease 1100ms backwards;
            animation-timeline: --m19-hero, auto;
            animation-range: exit 0% exit 13.33%, normal;
        }

        @supports (top: calc(1px * cos(0deg))) {
            @media (min-width: 48rem) and (min-height: 32rem) {
                .m19-swarm__item {
                    animation-name: m19-swarm-leave-ring, m19-swarm-arrive;
                }

                .m19-swarm__icon {
                    animation: m19-icon-leave linear both,
                    m19-icon-arrive var(--m19-duration-entrance) var(--m19-ease-out) calc(var(--m19-swarm-index) * var(--m19-stagger)) backwards;
                    animation-timeline: --m19-hero, auto;
                    animation-range: exit var(--m19-leave-start) exit var(--m19-leave-end), normal;
                }
            }
        }
    }
}

/* Browsers without scroll-driven animations (e.g. Safari 18) get the fly-away from
   site.js instead: the homepage <head> sets .m19-swarm-js for them. The entrance
   above runs in CSS everywhere. */

/* Ring entrance: from 2.6x the radius and 48deg back along the ring to the resting place */
@keyframes m19-swarm-arrive {
    from {
        opacity: 0;
        transform: rotate(calc(var(--m19-a) - 48deg)) translateX(calc(var(--m19-ring-r) * 2.6))
        rotate(calc(48deg - var(--m19-a)));
    }

    40% {
        opacity: 1;
    }

    to {
        opacity: 1;
        transform: rotate(var(--m19-a)) translateX(var(--m19-ring-r)) rotate(calc(-1 * var(--m19-a)));
    }
}

@keyframes m19-icon-arrive {
    from {
        rotate: calc(var(--m19-icon-rotate) - 48deg);
    }

    to {
        rotate: var(--m19-icon-rotate);
    }
}

/* Ring fly-away: 26deg further along the ring and out to 2.1x the radius */
@keyframes m19-swarm-leave-ring {
    from {
        opacity: 1;
        transform: rotate(var(--m19-a)) translateX(var(--m19-ring-r)) rotate(calc(-1 * var(--m19-a)));
    }

    to {
        opacity: 0;
        transform: rotate(calc(var(--m19-a) + 26deg)) translateX(calc(var(--m19-ring-r) * 2.1))
        rotate(calc(-26deg - var(--m19-a)));
    }
}

@keyframes m19-icon-leave {
    from {
        rotate: var(--m19-icon-rotate);
    }

    to {
        rotate: calc(var(--m19-icon-rotate) + 26deg);
    }
}

/* Flight path fly-away: drift out to the right */
@keyframes m19-swarm-leave-path {
    from {
        opacity: 1;
        transform: translateX(calc((sin(var(--m19-t)) - 0.5) * var(--m19-arc-amplitude)));
    }

    to {
        opacity: 0;
        transform: translateX(calc((sin(var(--m19-t)) - 0.5) * var(--m19-arc-amplitude) + var(--space-64)));
    }
}

@keyframes m19-sink {
    from {
        translate: 0 0;
    }

    to {
        translate: 0 40svh;
    }
}

@keyframes m19-logo-leave {
    from {
        opacity: 1;
        translate: 0 0;
        scale: 1;
    }

    to {
        opacity: 0.25;
        translate: 0 40svh;
        scale: 0.95;
    }
}

@keyframes m19-fade-out {
    from {
        opacity: 1;
    }

    to {
        opacity: 0;
    }
}

@keyframes m19-swarm-drift {
    from {
        opacity: 0;
        translate: var(--space-48) 0;
    }
}

@keyframes m19-flap {
    to {
        scale: 0.35 1;
    }
}

@keyframes m19-flutter {
    to {
        scale: 0.55 1;
    }
}

@keyframes m19-fade-in {
    from {
        opacity: 0;
    }
}

@keyframes m19-scroll-cue {
    to {
        translate: 0 100%;
    }
}

/* ---------- Fit into the rest of the homepage ---------- */

/* The sticky site header follows this section. When the scroll hint (or the
   skip link) jumps to <main>, leave room for that header above it. */
#inhalt {
    /* header: padding-block (2 x 16px) + logo (48px) + bottom border (1px) */
    scroll-margin-top: calc(var(--space-16) * 2 + var(--space-48) + var(--space-1));
}

/* The fixed "Tisch reservieren" bar on phones is tucked away while the
   dragonfly screen is in view (toggled by site.js). Without JavaScript it stays
   visible and takes the scroll hint's place at the bottom of the screen. */
.mobile-cta {
    transition: opacity 0.3s ease,
    translate 0.3s ease,
    visibility 0s linear 0s;
}

.mobile-cta.is-tucked {
    opacity: 0;
    translate: 0 var(--space-16);
    visibility: hidden;
    transition: opacity 0.3s ease,
    translate 0.3s ease,
    visibility 0s linear 0.3s;
}

.no-js .mobile-cta.is-tucked {
    opacity: 1;
    translate: none;
    visibility: visible;
}

@media (max-width: 639.98px) {
    .no-js .m19-hero__scroll {
        display: none;
    }
}
