/* ===================================================================
   Kerala 3D Landscape Mobile UI & Touch HUD Styles
   Zero-Latency Touch, Safe Area Adapting, Mobile Pull-to-Refresh Disabled
   =================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@400;500;600;700;800&family=Plus+Jakarta+Sans:wght@500;600;700&display=swap');

:root {
  --primary: #f59e0b;
  --primary-glow: rgba(245, 158, 11, 0.4);
  --accent: #fbbf24;
  --bg-dark: rgba(24, 24, 27, 0.78);
  --border-glass: rgba(255, 255, 255, 0.15);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: #1c1917;
  font-family: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--text-main);
  touch-action: none;
  overscroll-behavior: none;
  position: fixed;
}

/* 3D Canvas Viewport */
#game-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

#game-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* Fullscreen HUD Layer */
#hud-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 10;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: env(safe-area-inset-top, 12px) env(safe-area-inset-right, 16px) env(safe-area-inset-bottom, 14px) env(safe-area-inset-left, 16px);
}

/* Top Navigation Bar */
.hud-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: auto;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-dark);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-glass);
  padding: 6px 14px;
  border-radius: 999px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}

.brand-icon {
  font-size: 20px;
}

.brand-text {
  display: flex;
  flex-direction: column;
}

.brand-text .title {
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.8px;
  color: #a7f3d0;
}

.brand-text .subtitle {
  font-size: 10px;
  font-weight: 500;
  color: var(--text-muted);
}

.stats-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.stat-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-dark);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-glass);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--primary);
  box-shadow: 0 0 8px var(--primary);
  animation: pulse-dot 2s infinite ease-in-out;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.85); }
}

.user-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-dark);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-glass);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
}

.avatar-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
}

.char-pill-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(135deg, rgba(30, 41, 59, 0.95), rgba(15, 23, 42, 0.95));
  backdrop-filter: blur(12px);
  border: 1px solid rgba(245, 158, 11, 0.45);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  color: #f8fafc;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(245, 158, 11, 0.2);
  transition: all 0.2s ease;
}

.char-pill-btn:hover {
  border-color: #f59e0b;
  box-shadow: 0 0 16px rgba(245, 158, 11, 0.4);
  transform: translateY(-1px);
}

.char-pill-icon {
  font-size: 16px;
}

.char-pill-badge {
  font-size: 10px;
  font-weight: 800;
  background: #f59e0b;
  color: #0f172a;
  padding: 2px 7px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Audio Enable & Toggle Button */
.audio-pill-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  background: linear-gradient(135deg, rgba(30, 41, 59, 0.95), rgba(15, 23, 42, 0.95));
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(245, 158, 11, 0.6);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  color: #f8fafc;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(245, 158, 11, 0.25);
  transition: all 0.25s ease;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.audio-pill-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(245, 158, 11, 0.4);
}

.audio-pill-btn:active {
  transform: translateY(0);
}

/* Prompting user to enable audio with pulsing glow */
.audio-pill-btn.prompt-enable {
  border-color: #f59e0b;
  color: #fef3c7;
  animation: audioPulse 2s infinite ease-in-out;
}

@keyframes audioPulse {
  0% {
    box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.7);
  }
  70% {
    box-shadow: 0 0 0 10px rgba(245, 158, 11, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(245, 158, 11, 0);
  }
}

/* When Audio is Active & Playing */
.audio-pill-btn.playing {
  border-color: rgba(34, 197, 94, 0.65);
  box-shadow: 0 4px 16px rgba(34, 197, 94, 0.3);
  animation: none;
}

.audio-pill-btn.playing:hover {
  border-color: #22c55e;
  box-shadow: 0 0 18px rgba(34, 197, 94, 0.5);
}

.audio-pill-btn.playing .audio-pill-label {
  color: #86efac;
}

/* When Audio is Muted */
.audio-pill-btn.muted {
  border-color: rgba(148, 163, 184, 0.4);
  box-shadow: none;
  opacity: 0.85;
}

.audio-pill-btn.muted .audio-pill-label {
  color: #94a3b8;
}

/* When Loading Audio */
.audio-pill-btn.loading {
  border-color: rgba(59, 130, 246, 0.5);
  box-shadow: 0 0 12px rgba(59, 130, 246, 0.3);
}

/* Mini Audio Equalizer Wave Animation */
.audio-pill-wave {
  display: none;
  align-items: flex-end;
  gap: 2px;
  height: 12px;
  margin-left: 2px;
}

.audio-pill-btn.playing .audio-pill-wave {
  display: flex;
}

.audio-pill-wave span {
  width: 2.5px;
  background-color: #22c55e;
  border-radius: 2px;
  animation: waveBar 1.2s ease-in-out infinite alternate;
}

.audio-pill-wave span:nth-child(1) { height: 5px; animation-delay: 0s; }
.audio-pill-wave span:nth-child(2) { height: 12px; animation-delay: 0.2s; }
.audio-pill-wave span:nth-child(3) { height: 7px; animation-delay: 0.4s; }

@keyframes waveBar {
  0% { height: 3px; }
  100% { height: 12px; }
}

/* Dynamic Floating Nametags Container */
#nametags-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: hidden;
  z-index: 5;
}

.nametag {
  position: absolute;
  transform: translate(-50%, -100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
  transition: opacity 0.15s ease;
  white-space: nowrap;
}

.nametag-badge {
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  padding: 4px 10px;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 700;
  color: #ffffff;
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.archetype-icon {
  font-size: 12px;
}

.nametag-tag {
  font-size: 9px;
  font-weight: 800;
  padding: 1px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

/* Touch Virtual Joystick Zone (Bottom Left) */
#joystick-zone {
  position: absolute;
  bottom: calc(env(safe-area-inset-bottom, 16px) + 16px);
  left: calc(env(safe-area-inset-left, 16px) + 16px);
  width: 130px;
  height: 130px;
  pointer-events: auto;
  touch-action: none;
}

#joystick-base {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(16, 185, 129, 0.12) 0%, rgba(15, 23, 42, 0.55) 75%);
  border: 2px solid rgba(16, 185, 129, 0.35);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4), inset 0 0 16px rgba(16, 185, 129, 0.15);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(8px);
}

#joystick-thumb {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #34d399, #059669);
  border: 2px solid rgba(255, 255, 255, 0.8);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5), 0 0 12px var(--primary-glow);
  position: absolute;
  transform: translate(0, 0);
  transition: transform 0.05s ease-out;
  pointer-events: none;
}

/* Action Controls (Bottom Right) */
#action-controls {
  position: absolute;
  bottom: calc(env(safe-area-inset-bottom, 16px) + 16px);
  right: calc(env(safe-area-inset-right, 16px) + 16px);
  display: flex;
  align-items: flex-end;
  gap: 14px;
  pointer-events: auto;
}

/* Secondary Action Button (Jump) */
.action-btn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #059669, #047857);
  border: 2px solid rgba(255, 255, 255, 0.4);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  color: #ffffff;
  font-size: 11px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  touch-action: none;
  outline: none;
  transition: all 0.12s ease;
}

.action-btn:active {
  transform: scale(0.92);
  background: #10b981;
}

/* Orientation Warning Screen (Portrait Prompt) */
#orientation-warning {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #022c22;
  z-index: 9999;
  display: none;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
}

@media (orientation: portrait) and (max-width: 900px) {
  #orientation-warning {
    display: flex;
  }
}

.orient-content {
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid var(--border-glass);
  padding: 32px 28px;
  border-radius: 20px;
  max-width: 320px;
}

.orient-icon {
  font-size: 48px;
  margin-bottom: 16px;
  animation: rotate-phone 2s infinite ease-in-out;
}

@keyframes rotate-phone {
  0% { transform: rotate(0deg); }
  50% { transform: rotate(90deg); }
  100% { transform: rotate(0deg); }
}

.orient-content h2 {
  font-size: 18px;
  font-weight: 800;
  color: #a7f3d0;
  margin-bottom: 8px;
}

.orient-content p {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.4;
}

/* Audio / Name Setup Modal */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(2, 44, 34, 0.82);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-backdrop.hidden {
  display: none !important;
}

.modal-card {
  background: #0f172a;
  border: 1px solid rgba(16, 185, 129, 0.35);
  padding: 24px 22px;
  border-radius: 22px;
  width: 100%;
  max-width: 480px;
  max-height: 92vh;
  overflow-y: auto;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.7), 0 0 24px var(--primary-glow);
  text-align: center;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 8px;
}

.modal-header .modal-icon {
  font-size: 26px;
}

.modal-header h2 {
  font-size: 20px;
  font-weight: 800;
  color: #f8fafc;
  flex: 1;
  text-align: center;
  padding-left: 36px; /* Offset for absolute close button */
}

.modal-close-btn {
  background: none;
  border: none;
  color: #94a3b8;
  font-size: 20px;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: all 0.2s;
}

.modal-close-btn:hover {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.1);
}

.modal-desc {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.45;
  margin-bottom: 14px;
}

/* Character Picker Showcase */
.char-picker-section {
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  padding: 12px 14px;
  margin-bottom: 16px;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.35);
}

.char-carousel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  padding: 0 4px;
}

.char-counter {
  font-size: 11px;
  font-weight: 800;
  color: #94a3b8;
  letter-spacing: 0.5px;
}

.char-badge {
  font-size: 11px;
  font-weight: 800;
  color: #f59e0b;
  background: rgba(245, 158, 11, 0.15);
  border: 1px solid rgba(245, 158, 11, 0.35);
  padding: 2px 10px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.char-carousel-wrapper {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.char-nav-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(30, 41, 59, 0.85);
  color: #f8fafc;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.char-nav-btn:hover {
  background: var(--primary);
  border-color: var(--primary);
  box-shadow: 0 0 12px var(--primary-glow);
  transform: scale(1.08);
}

.char-nav-btn:active {
  transform: scale(0.95);
}

.char-card {
  flex: 1;
  background: linear-gradient(180deg, rgba(30, 41, 59, 0.65) 0%, rgba(15, 23, 42, 0.85) 100%);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 14px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.char-icon-glow-ring {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(245, 158, 11, 0.25) 0%, rgba(15, 23, 42, 0.8) 70%);
  border: 2px solid #f59e0b;
  box-shadow: 0 0 18px rgba(245, 158, 11, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: char-pulse 2.5s infinite ease-in-out;
}

@keyframes char-pulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 16px rgba(245, 158, 11, 0.35); }
  50% { transform: scale(1.05); box-shadow: 0 0 24px rgba(245, 158, 11, 0.6); }
}

.char-preview-icon {
  font-size: 32px;
}

.char-meta .char-name {
  font-size: 15px;
  font-weight: 800;
  color: #ffffff;
  letter-spacing: 0.3px;
  margin-bottom: 2px;
}

.char-meta .char-lore {
  font-size: 11px;
  color: #94a3b8;
  line-height: 1.35;
  max-width: 260px;
  margin: 0 auto;
}

.char-thumb-strip {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 4px 2px 2px 2px;
  scrollbar-width: thin;
}

.char-thumb-strip::-webkit-scrollbar {
  height: 4px;
}

.char-thumb-strip::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 2px;
}

.char-thumb-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(30, 41, 59, 0.7);
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.15s ease;
}

.char-thumb-btn:hover {
  border-color: #f59e0b;
  transform: translateY(-2px);
}

.char-thumb-btn.active {
  background: rgba(245, 158, 11, 0.25);
  border-color: #f59e0b;
  box-shadow: 0 0 10px rgba(245, 158, 11, 0.6);
  transform: scale(1.1);
}

.input-row {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  margin-bottom: 22px;
}

.input-row label {
  font-size: 12px;
  font-weight: 700;
  color: #cbd5e1;
}

.input-row input {
  width: 100%;
  background: #1e293b;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 14px;
  font-weight: 600;
  color: #f8fafc;
  outline: none;
  transition: border-color 0.2s;
}

.input-row input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 12px var(--primary-glow);
}

.btn-primary {
  width: 100%;
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  border: none;
  border-radius: 12px;
  padding: 14px 20px;
  font-size: 15px;
  font-weight: 800;
  color: #ffffff;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(16, 185, 129, 0.4);
  transition: all 0.15s ease;
}

.btn-primary:active {
  transform: scale(0.98);
}

.modal-subtext {
  display: block;
  font-size: 11px;
  color: #64748b;
  margin-top: 14px;
}

.hidden {
  display: none !important;
}

@media (max-width: 768px) {
  .hud-top-bar {
    gap: 6px;
  }
  .brand-text .subtitle {
    display: none;
  }
  .stat-pill.ping-pill {
    display: none;
  }
  .audio-pill-btn {
    padding: 5px 10px;
    font-size: 11px;
    gap: 5px;
  }
  .char-pill-btn {
    padding: 5px 10px;
    font-size: 11px;
    gap: 5px;
  }
}
