* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body, #game {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: Arial, sans-serif;
  background: #9bc9e8;
  color: white;
}

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

#topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 58px;
  padding: 0 22px;
  display: flex;
  align-items: center;
  gap: 22px;
  background: linear-gradient(90deg, rgba(12,20,35,.92), rgba(12,20,35,.55));
  z-index: 5;
}

.brand {
  font-size: 21px;
  font-weight: 900;
  letter-spacing: 1px;
}

.brand span {
  color: #42c5ff;
}

#connection, #player-count {
  font-size: 13px;
  color: #d8e5ef;
}

#connection {
  margin-left: auto;
}

#connection i {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #e6a23c;
  margin-right: 6px;
}

#connection.online i {
  background: #35d07f;
}

.panel {
  position: fixed;
  z-index: 10;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(390px, calc(100% - 36px));
  padding: 28px;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 18px;
  background: rgba(14,24,40,.94);
  box-shadow: 0 18px 70px rgba(0,0,0,.35);
  text-align: center;
}

.panel h1 {
  margin: 0 0 10px;
  font-size: 25px;
}

.panel p {
  color: #b9c7d8;
  font-size: 14px;
  line-height: 1.5;
}

.panel input {
  width: 100%;
  margin: 14px 0 10px;
  padding: 14px;
  border: 1px solid #43536a;
  border-radius: 9px;
  background: #1c2b40;
  color: white;
  font-size: 16px;
  outline: none;
}

.panel button {
  width: 100%;
  padding: 15px;
  border: 0;
  border-radius: 9px;
  background: #168bd0;
  color: white;
  font-weight: 900;
  cursor: pointer;
}

.hidden {
  display: none !important;
}

#player-label {
  position: fixed;
  top: 70px;
  left: 18px;
  padding: 9px 13px;
  border-radius: 8px;
  background: rgba(12,20,35,.72);
  font-size: 13px;
}

#help {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  padding: 9px 15px;
  border-radius: 8px;
  background: rgba(12,20,35,.65);
  color: #e2eaf2;
  font-size: 12px;
  white-space: nowrap;
}

#mobile-controls {
  display: none;
}

@media (pointer: coarse), (max-width: 700px) {
  #topbar {
    height: 48px;
    padding: 0 12px;
    gap: 10px;
  }

  .brand {
    font-size: 17px;
  }

  #connection, #player-count {
    font-size: 11px;
  }

  #mobile-controls {
    display: block;
  }

  #help {
    display: none;
  }

  #joystick {
    position: fixed;
    left: 22px;
    bottom: 28px;
    width: 126px;
    height: 126px;
    border: 2px solid rgba(255,255,255,.48);
    border-radius: 50%;
    background: rgba(12,20,35,.30);
    touch-action: none;
  }

  #stick {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 54px;
    height: 54px;
    margin: -27px;
    border-radius: 50%;
    background: rgba(225,239,255,.75);
    border: 2px solid white;
    box-shadow: 0 4px 12px rgba(0,0,0,.25);
  }

  #mobile-actions {
    position: fixed;
    right: 14px;
    bottom: 22px;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 9px;
  }

  .action-button {
    min-width: 88px;
    min-height: 48px;
    border: 1px solid rgba(255,255,255,.35);
    border-radius: 13px;
    padding: 9px 12px;
    background: rgba(20,40,65,.82);
    color: white;
    font-size: 11px;
    font-weight: 900;
    touch-action: none;
  }

  #use {
    width: 112px;
    min-height: 65px;
    background: #a72b2b;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 4px;
  }

  #use:disabled {
    opacity: .72;
    background: #465365;
  }

  #use-icon {
    font-size: 21px;
  }

  #use-label {
    font-size: 9px;
    text-align: center;
  }
}


/* Autorise le contrôle tactile de la caméra sur le jeu */
canvas { touch-action: none; }


/* Sélection des personnages MégaCity */
.character-panel {
  width: min(520px, calc(100% - 28px));
  padding: 26px;
  background: rgba(10, 19, 34, .96);
  border: 1px solid rgba(110, 177, 225, .35);
}

.character-panel h1 {
  font-size: 30px;
  letter-spacing: 1px;
}

.character-panel h1 span {
  color: #42c5ff;
}

.selection-kicker,
.selection-footer {
  color: #72c9f3;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 3px;
}

.selection-kicker {
  margin-bottom: 7px;
}

#character-selection {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin: 22px 0 12px;
}

.character-card {
  position: relative;
  min-width: 0;
  min-height: 170px;
  padding: 14px 8px;
  border: 2px solid #34465c;
  border-radius: 13px;
  background: linear-gradient(160deg, #24364c, #111e30);
  color: white;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  transition: border-color .18s, background .18s, transform .18s;
}

.character-card.selected {
  border-color: #42c5ff;
  background: linear-gradient(160deg, #24577a, #152b43);
  box-shadow: 0 0 20px rgba(66, 197, 255, .2);
  transform: translateY(-2px);
}

.character-preview {
  display: grid;
  place-items: center;
  width: 76px;
  height: 88px;
  border-radius: 12px;
  font-size: 58px;
  font-weight: 400;
  background: rgba(255,255,255,.08);
}

.male-preview {
  color: #65c8ff;
}

.female-preview {
  color: #ff9cc7;
}

.character-card-title {
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 1px;
}

.character-card-subtitle {
  color: #b8c9d9;
  font-size: 11px;
}

.character-check {
  position: absolute;
  top: 8px;
  right: 10px;
  display: none;
  color: #72dcff;
  font-weight: 900;
}

.character-card.selected .character-check {
  display: block;
}

.selection-footer {
  margin-top: 16px;
  color: #8297ad;
  font-size: 9px;
}

@media (max-width: 480px) {
  .character-panel {
    padding: 20px 16px;
  }

  .character-card {
    min-height: 150px;
  }
}
