:root {
  --bg: #0b1220;
  --bg2: #121c2e;
  --card: rgba(18, 28, 46, 0.92);
  --border: rgba(100, 180, 255, 0.18);
  --text: #e8f1ff;
  --muted: #8aa0b8;
  --accent: #3ddc97;
  --accent2: #4fc3f7;
  --danger: #ff5c7a;
  --warn: #ffb74d;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Menlo, monospace;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.hidden { display: none !important; }

#app { position: relative; width: 100%; height: 100%; }

/* ----- Screens ----- */
.panel-screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse at 30% 20%, rgba(61, 220, 151, 0.08), transparent 50%),
    radial-gradient(ellipse at 70% 80%, rgba(79, 195, 247, 0.08), transparent 50%),
    var(--bg);
  z-index: 20;
  padding: 1rem;
}

.card {
  width: min(400px, 100%);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2rem 1.75rem;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(12px);
}

.logo { text-align: center; margin-bottom: 1.5rem; }
.logo-icon {
  display: inline-flex;
  width: 56px; height: 56px;
  align-items: center; justify-content: center;
  font-size: 1.6rem;
  background: linear-gradient(135deg, rgba(61, 220, 151, 0.2), rgba(79, 195, 247, 0.2));
  border: 1px solid var(--border);
  border-radius: 14px;
  margin-bottom: 0.75rem;
}
.logo h1 {
  font-size: 2.2rem;
  letter-spacing: 0.28em;
  font-weight: 800;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.tagline {
  margin-top: 0.4rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 1rem;
}
.field span {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.field input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 1.1rem;
  padding: 0.75rem 1rem;
  outline: none;
}
.field input:focus {
  border-color: var(--accent2);
  box-shadow: 0 0 0 3px rgba(79, 195, 247, 0.15);
}

.btn {
  width: 100%;
  border: none;
  border-radius: 10px;
  padding: 0.9rem 1rem;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: transform 0.1s, filter 0.15s;
}
.btn:active { transform: scale(0.98); }
.btn.primary {
  background: linear-gradient(135deg, var(--accent), #2bb87a);
  color: #062016;
  margin-bottom: 0.6rem;
}
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.howto {
  list-style: none;
  margin-top: 1.25rem;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.7;
}
.howto kbd {
  display: inline-block;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 0.35rem;
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--accent2);
}
.status-line {
  margin-top: 1rem;
  text-align: center;
  font-size: 0.85rem;
  color: var(--muted);
  min-height: 1.2em;
}

/* Death */
.death-card h2 {
  text-align: center;
  color: var(--danger);
  letter-spacing: 0.2em;
  font-size: 1.8rem;
  margin-bottom: 0.4rem;
}
.death-sub {
  text-align: center;
  color: var(--muted);
  margin-bottom: 1.25rem;
}
.death-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}
.death-stats div {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem;
  text-align: center;
}
.death-stats strong {
  display: block;
  font-size: 1.4rem;
  font-variant-numeric: tabular-nums;
  color: var(--accent2);
}
.death-stats span {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

/* ----- Game ----- */
#game {
  position: absolute;
  inset: 0;
  z-index: 1;
}
#canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: #0a101c;
}

#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
}

#hud-left {
  position: absolute;
  left: 16px;
  top: 16px;
  width: min(260px, 50vw);
}
#hp-bar {
  height: 12px;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  margin-bottom: 6px;
}
#hp-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--danger), var(--accent));
  transition: width 0.1s linear;
}
#boost-bar {
  height: 8px;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(255, 183, 77, 0.35);
  border-radius: 6px;
  overflow: hidden;
  margin-bottom: 8px;
}
#boost-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #ff8a65, #ffb74d);
  transition: width 0.08s linear;
}
#boost-bar.boosting #boost-fill {
  filter: brightness(1.25);
}
#stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.6rem;
  font-family: var(--mono);
  font-size: 0.85rem;
  background: rgba(11, 18, 32, 0.65);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.45rem 0.65rem;
}
#stats .dim { color: var(--muted); font-size: 0.75rem; }

#hud-right {
  position: absolute;
  right: 16px;
  top: 16px;
  width: 180px;
}
#leaderboard {
  background: rgba(11, 18, 32, 0.72);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
  font-size: 0.78rem;
  font-family: var(--mono);
}
#leaderboard .title {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin-bottom: 0.35rem;
}
#leaderboard .row {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.15rem 0;
  white-space: nowrap;
}
#leaderboard .row.me { color: var(--accent); font-weight: 700; }
#leaderboard .row .nm {
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100px;
}
#pop {
  margin-top: 0.5rem;
  text-align: right;
  font-size: 0.72rem;
  color: var(--muted);
  font-family: var(--mono);
}

#kill-feed {
  position: absolute;
  left: 16px;
  top: 90px;
  font-size: 0.78rem;
  font-family: var(--mono);
  color: var(--muted);
  line-height: 1.55;
  max-width: 280px;
}
#kill-feed .k { color: var(--warn); }
#kill-feed .v { color: var(--danger); }

#minimap-wrap {
  position: absolute;
  right: 16px;
  bottom: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: rgba(11, 18, 32, 0.8);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  z-index: 5;
}
#minimap { display: block; }

/* When on-screen controls are visible, park radar above boost/fire */
#game:has(#mobile-controls:not(.hidden)) #minimap-wrap {
  bottom: 200px;
  right: 14px;
  transform: scale(0.9);
  transform-origin: bottom right;
}

/* Mobile */
#mobile-controls {
  position: absolute;
  inset: 0;
  z-index: 6;
  pointer-events: none;
}
.stick {
  pointer-events: auto;
  position: absolute;
  left: 28px;
  bottom: 28px;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  border: 2px solid rgba(255, 255, 255, 0.15);
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}
.stick-knob {
  position: absolute;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: rgba(61, 220, 151, 0.55);
  border: 2px solid rgba(61, 220, 151, 0.9);
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}
#mobile-actions {
  pointer-events: none;
  position: absolute;
  right: 16px;
  bottom: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}
#fire-btn, #boost-btn {
  pointer-events: auto;
  width: 64px;   /* 20% smaller than 80px */
  height: 64px;
  border-radius: 50%;
  color: #fff;
  font-weight: 800;
  font-size: 0.68rem;
  letter-spacing: 0.05em;
  cursor: pointer;
  /* Multi-touch: no double-tap zoom / callout; larger soft hit via padding box */
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
#fire-btn {
  border: 2px solid rgba(255, 92, 122, 0.7);
  background: rgba(255, 92, 122, 0.35);
}
#fire-btn:active {
  background: rgba(255, 92, 122, 0.65);
}
#boost-btn {
  border: 2px solid rgba(255, 183, 77, 0.75);
  background: rgba(255, 183, 77, 0.32);
}
#boost-btn:active {
  background: rgba(255, 183, 77, 0.65);
}

@media (max-width: 700px) {
  #hud-right { width: 140px; }
  #leaderboard { font-size: 0.7rem; }
  #minimap-wrap {
    bottom: 200px;
    right: 12px;
    transform: scale(0.85);
    transform-origin: bottom right;
  }
}
