@import 'mixins';

.nplayer {
  
  --theme-color: #007aff;
  --poster-bg-color: transparent;
  --progress-bg: #007aff;
  --volume-progress-bg: #007aff;

  $control_bottom: 8px;

  --safe-area-inset-bottom: $control_bottom;
  @supports (padding-bottom: constant(safe-area-inset-bottom)) {
    --safe-area-inset-bottom: max(#{$control_bottom}, constant(safe-area-inset-bottom));
  }

  @supports (padding-bottom: env(safe-area-inset-bottom)) {
    --safe-area-inset-bottom: max(#{$control_bottom}, env(safe-area-inset-bottom));
  }
  

  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  background: #000;
  font-family: -apple-system, BlinkMacSystemFont, 'Microsoft YaHei';
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  z-index: auto;
  user-select: none;

  * { box-sizing: content-box; }

  $control-z-index: 10;

  &_control { z-index: $control-z-index; &_bg { z-index: 9; } }
  &_poster { z-index: 20; }
  &_loading { z-index: 30; }
  &_contextmenu { z-index: 40; }
  &_toast { z-index: 50; }

  &:focus {
    outline: none;
  }

  &_flex {
    display: flex;
  }

  &_align-center {
    align-items: center;
  }

  &-web-full {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: 0;
    z-index: 99999;
  }

  &-web-full &_control {
    padding-bottom: var(--safe-area-inset-bottom);
  }

  &-loading &_loading {
    display: block;
  }

  &_icon {
    width: 28px;
    height: 28px;
    fill: #fff;
  }

  &_video {
    width: 100%;
    max-height: 100%;
    outline: none;
    touch-action: none;
  }

  &_spacer {
    flex: 1;
  }

  &_tooltip {
    position: relative;
    padding: 3px;
    transition: background .2s ease;
    cursor: pointer;

    @include hover {
      &:hover {
        background: var(--theme-color);
      }
  
      &:hover &_content {
        opacity: 1;
        transform: translate(-50%, 0);
      }
  
      &:hover &-left {
        transform: translate(0, 0);
      }
  
      &:hover &-right {
        transform: translate(0, 0);
      }
    }

    &_content {
      position: absolute;
      left: 50%;
      bottom: 100%;
      font-size: 12px;
      margin-bottom: 10px;
      padding: 5px 10px;
      white-space: nowrap;
      background: rgba(0, 0, 0, .7);
      transform: translate(-50%, 10px) scale(.8);
      transform-origin: 50% 100%;
      pointer-events: none;
      opacity: 0;
      transition: transform .2s .1s ease,opacity .2s .1s ease;
    }

    &-left {
      left: 0;
      transform: translate(0,10px) scale(.8);
      transform-origin: 0 100%;
    }

    &-right {
      left: auto;
      right: 0;
      transform: translate(0,10px) scale(.8);
      transform-origin: 100% 100%;
    }

    &-bottom {
      top: 100%;
      bottom: auto;
      margin-top: 10px;
      margin-bottom: 0;
      transform: translate(-50%, -10px) scale(.8);
    }

    $p: &;
    &-bottom {
      &#{$p}-left, &#{$p}-right {
        transform: translate(0,-10px) scale(.8);
      }
    }
  }


  &_popover {
    pointer-events: none;

    &-active {
      pointer-events: auto;
    }

    &-active &_panel {
      opacity: 1;
      transform: translateY(0);
    }

    &_panel {
      position: absolute;
      bottom: 100%;
      opacity: 0;
      right: 0;
      margin-bottom: 5px;
      padding: 3px 0;
      font-size: 14px;
      white-space: nowrap;
      overflow: hidden;
      transform: translateY(10px);
      background: rgba(0, 0, 0, .7);
      box-shadow: 0 1px 20px 1px rgba(0,0,0,.2);
      z-index: 2;
      transition: opacity .2s ease, transform .2s ease, height .2s cubic-bezier(.4,0,.2,1), width .2s cubic-bezier(.4,0,.2,1);

      &-bottom {
        bottom: auto;
        top: 100%;
        margin-top: 5px;
        margin-bottom: 0;
        transform: translateY(-10px);
      }

      &-left {
        left: 0;
        right: auto;
      }
    }

    &_mask {
      position: fixed;
      left: 0;
      right: 0;
      bottom: 0;
      top: 0;
      z-index: 1;
    }
  }

  &_switch {
    display: inline-block;
    width: 30px;
    padding: 2px;
    border-radius: 10px;
    background: rgba(255, 255, 255, .3);
    transition: background-color .3s cubic-bezier(.4, 0, .2, 1);
    cursor: pointer;
    user-select: none;

    &::after {
      content: '';
      display: block;
      width: 15px;
      height: 15px;
      border-radius: 50%;
      background: #fff;
      box-shadow: 0px 2px 1px -1px rgba(0,0,0,0.2), 0px 1px 1px 0px rgba(0,0,0,.14), 0px 1px 3px 0px rgba(0,0,0,.12);
      transition: transform .15s cubic-bezier(.4, 0, .2, 1);
    }

    &-active {
      background: var(--theme-color);

      &::after {
        transform: translateX(16px);
      }
    }
  }

  &_loading {
    display: none;
    pointer-events: none;
    position: absolute;
    left: 50%;
    top: 50%;
    width: 70px;
    height: 70px;
    transform: translate(-50%, -50%);

    i {
      position: absolute;
      left: 44.5%;
      top: 37%;
      width: 5px;
      height: 25%;
      border-radius: 50%/20%;
      opacity: .25;
      background-color: #fff;
      animation: nplayer-loading 1s linear infinite;
    }

    @for $i from 1 through 12 {
      i:nth-child(#{$i}) {
        transform: rotate(-180deg + 30 * $i) translateY(-150%);
        animation-delay: .0833s * ($i - 1);
      }
    }
  }

  &_toast {
    position: absolute;
    padding: 3px 5px;
    font-size: 16px;
    white-space: nowrap;
    background: rgba(0, 0, 0, .7);

    $pad-size: 5px;

    &-center {
      left: 50%;
      top: 50%;
      transform: translate(-50%, -50%);
    }

    &-left-top, &-right-top {
      top: $pad-size;
    }

    &-left-top, &-left-bottom {
      left: $pad-size;
    }

    &-right-top, &-right-bottom {
      right: $pad-size;
    }

    &-left-bottom, &-right-bottom {
      bottom: 60px;
    }
  }

  &_slider {
    display: inline-block;
    flex: 1;
    margin: 0 6px;
    padding: 5px 0;
    position: relative;
    cursor: pointer;
    user-select: none;

    &_track {
      width: 100%;
      height: 4px;
      overflow: hidden;
      background: rgba(255, 255, 255, 0.3);

      &_inner {
        height: 100%;
        transform-origin: 0 0;
        background: var(--theme-color);
      }
    }

    &_stop {
      position: absolute;
      width: 3px;
      height: 8px;
      top: 3px;
      white-space: nowrap;
      font-size: 12px;
      background: rgba(255, 255, 255, 0.7);

      span {
        position: absolute;
        left: 2px;
        top: 6px;
        transform: translateX(-50%);
      }

    }

    &_dot {
      position: absolute;
      top: .5px;
      left: -6px;
      width: 13px;
      height: 13px;
      border-radius: 50%;
      pointer-events: none;
      background: var(--theme-color);
    }

  }

  &_checkbox {
    position: relative;
    display: inline-flex;
    align-items: center;
    font-size: 12px;
    color: #fff;
    cursor: pointer;
    user-select: none;
    transition: color .2s ease;

    &::before {
      content: '';
      display: block;
      width: 1em;
      height: 1em;
      border: 1px solid currentColor;
      border-radius: 2px;
      margin-right: 5px;
      transition: background .2s ease;
    }

    &::after {
      content: '';
      position: absolute;
      opacity: 0;
      left: 0.5em;
      top: 50%;
      width: 4px;
      height: 7px;
      border: 1px solid #fff;
      border-top: 0;
      border-left: 0;
      transform: translate(-30%, -70%) rotate(45deg);
    }

    &:hover {
      color: var(--theme-color);
    }

    &-active {
      &::before {
        background: var(--theme-color);
        border-color: var(--theme-color);
      }

      &::after {
        opacity: 1;
      }
    }
  }

  &_poster {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    top: 0;
    background-repeat: no-repeat;
    background-position: 50% 50%;
    background-size: cover;
    background-color: var(--poster-bg-color);

    &_play {
      position: absolute;
      left: 50%;
      top: 50%;
      width: 50px;
      height: 50px;
      transform: translate(-50%, -50%);
      cursor: pointer;
    }
  }

  &_control {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    user-select: none;
    padding: 0 5px 8px;
    transition: opacity .2s ease;

    &-hide {
      opacity: 0;
      pointer-events: none;
    }

    &:hover {
      opacity: 1 !important;
      pointer-events: initial !important;
      cursor: default !important;
    }

    &:hover ~ &_bg {
      opacity: 1 !important;
    }

    &_bg {
      position: absolute;
      left: 0;
      right: 0;
      bottom: 0;
      height: 100px;
      background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAADGCAYAAAAT+OqFAAAAdklEQVQoz42QQQ7AIAgEF/T/D+kbq/RWAlnQyyazA4aoAB4FsBSA/bFjuF1EOL7VbrIrBuusmrt4ZZORfb6ehbWdnRHEIiITaEUKa5EJqUakRSaEYBJSCY2dEstQY7AuxahwXFrvZmWl2rh4JZ07z9dLtesfNj5q0FU3A5ObbwAAAABJRU5ErkJggg==) repeat-x bottom;
      pointer-events: none;
      transition: opacity .2s ease;

      &-hide {
        opacity: 0;
      }
    }

    &_bar {
      display: flex;
      align-items: center;
      font-size: 0;

      &-top {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        transition: opacity .2s ease;
        padding-top: 5px;
        z-index: $control-z-index;
      }

      &-hide {
        opacity: 0;
        pointer-events: none;
      }

      > div {
        margin: 0 3px;
      }
    }

    &_time {
      font-size: 13px;
      white-space: nowrap;

      &-live {
        display: flex;
        align-items: center;
      }

      &-live::before {
        content: '';
        display: block;
        width: 10px;
        height: 10px;
        margin-right: 5px;
        margin-top: 2px;
        border-radius: 50%;
        background: var(--theme-color);
      }

      :first-child::after {
        content: '/';
        display: inline-block;
        font-size: 12px;
        margin: 0 5px;
        transform: translateY(-0.5px);
      }
    }

    &_volume {
      position: relative;
      z-index: 1;

      &-ver &_bars {
        left: 0;
        right: 0;
        bottom: 100%;
      }

      &-hor &_bars {
        top: 0;
        bottom: 0;
        left: 100%;
      }

      &_bars {
        position: absolute;
        font-size: 0;
        background: rgba(255, 255, 255, .3);
        opacity: 0;
        pointer-events: none;
        overflow: hidden;
        transition: opacity .2s ease;
      }

      &:hover &_bars {
        opacity: 1;
        pointer-events: auto;
      }

      &_bar {
        width: 100%;
        height: 100%;
        transform-origin: 0 100%;
        transform: scaleX(0) scaleY(0);
        will-change: transform;
        background: var(--volume-progress-bg);
      }
    }

    &_setting {

      .nplayer_icon {
        transition: transform .2s ease;
      }

      &-active {
        background: var(--theme-color);

        .nplayer_icon {
          transform: rotate(90deg);
        }
      }

      &_item, &_option {
        display: flex;
        align-items: center;
        padding: 5px 8px;

        &:hover {
          background: rgba(255, 255, 255, .2);
        }
      }

      &_item {
        justify-content: space-between;

        & > :first-child {
          margin-right: 20px;
        }

        &-select {
          &::after {
            content: '';
            display: block;
            width: 0;
            height: 0;
            margin-left: 10px;
            border: 4px solid transparent;
            border-left-color: #fff;
          }
        }
      }

      &_option {

        &::before {
          content: '';
          opacity: 0;
          margin-left: 6px;
          margin-right: 17px;
          @include check-mark;
        }

        &-active {
          &::before {
            opacity: 1;
          }
        }
      }

      &_back {
        justify-content: flex-start;
        padding-right: 20px;
        border-bottom: 1px solid rgba(255, 255, 255, .2);

        &::before {
          content: '';
          display: block;
          width: 0;
          height: 0;
          margin-right: 21px;
          border: 4px solid transparent;
          border-right-color: #fff;
        }
      }
    }
  }

  &_contextmenu {
    position: absolute;
    top: 0;
    left: 0;
    padding: 3px 0;
    font-size: 14px;
    background: rgba(0, 0, 0, .7);

    &_item {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 5px 8px;
      white-space: nowrap;
      cursor: pointer;
      user-select: none;

      &:hover {
        background: rgba(255, 255, 255, .2);
      }

      &-disabled {
        color: rgba(255, 255, 255, .5);

        &:hover {
          background: transparent;
        }
      }

      &-checked {
        &::after {
          content: '';
          @include check-mark;
          margin: 0 2px 5px 2px
        }
      }
    }
  }

  &_progress {
    position: relative;
    cursor: pointer;
    padding: 5px 0;
    flex: 1;

    &_bars {
      position: relative;
      height: 4px;
      background: rgba(255, 255, 255, .3);
      
      touch-action: none;
      transition: height .12s ease;
      overflow: hidden;
    }

    &_dot {
      position: absolute;
      left: 0;
      top: 50%;
      transform: translateY(-50%);
      pointer-events: none;
      transition: opacity .2s ease;

      > :first-child {
        transform: translate(-50%);
      }

      &_inner {
        width: 13px;
        height: 13px;
        border-radius: 50%;
        background: var(--theme-color);
      }
    }

    @include hover {
      &_dot {
        opacity: 0;
      }
      &:hover &_dot {
        opacity: 1;
      }
    }

    &_played, &_buf {
      position: absolute;
      left: 0;
      right: 0;
      top: 0;
      bottom: 0;
      transform-origin: 0 0;
      transform: scaleX(0);
    }

    &_played {
      will-change: transform;
      background: var(--progress-bg);
    }

    &_buf {
      background: rgba(255, 255, 255, .5);
    }

    &_hover {
      opacity: 0;
      background: rgba(255, 255, 255, .5);
    }
  }

  &_progress:hover &_thumb {
    display: block;
  }

  &_thumb {
    display: none;
    position: absolute;
    left: 0;
    bottom: 20px;
    font-size: 12px;
    text-align: center; 
    pointer-events: none;
    text-shadow: 0 0 2px rgba(0,0,0,.3);

    &_img {
      border: 1px solid #fff;
      box-shadow: 0 0 10px rgba(0,0,0,0.1);
      background-color: rgba(255, 255, 255, .5);
      background-repeat: no-repeat;
    }

    &_time {
      display: inline-block;
      margin-top: 5px;
      padding: 2px 5px 3px;
      border-radius: 3px;
      background: rgba(0, 0, 0, .7);
    }
  }
}

@keyframes nplayer-loading {
  0% {
    opacity: .85;
  }
  50% {
    opacity: .25;
  }
  100% {
    opacity: .25;
  }
}
