:root {
  --bg-top: #0b0e14;
  --bg-bottom: #131826;
  --text: #ece7db;
  --muted: #8b93a7;
  --surface: rgba(255, 255, 255, 0.04);
  --line: rgba(255, 255, 255, 0.08);
  --accent: #ff9a3c;
  --accent-outer: #ff6b35;
  --accent-core: #ffd97a;
  --ember: #d63a1f;
  --danger: #e8a0a0;
}

* { box-sizing: border-box; }

/* v0.7.1: スクロールバーは全画面で非表示（操作はそのまま効く） */
html, body, * { scrollbar-width: none; -ms-overflow-style: none; }
html::-webkit-scrollbar, body::-webkit-scrollbar, *::-webkit-scrollbar { display: none; }

html, body { overscroll-behavior-y: none; }

body {
  margin: 0;
  background: linear-gradient(var(--bg-top), var(--bg-bottom));
  background-attachment: fixed;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

/* v0.7.1: チャット画面は 100dvh に収め、ページ全体はスクロールさせない */
body.in-chat {
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

body.in-chat .container {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

body.in-chat .chat {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.app-header {
  text-align: center;
  padding: 26px 16px 6px;
}

.app-header h1 {
  margin: 0;
  letter-spacing: 0.45em;
  font-weight: 600;
  text-indent: 0.45em;
}

.subtitle {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.container {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 12px 16px 20px;
  flex: 1;
}

.hidden { display: none !important; }
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---- entry: 箱を消し背景に直接置く ---- */
.entry {
  padding: 4px 2px 20px;
}

.entry h2 {
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.2em;
  margin: 6px 0 10px;
}

.entry-fire {
  position: relative;
  width: 100%;
  height: 150px;
  margin: 0 auto 2px;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: flex-end;
}

.entry-fire .fire-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* 通常はCanvas火だけ。CSS火は reduced-motion 時のフォールバック */
.entry-fire .fire-fallback { display: none; }

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 12px 0;
  font-size: 0.9rem;
  color: var(--muted);
}

input[type="text"] {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  color: var(--text);
  font-size: 1rem;
  width: 100%;
}

input[type="text"]::placeholder { color: var(--muted); }

button {
  cursor: pointer;
  border: 0;
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 1rem;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  border: 1px solid var(--line);
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #1a1210;
  font-weight: 700;
  width: 100%;
  margin-top: 8px;
}

button.primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.leave-quiet {
  background: transparent;
  border: 0;
  color: var(--muted);
  padding: 8px 4px;
  font-size: 0.85rem;
  white-space: nowrap;
}

.leave-quiet:hover { color: var(--text); }

.notice {
  margin-top: 16px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  font-size: 0.85rem;
  color: var(--muted);
}

.notice p { margin: 6px 0; }

.mode-field {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: transparent;
}

.mode-field legend {
  padding: 0 6px;
  color: var(--muted);
  font-size: 0.85rem;
}

.mode-field .radio {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  color: var(--text);
  font-size: 0.95rem;
}

/* v0.7.1: モード選択は横並びセグメント */
.mode-seg .seg {
  display: flex;
  gap: 6px;
}

.mode-seg .radio {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin: 0;
  padding: 10px 6px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
  cursor: pointer;
  white-space: nowrap;
}

.mode-seg .radio:has(input:checked) {
  background: rgba(255, 154, 60, 0.14);
  border-color: rgba(255, 154, 60, 0.55);
  color: var(--text);
}

.mode-seg .radio input { accent-color: var(--accent); }

.details {
  margin: 4px 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.details summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.85rem;
  padding: 4px 0;
}

.details p { margin: 6px 0; }

.name-note {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 8px 0;
}

.consent {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 12px 0;
  font-size: 0.9rem;
}

.error {
  color: #ff9d9d;
  min-height: 1.2em;
  font-size: 0.9rem;
}

/* ---- chat: 舞台が主役 ---- */
.chat { padding-bottom: 8px; }

.room-bar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 2px;
}

.room-label {
  font-size: 1.2rem;
  font-weight: 700;
}

.member-count {
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 4px;
}

.status {
  min-height: 1.4em;
  font-size: 0.85rem;
  color: var(--accent-core);
  margin: 6px 2px 0;
  opacity: 0.9;
}

.stage {
  position: relative;
  width: 100%;
  height: 400px;
  margin-top: 2px;
}

.fire-wrap {
  position: absolute;
  inset: 0;
}

.fire-wrap .fire-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* Canvas有効時はCSS火を隠す。reduced-motionでは逆にする（後述） */
.fire-wrap.canvas-on .fire-fallback,
.fire-wrap.canvas-on .fire-fallback-extra {
  display: none;
}

.seats {
  position: absolute;
  inset: 0;
  list-style: none;
  margin: 0;
  padding: 0;
  pointer-events: none;
}

.seats .seat {
  pointer-events: auto;
  position: absolute;
  width: 58px;
  height: 58px;
  margin: -29px 0 0 -29px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.14);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: box-shadow 0.35s, transform 0.35s, opacity 0.35s;
  z-index: 3;
}

.seats .seat .ic {
  font-size: 21px;
  line-height: 1.1;
}

.seats .seat .nm {
  font-size: 8.5px;
  color: #c9c2b2;
  margin-top: 1px;
  max-width: 52px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.seats .seat.host::after {
  content: '';
  position: absolute;
  bottom: -7px;
  left: 50%;
  width: 5px;
  height: 5px;
  margin-left: -2.5px;
  border-radius: 50%;
  background: var(--accent);
}

.seats .seat.lit,
.seats .seat.speaking {
  box-shadow: 0 0 0 2px rgba(255, 154, 60, 0.85), 0 0 24px rgba(255, 140, 60, 0.6);
  transform: translateY(-3px);
}

.seats .seat.away { opacity: 0.38; }

.seats .seat.away .away-tag {
  position: absolute;
  bottom: -15px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 9px;
  color: var(--muted);
  white-space: nowrap;
}

.seats .seat.empty {
  opacity: 0.16;
  border-style: dashed;
  cursor: default;
  pointer-events: none;
}

.seats .seat.empty .ic { font-size: 14px; }

.req-dot {
  position: absolute;
  top: -4px;
  right: -4px;
  background: transparent;
  border: 1px solid var(--accent);
  color: #ffc9a8;
  border-radius: 999px;
  padding: 0 5px;
  font-size: 10px;
  line-height: 16px;
}

.menu-pop {
  position: absolute;
  top: calc(100% + 6px);
  right: -10px;
  z-index: 20;
  background: #141922;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 160px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.55);
}

.menu-pop button {
  background: transparent;
  border: 0;
  color: var(--text);
  text-align: left;
  padding: 8px 10px;
  font-size: 0.85rem;
  border-radius: 6px;
}

.menu-pop button:hover { background: rgba(255, 255, 255, 0.06); }

/* 旧チップ互換（speaking検出の土台。席でも使う） */
.members-title { display: none; }

/* マイクは舞台の右下に大きな円形 */
.mic-fab {
  position: absolute;
  right: 6px;
  bottom: 8px;
  z-index: 4;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 154, 60, 0.55);
  color: #ffc9a8;
  font-size: 0.72rem;
  line-height: 1.2;
  padding: 6px;
}

.mic-fab.on {
  background: var(--accent);
  border-color: var(--accent);
  color: #1a1210;
  font-weight: 700;
  box-shadow: 0 0 18px rgba(255, 154, 60, 0.55);
}

.mic-fab:disabled {
  opacity: 0.6;
  cursor: wait;
}

/* v0.7.1: 音声だけモードでは主役なので少し大きく */
body.mode-voice .mic-fab {
  width: 84px;
  height: 84px;
  font-size: 0.8rem;
}

.voice-sub {
  min-height: 1.2em;
  padding: 0 2px;
}

.voice-error { flex: 1; font-size: 0.85rem; }

.voice-audios {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.messages {
  list-style: none;
  margin: 8px 0 10px;
  padding: 0;
  padding-bottom: 4px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 38vh;
  max-height: 38dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* v0.7.1: チャット時はメッセージ領域だけが内部スクロール */
body.in-chat .stage { flex: none; }
body.in-chat .room-bar,
body.in-chat .status,
body.in-chat .voice-sub,
body.in-chat .send-row,
body.in-chat .voice-audios { flex: none; }
body.in-chat .messages {
  flex: 1;
  min-height: 80px;
  max-height: none;
  overflow-y: auto;
}

.messages li {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
}

.messages li.self {
  background: rgba(255, 154, 60, 0.08);
  border-color: rgba(255, 154, 60, 0.22);
}

.messages .meta {
  font-size: 0.75rem;
  color: var(--muted);
  display: flex;
  gap: 8px;
  margin-bottom: 4px;
}

.messages .body {
  white-space: pre-wrap;
  word-break: break-word;
}

/* システム表示は「煙」：枠なし・中央・淡く */
.messages li.system {
  background: transparent;
  border: 0;
  color: var(--muted);
  font-size: 0.82rem;
  text-align: center;
  opacity: 0.85;
}

.send-row { display: flex; gap: 8px; }
.send-row input { flex: 1; }
.send-row button { width: auto; margin-top: 0; }

.footer {
  text-align: center;
  padding: 14px 16px 18px;
  color: var(--muted);
}

/* ---- v0.6 トレンド欄（フラグ有効時のみ表示） ---- */
.trend {
  margin-top: 16px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
}

.trend-title {
  margin: 0 0 6px;
  font-size: 0.9rem;
  font-weight: 700;
}

.trend-empty {
  margin: 6px 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.trend-list {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.trend-item {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 6px 12px;
  font-size: 0.85rem;
  color: var(--text);
}

.trend-item:hover { border-color: var(--accent); }

.trend-note {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
}

/* ---- v0.2 CSS火フォールバック（reduced-motion時とCanvas不可時に使用） ---- */
.fire {
  position: relative;
  width: 90px;
  height: 122px;
  transform-origin: 50% 100%;
  transition: transform 0.6s ease, filter 0.6s ease;
}

.fire::before {
  content: '';
  position: absolute;
  left: 50%;
  bottom: -14px;
  width: 190px;
  height: 60px;
  transform: translateX(-50%);
  background: radial-gradient(ellipse at center, rgba(255, 140, 60, 0.35) 0%, rgba(255, 140, 60, 0) 70%);
  pointer-events: none;
}

.flame {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform-origin: 50% 100%;
  border-radius: 50% 50% 50% 50% / 62% 62% 38% 38%;
  animation: flick 1.1s ease-in-out infinite;
}

.f-outer {
  width: 64px;
  height: 92px;
  margin-left: -32px;
  background: linear-gradient(to top, #d63a1f 0%, #f26a2b 55%, #ff9a3c 100%);
}

.f-mid {
  width: 44px;
  height: 66px;
  margin-left: -22px;
  background: linear-gradient(to top, #f2762b 0%, #ffab4a 60%, #ffd97a 100%);
  animation-delay: 0.18s;
  animation-duration: 0.9s;
}

.f-inner {
  width: 24px;
  height: 40px;
  margin-left: -12px;
  background: linear-gradient(to top, #ffb84d 0%, #ffe9a8 70%, #fff6dd 100%);
  animation-delay: 0.32s;
  animation-duration: 0.8s;
}

@keyframes flick {
  0%, 100% { transform: scaleY(1) scaleX(1) skewX(0deg); opacity: 0.95; }
  25% { transform: scaleY(1.06) scaleX(0.97) skewX(2deg); opacity: 1; }
  50% { transform: scaleY(0.94) scaleX(1.02) skewX(-2deg); opacity: 0.9; }
  75% { transform: scaleY(1.03) scaleX(0.99) skewX(1deg); opacity: 1; }
}

.fire-wrap .fire {
  transform: scale(calc(var(--bs, 1) * (1 + var(--heat, 0) * 0.5)));
  filter: brightness(calc(var(--bb, 1) + var(--heat, 0) * 0.4)) saturate(calc(0.95 + var(--heat, 0) * 0.35));
}

.fire-wrap[data-count="1"] .fire { --bs: 0.62; --bb: 0.82; }
.fire-wrap[data-count="2"] .fire { --bs: 0.76; --bb: 0.9; }
.fire-wrap[data-count="3"] .fire { --bs: 0.88; --bb: 0.96; }
.fire-wrap[data-count="4"] .fire { --bs: 1; --bb: 1; }
.fire-wrap[data-count="5"] .fire { --bs: 1.1; --bb: 1.06; }
.fire-wrap[data-count="6"] .fire { --bs: 1.2; --bb: 1.12; }

.fire-wrap {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  overflow: hidden;
}

.fire-wrap.talking .flame { animation-duration: 0.55s; }
.fire-wrap.talking .f-mid { animation-duration: 0.45s; }
.fire-wrap.talking .f-inner { animation-duration: 0.4s; }

.logs span,
.sparks span {
  position: absolute;
}

.sparks span {
  bottom: 64px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #ffb066;
  opacity: 0;
  animation: rise 5s linear infinite;
}

@keyframes rise {
  0% { transform: translateY(0) translateX(0); opacity: 0; }
  15% { opacity: 0.9; }
  100% { transform: translateY(-130px) translateX(12px); opacity: 0; }
}

.sparks span:nth-child(1) { left: 44%; animation-delay: 0s; animation-duration: 4.2s; }
.sparks span:nth-child(2) { left: 52%; animation-delay: 1.1s; animation-duration: 5s; width: 3px; height: 3px; }
.sparks span:nth-child(3) { left: 48%; animation-delay: 2.3s; animation-duration: 4.6s; }
.sparks span:nth-child(4) { left: 56%; animation-delay: 0.6s; animation-duration: 5.6s; width: 3px; height: 3px; }
.sparks span:nth-child(5) { left: 41%; animation-delay: 3s; animation-duration: 4.9s; }
.sparks span:nth-child(6) { left: 59%; animation-delay: 1.8s; animation-duration: 4.1s; }
.sparks span:nth-child(7) { left: 46%; animation-delay: 4.1s; animation-duration: 5.3s; width: 3px; height: 3px; }
.sparks span:nth-child(8) { left: 54%; animation-delay: 2.8s; animation-duration: 4.4s; }
.sparks span:nth-child(9) { left: 50%; animation-delay: 3.6s; animation-duration: 5.9s; width: 3px; height: 3px; }
.sparks span:nth-child(10) { left: 43%; animation-delay: 4.6s; animation-duration: 4.7s; }

@media (max-width: 480px) {
  .container { padding: 10px 12px 16px; }
  .stage { height: 360px; }
  .seats .seat { width: 52px; height: 52px; margin: -26px 0 0 -26px; }
  .seats .seat .ic { font-size: 19px; }
  .seats .seat .nm { font-size: 8px; max-width: 46px; }
  .mic-fab { width: 64px; height: 64px; }
  body.mode-voice .mic-fab { width: 76px; height: 76px; }
  .messages { max-height: 40vh; max-height: 40dvh; }
}

@media (prefers-reduced-motion: reduce) {
  .fire-wrap.canvas-on .fire-canvas { display: none; }
  .fire-wrap.canvas-on .fire-fallback,
  .fire-wrap.canvas-on .fire-fallback-extra {
    display: block;
  }
  .entry-fire .fire-canvas { display: none; }
  .entry-fire .fire-fallback { display: block; }
  .flame, .sparks span { animation: none; }
  .seats .seat { transition: none; }
}
