@font-face {
  font-family: 'Reem Kufi';
  src: url('../fonts/ReemKufi-Regular.ttf') format('truetype');
  font-weight: 400; font-display: swap;
}
@font-face {
  font-family: 'Reem Kufi';
  src: url('../fonts/ReemKufi-Bold.ttf') format('truetype');
  font-weight: 700; font-display: swap;
}
@font-face {
  font-family: 'IBM Plex Sans Arabic';
  src: url('../fonts/IBMPlexSansArabic-Regular.ttf') format('truetype');
  font-weight: 400; font-display: swap;
}
@font-face {
  font-family: 'IBM Plex Sans Arabic';
  src: url('../fonts/IBMPlexSansArabic-SemiBold.ttf') format('truetype');
  font-weight: 600; font-display: swap;
}

:root {
  --panel: rgba(30, 32, 34, 0.85);
  --accent: #E8A33D;
  --ink: #EDE6D6;
  --blood: #5A1A1A;
  --health: #C2562B;
  --dark: #17181A;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; width: 100%; height: 100%;
  overflow: hidden; background: #9AA3A0;
  font-family: 'IBM Plex Sans Arabic', system-ui, sans-serif;
  color: var(--ink);
  user-select: none; -webkit-user-select: none;
  touch-action: none;
}
#app { position: fixed; inset: 0; overflow: hidden; }
#scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* ---------- HUD panels ---------- */
.hud {
  position: absolute; inset: 0; pointer-events: none;
  padding: calc(8px + env(safe-area-inset-top)) calc(8px + env(safe-area-inset-right))
           calc(8px + env(safe-area-inset-bottom)) calc(8px + env(safe-area-inset-left));
  z-index: 5;
}
.panel {
  position: absolute;
  background: var(--panel);
  border-radius: 2px;
  border-top: 2px solid var(--accent);
  padding: 7px 12px;
  min-width: 118px;
  box-shadow: 0 3px 10px rgba(0,0,0,0.28);
}
.panel-day { top: 10px; right: 12px; text-align: center; padding: 6px 18px 8px; }
.day-label { font-size: 13px; letter-spacing: .04em; opacity: .92; }
.day-num { font-family: 'Reem Kufi', sans-serif; font-weight: 700; font-size: 40px; line-height: 1; }
.panel-stat { top: 10px; left: 12px; }
.stat-row { display: flex; align-items: center; gap: 7px; font-size: 15px; line-height: 1.7; }
.stat-row .ico { width: 18px; height: 18px; fill: var(--ink); flex: none; }
.stat-row .star { fill: var(--accent); }
.stat-name { opacity: .9; }
.stat-val { margin-inline-start: auto; font-weight: 600; font-variant-numeric: tabular-nums; min-width: 42px; text-align: end; }

.panel-health { bottom: 12px; right: 12px; min-width: 150px; }
.health-label { font-size: 12px; text-align: end; margin-bottom: 5px; opacity: .9; }
.health-bar { display: flex; gap: 3px; direction: ltr; justify-content: flex-end; }
.health-seg { width: 15px; height: 20px; background: var(--health); border-radius: 2px; transition: background .18s ease; }
.health-seg.lost { background: #33363A; }

.panel-weapon { bottom: 12px; left: 12px; min-width: 150px; }
.weapon-row { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.weapon-row .ico { width: 20px; height: 20px; fill: var(--ink); }
.weapon-name { font-weight: 600; }
.ammo-row { direction: ltr; text-align: left; margin-top: 2px; }
.ammo-mag { font-family: 'Reem Kufi', sans-serif; font-weight: 700; font-size: 34px; line-height: 1; }
.ammo-sep, .ammo-res { font-size: 18px; opacity: .8; }
.ammo-mag.low { color: var(--accent); }
.slots { display: flex; gap: 5px; margin-top: 6px; direction: ltr; }
.slot {
  width: 30px; height: 30px; background: #232528; border: 1px solid #3A3D40; border-radius: 2px;
  display: flex; align-items: center; justify-content: center; position: relative; font-size: 12px;
}
.slot .count { position: absolute; bottom: -1px; inset-inline-end: 1px; font-weight: 700; font-size: 12px; }
.slot svg { width: 18px; height: 18px; }
.slot.empty { opacity: .45; }
.slot.active { border-color: var(--accent); }

/* ---------- crosshair ---------- */
.crosshair { position: absolute; left: 50%; top: 50%; width: 26px; height: 26px; transform: translate(-50%,-50%); z-index: 6; pointer-events: none; }
.crosshair span { position: absolute; background: rgba(237,230,214,.85); }
.crosshair span:nth-child(1) { left: 50%; top: 0; width: 2px; height: 8px; transform: translateX(-50%); }
.crosshair span:nth-child(2) { left: 50%; bottom: 0; width: 2px; height: 8px; transform: translateX(-50%); }
.crosshair::before, .crosshair::after { content: ''; position: absolute; background: rgba(237,230,214,.85); }
.crosshair::before { top: 50%; left: 0; height: 2px; width: 8px; transform: translateY(-50%); }
.crosshair::after { top: 50%; right: 0; height: 2px; width: 8px; transform: translateY(-50%); }

/* ---------- damage tint ---------- */
.damage { position: absolute; inset: 0; pointer-events: none; z-index: 7; opacity: 0;
  box-shadow: inset 0 0 80px 0 var(--blood); transition: opacity .28s ease; }
.damage.on { opacity: .5; transition: opacity .06s ease; }

/* ---------- reload / banner / hint ---------- */
.reloading {
  position: absolute; left: 50%; top: 58%; transform: translateX(-50%); z-index: 6;
  background: var(--panel); border-top: 2px solid var(--accent); border-radius: 2px;
  padding: 5px 14px; font-size: 14px; display: none;
}
.reloading.show { display: block; }
.banner {
  position: absolute; left: 50%; top: 22%; transform: translate(-50%,-8px); z-index: 6;
  font-family: 'Reem Kufi', sans-serif; font-weight: 700; font-size: 34px; color: var(--ink);
  text-shadow: 0 2px 12px rgba(0,0,0,.5); opacity: 0; transition: opacity .35s ease, transform .35s ease;
  pointer-events: none; text-align: center;
}
.banner.show { opacity: 1; transform: translate(-50%,0); }
.hint {
  position: absolute; left: 50%; bottom: calc(14px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 6; font-size: 13px; background: var(--panel); padding: 4px 12px; border-radius: 2px;
  border-top: 2px solid var(--accent); opacity: .92; max-width: 60%; text-align: center;
}

/* ---------- sheets (title / gameover) ---------- */
.sheet {
  position: absolute; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center;
  background: rgba(20,22,24,0.42); backdrop-filter: none;
  transition: opacity .3s ease;
}
.sheet.hidden { opacity: 0; pointer-events: none; }
.title-inner, .over-inner { text-align: center; padding: 20px; max-width: 92vw; }
.game-title {
  font-family: 'Reem Kufi', sans-serif; font-weight: 700; font-size: clamp(40px, 12vw, 92px);
  color: var(--ink); margin: 0 0 6px; letter-spacing: .02em; text-shadow: 0 3px 18px rgba(0,0,0,.5);
}
.game-sub { font-size: clamp(14px, 3.4vw, 20px); opacity: .92; margin: 0 0 28px; }
.btn-primary {
  font-family: 'Reem Kufi', sans-serif; font-weight: 700; font-size: clamp(20px, 5vw, 30px);
  background: var(--accent); color: #1A1B1D; border: none; border-radius: 2px;
  padding: 12px 54px; cursor: pointer; pointer-events: auto;
  transition: transform .12s ease, background .15s ease;
}
.btn-primary:active { transform: scale(0.97); background: #f0b355; }
.controls-note { margin-top: 22px; font-size: clamp(11px, 2.8vw, 14px); opacity: .8; line-height: 1.9; }
.over-title { font-family: 'Reem Kufi', sans-serif; font-size: clamp(28px, 8vw, 56px); margin: 0 0 18px; color: var(--ink); }
.over-stats { display: flex; gap: 40px; justify-content: center; margin-bottom: 12px; }
.over-stat { display: flex; flex-direction: column; }
.over-label { font-size: 14px; opacity: .85; }
.over-num { font-family: 'Reem Kufi', sans-serif; font-weight: 700; font-size: clamp(40px, 12vw, 76px); line-height: 1.05; }
.over-best { font-size: 16px; opacity: .9; margin-bottom: 22px; }

/* ---------- touch controls ---------- */
:root { --stick: clamp(96px, 15vh, 118px); }
.touch { position: absolute; inset: 0; z-index: 8; pointer-events: none; display: none; }
html.has-touch .touch { display: block; }
html.has-touch .crosshair { opacity: .5; }
.stick {
  position: absolute; bottom: calc(20px + env(safe-area-inset-bottom));
  width: var(--stick); height: var(--stick);
  border-radius: 50%; background: rgba(30,32,34,0.32); border: 2px solid rgba(237,230,214,0.28);
  pointer-events: auto; touch-action: none;
}
#stickL { left: calc(16px + env(safe-area-inset-left)); }
#stickR { right: calc(16px + env(safe-area-inset-right)); }
.knob {
  position: absolute; left: 50%; top: 50%; width: 46%; height: 46%; margin: -23% 0 0 -23%;
  border-radius: 50%; background: rgba(232,163,61,0.55); border: 2px solid rgba(237,230,214,0.5);
}
.tbtn {
  position: absolute; pointer-events: auto; font-family: 'IBM Plex Sans Arabic', sans-serif;
  background: var(--panel); color: var(--ink); border: none; border-top: 2px solid var(--accent);
  border-radius: 2px; padding: 10px 10px; font-size: 13px; line-height: 1.1; min-width: 64px;
  white-space: nowrap;
  bottom: calc(28px + env(safe-area-inset-bottom));
}
/* on touch, lift the two corner panels clear of the sticks, buttons beside the right stick */
html.has-touch .panel-health,
html.has-touch .panel-weapon { bottom: calc(var(--stick) + 34px + env(safe-area-inset-bottom)); }
#btnReload { right: calc(26px + var(--stick) + 80px + env(safe-area-inset-right)); }
#btnNade { right: calc(26px + var(--stick) + 8px + env(safe-area-inset-right)); }
#btnSwap { right: calc(26px + var(--stick) + 152px + env(safe-area-inset-right)); }

/* HUD is hidden while a full-screen sheet is up */
body.ui-hidden #hud,
body.ui-hidden #touch,
body.ui-hidden #crosshair,
body.ui-hidden #hint,
body.ui-hidden #banner { display: none !important; }

@media (max-aspect-ratio: 1/1) {
  .panel { padding: 5px 9px; min-width: 100px; }
  .panel-day { padding: 4px 14px 6px; }
  .day-num { font-size: 30px; }
  .day-label { font-size: 11px; }
  .panel-stat { min-width: 132px; }
  .stat-row { font-size: 13px; line-height: 1.55; }
  .stat-row .ico { width: 16px; height: 16px; }
  .panel-health { min-width: 122px; }
  .panel-weapon { min-width: 122px; }
  .weapon-row { font-size: 12px; }
  .ammo-mag { font-size: 26px; }
  .health-seg { width: 12px; height: 18px; }
  .slot { width: 26px; height: 26px; }
  .slot svg { width: 16px; height: 16px; }
}
