* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; width: 100%; height: 100%;
  overflow: hidden; background: #0b1020;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: #eef1ff; touch-action: none;
  overscroll-behavior: none;
}
#game { display: block; width: 100vw; height: 100dvh; touch-action: none; }

#versionTag {
  position: fixed; bottom: max(6px, env(safe-area-inset-bottom)); right: max(8px, env(safe-area-inset-right));
  font-size: 10px; color: rgba(255,255,255,0.28); z-index: 5; pointer-events: none;
}

#flashOverlay {
  position: fixed; inset: 0; background: #fff; opacity: 0; z-index: 40; pointer-events: none;
  transition: opacity 0.08s ease-out;
}
#flashOverlay.hit { opacity: 0.92; transition: opacity 0.03s ease-in; }

#inkOverlay {
  position: fixed; inset: 0; background: radial-gradient(circle at 50% 50%, rgba(0,0,0,0.35) 0%, rgba(0,0,0,0.88) 78%);
  opacity: 0; z-index: 12; pointer-events: none; transition: opacity 0.4s ease;
}
#inkOverlay.show { opacity: 1; }

#hud {
  position: fixed; top: max(10px, env(safe-area-inset-top)); right: max(10px, env(safe-area-inset-right));
  display: flex; flex-direction: column; align-items: flex-end; gap: 8px;
  pointer-events: none; z-index: 5;
}
#leaderboard {
  background: rgba(10, 14, 30, 0.72); backdrop-filter: blur(6px);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 10px; padding: 10px 14px; min-width: 160px;
}
.lb-title { font-size: 12px; letter-spacing: .04em; opacity: .65; text-transform: uppercase; margin-bottom: 6px; }
#lb-list { margin: 0; padding: 0; list-style: none; font-size: 13px; line-height: 1.55; }
#lb-list li { display: flex; justify-content: space-between; gap: 10px; }
#lb-list li span.n { opacity: .55; margin-right: 6px; }
#playerCount {
  background: rgba(10, 14, 30, 0.72); border: 1px solid rgba(255,255,255,0.08);
  border-radius: 8px; padding: 4px 10px; font-size: 12px; opacity: .8;
}
#roundTimer {
  background: rgba(10, 14, 30, 0.72); border: 1px solid rgba(255,255,255,0.08);
  border-radius: 8px; padding: 4px 10px; font-size: 12px; opacity: .8;
  font-variant-numeric: tabular-nums;
}
#roundTimer.low { color: #ff8080; border-color: rgba(255,93,93,0.4); }

.overlay {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 30%, #171f3d 0%, #0b1020 70%);
  z-index: 20; overflow-y: auto; padding: 20px 0;
}
.overlay.hidden { display: none; }
.panel { text-align: center; padding: 24px; width: min(90vw, 360px); margin: auto; }
.panel h1 {
  font-size: 42px; margin: 0 0 6px; letter-spacing: .02em;
  background: linear-gradient(90deg, #7ee787, #4cc9f0);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
#authModal .panel h1 { font-size: 28px; }
.tagline { opacity: .75; margin: 0 0 20px; font-size: 14px; }
.tagline.error { color: #ff8080; opacity: 1; margin: 0 0 12px; font-size: 13px; }
#nameInput, #nameInput2, #authUser, #authPass {
  width: 100%; font-size: 16px; padding: 12px 14px; border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.15); background: rgba(255,255,255,0.06);
  color: #fff; outline: none; margin-bottom: 12px; text-align: center;
}
#nameInput:focus, #nameInput2:focus, #authUser:focus, #authPass:focus { border-color: #4cc9f0; }
#playBtn, #respawnBtn, #authSubmit {
  width: 100%; font-size: 17px; font-weight: 600; padding: 13px 14px; border-radius: 10px;
  border: none; cursor: pointer; color: #06121a;
  background: linear-gradient(90deg, #7ee787, #4cc9f0);
}
#playBtn:active, #respawnBtn:active, #authSubmit:active { filter: brightness(.92); }
.hint { font-size: 12px; opacity: .5; margin: 14px 0 0; }
.mobile-hint { display: none; }
#deathScore { color: #ffe74c; }

/* ---------- Color picker ---------- */
.color-picker {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 8px;
  margin-bottom: 14px;
}
.swatch {
  width: 30px; height: 30px; border-radius: 50%; cursor: pointer;
  border: 2px solid rgba(255,255,255,0.15); box-shadow: inset 0 0 0 2px rgba(0,0,0,0.15);
  flex: 0 0 auto; transition: transform .1s ease;
}
.swatch:active { transform: scale(.92); }
.swatch.selected { border-color: #fff; box-shadow: 0 0 0 2px #fff, 0 0 8px rgba(255,255,255,0.6); }

/* ---------- Auth / handedness top-left bar ---------- */
#topLeftBar {
  position: fixed; top: max(10px, env(safe-area-inset-top)); left: max(10px, env(safe-area-inset-left));
  z-index: 25; display: flex; align-items: center; gap: 8px;
}
#authBar {
  background: rgba(10, 14, 30, 0.72); border: 1px solid rgba(255,255,255,0.08);
  border-radius: 8px; padding: 4px 10px; font-size: 12px; display: flex; align-items: center; gap: 6px;
}
.link-btn {
  background: none; border: none; color: #4cc9f0; font-size: 12px; cursor: pointer;
  padding: 2px 0; font-family: inherit; text-decoration: underline;
}
#authStatus { display: flex; align-items: center; gap: 6px; color: #eef1ff; }
#authStatus.hidden { display: none; }
#handednessBtn {
  width: 30px; height: 30px; border-radius: 50%; flex: 0 0 auto;
  background: rgba(10, 14, 30, 0.72); border: 1px solid rgba(255,255,255,0.15);
  color: #eef1ff; font-size: 15px; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
#handednessBtn:active { filter: brightness(1.3); }

/* ---------- Buff HUD ---------- */
#buffHud {
  position: fixed; top: max(48px, calc(env(safe-area-inset-top) + 38px)); left: max(10px, env(safe-area-inset-left));
  z-index: 21; display: flex; flex-direction: column; gap: 6px; pointer-events: none;
}
.buff-pill {
  background: rgba(10, 14, 30, 0.78); border: 1px solid rgba(255,255,255,0.12);
  border-radius: 999px; padding: 4px 10px; font-size: 12px; font-weight: 600;
  display: flex; align-items: center; gap: 5px; color: #eef1ff;
  box-shadow: 0 0 8px rgba(255,255,255,0.08);
}

/* ---------- Unlock toast ---------- */
#unlockToast {
  position: fixed; top: max(10px, env(safe-area-inset-top)); left: 50%;
  transform: translate(-50%, -140%);
  background: rgba(10, 14, 30, 0.92); border: 1px solid rgba(255,231,76,0.5);
  border-radius: 12px; padding: 10px 16px; font-size: 13px; font-weight: 600;
  display: flex; align-items: center; gap: 8px; z-index: 30;
  transition: transform .35s ease, opacity .35s ease; opacity: 0; pointer-events: none;
  box-shadow: 0 4px 18px rgba(0,0,0,0.4);
}
#unlockToast.show { transform: translate(-50%, 0); opacity: 1; }
#unlockToast.hidden { display: none; }
#unlockSwatch {
  width: 16px; height: 16px; border-radius: 50%; display: inline-block;
  border: 1px solid rgba(255,255,255,0.4);
}

/* ---------- Round toast ---------- */
#roundToast {
  position: fixed; top: max(10px, env(safe-area-inset-top)); left: 50%;
  transform: translate(-50%, -140%);
  background: rgba(10, 14, 30, 0.92); border: 1px solid rgba(76,201,240,0.5);
  border-radius: 12px; padding: 10px 16px; font-size: 13px; font-weight: 600;
  display: flex; align-items: center; gap: 8px; z-index: 30;
  transition: transform .35s ease, opacity .35s ease; opacity: 0; pointer-events: none;
  box-shadow: 0 4px 18px rgba(0,0,0,0.4); text-align: center;
}
#roundToast.show { transform: translate(-50%, 0); opacity: 1; }
#roundToast.hidden { display: none; }

#touchControls.hidden { display: none; }
#joyBase {
  position: fixed; left: max(26px, env(safe-area-inset-left)); bottom: max(28px, env(safe-area-inset-bottom));
  width: 120px; height: 120px; border-radius: 50%;
  background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.15);
  z-index: 15; touch-action: none;
}
#joyStick {
  position: absolute; left: 50%; top: 50%; width: 54px; height: 54px; margin: -27px 0 0 -27px;
  border-radius: 50%; background: rgba(255,255,255,0.28); border: 1px solid rgba(255,255,255,0.4);
}
#boostBtn {
  position: fixed; right: max(30px, env(safe-area-inset-right)); bottom: max(34px, env(safe-area-inset-bottom));
  width: 84px; height: 84px; border-radius: 50%;
  background: rgba(255,93,93,0.22); border: 2px solid rgba(255,93,93,0.55);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; letter-spacing: .04em; color: #ffb4b4;
  z-index: 15; touch-action: none; user-select: none;
}
#boostBtn.active { background: rgba(255,93,93,0.45); }

/* left-handed mode: mirror joystick and boost button */
body.left-handed #joyBase { left: auto; right: max(26px, env(safe-area-inset-right)); }
body.left-handed #boostBtn { right: auto; left: max(30px, env(safe-area-inset-left)); }

@media (pointer: coarse) {
  .desktop-hint { display: none; }
  .mobile-hint { display: block; }
}
