@use '../../abstracts/variables' as *;

// Fiction activity component

.minilesson_fiction_yarncontainer {

  // Base styles
  .minilesson_fiction_yarnmedia {
    min-width: 300px;
    max-width: 300px;
    min-height: 300px;
    background-color: lightgray;

    video,
    img {
      max-width: 300px;
    }
  }

  .minilesson_fiction_yarnoptions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;

    .minilesson_fiction_option_number {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      width: 24px;
      height: 24px;
      margin-right: 8px;
      border: 1px solid $grey-400-alt;
      border-radius: 4px;
      background-color: $grey-100;
      font-size: 0.85em;
      font-weight: 600;
      color: $grey-600;
    }
  }

  .fiction-character-name {
    min-height: 1.5em;
  }

  .fiction-message-container {
    --my-gutter-height: 1.5rem;
    margin-top: var(--my-gutter-height);
    margin-bottom: var(--my-gutter-height);

    @media screen and (max-width: 576px) {
      --my-gutter-height: .8rem;
    }
  }

  .fiction-message-video,
  .fiction-message-audio,
  .fiction-message-image {
    max-width: 100%;
    width: 100%;

    @media screen and (max-width: 576px) {
      display: block;
      margin-left: auto;
      margin-right: auto;
    }
  }

  // Mobile chat variant
  &.mobilechat {
    display: flex;
    flex-direction: column;
    height: 600px;
    max-height: 80vh;
    background-color: $fiction-whatsapp-bg;
    position: relative;

    .chat-wrapper {
      overflow-y: auto;
      padding: 15px;
      display: flex;
      flex-direction: column;
      gap: 10px;
      flex-grow: 1;
      min-height: 0;
      position: relative;

      .charactercontainer {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        width: fit-content;
        background: $white;
        padding: 10px 14px;
        border-radius: 0 12px 12px 12px;
        box-shadow: 0 1px 2px rgba($black, 0.1);
        font-size: 14px;
        line-height: 1.4;
        padding-top: 0;
        position: relative;
        margin-left: 10px;

        &:not(.hasmedia) {
          max-width: 70%;
        }

        &.hasmedia {
          max-width: 50%;
        }

        .charactername {
          font-weight: bold;
          font-size: 14px;
        }

        .mediacontainer {
          margin: 8px 0;

          video,
          img {
            max-width: 100%;
            border-radius: 10px;
          }
        }

        &::before {
          content: "";
          position: absolute;
          left: -10px;
          border-width: 0 10px 10px 0;
          border-style: solid;
          border-color: transparent $white transparent transparent;
        }
      }

      .playercontainer {
        display: flex;
        flex-direction: column;
        align-items: flex-end;

        .playertext:not(:empty) {
          background-color: $fiction-whatsapp-sent;
          padding: 10px 14px;
          border-radius: 12px 0 12px 12px;
          box-shadow: 0 1px 2px rgba($black, 0.1);
          font-size: 14px;
          line-height: 1.4;
          max-width: 70%;
          word-wrap: break-word;
          display: inline-block;
        }

        &::before {
          content: "";
          position: absolute;
          right: 6px;
          border-width: 0px 0 10px 10px;
          border-style: solid;
          border-color: transparent transparent transparent $fiction-whatsapp-sent;
        }
      }
    }

    .yarnchoicescontainer {
      padding: 15px;
      border-top: 1px solid $grey-400;
      min-height: 88px;
      flex-shrink: 0;
    }

    .minilesson_fiction_yarnoptions:not(:empty) {
      display: flex;
      flex-direction: column;
      gap: 10px;
      margin-bottom: 15px;
    }

    .minilesson_fiction_optionbutton {
      background-color: $white;
      cursor: pointer;
      height: max-content;
    }

    .minilesson_fiction_continuebutton {
      background-color: $white;
      cursor: pointer;
    }

    .option_container {
      display: flex;
      justify-content: space-between;
      align-items: center;
      background: white;
      border-radius: 25px;
      padding: 10px 20px;

      &:has(button[style*="display: none"]),
      &:has(button.hidden) {
        display: none;
      }
    }

    #scroll-bottom-btn {
      position: absolute;
      right: 30px;
      display: none;
      padding: 5px 8px;
      border-radius: 20px;
      border: none;
      cursor: pointer;
      background-color: white;
      z-index: 10;
      bottom: 30px;
    }

    .character_profile_icon-image {
      height: 30px;
      width: 30px;
      border-radius: 100%;
    }

    .chat-loader {
      --loadercolor: #{$grey-300};
      width: 40px;
      aspect-ratio: 2;
      --_g: no-repeat radial-gradient(circle closest-side, var(--loadercolor) 90%, var(--loadercolor));
      background: var(--_g) 0% 50%, var(--_g) 50% 50%, var(--_g) 100% 50%;
      background-size: 25% 50%;
      animation: l3 1s infinite linear;
    }
  }

  // Plain variant
  &.plain {
    background-color: $fiction-narrator-bg;
    padding: 20px;
    height: 600px;
    display: flex;
    flex-direction: column;

    .chat-wrapper {
      display: flex;
      flex-direction: column;
      gap: 15px;
      padding-bottom: 20px;
      flex-grow: 1;
      overflow-y: auto;
      min-height: 0;
      max-height: none;

      .charactercontainer {
        background-color: $white;
        border-radius: 8px;
        padding: 15px;
        box-shadow: 0 1px 3px rgba($black, 0.1);
        position: relative;
        border-left: 4px solid transparent;

        &:not(.has-charactername) {
          background-color: $white;
          border-left: none;
        }

        &.has-charactername {
          background-color: $fiction-narrator-active;
          border-left: 4px solid $fiction-narrator-accent;
          margin-top: 20px;
        }

        .charactername {
          position: absolute;
          top: -25px;
          left: 0;
          font-weight: bold;
          color: $fiction-narrator-accent;
          font-size: 0.9em;
          text-transform: uppercase;
        }

        .charactertext {
          font-size: 1.1em;
          line-height: 1.5;
          color: $grey-900;
        }

        &.hasmedia {
          display: flex;
          flex-direction: row;
          gap: 20px;
          align-items: center;

          .mediacontainer {
            flex: 1;
            max-width: 50%;

            img,
            video {
              width: 100%;
              height: auto;
              border-radius: 4px;
              display: block;
            }

            .chat-loader {
              position: relative;
              transform: none;
              left: auto;
              top: auto;
              margin: 10px auto;
            }
          }

          .charactertext {
            flex: 1;
            max-width: 50%;
          }

          &:has(.chat-loader) .mediacontainer {
            min-height: 40px;
            display: flex;
            align-items: center;
            justify-content: center;
          }
        }
      }
    }

    .character_profile_icon {
      float: left;
      margin-right: 15px;
      width: 50px;
      height: 50px;
    }

    .character_profile_icon-image {
      width: 100%;
      height: 100%;
      border-radius: 50%;
      object-fit: cover;
    }

    .yarnchoicescontainer {
      margin-top: 20px;
      border-top: 1px solid $grey-500;
      padding-top: 20px;
      flex-shrink: 0;
      min-height: 55px;
    }

    .minilesson_fiction_yarnoptions {
      display: flex;
      flex-direction: column;
      gap: 10px;
    }

    .option_container {
      cursor: pointer;
    }

    .minilesson_fiction_optionbutton {
      background-color: $white;
      border: 1px solid $grey-400-alt;
      border-radius: 5px;
      padding: 15px;
      transition: background-color 0.2s, box-shadow 0.2s;

      &:hover {
        background-color: $grey-75;
        box-shadow: 0 2px 4px rgba($black, 0.05);
        border-color: $grey-550;
      }
    }

    .minilesson_fiction_fakeoptionbutton {
      cursor: default;
      opacity: 0.6;
      background-color: $grey-500;
      border: 1px solid $grey-400-alt;
      border-radius: 5px;
      padding: 15px;
      transition: background-color 0.2s, box-shadow 0.2s;
    }

    .optiontext {
      font-size: 1.1em;
      color: $grey-800;
    }

    .minilesson_fiction_continuebutton {
      margin-top: 15px;
      cursor: pointer;
      background-color: $white;
      border: 1px solid $grey-400-alt;
      border-radius: 5px;
      padding: 10px 20px;
      display: inline-block;
      width: 100%;
      text-align: center;

      &:hover {
        background-color: $grey-200;
      }
    }

    #scroll-bottom-btn {
      position: absolute;
      bottom: 0px;
      right: 20px;
      width: 40px;
      height: 40px;
      border-radius: 50%;
      border: 1px solid $grey-500;
      background-color: $white;
      box-shadow: 0 2px 5px rgba($black, 0.2);
      cursor: pointer;
      display: flex;
      justify-content: center;
      align-items: center;
      color: $grey-700;
      transition: all 0.2s;
      z-index: 10;

      &:hover {
        background-color: $grey-200;
        transform: translateY(-2px);
      }

      i {
        font-size: 1.2em;
      }
    }

    .playertext {
      width: 80%;
      margin: auto;
      text-align: center;
      background-color: aliceblue;
      padding-top: 2px;
      padding-bottom: 2px;
    }

    .chat-loader {
      display: inline-block;
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      width: 80px;
      height: 13px;
      text-align: center;

      &::after {
        content: " ";
        display: block;
        width: 6px;
        height: 6px;
        border-radius: 50%;
        background-color: $fiction-narrator-accent;
        margin: 0 auto;
        box-shadow: -12px 0 $fiction-narrator-accent, 12px 0 $fiction-narrator-accent;
        animation: minilesson_fiction_plain_dots 1s infinite linear alternate;
      }
    }
  }

  // Story mode variant
  &.storymode {
    background-color: $fiction-book-bg;
    color: $fiction-book-text;
    font-family: 'Georgia', 'Times New Roman', serif;
    line-height: 1.8;
    font-size: 1.2rem;
    padding: 20px;
    height: 600px;
    display: flex;
    flex-direction: column;

    .chat-wrapper {
      flex-grow: 1;
      overflow-y: auto;
      padding: 0 20px 20px 20px;
      max-width: 800px;
      margin: 0 auto;
      width: 100%;

      &::-webkit-scrollbar {
        width: 8px;
      }

      &::-webkit-scrollbar-track {
        background: $fiction-book-bg;
      }

      &::-webkit-scrollbar-thumb {
        background-color: $fiction-book-border;
        border-radius: 4px;
      }
    }

    .story-paragraph {
      margin-bottom: 1.5em;
      text-align: justify;

      .mediacontainer {
        text-align: center;
        margin: 2rem 0;

        img,
        video {
          max-width: 300px;
          width: 50%;
          border-radius: 2px;
          box-shadow: 0 4px 6px rgba($black, 0.1);
          border: 4px solid $white;
        }
      }

      &.player-choice {
        text-align: center;
        color: $fiction-book-accent;
        font-style: italic;
        margin-top: 2rem;
        margin-bottom: 2rem;
        position: relative;
        padding: 10px;
        border-top: 1px solid $fiction-book-divider;
        border-bottom: 1px solid $fiction-book-divider;

        &::before {
          content: "❧";
          display: block;
          font-size: 1.5rem;
          margin-bottom: 5px;
          color: $fiction-book-border;
        }
      }
    }

    .yarnchoicescontainer {
      max-width: 800px;
      margin: 0 auto;
      width: 100%;
      padding-top: 20px;
      border-top: 2px solid $fiction-book-divider;
      margin-top: 10px;
      flex-shrink: 0;
      min-height: 74px;
    }

    .minilesson_fiction_yarnoptions {
      display: flex;
      flex-wrap: wrap;
      justify-content: center;
      gap: 15px;
    }

    .minilesson_fiction_optionbutton {
      background-color: transparent;
      border: 2px solid $fiction-book-accent;
      color: $fiction-book-dark;
      font-family: inherit;
      padding: 10px 20px;
      border-radius: 30px;
      cursor: pointer;
      transition: all 0.3s ease;
      font-size: 1rem;
      font-weight: bold;

      &:hover {
        background-color: $fiction-book-accent;
        color: $fiction-book-bg;
        border-color: $fiction-book-accent;
      }
    }

    .minilesson_fiction_continuebutton {
      display: block;
      width: fit-content;
      margin: 20px auto;
      background-color: $fiction-book-dark;
      color: $fiction-book-bg;
      padding: 10px 30px;
      border-radius: 4px;
      font-family: inherit;
      cursor: pointer;
      text-transform: uppercase;
      letter-spacing: 1px;
      font-size: 0.9rem;

      &:hover {
        background-color: $fiction-book-text;
      }
    }

    #scroll-bottom-btn {
      position: absolute;
      bottom: 20px;
      right: 20px;
      width: 40px;
      height: 40px;
      border-radius: 50%;
      border: 1px solid $fiction-book-border;
      background-color: $fiction-book-bg;
      color: $fiction-book-accent;
      box-shadow: 0 2px 5px rgba($black, 0.1);
      cursor: pointer;
      display: flex;
      justify-content: center;
      align-items: center;
      z-index: 100;

      &:hover {
        background-color: $white;
        color: $fiction-book-dark;
      }
    }
  }
}

#scrolldownbtn {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: none;
}

@keyframes l3 {
  20% {
    background-position: 0% 0%, 50% 50%, 100% 50%;
  }

  40% {
    background-position: 0% 100%, 50% 0%, 100% 50%;
  }

  60% {
    background-position: 0% 50%, 50% 100%, 100% 0%;
  }

  80% {
    background-position: 0% 50%, 50% 50%, 100% 100%;
  }
}

@keyframes minilesson_fiction_plain_dots {
  0% {
    opacity: 0.2;
  }

  50%,
  100% {
    opacity: 1;
  }
}