/* ============================== base ============================== */
:root {
  --bg0: #0b0e1a;
  --bg1: #12172b;
  --panel: rgba(255, 255, 255, 0.045);
  --panel-border: rgba(255, 255, 255, 0.09);
  --text: #e8ecf6;
  --muted: #8b93ad;
  --accent: #ffae2b;
  --accent2: #ff6b3d;
  --danger: #ff4d5e;
  --radius: 16px;
  --p1: #ff4d5e; --p2: #3da5ff; --p3: #46d168; --p4: #ffc532;
}

* { box-sizing: border-box; }

html { height: 100%; }
html, body {
  margin: 0;
  min-height: 100%;
  background-attachment: fixed;
  overscroll-behavior: none;
  background:
    radial-gradient(1100px 600px at 70% -10%, #1d2547 0%, transparent 60%),
    radial-gradient(900px 500px at 10% 110%, #251a3a 0%, transparent 55%),
    linear-gradient(180deg, var(--bg0), var(--bg1));
  color: var(--text);
  font-family: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.bg-grid {
  position: fixed; inset: 0; pointer-events: none; opacity: .35;
  background-image:
    linear-gradient(rgba(255,255,255,.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.025) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(ellipse 80% 70% at 50% 40%, black 30%, transparent 100%);
}

#app {
  position: relative;
  max-width: 1080px;
  margin: 0 auto;
  padding: 28px 20px 60px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.view { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 22px; }
.hidden { display: none !important; }

/* ============================== shared UI ============================== */
.card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 22px;
  backdrop-filter: blur(14px);
  box-shadow: 0 20px 50px rgba(0, 0, 0, .35);
}

.btn {
  appearance: none; border: 0; cursor: pointer;
  font: inherit; font-weight: 700; letter-spacing: .2px;
  color: var(--text);
  padding: 12px 18px; border-radius: 12px;
  background: rgba(255,255,255,.07);
  border: 1px solid rgba(255,255,255,.1);
  transition: transform .08s ease, background .15s ease, box-shadow .15s ease;
}
.btn:hover { background: rgba(255,255,255,.12); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: .45; cursor: default; transform: none; }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #1d1304;
  border: 0;
  box-shadow: 0 8px 24px rgba(255, 140, 40, .35);
}
.btn-primary:hover { background: linear-gradient(135deg, #ffbe50, #ff7d52); box-shadow: 0 10px 28px rgba(255,140,40,.45); }
.btn-danger { background: rgba(255, 77, 94, .15); border-color: rgba(255, 77, 94, .4); color: #ff8c98; }
.btn-danger:hover { background: rgba(255, 77, 94, .28); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: rgba(255,255,255,.07); color: var(--text); }
.btn-big { width: 100%; padding: 15px 18px; font-size: 17px; }
.btn-small { padding: 8px 13px; font-size: 13.5px; }

input {
  font: inherit; color: var(--text);
  background: rgba(0,0,0,.3);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 11px;
  padding: 11px 13px;
  outline: none;
  transition: border-color .15s;
}
input:focus { border-color: var(--accent); }
input::placeholder { color: #5b6280; }

kbd {
  background: rgba(255,255,255,.09);
  border: 1px solid rgba(255,255,255,.16);
  border-bottom-width: 2px;
  border-radius: 6px;
  padding: 1px 7px;
  font-family: inherit;
  font-size: .86em;
}

.hint { color: var(--muted); font-size: 13.5px; text-align: center; }
.note { color: var(--muted); font-size: 13px; margin: 8px 0 0; min-height: 1em; }

/* ============================== home ============================== */
.logo { text-align: center; margin-top: 26px; }
.logo-bomb { font-size: 56px; filter: drop-shadow(0 8px 24px rgba(255,170,40,.4)); animation: bob 2.6s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-7px) rotate(-6deg); } }
.logo h1 {
  margin: 6px 0 4px; font-size: 46px; letter-spacing: 3px; font-weight: 900;
  background: linear-gradient(135deg, #fff, #ffae2b 55%, #ff6b3d);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.logo h1 span { font-weight: 300; }
.tagline { color: var(--muted); margin: 0; }

.home-card { width: min(430px, 100%); display: flex; flex-direction: column; gap: 13px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13.5px; color: var(--muted); }
.field input { width: 100%; }
.join-row { display: flex; gap: 9px; }
.join-row input { flex: 1; }

/* ============================== queue ============================== */
.queue-card { width: min(430px, 100%); text-align: center; display: flex; flex-direction: column; gap: 14px; align-items: center; padding: 38px 26px; }
.queue-card h2 { margin: 0; }
.queue-card p { margin: 0; color: var(--muted); }
.spinner {
  width: 46px; height: 46px; border-radius: 50%;
  border: 4px solid rgba(255,255,255,.12);
  border-top-color: var(--accent);
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================== lobby ============================== */
.lobby-grid {
  display: grid; gap: 18px; width: 100%;
  grid-template-columns: 1.4fr 1fr;
  align-items: start;
}
@media (max-width: 840px) { .lobby-grid { grid-template-columns: 1fr; } }

.lobby-head { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.lobby-head h2 { margin: 0; font-size: 24px; }
.invite-row { display: flex; gap: 8px; }
.invite-row input { flex: 1; font-size: 13px; color: var(--muted); }

.slots { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 520px) { .slots { grid-template-columns: 1fr; } }
.slot {
  display: flex; align-items: center; gap: 11px;
  padding: 13px 14px;
  border-radius: 12px;
  background: rgba(0,0,0,.25);
  border: 1px solid rgba(255,255,255,.07);
  min-height: 58px;
}
.slot.empty { border-style: dashed; color: #555d78; justify-content: center; font-size: 13.5px; }
.slot .dot { width: 15px; height: 15px; border-radius: 50%; flex: none; box-shadow: 0 0 12px currentColor; }
.slot .who { display: flex; flex-direction: column; min-width: 0; }
.slot .who b { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.slot .who small { color: var(--muted); font-size: 11.5px; }
.slot .tag { margin-left: auto; font-size: 10.5px; font-weight: 800; letter-spacing: .8px; color: var(--accent); border: 1px solid rgba(255,174,43,.4); padding: 2px 7px; border-radius: 99px; }
.name-edit {
  cursor: text;
  border-bottom: 1px dashed rgba(255,255,255,.3);
  transition: color .15s, border-color .15s;
}
.name-edit:hover { color: var(--accent); border-bottom-color: var(--accent); }
.name-input-inline {
  font: inherit; font-weight: 700; color: var(--text);
  background: rgba(0,0,0,.4);
  border: 1px solid var(--accent);
  border-radius: 7px;
  padding: 1px 7px;
  width: 130px;
  outline: none;
}

.spectators { grid-column: 1 / -1; color: var(--muted); font-size: 13px; padding: 4px 2px; }

.lobby-actions { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.lobby-actions .btn-primary { flex: 1; min-width: 160px; }

.lobby-side { display: flex; flex-direction: column; gap: 10px; }
.lobby-side h3 { margin: 4px 0 2px; font-size: 14px; text-transform: uppercase; letter-spacing: 1.2px; color: var(--muted); }

.settings { display: flex; flex-direction: column; gap: 7px; }
.setting { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 14px; }
.setting label { color: var(--text); }
.setting select {
  font: inherit; font-size: 13.5px; color: var(--text);
  background: rgba(0,0,0,.35); border: 1px solid rgba(255,255,255,.13);
  border-radius: 9px; padding: 6px 9px; outline: none;
}
.setting select:disabled { opacity: .6; }

.scoreboard {
  display: flex; flex-direction: column; gap: 3px;
  background: rgba(0,0,0,.25);
  border: 1px solid rgba(255,255,255,.06);
  border-radius: 10px; padding: 8px 11px;
  font-size: 13.5px;
}
.scoreboard .row { display: flex; align-items: baseline; gap: 8px; }
.scoreboard .row .rank { color: var(--muted); font-size: 12px; width: 16px; }
.scoreboard .row .sname { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.scoreboard .row .sname.gone { color: var(--muted); font-style: italic; }
.scoreboard .row .tally { font-variant-numeric: tabular-nums; color: var(--muted); }
.scoreboard .row .tally b { color: var(--accent); font-weight: 800; }

.chat-log {
  height: 150px; overflow-y: auto;
  background: rgba(0,0,0,.25);
  border: 1px solid rgba(255,255,255,.06);
  border-radius: 10px; padding: 9px 11px;
  font-size: 13.5px; display: flex; flex-direction: column; gap: 4px;
}
.chat-log .msg b { color: var(--accent); font-weight: 700; }
.chat-log .sys { color: var(--muted); font-style: italic; }
.chat-form { display: flex; gap: 8px; }
.chat-form input { flex: 1; padding: 8px 11px; }
.leave-btn { align-self: flex-end; margin-top: 6px; }

/* ============================== game ============================== */
#view-game { gap: 12px; touch-action: none; }

/* while a game is on screen: no page scrolling, no rubber-banding */
body.playing { overflow: hidden; height: 100dvh; }
body.playing #app { padding-top: 10px; padding-bottom: 8px; }

.hud {
  display: flex; gap: 10px; align-items: stretch; justify-content: center;
  flex-wrap: wrap; width: 100%;
}
.hud-player {
  display: flex; align-items: center; gap: 9px;
  background: var(--panel); border: 1px solid var(--panel-border);
  border-radius: 12px; padding: 7px 12px;
  min-width: 150px;
  transition: opacity .3s;
}
.hud-player.dead { opacity: .38; filter: saturate(.3); }
.hud-player .dot { width: 13px; height: 13px; border-radius: 50%; box-shadow: 0 0 10px currentColor; flex: none; }
.hud-player .info { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.hud-player .info b { font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 110px; }
.hud-player .stats { font-size: 11px; color: var(--muted); letter-spacing: .4px; }
.hud-player .wins { margin-left: auto; color: var(--accent); font-size: 13px; letter-spacing: 1px; }

.hud-timer {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--panel); border: 1px solid var(--panel-border);
  border-radius: 12px; padding: 7px 16px; min-width: 86px;
}
.hud-timer b { font-size: 19px; font-variant-numeric: tabular-nums; }
.hud-timer.warn b { color: var(--danger); animation: pulse .8s infinite; }
.hud-timer small { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 1.4px; }
@keyframes pulse { 50% { opacity: .5; } }

.canvas-wrap { position: relative; width: 100%; display: flex; justify-content: center; }
#game-canvas {
  width: min(100%, 1000px);
  aspect-ratio: 17 / 11;
  border-radius: 14px;
  box-shadow: 0 30px 70px rgba(0,0,0,.5), 0 0 0 1px rgba(255,255,255,.08);
  background: #16223a;
}

.overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  background: rgba(8, 10, 22, .55);
  backdrop-filter: blur(3px);
  border-radius: 14px;
  text-align: center;
  pointer-events: none;
}
.overlay .big {
  font-size: clamp(36px, 8vw, 76px); font-weight: 900; letter-spacing: 2px;
  text-shadow: 0 10px 40px rgba(0,0,0,.6);
  animation: popIn .35s cubic-bezier(.2, 1.6, .4, 1);
}
.overlay .sub { font-size: clamp(15px, 3vw, 21px); color: #cdd5ea; }
@keyframes popIn { from { transform: scale(.4); opacity: 0; } }

.game-footer { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.hint-inline { margin-right: 8px; }

/* ============================== touch controls ============================== */
#touch-controls { position: fixed; inset: 0; pointer-events: none; z-index: 40; }

#joystick {
  position: absolute; left: max(14px, env(safe-area-inset-left)); bottom: max(14px, env(safe-area-inset-bottom));
  width: 128px; height: 128px; border-radius: 50%;
  background: rgba(255,255,255,.07);
  border: 1.5px solid rgba(255,255,255,.22);
  backdrop-filter: blur(3px);
  pointer-events: auto; touch-action: none;
  -webkit-user-select: none; user-select: none;
}
#joy-knob {
  position: absolute; left: 50%; top: 50%;
  width: 56px; height: 56px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, rgba(255,255,255,.45), rgba(255,255,255,.18));
  border: 1.5px solid rgba(255,255,255,.4);
  box-shadow: 0 4px 14px rgba(0,0,0,.3);
  transform: translate(-50%, -50%);
  pointer-events: none;
}
#joystick.active { background: rgba(255,255,255,.12); }

#btn-bomb-touch {
  position: absolute; right: max(18px, env(safe-area-inset-right)); bottom: max(22px, env(safe-area-inset-bottom));
  width: 88px; height: 88px; border-radius: 50%;
  font-size: 36px; line-height: 1;
  background: rgba(255,140,40,.2);
  border: 2px solid rgba(255,174,43,.5);
  backdrop-filter: blur(3px);
  pointer-events: auto; touch-action: none;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
}
#btn-bomb-touch:active { background: rgba(255,140,40,.42); transform: scale(.94); }

/* fit the arena to the viewport height (address bars, short screens) */
#game-canvas { width: min(100%, 1000px, calc((100dvh - 150px) * 17 / 11)); }
@media (max-height: 540px) {
  #app { padding: 6px 8px; }
  #view-game { gap: 4px; }
  /* HUD chips float in the corners, mirroring the spawn points, freeing
     vertical space for the arena */
  .hud { position: fixed; inset: 0; pointer-events: none; z-index: 30; }
  .hud-player, .hud-timer { position: absolute; }
  .hud-player { min-width: 0; padding: 4px 9px; gap: 7px; background: rgba(11, 14, 26, .62); }
  .hud-player .info b { max-width: 92px; font-size: 12.5px; }
  .hud-player.pos-0 { left: max(8px, env(safe-area-inset-left)); top: 8px; }
  .hud-player.pos-2 { right: max(8px, env(safe-area-inset-right)); top: 8px; }
  .hud-player.pos-3 { left: max(8px, env(safe-area-inset-left)); bottom: 8px; }
  .hud-player.pos-1 { right: max(8px, env(safe-area-inset-right)); bottom: 8px; }
  /* on touch screens the bottom chips sit above the joystick / bomb button */
  body.touch .hud-player.pos-3 { bottom: 152px; }
  body.touch .hud-player.pos-1 { bottom: 122px; }
  .hud-timer { top: 8px; left: 50%; transform: translateX(-50%); padding: 4px 10px; min-width: 64px; }
  .hud-timer b { font-size: 15px; }
  .game-footer { position: fixed; bottom: 4px; left: 50%; transform: translateX(-50%); z-index: 31; }
  .game-footer .hint-inline { display: none; }
  #game-canvas { width: min(100%, calc((100dvh - 16px) * 17 / 11)); border-radius: 8px; }
}

/* ============================== toast ============================== */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  background: #20263e; border: 1px solid rgba(255,255,255,.14);
  color: var(--text); font-size: 14px; font-weight: 600;
  padding: 11px 18px; border-radius: 12px;
  box-shadow: 0 14px 40px rgba(0,0,0,.45);
  z-index: 50;
  animation: toastIn .25s ease;
}
@keyframes toastIn { from { transform: translate(-50%, 12px); opacity: 0; } }
