:root {
    --animation-duration : 1.2s;
    --animation-function : cubic-bezier(0.6, 0, 0.4, 1);
    --max-border-radius : 25%;
    --color-light : #eee;
    --color-dark : #333;
    --scale-down : .8;
}

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: var(--color-dark);
    background-color: #333;
}
body {
    display: grid;
    place-items: center;
    background-image: radial-gradient(circle farthest-side, rgba(255, 255, 255, .15) 30%, rgba(255, 255, 255, 0));
}
*, *:before, *:after { box-sizing: content-box; }

main {
    display: block;
    overflow: hidden;
    box-shadow:
        0 0 0 10px var(--color-light),
        0 15px 20px 5px rgba(0, 0, 0, .25),
        0 0 100px 0 rgba(0, 0, 0, .25);

    position: relative;
}

.grid {
    background: var(--color-light);
    overflow: hidden;
    display: grid;
    grid-column-gap: 0;
    grid-row-gap: 0;
    position: absolute;
    top: 0;
    left: 0;
}

main, .grid {

    width: min(calc(100vh - 120px), calc(100vw - 120px));
    height: min(calc(100vh - 120px), calc(100vw - 120px));
    max-width: 600px;
    max-height: 600px;
}

.grid > .box { position: relative; }

.token, .auxToken {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 0;
}

.tokenDark {    background: var(--color-dark); }
.tokenLight {   background: var(--color-light); }
.tokenTop {     animation: var(--animation-duration) top forwards var(--animation-function); }
.tokenBottom {  animation: var(--animation-duration) bottom forwards var(--animation-function); }
.tokenLeft {    animation: var(--animation-duration) left forwards var(--animation-function); }
.tokenRight {   animation: var(--animation-duration) right forwards var(--animation-function); }

/* --- */

@keyframes top {
    0%, 25% {
        border-radius: 0;
        transform: scale(1);
        top: 0; left: 0;
    }
    50% {
        border-radius: var(--max-border-radius);
        transform: scale(var(--scale-down));
        top: 0; left: 0;
    }
    75% {
        border-radius: var(--max-border-radius);
        transform: scale(var(--scale-down));
        top: -100%;
        left: 0;
    }
    100% {
        border-radius: 0;
        transform: scale(1);
        top: -100%;
        left: 0;
    }
}
@keyframes bottom {
    0%, 25% {
        border-radius: 0;
        transform: scale(1);
        top: 0; left: 0;
    }
    50% {
        border-radius: var(--max-border-radius);
        transform: scale(var(--scale-down));
        top: 0; left: 0;
    }
    75% {
        border-radius: var(--max-border-radius);
        transform: scale(var(--scale-down));
        top: 100%;
        left: 0;
    }
    100% {
        border-radius: 0;
        transform: scale(1);
        top: 100%;
        left: 0;
    }
}
@keyframes left {
    0%, 25% {
        border-radius: 0;
        transform: scale(1);
        top: 0; left: 0;
    }
    50% {
        border-radius: var(--max-border-radius);
        transform: scale(var(--scale-down));
        top: 0; left: 0;
    }
    75% {
        border-radius: var(--max-border-radius);
        transform: scale(var(--scale-down));
        top: 0;
        left: -100%;
    }
    100% {
        border-radius: 0;
        transform: scale(1);
        top: 0;
        left: -100%;
    }
}
@keyframes right {
    0%, 25% {
        border-radius: 0;
        transform: scale(1);
        top: 0; left: 0;
    }
    50% {
        border-radius: var(--max-border-radius);
        transform: scale(var(--scale-down));
        top: 0; left: 0;
    }
    75% {
        border-radius: var(--max-border-radius);
        transform: scale(var(--scale-down));
        top: 0;
        left: 100%;
    }
    100% {
        border-radius: 0;
        transform: scale(1);
        top: 0;
        left: 100%;
    }
}

/* --- */

.auxToken {
    opacity: 0;
    animation: var(--animation-duration) aux forwards var(--animation-function);
    border-radius: var(--max-border-radius);
}
@keyframes aux {
    0%, 25% {
        opacity: 0;
        border-radius: 0;
        transform: scale(0);
    }
    50% {
        opacity: 0;
        border-radius: var(--max-border-radius);
        transform: scale(var(--scale-down));
    }
    75% {
        opacity: 1;
        border-radius: var(--max-border-radius);
        transform: scale(var(--scale-down));
    }
    100% {
        opacity: 1;
        border-radius: 0;
        transform: scale(1);
    }
}
