//vars
$fg: #115FA2;
$pi: 3.14;

//config
$menu-items: 6;
$menu-items-always-open: 3;
$open-distance: 105px;
$opening-angle: $pi*2;
$hamburger-spacing: 10px;
$default-opacity: 0.70;
$item-spacing: 64px;

%item {
    background: $fg;
    border-radius: 4px;
    width: 52px;
    height: 52px;
    margin-left: -16px;
    position: absolute;
    top: 20px;
    color: white;
    text-align: center;
    line-height: 52px;
    transform: translate3d(0, 0, 0);
    transition: transform ease-out 200ms;
    opacity: $default-opacity;

    img {
        width: 42px;
        height: 42px;
        margin: 5px;
    }

    img.icon-32 {
        width: 32px;
        height: 32px;
    }
}

%item-hover {
    opacity: 1;
}

.menu {
    position: fixed;
    top: 0;
    right: 5px;
    width: 100px;
    max-height: 100vh;
    box-sizing: border-box;
    font-size: 20px;
    text-align: center;
    z-index: 1000;

    .menu-open {
        display: none;
    }

    .menu-item, .menu-item-always-open {
        @extend %item;
        opacity: 0;
        transition-timing-function: cubic-bezier(0.165, 0.840, 0.440, 1.000);

        @for $i from 1 through $menu-items {
            &:nth-child(#{$i+2}) {
                transition-duration: 180ms;
            }
        }
    }

    @for $i from 1 through $menu-items-always-open {
        .menu-item-always-open:nth-of-type(#{$i+$menu-items}) {
            opacity: $default-opacity;
            top: 20px + $item-spacing*$i;

            &:hover {
                @extend %item-hover;
            }
        }
    }

    .hamburger {
        $width: 32px;
        $height: 4px;
        width: $width;
        height: $height;
        background: white;
        display: block;
        position: absolute;
        top: 50%;
        left: 50%;
        margin-left: -$width/2;
        margin-top: -$height/2;
        transition: transform 200ms;
        border-radius: 20px;

        &:first-of-type {
            transform: translate3d(0, -$hamburger-spacing, 0);
        }

        &:nth-of-type(2) {
            transform: translate3d(0, 0, 0);
        }

        &:last-of-type {
            transform: translate3d(0, $hamburger-spacing, 0);
        }
    }

    .menu-open:checked + .menu-open-button {
        .hamburger {
            &:first-of-type {
                transform: translate3d(0, 0, 0) rotate(45deg);
            }

            &:nth-of-type(2) {
                transform: translate3d(0, 0, 0) scale(0.1, 1);
            }

            &:last-of-type {
                transform: translate3d(0, 0, 0) rotate(-45deg);
            }
        }
    }

    .menu-open-button {
        @extend %item;
        z-index: 2;
        transition-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1.275);
        transition-duration: 400ms;
        transform: scale(1.05, 1.05) translate3d(0, 0, 0);
        cursor: pointer;

        &:hover {
            @extend %item-hover;
            transform: scale(1.1, 1.1) translate3d(0, 0, 0);
        }
    }

    .menu-open:checked + .menu-open-button {
        transition-timing-function: linear;
        transition-duration: 200ms;
        transform: scale(0.9, 0.9) translate3d(0, 0, 0);
    }

    .menu-open:checked ~ .menu-item, .menu-open:checked ~ .menu-item-always-open {
        opacity: $default-opacity;

        &:hover {
            @extend %item-hover;
        }
    }

    .menu-open:checked ~ .menu-item {
        @for $i from 1 through $menu-items {
            &:nth-child(#{$i+2}) {
                transition-duration: 90ms+(100ms*$i);
                transform: translate3d(0, $item-spacing*$i, 0);
            }
        }
    }

    .menu-open:checked ~ .menu-item-always-open {
        transition-duration: 90ms+(100ms);
        transform: translate3d(0, $item-spacing*$menu-items, 0);
    }

    .language-icon {
        font-weight: 800;
        font-size: 1.6rem;
        color: white;
        text-decoration: none;
        text-align: center;
    }

    .menu-item.has-tooltip-text {
        span {
            display: none;
            background: $fg;
            border-top-left-radius: 4px;
            border-bottom-left-radius: 4px;
            height: 52px;
            position: absolute;
            right: 25px;
            padding: 0 30px 0 15px;
            text-align: center;
            white-space: nowrap;
            line-height: 52px;
            z-index:-1;
        }

        &:hover {
            span {
                display: block;
            }
        }
    }
}

.icon-centerer {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
}
