:root {
  --ink: #101010;
  --paper: #d7d7d7;
  --accent: #c81e1e;
  --ok: #2f8f4e;
  --ui-bg: rgba(16, 16, 16, .88);
  --ui-line: rgba(255, 255, 255, .14);
  --ui-fg: #eaeaea;
  --ui-dim: #9a9a9a;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: #0b0b0b;
  color: var(--ui-fg);
  font-family: "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  touch-action: none;
}

#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
  touch-action: none;
}

/* ---------- HUD ---------- */
.hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  padding: calc(10px + var(--safe-t)) calc(12px + var(--safe-r)) calc(10px + var(--safe-b)) calc(12px + var(--safe-l));
  font-variant-numeric: tabular-nums;
}

/* column-reverse: чипы статусов оказываются НАД полоской здоровья и не уезжают за край */
.hud-left {
  position: absolute;
  left: calc(14px + var(--safe-l));
  bottom: calc(14px + var(--safe-b));
  display: flex;
  flex-direction: column-reverse;
}
.hud-right { position: absolute; right: calc(14px + var(--safe-r)); bottom: calc(14px + var(--safe-b)); text-align: right; }
/* Ниже кнопки панели, чтобы киллфид её не перекрывал */
.hud-top { position: absolute; top: calc(60px + var(--safe-t)); right: calc(14px + var(--safe-r)); text-align: right; }

.hp { display: flex; align-items: center; gap: 10px; }
.hp-bar {
  width: min(34vw, 240px);
  height: 14px;
  background: rgba(0, 0, 0, .45);
  border: 2px solid rgba(0, 0, 0, .65);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .1);
}
.hp-bar i {
  display: block;
  height: 100%;
  width: 100%;
  background: linear-gradient(180deg, #e33 0%, #a11 100%);
  transition: width .12s linear;
}
.hp-num { font-size: 20px; font-weight: 800; text-shadow: 0 2px 0 rgba(0, 0, 0, .6); }

.chips { display: flex; gap: 6px; margin-bottom: 8px; flex-wrap: wrap; }
.chip {
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  padding: 3px 8px;
  background: var(--ui-bg);
  border: 1px solid var(--ui-line);
  border-radius: 2px;
}
.chip.hot { color: #ffd166; border-color: rgba(255, 209, 102, .45); }

.weapon-name {
  font-size: clamp(14px, 3.4vw, 22px);
  font-weight: 800;
  letter-spacing: .1em;
  text-shadow: 0 2px 0 rgba(0, 0, 0, .6);
}
.ammo { font-size: clamp(20px, 5vw, 34px); font-weight: 900; text-shadow: 0 2px 0 rgba(0, 0, 0, .6); }
.ammo.low { color: #ff5a5a; }
.ammo small { font-size: .5em; color: var(--ui-dim); font-weight: 700; }

.killfeed { display: flex; flex-direction: column; gap: 4px; align-items: flex-end; }
.killfeed div {
  background: var(--ui-bg);
  border-left: 3px solid var(--accent);
  padding: 3px 8px;
  font-size: 12px;
  animation: fadeout 3.5s forwards;
}
@keyframes fadeout { 0%, 70% { opacity: 1 } 100% { opacity: 0 } }

.perf {
  position: absolute;
  top: calc(10px + var(--safe-t));
  left: calc(14px + var(--safe-l));
  font-size: 11px;
  color: rgba(0, 0, 0, .5);
  font-family: ui-monospace, Consolas, monospace;
  white-space: pre;
}

/* ---------- Панель ---------- */
.panel-toggle {
  position: fixed;
  top: calc(8px + var(--safe-t));
  right: calc(8px + var(--safe-r));
  width: 42px;
  height: 42px;
  border-radius: 4px;
  border: 1px solid var(--ui-line);
  background: var(--ui-bg);
  color: var(--ui-fg);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  z-index: 30;
}
.panel-toggle:active { transform: scale(.94); }

.panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(380px, 92vw);
  background: var(--ui-bg);
  backdrop-filter: blur(8px);
  border-left: 1px solid var(--ui-line);
  z-index: 40;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-t);
  padding-bottom: var(--safe-b);
  padding-right: var(--safe-r);
}
.panel[hidden] { display: none; }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--ui-line);
}
.panel-head h1 { font-size: 14px; letter-spacing: .22em; margin: 0; font-weight: 800; }
.icon-btn {
  background: none;
  border: 1px solid var(--ui-line);
  color: var(--ui-fg);
  width: 30px;
  height: 30px;
  border-radius: 3px;
  cursor: pointer;
}

.panel-tabs {
  display: flex;
  border-bottom: 1px solid var(--ui-line);
  overflow-x: auto;
  scrollbar-width: none;
}
.panel-tabs::-webkit-scrollbar { display: none; }
.panel-tabs button {
  flex: 1 1 auto;
  padding: 11px 6px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--ui-dim);
  font-size: 11px;
  letter-spacing: .04em;
  text-transform: uppercase;
  cursor: pointer;
  white-space: nowrap;
}
.panel-tabs button.active { color: #fff; border-bottom-color: var(--accent); }

.panel-body { flex: 1; overflow-y: auto; padding: 12px 14px 28px; -webkit-overflow-scrolling: touch; }

.group { margin-bottom: 18px; }
.group > h2 {
  font-size: 11px;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--ui-dim);
  margin: 0 0 8px;
  font-weight: 700;
}
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 6px; }

.btn {
  appearance: none;
  border: 1px solid var(--ui-line);
  background: rgba(255, 255, 255, .05);
  color: var(--ui-fg);
  padding: 10px 8px;
  font-size: 12px;
  border-radius: 3px;
  cursor: pointer;
  text-align: left;
  min-height: 42px;
  line-height: 1.25;
}
.btn:hover { background: rgba(255, 255, 255, .12); }
.btn:active { transform: scale(.97); }
.btn.wide { grid-column: 1 / -1; }
.btn.danger { border-color: rgba(200, 30, 30, .5); color: #ff8181; }
.btn small { display: block; color: var(--ui-dim); font-size: 10px; margin-top: 2px; }

.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 7px 0; }
.row label { font-size: 13px; }
.row .val { font-size: 12px; color: var(--ui-dim); min-width: 44px; text-align: right; font-variant-numeric: tabular-nums; }
input[type=range] { flex: 1; accent-color: var(--accent); min-width: 90px; height: 28px; }

.toggle {
  position: relative;
  width: 44px;
  height: 26px;
  border-radius: 13px;
  background: rgba(255, 255, 255, .12);
  border: 1px solid var(--ui-line);
  cursor: pointer;
  flex: 0 0 auto;
}
.toggle::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #999;
  transition: .15s;
}
.toggle.on { background: rgba(200, 30, 30, .35); }
.toggle.on::after { left: 20px; background: #ff5a5a; }

.hint { font-size: 11px; color: var(--ui-dim); line-height: 1.5; }
.kbd {
  display: inline-block;
  border: 1px solid var(--ui-line);
  border-bottom-width: 2px;
  border-radius: 3px;
  padding: 0 5px;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 11px;
  margin-right: 3px;
}

/* ---------- Тач-управление ---------- */
.touch-layer { position: fixed; inset: 0; z-index: 20; pointer-events: none; }
.touch-layer[hidden] { display: none; }

.tc {
  position: absolute;
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .35);
  background: rgba(16, 16, 16, .3);
  color: rgba(255, 255, 255, .85);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .04em;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .8);
  backdrop-filter: blur(2px);
  transition: background .08s, transform .08s;
}
.tc.pressed { background: rgba(200, 30, 30, .45); transform: scale(.93); }

.stick-base {
  position: absolute;
  width: 130px;
  height: 130px;
  border-radius: 50%;
  border: 2px dashed rgba(255, 255, 255, .3);
  pointer-events: none;
  opacity: 0;
  transition: opacity .12s;
}
.stick-base.live { opacity: 1; }
.stick-knob {
  position: absolute;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .22);
  border: 2px solid rgba(255, 255, 255, .5);
  pointer-events: none;
  opacity: 0;
  transition: opacity .12s;
}
.stick-knob.live { opacity: 1; }

.boot-error {
  position: fixed;
  inset: auto 12px 12px 12px;
  background: #300;
  border: 1px solid #a33;
  color: #fdd;
  padding: 10px;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 12px;
  white-space: pre-wrap;
  z-index: 99;
}
.boot-error[hidden] { display: none; }

.rotate-hint {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: var(--ui-bg);
  border: 1px solid var(--ui-line);
  padding: 10px 16px;
  font-size: 12px;
  letter-spacing: .1em;
  border-radius: 3px;
  pointer-events: none;
}
.rotate-hint[hidden] { display: none; }

/* Тач-режим: правый нижний угол целиком отдан кнопкам, поэтому
   оружие/патроны переезжают наверх, а киллфид — под них. */
body.touch-on .perf { display: none; }
body.touch-on .hud-right {
  bottom: auto;
  top: calc(8px + var(--safe-t));
  right: calc(58px + var(--safe-r));
  display: flex;
  align-items: baseline;
  gap: 8px;
}
body.touch-on .hud-right .weapon-name { font-size: 12px; }
body.touch-on .hud-right .ammo { font-size: 20px; }
body.touch-on .hud-top { top: calc(44px + var(--safe-t)); }

@media (max-height: 460px) {
  .hud-right .ammo { font-size: 22px; }
  .hud-right .weapon-name { font-size: 13px; }
  .hp-bar { width: min(28vw, 170px); height: 11px; }
  .hp-num { font-size: 16px; }
}
