body {
  margin: 0;
  overflow: hidden;
  background-color: #050510;
  color: white;
  font-family: "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: 15px 20px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.9), transparent);
}

#score-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#score-board {
  font-size: 24px;
  font-weight: bold;
  text-shadow: 0 0 10px rgba(255, 204, 64, 0.6);
}

.market-event {
  max-width: min(320px, calc(100vw - 40px));
  padding: 7px 11px;
  border-radius: 12px;
  background: rgba(8, 8, 16, 0.72);
  border: 1px solid rgba(255, 210, 90, 0.18);
  color: #ffe8ab;
  font-size: 11px;
  line-height: 1.3;
}

#beta-tag {
  position: absolute;
  top: 14px;
  left: 190px;
  padding: 2px 8px;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 700;
  color: #ffd74f;
  background: rgba(255, 176, 0, 0.15);
  border: 1px solid rgba(255, 220, 120, 0.26);
  box-shadow: 0 0 12px rgba(255, 200, 60, 0.22);
  z-index: 2;
}

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

#status {
  max-width: min(220px, calc(100vw - 32px));
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(8, 8, 16, 0.7);
  border: 1px solid rgba(255, 210, 90, 0.2);
  backdrop-filter: blur(6px);
  font-size: 11px;
  line-height: 1.2;
  color: #fff4cf;
  text-align: right;
}

.hud-chip {
  pointer-events: auto;
  min-width: 92px;
  padding: 7px 12px;
  border: 1px solid rgba(255, 210, 90, 0.22);
  border-radius: 999px;
  background: rgba(8, 8, 16, 0.72);
  color: #fff4cf;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-align: center;
  cursor: pointer;
  backdrop-filter: blur(6px);
}

.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;
}

#instructions {
  position: absolute;
  right: 20px;
  bottom: 16px;
  max-width: min(280px, calc(100vw - 180px));
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(8, 8, 16, 0.66);
  border: 1px solid rgba(255, 210, 90, 0.18);
  backdrop-filter: blur(6px);
  font-size: 11px;
  line-height: 1.5;
  color: #e6ddc2;
  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: 20px;
  bottom: 16px;
  font-size: 14px;
  color: #ddd;
  text-shadow: 0 0 8px rgba(0, 0, 0, 0.7);
}

.meta {
  margin-top: 4px;
}

.leaderboard {
  width: min(220px, calc(100vw - 32px));
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(8, 8, 16, 0.62);
  border: 1px solid rgba(255, 210, 90, 0.2);
  backdrop-filter: blur(6px);
  font-size: 11px;
  line-height: 1.35;
  color: #fff4cf;
  text-align: right;
}

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

.leader-title {
  margin-bottom: 4px;
  color: #ffd54f;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.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;
}

.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: grid;
  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: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.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;
}

.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.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 {
    top: 76px;
    left: 12px;
    right: 96px;
    bottom: auto;
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    align-items: flex-start;
    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 - 96px);
  }

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

  .market-event {
    max-width: calc(100vw - 24px);
    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;
  }

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

  #status {
    max-width: 78px;
    padding: 4px 5px;
    font-size: 8px;
    line-height: 1.1;
    white-space: normal;
    text-align: center;
  }

  .hud-chip {
    min-width: 74px;
    padding: 6px 8px;
    font-size: 8px;
  }

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

  .leaderboard {
    width: 144px;
    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);
  }

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

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

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

  #instructions {
    right: 12px;
    bottom: 52px;
    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);
  }

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

  .mobile-help-toggle {
    position: absolute;
    right: 12px;
    bottom: 12px;
    z-index: 9;
    min-width: 74px;
  }

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

  .joystick {
    left: 12px;
    bottom: 12px;
    width: 88px;
    height: 88px;
  }

  .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);
  }
}
