* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #1a0d0d;
  overscroll-behavior: none;
  touch-action: none;
}

#game-root {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  position: absolute;
  inset: 0;
}

/* ----- Mute toggle ----- */
#btn-mute {
  position: absolute;
  top: calc(12px + env(safe-area-inset-top));
  right: calc(12px + env(safe-area-inset-right));
  z-index: 10;
  width: 44px;
  height: 44px;
  font-size: 22px;
  line-height: 1;
  color: #fff;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
#btn-mute:active { transform: scale(0.92); }
#btn-mute.muted { opacity: 0.55; }

/* ----- Live multiplayer status (during a run) ----- */
#mp-status {
  position: absolute;
  /* Top-right, pushed down below the canvas-drawn level name so they don't
     collide; clear of the score/best readout on the top-left. */
  top: calc(108px + env(safe-area-inset-top));
  right: calc(12px + env(safe-area-inset-right));
  z-index: 9;
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-end;
  pointer-events: none;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
#mp-status .mp-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.12);
  white-space: nowrap;
}
#mp-status .mp-row.you { border-color: rgba(255, 200, 120, 0.7); }
#mp-status .mp-row.dead { opacity: 0.5; }
#mp-status .mp-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #3ce06a;                 /* alive = green */
  box-shadow: 0 0 6px rgba(60, 224, 106, 0.8);
}
#mp-status .mp-row.dead .mp-dot {
  background: #ff5a18;                  /* burned = ember */
  box-shadow: none;
}
#mp-status .mp-name { max-width: 96px; overflow: hidden; text-overflow: ellipsis; }
#mp-status .mp-score { opacity: 0.7; font-variant-numeric: tabular-nums; }

/* ----- Overlay UI ----- */
#ui {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: #fff;
  pointer-events: none; /* screens re-enable for themselves */
}

.screen {
  pointer-events: auto;
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 32px;
  padding-top: calc(32px + env(safe-area-inset-top));
  padding-bottom: calc(32px + env(safe-area-inset-bottom));
  text-align: center;
  background: rgba(10, 6, 8, 0.55);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

.screen.overlay {
  background: transparent;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  pointer-events: none;
}

.hidden { display: none !important; }

.title {
  font-size: clamp(48px, 16vw, 96px);
  font-weight: 800;
  letter-spacing: 2px;
  line-height: 0.9;
  text-shadow: 0 0 28px rgba(255, 90, 20, 0.7);
}
.title span { display: block; color: #ff7a18; }

h2 {
  font-size: clamp(28px, 8vw, 44px);
  font-weight: 800;
  letter-spacing: 1px;
}
.burned { color: #ff5a18; text-shadow: 0 0 24px rgba(255,80,0,0.8); }

.tagline { font-size: 17px; opacity: 0.85; max-width: 320px; line-height: 1.4; }
.hint { font-size: 13px; opacity: 0.55; margin-top: 4px; }
.best { font-size: 15px; opacity: 0.7; }
.err { color: #ff7a6a; font-size: 14px; min-height: 18px; }

.code { color: #ffd27a; letter-spacing: 4px; }

.btn {
  pointer-events: auto;
  min-width: 240px;
  padding: 16px 24px;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 1px;
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-radius: 16px;
  cursor: pointer;
  transition: transform 0.06s ease, background 0.15s ease;
}
.btn:active { transform: scale(0.96); }
.btn-primary {
  background: linear-gradient(180deg, #ff8a2a, #ff4d00);
  border-color: rgba(255, 200, 120, 0.6);
  box-shadow: 0 6px 24px rgba(255, 80, 0, 0.4);
}
.btn-ghost {
  min-width: 0;
  background: none;
  border: none;
  opacity: 0.7;
  font-size: 15px;
  padding: 8px;
}

.field {
  width: 240px;
  padding: 14px 18px;
  font-size: 18px;
  text-align: center;
  color: #fff;
  background: rgba(0, 0, 0, 0.35);
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-radius: 14px;
  outline: none;
}
.field::placeholder { color: rgba(255,255,255,0.4); }
.field:focus { border-color: #ff7a18; }

.row { display: flex; gap: 10px; align-items: center; }
.field-code {
  width: 130px;
  letter-spacing: 6px;
  text-transform: uppercase;
  font-weight: 700;
}
.btn-join { min-width: 0; padding: 14px 22px; }

.players {
  list-style: none;
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.players li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  font-size: 17px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 12px;
}
.players li.dead { opacity: 0.45; }
.players li.you { border: 1px solid rgba(255, 200, 120, 0.6); }
.players li .tag { font-size: 12px; opacity: 0.7; }
.players li.winner {
  background: linear-gradient(180deg, rgba(255,180,60,0.3), rgba(255,80,0,0.2));
  border: 1px solid rgba(255, 200, 120, 0.8);
}

.result { font-size: 40px; font-weight: 800; }
.result-sub { font-size: 18px; opacity: 0.8; }

.count-num {
  font-size: clamp(120px, 40vw, 260px);
  font-weight: 900;
  color: #ffd27a;
  text-shadow: 0 0 50px rgba(255, 120, 0, 0.9);
  animation: pop 1s ease-out infinite;
}
.count-level {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 2px;
  opacity: 0.85;
}
@keyframes pop {
  0% { transform: scale(0.5); opacity: 0; }
  30% { transform: scale(1.1); opacity: 1; }
  100% { transform: scale(1); opacity: 0.9; }
}
