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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  color: #e8e8e8;
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-user-select: none;
  user-select: none;
}

#stage {
  display: block;
  width: 100vw;
  height: 100vh;
  cursor: none; /* прячем системный курсор — рисуем свой */
  touch-action: none;
}

#stage3d, #stagefps, #stagecp {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: none;
  touch-action: none;
  z-index: 1;
}

/* ---------- HUD шутера ---------- */
#fpsHud { position: fixed; inset: 0; z-index: 40; display: none; pointer-events: none; }
#fpsHud.show { display: block; }

#fpsCross {
  position: absolute; left: 50%; top: 50%;
  width: 6px; height: 6px; margin: -3px 0 0 -3px;
  border-radius: 50%;
  background: rgba(255,255,255,0.9);
  box-shadow: 0 0 0 2px rgba(0,0,0,0.5), 0 0 6px rgba(0,0,0,0.6);
}

#fpsHpWrap {
  position: absolute; left: 20px; bottom: 20px;
  width: 240px; height: 26px;
  background: rgba(0,0,0,0.5);
  border: 1px solid #2a2e37;
  border-radius: 8px;
  overflow: hidden;
}
#fpsHpBar { height: 100%; width: 100%; background: #4dd24d; transition: width 0.12s, background 0.2s; }
#fpsHpText {
  position: absolute; left: 0; top: 0; right: 0; bottom: 0;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 14px; text-shadow: 0 1px 2px #000;
}

#fpsFeed {
  position: absolute; right: 16px; top: 76px;
  display: flex; flex-direction: column; gap: 5px; align-items: flex-end;
}
.feed-line {
  background: rgba(0,0,0,0.55); color: #ffdca8;
  padding: 4px 10px; border-radius: 7px; font-size: 13px; font-weight: 600;
}

#fpsOverlay {
  position: absolute; inset: 0;
  display: none; align-items: center; justify-content: center;
  background: rgba(8,10,16,0.45);
  pointer-events: none;
}
#fpsOverlay.show { display: flex; }
#fpsOverlayText {
  color: #fff; font-size: 34px; font-weight: 800;
  text-shadow: 0 2px 10px rgba(0,0,0,0.7);
  padding: 18px 30px; background: rgba(0,0,0,0.4); border-radius: 16px;
}

/* хитмаркер */
#fpsHitmark {
  position: absolute; left: 50%; top: 50%; width: 26px; height: 26px;
  margin: -13px 0 0 -13px; opacity: 0; transition: opacity 0.05s;
}
#fpsHitmark.show { opacity: 1; }
#fpsHitmark::before, #fpsHitmark::after {
  content: ''; position: absolute; left: 50%; top: 50%;
  width: 12px; height: 3px; background: #fff; margin: -1.5px 0 0 -6px;
  box-shadow: 0 0 3px rgba(0,0,0,0.8);
}
#fpsHitmark::before { transform: rotate(45deg); }
#fpsHitmark::after { transform: rotate(-45deg); }
#fpsHitmark.head::before, #fpsHitmark.head::after { background: #ff5b5b; width: 16px; margin-left: -8px; }

/* полоса заряда лазера */
#fpsLaser {
  position: absolute; left: 20px; bottom: 54px; width: 240px; height: 14px;
  background: rgba(0,0,0,0.5); border: 1px solid #2a3e4a; border-radius: 7px;
  overflow: hidden; display: none;
}
#fpsLaserBar { height: 100%; width: 0; background: #3a7a9a; transition: width 0.08s, background 0.2s; }
#fpsLaserText {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 700; letter-spacing: 2px; color: #cfefff; text-shadow: 0 1px 2px #000;
}

/* меню деплоя */
#fpsDeploy {
  position: absolute; inset: 0; display: none; align-items: center; justify-content: center;
  background: rgba(8,12,20,0.55); pointer-events: auto;
}
#fpsDeploy.show { display: flex; }
.deploy-card {
  background: #14161b; border: 1px solid #2a2e37; border-radius: 18px;
  padding: 26px 28px; text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,0.6);
  min-width: 340px;
}
.deploy-card h2 { color: #fff; font-size: 22px; margin-bottom: 18px; }
.weap-row { display: flex; gap: 12px; margin-bottom: 18px; }
.weap-btn {
  flex: 1; display: flex; flex-direction: column; gap: 4px; align-items: center;
  padding: 16px 12px; font-size: 16px; font-weight: 700; color: #c7ccda;
  background: #1b1e26; border: 2px solid #2f333d; border-radius: 12px; cursor: pointer;
  transition: all 0.15s;
}
.weap-btn small { font-size: 11px; font-weight: 500; color: #8b90a0; }
.weap-btn:hover { border-color: #4d8dff; }
.weap-btn.active { border-color: #4d8dff; background: #223052; color: #fff; }
.deploy-go {
  width: 100%; padding: 14px; font-size: 18px; font-weight: 800; letter-spacing: 1px;
  color: #fff; background: linear-gradient(180deg, #37c46b, #2a9e54); border: none;
  border-radius: 12px; cursor: pointer; transition: filter 0.15s;
}
.deploy-go:hover { filter: brightness(1.08); }
.deploy-go:disabled { opacity: 0.5; cursor: not-allowed; }
#deployTimer { margin-top: 12px; color: #ffd24d; font-size: 14px; font-weight: 600; min-height: 18px; }
.sens-row { margin-bottom: 16px; text-align: left; }
.sens-row label { display: block; color: #c7ccda; font-size: 13px; margin-bottom: 6px; }
.sens-row b { color: #4dd2ff; }
#sensRange { width: 100%; accent-color: #4d8dff; cursor: pointer; }
.deploy-controls { margin-top: 12px; color: #6c7183; font-size: 12px; }

/* индикатор щита */
#fpsShield {
  position: absolute; left: 50%; top: 64px; transform: translateX(-50%);
  display: none; padding: 6px 16px; border-radius: 20px;
  background: rgba(60,180,255,0.22); border: 1px solid rgba(90,200,255,0.6);
  color: #bfeaff; font-weight: 800; letter-spacing: 1px; font-size: 15px;
  text-shadow: 0 1px 3px rgba(0,0,0,0.6);
  box-shadow: 0 0 18px rgba(70,190,255,0.35);
}
#fpsShield.show { display: block; }
#fpsHud.shielded { box-shadow: inset 0 0 90px rgba(70,190,255,0.28); }

/* ---------- Экран входа ---------- */
.login {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 40%, #16181d 0%, #000 70%);
  z-index: 100;
}

.login.hidden {
  display: none;
}

.card {
  width: min(92vw, 380px);
  background: #14161b;
  border: 1px solid #2a2e37;
  border-radius: 16px;
  padding: 28px 26px 22px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}

.card h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.card .sub {
  margin-top: 6px;
  color: #8b90a0;
  font-size: 13px;
}

.field-label {
  display: block;
  margin: 22px 0 8px;
  font-size: 12px;
  color: #9aa0b0;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.device-row { display: flex; gap: 8px; }
.device-btn {
  flex: 1; padding: 10px 8px; font-size: 14px; font-weight: 600;
  color: #c7ccda; background: #0c0d11; border: 1px solid #2f333d;
  border-radius: 10px; cursor: pointer; transition: all 0.15s;
}
.device-btn:hover { border-color: #4d8dff; color: #fff; }
.device-btn.sel { border-color: #4d8dff; background: #1b2740; color: #fff; }

#nick {
  width: 100%;
  padding: 12px 14px;
  font-size: 15px;
  color: #fff;
  background: #0c0d11;
  border: 1px solid #2f333d;
  border-radius: 10px;
  outline: none;
  transition: border-color 0.15s;
}

#nick:focus {
  border-color: #4d8dff;
}

button {
  font-family: inherit;
  cursor: pointer;
}

.ghost {
  width: 100%;
  margin-top: 12px;
  padding: 11px 14px;
  font-size: 13px;
  color: #c7ccda;
  background: transparent;
  border: 1px dashed #3a3f4a;
  border-radius: 10px;
  transition: all 0.15s;
}

.ghost:hover {
  border-color: #4d8dff;
  color: #fff;
}

.ghost b {
  color: #4dd2ff;
}

.primary {
  width: 100%;
  margin-top: 18px;
  padding: 13px 14px;
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(180deg, #4d8dff, #3b6fe0);
  border: none;
  border-radius: 10px;
  transition: filter 0.15s, transform 0.05s;
}

.primary:hover {
  filter: brightness(1.08);
}

.primary:active {
  transform: translateY(1px);
}

.primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.hint {
  margin-top: 16px;
  font-size: 12px;
  color: #6c7183;
  text-align: center;
}

/* ---------- Индикатор статуса ---------- */
.status {
  position: fixed;
  top: 12px;
  right: 12px;
  display: none;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: #d6dae4;
  background: rgba(20, 22, 28, 0.72);
  border: 1px solid #2a2e37;
  border-radius: 20px;
  backdrop-filter: blur(6px);
  z-index: 50;
}

.status.visible {
  display: flex;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #ff5b5b;
  box-shadow: 0 0 8px currentColor;
  color: #ff5b5b;
  transition: background 0.2s, color 0.2s;
}

.dot.ok {
  background: #4dff88;
  color: #4dff88;
}

.dot.warn {
  background: #ffd24d;
  color: #ffd24d;
}

/* ---------- Верхняя панель инструментов ---------- */
.toolbar {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: none;
  align-items: center;
  gap: 14px;
  padding: 8px 12px;
  background: rgba(20, 22, 28, 0.82);
  border: 1px solid #2a2e37;
  border-radius: 14px;
  backdrop-filter: blur(8px);
  z-index: 60;
  max-width: 96vw;
  flex-wrap: wrap;
  justify-content: center;
}

.toolbar.visible { display: flex; }

.tb-toggle {
  width: 30px; height: 30px; flex: 0 0 auto;
  color: #c7ccda; background: #1b1e26; border: 1px solid #2f333d;
  border-radius: 9px; cursor: pointer; font-size: 14px; line-height: 1;
  transition: all 0.15s;
}
.tb-toggle:hover { color: #fff; border-color: #4d8dff; }
.toolbar.collapsed { gap: 0; }
.toolbar.collapsed .modes,
.toolbar.collapsed .paint-tools { display: none; }

.modes { display: flex; gap: 6px; }

.mode {
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  color: #c7ccda;
  background: #1b1e26;
  border: 1px solid #2f333d;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.15s;
}
.mode:hover { color: #fff; border-color: #4d8dff; }
.mode.active { color: #fff; background: linear-gradient(180deg, #4d8dff, #3b6fe0); border-color: transparent; }

.paint-tools {
  display: none;
  align-items: center;
  gap: 10px;
  padding-left: 12px;
  border-left: 1px solid #2f333d;
}
.paint-tools.visible { display: flex; flex-wrap: wrap; gap: 8px; }

.palette { display: flex; gap: 5px; }
.swatch {
  width: 22px; height: 22px;
  border-radius: 6px;
  border: 2px solid transparent;
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.3);
  transition: transform 0.1s;
}
.swatch:hover { transform: scale(1.12); }
.swatch.sel { border-color: #fff; }

.tool { display: flex; align-items: center; }
#colorPick {
  width: 30px; height: 30px;
  padding: 0; border: none; border-radius: 8px;
  background: none; cursor: pointer;
}
.sizewrap { gap: 8px; }
#brushSize { width: 96px; accent-color: #4d8dff; cursor: pointer; }
.brush-dot {
  display: inline-block;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.3);
}

.btn {
  padding: 7px 12px;
  font-size: 13px; font-weight: 600;
  color: #c7ccda;
  background: #1b1e26;
  border: 1px solid #2f333d;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.15s;
}
.btn:hover { color: #fff; border-color: #4d8dff; }
.btn.active { color: #111; background: #ffd24d; border-color: transparent; }
.btn.danger:hover { border-color: #ff5b5b; color: #ff8a8a; }

.save-sel {
  padding: 7px 8px; font-size: 13px; font-weight: 600;
  color: #c7ccda; background: #1b1e26; border: 1px solid #2f333d;
  border-radius: 9px; cursor: pointer;
}

.build-hint { font-size: 13px; color: #c7ccda; }
.build-hint b {
  color: #fff;
  background: #2f333d;
  border-radius: 5px;
  padding: 1px 6px;
  font-variant: small-caps;
}

.btn.erase { background: #ff9d4d; color: #111; border-color: transparent; }
.btn.armed { animation: armedPulse 0.9s ease-in-out infinite; border-color: #4dd2ff; }
@keyframes armedPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(77,210,255,0.55); }
  50% { box-shadow: 0 0 0 6px rgba(77,210,255,0); }
}

/* ---------- Показ по устройству (ПК / телефон) ---------- */
.touch .desktop-only { display: none !important; }
.desktop .touch-only { display: none !important; }

/* Тач: крупнее цели под палец */
.touch .mode, .touch .btn { padding: 11px 14px; font-size: 14px; }
.touch .swatch { width: 30px; height: 30px; }
.touch #colorPick { width: 36px; height: 36px; }
.touch #brushSize { height: 26px; }

/* ---------- Адаптация под узкий экран телефона ---------- */
@media (max-width: 820px) {
  .toolbar {
    top: 6px;
    gap: 7px;
    padding: 6px 8px;
    border-radius: 12px;
    max-width: 98vw;
  }
  .modes { gap: 5px; }
  .mode { padding: 8px 9px; font-size: 12px; }
  .paint-tools { padding-left: 7px; gap: 6px; }
  #brushSize { width: 74px; }
  .btn { padding: 8px 9px; font-size: 12px; }
  .status { top: auto; bottom: 8px; right: 8px; }
  .card { width: min(94vw, 360px); padding: 22px 20px; }
}

@media (max-width: 520px) {
  .mode { padding: 7px 8px; font-size: 11px; }
  .palette { gap: 4px; }
  .build-hint { display: none; }
}

/* ---------- Всплывающее окно подтверждения ---------- */
.confirm-overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(6, 7, 10, 0.55);
  backdrop-filter: blur(3px);
  z-index: 200;
}
.confirm-overlay.visible { display: flex; }

.confirm-card {
  width: min(90vw, 380px);
  background: #14161b;
  border: 1px solid #2a2e37;
  border-radius: 16px;
  padding: 24px 22px 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  animation: confirmPop 0.15s ease-out;
}
@keyframes confirmPop {
  from { transform: scale(0.94); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.confirm-text {
  color: #e8e8e8;
  font-size: 15px;
  line-height: 1.5;
  margin-bottom: 18px;
  text-align: center;
}

.confirm-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}
.confirm-actions .btn { flex: 1; padding: 10px 14px; }

/* ---------- Выбор материалов в стройке ---------- */
.mat-cats { display: flex; gap: 5px; flex-wrap: wrap; }

.mat-cat-btn {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 9px;
  font-size: 13px;
  font-weight: 600;
  color: #c7ccda;
  background: #1b1e26;
  border: 1px solid #2f333d;
  border-radius: 9px;
  cursor: pointer;
  transition: all 0.15s;
}
.mat-cat-btn:hover { border-color: #4d8dff; color: #fff; }
.mat-cat-btn.selected { border-color: #4d8dff; background: #1b2740; color: #fff; }
.mat-cat-btn .swimg {
  width: 20px; height: 20px;
  image-rendering: pixelated;
  border-radius: 3px;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.25);
}
.mat-cat-btn .caret { font-size: 9px; opacity: 0.6; }

.mat-popover {
  position: fixed;
  display: none;
  flex-wrap: wrap;
  gap: 6px;
  max-width: 340px;
  padding: 10px;
  background: #14161b;
  border: 1px solid #2a2e37;
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
  z-index: 150;
}
.mat-popover.visible { display: flex; }

.mat-variant-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 64px;
  padding: 6px 4px;
  font-size: 10px;
  text-align: center;
  color: #c7ccda;
  background: #1b1e26;
  border: 1px solid #2f333d;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.12s;
}
.mat-variant-btn:hover { border-color: #4d8dff; color: #fff; }
.mat-variant-btn.selected { border-color: #ffd24d; }
.mat-variant-btn img {
  width: 34px; height: 34px;
  image-rendering: pixelated;
  border-radius: 4px;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.2);
}
.mat-variant-btn .door-pair { display: flex; flex-direction: column; width: 34px; height: 34px; box-shadow: 0 0 0 1px rgba(255,255,255,0.2); border-radius: 4px; overflow: hidden; }

/* ---------- HUD Color Party ---------- */
#cpHud { position: fixed; inset: 0; z-index: 40; display: none; pointer-events: none; }
#cpHud.show { display: block; }

#cpPanel {
  position: absolute; left: 50%; top: 12px; transform: translateX(-50%);
  display: none; gap: 14px; align-items: baseline;
  padding: 10px 22px; border-radius: 14px;
  background: rgba(10,12,18,0.7); border: 1px solid #2a2e37;
  font-size: 20px; font-weight: 800; color: #fff;
  text-shadow: 0 2px 6px rgba(0,0,0,0.6);
}
#cpHud.playing #cpPanel { display: flex; }
#cpPanelTime { font-variant-numeric: tabular-nums; color: #ffd24d; }

#cpCountdown {
  position: absolute; left: 50%; top: 38%; transform: translate(-50%,-50%);
  display: none;
  font-size: 120px; font-weight: 900; color: #fff;
  text-shadow: 0 4px 24px rgba(0,0,0,0.7);
}
#cpCountdown.show { display: block; }

#cpLobby {
  position: absolute; inset: 0; display: none; align-items: center; justify-content: center;
  background: rgba(8,10,16,0.55);
}
#cpLobby.show { display: flex; }
#cpLobbyText {
  color: #fff; font-size: 30px; font-weight: 800;
  padding: 18px 30px; background: rgba(0,0,0,0.4); border-radius: 16px;
}

#cpOverlay {
  position: absolute; inset: 0; display: none; align-items: center; justify-content: center;
  background: rgba(8,10,16,0.4);
}
#cpOverlay.show { display: flex; }
#cpOverlayText {
  color: #fff; font-size: 30px; font-weight: 800;
  text-shadow: 0 2px 10px rgba(0,0,0,0.7);
  padding: 16px 26px; background: rgba(0,0,0,0.4); border-radius: 14px;
}

/* ---------- Тач-управление (джойстик + обзор + кнопки) ---------- */
.touch-controls { position: fixed; inset: 0; z-index: 50; }
.tc-stick-zone {
  position: absolute; left: 0; bottom: 0; width: 45%; height: 55%;
  touch-action: none;
}
.tc-look-zone {
  position: absolute; right: 0; bottom: 0; width: 55%; height: 100%;
  touch-action: none;
}
.tc-stick-base {
  position: absolute; left: 60px; bottom: 60px;
  width: 110px; height: 110px; border-radius: 50%;
  background: rgba(255,255,255,0.12); border: 2px solid rgba(255,255,255,0.35);
}
.tc-stick-knob {
  position: absolute; left: 50%; top: 50%; width: 52px; height: 52px;
  margin: -26px 0 0 -26px; border-radius: 50%;
  background: rgba(255,255,255,0.55); border: 2px solid rgba(255,255,255,0.8);
  transition: transform 0.02s linear;
}
.tc-btn {
  position: absolute; width: 74px; height: 74px; border-radius: 50%;
  background: rgba(255,255,255,0.15); border: 2px solid rgba(255,255,255,0.45);
  color: #fff; font-size: 28px; display: flex; align-items: center; justify-content: center;
  touch-action: none; user-select: none;
}
.tc-btn.on { background: rgba(77,210,255,0.4); border-color: #4dd2ff; }
.tc-fire { right: 100px; bottom: 130px; background: rgba(255,90,90,0.28); border-color: rgba(255,120,120,0.6); }
.tc-crouch { right: 30px; bottom: 40px; }
.tc-jump { right: 30px; bottom: 130px; }
.touch-controls:has(.tc-crouch) .tc-jump { right: 110px; }
.mat-variant-btn .door-pair img { width: 34px; height: 17px; border-radius: 0; box-shadow: none; }
