@charset "utf-8";

/* 商品紹介リンク用 */
/* (Amazonと楽天リンク) */
/* 新しい AffiliateBox::render() 用のスタイル */
.affiliate-box {
  position: relative;
  margin: 21px 0 0;
  max-width: 500px;
  max-height: 100%;
  border: 1px solid #d1d1d1;
  border-radius: 5px;
  line-height: 0;
  text-align: center;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  justify-content: space-between;

  /* ADリボンの再現 */
  &::before {
    position: absolute;
    content: "AD";
    top: 0px;
    right: 5px;
    margin-top: 5px;
    padding: 1px 2px;
    line-height: 1;
    font-size: 0.6em;
    color: #f4cece;
    border-radius: 5px;
    border: 1px solid #f4cece;
    z-index: 10;
  }

  /* 画像と詳細情報を含むコンテナ */
  .product-info-container {
    display: flex;
    /* デフォルトは縦並び */
    flex-direction: column;
    padding: 10px 10px 0pt;
    line-height: 1.4;

    & a {
      text-decoration: none;
      color: inherit;
    }

    .product-image-link {
      display: block;
      margin: 0 auto 10px;
    }

    .product-image {
      max-width: 160px;
      margin: 0;
      display: block;
      /* 中央寄せのためにブロック化 */
    }

    .product-detail {
      display: flex;
      flex-direction: column;
      flex-grow: 1;
    }

    .product-title {
      font-size: 0.9375rem;
      font-weight: bold;
      padding: 0;
      margin: 0;
      overflow: hidden;
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 3;
      line-clamp: 3;
      line-height: 1.4;
      text-decoration: underline;
    }
  }

  /* --- 横並びレイアウト用 (.type-horizontal) --- */
  &.type-horizontal {
    .product-info-container {
      /* 横並びに変更 */
      flex-direction: row;
      align-items: center;
      gap: 15px;
      padding: 15px;
    }

    .product-image-link {
      flex-shrink: 0;
      width: 35%;
      max-width: 150px;
      margin: 0;
    }

    .product-image {
      margin: 0 auto;
      max-width: 100%;
    }

    .product-detail {
      flex-grow: 1;
    }

    .product-title {
      text-align: left;
      font-size: 0.875rem;
    }

    .buttonbox {
      margin: 15px 0 0;
      padding: 0;
      justify-content: flex-start;
      flex-wrap: wrap;
      gap: 10px;

      @media screen and (max-width: 480px) {
        .mercari-button {
          display: none;
        }
      }

      & > div {
        margin: 0;
        width: auto;
        padding: 5px 10px;
        font-size: 0.8125rem;
      }
    }
  }

  /* --- ボタンボックスの再現 --- */
  .buttonbox {
    display: flex;
    justify-content: center;
    margin: 10px 0 0;
    padding: 0 0 10px;
    gap: 10px;

    & > div {
      padding: 5px;
      width: 90px;
      border-radius: 5px;
      font-size: 0.9375rem;
      font-weight: bold;
      line-height: 1.5;
      text-align: center;

      & a {
        display: block;
        text-decoration: none;
        color: #fff;

        &:hover {
          color: #fff;
          /* hover時も色が変わらないように指定 */
        }
      }
    }

    .amazon-button {
      background-color: #f39c12;

      &:hover {
        background-color: #e67e22;
      }
    }

    .rakuten-button {
      background-color: #e74c3c;

      &:hover {
        background-color: #c0392b;
      }
    }

    .mercari-button {
      background-color: #3498db;

      &:hover {
        background-color: #2980b9;
      }
    }
  }

  /* SALE用 */
  .sale-banner-wrapper {
    /* 点滅するバナーを重ねて配置するコンテナ */
    position: relative;
    width: 100%;
    /* テキストの高さに合わせて調整 */
    height: 25px;
    overflow: hidden;
    box-sizing: border-box;
  }

  .sale-banner {
    /* バナー共通スタイル */
    font-size: 0.8125rem;
    font-weight: bold;
    color: #fff;
    line-height: 1.3;
    text-align: center;
    padding: 5px 0;
    border-radius: 0 0 4px 4px;
    user-select: none;
    cursor: default;

    /* テキスト内容自体は span でラップされています */
    & span {
      display: block;
    }
  }

  /* --- 2. 点滅モード（2つ用）のスタイル (.sale-flipping) --- */
  .sale-banner-wrapper.sale-flipping {

    /* 点滅する要素は全て絶対配置で重ねる */
    .sale-banner {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      /* アニメーション設定 (合計8秒サイクル) */
      animation: textSwitch 8s infinite;
      opacity: 0;
    }

    /* 1つ目のセール */
    .sale-banner:nth-child(1) {
      animation-delay: 0s;
    }

    /* 2つ目のセール */
    .sale-banner:nth-child(2) {
      /* 4秒後にアニメーションを開始 */
      animation-delay: 4s;
    }
  }

  /* --- 3. 点滅モード（3つ用）のスタイル (.sale-flipping-3) --- */
  .sale-banner-wrapper.sale-flipping-3 {
    .sale-banner {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      /* 9秒サイクル (3秒ずつ表示) */
      animation: textSwitch3 9s infinite;
      opacity: 0;
    }

    /* 1つ目 */
    .sale-banner:nth-child(1) {
      animation-delay: 0s;
    }

    /* 2つ目 */
    .sale-banner:nth-child(2) {
      animation-delay: 3s;
    }

    /* 3つ目 */
    .sale-banner:nth-child(3) {
      animation-delay: 6s;
    }
  }

  /* --- 4. 静的モード時のスタイル (一方のみ) --- */
  .sale-banner.static-sale {
    position: static;
    /* 絶対配置を解除し、通常フローに戻す */
    opacity: 1;
    /* 常に表示 */
    animation: none;
    /* アニメーションを停止 */
  }

  /* 配色 */
  .sale-banner.sale-amazon {
    background-color: #ff7f00;
  }

  .sale-banner.sale-rakuten {
    background-color: #bf0000;
  }

  .sale-banner.sale-mercari {
    background-color: #3087c1;
  }
}

/* AffiliateBox.php 商品画像無し用 */
.no-product-image img {
  width: 80px;
  height: auto;
}

/* --- @keyframes (アニメーション本体) --- */
/* 8秒サイクルで、3.5秒表示 + 0.5秒フェードアウト/インを実現 */
@keyframes textSwitch {
  0% {
    opacity: 0;
  }

  /* 0.5秒かけてフェードイン (8秒のサイクルの 6.25% に相当) */
  6.25% {
    opacity: 1;
  }

  /* 3.5秒間表示を維持 (8秒のサイクルの 43.75% に相当) */
  43.75% {
    opacity: 1;
  }

  /* 4.0秒 (50%) で非表示へフェードアウト */
  50% {
    opacity: 0;
  }

  /* 50%以降は非表示を維持し、次の要素の表示を待つ */
  100% {
    opacity: 0;
  }
}

/* --- @keyframes (3つ用アニメーション本体) --- */
/* 9秒サイクルで、約3秒表示(33%) */
@keyframes textSwitch3 {
  0% {
    opacity: 0;
  }

  5% {
    opacity: 1;
  }

  /* フェードイン */
  30% {
    opacity: 1;
  }

  /* 表示維持 */
  33.33% {
    opacity: 0;
  }

  /* フェードアウト完了 */
  100% {
    opacity: 0;
  }
}
