/* 舞台チャットを基準に、data-chat-theme だけで各ページの配色を切り替えます。 */
body[data-chat-theme] {
  --chat-surface-background: #090b1b;
  --chat-surface-border: rgba(174, 188, 255, .22);
  --chat-surface-text: var(--text);
  --chat-log-background: transparent;
}

body[data-chat-theme="chat"],
body[data-chat-theme="room"] {
  --chat-surface-background: rgba(211, 220, 216, .92);
  --chat-surface-border: rgba(88, 82, 87, .2);
  --chat-surface-text: #302d30;
  --chat-log-background: rgba(255, 255, 255, .08);
}

body[data-chat-theme="unit"] {
  --chat-surface-background: rgba(211, 220, 216, .92);
  --chat-surface-border: rgba(88, 82, 87, .2);
  --chat-surface-text: #302d30;
  --chat-log-background: rgba(255, 255, 255, .08);
}

body[data-chat-theme="stage"] {
  --chat-surface-background: #090b1b;
  --chat-surface-border: rgba(174, 188, 255, .22);
  --chat-surface-text: var(--text);
  --chat-log-background: transparent;
}

body[data-chat-theme] :is(.conversation-panel, .stage-conversation, #unit-panel-chat) {
  border-color: var(--chat-surface-border);
  background: var(--chat-surface-background);
  color: var(--chat-surface-text);
}

body[data-chat-theme] :is(.message-list, .stage-feed, .unit-message-list) {
  background: var(--chat-log-background);
}

/* 舞台を基準にしたチャット入力欄の共通配置。スマホ側の既存配置は維持します。 */
.unified-chat-composer-title,
.unified-chat-composer-actions,
.unified-chat-message-label {
  display: flex;
  align-items: center;
}

.unified-chat-composer-title { min-width: 0; gap: 12px; }
.unified-chat-composer-actions { flex: 0 0 auto; gap: 8px; }
.unified-chat-current-status { color: var(--muted); font: 700 .78rem/1.4 var(--font-sans); white-space: nowrap; }
.unified-chat-current-status strong { color: inherit; }
.unified-chat-message-label { justify-content: space-between; gap: 12px; }

@media (min-width: 769px) {
  .unified-chat-composer .unified-chat-composer-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
  }

  .unified-chat-composer .composer-primary-actions {
    display: flex;
    align-items: center;
    justify-content: flex-start;
  }

  .unified-chat-composer .composer-primary-actions .composer-decoration-toggle {
    justify-self: auto;
  }
}

/* ===== 装飾・発言設定：ユニットルームの「自分の台本」と同じ形にそろえる（通常・ルーム・ユニット・舞台チャット共通） =====
   PC：［装飾・発言設定］は幅広のボタン。開くと枠の中に「アイコン｜装飾ボタン｜発言者名｜名前横アイコン｜発言者名を隠す」を1段で並べる。
   スマホ：1段目にアイコンと装飾ボタン（7列）、2段目に発言者名と「隠す」、3段目に名前横アイコン。 */
.unified-chat-settings-layout { display: block; margin: 0 0 8px; }
.unified-chat-settings-layout > .composer-decoration-toggle {
  display: block;
  width: min(42%, 560px);
  min-height: 40px;
  margin: 0 0 8px;
  text-align: center;
  white-space: nowrap;
}
.unified-chat-settings-layout > .composer-decoration-toggle[hidden] { display: none; }
.unified-chat-settings-panel:not([hidden]) {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(150px, 220px) max-content max-content;
  align-items: center;
  gap: 6px 12px;
  margin: 0;
  padding: 6px 8px;
  border: 1px solid var(--chat-surface-border, var(--line));
  border-radius: 10px;
}
/* 装飾ボタンの段（アイコン＋装飾ボタン）。PCでは左側にまとめる */
.unified-chat-settings-panel .unified-chat-toolbar-row {
  display: flex;
  grid-column: 1;
  grid-row: 1;
  align-items: center;
  gap: 10px;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}
.unified-chat-settings-panel .unified-chat-toolbar-row > [hidden] { display: none; }
.unified-chat-settings-panel .chat-icon-control { flex: 0 0 auto; }
.unified-chat-settings-panel .current-icon-button { height: 48px; min-height: 0; }
.unified-chat-settings-panel .current-icon-button img { width: 38px; height: 38px; }
.unified-chat-settings-panel :is(.chat-toolbar, .stage-toolbar) {
  display: flex;
  flex: 1 1 auto;
  flex-wrap: wrap;
  align-content: center;
  gap: 4px;
  min-width: 0;
  min-height: 0;
  margin: 0;
}
.unified-chat-settings-panel :is(.chat-toolbar, .stage-toolbar) button {
  min-width: 29px;
  min-height: 28px;
  padding: 3px 6px;
}
/* 発言者名と「発言者名を隠す」は、それぞれ別の欄に置く */
.unified-chat-settings-panel .unified-chat-speaker-controls:not([hidden]) { display: contents; }
.unified-chat-settings-panel .speaker-name-label {
  display: grid;
  grid-column: 2;
  grid-row: 1;
  gap: 3px;
  min-width: 0;
  margin: 0;
}
.unified-chat-settings-panel .speaker-name-label input { min-height: 32px; padding-block: 5px; }
.unified-chat-settings-panel .unified-chat-name-icon-setting {
  display: flex;
  grid-column: 3;
  grid-row: 1;
  align-items: center;
  gap: 6px;
  min-width: 0;
  margin: 0;
}
.unified-chat-settings-panel .unified-chat-name-icon-setting > [hidden] { display: none; }
.unified-chat-settings-panel .unified-chat-name-icon-setting :is(.name-icon-toggle-button, .current-name-icon-button, .name-icon-disable-button) { min-height: 32px; }
.unified-chat-settings-panel .current-name-icon-button { height: 48px; }
.unified-chat-settings-panel .current-name-icon-button img { width: 38px; height: 38px; }
.unified-chat-settings-panel .speaker-hide-label {
  grid-column: 4;
  grid-row: 1;
  min-height: 28px;
  margin: 0;
  white-space: nowrap;
}

/* PCでも幅が足りないときは、装飾ボタンの段を上に、発言者名などを下の段へ */
@media (max-width: 1099px) and (min-width: 769px) {
  .unified-chat-settings-panel:not([hidden]) { grid-template-columns: minmax(150px, 260px) max-content max-content minmax(0, 1fr); }
  .unified-chat-settings-panel .unified-chat-toolbar-row { grid-column: 1 / -1; }
  .unified-chat-settings-panel .speaker-name-label { grid-column: 1; grid-row: 2; }
  .unified-chat-settings-panel .unified-chat-name-icon-setting { grid-column: 2; grid-row: 2; }
  .unified-chat-settings-panel .speaker-hide-label { grid-column: 3; grid-row: 2; }
}

@media (max-width: 768px) {
  .unified-chat-settings-layout > .composer-decoration-toggle { width: 100%; font-size: 0.72rem; }
  .unified-chat-settings-panel:not([hidden]) {
    grid-template-columns: minmax(0, 1fr) max-content;
    align-items: end;
    gap: 8px;
    padding: 8px;
  }
  .unified-chat-settings-panel .unified-chat-toolbar-row {
    display: grid;
    grid-column: 1 / -1;
    grid-row: 1;
    grid-template-columns: 52px minmax(0, 1fr);
    align-items: start;
    gap: 7px;
  }
  .unified-chat-settings-panel .unified-chat-toolbar-row > .chat-icon-control { grid-column: 1; grid-row: 1; width: 52px; min-width: 0; }
  .unified-chat-settings-panel .unified-chat-toolbar-row > :is(.chat-toolbar, .stage-toolbar) { grid-column: 2; grid-row: 1; width: auto; }
  .unified-chat-settings-panel .unified-chat-toolbar-row > .stage-align-controls { grid-column: 1 / -1; grid-row: 2; }
  .unified-chat-settings-panel .unified-chat-toolbar-row:not(:has(.chat-icon-control:not([hidden]))) { grid-template-columns: minmax(0, 1fr); }
  .unified-chat-settings-panel .unified-chat-toolbar-row:not(:has(.chat-icon-control:not([hidden]))) > :is(.chat-toolbar, .stage-toolbar) { grid-column: 1; }
  .unified-chat-settings-panel .current-icon-button {
    width: 52px;
    height: 52px;
    min-width: 0;
    padding: 5px;
    overflow: hidden;
  }
  .unified-chat-settings-panel .current-icon-button img { width: 40px; height: 40px; }
  .unified-chat-settings-panel .current-icon-button span { display: none; }
  .unified-chat-settings-panel :is(.chat-toolbar, .stage-toolbar) {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 4px;
  }
  .unified-chat-settings-panel :is(.chat-toolbar, .stage-toolbar) button {
    min-width: 0;
    min-height: 24px;
    padding: 2px 3px;
    font-size: 0.72rem;
  }
  .unified-chat-settings-panel .speaker-name-label { grid-column: 1; grid-row: 2; }
  .unified-chat-settings-panel .speaker-hide-label { grid-column: 2; grid-row: 2; padding-bottom: 9px; }
  .unified-chat-settings-panel .unified-chat-name-icon-setting { grid-column: 1 / -1; grid-row: 3; flex-wrap: wrap; }
  .unified-chat-settings-panel .name-icon-toggle-button { min-height: 34px; padding: 6px 9px; }
}

@media (max-width: 768px) {
  .unified-chat-current-status { display: none; }
  .unified-chat-composer-actions { margin-left: auto; }
  .unified-chat-composer-actions .button { min-width: 0; padding-inline: 10px; }
}

/* スクショモード中は「スクショモードを解除」ボタンを、メニューボタンのすぐ左（右端寄り）へ置く（チャット・ルーム・ユニット・舞台共通） */
body[data-chat-theme] .header-actions > .mode-camera-button[aria-pressed="true"] { order: 99; }
body[data-chat-theme] .header-actions > .menu-toggle-button { order: 100; }

/* 発言の「返信・編集・削除・発言へ」ボタンを大きく・太字にして見やすくする（チャット・ルーム・ユニット・舞台・ログ一覧共通） */
body[data-chat-theme] .message-actions { gap: 6px; align-items: center; }
body[data-chat-theme] .message-actions button {
  min-height: 30px;
  padding: 4px 13px;
  border-color: rgba(58, 55, 58, 0.45);
  color: #3a363a;
  font: 700 0.95rem/1.2 var(--font-sans, "Noto Sans JP", sans-serif);
  white-space: nowrap;
}
body[data-chat-theme] .message-actions button:hover { color: #fff; background: #585257; border-color: #585257; }
/* チャット・ルーム・秘話・ユニットの発言では、返信・編集・削除を発言の右下に置く。
   どの発言にも下にボタン1段分の幅を空けておき（ボタンが無い発言・システムログも同じ幅）、ボタンはその幅の右端に置く */
body[data-chat-theme] { --chat-actions-space: 36px; }
body[data-chat-theme]:not([data-chat-theme="stage"]) .chat-message:not(.follow-log-message):not([data-message-id="preview"]):not([data-unit-message-id="preview"]) { position: relative; padding-bottom: calc(5px + var(--chat-actions-space)); }
/* システムログ（アイテム使用ログ）は、灰色の枠は小さいまま、その外側（背景の部分）に同じ幅を空ける。
   左の線と文字のあいだは1文字分あける */
body[data-chat-theme]:not([data-chat-theme="stage"]) .chat-message.item-use-note:not(.follow-log-message):not([data-message-id="preview"]):not([data-unit-message-id="preview"]) { padding-bottom: 5px; padding-left: 1em; margin-bottom: var(--chat-actions-space); }
body[data-chat-theme] .message-actions-end { position: absolute; right: 0; bottom: 5px; display: inline-flex; margin: 0; white-space: nowrap; user-select: none; -webkit-user-select: none; }
/* 舞台は暗い背景なので明るい文字で */
body[data-chat-theme="stage"] .message-actions button { border-color: rgba(214, 220, 255, 0.5); color: #eef0ff; }
body[data-chat-theme="stage"] .message-actions button:hover { color: #090b1b; background: #eef0ff; border-color: #eef0ff; }
@media (max-width: 640px) {
  /* スマホでは返信・削除などのボタンを小さめに */
  body[data-chat-theme] .message-actions { gap: 4px; }
  body[data-chat-theme] .message-actions button { min-height: 24px; padding: 2px 8px; border-radius: 5px; font-size: 0.74rem; }
  body[data-chat-theme] { --chat-actions-space: 30px; }
}

/* 「この場所の通知を受け取る／通知を切る」ボタン（ベルアイコンは文字の左） */
.room-watch-button { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.room-watch-button[hidden] { display: none; }
.room-watch-icon { flex: 0 0 auto; width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.room-watch-button .room-watch-icon-off,
.room-watch-button.is-watching .room-watch-icon-plus { display: none; }
.room-watch-button.is-watching .room-watch-icon-off { display: block; }
.room-watch-button:disabled { opacity: 0.6; cursor: progress; }
.room-watch-toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 200;
  max-width: min(92vw, 520px);
  padding: 10px 16px;
  border-radius: 10px;
  color: #fff;
  background: rgba(48, 45, 48, 0.94);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  font: 700 0.84rem/1.6 var(--font-sans, "Noto Sans JP", sans-serif);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px);
  transition: opacity .2s, transform .2s;
}
.room-watch-toast.is-error { background: rgba(122, 52, 64, 0.95); }
.room-watch-toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
body.chat-screenshot-mode .room-watch-button,
.unit-screenshot-mode .room-watch-button { display: none !important; }
/* スマホで場所が足りないときはアイコンだけ */
@media (max-width: 640px) {
  .room-watch-button { gap: 0; padding-inline: 9px; }
  .room-watch-button .room-watch-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .room-watch-icon { width: 18px; height: 18px; }
}

/* 発言停止中：入力欄は残し、発言ボタンだけ背景になじむ灰色にして押せないことが分かるようにする
   （明るいテーマ・暗いテーマのどちらでも、その場の文字色から灰色を作ります） */
.button.is-posting-closed,
.button.is-posting-closed:disabled,
.button.is-posting-closed:hover {
  color: rgba(128, 132, 145, .95);
  color: color-mix(in srgb, var(--chat-surface-text, #8a8f9c) 50%, transparent);
  background: rgba(128, 132, 145, .18);
  background: color-mix(in srgb, var(--chat-surface-text, #8a8f9c) 12%, transparent);
  border: 1px dashed rgba(128, 132, 145, .6);
  border: 1px dashed color-mix(in srgb, var(--chat-surface-text, #8a8f9c) 38%, transparent);
  box-shadow: none;
  filter: none;
  opacity: 1;
  transform: none;
  cursor: not-allowed;
}

/* アイテムの使用ログ：アイコン・名前なし、ENo・発言No・時間だけのお知らせ風 */
.chat-message.item-use-note { border-left: 3px double currentColor; background: rgba(128, 132, 145, .08); }
.chat-message.item-use-note .message-meta { opacity: .8; }
.chat-message.item-use-note .item-use-note-body { font-style: italic; letter-spacing: .02em; }
.chat-message.item-use-note .item-use-note-body::before { content: "✦ "; font-style: normal; }

/* 発言の間隔（チャット・ルーム・秘話・ユニット・舞台・ログ一覧共通）
   セリフと地の文の間・発言同士の間を、名前の下の余白（9px）と同じくらいにする */
body[data-chat-theme] .chat-message { padding-top: 5px; padding-bottom: 5px; }
/* 舞台の「まとめて同時に出すセリフ」の枠は、枠の内側の余白をそのまま保つ */
body[data-chat-theme] .stage-dialogue-group .stage-message { padding: 14px; }
/* セリフ枠のすぐ後ろの改行は空行にしない（</serif> の後の改行で1行分あいていたため） */
body[data-chat-theme] .message-body .decor-dialogue-block + br { display: none; }
/* セリフ枠の下も、上（地の文との間）と同じくらいあける */
body[data-chat-theme] .message-body .decor-dialogue-block { margin-bottom: 7px; }

/* 文字数が上限を超えたときは、数を赤く表示する（装飾タグと画像・アイコンのURLは数えない） */
#message-character-count.is-over-limit,
#unit-message-character-count.is-over-limit,
#stage-character-count.is-over-limit { color: #ff7a8a; font-weight: 700; }

/* 舞台も、発言の下にボタン1段分の幅を空け、削除ボタンはその右下に置く（チャットと同じ）。
   システムの行（開演・演出のお知らせなど）にも同じ幅。入力プレビューと「まとめて同時に出すセリフ」の枠の中は除く */
body[data-chat-theme="stage"] .stage-message:not([data-message-id=""]) { position: relative; padding-bottom: calc(5px + var(--chat-actions-space)); }
body[data-chat-theme="stage"] .stage-dialogue-group .stage-message { padding: 14px; }
body[data-chat-theme="stage"] .stage-dialogue-group .message-actions-end { display: none; }
