:root {
  --stone: #caa472;
  --stone-dark: #9c7c4f;
  --ink: #2a2118;
  --panel: rgba(28, 22, 15, 0.82);
  --accent: #e9c46a;
  --danger: #e25b45;
}

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

html, body {
  width: 100%; height: 100%; overflow: hidden;
  background: #1a1410; color: #f3e9d8;
  font-family: -apple-system, "Segoe UI", "Heebo", Arial, sans-serif;
  touch-action: none; user-select: none; -webkit-user-select: none;
}

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

.hidden { display: none !important; }

/* ---------- Loading ---------- */
#loading {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 35%, #3a2c1c, #140f0a);
}
.loading-inner { text-align: center; }
.loading-inner h1 { font-size: 14vmin; letter-spacing: 0.4vmin; color: var(--accent); text-shadow: 0 0 24px rgba(233,196,106,.4); }
.loading-inner .sub { opacity: .65; margin-bottom: 24px; }
.bar { width: 64vmin; max-width: 420px; height: 10px; background: rgba(255,255,255,.12); border-radius: 6px; overflow: hidden; margin: 0 auto; }
#loading-bar { width: 0%; height: 100%; background: var(--accent); transition: width .2s; }
#loading-text { margin-top: 12px; opacity: .7; font-size: 14px; }

/* ---------- Start screen ---------- */
#start-screen {
  position: fixed; inset: 0; z-index: 40;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 30%, #3a2c1c, #120d09);
  padding: 16px;
}
.panel {
  background: var(--panel); border: 1px solid rgba(233,196,106,.25);
  border-radius: 18px; padding: 28px 26px; max-width: 720px; width: 100%;
  backdrop-filter: blur(6px); box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.panel h1 { font-size: 9vmin; color: var(--accent); letter-spacing: .3vmin; }
.panel .tag { opacity: .7; margin: 4px 0 18px; }
.controls-help { display: flex; gap: 18px; flex-wrap: wrap; }
.controls-help .col { flex: 1; min-width: 200px; background: rgba(255,255,255,.04); border-radius: 12px; padding: 14px 16px; }
.controls-help h3 { color: var(--accent); margin-bottom: 8px; font-size: 16px; }
.controls-help ul { list-style: none; line-height: 1.9; font-size: 14px; opacity: .92; }
.controls-help b { color: #fff; }
#start-btn {
  margin-top: 20px; width: 100%; padding: 16px; font-size: 20px; font-weight: 700;
  background: var(--accent); color: #2a2014; border: none; border-radius: 12px; cursor: pointer;
  transition: transform .1s, filter .1s;
}
#start-btn:active { transform: scale(.98); filter: brightness(1.08); }

/* ---------- HUD ---------- */
/* z-index מעל פקדי המגע (25) — כדי שכפתורי המפה/מקרא/סאונד יהיו לחיצים גם במובייל.
   ה-HUD עצמו pointer-events:none, רק האלמנטים האינטראקטיביים מקבלים auto. */
#hud { position: fixed; inset: 0; z-index: 26; pointer-events: none; }

/* מפת-מיני + לחצנים — למעלה משמאל */
#map-zone { position: absolute; top: 12px; left: 12px; display: flex; flex-direction: column; align-items: center; gap: 6px; }
#minimap {
  width: 150px; height: 150px; border-radius: 50%;
  border: 3px solid rgba(233,196,106,.6); background: #2a2118;
  box-shadow: 0 6px 18px rgba(0,0,0,.5); pointer-events: auto; cursor: pointer;
}
#map-buttons { display: flex; gap: 8px; }
#map-buttons button {
  pointer-events: auto; width: 40px; height: 40px; border-radius: 10px; font-size: 18px;
  background: var(--panel); border: 1px solid rgba(233,196,106,.5); color: #f3e9d8; cursor: pointer;
}
#map-buttons button:active { background: rgba(233,196,106,.4); }

/* מקרא צבעי המפה — איזה צבע = איזו חנות */
#map-legend {
  background: var(--panel); border: 1px solid rgba(233,196,106,.4); border-radius: 10px;
  padding: 6px 8px; font-size: 11px; line-height: 1.55; color: #f3e9d8;
  display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px;
  max-width: 230px; box-shadow: 0 4px 14px rgba(0,0,0,.45);
}
#map-legend.hidden { display: none; }
.legend-row { display: flex; align-items: center; gap: 5px; white-space: nowrap; }
.legend-dot {
  width: 9px; height: 9px; border-radius: 3px; flex: 0 0 auto;
  border: 1px solid rgba(0,0,0,.4);
}

/* סטטוס — למעלה מימין */
#stats { position: absolute; top: 12px; right: 12px; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
#clockbox { display: flex; gap: 8px; align-items: center; }
#clock { font-size: 20px; font-weight: 800; color: #fff; text-shadow: 0 2px 5px rgba(0,0,0,.6); font-variant-numeric: tabular-nums; }
#weather { font-size: 13px; background: var(--panel); padding: 2px 8px; border-radius: 12px; border: 1px solid rgba(255,255,255,.15); white-space: nowrap; }
#money { font-size: 26px; font-weight: 800; color: var(--accent); text-shadow: 0 2px 6px rgba(0,0,0,.6); }
#wanted { font-size: 22px; letter-spacing: 3px; min-height: 26px; filter: drop-shadow(0 2px 3px rgba(0,0,0,.6)); }
.bar-wrap { display: flex; align-items: center; gap: 8px; }
.bar-label { font-size: 12px; width: 30px; opacity: .85; text-align: center; }
.meter { width: 140px; height: 13px; background: rgba(0,0,0,.45); border-radius: 8px; overflow: hidden; border: 1px solid rgba(255,255,255,.15); }
#health-fill { width: 100%; height: 100%; background: linear-gradient(90deg, #e25b45, #f2a25c); transition: width .15s; }
#armor-fill { width: 100%; height: 100%; background: linear-gradient(90deg, #5b8def, #8fc1ff); transition: width .15s; }

#mission { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); font-size: 14px; color: #fff;
  background: var(--panel); padding: 6px 12px; border-radius: 10px; border: 1px solid rgba(58,139,255,.5); white-space: nowrap; }

#weapon-box {
  position: absolute; bottom: 16px; left: 16px; background: var(--panel);
  border-radius: 10px; padding: 8px 14px; font-size: 14px; display: flex; gap: 10px; align-items: baseline;
  border: 1px solid rgba(255,255,255,.12);
}
#weapon-name { color: #fff; font-weight: 700; }
#ammo { opacity: .8; }

#district-name {
  position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%);
  font-size: 15px; opacity: 0; transition: opacity .4s; background: var(--panel);
  padding: 6px 16px; border-radius: 20px; border: 1px solid rgba(233,196,106,.3); color: var(--accent);
}
#district-name.show { opacity: 1; }

#toast {
  position: absolute; top: 18%; left: 50%; transform: translateX(-50%);
  background: var(--panel); padding: 10px 18px; border-radius: 10px; font-size: 16px;
  border: 1px solid rgba(233,196,106,.3); opacity: 0; transition: opacity .3s; max-width: 80vw; text-align: center;
}
#toast.show { opacity: 1; }

#prompt {
  position: absolute; bottom: 30%; left: 50%; transform: translateX(-50%);
  background: rgba(28,22,15,.85); padding: 10px 18px; border-radius: 10px; font-size: 15px;
  border: 1px solid rgba(233,196,106,.5); color: #f3e9d8; text-align: center; white-space: nowrap;
}
#prompt b { color: var(--accent); }

/* כוונת ירי במרכז המסך */
#crosshair {
  position: absolute; top: 50%; left: 50%; width: 28px; height: 28px;
  transform: translate(-50%, -50%); pointer-events: none;
  border: 2px solid rgba(255,255,255,.45); border-radius: 50%;
  transition: border-color .12s, transform .12s;
}
#crosshair::before, #crosshair::after {
  content: ''; position: absolute; background: rgba(255,255,255,.9);
  box-shadow: 0 0 3px rgba(0,0,0,.9);
}
#crosshair::before { left: 50%; top: -7px; width: 2px; height: 42px; transform: translateX(-50%); }
#crosshair::after  { top: 50%; left: -7px; height: 2px; width: 42px; transform: translateY(-50%); }
#crosshair.hit { border-color: rgba(255,80,60,.95); transform: translate(-50%, -50%) scale(1.25); }
#crosshair.hit.head { border-color: rgba(255,210,60,1); transform: translate(-50%, -50%) scale(1.45); }
/* מצב זום — כוונת צלפים עדינה עם נקודת מרכז */
#crosshair.zoom { width: 16px; height: 16px; border-color: rgba(255,235,170,.85); }
#crosshair.zoom::before { top: -14px; height: 44px; width: 1.5px; }
#crosshair.zoom::after  { left: -14px; width: 44px; height: 1.5px; }

/* וינייטה קולנועית קבועה — עומק ופוקוס למרכז התמונה */
#cine-vignette {
  position: fixed; inset: 0; pointer-events: none; z-index: 17;
  background: radial-gradient(ellipse at center, transparent 58%, rgba(10, 8, 14, 0.32) 100%);
}

/* וינייטה אדומה כשנפגעים */
#damage-vignette {
  position: fixed; inset: 0; pointer-events: none; z-index: 18; opacity: 0;
  background: radial-gradient(ellipse at center, transparent 52%, rgba(170,10,10,.55) 100%);
  transition: opacity .1s;
}
#damage-vignette.show { opacity: 1; transition: opacity .05s; }

/* ---------- Touch UI ---------- */
#touch-ui { position: fixed; inset: 0; z-index: 25; pointer-events: none; }
/* תנועה: אגודל שמאל (אזור דינמי). מבט+לחצנים: אגודל ימין. */
#move-pad { position: absolute; left: 0; bottom: 0; width: 45%; height: 80%; pointer-events: auto; touch-action: none; }
#joystick {
  position: absolute; display: none; width: 130px; height: 130px; z-index: 1;
  border-radius: 50%; background: rgba(255,255,255,.10); border: 2px solid rgba(255,255,255,.22);
  pointer-events: none; touch-action: none;
}
#joystick .knob {
  position: absolute; top: 50%; left: 50%; width: 58px; height: 58px; margin: -29px 0 0 -29px;
  border-radius: 50%; background: rgba(233,196,106,.8); border: 2px solid rgba(255,255,255,.5);
}
.touch-btn {
  position: absolute; pointer-events: auto; touch-action: none;
  width: 72px; height: 72px; border-radius: 50%;
  background: rgba(28,22,15,.7); border: 2px solid rgba(233,196,106,.5);
  color: #f3e9d8; font-size: 13px; font-weight: 700; display: flex; align-items: center; justify-content: center;
}
.touch-btn:active { background: rgba(233,196,106,.5); }
/* פריסת לחצנים בקשת — בלי חפיפות (נבדק גיאומטרית) */
#btn-attack { bottom: 110px; right: 24px;  width: 86px; height: 86px; background: rgba(226,91,69,.55); }
#btn-jump   { bottom: 52px;  right: 132px; width: 64px; height: 64px; }
#btn-enter  { bottom: 150px; right: 124px; width: 64px; height: 64px; }
#btn-weapon { bottom: 28px;  right: 36px;  width: 64px; height: 64px; }
#btn-mission{ bottom: 232px; right: 116px; width: 56px; height: 56px; font-size: 12px; }
#btn-zoom   { bottom: 208px; right: 36px;  width: 56px; height: 56px; font-size: 22px; }
#btn-zoom.on { background: rgba(233,196,106,.6); border-color: #fff; }
/* אזור מבט: חצי ימין של המסך (הלחצנים מעליו תופסים עדיפות) */
#look-pad   { position: absolute; top: 0; right: 0; width: 55%; height: 100%; pointer-events: auto; touch-action: none; }

/* ---------- קטלוג חנות נשק ---------- */
#shop-menu {
  position: fixed; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center;
  background: rgba(10,8,5,.8); pointer-events: auto;
}
#shop-menu-panel {
  width: min(92vw, 460px); max-height: 86vh; overflow-y: auto;
  background: #1d1812; border: 2px solid rgba(233,196,106,.55); border-radius: 14px;
  padding: 18px 20px; box-shadow: 0 10px 40px rgba(0,0,0,.6);
}
#shop-menu-panel h2 { margin: 0 0 4px; color: var(--accent); font-size: 22px; }
#shop-menu-money { color: #9fdb9f; font-weight: 700; margin-bottom: 12px; }
.shop-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 9px 10px; margin-bottom: 7px; border-radius: 10px;
  background: rgba(255,255,255,.05); border: 1px solid rgba(233,196,106,.18);
}
.shop-item .w-name { font-weight: 700; color: #f3e9d8; }
.shop-item .w-stats { font-size: 11.5px; opacity: .65; }
.shop-item button {
  min-width: 110px; padding: 8px 10px; border-radius: 8px; border: 1px solid rgba(233,196,106,.5);
  background: rgba(233,196,106,.18); color: var(--accent); font-weight: 700; cursor: pointer; font-size: 13px;
}
.shop-item button:disabled { opacity: .4; cursor: default; }
.shop-item button.owned { border-color: rgba(120,200,120,.5); color: #9fdb9f; background: rgba(120,200,120,.12); }
#shop-menu-close {
  width: 100%; margin-top: 6px; padding: 10px; border-radius: 10px; cursor: pointer;
  background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.25); color: #f3e9d8; font-weight: 700;
}

/* ---------- מפה מלאה ---------- */
#bigmap-wrap {
  position: fixed; inset: 0; z-index: 35; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px;
  background: rgba(10,8,5,.82); pointer-events: auto;
}
#bigmap {
  width: min(92vmin, 760px); height: min(92vmin, 760px);
  border-radius: 14px; border: 2px solid rgba(233,196,106,.5); background: #2a2418;
  box-shadow: 0 10px 40px rgba(0,0,0,.6);
}
#bigmap-hint { font-size: 14px; color: var(--accent); opacity: .9; }

/* ---------- מובייל: צמצום וסידור ---------- */
@media (max-width: 820px), (pointer: coarse) {
  #minimap { width: 112px; height: 112px; border-width: 2px; }
  #map-buttons button { width: 36px; height: 36px; font-size: 16px; }
  #map-legend { font-size: 10px; max-width: 180px; padding: 4px 6px; }
  #clock { font-size: 17px; }
  #weather { font-size: 11px; padding: 2px 6px; }
  #money { font-size: 20px; }
  #wanted { font-size: 18px; min-height: 20px; }
  .meter { width: 104px; height: 11px; }
  .bar-label { font-size: 10px; width: 24px; }
  #mission { top: 8px; font-size: 12px; padding: 4px 9px; max-width: 60vw; overflow: hidden; text-overflow: ellipsis; }
  /* קופסת הנשק לא תתנגש עם הג'ויסטיק/לחצנים — למרכז־תחתון */
  #weapon-box { left: 50%; transform: translateX(-50%); bottom: 12px; padding: 6px 12px; font-size: 12px; }
  #district-name { bottom: 60px; font-size: 13px; }
  #prompt { bottom: 38%; font-size: 13px; max-width: 70vw; white-space: normal; }
  #toast { font-size: 14px; top: 14%; }
}
