:root {
  --bg: #0b0a14;
  --bg2: #14121f;
  --card: rgba(30, 27, 48, .82);
  --line: #322c4d;
  --text: #e8eaf0;
  --dim: #9aa1b5;
  --accent: #7c5cff;
  --accent2: #00d4a6;
  --danger: #ff5c7a;
  --warn: #ffb84d;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 15px;
}

/* 星空背景（纯 CSS，零图片） */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -2;
  background:
    radial-gradient(ellipse at 20% -10%, rgba(124, 92, 255, .25), transparent 55%),
    radial-gradient(ellipse at 85% 110%, rgba(0, 212, 166, .12), transparent 50%),
    linear-gradient(180deg, #0b0a14 0%, #141126 60%, #0b0a14 100%);
}
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background-image:
    radial-gradient(1.5px 1.5px at 25px 35px, rgba(255,255,255,.8), transparent),
    radial-gradient(1px 1px at 120px 90px, rgba(255,255,255,.55), transparent),
    radial-gradient(1.2px 1.2px at 220px 40px, rgba(255,255,255,.7), transparent),
    radial-gradient(1px 1px at 320px 130px, rgba(255,255,255,.45), transparent),
    radial-gradient(1.6px 1.6px at 420px 70px, rgba(255,255,255,.75), transparent),
    radial-gradient(1px 1px at 520px 150px, rgba(255,255,255,.5), transparent),
    radial-gradient(1.3px 1.3px at 620px 30px, rgba(255,255,255,.65), transparent),
    radial-gradient(1px 1px at 90px 210px, rgba(255,255,255,.5), transparent),
    radial-gradient(1.2px 1.2px at 300px 260px, rgba(255,255,255,.6), transparent),
    radial-gradient(1px 1px at 550px 300px, rgba(255,255,255,.45), transparent);
  background-repeat: repeat;
  background-size: 700px 340px;
  animation: twinkle 6s ease-in-out infinite alternate;
  pointer-events: none;
}
@keyframes twinkle { from { opacity: .55; } to { opacity: 1; } }

.hidden { display: none !important; }

.screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ---------- 大厅 / 结算 ---------- */
#lobby, #gameover {
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.lobby-card {
  width: 100%;
  max-width: 460px;
  background: var(--card);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 32px 28px;
  text-align: center;
  box-shadow: 0 18px 60px rgba(0, 0, 0, .45);
  animation: rise .5s ease both;
}
@keyframes rise { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }

.lobby-card h1 {
  font-size: 42px;
  letter-spacing: 4px;
  margin-bottom: 10px;
  text-shadow: 0 0 24px rgba(124, 92, 255, .6);
}

.accent { color: var(--accent); }

.tagline { color: var(--dim); margin-bottom: 18px; }

.rules {
  text-align: left;
  background: rgba(10, 9, 20, .55);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 20px;
  color: var(--dim);
  line-height: 1.9;
  font-size: 14px;
}
.rules b { color: var(--text); }

.stats-line {
  margin-top: 12px;
  color: var(--dim);
  font-size: 13px;
}
.stats-line b { color: var(--accent2); }

#playerName {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(10, 9, 20, .6);
  color: var(--text);
  font-size: 15px;
  margin-bottom: 14px;
  outline: none;
}
#playerName:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(124, 92, 255, .18); }

.btn-primary {
  width: 100%;
  padding: 13px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(135deg, #7c5cff, #5a3ee0);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform .12s, box-shadow .12s, opacity .15s;
  box-shadow: 0 6px 20px rgba(124, 92, 255, .35);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 8px 26px rgba(124, 92, 255, .5); }
.btn-primary:active { transform: none; }
.btn-primary:disabled { opacity: .4; cursor: not-allowed; box-shadow: none; }

.hint { margin-top: 12px; color: var(--warn); font-size: 13px; min-height: 18px; }

/* ---------- 游戏主界面 ---------- */
#game {
  height: 100vh;
  height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
}

#topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px 8px;
  background: rgba(16, 14, 28, .9);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.tb-item { font-size: 14px; color: var(--dim); }
.tb-phase { color: var(--text); font-weight: 600; }
.tb-timer { font-variant-numeric: tabular-nums; font-size: 18px; font-weight: 700; color: var(--accent2); }
.tb-timer.urgent { color: var(--danger); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .45; } }

/* 阶段倒计时进度条 */
#phaseBar {
  height: 3px;
  background: rgba(255, 255, 255, .07);
  overflow: hidden;
}
#phaseBar > div {
  height: 100%;
  width: 100%;
  background: var(--accent2);
  transition: width 1s linear, background-color .3s;
}
#phaseBar.vote > div { background: var(--danger); }

#playersBar {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  overflow-x: auto;
  background: rgba(16, 14, 28, .85);
  border-bottom: 1px solid var(--line);
}

.pchip {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 6px 8px;
  border-radius: 10px;
  border: 1px solid transparent;
  min-width: 56px;
  position: relative;
  transition: opacity .6s, filter .6s;
}

.pchip .avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px; color: #fff;
  box-shadow: 0 0 10px rgba(255, 255, 255, .14);
}

.pchip .pname { font-size: 12px; color: var(--text); max-width: 64px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pchip .ptag { font-size: 10px; color: var(--accent2); }
.pchip.dead { opacity: .3; filter: grayscale(1); }
.pchip.dead .pname { text-decoration: line-through; }
.pchip.me { border-color: var(--accent); box-shadow: 0 0 12px rgba(124, 92, 255, .25); }

#chat {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg { display: flex; gap: 8px; max-width: 92%; animation: msgIn .25s ease both; }
@keyframes msgIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.msg .avatar {
  flex: 0 0 32px;
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px; color: #fff;
}
.msg .bubble {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 4px 12px 12px 12px;
  padding: 8px 12px;
}
.msg .who { font-size: 12px; color: var(--dim); margin-bottom: 3px; }
.msg .text { line-height: 1.55; word-break: break-word; }

.msg.mine { align-self: flex-end; flex-direction: row-reverse; }
.msg.mine .bubble { background: rgba(53, 43, 110, .85); border-color: #4a3f85; border-radius: 12px 4px 12px 12px; }

.msg.sys { align-self: center; max-width: 100%; }
.msg.sys .sysbubble {
  background: rgba(16, 14, 28, .8);
  border: 1px dashed var(--line);
  color: var(--dim);
  font-size: 13px;
  padding: 6px 14px;
  border-radius: 999px;
  text-align: center;
}
.msg.sys .sysbubble.important { color: var(--warn); border-color: var(--warn); animation: flash .8s ease; }
.msg.sys .sysbubble.secret { color: var(--accent2); border-color: var(--accent2); }
@keyframes flash { 0%, 100% { box-shadow: none; } 40% { box-shadow: 0 0 22px rgba(255, 184, 77, .55); } }

/* 正在输入指示 */
#typingBar {
  padding: 0 14px 6px;
  color: var(--dim);
  font-size: 12.5px;
  min-height: 20px;
  font-style: italic;
}
#typingBar .dots::after {
  content: "";
  animation: dots 1.2s steps(4) infinite;
}
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }

/* ---------- 投票 ---------- */
#votePanel {
  background: rgba(24, 18, 32, .95);
  border-top: 1px solid var(--warn);
  padding: 10px 12px;
  animation: msgIn .25s ease both;
}

.vote-title { font-size: 13px; color: var(--warn); margin-bottom: 8px; text-align: center; }

#voteCards { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }

.vcard {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card);
  cursor: pointer;
  font-size: 14px;
  color: var(--text);
  transition: all .12s;
}
.vcard .avatar {
  width: 22px; height: 22px; font-size: 11px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700;
}
.vcard:hover { border-color: var(--warn); transform: translateY(-1px); }
.vcard.selected { border-color: var(--danger); background: rgba(70, 25, 40, .9); box-shadow: 0 0 14px rgba(255, 92, 122, .35); }
.vcard:disabled { opacity: .35; cursor: not-allowed; }
.vcard .votes { color: var(--danger); font-weight: 700; margin-left: 2px; }

/* ---------- 输入栏 ---------- */
#inputBar {
  display: flex;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: rgba(16, 14, 28, .9);
  border-top: 1px solid var(--line);
}

#msgInput {
  flex: 1;
  padding: 11px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(10, 9, 20, .65);
  color: var(--text);
  font-size: 15px;
  outline: none;
}
#msgInput:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(124, 92, 255, .16); }
#msgInput:disabled { opacity: .4; }

#sendBtn { width: auto; padding: 11px 22px; border-radius: 999px; }

/* ---------- 结算 ---------- */
#resultTitle.win { color: var(--accent2); text-shadow: 0 0 24px rgba(0, 212, 166, .5); }
#resultTitle.lose { color: var(--danger); text-shadow: 0 0 24px rgba(255, 92, 122, .5); }

#roleTable {
  text-align: left;
  background: rgba(10, 9, 20, .55);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 16px;
  margin-bottom: 16px;
  line-height: 2;
  font-size: 14px;
}
#roleTable .r-ai { color: var(--danger); font-weight: 700; }
#roleTable .r-uw { color: var(--warn); font-weight: 700; }
#roleTable .r-hu { color: var(--accent2); }
#roleTable .r-me { color: var(--accent); font-weight: 700; }

.typing::after {
  content: "▋";
  animation: blink .8s infinite;
  color: var(--accent2);
}
@keyframes blink { 50% { opacity: 0; } }

/* ---------- 第二轮：音效开关 / 复盘面板 ---------- */
.tb-sound {
  background: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  padding: 2px 8px;
  cursor: pointer;
  line-height: 1.4;
}
.tb-sound.off { opacity: .45; }

#replayPanel {
  text-align: left;
  background: rgba(10, 9, 20, .55);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 16px;
  max-height: 320px;
  overflow-y: auto;
  font-size: 13px;
  line-height: 1.7;
  color: var(--dim);
}
#replayPanel .rp-line { margin-bottom: 5px; word-break: break-word; }
#replayPanel .rp-sys { color: var(--warn); font-size: 12.5px; }
#replayPanel .rp-role { margin-left: 3px; }
