:root {
  --gold: #e7c860;
  --gold-deep: #b8902f;
  --ink: #3a2c16;
  --panel: rgba(58, 40, 18, 0.86);
  --accent: #d9534f;
  --good: #7fb33a;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: #1c1810;
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  user-select: none; -webkit-user-select: none;
  touch-action: none;
  overscroll-behavior: none;
}

#game {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
}

#gl {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  display: block;
  touch-action: none;
}

.hidden { display: none !important; }

/* ---------- Room transition fade ---------- */
#fade {
  position: absolute; inset: 0;
  background: #171206;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.28s ease;
  z-index: 20;
}
#fade.show { opacity: 1; }

/* ---------- FPS meter ---------- */
#fps {
  position: absolute;
  left: 8px; bottom: calc(8px + env(safe-area-inset-bottom));
  font: bold 12px/1 "Courier New", monospace;
  color: #d8ffa0;
  background: rgba(0,0,0,0.4);
  padding: 4px 7px; border-radius: 6px;
  z-index: 15; pointer-events: none;
}

/* ---------- Dev logger (mobile) ---------- */
#recBtn {
  position: absolute;
  right: 74px; bottom: calc(10px + env(safe-area-inset-bottom));
  z-index: 30;
  background: rgba(58,40,18,0.8);
  color: #f2cf5e;
  border: 2px solid var(--gold-deep);
  border-radius: 8px;
  font: bold 12px/1 "Trebuchet MS", sans-serif;
  padding: 8px 10px;
  pointer-events: auto;
  opacity: 0.7;
}
#recBtn:active, #recBtn.on { opacity: 1; background: rgba(150,60,40,0.9); }

#devlogBtn {
  position: absolute;
  right: 10px; bottom: calc(10px + env(safe-area-inset-bottom));
  z-index: 30;
  background: rgba(58,40,18,0.8);
  color: #f2cf5e;
  border: 2px solid var(--gold-deep);
  border-radius: 8px;
  font: bold 12px/1 "Trebuchet MS", sans-serif;
  padding: 8px 10px;
  pointer-events: auto;
  opacity: 0.7;
}
#devlogBtn:active { opacity: 1; }

#devlogPanel {
  position: absolute;
  inset: 6% 4% 12% 4%;
  z-index: 40;
  display: flex; flex-direction: column;
  background: rgba(16,12,6,0.96);
  border: 2px solid var(--gold-deep);
  border-radius: 12px;
  overflow: hidden;
  pointer-events: auto;
}
#devlogBar {
  display: flex; gap: 8px; padding: 8px;
  background: rgba(58,40,18,0.6);
}
.devlogAct {
  flex: 1;
  background: linear-gradient(180deg, #f2cf5e, #d99b2e);
  color: #3a2c16; border: none; border-radius: 8px;
  font: bold 14px/1 "Trebuchet MS", sans-serif;
  padding: 10px 8px; pointer-events: auto;
}
.devlogAct:last-child { flex: 0 0 48px; }
#devlogPre {
  flex: 1; margin: 0; padding: 8px;
  overflow: auto;
  font: 11px/1.35 "Courier New", monospace;
  color: #e7dcc0;
  white-space: pre-wrap; word-break: break-word;
  user-select: text; -webkit-user-select: text;
}

/* ---------- HUD ---------- */
#hud {
  position: absolute; inset: 0;
  pointer-events: none;
  padding: max(14px, env(safe-area-inset-top)) 14px 0;
}

#topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
}

#hpwrap { display: flex; align-items: center; gap: 8px; }

#hpbar {
  width: min(30vw, 240px); height: 16px;
  background: rgba(0,0,0,0.35);
  border: 2px solid rgba(0,0,0,0.45);
  border-radius: 10px;
  overflow: hidden;
}

#hpfill {
  height: 100%; width: 100%;
  background: linear-gradient(90deg, #e85b4a, #f2a23c);
  transition: width 0.12s ease-out;
}

#hplabel, #stats span {
  color: #fff7e0;
  font-weight: bold;
  font-size: clamp(12px, 3.6vw, 18px);
  white-space: nowrap;
  text-shadow: 0 2px 0 rgba(0,0,0,0.5);
}

#stats { display: flex; gap: 10px; }

#banner {
  position: absolute; top: 34%; left: 0; right: 0;
  text-align: center;
  color: #fff3cf;
  font-size: clamp(28px, 11vw, 64px);
  font-weight: 900;
  letter-spacing: 1px;
  text-shadow: 0 4px 0 rgba(0,0,0,0.4), 0 0 24px rgba(231,200,96,0.6);
  animation: bannerPop 0.5s ease-out;
}

@keyframes bannerPop {
  0% { transform: scale(0.6); opacity: 0; }
  60% { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

/* ---------- Joystick ---------- */
#stick { position: absolute; inset: 0; pointer-events: none; }

#stickBase, #stickKnob {
  position: absolute;
  left: 0; top: 0;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  will-change: transform;          /* move via transform only (compositor, no layout) */
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
}

#stickBase {
  width: 130px; height: 130px;
  background: rgba(255,255,255,0.08);
  border: 3px solid rgba(255,255,255,0.22);
}

#stickKnob {
  width: 64px; height: 64px;
  background: rgba(255,247,224,0.35);
  border: 3px solid rgba(255,255,255,0.5);
}

#stick.active #stickBase, #stick.active #stickKnob { opacity: 1; }

/* ---------- Overlays ---------- */
.overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center;
  gap: 18px; padding: 28px;
  background: radial-gradient(circle at 50% 40%, rgba(28,24,16,0.55), rgba(20,16,10,0.92));
  z-index: 10;
}

.overlay h1 {
  color: var(--gold);
  font-size: clamp(40px, 15vw, 92px);
  font-weight: 900;
  line-height: 0.95;
  letter-spacing: 2px;
  text-shadow: 0 6px 0 var(--gold-deep), 0 10px 18px rgba(0,0,0,0.6);
}

.overlay h2 {
  color: var(--gold);
  font-size: clamp(28px, 9vw, 52px);
  font-weight: 900;
  text-shadow: 0 4px 0 var(--gold-deep), 0 8px 14px rgba(0,0,0,0.6);
}

.overlay .sub { color: #efe2bf; font-size: clamp(15px, 4.6vw, 21px); line-height: 1.4; }
.overlay .hint { color: #bcae8a; font-size: clamp(12px, 3.6vw, 15px); max-width: 420px; }
.overlay .best { color: #f2c14e; font-size: clamp(14px, 4.4vw, 18px); font-weight: bold; }

.btn {
  pointer-events: auto;
  background: linear-gradient(180deg, #f2cf5e, #d99b2e);
  color: #3a2c16;
  border: none;
  border-radius: 16px;
  padding: 16px 34px;
  font-size: clamp(18px, 5.5vw, 24px);
  font-weight: 900;
  letter-spacing: 1px;
  box-shadow: 0 6px 0 #9c6f1e, 0 10px 18px rgba(0,0,0,0.45);
  cursor: pointer;
  transition: transform 0.06s, box-shadow 0.06s;
}
.btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #9c6f1e, 0 4px 10px rgba(0,0,0,0.45); }

#deathStats { color: #efe2bf; font-size: clamp(16px, 5vw, 22px); line-height: 1.7; }
#deathStats b { color: var(--gold); }

/* ---------- Perk cards ---------- */
#perkCards { display: flex; flex-direction: column; gap: 14px; width: min(92vw, 440px); }

.perkCard {
  pointer-events: auto;
  background: var(--panel);
  border: 3px solid var(--gold-deep);
  border-radius: 16px;
  padding: 16px 18px;
  text-align: left;
  cursor: pointer;
  display: flex; align-items: center; gap: 14px;
  transition: transform 0.08s, border-color 0.08s;
}
.perkCard:active { transform: scale(0.97); border-color: var(--gold); }
.perkCard .ic { font-size: 34px; line-height: 1; }
.perkCard .txt h3 { color: var(--gold); font-size: clamp(17px, 5vw, 21px); margin-bottom: 3px; }
.perkCard .txt p { color: #e7dcc0; font-size: clamp(13px, 3.8vw, 15px); line-height: 1.3; }

/* ---------- Meta shop ---------- */
.btn2 {
  background: linear-gradient(180deg, #8a6a34, #5e4420);
  color: #f7e6b8;
  box-shadow: 0 6px 0 #3e2c12, 0 10px 18px rgba(0,0,0,0.45);
  font-size: clamp(15px, 4.6vw, 20px);
  padding: 13px 26px;
}
.btn2:active { box-shadow: 0 2px 0 #3e2c12, 0 4px 10px rgba(0,0,0,0.45); }
#ebLabel { color: #ffd75e !important; }
#shopCards { display: flex; flex-direction: column; gap: 10px; width: min(100%, 460px); align-self: center; flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 2px 2px 6px; }
.shopCard { padding: 12px 14px; }
.shopCard .txt { flex: 1; text-align: left; }
.shopCard .pips { display: inline-flex; gap: 3px; margin-left: 6px; vertical-align: middle; }
.shopCard .pips i { width: 8px; height: 8px; border-radius: 50%; border: 1.5px solid #f2c14e; }
.shopCard .pips i.on { background: #f2c14e; }
.shopCard .price { color: #ffd75e; font-weight: 900; font-size: clamp(15px, 4.6vw, 19px); white-space: nowrap; }
.shopCard.poor { opacity: 0.55; }
.shopCard.maxed { border-color: var(--good); opacity: 0.8; }
.shopCard.shake { animation: shopShake 0.3s; }
@keyframes shopShake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
#deathStats small { color: #bcae8a; font-size: 0.72em; }

/* ---------- Combat buttons (drone / finish / capture) ---------- */
.actBtn {
  pointer-events: auto;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  width: 74px; height: 74px; border-radius: 50%;
  background: rgba(58,40,18,0.82);
  border: 3px solid var(--gold-deep);
  color: #fff7e0; font-size: 28px; line-height: 1;
  box-shadow: 0 4px 10px rgba(0,0,0,0.4);
  touch-action: none; user-select: none; -webkit-user-select: none;
}
.actBtn span { font: 900 10px/1 "Trebuchet MS", sans-serif; letter-spacing: 0.5px; color: #f2cf5e; }
.actBtn:active { transform: scale(0.94); border-color: var(--gold); }
#droneBtn {
  position: absolute; z-index: 8;
  right: 14px; bottom: calc(64px + env(safe-area-inset-bottom));
}
#droneBtn.cool { opacity: 0.55; }
#droneBtn.shake { animation: shopShake 0.3s; }
#actions {
  position: absolute; z-index: 8;
  right: 14px; bottom: calc(150px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 10px;
}
#actFinish { border-color: #c0503c; }
#actCapture { border-color: var(--good); }
#actCapture.busy { background: rgba(60,110,40,0.9); }

/* ---------- FPV icon ---------- */
.fpvIcon { width: 38px; height: 38px; display: block; }
.shopCard .ic .fpvIcon { width: 36px; height: 36px; }

/* ---------- Pause + settings ---------- */
#pauseBtn {
  position: absolute; z-index: 8;
  right: 12px; top: calc(max(14px, env(safe-area-inset-top)) + 34px);
  width: 40px; height: 40px; border-radius: 50%;
  background: rgba(58,40,18,0.75); border: 2px solid var(--gold-deep);
  color: #f2cf5e; font-size: 22px; line-height: 1; pointer-events: auto;
}
#setPanel {
  width: min(92vw, 440px);
  background: var(--panel); border: 3px solid var(--gold-deep); border-radius: 16px;
  padding: 12px 16px; display: flex; flex-direction: column; gap: 12px;
}
.setRow { display: flex; align-items: center; gap: 12px; color: #efe2bf; font-weight: bold; font-size: clamp(15px, 4.4vw, 18px); }
.setRow > span:first-child { flex: 0 0 34%; text-align: left; }
.setRow input[type=range] { flex: 1; accent-color: #f2c14e; pointer-events: auto; }
.setRow b { color: var(--gold); min-width: 44px; text-align: right; }
.toggle {
  pointer-events: auto; margin-left: auto;
  min-width: 96px; padding: 8px 14px; border-radius: 10px; border: none;
  background: linear-gradient(180deg, #8fcf4a, #5e9a2a); color: #1f2e0e;
  font: 900 14px/1 "Trebuchet MS", sans-serif;
}
.toggle.off { background: linear-gradient(180deg, #8a6a34, #5e4420); color: #f7e6b8; }
.setLangRow { align-items: flex-start; }
#setLangs { flex: 1; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.langBtn {
  pointer-events: auto; padding: 7px 6px; border-radius: 8px;
  border: 2px solid var(--gold-deep); background: rgba(0,0,0,0.25);
  color: #efe2bf; font: bold 13px/1.1 "Trebuchet MS", system-ui, sans-serif;
}
.langBtn.on { background: linear-gradient(180deg, #f2cf5e, #d99b2e); color: #3a2c16; border-color: var(--gold); }
#settings { gap: 14px; overflow-y: auto; }

.legal { font-size: 12px; color: #bcae8a; }
.legal a { color: #bcae8a; pointer-events: auto; }

/* ---------- Маркет: layout with the avatar stage ---------- */
#shop { justify-content: flex-start; gap: 8px; padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom)); }
#shop h2 { font-size: clamp(24px, 7.5vw, 42px); }
#shopBody { flex: 1 1 auto; min-height: 0; width: min(96vw, 940px); display: flex; flex-direction: column; gap: 8px; }
#shopHero { flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; gap: 2px; }
#shopStage {
  height: clamp(170px, 33vh, 330px); aspect-ratio: 260 / 300;
  background: radial-gradient(ellipse 60% 55% at 50% 52%, rgba(242,207,94,0.26), rgba(242,207,94,0) 70%);
}
#shopInfo { color: #efe2bf; font-weight: bold; font-size: clamp(13px, 3.9vw, 17px); }
#shopInfo b { color: var(--gold); }
#shopGear { color: #bcae8a; }
.shopNote { color: #bcae8a; font-size: clamp(11px, 3.2vw, 13px); max-width: 460px; }
@media (min-width: 760px) and (min-aspect-ratio: 1/1) {
  #shopBody { flex-direction: row; align-items: stretch; }
  #shopHero { flex: 0 0 44%; justify-content: center; }
  #shopStage { height: min(64vh, 470px); }
  #shopCards { align-self: stretch; }
}

/* ---------- avatar animation ---------- */
.avatar { width: 100%; height: 100%; display: block; overflow: visible; }
.avatar .av-upper { animation: avBreathe 3.2s ease-in-out infinite; }
@keyframes avBreathe { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-1.6px); } }
.avatar .av-head { transform-origin: 130px 99px; animation: avHead 6.5s ease-in-out infinite; }
@keyframes avHead { 0%, 100% { transform: rotate(0deg); } 30% { transform: rotate(-2.2deg); } 65% { transform: rotate(1.6deg); } }
.avatar .av-eyes { transform-box: fill-box; transform-origin: center; animation: avBlink 4.8s infinite; }
@keyframes avBlink { 0%, 92%, 100% { transform: scaleY(1); } 94% { transform: scaleY(0.1); } }
.avatar .av-drone { animation: avHover 2.2s ease-in-out infinite; }
.avatar .av-drone.b { animation-duration: 2.7s; animation-delay: -1.2s; }
@keyframes avHover { 0%, 100% { transform: translate(0, 0) rotate(-3deg); } 50% { transform: translate(-2px, -6px) rotate(3deg); } }
.avatar .av-prop { transform-box: fill-box; transform-origin: center; animation: avProp 0.13s linear infinite; }
@keyframes avProp { 0%, 100% { transform: scaleX(1); } 50% { transform: scaleX(0.22); } }
.avatar .av-led { animation: avLed 1.1s infinite; }
.avatar .av-led.b { animation-duration: 0.8s; }
.avatar .av-led.c { animation-duration: 1.5s; animation-delay: -0.4s; }
@keyframes avLed { 0%, 55% { opacity: 1; } 56%, 100% { opacity: 0.15; } }
.avatar .av-antenna { animation: avSway 2.8s ease-in-out infinite; }
.avatar .av-antenna.b { animation-delay: -1.1s; }
.avatar .av-antenna.c { animation-duration: 3.4s; }
.avatar .av-antenna.d { animation-duration: 1.4s; }
@keyframes avSway { 0%, 100% { transform: rotate(-1.6deg); } 50% { transform: rotate(1.6deg); } }
.avatar .av-ugv { animation: avUgv 1.6s ease-in-out infinite; }
@keyframes avUgv { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-1.3px); } }
.avatar .av-tread { animation: avTread 0.5s linear infinite; }
@keyframes avTread { to { stroke-dashoffset: -6; } }
.avatar .av-dust circle { transform-box: fill-box; transform-origin: center; animation: avDust 0.9s ease-out infinite; }
@keyframes avDust { 0% { transform: translateY(0) scale(0.3); opacity: 0.85; } 100% { transform: translateY(-5px) scale(1.7); opacity: 0; } }
.avatar .av-beam { animation: avBeam 2.4s ease-in-out infinite; }
@keyframes avBeam { 0%, 100% { opacity: 0.5; } 50% { opacity: 0.95; } }
.avatar .av-glint { animation: avGlint 1.8s ease-in-out infinite; }
@keyframes avGlint { 0%, 100% { opacity: 0.65; } 50% { opacity: 1; } }
.avatar .av-chart { stroke-dasharray: 26; animation: avChart 2.4s linear infinite; }
@keyframes avChart { 0% { stroke-dashoffset: 26; } 60%, 100% { stroke-dashoffset: 0; } }
.avatar .pop { transform-box: fill-box; transform-origin: center; animation: avPop 0.7s cubic-bezier(.2, 1.6, .4, 1) both; }
@keyframes avPop { 0% { transform: scale(0.2); opacity: 0; } 55% { opacity: 1; } 100% { transform: scale(1); opacity: 1; } }
.avatar .av-spark { transform-box: fill-box; transform-origin: center; animation: avSpark 0.85s ease-out forwards; }
@keyframes avSpark { 0% { transform: scale(0.3) rotate(0deg); opacity: 1; } 100% { transform: scale(1.7) rotate(40deg); opacity: 0; } }
.avatar .ghost { opacity: 0.4; }
.avatar .hl { filter: url(#avGlow); }
@media (prefers-reduced-motion: reduce) { .avatar * { animation: none !important; } }
.langBtn.auto { grid-column: 1 / -1; }
