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

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background: #87ceeb;
}

#app, #app canvas { position: fixed; inset: 0; display: block; }

.hidden { display: none !important; }

/* ---------- 菜单 ---------- */
.overlay {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(20, 30, 50, 0.55);
  backdrop-filter: blur(6px);
  z-index: 20;
}

.panel {
  background: #fffdf5;
  border-radius: 18px;
  padding: 32px 36px;
  width: min(420px, 92vw);
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
  text-align: center;
}

.panel h1 { font-size: 32px; color: #2b2b3a; letter-spacing: 1px; }
.panel .sub { color: #888; margin: 6px 0 20px; font-size: 14px; }

.panel label {
  display: block; text-align: left;
  font-size: 13px; color: #666; margin-bottom: 12px;
}
.panel input {
  display: block; width: 100%; margin-top: 4px;
  padding: 10px 12px; font-size: 16px;
  border: 2px solid #ddd; border-radius: 10px; outline: none;
}
.panel input:focus { border-color: #4a90d9; }

#join-btn {
  width: 100%; padding: 12px; margin-top: 6px;
  font-size: 18px; font-weight: bold; color: #fff;
  background: linear-gradient(135deg, #4a90d9, #7b5cd6);
  border: none; border-radius: 10px; cursor: pointer;
}
#join-btn:disabled { opacity: 0.6; cursor: wait; }

#menu-error { color: #d94a4a; font-size: 13px; min-height: 18px; margin-top: 8px; }

.help {
  margin-top: 16px; padding-top: 14px;
  border-top: 1px dashed #ddd;
  display: flex; flex-wrap: wrap; gap: 6px 14px; justify-content: center;
  font-size: 12px; color: #777;
}
.help b { color: #2b2b3a; background: #eee; border-radius: 4px; padding: 1px 5px; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }

#hud-top-left {
  position: absolute; top: 12px; left: 14px;
  color: #fff; text-shadow: 0 1px 3px rgba(0,0,0,0.5);
  font-size: 14px; line-height: 1.6;
}
#hud-room { font-weight: bold; }

#hud-speed {
  position: absolute; right: 18px; bottom: 16px;
  font-size: 42px; font-weight: 800; color: #fff;
  text-shadow: 0 2px 8px rgba(0,0,0,0.5);
}
#hud-speed::after { content: " km/h"; font-size: 14px; font-weight: 400; }

/* ---------- 聊天 ---------- */
#chat {
  position: fixed; left: 14px; bottom: 14px;
  width: min(340px, 70vw); z-index: 11;
}
#chat-log {
  max-height: 180px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 4px;
  margin-bottom: 6px;
  mask-image: linear-gradient(to bottom, transparent, #000 20%);
}
#chat-log .msg {
  background: rgba(0,0,0,0.45); color: #fff;
  border-radius: 8px; padding: 4px 10px;
  font-size: 13px; width: fit-content; max-width: 100%;
  word-break: break-word;
}
#chat-log .msg.sys { color: #ffd97b; font-style: italic; }
#chat-log .msg .nick { color: #8fd3ff; font-weight: bold; margin-right: 4px; }
#chat-input {
  width: 100%; padding: 8px 12px; font-size: 14px;
  border: none; border-radius: 8px; outline: none;
  background: rgba(255,255,255,0.92);
  display: none;
}
#chat-input.open { display: block; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; top: 18px; left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.65); color: #fff;
  padding: 8px 18px; border-radius: 20px;
  font-size: 14px; z-index: 30;
  opacity: 0; transition: opacity 0.25s;
  pointer-events: none;
}
#toast.show { opacity: 1; }

/* ---------- 移动端按键 ---------- */
#touch-controls {
  position: fixed; inset: auto 0 0 0;
  display: flex; justify-content: space-between;
  padding: 0 16px 20px; z-index: 12;
  pointer-events: none;
}
#touch-controls > div { display: flex; gap: 12px; align-items: flex-end; }
#touch-controls button {
  pointer-events: auto;
  width: 62px; height: 62px; border-radius: 50%;
  border: none; font-size: 24px;
  background: rgba(255,255,255,0.75);
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
  touch-action: none; user-select: none;
}
#touch-controls button:active { background: #ffd97b; }

@media (pointer: coarse) {
  #hud-speed { bottom: 100px; }
}
