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

body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #0d1f17, #07120d);
  font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif;
  color: #fff;
  overflow: hidden;
}

#wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

h1 {
  font-size: 24px;
  letter-spacing: 3px;
  color: #ffe082;
  text-shadow: 0 2px 8px rgba(0, 0, 0, .6);
}

#hud {
  display: flex;
  gap: 16px;
  font-size: 14px;
  align-items: center;
  width: 100%;
  padding: 0 4px;
}

#hud b { color: #ffd600; }

#hpbar {
  width: 130px;
  height: 14px;
  background: rgba(255, 255, 255, .15);
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, .25);
}

#hpfill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #ff5252, #ff8a65);
  border-radius: 8px;
  transition: width .15s;
}

#tip {
  margin-left: auto;
  font-size: 11px;
  color: #7f9c8b;
}

.touch-instructions { display: none; }

html[data-input-mode="touch"] .desktop-instructions { display: none; }
html[data-input-mode="touch"] .touch-instructions { display: inline; }

#canvas-box {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 10px 50px rgba(0, 0, 0, .65);
  border: 1px solid rgba(255, 255, 255, .08);
}

canvas { display: block; cursor: crosshair; }

html[data-input-mode="touch"] canvas {
  cursor: default;
  touch-action: none;
  -webkit-touch-callout: none;
}

#overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(6, 16, 11, .6);
  backdrop-filter: blur(2px);
  z-index: 5;
}

#touchControls {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: 0 max(24px, env(safe-area-inset-right)) max(22px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

#touchControls[hidden] { display: none; }

.touch-cluster {
  display: flex;
  align-items: flex-end;
  gap: 18px;
  pointer-events: none;
}

.touch-control {
  width: 168px;
  height: 168px;
  border: 4px solid rgba(255, 255, 255, .58);
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(9, 24, 17, .58);
  color: #fff7cf;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .42), inset 0 0 0 5px rgba(255, 255, 255, .08);
  font: 800 48px/1 'PingFang SC', 'Microsoft YaHei', sans-serif;
  letter-spacing: 2px;
  opacity: .78;
  pointer-events: auto;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform 70ms ease, background 70ms ease, border-color 70ms ease;
}

.touch-control[data-active="true"] {
  transform: scale(.9);
  border-color: #ffd600;
  background: rgba(118, 85, 0, .88);
}

.touch-jump {
  width: 168px;
  height: 168px;
  font-size: 42px;
}

.touch-fire {
  width: 184px;
  height: 184px;
  border-color: rgba(255, 174, 156, .72);
  background: rgba(92, 24, 16, .62);
  font-size: 44px;
}

.touch-pause {
  position: absolute;
  top: max(20px, env(safe-area-inset-top));
  right: max(24px, env(safe-area-inset-right));
  width: 156px;
  height: 156px;
  font-size: 50px;
}

#touchPauseBtn[hidden] { display: none; }

.touch-aim-hint {
  position: absolute;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  border-radius: 999px;
  background: rgba(4, 12, 8, .66);
  color: rgba(255, 255, 255, .72);
  font-size: 30px;
  padding: 11px 18px;
  white-space: nowrap;
  pointer-events: none;
}

#orientationHint {
  position: absolute;
  z-index: 7;
  left: 50%;
  top: 18px;
  transform: translateX(-50%);
  border: 2px solid rgba(255, 214, 0, .58);
  border-radius: 999px;
  background: rgba(30, 24, 4, .94);
  color: #fff0a6;
  box-shadow: 0 6px 22px rgba(0, 0, 0, .42);
  font-size: 40px;
  font-weight: 700;
  padding: 14px 24px;
  white-space: nowrap;
  pointer-events: none;
}

#orientationHint[hidden] { display: none; }

#panel {
  background: rgba(14, 30, 22, .94);
  border: 1px solid rgba(255, 255, 255, .14);
  border-radius: 16px;
  padding: 28px 36px;
  text-align: center;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .6);
  max-width: 640px;
}

#title {
  font-size: 30px;
  font-weight: 700;
  color: #ffe082;
  margin-bottom: 10px;
}

#sub {
  font-size: 13px;
  color: #bcd4c6;
  margin-bottom: 20px;
  line-height: 1.8;
}

#sub b { color: #ffd600; }

#leaderboardStatus {
  min-height: 22px;
  margin: -10px 0 16px;
  color: #ffe082;
  font-size: 12px;
  line-height: 1.6;
}

#leaderboardStatus.pending { color: #bcd4c6; }
#leaderboardStatus.success { color: #8fe3a0; }
#leaderboardStatus.error { color: #ffb4ab; }

#menuRow { display: flex; gap: 12px; justify-content: center; }

#startBtn {
  font-size: 16px;
  padding: 10px 36px;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  background: linear-gradient(90deg, #ffd600, #ff9100);
  color: #222;
  font-weight: 700;
  box-shadow: 0 4px 16px rgba(255, 180, 0, .4);
  transition: transform .15s;
}

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

#startBtn:disabled {
  background: rgba(255, 255, 255, .2);
  color: #9ab;
  box-shadow: none;
  cursor: not-allowed;
  transform: none;
}

.ghost {
  font-size: 15px;
  padding: 10px 22px;
  border: 1px solid rgba(255, 255, 255, .3);
  border-radius: 999px;
  cursor: pointer;
  background: rgba(255, 255, 255, .08);
  color: #fff;
  font-weight: 600;
  transition: background .15s, transform .15s;
}

.ghost:hover { background: rgba(255, 255, 255, .18); transform: scale(1.04); }

#lobby {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}

#lobby .row, #roomTools .row { display: flex; gap: 8px; align-items: center; justify-content: center; }

#lobby input {
  background: rgba(255, 255, 255, .12);
  border: 1px solid rgba(255, 255, 255, .3);
  border-radius: 8px;
  color: #fff;
  padding: 8px 12px;
  font-size: 14px;
  text-align: center;
  outline: none;
  width: 120px;
}

#lobby input:focus { border-color: #ffd600; }

#codeInput { width: 128px !important; letter-spacing: 3px; }

.identity-hint {
  color: #bcd4c6;
  font-size: 12px;
}

#netStatus {
  font-size: 13px;
  color: #8fe3a0;
  min-height: 18px;
  line-height: 1.5;
}

#netStatus.err { color: #ff8a80; }

#roomTools {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: min(480px, 78vw);
}

.room-heading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

#roomCodeLabel {
  color: #ffe082;
  font-size: 18px;
  letter-spacing: 3px;
}

#roomRole {
  border: 1px solid rgba(255, 255, 255, .24);
  border-radius: 999px;
  color: #bcd4c6;
  font-size: 11px;
  padding: 3px 8px;
}

.room-players {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 7px;
}

.room-player {
  border-radius: 999px;
  background: rgba(255, 255, 255, .09);
  color: #dcebe2;
  font-size: 12px;
  padding: 5px 10px;
}

.room-player::before { content: '●'; color: #72dc8a; margin-right: 5px; }
.room-player.offline::before { color: #ffb74d; }
.room-player.offline { color: #aebbb3; }

.invite-field {
  display: grid;
  gap: 5px;
  color: #9eb5a7;
  font-size: 11px;
  text-align: left;
}

#inviteInput {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, .24);
  border-radius: 8px;
  background: rgba(255, 255, 255, .08);
  color: #fff;
  font-size: 12px;
  padding: 8px 10px;
}

#roomStatus {
  min-height: 18px;
  color: #8fe3a0;
  font-size: 12px;
}

#connectionBanner {
  position: absolute;
  left: 50%;
  bottom: 18px;
  z-index: 4;
  display: none;
  transform: translateX(-50%);
  border: 1px solid rgba(255, 183, 77, .5);
  border-radius: 999px;
  background: rgba(36, 27, 8, .94);
  color: #ffe0a3;
  font-size: 13px;
  padding: 8px 16px;
  box-shadow: 0 5px 20px rgba(0, 0, 0, .45);
  pointer-events: none;
}

#connectionBanner.show { display: block; }

.link {
  background: none;
  border: none;
  color: #8aa0b5;
  font-size: 12px;
  cursor: pointer;
  text-decoration: underline;
}

.link:hover { color: #c0d2e2; }
