* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #0e1116;
  color: #e8edf2;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}

#game { position: fixed; inset: 0; display: block; }

#srcVideo {
  position: fixed;
  left: 0;
  top: 0;
  width: 2px;
  height: 2px;
  opacity: 0;
  pointer-events: none;
}

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

#lb {
  position: absolute;
  top: 12px;
  right: 12px;
  min-width: 190px;
  padding: 10px 14px;
  background: rgba(0, 0, 0, 0.45);
  border-radius: 10px;
  font-size: 14px;
}
.lb-title { font-weight: 700; text-align: center; margin-bottom: 6px; font-size: 16px; }
#lbList { margin: 0; padding-left: 22px; }
#lbList li { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; line-height: 1.45; }
#lbList li.me { color: #ffd84d; font-weight: 700; }

#score {
  position: absolute;
  left: 12px;
  bottom: 12px;
  padding: 6px 12px;
  background: rgba(0, 0, 0, 0.45);
  border-radius: 8px;
  font-size: 18px;
  font-weight: 600;
}
#score:empty { display: none; }

#minimap {
  position: absolute;
  right: 12px;
  bottom: 12px;
  width: 150px;
  height: 150px;
  border-radius: 8px;
}

#touchBtns {
  position: absolute;
  right: 176px;
  bottom: 18px;
  display: none;
  gap: 14px;
  pointer-events: auto;
}
#touchBtns button {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 24px;
  font-weight: 700;
}
body.touch #touchBtns { display: flex; }

/* ---------- меню ---------- */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  /* без backdrop-filter: размытие поверх постоянно перерисовываемого холста
     на Retina съедает кадры */
  background: rgba(8, 10, 14, 0.62);
}
.overlay.hidden { display: none; }

.panel {
  width: 100%;
  max-width: 360px;
  padding: 24px 24px 18px;
  background: rgba(22, 27, 34, 0.94);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 18px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  text-align: center;
  max-height: 100%;
  overflow-y: auto;
}

h1 { margin: 0; font-size: 34px; letter-spacing: -0.5px; }
h1 span { color: #3fb6ff; }
.tag { margin: 4px 0 16px; color: #9aa7b4; }

.preview {
  position: relative;
  width: 150px;
  height: 150px;
  margin: 0 auto 12px;
  border-radius: 50%;
  overflow: hidden;
  border: 5px solid #3fb6ff;
  background: #1e2630;
}
.preview canvas {
  display: block;
  width: 100%;
  height: 100%;
}
#noCam {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 48px;
  opacity: 0.6;
}
.has-cam #noCam { display: none; }

button, input { font: inherit; }

.looks-head { margin: 14px 0 8px; font-size: 13px; color: #9aa7b4; }
.looks-head b { color: #e8edf2; }
.looks {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
  justify-items: center;
}
.panel .looks button.look {
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid transparent;
  background: #232b36;
  font-size: 20px;
  line-height: 1;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.panel .looks button.look:hover { border-color: rgba(255, 255, 255, 0.3); }
.panel .looks button.look.on { border-color: #3fb6ff; box-shadow: 0 0 0 2px rgba(63, 182, 255, 0.35); }
.looks canvas { width: 100%; height: 100%; display: block; }

.panel button, .panel input[type="text"], #name {
  width: 100%;
  padding: 11px 14px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: #232b36;
  color: #e8edf2;
  outline: none;
}
.panel button { cursor: pointer; font-weight: 600; }
.panel button:hover { background: #2b3542; }
#name { margin: 12px 0 8px; text-align: center; font-size: 17px; }
#name:focus { border-color: #3fb6ff; }
button.primary { background: #2f9be0; border-color: #2f9be0; color: #fff; font-size: 18px; }
button.primary:hover { background: #3fb6ff; }
button.primary:disabled { opacity: 0.5; cursor: default; }

.check { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 12px 0 4px; color: #9aa7b4; font-size: 14px; cursor: pointer; }
.help { margin-top: 10px; font-size: 12px; color: #6f7c89; }
.credits { margin-top: 10px; font-size: 11px; line-height: 1.4; color: #5b6774; }
.credits a { color: #7d8b99; }
.bot-tag {
  display: inline-block;
  padding: 0 5px;
  border-radius: 6px;
  background: rgba(255, 216, 77, 0.18);
  color: #ffd84d;
  font-size: 10px;
  font-weight: 700;
  line-height: 15px;
  vertical-align: 1px;
}
.note { margin-top: 8px; font-size: 13px; color: #ffb35c; }

#death {
  margin: 0 0 14px;
  padding: 10px;
  border-radius: 10px;
  background: rgba(255, 90, 90, 0.12);
  color: #ffc9c9;
  font-size: 14px;
  line-height: 1.5;
}
#death b { color: #fff; }

#conn {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 14px;
  border-radius: 8px;
  background: rgba(200, 60, 60, 0.85);
  font-size: 14px;
}
#conn[hidden] { display: none; }

#perf {
  position: fixed;
  top: 12px;
  left: 12px;
  margin: 0;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.7);
  color: #9ff29f;
  font: 12px/1.45 ui-monospace, Menlo, Consolas, monospace;
  pointer-events: none;
  user-select: text;
  z-index: 10;
}
#perf[hidden] { display: none; }

@media (max-height: 760px) {
  .panel { padding-top: 16px; }
  h1 { font-size: 28px; }
  .tag { margin-bottom: 10px; }
  .preview { width: 110px; height: 110px; }
  .looks-head { margin-top: 10px; }
}

@media (max-width: 600px) {
  #lb { min-width: 0; padding: 6px 10px; font-size: 12px; }
  .lb-title { font-size: 13px; }
  #lbList li { max-width: 120px; }
  #lbList li:nth-child(n + 6) { display: none; }
  #minimap { width: 96px; height: 96px; }
  #touchBtns { right: 120px; }
  #score { font-size: 15px; }
}
