/*
 * https://github.com/morethanwords/tweb
 * Copyright (C) 2019-2021 Eduard Kuzmenko
 * https://github.com/morethanwords/tweb/blob/master/LICENSE
 */

.ckin {
  &__player {
    user-select: none;

    &.ckin__fullscreen {
      position: fixed;
      inset: 0;
      z-index: 10000; // TODO: Check if it's big enough
      background: #000;
      border-radius: 0 !important;
      display: flex;

      .ckin__video {
        width: 100%;
        height: 100%;
        object-fit: contain;
      }
    }
  }

  &__time {
    margin-left: .875rem;
    font-size: .875rem;
    color: #fff;

    @include respond-to(handhelds) {
      margin-left: 1.125rem;
    }
  }
}

.default {
  position: relative;
  font-size: 0;
  display: flex;
	align-items: center;
	justify-content: center;

  &.show-controls:not(.default-live) .ckin__video {
    cursor: pointer;
  }

  &__button {
    color: #fff;
    // padding: .375rem;

    &--big {
      background: none;
      border: 0;
      line-height: 1;
      color: #fff;
      text-align: center;
      outline: 0;
      padding: 0;
      position: absolute;
      opacity: 1;
      top: 50%;
      left: 50%;
      transform: translate3d(-50%, -50%, 0) scale(1);
      font-size: 4rem;

      @include respond-to(not-handhelds) {
        pointer-events: none;
      }
      
      @include animation-level(2) {
        transition: opacity var(--layer-transition);
      }

      @include respond-to(handhelds) {
        font-size: 3rem;
      }
    }
  }

  &__controls {
    position: absolute;
    bottom: 0;
    right: 0;
    left: 0;
    text-align: start;
    direction: ltr;
    z-index: 6;

    @include animation-level(2) {
      transition: transform var(--layer-transition);
    }

    .btn-menu {
      margin-bottom: .25rem;
    }

    .progress-line {
      margin: 0 16px;
      border-radius: var(--border-radius);
      background: rgba(255, 255, 255, .38);
  
      &__filled {
        background: var(--primary-color);
      }

      &__loaded {
        background-color: #fff;
      }
  
      @include respond-to(handhelds) {
        margin-bottom: -1px;
      }
    }
  }

  &__gradient-bottom {
    height: 49px;
    padding-top: 49px;
    // padding-top: 93px;
    bottom: 0;
    z-index: 2;
    width: 100%;
    position: absolute;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.7));
    // background-position: bottom;
    // background-repeat: repeat-x;
    // background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAADGCAYAAAAT+OqFAAAAdklEQVQoz42QQQ7AIAgEF/T/D+kbq/RWAlnQyyazA4aoAB4FsBSA/bFjuF1EOL7VbrIrBuusmrt4ZZORfb6ehbWdnRHEIiITaEUKa5EJqUakRSaEYBJSCY2dEstQY7AuxahwXFrvZmWl2rh4JZ07z9dLtesfNj5q0FU3A5ObbwAAAABJRU5ErkJggg==);
    pointer-events: none;
    border-bottom-left-radius: inherit;
    border-bottom-right-radius: inherit;

    @include animation-level(2) {
      transition: transform var(--layer-transition);
    }
  }

  &:not(.ckin__fullscreen) .default__gradient-bottom {
    @include respond-to(handhelds) {
      display: none;
    }
  }

  &__gradient-bottom {
    transform: translate3d(0, 50px, 0);
  }

  &__controls {
    transform: translate3d(0, 52px, 0);

    @include respond-to(handhelds) {
      transform: translate3d(0, 65px, 0);
    }
  }

  &.show-controls {
    .default__gradient-bottom, 
    .default__controls {
      transform: translateZ(0);
    }
  }

  &.is-playing {
    &:not(.show-controls):not(:has(.speed-drag-handler__speed-tip--visible)) {
      cursor: none;
    }
    &:has(.speed-drag-handler__speed-tip--visible) {
      cursor: pointer;
    }
  }

  &.is-playing,
  &:not(.played),
  &.is-seeking {
    .default__button--big {
      opacity: 0;
    }
  }

  .player-volume {
    --icon-size: 2.25rem;
    --icon-margin-right: .5rem;
    --selector-size: 50px;
    --selector-thumb-size: .75rem;
    --hide-width: var(--icon-size);
    --show-width: calc(var(--icon-size) + var(--icon-margin-right) + var(--selector-size) + var(--selector-thumb-size) * .75);
    // margin: 0 .125rem;
    display: flex;
    align-items: center;
    width: var(--hide-width);
    overflow: hidden;

    @include animation-level(2) {
      transition: width var(--layer-transition);
    }

    html.is-touch & {
      // margin-left: .125rem;
      display: none;
    }

    html:not(.is-touch) & {
      & + .ckin__time {
        margin-left: .5rem;
      }
    }

    @include hover() {
      width: var(--show-width);
    }

    &__icon {
      color: #fff;
      width: var(--icon-size);
      height: var(--icon-size);
      margin-right: var(--icon-margin-right);
      cursor: pointer;
      padding: .375rem;
      font-size: 1.5rem;
      display: flex;
      pointer-events: all;
    }

    .progress-line {
      --color: #fff;
      --thumb-size: var(--selector-thumb-size);
      --height: 4px;
      margin: 0;
      width: var(--selector-size);
      min-width: var(--selector-size);

      // https://stackoverflow.com/a/4816050
      html.is-ios & {
        display: none;
      }
    }
  }

  &.is-buffering {
    .default__button--big {
      display: none !important;
    }
  }
}

.admin-popup-container {
  position: absolute;
  opacity: 1;

  @include animation-level(2) {
    transition: opacity var(--transition-standard-in);
  }

  &.admin-hidden {
    opacity: 0;
    pointer-events: none;
  }
}

video::-webkit-media-controls-enclosure {
  display: none !important;
}

.progress-line {
  --color: var(--primary-color);
  --height: 5px;
  --border-radius: 6px;
  --thumb-size: 13px;
  --focus-scale: 1.125;
  border-radius: var(--border-radius);
  height: var(--height);
  position: relative;
  cursor: pointer;

  &:before {
    position: absolute;
    inset: 0;
    display: block;
    content: " ";
    border-radius: inherit;
  }

  &__seek {
    -webkit-appearance: none;
    -moz-appearance: none;
    background: transparent;
    width: 100%;
    cursor: pointer;
    padding: 0;
    margin: 0;
    outline: none;
    caret-color: var(--color);
    position: absolute;
    top: -.5rem;
    bottom: -.5rem;

    &:focus {
      outline: none;

      /* &::-webkit-slider-runnable-track {
        background: transparent;
      }

      &::-moz-range-track {
        outline: none;
      } */
    }

    &::-webkit-slider-thumb {
      display: none;
    }

    &::-moz-range-thumb {
      display: none;
      width: 0;
      height: 0;
    }

    &::-moz-range-track {
      display: none;
    }

    &::-webkit-slider-runnable-track {
      display: none;
    }

    /* &::-webkit-slider-thumb,
    &::-moz-range-thumb,
    &::-moz-range-track,
    &::-webkit-slider-runnable-track {
      -webkit-appearance: none;
      background: transparent; 
      border-color: transparent;
      color: transparent;
      width: 0;
      height: 0;
    } */
  }

  &__filled {
    // padding-right: 1px; // * need because there is border-radius
    max-width: 100%;

    &:not(.progress-line__loaded) {
      background-color: var(--color);
      z-index: 1;

      &:after {
        content: " ";
        display: block;
        height: var(--thumb-size);
        width: var(--thumb-size);
        border-radius: 50%;
        background-color: var(--color);
        cursor: pointer;
        position: absolute;
        inset-inline-end: 0;
        top: calc((var(--thumb-size) - var(--height)) / -2);
        transform: translateX(calc(var(--thumb-size) / 2 * var(--reflect))) scale(1);

        @include animation-level(2) {
          transition: transform .125s ease-in-out;
        }
      }
    }
  }

  &.is-focused .progress-line__filled:not(.progress-line__loaded):after {
    transform: translateX(calc(var(--thumb-size) / 2 * var(--reflect))) scale(var(--focus-scale));
  }

  &__loaded,
  &:before {
    opacity: .3;
    background-color: var(--secondary-color);
  }

  &__filled, 
  &__loaded {
    border-radius: var(--border-radius);
    position: absolute;
    top: 0;
    bottom: 0;
  }

  @include animation-level(2) {
    &.with-transition {
      .progress-line__filled {
        transition: width .2s;
      }
    }
  }

  &.use-transform {
    .progress-line__filled {
      width: 100%;
      transform-origin: var(--transform-origin-left-center);
    }
  }
}

input[type=range] {
  &::-ms-track {
    visibility: hidden;
  }

  &::-ms-ticks {
    background: none;
    color: none;
    border: none;
  }

  &::-ms-thumb {
    visibility: hidden;
  }

  &::-ms-tooltip {
    visibility: hidden;
  }
}

.left-controls,
.right-controls {
  display: flex;
  align-items: center;
}

.bottom-controls {
  padding: 0 .625rem;
  height: 2.25rem;
  display: flex;
  justify-content: space-between;
  align-items: center;

  @include respond-to(handhelds) {
    height: 3.625rem;
  }
}

.loading {
  position: absolute;
  inset: 0;

  background: linear-gradient(90deg, transparent 0%, rgba(255, 255, 255, 0.5) 50%, transparent 100%);
  animation: rtmp-loading-animation 1.5s infinite cubic-bezier(0.4, 0, 0.2, 1);

  @keyframes rtmp-loading-animation {
    0%, 10% {
      transform: translateX(-100%);
    }
    100% {
      transform: translateX(100%);
    }
  }

  &_bezel-wrap {
    position: absolute;
    inset: 0;
    border-radius: inherit;
    border: 2px solid transparent;
    mask: 
      linear-gradient(#fff 0 0) padding-box, 
      linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
  
    .loading {
      height: calc(100% + 8px);
      margin-top: -4px;
    }
  }

  &-wrap {
    transition: opacity var(--transition-standard-in);
    opacity: 0;
    border-radius: inherit;

    &.is-loading {
      opacity: 1 !important;
    }
  }
}

.default-live {
  // video { display: none; }
  border-radius: $border-radius-medium;

  @include respond-to(handhelds) {
    border-radius: 0;
  }

  .ckin__video {
    border-radius: $border-radius-medium;

    @include respond-to(handhelds) {
      border-radius: 0;
    }
  }

  &.dim-background {
    background: #000;
  }
  
  .bottom-controls {
    padding: .5rem;
    height: auto;
  }

  .right-controls {
    gap: .25rem;
  }

  &.is-buffering .loading-wrap {
    opacity: 1;
  }

  .controls-live {
    background: linear-gradient(75deg, #4588E3 -79.42%, #976FFF 20.35%, #E46ACE 100.03%), #EA3323;
    display: flex;
    padding: 4px 7px;
    justify-content: center;
    align-items: center;
    border-radius: 12px;
    color: #fff;
    font-size: var(--font-size-14);
    font-weight: var(--font-weight-bold);
    line-height: normal;
    transition: filter var(--transition-standard-in);
    margin: 8px;
    filter: grayscale(1);

    &.is-not-buffering {
      filter: none;
    }
  }

  .btn-menu-toggle {
    color: #fff !important;
  }

  .player-volume {
    margin: 0 2px;
  }
}
