*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #1a1a2e;
  color: #fff;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  touch-action: none;
}

#game-container {
  position: absolute;
  inset: 0;
  z-index: 1;
}

#ui {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

#ui > * {
  pointer-events: auto;
}

#lobby {
  background: rgba(26, 26, 46, 0.95);
  border: 1px solid #333;
  border-radius: 12px;
  padding: 2rem;
  max-width: 90vw;
  width: 360px;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

#lobby h1 {
  margin: 0 0 1.5rem;
  font-size: 1.75rem;
}

#lobby button {
  width: 100%;
  padding: 0.75rem;
  font-size: 1rem;
  border: none;
  border-radius: 8px;
  background: #4f46e5;
  color: #fff;
  cursor: pointer;
  margin-bottom: 0.75rem;
}

#lobby button:hover {
  background: #4338ca;
}

#lobby button:disabled {
  background: #555;
  cursor: not-allowed;
}

#hud {
  position: absolute;
  top: 1rem;
  left: 1rem;
  z-index: 20;
  background: rgba(26, 26, 46, 0.9);
  border: 1px solid #333;
  border-radius: 8px;
  padding: 0.75rem;
  min-width: 160px;
  pointer-events: none;
}

#hudHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.hud-title {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #888;
}

#hudToggle {
  pointer-events: auto;
  flex: none;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 1px solid #333;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  color: #ccc;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}

#hudToggle:hover {
  background: rgba(255, 255, 255, 0.18);
}

#hudBody {
  margin-top: 0.6rem;
}

#hud.collapsed {
  min-width: 0;
}

#hud.collapsed #hudBody {
  display: none;
}

.hud-section {
  margin-bottom: 0.75rem;
}

.hud-section:last-child {
  margin-bottom: 0;
}

.hud-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #888;
  margin-bottom: 0.25rem;
}

.hud-value {
  font-size: 1rem;
  font-weight: 600;
}

#hudPlayerList {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 0.875rem;
}

#hudPlayerList li {
  padding: 0.15rem 0;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

#hudPlayerList .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
}

#hudPlayerList .you {
  color: #a5b4fc;
}

#hudPlayerList .kd {
  margin-left: auto;
  font-variant-numeric: tabular-nums;
  color: #c9c9ce;
  font-size: 0.8rem;
}

.joinRow {
  display: flex;
  gap: 0.5rem;
}

.joinRow input {
  flex: 1;
  padding: 0.75rem;
  font-size: 1rem;
  border: 1px solid #444;
  border-radius: 8px;
  background: #222;
  color: #fff;
  text-transform: uppercase;
}

.joinRow button {
  width: auto;
  margin-bottom: 0;
}

#status {
  margin-top: 1rem;
  min-height: 1.5rem;
  color: #aaa;
  font-size: 0.875rem;
}

.hidden {
  display: none !important;
}

/* Lobby: open rooms list */
#roomList {
  margin-top: 1.25rem;
  text-align: left;
}

.roomList-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.link-btn {
  background: none !important;
  border: none;
  color: #a5b4fc;
  cursor: pointer;
  font-size: 0.8rem;
  padding: 0;
  margin: 0 !important;
}

#roomListItems {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 220px;
  overflow-y: auto;
}

#roomListItems li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.5rem;
  border: 1px solid #333;
  border-radius: 6px;
  margin-bottom: 0.4rem;
}

#roomListItems .room-id {
  font-weight: 600;
  letter-spacing: 0.05em;
}

#roomListItems .room-count {
  margin-left: auto;
  color: #aaa;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

#roomListItems .room-join {
  margin: 0 !important;
  padding: 0.3rem 0.75rem;
  font-size: 0.8rem;
}

.empty-note {
  color: #888;
  font-style: italic;
  font-size: 0.85rem;
}

/* HUD infobar: capacity + QR */
.hud-capacity {
  font-size: 0.8rem;
  color: #aaa;
  margin-top: 0.25rem;
  font-variant-numeric: tabular-nums;
}

.hud-qr {
  margin-top: 0.5rem;
  background: #fff;
  padding: 4px;
  border-radius: 6px;
  width: fit-content;
}

.hud-qr img {
  display: block;
}

.hud-full {
  margin-top: 0.5rem;
  color: #ff7b72;
  font-weight: 600;
  font-size: 0.85rem;
}

@media (max-width: 480px) {
  #lobby {
    padding: 1.5rem;
  }

  #lobby h1 {
    font-size: 1.5rem;
  }
}
