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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #ffffff;
  color: #111827;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  user-select: none;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}

.hidden {
  display: none !important;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}

.card {
  background: #ffffff;
  border: 1.5px solid #e5e7eb;
  border-radius: 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.06);
}

.join-card {
  width: 340px;
  padding: 28px;
  text-align: center;
}

.join-card h1 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 6px;
}

.subtitle {
  font-size: 13px;
  color: #6b7280;
  margin-bottom: 20px;
}

.join-card input {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid #d1d5db;
  border-radius: 8px;
  font-size: 15px;
  outline: none;
  margin-bottom: 16px;
}

.join-card input:focus {
  border-color: #111827;
}

.color-picker {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-bottom: 20px;
}

.color-dot {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.12s ease;
}

.color-dot:hover {
  transform: scale(1.15);
}

.color-dot.active {
  outline: 2px solid #111827;
  outline-offset: 2px;
}

.btn-primary {
  background: #111827;
  color: #ffffff;
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.btn-primary:hover {
  background: #374151;
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-ghost {
  background: #f3f4f6;
  color: #374151;
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.btn-ghost:hover {
  background: #e5e7eb;
}

.btn-sm {
  padding: 7px 12px;
  font-size: 13px;
}

.btn-xs {
  padding: 4px 9px;
  font-size: 12px;
}

.hud-top-left {
  position: fixed;
  top: 14px;
  left: 14px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  z-index: 14;
}

.hud-top-left .pill,
.hud-top-right .pill {
  pointer-events: auto;
}

.hud-top-right {
  position: fixed;
  top: 14px;
  right: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 14;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  width: fit-content;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid #e5e7eb;
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 13px;
  font-weight: 600;
}

.dot-online {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #16a34a;
}

.hint {
  font-size: 12px;
  color: #6b7280;
  background: rgba(255, 255, 255, 0.85);
  padding: 3px 8px;
  border-radius: 6px;
}

.invite-box {
  position: fixed;
  top: 56px;
  right: 16px;
  padding: 14px 16px;
  width: 260px;
  z-index: 15;
}

.invite-box #inviteText {
  font-size: 13px;
  margin-bottom: 10px;
  line-height: 1.4;
}

.invite-actions {
  display: flex;
  gap: 8px;
}

.toast {
  position: fixed;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: #111827;
  color: #ffffff;
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 15;
  pointer-events: none;
}

.private-panel {
  position: fixed;
  right: 16px;
  bottom: 76px;
  width: 300px;
  max-height: 300px;
  display: flex;
  flex-direction: column;
  z-index: 12;
}

.private-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid #f3f4f6;
  font-size: 13px;
}

.private-messages {
  padding: 10px 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 230px;
  font-size: 13px;
  user-select: text;
}

.p-msg {
  padding: 6px 10px;
  border-radius: 8px;
  background: #f3f4f6;
  align-self: flex-start;
  max-width: 85%;
  word-break: break-word;
}

.p-msg.me {
  background: #111827;
  color: #ffffff;
  align-self: flex-end;
}

.nearby-prompt {
  position: fixed;
  bottom: 74px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid #d1d5db;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 12px;
  color: #374151;
  pointer-events: none;
}

.bottom-bar {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  width: min(560px, calc(100% - 24px));
  z-index: 10;
}

.emote-bar {
  display: flex;
  gap: 4px;
  background: #ffffff;
  border: 1.5px solid #e5e7eb;
  border-radius: 10px;
  padding: 4px;
}

.emote-btn {
  background: transparent;
  border: none;
  font-size: 16px;
  width: 30px;
  height: 30px;
  border-radius: 6px;
  cursor: pointer;
}

.emote-btn:hover {
  background: #f3f4f6;
}

.chat-form {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  background: #ffffff;
  border: 1.5px solid #e5e7eb;
  border-radius: 10px;
  padding: 4px 6px 4px 10px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.04);
}

.mode-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 7px;
  border-radius: 6px;
  background: #f3f4f6;
  color: #374151;
  white-space: nowrap;
}

.mode-badge.private {
  background: #fef3c7;
  color: #92400e;
}

.chat-form input {
  flex: 1;
  border: none;
  outline: none;
  font-size: 14px;
  background: transparent;
  min-width: 0;
}

.sticker-more-btn {
  font-size: 13px;
  color: #4b5563;
}

.sticker-panel {
  position: fixed;
  bottom: 72px;
  left: 50%;
  transform: translateX(-50%);
  width: min(330px, calc(100% - 24px));
  padding: 10px;
  z-index: 14;
}

.sticker-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
  border-bottom: 1px solid #f3f4f6;
  padding-bottom: 6px;
}

.sticker-tab {
  background: transparent;
  border: none;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  color: #6b7280;
  cursor: pointer;
}

.sticker-tab.active {
  background: #111827;
  color: #ffffff;
}

.sticker-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.sticker-item {
  background: #f9fafb;
  border: 1px solid #f3f4f6;
  border-radius: 8px;
  height: 44px;
  font-size: 22px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s ease, background 0.1s ease;
}

.sticker-item:hover {
  background: #f3f4f6;
  transform: scale(1.08);
}

.help-btn {
  position: fixed;
  top: 14px;
  right: 14px;
  cursor: pointer;
  color: #111827;
  z-index: 14;
}

.help-btn:hover {
  background: #f9fafb;
}

.help-card {
  width: min(460px, calc(100% - 28px));
  max-height: 85vh;
  overflow-y: auto;
  padding: 20px;
}

.help-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.help-header h2 {
  font-size: 18px;
  font-weight: 700;
}

.help-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
  font-size: 13px;
  line-height: 1.55;
  color: #374151;
}

.help-body ul {
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.help-section h3 {
  font-size: 14px;
  font-weight: 700;
  color: #111827;
  margin-bottom: 6px;
}

.help-section ul {
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.help-section code {
  background: #f3f4f6;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12px;
  color: #111827;
}

.help-ok-btn {
  width: 100%;
  margin-top: 16px;
}

.icon {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  display: inline-block;
  vertical-align: middle;
}

.icon-sm {
  width: 12px;
  height: 12px;
}

.icon-amber {
  color: #d97706;
}

.btn-icon {
  padding: 5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.private-title,
.help-section h3,
.mode-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.emote-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.emote-wheel {
  position: fixed;
  width: 0;
  height: 0;
  z-index: 16;
  pointer-events: none;
}

.wheel-ring {
  position: absolute;
  left: -62px;
  top: -62px;
  width: 124px;
  height: 124px;
  border-radius: 50%;
  border: 1.5px dashed rgba(17, 24, 39, 0.16);
  pointer-events: none;
}

.wheel-item {
  position: absolute;
  width: 38px;
  height: 38px;
  margin-left: -19px;
  margin-top: -19px;
  border-radius: 50%;
  background: #ffffff;
  border: 1.5px solid #e5e7eb;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.09);
  font-size: 19px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  pointer-events: auto;
  transition: transform 0.12s ease, border-color 0.12s ease;
}

.wheel-item:hover {
  transform: scale(1.18);
  border-color: #111827;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  background: #f3f4f6;
  padding: 4px;
  border-radius: 10px;
  margin-bottom: 14px;
}

.auth-tab {
  border: none;
  background: transparent;
  padding: 7px 10px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 600;
  color: #6b7280;
  cursor: pointer;
}

.auth-tab.active {
  background: #ffffff;
  color: #111827;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.auth-error {
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fecaca;
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 12px;
  margin-bottom: 12px;
  text-align: left;
}

.auth-submit-btn {
  width: 100%;
}

.pill-btn {
  cursor: pointer;
  color: #111827;
}

.pill-btn:hover {
  background: #f9fafb;
}

.pill-coins {
  color: #92400e;
  background: #fffbeb;
  border-color: #fde68a;
}

.shop-card {
  width: min(720px, calc(100% - 24px));
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  padding: 22px;
}

.shop-sub {
  font-size: 12px;
  color: #6b7280;
  margin-top: 2px;
}

.pet-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(195px, 1fr));
  gap: 12px;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 4px;
}

.pet-card {
  border: 1.5px solid #e5e7eb;
  border-radius: 12px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 8px;
  background: #ffffff;
  min-width: 0;
}

.pet-card.equipped {
  border-color: #111827;
  background: #f9fafb;
}

.pet-preview {
  width: 68px;
  height: 54px;
  background: #f8fafc;
  border-radius: 8px;
}

.pet-name {
  font-size: 14px;
  font-weight: 700;
}

.pet-kind {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 999px;
  background: #f3f4f6;
  color: #4b5563;
}

.pet-desc {
  font-size: 11.5px;
  color: #6b7280;
  line-height: 1.35;
  flex: 1;
}

.pet-action-btn {
  width: 100%;
  margin-top: 4px;
}

.hunger-bar-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #f8fafc;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 8px 12px;
}

.hunger-label {
  font-size: 12px;
  color: #374151;
  line-height: 1.4;
}

.hunger-track {
  flex: 1;
  height: 8px;
  background: #e5e7eb;
  border-radius: 999px;
  overflow: hidden;
}

.hunger-fill {
  height: 100%;
  background: #16a34a;
  border-radius: 999px;
  transition: width 0.25s ease;
}

.food-actions {
  display: flex;
  gap: 8px;
  width: 100%;
  margin-top: 4px;
}

.food-actions button {
  flex: 1;
  white-space: nowrap;
  padding: 7px 8px;
  font-size: 12px;
}

.wheel-qty {
  position: absolute;
  right: -5px;
  bottom: -4px;
  background: #111827;
  color: #ffffff;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 999px;
  line-height: 1.2;
}

.quest-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #dc2626;
}

.quest-card {
  width: min(500px, calc(100% - 24px));
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  padding: 22px;
}

.quest-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  padding-right: 4px;
}

.quest-item {
  border: 1.5px solid #e5e7eb;
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: #ffffff;
}

.quest-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.quest-title {
  font-size: 13.5px;
  font-weight: 700;
  color: #111827;
}

.quest-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: #6b7280;
}

.quest-reward {
  color: #92400e;
  background: #fffbeb;
  border: 1px solid #fde68a;
  padding: 1px 7px;
  border-radius: 999px;
  font-weight: 600;
}

/* Fix progress bar height inside flex-direction: column .quest-info */
.quest-info .hunger-track {
  flex: none;
  width: 100%;
  height: 8px;
}

/* Mobile-first responsive polish */
@media (max-width: 640px) {
  .hud-top-left {
    top: 10px;
    left: 10px;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }

  .hud-top-right {
    top: 10px;
    right: 10px;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
  }

  .mobile-hide,
  .hud-top-right .pill span {
    display: none;
  }

  .pill {
    padding: 6px 9px;
    font-size: 12px;
    gap: 5px;
  }

  .hud-top-right .pill {
    padding: 7px 8px;
  }

  .join-card {
    width: min(340px, calc(100% - 24px));
    padding: 20px;
  }

  .shop-card,
  .quest-card,
  .help-card {
    width: calc(100% - 16px);
    max-height: 86dvh;
    padding: 15px;
  }

  .pet-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .pet-card {
    padding: 10px;
    gap: 5px;
  }

  .food-actions {
    flex-direction: column;
    gap: 5px;
  }

  .bottom-bar {
    bottom: max(10px, env(safe-area-inset-bottom));
    left: 8px;
    right: 8px;
    transform: none;
    width: auto;
    gap: 5px;
  }

  .emote-bar {
    padding: 2px;
    gap: 1px;
    flex-shrink: 0;
  }

  .emote-btn {
    width: 26px;
    height: 26px;
    font-size: 14px;
  }

  .chat-form {
    flex: 1;
    min-width: 0;
    padding: 3px 4px 3px 7px;
    gap: 4px;
  }

  .mode-badge {
    padding: 2px 5px;
    font-size: 10.5px;
  }

  .chat-form input {
    width: 100%;
    min-width: 0;
    font-size: 15px;
  }

  .chat-form .btn-sm {
    padding: 6px 10px;
    font-size: 12px;
    flex-shrink: 0;
  }

  .private-panel {
    left: 10px;
    right: 10px;
    width: auto;
    bottom: 68px;
    max-height: 220px;
  }

  .invite-box {
    top: 52px;
    right: 10px;
    width: min(260px, calc(100% - 20px));
  }

  .nearby-prompt {
    bottom: 66px;
    font-size: 11px;
    padding: 5px 11px;
    max-width: calc(100% - 20px);
    text-align: center;
  }
}

.player-menu {
  position: fixed;
  width: 196px;
  max-height: calc(100dvh - 24px);
  overflow-y: auto;
  padding: 8px;
  z-index: 16;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.bet-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 4px 6px 0;
  font-size: 11.5px;
  color: #4b5563;
  font-weight: 600;
  border-top: 1px solid #f3f4f6;
}

.bet-row input {
  width: 72px;
  padding: 3px 6px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 12px;
  text-align: right;
  outline: none;
}

.bet-chips {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 2px 6px;
}

.bet-chip {
  border: 1px solid #e5e7eb;
  background: #f9fafb;
  border-radius: 6px;
  padding: 3px 0;
  font-size: 11px;
  font-weight: 600;
  color: #374151;
  cursor: pointer;
}

.bet-chip:hover {
  background: #e5e7eb;
}

.player-menu-title {
  font-size: 12px;
  font-weight: 700;
  color: #6b7280;
  padding: 4px 8px;
  border-bottom: 1px solid #f3f4f6;
  margin-bottom: 2px;
}

.menu-opt {
  display: flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: none;
  border-radius: 8px;
  padding: 7px 8px;
  font-size: 13px;
  font-weight: 500;
  color: #111827;
  cursor: pointer;
  text-align: left;
}

.menu-opt:hover {
  background: #f3f4f6;
}

.game-bar {
  position: fixed;
  top: 56px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 14;
  max-width: calc(100vw - 24px);
}

.game-bar-info {
  font-size: 13px;
  font-weight: 600;
  color: #111827;
  white-space: nowrap;
}

.game-bar-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

@media (max-width: 640px) {
  .game-bar {
    top: 8px;
    flex-direction: column;
    gap: 6px;
    padding: 7px 10px;
    max-width: calc(100vw - 124px);
    text-align: center;
  }

  .game-bar-info {
    font-size: 11.5px;
    white-space: normal;
  }
}

.game-action-bar {
  position: fixed;
  bottom: 72px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 15;
}

.race-tap-btn {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: #111827;
  color: #ffffff;
  border: none;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.16);
  transition: transform 0.06s ease;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.race-tap-btn:active:not(:disabled) {
  transform: scale(0.9);
  background: #374151;
}

.game-action-bar.is-circle {
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 0;
}
