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

:root {
  --bg-0: #ffffff;
  --bg-1: #f4f4f4;
  --accent: #f59e0b;
  --accent2: #fb7185;
  --text: #1f2937;
  --text-dim: #6b7280;
  --line: rgba(0, 0, 0, 0.08);
  --radius: 18px;
}

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

.hidden { display: none !important; }

/* ---------------- 输入界面 ---------------- */
.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background:
    radial-gradient(900px 600px at 15% -10%, rgba(245, 158, 11, 0.12), transparent 60%),
    radial-gradient(800px 500px at 95% 110%, rgba(251, 113, 133, 0.1), transparent 55%),
    linear-gradient(160deg, #ffffff, #fafafa 60%, #f0f0f0);
  z-index: 20;
}

.lobby-card {
  width: min(92vw, 420px);
  padding: 44px 38px 34px;
  border-radius: 28px;
  background: #ffffff;
  border: 1px solid var(--line);
  box-shadow:
    0 20px 60px rgba(0, 0, 0, 0.08),
    0 2px 6px rgba(0, 0, 0, 0.04);
  text-align: center;
  animation: rise 0.6s cubic-bezier(0.22, 1.2, 0.36, 1) both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(26px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.planet-logo { position: relative; width: 84px; height: 84px; margin: 0 auto 18px; }
.planet-logo .orb {
  position: absolute; inset: 6px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 32% 28%, #fde68a, #f59e0b 50%, #fb7185 85%);
  box-shadow: 0 0 30px rgba(245, 158, 11, 0.35), 0 10px 22px rgba(0,0,0,0.15);
}
.planet-logo .ring {
  position: absolute; inset: -6px -20px;
  border: 3px solid rgba(31, 41, 55, 0.18);
  border-radius: 50%;
  transform: rotate(-22deg) scaleX(1.5);
}
.planet-logo .ring::after {
  content: ""; position: absolute; inset: -3px -14px;
  border: 2px dashed rgba(31, 41, 55, 0.1);
  border-radius: 50%;
}

.title {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: 2px;
  background: linear-gradient(120deg, #f59e0b, #fb7185 60%, #f43f5e);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.subtitle { margin-top: 8px; font-size: 13.5px; color: var(--text-dim); }

.field { margin: 30px 0 22px; text-align: left; }
.field label { display: block; font-size: 13px; color: var(--text-dim); margin-bottom: 10px; font-weight: 600; }

.input-wrap {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  height: 54px;
  border-radius: 14px;
  background: #f9fafb;
  border: 1.5px solid var(--line);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.input-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.14);
}
.input-wrap input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font-size: 17px;
  min-width: 0;
}
.input-wrap input::placeholder { color: #9ca3af; }
#nameCount { font-size: 12px; color: var(--text-dim); white-space: nowrap; }

.hint { margin-top: 8px; font-size: 12.5px; min-height: 16px; color: #dc2626; }

#joinBtn {
  width: 100%;
  height: 56px;
  border: none;
  border-radius: 14px;
  cursor: pointer;
  font-size: 17px;
  font-weight: 700;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: linear-gradient(120deg, var(--accent), var(--accent2));
  box-shadow: 0 10px 24px rgba(245, 158, 11, 0.25);
  transition: transform 0.15s, filter 0.2s;
}
#joinBtn:hover { transform: translateY(-2px); filter: brightness(1.05); }
#joinBtn:active { transform: translateY(0); }
#joinBtn[disabled] { opacity: 0.5; cursor: not-allowed; }
.btn-arrow { font-size: 20px; }

.lobby-status { margin-top: 16px; font-size: 12.5px; color: var(--text-dim); min-height: 16px; }
.lobby-status.err { color: #dc2626; }

/* ---------------- 游戏界面 ---------------- */
.game { position: fixed; inset: 0; }
#world { display: block; width: 100%; height: 100%; background: #fff; cursor: crosshair; }

.hud { position: absolute; display: flex; gap: 10px; z-index: 5; }
.hud-top { top: 16px; left: 16px; right: 16px; justify-content: flex-start; flex-wrap: wrap; pointer-events: none; }

.chip {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px;
  font-size: 13px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  color: var(--text-dim);
}
.chip b { color: var(--text); font-size: 14px; }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: #f59e0b; }
.chip .dot.ok { background: #22C55E; }
.chip .dot.bad { background: #ef4444; }

.hud-right { margin-left: auto; display: flex; gap: 10px; pointer-events: auto; }
.hud-btn {
  padding: 8px 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #ffffff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.2s;
}
.hud-btn:hover { transform: translateY(-2px); border-color: var(--accent); }
.hud-btn:active { transform: translateY(0); }

/* 特殊开关 */
.cheat-btn {
  width: 40px; height: 40px;
  border: 1px solid rgba(245, 158, 11, 0.5);
  border-radius: 12px;
  background: #ffffff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  color: var(--accent);
  font-size: 20px;
  cursor: pointer;
  display: grid; place-items: center;
  transition: transform 0.3s, box-shadow 0.3s;
}
.cheat-btn:hover { transform: rotate(60deg); box-shadow: 0 0 14px rgba(245, 158, 11, 0.35); }
.cheat-btn.unlocked { color: #22C55E; border-color: #22C55E; }

.atk-touch { border-color: rgba(251, 113, 133, 0.55); color: #fb7185; }
.atk-touch:hover { border-color: #fb7185; }

/* 密码弹窗 */
.modal {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  background: rgba(0, 0, 0, 0.35);
  z-index: 30;
  animation: fadeIn 0.2s ease both;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal-card {
  width: min(90vw, 340px);
  padding: 26px 24px 22px;
  border-radius: 18px;
  background: #ffffff;
  border: 1px solid var(--line);
  box-shadow: 0 20px 50px rgba(0,0,0,0.15);
  text-align: center;
  animation: rise 0.3s cubic-bezier(0.22, 1.2, 0.36, 1) both;
}
.mc-title { font-size: 18px; font-weight: 800; color: var(--text); }
.mc-sub { font-size: 12.5px; color: var(--text-dim); margin: 8px 0 16px; }
.modal-card input[type=password] {
  width: 100%; height: 48px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1.5px solid var(--line);
  background: #f9fafb;
  color: var(--text); font-size: 16px; letter-spacing: 1px;
  outline: none;
  transition: border-color 0.2s;
  text-align: center;
}
.modal-card input[type=password]:focus { border-color: var(--accent); }
.mc-err { min-height: 18px; margin-top: 8px; font-size: 12.5px; color: #dc2626; }
.modal-actions { display: flex; gap: 10px; margin-top: 4px; }

/* 按钮 */
.btn {
  flex: 1; height: 44px;
  border: none; border-radius: 12px;
  font-size: 15px; font-weight: 700; cursor: pointer;
  transition: transform 0.15s, filter 0.2s;
}
.btn:hover { transform: translateY(-1px); }
.btn.primary { background: linear-gradient(120deg, var(--accent), var(--accent2)); color: #ffffff; }
.btn.plain { background: #f3f4f6; color: var(--text); border: 1px solid var(--line); }
.btn.green { background: linear-gradient(120deg, #22C55E, #10B981); color: #ffffff; border: none; }
.btn.warn { background: linear-gradient(120deg, #F59E0B, #DC2626); color: #ffffff; border: none; }
.btn.warn.unlocked { background: linear-gradient(120deg, #6B7280, #4B5563); }
.btn.block { width: 100%; margin-top: 6px; }

/* 战斗增强面板 */
.cheat-panel {
  position: absolute; top: 62px; right: 16px;
  width: 250px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  transform-origin: top right;
  animation: panelIn 0.22s ease both;
  z-index: 15;
  box-shadow: 0 12px 32px rgba(0,0,0,0.12);
}
.cp-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px;
  font-size: 14px; font-weight: 700;
  color: var(--accent);
  background: #fffbeb;
  border-bottom: 1px solid var(--line);
}
.cp-close { background: none; border: none; color: var(--text-dim); font-size: 20px; cursor: pointer; line-height: 1; }
.cp-close:hover { color: #dc2626; }
.cp-body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 14px; }
.cp-row { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.cp-name { flex: auto; color: var(--text); }
.cp-val { width: 38px; text-align: right; color: var(--accent); font-weight: 700; white-space: nowrap; }
.cp-row input[type=range] { flex: 1; min-width: 0; accent-color: var(--accent); }
.cp-row input[type=number] {
  width: 80px; height: 34px;
  border-radius: 8px; border: 1.5px solid var(--line);
  background: #f9fafb; color: var(--text);
  text-align: center; outline: none; font-size: 14px;
}
.cp-row input[type=number]:focus { border-color: var(--accent); }
.cp-check { width: 20px; height: 20px; accent-color: var(--accent); }
.cp-hint { font-size: 12px; color: var(--text-dim); line-height: 1.5; }
.cp-hint b { color: var(--accent); }
.cp-hint.small { font-size: 11px; color: #9CA3AF; margin: 4px 0 8px 0; }
.cp-divider { height: 1px; background: var(--line); margin: 12px 0; }

/* 聊天记录 */
.chat-log {
  position: absolute;
  left: 16px; bottom: 78px;
  max-width: min(52vw, 420px);
  display: flex; flex-direction: column; gap: 4px;
  pointer-events: none;
  z-index: 5;
}
.msg-line {
  font-size: 14px;
  line-height: 1.4;
  padding: 5px 12px;
  border-radius: 12px;
  background: rgba(255,255,255,0.92);
  border: 1px solid var(--line);
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
  width: fit-content;
  max-width: 100%;
  animation: msgIn 0.25s ease both;
  color: var(--text);
}
@keyframes msgIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.msg-line .m-name { font-weight: 700; margin-right: 8px; }

/* 聊天输入条 */
.chat-bar {
  position: absolute;
  left: 16px; bottom: 18px;
  display: flex; align-items: center; gap: 8px;
  width: min(52vw, 420px);
  padding: 0 8px 0 16px;
  height: 46px;
  border-radius: 14px;
  background: #ffffff;
  border: 1.5px solid var(--line);
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  z-index: 6;
}
.chat-prefix { font-size: 13px; font-weight: 700; white-space: nowrap; color: var(--text-dim); }
.chat-bar input {
  flex: 1; min-width: 0;
  border: none; outline: none; background: transparent;
  color: var(--text); font-size: 15px;
}

/* 在线成员 */
.member-panel {
  position: absolute;
  top: 62px; right: 16px;
  width: 216px;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(0,0,0,0.1);
  padding: 12px;
  transform-origin: top right;
  animation: panelIn 0.22s ease both;
  z-index: 5;
}
@keyframes panelIn { from { opacity: 0; transform: translateY(-8px) scale(0.98); } to { opacity: 1; transform: none; } }
.member-panel h3 { font-size: 13px; color: var(--text-dim); margin-bottom: 10px; letter-spacing: 1px; }
.member-item {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 6px;
  border-radius: 10px;
  font-size: 14px;
}
.member-item:hover { background: #f9fafb; }
.member-item .av { width: 22px; height: 22px; border-radius: 50%; flex: none; border: 1px solid rgba(0,0,0,0.1); }
.member-item .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member-item .you { margin-left: auto; font-size: 11px; color: var(--accent); }

/* 移动端摇杆 */
.joystick { position: absolute; right: 28px; bottom: 28px; z-index: 8; touch-action: none; }
.js-base {
  width: 110px; height: 110px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.85);
  border: 1.5px solid var(--line);
  box-shadow: 0 4px 14px rgba(0,0,0,0.08);
  position: relative;
}
.js-knob {
  position: absolute; left: 50%; top: 50%;
  width: 46px; height: 46px;
  margin: -23px 0 0 -23px;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, #fff, var(--accent));
  box-shadow: 0 4px 12px rgba(0,0,0,0.18);
}

::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.12); border-radius: 8px; }

/* 头像选择界面 */
.avatar-card { min-width: 360px; }
.pick-name { color: var(--accent); font-weight: 700; }
.avatar-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin: 20px 0 24px;
}
.avatar-item {
  aspect-ratio: 1;
  border-radius: 14px;
  border: 3px solid var(--line);
  overflow: hidden;
  cursor: pointer;
  position: relative;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  background: #fafafa;
}
.avatar-item:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(0,0,0,0.1); }
.avatar-item.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.18);
  transform: translateY(-2px);
}
.avatar-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.avatar-item .check-mark {
  position: absolute;
  top: 6px; right: 6px;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.avatar-item.selected .check-mark { opacity: 1; }
.pick-actions {
  display: flex;
  gap: 10px;
  justify-content: space-between;
}
.pick-actions .btn {
  flex: 1;
  max-width: 160px;
}
.pick-actions .btn.plain {
  flex: 0 0 auto;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text-dim);
}

@media (max-width: 720px) {
  .chat-log, .chat-bar { max-width: calc(100vw - 32px); width: calc(100vw - 32px); }
  .hud-top { top: 10px; }
}
