/* Material Design 3 (MUI) Style Theme & Mobile Responsive */
:root {
  --md-sys-color-background: #141218;
  --md-sys-color-surface: #1d1b20;
  --md-sys-color-surface-variant: #2b2930;
  --md-sys-color-surface-container: #211f26;
  --md-sys-color-surface-container-high: #2b2930;
  --md-sys-color-primary: #d0bcff;
  --md-sys-color-on-primary: #381e72;
  --md-sys-color-primary-container: #4f378b;
  --md-sys-color-on-primary-container: #eaddff;
  --md-sys-color-secondary: #ccc2dc;
  --md-sys-color-secondary-container: #4a4458;
  --md-sys-color-on-secondary-container: #e8def8;
  --md-sys-color-outline: #938f99;
  --md-sys-color-outline-variant: #49454f;
  --md-sys-color-on-surface: #e6e1e5;
  --md-sys-color-on-surface-variant: #cac4d0;
  --md-sys-color-error: #f2b8b5;
  --md-sys-color-error-container: #8c1d18;
  
  --role-werewolf: #f2b8b5;
  --role-seer: #d0bcff;
  --role-bodyguard: #fde293;
  --role-villager: #a8eff0;
  --role-thief: #ffb4ab;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Roboto', 'Noto Sans JP', sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  background-color: var(--md-sys-color-background);
  color: var(--md-sys-color-on-surface);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

#app-container {
  max-width: 1140px;
  width: 100%;
  margin: 0 auto;
  padding: 1rem;
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* Material Header */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.8rem 1rem;
  background: var(--md-sys-color-surface-container);
  border-radius: 18px;
  margin-bottom: 1.2rem;
}

.logo {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--md-sys-color-primary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.room-badge {
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  padding: 0.4rem 0.8rem;
  border-radius: 12px;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.5px;
}

/* 画面切替 */
.screen {
  display: none;
}

.screen.active {
  display: block;
  animation: muiFadeIn 0.3s ease-out;
}

@keyframes muiFadeIn {
  from { opacity: 0; transform: scale(0.98); }
  to { opacity: 1; transform: scale(1); }
}

/* MUI Card / Surface */
.mui-card {
  background: var(--md-sys-color-surface-variant);
  border-radius: 20px;
  padding: 1.4rem;
  margin-bottom: 1.2rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

/* 1行ずつ見やすく整列したフォーム群 */
.form-group {
  margin-bottom: 1.2rem;
}

.form-group label {
  display: block;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--md-sys-color-on-surface-variant);
  margin-bottom: 0.5rem;
}

input[type="text"],
input[type="password"],
input[type="number"],
select {
  width: 100%;
  padding: 0.9rem 1.1rem;
  background: var(--md-sys-color-surface-container);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: 14px;
  color: var(--md-sys-color-on-surface);
  font-size: 16px; /* iOS自動ズーム防止 */
  outline: none;
  transition: all 0.2s ease;
  min-height: 48px;
}

input[type="text"]:focus,
input[type="password"]:focus,
input[type="number"]:focus,
select:focus {
  border-color: var(--md-sys-color-primary);
  background: var(--md-sys-color-surface);
  box-shadow: 0 0 0 2px var(--md-sys-color-primary);
}

/* アコーディオン設定トグルヘッダー */
.settings-toggle-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  padding: 0.4rem 0;
  user-select: none;
}

.settings-summary-bar {
  background: var(--md-sys-color-surface-container);
  border-radius: 12px;
  padding: 0.6rem 0.9rem;
  font-size: 0.82rem;
  color: var(--md-sys-color-primary);
  margin-top: 0.6rem;
  line-height: 1.4;
}

/* Material Buttons */
.btn-primary {
  width: 100%;
  padding: 0.95rem;
  min-height: 48px;
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  border: none;
  border-radius: 100px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: background 0.2s, transform 0.1s;
}

.btn-primary:active {
  transform: scale(0.98);
}

.btn-secondary {
  width: 100%;
  padding: 0.85rem;
  min-height: 48px;
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
  border: none;
  border-radius: 100px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: background 0.2s;
}

/* レスポンシブレイアウト */
.responsive-lobby-grid {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 1.2rem;
}

@media (max-width: 768px) {
  .responsive-lobby-grid {
    grid-template-columns: 1fr;
  }
}

.game-layout {
  display: grid;
  grid-template-columns: 1fr 420px;
  gap: 1.2rem;
}

/* スマホ用ボトムナビゲーション＆ビュー切り替え */
.mobile-tab-bar {
  display: none;
}

/* フェーズバナーとヘッダーアクションボタン */
.phase-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  border-radius: 18px;
  padding: 1rem 1.4rem;
  margin-bottom: 1.2rem;
}

.phase-header-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.banner-btn-group {
  display: flex;
  gap: 0.5rem;
}

.btn-header-action {
  width: auto;
  padding: 0.5rem 0.9rem;
  font-size: 0.82rem;
  min-height: 38px;
  margin: 0;
}

.btn-danger {
  background: var(--md-sys-color-error-container);
  color: var(--md-sys-color-error);
}

@media (max-width: 768px) {
  #app-container {
    padding-bottom: 75px;
  }

  .game-layout {
    display: block;
  }

  .mobile-view-panel {
    display: none;
  }

  .mobile-view-panel.active {
    display: block;
  }

  /* スマホでのフェーズバナー内のレイアウト整理（誤タップ防止） */
  .phase-banner {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.8rem;
    padding: 1rem;
  }

  .phase-header-actions {
    width: 100%;
    justify-content: space-between;
  }

  .banner-btn-group {
    display: flex;
    gap: 0.6rem;
  }

  .mobile-tab-bar {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 60px;
    background: var(--md-sys-color-surface-container);
    border-top: 1px solid var(--md-sys-color-outline-variant);
    z-index: 100;
  }

  .mobile-tab-btn {
    flex: 1;
    background: none;
    border: none;
    color: var(--md-sys-color-on-surface-variant);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    font-size: 0.75rem;
    font-weight: 700;
    cursor: pointer;
    position: relative;
  }

  .mobile-tab-btn.active {
    color: var(--md-sys-color-primary);
  }

  .unread-badge {
    position: absolute;
    top: 6px;
    right: 35%;
    width: 10px;
    height: 10px;
    background: var(--md-sys-color-error);
    border-radius: 50%;
  }
}

.phase-info h2 {
  font-size: 1.2rem;
  font-weight: 700;
}

.timer {
  font-size: 1.6rem;
  font-weight: 800;
  color: #ffd8e4;
  font-family: monospace;
}

/* 役職カード */
.role-card {
  background: var(--md-sys-color-surface-container);
  border-radius: 18px;
  padding: 1.2rem;
  margin-bottom: 1.2rem;
}

.role-badge {
  display: inline-block;
  padding: 0.35rem 0.8rem;
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 700;
  margin-bottom: 0.4rem;
}

.role-badge.WEREWOLF { background: var(--md-sys-color-error-container); color: var(--md-sys-color-error); }
.role-badge.SEER { background: var(--md-sys-color-primary-container); color: var(--md-sys-color-primary); }
.role-badge.BODYGUARD { background: #4a3800; color: #fde293; }
.role-badge.VILLAGER { background: #004f4f; color: #a8eff0; }

/* プレイヤーリスト (スマホ最適化) */
.players-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 0.8rem;
  margin-bottom: 1.2rem;
}

.player-card {
  background: var(--md-sys-color-surface-container);
  border-radius: 16px;
  padding: 0.9rem 0.5rem;
  text-align: center;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all 0.2s;
  min-height: 90px;
}

.player-card:active {
  transform: scale(0.96);
}

.player-card.selected {
  border-color: var(--md-sys-color-error);
  background: rgba(242, 184, 181, 0.15);
}

.player-card.dead {
  opacity: 0.4;
  filter: grayscale(1);
}

.player-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--md-sys-color-surface-variant);
  margin: 0 auto 0.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
}

/* チャット領域 */
.chat-container {
  display: flex;
  flex-direction: column;
  height: 580px;
  min-height: 0;
  max-height: 100%;
  overflow: hidden;
}

/* Keep the composer fixed; only the message list is scrollable. */
#room-chat-panel {
  display: flex;
  flex: 1;
  min-height: 0;
  flex-direction: column;
  overflow: hidden;
}

#room-history-panel {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

#lobby-chat-panel {
  display: flex !important;
  flex-direction: column;
  height: min(580px, calc(100vh - 180px));
  min-height: 360px;
  box-sizing: border-box;
}

#lobby-chat-messages {
  flex: 1;
  min-height: 0 !important;
  max-height: none !important;
  overflow-y: auto;
}

#mobile-view-chat {
  min-height: 0;
  overflow: hidden;
}

@media (max-width: 768px) {
  .chat-container {
    height: calc(100vh - 200px);
    min-height: 400px;
  }
}

.chat-messages {
  flex: 1;
  min-height: 0;
  max-height: none;
  overflow-y: auto;
  padding-right: 0.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.chat-msg {
  background: var(--md-sys-color-surface-container);
  padding: 0.85rem 1.1rem;
  border-radius: 16px;
  font-size: 16px;
  line-height: 1.5;
  word-break: break-word;
}

.chat-msg.SYSTEM {
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
}

.chat-msg.WEREWOLF {
  background: var(--md-sys-color-error-container);
  color: var(--md-sys-color-error);
}

.chat-msg .sender {
  font-weight: 700;
  font-size: 0.85rem;
  margin-bottom: 0.2rem;
  color: var(--md-sys-color-primary);
}

.chat-avatar {
  font-size: 1.05rem;
  vertical-align: middle;
  margin-right: 0.25rem;
  color: var(--md-sys-color-primary);
}

.elimination-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.15rem;
  height: 1.15rem;
  margin-left: 0.3rem;
  border-radius: 50%;
  background: var(--md-sys-color-error-container);
  color: var(--md-sys-color-error);
  font-size: 0.7rem;
  font-weight: 800;
  vertical-align: middle;
}

.chat-input-box {
  display: flex;
  flex: 0 0 auto;
  gap: 0.5rem;
  margin-top: 0.8rem;
}

.chat-input-box input {
  font-size: 16px;
}

/* ログパネル */
.log-box {
  background: var(--md-sys-color-surface-container);
  border-radius: 14px;
  padding: 0.8rem 1rem;
  font-size: 0.88rem;
  color: var(--md-sys-color-on-surface-variant);
  max-height: 120px;
  overflow-y: auto;
  line-height: 1.5;
}

/* モーダル */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.75);
  z-index: 999;
}

.modal-content {
  background: var(--md-sys-color-surface-variant);
  border-radius: 24px;
  padding: 1.4rem;
}
