* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  background: #0f172a;
}

#game-canvas {
  position: fixed;
  inset: 0;
  touch-action: none;
}

#virtual-joystick {
  position: fixed;
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.22);
  border: 2px solid rgba(255, 255, 255, 0.55);
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 20;
}

#joystick-knob {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

.hud-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  padding: 12px;
  z-index: 10;
}

.hud-layer button,
.hud-layer a {
  pointer-events: auto;
  cursor: pointer;
  font-family: inherit;
}

.hud-top {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  flex-wrap: nowrap;
}

.pill-btn {
  height: 42px;
  padding: 0 11px;
  border-radius: 14px;
  border: 1px solid #e2e8f0;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 3px 0 #cbd5e1, 0 8px 16px rgba(0, 0, 0, 0.18);
  font-size: 13px;
  font-weight: 800;
  color: #1e293b;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  white-space: nowrap;
  transition: transform 0.1s;
}
.pill-btn:active { transform: translateY(2px); }

.level-card {
  flex: 1;
  min-width: 0;
  background: rgba(255, 255, 255, 0.94);
  border-radius: 16px;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
}

.level-badge {
  background: #16a34a;
  color: #ffffff;
  font-weight: 800;
  font-size: 12px;
  padding: 6px 8px;
  border-radius: 10px;
  white-space: nowrap;
}

.level-meta {
  flex: 1;
  min-width: 0;
}

.level-title {
  font-weight: 700;
  font-size: 13px;
  color: #0f172a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
}

.progress-bar {
  position: relative;
  height: 16px;
  background: #e5e7eb;
  border-radius: 99px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.progress-fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 0%;
  background: #10b981;
  transition: width 0.2s ease;
}

.progress-text {
  position: relative;
  font-size: 11px;
  font-weight: 800;
  color: #064e3b;
}

.wallet-card {
  background: rgba(255, 255, 255, 0.94);
  border-radius: 16px;
  padding: 6px 12px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
  text-align: right;
  white-space: nowrap;
}

.coins-row {
  font-weight: 800;
  font-size: 15px;
  color: #b45309;
}

.bag-row {
  font-size: 11.5px;
  font-weight: 800;
  color: #047857;
}

.hud-sub {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 8px;
}

.inv-pill {
  padding: 6px 12px;
  border-radius: 99px;
  border: 2px solid #94a3b8;
  background: #f1f5f9;
  font-size: 12px;
  font-weight: 800;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
}

.level-nav {
  display: flex;
  gap: 6px;
  align-items: center;
}

.mini-chip {
  padding: 6px 10px;
  border-radius: 99px;
  border: none;
  background: rgba(255, 255, 255, 0.92);
  color: #334155;
  font-size: 11.5px;
  font-weight: 800;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.15);
}
.mini-chip.active {
  background: #10b981;
  color: #ffffff;
}
.mini-chip:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.hud-banners {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.next-banner {
  align-self: flex-end;
  background: #10b981;
  color: #ffffff;
  border: none;
  border-radius: 99px;
  padding: 8px 16px;
  font-weight: 800;
  font-size: 13px;
  box-shadow: 0 6px 16px rgba(16, 185, 129, 0.45);
}

.toast-banner {
  background: #facc15;
  color: #ffffff;
  font-weight: 800;
  font-size: 12.5px;
  padding: 7px 16px;
  border-radius: 99px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.28);
}
.toast-banner.warn {
  background: #f97316;
}

.controls-hint {
  margin-top: auto;
  align-self: center;
  background: rgba(15, 23, 42, 0.55);
  color: rgba(255, 255, 255, 0.88);
  padding: 4px 12px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  margin-bottom: 6px;
}

.hud-bottom {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 680px;
  width: 100%;
  margin: 0 auto;
}

.robot-row {
  display: flex;
  justify-content: flex-end;
}

.robot-pill {
  border: none;
  border-radius: 99px;
  padding: 7px 14px;
  color: #ffffff;
  font-size: 12px;
  font-weight: 800;
  background: #64748b;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}
.robot-pill:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.upgrade-bar {
  background: rgba(255, 255, 255, 0.94);
  border-radius: 16px;
  padding: 6px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
}

.upg-btn {
  border: 1.5px solid #e5e7eb;
  border-radius: 12px;
  padding: 6px 4px;
  background: #ffffff;
  box-shadow: 0 3px 0 #cbd5e1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  opacity: 0.55;
  transition: transform 0.1s;
}
.upg-btn.can-buy {
  opacity: 1;
  background: #f0fdf4;
  border-color: #34d399;
  box-shadow: 0 3px 0 #059669;
}
.upg-btn.highlight {
  background: #fff7ed;
  border-color: #f97316;
  box-shadow: 0 3px 0 #ea580c;
}
.upg-btn:active:not(:disabled) { transform: translateY(2px); }
.upg-btn:disabled { cursor: not-allowed; }

.upg-top {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
}
.upg-lvl {
  background: #e2e8f0;
  color: #1e293b;
  font-size: 10px;
  font-weight: 800;
  padding: 1px 5px;
  border-radius: 6px;
}
.upg-name {
  font-size: 11px;
  font-weight: 800;
  color: #0f172a;
}
.upg-cost-pill {
  background: #fef3c7;
  color: #b45309;
  font-size: 10.5px;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 99px;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}
.modal-backdrop.hidden { display: none; }

.modal-box {
  background: #ffffff;
  border-radius: 22px;
  padding: 18px;
  width: 100%;
  max-width: 520px;
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
}
.modal-box.small { max-width: 420px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.modal-header h3 { font-size: 17px; font-weight: 800; color: #0f172a; }
.modal-close {
  border: none;
  background: #f1f5f9;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-weight: 800;
  cursor: pointer;
}
.modal-sub { font-size: 12.5px; color: #64748b; margin-bottom: 12px; line-height: 1.5; }

.level-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  overflow-y: auto;
  padding: 4px 0;
}
.level-cell {
  padding: 10px 4px;
  border-radius: 12px;
  border: none;
  background: #f1f5f9;
  color: #1e293b;
  font-weight: 800;
  font-size: 13px;
  cursor: pointer;
}
.level-cell.active { background: #10b981; color: #ffffff; }
.level-cell:disabled { background: #e2e8f0; color: #94a3b8; cursor: not-allowed; }

.inventory-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
}
.inv-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 14px;
  border-style: solid;
}
.inv-emoji { font-size: 28px; }
.inv-info { flex: 1; min-width: 0; }
.inv-name { font-weight: 800; font-size: 13px; }
.inv-aff { font-size: 11.5px; font-weight: 700; color: #334155; }
.inv-stats { font-size: 11px; color: #475569; }
.inv-actions { display: flex; flex-direction: column; gap: 4px; align-items: flex-end; }
.btn-equip {
  background: #10b981;
  color: #ffffff;
  border: none;
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 11.5px;
  font-weight: 700;
  cursor: pointer;
}
.btn-equip:disabled { background: #94a3b8; cursor: default; }
.btn-sell {
  background: transparent;
  border: none;
  color: #b45309;
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
}

.online-status-box {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
}
.badge-soon {
  background: #fef3c7;
  color: #b45309;
  font-weight: 800;
  font-size: 11.5px;
  padding: 4px 10px;
  border-radius: 99px;
}

.feedback-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.feedback-form input,
.feedback-form textarea {
  border: 1.5px solid #e2e8f0;
  border-radius: 12px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 13.5px;
  user-select: text;
  -webkit-user-select: text;
}
.btn-primary {
  background: #10b981;
  color: #ffffff;
  border: none;
  border-radius: 12px;
  padding: 11px;
  font-weight: 800;
  cursor: pointer;
}
.feedback-status { font-size: 12.5px; color: #059669; font-weight: 700; }

@media (max-width: 600px) {
  .controls-hint { display: none; }
  .pill-btn { padding: 0 8px; font-size: 12px; height: 38px; }
  .level-card { padding: 6px 8px; }
}
