* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; height: 100%; overflow: hidden;
  background: #1a1d24; color: #e8eaf0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  user-select: none; -webkit-user-select: none;
  touch-action: none; overscroll-behavior: none;
}
.hidden { display: none !important; }

#rotateOverlay {
  display: none;
  position: fixed; inset: 0; z-index: 9999;
  background: #12141a; color: #e8eaf0;
  align-items: center; justify-content: center; text-align: center;
  padding: 20px;
}
.rotateInner { font-size: 16px; }
.phoneIcon {
  font-size: 60px; margin-bottom: 16px;
  animation: rotateHint 2s ease-in-out infinite;
}
@keyframes rotateHint {
  0%,40%   { transform: rotate(0deg); }
  60%,100% { transform: rotate(90deg); }
}
@media (orientation: portrait) {
  #rotateOverlay { display: flex; }
  @media (min-width: 900px) {
    #rotateOverlay { display: none; }
  }
}

/* Экран входа */
.screen {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 30%, #262b36, #12141a);
  padding: 20px;
}
.card {
  width: 100%; max-width: 340px; padding: 20px;
  background: #222732; border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
  display: flex; flex-direction: column; gap: 10px;
}
.card h1 { margin: 0; font-size: 24px; text-align: center; }
.card .sub { margin: 0 0 4px; text-align: center; color: #8b93a7; font-size: 13px; }
.card input {
  padding: 12px; border-radius: 10px; border: 1px solid #333a48;
  background: #1a1d24; color: #fff; font-size: 15px;
}
.card input:focus { outline: none; border-color: #4a90e2; }
.card button {
  padding: 12px; border: none; border-radius: 10px;
  background: #4a90e2; color: #fff; font-size: 15px; font-weight: 600;
}
.card button:active { background: #3a78c2; }
.error { color: #ff6b6b; font-size: 13px; text-align: center; min-height: 16px; }
.installBtn { background: #2a7d4f !important; }
.installBtn:active { background: #1f5e3b !important; }

/* Игра */
#game { position: fixed; inset: 0; }
#canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.panel {
  background: rgba(20, 24, 33, .82);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 12px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

#hud {
  position: absolute;
  top: calc(env(safe-area-inset-top, 8px) + 6px);
  left: calc(env(safe-area-inset-left, 8px) + 8px);
  right: calc(env(safe-area-inset-right, 8px) + 8px);
  display: flex; justify-content: space-between; align-items: flex-start;
  pointer-events: none;
}
.hp {
  width: 160px; height: 26px; position: relative; overflow: hidden;
  display: flex; align-items: center;
}
#hpFill {
  position: absolute; left: 0; top: 0; bottom: 0; width: 100%;
  background: linear-gradient(90deg, #4caf51, #8bc34a);
  transition: width .15s ease;
}
#hpText {
  position: relative; width: 100%; text-align: center; font-size: 13px;
  font-weight: 700; text-shadow: 0 1px 2px #000;
}
.hudRight { display: flex; gap: 8px; pointer-events: none; }
.hudRight button { pointer-events: auto; }
#btnBoard, #btnLeave, #btnMute {
  width: 42px; height: 42px; border-radius: 12px;
  background: rgba(20,24,33,.82); color: #fff; font-size: 18px;
  border: 1px solid rgba(255,255,255,.08);
}
#btnBoard:active { background: rgba(74,144,226,.4); }
#btnLeave:active { background: rgba(229,57,53,.4); }
#btnMute:active { background: rgba(74,144,226,.4); }
#btnMute.muted { color: #8b93a7; }

/* Рейтинг */
#board {
  position: absolute; top: 60px;
  right: calc(env(safe-area-inset-right, 8px) + 8px);
  width: 200px; max-height: 50vh; overflow-y: auto; padding: 10px; z-index: 20;
}
.boardHead { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.boardHead h3 { margin: 0; font-size: 14px; }
#boardClose { background: none; border: none; color: #8b93a7; font-size: 16px; padding: 4px 8px; }
.boardRow { display: flex; justify-content: space-between; font-size: 12px; padding: 3px 0; }
.boardRow.me { color: #4a90e2; font-weight: 700; }

/* Нижняя панель */
#bottomBar {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 6px);
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  pointer-events: none;
  z-index: 10;
}
#ammoRow, #emoRow { display: flex; gap: 6px; pointer-events: auto; }
.aBtn, .eBtn {
  width: 44px; height: 44px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,.1);
  background: rgba(20,24,33,.82);
  color: #fff; font-size: 18px;
  display: flex; align-items: center; justify-content: center;
  position: relative;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  overflow: hidden;
}
.aBtn.active { background: #4a90e2; border-color: #4a90e2; }
.aBtn .num {
  position: absolute; bottom: 2px; right: 4px;
  font-size: 9px; color: #8b93a7;
}
.aBtn.active .num { color: #fff; }
.eBtn:active, .aBtn:active { transform: scale(.92); transition: transform .05s; }

/* Оверлей перезарядки на кнопках патронов */
.aBtn .cdOverlay {
  position: absolute;
  left: 0; right: 0; top: 0;
  height: 0%;
  background: rgba(0,0,0,.65);
  pointer-events: none;
  transition: height .08s linear;
}
.aBtn.ready .cdOverlay { display: none; }

/* Джойстики */
.joy {
  position: absolute;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 12px);
  width: 130px; height: 130px; border-radius: 50%;
  background: rgba(255,255,255,.05);
  border: 2px solid rgba(255,255,255,.12);
  touch-action: none;
}
#joyMove { left: calc(env(safe-area-inset-left, 0px) + 16px); }
#joyAim  { right: calc(env(safe-area-inset-right, 0px) + 16px); }
.joy.aim { border-color: rgba(74,144,226,.35); }
.knob {
  position: absolute; left: 50%; top: 50%; width: 54px; height: 54px;
  margin: -27px 0 0 -27px; border-radius: 50%;
  background: rgba(255,255,255,.18);
  border: 2px solid rgba(255,255,255,.3);
  transition: background .1s;
}
#joyMove .knob { background: rgba(140,195,74,.35); border-color: rgba(140,195,74,.6); }
#joyAim  .knob { background: rgba(74,144,226,.35); border-color: rgba(74,144,226,.6); }

/* Кнопка огня — над правым джойстиком */
#fireBtn {
  position: absolute;
  right: calc(env(safe-area-inset-right, 0px) + 135px);   /* было 22px */
  bottom: calc(env(safe-area-inset-bottom, 0px) + 100px); /* было 158px */
  width: 76px;
  height: 76px;
  border-radius: 50%;
  background: rgba(229, 57, 53, 0.72);
  border: 2px solid rgba(255,255,255,0.4);
  color: #fff;
  font-size: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  z-index: 10;
  box-shadow: 0 4px 12px rgba(0,0,0,0.35);
  user-select: none;
  -webkit-user-select: none;
  padding: 0;
  transition: transform .05s, background .1s;
}
#fireBtn.pressed {
  background: rgba(229, 57, 53, 1);
  transform: scale(0.94);
  box-shadow: 0 0 22px rgba(229,57,53,0.8);
}

/* Оверлеи */
#deathOverlay {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(180, 30, 30, .25); z-index: 30; pointer-events: none;
}
#deathText {
  font-size: 32px; font-weight: 800; color: #fff; text-shadow: 0 2px 12px #000;
  animation: pop .4s ease;
}
@keyframes pop { from { transform: scale(.5); opacity: 0; } to { transform: scale(1); opacity: 1; } }
#connLost {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.7); color: #fff; font-size: 18px; z-index: 100;
}

/* Лобби */
.lobbyCard {
  background: #222732;
  border-radius: 16px;
  padding: 16px;
  max-width: 720px;
  width: 100%;
  max-height: 92vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.lobbyHead {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 8px;
}
.lobbyHead h2 { margin: 0; font-size: 20px; }
.lobbyActions { display: flex; align-items: center; gap: 10px; }
.meName { color: #8bc34a; font-weight: 600; font-size: 14px; }
.logoutBtn {
  background: #e53935;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 14px;
  cursor: pointer;
}
.logoutBtn:active { background: #c62828; }
.mapList {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}
.mapCard {
  background: #1a1d24;
  border: 1px solid #333a48;
  border-radius: 12px;
  padding: 14px;
  cursor: pointer;
  transition: all .15s;
  user-select: none;
}
.mapCard:active, .mapCard:hover { background: #2a2f3a; border-color: #4a90e2; }
.mapCard.full { opacity: .5; cursor: not-allowed; }
.mapCard.full:hover { background: #1a1d24; border-color: #333a48; }
.mapName { font-size: 18px; font-weight: 700; margin-bottom: 8px; }
.mapInfo { display: flex; justify-content: space-between; font-size: 13px; color: #8b93a7; }
.mapInfo .cnt { color: #8bc34a; font-weight: 600; }
.mapInfo .cnt.full { color: #e53935; }

/* Компактный режим для телефона в ландшафте */
@media (orientation: landscape) and (max-height: 500px) {
  .joy { width: 110px; height: 110px; }
  .knob { width: 46px; height: 46px; margin: -23px 0 0 -23px; }
  .aBtn, .eBtn { width: 40px; height: 40px; font-size: 16px; border-radius: 10px; }
  .hp { width: 130px; height: 22px; }
  #bottomBar { gap: 4px; }
  #btnBoard, #btnLeave, #btnMute { width: 38px; height: 38px; font-size: 16px; }
  #fireBtn {
    right: calc(env(safe-area-inset-right, 0px) + 135px);   /* было без right */
    bottom: calc(env(safe-area-inset-bottom, 0px) + 70px);  /* было 132px */
    width: 66px;
    height: 66px;
    font-size: 26px;
  }
}