* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  font-family: system-ui, -apple-system, sans-serif;
  background: #0a0f1c;
  color: #e2e8f0;
  position: fixed;
  inset: 0;
}

body.game-active {
  touch-action: none;
  overflow: hidden;
}

#loading, #login-error, #pet-picker {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0a0f1c;
  flex-direction: column;
  gap: 1rem;
  padding: max(1rem, env(safe-area-inset-top)) 1.25rem max(1rem, env(safe-area-inset-bottom));
  text-align: center;
  overflow: hidden;
}
#loading.hidden, #login-error.hidden, #pet-picker.hidden { display: none; }

#early-access-card {
  width: 100%;
  max-width: 440px;
  padding: 2rem 2rem 1.75rem;
  background: rgba(15, 23, 42, 0.94);
  border: 2px solid rgba(34, 211, 153, 0.45);
  border-radius: 20px;
  box-shadow:
    0 0 30px rgba(34, 211, 153, 0.2),
    0 20px 50px rgba(0, 0, 0, 0.45);
  animation: control-box-glow 2.4s ease-in-out infinite;
}
#metaverse-hero {
  text-align: center;
  margin-bottom: 1.35rem;
  padding: 1.1rem 0.75rem;
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(34, 211, 153, 0.12), rgba(167, 139, 250, 0.12));
  border: 1px solid rgba(167, 139, 250, 0.35);
}
.metaverse-kicker {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: #f472b6;
  margin-bottom: 0.45rem;
  animation: metaverse-pulse 1.8s ease-in-out infinite;
}
.metaverse-title {
  font-size: clamp(2rem, 8vw, 2.65rem);
  font-weight: 900;
  letter-spacing: 0.12em;
  background: linear-gradient(90deg, #22d3ee, #34d399, #a78bfa, #f472b6);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 40px rgba(34, 211, 153, 0.35);
  line-height: 1.1;
}
.metaverse-sub {
  margin-top: 0.45rem;
  font-size: 0.92rem;
  font-weight: 600;
  color: #e2e8f0;
  opacity: 0.9;
}
@keyframes metaverse-pulse {
  0%, 100% { opacity: 0.75; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.03); }
}
.login-hint {
  font-size: 0.82rem;
  opacity: 0.7;
  margin-bottom: 1rem;
  text-align: center;
}
.login-error-detail {
  color: #fca5a5;
  font-size: 0.88rem;
  margin-bottom: 1rem;
  text-align: center;
}
.login-success-detail {
  color: #6ee7b7;
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 1rem;
  text-align: center;
  padding: 0.65rem 0.75rem;
  border-radius: 10px;
  background: rgba(16, 185, 129, 0.12);
  border: 1px solid rgba(52, 211, 153, 0.35);
}
.login-error-detail.hidden,
.login-success-detail.hidden { display: none; }
#early-access-form {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  text-align: left;
}
#early-access-form label {
  font-size: 0.78rem;
  opacity: 0.75;
  margin-top: 0.35rem;
}
#early-access-form input {
  width: 100%;
  padding: 0.75rem 0.9rem;
  border-radius: 10px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  background: rgba(2, 6, 23, 0.65);
  color: #e2e8f0;
  font-size: 1rem;
}
#early-access-form input:focus {
  outline: none;
  border-color: rgba(34, 211, 153, 0.55);
  box-shadow: 0 0 0 2px rgba(34, 211, 153, 0.15);
}
#ea-login-btn { margin-top: 1rem; width: 100%; }

#pet-picker {
  justify-content: center;
  align-items: center;
  padding: max(1.5rem, env(safe-area-inset-top)) 1.25rem max(1.5rem, env(safe-area-inset-bottom));
}
#pet-picker-inner {
  width: 100%;
  max-width: 640px;
  max-height: calc(100dvh - 2.5rem);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 1.5rem 1.75rem 1.25rem;
  background: rgba(15, 23, 42, 0.94);
  border: 1px solid rgba(52, 211, 153, 0.28);
  border-radius: 20px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}
#pet-picker-inner h2 { margin-bottom: 0.35rem; flex-shrink: 0; }
#pet-picker-inner .picker-sub {
  opacity: 0.72; font-size: 0.88rem; margin-bottom: 1rem; flex-shrink: 0;
}
#pet-grid-wrap {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  margin: 0 -0.35rem;
  padding: 0 0.35rem 0.25rem;
  scrollbar-width: thin;
  scrollbar-color: rgba(52, 211, 153, 0.4) transparent;
}
#pet-grid-wrap::-webkit-scrollbar { width: 8px; }
#pet-grid-wrap::-webkit-scrollbar-thumb {
  background: rgba(52, 211, 153, 0.4);
  border-radius: 4px;
}
#enter-world-btn {
  flex-shrink: 0;
  margin-top: 1rem;
  width: 100%;
}

.spinner {
  width: 48px; height: 48px;
  border: 4px solid rgba(255,255,255,0.1);
  border-top-color: #34d399;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#game-wrap {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  display: none;
  overflow: hidden;
}
#game-wrap.active { display: block; }

#world-gl,
#world-canvas {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
  display: block;
  touch-action: none;
}
#world-gl {
  z-index: 1;
  display: none;
}
#world-canvas {
  z-index: 2;
  cursor: crosshair;
}
body.render-3d #world-gl { display: block; }
body.render-3d #world-canvas { opacity: 0; pointer-events: none; }
body.render-3d:not(.battle-active):not(.battle-intro):not(.modal-open):not(.panel-open) #world-gl {
  cursor: pointer;
}

#fp-crosshair {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 20px;
  height: 20px;
  z-index: 15;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s;
}
#fp-crosshair::before,
#fp-crosshair::after {
  content: '';
  position: absolute;
  background: rgba(255, 255, 255, 0.55);
}
#fp-crosshair::before {
  width: 12px;
  height: 1.5px;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}
#fp-crosshair::after {
  width: 1.5px;
  height: 12px;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}
#fp-crosshair.visible { opacity: 1; }

#fp-click-hint {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, calc(-50% + 2.5rem));
  z-index: 15;
  color: rgba(255, 255, 255, 0.65);
  font-size: 0.85rem;
  pointer-events: none;
  text-align: center;
  display: none;
}
body.render-3d.fp-ready:not(.mobile):not(.battle-active):not(.battle-intro):not(.modal-open):not(.panel-open) #fp-click-hint {
  display: block;
}
body.mobile.render-3d #fp-crosshair { display: none !important; opacity: 0 !important; }
body.fp-locked #fp-click-hint { display: none !important; }
body.battle-active #world-canvas,
body.battle-intro #world-canvas { opacity: 1 !important; display: block !important; }
body.battle-active #world-gl,
body.battle-intro #world-gl { display: none !important; }
body.battle-active #fp-crosshair,
body.battle-intro #fp-crosshair,
body.battle-active #fp-click-hint,
body.battle-intro #fp-click-hint { display: none !important; opacity: 0 !important; }
body.battle-active #world-canvas,
body.battle-intro #world-canvas { cursor: default !important; }

#hud {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 20;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: max(0.5rem, env(safe-area-inset-top)) 0.75rem 0.5rem;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(0,0,0,0.75) 0%, transparent 100%);
  transition: transform 0.25s ease;
}
#hud.collapsed { transform: translateY(-85%); }
#hud > * { pointer-events: auto; }

.hud-left { display: flex; flex-direction: column; gap: 0.25rem; max-width: 55vw; }
.hud-title { font-size: clamp(0.85rem, 2.5vw, 1.15rem); font-weight: 700; color: #34d399; }
.hud-zone { font-size: clamp(0.7rem, 2vw, 0.85rem); opacity: 0.85; }
.hud-coords { font-size: 0.65rem; opacity: 0.5; }
.hud-pet {
  display: flex; align-items: center; gap: 0.4rem;
  background: rgba(0,0,0,0.55); border-radius: 10px;
  padding: 0.25rem 0.5rem;
  border: 1px solid rgba(52,211,153,0.3);
}
.hud-pet {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  position: relative;
}
.hud-pet img {
  width: 32px; height: 32px; border-radius: 50%; object-fit: cover;
  border: 2px solid transparent;
  transition: border-color 0.25s ease, box-shadow 0.25s ease, transform 0.25s ease;
}
.hud-pet.has-color img {
  border-color: var(--hud-pet-color, #f59e0b);
  box-shadow: 0 0 10px color-mix(in srgb, var(--hud-pet-color, #f59e0b) 50%, transparent);
}
.hud-pet.pet-switched img {
  transform: scale(1.12);
  box-shadow: 0 0 16px rgba(251, 191, 36, 0.75);
}
.hud-pet span { font-size: 0.75rem; }

#btn-mute {
  position: fixed;
  top: max(0.4rem, env(safe-area-inset-top));
  right: max(0.5rem, env(safe-area-inset-right));
  z-index: 26;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.18);
  background: rgba(0,0,0,0.55);
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
}
#btn-mute.muted { opacity: 0.65; }
#btn-mute:active { transform: scale(0.94); }

#hud-toggle {
  position: fixed;
  top: max(0.4rem, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 25;
  background: rgba(0,0,0,0.6);
  border: 1px solid rgba(255,255,255,0.15);
  color: #fff;
  border-radius: 999px;
  padding: 0.2rem 0.65rem;
  font-size: 0.65rem;
  cursor: pointer;
}

#online-panel {
  background: rgba(0,0,0,0.55);
  border-radius: 10px;
  padding: 0.35rem 0.55rem;
  border: 1px solid rgba(255,255,255,0.1);
  min-width: 100px;
  max-width: 38vw;
  max-height: 120px;
  overflow-y: auto;
  font-size: 0.68rem;
  -webkit-overflow-scrolling: touch;
}
#online-panel h4 { font-size: 0.65rem; opacity: 0.6; margin-bottom: 0.25rem; }

#feed-panel {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 20;
  max-height: 72px;
  overflow: hidden;
  background: linear-gradient(0deg, rgba(0,0,0,0.88) 0%, transparent 100%);
  padding: 0.35rem 0.75rem max(0.5rem, env(safe-area-inset-bottom));
  pointer-events: none;
}
#feed-list { display: flex; flex-direction: column-reverse; gap: 0.15rem; }
.feed-item { font-size: 0.68rem; opacity: 0.85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.feed-item.battle { color: #fca5a5; }
.feed-item.info { color: #93c5fd; }
.feed-item.scenario { color: #fde68a; }

#minimap {
  position: fixed;
  right: 0.75rem;
  bottom: max(5.5rem, calc(5rem + env(safe-area-inset-bottom)));
  z-index: 22;
  width: 88px; height: 88px;
  border-radius: 12px;
  border: 2px solid rgba(52,211,153,0.4);
  background: rgba(0,0,0,0.5);
  overflow: hidden;
}
#minimap canvas { width: 100%; height: 100%; display: block; }

#mobile-controls {
  display: none;
  pointer-events: none;
}
#joystick-zone { display: none; }

#action-btns {
  display: flex;
  right: max(1rem, env(safe-area-inset-right));
  bottom: max(1.25rem, calc(1rem + env(safe-area-inset-bottom)));
}

@media (max-width: 900px), (pointer: coarse) {
  #mobile-controls { display: block; }
  #joystick-zone { display: block; }
  #controls-hint { display: none !important; }
  #feed-panel { display: none; }
  #online-panel { display: none; }
  #minimap {
    top: max(3.25rem, calc(2.75rem + env(safe-area-inset-top)));
    bottom: auto;
    right: max(0.65rem, env(safe-area-inset-right));
    width: 92px;
    height: 92px;
    opacity: 0.95;
  }
  #chat-fab {
    left: max(0.85rem, env(safe-area-inset-left));
    right: auto;
    bottom: max(11.75rem, calc(11rem + env(safe-area-inset-bottom)));
    top: auto;
    width: 64px;
    height: 64px;
    font-size: 1.75rem;
    z-index: 32;
    border-width: 3px;
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.55);
  }
  body.panel-open #chat-fab {
    bottom: max(14rem, calc(13rem + env(safe-area-inset-bottom)));
    opacity: 1;
    pointer-events: auto;
  }
  #btn-mute {
    width: 48px;
    height: 48px;
    font-size: 1.35rem;
    border-width: 2px;
  }
  #hud-toggle {
    padding: 0.45rem 1rem;
    font-size: 0.82rem;
    min-height: 36px;
  }
  .hud-title { font-size: 1.08rem; }
  .hud-zone { font-size: 0.88rem; }
  .hud-coords { font-size: 0.72rem; }
  .hud-pet img { width: 46px; height: 46px; }
  .hud-pet span { font-size: 0.9rem; }
  #toast {
    font-size: 0.95rem;
    padding: 0.75rem 1.1rem;
    max-width: min(94vw, 440px);
  }
  .ptab {
    font-size: 1.5rem;
    padding: 0.7rem 0.35rem;
    min-height: 54px;
  }
  .panel-hint { font-size: 0.82rem; }
  .panel-mini { font-size: 0.76rem; }
  .panel-btn { font-size: 0.95rem; padding: 0.7rem; min-height: 50px; }
  #chat-log { font-size: 0.85rem; }
  #chat-input { font-size: 1rem; padding: 0.6rem 0.75rem; min-height: 46px; }
  #chat-send { font-size: 0.95rem; padding: 0.6rem 1rem; min-height: 46px; }
  .shop-item, .wild-item { font-size: 0.88rem; padding: 0.6rem; }
  .shop-item button, .wild-item button {
    font-size: 0.85rem;
    padding: 0.5rem 0.85rem;
    min-height: 42px;
  }
}

#joystick-zone {
  position: fixed;
  left: max(0.85rem, env(safe-area-inset-left));
  bottom: max(1.35rem, calc(1.1rem + env(safe-area-inset-bottom)));
  width: 150px;
  height: 150px;
  border-radius: 50%;
  background: rgba(8, 18, 32, 0.55);
  border: 3px solid rgba(34, 211, 153, 0.4);
  pointer-events: auto;
  touch-action: none;
  z-index: 31;
  box-shadow:
    0 0 14px rgba(34, 211, 153, 0.3),
    0 4px 20px rgba(0, 0, 0, 0.35);
  animation: control-box-glow 2.4s ease-in-out infinite;
}
#joystick-knob {
  position: absolute;
  width: 64px; height: 64px;
  left: 50%; top: 50%;
  margin: -32px 0 0 -32px;
  border-radius: 50%;
  background: rgba(52,211,153,0.65);
  border: 3px solid #34d399;
  pointer-events: none;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
}

#action-btns {
  position: fixed;
  flex-direction: column;
  gap: 0.45rem;
  pointer-events: auto;
  z-index: 31;
}
@media (max-width: 900px), (pointer: coarse) {
  #action-btns {
    right: max(0.85rem, env(safe-area-inset-right));
    bottom: max(1.35rem, calc(1.1rem + env(safe-area-inset-bottom)));
    gap: 0.65rem;
  }
}
.mobile-btn {
  width: 58px; height: 58px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.25);
  background: rgba(0,0,0,0.65);
  color: #fff;
  font-size: 1.45rem;
  line-height: 1;
  cursor: pointer;
  touch-action: none;
  box-shadow: 0 3px 14px rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
}
.mobile-btn.hub { font-size: 1.25rem; border-color: #34d399; }
@media (max-width: 900px), (pointer: coarse) {
  .mobile-btn {
    width: 72px; height: 72px;
    border-width: 3px;
    font-size: 2rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.55);
  }
  .mobile-btn.hub { font-size: 1.8rem; }
}

#controls-hint {
  position: fixed;
  bottom: max(6.5rem, calc(6rem + env(safe-area-inset-bottom)));
  left: 50%;
  transform: translateX(-50%);
  z-index: 15;
  font-size: 0.72rem;
  pointer-events: none;
  text-align: center;
  white-space: nowrap;
  padding: 0.55rem 1.1rem;
  border-radius: 12px;
  background: rgba(8, 18, 32, 0.82);
  border: 1px solid rgba(34, 211, 153, 0.45);
  color: #e2e8f0;
  box-shadow:
    0 0 12px rgba(34, 211, 153, 0.25),
    0 0 28px rgba(34, 211, 153, 0.12),
    inset 0 0 18px rgba(34, 211, 153, 0.06);
  animation: control-box-glow 2.4s ease-in-out infinite;
}
@keyframes control-box-glow {
  0%, 100% {
    border-color: rgba(34, 211, 153, 0.35);
    box-shadow:
      0 0 10px rgba(34, 211, 153, 0.2),
      0 0 22px rgba(34, 211, 153, 0.08),
      inset 0 0 14px rgba(34, 211, 153, 0.04);
  }
  50% {
    border-color: rgba(52, 211, 153, 0.85);
    box-shadow:
      0 0 18px rgba(52, 211, 153, 0.55),
      0 0 36px rgba(34, 211, 153, 0.28),
      inset 0 0 22px rgba(52, 211, 153, 0.12);
  }
}

#battle-hud {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 45;
  padding: 0.5rem 0.75rem max(0.65rem, env(safe-area-inset-bottom));
  background: linear-gradient(transparent, rgba(0,0,0,0.88) 35%);
  pointer-events: none;
}
#battle-hud.active { pointer-events: auto; }
#battle-hud.hidden { display: none; }

#battle-hud-hint {
  text-align: center; font-size: 0.68rem; opacity: 0.65; margin: 0 0 0.25rem;
}
#battle-hud-log {
  text-align: center; font-size: 0.8rem; margin: 0 0 0.45rem;
  color: #fbbf24; min-height: 1.1rem;
}
.battle-hud-bars {
  display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.45rem;
}
.bhud-side { flex: 1; font-size: 0.72rem; }
.bhud-side.you { text-align: left; }
.bhud-side.them { text-align: right; }
.bhud-bar {
  height: 8px; background: rgba(255,255,255,0.15); border-radius: 4px;
  overflow: hidden; margin: 0.2rem 0;
}
.bhud-fill {
  height: 100%; background: linear-gradient(90deg, #34d399, #22d3ee);
  border-radius: 4px; transition: width 0.35s ease;
}
.bhud-fill.them { background: linear-gradient(90deg, #f87171, #dc2626); }
.bhud-vs { font-weight: 800; color: #dc2626; font-size: 0.85rem; }
.battle-hud-actions {
  display: flex; gap: 0.4rem; justify-content: center;
}
.bhud-btn {
  flex: 1; max-width: 130px; padding: 0.6rem 0.4rem;
  border: none; border-radius: 12px; font-weight: 700; font-size: 0.78rem;
  cursor: pointer; min-height: 46px;
}
.bhud-btn.attack { background: #dc2626; color: #fff; }
.bhud-btn.defend { background: #2563eb; color: #fff; }
.bhud-btn.special {
  background: #7c3aed; color: #fff; position: relative; overflow: hidden;
}
.bhud-btn.forfeit {
  flex: 0 0 auto; max-width: none; min-width: 5.5rem;
  background: rgba(255,255,255,0.1); color: #fca5a5;
  border: 1px solid rgba(248,113,113,0.45);
}
.bhud-btn.forfeit:hover { background: rgba(248,113,113,0.2); }
.bhud-btn.special.charging {
  box-shadow: 0 0 18px rgba(167,139,250,0.85);
  animation: chargePulse 0.45s ease-in-out infinite alternate;
}
.bhud-btn.special .charge-fill {
  position: absolute; left: 0; bottom: 0; width: 100%; height: 0%;
  background: rgba(255,255,255,0.28); pointer-events: none;
  transition: height 0.05s linear;
}
@keyframes chargePulse {
  from { transform: scale(1); }
  to { transform: scale(1.04); }
}
.bhud-btn:disabled { opacity: 0.35; cursor: not-allowed; }

#screen-shake-wrap { width: 100%; height: 100%; }

body.battle-active #world-panel,
body.battle-intro #world-panel { display: none; }
body.battle-active #hud,
body.battle-intro #hud { opacity: 0.35; }
body.battle-active #minimap,
body.battle-intro #minimap { display: none; }

@media (max-width: 900px), (pointer: coarse) {
  body.battle-intro #joystick-zone,
  body.battle-active #joystick-zone { display: none; }

  body.battle-active #mobile-controls,
  body.battle-intro #mobile-controls {
    opacity: 1 !important;
    pointer-events: none;
  }
  body.battle-active #action-btns {
    bottom: max(11rem, calc(10rem + env(safe-area-inset-bottom)));
    right: max(0.85rem, env(safe-area-inset-right));
    gap: 0.75rem;
  }
  body.battle-active .mobile-btn {
    width: 76px; height: 76px;
    font-size: 2.15rem;
  }

  #battle-hud {
    padding: 0.65rem 0.65rem max(0.85rem, env(safe-area-inset-bottom));
    background: linear-gradient(transparent 0%, rgba(0,0,0,0.92) 28%);
    z-index: 50;
  }
  #battle-hud-hint { font-size: 0.78rem; opacity: 0.8; }
  #battle-hud-log { font-size: 0.92rem; font-weight: 600; }
  .bhud-side { font-size: 0.82rem; font-weight: 600; }
  .bhud-bar { height: 11px; }
  .bhud-vs { font-size: 1rem; }
  .battle-hud-actions { gap: 0.5rem; }
  .bhud-btn {
    max-width: none;
    min-height: 54px;
    font-size: 0.88rem;
    border-radius: 14px;
  }

  #battle-countdown-num {
    font-size: clamp(5.5rem, 32vw, 9rem);
  }
  .battle-vignette {
    background: radial-gradient(ellipse at center, transparent 50%, rgba(0,0,0,0.35) 100%);
  }

  body.battle-intro #hud,
  body.battle-active #hud { display: none; }

  .mobile-btn.adopt-ready {
    border-color: #fbbf24;
    background: rgba(251, 191, 36, 0.28);
    animation: adoptPulse 1.1s ease-in-out infinite;
  }
  .mobile-btn.loot-ready {
    border-color: #38bdf8;
    background: rgba(56, 189, 248, 0.28);
    animation: lootPulse 1.1s ease-in-out infinite;
  }
  @keyframes adoptPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(251, 191, 36, 0.45); }
    50% { box-shadow: 0 0 0 10px rgba(251, 191, 36, 0); }
  }
  @keyframes lootPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(56, 189, 248, 0.45); }
    50% { box-shadow: 0 0 0 10px rgba(56, 189, 248, 0); }
  }

  #world-panel { max-height: 42vh; }
  #world-panel.expanded { max-height: 48vh; }
}

#challenge-popup {
  position: fixed; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  z-index: 60; display: none;
  background: #1e293b; border: 2px solid #f59e0b;
  border-radius: 16px; padding: 1.25rem;
  text-align: center; max-width: min(320px, 92vw);
}
#challenge-popup.active { display: block; }
#challenge-popup button {
  margin: 0.35rem; padding: 0.55rem 1.2rem; min-height: 44px;
  border: none; border-radius: 10px; cursor: pointer; font-weight: 600;
}
.btn-accept { background: #22c55e; color: #000; }
.btn-decline { background: #64748b; color: #fff; }

.pet-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.75rem;
  width: 100%;
}
.pet-card {
  background: #1e293b; border: 2px solid transparent;
  border-radius: 14px; padding: 0.75rem; cursor: pointer;
  text-align: center;
  transition: border-color 0.15s ease, transform 0.15s ease;
}
.pet-card:hover { transform: translateY(-2px); border-color: rgba(52, 211, 153, 0.35); }
.pet-card.selected { border-color: #34d399; background: rgba(52, 211, 153, 0.1); }
.pet-card img { width: 64px; height: 64px; border-radius: 50%; object-fit: cover; margin-bottom: 0.35rem; }
.pet-card .name { font-size: 0.82rem; font-weight: 600; }

.badge-3d {
  display: inline-block;
  margin-top: 4px;
  font-size: 0.58rem;
  padding: 1px 6px;
  border-radius: 999px;
  background: #166534;
  color: #86efac;
  border: 1px solid #4ade80;
  font-weight: 700;
  letter-spacing: 0.5px;
}
.badge-3d.relief {
  background: #334155;
  color: #94a3b8;
  border-color: #64748b;
}

/* ArcGIS map panel */
#arcgis-search-row {
  display: flex;
  gap: 0.4rem;
  margin: 0.5rem 0;
}
#arcgis-search {
  flex: 1;
  min-width: 0;
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 10px;
  color: #e2e8f0;
  padding: 0.5rem 0.65rem;
  font-size: 0.85rem;
}
#arcgis-results {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  max-height: 160px;
  overflow-y: auto;
  margin-bottom: 0.5rem;
}
button.arcgis-result {
  text-align: left;
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 10px;
  color: #e2e8f0;
  padding: 0.45rem 0.6rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
button.arcgis-result:hover { border-color: #34d399; }
button.arcgis-result span { font-size: 0.7rem; opacity: 0.7; }
#arcgis-meta, #arcgis-elev { font-size: 0.72rem; line-height: 1.35; opacity: 0.85; }
#arcgis-results .error { color: #fca5a5; }

.btn-primary {
  background: linear-gradient(90deg, #34d399, #22d3ee);
  color: #000; border: none; border-radius: 14px;
  padding: 0.85rem 1.5rem; font-weight: 700;
  cursor: pointer; font-size: 1rem; min-height: 48px;
}

#toast {
  position: fixed;
  top: max(4.5rem, calc(4rem + env(safe-area-inset-top)));
  left: 50%; transform: translateX(-50%);
  z-index: 70;
  background: #1e293b; border: 1px solid #475569;
  padding: 0.6rem 1rem; border-radius: 12px;
  font-size: 0.82rem; display: none;
  max-width: min(92vw, 400px);
  text-align: center;
}
#toast.show { display: block; }

#scenario-banner {
  position: fixed;
  top: 35%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 30;
  background: rgba(0,0,0,0.75);
  border: 1px solid #fbbf24;
  border-radius: 14px;
  padding: 0.75rem 1.25rem;
  font-size: 0.85rem;
  max-width: 90vw;
  text-align: center;
  display: none;
  pointer-events: none;
}
#scenario-banner.show { display: block; animation: fadeIn 0.35s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

@media (min-width: 901px) {
  #hud { padding: 0.85rem 1.25rem; }
  #online-panel { max-height: 200px; min-width: 160px; font-size: 0.75rem; }
  #feed-panel { max-height: 100px; }
  .hud-pet img { width: 42px; height: 42px; }
  #world-panel { max-height: 280px; }
  #world-panel.expanded { max-height: 340px; }
}

#world-panel {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 25;
  background: rgba(10,15,28,0.95);
  border-top: 1px solid rgba(52,211,153,0.35);
  max-height: 200px;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
  transition: max-height 0.25s ease;
}
#world-panel.collapsed { max-height: 42px; overflow: hidden; }
#world-panel.expanded { max-height: 260px; }
#world-panel.panel-hidden {
  transform: translateY(100%);
  opacity: 0;
  pointer-events: none;
  max-height: 0 !important;
}

#chat-fab {
  position: fixed;
  right: max(1rem, env(safe-area-inset-right));
  bottom: max(1rem, env(safe-area-inset-bottom));
  z-index: 27;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 2px solid rgba(52, 211, 153, 0.5);
  background: rgba(10, 15, 28, 0.9);
  color: #fff;
  font-size: 1.35rem;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.45);
  transition: bottom 0.25s ease, opacity 0.2s ease;
}
#chat-fab:hover { background: rgba(52, 211, 153, 0.25); }
body.panel-open #chat-fab {
  bottom: max(11rem, calc(10rem + env(safe-area-inset-bottom)));
}
body.battle-active #chat-fab,
body.battle-intro #chat-fab { display: none; }

@media (min-width: 901px) {
  #world-canvas { cursor: crosshair; }
  body.panel-open #world-canvas { cursor: default; }
  #chat-fab {
    bottom: max(8.5rem, calc(8rem + env(safe-area-inset-bottom)));
  }
}

#panel-tabs { display: flex; gap: 0; border-bottom: 1px solid rgba(255,255,255,0.1); }
.ptab {
  flex: 1; padding: 0.5rem; border: none; background: transparent;
  color: rgba(255,255,255,0.6); font-size: 1.1rem; cursor: pointer;
}
.ptab.active { color: #34d399; background: rgba(52,211,153,0.1); }

#panel-body { flex: 1; overflow: hidden; min-height: 0; }
.ptab-content { display: none; height: 100%; flex-direction: column; padding: 0.5rem 0.75rem; overflow: hidden; }
.ptab-content.active { display: flex; }

.panel-hint { font-size: 0.68rem; opacity: 0.65; margin-bottom: 0.35rem; }
.panel-mini { font-size: 0.62rem; opacity: 0.5; word-break: break-all; margin-bottom: 0.35rem; }
.panel-btn {
  width: 100%; margin-top: 0.35rem; padding: 0.5rem;
  border-radius: 10px; border: 1px solid rgba(255,255,255,0.15);
  background: rgba(52,211,153,0.15); color: #fff; font-weight: 600; cursor: pointer;
}

#chat-log {
  flex: 1; overflow-y: auto; font-size: 0.72rem;
  -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  margin-bottom: 0.35rem; min-height: 60px;
}
#chat-input-row { display: flex; gap: 0.35rem; }
#chat-input {
  flex: 1; padding: 0.45rem 0.65rem; border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.15); background: rgba(0,0,0,0.4); color: #fff;
  font-size: 0.85rem;
}
#chat-send {
  padding: 0.45rem 0.85rem; border: none; border-radius: 10px;
  background: #34d399; color: #000; font-weight: 700; cursor: pointer;
}

#shop-list, #wild-list { overflow-y: auto; flex: 1; -webkit-overflow-scrolling: touch; }
.shop-item, .wild-item {
  padding: 0.45rem; margin-bottom: 0.35rem; border-radius: 10px;
  background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.08);
  font-size: 0.75rem;
}
.shop-item button, .wild-item button {
  margin-top: 0.25rem; padding: 0.3rem 0.6rem; border-radius: 8px;
  border: none; background: #7c3aed; color: #fff; font-size: 0.7rem; cursor: pointer;
}
.wild-item.released { border-color: rgba(251,191,36,0.5); }
.wild-item.legendary { border-color: #fbbf24; }

.world-modal {
  position: fixed; inset: 0; z-index: 80;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.82);
  padding: 1rem;
  touch-action: manipulation;
}
.world-modal.hidden { display: none; }

.modal-card {
  background: #111827;
  border: 2px solid rgba(52,211,153,0.45);
  border-radius: 18px;
  padding: clamp(1rem, 4vw, 1.35rem);
  max-width: 420px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.social-card {
  display: flex;
  flex-direction: column;
  max-height: min(92vh, 720px);
  overflow: hidden;
}
.social-card #social-modal-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  min-height: 0;
  margin-bottom: 0.25rem;
}
.social-card .modal-actions {
  flex-shrink: 0;
  position: sticky;
  bottom: 0;
  background: linear-gradient(180deg, transparent 0%, #111827 28%);
  padding-top: 0.85rem;
  margin-top: 0.5rem;
  z-index: 2;
}
.modal-card h3 { margin: 0 0 0.5rem; font-size: 1.1rem; }
.modal-hint { font-size: 0.78rem; opacity: 0.7; margin-bottom: 0.75rem; }
.modal-actions {
  display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 1rem; flex-wrap: wrap;
}
.btn-secondary {
  padding: 0.55rem 1rem; border: none; border-radius: 10px;
  background: #475569; color: #fff; font-weight: 600; cursor: pointer; min-height: 44px;
  touch-action: manipulation;
}
.btn-primary { min-height: 44px; touch-action: manipulation; }

body.modal-open #joystick-zone,
body.modal-open #action-btns,
body.modal-open #chat-fab,
body.modal-open #mobile-controls {
  visibility: hidden !important;
  pointer-events: none !important;
}

@media (max-width: 900px), (pointer: coarse) {
  .social-card {
    max-height: 94vh;
    width: min(100%, 440px);
    padding: 1rem 1rem 0.85rem;
  }
  .social-card .modal-actions {
    flex-direction: column-reverse;
    gap: 0.55rem;
  }
  .social-card .modal-actions button {
    width: 100%;
    min-height: 54px;
    font-size: 1rem;
  }
  .pick-item {
    min-height: 64px;
    padding: 0.75rem 0.85rem;
  }
  .pick-item img {
    width: 52px;
    height: 52px;
  }
  .pick-item strong { font-size: 1rem; }
  .pick-item .pick-meta { font-size: 0.82rem; }
}

.pick-list { display: flex; flex-direction: column; gap: 0.5rem; }
.pick-item {
  display: flex; align-items: center; gap: 0.65rem;
  padding: 0.65rem 0.75rem; border-radius: 12px;
  background: rgba(255,255,255,0.05); border: 2px solid transparent;
  cursor: pointer; text-align: left; width: 100%; color: #fff;
  min-height: 58px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(52, 211, 153, 0.25);
}
.pick-item:hover { background: rgba(255,255,255,0.08); }
.pick-item.selected { border-color: #34d399; background: rgba(52,211,153,0.12); }
.pick-item img {
  width: 44px; height: 44px; border-radius: 50%; object-fit: cover;
  border: 2px solid #374151; flex-shrink: 0;
}
.pick-item .pick-meta { font-size: 0.72rem; opacity: 0.75; }

#breed-name-progress {
  font-weight: 600;
  color: #34d399;
  margin-bottom: 0.35rem;
}
#breed-color-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin: 0.5rem 0 0.35rem;
}
#breed-color-preview {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.35);
  box-shadow: 0 0 12px currentColor;
  flex-shrink: 0;
}
#breed-color-label {
  font-size: 0.82rem;
  opacity: 0.8;
  text-transform: capitalize;
}

#breed-name-input {
  width: 100%; padding: 0.6rem 0.75rem; border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.2); background: rgba(0,0,0,0.4);
  color: #fff; font-size: 1rem; margin-top: 0.5rem;
}

#breed-celebration {
  z-index: 58;
  background: rgba(5, 10, 24, 0.82);
  backdrop-filter: blur(6px);
}
#breed-celebration .breed-celebration-card {
  position: relative;
  max-width: min(520px, 94vw);
  max-height: calc(100dvh - 2rem);
  overflow-y: auto;
  padding: 1.5rem 1.35rem 1.25rem;
  background: linear-gradient(160deg, rgba(20, 30, 55, 0.98), rgba(10, 18, 38, 0.98));
  border: 2px solid rgba(251, 191, 36, 0.45);
  border-radius: 22px;
  box-shadow: 0 0 60px rgba(251, 191, 36, 0.2), 0 24px 48px rgba(0, 0, 0, 0.5);
  text-align: center;
  animation: celebrationPop 0.55s cubic-bezier(0.34, 1.4, 0.64, 1);
}
#breed-celebration h2 {
  font-size: clamp(1.35rem, 5vw, 1.75rem);
  color: #fde68a;
  margin-bottom: 0.35rem;
}
.celebration-sparkles {
  pointer-events: none;
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: 22px;
}
.celebration-sparkles::before,
.celebration-sparkles::after {
  content: '✨';
  position: absolute;
  font-size: 1.25rem;
  animation: sparkleFloat 2.4s ease-in-out infinite;
}
.celebration-sparkles::before { left: 12%; top: 8%; animation-delay: 0s; }
.celebration-sparkles::after { right: 10%; top: 14%; animation-delay: 1.1s; content: '🌟'; }
.celebration-parents-label,
.celebration-babies-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.65;
  margin: 0.75rem 0 0.4rem;
}
.celebration-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.75rem 1rem;
}
.celebration-row.parents { margin-bottom: 0.25rem; }
.celebration-connector {
  font-size: 1.5rem;
  margin: 0.15rem 0;
  animation: heartPulse 1.2s ease-in-out infinite;
}
.celebration-pet {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  min-width: 72px;
  animation: babyBounce 0.7s ease backwards;
}
.celebration-row.babies .celebration-pet:nth-child(1) { animation-delay: 0.1s; }
.celebration-row.babies .celebration-pet:nth-child(2) { animation-delay: 0.22s; }
.celebration-row.babies .celebration-pet:nth-child(3) { animation-delay: 0.34s; }
.celebration-row.babies .celebration-pet:nth-child(4) { animation-delay: 0.46s; }
.celebration-pet.parent .celebration-portrait {
  border-color: rgba(52, 211, 153, 0.7);
  box-shadow: 0 0 18px rgba(52, 211, 153, 0.35);
}
.celebration-pet.parent:last-child .celebration-portrait {
  border-color: rgba(251, 191, 36, 0.7);
  box-shadow: 0 0 18px rgba(251, 191, 36, 0.35);
}
.celebration-portrait {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  border: 3px solid var(--pet-color, #f59e0b);
  box-shadow: 0 0 16px color-mix(in srgb, var(--pet-color, #f59e0b) 55%, transparent);
  overflow: hidden;
  background: rgba(0, 0, 0, 0.35);
}
.celebration-row.babies .celebration-portrait {
  width: 58px;
  height: 58px;
}
.celebration-portrait img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.celebration-pet strong {
  font-size: 0.82rem;
  max-width: 88px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.celebration-pet .celebration-color {
  font-size: 0.68rem;
  opacity: 0.75;
  text-transform: capitalize;
  color: var(--pet-color, #f59e0b);
}
.celebration-pet .celebration-role {
  font-size: 0.62rem;
  opacity: 0.55;
}
#breed-celebration-close {
  margin-top: 1.1rem;
  width: 100%;
}
body.breed-celebrating #mobile-controls,
body.breed-celebrating #world-panel {
  pointer-events: none;
  opacity: 0.35;
}
@keyframes celebrationPop {
  from { transform: scale(0.82); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
@keyframes sparkleFloat {
  0%, 100% { transform: translateY(0) rotate(0deg); opacity: 0.5; }
  50% { transform: translateY(-8px) rotate(12deg); opacity: 1; }
}
@keyframes heartPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}
@keyframes babyBounce {
  from { transform: translateY(16px) scale(0.85); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}

#battle-countdown {
  position: fixed; inset: 0; z-index: 55;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
  background: rgba(0,0,0,0.35);
}
#battle-countdown.hidden { display: none; }
#battle-countdown-num {
  font-size: clamp(4rem, 18vw, 8rem);
  font-weight: 900;
  color: #fff;
  text-shadow: 0 0 40px #dc2626, 0 4px 0 #7f1d1d;
  animation: countPulse 0.55s ease;
}
@keyframes countPulse {
  from { transform: scale(1.6); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

body.battle-intro #hud,
body.battle-intro #world-panel,
body.battle-intro #minimap,
body.battle-intro #mobile-controls,
body.battle-intro #controls-hint,
body.battle-intro #feed-panel {
  opacity: 0.15;
  pointer-events: none;
  transition: opacity 0.4s ease;
}
body.battle-intro #battle-hud { display: none !important; }

.battle-vignette {
  position: fixed; inset: 0; z-index: 12; pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 30%, rgba(0,0,0,0.65) 100%);
}
.battle-vignette.hidden { display: none; }

#panel-toggle {
  align-self: center; padding: 0.2rem 1rem; margin: 0.15rem;
  border: none; background: transparent; color: rgba(255,255,255,0.5);
  font-size: 0.65rem; cursor: pointer;
}

#feed-panel { bottom: 42px; }
body.panel-open #feed-panel { bottom: 200px; }
@media (max-width: 900px) {
  #feed-panel { display: none; }
  #world-panel { max-height: 180px; }
}