/* ==========================================================================
   チャット形式（会話）の記事：吹き出し（2026.11.19 追加・試作）
   中身の組み立ては lib/fn-article_chat.php。記事ページと編集画面の両方で読み込みます。
   ・左の話し手：黒い丸に名前／グレーの吹き出し
   ・右の話し手：緑の丸に名前／うすい緑の吹き出し
   ・文字の大きさは本文に合わせて 15px（スマホは画面幅の割合で小さく）
   ========================================================================== */
.tj-chat { --tj-chat-face: 52px; display: grid; gap: 20px; margin: 2.4em 0; }
.tj-chat + .tj-chat { margin-top: 2em; }

.tj-chat .tj-chatMsg {
  display: grid;
  grid-template-columns: var(--tj-chat-face) minmax(0, 1fr);
  column-gap: 14px;
  align-items: start;
  margin: 0;
}
.tj-chat .tj-chatMsg.is-right { grid-template-columns: minmax(0, 1fr) var(--tj-chat-face); }

/* --- 話し手（丸の中に名前） --- */
.tj-chat p.tj-chatMsg_who,
.tj-chat .tj-chatMsg_who {
  display: grid;
  place-items: center;
  width: var(--tj-chat-face);
  height: var(--tj-chat-face);
  margin: 0;
  padding: 4px;
  box-sizing: border-box;
  border-radius: 50%;
  background: #373737;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: 0.04em;
  text-align: center;
  word-break: break-all;
}
.tj-chat .tj-chatMsg.is-right .tj-chatMsg_who { grid-column: 2; grid-row: 1; background: #aacf52; }

/* --- 吹き出し --- */
.tj-chat .tj-chatMsg_body {
  position: relative;
  justify-self: start;
  max-width: 36em;
  margin: 0;
  padding: 14px 20px;
  border-radius: 16px;
  background: #f3f3f3;
}
.tj-chat .tj-chatMsg.is-right .tj-chatMsg_body { grid-column: 1; grid-row: 1; justify-self: end; background: #eef5dc; }
.tj-chat .tj-chatMsg_body::before {
  content: "";
  position: absolute;
  top: 18px;
  left: -7px;
  width: 14px;
  height: 14px;
  background: inherit;
  rotate: 45deg;
  border-radius: 2px;
}
.tj-chat .tj-chatMsg.is-right .tj-chatMsg_body::before { left: auto; right: -7px; }

/* 吹き出しの中の段落は、本文の段落の余白・大きさを使わない（本文の指定より強く効かせるためクラスを重ねる） */
.tj-chat .tj-chatMsg .tj-chatMsg_body p,
.mk_articlePage .bl_single_body .tj-chat .tj-chatMsg_body p {
  position: relative;
  margin: 0;
  font-size: 15px;
  line-height: 1.9;
  color: #373737;
}
.tj-chat .tj-chatMsg .tj-chatMsg_body p + p,
.mk_articlePage .bl_single_body .tj-chat .tj-chatMsg_body p + p { margin-top: 0.6em; }

/* --- スマホ：丸と文字を画面幅に合わせて小さく --- */
@media (max-width: 767px) {
  .tj-chat { --tj-chat-face: clamp(38px, 11.2vw, 52px); gap: 16px; }
  .tj-chat .tj-chatMsg { column-gap: 10px; }
  .tj-chat p.tj-chatMsg_who, .tj-chat .tj-chatMsg_who { font-size: clamp(9px, 2.67vw, 11px); padding: 2px; }
  .tj-chat .tj-chatMsg_body { padding: 12px 16px; border-radius: 14px; }
  .tj-chat .tj-chatMsg_body::before { top: 14px; }
  .tj-chat .tj-chatMsg .tj-chatMsg_body p,
  .mk_articlePage .bl_single_body .tj-chat .tj-chatMsg_body p { font-size: clamp(13px, 3.73vw, 15px) !important; line-height: 1.8; }
}

/* 記事ページではグループの中身が「wp-block-group__inner-container」でもう一段包まれるため、
   その箱をないものとして扱い、上の並び（丸と吹き出しの 2 列）がそのまま効くようにする */
.tj-chat .wp-block-group__inner-container { display: contents; }
.tj-chat :is(.tj-chatMsg, .tj-chatMsg_who, .tj-chatMsg_body) { margin-block: 0; }

/* 記事ページの本文の段落の指定（16px・行の高さ 2）が名前の丸にも効いて「編集／部」と折り返していたため、クラスを重ねて上書き */
.mk_articlePage .bl_single_body .tj-chat p.tj-chatMsg_who { font-size: 11px !important; line-height: 1.3 !important; letter-spacing: 0.04em !important; word-break: keep-all; overflow-wrap: anywhere; }
@media (max-width: 767px) {
  .mk_articlePage .bl_single_body .tj-chat p.tj-chatMsg_who { font-size: clamp(9px, 2.67vw, 11px) !important; }
}

/* ==========================================================================
   話し手の写真（2026.11.20 追加）
   ・吹き出しの最初の画像ブロック「tj-chatMsg_photo」に写真を選ぶと、丸の中が写真になり、名前は写真の下に小さく出る
   ・写真を選ばなければ、記事ページでは画像ブロックは出さず、これまでどおり丸の中に名前
   ・並びは「左の列：写真→名前／右の列：吹き出し（2 行分）」（右からの吹き出しは左右が逆）
   ========================================================================== */
.tj-chat .tj-chatMsg { row-gap: 6px; }
.tj-chat .tj-chatMsg .tj-chatMsg_photo,
.tj-chat .tj-chatMsg .tj-chatMsg_who { grid-column: 1; grid-row: 1; }
.tj-chat .tj-chatMsg .tj-chatMsg_body { grid-column: 2; grid-row: 1 / span 2; }
.tj-chat .tj-chatMsg.is-right .tj-chatMsg_photo,
.tj-chat .tj-chatMsg.is-right .tj-chatMsg_who { grid-column: 2; }
.tj-chat .tj-chatMsg.is-right .tj-chatMsg_body { grid-column: 1; grid-row: 1 / span 2; }

.tj-chat .tj-chatMsg_photo { width: var(--tj-chat-face); margin: 0 !important; }
.tj-chat .tj-chatMsg_photo img { display: block; width: 100%; height: auto; aspect-ratio: 1; object-fit: cover; border-radius: 50%; margin: 0; }
.tj-chat .tj-chatMsg_photo figcaption { display: none; }

/* 写真が選ばれていない画像ブロックは、記事ページでは出さない（編集画面では写真を選ぶ欄として出す） */
.tj-chat .tj-chatMsg_photo:not(.block-editor-block-list__block):not(:has(img[src])) { display: none; }

/* 写真があるとき：名前は丸ではなく、写真の下の小さな文字に */
.tj-chat .tj-chatMsg:has(.tj-chatMsg_photo img[src]) .tj-chatMsg_who { grid-row: 2; }
.tj-chat .tj-chatMsg:has(.tj-chatMsg_photo img[src]) p.tj-chatMsg_who,
.mk_articlePage .bl_single_body .tj-chat .tj-chatMsg:has(.tj-chatMsg_photo img[src]) p.tj-chatMsg_who {
  display: block; height: auto; padding: 0; border-radius: 0; background: none; color: #373737;
  font-size: 10px !important; line-height: 1.4 !important; letter-spacing: 0.02em !important;
}

/* 編集画面：写真がまだないときの「写真を選ぶ欄」は吹き出しの上に横長で出し、小さくまとめる */
.tj-chat .tj-chatMsg .tj-chatMsg_photo:has(.components-placeholder) { grid-column: 1 / -1; grid-row: 1; width: auto; }
.tj-chat .tj-chatMsg:has(.tj-chatMsg_photo .components-placeholder) .tj-chatMsg_who { grid-row: 2; }
.tj-chat .tj-chatMsg:has(.tj-chatMsg_photo .components-placeholder) .tj-chatMsg_body { grid-row: 2 / span 2; }
.tj-chat .tj-chatMsg_photo .components-placeholder { min-height: 0 !important; padding: 8px 12px !important; box-shadow: inset 0 0 0 1px #dcdcdc !important; }
.tj-chat .tj-chatMsg_photo .components-placeholder::before { content: "話し手の写真（任意）：入れないときは、名前が丸の中に出ます"; font-size: 11px; color: #757575; }
.tj-chat .tj-chatMsg_photo .components-placeholder__label,
.tj-chat .tj-chatMsg_photo .components-placeholder__instructions { display: none; }

/* 吹き出しの文字の大きさを、記事の本文の段落と同じにする（2026.11.26）
   本文：767px 以下は 14px、768px 以上は 16px（renewal.css の本文の段落の指定と同じ） */
.mk_articlePage .bl_single_body .tj-chat .tj-chatMsg_body p { font-size: 14px !important; }
@media (min-width: 768px) {
  .mk_articlePage .bl_single_body .tj-chat .tj-chatMsg_body p { font-size: 16px !important; }
}

/* ==========================================================================
   吹き出しの色を、左右の位置とは別に選べるようにする（2026.11.26 追加）
   ・吹き出し（tj-chatMsg）に「is-green」を足すと緑、「is-gray」を足すとグレーになる
   ・付けなければこれまでどおり（左＝グレー、右＝緑）
   ・例：編集部を左に置いたまま緑にしたいときは「tj-chatMsg is-left is-green」
   ========================================================================== */
.tj-chat .tj-chatMsg.is-green .tj-chatMsg_body { background: #eef5dc; }
.tj-chat .tj-chatMsg.is-green .tj-chatMsg_who { background: #aacf52; }
.tj-chat .tj-chatMsg.is-gray .tj-chatMsg_body { background: #f3f3f3; }
.tj-chat .tj-chatMsg.is-gray .tj-chatMsg_who { background: #373737; }
/* 写真があるときは名前の丸は出さない（写真の下の小さな文字のまま） */
.tj-chat .tj-chatMsg:is(.is-green, .is-gray):has(.tj-chatMsg_photo img[src]) .tj-chatMsg_who { background: none; }

/* --------------------------------------------------------------
   2026.12.03 話し手の写真の「位置・大きさ」（編集画面の「写真の位置と大きさ」で設定。assets/js/editor-chat-photo.js）
   値は画像ブロックの figure に --tj-photo-x / --tj-photo-y（見せたい場所 0〜100%）と --tj-photo-z（拡大率）として入る。
   値がない写真はこれまでと同じ見た目（中央・等倍）
   -------------------------------------------------------------- */
.tj-chat .tj-chatMsg_photo:has(img[src]) { border-radius: 50%; overflow: hidden; }
.tj-chat .tj-chatMsg_photo img {
  object-position: var(--tj-photo-x, 50%) var(--tj-photo-y, 50%);
  transform: scale(var(--tj-photo-z, 1));
  transform-origin: var(--tj-photo-x, 50%) var(--tj-photo-y, 50%);
}
