:root {
  --bg: #0f1117;
  --bg-panel: #191c26;
  --bg-panel-2: #21252f;
  --border: #2c313d;
  --text: #e6e8ee;
  --text-dim: #9aa0ae;
  --accent: #7c5cff;
  --accent-2: #a78bfa;
  --wolf: #e5484d;
  --good: #30a46c;
  --gold: #f5b843;
  --danger: #e5484d;
  --radius: 12px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: radial-gradient(1200px 600px at 50% -10%, #1a1d2b 0%, var(--bg) 60%);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

.view { display: none; }
.view.active { display: block; }

/* ---------- 首页 ---------- */
#view-home {
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
#view-home.active { display: flex; }
.home-box {
  width: 100%;
  max-width: 360px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px 24px;
}
.logo { font-size: 32px; font-weight: 800; text-align: center; }
.subtitle { text-align: center; color: var(--text-dim); font-size: 13px; margin: 6px 0 22px; }
.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 13px; color: var(--text-dim); margin-bottom: 6px; }
input {
  width: 100%;
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 11px 13px;
  font-size: 15px;
  outline: none;
}
input:focus { border-color: var(--accent); }
.room-code-input { letter-spacing: 4px; text-transform: uppercase; font-weight: 700; }

.btn {
  width: 100%;
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 12px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: #2a2f3b; }
.btn:active { background: #232833; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #6b4dff; }
.btn-sm { width: auto; padding: 9px 16px; font-size: 14px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.divider { text-align: center; margin: 16px 0; position: relative; color: var(--text-dim); font-size: 12px; }
.divider::before, .divider::after {
  content: ""; position: absolute; top: 50%; width: 40%; height: 1px; background: var(--border);
}
.divider::before { left: 0; } .divider::after { right: 0; }
.error-text { color: var(--danger); font-size: 13px; text-align: center; margin-top: 12px; min-height: 18px; }

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 18px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
  z-index: 10;
}
.room-badge { font-size: 14px; color: var(--text-dim); }
.room-badge b { color: var(--gold); letter-spacing: 2px; font-size: 16px; }
.phase-info { font-weight: 700; font-size: 16px; }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--accent-2); min-width: 46px; text-align: right; }
.timer.urgent { color: var(--danger); }

/* ---------- 游戏整体：顶栏 / 主体 / 底部操作条 三段 ---------- */
#view-game.view.active {
  display: flex;
  flex-direction: column;
  height: 100vh;
}
.game-body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  gap: 16px;
  padding: 16px;
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
  overflow: hidden;
}
.stage {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.side {
  flex: 0 0 340px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
}

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.panel h3 { font-size: 15px; margin-bottom: 12px; }
.hint { color: var(--text-dim); font-size: 12px; margin-top: 10px; }
.hidden { display: none !important; }

/* ---------- 大厅配置面板（居中卡片） ---------- */
.lobby-panel {
  width: 100%;
  max-width: 460px;
  margin: 0 auto;
  align-self: center;
  overflow-y: auto;
  max-height: 100%;
}
.lobby-players-wrap { margin-bottom: 16px; }
.lobby-sub { font-size: 12px; color: var(--text-dim); margin-bottom: 8px; }
.lobby-players { display: flex; flex-wrap: wrap; gap: 8px; }
.lobby-chip {
  display: flex; align-items: center; gap: 6px;
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 12px 5px 8px;
  font-size: 13px;
}
.lobby-chip .lc-seat { color: var(--text-dim); font-size: 11px; }
.lobby-chip.me { border-color: var(--accent); }
.lobby-chip.host .lc-name::after { content: " 👑"; }
.lobby-empty { color: var(--text-dim); font-size: 13px; }

/* ---------- 环形桌面 ---------- */
.table {
  flex: 1 1 auto;
  position: relative;
  min-height: 0;
  border-radius: 50%;
}
.seats { position: absolute; inset: 0; }
.table-center {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: min(46%, 260px);
  text-align: center;
  pointer-events: none;
}
.tc-phase { font-size: 20px; font-weight: 800; }
.tc-round { font-size: 13px; color: var(--text-dim); margin-top: 4px; }
.tc-hint { font-size: 13px; color: var(--accent-2); margin-top: 10px; line-height: 1.5; }
/* 桌布圆盘 */
.table::before {
  content: "";
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: min(58%, 340px);
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 40%, #20232f 0%, #14161f 70%);
  border: 1px solid var(--border);
  box-shadow: inset 0 0 40px rgba(0,0,0,.5);
}

/* ---------- 座位（环形绝对定位；内部样式保留） ---------- */
.seat {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 92px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 6px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  /* 明确不做 hover 上浮 */
}
.seat .seat-no { font-size: 11px; color: var(--text-dim); }
.seat .avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--bg-panel-2);
  display: flex; align-items: center; justify-content: center;
  margin: 5px auto; font-size: 19px;
}
.seat .seat-name { font-size: 12px; font-weight: 600; word-break: break-all; line-height: 1.2; }
.seat .seat-tag { font-size: 10px; margin-top: 3px; color: var(--text-dim); min-height: 12px; }
.seat.dead { opacity: .4; }
.seat.dead .avatar { filter: grayscale(1); }
.seat.me { border-color: var(--accent); }
.seat.host .seat-no::after { content: " 👑"; }
.seat.wolf-ally { border-color: var(--wolf); }
.seat.selectable { cursor: pointer; border-color: var(--accent-2); }
.seat.selectable:hover { background: var(--bg-panel-2); }
.seat.selected { background: rgba(124,92,255,.18); border-color: var(--accent); }
.seat .role-badge {
  font-size: 10px; margin-top: 4px; padding: 1px 6px; border-radius: 6px;
  display: inline-block; background: var(--bg-panel-2);
}
.seat .role-badge.wolf { background: rgba(229,72,77,.2); color: #ff9ea0; }
.seat .role-badge.good { background: rgba(48,163,108,.2); color: #7ee2b0; }
.seat .vote-count { position: absolute; top: -6px; right: -6px; font-size: 11px; background: var(--accent); color:#fff; border-radius: 8px; padding: 0 6px; box-shadow: 0 0 0 2px var(--bg); }

/* ---------- 配置编辑 ---------- */
.config-editor { display: flex; flex-direction: column; gap: 10px; }
.config-row { display: flex; align-items: center; justify-content: space-between; }
.config-row .cfg-name { font-size: 14px; }
.config-row .cfg-name small { color: var(--text-dim); font-size: 11px; display: block; }
.stepper { display: flex; align-items: center; gap: 10px; }
.stepper button {
  width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg-panel-2); color: var(--text); font-size: 18px; cursor: pointer;
}
.stepper button:hover { background: #2a2f3b; }
.stepper .val { min-width: 22px; text-align: center; font-weight: 700; }
.config-total { margin: 14px 0; font-size: 14px; color: var(--text-dim); }
.config-total b { color: var(--text); }

/* ---------- 身份卡 ---------- */
.role-card {
  background: linear-gradient(135deg, #24202f, #1a1d26);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  flex: 0 0 auto;
}
.role-card .rc-title { font-size: 12px; color: var(--text-dim); }
.role-card .rc-role { font-size: 22px; font-weight: 800; margin: 4px 0; }
.role-card .rc-role.wolf { color: #ff9ea0; }
.role-card .rc-role.good { color: #7ee2b0; }
.role-card .rc-desc { font-size: 13px; color: var(--text-dim); }
.role-card .rc-dead { color: var(--danger); font-size: 13px; margin-top: 6px; font-weight: 600; }

/* ---------- 播报 + 聊天（右列内部分区、各自滚动）---------- */
.log-box, .chat-box {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.log-box { flex: 1 1 40%; }
.chat-box { flex: 1 1 60%; }
.log-title, .chat-title { padding: 10px 14px; font-size: 13px; font-weight: 700; border-bottom: 1px solid var(--border); flex: 0 0 auto; }
.system-log { flex: 1 1 auto; overflow-y: auto; padding: 8px 14px; }
.system-log .log-item { font-size: 13px; color: var(--text-dim); padding: 3px 0; line-height: 1.5; }

/* ---------- 聊天 ---------- */
.chat-log { flex: 1 1 auto; overflow-y: auto; padding: 10px 14px; display: flex; flex-direction: column; gap: 6px; }
.chat-msg { font-size: 13px; line-height: 1.5; word-break: break-word; }
.chat-msg .cm-name { font-weight: 700; color: var(--accent-2); }
.chat-msg.wolf .cm-name { color: var(--wolf); }
.chat-msg.wolf { color: #ffbfc0; }
.chat-input-row { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--border); flex: 0 0 auto; }
.chat-input-row input { flex: 1; }
.chat-input-row input:disabled { opacity: .5; }

/* ---------- 底部常驻操作条 ---------- */
.action-bar {
  flex: 0 0 auto;
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  padding: 12px 18px;
  max-height: 40vh;
  overflow-y: auto;
}
.action-panel { max-width: 1280px; margin: 0 auto; }
.action-panel h3 { font-size: 15px; margin-bottom: 6px; }
.act-desc { font-size: 13px; color: var(--text-dim); margin-bottom: 10px; }
.act-buttons { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.act-buttons .btn { width: auto; flex: 0 0 auto; }
.act-wait { font-size: 14px; color: var(--text-dim); text-align: center; padding: 4px 0; }
.act-wait b { color: var(--accent-2); }

/* ---------- 结算 ---------- */
.result-panel { width: 100%; max-width: 460px; margin: 0 auto; align-self: center; overflow-y: auto; max-height: 100%; }
.result-banner { text-align: center; font-size: 24px; font-weight: 800; padding: 12px; border-radius: var(--radius); margin-bottom: 14px; }
.result-banner.wolf { background: rgba(229,72,77,.15); color: #ff9ea0; }
.result-banner.good { background: rgba(48,163,108,.15); color: #7ee2b0; }
.reveal-list { display: flex; flex-direction: column; gap: 6px; }
.reveal-item { display: flex; justify-content: space-between; font-size: 14px; padding: 6px 0; border-bottom: 1px solid var(--border); }

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #2a2f3b; color: #fff; padding: 10px 18px; border-radius: 10px;
  font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 100;
  border: 1px solid var(--border);
}
.toast.show { opacity: 1; }

::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-thumb { background: #2c313d; border-radius: 4px; }

/* ---------- 移动端：单列 + 座位网格回退（放弃环形，避免拥挤） ---------- */
@media (max-width: 860px) {
  #view-game.view.active { height: auto; min-height: 100vh; }
  .game-body { flex-direction: column; overflow: visible; height: auto; padding: 12px; }
  .side { flex: 1 1 auto; }
  .stage { overflow: visible; }

  .table { border-radius: 0; min-height: auto; }
  .table::before { display: none; }
  .table-center {
    position: static; transform: none; width: 100%;
    background: var(--bg-panel); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 12px; margin-bottom: 12px;
  }
  /* 座位回退成网格 */
  .seats {
    position: static;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
    gap: 10px;
  }
  .seat { position: static; transform: none; width: auto; }

  .chat-box { max-height: 46vh; }
  .log-box { max-height: 30vh; }

  .action-bar { position: sticky; bottom: 0; max-height: 44vh; }
}
