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

body {
  background: #1a1a2e;
  color: #e0e0e0;
  font-family: 'Segoe UI', sans-serif;
  overflow: hidden;
  height: 100vh; /* fallback */
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* Top Bar */
#top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  background: #16213e;
  border-bottom: 2px solid #0f3460;
  z-index: 100;
  height: 44px;
}
.top-left { display: flex; align-items: center; gap: 16px; }
.top-center { flex: 1; display: flex; justify-content: center; align-items: center; min-width: 0; overflow: hidden; }
.top-right { display: flex; align-items: center; gap: 16px; font-size: 13px; }
.back-link {
  color: #e94560;
  text-decoration: none;
  font-weight: bold;
  font-size: 14px;
}
.back-link:hover { color: #ff6b81; }
.town-title {
  font-size: 18px;
  font-weight: bold;
  color: #f5c542;
  text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
}
#player-count {
  color: #4ecca3;
  font-weight: bold;
}
#wallet-display {
  color: #aaa;
  max-width: 480px;
  overflow: hidden;
  text-align: center;
  cursor: pointer;
  line-height: 1.3;
}
.wallet-addr { font-size: 12px; display: block; }
.wallet-bals { font-size: 10px; display: block; margin-top: 1px; }

/* Game Container */
#game-container {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  background: #0a0a1a;
}
#game-container canvas {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* Interaction Panel */
.panel {
  position: fixed;
  right: 12px;
  top: 56px;
  width: 320px;
  max-height: calc(100vh - 68px);
  background: #16213e;
  border: 2px solid #0f3460;
  border-radius: 8px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}
.hidden { display: none !important; }
.panel.hidden { display: none !important; }
.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  background: #0f3460;
  border-radius: 6px 6px 0 0;
  font-weight: bold;
  color: #f5c542;
}
.panel-header button {
  background: none;
  border: none;
  color: #e94560;
  font-size: 18px;
  cursor: pointer;
}
#panel-content {
  padding: 12px;
  overflow-y: auto;
  flex: 1;
}

/* Listing items in panel */
.listing-item {
  background: #1a1a3e;
  border: 1px solid #0f3460;
  border-radius: 6px;
  padding: 10px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: border-color 0.2s;
}
.listing-item:hover {
  border-color: #4ecca3;
}
.listing-type {
  font-weight: bold;
  font-size: 13px;
}
.listing-type.sell { color: #e94560; }
.listing-type.buy { color: #4ecca3; }
.listing-price { color: #f5c542; font-size: 12px; margin-top: 4px; }
.listing-range { color: #888; font-size: 11px; }
.listing-addr { color: #666; font-size: 10px; margin-top: 4px; }

/* Modal */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 500;
}
.modal-overlay.hidden { display: none; }
.modal-box {
  background: #16213e;
  border: 2px solid #0f3460;
  border-radius: 10px;
  width: 400px;
  max-width: 90vw;
  max-height: 80vh;
  overflow-y: auto;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: #0f3460;
  border-radius: 8px 8px 0 0;
  font-weight: bold;
  color: #f5c542;
}
.modal-header button {
  background: none;
  border: none;
  color: #e94560;
  font-size: 18px;
  cursor: pointer;
}
#modal-content { padding: 16px; }

/* Controls Help */
#controls-help {
  position: fixed;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 12px;
  flex-wrap: nowrap;
  white-space: nowrap;
  background: rgba(22, 33, 62, 0.85);
  padding: 5px 14px;
  border-radius: 20px;
  font-size: 11px;
  color: #888;
  z-index: 100;
  max-width: calc(100vw - 40px);
}
#controls-help span { white-space: nowrap; }

/* Player bubble */
.player-bubble {
  font-size: 11px;
  color: #f5c542;
  font-weight: bold;
  text-shadow: 1px 1px 2px #000;
}

/* Buttons */
.btn {
  padding: 8px 16px;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-size: 13px;
  font-weight: bold;
}
.btn-primary { background: #4ecca3; color: #000; }
.btn-primary:hover { background: #3db892; }
.btn-danger { background: #e94560; color: #fff; }
.btn-danger:hover { background: #d63851; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* Form in modal */
.form-group { margin-bottom: 12px; }
.form-group label { display: block; font-size: 12px; color: #aaa; margin-bottom: 4px; }
.form-group input, .form-group select {
  width: 100%;
  padding: 8px;
  background: #1a1a3e;
  border: 1px solid #0f3460;
  border-radius: 4px;
  color: #e0e0e0;
  font-size: 13px;
}
.form-group input:focus, .form-group select:focus {
  outline: none;
  border-color: #4ecca3;
}

/* NPC indicator */
.npc-glow {
  animation: npcPulse 2s ease-in-out infinite;
}
@keyframes npcPulse {
  0%, 100% { opacity: 0.8; }
  50% { opacity: 1; }
}

/* Panel Tabs */
.panel-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 10px;
}
.tab-btn {
  flex: 1;
  padding: 6px 8px;
  background: #1a1a3e;
  border: 1px solid #0f3460;
  border-radius: 4px;
  color: #888;
  font-size: 12px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.2s;
}
.tab-btn.active {
  background: #0f3460;
  color: #f5c542;
  border-color: #4ecca3;
}
.tab-btn:hover:not(.active) {
  color: #ccc;
}

/* Listing item own marker */
.listing-item.own {
  border-color: #f5c542;
  opacity: 0.8;
}
.listing-item.own:hover {
  border-color: #e94560;
}

/* Trade status badges */
.trade-badge {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 3px;
  font-weight: bold;
}
.trade-badge.active {
  background: #0f3460;
  color: #4ecca3;
}
.trade-badge.done {
  background: #1a3d2e;
  color: #4ecca3;
}
.trade-badge.cancelled {
  background: #3d1a1a;
  color: #e94560;
}

/* Swap Steps */
.swap-steps {
  display: flex;
  gap: 4px;
  margin: 12px 0;
}
.swap-step {
  flex: 1;
  text-align: center;
  font-size: 9px;
  padding: 6px 2px;
  border-radius: 4px;
  background: #1a1a3e;
  color: #555;
  border: 1px solid #0f3460;
}
.swap-step.active {
  background: #0f3460;
  color: #f5c542;
  border-color: #f5c542;
}
.swap-step.done {
  background: #1a3d2e;
  color: #4ecca3;
  border-color: #4ecca3;
}
.step-num {
  display: block;
  font-size: 14px;
  font-weight: bold;
  margin-bottom: 2px;
}

/* Action box */
.action-box {
  background: #0f3460;
  border: 1px solid #4ecca3;
  border-radius: 6px;
  padding: 12px;
  margin: 10px 0;
}
.action-box h4 {
  color: #f5c542;
  font-size: 13px;
  margin-bottom: 6px;
}

/* Info box */
.info-box {
  background: #1a1a3e;
  border: 1px solid #0f3460;
  border-radius: 6px;
  padding: 10px;
  margin-bottom: 10px;
}

/* Scrollbar */
#panel-content::-webkit-scrollbar,
#modal-content::-webkit-scrollbar,
#townChatMessages::-webkit-scrollbar {
  width: 4px;
}
#panel-content::-webkit-scrollbar-thumb,
#modal-content::-webkit-scrollbar-thumb,
#townChatMessages::-webkit-scrollbar-thumb {
  background: #0f3460;
  border-radius: 2px;
}

/* Town Disclaimer Modal */
.disclaimer-modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.92);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 10000;
}
.disclaimer-modal-content {
  background: #16213e;
  border: 2px solid #0f3460;
  border-radius: 12px;
  padding: 28px;
  max-width: 560px;
  width: 90vw;
  max-height: 90vh;
  overflow-y: auto;
}
.disclaimer-modal-content h2 {
  color: #f5c542;
  font-size: 18px;
  margin-bottom: 16px;
}
.disclaimer-text {
  color: #ccc;
  font-size: 13px;
  line-height: 1.6;
}
.disclaimer-text ul {
  padding-left: 20px;
  margin: 10px 0;
}
.disclaimer-text li {
  margin-bottom: 6px;
}
.disclaimer-text .warning-text {
  color: #e94560;
  font-weight: bold;
  margin-top: 12px;
}
.disclaimer-checkbox {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 16px 0;
  cursor: pointer;
  font-size: 13px;
  color: #aaa;
}
.disclaimer-checkbox input[type="checkbox"] {
  margin-top: 3px;
  min-width: 16px;
}
.disclaimer-enter-btn {
  width: 100%;
  padding: 12px;
  font-size: 15px;
}
.disclaimer-enter-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ========== Mobile Controls ========== */
#mobile-controls {
  display: none;
  position: fixed;
  bottom: 0;
  bottom: env(safe-area-inset-bottom, 0px);
  left: 0;
  right: 0;
  height: 180px;
  pointer-events: none;
  z-index: 150;
}

#joystick-base {
  position: absolute;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  left: 20px;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  border: 2px solid rgba(255, 255, 255, 0.2);
  pointer-events: auto;
  touch-action: none;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
}

#joystick-stick {
  position: absolute;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.3);
  border: 2px solid rgba(255, 255, 255, 0.45);
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

#mobile-action-btn {
  position: absolute;
  bottom: calc(36px + env(safe-area-inset-bottom, 0px));
  right: 24px;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: rgba(78, 204, 163, 0.15);
  border: 2px solid rgba(78, 204, 163, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255, 255, 255, 0.7);
  font-weight: bold;
  font-size: 13px;
  font-family: Arial, sans-serif;
  pointer-events: auto;
  touch-action: none;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
}

#mobile-action-btn.active {
  background: rgba(78, 204, 163, 0.45);
  border-color: rgba(78, 204, 163, 0.8);
}

/* Prevent canvas zoom/scroll on mobile */
#game-container canvas {
  touch-action: none;
}

/* ======================== Market Price Panel ======================== */
#market-panel {
  position: fixed;
  top: 54px;
  left: 12px;
  width: 188px;
  background: rgba(13, 22, 50, 0.93);
  border: 1px solid #1a3060;
  border-radius: 8px;
  z-index: 150;
  font-size: 12px;
  color: #c0c8e0;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
  overflow: hidden;
}
.market-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 10px;
  background: rgba(20, 40, 90, 0.95);
  cursor: pointer;
  font-weight: bold;
  font-size: 12px;
  color: #f5c542;
  user-select: none;
  letter-spacing: 0.5px;
}
.market-panel-header:hover { background: rgba(30, 55, 110, 0.95); }
#market-panel-toggle-icon { font-size: 14px; color: #aaa; line-height: 1; }
.market-panel-body {
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow: hidden;
  max-height: 400px;
  transition: max-height 0.3s ease, padding 0.3s ease, opacity 0.3s ease;
  opacity: 1;
}
#market-panel.collapsed .market-panel-body {
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  opacity: 0;
}
.mp-section { display: flex; flex-direction: column; gap: 2px; }
.mp-coin { font-size: 10px; color: #7888aa; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 1px; }
.mp-price { font-size: 15px; font-weight: bold; color: #e8eaf6; line-height: 1.2; }
.mp-usd { font-size: 11px; color: #7bafd4; }
.mp-change { font-size: 11px; font-weight: bold; }
.mp-change.up { color: #4ecca3; }
.mp-change.down { color: #e94560; }
.mp-divider { height: 1px; background: rgba(255,255,255,0.07); margin: 4px 0; }
.mp-row { display: flex; justify-content: space-between; font-size: 10px; margin-top: 2px; }
.mp-row span:last-child { color: #c0c8e0; }
.mp-label { color: #7888aa; }
.mp-footer { font-size: 9px; color: #445566; text-align: right; margin-top: 2px; }

/* ======================== Town Global Chat ======================== */
#town-chat {
  position: fixed;
  left: 12px;
  bottom: 40px;
  width: 380px;
  max-height: 354px;
  display: flex;
  flex-direction: column;
  pointer-events: none;
  z-index: 100;
  overflow: visible;
}

#town-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 8px 10px;
  background: transparent;
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  scrollbar-width: none;
  -ms-overflow-style: none;
  mask-image: linear-gradient(to bottom, transparent 0%, black 20%);
  -webkit-mask-image: linear-gradient(to bottom, transparent 0%, black 20%);
  transition: background 0.8s ease;
}
#town-chat-messages.chat-active {
  background: rgba(10, 10, 30, 0.65);
}
#town-chat-messages::-webkit-scrollbar { display: none; }

.town-chat-line {
  font-size: 12px;
  line-height: 1.4;
  text-shadow: 1px 1px 3px rgba(0,0,0,0.9), 0 0 6px rgba(0,0,0,0.7);
  animation: chatFadeIn 0.3s ease;
}
.town-chat-line .chat-name { font-weight: bold; margin-right: 6px; }
.town-chat-line .chat-text { color: #e8e8e8; }
.chat-tl-btn {
  background: none; border: none; cursor: pointer; font-size: 11px;
  opacity: 0.45; padding: 0 2px; vertical-align: middle; line-height: 1;
  transition: opacity 0.15s; pointer-events: auto;
}
.chat-tl-btn:hover { opacity: 1; }
.chat-tl-result {
  display: block; font-size: 10px; color: #8ecfc4; padding: 1px 0 2px 6px;
  line-height: 1.3; word-break: break-word; min-height: 0;
}

@keyframes chatFadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

#town-chat-input-row {
  pointer-events: auto;
  padding: 4px 0 0;
  display: flex;
  gap: 4px;
  align-items: center;
}

#town-chat-input {
  flex: 1;
  padding: 6px 10px;
  background: rgba(10, 10, 30, 0.82);
  border: 1px solid rgba(78, 204, 163, 0.55);
  border-radius: 4px;
  color: #e0e0e0;
  font-size: 12px;
  outline: none;
  opacity: 0.75;
  transition: opacity 0.2s, border-color 0.2s, background 0.2s, box-shadow 0.2s;
}
#town-chat-input:focus {
  opacity: 1;
  background: rgba(10, 10, 30, 0.92);
  border-color: rgba(78, 204, 163, 0.9);
  box-shadow: 0 0 0 2px rgba(78, 204, 163, 0.18);
}
#town-chat-input::placeholder { color: #555; }

#town-chat-send-btn {
  flex-shrink: 0;
  padding: 5px 10px;
  background: rgba(78, 204, 163, 0.2);
  border: 1px solid rgba(78, 204, 163, 0.5);
  border-radius: 4px;
  color: #4ecca3;
  font-size: 13px;
  cursor: pointer;
  pointer-events: auto;
  transition: background 0.15s;
  line-height: 1;
}
#town-chat-send-btn:hover { background: rgba(78, 204, 163, 0.4); }
#town-chat-send-btn:active { background: rgba(78, 204, 163, 0.6); }

@media (max-width: 600px) {
  #top-bar { height: auto; min-height: 44px; padding: 4px 8px; }
  .top-left { gap: 8px; }
  .town-title { font-size: 14px; }
  .back-link { font-size: 12px; }
  .top-right { gap: 6px; font-size: 11px; }
  #player-count { display: none; }
  .wallet-addr { font-size: 11px; }
  .wallet-bals { font-size: 9px; }
  #town-chat { width: calc(100% - 24px); bottom: calc(120px + env(safe-area-inset-bottom, 0px)); left: 12px; }
  #town-chat-messages { max-height: 120px; }
  #emoji-bar { position: fixed !important; left: 50% !important; bottom: calc(300px + env(safe-area-inset-bottom, 0px)) !important; transform: translateX(-50%) !important; width: 300px !important; grid-template-columns: repeat(10, 1fr) !important; border-radius: 10px !important; box-shadow: 0 -4px 20px rgba(0,0,0,0.6) !important; background: rgba(10,20,40,0.88) !important; padding: 8px !important; }
  /* Disclaimer modal compact for mobile */
  .disclaimer-modal-content { padding: 14px 14px 12px; max-height: 96dvh; max-height: 96vh; }
  .disclaimer-modal-content h2 { font-size: 14px; margin-bottom: 8px; }
  .disclaimer-text { font-size: 11px; line-height: 1.35; }
  .disclaimer-text ul { padding-left: 14px; margin: 5px 0; }
  .disclaimer-text li { margin-bottom: 3px; }
  .disclaimer-text .warning-text { font-size: 11px; margin-top: 6px; }
  .disclaimer-text p { margin: 4px 0; }
  .disclaimer-checkbox { font-size: 11px; margin: 8px 0; }
  .disclaimer-enter-btn { padding: 9px; font-size: 13px; }
}

/* ======================== Town Wallet Modal ======================== */
#town-wallet-modal .modal-box { padding: 0; overflow: hidden; }
#town-wallet-content { padding: 16px; display: flex; flex-direction: column; gap: 0; max-height: 80vh; overflow-y: auto; }
.tw-section { display: flex; flex-direction: column; gap: 8px; padding: 4px 0; }
.tw-coin-header { display: flex; justify-content: space-between; align-items: baseline; }
.tw-coin-name { font-size: 14px; font-weight: bold; color: #4ecca3; letter-spacing: 0.5px; }
.tw-balance { font-size: 20px; font-weight: bold; color: #f5c542; }
.tw-addr { font-size: 10px; color: #668; font-family: monospace; word-break: break-all; background: rgba(0,0,0,0.3); padding: 4px 8px; border-radius: 4px; }
.tw-divider { height: 1px; background: rgba(255,255,255,0.07); margin: 12px 0; }
.tw-send { display: flex; flex-direction: column; gap: 6px; }
.tw-send-title { font-size: 12px; color: #aaa; font-weight: bold; margin-top: 4px; }
.tw-send input { width: 100%; padding: 8px 10px; background: #0d1220; border: 1px solid #1a3060; border-radius: 6px; color: #e0e0e0; font-size: 13px; box-sizing: border-box; }
.tw-send input:focus { outline: none; border-color: #4ecca3; }
.tw-fee { font-size: 11px; color: #e94560; }
.tw-send-btn { margin-top: 2px; width: 100%; }
.tw-msg { font-size: 12px; padding: 6px 10px; border-radius: 4px; margin-top: 2px; }
.tw-msg.error { background: rgba(233,69,96,0.15); color: #e94560; border: 1px solid rgba(233,69,96,0.3); }
.tw-msg.success { background: rgba(78,204,163,0.15); color: #4ecca3; border: 1px solid rgba(78,204,163,0.3); }
.tw-nokey { font-size: 11px; color: #e94560; padding: 6px 8px; background: rgba(233,69,96,0.08); border-radius: 4px; }
.tw-actions { display: flex; gap: 6px; margin-top: 8px; }
.tw-act-btn { font-size: 11px !important; padding: 4px 10px !important; background: rgba(78,204,163,0.1); border: 1px solid rgba(78,204,163,0.3); color: #4ecca3; border-radius: 4px; cursor: pointer; }
.tw-act-btn:hover { background: rgba(78,204,163,0.2); }
.tw-import-box { display: flex; gap: 6px; margin-top: 6px; align-items: center; }
.tw-import-box input { flex: 1; padding: 6px 8px; background: #0d1b2a; border: 1px solid #2a3f5f; border-radius: 4px; color: #e8eaf0; font-size: 12px; }
.tw-import-box input:focus { outline: none; border-color: #4ecca3; }
.tw-backup { margin-top: 6px; padding: 8px; background: rgba(233,69,96,0.08); border: 1px solid rgba(233,69,96,0.2); border-radius: 4px; font-size: 11px; word-break: break-all; user-select: all; color: #f5c542; }
.tw-switch { margin-bottom: 4px; }
.tw-switch select { width: 100%; padding: 5px 8px; background: #0d1b2a; border: 1px solid #2a3f5f; border-radius: 4px; color: #e8eaf0; font-size: 12px; cursor: pointer; }
.tw-switch select:focus { outline: none; border-color: #4ecca3; }
/* Emoji bar */
#emoji-bar { position: absolute; left: calc(100% + 8px); bottom: 0; width: 200px; display: grid; grid-template-columns: repeat(5, 1fr); gap: 1px; background: rgba(10,20,40,0.75); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); border: 1px solid rgba(15,52,96,0.5); border-radius: 6px; padding: 8px; pointer-events: auto; align-items: center; box-shadow: 0 4px 16px rgba(0,0,0,0.4); }
#emoji-bar button { font-size: 18px; background: none; border: none; cursor: pointer; padding: 2px 4px; border-radius: 4px; transition: background 0.15s; }
#emoji-bar button:hover { background: rgba(255,255,255,0.15); }
#emoji-toggle-btn { background: none; border: none; font-size: 18px; cursor: pointer; padding: 2px 6px; flex-shrink: 0; }
#wallet-display { cursor: pointer; }
#wallet-display:hover { opacity: 0.8; }

/* ======================== Character Customizer ======================== */
#char-open-btn {
  background: none; border: none; font-size: 18px; cursor: pointer;
  padding: 2px 6px; border-radius: 4px; transition: background 0.15s;
}
#char-open-btn:hover { background: rgba(255,255,255,0.15); }

/* Preview canvas */
.char-preview-wrap {
  text-align: center;
  margin: 8px 0 12px;
}
#char-preview-canvas {
  width: 96px;
  height: 128px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  border: 2px solid rgba(78,204,163,0.4);
  border-radius: 6px;
  background: rgba(0,0,0,0.3);
}

/* Section row */
.char-section {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.char-label {
  font-size: 11px;
  color: #aaa;
  min-width: 52px;
  font-weight: bold;
  flex-shrink: 0;
}

/* Option buttons (type / hat / glasses) */
.char-opts {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.char-opt {
  font-size: 12px;
  padding: 4px 9px;
  background: rgba(78,204,163,0.07);
  border: 1px solid rgba(78,204,163,0.2);
  border-radius: 4px;
  color: #c0cce0;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.char-opt:hover { background: rgba(78,204,163,0.17); }
.char-opt.active {
  background: rgba(78,204,163,0.3);
  border-color: #4ecca3;
  color: #fff;
}

/* Color swatches */
.char-colors {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.char-color {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
}
.char-color:hover { transform: scale(1.15); }
.char-color.active {
  border-color: #4ecca3;
  box-shadow: 0 0 0 2px rgba(78,204,163,0.4);
}

/* ============ Mining Panel ============ */
#mine-open-btn {
  background: none;
  border: 1px solid #555;
  color: #f0f0f0;
  font-size: 16px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  transition: border-color 0.2s, background 0.2s;
}
#mine-open-btn:hover { border-color: #00d4ff; }
#mine-open-btn.mining-active {
  border-color: #4ecca3;
  background: rgba(78,204,163,0.15);
  animation: mine-pulse 2s infinite;
}
@keyframes mine-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(78,204,163,0.3); }
  50% { box-shadow: 0 0 8px 2px rgba(78,204,163,0.5); }
}
.mine-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 6px;
}
.mine-label {
  color: #8899aa;
  font-size: 12px;
  min-width: 80px;
}
.mine-val {
  color: #f0f0f0;
  font-size: 12px;
  text-align: right;
}
.mine-btn {
  flex: 1;
  padding: 8px 12px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: bold;
  transition: background 0.2s, opacity 0.2s;
}
.mine-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.mine-btn-start {
  background: linear-gradient(135deg, #00d4ff 0%, #0099dd 100%);
  color: #fff;
}
.mine-btn-start:hover:not(:disabled) {
  background: linear-gradient(135deg, #00e4ff 0%, #00aaee 100%);
}
.mine-btn-start.mining {
  background: linear-gradient(135deg, #ff6b6b 0%, #cc4444 100%);
}
.mine-btn-start.mining:hover {
  background: linear-gradient(135deg, #ff7b7b 0%, #dd5555 100%);
}

/* ======================== Combat HUD ======================== */
#combat-hud {
  position: fixed;
  top: 52px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 5000;
  pointer-events: auto;
}
#combat-hud.hidden { display: none; }

#combat-info {
  display: flex;
  gap: 8px;
  font-size: 12px;
  font-family: Arial, sans-serif;
  font-weight: bold;
  text-shadow: 0 1px 3px rgba(0,0,0,0.9);
  background: rgba(0,0,0,0.5);
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid rgba(78,204,163,0.25);
}
#level-display { color: #88ccff; }
#bit-display { color: #f5c542; }

#quick-drink {
  background: rgba(0,0,0,0.55);
  border: 1px solid rgba(78,204,163,0.4);
  border-radius: 6px;
  color: #fff;
  font-size: 12px;
  padding: 4px 8px;
  cursor: pointer;
  font-family: Arial, sans-serif;
  font-weight: bold;
  transition: background 0.2s;
  pointer-events: auto;
}
#quick-drink:hover:not(:disabled) { background: rgba(78,204,163,0.3); }
#quick-drink:disabled { opacity: 0.4; cursor: not-allowed; }

/* Hunt mode button */
#hunt-toggle-btn {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 6px;
  font-size: 18px;
  padding: 2px 6px;
  cursor: pointer;
  transition: all 0.3s;
}
#hunt-toggle-btn.hunt-active {
  background: rgba(229,69,96,0.3);
  border-color: #e94560;
  box-shadow: 0 0 8px rgba(229,69,96,0.5);
  animation: huntPulse 1.5s ease-in-out infinite;
}
@keyframes huntPulse {
  0%, 100% { box-shadow: 0 0 8px rgba(229,69,96,0.4); }
  50% { box-shadow: 0 0 16px rgba(229,69,96,0.8); }
}

/* Shop Modal */
.shop-balance {
  text-align: center;
  font-size: 16px;
  font-weight: bold;
  color: #f5c542;
  margin-bottom: 12px;
  padding: 8px;
  background: rgba(245,197,66,0.1);
  border-radius: 8px;
}
#shop-items { display: flex; flex-direction: column; gap: 8px; }
.shop-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  transition: background 0.2s;
}
.shop-item:hover { background: rgba(255,255,255,0.1); }
.shop-item-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.shop-item-name { font-size: 13px; font-weight: bold; color: #f0f0f0; }
.shop-item-desc { font-size: 11px; color: #888; }
.shop-item-price {
  font-size: 12px;
  font-weight: bold;
  color: #f5c542;
  white-space: nowrap;
}
.shop-buy-btn {
  background: linear-gradient(135deg, #00d4ff 0%, #0099dd 100%);
  border: none;
  color: #fff;
  padding: 5px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 11px;
  font-weight: bold;
  margin-left: 8px;
  transition: background 0.2s;
}
.shop-buy-btn:hover { background: linear-gradient(135deg, #00e4ff 0%, #00aaee 100%); }
.shop-tab-btn {
  flex: 1;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.15);
  color: #aaa;
  padding: 6px 0;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  font-weight: bold;
  transition: all 0.18s;
}
.shop-tab-btn.active {
  background: linear-gradient(135deg, #0f3f5a 0%, #0a2a40 100%);
  border-color: #00d4ff;
  color: #00d4ff;
}
.shop-tab-btn:hover:not(.active) { background: rgba(255,255,255,0.1); color: #ddd; }
.shop-item-equipped {
  border-color: rgba(78,204,163,0.4) !important;
  background: rgba(78,204,163,0.06) !important;
}
.shop-divider {
  border-top: 1px solid rgba(255,255,255,0.1);
  margin: 12px 0;
}
.shop-section-title {
  font-size: 13px;
  font-weight: bold;
  margin-bottom: 8px;
  color: #aaa;
}
.inv-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  background: rgba(255,255,255,0.04);
  border-radius: 6px;
  margin-bottom: 4px;
}
.inv-item-name { font-size: 12px; color: #ccc; }
.inv-item-qty { font-size: 12px; font-weight: bold; color: #88ccff; }
.inv-use-btn {
  background: #27ae60;
  border: none;
  color: #fff;
  padding: 3px 8px;
  border-radius: 3px;
  cursor: pointer;
  font-size: 10px;
  font-weight: bold;
}
.inv-use-btn:hover { background: #2ecc71; }

/* Mobile attack button */
#mobile-attack-btn {
  position: fixed;
  bottom: calc(36px + env(safe-area-inset-bottom, 0px));
  right: calc(24px + 64px + 14px);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: rgba(229,69,96,0.3);
  border: 2px solid rgba(229,69,96,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  cursor: pointer;
  z-index: 6000;
  pointer-events: auto;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
  transition: background 0.15s;
}
#mobile-attack-btn.hidden { display: none; }
#mobile-attack-btn:active {
  background: rgba(229,69,96,0.6);
  transform: scale(0.92);
}

/* ======================== Mobile Combat ======================== */
@media (max-width: 600px) {
  #combat-hud {
    top: 52px;
    left: auto;
    right: 8px;
    transform: none;
    gap: 4px;
  }
  #combat-info { font-size: 10px; gap: 6px; padding: 3px 8px; }
  #quick-drink { font-size: 11px; padding: 3px 6px; }
}

/* ======================== Stats Modal ======================== */
#level-display {
  cursor: pointer;
  transition: color 0.15s, text-shadow 0.15s;
}
#level-display:hover {
  color: #aaddff;
  text-shadow: 0 0 6px rgba(136,204,255,0.7);
}

.stats-modal-box {
  max-width: 360px;
  width: 94%;
}

.stats-divider {
  border: none;
  border-top: 1px solid rgba(78,204,163,0.25);
  margin: 10px 0;
}

.stats-section-title {
  font-size: 11px;
  color: rgba(255,255,255,0.45);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 7px;
}

/* EXP Bar */
.stats-exp-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 2px;
}
.stats-exp-label {
  font-size: 13px;
  color: #88ccff;
  font-weight: bold;
  min-width: 44px;
}
.stats-exp-bar-bg {
  flex: 1;
  height: 10px;
  background: rgba(255,255,255,0.1);
  border-radius: 5px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.12);
}
.stats-exp-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #4eccd6, #88ccff);
  border-radius: 5px;
  transition: width 0.4s ease;
}
.stats-exp-text {
  font-size: 11px;
  color: rgba(255,255,255,0.55);
  min-width: 56px;
  text-align: right;
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 12px;
}
.stats-cell {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
}
.stats-cell-icon { font-size: 14px; min-width: 18px; }
.stats-cell-label { color: rgba(255,255,255,0.55); font-size: 11px; min-width: 32px; }
.stats-cell-value { color: #f0f0f0; font-weight: bold; }

/* Battle Stats Row */
.stats-battle-row {
  display: flex;
  justify-content: space-around;
  margin: 2px 0;
}
.stats-battle-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.stats-battle-icon { font-size: 16px; }
.stats-battle-label { font-size: 10px; color: rgba(255,255,255,0.45); }
.stats-battle-value { font-size: 14px; font-weight: bold; color: #f0f0f0; }

/* Inventory in Stats */
.stats-inv-list { display: flex; flex-direction: column; gap: 5px; }
.stats-inv-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255,255,255,0.05);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 12px;
}
.stats-inv-name { flex: 1; color: #e0e0e0; }
.stats-inv-qty { color: rgba(255,255,255,0.5); min-width: 28px; }
.stats-inv-use {
  background: rgba(78,204,163,0.2);
  border: 1px solid rgba(78,204,163,0.5);
  color: #4ecca3;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  cursor: pointer;
  transition: background 0.15s;
}
.stats-inv-use:hover { background: rgba(78,204,163,0.4); }

.stats-bit-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
}
.stats-bit-row .bit-icon { font-size: 16px; }
.stats-bit-row .bit-value { color: #f5c542; font-weight: bold; }
.stats-bit-row .bit-label { color: rgba(255,255,255,0.45); font-size: 11px; }

.stats-empty-inv {
  color: rgba(255,255,255,0.3);
  font-size: 12px;
  text-align: center;
  padding: 6px 0;
}

/* ---- Equipment Slot ---- */
.stats-equip-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 4px;
}
.stats-equip-slot {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid;
  min-height: 46px;
}
.stats-equip-slot.occupied {
  background: rgba(78, 204, 163, 0.08);
  border-color: rgba(78, 204, 163, 0.35);
}
.stats-equip-slot.empty {
  background: rgba(255,255,255,0.03);
  border-color: rgba(255,255,255,0.12);
  border-style: dashed;
}
.stats-equip-slot-label {
  font-size: 12px;
  color: rgba(255,255,255,0.5);
  min-width: 68px;
  flex-shrink: 0;
}
.stats-equip-item-info {
  display: flex;
  flex-direction: column;
  flex: 1;
  gap: 2px;
}
.stats-equip-item-name {
  font-size: 13px;
  font-weight: bold;
  color: #e0e0e0;
}
.stats-equip-item-bonus {
  font-size: 11px;
  color: #4ecca3;
}
.stats-equip-empty {
  flex: 1;
  font-size: 12px;
  color: rgba(255,255,255,0.2);
  font-style: italic;
}
.stats-unequip-btn {
  background: rgba(233,69,96,0.25) !important;
  border: 1px solid rgba(233,69,96,0.5) !important;
  color: #e94560 !important;
  font-size: 10px;
  padding: 3px 8px;
  border-radius: 4px;
  cursor: pointer;
  flex-shrink: 0;
}
.stats-unequip-btn:hover {
  background: rgba(233,69,96,0.45) !important;
}

@media (max-width: 600px) {
  .stats-modal-box { max-width: 100%; width: 96%; }
}

/* ======================== PvP Duel ======================== */
.duel-round-block {
  background: rgba(255,255,255,0.04);
  border-radius: 6px;
  padding: 8px 10px;
  margin-bottom: 8px;
  border: 1px solid rgba(255,255,255,0.07);
}
.duel-round-title {
  font-size: 12px;
  font-weight: bold;
  color: #e0e0e0;
  margin-bottom: 5px;
}
.duel-log {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.duel-log-line {
  font-size: 11px;
  color: rgba(255,255,255,0.65);
  display: flex;
  gap: 4px;
  align-items: center;
}
.duel-log-line.crit { color: #f5c542; }
.duel-log-line .atk { color: #4ecca3; min-width: 42px; }
.duel-log-line .dmg { font-weight: bold; color: #e94560; min-width: 30px; }
.duel-log-line .rem { color: rgba(255,255,255,0.4); font-size: 10px; }

/* Duel VS screen */
.duel-vs-wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  padding: 10px;
  background: rgba(0,0,0,0.25);
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.07);
}
.duel-fighter {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
.duel-fighter-char { font-size: 28px; }
.duel-fighter-name {
  font-size: 11px;
  font-weight: bold;
  color: #e0e0e0;
  max-width: 80px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.duel-fighter-hp-bg {
  width: 80px;
  height: 8px;
  background: rgba(255,255,255,0.1);
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.1);
}
.duel-fighter-hp-fill {
  height: 100%;
  border-radius: 4px;
  background: #4ecca3;
  transition: width 0.3s ease, background 0.3s ease;
}
.duel-fighter-hp-text {
  font-size: 10px;
  color: rgba(255,255,255,0.5);
}
.duel-vs-badge {
  font-size: 22px;
  flex-shrink: 0;
}
.duel-round-banner {
  text-align: center;
  font-size: 13px;
  font-weight: bold;
  color: #88ccff;
  padding: 5px 0 2px;
  min-height: 22px;
  animation: duelFadeIn 0.3s ease;
}
.duel-final-banner {
  text-align: center;
  font-size: 24px;
  font-weight: bold;
  padding: 10px 0 6px;
  animation: duelFadeIn 0.45s ease;
}
.duel-final-banner.win  { color: #4ecca3; text-shadow: 0 0 12px rgba(78,204,163,0.6); }
.duel-final-banner.lose { color: #e94560; }

@keyframes duelFadeIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes duelShake {
  0%,100% { transform: translateX(0); }
  20%     { transform: translateX(-6px); }
  50%     { transform: translateX(6px); }
  80%     { transform: translateX(-4px); }
}
.duel-shake { animation: duelShake 0.3s ease; }
.duel-log-line { animation: duelFadeIn 0.2s ease; }

/* Hide number input spinners */
#pp-bet-input::-webkit-inner-spin-button,
#pp-bet-input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
#pp-bet-input { -moz-appearance: textfield; }

/* ======================== Item Market ======================== */
#market-listings { display: flex; flex-direction: column; gap: 6px; max-height: 260px; overflow-y: auto; }
.market-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.07);
  border-radius: 8px;
  padding: 8px 10px;
  gap: 8px;
}
.market-item:hover { background: rgba(255,255,255,0.08); }
.market-item-info { flex: 1; min-width: 0; }
.market-item-name { font-size: 13px; font-weight: bold; color: #f0f0f0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.market-item-seller { font-size: 10px; color: #888; margin-top: 2px; }
.market-item-right { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.market-item-price { font-size: 12px; font-weight: bold; color: #f5c542; white-space: nowrap; }
.market-buy-btn {
  background: linear-gradient(135deg, #1a6e3a, #27ae60);
  color: #fff; border: none; border-radius: 6px;
  padding: 4px 10px; font-size: 11px; font-weight: bold; cursor: pointer;
}
.market-buy-btn:hover { background: linear-gradient(135deg, #27ae60, #2ecc71); }
.market-cancel-btn {
  background: rgba(180,40,40,0.6); color: #fff; border: 1px solid rgba(255,80,80,0.4);
  border-radius: 6px; padding: 4px 10px; font-size: 11px; font-weight: bold; cursor: pointer;
}
.market-cancel-btn:hover { background: rgba(220,60,60,0.8); }
.market-list-btn {
  background: linear-gradient(135deg, #1a4a8e, #2980b9);
  color: #fff; border: none; border-radius: 6px;
  padding: 5px 12px; font-size: 12px; font-weight: bold; cursor: pointer;
}
.market-list-btn:hover { background: linear-gradient(135deg, #2980b9, #3498db); }
.market-sell-form {
  background: rgba(10,22,40,0.8);
  border: 1px solid rgba(78,204,163,0.25);
  border-radius: 8px; padding: 10px 12px; margin-bottom: 10px;
}
/* Hide market sell price spinner */
#market-sell-price::-webkit-inner-spin-button,
#market-sell-price::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
#market-sell-price { -moz-appearance: textfield; }

/* ── 1:1 Trade modals ── */
.trade-bit-input {
  flex: 1;
  background: #0a1628;
  border: 1px solid #2a3f6a;
  color: #f5c542;
  padding: 5px 8px;
  border-radius: 6px;
  font-size: 12px;
}
.trade-bit-input::-webkit-inner-spin-button,
.trade-bit-input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.trade-bit-input { -moz-appearance: textfield; }

