:root {
  --bg: #10131a;
  --panel: rgba(14, 17, 23, 0.72);
  --panel-solid: #151a22;
  --line: rgba(255, 255, 255, 0.12);
  --text: #eef2f6;
  --muted: #9aa6b4;
  --accent: #ffc93c;
  --danger: #e4463c;
  --hp: #3ecf6a;
  --armor: #58a6ff;
  --font: 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
  touch-action: none;
}

#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* --- прицел --- */
#crosshair {
  position: fixed;
  left: 50%;
  top: 50%;
  width: 26px;
  height: 26px;
  transform: translate(-50%, -50%);
  pointer-events: none;
  opacity: 0;
  transition: opacity .12s;
}
#crosshair.show { opacity: .9; }
#crosshair span {
  position: absolute;
  background: rgba(255, 255, 255, .9);
  box-shadow: 0 0 3px rgba(0, 0, 0, .8);
}
#crosshair span:nth-child(1) { left: 12px; top: 0; width: 2px; height: 8px; }
#crosshair span:nth-child(2) { left: 12px; bottom: 0; width: 2px; height: 8px; }
#crosshair span:nth-child(3) { top: 12px; left: 0; height: 2px; width: 8px; }
#crosshair span:nth-child(4) { top: 12px; right: 0; height: 2px; width: 8px; }

#damage-flash {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity .25s;
  background: radial-gradient(ellipse at center, rgba(180, 0, 0, 0) 35%, rgba(150, 10, 10, .95) 100%);
}

#hud-toast {
  position: fixed;
  top: 84px;
  left: 50%;
  transform: translateX(-50%) translateY(-14px);
  padding: 9px 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  font-size: 14px;
  letter-spacing: .3px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s, transform .25s;
  backdrop-filter: blur(6px);
}
#hud-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* --- HUD --- */
#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity .4s;
}
#hud.show { opacity: 1; }

.hud-top-left {
  position: absolute;
  top: 14px;
  left: 16px;
}
.bars { display: flex; flex-direction: column; gap: 6px; }
.bar-row { display: flex; align-items: center; gap: 8px; }
.bar-label {
  font-size: 11px;
  color: #dce4ec;
  width: 20px;
  font-weight: 700;
  text-shadow: 0 1px 3px rgba(0, 0, 0, .95);
}
.bar {
  width: 190px;
  height: 12px;
  background: rgba(0, 0, 0, .55);
  border: 1px solid var(--line);
  border-radius: 3px;
  overflow: hidden;
}
.fill { display: block; height: 100%; width: 100%; transition: width .18s; }
.fill.health { background: linear-gradient(90deg, #2fae57, var(--hp)); }
.fill.health.low { background: linear-gradient(90deg, #a8231b, #e4463c); }
.fill.armor { background: linear-gradient(90deg, #2f6fae, var(--armor)); }
.bar-value {
  font-size: 12px;
  color: #dce4ec;
  width: 30px;
  text-shadow: 0 1px 3px rgba(0, 0, 0, .95);
}
.stats, .street { text-shadow: 0 1px 3px rgba(0, 0, 0, .95); }
.street {
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
  text-shadow: 0 1px 3px #000;
}

.hud-top-right {
  position: absolute;
  top: 14px;
  right: 16px;
  text-align: right;
}
.wanted { font-size: 22px; letter-spacing: 3px; height: 26px; }
.wanted .star { color: rgba(255, 255, 255, .16); }
.wanted .star.on { color: var(--accent); text-shadow: 0 0 10px rgba(255, 201, 60, .8); }
.wanted.active { animation: wpulse 1.1s infinite; }
@keyframes wpulse { 50% { opacity: .55; } }
.money {
  font-size: 24px;
  font-weight: 700;
  color: #8fe08f;
  text-shadow: 0 2px 4px rgba(0, 0, 0, .8);
}
.stats { font-size: 11px; color: var(--muted); margin-top: 4px; }

.hud-bottom-right {
  position: absolute;
  right: 16px;
  bottom: 16px;
  text-align: right;
}
.speedo {
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .2s, transform .2s;
  margin-bottom: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  backdrop-filter: blur(6px);
}
.speedo.show { opacity: 1; transform: translateY(0); }
.car-name { font-size: 12px; color: var(--muted); }
.speed-line { font-size: 30px; font-weight: 700; line-height: 1.05; }
.speed-line small { font-size: 12px; color: var(--muted); margin-left: 4px; font-weight: 400; }
.car-bar {
  width: 120px;
  height: 5px;
  background: rgba(0, 0, 0, .5);
  border-radius: 3px;
  margin-top: 6px;
  overflow: hidden;
}
.car-bar i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, #b8792a, #e0a92b); }

.weapon {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 14px;
  backdrop-filter: blur(6px);
}
#hud-weapon-name { font-size: 13px; color: var(--muted); }
#hud-ammo { font-size: 24px; font-weight: 700; }

.hud-bottom-left { position: absolute; left: 16px; bottom: 16px; }
#minimap {
  width: 176px;
  height: 176px;
  border-radius: 50%;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .6);
}

#killfeed {
  position: absolute;
  top: 116px;
  right: 16px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}
.kill-row {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 4px 10px;
  font-size: 13px;
  transition: opacity .5s;
  backdrop-filter: blur(4px);
}
.kill-row.fade { opacity: 0; }
.kill-row b { color: var(--accent); }
.kill-row i { color: var(--muted); font-style: normal; margin: 0 6px; }

.hint {
  position: absolute;
  bottom: 96px;
  left: 50%;
  transform: translateX(-50%) translateY(6px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 14px;
  font-size: 13px;
  opacity: 0;
  transition: opacity .18s, transform .18s;
  backdrop-filter: blur(6px);
}
.hint.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.hint b { color: var(--accent); }

#chat {
  position: absolute;
  left: 16px;
  bottom: 210px;
  width: 380px;
  max-width: 46vw;
}
#chat-log {
  max-height: 168px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 2px;
  font-size: 13px;
  text-shadow: 0 1px 3px rgba(0, 0, 0, .95);
}
.chat-row { opacity: .28; transition: opacity .5s; }
.chat-row.fresh { opacity: 1; }
.chat-row .who { color: var(--accent); font-weight: 600; }
.chat-row.system { color: #7fd4ff; }
.chat-row.kill { color: #ff9f9f; }

#chat-form { display: none; margin-top: 6px; pointer-events: auto; }
#chat-form.open { display: block; }
#chat-input {
  width: 100%;
  padding: 8px 12px;
  border-radius: 6px;
  border: 1px solid var(--accent);
  background: rgba(8, 10, 14, .92);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  outline: none;
}

/* --- таблица игроков --- */
#scoreboard {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(.96);
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 18px 22px;
  min-width: 460px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s, transform .15s;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .6);
}
#scoreboard.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
#scoreboard h3 { margin: 0 0 12px; font-size: 16px; letter-spacing: 1px; }
#scoreboard table { width: 100%; border-collapse: collapse; font-size: 14px; }
#scoreboard th {
  text-align: left;
  color: var(--muted);
  font-weight: 500;
  font-size: 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
}
#scoreboard td { padding: 5px 0; border-bottom: 1px solid rgba(255, 255, 255, .05); }
#scoreboard tr.me td { color: var(--accent); font-weight: 600; }
.hint-small { color: var(--muted); font-size: 11px; margin: 10px 0 0; }

/* --- смерть --- */
#death-screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(40, 0, 0, .55);
  opacity: 0;
  pointer-events: none;
  transition: opacity .4s;
}
#death-screen.show { opacity: 1; }
#death-screen h2 {
  font-size: 52px;
  letter-spacing: 8px;
  margin: 0;
  color: #ff5b4d;
  text-shadow: 0 4px 20px rgba(0, 0, 0, .9);
}
#death-screen p { color: #ffd9d5; font-size: 16px; }

/* --- меню --- */
#menu {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(255, 201, 60, .12), transparent 60%),
    linear-gradient(160deg, #0d1017, #171c26 60%, #0d1017);
  z-index: 20;
  transition: opacity .45s;
  overflow: auto;
  padding: 20px;
}
#menu.hide { opacity: 0; pointer-events: none; }
.menu-card {
  width: min(520px, 96vw);
  background: rgba(18, 22, 30, .86);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 26px 28px 22px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .65);
}
.menu-card h1 {
  margin: 0;
  font-size: 46px;
  letter-spacing: 10px;
  background: linear-gradient(180deg, #fff, #ffc93c);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.tagline { color: var(--muted); margin: 6px 0 20px; font-size: 14px; line-height: 1.5; }
.field { display: block; margin-bottom: 16px; }
.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
#name-input {
  width: 100%;
  padding: 11px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, .35);
  color: var(--text);
  font-size: 15px;
  font-family: var(--font);
  outline: none;
}
#name-input:focus { border-color: var(--accent); }
.skins { display: flex; gap: 8px; flex-wrap: wrap; }
.skin {
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, .3);
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-family: var(--font);
  transition: .15s;
}
.skin:hover { border-color: rgba(255, 255, 255, .3); color: var(--text); }
.skin.active { border-color: var(--accent); color: var(--accent); background: rgba(255, 201, 60, .1); }
.play {
  width: 100%;
  padding: 14px;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 3px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(180deg, #ffd45e, #e8a41c);
  color: #221a05;
  cursor: pointer;
  font-family: var(--font);
  transition: .15s;
}
.play:hover { filter: brightness(1.08); }
.play:disabled { opacity: .5; cursor: default; }
.status { text-align: center; font-size: 12px; color: var(--muted); margin-top: 10px; min-height: 16px; }
.status.error { color: var(--danger); }
.controls { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 14px; }
.controls h4 { margin: 0 0 8px; font-size: 13px; color: var(--muted); font-weight: 600; }
.controls ul { margin: 0; padding-left: 18px; color: var(--muted); font-size: 13px; line-height: 1.75; }
.controls b { color: var(--text); }
.warn { color: #ffb27a; font-size: 12px; margin: 10px 0 0; }

/* --- загрузка --- */
#loading {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: #0d1017;
  z-index: 30;
  color: var(--muted);
  font-size: 14px;
}
#loading.show { display: flex; }
.spinner {
  width: 42px;
  height: 42px;
  border: 3px solid rgba(255, 255, 255, .15);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- сенсорное управление --- */
#touch-ui { display: none; }
body.is-touch #touch-ui { display: block; }
#touch-look {
  position: fixed;
  inset: 0;
  z-index: 1;
}
#touch-stick {
  position: fixed;
  left: 24px;
  bottom: 24px;
  width: 128px;
  height: 128px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .07);
  border: 1px solid rgba(255, 255, 255, .16);
  z-index: 3;
  touch-action: none;
}
#touch-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 52px;
  height: 52px;
  margin: -26px 0 0 -26px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .28);
}
.touch-buttons {
  position: fixed;
  right: 18px;
  bottom: 18px;
  display: grid;
  grid-template-columns: repeat(2, 78px);
  gap: 10px;
  z-index: 3;
}
.tbtn {
  height: 62px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, .2);
  background: rgba(20, 24, 32, .6);
  color: var(--text);
  font-size: 12px;
  font-family: var(--font);
  touch-action: none;
}
.tbtn.fire { background: rgba(180, 40, 32, .65); }

body.is-touch #chat { display: none; }
body.is-touch .hud-bottom-left { bottom: 170px; }

@media (max-width: 720px) {
  .bar { width: 130px; }
  #minimap { width: 128px; height: 128px; }
  .menu-card h1 { font-size: 34px; letter-spacing: 6px; }
  #chat { display: none; }
}
