src/modules/profile/recentTracks/styles/recentTracks.css
@import './customProperties.css';

@import './backgrounds.css';

@keyframes rotate {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

@keyframes image-shift {
  0% { transform: translateY(-50%); }
  25% { transform: translateY(-75%); }
  50% { transform: translateY(-50%); }
  75% { transform: translateY(-25%); }
  100% { transform: translateY(-50%); }
}

[data-element="rymstats-track-artist-link"],
[data-element="rymstats-track-link"],
[data-element="rymstats-track-album-link"] {
  font-weight: bold;
  position: relative;

  &:after {
    content: '';
    border-bottom: 1px solid transparent;
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
  }

  &:hover:after {
    border-bottom-color: currentColor;
  }
}

[data-element="rymstats-track-item"] {
  padding-top: 0;
  position: relative;
  align-items: center;

  [data-element="rymstats-track-artbox"] {
    transition: all .3s ease-out;
    transform: translateX(0);
    opacity: 1;

    &.is-transitioning {
      transform: translateX(-50%);
      opacity: 0;
    }

    max-width: none;

    a {
      position: relative;

      &:before {
        content: '';
        position: absolute;
        z-index: 1;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 33%;
        height: 33%;
        border-radius: 50%;
        margin: auto;
        background-color: color-mix(in lab, var(--clr-dark-accent), transparent 40%);
        outline: 2px solid color-mix(in lab, var(--clr-dark-accent), white 10%);
        outline-offset: -2px;
        box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
        opacity: 0;
        z-index: 100;
        transition: opacity .15s ease-in-out, transform .15s ease-in-out;
      }

      img {
        outline: 2px solid color-mix(in lab, var(--clr-dark-accent), transparent 50%);
        outline-offset: -2px;
      }
    }
  }

  [data-element="rymstats-track-infobox"] {
    padding: 0;
    overflow: visible;
  }

  [data-element="rymstats-track-item-date"] {
    color: var(--clr-accent);

    svg {
      width: 12px;
      height: 12px;
      opacity: 1;
      margin-left: 1rem;
    }
  }

  [data-element="rymstats-track-item-art"] {
    display: block;
    width: 145px;
    height: 145px;
    max-width: none;
  }

  [data-element="rymstats-track-rating"] {
    font-size: 0.8em;
    width: fit-content;
    margin-bottom: 1.25em;
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: bold;
    color: var(--clr-accent);

    &.no-rating {
      [data-element="rymstats-track-rating-stars"] {
        & > * {
          opacity: 0.15;
          filter: grayscale(100%);
        }

        &:after {
          content: 'Not rated';
          color: var(--clr-accent);
          text-transform: uppercase;
          position: absolute;
          inset: 0;
          display: flex;
          align-items: center;
          justify-content: center;
          font-weight: bold;
          letter-spacing: 0.25em;
        }
      }
    }

    &.has-ownership {
      [data-element="rymstats-track-format"] {
        display: block;
      }
    }

    [data-element="rymstats-track-rating-stars"] {
      position: relative;
    }

    [data-element="rymstats-track-format"] {
      display: none;
    }

    .stars-filled,
    .stars-empty {
      display: flex;
      flex-wrap: nowrap;

      & > * {
        flex-shrink: 0;
      }
    }

    .stars-filled {
      position: absolute;
      overflow: hidden;
      white-space: nowrap;
      inset: 0;
      transition: width .3s ease-in-out;

      svg {
        color: color-mix(in lab, currentColor, transparent 50%);
        fill: var(--clr-dark-accent);
      }
    }

    .stars-empty {
      svg {
        color: color-mix(in lab, currentColor, transparent 90%);
        fill: transparent;
      }
    }

    svg {
      width: 2em;
      height: 2em;
    }
  }

  [data-element="rymstats-from-album"] {
    font-size: 0.8em;
    width: fit-content;
    margin-top: 1.75em;

    &:before {
      content: 'Album: ';
      color: var(--clr-accent);
      display: none;
    }

    &:has(a):before {
      display: inline;
    }
  }

  &.is-now-playing {
    /* [data-element="rymstats-track-item-date"] svg {
      display: inline;
    } */

    [data-element="rymstats-track-artbox"] {
      border-radius: 50%;
      position: relative;

      a {
        mask-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><rect width="100%" height="100%" fill="white"/><circle cx="50" cy="50" r="9" fill="black"/></svg>');
        mask-repeat: no-repeat;
        mask-size: 100% 100%;
        mask-mode: luminance;

        img {
          animation: rotate 9s linear infinite;
          border-radius: 50%;
          outline: 4px solid color-mix(in lab, var(--clr-dark-accent), transparent 50%);
          outline-offset: -4px;
          border-width: 2px;
          border-style: solid;
        }

        &:after {
          content: '';
          border-radius: 50%;
          position: absolute;
          inset: 4px;
          background: conic-gradient(from 30deg,
              rgba(255, 255, 255, 0) 0deg,
              rgba(255, 255, 255, 0.1) calc(15deg - 7deg),
              rgba(255, 255, 255, 0.2) calc(15deg),
              rgba(255, 255, 255, 0.1) calc(15deg + 7deg),
              rgba(255, 255, 255, 0) 30deg,

              rgba(255, 255, 255, 0) calc(15deg + 180deg - 50deg),
              rgba(255, 255, 255, 0.05) calc(15deg + 180deg - 40deg),
              rgba(255, 255, 255, 0.1) calc(15deg + 180deg - 30deg),
              rgba(255, 255, 255, 0.125) calc(15deg + 180deg - 20deg),
              rgba(255, 255, 255, 0.15) calc(15deg + 180deg - 10deg),
              rgba(255, 255, 255, 0.175) calc(15deg + 180deg),
              rgba(255, 255, 255, 0.15) calc(15deg + 180deg + 10deg),
              rgba(255, 255, 255, 0.125) calc(15deg + 180deg + 20deg),
              rgba(255, 255, 255, 0.1) calc(15deg + 180deg + 30deg),
              rgba(255, 255, 255, 0.05) calc(15deg + 180deg + 40deg),
              rgba(255, 255, 255, 0) calc(15deg + 180deg + 50deg),

              transparent 360deg);
        }

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

html[data-scheme="dark"] {
  [data-element="rymstats-track-item"] {
    [data-element="rymstats-track-artbox"] {
      box-shadow: 0 0 0.5em rgba(0, 0, 0, 0.75);
    }

    &.is-now-playing {
      [data-element="rymstats-track-artbox"] {
        a {
          img {
            border-color: color-mix(in lab, var(--clr-dark-accent), white 50%);
          }
        }
      }
    }
  }
}

html[data-scheme="light"] {
  [data-element="rymstats-track-item"] {
    [data-element="rymstats-track-artbox"] {
      box-shadow: 0 0 0.5em rgba(255, 255, 255, 0.75);
    }

    &.is-now-playing {
      [data-element="rymstats-track-artbox"] {
        a {
          img {
            border-color: color-mix(in lab, var(--clr-light-accent), black 50%);
          }
        }
      }
    }
  }
}

#profile_play_history_container {
  position: relative;
}

@keyframes track-panel-rotate-gradient {
  0% {
    --track-panel-gradient-stripe-width: 40px;
  }

  25% {
    --track-panel-gradient-stripe-width: 20px;
  }

  50% {
    --track-panel-gradient-stripe-width: 40px;
  }

  75% {
    --track-panel-gradient-stripe-width: 60px;
  }

  100% {
    --track-panel-gradient-stripe-width: 40px;
  }
}

[data-element="rymstats-track-panel"] {
  padding-right: 1rem;
  transition: all 0.3s ease-out;
  transition-property: background-color, color, border-radius;
  position: relative;
  margin-top: .4em;
  margin-bottom: .4em;
  min-height: 162px;

  & > .loader {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    aspect-ratio: 1 / 1;
    height: 100%;
    color: var(--color-lastfm);

    svg {
      width: 100%;
      height: 100%;
    }
  }

  &.is-loaded {
    & > .loader {
      display: none;
    }
  }

  &:before {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    aspect-ratio: 1 / 1;
    transform: translateY(-50%);
    background-image: var(--bg-image);
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    filter: blur(4px);
    opacity: 0.2;
  }

  &:after {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 1;

    --track-panel-gradient-stripe-width: 40px;
    --track-panel-gradient-angle: -45deg;

    background-position: center center;
    opacity: 0.1;
  }

  & > * {
    position: relative;
    z-index: 2;
  }

  a {
    color: inherit;
  }

  &.is-now-playing {
    border-radius: 9999px 0 0 9999px;
  }
}

html[data-scheme="light"] {
  /* --clr-accent: var(--clr-light-accent); */
  [data-element="rymstats-track-panel"] {
    border-color: var(--clr-light-accent);
  }
}

html[data-scheme="dark"] {
  /* --clr-accent: var(--clr-dark-accent); */
  [data-element="rymstats-track-panel"] {
    border-color: var(--clr-dark-accent);
  }
}

.profile_view_play_history_btn {
  gap: 1rem;
  min-height: 45px;
  align-items: center;
  flex: 1 0 auto;
}

.btn.btn-lastfm,
.btn.btn-profile {
  --bg-color: var(--color-lastfm);
  --bg-color-hover: color-mix(in lab, var(--bg-color) 90%, white);
  --bg-color-active: color-mix(in lab, var(--bg-color) 80%, black);
  --color: #fff;
  background-color: var(--bg-color) !important;
  color: var(--color) !important;
  transition: background-color 0.3s ease-out, color 0.3s ease-out;
  border: 2px solid color-mix(in lab, var(--bg-color) 80%, white);
  margin-right: 0;

  &:hover {
    background-color: var(--bg-color-hover) !important;
  }

  &:active {
    background-color: var(--bg-color-active) !important;
    position: relative;
    top: 2px;
  }

  display: flex;
  width: fit-content;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 41.15px;
  padding-block: 0 !important;

  svg {
    order: -1;
    width: 1.75em;
    height: 1.75em;
  }
}

.btn-settings {
  color: var(--color) !important;
  opacity: 0;
  transition-property: opacity, color;
  transition-duration: 0.3s;
  transition-timing-function: ease-out;
  width: 30px;
  height: 30px;
  padding: 5px;
  top: 0;
  right: 0;
  position: absolute;

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

[data-element="rymstats-track-panel"]:hover {
  .btn-settings {
    opacity: .3;
  }
}

html[data-scheme="light"] {
  .btn.btn-lastfm,
  .btn.btn-profile {
    --bg-color: var(--clr-light-accent);
    --color: var(--clr-light-accent-contrast);
  }

  .btn-settings {
    --color: var(--clr-light-accent);
  }
}

html[data-scheme="dark"] {
  .btn.btn-lastfm,
  .btn.btn-profile {
    --bg-color: var(--clr-dark-accent);
    --color: var(--clr-dark-accent-contrast);
  }

  .btn-settings {
    --color: var(--clr-dark-accent);
  }
}

.lastfm-tracks-wrapper {
  display: block;
  position: absolute;
  left: -9999px;
  right: 9999px;
  transition: all .15s ease-out;
  opacity: 0;
  transform: translateY(-10px);
  margin-top: .4em;
  margin-bottom: .4em;
  padding-bottom: 30px;

  &.is-loading {
    display: none;
  }

  &::before,
  &::after {
    position: absolute;
    opacity: 0.75;
    bottom: 0;
    height: 30px;
    padding: 0 15px;
    font-size: 0.75em;
    line-height: 29px;
  }

  &:before {
    content: attr(data-timestamp);
    right: 0;
  }

  &:after {
    content: 'Powered by RYM Last.fm Stats';
    left: 0;
  }

  &.is-active {
    opacity: 1;
    transform: translateY(0);
    position: relative;
    left: auto;
    right: auto;
  }

  ul {
    display: table;
    width: 100%;
  }

  li {
    display: table-row;

    & + li {
      border-top: 1px solid;
    }

    & > * {
      display: table-cell;
      vertical-align: middle;
      padding: 9px;

      &:first-child {
        padding-left: 15px;
      }

      &:last-child {
        padding-right: 15px;
        white-space: nowrap;
      }
    }
  }

  .track-image {
    a {
      display: block;
      position: relative;
      width: 34px;
      height: 34px;

      &:empty::after {
        content: '?';
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
      }
    }

    img {
      display: block;
      width: 100%;
      height: 100%;
    }
  }

  .track-title {
    font-weight: bold;
    width: 60%;
  }

  .track-artist {
    width: 40%;
    font-weight: bold;
  }

  .track-date {
    text-align: right;

    svg {
      margin-right: 0.5em;
      width: 12px;
      height: 12px;
    }
  }

  .track-image a {
    background: var(--color);
  }

  li {
    & + li {
      border-color: var(--color);
    }

    &.is-now-playing {
      background: var(--color);
    }
  }
}

html[data-scheme="light"] {
  .lastfm-tracks-wrapper {
    --color: rgba(0, 0, 0, 0.1);
  }
}

html[data-scheme="dark"] {
  .lastfm-tracks-wrapper {
    --color: rgba(255, 255, 255, 0.1);
  }
}

.btn-bg-switcher {
  position: absolute;
  bottom: 0;
  right: 0;
  padding: 3px;
  width: 30px;
  height: 30px;
  background: none;
  border: none;
  cursor: pointer;
  color: currentColor;
  opacity: 0;
  transition: opacity 0.3s ease-out;

  &:before {
    content: attr(data-option);
    font-size: 1rem;
    position: absolute;
    top: 50%;
    white-space: nowrap;
    right: 100%;
    transform: translateY(-50%);
    padding-right: 5px;
    opacity: 0;
    transition: opacity 0.3s ease-out;
  }

  &:hover {
    opacity: 1 !important;

    &:before {
      opacity: 1;
    }
  }

  svg {
    fill: currentColor;
    display: block;
    width: 100%;
    height: 100%;
  }
}

[data-element="rymstats-track-panel"]:hover {
  .btn-bg-switcher {
    opacity: .3;
  }
}

@property --progress { syntax: '<angle>'; inherits: true; initial-value: 0deg; }

@keyframes progress-animation {
  0% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
  100% {
    opacity: 1;
  }
}

.btn.btn-lastfm {
  position: relative;
  transition: opacity 0.3s ease-out;

  &:before {
    content: '';
    position: absolute;
    inset: -5px;
    z-index: -1;
    opacity: 0.75;
    pointer-events: none;
    background: conic-gradient(
      var(--bg-color) var(--progress),
      transparent 0deg
    );
    border-radius: inherit;
  }

  &.is-fetching {
    animation: progress-animation 1.5s linear infinite;
  }
}

.rymstats-rym-sync-hint {
  &:hover {
    text-decoration: underline;
  }
}

.rymstats-rym-sync-hint-icon {
  cursor: help;
}

.profile_view_play_history_btn_group {
  position: relative;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;

  @media (pointer: fine) and (hover: hover) {
    .btn-toggle-history-pinned,
    .btn-toggle-polling {
      position: absolute;
      left: 50%;
      opacity: 0;
      transition-duration: 0.15s;
      transition-property: opacity, transform;
    }

    .btn-toggle-history-pinned {
      transform: translateX(-50%) translateY(10px);
      bottom: calc(100% + 5px);
    }

    .btn-toggle-polling {
      transform: translateX(-50%) translateY(-10px);
      top: calc(100% + 5px);
    }

    &:hover {
      .btn-toggle-history-pinned,
      .btn-toggle-polling {
        opacity: 0.5;
        transform: translateX(-50%) translateY(0);

        &:hover {
          opacity: 1;
        }
      }
    }
  }
}
