/* Schnittstellen: the picture of the connections, and a page per connection with
   its details and what is kept from it. */

@layer connector {
    /*
     * The picture at the top: Mission Control as a dark hub, a trunk beside it, and
     * one line per system from the trunk to the plate of the system. The state sits
     * on the line as a badge with its word, and the line says it by its form too:
     * solid when reachable, dashed when unknown or replaced by a stand-in, dashed
     * and broken on both sides of the badge for missing access data or an error.
     *
     * Laid out by the grid, not by coordinates: every row is as high as its plate,
     * the lines of all rows share one column that is at least as wide as the widest
     * badge with its word, and the trunk is built from one segment per row. So the
     * picture holds any number of systems and no text can run into a line. Narrow
     * windows, and browsers without container queries, get a list with the trunk
     * running down from the hub.
     */
    /* The picture stands alone on its page, so it gets room above and below. */
    .network-frame {
        container: network / inline-size;
        margin-block: clamp(24px, 4vw, 56px) clamp(32px, 6vw, 80px);
    }

    .network {
        --hub: 120px;
        --badge: 38px;
        --branch: 22px;
        --gap: 24px;
        --wire: #bdb8af;

        max-width: 1180px;
        margin-inline: auto;
        padding-block: 16px;
    }

    @media (prefers-color-scheme: dark) {
        .network {
            --wire: #4d4843;
        }
    }

    /* The hub, in the manner of the orbit in the services of postyou.de: a dark
       round centre with a gold ring that pulses outwards, raised above a second
       plate that lies offset beneath it. */
    .network__center {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
    }

    .network__hub {
        position: relative;
        flex: none;
        width: var(--hub);
        height: var(--hub);
    }

    /* Painted in this order without z-index: plate, face, ring. */
    .network__hub::before {
        content: "";
        position: absolute;
        inset: 0;
        background: var(--line);
        border-radius: 50%;
        transform: translate(5px, 7px);
    }

    .network__hub::after {
        content: "";
        position: absolute;
        inset: 0;
        border: 1px solid var(--gold);
        border-radius: 50%;
        opacity: 0;
        pointer-events: none;
        animation: orbit-pulse-scale 3.2s ease-out infinite;
    }

    .network__face {
        position: relative;
        display: grid;
        place-content: center;
        justify-items: center;
        gap: 8px;
        height: 100%;
        border-radius: 50%;
        background-color: #1f1d1b;
        background-image: var(--grain-fine);
        background-size: var(--grain-size);
        color: #f5f4f1;
        text-align: center;
        outline: 1px solid rgb(206 175 88 / 0.45);
        outline-offset: 5px;
        box-shadow: var(--shadow-plate), 0 18px 40px rgb(31 29 27 / 0.18);
        transform: perspective(600px) rotateX(var(--tilt-y, 0deg)) rotateY(var(--tilt-x, 0deg));
        transition: transform 0.4s var(--ease);
    }

    .network__face .logo {
        height: 11px;
    }

    .network__product {
        font-weight: 500;
        font-size: 13px;
        line-height: 1.2;
        letter-spacing: 0.02em;
    }

    /* From the hub to the trunk: downwards in the list, sideways in the picture. */
    .network__stem {
        width: 0;
        height: var(--gap);
        margin-left: calc(var(--hub) / 2 - 1px);
        border-left: 2px solid var(--wire);
    }

    .network__systems {
        margin-left: calc(var(--hub) / 2 - 1px);
    }

    .network__item {
        position: relative;
        animation: network-reveal 0.9s var(--ease) both;
        animation-delay: calc(var(--i, 0) * 90ms + 120ms);
    }

    .network__item + .network__item {
        margin-top: var(--gap);
    }

    /* The trunk, one segment per row. Each bridges half the gap above and below
       it, the first starts at the stem and the last ends at its own line. */
    .network__item::before {
        content: "";
        position: absolute;
        top: calc(var(--gap) / -2);
        bottom: calc(var(--gap) / -2);
        left: 0;
        width: 2px;
        background: var(--wire);
    }

    .network__item:first-child::before {
        top: 0;
    }

    .network__item:last-child::before {
        bottom: calc(100% - var(--badge) / 2);
    }

    .network__link {
        --state: var(--unknown);

        display: block;
        color: inherit;
        text-decoration: none;
    }

    .network__link--ok {
        --state: var(--ok);
    }

    .network__link--warning {
        --state: var(--warning);
    }

    .network__link--critical {
        --state: var(--critical);
    }

    /* The focus is shown on the plate, which is what the link stands for. */
    .network__link:focus-visible {
        outline: none;
    }

    .network__link:focus-visible .network__node {
        outline: 2px solid var(--gold-dark);
        outline-offset: 3px;
    }

    .network__line {
        position: relative;
        display: flex;
        align-items: center;
        height: var(--badge);
        color: var(--state);
    }

    .network__wire {
        flex: 0 0 var(--branch);
        border-top: 2px solid currentColor;
    }

    .network__wire--end {
        display: none;
    }

    .network__link--unknown .network__wire,
    .network__link--warning .network__wire,
    .network__link--critical .network__wire {
        border-top-style: dashed;
    }

    /* Broken: the line does not reach the badge, nor the system. */
    .network__link--warning .network__wire,
    .network__link--critical .network__wire {
        margin-right: 8px;
    }

    .network__link--warning .network__wire--end,
    .network__link--critical .network__wire--end {
        margin-right: 16px;
        margin-left: 8px;
    }

    /* May shrink only where the window is narrower than about 330 pixels. The
       column of the wide picture is always wide enough, see .network__systems. */
    .network__state {
        position: relative;
        display: inline-flex;
        flex: 0 1 auto;
        align-items: center;
        min-width: 0;
        gap: 8px;
        height: var(--badge);
        padding: 0 14px 0 3px;
        background: var(--surface);
        border: 1px solid var(--line);
        border-radius: 100px;
        color: var(--text-primary);
        font-weight: 500;
        font-size: 14px;
        white-space: nowrap;
    }

    .network__word {
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .network__badge {
        display: grid;
        flex: none;
        place-items: center;
        width: calc(var(--badge) - 8px);
        height: calc(var(--badge) - 8px);
        border: 2px solid var(--state);
        border-radius: 50%;
    }

    .network__badge .icon {
        width: 16px;
        height: 16px;
        vertical-align: 0;
    }

    /* Something travels on a working line, slowly, from the hub to the system and
       back, and the lines do not move in step. It passes behind the badge. */
    .network__track {
        display: none;
        position: absolute;
        inset: 0;
        container-type: inline-size;
        pointer-events: none;
    }

    .network__dot {
        position: absolute;
        top: 50%;
        left: 0;
        width: 8px;
        height: 8px;
        margin-top: -4px;
        background: currentColor;
        border-radius: 50%;
        animation: network-travel 7s var(--ease) infinite alternate;
        animation-delay: calc(var(--i, 0) * -1.9s);
    }

    .network__node {
        display: grid;
        grid-template-columns: auto minmax(0, 1fr);
        column-gap: 14px;
        align-items: center;
        margin: 10px 0 0 var(--branch);
        padding: 16px 20px;
        background: var(--surface);
        border: 1px solid var(--line);
        box-shadow: var(--shadow-plate);
        transform: perspective(700px) rotateX(var(--tilt-y, 0deg)) rotateY(var(--tilt-x, 0deg)) translateY(var(--lift, 0px));
        transition:
            transform 0.4s var(--ease),
            box-shadow 0.4s var(--ease),
            border-color 0.15s;
    }

    .network__link:hover .network__node,
    .network__link:focus-visible .network__node {
        --lift: -3px;

        border-color: var(--text-secondary);
        box-shadow: var(--shadow-lifted);
    }

    .network__pictogram {
        display: grid;
        grid-row: span 2;
        place-items: center;
        width: 48px;
        height: 48px;
        background-color: var(--page);
        background-image: var(--grain-paper);
        background-size: var(--grain-size);
        background-blend-mode: soft-light;
    }

    .network__pictogram .icon {
        width: 26px;
        height: 26px;
        vertical-align: 0;
    }

    .network__name {
        font-weight: 600;
        font-size: 19px;
        line-height: 1.25;
    }

    .network__use {
        color: var(--text-secondary);
        font-size: 14px;
        line-height: 1.35;
    }

    /* Wide enough for the picture: hub on the left, vertically centred on the
       trunk, and the rows as a grid whose two columns all rows share (subgrid). */
    @container network (min-width: 900px) {
        .network {
            --hub: 196px;

            display: grid;
            grid-template-columns: auto minmax(0, 1fr);
        }

        .network__center {
            flex-direction: row;
            align-items: center;
        }

        .network__face {
            gap: 10px;
        }

        .network__face .logo {
            height: 14px;
        }

        .network__product {
            font-size: 16px;
        }

        .network__stem {
            flex: 1 0 48px;
            height: 0;
            margin-left: 0;
            border-top: 2px solid var(--wire);
            border-left: 0;
        }

        .network__systems {
            display: grid;
            grid-template-columns: minmax(max-content, 1fr) minmax(260px, 400px);
            row-gap: var(--gap);
            margin-left: 0;
        }

        .network__item,
        .network__region,
        .network__link {
            display: grid;
            grid-column: 1 / -1;
            grid-template-columns: subgrid;
            align-items: center;
        }

        .network__item + .network__item {
            margin-top: 0;
        }

        .network__item:first-child::before {
            top: 50%;
        }

        .network__item:last-child::before {
            bottom: 50%;
        }

        .network__wire {
            flex: 1 0 32px;
        }

        .network__wire--end {
            display: block;
        }

        .network__track {
            display: block;
        }

        .network__node {
            margin: 0;
        }
    }

    @keyframes orbit-pulse-scale {
        0% {
            opacity: 0;
            transform: scale(1);
        }

        8% {
            opacity: 0.55;
        }

        100% {
            opacity: 0;
            transform: scale(1.5);
        }
    }

    @keyframes network-travel {
        0% {
            opacity: 0;
            transform: translateX(0);
        }

        15%,
        85% {
            opacity: 1;
        }

        100% {
            opacity: 0;
            transform: translateX(calc(100cqw - 8px));
        }
    }

    @keyframes network-reveal {
        from {
            opacity: 0;
            transform: translateY(24px);
        }
    }

    @media (prefers-reduced-motion: reduce) {
        .network__hub::after,
        .network__track {
            display: none;
        }

        .network__item {
            animation: none;
        }

        .network__face,
        .network__node {
            transform: none;
            transition: none;
        }
    }

    /* The page of one connection. */
    .connection__title {
        display: flex;
        align-items: center;
        gap: 16px;
    }

    .connection__icon {
        display: inline-flex;
        flex: none;
        width: 0.9em;
        height: 0.9em;
    }

    .connection__icon .icon {
        width: 100%;
        height: 100%;
        vertical-align: 0;
    }

    .connection__heading {
        font-weight: 600;
        font-size: 24px;
        line-height: 1.2;
    }

    .connection__facts {
        row-gap: 18px;
        max-width: 80ch;
    }

    .connection__actions {
        margin-top: 20px;
    }

    .kept__body,
    .kept__modules {
        display: grid;
        gap: 28px;
    }

    .kept__more {
        padding: 10px 16px 14px;
        color: var(--text-secondary);
        font-size: 14px;
    }

    .kept__link {
        margin-top: 10px;
    }

    .kept__none {
        color: var(--text-secondary);
    }

    .connector-columns {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
        gap: 24px;
        align-items: start;
    }
}
