@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');

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

:root {
  --bg: #0f0e17;
  --surface: #1a1a2e;
  --red: #ff6b6b;
  --teal: #4ecdc4;
  --yellow: #ffe66d;
  --purple: #a855f7;
  --muted: #a7a9be;
  --dark-purple: #2d1b30;
  --dark-teal: #1b3a35;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--muted);
  font-family: 'Press Start 2P', monospace;
  overflow: hidden;
  cursor: crosshair;
}

/* ── Scanlines overlay ── */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0,0,0,0.06) 2px,
    rgba(0,0,0,0.06) 4px
  );
  z-index: 9999;
}

/* ── Layout ── */
.wrapper {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 900px;
  margin: 0 auto;
  padding: 16px;
  gap: 12px;
}

/* ── Header ── */
header {
  text-align: center;
  padding: 18px 12px;
  background: var(--surface);
  border: 2px solid var(--purple);
  border-radius: 8px;
  flex-shrink: 0;
  position: relative;
}
header h1 {
  font-size: 18px;
  color: var(--yellow);
  text-shadow: 0 0 20px rgba(255,230,109,0.4);
  margin-bottom: 6px;
}
header p {
  font-size: 7px;
  color: var(--muted);
  letter-spacing: 1px;
}
.header-encyclopedia-link {
  position: absolute;
  top: 50%;
  right: 12px;
  transform: translateY(-50%);
  font-size: 8px;
  color: var(--teal);
  text-decoration: none;
  padding: 8px 12px;
  border: 2px solid var(--teal);
  border-radius: 4px;
  background: rgba(78, 205, 196, 0.1);
  transition: all 0.2s;
  letter-spacing: 0.5px;
}
.header-encyclopedia-link:hover {
  background: var(--teal);
  color: var(--bg);
  transform: translateY(-50%) scale(1.05);
  box-shadow: 0 0 12px rgba(78,205,196,0.4);
}

/* Wiki link in start screen */
.wiki-link {
  color: var(--teal);
  text-decoration: none;
  border-bottom: 1px solid rgba(78,205,196,0.4);
  padding-bottom: 1px;
  transition: border-color 0.2s;
}
.wiki-link:hover {
  border-bottom-color: var(--teal);
}

/* ── HUD ── */
.hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.hud-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  padding: 8px 14px;
  border-radius: 6px;
  border: 1px solid #2a2a4a;
  font-size: 8px;
}

.hud-label { color: var(--muted); }
.hud-value { color: var(--yellow); }
.hud-value.hp { color: var(--teal); }
.hud-value.bugs { color: var(--red); }

.hp-bar-track {
  width: 80px;
  height: 10px;
  background: var(--bg);
  border: 1px solid #3d3d5c;
  border-radius: 2px;
  overflow: hidden;
}
.hp-bar-fill {
  height: 100%;
  background: var(--teal);
  border-radius: 1px;
  transition: width 0.4s ease, background-color 0.4s ease;
}
.hp-bar-fill.low { background: var(--red); animation: pulse-hp 0.6s infinite; }

@keyframes pulse-hp {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ── Game Arena ── */
.arena-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
}

.arena {
  width: 100%;
  height: 100%;
  background:
    radial-gradient(circle at 20% 80%, rgba(168,85,247,0.05) 0%, transparent 50%),
    radial-gradient(circle at 80% 20%, rgba(78,205,196,0.05) 0%, transparent 50%),
    var(--bg);
  border: 2px solid #2a2a4a;
  border-radius: 8px;
  position: relative;
  overflow: hidden;
}

/* Grid floor */
.arena::before {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 100px;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 18px,
    rgba(167,169,190,0.06) 18px,
    rgba(167,169,190,0.06) 19px
  );
  pointer-events: none;
}

/* ── Bug sprite ── */
.bug {
  position: absolute;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  transition: transform 0.08s;
  z-index: 10;
  animation: bug-spawn 0.3s ease-out;
}
.bug:active { transform: scale(0.7); }

.bug-body {
  position: relative;
  width: 36px;
  height: 28px;
  background: var(--red);
  border-radius: 50%;
  box-shadow: 0 0 12px rgba(255,107,107,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
}

.bug-body::before,
.bug-body::after {
  content: '';
  position: absolute;
  top: -6px;
  width: 4px;
  height: 10px;
  background: var(--red);
  border-radius: 2px;
}
.bug-body::before { left: 8px; transform: rotate(-20deg); }
.bug-body::after { right: 8px; transform: rotate(20deg); }

.bug-eyes {
  font-size: 10px;
  color: var(--bg);
  font-family: monospace;
  font-weight: bold;
  letter-spacing: 4px;
  margin-top: -2px;
}

/* Bug legs */
.bug-legs {
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  pointer-events: none;
}
.bug-legs span {
  position: absolute;
  width: 6px;
  height: 2px;
  background: var(--red);
  border-radius: 1px;
}
.bug-legs span:nth-child(1) { top: 8px; left: -4px; transform: rotate(-30deg); }
.bug-legs span:nth-child(2) { top: 16px; left: -5px; transform: rotate(0deg); }
.bug-legs span:nth-child(3) { top: 24px; left: -4px; transform: rotate(30deg); }
.bug-legs span:nth-child(4) { top: 8px; right: -4px; transform: rotate(30deg); }
.bug-legs span:nth-child(5) { top: 16px; right: -5px; transform: rotate(0deg); }
.bug-legs span:nth-child(6) { top: 24px; right: -4px; transform: rotate(-30deg); }

.bug.walking {
  animation: bug-walk 0.4s steps(2) infinite;
}

@keyframes bug-walk {
  0% { transform: translateY(0); }
  50% { transform: translateY(-2px); }
}

@keyframes bug-spawn {
  0% { transform: scale(0) rotate(180deg); opacity: 0; }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

/* ── Squash effect ── */
.squash {
  position: absolute;
  pointer-events: none;
  z-index: 20;
  animation: squash-anim 0.5s ease-out forwards;
}
.squash-text {
  font-family: 'Press Start 2P', monospace;
  font-size: 11px;
  color: var(--yellow);
  text-shadow: 0 0 8px rgba(255,230,109,0.6);
  white-space: nowrap;
}

@keyframes squash-anim {
  0% { transform: translateY(0) scale(1); opacity: 1; }
  100% { transform: translateY(-50px) scale(1.3); opacity: 0; }
}

/* ── Screens (start / game over / win) ── */
.screen-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(15,14,23,0.92);
  z-index: 100;
  gap: 20px;
  border-radius: 8px;
  text-align: center;
  padding: 20px;
}
.screen-overlay.hidden { display: none; }

.screen-title {
  font-size: 20px;
  color: var(--yellow);
  text-shadow: 0 0 24px rgba(255,230,109,0.5);
  line-height: 1.6;
}
.screen-title.fail { color: var(--red); text-shadow: 0 0 24px rgba(255,107,107,0.5); }
.screen-title.win { color: var(--teal); text-shadow: 0 0 24px rgba(78,205,196,0.5); }

.screen-sub {
  font-size: 7px;
  color: var(--muted);
  line-height: 2;
  max-width: 500px;
}

.screen-stats {
  display: flex;
  gap: 24px;
  font-size: 8px;
}
.screen-stats span { color: var(--yellow); }

.btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  padding: 14px 28px;
  border: 2px solid var(--purple);
  background: var(--dark-purple);
  color: var(--purple);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
  letter-spacing: 1px;
}
.btn:hover {
  background: var(--purple);
  color: var(--bg);
  box-shadow: 0 0 20px rgba(168,85,247,0.4);
}

/* ── Message bar ── */
.message-bar {
  flex-shrink: 0;
  text-align: center;
  padding: 10px;
  font-size: 6px;
  color: var(--muted);
  opacity: 0.5;
  line-height: 1.8;
}
.message-bar em {
  color: var(--purple);
  font-style: normal;
}

/* ── Floating decorative pixels ── */
.deco-pixel {
  position: fixed;
  width: 4px;
  height: 4px;
  opacity: 0.15;
  pointer-events: none;
  z-index: 0;
}

/* ── Remote player cursor ── */
.remote-cursor {
  position: absolute;
  pointer-events: none;
  user-select: none;
  z-index: 50;
  transition: left 60ms linear, top 60ms linear;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.remote-cursor-icon {
  font-size: 22px;
  line-height: 1;
  filter: drop-shadow(0 0 4px rgba(255,255,255,0.3));
}
.remote-cursor-name {
  font-family: 'Press Start 2P', monospace;
  font-size: 5px;
  white-space: nowrap;
  opacity: 0.8;
}

/* ── Scoreboard on end screens ── */
.scoreboard {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 7px;
  max-width: 300px;
  width: 100%;
}
.scoreboard-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 8px;
  background: rgba(255,255,255,0.04);
  border-radius: 4px;
  gap: 12px;
}
.scoreboard-name {
  display: flex;
  align-items: center;
  gap: 6px;
}
.scoreboard-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.scoreboard-points {
  color: var(--yellow);
}

/* ── Name entry screen ── */
.name-entry {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 500;
  gap: 20px;
  text-align: center;
  padding: 20px;
}
.name-entry.hidden { display: none; }

.name-entry-title {
  font-size: 20px;
  color: var(--yellow);
  text-shadow: 0 0 24px rgba(255,230,109,0.5);
}

.name-entry-sub {
  font-size: 7px;
  color: var(--muted);
  line-height: 2;
}

.name-input {
  font-family: 'Press Start 2P', monospace;
  font-size: 12px;
  padding: 12px 20px;
  background: var(--surface);
  border: 2px solid var(--purple);
  border-radius: 6px;
  color: var(--yellow);
  text-align: center;
  outline: none;
  width: 280px;
  max-width: 90vw;
}
.name-input::placeholder {
  color: #3d3d5c;
  font-size: 9px;
}
.name-input:focus {
  border-color: var(--yellow);
  box-shadow: 0 0 16px rgba(255,230,109,0.2);
}

.icon-picker {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 320px;
}
.icon-picker-label {
  font-size: 7px;
  color: var(--muted);
  width: 100%;
  margin-bottom: 4px;
}
.icon-option {
  width: 48px;
  height: 48px;
  font-size: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 2px solid #2a2a4a;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
}
.icon-option:hover {
  border-color: var(--muted);
  transform: scale(1.1);
}
.icon-option.selected {
  border-color: var(--yellow);
  background: var(--dark-purple);
  box-shadow: 0 0 12px rgba(255,230,109,0.3);
  transform: scale(1.15);
}

/* ── Connection status ── */
.conn-status {
  position: fixed;
  top: 8px;
  right: 8px;
  font-size: 5px;
  padding: 4px 8px;
  border-radius: 4px;
  background: var(--surface);
  border: 1px solid #2a2a4a;
  z-index: 200;
  opacity: 0.7;
}
.conn-status.connected { color: var(--teal); }
.conn-status.disconnected { color: var(--red); }

/* ── Boss sprite ── */
.boss {
  position: absolute;
  width: 120px;
  height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  z-index: 15;
  animation: boss-spawn 0.8s ease-out;
}
.boss:active { transform: scale(0.9); }

.boss-body {
  position: relative;
  width: 80px;
  height: 60px;
  background: linear-gradient(135deg, #a855f7, #7c3aed);
  border-radius: 50%;
  box-shadow: 0 0 24px rgba(168,85,247,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Boss antennae */
.boss-body::before,
.boss-body::after {
  content: '';
  position: absolute;
  top: -12px;
  width: 6px;
  height: 16px;
  background: #a855f7;
  border-radius: 3px;
}
.boss-body::before { left: 16px; transform: rotate(-25deg); }
.boss-body::after { right: 16px; transform: rotate(25deg); }

.boss-eyes {
  font-size: 18px;
  color: var(--bg);
  font-family: monospace;
  font-weight: bold;
  letter-spacing: 8px;
  margin-top: -2px;
}

/* Boss legs */
.boss-legs {
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  pointer-events: none;
}
.boss-legs span {
  position: absolute;
  width: 10px;
  height: 3px;
  background: #a855f7;
  border-radius: 2px;
}
.boss-legs span:nth-child(1) { top: 14px; left: 4px; transform: rotate(-30deg); }
.boss-legs span:nth-child(2) { top: 28px; left: 1px; transform: rotate(0deg); }
.boss-legs span:nth-child(3) { top: 42px; left: 4px; transform: rotate(30deg); }
.boss-legs span:nth-child(4) { top: 14px; right: 4px; transform: rotate(30deg); }
.boss-legs span:nth-child(5) { top: 28px; right: 1px; transform: rotate(0deg); }
.boss-legs span:nth-child(6) { top: 42px; right: 4px; transform: rotate(-30deg); }

/* Boss crown spikes */
.boss-crown {
  position: absolute;
  top: -20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 4px;
  pointer-events: none;
}
.boss-crown span {
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-bottom: 12px solid #ffe66d;
}
.boss-crown span:nth-child(2) { border-bottom-height: 16px; border-bottom: 16px solid #ffe66d; }

.boss.walking {
  animation: boss-walk 0.6s steps(2) infinite;
}

/* Boss enraged state */
.boss.enraged .boss-body {
  background: linear-gradient(135deg, #ff6b6b, #dc2626);
  box-shadow: 0 0 32px rgba(255,107,107,0.8);
  animation: boss-pulse 0.8s ease-in-out infinite;
}
.boss.enraged .boss-body::before,
.boss.enraged .boss-body::after {
  background: #ff6b6b;
}
.boss.enraged .boss-legs span {
  background: #ff6b6b;
}
.boss.enraged .boss-crown span {
  border-bottom-color: #ff6b6b;
}

/* Boss HP bar */
.boss-hp-bar-container {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 90;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.boss-hp-bar-label {
  font-family: 'Press Start 2P', monospace;
  font-size: 6px;
  color: var(--muted);
}
.boss-hp-bar-track {
  width: 300px;
  height: 14px;
  background: var(--bg);
  border: 2px solid #3d3d5c;
  border-radius: 3px;
  overflow: hidden;
}
.boss-hp-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #a855f7, #c084fc);
  border-radius: 1px;
  transition: width 0.3s ease;
}
.boss-hp-bar-fill.enraged {
  background: linear-gradient(90deg, #dc2626, #ff6b6b);
}

/* Boss timer */
.boss-timer {
  font-family: 'Press Start 2P', monospace;
  font-size: 12px;
  color: var(--yellow);
  text-shadow: 0 0 8px rgba(255,230,109,0.4);
}
.boss-timer.urgent {
  color: var(--red);
  text-shadow: 0 0 12px rgba(255,107,107,0.6);
  animation: pulse-hp 0.6s infinite;
}

/* Boss regen number */
.boss-regen-num {
  position: absolute;
  pointer-events: none;
  z-index: 23;
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  color: #22c55e;
  text-shadow: 0 0 8px rgba(34,197,94,0.6);
  white-space: nowrap;
  animation: regen-float 0.8s ease-out forwards;
}

@keyframes regen-float {
  0% { transform: translateY(0); opacity: 1; }
  100% { transform: translateY(-30px); opacity: 0; }
}

/* Boss escalation warning */
.escalation-flash {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 82;
  border-radius: 8px;
  background: rgba(168,85,247,0.2);
  animation: enrage-flash-anim 0.4s ease-out forwards;
}

/* Boss animations */
@keyframes boss-spawn {
  0% { transform: scale(0) rotate(720deg); opacity: 0; }
  60% { transform: scale(1.2) rotate(0deg); opacity: 1; }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

@keyframes boss-walk {
  0% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

@keyframes boss-pulse {
  0%, 100% { box-shadow: 0 0 32px rgba(255,107,107,0.8); }
  50% { box-shadow: 0 0 48px rgba(255,107,107,1); }
}

@keyframes boss-hit-flash {
  0% { filter: brightness(3); }
  100% { filter: brightness(1); }
}

@keyframes boss-explode {
  0% { transform: scale(1) rotate(0deg); opacity: 1; }
  40% { transform: scale(1.5) rotate(180deg); opacity: 0.8; }
  100% { transform: scale(0) rotate(720deg); opacity: 0; }
}

/* Boss warning title */
.screen-title.boss-title {
  color: var(--purple);
  text-shadow: 0 0 24px rgba(168,85,247,0.7), 0 0 48px rgba(168,85,247,0.3);
}

/* ── Particle burst ── */
.particle {
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  pointer-events: none;
  z-index: 22;
  animation: particle-fly 0.4s ease-out forwards;
}

@keyframes particle-fly {
  0% { transform: translate(0, 0) scale(1); opacity: 1; }
  100% { transform: translate(var(--px), var(--py)) scale(0); opacity: 0; }
}

/* ── Screen shake ── */
.arena.shake-light { animation: shake-light 200ms ease-out; }
.arena.shake-micro { animation: shake-micro 100ms ease-out; }
.arena.shake-medium { animation: shake-medium 300ms ease-out; }
.arena.shake-heavy { animation: shake-heavy 500ms ease-out; }

@keyframes shake-light {
  0%, 100% { transform: translate(0, 0); }
  25% { transform: translate(-3px, 2px); }
  50% { transform: translate(3px, -2px); }
  75% { transform: translate(-2px, 1px); }
}

@keyframes shake-micro {
  0%, 100% { transform: translate(0, 0); }
  25% { transform: translate(-1px, 1px); }
  75% { transform: translate(1px, -1px); }
}

@keyframes shake-medium {
  0%, 100% { transform: translate(0, 0); }
  10% { transform: translate(-5px, 3px); }
  30% { transform: translate(4px, -4px); }
  50% { transform: translate(-3px, 5px); }
  70% { transform: translate(5px, -2px); }
  90% { transform: translate(-2px, 1px); }
}

@keyframes shake-heavy {
  0%, 100% { transform: translate(0, 0); }
  8% { transform: translate(-8px, 5px); }
  16% { transform: translate(7px, -6px); }
  24% { transform: translate(-6px, 7px); }
  32% { transform: translate(8px, -4px); }
  48% { transform: translate(-5px, 6px); }
  64% { transform: translate(6px, -5px); }
  80% { transform: translate(-4px, 3px); }
  90% { transform: translate(2px, -1px); }
}

/* ── Impact ring ── */
.impact-ring {
  position: absolute;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 3px solid currentColor;
  pointer-events: none;
  z-index: 21;
  transform: translate(-50%, -50%) scale(0);
  animation: ring-expand 0.4s ease-out forwards;
}

@keyframes ring-expand {
  0% { transform: translate(-50%, -50%) scale(0); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1.5); opacity: 0; }
}

/* ── Damage vignette ── */
.damage-vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 80;
  border-radius: 8px;
  animation: vignette-flash 0.4s ease-out forwards;
}

@keyframes vignette-flash {
  0% { background: radial-gradient(ellipse at center, transparent 50%, rgba(255,60,60,0) 100%); }
  30% { background: radial-gradient(ellipse at center, transparent 50%, rgba(255,60,60,0.4) 100%); }
  100% { background: radial-gradient(ellipse at center, transparent 50%, rgba(255,60,60,0) 100%); }
}

/* ── Bug death pop ── */
.bug.popping {
  pointer-events: none;
  animation: bug-pop 0.2s ease-out forwards;
}

@keyframes bug-pop {
  0% { transform: scale(1) rotate(0deg); opacity: 1; }
  50% { transform: scale(1.3) rotate(15deg); opacity: 0.8; }
  100% { transform: scale(0) rotate(-30deg); opacity: 0; }
}

/* ── Boss damage number ── */
.boss-damage-num {
  position: absolute;
  pointer-events: none;
  z-index: 23;
  font-family: 'Press Start 2P', monospace;
  font-size: 14px;
  text-shadow: 0 0 8px currentColor;
  white-space: nowrap;
  animation: squash-anim 0.5s ease-out forwards;
}

/* ── Enrage flash ── */
.enrage-flash {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 82;
  border-radius: 8px;
  background: rgba(255,60,60,0.25);
  animation: enrage-flash-anim 0.4s ease-out forwards;
}

@keyframes enrage-flash-anim {
  0% { opacity: 0; }
  30% { opacity: 1; }
  60% { opacity: 0.6; }
  100% { opacity: 0; }
}

/* ── Level flash ── */
.level-flash {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 85;
  border-radius: 8px;
  background: white;
  animation: level-flash-anim 0.5s ease-out forwards;
}

@keyframes level-flash-anim {
  0% { opacity: 0; }
  30% { opacity: 0.3; }
  100% { opacity: 0; }
}

/* ══════════════════════════════════════════════════
   NEW FEATURE STYLES
   ══════════════════════════════════════════════════ */

/* ── Feature 1: Heisenbug ── */
.bug.heisenbug .bug-body {
  background: var(--teal);
  box-shadow: 0 0 16px rgba(78,205,196,0.6), 0 0 32px rgba(78,205,196,0.2);
  animation: heisenbug-shimmer 0.3s steps(3) infinite;
}
.bug.heisenbug .bug-body::before,
.bug.heisenbug .bug-body::after {
  background: var(--teal);
}
.bug.heisenbug .bug-legs span {
  background: var(--teal);
}

.bug.heisenbug-stabilized .bug-body {
  background: var(--teal);
  box-shadow: 0 0 8px rgba(78,205,196,0.3);
}
.bug.heisenbug-stabilized .bug-body::before,
.bug.heisenbug-stabilized .bug-body::after {
  background: var(--teal);
}
.bug.heisenbug-stabilized .bug-legs span {
  background: var(--teal);
}

@keyframes heisenbug-shimmer {
  0% { opacity: 1; transform: scale(1); }
  33% { opacity: 0.7; transform: scale(1.05); }
  66% { opacity: 0.9; transform: scale(0.95); }
  100% { opacity: 1; transform: scale(1); }
}

.heisenbug-ghost {
  position: absolute;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 20;
  font-family: 'Press Start 2P', monospace;
  font-size: 18px;
  color: var(--teal);
  text-shadow: 0 0 12px rgba(78,205,196,0.8);
  animation: heisenbug-ghost-fade 0.4s ease-out forwards;
}

@keyframes heisenbug-ghost-fade {
  0% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.5); }
}

/* ── Feature 2: Feature-Not-A-Bug ── */
.bug.feature-bug .bug-body {
  background: #22c55e;
  box-shadow: 0 0 12px rgba(34,197,94,0.4);
}
.bug.feature-bug .bug-body::before,
.bug.feature-bug .bug-body::after {
  background: #22c55e;
}
.bug.feature-bug .bug-legs span {
  background: #22c55e;
}
.bug.feature-bug .bug-eyes::after {
  content: '\2713';
  font-size: 14px;
  position: absolute;
  top: -14px;
  left: 50%;
  transform: translateX(-50%);
  color: #22c55e;
  text-shadow: 0 0 6px rgba(34,197,94,0.6);
}

.bug.feature-leaving {
  pointer-events: none;
  animation: feature-leave 0.5s ease-in forwards;
}

@keyframes feature-leave {
  0% { transform: scale(1); opacity: 1; }
  100% { transform: scale(0.5); opacity: 0; }
}

.feature-penalty-text {
  position: absolute;
  pointer-events: none;
  z-index: 25;
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  color: var(--red);
  text-shadow: 0 0 8px rgba(255,107,107,0.6);
  white-space: nowrap;
  transform: translateX(-50%);
  animation: feature-penalty-rise 1.2s ease-out forwards;
}

@keyframes feature-penalty-rise {
  0% { transform: translateX(-50%) translateY(0); opacity: 1; }
  100% { transform: translateX(-50%) translateY(-60px); opacity: 0; }
}

/* ── Feature 3: Memory Leak ── */
.bug.memory-leak {
  cursor: grab;
}

.bug.memory-leak .bug-body {
  background: #9333ea;
  box-shadow: 0 0 12px rgba(147,51,234,0.4);
  transition: transform 2s ease-out, background-color 2s ease-out, box-shadow 2s ease-out;
}
.bug.memory-leak .bug-body::before,
.bug.memory-leak .bug-body::after {
  background: #9333ea;
  transition: background-color 2s ease-out;
}
.bug.memory-leak .bug-legs span {
  background: #9333ea;
  transition: background-color 2s ease-out;
}

/* Growth stage 1: slightly larger, darker purple */
.bug.memory-leak[data-growth-stage="1"] .bug-body {
  transform: scale(1.15);
  background: #7c3aed;
  box-shadow: 0 0 14px rgba(124,58,237,0.5);
}
.bug.memory-leak[data-growth-stage="1"] .bug-body::before,
.bug.memory-leak[data-growth-stage="1"] .bug-body::after {
  background: #7c3aed;
}
.bug.memory-leak[data-growth-stage="1"] .bug-legs span {
  background: #7c3aed;
}

/* Growth stage 2: noticeably larger, even darker */
.bug.memory-leak[data-growth-stage="2"] .bug-body {
  transform: scale(1.35);
  background: #6d28d9;
  box-shadow: 0 0 16px rgba(109,40,217,0.6);
}
.bug.memory-leak[data-growth-stage="2"] .bug-body::before,
.bug.memory-leak[data-growth-stage="2"] .bug-body::after {
  background: #6d28d9;
}
.bug.memory-leak[data-growth-stage="2"] .bug-legs span {
  background: #6d28d9;
}

/* Growth stage 3: maximum size, darkest purple */
.bug.memory-leak[data-growth-stage="3"] .bug-body {
  transform: scale(1.6);
  background: #5b21b6;
  box-shadow: 0 0 20px rgba(91,33,182,0.8), 0 0 40px rgba(91,33,182,0.3);
  animation: memory-leak-pulse 1s ease-in-out infinite;
}
.bug.memory-leak[data-growth-stage="3"] .bug-body::before,
.bug.memory-leak[data-growth-stage="3"] .bug-body::after {
  background: #5b21b6;
}
.bug.memory-leak[data-growth-stage="3"] .bug-legs span {
  background: #5b21b6;
}

@keyframes memory-leak-pulse {
  0%, 100% { box-shadow: 0 0 20px rgba(91,33,182,0.8), 0 0 40px rgba(91,33,182,0.3); }
  50% { box-shadow: 0 0 24px rgba(91,33,182,1), 0 0 48px rgba(91,33,182,0.5); }
}

/* Memory leak hold progress bar */
.memory-leak-progress {
  position: absolute;
  bottom: -8px;
  left: 50%;
  transform: translateX(-50%);
  width: 44px;
  height: 4px;
  background: rgba(0,0,0,0.4);
  border-radius: 2px;
  overflow: hidden;
  border: 1px solid rgba(147,51,234,0.5);
}

.memory-leak-progress-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #9333ea, #a855f7);
  box-shadow: 0 0 8px rgba(147,51,234,0.8);
}

.memory-leak-holder-count {
  position: absolute;
  top: -16px;
  left: 50%;
  transform: translateX(-50%);
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  color: #a855f7;
  text-shadow: 0 0 6px rgba(168,85,247,0.8);
  white-space: nowrap;
  display: none;
}

.bug.memory-leak.being-held {
  cursor: grabbing;
  filter: brightness(1.2);
}

.memory-leak-early-release {
  position: absolute;
  pointer-events: none;
  z-index: 25;
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  color: var(--red);
  text-shadow: 0 0 8px rgba(255,107,107,0.6);
  white-space: nowrap;
  transform: translateX(-50%);
  animation: memory-leak-early-release-rise 1s ease-out forwards;
}

@keyframes memory-leak-early-release-rise {
  0% { transform: translateX(-50%) translateY(0) scale(1.2); opacity: 1; }
  100% { transform: translateX(-50%) translateY(-40px) scale(0.8); opacity: 0; }
}

/* ── Feature 4: Rubber Duck Debugger ── */
.rubber-duck {
  position: absolute;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  z-index: 14;
  font-size: 28px;
  animation: duck-bob 0.8s ease-in-out infinite;
  filter: drop-shadow(0 0 8px rgba(255,230,109,0.6));
}
.rubber-duck::after {
  content: '\1F986';
}

@keyframes duck-bob {
  0%, 100% { transform: translateY(0) rotate(-5deg); }
  50% { transform: translateY(-6px) rotate(5deg); }
}

.duck-buff-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 4;
  border-radius: 8px;
  border: 3px solid rgba(255,230,109,0.4);
  animation: duck-buff-pulse 1s ease-in-out infinite;
}

@keyframes duck-buff-pulse {
  0%, 100% { border-color: rgba(255,230,109,0.2); box-shadow: inset 0 0 20px rgba(255,230,109,0.05); }
  50% { border-color: rgba(255,230,109,0.5); box-shadow: inset 0 0 30px rgba(255,230,109,0.1); }
}

/* ── Hotfix Hammer ── */
.hotfix-hammer {
  position: absolute;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  z-index: 14;
  font-size: 32px;
  animation: hammer-pulse 0.6s ease-in-out infinite;
  filter: drop-shadow(0 0 10px rgba(255,107,107,0.6));
}
.hotfix-hammer::after {
  content: '\1F528';
}

@keyframes hammer-pulse {
  0%, 100% { transform: scale(1) rotate(-15deg); }
  50% { transform: scale(1.1) rotate(15deg); }
}

.hammer-shockwave {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: 4px solid rgba(255,107,107,0.8);
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 15;
  animation: hammer-shockwave-expand 0.8s ease-out forwards;
}

@keyframes hammer-shockwave-expand {
  0% {
    width: 80px;
    height: 80px;
    opacity: 1;
    border-width: 4px;
  }
  100% {
    width: 1200px;
    height: 1200px;
    opacity: 0;
    border-width: 2px;
  }
}

.bug.stunned {
  animation: bug-stunned 0.3s ease-in-out infinite !important;
  filter: grayscale(0.5) brightness(1.2);
}

@keyframes bug-stunned {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-2px); }
}

.boss.stunned {
  animation: boss-stunned 0.3s ease-in-out infinite !important;
  filter: grayscale(0.5) brightness(1.2);
}

@keyframes boss-stunned {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.02); }
}

/* ── Feature 5: Merge Conflict ── */
.bug.merge-left .bug-body,
.bug.merge-right .bug-body {
  border: 2px solid var(--yellow);
  box-shadow: 0 0 12px rgba(255,230,109,0.3);
}

.bug.merge-left .bug-eyes::after {
  content: '<<<';
  font-family: 'Press Start 2P', monospace;
  font-size: 6px;
  position: absolute;
  top: -16px;
  left: 50%;
  transform: translateX(-50%);
  color: var(--yellow);
  text-shadow: 0 0 6px rgba(255,230,109,0.4);
  white-space: nowrap;
}

.bug.merge-right .bug-eyes::after {
  content: '>>>';
  font-family: 'Press Start 2P', monospace;
  font-size: 6px;
  position: absolute;
  top: -16px;
  left: 50%;
  transform: translateX(-50%);
  color: var(--yellow);
  text-shadow: 0 0 6px rgba(255,230,109,0.4);
  white-space: nowrap;
}

.bug.merge-halfclick {
  animation: merge-bounce 0.5s ease-out;
}

@keyframes merge-bounce {
  0% { transform: scale(1); }
  25% { transform: scale(1.2); }
  50% { transform: scale(0.9); }
  75% { transform: scale(1.05); }
  100% { transform: scale(1); }
}

.merge-resolved-text {
  position: absolute;
  pointer-events: none;
  z-index: 25;
  font-family: 'Press Start 2P', monospace;
  font-size: 14px;
  color: var(--yellow);
  text-shadow: 0 0 12px rgba(255,230,109,0.8);
  white-space: nowrap;
  transform: translateX(-50%);
  animation: merge-resolved-rise 1s ease-out forwards;
}

@keyframes merge-resolved-rise {
  0% { transform: translateX(-50%) translateY(0) scale(0.8); opacity: 0; }
  20% { transform: translateX(-50%) translateY(-10px) scale(1.2); opacity: 1; }
  100% { transform: translateX(-50%) translateY(-60px) scale(1); opacity: 0; }
}

/* ── Feature 8: Pipeline Bug ── */
.bug.pipeline-bug .bug-body {
  background: linear-gradient(135deg, #a855f7, #6366f1);
  box-shadow: 0 0 14px rgba(168,85,247,0.5);
  border: 2px solid rgba(168,85,247,0.6);
  animation: pipeline-pulse 1.5s ease-in-out infinite;
}
.bug.pipeline-bug .bug-body::before,
.bug.pipeline-bug .bug-body::after {
  background: #a855f7;
}
.bug.pipeline-bug .bug-legs span {
  background: #a855f7;
}
.bug.pipeline-bug .bug-eyes::after {
  content: attr(data-chain-index);
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  position: absolute;
  top: -16px;
  left: 50%;
  transform: translateX(-50%);
  color: #c084fc;
  text-shadow: 0 0 6px rgba(168,85,247,0.6);
  white-space: nowrap;
}

.bug.pipeline-bug[data-chain-index="0"] .bug-eyes::after { content: '1'; }
.bug.pipeline-bug[data-chain-index="1"] .bug-eyes::after { content: '2'; }
.bug.pipeline-bug[data-chain-index="2"] .bug-eyes::after { content: '3'; }
.bug.pipeline-bug[data-chain-index="3"] .bug-eyes::after { content: '4'; }
.bug.pipeline-bug[data-chain-index="4"] .bug-eyes::after { content: '5'; }

@keyframes pipeline-pulse {
  0%, 100% { box-shadow: 0 0 14px rgba(168,85,247,0.5); }
  50% { box-shadow: 0 0 22px rgba(168,85,247,0.8), 0 0 6px rgba(99,102,241,0.4); }
}

.bug.pipeline-reset {
  animation: pipeline-error-flash 0.5s ease-out !important;
}

@keyframes pipeline-error-flash {
  0% { filter: brightness(1); }
  25% { filter: brightness(2) hue-rotate(-60deg); }
  50% { filter: brightness(1.5) hue-rotate(-30deg); }
  100% { filter: brightness(1); }
}

.pipeline-resolved-text {
  position: absolute;
  pointer-events: none;
  z-index: 25;
  font-family: 'Press Start 2P', monospace;
  font-size: 12px;
  color: #a855f7;
  text-shadow: 0 0 12px rgba(168,85,247,0.8), 0 0 24px rgba(99,102,241,0.4);
  white-space: nowrap;
  transform: translateX(-50%);
  animation: pipeline-resolved-rise 1.2s ease-out forwards;
}

@keyframes pipeline-resolved-rise {
  0% { transform: translateX(-50%) translateY(0) scale(0.6); opacity: 0; }
  15% { transform: translateX(-50%) translateY(-10px) scale(1.3); opacity: 1; }
  100% { transform: translateX(-50%) translateY(-70px) scale(1); opacity: 0; }
}

.pipeline-reset-text {
  position: absolute;
  pointer-events: none;
  z-index: 25;
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  color: var(--red);
  text-shadow: 0 0 8px rgba(255,107,107,0.6);
  white-space: nowrap;
  transform: translateX(-50%);
  animation: pipeline-reset-rise 1s ease-out forwards;
}

@keyframes pipeline-reset-rise {
  0% { transform: translateX(-50%) translateY(0) scale(1.2); opacity: 1; }
  100% { transform: translateX(-50%) translateY(-50px) scale(0.8); opacity: 0; }
}

/* ── Lobby Browser ── */
.lobby-browser {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 450;
  gap: 16px;
  text-align: center;
  padding: 20px;
}
.lobby-browser.hidden { display: none; }

.lobby-browser-title {
  font-size: 18px;
  color: var(--yellow);
  text-shadow: 0 0 24px rgba(255,230,109,0.5);
}

.lobby-browser-sub {
  font-size: 7px;
  color: var(--muted);
  line-height: 2;
}

.lobby-create-form {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 500px;
}

.lobby-name-input {
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  padding: 10px 14px;
  background: var(--surface);
  border: 2px solid var(--purple);
  border-radius: 6px;
  color: var(--yellow);
  text-align: center;
  outline: none;
  width: 180px;
}
.lobby-name-input::placeholder {
  color: #3d3d5c;
  font-size: 7px;
}
.lobby-name-input:focus {
  border-color: var(--yellow);
  box-shadow: 0 0 12px rgba(255,230,109,0.2);
}

.custom-select {
  position: relative;
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  cursor: pointer;
  user-select: none;
}
.custom-select-trigger {
  padding: 10px 14px;
  background: var(--surface);
  border: 2px solid var(--purple);
  border-radius: 6px;
  color: var(--yellow);
  white-space: nowrap;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.custom-select.open .custom-select-trigger {
  border-color: var(--yellow);
  box-shadow: 0 0 12px rgba(255,230,109,0.2);
}
.custom-select-options {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 2px solid var(--purple);
  border-radius: 6px;
  overflow: hidden;
  z-index: 100;
}
.custom-select.open .custom-select-options {
  display: block;
}
.custom-select-option {
  padding: 8px 14px;
  color: var(--muted);
  transition: background 0.1s, color 0.1s;
  white-space: nowrap;
}
.custom-select-option:hover {
  background: var(--purple);
  color: var(--yellow);
}
.custom-select-option.selected {
  color: var(--yellow);
}

.btn-small {
  font-size: 7px;
  padding: 10px 16px;
}

.lobby-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 500px;
  width: 100%;
  max-height: 280px;
  overflow-y: auto;
}

.lobby-list-empty {
  font-size: 7px;
  color: var(--muted);
  padding: 20px;
  opacity: 0.6;
}

.lobby-list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid #2a2a4a;
  border-radius: 6px;
  gap: 12px;
  transition: border-color 0.15s;
}
.lobby-list-item:hover {
  border-color: var(--purple);
}

.lobby-list-info {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 7px;
}

.lobby-list-name {
  color: var(--yellow);
}

.lobby-list-code {
  color: var(--teal);
  font-size: 6px;
  opacity: 0.7;
}

.lobby-list-players {
  color: var(--muted);
  font-size: 6px;
}

.lobby-join-btn {
  font-size: 6px;
  padding: 8px 14px;
}
.lobby-join-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  border-color: #3d3d5c;
  background: var(--surface);
  color: var(--muted);
}
.lobby-join-btn:disabled:hover {
  background: var(--surface);
  color: var(--muted);
  box-shadow: none;
}

.lobby-error {
  font-size: 7px;
  color: var(--red);
  padding: 8px 16px;
  background: rgba(255,107,107,0.1);
  border: 1px solid rgba(255,107,107,0.3);
  border-radius: 6px;
  max-width: 400px;
}
.lobby-error.hidden { display: none; }

/* ── Leave lobby buttons ── */
.btn-leave {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  padding: 10px 20px;
  border: 2px solid var(--red);
  background: rgba(255,107,107,0.1);
  color: var(--red);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
  letter-spacing: 1px;
}
.btn-leave:hover {
  background: var(--red);
  color: var(--bg);
  box-shadow: 0 0 16px rgba(255,107,107,0.4);
}

.hud-leave-btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 6px;
  padding: 6px 12px;
  border: 1px solid var(--red);
  background: rgba(255,107,107,0.1);
  color: var(--red);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
}
.hud-leave-btn:hover {
  background: var(--red);
  color: var(--bg);
}
.hud-leave-btn.hidden { display: none; }

/* ── Play button ── */
.btn-play {
  font-size: 14px;
  padding: 16px 48px;
  border-color: var(--teal);
  background: var(--dark-teal);
  color: var(--teal);
}
.btn-play:hover {
  background: var(--teal);
  color: var(--bg);
  box-shadow: 0 0 24px rgba(78,205,196,0.5);
}

/* ── Auth UI ── */
.auth-status {
  font-size: 7px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
  margin-top: 8px;
  opacity: 0.7;
  transition: opacity 0.15s;
}
.auth-status:hover {
  opacity: 1;
}

.auth-or {
  opacity: 0.6;
}

.auth-username {
  color: var(--yellow);
}

.auth-logged-in-view.hidden,
.auth-guest-view.hidden { display: none; }

.btn-link {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  background: none;
  border: none;
  color: var(--teal);
  cursor: pointer;
  padding: 4px 8px;
  transition: color 0.15s;
  text-decoration: none;
}
.btn-link:hover {
  color: var(--yellow);
  text-shadow: 0 0 8px rgba(255,230,109,0.3);
}

.auth-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 510;
  gap: 16px;
  text-align: center;
  padding: 20px;
}
.auth-overlay.hidden { display: none; }

.auth-overlay-title {
  font-size: 18px;
  color: var(--yellow);
  text-shadow: 0 0 24px rgba(255,230,109,0.5);
}

.auth-tabs {
  display: flex;
  gap: 4px;
}

.auth-tab {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  padding: 8px 16px;
  border: 2px solid #2a2a4a;
  background: var(--surface);
  color: var(--muted);
  border-radius: 6px 6px 0 0;
  cursor: pointer;
  transition: all 0.15s;
}
.auth-tab.active {
  border-color: var(--purple);
  color: var(--yellow);
  background: var(--dark-purple);
}
.auth-tab:hover:not(.active) {
  border-color: var(--muted);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
  width: 280px;
  max-width: 90vw;
}
.auth-form.hidden { display: none; }

.auth-input {
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  padding: 10px 14px;
  background: var(--surface);
  border: 2px solid var(--purple);
  border-radius: 6px;
  color: var(--yellow);
  text-align: center;
  outline: none;
  width: 100%;
}
.auth-input::placeholder {
  color: #3d3d5c;
  font-size: 7px;
}
.auth-input:focus {
  border-color: var(--yellow);
  box-shadow: 0 0 12px rgba(255,230,109,0.2);
}

.auth-error {
  font-size: 7px;
  color: var(--red);
  padding: 8px 16px;
  background: rgba(255,107,107,0.1);
  border: 1px solid rgba(255,107,107,0.3);
  border-radius: 6px;
  max-width: 280px;
}
.auth-error.hidden { display: none; }

.auth-back-btn {
  margin-top: 8px;
  color: var(--muted);
}

/* ── Lobby Tabs ── */
.lobby-tabs {
  display: flex;
  gap: 4px;
}

.lobby-tab {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  padding: 8px 16px;
  border: 2px solid #2a2a4a;
  background: var(--surface);
  color: var(--muted);
  border-radius: 6px 6px 0 0;
  cursor: pointer;
  transition: all 0.15s;
}
.lobby-tab.active {
  border-color: var(--purple);
  color: var(--yellow);
  background: var(--dark-purple);
}
.lobby-tab:hover:not(.active) {
  border-color: var(--muted);
}
.lobby-tab-link {
  text-decoration: none;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lobby-tab-link:hover {
  border-color: var(--teal);
  color: var(--teal);
}

#lobby-list-panel.hidden { display: none; }

/* ── Leaderboard ── */
.leaderboard-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 500px;
  width: 100%;
  align-items: center;
}
.leaderboard-panel.hidden { display: none; }

.leaderboard-header {
  font-size: 10px;
  color: var(--teal);
  text-shadow: 0 0 12px rgba(78,205,196,0.4);
  letter-spacing: 2px;
}

.leaderboard-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  max-height: 320px;
  overflow-y: auto;
}

.leaderboard-empty {
  font-size: 7px;
  color: var(--muted);
  padding: 20px;
  opacity: 0.6;
}

.leaderboard-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid #2a2a4a;
  border-radius: 6px;
  font-size: 7px;
  transition: border-color 0.15s;
}
.leaderboard-row:hover {
  border-color: var(--purple);
}

.leaderboard-rank {
  color: var(--muted);
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}

.leaderboard-icon {
  font-size: 16px;
  flex-shrink: 0;
}

.leaderboard-name {
  color: var(--yellow);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard-score {
  color: var(--teal);
  flex-shrink: 0;
}

.leaderboard-wins {
  color: var(--purple);
  flex-shrink: 0;
  font-size: 6px;
}

.leaderboard-winrate {
  color: var(--muted);
  flex-shrink: 0;
  font-size: 6px;
  width: 32px;
  text-align: right;
}

/* Top 3 highlights */
.leaderboard-row.leaderboard-rank-gold {
  border-color: #ffe66d;
  background: rgba(255,230,109,0.08);
}
.leaderboard-rank-gold .leaderboard-rank { color: #ffe66d; }

.leaderboard-row.leaderboard-rank-silver {
  border-color: #c0c0c0;
  background: rgba(192,192,192,0.06);
}
.leaderboard-rank-silver .leaderboard-rank { color: #c0c0c0; }

.leaderboard-row.leaderboard-rank-bronze {
  border-color: #cd7f32;
  background: rgba(205,127,50,0.06);
}
.leaderboard-rank-bronze .leaderboard-rank { color: #cd7f32; }

/* ══════════════════════════════════════════════════
   LOBBY WAITING SCREEN
   ══════════════════════════════════════════════════ */

/* ── Background bugs layer ── */
.lobby-bg-bugs {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 0;
}

.lobby-bg-bug {
  position: absolute;
  width: 20px;
  height: 14px;
  pointer-events: auto;
  cursor: pointer;
  z-index: 1;
  opacity: 0.3;
  transition: opacity 0.2s;
}
.lobby-bg-bug:hover {
  opacity: 0.7;
}
.lobby-bg-bug-body {
  width: 16px;
  height: 12px;
  background: var(--red);
  border-radius: 50%;
  position: relative;
  box-shadow: 0 0 6px rgba(255,107,107,0.3);
}
.lobby-bg-bug-body::before,
.lobby-bg-bug-body::after {
  content: '';
  position: absolute;
  width: 3px;
  height: 2px;
  background: var(--red);
  border-radius: 1px;
}
.lobby-bg-bug-body::before { top: 3px; left: -3px; transform: rotate(-15deg); }
.lobby-bg-bug-body::after { top: 3px; right: -3px; transform: rotate(15deg); }

.lobby-bg-bug-eyes {
  position: absolute;
  top: 2px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 4px;
  color: var(--bg);
  font-family: monospace;
  font-weight: bold;
  letter-spacing: 2px;
}

/* Crawl animation variants */
.lobby-bg-bug.crawl-right {
  animation: lobby-crawl-right var(--crawl-dur, 12s) linear infinite;
  animation-delay: var(--crawl-delay, 0s);
}
.lobby-bg-bug.crawl-left {
  animation: lobby-crawl-left var(--crawl-dur, 10s) linear infinite;
  animation-delay: var(--crawl-delay, 0s);
  transform: scaleX(-1);
}
.lobby-bg-bug.crawl-down {
  animation: lobby-crawl-down var(--crawl-dur, 14s) linear infinite;
  animation-delay: var(--crawl-delay, 0s);
  transform: rotate(90deg);
}
.lobby-bg-bug.crawl-up {
  animation: lobby-crawl-up var(--crawl-dur, 11s) linear infinite;
  animation-delay: var(--crawl-delay, 0s);
  transform: rotate(-90deg);
}

@keyframes lobby-crawl-right {
  0% { left: -30px; }
  100% { left: calc(100% + 30px); }
}
@keyframes lobby-crawl-left {
  0% { left: calc(100% + 30px); }
  100% { left: -30px; }
}
@keyframes lobby-crawl-down {
  0% { top: -30px; }
  100% { top: calc(100% + 30px); }
}
@keyframes lobby-crawl-up {
  0% { top: calc(100% + 30px); }
  100% { top: -30px; }
}

/* Bug wiggle while crawling */
.lobby-bg-bug .lobby-bg-bug-body {
  animation: lobby-bug-wiggle 0.3s steps(2) infinite;
}
@keyframes lobby-bug-wiggle {
  0% { transform: translateY(0); }
  50% { transform: translateY(-1px); }
}

/* Squish effect */
.lobby-bg-bug.squished {
  pointer-events: none;
  animation: lobby-bug-squish 0.35s ease-out forwards !important;
}
@keyframes lobby-bug-squish {
  0% { transform: scale(1) rotate(0deg); opacity: 0.7; }
  30% { transform: scale(1.4) rotate(10deg); opacity: 1; }
  100% { transform: scale(0) rotate(-45deg); opacity: 0; }
}

/* Squish splat particle */
.lobby-splat {
  position: absolute;
  pointer-events: none;
  z-index: 2;
}
.lobby-splat-dot {
  position: absolute;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--red);
  animation: lobby-splat-fly 0.4s ease-out forwards;
}
@keyframes lobby-splat-fly {
  0% { transform: translate(0, 0) scale(1); opacity: 1; }
  100% { transform: translate(var(--sx), var(--sy)) scale(0); opacity: 0; }
}

/* ── Glitch title ── */
.lobby-title-wrap {
  position: relative;
  z-index: 10;
  text-align: center;
  margin-bottom: 4px;
}

.lobby-title {
  font-size: 22px;
  color: var(--yellow);
  text-shadow:
    0 0 20px rgba(255,230,109,0.5),
    0 0 60px rgba(255,230,109,0.15);
  position: relative;
  animation: lobby-title-pulse 3s ease-in-out infinite;
  letter-spacing: 3px;
}

/* Glitch pseudo-layers */
.lobby-title::before,
.lobby-title::after {
  content: attr(data-text);
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
.lobby-title::before {
  color: var(--red);
  animation: lobby-glitch-1 4s infinite linear alternate-reverse;
  clip-path: inset(0 0 60% 0);
  opacity: 0.6;
}
.lobby-title::after {
  color: var(--teal);
  animation: lobby-glitch-2 3s infinite linear alternate;
  clip-path: inset(60% 0 0 0);
  opacity: 0.6;
}

@keyframes lobby-title-pulse {
  0%, 100% { text-shadow: 0 0 20px rgba(255,230,109,0.5), 0 0 60px rgba(255,230,109,0.15); }
  50% { text-shadow: 0 0 30px rgba(255,230,109,0.7), 0 0 80px rgba(255,230,109,0.25), 0 0 120px rgba(255,230,109,0.1); }
}

@keyframes lobby-glitch-1 {
  0%, 92% { transform: translate(0); }
  93% { transform: translate(-3px, 1px); }
  94% { transform: translate(2px, -1px); }
  95% { transform: translate(-1px, 2px); }
  96%, 100% { transform: translate(0); }
}
@keyframes lobby-glitch-2 {
  0%, 90% { transform: translate(0); }
  91% { transform: translate(2px, 1px); }
  92% { transform: translate(-3px, -1px); }
  93% { transform: translate(1px, -2px); }
  94%, 100% { transform: translate(0); }
}

.lobby-subtitle {
  font-size: 6px;
  color: var(--teal);
  letter-spacing: 4px;
  margin-top: 8px;
  opacity: 0.7;
  animation: lobby-sub-flicker 5s ease-in-out infinite;
}

@keyframes lobby-sub-flicker {
  0%, 100% { opacity: 0.7; }
  48% { opacity: 0.7; }
  49% { opacity: 0.2; }
  50% { opacity: 0.8; }
  51% { opacity: 0.3; }
  52% { opacity: 0.7; }
}

/* ── Player roster ── */
.lobby-roster {
  position: relative;
  z-index: 10;
  width: 100%;
  max-width: 340px;
}

.lobby-roster-label {
  font-size: 6px;
  color: var(--muted);
  letter-spacing: 2px;
  margin-bottom: 8px;
  text-align: center;
  opacity: 0.6;
}

.lobby-roster-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}

.lobby-player-card {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: rgba(26,26,46,0.8);
  border: 1px solid #2a2a4a;
  border-radius: 6px;
  font-size: 6px;
  color: var(--muted);
  animation: lobby-card-in 0.3s ease-out backwards;
  transition: border-color 0.3s, box-shadow 0.3s;
}
.lobby-player-card:hover {
  border-color: var(--purple);
}
.lobby-player-card.is-me {
  border-color: var(--yellow);
  box-shadow: 0 0 8px rgba(255,230,109,0.15);
}

@keyframes lobby-card-in {
  0% { transform: scale(0.8) translateY(6px); opacity: 0; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}

.lobby-player-icon {
  font-size: 16px;
  line-height: 1;
}

.lobby-player-name {
  color: var(--yellow);
  max-width: 80px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lobby-player-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  flex-shrink: 0;
  animation: lobby-dot-pulse 1.5s ease-in-out infinite;
}
@keyframes lobby-dot-pulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 4px currentColor; }
  50% { opacity: 0.4; box-shadow: none; }
}

.lobby-player-you {
  font-size: 5px;
  color: var(--teal);
  opacity: 0.7;
}

/* ── Action buttons ── */
.lobby-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  z-index: 10;
  position: relative;
}

.lobby-start-btn {
  font-size: 12px;
  padding: 14px 32px;
  border-color: var(--teal);
  background: var(--dark-teal);
  color: var(--teal);
  position: relative;
  overflow: hidden;
}
.lobby-start-btn:hover {
  background: var(--teal);
  color: var(--bg);
  box-shadow: 0 0 24px rgba(78,205,196,0.5), 0 0 60px rgba(78,205,196,0.15);
}
.lobby-start-btn::after {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: linear-gradient(
    45deg,
    transparent 40%,
    rgba(78,205,196,0.08) 50%,
    transparent 60%
  );
  animation: lobby-btn-shine 3s ease-in-out infinite;
}
@keyframes lobby-btn-shine {
  0% { transform: translateX(-100%) rotate(0deg); }
  100% { transform: translateX(100%) rotate(0deg); }
}

.lobby-start-icon {
  margin-right: 6px;
  font-size: 10px;
}

/* ── Tips ticker ── */
.lobby-tips {
  position: absolute;
  bottom: 12px;
  left: 12px;
  right: 12px;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: rgba(15,14,23,0.7);
  border: 1px solid #2a2a4a;
  border-radius: 4px;
  font-size: 6px;
  overflow: hidden;
}

.lobby-tips-label {
  color: var(--purple);
  flex-shrink: 0;
  letter-spacing: 1px;
}

.lobby-tips-text {
  color: var(--muted);
  white-space: nowrap;
  animation: lobby-tip-slide 0.4s ease-out;
  line-height: 1.6;
}

@keyframes lobby-tip-slide {
  0% { transform: translateY(10px); opacity: 0; }
  100% { transform: translateY(0); opacity: 1; }
}

/* Dashed border glow on entire start screen */
#start-screen::before {
  content: '';
  position: absolute;
  inset: 6px;
  border: 1px dashed rgba(168,85,247,0.15);
  border-radius: 6px;
  pointer-events: none;
  z-index: 0;
  animation: lobby-border-glow 4s ease-in-out infinite;
}
@keyframes lobby-border-glow {
  0%, 100% { border-color: rgba(168,85,247,0.1); }
  50% { border-color: rgba(168,85,247,0.25); }
}

/* ── Responsive ── */
@media (max-width: 600px) {
  header h1 { font-size: 12px; }
  header p { font-size: 6px; }
  .hud { gap: 6px; }
  .hud-item { padding: 6px 8px; font-size: 6px; }
  .hp-bar-track { width: 50px; }
  .bug { width: 40px; height: 40px; }
  .bug-body { width: 28px; height: 22px; }
  .screen-title { font-size: 14px; }
  .lobby-title { font-size: 16px; }
  .lobby-roster { max-width: 260px; }
  .lobby-start-btn { font-size: 10px; padding: 12px 24px; }
}
