/* =================================================================== */
/*             IG 粉絲排行榜 - 最終整合 CSS (含手機版修正)              */
/* =================================================================== */

/* --- 主要容器 --- */
.ig-leaderboard {
  max-width: 600px;
  margin: 0 auto 40px auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  font-family: system-ui, -apple-system, sans-serif;
}

/* --- 單張卡片 --- */
.ig-rank-card {
  display: flex;
  align-items: center;
  background: #fff;
  border-radius: 16px;
  padding: 12px 20px;
  color: #333;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  transition: transform 0.2s, box-shadow 0.2s;
  position: relative;
}
.ig-rank-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

/* --- 左側：排名數字與皇冠 --- */
.rank-number-wrapper {
  width: 40px;
  flex-shrink: 0;
  text-align: center;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin-right: 16px;
}
.rank-number {
  font-size: 20px;
  font-weight: 600;
  color: #e1306c;
  line-height: 1;
}
.rank-crown {
  position: absolute;
  top: -20px;
  left: 50%;
  transform: translateX(-50%);
  width: 24px;
  height: 24px;
  color: #ffc107;
}
.ig-rank-card.rank-top-1 .rank-number,
.ig-rank-card.rank-top-2 .rank-number,
.ig-rank-card.rank-top-3 .rank-number {
  font-size: 26px;
}

/* --- 左側：頭像 --- */
.rank-thumb-link {
  flex-shrink: 0;
}
.rank-thumb {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  overflow: hidden;
  border: 3px solid #f0f0f0;
  display: block;
}
.rank-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* --- 中間：資訊區 (姓名 & 節目) --- */
.rank-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 0 16px;
  align-items: flex-start;
  min-width: 0; /* <<-- 解決重疊的關鍵！允許此區塊被壓縮 */
}
.rank-name,
.rank-show {
  width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rank-name {
  font-size: 15px;
  font-weight: 300;
  text-decoration: none;
  color: #333;
  transition: color 0.2s;
}
.rank-name:hover { color: #e1306c; }
.rank-show {
  font-size: 13px;
  color: #777;
  text-decoration: none;
  transition: color 0.2s;
}
.rank-show:hover { color: #e1306c; }
.rank-show-placeholder {
  font-size: 13px;
  height: 1em;
}

/* --- 右側：粉絲數 --- */
.rank-fans {
  color: #e1306c;
  margin-left: auto;
  white-space: nowrap;
  display: flex;
  align-items: baseline;
  gap: 0.25em;
}
.fans-number {
  font-size: 22px;
  font-weight: 300;
  line-height: 1; 
}
.fans-unit {
  font-size: 13px;
  font-weight: 100;
}


/* =================================================================== */
/*             !!! 手機版響應式修正 !!!                              */
/* =================================================================== */
@media (max-width: 768px) {
  /* 縮小卡片內邊距，爭取空間 */
  .ig-rank-card {
    padding-left: 15px;
    padding-right: 15px;
  }
  
  /* 縮小頭像 */
  .rank-thumb {
    width: 48px;
    height: 48px;
  }
  
  /* 縮小各種間距 */
  .rank-number-wrapper { margin-right: 12px; }
  .rank-info { margin: 0 10px; }
  
  /* 縮小各種字體 */
  .rank-name {
    font-size: 15px; /* 排行榜姓名統一 15px */
  }
  .fans-number {
    font-size: 16px; /* 縮小粉絲數 */
  }
  .fans-unit {
    font-size: 12px;
  }
  .rank-number,
  .ig-rank-card.rank-top-1 .rank-number,
  .ig-rank-card.rank-top-2 .rank-number,
  .ig-rank-card.rank-top-3 .rank-number {
    font-size: 18px; /* 統一排名數字大小 */
  }
}


/* --- 變數定義 (方便統一修改) --- */
:root {
    /* 移除 --profile-grid-columns，因為它將由特定規則處理 */
    --profile-image-size: 550px;
    --profile-grid-gap: 30px;
    --main-layout-gap: 30px;
    --promo-image-radius: 30px;
    --ig-icon-bg: #e1306c;
}

/* --- 整個節目區塊 --- */
.show-block {
    max-width: 1200px;
    margin: 40px auto;
    padding-bottom: 40px;
    font-family: system-ui, -apple-system, sans-serif;
    border-bottom: 1px solid #e5e7eb;
}
.show-list > .show-block:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

/* --- 內部主要容器 --- */
.show-inner {
    display: flex;
    align-items: flex-start; 
    gap: var(--main-layout-gap);
}

/* --- 左側容器 (包裹圖片和標題) --- */
.left-panel-wrapper {
    flex: 1;
    position: relative;
    max-width: 315px; 
}

/* 16:9 圖片容器 */
.left-panel-wrapper::before {
    content: '';
    display: block;
    padding-top: 56.25%; /* 16:9 */
}

/* 左側大圖 */
.left-panel-wrapper .show-thumbnail {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover; 
    object-position: center;
    border-radius: var(--promo-image-radius);
}

/* 節目標題 */
.left-panel-wrapper .show-title {
	max-width: 100%;
    position: absolute;
    bottom: 0px;
    right: 0px;
    background-color: var(--ig-icon-bg);
    padding: 8px 30px;
    border-radius: 30px 0; 
    font-size: 0.8rem;
    font-weight: 400;
    color: #fff;
    margin: 0;
    white-space: nowrap;
    z-index: 10;
    transition: background-color 0.3s;
	letter-spacing:0.2rem;
}
.left-panel-wrapper .show-title a {
    text-decoration: none;
    color: inherit;
}
.left-panel-wrapper .show-title:hover {
    background-color: #c8235c;
}

/* --- 右側演員區 --- */
.show-inner .show-content {
    flex: 1.5;
    padding-top: 0;
}

/* --- 右側演員網格 --- */
.cast-group {
    display: grid;
    gap: var(--profile-grid-gap);
    justify-items: center;
}

/* 
   --- 【關鍵修改點】 ---
   根據 .cast-group 內部包含的卡片類型來設定欄數
*/
/* 如果 .cast-group 裡面有 .cast-card1，就設定為 5 欄 */
.cast-group:has(.cast-card1) {
    grid-template-columns: repeat(5, 1fr);
}

/* 如果 .cast-group 裡面有 .cast-card2，就設定為 4 欄 */
.cast-group:has(.cast-card2) {
    grid-template-columns: repeat(3, 1fr);
}

/* 如果 .cast-group 裡面有 .cast-card3，就設定為 5 欄 */
.cast-group:has(.cast-card3) {
    grid-template-columns: repeat(4, 1fr);
}


/* --- 單一演員卡片 --- */
.cast-card1, .cast-card2, .cast-card3 {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%; 
    text-align: center;
}

/* 演員圓形頭像 */
.cast-card1 .cast-thumbnail, 
.cast-card2 .cast-thumbnail,
.cast-card3 .cast-thumbnail {
    width: var(--profile-image-size);
    aspect-ratio: 1 / 1;    
    border-radius: 50%;
    object-fit: cover;  
    margin-bottom: 0px;
    border: 4px solid #f0f2f5;
    transition: transform 0.3s ease;
}
.cast-card1 .cast-thumbnail:hover,
.cast-card2 .cast-thumbnail:hover,
.cast-card3 .cast-thumbnail:hover{
    transform: scale(1.05);
}

/* (以下的名字、IG 圖示等樣式保持不變) */
.cast-name-line {
    display: grid;
    grid-template-columns: 26px minmax(0, 1fr) 26px;
    align-items: center;
    width: 100%;
    min-width: 0;
}
.cast-name {
    display: block;
    grid-column: 2;
    width: 100%;
    min-width: 0;
    font-size: 1rem;
    line-height: 1.25;
    color: #444;
    text-decoration: none;
    font-weight: 300;
    text-align: center;
}
.cast-name-line:not(:has(.ig-icon)) {
    display: flex;
    justify-content: center;
}
.cast-name-line:not(:has(.ig-icon)) .cast-name {
    flex: 1 1 auto;
    width: auto;
}
.cast-name-stage,
.cast-name-chinese {
    overflow-wrap: anywhere;
}
.cast-name:hover { color: var(--ig-icon-bg); }
.ig-icon {
    display: inline-flex;
    grid-column: 3;
    justify-self: end;
    flex: 0 0 24px;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    width: 24px;
    min-width: 24px;
    height: 24px;
    min-height: 24px;
    background-color: var(--ig-icon-bg);
    border-radius: 50%;
    color: white;
    transition: transform 0.2s;
}
.ig-icon:hover { transform: scale(1.1); }
.ig-icon svg { display: block; flex: 0 0 13px; width: 13px; height: 13px; }

/* --- 響應式設計 (RWD) --- */

/* 平板尺寸 */
@media (max-width: 1024px) {
    /* 平板上 card1 維持 5 欄，card2 為 3 欄 */
    .cast-group:has(.cast-card1) {
        grid-template-columns: repeat(5, 1fr);
    }
    .cast-group:has(.cast-card2) {
        grid-template-columns: repeat(3, 1fr);
    }
    .show-block {
        --profile-image-size: 100px;
    }
}

/* 手機尺寸 */
@media (max-width: 768px) {
    .show-inner {
        flex-direction: column; 
        gap: 30px;
    }
    .left-panel-wrapper {
        width: 100%;
        max-width: 100%;
    }
    
    .show-inner .show-content {
        display: flex;
        justify-content: center;
        width: 100%;
    }
    
    /* 手機上仍然統一為 3 欄 */
    .cast-group:has(.cast-card1) {
        grid-template-columns: repeat(3, 1fr);
        gap: 25px; /* 這裡可以直接設定 gap，不需要再用變數 */
    }
	.cast-group:has(.cast-card2) {
        grid-template-columns: repeat(2, 1fr);
        gap: 25px; /* 這裡可以直接設定 gap，不需要再用變數 */
    }
	.cast-group:has(.cast-card3) {
        grid-template-columns: repeat(2, 1fr);
        gap: 25px; /* 這裡可以直接設定 gap，不需要再用變數 */
    }
    .show-block {
        --profile-image-size: 110px;
    }
}

/* 成員總表中的純文字換行 */
body.post-type-archive-cast_member .entry-title,
body.post-type-archive-cast_member .elementor-post__title,
body.post-type-archive-cast_member .elementor-heading-title {
  white-space: pre-line;
}
