:root {
  --bg-loaded: 0;
}

html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
  width: 100%;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  background: url(bg.jpg) no-repeat center;
  background-size: cover;
  cursor: crosshair;
  overflow: hidden;
  transition: filter 0.1s;
}

/* Muzzle flash */
body.flash {
  filter: brightness(1.8);
  transition: filter 0s;
}

body.flash-reset {
  filter: brightness(1);
  transition: filter 0.15s ease-out;
}

/* Screen shake */
body.shake {
  animation: screenShake 0.12s ease-out;
}

@keyframes screenShake {
  0% {
    transform: translate(0, 0);
  }

  15% {
    transform: translate(-4px, 3px);
  }

  30% {
    transform: translate(4px, -2px);
  }

  45% {
    transform: translate(-3px, -3px);
  }

  60% {
    transform: translate(3px, 2px);
  }

  75% {
    transform: translate(-2px, 1px);
  }

  90% {
    transform: translate(1px, -1px);
  }

  100% {
    transform: translate(0, 0);
  }
}

/* ============ PRELOADER ============ */
#preloader {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: linear-gradient(
    135deg,
    #1a2f0b 0%,
    #2d4a14 30%,
    #3d5c1e 60%,
    #1a2f0b 100%
  );
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  transition: opacity 0.6s ease, visibility 0.6s ease;
  font-family: "Georgia", "Times New Roman", serif;
}

#preloader.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.preloader-inner {
  text-align: center;
  color: #e8d5a3;
}

.preloader-title {
  font-size: clamp(2rem, 5vw, 4rem);
  font-weight: bold;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: #f4e4c1;
  text-shadow: 0 4px 12px rgba(0, 0, 0, 0.6), 0 0 40px rgba(180, 140, 60, 0.5);
  margin-bottom: 0.3em;
}

.preloader-subtitle {
  font-size: 0.9rem;
  letter-spacing: 0.3em;
  color: #c4a86c;
  margin-bottom: 2rem;
  text-transform: uppercase;
}

/* Crosshair spinner */
.crosshair-spinner {
  width: 80px;
  height: 80px;
  position: relative;
  margin: 0 auto 2rem;
  animation: spinCrosshair 2s linear infinite;
}

.crosshair-spinner::before,
.crosshair-spinner::after {
  content: "";
  position: absolute;
  background: #e8d5a3;
  border-radius: 2px;
}

.crosshair-spinner::before {
  width: 4px;
  height: 100%;
  left: 50%;
  transform: translateX(-50%);
  box-shadow: 0 0 8px rgba(232, 213, 163, 0.7);
}

.crosshair-spinner::after {
  height: 4px;
  width: 100%;
  top: 50%;
  transform: translateY(-50%);
  box-shadow: 0 0 8px rgba(232, 213, 163, 0.7);
}

.crosshair-ring {
  position: absolute;
  inset: 8px;
  border: 3px solid #e8d5a3;
  border-radius: 50%;
  opacity: 0.6;
  box-shadow: 0 0 15px rgba(232, 213, 163, 0.4);
}

.crosshair-dot {
  position: absolute;
  width: 10px;
  height: 10px;
  background: #ff4444;
  border-radius: 50%;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 20px rgba(255, 68, 68, 0.8);
  animation: pulseDot 0.8s ease-in-out infinite;
}

@keyframes spinCrosshair {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}

@keyframes pulseDot {
  0%,
  100% {
    transform: translate(-50%, -50%) scale(1);
  }

  50% {
    transform: translate(-50%, -50%) scale(1.8);
  }
}

/* Countdown display */
.countdown-number {
  font-size: 5rem;
  font-weight: bold;
  color: #fff;
  text-shadow: 0 0 60px rgba(255, 200, 60, 0.9), 0 4px 20px rgba(0, 0, 0, 0.7);
  min-height: 1.2em;
  transition: transform 0.2s ease;
  animation: countBounce 0.7s ease-out;
}

@keyframes countBounce {
  0% {
    transform: scale(2);
    opacity: 0;
  }

  40% {
    transform: scale(0.9);
    opacity: 1;
  }

  100% {
    transform: scale(1);
    opacity: 1;
  }
}

/* Loading bar */
.loading-bar-track {
  width: 220px;
  height: 6px;
  background: rgba(0, 0, 0, 0.4);
  border-radius: 3px;
  margin: 1.5rem auto 0;
  overflow: hidden;
}

.loading-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #c4a86c, #f4e4c1, #c4a86c);
  border-radius: 3px;
  width: 0%;
  transition: width 0.3s ease;
  box-shadow: 0 0 10px rgba(244, 228, 193, 0.6);
}

/* ============ GAME UI ============ */
#game-ui {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  pointer-events: none;
  padding: 15px 20px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 10px;
}

#score-panel {
  background: rgba(0, 0, 0, 0.65);
  border: 2px solid rgba(180, 140, 60, 0.6);
  border-radius: 10px;
  padding: 10px 18px;
  color: #f4e4c1;
  font-family: "Georgia", serif;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

#score-panel .score-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: #c4a86c;
}

#score-panel .score-value {
  font-size: 2.2rem;
  font-weight: bold;
  line-height: 1;
  text-shadow: 0 0 20px rgba(255, 200, 60, 0.6);
  transition: transform 0.15s ease;
}

#combo-text {
  color: #ffcc00;
  font-size: 0.85rem;
  min-height: 1.2em;
  letter-spacing: 0.05em;
  transition: all 0.3s;
}

/* Miss counter */
#miss-counter {
  font-size: 0.8rem;
  letter-spacing: 0.05em;
  color: #ccc;
  margin-top: 2px;
  transition: color 0.3s, transform 0.2s;
  min-height: 1.2em;
}

#miss-counter.warning {
  color: #ffa500;
  animation: missPulse 0.8s ease-in-out infinite;
}

#miss-counter.danger {
  color: #ff4444;
  animation: missPulse 0.4s ease-in-out infinite;
  font-weight: bold;
}

@keyframes missPulse {
  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.5;
  }
}

h2 {
  position: absolute;
  font-family: sans-serif;
  top: 0px;
  text-align: center;
  left: 0px;
  right: 0px;
  padding: 5%;
  pointer-events: none;
  z-index: 5;
  color: rgba(255, 255, 255, 0.6);
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  font-size: clamp(1rem, 3vw, 1.8rem);
  letter-spacing: 0.1em;
}

/* ============ DUCKS ============ */
.range {
  position: fixed;
  inset: 0;
  z-index: 1;
}

.duck {
  position: absolute;
  left: -150px;
  right: 0px;
  height: 0px;
  z-index: 10;
  transform: translateZ(0);
  animation: fly var(--fly-dur, 10s) var(--fly-delay, 0s) linear infinite;
  pointer-events: auto;
  border: none;
  outline: none;
}

.duck a {
  display: block;
  cursor: crosshair;
  transition: all 0.6s;
  background: no-repeat center url(duck.png);
  background-size: cover;
  width: var(--duck-size, 80px);
  animation: float var(--float-dur, 2s) infinite
    cubic-bezier(0.58, 0.14, 0.46, 0.92);
  pointer-events: auto;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  border: none;
  outline: none;
  text-decoration: none;
}

.duck a:focus,
.duck a:active,
.duck a:visited {
  outline: none;
  border: none;
  text-decoration: none;
  box-shadow: none;
}

.duck a::after {
  content: "";
  display: block;
  padding-bottom: 100%;
}

/* Hit state: stops fly animation, plays burst */
.duck:target,
.duck.dead {
  animation: none !important;
  pointer-events: none;
}

.duck:target a,
.duck.dead a {
  animation: hitBurst 0.5s ease-out forwards !important;
  pointer-events: none;
  cursor: default;
}

@keyframes hitBurst {
  0% {
    transform: scale(1);
    opacity: 1;
    filter: brightness(1);
  }

  30% {
    transform: scale(1.4);
    opacity: 0.9;
    filter: brightness(2) saturate(0);
  }

  100% {
    transform: scale(0.2);
    opacity: 0;
    filter: brightness(3) saturate(0);
  }
}

@keyframes fly {
  0% {
    transform: translateX(0px);
  }

  100% {
    transform: translateX(calc(100vw + 300px));
  }
}

@keyframes float {
  0% {
    transform: translateY(40%);
  }

  50% {
    transform: translateY(-40%);
  }

  100% {
    transform: translateY(40%);
  }
}

/* Hit marker popup */
.hit-marker {
  position: fixed;
  pointer-events: none;
  z-index: 200;
  font-family: "Georgia", serif;
  font-weight: bold;
  font-size: 1.4rem;
  color: #ffdd57;
  text-shadow: 0 0 15px rgba(255, 200, 40, 0.9), 0 2px 6px rgba(0, 0, 0, 0.7);
  animation: markerFloat 1.2s ease-out forwards;
  white-space: nowrap;
}

@keyframes markerFloat {
  0% {
    transform: translateY(0) scale(0.5);
    opacity: 0;
  }

  20% {
    transform: translateY(-20px) scale(1.2);
    opacity: 1;
  }

  100% {
    transform: translateY(-90px) scale(0.7);
    opacity: 0;
  }
}

/* Miss indicator */
.miss-indicator {
  position: fixed;
  pointer-events: none;
  z-index: 199;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.7);
  box-shadow: 0 0 25px rgba(255, 255, 255, 0.5);
  animation: missPop 0.5s ease-out forwards;
  transform: translate(-50%, -50%);
}

@keyframes missPop {
  0% {
    transform: translate(-50%, -50%) scale(0.3);
    opacity: 1;
  }

  100% {
    transform: translate(-50%, -50%) scale(2.5);
    opacity: 0;
  }
}

/* ============ GAME OVER MODAL ============ */
#game-over-overlay {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.5s ease, visibility 0.5s ease;
}

#game-over-overlay.visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.game-over-card {
  background: linear-gradient(180deg, #3d2613 0%, #2d1a08 40%, #1a0f04 100%);
  border: 3px solid #b8904a;
  border-radius: 20px;
  padding: clamp(20px, 4vw, 35px) clamp(20px, 5vw, 40px);
  text-align: center;
  font-family: "Georgia", "Times New Roman", serif;
  max-width: 440px;
  width: 90%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.7), 0 0 80px rgba(180, 120, 40, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
  animation: modalEnter 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  transform: scale(0.7);
}

#game-over-overlay.visible .game-over-card {
  animation: modalEnter 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes modalEnter {
  0% {
    transform: scale(0.7);
    opacity: 0;
  }

  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.game-over-icon {
  font-size: 4rem;
  margin-bottom: 0.2em;
  animation: iconBounce 1s ease-in-out infinite;
}

@keyframes iconBounce {
  0%,
  100% {
    transform: translateY(0);
  }

  30% {
    transform: translateY(-15px);
  }

  50% {
    transform: translateY(0);
  }

  70% {
    transform: translateY(-8px);
  }

  85% {
    transform: translateY(0);
  }
}

.game-over-title {
  font-size: clamp(2rem, 5vw, 3rem);
  font-weight: bold;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #f4d78c;
  text-shadow: 0 0 30px rgba(220, 160, 40, 0.7), 0 3px 10px rgba(0, 0, 0, 0.6);
  margin: 0 0 0.3em;
}

.game-over-subtitle {
  font-size: 1rem;
  color: #c4a86c;
  letter-spacing: 0.05em;
  margin-bottom: 1.5em;
  margin-top: 45px;
}

.game-over-divider {
  width: 60%;
  height: 2px;
  background: linear-gradient(90deg, transparent, #b8904a, transparent);
  margin: 0 auto 1.2em;
  border-radius: 1px;
}

.game-over-score-block {
  background: rgba(0, 0, 0, 0.4);
  border-radius: 12px;
  padding: 15px 20px;
  margin-bottom: 1.5em;
  border: 1px solid rgba(180, 140, 60, 0.3);
}

.final-score-label {
  display: block;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: #a08050;
  margin-bottom: 0.3em;
}

.final-score-value {
  display: block;
  font-size: 3.5rem;
  font-weight: bold;
  color: #fff;
  text-shadow: 0 0 30px rgba(255, 200, 60, 0.8);
  line-height: 1;
}

.final-miss-text {
  font-size: 0.85rem;
  color: #e07070;
  margin-top: 0.5em;
  letter-spacing: 0.05em;
}

.play-again-btn {
  display: inline-block;
  padding: 14px 36px;
  font-size: 1.1rem;
  font-weight: bold;
  font-family: "Georgia", serif;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #1a0f04;
  background: linear-gradient(180deg, #f4d78c 0%, #c8943e 50%, #a07028 100%);
  border: 2px solid #e8c870;
  border-radius: 30px;
  cursor: pointer;
  transition: all 0.25s ease;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4), 0 0 25px rgba(200, 150, 50, 0.4);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.3);
  position: relative;
  overflow: hidden;
}

.play-again-btn:hover {
  background: linear-gradient(180deg, #fff3c8 0%, #e0b050 50%, #b88030 100%);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5), 0 0 40px rgba(220, 170, 50, 0.6);
  transform: translateY(-2px);
}

.play-again-btn:active {
  transform: translateY(1px) scale(0.97);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.4), 0 0 15px rgba(200, 150, 50, 0.3);
  transition: all 0.08s ease;
}

.play-again-btn::after {
  content: "";
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(
    circle,
    rgba(255, 255, 255, 0.3) 0%,
    transparent 60%
  );
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}

.play-again-btn:hover::after {
  opacity: 1;
}

/* Responsive */
@media (max-width: 600px) {
  #score-panel {
    padding: 6px 12px;
  }

  #score-panel .score-value {
    font-size: 1.5rem;
  }

  .duck a {
    width: clamp(40px, var(--duck-size, 60px), 100px) !important;
  }

  .preloader-title {
    font-size: 1.5rem;
  }

  .countdown-number {
    font-size: 3rem;
  }

  .game-over-card {
    padding: 20px 18px;
    border-radius: 16px;
  }

  .final-score-value {
    font-size: 2.5rem;
  }

  .game-over-icon {
    font-size: 3rem;
  }

  .play-again-btn {
    padding: 12px 28px;
    font-size: 1rem;
  }

  #miss-counter {
    font-size: 0.7rem;
  }
}
