:root {
  --bg-dark: #120a0a;
  --bg-dark2: #1d1010;
  --gold: #e8b04a;
  --gold-dim: #a97c34;
  --red: #c9432f;
  --green: #6fbf4f;
  --cream: #f1e6d8;
  --muted: #b79a86;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; user-select: none; }

html, body {
  margin: 0; padding: 0; width: 100%; height: 100%;
  background: var(--bg-dark);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--cream);
  overflow: hidden;
  overscroll-behavior: none;
}

#canvasWrap { position: fixed; inset: 0; }
#c { width: 100%; height: 100%; display: block; touch-action: none; }

/* ---------------- damage / hit flashes ---------------- */
#vignette {
  position: fixed; inset: 0; pointer-events: none; z-index: 30;
  box-shadow: inset 0 0 0 0 rgba(201,67,47,0);
}
#vignette.flashDamage { animation: dmgFlash 0.5s ease-out; }
@keyframes dmgFlash {
  0%   { box-shadow: inset 0 0 140px 40px rgba(201,67,47,0.85); }
  100% { box-shadow: inset 0 0 140px 40px rgba(201,67,47,0); }
}
#hitFlash {
  position: fixed; inset: 0; pointer-events: none; z-index: 29;
  background: rgba(255,255,255,0);
}
#hitFlash.flashHit { animation: hitFlash 0.18s ease-out; }
@keyframes hitFlash {
  0%   { background: rgba(255, 225, 150, 0.28); }
  100% { background: rgba(255, 225, 150, 0); }
}

/* ---------------- overlays (menu / gameover / victory) ---------------- */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  display: none; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, rgba(40,18,18,0.55) 0%, rgba(8,4,4,0.92) 75%);
  padding: 24px;
}
.menuCard {
  width: 100%; max-width: 380px;
  max-height: calc(100dvh - 24px); overflow-y: auto;
  background: linear-gradient(180deg, #241413, #170d0c);
  border: 2px solid var(--gold-dim);
  outline: 1px solid rgba(0,0,0,0.6);
  outline-offset: -8px;
  border-radius: 14px;
  padding: 28px 24px 24px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}
.menuCard h1 {
  font-size: 34px;
  margin: 0 0 6px;
  font-weight: 800;
  letter-spacing: 0.5px;
  color: var(--gold);
  text-shadow: 0 0 18px rgba(232,176,74,0.5), 0 2px 0 #000;
  transform: skewX(-2deg);
}
.menuCard h1.badTitle { color: var(--red); text-shadow: 0 0 18px rgba(201,67,47,0.55), 0 2px 0 #000; }
.menuCard h1.goodTitle { color: var(--green); text-shadow: 0 0 18px rgba(111,191,79,0.5), 0 2px 0 #000; }
.subtitle { color: var(--muted); font-size: 14.5px; margin: 0 0 20px; line-height: 1.4; }
.versionNote { margin-bottom: 16px; color: #c8ad96; font-size: 12.5px; }

.diffRow { display: flex; gap: 10px; margin-bottom: 18px; }
.diffBtn {
  flex: 1; padding: 10px 0; border-radius: 8px;
  border: 1.5px solid var(--gold-dim); background: transparent; color: var(--muted);
  font-size: 14px; font-weight: 700; cursor: pointer;
}
.diffBtn.active { background: var(--gold); color: #221208; border-color: var(--gold); }

.bigBtn {
  display: block; width: 100%; padding: 15px 0; margin-bottom: 10px;
  border: none; border-radius: 10px;
  background: linear-gradient(180deg, var(--gold), var(--gold-dim));
  color: #221208; font-size: 18px; font-weight: 800; letter-spacing: 0.3px;
  cursor: pointer;
  box-shadow: 0 6px 0 #6b4d1e, 0 10px 18px rgba(0,0,0,0.4);
}
.bigBtn:active { transform: translateY(4px); box-shadow: 0 2px 0 #6b4d1e; }

.downloadBtn {
  display: flex; width: 100%; min-height: 54px; margin-bottom: 10px; padding: 9px 14px;
  align-items: center; justify-content: center; gap: 11px;
  border: 1.5px solid rgba(111,191,79,0.72); border-radius: 10px;
  background: linear-gradient(180deg, rgba(51,88,39,0.78), rgba(25,53,20,0.88));
  color: #e9f5e4; text-decoration: none; cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.08), 0 5px 14px rgba(0,0,0,0.3);
  transition: transform 0.16s ease, border-color 0.16s ease, filter 0.16s ease;
}
.downloadBtn:hover { border-color: #8ed270; filter: brightness(1.08); }
.downloadBtn:active { transform: translateY(2px) scale(0.99); }
.downloadBtn:focus-visible { outline: 3px solid rgba(232,176,74,0.55); outline-offset: 2px; }
.downloadBtn > span:last-child { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.15; }
.downloadBtn b { font-size: 14px; letter-spacing: 0.15px; }
.downloadBtn small { margin-top: 4px; color: #b9d5ae; font-size: 10.5px; font-weight: 600; }
.downloadIcon {
  display: grid; width: 31px; height: 31px; flex: 0 0 31px; place-items: center;
  border: 1px solid rgba(190,232,173,0.5); border-radius: 50%;
  color: #d9f3cf; font-size: 23px; font-weight: 800; line-height: 1;
}

.ghostBtn {
  display: block; width: 100%; padding: 11px 0; margin-bottom: 4px;
  border: 1.5px solid var(--gold-dim); border-radius: 10px;
  background: transparent; color: var(--muted); font-size: 14px; font-weight: 600;
  cursor: pointer;
}

.howto { margin-top: 18px; font-size: 12.5px; color: var(--muted); line-height: 1.5; border-top: 1px solid rgba(169,124,52,0.3); padding-top: 14px; }

/* ---------------- settings screen ---------------- */
.settingRow { margin-bottom: 18px; }
.settingRow label { display: block; color: var(--muted); font-size: 14px; font-weight: 700; margin-bottom: 10px; }
.settingSliderRow { display: flex; align-items: center; gap: 12px; }
.settingSliderRow input[type="range"] {
  flex: 1; -webkit-appearance: none; appearance: none;
  height: 6px; border-radius: 4px; background: rgba(169,124,52,0.35); outline: none;
}
.settingSliderRow input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 24px; height: 24px; border-radius: 50%;
  background: linear-gradient(180deg, var(--gold), var(--gold-dim));
  border: 2px solid #221208; cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,0.5);
}
.settingSliderRow input[type="range"]::-moz-range-thumb {
  width: 24px; height: 24px; border-radius: 50%;
  background: linear-gradient(180deg, var(--gold), var(--gold-dim));
  border: 2px solid #221208; cursor: pointer;
}
.settingSliderRow span {
  min-width: 52px; text-align: right;
  color: var(--gold); font-size: 15px; font-weight: 800; font-variant-numeric: tabular-nums;
}
.settingsCard { max-height: min(92vh, 640px); overflow-y: auto; }
.layoutRow { display: flex; flex-direction: column; gap: 8px; }
.layoutBtn {
  text-align: left; padding: 12px 14px; border-radius: 12px;
  background: rgba(20,12,10,0.55); border: 1.5px solid rgba(169,124,52,0.35);
  color: var(--cream); cursor: pointer;
}
.layoutBtn .layoutTitle { display: block; font-weight: 800; font-size: 15px; color: var(--gold); margin-bottom: 3px; }
.layoutBtn .layoutHint { display: block; font-size: 12px; color: var(--muted); line-height: 1.35; }
.layoutBtn.active {
  border-color: var(--gold);
  background: rgba(232,176,74,0.14);
  box-shadow: 0 0 0 1px rgba(232,176,74,0.25);
}

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

#topBar {
  position: fixed; top: calc(14px + env(safe-area-inset-top)); left: 14px; right: 14px;
  display: flex; justify-content: space-between; align-items: center;
  z-index: 25; pointer-events: none;
}
#hearts { font-size: 24px; letter-spacing: 3px; filter: drop-shadow(0 2px 3px rgba(0,0,0,0.7)); }
#keyBadge {
  background: rgba(20,12,10,0.7); border: 1px solid var(--gold-dim); border-radius: 20px;
  padding: 6px 14px; font-weight: 700; font-size: 15px; color: var(--gold);
}
#topRight { display: flex; align-items: center; gap: 8px; pointer-events: all; }
.hudIconBtn {
  width: 34px; height: 34px; border-radius: 50%;
  background: rgba(20,12,10,0.7); border: 1px solid var(--gold-dim);
  color: var(--gold); font-size: 17px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  padding: 0; cursor: pointer;
  position: relative; z-index: 26; pointer-events: all;
}
.hudIconBtn:active { background: rgba(20,12,10,0.95); }

#prompt {
  /* Подсказка действия — у самого низа экрана, на одном уровне с кнопкой
     "действие", чтобы явно указывать, что жать, а не отвлекать в центре кадра. */
  position: fixed; bottom: calc(50px + env(safe-area-inset-bottom));
  left: 50%; transform: translate(-50%, 0); pointer-events: none; z-index: 22;
  background: rgba(15,9,8,0.8); border: 1px solid var(--gold-dim); border-radius: 8px;
  padding: 8px 16px; font-size: 14px; font-weight: 600; color: var(--cream);
  opacity: 0; transition: opacity 0.15s; white-space: nowrap;
}
#toast {
  position: fixed; top: 16%; left: 50%; transform: translate(-50%, 0);
  background: rgba(15,9,8,0.85); border: 1px solid var(--gold); border-radius: 8px;
  padding: 9px 18px; font-size: 14.5px; font-weight: 700; color: var(--gold);
  opacity: 0; transition: opacity 0.3s; text-align: center; max-width: 80vw;
}

#invBar {
  position: fixed; top: calc(60px + env(safe-area-inset-top)); left: 14px;
  display: flex; gap: 8px;
}
.invIcon {
  width: 42px; height: 42px; object-fit: contain; padding: 4px;
  background: rgba(15,9,8,0.7); border: 1.5px solid var(--gold-dim); border-radius: 8px;
  pointer-events: all;
}
.invIcon.heldIcon { border-color: var(--gold); box-shadow: 0 0 10px rgba(232,176,74,0.7); }

/* ---------------- touch controls ---------------- */
#joyBase {
  position: fixed; left: 26px; bottom: calc(30px + env(safe-area-inset-bottom));
  width: var(--joy-size, 120px); height: var(--joy-size, 120px); border-radius: 50%;
  background: rgba(255,255,255,0.06); border: 2px solid rgba(232,176,74,0.35);
  pointer-events: all;
}
#joyKnob {
  position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px 0 0 -26px;
  border-radius: 50%; background: rgba(232,176,74,0.55); border: 2px solid rgba(232,176,74,0.8);
  transition: transform 0.02s linear;
}
#lookZone {
  /* Только верх/середина правой половины — низ отдаём кнопкам, иначе свайп
     камеры перехватывает нажатия на удар/действие/бег. */
  position: fixed; right: 0; top: calc(64px + env(safe-area-inset-top));
  width: 55%; height: 55%;
  pointer-events: all; z-index: 21;
}

/* Масштаб кнопок задаётся через --btn-scale на #hud (настройки).
   Базовый размер чуть крупнее прежнего — на телефоне так удобнее попадать. */
#hud {
  --btn-scale: 1.15;
  --btn-size: calc(68px * var(--btn-scale));
  --btn-action-size: calc(78px * var(--btn-scale));
  --btn-font: calc(22px * var(--btn-scale));
  --btn-label: calc(9.5px * var(--btn-scale));
  --cluster-gap: calc(11px * var(--btn-scale));
  --cluster-width: calc(168px * var(--btn-scale));
  --joy-size: calc(120px * min(1.15, var(--btn-scale)));
}

#buttonCluster {
  position: fixed; right: 18px; bottom: calc(26px + env(safe-area-inset-bottom));
  display: flex; flex-wrap: wrap; flex-direction: row-reverse; align-items: flex-end;
  justify-content: flex-start; gap: var(--cluster-gap); width: var(--cluster-width);
  pointer-events: all;
}
/* 4 кнопки в 2 ряда по 2 (row-reverse + wrap). */
.ctrlBtn {
  width: var(--btn-size); height: var(--btn-size); border-radius: 50%;
  background: rgba(30,16,14,0.75); border: 2px solid var(--gold-dim);
  color: var(--cream); font-size: var(--btn-font); display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 1px;
  pointer-events: all;
}
.ctrlBtn span { font-size: var(--btn-label); font-weight: 700; color: var(--muted); }
.ctrlBtn.pressed { background: rgba(232,176,74,0.35); border-color: var(--gold); transform: scale(0.94); }
.ctrlBtn.hitBtn { border-color: var(--red); }
.ctrlBtn.hitBtn.pressed { background: rgba(201,67,47,0.4); border-color: var(--red); }
.ctrlBtn.actionBtn { width: var(--btn-action-size); height: var(--btn-action-size); }
.ctrlBtn.sprintBtn { border-color: rgba(120,200,255,0.55); }
.ctrlBtn.sprintBtn.pressed { background: rgba(120,200,255,0.3); border-color: #78c8ff; }

/* Раскладка «раздельно»: спринт уезжает влево над джойстиком */
#hud.layout-split #btnSprint {
  position: fixed;
  left: 32px;
  bottom: calc(170px + env(safe-area-inset-bottom));
  /* вытаскиваем из flex-кластера */
}
#hud.layout-split #buttonCluster {
  /* без спринта кластер уже из 3 кнопок */
  width: calc(var(--cluster-width) * 0.72);
}

#joyBase {
  width: var(--joy-size); height: var(--joy-size);
}

@media (max-height: 420px) {
  .overlay { padding: 10px; }
  .menuCard { padding: 18px 20px 16px; }
  .menuCard h1 { font-size: 28px; }
  .subtitle { margin-bottom: 10px; }
  .howto { margin-top: 12px; padding-top: 10px; }
  #hud {
    --btn-size: calc(56px * var(--btn-scale));
    --btn-action-size: calc(64px * var(--btn-scale));
    --cluster-gap: calc(8px * var(--btn-scale));
    --cluster-width: calc(140px * var(--btn-scale));
    --joy-size: calc(100px * min(1.15, var(--btn-scale)));
  }
  #hud.layout-split #btnSprint {
    bottom: calc(140px + env(safe-area-inset-bottom));
  }
  #prompt { bottom: calc(50px + env(safe-area-inset-bottom)); font-size: 13px; }
}

/* ---------------- stealth indicator ---------------- */
#stealthBadge {
  background: rgba(20,12,10,0.72); border: 1px solid var(--gold-dim); border-radius: 20px;
  padding: 5px 12px; font-weight: 700; font-size: 13px; color: var(--muted);
  transition: color 0.2s, border-color 0.2s, box-shadow 0.2s;
}
#stealthBadge.hidden { color: #8fbf87; border-color: rgba(111,191,79,0.45); }
#stealthBadge.searching { color: var(--gold); border-color: var(--gold); }
#stealthBadge.seen {
  color: #ffd9d0; border-color: var(--red); background: rgba(90,20,14,0.8);
  box-shadow: 0 0 14px rgba(201,67,47,0.55);
  animation: seenPulse 0.9s ease-in-out infinite;
}
@keyframes seenPulse { 50% { box-shadow: 0 0 4px rgba(201,67,47,0.25); } }

/* ---------------- sprint button + stamina bar ---------------- */
/* Кнопка спринта перенесена в правый кластер (см. #buttonCluster ниже, класс
   .sprintBtn) — она больше НЕ позиционируется здесь отдельным fixed-блоком.
   Раньше она висела слева над джойстиком, что вынуждало тот же палец, который
   двигает джойстик, ещё и дотягиваться до спринта, пока правая рука ничего не
   делала. Теперь спринт держится вместе с прыжком/ударом/действием — правой
   рукой, что для одноручного удержания джойстика гораздо удобнее.
   Полоска стамины (чисто индикатор, не кнопка) остаётся слева над джойстиком,
   раз её не нужно нажимать — на неё просто поглядывают боковым зрением. */
#staminaWrap {
  position: fixed; left: 26px; bottom: calc(152px + env(safe-area-inset-bottom));
  width: 120px; height: 9px; border-radius: 6px;
  background: rgba(10,6,6,0.75); border: 1px solid rgba(232,176,74,0.35);
  overflow: hidden;
}
#staminaFill {
  height: 100%; width: 100%; border-radius: 5px;
  background: linear-gradient(90deg, #4c9fd6, #8fd6ff);
  transition: width 0.08s linear, background 0.25s;
}
#staminaFill.active { background: linear-gradient(90deg, #6fd0ff, #cdefff); }
#staminaFill.low { background: linear-gradient(90deg, #8d2c1e, #c9432f); }

@media (max-height: 420px) {
  #staminaWrap { width: 100px; bottom: calc(126px + env(safe-area-inset-bottom)); }
}


/* ---------------- control editor ---------------- */
#controlEditOverlay {
  display: none; z-index: 60; background: rgba(0,0,0,0.35);
  pointer-events: none; /* bar itself is interactive */
  align-items: flex-start; justify-content: center;
  padding-top: calc(10px + env(safe-area-inset-top));
}
#controlEditOverlay.visible { display: flex; }
#controlEditBar {
  pointer-events: all;
  width: min(94vw, 420px);
  background: rgba(18,11,10,0.94);
  border: 1.5px solid var(--gold-dim);
  border-radius: 16px;
  padding: 12px 14px 14px;
  box-shadow: 0 8px 28px rgba(0,0,0,0.55);
}
.editBarTitle { font-weight: 800; color: var(--gold); font-size: 16px; }
.editBarHint { color: var(--muted); font-size: 12.5px; margin: 4px 0 10px; }
.editSizeRow { margin-bottom: 12px; }
.editSizeRow label { color: var(--muted); font-size: 13px; font-weight: 700; min-width: 52px; }
.editBarActions { display: flex; gap: 10px; }
.editBarActions .ghostBtn, .editBarActions .bigBtn { flex: 1; margin: 0; }
.bigBtn.secondaryBtn {
  background: rgba(232,176,74,0.12);
  border: 1.5px solid var(--gold-dim);
  color: var(--gold);
  margin-bottom: 8px;
}
.settingHint {
  font-size: 12.5px; color: var(--muted); line-height: 1.4;
  margin: -4px 0 14px;
}

/* В режиме правки кнопки подсвечиваются и перетаскиваются */
#hud.editing-controls .ctrlBtn,
#hud.editing-controls #joyBase {
  outline: 2px dashed rgba(232,176,74,0.85);
  outline-offset: 3px;
  box-shadow: 0 0 0 4px rgba(232,176,74,0.15);
  z-index: 40 !important;
}
#hud.editing-controls .ctrlBtn.selected,
#hud.editing-controls #joyBase.selected {
  outline: 3px solid #78c8ff;
  box-shadow: 0 0 16px rgba(120,200,255,0.45);
}
#hud.editing-controls #lookZone { pointer-events: none !important; }
#hud.editing-controls #staminaWrap { opacity: 0.35; pointer-events: none; }

/* Свободная раскладка: каждая кнопка — fixed, координаты задаёт JS */
#hud.free-layout #buttonCluster {
  /* кластер больше не позиционирует детей — только группирует в DOM */
  position: static; width: 0; height: 0; overflow: visible;
  display: block; gap: 0;
}
#hud.free-layout .ctrlBtn {
  position: fixed;
  z-index: 35;
  pointer-events: all !important;
  touch-action: none;
}
#hud.free-layout #joyBase {
  position: fixed;
  z-index: 35;
  pointer-events: all !important;
  touch-action: none;
}
#hud.free-layout #staminaWrap {
  /* стамина следует за джойстиком через JS */
  position: fixed;
}
