* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: #111; color: #fff;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  touch-action: none; overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}
button { font-family: inherit; }
#game, #game canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }

/* ---------- Fenster / Overlays ---------- */
#menu, #pause, #disconnected {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, rgba(10, 20, 35, .55), rgba(5, 8, 15, .9));
  z-index: 20;
}
.box {
  background: rgba(15, 22, 35, .85); border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 14px; padding: 32px 40px; text-align: center; min-width: 320px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
}
#pause, #disconnected { cursor: pointer; }
#menu h1 { margin: 0 0 24px; font-size: 44px; letter-spacing: 4px; font-weight: 900; }
#menu h1 span { color: #ff8a3d; margin-left: 10px; }
#name, #room {
  display: block; width: 100%; padding: 12px 14px; font-size: 18px; border-radius: 8px; margin-bottom: 8px;
  border: 1px solid rgba(255, 255, 255, .2); background: rgba(0, 0, 0, .4); color: #fff; outline: none;
  -webkit-user-select: text; user-select: text;
}
#room { font-size: 15px; padding: 9px 14px; }
#name:focus, #room:focus { border-color: #ff8a3d; }
.hint { margin: 14px 0 0; font-size: 12px; color: #8b97a8; }
.bigbtn {
  display: block; width: 100%; margin-top: 12px; padding: 14px; font-size: 20px; font-weight: 800;
  letter-spacing: 2px; border: 0; border-radius: 8px; cursor: pointer;
  background: linear-gradient(#ff9a4d, #e8662a); color: #fff; text-transform: uppercase;
}
.bigbtn:hover { filter: brightness(1.1); }
.controls {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px 20px; margin-top: 24px;
  text-align: left; font-size: 14px; color: #b9c3d1;
}
.controls b { color: #fff; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
.label { font-size: 11px; letter-spacing: 2px; color: rgba(255, 255, 255, .6); font-weight: 700; }

#crosshair { position: absolute; left: 50%; top: 50%; width: 0; height: 0; }
#crosshair i { position: absolute; background: #fff; box-shadow: 0 0 2px #000; }
#crosshair i:nth-child(1) { width: 2px; height: 8px; left: -1px; top: -14px; }
#crosshair i:nth-child(2) { width: 2px; height: 8px; left: -1px; top: 6px; }
#crosshair i:nth-child(3) { width: 8px; height: 2px; left: -14px; top: -1px; }
#crosshair i:nth-child(4) { width: 8px; height: 2px; left: 6px; top: -1px; }

#hitmarker { position: absolute; left: 50%; top: 50%; opacity: 0; transition: opacity .25s; }
#hitmarker.show { opacity: 1; transition: none; }
#hitmarker i { position: absolute; width: 22px; height: 3px; left: -11px; top: -1.5px; background: #fff; }
#hitmarker.head i { background: #ff3b3b; }
#hitmarker i:nth-child(1) { transform: rotate(45deg); }
#hitmarker i:nth-child(2) { transform: rotate(-45deg); }

#vignette {
  position: absolute; inset: 0; opacity: 0; transition: opacity .4s;
  background: radial-gradient(ellipse at center, transparent 45%, rgba(220, 0, 0, .6));
}
#vignette.show { opacity: 1; transition: none; }

#health { position: absolute; left: 28px; bottom: 26px; }
#healthbar { width: 240px; height: 14px; margin-top: 6px; background: rgba(0, 0, 0, .5); border-radius: 7px; overflow: hidden; }
#healthfill { height: 100%; width: 100%; background: linear-gradient(90deg, #2ecc71, #7bed9f); transition: width .15s; }
#healthfill.low { background: linear-gradient(90deg, #e74c3c, #ff7675); }
#healthtext { font-size: 36px; font-weight: 900; text-shadow: 0 2px 6px rgba(0, 0, 0, .6); }

#ammo { position: absolute; right: 28px; bottom: 26px; text-align: right; font-size: 40px; font-weight: 900; text-shadow: 0 2px 6px rgba(0, 0, 0, .6); }
#ammo .dim { font-size: 22px; color: rgba(255, 255, 255, .55); }
#reloadhint { font-size: 14px; color: #ffcf6b; letter-spacing: 2px; min-height: 18px; }

#weapons { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; margin-bottom: 10px; }
#weapons .slot {
  font-size: 13px; font-weight: 600; padding: 3px 10px; border-radius: 5px;
  background: rgba(0, 0, 0, .35); color: rgba(255, 255, 255, .5); text-shadow: none;
}
#weapons .slot b { display: inline-block; width: 14px; margin-right: 6px; color: rgba(255, 255, 255, .7); }
#weapons .slot.active { background: rgba(255, 138, 61, .85); color: #fff; }
#weapons .slot.active b { color: #fff; }
#killfeed .wpn { color: #b9c3d1; font-weight: 400; font-size: 13px; }

/* Zielfernrohr */
#health, #ammo, #killfeed, #mystats { z-index: 1; }
#scope {
  position: absolute; inset: 0; z-index: 0;
  background:
    linear-gradient(#000, #000) center / 1px 100% no-repeat,
    linear-gradient(#000, #000) center / 100% 1px no-repeat,
    radial-gradient(circle at center, transparent 0, transparent 34vh, #000 34.3vh);
}
#scope::after {
  content: ""; position: absolute; left: 50%; top: 50%; width: 4px; height: 4px; margin: -2px 0 0 -2px;
  background: #ff3b3b; border-radius: 50%;
}

#killfeed { position: absolute; right: 20px; top: 18px; display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
#killfeed div {
  background: rgba(0, 0, 0, .55); padding: 6px 12px; border-radius: 6px; font-size: 15px; font-weight: 600;
  animation: fadein .2s;
}
#killfeed .info { color: #b9c3d1; font-weight: 400; }
@keyframes fadein { from { opacity: 0; transform: translateX(20px); } }

#mystats { position: absolute; left: 20px; top: 18px; background: rgba(0, 0, 0, .45); padding: 6px 12px; border-radius: 6px; font-weight: 600; }

#center-msg {
  position: absolute; left: 0; right: 0; top: 30%; text-align: center; font-size: 28px; font-weight: 900;
  color: #ffcf6b; text-shadow: 0 2px 8px rgba(0, 0, 0, .7); opacity: 0; transition: opacity .5s;
}
#center-msg.show { opacity: 1; transition: none; }

/* ---------- Punktestand ---------- */
#scoreboard {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 15;
  background: rgba(10, 15, 25, .88); border-radius: 12px; padding: 20px 28px; min-width: 380px;
  border: 1px solid rgba(255, 255, 255, .12);
}
#scoreboard h2 { margin: 0 0 12px; text-align: center; letter-spacing: 2px; }
#scoreboard table { width: 100%; border-collapse: collapse; }
#scoreboard th { text-align: left; font-size: 12px; color: #8b97a8; letter-spacing: 1px; padding: 4px 8px; }
#scoreboard td { padding: 6px 8px; border-top: 1px solid rgba(255, 255, 255, .07); font-weight: 600; }
#scoreboard th:not(:first-child), #scoreboard td:not(:first-child) { text-align: right; }
#scoreboard tr.me td { background: rgba(255, 138, 61, .15); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 8px; }

/* ---------- Tod ---------- */
#death {
  position: fixed; inset: 0; z-index: 12; display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: rgba(90, 0, 0, .35); pointer-events: none; text-shadow: 0 2px 10px rgba(0, 0, 0, .8);
}
#death h1 { font-size: 64px; margin: 0; letter-spacing: 4px; }
#death p { font-size: 22px; margin: 8px; }

/* ======================= Handy & Tablet ======================= */
.touch-only { display: none !important; }
body.touch .touch-only { display: grid !important; }
body.touch .desktop-only { display: none !important; }
.controls.touch-only { grid-template-columns: 1fr; }

#menu { overflow-y: auto; touch-action: pan-y; padding: 12px; }
#menu .box { max-height: 100%; overflow-y: auto; margin: auto; }

#rotate {
  display: none; position: fixed; inset: 0; z-index: 50; align-items: center; justify-content: center;
  background: #0f1623;
}
@media (orientation: portrait) {
  body.touch #rotate { display: flex; }
}

#touch { position: fixed; inset: 0; z-index: 11; }
#touch-look { position: absolute; top: 64px; right: 0; bottom: 0; width: 55%; touch-action: none; }
#touch-move { position: absolute; top: 25%; left: 0; bottom: 0; width: 45%; touch-action: none; }
#joy {
  position: absolute; width: 120px; height: 120px; margin: -60px 0 0 -60px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .35); background: rgba(255, 255, 255, .08);
  pointer-events: none; display: none;
}
#joy.on { display: block; }
#joy-knob {
  position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px 0 0 -26px; border-radius: 50%;
  background: rgba(255, 255, 255, .55); box-shadow: 0 2px 8px rgba(0, 0, 0, .4);
}
.tbtn {
  position: absolute; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .45);
  background: rgba(15, 22, 35, .45); color: #fff; font-size: 24px; font-weight: 800;
  touch-action: none; padding: 0; display: flex; align-items: center; justify-content: center;
  -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
}
.tbtn.down { background: rgba(255, 138, 61, .7); border-color: #ffb07a; }
#btn-fire { width: 96px; height: 96px; font-size: 38px; right: calc(28px + env(safe-area-inset-right)); bottom: 70px; }
#btn-jump { width: 66px; height: 66px; font-size: 30px; right: calc(140px + env(safe-area-inset-right)); bottom: 28px; }
#btn-reload { width: 54px; height: 54px; right: calc(140px + env(safe-area-inset-right)); bottom: 112px; }
#btn-scope { width: 58px; height: 58px; right: calc(48px + env(safe-area-inset-right)); bottom: 184px; }
#btn-scores { width: 40px; height: 40px; font-size: 18px; left: calc(14px + env(safe-area-inset-left)); top: calc(52px + env(safe-area-inset-top)); }

/* HUD im Touch-Modus umsortieren, damit nichts unter den Daumen liegt */
body.touch #mystats { left: calc(14px + env(safe-area-inset-left)); top: calc(10px + env(safe-area-inset-top)); font-size: 13px; padding: 4px 10px; }
body.touch #health { left: calc(64px + env(safe-area-inset-left)); top: calc(50px + env(safe-area-inset-top)); bottom: auto; }
body.touch #healthbar { width: 130px; height: 10px; }
body.touch #healthtext { font-size: 20px; }
body.touch #health .label { display: none; }
body.touch #ammo { left: 0; right: 0; top: calc(48px + env(safe-area-inset-top)); bottom: auto; text-align: center; font-size: 26px; }
body.touch #ammo .label { display: none; }
body.touch #ammo .dim { font-size: 16px; }
body.touch #weapons {
  position: fixed; top: calc(8px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  flex-direction: row; gap: 6px; margin: 0; pointer-events: auto;
}
body.touch #weapons .slot { font-size: 12px; padding: 7px 10px; }
body.touch #weapons .slot b { display: none; }
body.touch #killfeed { top: calc(10px + env(safe-area-inset-top)); right: calc(12px + env(safe-area-inset-right)); }
body.touch #killfeed div { font-size: 12px; padding: 4px 8px; }

/* Kleine Bildschirme (Handy quer) */
@media (max-height: 500px) {
  .box { padding: 18px 22px; min-width: 0; }
  #menu h1 { font-size: 28px; margin-bottom: 12px; }
  .bigbtn { padding: 10px; font-size: 17px; }
  .controls { font-size: 12px; margin-top: 12px; gap: 3px 14px; }
  #death h1 { font-size: 40px; }
  #death p { font-size: 16px; }
  #scoreboard { min-width: 300px; padding: 12px 16px; }
  #center-msg { font-size: 20px; }
  .tbtn { transform: scale(.85); transform-origin: bottom right; }
}
