* {
  box-sizing: border-box;
}

/* hidden 属性は必ず効かせる。class側で display を指定すると、
ブラウザ既定の [hidden] より後から当たって打ち消してしまう。 */
[hidden] {
  display: none !important;
}

:root {
  --bg: #f0e0d6;
  --panel: #f6eadf;
  --panel2: #f3e3d7;
  --accent: #e5a27d;
  --border: #cfa88e;
  --text: #800000;
  --text2: #5f2f1f;
  --blue: #3a78d4;
  --blue2: #1d57b3;
  --offline-image: none;

  /* ダーク対応済みの宣言。Androidの強制色反転を防ぐ */
  color-scheme: light;

  /* ここからテーマ切り替え用に追加した変数(ライト=ふたば風) */
  --header-bg: #e9dbcf;
  --card-strong: #ead9cd;
  --content-bg: #fffdfa;
  --btn-bg: #ffffff;
  --btn-hover: #faf3ed;
  --input-bg: #ffffff;
  --input-text: #333333;
  --muted-border: #888888;
  --tab-bg: #eeeeee;
  --tab-text: #555555;
  --tab-active-bg: #ffffff;
  --tab-active-text: #222222;
  --tab-active-line: #c0392b;
  --meta: #666666;
  --name-color: #117743;
  --help-text: #7a5b48;
  --offline-box-bg: rgba(255, 245, 235, 0.84);
  /* システム通知の種別色。枠線だけでなく地の色も変えて、
  ぱっと見で種類が分かるようにする。 */
  --notice-system: #8a7060;
  --notice-system-bg: #f3e7dc;
  --notice-image: #2f7ec2;
  --notice-image-bg: #e2eefa;
  --notice-video: #9a4fc0;
  --notice-video-bg: #f1e5f8;
  --notice-sound: #1f8f5b;
  --notice-sound-bg: #e0f3e9;
  --notice-poll: #bb8620;
  --notice-poll-bg: #faeed6;
}

/* ダークテーマ(Discord風)。htmlタグに dark クラスが付くと有効 */
html.dark {
  color-scheme: dark;
  --bg: #1e1f22;
  --panel: #2b2d31;
  --panel2: #313338;
  --accent: #404249;
  --border: #3f4147;
  --text: #f2f3f5;
  --text2: #dbdee1;
  --blue: #5865f2;
  --blue2: #4752c4;
  --header-bg: #111214;
  --card-strong: #2b2d31;
  --content-bg: #313338;
  --btn-bg: #383a40;
  --btn-hover: #43454c;
  --input-bg: #1e1f22;
  --input-text: #dbdee1;
  --muted-border: #3f4147;
  --tab-bg: #2b2d31;
  --tab-text: #949ba4;
  --tab-active-bg: #383a40;
  --tab-active-text: #f2f3f5;
  --tab-active-line: #5865f2;
  --meta: #949ba4;
  --name-color: #23a559;
  --help-text: #949ba4;
  --offline-box-bg: rgba(30, 31, 34, 0.86);
  /* 暗い地の上では中間色が沈むので、枠線は明るく、地の色ははっきり分ける。 */
  --notice-system: #b5bdc9;
  --notice-system-bg: #3a3d44;
  --notice-image: #6cb6f5;
  --notice-image-bg: #1d3348;
  --notice-video: #cf95f5;
  --notice-video-bg: #33254a;
  --notice-sound: #57dc9b;
  --notice-sound-bg: #17372a;
  --notice-poll: #f5c95a;
  --notice-poll-bg: #3d331a;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text2);
  font-family: "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  font-size: 14px;
}

header {
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 14px;
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.site-title {
  font-weight: 900;
  color: var(--text);
  font-size: 18px;
}

#liveBadge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 900;
  border: 1px solid var(--muted-border);
  background: var(--tab-bg);
  color: var(--tab-text);
}

#liveBadge::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--tab-text);
}

#liveBadge.live {
  background: #a51616;
  border-color: #7d0000;
  color: #fff;
}

#liveBadge.live::before {
  background: #fff;
  box-shadow: 0 0 8px #fff;
}

#statusText {
  font-size: 13px;
  white-space: nowrap;
}

.layout {
  padding: 10px;
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 10px;
  min-height: calc(100vh - 52px);
}

.left-column {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.right-column {
  min-width: 0;
}

.player-card,
.info-card,
.side-card {
  background: var(--panel);
  border: 1px solid var(--border);
}

.player-card {
  padding: 8px;
}

.player-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: nowrap;
  min-width: 0;
}

.toolbar-left,
.toolbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.toolbar-left {
  overflow: hidden;
}

#toolbarTitle {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toolbar-right {
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: thin;
}

.toolbar-right > * {
  flex: 0 0 auto;
}

button {
  font: inherit;
}

/* そうだね */
.soudane-wrap {
  margin-left: 6px;
  white-space: nowrap;
}

.soudane-count {
  color: var(--name-color);
  font-weight: 700;
  margin-right: 4px;
}

.soudane-btn {
  border: 1px solid var(--muted-border);
  background: var(--btn-bg);
  color: var(--tab-text);
  cursor: pointer;
  font-size: 11px;
  line-height: 1;
  padding: 2px 6px;
  vertical-align: middle;
}

.soudane-btn:hover {
  background: var(--btn-hover);
}

.soudane-btn.done {
  opacity: 0.4;
  cursor: default;
}


/* DOODLE_PATCH: 落書き用のキャンバスと道具箱 */
#doodleCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 5;
}

body.doodle-on #doodleCanvas {
  pointer-events: auto;
  cursor: crosshair;
  touch-action: none;
}

/* 撮影専用の映像。画面には出さず、スクショの材料としてだけ使う */
#captureVideo {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.doodle-tools {
  display: none;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

body.doodle-on .doodle-tools {
  display: flex;
}

.doodle-color {
  width: 22px;
  height: 22px;
  border: 2px solid var(--border);
  border-radius: 50%;
  cursor: pointer;
  padding: 0;
}

.doodle-color.is-active {
  border-color: var(--text);
  transform: scale(1.15);
}

button:disabled {
  opacity: 0.55;
  cursor: default;
}

.mode-btn,
.mode-select,
.tab-btn,
.reaction-btn,
.upload-btn {
  border: 1px solid var(--border);
  background: var(--btn-bg);
  color: var(--text2);
  padding: 7px 10px;
  cursor: pointer;
  font-weight: 700;
}

.mode-btn:hover,
.mode-select:hover,
.tab-btn:hover,
.reaction-btn:hover,
.upload-btn:hover {
  background: var(--btn-hover);
}

/* selectはフォントを継承せず、内部の行高も固定なので、
他のボタンと同じ高さになるよう指定し直す。 */
.mode-select {
  font-family: inherit;
  font-size: inherit;
  padding: 6px 10px;
}

/* 選択できない画質はグレー表示のまま一覧へ残す。 */
.mode-select option:disabled {
  color: var(--meta);
}

.mode-btn.active,
.tab-btn.active {
  background: var(--blue);
  border-color: var(--blue2);
  color: #fff;
}

.icon-btn {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  padding: 5px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: var(--text2);
  cursor: pointer;
}

.icon-btn:hover,
.icon-btn:focus-visible {
  border-color: var(--border);
  background: var(--btn-hover);
  outline: none;
}

.icon-btn.active {
  background: var(--blue);
  color: #fff;
}

.icon-btn svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

.window-only-chat-popup {
  display: none;
}

.player-wrap {
  position: relative;
  background: #000;
  border: 1px solid var(--border);
  overflow: hidden;
  min-height: 420px;
}

#streamVideo {
  width: 100%;
  height: min(70vh, 720px);
  min-height: 420px;
  display: block;
  background: #000;
  object-fit: contain;
}

#offlineOverlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  background: linear-gradient(135deg, #26140f 0%, #51291e 48%, #1c1110 100%);
  color: #fff;
  text-align: center;
  padding: 20px;
}

#offlineOverlay.show {
  display: flex;
}

.offline-box {
  background: var(--offline-box-bg);
  color: var(--text2);
  border: 1px solid var(--border);
  padding: 18px 24px;
  max-width: min(92%, 560px);
}

.offline-title {
  font-size: 28px;
  font-weight: 900;
  letter-spacing: 0.08em;
  color: var(--text);
  margin-bottom: 8px;
}

.offline-sub {
  font-size: 14px;
  line-height: 1.6;
}

.info-card {
  display: grid;
  grid-template-columns: 180px 1fr;
  overflow: hidden;
}

.thumb-wrap {
  background: var(--card-strong);
  border-right: 1px solid var(--border);
  padding: 8px;
}

.thumb-wrap img {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  display: block;
  border: 1px solid var(--border);
  background: var(--btn-bg);
}

.info-row,
.form-row,
.card-head {
  display: grid;
  grid-template-columns: 92px 1fr;
  border-bottom: 1px solid var(--border);
}

.info-row:last-child,
.form-row:last-child {
  border-bottom: none;
}

.info-label,
.form-label,
.card-head-label {
  background: var(--accent);
  color: var(--text);
  font-weight: 800;
  padding: 10px;
  border-right: 1px solid var(--border);
  display: flex;
  align-items: center;
  /* ラベルの文字は左、色の選択は右の空きへ寄せる。 */
  justify-content: space-between;
  gap: 6px;
}

.info-main,
.form-field,
.card-head-main {
  background: var(--panel2);
  padding: 10px;
  line-height: 1.55;
  min-width: 0;
  word-break: break-word;
}

.chat-head-main {
  min-height: 43px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 5px 7px 5px 10px;
}

.chat-head-hint {
  min-width: 0;
  overflow: hidden;
  color: var(--meta);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-head-actions {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.chat-restore-rail {
  position: fixed;
  top: 50%;
  right: 0;
  z-index: 9000;
  width: 34px;
  height: 46px;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 4px;
  border: 1px solid var(--border);
  border-right: 0;
  border-radius: 5px 0 0 5px;
  background: var(--panel);
  color: var(--text2);
  cursor: pointer;
  transform: translateY(-50%);
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.chat-restore-rail svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

body.hide-chat .chat-restore-rail {
  display: inline-flex;
}

/* チャット欄が元々無い画面(別窓・管理の確認枠・中継)には復帰の縁も出さない。
hide-chatが何かの拍子に付いても、押せないボタンが映像に浮かないように
(監査 2026-08-27)。 */
body.popout .chat-restore-rail,
body.video-preview .chat-restore-rail,
body.is-mirror .chat-restore-rail {
  display: none !important;
}

#streamTitle {
  font-weight: 900;
  color: var(--text);
}

#streamDescription {
  white-space: pre-wrap;
}

/* 概要欄の線と折り畳み(<hr> / --- と <折りたたみ>)。 */
#streamDescription .description-rule {
  border: 0;
  border-top: 1px solid currentColor;
  opacity: 0.55;
  margin: 8px 0;
}

#streamDescription .description-fold {
  margin: 4px 0;
}

#streamDescription .description-fold > summary {
  cursor: pointer;
  font-weight: 700;
  white-space: normal;
}

#streamDescription .description-fold-body {
  padding: 2px 0 2px 14px;
  border-left: 2px solid var(--border);
  margin-top: 2px;
}

/* 長い概要欄は途中まで。下を薄くして、続きがあると分かるようにする。 */
#streamDescription.is-collapsed {
  max-height: 11em;
  overflow: hidden;
  -webkit-mask-image: linear-gradient(to bottom, #000 70%, transparent);
  mask-image: linear-gradient(to bottom, #000 70%, transparent);
}

.description-more {
  margin-top: 4px;
  border: 1px solid var(--muted-border);
  border-radius: 3px;
  background: var(--btn-bg);
  color: var(--text2);
  padding: 2px 10px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.description-more[hidden] { display: none; }
.description-more:hover { background: var(--btn-hover); }

.playback-recovery-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--border);
  border-top: 0;
  background: var(--panel);
  color: var(--text);
  font-size: 13px;
}

.playback-recovery-actions[hidden] {
  display: none;
}

.mobile-chat-dock,
.mobile-sheet-controls,
.overview-toggle {
  display: none;
}

.latest-comment-bar {
  width: 100%;
  min-width: 0;
  grid-template-columns: auto auto minmax(0, 1fr);
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  padding: 8px 10px;
  text-align: left;
}

.latest-kind {
  border-left: 3px solid var(--muted-border);
  padding-left: 6px;
  color: var(--meta);
  font-size: 11px;
  font-weight: 800;
}

.latest-comment-bar[data-kind="system"] .latest-kind {
  border-left-color: #78899f;
}

.latest-comment-bar[data-kind="reaction"] .latest-kind {
  border-left-color: #bf7b31;
}

.latest-comment-bar[data-kind="poll"] .latest-kind {
  border-left-color: #6879cf;
}

.latest-name {
  color: var(--name-color);
  font-weight: 800;
  white-space: nowrap;
}

.latest-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 利用者が選んだ色。#RRGGBBは検証済みの値だけが--user-colorへ入る。
.name/.comment-body/.latest-name/.latest-textが後方で色を指定するため、
クラスを二重に書いて詳細度を上げる。付く場所に依存させない。 */
.name-color-custom.name-color-custom,
.text-color-custom.text-color-custom {
  color: var(--user-color, inherit);
  /* 背景に近い色でも読めるよう縁取りを付ける。 */
  text-shadow:
  0 0 2px var(--content-bg),
  0 1px 2px rgba(0, 0, 0, 0.55);
}

/* 金色。単色の黄ではなく暗い金と明るい金のグラデーション。 */
.name-color-gold.name-color-gold,
.text-color-gold.text-color-gold {
  /* 明るい帯を細く重ねて金属らしい照り返しを作る。1本の坂だと地味になる。 */
  background-image: linear-gradient(
  100deg,
  #7a4a00 0%,
  #d9a406 14%,
  #ffe680 28%,
  #fffbe8 37%,
  #ffe680 41%,
  #e8b219 46%,
  #a06a00 58%,
  #ffdf6b 72%,
  #fff7d0 82%,
  #c98f0a 92%,
  #6b3f00 100%
  );
  background-size: 220% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
  /* 照りは流さず、一番明るい帯が文字に乗る位置で止める。流す演出は
  表示中ずっとチャット欄の描き直しを強いて、映像の再生を圧迫した
  (「チャットを隠すとぐるぐるが直る」という視聴者報告の原因)。 */
  background-position: 30% 50%;
  /* 明るい画面では濃い縁、暗い画面では明るい縁で、地から浮かせる。 */
  filter:
  drop-shadow(0 0 1px rgba(60, 32, 0, 0.9))
  drop-shadow(0 1px 1px rgba(0, 0, 0, 0.55))
  drop-shadow(0 0 5px rgba(255, 206, 84, 0.55));
  font-weight: 800;
}

html.dark .name-color-gold.name-color-gold,
html.dark .text-color-gold.text-color-gold {
  filter:
  drop-shadow(0 0 1px rgba(0, 0, 0, 0.85))
  drop-shadow(0 0 6px rgba(255, 214, 102, 0.75))
  drop-shadow(0 0 12px rgba(255, 184, 0, 0.4));
}

/* 虹色。横方向のグラデーションを静止で載せる。点滅はさせない。 */
.name-color-rainbow.name-color-rainbow,
.text-color-rainbow.text-color-rainbow {
  /* 薄い色を並べると白っぽく溶ける。濃い色を細かく刻んで色を立たせる。 */
  background-image: linear-gradient(
  92deg,
  #ff2d55 0%, #ff6a00 12%, #ffd200 24%, #7bff3d 36%, #00e5c0 48%,
  #12b8ff 60%, #6a5cff 72%, #d94dff 84%, #ff2d55 100%
  );
  background-size: 240% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
  /* 帯の起点で止めると全色が文字幅に収まる。金色と同じ理由で流さない。 */
  background-position: 0% 50%;
  /* 金色と同じだけ地から浮かせる。輪郭と、色のにじみを重ねる。 */
  filter:
  drop-shadow(0 0 1px rgba(20, 8, 40, 0.9))
  drop-shadow(0 1px 1px rgba(0, 0, 0, 0.55))
  drop-shadow(0 0 5px rgba(120, 90, 255, 0.5));
  font-weight: 800;
}

html.dark .name-color-rainbow.name-color-rainbow,
html.dark .text-color-rainbow.text-color-rainbow {
  filter:
  drop-shadow(0 0 1px rgba(0, 0, 0, 0.85))
  drop-shadow(0 0 6px rgba(160, 130, 255, 0.75))
  drop-shadow(0 0 12px rgba(0, 200, 255, 0.4));
}

/* 接続人数が上限に達している時だけ出す案内。 */
/* 満員案内とレイド案内は同じ形の帯。色だけ変える。 */
.viewer-full-notice,
.mirror-source-notice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-left: 3px solid #b4483c;
  border-radius: 4px;
  background: var(--card-strong);
}

.viewer-full-text,
.raid-banner-text {
  font-weight: 700;
  color: var(--text2);
}

.viewer-full-actions,
.raid-banner-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.viewer-full-actions button,
.viewer-full-actions .button-link,
.raid-banner-actions button,
.raid-banner-actions .button-link {
  border: 1px solid var(--border);
  background: var(--btn-bg);
  color: var(--text2);
  border-radius: 3px;
  padding: 5px 10px;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

.viewer-full-actions button:hover,
.viewer-full-actions .button-link:hover,
.raid-banner-actions button:hover,
.raid-banner-actions .button-link:hover { background: var(--btn-hover); }

/* レイドの案内はアンケートと同じ場所に同じ枠で出す。 */
.raid-banner {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  border: 1px solid var(--border);
  border-left: 3px solid #3c78b4;
  border-radius: 4px;
  background: var(--card-strong);
  padding: 8px 10px;
  margin-bottom: 6px;
}
.mirror-source-notice { border-left-color: #6a8f3c; font-weight: 700; color: var(--text2); }

/* 中継のときは参加の場所ごと畳むので、映像だけの1列にする。 */
body.is-mirror .layout { grid-template-columns: 1fr; }
body.is-mirror .mobile-chat-dock,
body.is-mirror .right-column { display: none; }
.mirror-source-notice .button-link {
  margin-left: 8px;
  border: 1px solid var(--border);
  background: var(--btn-bg);
  color: var(--text2);
  border-radius: 3px;
  padding: 3px 8px;
  text-decoration: none;
  font-weight: 700;
}
.mirror-source-notice .button-link:hover { background: var(--btn-hover); }

/* アンケートとピン止めを通常フローで縦に並べる。子が無ければ高さも残らない。 */
.chat-top-area {
  flex: none;
  display: grid;
  gap: 6px;
  max-height: 55%;
  min-height: 0;
  overflow-y: auto;
}

/* コメント欄上部の固定カード。スマホでも場所を取りすぎないようにする。 */
.poll-card {
  flex: none;
  border: 1px solid var(--border);
  border-left: 3px solid #d4a03a;
  border-radius: 4px;
  background: var(--card-strong);
  padding: 8px 10px;
}

.pinned-comment-card {
  border: 1px solid var(--border);
  border-left: 3px solid var(--blue);
  border-radius: 4px;
  background: var(--card-strong);
  padding: 7px 10px;
}

.pinned-comment-head,
.pinned-comment-actions,
.pinned-comment-line {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.pinned-comment-badge {
  flex: none;
  border: 1px solid var(--muted-border);
  border-radius: 999px;
  background: var(--content-bg);
  padding: 0 8px;
  font-size: 11px;
  font-weight: 800;
}

.pinned-comment-time { color: var(--meta); font-size: 12px; }
.pinned-comment-actions { margin-left: auto; }
.pinned-comment-actions button {
  border: 1px solid var(--muted-border);
  border-radius: 3px;
  background: var(--btn-bg);
  color: var(--text2);
  padding: 2px 6px;
  cursor: pointer;
}
.pinned-comment-line { margin-top: 4px; }
.pinned-comment-line .name { flex: none; }
.pinned-comment-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pinned-comment-card.is-expanded .pinned-comment-text {
  max-height: min(40vh, 12em);
  overflow: hidden auto;
  white-space: normal;
  word-break: normal;
  overflow-wrap: anywhere;
}

.poll-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.poll-head-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}

.poll-head-btn {
  width: 22px;
  height: 22px;
  padding: 0;
  line-height: 1;
  border: 1px solid var(--muted-border);
  border-radius: 3px;
  background: var(--btn-bg);
  color: var(--text2);
  font-weight: 700;
  cursor: pointer;
}

.poll-head-btn:hover { background: var(--btn-hover); }

/* 畳んでいる間は見出しだけ残す。 */
.poll-card.is-collapsed .poll-question,
.poll-card.is-collapsed .poll-choices,
.poll-card.is-collapsed .poll-status {
  display: none;
}

.poll-badge {
  font-size: 11px;
  font-weight: 800;
  color: var(--text2);
  border: 1px solid var(--muted-border);
  border-radius: 999px;
  padding: 0 8px;
  background: var(--content-bg);
}

.poll-remaining {
  font-size: 12px;
  color: var(--meta);
}

.poll-question {
  font-weight: 700;
  color: var(--text2);
  word-break: break-word;
  margin-bottom: 6px;
}

.poll-choices {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.poll-choice {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  min-height: 32px;
  padding: 5px 8px;
  border: 1px solid var(--muted-border);
  border-radius: 3px;
  background: var(--btn-bg);
  color: var(--text2);
  font-weight: 700;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  /* 選択肢が長い時は折り返す。 */
  white-space: normal;
  word-break: break-word;
}

.poll-choice:hover:not(:disabled) { background: var(--btn-hover); }
.poll-choice:disabled { cursor: default; }

/* 投票後の棒グラフ。背景の帯だけが伸びる。 */
.poll-bar {
  position: absolute;
  inset: 0 auto 0 0;
  background: var(--blue);
  opacity: 0.25;
  pointer-events: none;
}

.poll-choice.is-winner .poll-bar { background: #d4a03a; opacity: 0.38; }

.poll-choice-text,
.poll-choice-value {
  position: relative;
}

.poll-choice-value {
  flex: none;
  font-size: 12px;
  color: var(--meta);
}

.poll-status {
  margin-top: 5px;
  font-size: 12px;
  color: var(--meta);
}

/* 落書きを表示中のトグル。押されていることが分かるようにする。 */
.icon-btn.is-active {
  background: var(--blue);
  border-color: var(--blue2);
  color: #fff;
}

/* 管理者が禁止した種別のタブ。押せないが位置は残す。 */
.reaction-tab.is-banned {
  color: var(--meta);
  background: var(--tab-bg);
  cursor: not-allowed;
  opacity: 0.6;
}

.reaction-tab.is-banned:hover {
  background: var(--tab-bg);
}

/* リアクションを出す位置。9区画＋ランダム。 */
.reaction-zone {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.reaction-zone-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text2);
}

.reaction-zone-grid {
  display: grid;
  grid-template-columns: repeat(3, 18px);
  grid-template-rows: repeat(3, 18px);
  gap: 2px;
}

.reaction-zone-grid button {
  border: 1px solid var(--muted-border);
  background: var(--btn-bg);
  border-radius: 2px;
  padding: 0;
  cursor: pointer;
}

.reaction-zone-grid button:hover { background: var(--btn-hover); }

.reaction-zone-grid button.is-active,
.reaction-zone-random.is-active {
  background: var(--blue);
  border-color: var(--blue2);
}

.reaction-zone-random {
  border: 1px solid var(--muted-border);
  background: var(--btn-bg);
  color: var(--text2);
  border-radius: 3px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.reaction-zone-random.is-active { color: #fff; }
.reaction-zone-random:hover { background: var(--btn-hover); }

/* 入力欄の右の空きスペースに置く色選択ボタン。 */
.color-control {
  position: relative;
  flex: none;
}

.color-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--border);
  background: var(--btn-bg);
  border-radius: 4px;
  cursor: pointer;
}

.color-btn:hover { background: var(--btn-hover); }

.color-swatch {
  width: 16px;
  height: 16px;
  border: 1px solid var(--muted-border);
  border-radius: 3px;
  background: var(--name-color);
}

.color-swatch-gold {
  background: linear-gradient(180deg, #fff3b0 0%, #e0a406 45%, #8a5a00 100%);
}

.color-swatch-rainbow {
  background: linear-gradient(90deg, #ff5f6d, #ffc371, #f7ff6b, #5fff8f, #5fd0ff, #9a7bff);
}

/* 検証済みの#RRGGBBだけが--user-colorへ入る。 */
.color-swatch-custom { background: var(--user-color, var(--name-color)); }

.color-panel {
  /* コメント欄側に overflow があるので、画面を基準に置く。
  位置は開くときにJavaScriptが入れる。 */
  position: fixed;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--content-bg);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.28);
  white-space: nowrap;
}

.color-panel button {
  border: 1px solid var(--muted-border);
  background: var(--btn-bg);
  color: var(--text2);
  padding: 4px 10px;
  border-radius: 3px;
  cursor: pointer;
  font-weight: 700;
  text-align: left;
}

.color-panel button:hover { background: var(--btn-hover); }

/* 色の見本は正方形のボタンを並べる。金色と虹色だけ塗り方が違う。 */
.color-choices {
  display: grid;
  grid-template-columns: repeat(3, 22px);
  gap: 4px;
}

.color-choices .color-choice {
  width: 22px;
  height: 22px;
  padding: 0;
  border: 1px solid var(--muted-border);
  border-radius: 3px;
  background: var(--choice-color, transparent);
  cursor: pointer;
}

.color-choices .color-choice-default {
  background: repeating-linear-gradient(45deg, var(--btn-bg), var(--btn-bg) 4px, var(--muted-border) 4px, var(--muted-border) 8px);
}

.color-choices .color-choice:hover {
  outline: 2px solid var(--accent);
}

/* 金色と虹色は単色では表せない。コメントの見本と落書きのボタンで同じ塗りを使う。 */
.color-choices .color-choice-gold,
.doodle-color-gold {
  background: linear-gradient(135deg, #f7e08a, #d4af37 45%, #f7e08a);
}

.color-choices .color-choice-rainbow,
.doodle-color-rainbow {
  background: linear-gradient(90deg, #e74c3c, #f1c40f, #2ecc71, #3498db, #9b59b6);
}

.color-hex {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: 12px;
  color: var(--text2);
}

/* SYSTEM・リアクション・アンケートのシステム通知行。
通常コメントと背景を変え、左端に種別色ラインを引き、少し小さくする。 */
.msg-system,
.msg-reaction,
.msg-poll {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-size: 12.5px;
  background: var(--notice-system-bg);
  border-left: 4px solid var(--notice-system);
  border-radius: 3px;
  padding: 3px 6px;
}

.msg-reaction[data-asset-type="image"] {
  border-left-color: var(--notice-image);
  background: var(--notice-image-bg);
}

.msg-reaction[data-asset-type="video"] {
  border-left-color: var(--notice-video);
  background: var(--notice-video-bg);
}

.msg-reaction[data-asset-type="sound"] {
  border-left-color: var(--notice-sound);
  background: var(--notice-sound-bg);
}

.msg-poll {
  border-left-color: var(--notice-poll);
  background: var(--notice-poll-bg);
}

.notice-badge {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 0 6px;
  border: 1px solid var(--muted-border);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text2);
  background: var(--content-bg);
}

.notice-icon {
  font-size: 11px;
  line-height: 1;
}

.notice-text {
  color: var(--text2);
  word-break: break-word;
}

.side-card {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 72px);
  min-height: 520px;
  overflow: hidden;
}

.side-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border-bottom: 1px solid var(--border);
  background: var(--card-strong);
  padding: 8px;
  gap: 6px;
}

.side-content {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: var(--content-bg);
}

.side-pane {
  display: none;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.side-pane.active {
  display: flex;
  flex-direction: column;
}

#messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  background: var(--content-bg);
  padding: 10px;
  border-bottom: 1px solid var(--border);
}

.msg {
  line-height: 1.5;
  word-break: break-word;
  margin-bottom: 6px;
}

.msg.is-pin-target {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
  background: rgba(58, 120, 212, .12);
}

.meta {
  color: var(--meta);
  font-size: 12px;
  margin-right: 6px;
}

.name {
  color: var(--name-color);
  font-weight: 800;
  margin-right: 6px;
}

.capture-status,
.offline-image-status {
  font-size: 11px;
  opacity: 0.9;
}

.comment-delete-btn {
  margin-left: 6px;
  padding: 1px 5px;
  border: 1px solid var(--muted-border);
  background: transparent;
  color: var(--meta);
  cursor: pointer;
  font-size: 11px;
}

.comment-report-btn {
  margin-left: 4px;
  padding: 1px 5px;
  border: 1px solid var(--muted-border);
  background: transparent;
  color: var(--meta);
  cursor: pointer;
  font-size: 11px;
}

.chat-form-wrap {
  background: var(--panel);
  flex: 0 0 auto;
}

.form-field {
  display: flex;
  align-items: center;
  gap: 8px;
}

input {
  font: inherit;
}

textarea {
  font: inherit;
  resize: none;
  min-height: 2.6em;
  max-height: 8.2em;
  overflow-y: auto;
  line-height: 1.4;
}

#name,
#text,
.upload-input {
  width: 100%;
  border: 1px solid var(--muted-border);
  background: var(--input-bg);
  color: var(--input-text);
  padding: 8px 10px;
  outline: none;
}

.text-counter {
  flex: 0 0 100%;
  color: var(--meta);
  font-size: 11px;
  text-align: right;
  min-height: 1.2em;
}

.send-btn,
.upload-btn.primary {
  border: 1px solid var(--blue2);
  background: var(--blue);
  color: #fff;
  padding: 8px 14px;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
}

#reactionPane {
  overflow-y: auto;
  background: var(--content-bg);
}

.reaction-section {
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}

.reaction-title {
  background: var(--card-strong);
  border-bottom: 1px solid var(--border);
  padding: 8px 10px;
  color: var(--text);
  font-weight: 800;
}

.reaction-body {
  padding: 10px;
  background: var(--content-bg);
}

.reaction-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 8px;
  /* カテゴリ折り畳みで一覧が縦に伸びた。スクロールしてもタブへ戻らずに
  済むよう、一覧の上端に貼り付ける(要望: 毎回上まで戻るのが手間)。 */
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 4px 0;
  background: var(--content-bg);
}

.reaction-tab {
  flex: 1;
  padding: 6px 10px;
  border: 1px solid var(--muted-border);
  background: var(--tab-bg);
  color: var(--tab-text);
  cursor: pointer;
  font-size: 13px;
}

.reaction-tab.is-active {
  background: var(--tab-active-bg);
  color: var(--tab-active-text);
  border-bottom: 2px solid var(--tab-active-line);
  font-weight: bold;
}

.reaction-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.reaction-btn {
  max-width: 100%;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.reaction-group {
  width: 100%;
  border: 1px solid var(--muted-border);
  background: var(--tab-bg);
}

.reaction-group-title {
  cursor: pointer;
  padding: 6px 10px;
  font-size: 13px;
  font-weight: bold;
  color: var(--tab-text);
  user-select: none;
}

.reaction-group-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 6px 8px 8px;
}

.reaction-with-preview {
  display: inline-flex;
  align-items: stretch;
  gap: 2px;
  max-width: 100%;
}

.reaction-preview-mount:empty {
  display: none;
}

.reaction-preview-video {
  display: block;
  max-width: 100%;
  max-height: 160px;
  margin-top: 6px;
  border: 1px solid var(--border);
  background: #000;
}

.reaction-preview-btn {
  padding: 0 8px;
  font-size: 12px;
}

/* 画像リアクションのホバー拡大。一覧と同じファイルを大きく出すだけ。
クリックを奪わないよう、絵の上ではポインターを素通りさせる。 */
.reaction-hover-preview {
  position: fixed;
  z-index: 40;
  max-width: 160px;
  max-height: 160px;
  object-fit: contain;
  pointer-events: none;
  border: 1px solid var(--border);
  background: var(--btn-bg);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}

.reaction-hover-preview[hidden] {
  display: none;
}

/* 自分が上げた素材の削除(×)。送るボタンの横に小さく。 */
.reaction-with-own-delete {
  display: inline-flex;
  align-items: stretch;
}

.reaction-own-delete-btn {
  padding: 0 6px;
  font-size: 12px;
}

/* なんちゃってチアー。お金は絡まない冗談の応援であることを常に添える。 */
.cheer-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.cheer-row[hidden] {
  display: none;
}

.cheer-number {
  width: 6em;
}

.cheer-status {
  font-size: 12px;
  color: var(--muted, #888);
}

.reaction-volume {
  display: block;
  margin: 6px 0;
  font-size: 13px;
}

.reaction-thumb {
  width: 24px;
  height: 24px;
  object-fit: cover;
  border: 1px solid var(--border);
  background: var(--btn-bg);
}

.upload-form {
  display: grid;
  gap: 6px;
}

.upload-row {
  display: grid;
  gap: 6px;
}

.upload-row.two {
  grid-template-columns: 1fr auto;
}

.upload-help,
#reactionStatus {
  margin-top: 6px;
  font-size: 12px;
  color: var(--help-text);
  line-height: 1.5;
  white-space: pre-wrap;
}

body.theater .layout {
  grid-template-columns: 1fr 300px;
  padding: 0;
  gap: 0;
}

body.theater .player-card {
  border: none;
  padding: 0;
  background: #000;
}

/* 位置と背景は、下の「映像を優先する表示」の並びで決める。
ここに同じことを書くと、片方だけ直したときに食い違う。 */
body.theater .player-toolbar {
  padding: 8px;
  color: #eee;
}

body.theater .player-wrap {
  border: none;
}

body.theater .info-card {
  display: none;
}

body.theater .side-card {
  /* 操作ボタンが枠の上に重なるようになり、高さを取らなくなった。 */
  height: 100vh;
  min-height: 0;
  border-top: none;
  border-bottom: none;
  border-right: none;
}

body.hide-chat .layout {
  grid-template-columns: 1fr;
}

body.hide-chat .right-column {
  display: none;
}

/* ブラウザのFullscreen APIとは独立した、同じタブ内の動画専用表示。 */
html.window-player-mode,
body.window-player-mode {
  overflow: hidden;
  overscroll-behavior: none;
  background: #000;
}

body.window-player-mode > header,
body.window-player-mode .info-card,
body.window-player-mode .mobile-chat-dock,
body.window-player-mode .chat-restore-rail {
  display: none !important;
}

body.window-player-mode .layout,
body.window-player-mode .left-column {
  display: block;
  min-height: 100vh;
  padding: 0;
  margin: 0;
}

body.window-player-mode .player-card {
  position: fixed;
  inset: 0;
  z-index: 10000;
  width: 100vw;
  height: 100vh;
  padding: 0;
  margin: 0;
  border: 0;
  background: #000;
}

body.window-player-mode .player-toolbar {
  position: absolute;
  top: max(8px, env(safe-area-inset-top));
  right: max(8px, env(safe-area-inset-right));
  z-index: 20;
  margin: 0;
  padding: 5px;
  border: 1px solid rgba(255,255,255,0.28);
  background: rgba(0,0,0,0.68);
  border-radius: 5px;
}

body.window-player-mode .player-toolbar .toolbar-left,
/* data-window-player-control は常時表示を強制する部品(全画面終了・チャット別窓)。 */
/* data-window-player-optional は「隠さないだけ」の部品(画質・落書き・スクショ)。 */
/* 後者に表示を強制すると、落書き無効時や画質未確定時の display:none まで */
/* 上書きしてしまうので、除外だけして表示は各自の制御に任せる。 */
body.window-player-mode .player-toolbar .toolbar-right > :not([data-window-player-control]):not([data-window-player-optional]) {
  display: none !important;
}

body.window-player-mode .player-toolbar [data-window-player-control] {
  display: inline-flex !important;
  align-items: center;
  min-height: 34px;
}

body.window-player-mode .player-toolbar .window-only-chat-popup {
  width: 34px;
  color: #fff;
}

body.window-player-mode .player-wrap {
  position: absolute;
  inset: 0;
  width: 100vw;
  height: 100vh;
  min-height: 0;
  border: 0;
  background: #000;
}

body.window-player-mode #streamVideo {
  width: 100vw;
  height: 100vh;
  min-height: 0;
  object-fit: contain;
  background: #000;
}

/* 全画面中のチャット重ね表示。右端の帯にカーソルを寄せた間だけチャット欄を
出す。出ていない間は display:none で、チャットの描き直しが映像を圧迫しない
(チャット欄は見えているだけで再生を圧迫した実績がある)。表示はふわっと
出すが、消える方は即時(displayの切替では遷移が効かない)。 */
body.window-player-mode .right-column {
  display: none;
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(360px, 92vw);
  z-index: 10003;
  background: var(--panel);
  border-left: 1px solid var(--border);
}

/* 帯は全画面中だけの存在。通常表示では消しておく(gridの並びに入れない)。 */
.chat-overlay-hover-zone {
  display: none;
}

/* 上下を空けるのは、右上のツールバーと動画の再生ボタン列(右下)への
ホバー・クリックを帯が横取りしないため(監査 2026-08-27)。 */
body.window-player-mode .chat-overlay-hover-zone {
  display: block;
  position: fixed;
  top: 96px;
  right: 0;
  bottom: 96px;
  width: 40px;
  padding: 0;
  border: 0;
  z-index: 10002;
  background: transparent;
}

/* キーボードで辿ってきた人への目印。帯はbutton要素なのでTabで届く。 */
body.window-player-mode .chat-overlay-hover-zone:focus-visible {
  outline: 2px solid var(--tab-active-line);
  outline-offset: -2px;
}

/* ホバーでの出し入れは、本物のホバーがある環境だけ。タッチのホバー擬似は
タップ後も残り続け、閉じる操作と食い違う(監査 2026-08-27)。 */
@media (hover: hover) {
  body.window-player-mode .chat-overlay-hover-zone:hover ~ .right-column,
  body.window-player-mode .right-column:hover {
    display: flex;
    flex-direction: column;
    animation: chat-overlay-fade 180ms ease;
  }
}

body.window-player-mode .chat-overlay-hover-zone:focus-visible ~ .right-column,
body.window-player-mode .right-column:focus-within,
body.window-player-mode.chat-overlay-open .right-column {
  display: flex;
  flex-direction: column;
  animation: chat-overlay-fade 180ms ease;
}

/* 全画面中、通知類(復旧・満員・中継元・別窓)は絶対配置の映像面より後ろに
描かれて見えなくなる。前へ出さないと、黒画面のまま案内も操作も届かない
(監査 2026-08-27)。 */
body.window-player-mode .popout-parent-notice,
body.window-player-mode .viewer-report-panel,
body.window-player-mode .mirror-source-notice,
body.window-player-mode .viewer-full-notice,
body.window-player-mode .playback-recovery-actions {
  position: relative;
  z-index: 21;
}

body.window-player-mode .right-column .side-card {
  flex: 1 1 auto;
  height: 100%;
  min-height: 0;
  border: 0;
}

@keyframes chat-overlay-fade {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

/* 指で触る画面にはホバーが無い。帯を細くして最前面に置き、タップで開閉する
(viewer.js)。開いている間もチャットの右端に帯が重なるが、閉じる手段を
失うよりよい。 */
@media (hover: none) {
  body.window-player-mode .chat-overlay-hover-zone {
    width: 28px;
    z-index: 10004;
  }
}

@media (prefers-reduced-motion: reduce) {
  body.window-player-mode .chat-overlay-hover-zone:hover ~ .right-column,
  body.window-player-mode .right-column:hover,
  body.window-player-mode .right-column:focus-within,
  body.window-player-mode.chat-overlay-open .right-column {
    animation: none;
  }
}

/* 幅の狭い画面では重ね表示を出さない。全画面中はチャットも出ない
(従来どおり)ので、コメントは全画面を終えてボトムシートから。 */
@media (max-width: 640px) {
  body.window-player-mode .chat-overlay-hover-zone {
    display: none;
  }

  body.window-player-mode .right-column {
    display: none !important;
  }
}

/* 映像専用の別窓(popout)と中継(is-mirror)ではチャット欄を復活させない。
別窓は映像だけの窓、中継は話す場を配信元に1つ置く設計のため。自分で
チャットを隠した人(hide-chat)にも重ねない(監査 2026-08-27)。
ただし「配信者の既定で畳んだだけ」の人(chat-default-hidden)は別扱いにする。
本人が一度も選んでいないのに、全画面で右端から重ねて出す機能まで使えなく
なるため(別窓で開く道は残っているので到達不能ではない。方針の調整
2026-08-29)。 */
body.popout .chat-overlay-hover-zone,
body.is-mirror .chat-overlay-hover-zone,
body.window-player-mode.hide-chat:not(.chat-default-hidden) .chat-overlay-hover-zone,
body.popout .right-column,
body.is-mirror .right-column,
body.window-player-mode.hide-chat:not(.chat-default-hidden) .right-column {
  display: none !important;
}

body.popout {
  background: #000;
}

body.popout header,
body.popout .right-column,
body.popout .info-card,
body.popout .mobile-chat-dock,
body.popout .player-toolbar .toolbar-left,
/* 別窓の中では意味がない操作。シアターは窓の広げ直しで足り、ポップアップは */
/* すでにこの窓自身、アーカイブは元の画面から開く。 */
body.popout #theaterBtn,
body.popout #popoutBtn,
body.popout #archiveLinkBtn {
  display: none;
}

/* 別窓再生中の親画面に出す案内。レイドの案内と同じ枠のつくり。 */
.popout-parent-notice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  border: 1px solid var(--border);
  border-left: 3px solid var(--blue);
  border-radius: 4px;
  background: var(--card-strong);
  padding: 8px 10px;
  margin-bottom: 8px;
}

.popout-parent-notice button {
  border: 1px solid var(--muted-border);
  border-radius: 3px;
  background: var(--btn-bg);
  color: var(--text2);
  padding: 4px 10px;
  font-weight: 700;
  cursor: pointer;
}

.popout-parent-notice button:hover { background: var(--btn-hover); }

/* 「不具合を報告」で開く入力欄。映像のすぐ上に出し、送ったら閉じなくてよい。 */
.viewer-report-panel {
  display: grid;
  gap: 6px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--blue);
  border-radius: 4px;
  background: var(--card-strong);
  color: var(--text);
  padding: 8px 10px;
  margin-bottom: 8px;
}

.viewer-report-panel[hidden] { display: none; }

.viewer-report-panel label { font-weight: 700; }

.viewer-report-panel input {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--muted-border);
  border-radius: 3px;
  background: var(--input-bg);
  color: var(--input-text);
  padding: 6px 8px;
  font: inherit;
}

.viewer-report-note {
  margin: 0;
  font-size: 12px;
  color: var(--help-text);
}

.viewer-report-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.viewer-report-actions button {
  border: 1px solid var(--muted-border);
  border-radius: 3px;
  background: var(--btn-bg);
  color: var(--text2);
  padding: 4px 10px;
  font-weight: 700;
  cursor: pointer;
}

.viewer-report-actions button:hover { background: var(--btn-hover); }
.viewer-report-actions button:disabled { opacity: 0.6; cursor: default; }

.viewer-report-status {
  font-size: 12px;
  color: var(--help-text);
}

body.popout .layout {
  padding: 0;
  display: block;
  min-height: 100vh;
}

body.popout .player-card {
  padding: 0;
  border: none;
  background: #000;
  height: 100vh;
}

body.popout .player-toolbar {
  position: fixed;
  top: 8px;
  right: 8px;
  /* ホバー検出の透明帯(z-index:19)より上に置く。下に置くと、ボタンは */
  /* 見えてもクリックが帯に食われて反応しない。シアターと別窓モードは20。 */
  z-index: 20;
  margin: 0;
  background: rgba(0,0,0,0.55);
  padding: 6px;
  border: 1px solid rgba(255,255,255,0.2);
}

body.popout .player-wrap {
  border: none;
  min-height: 100vh;
  height: 100vh;
}

body.popout #streamVideo {
  height: 100vh;
  min-height: 100vh;
}

body.chat-popup-page {
  min-width: 300px;
  height: 100vh;
  overflow: hidden;
}

.chat-popup-header {
  min-height: 46px;
  padding: 6px 10px;
}

.chat-popup-header > div {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

#chatConnectionStatus {
  color: var(--meta);
  font-size: 12px;
}

.chat-popup-shell {
  height: calc(100vh - 46px);
  padding: 0;
}

.chat-popup-card {
  height: 100%;
  min-height: 0;
  border-width: 1px 0 0;
}

.chat-popup-page #reactionPane {
  overflow-y: auto;
}

@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .side-card {
    height: 540px;
    min-height: 420px;
  }

  .player-wrap,
  #streamVideo {
    min-height: 280px;
  }

  .info-card {
    grid-template-columns: 1fr;
  }

  .thumb-wrap {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .thumb-wrap img {
    max-width: 360px;
  }
}

@media (max-width: 640px) {
  .chat-top-area { gap: 4px; }
  .poll-card,
  .pinned-comment-card { padding: 5px 7px; }
  .pinned-comment-actions button { padding: 1px 5px; font-size: 11px; }
  header {
    align-items: flex-start;
    flex-direction: column;
  }

  .form-row,
  .card-head,
  .info-row {
    grid-template-columns: 1fr;
  }

  .form-label,
  .card-head-label,
  .info-label {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .form-field {
    flex-wrap: wrap;
  }

  .mobile-chat-dock {
    display: grid;
    gap: 6px;
  }

  .latest-comment-bar:not([hidden]) {
    display: grid;
  }

  .mobile-chat-open,
  .overview-toggle,
  .mobile-sheet-controls {
    display: flex;
  }

  .mobile-chat-open,
  .overview-toggle {
    width: 100%;
    justify-content: center;
    border: 1px solid var(--border);
    background: var(--btn-bg);
    color: var(--btn-text);
    padding: 9px 12px;
  }

  .overview-toggle {
    order: 4;
  }

  .info-card {
    display: none;
    order: 5;
  }

  body.mobile-overview-open .info-card {
    display: grid;
  }

  .right-column {
    display: none;
  }

  body.mobile-sheet-open .right-column {
    display: block;
    position: fixed;
    inset: auto 0 0;
    z-index: 1000;
    height: min(62dvh, 620px);
    padding: 0;
    background: var(--panel);
    box-shadow: 0 -12px 32px rgba(0, 0, 0, 0.35);
  }

  body.mobile-sheet-full .right-column {
    top: max(0px, env(safe-area-inset-top));
    height: auto;
  }

  body.mobile-sheet-open .side-card {
    height: 100%;
    min-height: 0;
    border-width: 1px 0 0;
    padding-bottom: calc(126px + env(safe-area-inset-bottom));
  }

  .mobile-sheet-controls {
    flex: 0 0 auto;
    justify-content: flex-end;
    gap: 6px;
    padding: 6px;
    border-bottom: 1px solid var(--border);
    background: var(--card-strong);
  }

  .mobile-sheet-controls button {
    border: 1px solid var(--muted-border);
    background: var(--btn-bg);
    color: var(--btn-text);
    padding: 7px 9px;
  }

  #mobileComposerMount .chat-form-wrap {
    border: 1px solid var(--border);
  }

  body.mobile-sheet-open #mobileComposerMount {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1002;
    max-height: 126px;
    overflow-y: auto;
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--panel);
  }

  /* 固定入力枠の中だけは、通常のスマホ用縦積みにしない。縦積みのまま
  126pxへ収めるとコメント欄と送信ボタンが見える範囲の下へ落ちる。 */
  #mobileComposerMount .form-row,
  body.chat-popup-page .form-row {
    grid-template-columns: 72px minmax(0, 1fr);
  }

  #mobileComposerMount .form-label,
  body.chat-popup-page .form-label {
    padding: 5px 6px;
    border-right: 1px solid var(--border);
    border-bottom: none;
  }

  #mobileComposerMount .form-field,
  body.chat-popup-page .form-field {
    flex-wrap: nowrap;
    padding: 5px 6px;
  }

  #mobileComposerMount #name,
  #mobileComposerMount #text,
  body.chat-popup-page #name,
  body.chat-popup-page #text {
    padding: 5px 7px;
  }

  #mobileComposerMount #text,
  body.chat-popup-page #text {
    max-height: 3.2em;
  }

  #mobileComposerMount .send-btn,
  body.chat-popup-page .send-btn {
    width: auto;
    padding-inline: 10px;
  }

  #mobileComposerMount .text-counter,
  body.chat-popup-page .text-counter {
    grid-column: 2;
    padding: 0 6px;
    background: var(--panel2);
  }

  body.mobile-sheet-open .mobile-chat-open,
  body.mobile-sheet-open .latest-comment-bar {
    visibility: hidden;
  }

  body.hide-chat .right-column {
    display: none;
  }

  .send-btn,
  .upload-btn.primary {
    width: 100%;
  }

  .upload-row.two {
    grid-template-columns: 1fr;
  }

  /* プレイヤーを16:9ちょうどの高さにして無駄な黒帯をなくす */
  .player-wrap {
    min-height: 0;
  }

  #streamVideo {
    min-height: 0;
    height: auto;
    aspect-ratio: 16 / 9;
  }

  /* スマホでは意味のないボタンを隠してボタン列を1段に収める */
  #theaterBtn,
  #popoutBtn {
    display: none;
  }

  /* 指で押しやすい大きさに */
  .mode-btn {
    padding: 9px 12px;
  }

  .player-toolbar .mode-btn {
    padding: 7px 9px;
  }

  /* selectは内部行高が高いぶん、縦paddingを1px減らして高さを揃える。 */
  .mode-select {
    padding: 8px 12px;
  }

  .player-toolbar .mode-select {
    padding: 6px 9px;
  }

  .chat-head-hint {
    font-size: 11px;
  }

  /* iPhoneで入力欄タップ時に画面が勝手に拡大されるのを防ぐ */
  input,
  textarea {
    font-size: 16px;
  }
}

/* 管理画面の確認枠。映像の器だけを残し、枠いっぱいに広げる。 */
body.video-preview {
  background: #000;
  overflow: hidden;
}

body.video-preview header,
body.video-preview .player-toolbar,
body.video-preview .layout > :not(.left-column),
body.video-preview .left-column > :not(.player-card) {
  display: none !important;
}

body.video-preview .layout {
  display: block;
  margin: 0;
  padding: 0;
  max-width: none;
  gap: 0;
}

body.video-preview .player-card {
  margin: 0;
  border: 0;
  border-radius: 0;
  background: #000;
}

/* 普段は最低420pxを確保し、映像の高さも画面比で決めている。枠の中では
その分だけ下に黒が余る。枠の高さぴったりに合わせる。 */
body.video-preview .player-wrap {
  border-radius: 0;
  border: 0;
  margin: 0;
  height: 100vh;
  min-height: 0;
}

body.video-preview #streamVideo {
  height: 100%;
  min-height: 0;
  object-fit: contain;
}

body.video-preview .player-card {
  height: 100vh;
}

/* 名前とコメントの見出しは入力欄の横に置く。枠が狭いと縦に積まれ、
4行ぶんの高さを使ってコメントの見える量が減る。 */
body.chat-preview .form-row {
  grid-template-columns: 92px 1fr;
}

body.chat-preview .form-label {
  border-right: 1px solid var(--border);
  border-bottom: none;
}

body.chat-preview .form-field {
  flex-wrap: nowrap;
}

/* コメントの確認枠。書き込みと読み取りだけを残す。 */
body.chat-preview .chat-popup-header,
body.chat-preview .side-tabs {
  display: none !important;
}

body.chat-preview,
body.chat-preview .chat-popup-shell {
  height: 100vh;
  min-height: 0;
  padding: 0;
  overflow: hidden;
}

/* 普段のチャット欄は最低520pxを確保する。狭い枠ではその高さが入り切らず、
入力欄が枠の外へ押し出されて書き込めなくなる。枠に合わせて縮める。 */
body.chat-preview .side-card,
body.chat-preview .chat-popup-card {
  height: 100%;
  min-height: 0;
  margin: 0;
  border: 0;
  border-radius: 0;
}

/* 残りの高さはコメントの一覧が受け持ち、入力欄は縮めない。 */
body.chat-preview .side-content,
body.chat-preview .side-pane.active {
  min-height: 0;
}

body.chat-preview #messages {
  flex: 1 1 auto;
  min-height: 0;
}

body.chat-preview .chat-form-wrap {
  flex: 0 0 auto;
}

/* 映像を優先する表示（別窓・全画面・シアター）では、操作ボタンを
出しっぱなしにしない。画面上部にカーソルを乗せた間だけ出し、
離れたら薄れて消える。押している最中と、キーボードで辿っている
間は消さない。通常表示では何も変わらない。 */
.toolbar-hover-zone {
  display: none;
}

body.popout .toolbar-hover-zone,
body.window-player-mode .toolbar-hover-zone,
body.theater .toolbar-hover-zone {
  display: block;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  /* ボタンの高さより広く取る。狭いと出す前に通り過ぎる。 */
  height: 96px;
  z-index: 19;
  pointer-events: auto;
  background: transparent;
}

body.popout .player-toolbar,
body.window-player-mode .player-toolbar,
body.theater .player-toolbar {
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms ease;
}

body.popout .toolbar-hover-zone:hover ~ .player-toolbar,
body.popout .player-toolbar:hover,
body.popout .player-toolbar:focus-within,
body.window-player-mode .toolbar-hover-zone:hover ~ .player-toolbar,
body.window-player-mode .player-toolbar:hover,
body.window-player-mode .player-toolbar:focus-within,
body.theater .toolbar-hover-zone:hover ~ .player-toolbar,
body.theater .player-toolbar:hover,
body.theater .player-toolbar:focus-within {
  opacity: 1;
  pointer-events: auto;
}

/* 消える前提になるので、シアターでも枠に重ねる。空いた高さは映像へ回す。 */
body.theater .player-card {
  position: relative;
}

body.theater .player-toolbar {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 20;
  margin: 0;
  border: 1px solid rgba(255,255,255,0.28);
  border-bottom: 1px solid rgba(255,255,255,0.28);
  background: rgba(0,0,0,0.68);
  border-radius: 5px;
}

body.theater .player-wrap,
body.theater #streamVideo {
  min-height: 100vh;
  height: 100vh;
}

/* 指で触る画面にはホバーが無い。触れたら出す形にしておかないと、
操作そのものへ辿り着けなくなる。 */
@media (hover: none) {
  body.popout .player-toolbar,
  body.window-player-mode .player-toolbar,
  body.theater .player-toolbar {
    opacity: 1;
    pointer-events: auto;
  }
}

/* 動きを減らす設定の人には、薄れる演出をしない。出るか消えるかだけ。 */
@media (prefers-reduced-motion: reduce) {
  body.popout .player-toolbar,
  body.window-player-mode .player-toolbar,
  body.theater .player-toolbar {
    transition: none;
  }
}

/* 診断の窓。?diag=1 を付けたときだけ作られるので、通常は存在しない。 */
#playbackDiagPanel {
  position: fixed;
  left: 8px;
  bottom: 8px;
  z-index: 30000;
  max-width: min(560px, 92vw);
  padding: 8px;
  border: 1px solid rgba(255,255,255,0.28);
  border-radius: 5px;
  background: rgba(0,0,0,0.82);
  color: #eee;
  font-size: 11px;
  line-height: 1.35;
}

#playbackDiagPanel pre {
  margin: 0 0 6px;
  max-height: 30vh;
  overflow: auto;
  white-space: pre;
  font-family: ui-monospace, Consolas, monospace;
}
