body {
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at top, rgba(255, 208, 71, 0.1), transparent 28%),
    linear-gradient(180deg, #06070d 0%, #04050a 100%);
  color: white;
  font-family: "Trebuchet MS", "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

canvas {
  display: block;
}

#ui-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

#header {
  padding: 18px 24px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  background:
    linear-gradient(180deg, rgba(4, 6, 10, 0.94) 0%, rgba(4, 6, 10, 0.66) 58%, transparent 100%);
}

#score-wrap {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 320px;
}

#score-board {
  width: fit-content;
  padding: 12px 16px;
  border-radius: 18px;
  background:
    linear-gradient(180deg, rgba(20, 23, 31, 0.9), rgba(8, 10, 16, 0.86));
  border: 1px solid rgba(255, 204, 84, 0.28);
  box-shadow:
    0 18px 48px rgba(0, 0, 0, 0.28),
    inset 0 1px 0 rgba(255, 246, 214, 0.08);
  font-size: 29px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.03em;
  color: #fff5d6;
  text-shadow: 0 0 18px rgba(255, 204, 64, 0.28);
}

.market-event {
  max-width: min(420px, calc(100vw - 80px));
  min-height: 48px;
  padding: 11px 14px;
  border-radius: 18px;
  background:
    linear-gradient(180deg, rgba(18, 21, 30, 0.9), rgba(10, 12, 18, 0.84));
  border: 1px solid rgba(255, 210, 90, 0.2);
  box-shadow: 0 16px 38px rgba(0, 0, 0, 0.24);
  color: #ffe7a3;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.45;
}

#beta-tag {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: #1a1200;
  background:
    linear-gradient(180deg, rgba(255, 224, 118, 0.98), rgba(219, 156, 0, 0.96));
  border: 1px solid rgba(255, 234, 177, 0.52);
  box-shadow:
    0 14px 30px rgba(183, 128, 0, 0.28),
    inset 0 1px 0 rgba(255, 247, 220, 0.65);
  z-index: 2;
}

.network-indicator {
  position: absolute;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(10, 12, 18, 0.82);
  border: 1px solid rgba(255, 210, 90, 0.24);
  color: #fff4cf;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(10px);
  z-index: 2;
}

.network-indicator.is-good {
  color: #a2f3c5;
}

.network-indicator.is-medium {
  color: #ffe39a;
}

.network-indicator.is-bad {
  color: #ffb0a6;
}

#hud-top-right {
  position: absolute;
  top: 18px;
  right: 24px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
}

#status {
  max-width: min(260px, calc(100vw - 48px));
  padding: 9px 14px;
  border-radius: 999px;
  background: rgba(10, 12, 18, 0.82);
  border: 1px solid rgba(255, 210, 90, 0.24);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(10px);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.2;
  color: #fff4cf;
  text-align: right;
}

.hud-chip {
  pointer-events: auto;
  min-width: 104px;
  padding: 9px 14px;
  border: 1px solid rgba(255, 210, 90, 0.24);
  border-radius: 999px;
  background:
    linear-gradient(180deg, rgba(20, 24, 33, 0.9), rgba(10, 12, 18, 0.82));
  color: #fff4cf;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-align: center;
  cursor: pointer;
  box-shadow:
    0 12px 24px rgba(0, 0, 0, 0.18),
    inset 0 1px 0 rgba(255, 247, 220, 0.06);
  backdrop-filter: blur(10px);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.hud-chip.is-muted {
  color: #d4c7a0;
  border-color: rgba(255, 210, 90, 0.12);
  background: rgba(8, 8, 16, 0.5);
}

.hud-chip:active {
  transform: scale(0.97);
}

.mobile-hud-toggle,
.mobile-help-toggle {
  display: none;
}

.hud-icon-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

#instructions {
  position: absolute;
  right: 24px;
  bottom: 22px;
  max-width: min(320px, calc(100vw - 220px));
  padding: 14px 16px;
  border-radius: 18px;
  background:
    linear-gradient(180deg, rgba(16, 19, 27, 0.92), rgba(9, 11, 17, 0.82));
  border: 1px solid rgba(255, 210, 90, 0.18);
  box-shadow:
    0 18px 40px rgba(0, 0, 0, 0.24),
    inset 0 1px 0 rgba(255, 246, 214, 0.04);
  backdrop-filter: blur(12px);
  font-size: 12px;
  line-height: 1.55;
  color: #efe6ca;
  text-align: right;
  box-sizing: border-box;
}

.danger {
  color: #ff3333;
}

#controls {
  padding: 20px;
  display: flex;
  justify-content: flex-end;
  align-items: flex-end;
}

.btn {
  background: rgba(255, 193, 7, 0.18);
  border: 2px solid rgba(255, 193, 7, 0.72);
  color: white;
  border-radius: 50%;
  width: 80px;
  height: 80px;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  backdrop-filter: blur(5px);
  text-transform: uppercase;
  pointer-events: auto;
}

.btn:active {
  background: rgba(255, 193, 7, 0.42);
  transform: scale(0.9);
}

#meta-panel {
  position: absolute;
  left: 24px;
  bottom: 22px;
  display: grid;
  gap: 8px;
  min-width: 172px;
  padding: 14px 16px;
  border-radius: 18px;
  background:
    linear-gradient(180deg, rgba(16, 19, 27, 0.92), rgba(9, 11, 17, 0.82));
  border: 1px solid rgba(255, 210, 90, 0.18);
  box-shadow:
    0 18px 40px rgba(0, 0, 0, 0.24),
    inset 0 1px 0 rgba(255, 246, 214, 0.04);
  font-size: 14px;
  color: #f4ead0;
  letter-spacing: 0.01em;
  text-shadow: 0 0 8px rgba(0, 0, 0, 0.45);
}

.meta {
  margin-top: 0;
  font-weight: 700;
}

.leaderboard {
  width: min(260px, calc(100vw - 48px));
  padding: 14px 14px 12px;
  border-radius: 18px;
  background:
    linear-gradient(180deg, rgba(17, 20, 28, 0.92), rgba(9, 11, 17, 0.82));
  border: 1px solid rgba(255, 210, 90, 0.2);
  box-shadow:
    0 18px 38px rgba(0, 0, 0, 0.24),
    inset 0 1px 0 rgba(255, 248, 225, 0.04);
  backdrop-filter: blur(12px);
  font-size: 11px;
  line-height: 1.45;
  color: #fff4cf;
  text-align: right;
}

.leader-row {
  margin-top: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.leader-title {
  margin-bottom: 8px;
  color: #ffd54f;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.18em;
}

.joystick {
  position: fixed;
  left: 18px;
  bottom: 18px;
  width: 116px;
  height: 116px;
  border-radius: 50%;
  border: 2px solid rgba(255, 204, 84, 0.34);
  background: rgba(255, 255, 255, 0.08);
  box-shadow: inset 0 0 24px rgba(255, 255, 255, 0.05), 0 0 24px rgba(120, 80, 0, 0.18);
  backdrop-filter: blur(6px);
  pointer-events: auto;
  z-index: 8;
  display: none;
}

.joystick-thumb {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 42px;
  height: 42px;
  margin-left: -21px;
  margin-top: -21px;
  border-radius: 50%;
  background: linear-gradient(180deg, rgba(180, 210, 255, 0.95), rgba(90, 140, 255, 0.88));
  box-shadow: 0 6px 18px rgba(0, 40, 120, 0.32);
  transition: transform 0.05s linear;
}

#game-over {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(10, 10, 20, 0.95);
  padding: 40px;
  border: 3px solid #f0b400;
  border-radius: 15px;
  text-align: center;
  display: none;
  pointer-events: auto;
  z-index: 10;
}

#name-modal {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at top, rgba(255, 214, 102, 0.06), transparent 34%),
    rgba(4, 5, 10, 0.88);
  pointer-events: auto;
  padding: 18px;
  box-sizing: border-box;
}

.name-card {
  min-width: 280px;
  padding: 14px 14px 12px;
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(14, 16, 24, 0.97), rgba(8, 10, 16, 0.98));
  border: 1px solid rgba(255, 204, 84, 0.42);
  box-shadow:
    0 18px 55px rgba(0, 0, 0, 0.42),
    inset 0 1px 0 rgba(255, 255, 255, 0.04);
  text-align: center;
}

.lobby-card {
  width: min(480px, calc(100vw - 220px));
  max-height: calc(100vh - 36px);
  overflow: hidden;
}

.name-card h2 {
  margin: 0 0 8px;
  color: #ffd54f;
  font-size: 14px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.lobby-copy {
  margin: 0 0 8px;
  color: #b9c1d0;
  font-size: 11px;
  line-height: 1.4;
}

.wallet-panel {
  display: none;
  gap: 8px;
  margin-bottom: 10px;
}

.wallet-status {
  min-height: 16px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid rgba(255, 204, 84, 0.16);
  background: rgba(255, 255, 255, 0.04);
  color: #f5f0dd;
  font-size: 11px;
  line-height: 1.35;
}

.wallet-status.is-connected {
  border-color: rgba(88, 214, 141, 0.24);
  color: #dff9ea;
}

.wallet-connect {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid rgba(255, 204, 84, 0.26);
  border-radius: 10px;
  background: rgba(255, 204, 84, 0.08);
  color: #ffe49a;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.wallet-connect:disabled {
  opacity: 0.72;
  cursor: wait;
}

.arena-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 8px;
  align-items: stretch;
}

.arena-card {
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: linear-gradient(180deg, rgba(22, 24, 34, 0.96), rgba(15, 17, 26, 0.96));
  border-radius: 14px;
  padding: 9px 10px 8px;
  text-align: left;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
  min-height: 68px;
  box-sizing: border-box;
}

.arena-card.guest-market {
  border-color: rgba(82, 225, 183, 0.2);
  background: linear-gradient(180deg, rgba(14, 34, 31, 0.96), rgba(10, 24, 23, 0.96));
}

.arena-card.wallet-market {
  border-color: rgba(255, 204, 84, 0.16);
}

.arena-card:hover {
  transform: translateY(-1px);
  border-color: rgba(255, 204, 84, 0.32);
  background: linear-gradient(180deg, rgba(24, 27, 38, 0.98), rgba(17, 19, 28, 0.98));
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.18);
}

.arena-card.selected {
  border-color: rgba(255, 204, 84, 0.9);
  background: linear-gradient(180deg, rgba(36, 30, 18, 0.98), rgba(24, 21, 14, 0.98));
  box-shadow:
    0 0 0 1px rgba(255, 213, 79, 0.18) inset,
    0 10px 18px rgba(0, 0, 0, 0.24);
}

.arena-card.guest-market.selected {
  border-color: rgba(82, 225, 183, 0.88);
  background: linear-gradient(180deg, rgba(17, 49, 42, 0.98), rgba(10, 31, 28, 0.98));
  box-shadow:
    0 0 0 1px rgba(82, 225, 183, 0.16) inset,
    0 10px 18px rgba(0, 0, 0, 0.24);
}

.arena-card.full {
  opacity: 0.55;
  cursor: not-allowed;
}

.arena-name {
  font-weight: 700;
  color: #f5f7fb;
  margin-bottom: 2px;
  font-size: 12px;
}

.arena-meta {
  font-size: 10px;
  color: #b8c0cf;
  line-height: 1.2;
}

.access-label {
  margin-top: 2px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.guest-market .access-label {
  color: #7df0cb;
}

.wallet-market .access-label {
  color: #ffd875;
}

.arena-pill {
  display: inline-block;
  margin-top: 5px;
  padding: 2px 6px;
  border-radius: 999px;
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.arena-pill.open {
  background: rgba(38, 190, 122, 0.16);
  color: #8ee2b0;
}

.arena-pill.guest {
  background: rgba(57, 179, 145, 0.24);
  color: #92f2d8;
}

.arena-pill.busy {
  background: rgba(255, 187, 72, 0.14);
  color: #ffd27d;
}

.arena-pill.full {
  background: rgba(255, 93, 93, 0.14);
  color: #ffb0b0;
}

.selected-arena {
  margin-bottom: 8px;
  min-height: 14px;
  font-size: 10px;
  color: #ffd54f;
  opacity: 0.92;
}

#name-input {
  width: 100%;
  box-sizing: border-box;
  padding: 8px 10px;
  margin-bottom: 8px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.05);
  color: #f5f7fb;
  font-size: 12px;
}

#name-input:focus {
  outline: none;
  border-color: rgba(255, 204, 84, 0.7);
  box-shadow: 0 0 0 3px rgba(255, 204, 84, 0.12);
}

#name-submit {
  width: 100%;
  padding: 8px 12px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(180deg, #f0be3b, #d89a00);
  color: #221400;
  font-size: 12px;
  font-weight: bold;
  cursor: pointer;
  box-shadow:
    inset 0 1px 0 rgba(255, 246, 219, 0.4),
    0 8px 18px rgba(160, 112, 0, 0.22);
}

#name-submit:disabled,
#name-input:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

#game-over h1 {
  margin-top: 0;
  color: #ffd54f;
}

#game-over h2 {
  color: #ff3333;
  margin: 5px 0 20px;
  font-size: 18px;
}

#restart-btn {
  margin-top: 20px;
  padding: 12px 30px;
  font-size: 20px;
  font-weight: bold;
  background: linear-gradient(45deg, #c58a00, #ffd54f);
  color: #241600;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  pointer-events: auto;
}

.mobile-only {
  display: none;
}

.hidden {
  display: none;
}

@media (max-width: 768px) {
  #header {
    padding: 12px 12px 0;
    display: block;
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0.78), transparent 82%);
  }

  #meta-panel {
    left: 110px;
    right: 12px;
    bottom: 18px;
    top: auto;
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    align-items: center;
    font-size: 9px;
    background: transparent;
    border: 0;
    border-radius: 0;
    padding: 0;
    max-width: none;
    box-sizing: border-box;
    overflow: hidden;
    z-index: 5;
  }

  #score-wrap {
    min-width: 0;
    gap: 6px;
    max-width: calc(100vw - 126px);
  }

  #score-board {
    font-size: 16px;
    line-height: 1;
    letter-spacing: 0.01em;
  }

  .market-event {
    max-width: calc(100vw - 136px);
    padding: 5px 9px;
    font-size: 9px;
    line-height: 1.2;
    border-radius: 999px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  #beta-tag {
    display: none;
  }

  .network-indicator {
    display: block;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    padding: 4px 8px;
    font-size: 9px;
    line-height: 1;
    z-index: 7;
  }

  #hud-top-right {
    top: 12px;
    right: 12px;
    gap: 6px;
    align-items: stretch;
    z-index: 6;
    width: 96px;
  }

  #status {
    max-width: 100%;
    padding: 5px 6px;
    font-size: 7px;
    line-height: 1.1;
    white-space: normal;
    text-align: center;
    border-radius: 999px;
    backdrop-filter: none;
  }

  .hud-chip {
    min-width: 74px;
    padding: 6px 8px;
    font-size: 8px;
    border-radius: 999px;
    backdrop-filter: none;
  }

  #audio-toggle {
    min-width: 34px;
    width: 34px;
    height: 34px;
    padding: 0;
    display: grid;
    place-items: center;
    font-size: 15px;
    line-height: 1;
  }

  .mobile-hud-toggle,
  .mobile-help-toggle {
    display: block;
  }

  .leaderboard {
    width: 148px;
    max-height: 136px;
    overflow: hidden;
    padding: 8px 8px;
    font-size: 8px;
    line-height: 1.16;
    border-radius: 12px;
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.28);
    align-self: flex-end;
    backdrop-filter: none;
  }

  .leaderboard.mobile-collapsed {
    display: none;
  }

  .leader-title {
    font-size: 9px;
    margin-bottom: 3px;
  }

  .leader-row {
    margin-top: 2px;
  }

  #instructions {
    right: 12px;
    top: 142px;
    bottom: auto;
    max-width: 152px;
    padding: 8px 9px;
    font-size: 8px;
    line-height: 1.25;
    border-radius: 10px;
    background: rgba(8, 8, 16, 0.54);
    box-shadow: 0 10px 22px rgba(0, 0, 0, 0.24);
    backdrop-filter: none;
  }

  #instructions.mobile-collapsed {
    display: none;
  }

  .mobile-help-toggle {
    min-width: 34px;
    width: 34px;
    height: 34px;
    padding: 0;
    display: grid;
    place-items: center;
    font-size: 14px;
    line-height: 1;
  }

  .arena-list {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .joystick {
    display: block;
    left: 12px;
    bottom: 12px;
    width: 88px;
    height: 88px;
    backdrop-filter: none;
  }

  .joystick-thumb {
    width: 30px;
    height: 30px;
    margin-left: -15px;
    margin-top: -15px;
  }

  .lobby-card {
    width: min(100%, 320px);
    padding: 12px 12px 10px;
    max-height: calc(100vh - 16px);
  }

  .name-card h2 {
    font-size: 13px;
    margin-bottom: 6px;
  }

  .lobby-copy,
  .selected-arena {
    font-size: 10px;
  }

  .wallet-status,
  .wallet-connect {
    font-size: 10px;
  }

  .arena-card {
    min-height: 62px;
    padding: 8px;
  }

  .arena-name {
    font-size: 11px;
  }

  .arena-meta {
    font-size: 9px;
  }

  #name-input,
  #name-submit {
    font-size: 11px;
  }

  .mobile-only {
    display: block;
  }

  .meta {
    margin-top: 0;
    white-space: nowrap;
    padding: 4px 8px;
    border-radius: 999px;
    background: rgba(8, 8, 16, 0.58);
    border: 1px solid rgba(255, 210, 90, 0.15);
  }
}
