/* Crosshair cursor + shooting effect (see fx.js). Uses the color tokens from styles.css. */

/* Hide the native cursor only when our crosshair is active (mouse users). */
html.fx-crosshair,
html.fx-crosshair * { cursor: none !important; }

.fx-layer {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  overflow: hidden;
  pointer-events: none;
  z-index: 90;
}

/* ---------- crosshair ---------- */
.fx-cross {
  --c: var(--accent, #c6ff3a);
  --gap: 6px;
  --len: 9px;
  position: fixed;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  pointer-events: none;
  z-index: 100;
  opacity: 0;
  transition: opacity 0.15s;
  will-change: transform;
}
.fx-cross.is-visible { opacity: 1; }

.fx-cross__line,
.fx-cross__dot {
  position: absolute;
  background: var(--c);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.55), 0 0 8px rgba(var(--accent-rgb, 198, 255, 58), 0.5);
  transition: transform 0.18s var(--ease, ease), background 0.15s;
}
.fx-cross__dot { width: 3px; height: 3px; left: -1.5px; top: -1.5px; border-radius: 50%; }
.fx-cross__line--t,
.fx-cross__line--b { width: 2px; height: var(--len); left: -1px; }
.fx-cross__line--l,
.fx-cross__line--r { height: 2px; width: var(--len); top: -1px; }
.fx-cross__line--t { top: calc(-1 * (var(--gap) + var(--len))); }
.fx-cross__line--b { top: var(--gap); }
.fx-cross__line--l { left: calc(-1 * (var(--gap) + var(--len))); }
.fx-cross__line--r { left: var(--gap); }

/* Over links/buttons: lines close in and turn red ("target locked"). */
.fx-cross.is-locked { --c: #ff4d4d; }
.fx-cross.is-locked .fx-cross__line--t { transform: translateY(3px); }
.fx-cross.is-locked .fx-cross__line--b { transform: translateY(-3px); }
.fx-cross.is-locked .fx-cross__line--l { transform: translateX(3px); }
.fx-cross.is-locked .fx-cross__line--r { transform: translateX(-3px); }

/* Recoil: lines kick outward, then settle. */
.fx-cross.is-recoil .fx-cross__line--t { animation: fx-kick-t 0.22s var(--ease, ease); }
.fx-cross.is-recoil .fx-cross__line--b { animation: fx-kick-b 0.22s var(--ease, ease); }
.fx-cross.is-recoil .fx-cross__line--l { animation: fx-kick-l 0.22s var(--ease, ease); }
.fx-cross.is-recoil .fx-cross__line--r { animation: fx-kick-r 0.22s var(--ease, ease); }
@keyframes fx-kick-t { 40% { transform: translateY(-7px); } }
@keyframes fx-kick-b { 40% { transform: translateY(7px); } }
@keyframes fx-kick-l { 40% { transform: translateX(-7px); } }
@keyframes fx-kick-r { 40% { transform: translateX(7px); } }

/* ---------- ammo counter ---------- */
.fx-hud {
  position: fixed;
  right: 18px;
  bottom: 16px;
  z-index: 95;
  display: flex;
  align-items: stretch;
  gap: 6px;
  direction: ltr;
}
.fx-sound {
  display: grid;
  place-items: center;
  width: 34px;
  padding: 0;
  color: var(--muted, #9ba8b5);
  background: rgba(7, 9, 12, 0.72);
  border: 1px solid var(--line-strong, rgba(255, 255, 255, 0.18));
  border-radius: var(--radius, 4px);
  backdrop-filter: blur(4px);
  transition: color 0.15s, border-color 0.15s;
}
.fx-sound:hover { color: var(--text, #eaf0f5); border-color: rgba(var(--accent-rgb, 198, 255, 58), 0.5); }
.fx-sound.is-on { color: var(--accent, #c6ff3a); border-color: rgba(var(--accent-rgb, 198, 255, 58), 0.5); }
.fx-sound:focus-visible { outline: 2px solid var(--accent, #c6ff3a); outline-offset: 2px; }
.fx-ammo {
  pointer-events: none;
  font-family: "Chakra Petch", ui-monospace, monospace;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--text, #eaf0f5);
  background: rgba(7, 9, 12, 0.72);
  border: 1px solid var(--line-strong, rgba(255, 255, 255, 0.18));
  border-radius: var(--radius, 4px);
  padding: 6px 10px;
  line-height: 1;
  direction: ltr;
  backdrop-filter: blur(4px);
}
.fx-ammo__count { font-size: 1.25rem; color: var(--accent, #c6ff3a); }
.fx-ammo__mag { font-size: 0.8rem; color: var(--muted, #9ba8b5); margin-left: 2px; }
.fx-ammo.is-low .fx-ammo__count { color: #ff4d4d; }
.fx-ammo__reload { font-size: 0.8rem; color: #ffb02e; animation: fx-blink 0.5s steps(2) infinite; }
@keyframes fx-blink { 50% { opacity: 0.25; } }

/* ---------- hit effects (all centred on the shot point) ---------- */
.fx-flash,
.fx-hitmark,
.fx-spark,
.fx-shell,
.fx-hole { position: absolute; pointer-events: none; }

.fx-flash {
  width: 56px;
  height: 56px;
  margin: -28px 0 0 -28px;
  border-radius: 50%;
  background: radial-gradient(circle, #fff 0 12%, #ffe38a 22%, rgba(255, 170, 40, 0.75) 40%, rgba(255, 120, 0, 0) 70%);
  mix-blend-mode: screen;
  animation: fx-flash 0.26s ease-out forwards;
}
@keyframes fx-flash {
  0% { transform: scale(0.3); opacity: 1; }
  100% { transform: scale(1.4); opacity: 0; }
}

/* Hit marker: the four short diagonal ticks shooters use to confirm a hit. */
.fx-hitmark {
  width: 26px;
  height: 26px;
  margin: -13px 0 0 -13px;
  background:
    linear-gradient(45deg, transparent 46%, #fff 46% 54%, transparent 54%) top left / 8px 8px no-repeat,
    linear-gradient(-45deg, transparent 46%, #fff 46% 54%, transparent 54%) top right / 8px 8px no-repeat,
    linear-gradient(-45deg, transparent 46%, #fff 46% 54%, transparent 54%) bottom left / 8px 8px no-repeat,
    linear-gradient(45deg, transparent 46%, #fff 46% 54%, transparent 54%) bottom right / 8px 8px no-repeat;
  filter: drop-shadow(0 0 2px rgba(0, 0, 0, 0.8));
  animation: fx-hitmark 0.45s ease-out forwards;
}
@keyframes fx-hitmark {
  0% { transform: scale(1.5); opacity: 0; }
  20% { transform: scale(1); opacity: 1; }
  100% { transform: scale(1.1); opacity: 0; }
}

.fx-spark {
  width: 10px;
  height: 2px;
  margin: -1px 0 0 -5px;
  border-radius: 2px;
  background: linear-gradient(90deg, rgba(255, 200, 80, 0), #ffd66b 40%, #fff);
  transform: rotate(var(--rot));
  animation: fx-spark 0.45s ease-out forwards;
}
@keyframes fx-spark {
  0% { transform: translate(0, 0) rotate(var(--rot)) scaleX(0.4); opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) rotate(var(--rot)) scaleX(1); opacity: 0; }
}

/* Brass casing ejected sideways, arcing down. */
.fx-shell {
  width: 4px;
  height: 10px;
  margin: -5px 0 0 -2px;
  border-radius: 2px 2px 1px 1px;
  background: linear-gradient(90deg, #8a5a17, #f4c45a 45%, #b07a24);
  animation: fx-shell 0.8s cubic-bezier(0.3, 0, 0.7, 1) forwards;
}
@keyframes fx-shell {
  0% { transform: translate(0, 0) rotate(0); opacity: 1; }
  35% { transform: translate(calc(var(--dx) * 0.55), -34px) rotate(calc(var(--spin) * 0.4)); }
  100% { transform: translate(var(--dx), 70px) rotate(var(--spin)); opacity: 0; }
}

/* Bullet hole that stays on the page, then fades. */
.fx-hole {
  margin: -23px 0 0 -23px;
  overflow: visible;
  transform: rotate(var(--rot));
  animation: fx-hole-in 0.12s ease-out;
  transition: opacity 1s ease;
}
.fx-hole.is-fading { opacity: 0; }
@keyframes fx-hole-in { from { transform: rotate(var(--rot)) scale(0.4); } }

.fx-hole__burn { fill: rgba(20, 14, 8, 0.38); }
.fx-hole__crack { fill: none; stroke: rgba(230, 240, 250, 0.55); stroke-width: 0.8; stroke-linecap: round; stroke-linejoin: round; }
.fx-hole__rim { fill: #2a2622; stroke: rgba(255, 255, 255, 0.35); stroke-width: 0.8; }
.fx-hole__core { fill: #000; }

@media (prefers-reduced-motion: reduce) {
  .fx-hole { animation: none; }
}

@media print {
  .fx-layer, .fx-cross, .fx-hud { display: none !important; }
}

/* ---------- photo swap (shoot the photo: normal <-> combat) ---------- */
@property --p {
  syntax: "<percentage>";
  inherits: false;
  initial-value: 0%;
}

.portrait { --hx: 50%; --hy: 40%; }
.portrait.has-alt { cursor: crosshair; }

/* Alt photo sits on top of the normal one; hidden until revealed. */
.portrait__photo--alt { visibility: hidden; }
.portrait__photo--alt img { opacity: 1 !important; filter: saturate(1) contrast(1.06); }

/* Revealed through a circle that grows from where the shot landed. */
.portrait.is-entering .portrait__photo--alt,
.portrait.is-alt .portrait__photo--alt {
  visibility: visible;
  -webkit-mask-image: radial-gradient(circle farthest-corner at var(--hx) var(--hy), #000 calc(var(--p) - 4%), transparent var(--p));
  mask-image: radial-gradient(circle farthest-corner at var(--hx) var(--hy), #000 calc(var(--p) - 4%), transparent var(--p));
}
.portrait.is-alt .portrait__photo--alt { --p: 104%; }
.portrait.is-entering .portrait__photo--alt { animation: fx-reveal 0.85s cubic-bezier(0.7, 0, 0.2, 1) forwards; }

/* Going back: a hole grows from the new shot, showing the normal photo underneath. */
.portrait.is-leaving .portrait__photo--alt {
  visibility: visible;
  -webkit-mask-image: radial-gradient(circle farthest-corner at var(--hx) var(--hy), transparent calc(var(--p) - 4%), #000 var(--p));
  mask-image: radial-gradient(circle farthest-corner at var(--hx) var(--hy), transparent calc(var(--p) - 4%), #000 var(--p));
  animation: fx-reveal 0.85s cubic-bezier(0.7, 0, 0.2, 1) forwards;
}
@keyframes fx-reveal { from { --p: 0%; } to { --p: 104%; } }

/* Impact: the card jolts and the image glitches for a moment. */
.portrait.is-swapping { animation: fx-jolt 0.42s steps(1, end); }
.portrait.is-swapping .portrait__photo img { animation: fx-glitch 0.5s steps(1, end); }
@keyframes fx-jolt {
  0%   { transform: translate(0, 0); }
  12%  { transform: translate(-4px, 2px); }
  24%  { transform: translate(5px, -3px); }
  36%  { transform: translate(-3px, -2px); }
  48%  { transform: translate(3px, 3px); }
  60%  { transform: translate(-2px, 1px); }
  75%  { transform: translate(1px, -1px); }
  100% { transform: translate(0, 0); }
}
@keyframes fx-glitch {
  0%   { filter: contrast(1.8) saturate(2.2) hue-rotate(-25deg); }
  15%  { filter: contrast(1.4) saturate(0) brightness(1.4); }
  30%  { filter: contrast(1.6) saturate(2) hue-rotate(30deg); }
  45%  { filter: contrast(1.2) saturate(1.4) brightness(0.8); }
  60%  { filter: none; }
}

.fx-photo-flash {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle at var(--hx) var(--hy), rgba(255, 255, 255, 0.9), rgba(255, 220, 150, 0.35) 30%, transparent 60%);
  mix-blend-mode: screen;
  animation: fx-photo-flash 0.35s ease-out forwards;
  z-index: 3;
}
@keyframes fx-photo-flash { from { opacity: 1; } to { opacity: 0; } }

.fx-ring {
  position: absolute;
  width: 0;
  height: 0;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  border: 2px solid rgba(var(--accent-rgb, 198, 255, 58), 0.95);
  box-shadow: 0 0 18px 4px rgba(var(--accent-rgb, 198, 255, 58), 0.55), inset 0 0 18px 2px rgba(255, 160, 40, 0.45);
  pointer-events: none;
  z-index: 3;
  animation: fx-ring 0.85s cubic-bezier(0.7, 0, 0.2, 1) forwards;
}
@keyframes fx-ring {
  0%   { width: 0; height: 0; opacity: 1; }
  80%  { opacity: 1; }
  100% { width: var(--d); height: var(--d); opacity: 0; }
}

/* HUD hint on the photo */
.portrait__hint {
  position: absolute;
  inset-inline-start: 12px;
  bottom: 12px;
  z-index: 4;
  pointer-events: none;
  font-family: var(--font-label);
  font-size: 0.68rem;
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  color: var(--accent);
  background: rgba(7, 9, 12, 0.6);
  border: 1px solid rgba(var(--accent-rgb), 0.35);
  border-radius: 2px;
  padding: 4px 8px;
  animation: fx-hint-pulse 2.4s ease-in-out infinite;
}
.portrait.is-alt .portrait__hint { color: #ffb02e; border-color: rgba(255, 176, 46, 0.45); }
@keyframes fx-hint-pulse { 50% { opacity: 0.55; } }

@media (prefers-reduced-motion: reduce) {
  .portrait.is-swapping,
  .portrait.is-swapping .portrait__photo img,
  .portrait__hint { animation: none; }
  .portrait.is-entering .portrait__photo--alt,
  .portrait.is-leaving .portrait__photo--alt { -webkit-mask-image: none; mask-image: none; }
  .portrait.is-entering .portrait__photo--alt { animation: fx-fade-in 0.4s ease forwards; }
  .portrait.is-leaving .portrait__photo--alt { animation: fx-fade-out 0.4s ease forwards; }
  @keyframes fx-fade-in { from { opacity: 0; } to { opacity: 1; } }
  @keyframes fx-fade-out { from { opacity: 1; } to { opacity: 0; } }
}
