:root {
  --ink: #0b1020;
  --acid: #8aff3c;
  --red: #ff4d4d;
  --panel: rgba(11, 16, 32, 0.82);
}

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

html, body {
  width: 100%;
  height: 100dvh;
  overflow: hidden;
  background: var(--ink);
  font-family: -apple-system, "SF Pro Rounded", "Helvetica Neue", Arial, sans-serif;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

/* Слои: видео → фолбэк → canvas → HUD → оверлеи */
#camera-feed, #bg-fallback, #game-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100dvh;
}

#camera-feed { object-fit: cover; z-index: 0; }

#bg-fallback {
  z-index: 0;
  background:
    radial-gradient(ellipse at 30% 20%, #2a3550 0%, transparent 55%),
    radial-gradient(ellipse at 75% 80%, #1d2b1f 0%, transparent 55%),
    linear-gradient(180deg, #16203a 0%, #0b1020 100%);
}

#game-canvas { z-index: 1; }

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

#hud-top {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 10px);
  left: 0; right: 0;
  display: flex;
  justify-content: center;
  gap: 8px;
}

.hud-chip {
  background: var(--panel);
  color: #fff;
  border: 1.5px solid rgba(255,255,255,0.18);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 15px;
  font-weight: 700;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

#hud-kills { color: var(--acid); }

/* Прицел */
#crosshair {
  position: absolute;
  left: 50%; top: 50%;
  width: 64px; height: 64px;
  transform: translate(-50%, -50%);
}
.ch-ring {
  position: absolute; inset: 0;
  border: 3px solid rgba(255,255,255,0.9);
  border-radius: 50%;
  box-shadow: 0 0 8px rgba(0,0,0,0.5), inset 0 0 8px rgba(0,0,0,0.3);
  transition: transform 0.08s ease-out, border-color 0.08s;
}
.ch-dot {
  position: absolute;
  left: 50%; top: 50%;
  width: 6px; height: 6px;
  background: var(--red);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 6px var(--red);
}
#crosshair.recoil .ch-ring { transform: scale(1.35); border-color: var(--acid); }
#crosshair.on-target .ch-ring { border-color: var(--acid); }

/* Стрелка-радар к ближайшему слизню */
#radar-arrow {
  position: absolute;
  left: 50%; top: 50%;
  font-size: 34px;
  color: var(--acid);
  text-shadow: 0 0 10px rgba(138,255,60,0.8), 0 2px 4px rgba(0,0,0,0.6);
  transform-origin: center;
  animation: radar-pulse 0.9s ease-in-out infinite;
}
@keyframes radar-pulse {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}

/* Хитмаркер */
#hitmarker {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%) scale(0.5);
  font-size: 44px;
  font-weight: 900;
  color: var(--acid);
  text-shadow: 0 0 12px rgba(138,255,60,0.9);
  opacity: 0;
}
#hitmarker.show {
  animation: hit-pop 0.3s ease-out;
}
@keyframes hit-pop {
  0% { opacity: 1; transform: translate(-50%, -50%) scale(0.6); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.6); }
}

/* Кнопка огня */
#fire-btn {
  position: absolute;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 28px);
  transform: translateX(-50%);
  width: 92px; height: 92px;
  border-radius: 50%;
  border: 4px solid rgba(255,255,255,0.85);
  background: radial-gradient(circle at 35% 30%, #ff7b7b, var(--red) 60%, #b81f1f);
  box-shadow: 0 6px 20px rgba(255,77,77,0.45), 0 3px 0 #8f1616;
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.06s;
}
#fire-btn:active { transform: translateX(-50%) scale(0.9); }
.fire-core {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.9);
}

/* Вспышка выстрела */
#flash {
  position: fixed; inset: 0;
  background: radial-gradient(circle at 50% 50%, rgba(255,255,200,0.35), transparent 60%);
  opacity: 0;
  pointer-events: none;
}
#flash.show { animation: flash-anim 0.12s ease-out; }
@keyframes flash-anim { 0% { opacity: 1; } 100% { opacity: 0; } }

/* Оверлеи */
.overlay {
  position: fixed; inset: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(6, 9, 20, 0.72);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: 24px;
}
.overlay[hidden] { display: none; }

.panel {
  text-align: center;
  color: #fff;
  max-width: 420px;
  width: 100%;
}

.panel h1 {
  font-size: 44px;
  font-weight: 900;
  letter-spacing: 2px;
  color: var(--acid);
  text-shadow: 0 4px 0 #2c5c0e, 0 8px 24px rgba(138,255,60,0.35);
  margin: 14px 0 10px;
}

.panel h2 { font-size: 30px; font-weight: 900; margin-bottom: 10px; }

.subtitle { font-size: 17px; line-height: 1.45; opacity: 0.92; margin-bottom: 24px; }

.big-btn {
  font-size: 22px;
  font-weight: 900;
  letter-spacing: 1px;
  color: var(--ink);
  background: linear-gradient(180deg, #b4ff70, var(--acid));
  border: none;
  border-radius: 999px;
  padding: 18px 54px;
  box-shadow: 0 5px 0 #4d8c1c, 0 10px 24px rgba(138,255,60,0.35);
  cursor: pointer;
  transition: transform 0.08s;
}
.big-btn:active { transform: translateY(3px); }

.hint { font-size: 13px; opacity: 0.65; margin-top: 18px; line-height: 1.4; }
.best { font-size: 15px; color: var(--acid); margin-top: 14px; font-weight: 700; }

/* Плашка «гироскоп не отвечает» */
#gyro-warn {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 62px);
  left: 50%; transform: translateX(-50%);
  pointer-events: auto;
}
.gyro-warn-panel {
  background: rgba(255, 77, 77, 0.9);
  color: #fff;
  padding: 10px 16px 12px;
  border-radius: 14px;
  text-align: center;
  box-shadow: 0 6px 20px rgba(255,77,77,0.35);
  max-width: 300px;
}
.gyro-warn-title { font-size: 14px; font-weight: 900; }
.gyro-warn-sub { font-size: 12px; opacity: 0.92; margin: 2px 0 8px; }
#btn-gyro-enable {
  background: #fff;
  color: #a91d1d;
  border: none;
  border-radius: 999px;
  padding: 6px 16px;
  font-size: 13px;
  font-weight: 800;
}

/* Кнопка «сброс севера» */
#btn-recenter {
  position: absolute;
  right: 14px;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 48px);
  width: 46px; height: 46px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.55);
  background: rgba(11, 16, 32, 0.6);
  color: #fff;
  font-size: 20px;
  font-weight: 700;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  pointer-events: auto;
}

/* Настройки — полузаметная кнопка в левом нижнем углу */
#settings-btn {
  position: fixed;
  left: 10px;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 8px);
  z-index: 4;
  background: transparent;
  color: rgba(255,255,255,0.35);
  border: none;
  font: 11px/1 monospace;
  padding: 6px 8px;
  letter-spacing: 0.5px;
}
#settings-btn:hover, #settings-btn:active { color: rgba(255,255,255,0.85); }

#settings-panel {
  position: fixed;
  left: 8px; right: 8px;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 30px);
  max-height: 60dvh;
  z-index: 5;
  background: rgba(11, 16, 32, 0.94);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 14px;
  padding: 10px 12px 14px;
  overflow-y: auto;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 12px 32px rgba(0,0,0,0.5);
}
.set-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 800;
  font-size: 14px;
  margin-bottom: 8px;
  color: var(--acid);
}
.set-head > div { display: flex; gap: 6px; }
.set-head button {
  background: rgba(255,255,255,0.08);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 4px 10px;
  font: 12px/1 -apple-system, sans-serif;
  font-weight: 700;
}
#settings-close { font-size: 18px; padding: 2px 10px 4px; }
#settings-list { display: flex; flex-direction: column; gap: 10px; }
.set-row { display: flex; flex-direction: column; gap: 3px; }
.set-lbl { display: flex; justify-content: space-between; font-size: 12px; opacity: 0.9; }
.set-val { color: var(--acid); font-family: monospace; }
.set-row input[type="range"] {
  width: 100%;
  accent-color: var(--acid);
  height: 22px;
}

/* Debug-плашка (?debug=1) */
#debug {
  position: absolute;
  left: 8px;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 8px);
  background: rgba(0,0,0,0.6);
  color: #8aff3c;
  font: 11px/1.3 monospace;
  padding: 6px 8px;
  border-radius: 8px;
  max-width: 60vw;
  white-space: pre;
}

.logo-slime {
  width: 120px; height: 120px;
  margin: 0 auto;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  animation: logo-bob 2.2s ease-in-out infinite;
}
@keyframes logo-bob {
  0%, 100% { transform: translateY(0) scaleY(1); }
  50% { transform: translateY(-8px) scaleY(1.06); }
}
