:root {
  --bg: #0b0f1a;
  --bg2: #131a2b;
  --card: #1a2338;
  --card2: #222d47;
  --line: #2e3c5c;
  --text: #e8edf7;
  --muted: #8b96ad;
  --accent: #4f8cff;
  --accent2: #7c5cff;
  --danger: #ff5c6c;
  --good: #3ddc84;
  --impostor: #ff5c6c;
  --crew: #4fc3f7;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  user-select: none;
  -webkit-user-select: none;
}

body {
  background: radial-gradient(1200px 700px at 50% -10%, #1b2a4d 0%, var(--bg) 60%);
}

.view { position: fixed; inset: 0; display: none; }
.view.active { display: flex; }

input {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  padding: 14px 16px;
  font-size: 16px;
  width: 100%;
  outline: none;
  transition: border .15s;
}
input:focus { border-color: var(--accent); }

.btn {
  border: none; border-radius: 14px; padding: 14px 20px;
  font-size: 16px; font-weight: 600; cursor: pointer;
  transition: transform .06s, filter .15s, opacity .15s;
  color: var(--text);
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent2)); width: 100%; }
.btn-secondary { background: var(--card2); width: 100%; }
.btn-ghost { background: transparent; border: 1px solid var(--line); padding: 10px 16px; font-size: 14px; }
.btn-start { width: 100%; font-size: 18px; padding: 16px; }
.btn-primary:hover { filter: brightness(1.1); }
.btn-secondary:hover { background: #2b3a5c; }
.btn-ghost:hover { background: var(--card2); }

.error { color: var(--danger); min-height: 20px; font-size: 14px; margin-top: 10px; text-align: center; }
.hint { color: var(--muted); font-size: 14px; text-align: center; }
.hidden { display: none !important; }

/* ===== 首页 ===== */
#view-home { align-items: center; justify-content: center; padding: 24px; }
.home-card {
  width: 100%; max-width: 380px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 32px 28px;
  display: flex; flex-direction: column; gap: 18px;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.logo { text-align: center; margin-bottom: 6px; }
.logo-astronaut { font-size: 52px; animation: float 3s ease-in-out infinite; }
.logo h1 { font-size: 32px; letter-spacing: 2px; background: linear-gradient(135deg, #fff, #9db9ff); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
.subtitle { color: var(--muted); font-size: 14px; margin-top: 4px; }
.field { display: flex; flex-direction: column; gap: 8px; }
.field label { font-size: 13px; color: var(--muted); }
.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 12px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

@keyframes float { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }

/* ===== 大厅 ===== */
#view-lobby { align-items: center; justify-content: center; padding: 20px; }
.lobby-wrap {
  width: 100%; max-width: 560px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 24px;
  display: flex; flex-direction: column; gap: 20px;
}
.lobby-header { display: flex; align-items: center; justify-content: space-between; }
.room-label { font-size: 12px; color: var(--muted); }
.room-code { font-size: 34px; font-weight: 800; letter-spacing: 6px; }
.players-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 12px; }
.player-chip {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 14px;
  padding: 14px 8px; text-align: center; display: flex; flex-direction: column; gap: 8px; align-items: center;
}
.player-chip .dot { width: 34px; height: 34px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 18px; }
.player-chip .pname { font-size: 13px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-chip .pbadge { font-size: 11px; color: var(--accent); }
.player-chip.dead { opacity: .4; }
.lobby-footer { display: flex; flex-direction: column; gap: 12px; }

/* ===== 游戏画布 ===== */
#view-game { background: #0a0e18; }
#game-canvas { width: 100%; height: 100%; display: block; touch-action: none; }

.hud-top { position: absolute; top: 12px; left: 12px; right: 12px; display: flex; justify-content: space-between; pointer-events: none; }
.hud-role {
  background: rgba(0,0,0,.55); backdrop-filter: blur(6px);
  padding: 10px 16px; border-radius: 12px; font-size: 15px; font-weight: 600;
}
.hud-role.impostor { color: var(--impostor); }
.hud-role.crewmate { color: var(--crew); }
.hud-count {
  background: rgba(0,0,0,.55); padding: 10px 16px; border-radius: 12px;
  font-size: 14px; color: var(--muted);
}

.hud-actions {
  position: absolute; bottom: 24px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 12px; pointer-events: auto;
}
.action-btn {
  background: rgba(20,28,48,.9); border: 1px solid var(--line); color: var(--text);
  border-radius: 14px; padding: 14px 18px; font-size: 15px; font-weight: 600; cursor: pointer;
  backdrop-filter: blur(6px);
}
.action-btn:active { transform: scale(.96); }
.action-btn:disabled { opacity: .35; cursor: not-allowed; }
.action-btn.active { border-color: var(--danger); color: var(--danger); }

.hud-toast {
  position: absolute; top: 70px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,.7); color: #fff; padding: 10px 20px; border-radius: 20px;
  font-size: 14px; opacity: 0; transition: opacity .25s; pointer-events: none; max-width: 86vw; text-align: center;
}
.hud-toast.show { opacity: 1; }

.btn-roster { position: absolute; top: 12px; right: 12px; font-size: 18px; }
.roster-panel {
  position: absolute; top: 60px; right: 12px; width: 200px;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 12px; display: flex; flex-direction: column; gap: 8px; max-height: 60vh; overflow-y: auto;
}
.roster-item { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.roster-item .rdot { width: 16px; height: 16px; border-radius: 50%; flex-shrink: 0; }
.roster-item.dead { opacity: .4; text-decoration: line-through; }

/* 虚拟摇杆 */
.joystick {
  position: absolute; left: 28px; bottom: 30px; width: 120px; height: 120px;
  background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.12);
  border-radius: 50%; display: none; touch-action: none;
}
.joystick.active { display: block; }
.joystick-knob {
  position: absolute; left: 50%; top: 50%; width: 52px; height: 52px;
  margin: -26px 0 0 -26px; border-radius: 50%;
  background: rgba(255,255,255,.35); pointer-events: none;
}

/* ===== 会议 / 结束 弹层 ===== */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.75); backdrop-filter: blur(4px);
  display: none; align-items: center; justify-content: center; padding: 20px; z-index: 50;
}
.overlay.active { display: flex; }

.meeting-card {
  width: 100%; max-width: 560px; max-height: 92vh;
  background: var(--card); border: 1px solid var(--line); border-radius: 24px;
  padding: 24px; display: flex; flex-direction: column; gap: 14px; overflow-y: auto;
}
.meeting-title { font-size: 22px; font-weight: 800; text-align: center; }
.meeting-chat {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 14px;
  padding: 12px; height: 200px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px;
}
.chat-msg { font-size: 14px; line-height: 1.4; word-break: break-word; }
.chat-msg .cname { font-weight: 700; }
.chat-msg.dead .cname { text-decoration: line-through; }
.meeting-input { display: flex; gap: 8px; }
.meeting-input input { flex: 1; }
.meeting-input .btn { width: auto; }
.meeting-vote-title { font-size: 15px; font-weight: 700; margin-top: 6px; }
.vote-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.vote-item {
  background: var(--bg2); border: 2px solid var(--line); border-radius: 14px;
  padding: 12px; text-align: center; cursor: pointer; font-size: 14px; font-weight: 600;
  display: flex; flex-direction: column; gap: 6px; align-items: center;
}
.vote-item .vdot { width: 22px; height: 22px; border-radius: 50%; }
.vote-item.selected { border-color: var(--accent); background: #1e2c4d; }
.vote-item.voted { opacity: .45; pointer-events: none; }
.meeting-result { font-size: 16px; font-weight: 700; text-align: center; min-height: 24px; }
.vote-status { font-size: 13px; color: var(--muted); text-align: center; }

.end-card {
  width: 100%; max-width: 440px;
  background: var(--card); border: 1px solid var(--line); border-radius: 24px;
  padding: 32px 28px; display: flex; flex-direction: column; gap: 14px; align-items: center; text-align: center;
}
.end-emoji { font-size: 60px; }
.end-card h2 { font-size: 28px; }
.end-sub { color: var(--muted); font-size: 14px; }
.reveal-list { width: 100%; display: flex; flex-direction: column; gap: 8px; max-height: 40vh; overflow-y: auto; }
.reveal-item {
  display: flex; align-items: center; gap: 12px; background: var(--bg2);
  border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; font-size: 14px;
}
.reveal-item .rdot { width: 16px; height: 16px; border-radius: 50%; flex-shrink: 0; }
.reveal-item .rrole { margin-left: auto; font-weight: 700; }
.reveal-item .rrole.impostor { color: var(--impostor); }
.reveal-item .rrole.crewmate { color: var(--crew); }
.reveal-item.dead { opacity: .5; text-decoration: line-through; }
