html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #05070b;
  color: #f2f6ff;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  touch-action: none;
  user-select: none;
}

#game,
canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.panel {
  position: fixed;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 18px;
  padding: 32px;
  text-align: center;
  background:
    radial-gradient(circle at 50% 40%, rgba(170, 30, 25, 0.35), transparent 24rem),
    linear-gradient(135deg, rgba(3, 5, 10, 0.94), rgba(16, 20, 28, 0.92));
  z-index: 10;
}

.panel h1 {
  margin: 0;
  font-size: clamp(54px, 9vw, 118px);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-shadow: 0 0 26px rgba(255, 74, 50, 0.55);
}

.panel p {
  max-width: 720px;
  margin: 0 auto;
  font-size: 18px;
  color: #cad4e8;
}

.panel .small {
  font-size: 14px;
  color: #99a6bd;
}

button {
  justify-self: center;
  border: 0;
  border-radius: 4px;
  padding: 14px 28px;
  background: #c62520;
  color: white;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: 0 10px 28px rgba(198, 37, 32, 0.32);
}

button:hover {
  background: #e1342e;
}

.hidden {
  display: none !important;
}

#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

#crosshair {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 20px;
  height: 20px;
  transform: translate(-50%, -50%);
}

#crosshair::before,
#crosshair::after {
  content: "";
  position: absolute;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.55);
}

#crosshair::before {
  left: 9px;
  top: 0;
  width: 2px;
  height: 20px;
}

#crosshair::after {
  left: 0;
  top: 9px;
  width: 20px;
  height: 2px;
}

#hitmarker {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) scale(1.8);
  color: #ff332c;
  font-size: 44px;
  font-weight: 900;
  opacity: 0;
  transition: opacity 90ms linear;
}

#hitmarker.show {
  opacity: 1;
}

#stats {
  position: absolute;
  left: 22px;
  bottom: 22px;
  display: flex;
  gap: 18px;
  padding: 12px 16px;
  background: rgba(3, 8, 15, 0.62);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 6px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

#stats strong {
  color: #ffcc4a;
}

#message {
  position: absolute;
  top: 28px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 16px;
  background: rgba(3, 8, 15, 0.58);
  border-radius: 6px;
  color: #dce7ff;
  letter-spacing: 0.04em;
}

#weapon {
  position: absolute;
  right: 12%;
  bottom: -2%;
  width: 180px;
  height: 260px;
  transform: rotate(-10deg);
}

#barrel {
  position: absolute;
  left: 58px;
  top: 24px;
  width: 54px;
  height: 220px;
  border-radius: 18px 18px 8px 8px;
  background: linear-gradient(90deg, #15191f, #5c6978 42%, #1f252d);
  box-shadow: inset -12px 0 24px rgba(0, 0, 0, 0.42), 0 20px 42px rgba(0, 0, 0, 0.45);
}

#muzzle {
  position: absolute;
  left: 43px;
  top: 0;
  width: 84px;
  height: 44px;
  border-radius: 50%;
  background: radial-gradient(circle, #0c1015 0 28%, #778699 31%, #202630 72%);
}

#weapon.fire #muzzle {
  box-shadow: 0 -20px 58px 18px rgba(255, 180, 45, 0.9);
}

#mobile-controls {
  display: none;
}

@media (max-width: 820px), (pointer: coarse) {
  .panel {
    padding: max(18px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
    gap: 14px;
  }

  .panel h1 {
    font-size: clamp(42px, 15vw, 78px);
  }

  .panel p {
    font-size: 15px;
  }

  .panel .small {
    font-size: 12px;
  }

  button {
    min-width: 120px;
    min-height: 52px;
    padding: 12px 18px;
    font-size: 15px;
  }

  #stats {
    left: max(10px, env(safe-area-inset-left));
    right: max(10px, env(safe-area-inset-right));
    bottom: auto;
    top: max(10px, env(safe-area-inset-top));
    justify-content: space-between;
    gap: 8px;
    padding: 9px 10px;
    font-size: 12px;
  }

  #message {
    top: max(58px, calc(env(safe-area-inset-top) + 54px));
    width: min(78vw, 520px);
    font-size: 12px;
    text-align: center;
  }

  #weapon {
    right: 22%;
    bottom: -8%;
    width: 112px;
    height: 170px;
    opacity: 0.86;
  }

  #barrel {
    left: 36px;
    top: 18px;
    width: 34px;
    height: 138px;
  }

  #muzzle {
    left: 27px;
    width: 54px;
    height: 30px;
  }

  #mobile-controls {
    position: absolute;
    inset: 0;
    display: block;
    pointer-events: none;
  }

  #move-zone,
  #look-zone {
    position: absolute;
    bottom: max(58px, calc(env(safe-area-inset-bottom) + 58px));
    display: grid;
    place-content: center;
    width: min(31vw, 180px);
    height: min(31vw, 180px);
    border: 2px solid rgba(255, 255, 255, 0.18);
    border-radius: 50%;
    background: rgba(3, 8, 15, 0.22);
    color: rgba(255, 255, 255, 0.45);
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }

  #move-zone {
    left: max(22px, env(safe-area-inset-left));
  }

  #look-zone {
    right: max(22px, env(safe-area-inset-right));
  }

  #look-hint {
    position: absolute;
    left: 50%;
    bottom: max(12px, env(safe-area-inset-bottom));
    width: min(92vw, 640px);
    transform: translateX(-50%);
    padding: 8px 12px;
    border-radius: 999px;
    background: rgba(3, 8, 15, 0.46);
    color: rgba(255, 255, 255, 0.7);
    font-size: 12px;
    text-align: center;
  }

  @media (orientation: portrait) {
    #mobile-controls::before {
      content: "Vrid telefonen till landskap för helskärmsläge.";
      position: absolute;
      inset: 0;
      display: grid;
      place-content: center;
      padding: 24px;
      background: rgba(3, 5, 10, 0.86);
      color: white;
      font-size: 20px;
      font-weight: 800;
      text-align: center;
      z-index: 5;
    }
  }
}
