:root {
  /* 主题系统（借鉴 nakama index.css 暗色主题：深紫夜色底 + 血红/金强调） */
  --bg: #0f0f23;
  --bg-secondary: #1a1a3a;
  --bg-tertiary: #252550;
  --card: #1e1e3e;
  --overlay: rgba(0, 0, 0, 0.8);
  --primary: #2e7d32;
  --primary-bright: #3d9b43;
  --accent: #f59e0b;
  --blood: #8b0000;
  --danger: #ef4444;
  --success: #10b981;
  --night-purple: #7b1fa2;
  --muted: #a0a0a0;
  --border: #374151;
  --border-strong: #4b5563;
  --text: #e0e0e0;
  --text-inverse: #1a1a2e;
  --dur: 200ms;
  --elevation-1: 0 1px 3px rgba(0, 0, 0, 0.2);
  --elevation-2: 0 4px 8px rgba(0, 0, 0, 0.25);
  --elevation-3: 0 10px 20px rgba(0, 0, 0, 0.3);
  --elevation-4: 0 20px 40px rgba(0, 0, 0, 0.35);
  --blur-amount: 8px;
  --night-badge: #7b1fa2;
  --discord: #5865F2;
  --speaker-color: #fbbf24;
}

@media (prefers-reduced-motion: reduce) {
  :root { --dur: 0ms; }
  * { transition: none !important; animation: none !important; }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Noto Sans SC", sans-serif;
  min-height: 100vh;
  min-height: 100dvh;
  overscroll-behavior-y: contain;
  -webkit-tap-highlight-color: transparent;
}

.view { display: none; padding: 8px; }
.view.active { display: block; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  box-shadow: var(--elevation-2);
  transition: box-shadow var(--dur), transform var(--dur);
}
.card.clickable:hover {
  box-shadow: var(--elevation-3);
  transform: translateY(-1px);
}

.title { margin: 0 0 4px; font-size: 22px; }
.muted { color: var(--muted); font-size: 13px; }
.error { color: var(--danger); font-size: 13px; }

/* 按钮（≥44px 触控目标保持） */
.btn {
  min-height: 44px;
  padding: 10px 18px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--dur), opacity var(--dur), transform 150ms, border-color var(--dur), box-shadow var(--dur);
}
.btn:hover:not(:disabled) { background: var(--bg-tertiary); }
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: rgba(255, 255, 255, 0.12); }
.btn-primary:hover:not(:disabled) { background: var(--primary-bright); border-color: var(--accent); }
.btn-danger { background: var(--danger); }
.btn-ghost { background: transparent; }
.btn-ghost:hover:not(:disabled) { background: rgba(255, 255, 255, 0.06); }
.btn-sm { min-height: 36px; padding: 6px 12px; }
.btn.accent { border-color: var(--accent); color: var(--accent); }
.btn-discord { background: var(--discord); border-color: transparent; }
.btn-discord:hover:not(:disabled) { background: #4752C4; box-shadow: var(--elevation-3); }
.btn-vote:hover:not(:disabled) { border-color: var(--accent); }

input {
  width: 100%;
  min-height: 44px;
  margin: 6px 0 12px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  transition: border-color var(--dur), box-shadow var(--dur);
}
input:focus {
  outline: none;
  border-color: var(--primary-bright);
  box-shadow: 0 0 0 3px rgba(46, 125, 50, 0.3);
}

label { font-size: 13px; color: var(--muted); }

/* 顶栏 */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  background: rgba(26, 26, 58, 0.8);
  -webkit-backdrop-filter: blur(var(--blur-amount));
  backdrop-filter: blur(var(--blur-amount));
  box-shadow: var(--elevation-1);
  position: relative;
  z-index: 10;
}
.me-chip { display: flex; align-items: center; gap: 8px; }
.me-name { font-weight: 600; }
.avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--night-purple);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; flex: none;
}
.game-title { font-weight: 700; }

/* 登录 */
.login-card {
  max-width: 360px;
  margin: 60px auto;
  box-shadow: var(--elevation-3);
  animation: card-in var(--dur) ease-out;
}
@keyframes card-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* 大厅 */
.lobby-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin: 12px 0;
}
.room-list { display: flex; flex-direction: column; gap: 8px; }
.room-row {
  display: flex; align-items: center; gap: 8px;
  padding: 12px; border: 1px solid var(--border);
  border-radius: 12px; background: var(--card); flex-wrap: wrap;
  box-shadow: var(--elevation-2);
  transition: box-shadow var(--dur), transform var(--dur), border-color var(--dur);
  cursor: default;
}
.room-row:hover {
  box-shadow: var(--elevation-3);
  transform: translateY(-1px);
  border-color: var(--border-strong);
}
.room-row.empty { color: var(--muted); box-shadow: none; }
.room-row.mine {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px rgba(46, 125, 50, 0.4), var(--elevation-2);
}
.btn.confirm-danger {
  background: var(--danger);
  border-color: #FCA5A5;
  color: #fff;
}
.room-id { font-weight: 600; margin-right: auto; }
.badge {
  font-size: 12px; padding: 3px 8px; border-radius: 999px;
  background: var(--bg-secondary); border: 1px solid var(--border); color: var(--muted);
}
.badge.accent { background: var(--accent); color: var(--text-inverse); }
.badge.primary { background: var(--primary); color: #fff; }
.badge.day { background: rgba(245, 158, 11, 0.15); color: var(--accent); border-color: rgba(245, 158, 11, 0.45); }
.badge.night { background: rgba(123, 31, 162, 0.25); color: #C4B5FD; border-color: rgba(123, 31, 162, 0.55); }
.badge.ended { background: rgba(239, 68, 68, 0.15); color: #FCA5A5; border-color: rgba(239, 68, 68, 0.45); }
.badge.muted { background: var(--bg-secondary); color: var(--muted); }

/* 游戏 */
.game-body { padding: 8px; padding-bottom: 200px; }
.seat-grid {
  display: grid; gap: 8px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}

/* 席位卡（借鉴 nakama PlayerSeat：头像圆框 + 状态徽章 + 说话呼吸光圈） */
.seat {
  position: relative;
  display: flex; align-items: center; gap: 10px;
  padding: 10px; border-radius: 12px;
  background: var(--card); border: 2px solid transparent;
  cursor: pointer;
  transition: border-color var(--dur), transform var(--dur), opacity var(--dur), box-shadow var(--dur), background var(--dur);
  text-align: left; font: inherit; color: var(--text);
  min-height: 60px;
  box-shadow: var(--elevation-1);
}
.seat.mine { border-color: var(--primary); cursor: default; }
.seat.speaking {
  border-color: var(--accent);
  animation: breathe 1.8s ease-in-out infinite;
  z-index: 2;
}
@keyframes breathe {
  0%, 100% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.45); }
  50% { box-shadow: 0 0 0 6px rgba(245, 158, 11, 0.12); }
}
.seat.dead { opacity: 0.45; filter: grayscale(0.75); transform: none; animation: none; }
.seat.votable:hover:not(:disabled) {
  border-color: var(--accent);
  box-shadow: var(--elevation-2);
  transform: translateY(-1px);
}
.seat.votable:active:not(:disabled) { transform: scale(0.97); }
.seat .speak-flag {
  position: absolute; top: -8px; right: 8px;
  font-size: 11px; background: var(--accent); color: var(--text-inverse);
  padding: 1px 6px; border-radius: 999px;
}
.seat-name { font-weight: 600; }
.seat-role { font-size: 12px; color: var(--muted); }

/* 头像圆框 + 状态徽章（存活绿点 / 死亡灰点加叉） */
.seat-avatar { position: relative; flex: none; }
.status-dot {
  position: absolute; right: -2px; bottom: -2px;
  width: 14px; height: 14px;
  border-radius: 50%;
  border: 2px solid var(--card);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 700; line-height: 1;
}
.status-dot.alive { background: var(--success); }
.status-dot.dead { background: #6b7280; color: #fff; }

/* 死人亮牌 / 终局亮牌立绘缩略（同映射） */
.seat-revealed {
  display: flex; align-items: center; gap: 6px;
}
.seat-card {
  height: 34px; width: auto; border-radius: 5px;
  border: 1px solid var(--border-strong);
  display: block;
}

/* 身份卡（立绘卡 + 阵营底色：狼红 / 神蓝 / 民绿） */
.role-card {
  margin: 8px; padding: 10px 16px;
  border-radius: 12px;
  display: flex; align-items: center; gap: 12px;
  background: var(--bg-secondary); border: 1px solid var(--border);
  box-shadow: var(--elevation-4);
  -webkit-backdrop-filter: blur(var(--blur-amount));
  backdrop-filter: blur(var(--blur-amount));
}
.role-card.fac-wolf {
  background: linear-gradient(135deg, rgba(139, 0, 0, 0.85), rgba(120, 20, 20, 0.7));
  border-color: rgba(239, 68, 68, 0.6);
}
.role-card.fac-god {
  background: linear-gradient(135deg, rgba(21, 101, 192, 0.8), rgba(30, 30, 80, 0.7));
  border-color: rgba(59, 130, 246, 0.6);
}
.role-card.fac-villager {
  background: linear-gradient(135deg, rgba(46, 125, 50, 0.8), rgba(26, 26, 58, 0.7));
  border-color: rgba(61, 155, 67, 0.6);
}
.role-img {
  height: 72px; width: auto; border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  display: block;
}
.role-img-fallback {
  min-width: 44px; min-height: 44px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: 700; background: rgba(0, 0, 0, 0.3);
}
.role-text { display: flex; flex-direction: column; }
.role-label { font-size: 12px; opacity: 0.85; }
.role-name { font-size: 18px; font-weight: 700; }

/* 倒计时（width transition 300ms） */
.timer-wrap { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 120px; }
.timer-bar {
  flex: 1; height: 6px; border-radius: 3px;
  background: linear-gradient(90deg, var(--blood), var(--danger), var(--accent));
  transition: width 300ms linear;
}
.timer-text { font-size: 12px; }

/* 事件日志 */
.event-log {
  margin-top: 12px;
  max-height: 220px; overflow-y: auto;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--card); padding: 8px 12px;
  display: flex; flex-direction: column; gap: 4px;
}
.log-line {
  font-size: 13px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  transition: background var(--dur);
}
.log-line:hover { background: rgba(255, 255, 255, 0.06); }
.log-line .speaker { color: var(--speaker-color); font-weight: 600; }
.log-line.sys { color: var(--muted); font-style: italic; background: transparent; border-color: transparent; }

/* 动作区（焦点保护机制所在 DOM，保持独立于重渲染） */
.action-area {
  position: fixed; left: 0; right: 0; bottom: 0;
  background: rgba(26, 26, 58, 0.9);
  -webkit-backdrop-filter: blur(var(--blur-amount));
  backdrop-filter: blur(var(--blur-amount));
  border-top: 1px solid var(--border);
  padding: 12px 8px;
  display: flex; flex-direction: column; gap: 8px;
  box-shadow: var(--elevation-3);
  z-index: 20;
}
.action-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.action-row input { flex: 1; min-width: 160px; margin: 0; }
.speak-wrap { display: flex; flex-direction: column; gap: 6px; flex: 1; }
.speak-wrap .action-row { margin: 0; }

/* 快捷短语条（借鉴 nakama QuickPhrases） */
.quick-phrases {
  display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px;
}
.quick-chip {
  flex-shrink: 0;
  min-height: 30px;
  padding: 4px 12px;
  font-size: 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-tertiary);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  transition: background var(--dur), border-color var(--dur), color var(--dur);
}
.quick-chip:hover { background: var(--night-purple); border-color: var(--night-purple); color: #fff; }

/* 夜晚氛围（借鉴 nakama NightOverlay）：星星 + 暗角 vignette，不只压暗 */
#view-game { transition: filter 300ms ease; }
body.night #view-game { filter: brightness(0.72) hue-rotate(200deg) saturate(1.15); }
body::before {
  content: "";
  position: fixed; inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 300ms ease;
  z-index: 4;
  background-image:
    radial-gradient(1.5px 1.5px at 12% 18%, rgba(255, 255, 255, 0.9), transparent 60%),
    radial-gradient(1px 1px at 32% 8%, rgba(255, 255, 255, 0.7), transparent 60%),
    radial-gradient(2px 2px at 48% 24%, rgba(255, 255, 255, 0.8), transparent 60%),
    radial-gradient(1px 1px at 64% 12%, rgba(255, 255, 255, 0.7), transparent 60%),
    radial-gradient(1.5px 1.5px at 78% 20%, rgba(255, 255, 255, 0.85), transparent 60%),
    radial-gradient(1px 1px at 88% 6%, rgba(255, 255, 255, 0.6), transparent 60%),
    radial-gradient(1.5px 1.5px at 22% 34%, rgba(255, 255, 255, 0.7), transparent 60%),
    radial-gradient(1px 1px at 56% 38%, rgba(255, 255, 255, 0.6), transparent 60%),
    radial-gradient(2px 2px at 92% 30%, rgba(255, 255, 255, 0.75), transparent 60%),
    radial-gradient(ellipse at 50% 50%, transparent 45%, rgba(5, 5, 20, 0.55) 100%);
}
body.night::before { opacity: 1; }
body::after {
  content: "";
  position: fixed; inset: 0;
  background: rgba(15, 15, 35, 0);
  pointer-events: none;
  transition: background 300ms ease;
  z-index: 5;
}
body.night::after {
  background: rgba(15, 15, 35, 0.28);
}

/* 阶段过渡层（借鉴 nakama PhaseTransition，1.2s，reduced-motion 禁用） */
.phase-transition {
  position: fixed; inset: 0;
  z-index: 45;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}
.phase-transition.to-night {
  background: linear-gradient(180deg, #0f0f23 0%, #1a1a3a 55%, #252550 100%);
  animation: pt-night 1.2s ease-in-out;
}
.phase-transition.to-day {
  background: linear-gradient(180deg, #fde68a 0%, #fbbf24 45%, #87ceeb 100%);
  animation: pt-day 1.2s ease-in-out;
}
@keyframes pt-night {
  0% { opacity: 0; }
  35% { opacity: 1; }
  70% { opacity: 1; }
  100% { opacity: 0; }
}
@keyframes pt-day {
  0% { opacity: 0; }
  35% { opacity: 1; }
  70% { opacity: 1; }
  100% { opacity: 0; }
}
.pt-label {
  font-size: 28px; font-weight: 700; color: #fff;
  text-shadow: 0 0 20px rgba(123, 31, 162, 0.8), 0 0 40px rgba(0, 0, 0, 0.5);
  animation: pt-label-in 1.2s ease-out;
}
.phase-transition.to-day .pt-label {
  color: var(--text-inverse);
  text-shadow: 0 0 20px rgba(255, 255, 255, 0.6);
}
@keyframes pt-label-in {
  0% { transform: translateY(30px); opacity: 0; }
  35% { transform: translateY(0); opacity: 1; }
  85% { opacity: 1; }
  100% { opacity: 0; }
}

/* 投票结果揭示动画（借鉴 nakama VoteAnimation） */
.vote-flash {
  position: fixed; top: 20%; left: 50%; transform: translateX(-50%);
  z-index: 46;
  background: rgba(30, 30, 62, 0.95);
  border: 1px solid var(--accent);
  border-radius: 12px;
  padding: 14px 28px;
  font-weight: 700; font-size: 18px;
  box-shadow: var(--elevation-4);
  pointer-events: none;
}
.vote-flash.run { animation: vote-flash-in 1.8s ease-out; }
@keyframes vote-flash-in {
  0% { opacity: 0; transform: translateX(-50%) translateY(20px) scale(0.9); }
  20% { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; }
}

/* toast */
.toast {
  position: fixed; top: 16px; left: 50%; transform: translateX(-50%);
  background: var(--card); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 16px; font-size: 14px;
  z-index: 50; max-width: 90vw;
  box-shadow: var(--elevation-4);
}
.toast.err { border-color: var(--danger); color: #FCA5A5; }
