/* ===== リセット & ベース ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #1a1a2e;
  --bg-card: #16213e;
  --bg-post: #0f3460;
  --bg-system: #1a3a1a;
  --accent: #e94560;
  --accent2: #0f8b8d;
  --text: #e0e0e0;
  --text-muted: #8899aa;
  --text-system: #88cc88;
  --border: #2a4a6a;
  --wolf: #cc3333;
  --village: #3399cc;
  --radius: 6px;
  --font-mono: 'Courier New', 'MS Gothic', monospace;
  --font-main: 'Segoe UI', 'Hiragino Kaku Gothic ProN', 'Meiryo', sans-serif;
  --filter-player-color: #cccc00;
  --filter-player-bg: #2a2800;
  --filter-bookmark-color: #ff8800;
  --filter-bookmark-bg: #153525;
  --bbs-name-width: 86px;
  --dead-player-portrait-opacity: 0.45;
}

html, body {
  height: 100%;
}

body {
  background-color: var(--bg);
  color: var(--text);
  font-family: var(--font-main);
  font-size: 14px;
  line-height: 1.6;
}

a { color: var(--accent2); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { line-height: 1.3; }

/* ===== サイトヘッダー ===== */
.site-header {
  background: var(--bg-card);
  border-bottom: 2px solid var(--accent);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.site-header__title {
  font-size: 1.4rem;
  font-weight: bold;
  color: var(--accent);
  font-family: var(--font-mono);
  letter-spacing: 2px;
}

.site-header__sub {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ===== ロビーページ ===== */
.lobby {
  max-width: 600px;
  margin: 40px auto;
  padding: 0 16px;
}

.lobby__title {
  text-align: center;
  font-size: 2rem;
  color: var(--accent);
  font-family: var(--font-mono);
  letter-spacing: 4px;
  margin-bottom: 8px;
}

.lobby__subtitle {
  text-align: center;
  color: var(--text-muted);
  margin-bottom: 32px;
  font-size: 0.9rem;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
}

.card__title {
  font-size: 1rem;
  color: var(--accent2);
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}

/* ===== フォーム ===== */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.form-control {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 8px 12px;
  font-size: 0.9rem;
  font-family: var(--font-main);
  transition: border-color 0.2s;
}

.form-control:focus {
  outline: none;
  border-color: var(--accent2);
}

.form-control option {
  background: var(--bg-card);
}

.input-group {
  display: flex;
  gap: 8px;
}

.input-group .form-control {
  flex: 1;
}

/* ===== ボタン ===== */
.btn {
  display: inline-block;
  padding: 8px 18px;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  font-family: var(--font-main);
  transition: opacity 0.15s, transform 0.1s;
  white-space: nowrap;
}

.btn:hover { opacity: 0.85; }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

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

.btn--secondary {
  background: var(--border);
  color: var(--text);
}

.btn--start {
  width: 100%;
  padding: 12px;
  font-size: 1.1rem;
  background: var(--accent);
  color: #fff;
  font-weight: bold;
  letter-spacing: 2px;
}

.btn--vote {
  background: #5a2020;
  color: #ffaaaa;
  border: 1px solid #cc3333;
  margin: 4px;
}

.btn--vote:hover { background: #7a2020; }

.btn--night {
  background: #1a2a5a;
  color: #aaccff;
  border: 1px solid var(--border);
  margin: 4px;
}

.btn--night:hover { background: #2a3a7a; }

/* ===== 役職プレビュー ===== */
.role-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.role-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 8px 12px;
  margin-top: 8px;
}

.role-option {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text);
}

.role-badge {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 10px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ===== ゲームページレイアウト ===== */
.game-layout {
  display: grid;
  grid-template-columns: 1fr 240px;
  grid-template-rows: auto 1fr auto;
  grid-template-areas:
    "header header"
    "bbs    sidebar"
    "chat   sidebar";
  height: 100vh;
  gap: 0;
}

.game-header {
  grid-area: header;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.game-header__phase {
  font-size: 1rem;
  font-weight: bold;
  color: var(--accent);
}

.game-header__day {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.game-header__role {
  margin-left: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 10px;
  font-size: 0.85rem;
  color: var(--accent2);
}

/* ===== BBS エリア ===== */
.bbs-area {
  grid-area: bbs;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  position: relative;
}

#bbs-container {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  scroll-behavior: smooth;
}

/* ===== BBS 投稿 ===== */
.bbs-post {
  margin-bottom: 4px;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.bbs-post__row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 5px 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.bbs-post__bookmark {
  display: inline-flex;
  align-items: center;
}

.bbs-post__bookmark-checkbox {
  cursor: pointer;
}

.bbs-post__row--bookmarked {
  background: #23324b;
}

.bbs-post__row--whisper,
.bbs-post__row--wolf-chat {
  background: #2a1010;
  border-color: #7a2020;
}

.bbs-post__name {
  color: #ffffff;
  font-weight: bold;
  white-space: normal;
  flex-shrink: 0;
  width: var(--bbs-name-width);
  overflow: hidden;
  line-height: 1.25;
  text-align: left;
  word-break: break-word;
}

.bbs-post__body {
  flex: 1;
  font-size: 0.9rem;
  line-height: 1.6;
  word-break: break-word;
}

/* 投票発言 */
.bbs-post--vote .bbs-post__body {
  color: #ffaaaa;
  font-style: italic;
}

.bbs-post__whisper-prefix {
  color: #d7b5ff;
  font-weight: bold;
}

/* システムメッセージ */
.bbs-post--system {
  margin: 8px 0;
}

.bbs-post__system {
  background: var(--bg-system);
  border: 1px solid #3a6a3a;
  border-radius: var(--radius);
  padding: 8px 14px;
  font-size: 0.85rem;
  color: var(--text-system);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* フェーズヘッダー */
.bbs-phase-header {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.8rem;
  letter-spacing: 2px;
  margin: 16px 0 8px;
  border-top: 1px dashed var(--border);
  padding-top: 12px;
}

/* タイピングインジケーター */
.bbs-typing {
  color: var(--text-muted);
  font-size: 0.8rem;
  font-style: italic;
  padding: 6px 12px;
  animation: blink 1s ease infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ===== 常時チャット入力バー ===== */
.chat-bar {
  grid-area: chat;
  background: var(--bg-card);
  border-top: 1px solid var(--accent);
  padding: 8px 12px;
}

.chat-form {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.chat-form__top {
  display: flex;
  gap: 8px;
  align-items: center;
}

#chat-top-actions {
  display: inline-flex;
  gap: 6px;
}

.chat-form__bottom {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.chat-role-label {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 10px;
  font-size: 0.85rem;
  color: var(--accent2);
  white-space: nowrap;
  flex-shrink: 0;
}

.btn--sm {
  padding: 4px 10px;
  font-size: 0.8rem;
}

.co-role-select {
  width: auto;
  font-size: 0.8rem;
  padding: 4px 8px;
}

.chat-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 6px 10px;
  font-family: var(--font-main);
  font-size: 0.9rem;
  resize: none;
}

#chat-submit,
#whisper-mode-btn {
  align-self: stretch;
}

.chat-input:focus {
  outline: none;
  border-color: var(--accent2);
}

.btn--whisper-active {
  background: #3a1f4d;
  color: #e8c8ff;
  border: 1px solid #8a5fb3;
}

.action-label {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 8px;
}
.sidebar {
  grid-area: sidebar;
  background: var(--bg-card);
  overflow-y: auto;
  padding: 12px;
}

.sidebar__title {
  font-size: 0.8rem;
  color: var(--text-muted);
  letter-spacing: 1px;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
}

/* ===== プレイヤーカード ===== */
.player-card {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  margin-bottom: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.875rem;
  transition: border-color 0.2s, box-shadow 0.2s;
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
  text-align: left;
  cursor: pointer;
  color: inherit;
  appearance: none;
}

.player-card--dead {
  opacity: 1;
  text-decoration: none;
}

.player-card--dead .player-portrait--card {
  opacity: var(--dead-player-portrait-opacity);
}

.player-card--active {
  border-color: var(--filter-player-color);
  background: var(--filter-player-bg);
  box-shadow: 0 0 0 1px var(--filter-player-color) inset;
}

.player-card--vote-target {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent) inset;
}

.player-card--human {
  border-width: 3px;
}

.player-card:focus-visible {
  outline: 2px solid var(--accent2);
  outline-offset: 1px;
}

.player-card__name {
  flex: 1;
}

.badge {
  font-size: 0.7rem;
  padding: 2px 6px;
  border-radius: 3px;
  white-space: nowrap;
}

.badge--dead {
  background: #660000;
  color: #ffaaaa;
}

.btn--active {
  border: 1px solid var(--accent2);
}

.btn--bookmark-active {
  background: #7a3800;
  color: #ffaa44;
  border: 1px solid var(--filter-bookmark-color);
}

.ally-name {
  text-decoration: underline;
}

/* ===== 終了モーダル ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-overlay.hidden {
  display: none;
}

.modal {
  background: var(--bg-card);
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  padding: 32px;
  max-width: 440px;
  width: 90%;
  text-align: center;
}

.modal__title {
  font-size: 1.5rem;
  color: var(--accent);
  margin-bottom: 20px;
  font-family: var(--font-mono);
}

.end-result {
  font-size: 1.3rem;
  font-weight: bold;
  margin-bottom: 12px;
}

.player-roles {
  margin: 16px 0;
  text-align: left;
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 2;
}

.font-bold { font-weight: bold; color: var(--text); }

/* ===== ルール説明 ===== */
.rules-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-top: 8px;
}

.role-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
}

.role-card__name {
  font-weight: bold;
  margin-bottom: 4px;
}

.role-card__desc {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.role-card--werewolf { border-color: var(--wolf); }
.role-card--village  { border-color: var(--village); }

/* ===== ユーティリティ ===== */
.text-center { text-align: center; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.text-muted { color: var(--text-muted); font-size: 0.85rem; }

/* ===== スクロールバー ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ===== レスポンシブ ===== */
@media (max-width: 640px) {
  .game-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto auto;
    grid-template-areas:
      "header"
      "bbs"
      "chat"
      "sidebar";
  }

  .sidebar {
    border-top: 1px solid var(--border);
    overflow-x: auto;
    overflow-y: hidden;
    display: flex;
    flex-wrap: nowrap;
    gap: 6px;
    padding: 6px 8px;
    align-items: center;
  }

  .sidebar__title {
    display: none;
  }

  #player-list {
    display: flex;
    flex-wrap: nowrap;
    gap: 6px;
    align-items: center;
  }

  .player-card {
    padding: 4px 8px;
    font-size: 0.8rem;
    flex-shrink: 0;
    margin-bottom: 0;
    max-width: 90px;
    overflow: hidden;
  }

  .player-card__name {
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
  }

  .player-portrait--card {
    width: 56px;
    height: 56px;
  }

  .bbs-area {
    border-right: none;
  }
}

@media (min-width: 900px) {
  .game-layout {
    grid-template-columns: minmax(0, 1fr) 280px;
  }
}

/* ===== ロジックAI モーダル ===== */
.modal--logic-ai {
  max-width: 560px;
  text-align: left;
}

.logic-ai-content {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  font-size: 0.85rem;
  line-height: 1.8;
  color: var(--text);
  white-space: pre-wrap;
  max-height: 60vh;
  overflow-y: auto;
  margin-top: 12px;
}

/* ===== ポートレート画像 ===== */
.player-portrait {
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
  display: inline-block;
  vertical-align: middle;
}

.player-portrait--card {
  width: 70px;
  height: 70px;
}

.player-portrait--post {
  width: 40px;
  height: 40px;
  border-radius: 3px;
}

/* ===== アクションモーダル（投票・夜行動） ===== */
.modal--action {
  max-width: 90%;
}

.modal-player-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
  max-height: 50vh;
  overflow-y: auto;
  align-items: center;
}

.modal-player-btn {
  width: 90%;
  text-align: left;
  padding: 10px 16px;
  font-size: 1rem;
  display: flex;
  align-items: center;
  gap: 10px;
}

.modal-player-btn__name {
  min-width: 0;
}

.hidden {
  display: none !important;
}

.btn--attention {
  animation: actionBlink 1s ease-in-out infinite;
}

@media (prefers-reduced-motion: reduce) {
  .btn--attention {
    animation: none;
  }
}

@keyframes actionBlink {
  0%, 100% { opacity: 1; box-shadow: none; }
  50% { opacity: 0.6; box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.4); }
}

.bbs-scroll-bottom-btn {
  position: absolute;
  right: 14px;
  bottom: 12px;
  z-index: 3;
  border: 1px solid var(--border);
}

.bbs-scroll-day-controls {
  position: absolute;
  top: 10px;
  right: 10px;
  display: inline-flex;
  flex-direction: column;
  gap: 4px;
  z-index: 3;
}

.bbs-scroll-day-controls .btn {
  font-size: 1.2rem;
  padding: 6px 15px;
}

/* ===== player-card のポートレート対応 ===== */
.player-card__name {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

/* bbs-post__row のポートレート整列 */
.bbs-post__row {
  align-items: center;
}

/* ===== ポートレートラッパー（死亡オーバーレイ用） ===== */
.player-portrait-wrapper {
  position: relative;
  display: inline-block;
  flex-shrink: 0;
}

.player-dead-label {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.72);
  color: #ffaaaa;
  font-size: 0.65rem;
  font-weight: bold;
  text-align: center;
  padding: 2px 0;
  border-radius: 0 0 4px 4px;
  pointer-events: none;
}

/* ===== CO役職ごとのプレイヤー名カラー ===== */
.player-name-text {
  color: #ffffff;
}
.player-name--co-villager  { color: #ffffff; }
.player-name--co-seer      { color: #ff88cc; }
.player-name--co-medium    { color: #5599ff; }
.player-name--co-hunter    { color: #00bbaa; }
.player-name--co-madman    { color: #ff9933; }
.player-name--co-werewolf  { color: #ff4444; }
.player-name--co-white_wolf { color: #cc0000; }
.player-name--co-shared    { color: #44cc66; }
.player-name--co-cat       { color: #ffcc00; }
.player-name--co-fox       { color: #FF00FF; }

/* ===== 人狼専用チャット背景 ===== */
.chat-bar--wolf-chat {
  background: #2a0a0a;
  border-top-color: #cc2222;
}

.chat-input--wolf-chat {
  background: #1a0505;
  border-color: #7a2020;
}

