:root {
  --bg: #070a1c;
  --panel: rgba(14, 20, 48, 0.84);
  --border: rgba(126, 240, 255, 0.28);
  --text: #f3f7ff;
  --muted: #9db2dc;
  --cyan: #4ff0e2;
  --pink: #ff62c8;
  --violet: #a774ff;
  --gold: #ffd45c;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  font-family: 'Nunito', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  user-select: none;
  -webkit-user-select: none;
}

#viewport {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

#viewport canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* Crosshair */
.crosshair {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 34px;
  height: 34px;
  pointer-events: none;
  z-index: 6;
}
.crosshair::before, .crosshair::after {
  content: '';
  position: absolute;
  background: rgba(79, 240, 226, 0.95);
  box-shadow: 0 0 8px rgba(79, 240, 226, 0.9);
}
.crosshair::before { left: 50%; top: 2px; width: 2px; height: 30px; transform: translateX(-50%); }
.crosshair::after { top: 50%; left: 2px; height: 2px; width: 30px; transform: translateY(-50%); }
.crosshair-ring {
  position: absolute;
  inset: 5px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.85);
  transition: transform 0.08s ease, border-color 0.08s ease;
}
.crosshair.hit .crosshair-ring {
  transform: scale(1.45);
  border-color: var(--gold);
}

/* Damage Flash */
.damage-vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 5;
  background: radial-gradient(circle, transparent 52%, rgba(255, 70, 140, 0.52) 100%);
  opacity: 0;
  transition: opacity 0.16s ease;
}
.damage-vignette.show { opacity: 1; }

/* In-Game HUD */
.hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 7;
  padding: calc(14px + env(safe-area-inset-top, 0px)) 20px calc(18px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.hud-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.scoreboard {
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: rgba(12, 18, 44, 0.78);
  backdrop-filter: blur(10px);
  border: 1.5px solid var(--border);
  border-radius: 18px;
  padding: 8px 20px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

.sb-row {
  display: flex;
  align-items: center;
  gap: 14px;
  font-family: 'Fredoka', sans-serif;
  font-size: 1.15rem;
}

.sb-name { max-width: 125px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-p1 { color: var(--cyan); }
.sb-p2 { color: var(--pink); }
.sb-score { font-size: 1.55rem; color: #fff; letter-spacing: 2px; }
.sb-sub { font-size: 0.68rem; font-weight: 800; letter-spacing: 1.4px; color: var(--gold); margin-top: 2px; }

.hud-top-actions {
  position: absolute;
  top: calc(14px + env(safe-area-inset-top, 0px));
  right: 18px;
  display: flex;
  gap: 8px;
  pointer-events: auto;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(12, 18, 44, 0.76);
  color: #fff;
  font-size: 1.02rem;
  cursor: pointer;
  display: grid;
  place-items: center;
}
.icon-btn:hover { background: rgba(79, 240, 226, 0.25); }

.round-banner {
  position: fixed;
  left: 50%;
  top: 28%;
  transform: translate(-50%, -50%);
  z-index: 9;
  font-family: 'Fredoka', sans-serif;
  font-size: clamp(1.8rem, 4.5vw, 3rem);
  color: #fff;
  text-shadow: 0 4px 26px rgba(79, 240, 226, 0.85);
  background: rgba(12, 18, 46, 0.78);
  border: 1.5px solid rgba(79, 240, 226, 0.55);
  padding: 12px 28px;
  border-radius: 22px;
  pointer-events: none;
}

.hud-bottom {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
}

.vitals-card, .weapon-card {
  background: rgba(12, 18, 44, 0.78);
  backdrop-filter: blur(10px);
  border: 1.5px solid var(--border);
  border-radius: 18px;
  padding: 11px 16px;
  min-width: 190px;
}

.bar-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.8px;
  margin-bottom: 4px;
}

.bar-track {
  height: 10px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.14);
  overflow: hidden;
  margin-bottom: 8px;
}
.bar-track:last-child { margin-bottom: 0; }
.bar-fill { height: 100%; width: 100%; border-radius: 99px; transition: width 0.1s linear; }
.hp-fill { background: linear-gradient(90deg, #ff5ea8, #4ff0e2); }
.dash-fill { background: linear-gradient(90deg, #6c7bff, #4ff0e2); }

.weapon-card { text-align: right; min-width: 175px; }
.weapon-name { font-family: 'Fredoka', sans-serif; font-size: 1.05rem; color: var(--cyan); }
.weapon-ammo { font-family: 'Fredoka', sans-serif; font-size: 1.5rem; color: #fff; }
.weapon-hint { font-size: 0.7rem; color: var(--muted); font-weight: 700; }

/* Lock-Pointer Prompt */
.lock-prompt {
  position: fixed;
  left: 50%;
  bottom: 92px;
  transform: translateX(-50%);
  z-index: 8;
  background: rgba(12, 18, 44, 0.88);
  border: 1.5px solid var(--cyan);
  color: #fff;
  padding: 10px 20px;
  border-radius: 999px;
  font-family: 'Fredoka', sans-serif;
  font-size: 0.96rem;
  cursor: pointer;
  pointer-events: auto;
  box-shadow: 0 0 24px rgba(79, 240, 226, 0.35);
}

/* Mobile / Tablet Touch Controls */
.touch-controls {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 8;
}

.stick-zone {
  position: absolute;
  left: 22px;
  bottom: calc(96px + env(safe-area-inset-bottom, 0px));
  width: 118px;
  height: 118px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  border: 2px solid rgba(79, 240, 226, 0.42);
  pointer-events: auto;
  touch-action: none;
}

.stick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 48px;
  height: 48px;
  margin: -24px 0 0 -24px;
  border-radius: 50%;
  background: radial-gradient(circle, #7efce8, #4b8bff);
  box-shadow: 0 0 16px rgba(79, 240, 226, 0.65);
}

.touch-action-pad {
  position: absolute;
  right: 22px;
  bottom: calc(96px + env(safe-area-inset-bottom, 0px));
  display: grid;
  grid-template-columns: repeat(2, 62px);
  gap: 10px;
  pointer-events: auto;
}

.touch-btn {
  height: 62px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.3);
  background: rgba(14, 22, 54, 0.78);
  color: #fff;
  font-family: 'Fredoka', sans-serif;
  font-size: 0.85rem;
  font-weight: 700;
  touch-action: none;
}
.touch-btn.fire {
  grid-column: 1 / -1;
  border-radius: 999px;
  background: linear-gradient(135deg, #4ff0e2, #a774ff);
  color: #081128;
  border-color: #fff;
  font-size: 1rem;
}

/* Menu / Lobby Overlay */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: calc(16px + env(safe-area-inset-top, 0px)) 16px calc(20px + env(safe-area-inset-bottom, 0px));
  background: rgba(6, 10, 28, 0.66);
  backdrop-filter: blur(10px);
  overflow-y: auto;
}

.lobby-card {
  width: 100%;
  max-width: 960px;
  background: var(--panel);
  border: 1.5px solid var(--border);
  border-radius: 28px;
  padding: 22px 26px 26px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.65);
}

.lobby-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding-bottom: 16px;
  margin-bottom: 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.brand-title {
  font-family: 'Fredoka', sans-serif;
  font-size: 2.2rem;
  background: linear-gradient(90deg, #6ef7e8 0%, #fff 48%, #ff77cc 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.pill-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: #fff;
  font-family: inherit;
  font-size: 0.84rem;
  font-weight: 700;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
}
.pill-btn:hover { background: rgba(79, 240, 226, 0.2); border-color: var(--cyan); }

.lobby-grid {
  display: grid;
  grid-template-columns: 1.05fr 1fr;
  gap: 22px;
}

.sub-panel {
  background: rgba(8, 13, 34, 0.62);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 20px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.sec-title {
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 1.3px;
  text-transform: uppercase;
  color: var(--cyan);
}

.row-pills { display: flex; flex-wrap: wrap; gap: 8px; }
.choice-pill {
  flex: 1;
  min-width: 90px;
  padding: 10px 10px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.06);
  border: 1.5px solid rgba(255, 255, 255, 0.12);
  color: #fff;
  font-family: 'Fredoka', sans-serif;
  font-size: 0.9rem;
  cursor: pointer;
  text-align: center;
}
.choice-pill.active {
  background: rgba(79, 240, 226, 0.18);
  border-color: var(--cyan);
  box-shadow: 0 0 16px rgba(79, 240, 226, 0.24);
}
.choice-pill small { display: block; font-family: 'Nunito', sans-serif; font-size: 0.7rem; color: var(--muted); margin-top: 2px; }

.input-row { display: flex; gap: 8px; }
.text-input {
  flex: 1;
  background: rgba(6, 10, 26, 0.9);
  border: 1.5px solid rgba(130, 210, 255, 0.3);
  border-radius: 13px;
  padding: 10px 13px;
  color: #fff;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 800;
  outline: none;
}
.text-input:focus { border-color: var(--cyan); }

.primary-btn {
  background: linear-gradient(135deg, #4ff0e2 0%, #6b8cff 52%, #ff6ec7 100%);
  color: #071026;
  border: none;
  border-radius: 999px;
  padding: 12px 20px;
  font-family: 'Fredoka', sans-serif;
  font-size: 1.02rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(79, 240, 226, 0.32);
}
.primary-btn:hover { filter: brightness(1.07); transform: translateY(-1px); }

.secondary-btn {
  background: rgba(255, 255, 255, 0.09);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  border-radius: 999px;
  padding: 11px 18px;
  font-family: 'Fredoka', sans-serif;
  font-size: 0.96rem;
  cursor: pointer;
}
.secondary-btn:hover { background: rgba(255, 255, 255, 0.16); }

.room-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 170px;
  overflow-y: auto;
}

.room-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
}
.room-item strong { font-size: 0.92rem; }
.room-item span { display: block; font-size: 0.74rem; color: var(--muted); }
.join-btn {
  background: var(--cyan);
  color: #071026;
  border: none;
  border-radius: 999px;
  padding: 6px 14px;
  font-family: 'Fredoka', sans-serif;
  font-weight: 700;
  cursor: pointer;
}

.waiting-box {
  padding: 14px;
  border-radius: 16px;
  background: rgba(79, 240, 226, 0.12);
  border: 1.5px solid var(--cyan);
  text-align: center;
}
.code-big {
  font-family: 'Fredoka', sans-serif;
  font-size: 2rem;
  letter-spacing: 5px;
  color: var(--gold);
  margin: 6px 0;
}

.modal-card {
  width: 100%;
  max-width: 440px;
  background: var(--panel);
  border: 1.5px solid var(--border);
  border-radius: 26px;
  padding: 26px;
  text-align: center;
}

.hidden { display: none !important; }

@media (max-width: 820px) {
  .lobby-grid { grid-template-columns: 1fr; }
}
