/* ================================
   バタフライチャート（共有）
   compare.html / compare-teams.html / match.html の
   .match-stats-grid 比較UI、および選手比較のポジション行で使用。
   ================================ */

.match-stats-grid {
  --match-stat-track: rgba(0, 0, 0, 0.06);
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.match-stat-leader-name {
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1.35;
  color: var(--color-text-muted, #4a5568);
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.match-stat-leader-name--home {
  grid-column: 1 / 3;
  text-align: right;
  padding-right: 2px;
}

.match-stat-leader-mid {
  grid-column: 3;
  min-height: 0;
}

.match-stat-leader-name--away {
  grid-column: 4 / 6;
  text-align: left;
  padding-left: 2px;
}

.match-stat-row {
  display: grid;
  /* PC: 中心ラベルを20%に縮小（40%の50%） */
  /* 横幅を可変にしてcontainerの幅に合わせる */
  /* 左右の空白幅を揃えるため、値セルとバーセルの幅を均等に */
  grid-template-columns: 1fr 32% 20% 32% 1fr;
  align-items: center;
  column-gap: var(--space-sm);
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  min-width: 0; /* 最小幅制約を解除して可変にする */
}

/* 所属選手ハイライトの下段: ベース .match-stat-row より詳細度を上げ align-items を上書き */
.match-stat-row.match-stat-row--leader-names {
  margin-top: -4px;
  padding-bottom: 2px;
  align-items: start;
}

.match-stat-cell {
  min-width: 0;
}

.match-stat-cell--value {
  font-variant-numeric: tabular-nums;
  font-size: 0.85rem;
  line-height: 1.2;
}

.match-stat-cell--home-value {
  text-align: right;
}

.match-stat-cell--away-value {
  text-align: left;
}

.match-stat-label {
  font-size: 0.8rem;
  text-align: center;
  white-space: normal;
  word-break: keep-all;
  line-height: 1.3;
  padding: 0 4px; /* PCでも文字とチャートバーが重ならないように調整 */
  min-width: 0; /* テキストオーバーフローを防ぐ */
  overflow-wrap: break-word; /* 長いテキストを折り返す */
}

/* ポジションヘッダー行（バタフライチャートのヘッダー） */
.compare-positions-row {
  margin-bottom: 8px;
  border-bottom: 1px solid var(--color-border, #d9e1ee);
  padding-bottom: 8px;
}

.compare-positions-cell {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-text, #333);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.compare-positions-cell--left {
  grid-column: 2;
}

.compare-positions-cell--right {
  grid-column: 4;
}

.compare-positions-label {
  /* 中央ラベル列（20%）に配置、既存の項目名と同じフォント感 */
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-text, #333);
  text-align: center;
}

/* ポジション行の値セルは中央揃えで表示 */
.match-stat-cell--position {
  text-align: center !important;
}

.match-stat-cell--bar {
  display: flex;
  align-items: center;
}

.match-stat-bar {
  position: relative;
  width: 100%;
  max-width: 100%;
  height: 8px;
  border-radius: 999px;
  overflow: hidden;
  background-color: var(--match-stat-track);
}

.match-stat-bar--home::before,
.match-stat-bar--away::before {
  content: "";
  position: absolute;
  inset: 0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.match-stat-bar--home::before {
  left: auto;
  right: 0;
  width: calc(var(--value, 0) * 1%);
  background-color: var(--bar-color, var(--color-primary));
}

.match-stat-bar--away::before {
  left: 0;
  right: auto;
  width: calc(var(--value, 0) * 1%);
  background-color: var(--bar-color, var(--color-accent, #ff5a5f));
}

.match-stat-value {
  font-weight: 600;
}

@media (max-width: 768px) {
  .match-stats-grid {
    width: 100%;
    max-width: 100%;
    overflow-x: visible; /* 横スクロールを無効化、container内に収める */
  }

  .match-stat-row {
    /* ガイドライン 3.2 準拠（Mobile）: 左右の空白幅を揃えるため、値セルとバーセルの幅を均等に */
    grid-template-columns: 1fr 22% 36% 22% 1fr;
    column-gap: var(--space-xs);
    width: 100%;
    max-width: 100%;
    /* min-widthを削除して横幅を可変にする */
  }

  /* モバイルでセルテキストの折り返しを有効化 */
  .match-stat-cell,
  .match-stat-label {
    white-space: normal; /* nowrap を上書き */
    overflow: visible; /* 切り落としを回避 */
    word-wrap: break-word;
    word-break: break-word;
  }

  .match-stat-cell--value {
    font-size: 0.75rem;
  }

  .match-stat-label {
    font-size: 0.75rem;
    padding-inline: 4px; /* 文字とチャートバーが重ならないようにpaddingを増やす */
    min-width: 0; /* テキストオーバーフローを防ぐ */
    overflow-wrap: break-word; /* 長いテキストを折り返す */
  }

  /* モバイルでのポジションヘッダー行 */
  .compare-positions-cell {
    font-size: 0.75rem;
  }

  .compare-positions-label {
    font-size: 0.75rem;
  }

  .match-stat-bar {
    height: 6px;
  }

  .match-stat-leader-name {
    font-size: 0.68rem;
  }
}
