{% extends "base.html" %} {% block content %}
<!--<div id="preloader"></div>-->
<div id="anime_downloader_wrapper" class="content-cloak">
  <div id="preloader" class="loader">
    <div class="loader-inner">
      <div class="loader-line-wrap">
        <div class="loader-line"></div>
      </div>
      <div class="loader-line-wrap">
        <div class="loader-line"></div>
      </div>
      <div class="loader-line-wrap">
        <div class="loader-line"></div>
      </div>
      <div class="loader-line-wrap">
        <div class="loader-line"></div>
      </div>
      <div class="loader-line-wrap">
        <div class="loader-line"></div>
      </div>
    </div>
  </div>
  <div id="yommi_wrapper">
    <div class="input-group mb-2">
      <input
        id="input_search"
        type="search"
        class="form-control rounded"
        placeholder="Search"
        aria-label="Search"
        aria-describedby="search-addon"
      />
      <button id="btn_search" type="button" class="btn btn-primary">
        search
      </button>
    </div>

    <div
      id="anime_category"
      class="btn-group"
      role="group"
      aria-label="Linkkf Button"
    >
      <button id="ing" type="button" class="btn btn-success">방영중</button>
      <button id="movie" type="button" class="btn btn-primary">극장판</button>
      <button id="complete_anilist" type="button" class="btn btn-dark">
        완결
      </button>
      <button id="top_view" type="button" class="btn btn-yellow">Top</button>
    </div>
    <form id="airing_list_form">
      <div id="airing_list"></div>
    </form>
    <form id="screen_movie_list_form">
      <div id="screen_movie_list" class="container-fluid px-0"></div>
    </form>
    {#
    <div class="text-center">
      #} {#
      <div id="spinner" class="spinner-border" role="status">
        #} {# <span class="sr-only">Loading...</span>#} {#
      </div>
      #} {#
    </div>
    #}
    <form id="program_auto_form">
      <div id="episode_list"></div>
    </form>
  </div>
</div>
<!--전체-->

<script
  type="text/javascript"
  src="https://cdn.jsdelivr.net/npm/lozad/dist/lozad.min.js"
></script>
<script src="{{ url_for('.static', filename='js/sjva_ui14.js') }}"></script>
<script
  src="https://cdnjs.cloudflare.com/ajax/libs/jquery.lazyload/1.9.1/jquery.lazyload.min.js"
  integrity="sha512-jNDtFf7qgU0eH/+Z42FG4fw3w7DM/9zbgNPe3wfJlCylVDTT3IgKW5r92Vy9IHa6U50vyMz5gRByIu4YIXFtaQ=="
  crossorigin="anonymous"
  referrerpolicy="no-referrer"
></script>
<script type="text/javascript">
  const package_name = "{{arg['package_name'] }}";
  const sub = "{{arg['sub'] }}";
  const anilife_url = "{{arg['anilife_url']}}";
  // let current_data = null;
  let page = 1;
  let next_page = Number
  let current_cate = ''
  let current_query = ''

  const loader = document.getElementById("preloader");

  const dismissLoadingScreen = function () {
      loader.style.display = "none";
  };

  const wait3seconds = function () {
      // REFERENCE:  https://www.w3schools.com/jsref/met_win_settimeout.asp
      const result = setTimeout(dismissLoadingScreen, 2000);
  };

  window.addEventListener("load", wait3seconds);
  // window.addEventListener("load", dismissLoadingScreen);


  const observer = lozad('.lozad', {
      rootMargin: '10px 0px', // syntax similar to that of CSS Margin
      threshold: 0.1, // ratio of element convergence
      enableAutoReload: true // it will reload the new image when validating attributes changes
  });
  observer.observe();


  const get_anime_screen_movie = (page) => {
      let data = {page: page};
      $.ajax({
          url: '/' + package_name + '/ajax/' + sub + '/screen_movie_list',
          type: "POST",
          data: data,
          cache: false,
          dataType: "json",
          success: (ret) => {
              current_screen_movie_data = ret;
              total_page = ret.total_page;
              // console.log("ret::>", ret);

              if (current_screen_movie_data !== "") {
                  make_screen_movie_list(ret, page);
                  $("img.lazyload").lazyload({
                      threshold: 100,
                      effect: "fadeIn",
                  });
                  div_visible = true;
              }
              next_page = page + 1;
          },
      });
  };

  const get_anime_list = (type, page) => {
      //console.log(`type: ${type}, page: ${page}`);
      let url = ''
      let data = {"page": page, "type": type}

      switch (type) {
          case 'ing':
              url = '/' + package_name + '/ajax/' + sub + '/anime_list'
              current_cate = 'ing'
              break;
          case 'movie':
              url = '/' + package_name + '/ajax/' + sub + '/screen_movie_list'
              current_cate = 'movie'
              break;
          case 'complete':
              url = '/' + package_name + '/ajax/' + sub + '/anime_list'
              current_cate = 'complete'
              break;
          case 'top_view':
              url = '/' + package_name + '/ajax/' + sub + '/complete_list'
              current_cate = 'complete'
              break
          default:
              break;
      }

      $.ajax({
          url: url,
          type: "POST",
          data: data,
          cache: false,
          dataType: "json",
          success: (ret) => {
              current_screen_movie_data = ret
              // console.log('ret::>', ret)

              if (current_screen_movie_data !== '') {
                  if (type === "ing") {
                      //make_airing_list(ret.data, page)
                      make_screen_movie_list(ret.data, page);
                      observer.observe();
                  } else if (type === "fin") {
                      make_screen_movie_list(ret.data, page)
                      observer.observe();
                  } else if (type === "theater") {
                      make_screen_movie_list(ret.data, page)
                      observer.observe();
                  } else {
                      make_screen_movie_list(ret.data, page)
                  }
                  div_visible = true
                  // console.log(div_visible)
              }
              next_page = page + 1
          }
      });
  }

  function make_airing_list(data, page) {
      let str = ''
      let tmp = ''

      str += '<div>';
      str += '<button type="button" class="btn btn-info">Page <span class="badge bg-warning">' + page + '</span></button>';
      str += '</div>';
      // str += '<div class="card-columns">'
      str += '<div id="inner_screen_movie" class="row infinite-scroll">';
      for (let i in data.anime_list) {

          tmp = '<div class="col-6 col-sm-4 col-md-3">';
          tmp += '<div class="card">';
          // tmp += '<img class="lozad" data-src="' + data.anime_list[i].image_link + '" />';
          tmp += '<img class="lazyload" src="../static/img_loader_x200.svg" data-original="' + data.anime_list[i].image_link + '" style="cursor: pointer" onclick="location.href=\'./request?code=' + data.anime_list[i].code + '\'"/>';
          tmp += '<div class="card-body">'
          // {#tmp += '<button id="code_button" data-code="' + data.episode[i].code + '" type="button" class="btn btn-primary code-button bootstrap-tooltip" data-toggle="button" data-tooltip="true" aria-pressed="true" autocomplete="off" data-placement="top">' +#}
          //  {#    '<span data-tooltip-text="'+data.episode[i].title+'">' + data.episode[i].code + '</span></button></div>';#}
          tmp += '<h5 class="card-title">' + data.anime_list[i].title + '</h5>';
          tmp += '<p class="card-text">' + data.anime_list[i].code + '<button id="add_whitelist" name="add_whitelist" class="btn btn-sm btn-favorite mb-1" data-code="' +
              data.anime_list[i].code +
              '"><i class="bi bi-heart-fill"></i></button></p>';
          tmp += '<a href="./request?code=' + data.anime_list[i].code + '" class="btn btn-primary cut-text">' + data.anime_list[i].title + '</a>';
          // tmp +=
          // '<button id="add_whitelist" name="add_whitelist" class="btn btn-sm btn-favorite mb-1" data-code="' +
          // data.anime_list[i].code +
          // '"><i class="bi bi-heart-fill"></i></button>';
          tmp += '</div><!-- .card -->';
          tmp += '</div>';
          tmp += '</div>';
          str += tmp

      }
      str += '</div>';
      // str += '</div><!-- .card-columns -->';
      str += m_hr_black();

      if (page > 1) {

          const temp = document.createElement('div')
          temp.innerHTML = str;
          while (temp.firstChild) {
              document.getElementById("screen_movie_list").appendChild(temp.firstChild);
          }
          page++

      } else {

          document.getElementById("screen_movie_list").innerHTML = str;

      }

      $("img.lazyload").lazyload({
          threshold: 10,
          effect: "fadeIn",
      });

  }

  function make_search_result_list(data, page) {
      let str = ''
      let tmp = ''
      
      let list = data.anime_list || data.episode || [];

      str += '<div>';
      str += '<button type="button" class="btn btn-info">Page <span class="badge bg-warning">' + page + '</span></button>';
      str += '</div>';
      str += '<div id="inner_screen_movie" class="row infinite-scroll">';
      
      for (let i in list) {
          let item = list[i];
          if (item.wr_id !== undefined && item.wr_id !== '') {
              const re = /bo_table=([^&]+)/
              const bo_table = item.link.match(re)
              if (bo_table != null) {
                  request_url = './request?code=' + item.code + '&amp;wr_id=' + item.wr_id + '&amp;bo_table=' + bo_table[1]
              } else {
                  request_url = './request?code=' + item.code
              }
          } else {
              request_url = './request?code=' + item.code
          }

          tmp = '<div class="col-6 col-sm-4 col-md-3">';
          tmp += '<div class="card">';
          tmp += '<img class="card-img-top" src="' + item.image_link + '" style="cursor: pointer" onclick="location.href=\'' + request_url + '\'"/>';
          tmp += '<div class="card-body">'
          tmp += '<h5 class="card-title">' + item.title + '</h5>';
          tmp += '<div class="d-flex justify-content-between align-items-center mb-2">';
          tmp += '<span class="card-text mb-0">' + item.code + '</span>';
          tmp += '<button id="add_whitelist" name="add_whitelist" class="btn btn-sm btn-favorite" data-code="' + item.code + '"><i class="bi bi-heart-fill"></i></button>';
          tmp += '</div>';
          tmp += '<a href="' + request_url + '" class="btn btn-primary cut-text">' + item.title + '</a>';
          tmp += '</div>';
          tmp += '</div>';
          tmp += '</div>';
          str += tmp
      }
      str += '</div>';
      str += m_hr_black();

      if (page > 1) {

          const temp = document.createElement('div')
          temp.innerHTML = str;
          while (temp.firstChild) {
              document.getElementById("screen_movie_list").appendChild(temp.firstChild);
          }
          page++

      } else {
          document.getElementById("screen_movie_list").innerHTML = str;
      }

  }

  function make_screen_movie_list(data, page) {
      let str = "";
      let tmp = "";
      let new_anime = true;
      let new_style = ''
      // console.log('page a: ', page)
      // console.log(data)
      // console.log(data.data)
      //console.log(data.episode)

      let page_elem = "";
      if (page === undefined) {
      } else {
          page_elem = '<span class="badge bg-warning">' + page + "</span>";
      }

      // str += "<div id='page_caption' style='border-bottom: aqua 1px solid; margin-bottom: 5px'>";
      str += "<div id='page_caption' style='padding-bottom: 3px'>";
      str +=
          '<button type="button" class="btn btn-info">Page ' +
          page_elem +
          "</button>";
      str += "</div>";
      str += '<div id="inner_screen_movie" class="row infinite-scroll">';
      for (let i in data.data) {
        // console.log(i)
        // console.log(data.data[i])
          if (data.data[i].postid === data.latest_anime_code) {
              new_anime = false
          }

          if (new_anime && page === '1') {
              new_style = 'new-anime';
          } else {
              new_style = '';
          }

          tmp = '<div class="col-6 col-sm-4 col-md-3">';
          tmp += '<div class="card ' + new_style + '">';
          // tmp += '<div class="card-header">';

          // tmp +=
          //   '<img class="card-img-top lazyload" src="./static/img_loader_x200.svg" data-original="' + data.episode[i].image_link + '" />';
          tmp +=
              '<img class="card-img-top lazy" src="{{ url_for('.static', filename='img_loader_x200.svg') }}" data-lazy-src="' +
              data.data[i].postthum +
              '" style="cursor: pointer" onclick="location.href=\'./request?code=' +
              data.data[i].postid +
              "'\"/>";
          if (current_cate === "ing") {
              tmp +=
                  '<span class="badge badge-danger badge-on-image">' +
                  data.data[i].postnote +
                  "</span>";
          }
          // tmp += '<div class="card-body '+ new_anime ? 'new-anime' : '' +'">';
          tmp += '<div class="card-body">';
          tmp += '<h5 class="card-title">' + data.data[i].postname + "</h5>";
          tmp += '<div class="d-flex justify-content-between align-items-center mb-2">';
          tmp += '<span class="card-text mb-0">' + data.data[i].postid + '</span>';
          tmp += '<button id="add_whitelist" name="add_whitelist" class="btn btn-sm btn-favorite" data-code="' + data.data[i].postid + '"><i class="bi bi-heart-fill"></i></button>';
          tmp += '</div>';
          tmp +=
              '<a href="./request?code=' +
              data.data[i].postid +
              '" class="btn btn-primary cut-text">' +
              data.data[i].postname +
              "</a>";
          tmp += "</div>";
          tmp += "</div>";
          // tmp += "</div>"
          tmp += "</div>";
          str += tmp;
      }
      str += "</div>";
      str += m_hr_black();

      if (page > 1) {
          const temp = document.createElement("div");
          temp.innerHTML = str;
          while (temp.firstChild) {
              document.getElementById("screen_movie_list").appendChild(temp.firstChild);
          }
          page++;
      } else {
          document.getElementById("screen_movie_list").innerHTML = str;
      }
      $("img.lazyload").lazyload({
          threshold: 100,
          effect: "fadeIn",
      });
  }

  $(document).ready(function () {

      // if ( "{{arg['anilife_current_code']}}" !== "" ) {
      //     document.getElementById("code").value = "{{arg['anilife_current_code']}}";
      //     // 값이 공백이 아니면 분석 버튼 계속 누름
      //     document.getElementById("analysis_btn").click();
      // }
      $("#input_search").keydown(function (key) {
          if (key.keyCode === 13) {
              // alert("엔터키를 눌렀습니다.");
              $("#btn_search").trigger("click");
          }
      })

      get_anime_list("ing", 1)


      const observer = lozad('.lozad', {
          rootMargin: '10px 0px', // syntax similar to that of CSS Margin
          threshold: 0.1, // ratio of element convergence
          enableAutoReload: true // it will reload the new image when validating attributes changes
      });
      observer.observe();

  });

  $("body").on("click", "#btn_search", function (e) {
      e.preventDefault();
      let query = $("#input_search").val();
      // console.log(query);
      current_cate = "search"
      current_query = query

      if ($("#input_search").val() === "") {
          // console.log("search keyword nothing");
          return false;
      }

      $.ajax({
          url: "/" + package_name + "/ajax/" + sub + "/search",
          type: "POST",
          cache: false,
          data: {query: query, type: current_cate, page: page},
          // dataType: "json",
          contentType: "application/x-www-form-urlencoded; charset=UTF-8",
          success: function (ret) {
              if (ret.ret) {
                  // console.log('ret:::', ret)
                  make_search_result_list(ret.data, 1);
                  next_page = page + 1
              } else {
                  $.notify("<strong>분석 실패</strong><br>" + ret.log, {
                      type: "warning",
                  });
              }
          },
      });
  });


  $("#anime_category").on("click", function (e) {
      // console.log($(this))
      // console.log(e)

      switch (e.target.id) {
          case "ing":
              // console.log("ing.....")

          {#spinner_loading.style.display = "block";#}
              current_cate = "ing";
              get_anime_list(1, "ing");
              break;
          case "movie":
              // console.log("movie")
              current_cate = "movie";
              get_anime_screen_movie(1);
              break;
          case "complete_anilist":
              // console.log("complete")
              current_cate = "complete";
              get_complete_anilist(1);
              break;
          case "top_view":
              // console.log("top_view")
              current_cate = "top_view";
              get_anime_list(1, "top_view");
              break;
          default:
              // console.log("default")
              spinner_loading.style.display = "block";
              current_cate = "ing";
              get_anime_list(1, "ing");
              break;

      }
  });

  /*

  // 분석 버튼 클릭시 호출
  $("body").on('click', '#analysis_btn', function (e) {
      e.preventDefault();
      const code = document.getElementById("code").value
      // console.log(code)
      $.ajax({
          url: '/' + package_name + '/ajax/' + sub + '/analysis',
          type: "POST",
          cache: false,
          data: {code: code},
          dataType: "json",
          success: function (ret) {
              if (ret.ret === 'success' && ret.data != null) {
                  // console.log(ret.code)
                  // console.log(ret.data)
                  make_program(ret.data)
              } else {
                  $.notify('<strong>분석 실패</strong><br>' + ret.log, {type: 'warning'});
              }
          }
      });
  });
  */


  $("body").on('click', '#go_anilife_btn', function (e) {
      e.preventDefault();
      window.open("{{arg['anilife_url']}}", "_blank");
  });

  $("body").on("click", "#add_whitelist", function (e) {
      e.preventDefault();
      let $btn = $(this);
      let data_code = $btn.attr("data-code");
      
      $.ajax({
          url: "/" + package_name + "/ajax/" + sub + "/add_whitelist",
          type: "POST",
          cache: false,
          data: JSON.stringify({data_code: data_code}),
          contentType: "application/json;charset=UTF-8",
          dataType: "json",
          success: function (ret) {
              if (ret.ret) {
                  $.notify("<strong>추가하였습니다. [" + data_code + "]</strong>", {
                      type: "success",
                  });
                  // 시각적 피드백: 하트 색상 변경
                  $btn.addClass('active').css('color', '#ef4444');
              } else {
                  $.notify("<strong>" + ret.log + "</strong>", {
                      type: "warning",
                  });
                  if (ret.log === "이미 추가되어 있습니다.") {
                      $btn.addClass('active').css('color', '#ef4444');
                  }
              }
          },
      });
  });

  $("body").on('click', '#all_check_on_btn', function (e) {
      e.preventDefault();
      $('input[id^="checkbox_"]').bootstrapToggle('on')
  });

  $("body").on('click', '#all_check_off_btn', function (e) {
      e.preventDefault();
      $('input[id^="checkbox_"]').bootstrapToggle('off')
  });

  $("body").on('click', '#add_queue_btn', function (e) {
      e.preventDefault();
      data = current_data.episode[$(this).data('idx')];
      // console.log('data:::>', data)
      $.ajax({
          url: '/' + package_name + '/ajax/' + sub + '/add_queue',
          type: "POST",
          cache: false,
          data: {data: JSON.stringify(data)},
          dataType: "json",
          success: function (data) {
              if (data.ret == 'enqueue_db_append' || data.ret == 'enqueue_db_exist') {
                  $.notify('<strong>다운로드 작업을 추가 하였습니다.</strong>', {type: 'success'});
              } else if (data.ret == 'queue_exist') {
                  $.notify('<strong>이미 큐에 있습니다. 삭제 후 추가하세요.</strong>', {type: 'warning'});
              } else if (data.ret == 'db_completed') {
                  $.notify('<strong>DB에 완료 기록이 있습니다.</strong>', {type: 'warning'});
              } else {
                  $.notify('<strong>추가 실패</strong><br>' + ret.log, {type: 'warning'});
              }
          }
      });
  });
  // const observer = lozad();
  //  	const el = document.querySelector('img');
  // const observer = lozad(el); // passing a `NodeList` (e.g. `document.querySelectorAll()`) is also valid
  // observer.observe();
  // console.log('scroll 세로크기:', document.body.scrollHeight)

  const loadNextAnimes = (cate, page, ch) => {
      // spinner.style.display = "block";
      loader.style.display = "block";
      let data = {type: cate, page: String(page)};
      let url = ''
      switch (cate) {
          case 'ing':
              url = '/' + package_name + '/ajax/' + sub + '/anime_list'
              current_cate = 'ing'
              break;
          case 'movie':
              url = '/' + package_name + '/ajax/' + sub + '/screen_movie_list'
              current_cate = 'movie'
              break;
          case 'theater':
              url = '/' + package_name + '/ajax/' + sub + '/anime_list'
              current_cate = 'theater'
              break;
          case 'fin':
              url = '/' + package_name + '/ajax/' + sub + '/complete_list'
              current_cate = 'fin'
              break
          case 'search':
              url = "/" + package_name + "/ajax/" + sub + "/search"
              current_cate = 'search'
              data.query = current_query
              break;
          default:
              break;
      }

      fetch(url, {
          method: "POST",
          cache: "no-cache",
          headers: {
              "Content-Type": "application/x-www-form-urlencoded",
          },
          body: new URLSearchParams(data),
      })
          .then((res) => res.json())
          .then((response) => {
              // console.log("Success:", JSON.stringify(response));
              // {#imagesContainer.appendChild()#}
              // console.log("return page:::> ", String(response.page));
              // {#page = response.page#}
              loader.style.display = "block";
              if (current_cate === 'search') {
                  make_search_result_list(response.data, response.page);

              } else {
                  make_screen_movie_list(response.data, response.page);
              }

              // console.log(document.body.scrollHeight)
              // console.log(ch)
              window.scrollBy({
                  top: ch + 35,
                  left: 0,
                  behavior: 'smooth'
              });

              loader.style.display = "none";
              page++;
              next_page++;
          })
          .catch((error) => console.error("Error:", error));
  };


  const onScroll = (e) => {
      console.dir(e.target.scrollingElement.scrollHeight);
      const {scrollTop, scrollHeight, clientHeight} = e.target.scrollingElement;
      if (Math.round(scrollHeight - scrollTop) <= clientHeight + 170) {
          {#document.getElementById("spinner").style.display = "block";#}
          // console.log("loading");
          // console.log("now page::> ", page);
          // console.log("next_page::> ", String(next_page));
          loadNextAnimes(current_cate, next_page, clientHeight);
          /*window.scrollBy({
              top: e.target.scrollingElement.scrollHeight + 200,
              left: 0,
              behavior: 'smooth'
          });
          */


      }
  };

  const debounce = (func, delay) => {
      let timeoutId = null;
      return (...args) => {
          clearTimeout(timeoutId);
          timeoutId = setTimeout(func.bind(null, ...args), delay);
      };
  };

  document.addEventListener("scroll", debounce(onScroll, 300));
  window.lazyLoadOptions = {
      elements_selector:
          "img[data-lazy-src],.rocket-lazyload,iframe[data-lazy-src]",
      data_src: "lazy-src",
      data_srcset: "lazy-srcset",
      data_sizes: "lazy-sizes",
      class_loading: "lazyloading",
      class_loaded: "lazyloaded",
      threshold: 50,
      callback_loaded: function (element) {
          if (
              element.tagName === "IFRAME" &&
              element.dataset.rocketLazyload == "fitvidscompatible"
          ) {
              if (element.classList.contains("lazyloaded")) {
                  if (typeof window.jQuery != "undefined") {
                      if (jQuery.fn.fitVids) {
                          jQuery(element).parent().fitVids();
                      }
                  }
              }
          }
      },
  };
  window.addEventListener(
      "LazyLoad::Initialized",
      function (e) {
          var lazyLoadInstance = e.detail.instance;
          if (window.MutationObserver) {
              var observer = new MutationObserver(function (mutations) {
                  var image_count = 0;
                  var iframe_count = 0;
                  var rocketlazy_count = 0;
                  mutations.forEach(function (mutation) {
                      for (var i = 0; i < mutation.addedNodes.length; i++) {
                          if (
                              typeof mutation.addedNodes[i].getElementsByTagName !== "function"
                          ) {
                              continue;
                          }
                          if (
                              typeof mutation.addedNodes[i].getElementsByClassName !==
                              "function"
                          ) {
                              continue;
                          }
                          images = mutation.addedNodes[i].getElementsByTagName("img");
                          is_image = mutation.addedNodes[i].tagName == "IMG";
                          iframes = mutation.addedNodes[i].getElementsByTagName("iframe");
                          is_iframe = mutation.addedNodes[i].tagName == "IFRAME";
                          rocket_lazy =
                              mutation.addedNodes[i].getElementsByClassName("rocket-lazyload");
                          image_count += images.length;
                          iframe_count += iframes.length;
                          rocketlazy_count += rocket_lazy.length;
                          if (is_image) {
                              image_count += 1;
                          }
                          if (is_iframe) {
                              iframe_count += 1;
                          }
                      }
                  });
                  if (image_count > 0 || iframe_count > 0 || rocketlazy_count > 0) {
                      lazyLoadInstance.update();
                  }
              });
              var b = document.getElementsByTagName("body")[0];
              var config = {
                  childList: !0,
                  subtree: !0,
              };
              observer.observe(b, config);
          }
      },
      !1
  );
</script>
<script
  src="https://cdnjs.cloudflare.com/ajax/libs/jquery.lazyload/1.9.1/jquery.lazyload.min.js"
  integrity="sha512-jNDtFf7qgU0eH/+Z42FG4fw3w7DM/9zbgNPe3wfJlCylVDTT3IgKW5r92Vy9IHa6U50vyMz5gRByIu4YIXFtaQ=="
  crossorigin="anonymous"
  referrerpolicy="no-referrer"
></script>
<script
  async
  src="https://cdn.jsdelivr.net/npm/vanilla-lazyload@17.7.0/dist/lazyload.min.js"
></script>

<style>
  :root {
      --bg-primary: #0f172a;
      --bg-secondary: #1e293b;
      --bg-card: rgba(30, 41, 59, 0.85);
      --text-primary: #f1f5f9;
      --text-secondary: #94a3b8;
      --accent-primary: #60a5fa;
      --accent-secondary: #818cf8;
      --accent-success: #34d399;
      --accent-warning: #fbbf24;
      --accent-danger: #f87171;
      --border-color: rgba(148, 163, 184, 0.2);
      --shadow-color: rgba(0, 0, 0, 0.3);
  }

  body {
      background: linear-gradient(135deg, var(--bg-primary) 0%, #1a2744 50%, var(--bg-secondary) 100%) !important;
      min-height: 100vh;
      font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, system-ui, Roboto, sans-serif;
  }

  #anime_downloader_wrapper {
      color: var(--text-primary);
      padding: 20px;
  }

  #yommi_wrapper {
      max-width: 100%;
      margin: 0 auto;
      padding: 0 20px;
  }

  .container, .container-fluid {
      max-width: 100% !important;
      padding: 0 !important;
  }

  .input-group {
      max-width: 600px;
      margin: 0 auto 24px;
  }

  #input_search {
      background: var(--bg-card);
      border: 1px solid var(--border-color);
      border-radius: 12px 0 0 12px !important;
      color: var(--text-primary);
      padding: 14px 20px;
      font-size: 1rem;
      backdrop-filter: blur(12px);
      transition: all 0.3s ease;
  }

  #input_search:focus {
      background: rgba(30, 41, 59, 0.95);
      border-color: var(--accent-primary);
      box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.2);
      outline: none;
  }

  #input_search::placeholder { color: var(--text-secondary); }

  #btn_search {
      background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
      border: none;
      border-radius: 0 12px 12px 0 !important;
      padding: 14px 28px;
      font-weight: 600;
      transition: all 0.3s ease;
  }

  #btn_search:hover {
      transform: translateY(-2px);
      box-shadow: 0 6px 20px rgba(96, 165, 250, 0.4);
  }

  #anime_category {
      display: flex;
      justify-content: center;
      gap: 12px;
      margin-bottom: 28px;
      flex-wrap: wrap;
  }

  #anime_category .btn {
      border: none;
      border-radius: 25px;
      padding: 10px 24px;
      font-weight: 600;
      transition: all 0.3s ease;
  }

  #anime_category .btn-success { background: linear-gradient(135deg, #10b981, #059669); }
  #anime_category .btn-success:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(16, 185, 129, 0.4); }
  #anime_category .btn-primary { background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary)); }
  #anime_category .btn-primary:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(96, 165, 250, 0.4); }
  #anime_category .btn-dark { background: linear-gradient(135deg, #475569, #334155); }
  #anime_category .btn-dark:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(71, 85, 105, 0.4); }
  #anime_category .btn-yellow { background: linear-gradient(135deg, #fbbf24, #f59e0b); color: #1e293b; }
  #anime_category .btn-yellow:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(251, 191, 36, 0.4); }

  #screen_movie_list { margin-top: 20px; }

  #page_caption { text-align: center; margin-bottom: 20px; }
  #page_caption .btn-info { background: linear-gradient(135deg, #06b6d4, #0891b2); border: none; border-radius: 20px; padding: 8px 20px; }
  #page_caption .badge { background: var(--accent-warning) !important; color: #1e293b; font-weight: 700; }

  .card {
      background: var(--bg-card);
      border: 1px solid var(--border-color);
      border-radius: 16px;
      overflow: hidden;
      backdrop-filter: blur(12px);
      transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
      margin-bottom: 20px;
  }

  .card:hover {
      transform: translateY(-8px);
      box-shadow: 0 20px 40px var(--shadow-color);
      border-color: var(--accent-primary);
  }

  .card img, .card-img-top {
      width: 100%;
      aspect-ratio: 3/4;
      object-fit: cover;
      transition: transform 0.4s ease;
      cursor: pointer;
  }

  .card:hover img { transform: scale(1.05); }

  .card-body {
      padding: 16px !important;
      background: linear-gradient(to bottom, transparent, rgba(15, 23, 42, 0.9));
  }

  .card-title {
      color: var(--text-primary);
      font-size: 1rem;
      font-weight: 600;
      margin-bottom: 8px;
      padding: 0 !important;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
      overflow: hidden;
  }

  .card-text { color: var(--text-secondary); font-size: 0.85rem; margin-bottom: 12px; }

  .card .btn-primary {
      background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
      border: none;
      border-radius: 10px;
      padding: 10px 16px;
      font-weight: 600;
      font-size: 0.85rem;
      width: 100%;
      transition: all 0.3s ease;
  }

  .card .btn-primary:hover { box-shadow: 0 4px 15px rgba(96, 165, 250, 0.4); transform: translateY(-2px); }

  button#add_whitelist, .btn-favorite {
      background: linear-gradient(135deg, #fbbf24, #f59e0b) !important;
      border: none !important;
      border-radius: 8px !important;
      padding: 6px 12px !important;
      color: #1e293b !important;
      font-weight: 600;
      transition: all 0.3s ease;
  }

  button#add_whitelist:hover, .btn-favorite:hover { transform: scale(1.1); box-shadow: 0 4px 15px rgba(251, 191, 36, 0.4); }

  .new-anime { border: 2px solid var(--accent-warning) !important; position: relative; }
  .new-anime::before {
      content: 'NEW';
      position: absolute;
      top: 10px;
      left: 10px;
      background: linear-gradient(135deg, #f87171, #ef4444);
      color: white;
      padding: 4px 10px;
      border-radius: 6px;
      font-size: 0.7rem;
      font-weight: 700;
      z-index: 10;
  }

  .badge-on-image {
      position: absolute;
      top: 10px;
      right: 10px;
      background: linear-gradient(135deg, #f87171, #ef4444) !important;
      padding: 6px 14px;
      border-radius: 8px;
      font-weight: 600;
      font-size: 0.8rem;
      z-index: 10;
  }

  #screen_movie_list .row { 
      display: grid !important; 
      grid-template-columns: repeat(2, minmax(0, 1fr)) !important; 
      gap: 16px !important; 
      width: 100% !important;
      max-width: 100% !important;
      margin: 0 !important;
  }
  #screen_movie_list .row > div {
      width: 100% !important;
      max-width: 100% !important;
      min-width: 0 !important;
      flex: none !important;
      padding: 0 !important;
      overflow: hidden !important;
  }
  #screen_movie_list .row > div img {
      max-width: 100% !important;
      height: auto !important;
  }
  #screen_movie_list .card {
      max-width: 100% !important;
      overflow: hidden !important;
  }
  @media (min-width: 576px) { #screen_movie_list .row { grid-template-columns: repeat(3, minmax(0, 1fr)) !important; } }
  @media (min-width: 768px) { #screen_movie_list .row { grid-template-columns: repeat(4, minmax(0, 1fr)) !important; } }
  @media (min-width: 992px) { #screen_movie_list .row { grid-template-columns: repeat(5, minmax(0, 1fr)) !important; } }
  @media (min-width: 1200px) { #screen_movie_list .row { grid-template-columns: repeat(6, minmax(0, 1fr)) !important; gap: 20px !important; } }
  #yommi_wrapper { max-width: 100%; padding: 0 20px; overflow-x: hidden; }

  #preloader {
      background: rgba(15, 23, 42, 0.9);
      backdrop-filter: blur(8px);
      position: fixed;
      inset: 0;
      z-index: 99999;
      display: flex;
      align-items: center;
      justify-content: center;
  }

  .loader-inner, .loader-line-wrap { display: none; }

  #preloader::after {
      content: '';
      width: 50px;
      height: 50px;
      border: 4px solid rgba(96, 165, 250, 0.2);
      border-top-color: #60a5fa;
      border-radius: 50%;
      animation: spin 0.8s linear infinite;
  }

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

  #loading { background: rgba(15, 23, 42, 0.85) !important; backdrop-filter: blur(8px) !important; }
  #loading img, #loading svg { display: none !important; visibility: hidden !important; width: 0 !important; height: 0 !important; }
  #loading::before {
      content: '';
      position: fixed;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      width: 50px;
      height: 50px;
      border: 4px solid rgba(96, 165, 250, 0.2);
      border-top-color: #60a5fa;
      border-radius: 50%;
      animation: spin 0.8s linear infinite;
      z-index: 100001;
  }

  .cut-text { text-overflow: ellipsis; overflow: hidden; white-space: nowrap; }
  hr { border-color: var(--border-color); margin: 24px 0; }
  ::-webkit-scrollbar { width: 8px; }
  ::-webkit-scrollbar-track { background: var(--bg-primary); }
  ::-webkit-scrollbar-thumb { background: var(--accent-primary); border-radius: 4px; }
  ::-webkit-scrollbar-thumb:hover { background: var(--accent-secondary); }
    /* Navigation Menu Override */
    ul.nav.nav-pills.bg-light {
        background-color: rgba(30, 41, 59, 0.6) !important;
        backdrop-filter: blur(10px);
        border: 1px solid rgba(255, 255, 255, 0.08);
        border-radius: 50rem !important;
        padding: 6px !important;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2) !important;
        display: inline-flex !important;
        flex-wrap: wrap;
        justify-content: center;
        width: auto !important;
        margin-bottom: 20px;
    }

    ul.nav.nav-pills .nav-item {
        margin: 0 2px;
    }

    ul.nav.nav-pills .nav-link {
        border-radius: 50rem !important;
        padding: 8px 20px !important;
        color: #94a3b8 !important;
        font-weight: 600;
        transition: all 0.3s ease;
    }

    ul.nav.nav-pills .nav-link:hover {
        background-color: rgba(255, 255, 255, 0.1);
        color: #fff !important;
        transform: translateY(-1px);
    }

    ul.nav.nav-pills .nav-link.active {
        background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%) !important;
        color: #fff !important;
        box-shadow: 0 4px 12px rgba(37, 99, 235, 0.4);
    }
</style>
<link href="{{ url_for('.static', filename='css/bootstrap.min.css') }}" type="text/css" rel="stylesheet" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.7.1/font/bootstrap-icons.css" />

<style>
    /* Smooth Load Transition */
    .content-cloak, 
    #menu_module_div, 
    #menu_page_div {
        opacity: 0;
        transition: opacity 0.5s ease-out;
    }
    
    /* Staggered Delays for Natural Top-Down Flow */
    #menu_module_div.visible {
        opacity: 1;
        transition-delay: 0ms;
    }

    #menu_page_div.visible {
        opacity: 1;
        transition-delay: 150ms;
    }

    .content-cloak.visible {
        opacity: 1;
        transition-delay: 300ms;
    }
    
    /* Navigation Menu Override (Top Sub-menu) */
    ul.nav.nav-pills.bg-light {
        background-color: rgba(30, 41, 59, 0.6) !important;
        backdrop-filter: blur(10px);
        border: 1px solid rgba(255, 255, 255, 0.08);
        border-radius: 50rem !important;
        padding: 6px !important;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2) !important;
        display: inline-flex !important;
        flex-wrap: wrap;
        justify-content: center;
        width: auto !important;
        margin-bottom: 20px;
    }

    ul.nav.nav-pills .nav-item { margin: 0 2px; }
    ul.nav.nav-pills .nav-link {
        border-radius: 50rem !important;
        padding: 8px 20px !important;
        color: #94a3b8 !important;
        font-weight: 600;
        transition: all 0.3s ease;
    }
    ul.nav.nav-pills .nav-link:hover {
        background-color: rgba(255, 255, 255, 0.1);
        color: #fff !important;
        transform: translateY(-1px);
    }
    ul.nav.nav-pills .nav-link.active {
        background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%) !important;
        color: #fff !important;
        box-shadow: 0 4px 12px rgba(37, 99, 235, 0.4);
    }
</style>

<script type="text/javascript">
$(document).ready(function(){
  // Smooth Load Trigger
  setTimeout(function() {
      $('.content-cloak, #menu_module_div, #menu_page_div').addClass('visible');
  }, 100);
});
</script>
<style>
/* Mobile Margin Fix */
@media (max-width: 768px) {
    body { overflow-x: hidden !important; padding: 0 !important; margin: 0 !important; }
    .container, .container-fluid, .row, form, #program_list, #program_auto_form, #episode_list, .queue-container, #yommi_wrapper, #main_container {
        width: 100% !important; max-width: 100% !important;
        padding-left: 4px !important; padding-right: 4px !important;
        margin-left: 0 !important; margin-right: 0 !important;
        box-sizing: border-box !important;
    }
    .form-group, .form-inline, [class*="col-"] {
        flex: 0 0 100% !important; max-width: 100% !important; width: 100% !important;
        padding-left: 0 !important; padding-right: 0 !important;
    }
    .row { margin-left: 0 !important; margin-right: 0 !important; }
    .card, .card.p-4, .card.p-lg-5, .card.border-light {
         width: calc(100% - 8px) !important; max-width: 100% !important;
         padding: 8px !important; margin: 4px !important;
         border-radius: 12px !important; box-sizing: border-box !important;
    }
    .badge {
        white-space: normal !important; text-align: left !important;
        line-height: 1.4 !important; height: auto !important; display: inline-block !important;
    }
}
</style>
{% endblock %}
