* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #111;
  font-family: "Segoe UI", Roboto, sans-serif;
  color: #fff;
  cursor: crosshair;
}

canvas {
  display: block;
}

#hud {
  position: fixed;
  top: 20px;
  left: 20px;
  z-index: 10;
  pointer-events: none;
}

#health-bar {
  width: 240px;
  height: 22px;
  background: rgba(0, 0, 0, 0.55);
  border: 2px solid #fff;
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 8px;
}

#health-fill {
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, #2ecc71, #27ae60);
  transition: width 0.2s ease;
}

#super-bar {
  position: relative;
  width: 240px;
  height: 18px;
  background: rgba(0, 0, 0, 0.55);
  border: 2px solid #fff;
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 8px;
}

#super-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #ff4081, #ab47bc);
  transition: width 0.15s ease;
}

#super-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.5px;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
  pointer-events: none;
}

#super-bar.ready {
  box-shadow: 0 0 14px rgba(255, 64, 129, 0.9);
  animation: super-pulse 1s ease-in-out infinite;
}

@keyframes super-pulse {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.4); }
}

#score, #ammo {
  background: rgba(0, 0, 0, 0.55);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  display: inline-block;
  margin-bottom: 6px;
}

#ammo {
  display: block;
  width: fit-content;
}

#roster {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(880px, 92vw);
  background: rgba(10, 10, 20, 0.88);
  padding: 32px 38px;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #fff;
  z-index: 80;
  pointer-events: none;
  font-size: 14px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  opacity: 0;
}

#roster h3 { font-size: 22px !important; margin-bottom: 18px !important; }

#roster-list { gap: 16px !important; }

#roster.show {
  animation: roster-intro 3s ease forwards;
}

@keyframes roster-intro {
  0% { opacity: 0; transform: translate(-50%, -55%); }
  12% { opacity: 1; transform: translate(-50%, -50%); }
  85% { opacity: 1; transform: translate(-50%, -50%); }
  100% { opacity: 0; transform: translate(-50%, -48%); }
}

#roster h3 {
  font-size: 16px;
  letter-spacing: 2px;
  margin-bottom: 12px;
  border-bottom: 1px solid rgba(255,255,255,0.15);
  padding-bottom: 6px;
  text-align: center;
  color: #ffeb3b;
}

#roster-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
}

#roster-list li {
  background: rgba(255,255,255,0.05);
  border: 2px solid transparent;
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  transition: transform 0.25s, box-shadow 0.25s;
  padding-bottom: 6px;
}

#roster-list li.me {
  box-shadow: 0 0 14px var(--accent, #ffeb3b);
  transform: scale(1.08);
}

#roster-list li .portrait {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: contain;
}

#roster-list li .portrait-fallback {
  width: 70%;
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  opacity: 0.8;
  margin: 10px auto;
}

#roster-list li .nm {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-align: center;
  padding: 2px 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  color: var(--accent, #fff);
}

#instructions {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.55);
  padding: 10px 20px;
  border-radius: 12px;
  font-size: 14px;
  z-index: 10;
  pointer-events: none;
  text-align: center;
}

/* Contrôles tactiles (tablette / mobile) */
#touch-controls {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 50;
  user-select: none;
}
#touch-controls.hidden { display: none; }

.stick-zone {
  position: absolute;
  width: 150px;
  height: 150px;
  bottom: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  border: 2px solid rgba(255, 255, 255, 0.22);
  pointer-events: auto;
  touch-action: none;
}
#touch-move { left: 40px; }
#touch-shoot { right: 40px; }

.stick-knob {
  position: absolute;
  width: 64px;
  height: 64px;
  top: calc(50% - 32px);
  left: calc(50% - 32px);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.35);
  border: 2px solid rgba(255, 255, 255, 0.6);
  pointer-events: none;
  transition: transform 0.06s linear;
}

.touch-btn {
  position: absolute;
  right: 210px;
  bottom: 110px;
  width: 82px;
  height: 82px;
  border-radius: 50%;
  background: linear-gradient(135deg, #ff4081, #ab47bc);
  color: #fff;
  font-size: 34px;
  font-weight: 800;
  border: 3px solid rgba(255, 255, 255, 0.5);
  box-shadow: 0 6px 20px rgba(255, 64, 129, 0.45);
  pointer-events: auto;
  touch-action: none;
  cursor: pointer;
  opacity: 0.55;
  transition: opacity 0.2s, transform 0.1s;
}
.touch-btn.ready {
  opacity: 1;
  animation: super-pulse 1s ease-in-out infinite;
}
.touch-btn:active { transform: scale(0.92); }

@media (max-width: 520px) {
  .stick-zone { width: 120px; height: 120px; bottom: 24px; }
  #touch-move { left: 24px; }
  #touch-shoot { right: 24px; }
  .stick-knob { width: 52px; height: 52px; top: calc(50% - 26px); left: calc(50% - 26px); }
  .touch-btn { right: 170px; bottom: 80px; width: 68px; height: 68px; font-size: 28px; }
}

#game-over {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  z-index: 100;
}

#game-over.hidden {
  display: none;
}

#game-over h1 {
  font-size: 64px;
  color: #e74c3c;
  text-shadow: 0 0 20px rgba(231, 76, 60, 0.6);
}

#game-over p {
  font-size: 24px;
}

#restart {
  padding: 14px 32px;
  font-size: 20px;
  font-weight: 700;
  background: #2ecc71;
  color: #fff;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: transform 0.15s;
}

#restart:hover {
  transform: scale(1.05);
}

#landing, #lobby {
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse at center, rgba(18, 10, 40, 0.92), rgba(5, 2, 15, 0.98));
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 400;
  padding: 30px;
}
#landing.hidden, #lobby.hidden { display: none; }

#landing-panel, #lobby-panel {
  background: rgba(15, 10, 30, 0.92);
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-radius: 20px;
  padding: 44px 56px;
  text-align: center;
  width: min(520px, 92vw);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  color: #fff;
}
#landing-panel h1, #lobby-panel h1 {
  font-size: 46px;
  letter-spacing: 5px;
  color: #ffeb3b;
  margin-bottom: 8px;
  text-shadow: 0 0 20px rgba(255, 235, 59, 0.35);
}
#landing-panel .tagline, #lobby-panel .tagline {
  opacity: 0.75;
  margin-bottom: 22px;
  font-size: 14px;
  letter-spacing: 1px;
}
#player-name, #room-code {
  width: 100%;
  padding: 12px 16px;
  border-radius: 10px;
  border: 2px solid rgba(255, 255, 255, 0.12);
  background: rgba(0, 0, 0, 0.4);
  color: #fff;
  font-size: 15px;
  margin-bottom: 14px;
  font-family: inherit;
}
#player-name:focus, #room-code:focus {
  outline: none;
  border-color: #ffeb3b;
}
#room-code {
  text-transform: uppercase;
  letter-spacing: 4px;
  text-align: center;
  margin-bottom: 0;
  flex: 1;
}
#landing-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
#join-row { display: flex; gap: 10px; }
.landing-btn {
  padding: 14px 22px;
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 1px;
  cursor: pointer;
  transition: transform 0.15s, background 0.2s, border-color 0.2s;
  font-family: inherit;
}
.landing-btn:hover {
  transform: translateY(-2px);
  background: rgba(255, 235, 59, 0.12);
  border-color: #ffeb3b;
}
.landing-btn.primary {
  background: linear-gradient(135deg, #ffeb3b, #ffc107);
  color: #222;
  border-color: transparent;
}
.landing-btn.primary:hover {
  filter: brightness(1.05);
}
.ghost-btn {
  margin-top: 10px;
  padding: 8px 14px;
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.5);
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
}
.ghost-btn:hover { color: #fff; }
.error {
  color: #ff5252;
  min-height: 18px;
  font-size: 13px;
  margin-top: 10px;
}
#server-status {
  margin-top: 12px;
  font-size: 12px;
  opacity: 0.55;
}
#server-status.ok { color: #66bb6a; opacity: 0.8; }
#server-status.ko { color: #ff5252; opacity: 0.9; }

#lobby-code {
  color: #ffeb3b;
  font-weight: 800;
  letter-spacing: 4px;
  font-size: 22px;
}
#lobby-players {
  list-style: none;
  padding: 0;
  margin: 0 0 20px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  min-height: 140px;
}
#lobby-players li {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}
#lobby-players li.host::before { content: "👑"; }
#lobby-players li.me { border-color: #ffeb3b; }
#lobby-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
#lobby-hint { margin-top: 12px; opacity: 0.65; font-size: 13px; }

#lobby-host-opts {
  margin-bottom: 14px;
  font-size: 14px;
  opacity: 0.85;
}
#lobby-host-opts.hidden { display: none; }
#lobby-host-opts input {
  width: 60px;
  padding: 6px 8px;
  margin-left: 6px;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.2);
  background: rgba(0,0,0,0.4);
  color: #fff;
  font-family: inherit;
  text-align: center;
}

#main-menu {
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse at center, rgba(18, 10, 40, 0.9), rgba(5, 2, 15, 0.97));
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
  padding: 30px;
}

#main-menu.hidden { display: none; }

#main-panel {
  background: rgba(15, 10, 30, 0.92);
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-radius: 20px;
  padding: 44px 56px;
  text-align: center;
  max-width: 820px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}

#main-panel h1 {
  font-size: 58px;
  letter-spacing: 6px;
  color: #ffeb3b;
  text-shadow: 0 0 26px rgba(255, 235, 59, 0.45);
  margin-bottom: 6px;
}

#main-panel .tagline {
  color: rgba(255, 255, 255, 0.75);
  letter-spacing: 2px;
  margin-bottom: 28px;
  font-size: 15px;
}

#mode-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.mode-card {
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.07), rgba(255, 255, 255, 0.02));
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  padding: 28px 24px;
  cursor: pointer;
  color: #fff;
  transition: transform 0.2s, border-color 0.2s, background 0.2s, box-shadow 0.2s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  font-family: inherit;
}

.mode-card:hover {
  transform: translateY(-5px);
  border-color: #ffeb3b;
  box-shadow: 0 8px 30px rgba(255, 235, 59, 0.25);
}

.mode-emoji { font-size: 52px; line-height: 1; }
.mode-title { font-size: 24px; font-weight: 800; letter-spacing: 2px; color: #ffeb3b; }
.mode-desc  { font-size: 13px; opacity: 0.8; max-width: 240px; line-height: 1.4; }

#character-select {
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse at center, rgba(20, 15, 40, 0.85), rgba(5, 3, 15, 0.95));
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 30px;
}

#character-select.hidden {
  display: none;
}

#char-panel {
  background: rgba(15, 15, 25, 0.9);
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-radius: 20px;
  padding: 36px 44px;
  max-width: 1100px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

#char-panel h1 {
  text-align: center;
  font-size: 38px;
  letter-spacing: 3px;
  margin-bottom: 24px;
  color: #ffeb3b;
  text-shadow: 0 0 18px rgba(255, 235, 59, 0.4);
}

#char-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
}

.char-card {
  background: linear-gradient(135deg, rgba(255,255,255,0.06), rgba(255,255,255,0.02));
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-radius: 14px;
  padding: 18px;
  cursor: pointer;
  transition: transform 0.18s, border-color 0.18s, background 0.18s;
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.char-preview {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  background: radial-gradient(ellipse at 50% 65%, rgba(255,255,255,0.08), transparent 65%);
  border-radius: 10px;
  margin-bottom: 10px;
  display: block;
}

.char-card:hover {
  transform: translateY(-4px);
  border-color: var(--accent, #ffeb3b);
  background: linear-gradient(135deg, rgba(255, 235, 59, 0.1), rgba(255,255,255,0.03));
}

.char-card h2 {
  font-size: 22px;
  margin-bottom: 6px;
  color: var(--accent, #ffeb3b);
  letter-spacing: 1px;
}

.char-card .attack-tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  margin-bottom: 10px;
}

.char-card ul {
  list-style: none;
  font-size: 13px;
  line-height: 1.6;
  opacity: 0.9;
}

.char-card ul li {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px dashed rgba(255,255,255,0.08);
  padding: 2px 0;
}

.char-card ul li span:last-child {
  font-weight: 600;
  color: var(--accent, #ffeb3b);
}

#char-hint {
  text-align: center;
  margin-top: 22px;
  opacity: 0.65;
  font-size: 13px;
}
