//
// Variables
// -----------------------------------------

$balloon-bg:             fade-out(#111, .1);
$balloon-base-size:      10px;
$balloon-arrow-height:   6px;


//
// Mixins
// -----------------------------------------

@mixin svg-arrow ($color, $position: up) {

    $degrees: 0;
    $height:  6px;
    $width:   18px;

    @if ($position == down) {
        $degrees: 180 18 6;
    } @else if ($position == left) {
        $degrees: -90 18 18;
        $width: 6px;
        $height: 18px;
    } @else if ($position == right) {
        $degrees: 90 6 6;
        $width: 6px;
        $height: 18px;
    }

    background: no-repeat url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="#{$width * 2}" height="#{$height * 2}"><path fill="#{$color}" transform="rotate(#{$degrees})" d="M2.658,0.000 C-13.615,0.000 50.938,0.000 34.662,0.000 C28.662,0.000 23.035,12.002 18.660,12.002 C14.285,12.002 8.594,0.000 2.658,0.000 Z"/></svg>');
    background-size: 100% auto;
    width: $width;
    height: $height;
}

@mixin transition ($args...) {
  -webkit-transition: $args;
  -moz-transition: $args;
  -ms-transition: $args;
  -o-transition: $args;
  transition: $args;
}

@mixin transform ($val) {
  -webkit-transform: $val;
  -moz-transform: $val;
  -ms-transform: $val;
  transform: $val;
}

@mixin transform-origin ($val) {
  -webkit-transform-origin: $val;
  -moz-transform-origin: $val;
  -ms-transform-origin: $val;
  transform-origin: $val;
}

@mixin opacity ($trans) {
  filter: alpha(opactiy=($trans * 100));
  -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=#{$trans * 100})";
  -moz-opacity: $trans;
  -khtml-opacity: $trans;
  opacity: $trans;
}

@mixin base-effects () {
    @include opacity(0);
    pointer-events: none;
    @include transition(all .18s ease-out);
}


//
// Styles
// -----------------------------------------


[data-balloon] {
    position: relative; // alt. absolute or fixed

    &:before {
        @include base-effects();

        background: $balloon-bg;
        border-radius: 4px;
        color: #fff;
        content: attr(data-balloon);
        font-size: $balloon-base-size + 2;
        padding: .5em 1em;
        position: absolute;
        white-space: nowrap;
        z-index: 10;
    }

    &:after {
        @include svg-arrow($balloon-bg);
        @include base-effects();

        content: '';
        position: absolute;
        z-index: 10;
    }

    &:hover {
        &:before,
        &:after {
            @include opacity(1);
            pointer-events: auto;
        }
    }

    &[data-balloon-break] {
        &:before {
            white-space: normal;
        }
    }

    &[data-balloon-pos="up"] {
        &:before {
            bottom: 100%;
            left: 50%;
            margin-bottom: 5px + $balloon-arrow-height;
            @include transform(translate3d(-50%, 10px, 0));
            @include transform-origin(top);
        }

        &:after {
            bottom: 100%;
            left: 50%;
            margin-bottom: 5px;
            @include transform(translate3d(-50%, 10px, 0));
            @include transform-origin(top);
        }

        &:hover {
            &:before {
                @include transform(translate3d(-50%, 0, 0));
            }

            &:after {
                @include transform(translate3d(-50%, 0, 0));
            }
        }

    }

    &[data-balloon-pos='down'] {
        &:before {
            left: 50%;
            margin-top: 5px + $balloon-arrow-height;
            top: 100%;
            @include transform(translate3d(-50%, -10px, 0));
        }

        &:after {
            @include svg-arrow($balloon-bg, 'down');

            left: 50%;
            margin-top: 5px;
            top: 100%;
            @include transform(translate3d(-50%, -10px, 0));
        }

        &:hover {
            &:before {
                @include transform(translate3d(-50%, 0, 0));
            }

            &:after {
                @include transform(translate3d(-50%, 0, 0));
            }
        }
    }

    &[data-balloon-pos='left'] {
        &:before {
            margin-right: 5px + $balloon-arrow-height;
            right: 100%;
            top: 50%;
            @include transform(translate3d(10px, -50%, 0));
        }

        &:after {
            @include svg-arrow($balloon-bg, 'left');

            margin-right: 5px;
            right: 100%;
            top: 50%;
            @include transform(translate3d(10px, -50%, 0));
        }

        &:hover {
            &:before {
                @include transform(translate3d(0, -50%, 0));
            }

            &:after {
                @include transform(translate3d(0, -50%, 0));
            }
        }

    }

    &[data-balloon-pos='right'] {
        &:before {

            left: 100%;
            margin-left: 5px + $balloon-arrow-height;
            top: 50%;
            @include transform(translate3d(-10px, -50%, 0));
        }

        &:after {
            @include svg-arrow($balloon-bg, 'right');

            left: 100%;
            margin-left: 5px;
            top: 50%;
            @include transform(translate3d(-10px, -50%, 0));
        }

        &:hover {
            &:before {
                @include transform(translate3d(0, -50%, 0));
            }

            &:after {
                @include transform(translate3d(0, -50%, 0));
            }
        }
    }

    &[data-balloon-length='small'] {
        &:before {
            white-space: normal;
            width: 80px;
        }
    }

    &[data-balloon-length='medium'] {
        &:before {
            white-space: normal;
            width: 150px;
        }
    }

    &[data-balloon-length='large'] {
        &:before {
            white-space: normal;
            width: 260px;
        }
    }

    &[data-balloon-length='xlarge'] {
        &:before {
            white-space: normal;
            width: 380px;

            @media screen and (max-width: 768px) {
                white-space: normal;
                width: 90vw;
            }
        }
    }

    &[data-balloon-length='fit'] {
        &:before {
            white-space: normal;
            width: 100%;
        }
    }
}
