//******
// SEE https://github.com/kazzkiq/balloon.css
// ******


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

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

$breakpoint:             860px; //When to not show annotations


//
// 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 .18s);
}


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

@media screen and (min-width: $breakpoint) {
  [data-balloon] {
      position: relative; // alt. absolute or fixed

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

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

      &:before {
          @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] {
          &:after {
              white-space: normal;
          }
      }

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

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

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

      }

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

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

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

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

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

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

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

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

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

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

      }

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

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

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

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

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

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

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

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

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

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

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

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

// Additional styles to make the buttons look like text

button {
  border: none;
  background: none;
  font-size: inherit;
  font-family: inherit;
  color: inherit;
  margin: 0;
  padding: 0;
  border-bottom: 1px dotted $dark-grey;
  cursor: help;
}

div#smallscreens {
  display:none;
}


@media screen and (max-width: ($breakpoint - 1)) {
  div#annotatededition {
    display: none;
  }
  
  div#smallscreens {
  display:inline;
  }
}
