* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: #0d0a07;
  color: #f8fafc;
  overflow: hidden;
  height: 100vh;
  height: 100dvh;
  width: 100vw;
  width: 100dvw;
  display: flex;
  flex-direction: column;
}

.hidden {
  display: none !important;
}

/* 1. Universal Top HUD */
.hud-bar {
  height: 54px;
  background: #18120c;
  border-bottom: 2px solid #3d2615;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  z-index: 100;
  flex-shrink: 0;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.6);
}

.hud-left, .hud-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.hud-btn {
  background: #2b1a0e;
  color: #f8fafc;
  border: 1px solid #4a2e1b;
  padding: 6px 11px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.hud-btn:hover {
  background: #3d2615;
  border-color: #613b22;
}

.hud-btn:active {
  transform: scale(0.97);
}

.hub-btn {
  background: #0284c7;
  border-color: #0369a1;
}

.hub-btn:hover {
  background: #0369a1;
}

.restart-btn {
  background: #16a34a;
  border-color: #15803d;
}

.restart-btn:hover {
  background: #15803d;
}

.sound-btn {
  background: #475569;
}

.sound-btn.off {
  background: #e11d48;
}

.hud-title {
  font-weight: 700;
  font-size: 15px;
  color: #facc15;
  text-shadow: 0 0 10px rgba(250, 204, 21, 0.4);
}

.hud-select {
  background: #24160d;
  color: #fef08a;
  border: 1px solid #573319;
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  outline: none;
}

.hud-badge {
  font-size: 12px;
  font-weight: 600;
  padding: 4px 8px;
  background: #27170e;
  border-radius: 6px;
  border: 1px solid #452414;
  color: #cbd5e1;
}

/* Scoreboard */
.hud-center {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.hud-scoreboard {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 24px;
  font-weight: 900;
  font-family: monospace;
}

.score.p1 {
  color: #38bdf8;
  text-shadow: 0 0 12px rgba(56, 189, 248, 0.6);
}

.score.p2 {
  color: #ef4444;
  text-shadow: 0 0 12px rgba(239, 68, 68, 0.6);
}

.score-divider {
  color: #64748b;
  font-size: 18px;
}

.hud-target {
  font-size: 10px;
  color: #a16207;
  letter-spacing: 1px;
  font-weight: 700;
}

/* 2. Floating Online Pill Banner */
#online-pill-banner {
  position: absolute;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(24, 18, 12, 0.92);
  border: 1px solid #713f12;
  backdrop-filter: blur(8px);
  padding: 6px 14px;
  border-radius: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
  z-index: 10;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
}

#btn-pill-open-modal {
  background: #ca8a04;
  color: #000;
  border: none;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}

/* 3. Main Arena Container */
#game-container {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at center, #1c130b 0%, #080604 100%);
  overflow: hidden;
  padding: 6px;
}

#gameCanvas {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - 66px);
  max-height: calc(100dvh - 66px);
  aspect-ratio: 600 / 1000;
  border-radius: 14px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8), 0 0 20px rgba(234, 179, 8, 0.15);
  touch-action: none;
  cursor: grab;
}

#gameCanvas:active {
  cursor: grabbing;
}

/* 4. Victory Overlay */
#victory-overlay {
  position: absolute;
  inset: 0;
  background: rgba(13, 10, 7, 0.85);
  backdrop-filter: blur(6px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  animation: fadeIn 0.25s ease-out;
}

.victory-card {
  background: #1e130a;
  border: 2px solid #eab308;
  box-shadow: 0 12px 40px rgba(234, 179, 8, 0.35);
  padding: 30px;
  border-radius: 20px;
  text-align: center;
  max-width: 380px;
  width: 90%;
  animation: popScale 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.victory-title {
  font-size: 26px;
  font-weight: 900;
  color: #fde047;
  margin-bottom: 10px;
}

.victory-score {
  font-size: 16px;
  color: #cbd5e1;
  margin-bottom: 22px;
}

.btn-primary {
  background: linear-gradient(135deg, #eab308, #ca8a04);
  color: #1a0f02;
  font-weight: 800;
  font-size: 15px;
  padding: 12px 24px;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.2s;
  width: 100%;
}

.btn-primary:hover {
  opacity: 0.95;
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: translateY(0);
}

/* 5. Online Matchmaking Modal */
#online-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 300;
}

.modal-card {
  background: #1a1209;
  border: 1px solid #713f12;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.8);
  border-radius: 18px;
  padding: 24px;
  max-width: 440px;
  width: 92%;
  position: relative;
}

.modal-close-btn {
  position: absolute;
  top: 14px;
  right: 14px;
  background: #2b1b0e;
  border: 1px solid #4a2f1a;
  color: #cbd5e1;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 16px;
  font-weight: bold;
}

.modal-close-btn:hover {
  background: #4a2f1a;
  color: white;
}

.modal-tabs {
  display: flex;
  gap: 8px;
  margin: 14px 0;
}

.modal-tab {
  flex: 1;
  padding: 9px;
  background: #24160a;
  border: 1px solid #452410;
  color: #94a3b8;
  border-radius: 8px;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}

.modal-tab.active {
  background: #ca8a04;
  color: #170d02;
  border-color: #eab308;
}

.room-code-badge {
  font-size: 28px;
  font-weight: 900;
  font-family: monospace;
  letter-spacing: 3px;
  color: #facc15;
  margin: 6px 0;
}

.modal-btn-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

.btn-action {
  padding: 10px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 13px;
  border: none;
  cursor: pointer;
  transition: opacity 0.2s;
}

.btn-action:hover {
  opacity: 0.92;
}

.btn-share {
  background: #0284c7;
  color: white;
}

.btn-copy {
  background: #16a34a;
  color: white;
}

.input-code {
  width: 100%;
  background: #0e0905;
  border: 1px solid #573319;
  padding: 12px;
  border-radius: 8px;
  color: #fde047;
  font-size: 18px;
  font-weight: 700;
  text-align: center;
  letter-spacing: 2px;
  outline: none;
  margin-bottom: 10px;
}

.input-code:focus {
  border-color: #eab308;
}

@keyframes popScale {
  from { transform: scale(0.85); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Mobile Responsive */
@media (max-width: 600px) {
  .hud-title, .hud-badge {
    display: none;
  }
  .hud-btn {
    padding: 5px 8px;
    font-size: 12px;
  }
}
