/* ui-popup.css */
/* ポップアップおよびモーダル関連のスタイル */

/* スペシャル動画ポップアップ */
.special-popup {
  position: fixed;
  bottom: -300px; /* より下に初期位置を設定 */
  left: 50%;
  transform: translateX(-50%);
  width: 90%;
  max-width: 480px;
  background-color: rgba(255, 255, 255, 0.95);
  border-radius: var(--border-radius);
  padding: var(--spacing-medium);
  box-shadow: var(--shadow-medium);
  text-align: center;
  z-index: 50;
  transition: bottom 0.4s ease-in-out, opacity 0.3s ease-in-out, visibility 0.3s ease-in-out;
}

.special-popup.is-visible {
  bottom: 20px; /* 表示位置 */
  visibility: visible;
  opacity: 1;
}

.special-popup.is-hidden {
  visibility: hidden;
  opacity: 0;
  bottom: -300px; /* 非表示位置に戻す */
}

/* アイコンを上部中央に配置 */
.special-popup__avatar {
  width: 70px;
  height: 70px;
  border-radius: 50%;
  border: 3px solid var(--color-secondary);
  overflow: hidden;
  margin: -45px auto 5px; /* 上部にはみ出させて配置 */
  box-shadow: var(--shadow-medium);
}

.special-popup__img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* 名前をアイコンのすぐ下に配置 */
.special-popup__name {
  font-size: 0.8rem;
  color: var(--color-text-light);
  margin: 0 0 var(--spacing-small);
  text-align: center;
}

.special-popup__content {
  margin: 0 auto;
  max-width: 90%;
  text-align: center;
}

.special-popup__title {
  font-size: var(--font-size-medium);
  font-weight: bold;
  color: var(--color-secondary);
  margin-bottom: var(--spacing-medium);
  text-align: center;
}

.special-popup__text {
  font-size: var(--font-size-small);
  color: var(--color-white);
  text-align: center;
  cursor: pointer;
  display: inline-block;
  padding: var(--spacing-xsmall) var(--spacing-medium);
  background-color: var(--color-secondary);
  border-radius: 20px;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.special-popup__text:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-small);
}

.special-popup__close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 24px;
  height: 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.special-popup__close::before,
.special-popup__close::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 2px;
  background-color: var(--color-secondary);
}

.special-popup__close::before {
  transform: rotate(45deg);
}

.special-popup__close::after {
  transform: rotate(-45deg);
}

/* コンテンツモーダル */
.content-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.9); /* 背景を暗く */
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease-in-out, visibility 0.3s ease-in-out;
  padding: 20px; /* 全体のパディングを追加 */
  box-sizing: border-box;
}

.content-modal.is-visible {
  opacity: 1;
  visibility: visible;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
}

/* コンテンツコンテナ - 基本スタイル */
.content-modal__container {
  position: relative;
  background-color: transparent; /* 透明に変更 */
  border-radius: var(--border-radius);
  overflow: visible; /* overflow:hiddenを解除して閉じるボタンが見えるように */
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 101; /* 確実に前面に表示 */
  transition: width 0.3s ease, height 0.3s ease;
  box-sizing: border-box;
  margin: 0 auto; /* 水平方向の中央揃え */
}

/* YouTube用コンテナ - 横長 (16:9) */
.content-modal__container.youtube-container {
  box-shadow: var(--shadow-large);
  background-color: black;
  /* JSが計算した値を優先するためにCSSの値を初期化または補助的な設定にする */
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
}

/* YouTube Shorts用コンテナ - 縦長 (9:16) */
.content-modal__container.shorts-container {
  box-shadow: var(--shadow-large);
  background-color: black;
  /* JSが計算した値を優先するためにCSSの値を初期化または補助的な設定にする */
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
}

/* X投稿用コンテナ */
.content-modal__container.tweet-container {
  background-color: white;
  box-shadow: var(--shadow-large);
  /* X投稿のみCSS側で制御 */
  width: 550px;
  height: auto;
  max-height: 80vh;
}

/* 閉じるボタン - 基本スタイル */
.content-modal__close {
  position: absolute;
  width: 44px;
  height: 44px;
  background-color: rgba(255, 255, 255, 0.95);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 1000; /* 非常に高い値に設定して確実に最前面に */
  box-shadow: 0 3px 15px rgba(0, 0, 0, 0.5);
  transition: background-color 0.2s ease, transform 0.2s ease;
  /* 基本位置は右上 */
  top: -50px;
  right: 0;
  pointer-events: auto !important; /* クリックイベントを確実に受け取る */
}

/* 閉じるボタン共通のホバー効果 */
.content-modal__close:hover {
  background-color: white;
  transform: scale(1.1);
}

.content-modal__close::before,
.content-modal__close::after {
  content: '';
  position: absolute;
  width: 24px; /* より太く */
  height: 3px; /* より太く */
  background-color: rgba(0, 0, 0, 0.8); /* より濃く */
}

.content-modal__close::before {
  transform: rotate(45deg);
}

.content-modal__close::after {
  transform: rotate(-45deg);
}

/* コンテンツラッパー */
.content-modal__content-wrapper {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden; /* コンテンツ自体はオーバーフローを隠す */
}

/* コンテンツタイプ別のスタイル調整 - 非表示をデフォルトに */
.content-modal__youtube,
.content-modal__shorts,
.content-modal__tweet {
  display: none; /* 初期状態では全て非表示 */
}

/* アクティブなコンテナのみ表示 */
.active-container {
  display: flex !important;
}

/* コンテンツタイプ別のスタイル調整 */
.content-modal__iframe-container {
  width: 100%;
  height: 100%;
  background-color: #000;
  align-items: center !important;
  justify-content: center !important;
  position: relative;
  overflow: hidden; /* iframe内のコンテンツはoverflowを隠す */
}

.content-modal__iframe {
  border: none;
  width: 100%;
  height: 100%;
}

/* X(Twitter)埋め込み用 */
.content-modal__tweet-container {
  width: 100%;
  height: auto;
  max-height: 100%;
  background-color: white;
  padding: var(--spacing-medium);
  border-radius: var(--border-radius);
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Twitter埋め込みを中央揃えにする */
.content-modal__tweet blockquote.twitter-tweet {
  margin: 0 auto !important;
}

/* レスポンシブ調整 - スマホサイズ (767px以下) */
@media (max-width: 767px) {
  .special-popup {
    width: 95%;
    padding: var(--spacing-small);
  }
  
  .special-popup__avatar {
    width: 50px;
    height: 50px;
    margin-top: -35px;
  }
  
  .special-popup__title {
    font-size: var(--font-size-small);
  }
  
  .content-modal {
    padding: 10px;
  }
  
  /* モバイルでの閉じるボタンの共通スタイル */
  .content-modal__close {
    width: 46px;
    height: 46px;
    top: -60px;
    right: 0;
    background-color: rgba(255, 255, 255, 0.9);
    box-shadow: 0 2px 15px rgba(0, 0, 0, 0.6);
    z-index: 2000;
  }

  /* YouTube - スマホ */
  /* JavaScript側で制御するためCSSの上書きを削除 */
  
  /* Shorts - スマホ */
  /* JavaScript側で制御するためCSSの上書きを削除 */
  
  /* X投稿のみCSS側で制御 */
  .content-modal__container.tweet-container {
    width: 95%;
    max-width: 550px;
    height: auto;
    max-height: 75vh;
    padding: 20px;
  }
}

/* タブレットサイズ (768px ~ 991px) */
@media (min-width: 768px) and (max-width: 991px) {
  /* デスクトップと同じ処理でJSに任せる */

  /* X投稿のみCSS側で制御 */
  .content-modal__container.tweet-container {
    width: 550px;
    height: auto;
    max-height: 80vh;
  }
}

/* デスクトップサイズ (992px以上) */
@media (min-width: 992px) {
  /* デスクトップでJSでの計算を優先 */
  
  /* X投稿のみCSS側で制御 */
  .content-modal__container.tweet-container {
    width: 550px;
    height: auto;
    max-height: 80vh;
  }
}

/* 横向き画面対応 - 入れ子にせず独立したメディアクエリとして定義 */
@media (orientation: landscape) and (max-height: 600px) {
  /* 低い高さの横向き画面（スマホ横向きなど）の場合 */
  .content-modal__close {
    top: 10px;
    right: 10px;
  }
}

/* アニメーション: モーダル表示時のエフェクト */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes scaleIn {
  from { transform: scale(0.9); }
  to { transform: scale(1); }
}

.content-modal.is-visible .content-modal__container {
  animation: fadeIn 0.3s ease-out, scaleIn 0.3s ease-out;
}