/* style.css — NICO Meet（担当B）。フレームワークは入れない。 */

:root {
  --bg: #0e1116;
  --bg-soft: #161b22;
  --line: #262d38;
  --fg: #e7ecf3;
  --fg-dim: #97a3b4;
  --accent: #4f8cff;
  --danger: #f04a54;
  --ok: #2fbf71;
  --radius: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

/* hidden属性は display を指定した要素に負ける。
   録画インジケータ(.rec)が display:inline-flex を持つため、これが無いと
   録画していないのに「録画中」が出たままになる。必ず最優先で消す。 */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.6 system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif;
  overflow: hidden;
}

.screen { display: none; height: 100dvh; }
.screen.is-active { display: flex; }

/* ---------------------------------------------------------- 入室画面 */

#lobby {
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(1200px 600px at 50% -10%, #1b2740, var(--bg));
}

.lobby-card {
  width: min(420px, 100%);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 32px 28px;
  box-shadow: 0 24px 60px rgb(0 0 0 / 45%);
}

.brand {
  margin: 0;
  font-size: 30px;
  letter-spacing: .04em;
}

.tagline {
  margin: 6px 0 26px;
  color: var(--fg-dim);
  font-size: 13.5px;
}

.field { display: block; margin-bottom: 16px; }

.field span {
  display: block;
  margin-bottom: 6px;
  font-size: 12.5px;
  color: var(--fg-dim);
}

.field input {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #0f141b;
  color: var(--fg);
  font-size: 15px;
}

.field input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: transparent;
}

.note {
  margin: 16px 0 0;
  font-size: 12.5px;
  color: #ffd479;
  min-height: 1em;
}

.hint {
  margin: 10px 0 0;
  font-size: 11.5px;
  color: #6d7a8b;
}

/* ---------------------------------------------------------- ボタン */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #1d2530;
  color: var(--fg);
  font: inherit;
  cursor: pointer;
  transition: background .15s, transform .05s, border-color .15s;
}

.btn:hover { background: #253040; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.btn-primary:hover { background: #3d7bf0; }

.btn-block { width: 100%; padding: 12px; margin-top: 6px; }
.btn-sm { padding: 6px 10px; font-size: 12.5px; }
.btn-ghost { background: transparent; }

.btn-round {
  flex-direction: column;
  gap: 2px;
  min-width: 74px;
  padding: 8px 10px;
  border-radius: var(--radius);
}

.btn-round .ico { font-size: 19px; line-height: 1.1; }
.btn-round .lbl { font-size: 10.5px; color: var(--fg-dim); }

/* OFF状態（aria-pressed=false）は赤く光らせる */
.btn-round[aria-pressed="false"]:not(#btn-rec) {
  background: #3a1e22;
  border-color: #5d2a30;
}
.btn-round[aria-pressed="false"]:not(#btn-rec) .lbl { color: #ffb3b8; }

#btn-rec[aria-pressed="true"] {
  background: var(--danger);
  border-color: var(--danger);
}
#btn-rec[aria-pressed="true"] .lbl { color: #fff; }

.btn-danger { background: #401c20; border-color: #5d2a30; }
.btn-danger:hover { background: #5a262c; }

/* ---------------------------------------------------------- 会議画面 */

#meeting { flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-soft);
  flex: 0 0 auto;
}

.room-info { display: flex; align-items: center; gap: 8px; min-width: 0; }
.room-info strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

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

.pill {
  padding: 2px 9px;
  border-radius: 999px;
  background: #223048;
  color: #b9cbe8;
  font-size: 11.5px;
  white-space: nowrap;
}

.pill-quiet { background: #1e2530; color: var(--fg-dim); }

/* 再接続中・切断は目に入る色にする（黙って止まっていると気づけない） */
.pill-warn {
  background: #4a2a12;
  color: #ffcf9a;
  animation: blink 1.4s steps(2, start) infinite;
}

.rec {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #ffb3b8;
}

.rec i {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--danger);
  animation: blink 1.2s steps(2, start) infinite;
}

@keyframes blink { 50% { opacity: .25; } }

/* meeting-body: グリッドとチャットパネルを横に並べる器。
   グリッド自体のレイアウトは今までどおり(.grid)。
   position:relative は字幕オーバーレイ(.captions)の基準にするため。 */
.meeting-body {
  position: relative;
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
}

/* --- リアルタイム字幕 --- */

.captions {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  max-width: min(90%, 720px);
  padding: 8px 18px;
  border-radius: 10px;
  background: rgb(0 0 0 / 68%);
  backdrop-filter: blur(4px);
  color: #fff;
  font-size: 16px;
  line-height: 1.5;
  text-align: center;
  pointer-events: none; /* クリックや録画の操作を妨げない */
  z-index: 20;
}

/* --- 映像グリッド --- */

.grid {
  flex: 1 1 auto;
  display: grid;
  gap: 10px;
  padding: 12px;
  min-height: 0;
  grid-template-columns: 1fr;
  grid-auto-rows: 1fr;
}

.grid[data-count="2"] { grid-template-columns: repeat(2, 1fr); }
.grid[data-count="3"],
.grid[data-count="4"] { grid-template-columns: repeat(2, 1fr); }
.grid[data-count="5"],
.grid[data-count="6"] { grid-template-columns: repeat(3, 1fr); }
.grid[data-count="7"],
.grid[data-count="8"],
.grid[data-count="9"] { grid-template-columns: repeat(3, 1fr); }

@media (max-width: 640px) {
  .grid,
  .grid[data-count="2"],
  .grid[data-count="3"],
  .grid[data-count="4"] { grid-template-columns: 1fr; }
}

/* --- チャットパネル（S15。cm.sendChatへの配線はS16） --- */

.chat-panel {
  display: flex;
  flex-direction: column;
  width: 280px;
  flex: 0 0 auto;
  border-left: 1px solid var(--line);
  background: var(--bg-soft);
  min-height: 0;
}

@media (max-width: 640px) {
  /* 狭い画面ではグリッドを潰さず、チャットを全画面に前面表示する */
  .chat-panel {
    position: fixed;
    inset: 0;
    width: auto;
    z-index: 40;
  }
}

.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}

.chat-messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-msg { max-width: 90%; }
.chat-msg.is-self { align-self: flex-end; text-align: right; }

.chat-msg .chat-meta {
  font-size: 10.5px;
  color: var(--fg-dim);
  margin-bottom: 2px;
}

.chat-msg .chat-bubble {
  display: inline-block;
  padding: 6px 10px;
  border-radius: 12px;
  background: #1d2530;
  font-size: 13px;
  line-height: 1.4;
  word-break: break-word;
  white-space: pre-wrap;
}

.chat-msg.is-self .chat-bubble { background: var(--accent); color: #fff; }

.chat-bubble a { color: inherit; text-decoration: underline; word-break: break-all; }
.chat-msg:not(.is-self) .chat-bubble a { color: #9cc4ff; }

/* S17: 未読件数バッジ（チャットボタンに乗せる小さな丸） */
.chat-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  margin-left: 4px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  vertical-align: middle;
}

.chat-empty {
  color: var(--fg-dim);
  font-size: 12.5px;
  text-align: center;
  margin-top: 16px;
}

.chat-form {
  display: flex;
  gap: 6px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  flex: 0 0 auto;
}

.chat-form input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0f141b;
  color: var(--fg);
  font: inherit;
  font-size: 13px;
}

.chat-form input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: transparent;
}

.tile {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius);
  background: #0a0d12;
  border: 1px solid var(--line);
  min-height: 0;
}

.tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: #0a0d12;
}

.tile.is-self:not([data-peer^="screen-"]) video { transform: scaleX(-1); } /* 自分のカメラは鏡像が自然。画面共有(data-peer=screen-*)は反転させない */

.tile .name {
  position: absolute;
  left: 10px;
  bottom: 10px;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgb(0 0 0 / 58%);
  font-size: 12px;
  backdrop-filter: blur(4px);
}

.tile .badge {
  position: absolute;
  right: 10px;
  top: 10px;
  font-size: 13px;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgb(0 0 0 / 58%);
  backdrop-filter: blur(4px);
}

/* 「音声なし」は文字が入るので幅を持たせる。ミュート(🔇)と別物だと分かるよう色も変える */
.tile .badge-wide {
  font-size: 11.5px;
  padding: 3px 10px;
  background: rgb(120 60 20 / 72%);
  color: #ffd9c2;
}

.tile .novideo {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 44px;
  color: #3c4a5e;
  background: #10151d;
}

.tile.cam-off .novideo { display: flex; }

/* --- 操作バー --- */

.controls {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap; /* 狭い画面(スマホ)ではボタンを折り返して切れないようにする。広い画面は1列のまま */
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px;
  border-top: 1px solid var(--line);
  background: var(--bg-soft);
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}

.rec-opt {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  color: var(--fg-dim);
  cursor: pointer;
  user-select: none;
}

/* ---------------------------------------------------------- リアクション（S18） */

.react-wrap {
  position: relative;
  display: inline-flex;
}

.react-picker {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 4px;
  padding: 6px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .45);
  z-index: 20;
}

.react-emoji {
  border: 0;
  background: transparent;
  font-size: 22px;
  line-height: 1;
  padding: 5px 6px;
  border-radius: 8px;
  cursor: pointer;
}

.react-emoji:hover {
  background: #1e2530;
  transform: scale(1.18);
}

/* タイルにふわっと浮かんで消える一過性の絵文字 */
.reaction-fly {
  position: absolute;
  bottom: 12px;
  font-size: 40px;
  pointer-events: none;
  z-index: 15;
  will-change: transform, opacity;
  animation: reaction-fly 2.4s ease-out forwards;
  text-shadow: 0 2px 6px rgba(0, 0, 0, .5);
}

@keyframes reaction-fly {
  0%   { transform: translateY(0) scale(.6);   opacity: 0; }
  15%  { transform: translateY(-10px) scale(1.15); opacity: 1; }
  70%  { opacity: 1; }
  100% { transform: translateY(-120px) scale(1); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .reaction-fly { animation: reaction-fade 2s ease-out forwards; }
  @keyframes reaction-fade { 0%,80% { opacity: 1; } 100% { opacity: 0; } }
}

/* ---------------------------------------------------------- バーチャル背景（S19） */

.bg-panel {
  position: absolute;
  right: 12px;
  bottom: 12px;
  width: 300px;
  max-width: calc(100% - 24px);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .45);
  padding: 12px;
  z-index: 30;
}

.bg-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.bg-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.bg-opt {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border: 2px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--fg-dim);
  font-size: 11px;
  cursor: pointer;
}

.bg-opt:hover { background: #1e2530; }
.bg-opt.is-on { border-color: var(--accent); color: var(--fg); }

.bg-th {
  width: 100%;
  aspect-ratio: 16 / 10;
  border-radius: 7px;
  background: #0e1116 center / cover no-repeat;
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  font-size: 18px;
}

.bg-th-none { background: #2a2f38; }
.bg-th-blur {
  background: linear-gradient(120deg, #3a4657, #6b7787);
  filter: blur(1px);
}

.bg-upload {
  display: block;
  margin-top: 10px;
  padding: 9px;
  text-align: center;
  border: 1px dashed var(--line);
  border-radius: 9px;
  color: var(--fg-dim);
  font-size: 12.5px;
  cursor: pointer;
}
.bg-upload:hover { color: var(--fg); border-color: var(--accent); }

.bg-note {
  margin: 10px 0 0;
  font-size: 11px;
  line-height: 1.5;
  color: var(--fg-dim);
}

/* ---------------------------------------------------------- トースト */

.toasts {
  position: fixed;
  left: 50%;
  bottom: 96px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 50;
  pointer-events: none;
}

.toast {
  padding: 9px 16px;
  border-radius: 999px;
  background: #202a38;
  border: 1px solid var(--line);
  font-size: 13px;
  box-shadow: 0 8px 24px rgb(0 0 0 / 40%);
  animation: rise .2s ease-out;
}

.toast.err { background: #3a1e22; border-color: #5d2a30; color: #ffc9cd; }
.toast.ok { background: #14301f; border-color: #1f5637; color: #b6f0cd; }

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
}

/* --- S12: 画面共有中のレイアウト（画面を大きく・顔を小さく） ---
   ui.js の updateScreenLayout() が、画面共有タイルは .grid 直下に残したまま
   人物タイルだけ .grid-thumbs（横スクロールの帯）へ移す。DOM構造を変えるので、
   ここは通常時の .grid[data-count] とは独立したセレクタで上書きする。
   （クラス2つ vs クラス+属性で詳細度が同点のため、後勝ちさせる目的でファイル末尾に置く） */
.grid.has-screen {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* 画面共有タイル本体（.grid直下に残る唯一の.tile） */
.grid.has-screen > .tile {
  flex: 1 1 auto;
  min-height: 0;
}

.grid-thumbs {
  flex: 0 0 96px;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px; /* スクロールバーで映像が隠れないように */
}

.grid-thumbs .tile {
  flex: 0 0 140px;
  height: 96px;
}

@media (max-width: 640px) {
  .grid-thumbs .tile { flex-basis: 110px; }
}
