:root {
  --bg: #0e1017;
  --bg2: #151a26;
  --card: #1b2130;
  --line: #2a3244;
  --text: #e9edf6;
  --muted: #93a0b8;
  --primary: #6c8cff;
  --primary2: #8f6cff;
  --danger: #ff6b6b;
  --ok: #49d59a;
  --warn: #ffc857;
}

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

html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(1200px 600px at 50% -10%, #1a2136 0%, var(--bg) 60%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Noto Sans SC', 'Microsoft YaHei', sans-serif;
  min-height: 100%;
}

.app {
  max-width: 520px;
  margin: 0 auto;
  padding: 16px 16px calc(24px + env(safe-area-inset-bottom));
}

.screen { display: none; }
.screen.active { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.hidden { display: none !important; }

/* 入口 */
.hero { text-align: center; padding: 34px 0 18px; }
.logo { font-size: 56px; line-height: 1; }
.hero h1 { font-size: 30px; margin: 10px 0 4px; letter-spacing: 1px; }
.sub { color: var(--muted); font-size: 13px; margin: 0; }

.field { display: block; margin: 14px 0; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field em { font-style: normal; opacity: .7; }

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

.btn {
  display: block;
  width: 100%;
  border: none;
  border-radius: 12px;
  padding: 14px;
  font-size: 16px;
  font-weight: 600;
  color: #fff;
  background: var(--card);
  margin-top: 12px;
  cursor: pointer;
  transition: transform .06s ease, filter .15s ease;
}
.btn:active { transform: scale(.985); }
.btn.primary { background: linear-gradient(135deg, var(--primary), var(--primary2)); }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--text); }
.btn.small { padding: 9px 14px; font-size: 13px; width: auto; margin-top: 0; }
.btn.big { padding: 16px; font-size: 17px; }
.btn:disabled { opacity: .5; }

.err { color: var(--danger); font-size: 13px; min-height: 18px; margin: 10px 0 0; }

/* 顶栏 */
.topbar { display: flex; justify-content: space-between; align-items: center; margin: 6px 0 16px; gap: 10px; }
.label { font-size: 12px; color: var(--muted); }
.code { font-size: 26px; font-weight: 700; letter-spacing: 3px; }
.code.small { font-size: 15px; letter-spacing: 2px; color: var(--muted); }

.badge {
  padding: 7px 12px;
  border-radius: 999px;
  font-size: 13px;
  background: var(--card);
  border: 1px solid var(--line);
  white-space: nowrap;
}
.badge.civilian { color: var(--ok); border-color: rgba(73,213,154,.4); }
.badge.undercover { color: var(--danger); border-color: rgba(255,107,107,.45); }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  margin: 14px 0;
}
.cardTitle { font-size: 13px; color: var(--muted); margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.card.hint { font-size: 13px; color: var(--muted); line-height: 1.65; }
.card.hint b { color: var(--text); }
.card.hint p { margin: 6px 0 0; }

.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: #232b3d;
  color: var(--muted);
  font-size: 12px;
}

/* 玩家列表 */
.players { list-style: none; margin: 0; padding: 0; }
.players li {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 4px;
  border-bottom: 1px solid rgba(255,255,255,.05);
  font-size: 15px;
}
.players li:last-child { border-bottom: none; }
.players li.out { opacity: .45; text-decoration: line-through; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #2f3a55, #3b2f55);
  font-size: 14px;
}
.dot { width: 7px; height: 7px; border-radius: 50%; background: #4a5468; margin-left: auto; }
.dot.on { background: var(--ok); }
.tag { font-size: 11px; padding: 2px 7px; border-radius: 6px; background: #2a3450; color: var(--muted); }

/* 词卡 */
.wordCard {
  text-align: center;
  padding: 24px 14px;
  border-radius: 18px;
  background: linear-gradient(160deg, #232c44, #1a2033);
  border: 1px solid var(--line);
  margin: 6px 0 14px;
}
.wordCard .word { font-size: 34px; font-weight: 800; letter-spacing: 2px; margin: 8px 0 4px; }
.wordCard .role { font-size: 13px; color: var(--muted); }

.banner {
  text-align: center;
  font-size: 15px;
  padding: 12px;
  border-radius: 12px;
  background: rgba(108,140,255,.12);
  border: 1px solid rgba(108,140,255,.28);
  margin-bottom: 6px;
}
.banner.me { background: rgba(73,213,154,.12); border-color: rgba(73,213,154,.32); }

/* 发言 */
.desc { list-style: none; margin: 0; padding: 0; }
.desc li { padding: 9px 0; border-bottom: 1px dashed rgba(255,255,255,.06); font-size: 15px; line-height: 1.5; }
.desc li:last-child { border-bottom: none; }
.desc b { color: var(--primary); font-weight: 600; margin-right: 8px; }
.desc .count { color: var(--warn); margin-left: 8px; font-size: 13px; }

.row { display: flex; gap: 8px; }
.row input { flex: 1; }
.row .btn { width: auto; padding: 14px 18px; margin-top: 0; }

/* 投票 */
.vote { list-style: none; margin: 0; padding: 0; }
.vote li { margin: 8px 0; }
.vote button {
  width: 100%;
  text-align: left;
  padding: 13px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg2);
  color: var(--text);
  font-size: 15px;
  cursor: pointer;
}
.vote button.chosen { border-color: var(--primary); background: rgba(108,140,255,.14); }
.vote button:disabled { opacity: .55; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 30px;
  transform: translate(-50%, 20px);
  background: #2c3550;
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: all .2s ease;
  max-width: 86vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---- 两步投票 ---- */
.vrow {
  display: flex; align-items: center; gap: 8px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--bg2); padding: 4px;
}
.vrow.sel { border-color: var(--primary); background: rgba(108,140,255,.12); }
.vrow.voted { border-color: rgba(73,213,154,.4); }
.vname {
  flex: 1; text-align: left; padding: 12px;
  background: transparent; border: none; color: var(--text);
  font-size: 16px; cursor: pointer;
}
.vact {
  width: 46px; height: 42px; border-radius: 10px; border: none;
  font-size: 18px; font-weight: 700; cursor: pointer; color: #fff;
}
.vact.cancel { background: #3a2b33; color: #ff8a8a; }
.vact.confirm { background: linear-gradient(135deg, var(--primary), var(--primary2)); }
.vok { color: var(--ok); font-size: 13px; padding-right: 12px; }

/* ---- 点歌面板 ---- */
.sheet {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(6,8,14,.72);
  display: flex; align-items: flex-end; justify-content: center;
  backdrop-filter: blur(2px);
}
.sheetCard {
  width: 100%; max-width: 520px; max-height: 82vh; overflow-y: auto;
  background: var(--bg2);
  border: 1px solid var(--line); border-bottom: none;
  border-radius: 18px 18px 0 0;
  padding: 16px 16px calc(20px + env(safe-area-inset-bottom));
  animation: sheetUp .2s ease;
}
@keyframes sheetUp { from { transform: translateY(30px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheetHead { display: flex; align-items: center; justify-content: space-between; }

.nowPlaying {
  display: flex; align-items: center; gap: 12px;
  margin-top: 12px; padding: 10px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
}
.npArt { width: 46px; height: 46px; border-radius: 8px; object-fit: cover; background: #2a3147; }
.npInfo { flex: 1; min-width: 0; }
.npTitle { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.npSub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.tracks { list-style: none; margin: 8px 0 0; padding: 0; }
.track {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 0; border-bottom: 1px solid rgba(255,255,255,.05);
}
.track:last-child { border-bottom: none; }
.cov { width: 40px; height: 40px; border-radius: 8px; object-fit: cover; background: #2a3147; }
.covEmpty { display: grid; place-items: center; color: var(--muted); font-size: 18px; }
.tinfo { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.tinfo b { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tinfo em { font-style: normal; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.muted { color: var(--muted); font-size: 13px; padding: 8px 0; list-style: none; }

.soundHint {
  position: fixed; left: 50%; bottom: 80px; transform: translateX(-50%);
  background: linear-gradient(135deg, var(--primary), var(--primary2));
  color: #fff; padding: 12px 20px; border-radius: 999px;
  font-size: 14px; font-weight: 600; z-index: 60; cursor: pointer;
  box-shadow: 0 8px 24px rgba(108,140,255,.35);
}

.tbRight { display: flex; gap: 8px; align-items: center; }
.tbRight .btn { width: auto; }

/* ---- 游戏选择 ---- */
.games { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.gameCard {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 14px 8px; border-radius: 14px;
  background: var(--bg2); border: 1px solid var(--line);
  color: var(--text); cursor: default; font-family: inherit;
}
.gameCard.clickable { cursor: pointer; }
.gameCard.active { border-color: var(--primary); background: rgba(108,140,255,.12); box-shadow: 0 0 0 1px rgba(108,140,255,.35) inset; }
.gameCard .gIcon { font-size: 26px; }
.gameCard b { font-size: 15px; }
.gameCard em { font-style: normal; font-size: 11px; color: var(--muted); }

/* ---- 画板 ---- */
.boardWrap {
  width: 100%; aspect-ratio: 4 / 3;
  border-radius: 16px; overflow: hidden;
  border: 1px solid var(--line);
  background: #141a28;
  margin: 8px 0 12px;
}
#board { width: 100%; height: 100%; display: block; touch-action: none; }

.tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.palette { display: flex; gap: 8px; flex: 1; }
.swatch {
  width: 30px; height: 30px; border-radius: 50%;
  border: 2px solid transparent; cursor: pointer; padding: 0;
}
.swatch.on { border-color: #fff; box-shadow: 0 0 0 2px rgba(255,255,255,.25); }
.toolRow { display: flex; gap: 8px; }
.btn.on { background: rgba(108,140,255,.25); border-color: var(--primary); }

/* ---- 电子斗蛐蛐 ---- */
.arena {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 10px 0;
}
.bug {
  background: linear-gradient(160deg, #232c44, #1a2033);
  border: 1px solid var(--line); border-radius: 14px;
  padding: 10px 12px; transition: opacity .2s ease;
}
.bug.dead { opacity: .35; filter: grayscale(1); }
.bugTop { display: flex; align-items: center; gap: 6px; }
.bugEmoji { font-size: 20px; }
.bugName { font-weight: 700; font-size: 15px; }
.bugOwner { font-size: 11px; color: var(--muted); margin: 2px 0 8px; }
.hpBar { height: 8px; border-radius: 999px; background: #0f1420; overflow: hidden; }
.hpBar i { display: block; height: 100%; transition: width .35s ease; }
.hpHigh { background: linear-gradient(90deg, #49d59a, #6c8cff); }
.hpMid { background: linear-gradient(90deg, #ffc857, #ff9f43); }
.hpLow { background: linear-gradient(90deg, #ff6b6b, #c0392b); }
.bugHp { font-size: 11px; color: var(--muted); margin-top: 4px; }
.bugStats { font-size: 11px; color: var(--muted); margin-top: 2px; }

.arenaWrap { width: 100%; aspect-ratio: 1 / 1; border-radius: 16px; overflow: hidden; border: 1px solid var(--line); margin: 8px 0 12px; background: #121828; }
#cArena { width: 100%; height: 100%; display: block; }

/* 角色选择 */
.styles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.styleBtn {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 10px 6px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg2); color: var(--text); cursor: pointer; font-family: inherit;
}
.styleBtn .stEmoji { font-size: 20px; }
.styleBtn b { font-size: 13px; }
.styleBtn i { font-style: normal; font-size: 11px; color: var(--muted); }
.styleBtn.on { border-color: var(--primary); background: rgba(108,140,255,.16); box-shadow: 0 0 0 1px rgba(108,140,255,.4) inset; }

/* 枪战 */
.shootWrap { width: 100%; aspect-ratio: 1 / 1; border-radius: 16px; overflow: hidden; border: 1px solid var(--line); margin: 8px 0; background: #0d1220; }
#sCanvas { width: 100%; height: 100%; display: block; touch-action: none; }
.scorebar { display: flex; gap: 10px; overflow-x: auto; padding: 4px 2px 8px; }
.sPlayer { display: flex; flex-direction: column; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; min-width: 78px; }
.sPlayer b { font-size: 13px; }
.sPlayer i { font-style: normal; font-size: 12px; color: var(--primary); }

/* 枪战 3D 控件 */
.shootControls { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 10px; }
.joyHint { font-size: 12px; color: var(--muted); }
.btns { display: flex; align-items: center; gap: 8px; }
.fireBtn {
  width: 84px; height: 84px; border-radius: 50%; border: none;
  background: radial-gradient(circle at 35% 30%, #ff8a8a, #d63b3b);
  color: #fff; font-size: 16px; font-weight: 700; font-family: inherit;
  box-shadow: 0 6px 18px rgba(214,59,59,.45);
  touch-action: none;
}
.fireBtn:active { transform: scale(.94); }
.shootWrap { aspect-ratio: 1 / 1; }
#sCanvas { width: 100%; height: 100%; display: block; touch-action: none; }
