:root {
  --panel-bg: rgba(24, 26, 22, 0.84);
  --panel-border: rgba(217, 179, 108, 0.28);
  --text-main: #fef3c7;
  --text-muted: #cbd5c0;
  --gold: #f59e0b;
  --gold-bright: #fbbf24;
  --emerald: #34d399;
  --btn-bg: rgba(255, 255, 255, 0.07);
  --btn-hover: rgba(251, 191, 36, 0.18);
}

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

html, body {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  background: radial-gradient(circle at 55% 45%, #faf8f5 0%, #ede8df 60%, #dcd4c6 100%);
  color: var(--text-main);
  transition: background 0.8s ease;
}

body.afternoon-mode {
  background: radial-gradient(circle at 55% 42%, #fde68a 0%, #f59e0b 40%, #9a3412 80%, #451a03 100%);
}

body.night-mode {
  background: radial-gradient(circle at 55% 45%, #1e2436 0%, #111522 60%, #080a10 100%);
}

#canvas-container {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  touch-action: none;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
}

canvas:active {
  cursor: grabbing;
}

/* Floating HUD */
.hud-panel {
  position: fixed;
  top: 14px;
  left: 14px;
  width: 342px;
  z-index: 16;
  background: var(--panel-bg);
  backdrop-filter: blur(14px) saturate(160%);
  -webkit-backdrop-filter: blur(14px) saturate(160%);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 12px 13px;
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.42), inset 0 1px 0 rgba(255, 255, 255, 0.12);
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: calc(100dvh - 28px);
  overflow-y: auto;
  scrollbar-width: thin;
}

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

.hud-title {
  font-size: 14.5px;
  font-weight: 700;
  color: #fde68a;
  display: flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
  flex-shrink: 0;
}

.hud-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #34d399;
  box-shadow: 0 0 8px #34d399;
  flex-shrink: 0;
}

.fps-badge {
  display: none;
}

.hud-desc {
  font-size: 11.5px;
  line-height: 1.42;
  color: var(--text-muted);
}

.stats-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(12, 14, 11, 0.65);
  border: 1px solid rgba(251, 191, 36, 0.15);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 11.5px;
  color: #e5e7eb;
}

.stat-val {
  font-weight: 700;
  color: var(--gold-bright);
}

.hud-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.section-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #a3b19b;
}

.btn-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.hud-btn {
  appearance: none;
  border: 1px solid rgba(251, 191, 36, 0.2);
  background: var(--btn-bg);
  color: #fef3c7;
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 500;
  padding: 7px 9px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  white-space: nowrap;
}

.hud-btn:hover {
  background: var(--btn-hover);
  border-color: rgba(251, 191, 36, 0.48);
}

.hud-btn:active {
  transform: scale(0.97);
}

.hud-btn.active {
  border-color: #fbbf24;
  background: rgba(245, 158, 11, 0.22);
  color: #ffffff;
  box-shadow: 0 0 10px rgba(245, 158, 11, 0.22);
}

.hud-btn.full-width {
  width: 100%;
  font-weight: 600;
}

.bottom-hint-pill {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  background: rgba(24, 26, 22, 0.86);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(217, 179, 108, 0.26);
  border-radius: 999px;
  padding: 7px 18px;
  font-size: 11.5px;
  color: #fef3c7;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
  white-space: nowrap;
  pointer-events: none;
}

/* Proximity Incense Offering Prompt Banner */
.incense-prompt {
  position: fixed;
  bottom: calc(168px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  z-index: 15;
  width: max-content;
  max-width: calc(100vw - 28px);
  background: linear-gradient(135deg, rgba(180, 83, 9, 0.94), rgba(124, 45, 18, 0.96));
  border: 1.5px solid #fde047;
  border-radius: 16px;
  padding: 9px 16px;
  font-size: 12.5px;
  font-weight: 700;
  line-height: 1.38;
  text-align: center;
  color: #fef9c3;
  box-shadow: 0 10px 30px rgba(245, 158, 11, 0.45), 0 0 16px rgba(251, 191, 36, 0.35);
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease;
  white-space: normal;
}

.incense-prompt.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}

.incense-prompt:active {
  transform: translateX(-50%) scale(0.96);
}

/* First-person Lotus Reticle */
.fp-reticle {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 22px;
  height: 22px;
  border: 1.5px solid rgba(253, 230, 138, 0.78);
  border-radius: 50%;
  z-index: 8;
  pointer-events: none;
  display: none;
  box-shadow: 0 0 10px rgba(245, 158, 11, 0.45);
}
.fp-reticle::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 4px;
  height: 4px;
  background: #fde047;
  border-radius: 50%;
  transform: translate(-50%, -50%);
}
.fp-reticle.visible {
  display: block;
}

/* Header Right Actions & Collapse Button */
.hud-header-right {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: nowrap;
}

.hud-collapse-btn {
  appearance: none;
  border: 1px solid rgba(251, 191, 36, 0.28);
  background: rgba(255, 255, 255, 0.08);
  color: #fde68a;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 9px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.hud-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.hud-panel.collapsed .hud-body {
  display: none;
}

/* Quick bar shown when HUD is collapsed */
.hud-quick-bar {
  display: none;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
  margin-top: 2px;
}

.hud-panel.collapsed .hud-quick-bar {
  display: grid;
}

/* Mobile & First-Person Virtual Joystick + Floating Action Pad */
.fp-mobile-controls {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 12;
  display: none;
}

.fp-mobile-controls.visible {
  display: block;
}

.joystick-zone {
  position: absolute;
  bottom: calc(28px + env(safe-area-inset-bottom, 0px));
  left: 22px;
  width: 118px;
  height: 118px;
  border-radius: 50%;
  background: rgba(20, 22, 18, 0.62);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1.5px solid rgba(251, 191, 36, 0.38);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45), inset 0 0 18px rgba(251, 191, 36, 0.12);
  pointer-events: auto;
  touch-action: none;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: left 0.22s ease, opacity 0.2s ease;
}

@media (min-width: 769px) {
  #hud-panel:not(.collapsed) ~ #fp-mobile-controls .joystick-zone {
    left: 372px;
  }
}
.joystick-arrows {
  position: absolute;
  inset: 6px;
  pointer-events: none;
  color: rgba(253, 230, 138, 0.42);
  font-size: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.joystick-arrows span {
  position: absolute;
}
.joystick-arrows .arr-u { top: 2px; left: 50%; transform: translateX(-50%); }
.joystick-arrows .arr-d { bottom: 2px; left: 50%; transform: translateX(-50%); }
.joystick-arrows .arr-l { left: 4px; top: 50%; transform: translateY(-50%); }
.joystick-arrows .arr-r { right: 4px; top: 50%; transform: translateY(-50%); }

.joystick-knob {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fde047, #d97706);
  border: 2px solid rgba(255, 255, 255, 0.65);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5), 0 0 12px rgba(245, 158, 11, 0.55);
  pointer-events: none;
  transform: translate(0px, 0px);
  transition: transform 0.04s linear;
}

.fp-action-pad {
  position: absolute;
  bottom: calc(28px + env(safe-area-inset-bottom, 0px));
  right: 20px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  pointer-events: auto;
  touch-action: none;
}

.fp-action-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.mob-action-btn {
  appearance: none;
  border: 1.5px solid rgba(251, 191, 36, 0.45);
  background: rgba(24, 26, 22, 0.78);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: #fef3c7;
  border-radius: 999px;
  padding: 10px 14px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.45);
  cursor: pointer;
  touch-action: manipulation;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.mob-action-btn.primary-bow {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.88), rgba(180, 83, 9, 0.92));
  color: #ffffff;
  border-color: #fde047;
  padding: 13px 18px;
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(245, 158, 11, 0.4);
}

.mob-action-btn:active {
  transform: scale(0.94);
}
/* =========================================================================
   REALTIME MULTI-USER ONBOARDING MODAL & ONLINE PILGRIMS HUD
   ========================================================================= */
.join-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: radial-gradient(circle at 50% 45%, rgba(28, 19, 14, 0.72), rgba(10, 8, 6, 0.90));
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  transition: opacity 0.32s ease, visibility 0.32s ease;
}
.join-modal-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
.join-modal-card {
  width: 100%;
  max-width: 430px;
  background: linear-gradient(165deg, rgba(36, 26, 20, 0.96), rgba(22, 16, 13, 0.98));
  border: 1.5px solid rgba(251, 191, 36, 0.42);
  border-radius: 18px;
  padding: 22px 22px 20px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.75), 0 0 36px rgba(245, 158, 11, 0.16);
  color: #fef3c7;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.join-modal-header {
  text-align: center;
  border-bottom: 1px solid rgba(251, 191, 36, 0.18);
  padding-bottom: 12px;
}
.join-modal-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(16, 185, 129, 0.16);
  border: 1px solid rgba(52, 211, 153, 0.38);
  color: #34d399;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.4px;
  margin-bottom: 6px;
}
.join-modal-title {
  font-size: 18px;
  font-weight: 800;
  color: #fde68a;
  letter-spacing: 0.3px;
}
.join-modal-sub {
  font-size: 12px;
  color: #cbd5e1;
  margin-top: 4px;
  line-height: 1.4;
}
.join-field-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.join-field-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #fcd34d;
}
.join-name-input {
  width: 100%;
  padding: 10px 13px;
  border-radius: 10px;
  border: 1px solid rgba(251, 191, 36, 0.35);
  background: rgba(12, 10, 9, 0.78);
  color: #fffbeb;
  font-size: 14px;
  font-weight: 600;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  user-select: text;
  -webkit-user-select: text;
}
.join-name-input:focus {
  border-color: #fbbf24;
  box-shadow: 0 0 0 3px rgba(251, 191, 36, 0.2);
}
.join-gender-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.join-gender-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 12px 10px;
  border-radius: 12px;
  border: 1.5px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.04);
  color: #e2e8f0;
  cursor: pointer;
  transition: all 0.18s ease;
}
.join-gender-card:hover {
  background: rgba(251, 191, 36, 0.1);
  border-color: rgba(251, 191, 36, 0.4);
}
.join-gender-card.active {
  background: linear-gradient(145deg, rgba(245, 158, 11, 0.24), rgba(180, 83, 9, 0.34));
  border-color: #fbbf24;
  color: #fef08a;
  box-shadow: 0 4px 16px rgba(245, 158, 11, 0.25);
}
.join-gender-icon {
  font-size: 26px;
  line-height: 1;
}
.join-gender-name {
  font-size: 13px;
  font-weight: 700;
}
.join-gender-desc {
  font-size: 10.5px;
  color: #94a3b8;
}
.join-gender-card.active .join-gender-desc {
  color: #fde68a;
}
.join-submit-btn {
  width: 100%;
  padding: 12px 16px;
  border-radius: 11px;
  border: 1px solid #fde047;
  background: linear-gradient(135deg, #d97706, #b45309);
  color: #ffffff;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(217, 119, 6, 0.4);
  transition: transform 0.15s, filter 0.15s;
  margin-top: 2px;
}
.join-submit-btn:hover {
  filter: brightness(1.08);
}
.join-submit-btn:active {
  transform: scale(0.98);
}

/* Online Pilgrims List inside HUD */
.online-pilgrims-box {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 112px;
  overflow-y: auto;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(251, 191, 36, 0.18);
  border-radius: 9px;
  padding: 5px 6px;
}
.online-pilgrim-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 4px 7px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.04);
  font-size: 11.2px;
  cursor: pointer;
  transition: background 0.15s;
}
.online-pilgrim-row:hover {
  background: rgba(251, 191, 36, 0.15);
}
.online-pilgrim-row.is-self {
  border-left: 2.5px solid #34d399;
  background: rgba(16, 185, 129, 0.09);
}
.online-pilgrim-left {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
  overflow: hidden;
}
.online-pilgrim-name {
  font-weight: 700;
  color: #fef3c7;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.online-pilgrim-meta {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
  font-size: 10.5px;
}
.online-pilgrim-zone {
  color: #93c5fd;
  background: rgba(30, 58, 138, 0.35);
  padding: 1px 5px;
  border-radius: 4px;
}
.online-pilgrim-act {
  color: #fde047;
  font-weight: 600;
}

/* Full-Screen Interactive Satellite Sketch Map Modal (Key M, inspired by research-3d) */
.sat-map-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 480;
  background: radial-gradient(circle at 50% 45%, rgba(15, 23, 42, 0.82), rgba(6, 10, 18, 0.94));
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
}
.sat-map-modal-overlay.open {
  display: flex;
}
.sat-map-modal-card {
  width: 100%;
  max-width: 920px;
  background: linear-gradient(165deg, rgba(24, 28, 24, 0.96), rgba(14, 18, 22, 0.98));
  border: 1.5px solid rgba(251, 191, 36, 0.45);
  border-radius: 18px;
  padding: 16px 18px;
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.72);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.sat-map-modal-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.sat-map-modal-title {
  font-size: 16px;
  font-weight: 800;
  color: #fde68a;
  display: flex;
  align-items: center;
  gap: 8px;
}
.sat-map-modal-sub {
  font-size: 11.5px;
  color: #cbd5c0;
}
.sat-map-close-btn {
  appearance: none;
  border: 1px solid rgba(251, 191, 36, 0.4);
  background: rgba(245, 158, 11, 0.16);
  color: #fef3c7;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
.sat-map-close-btn:hover {
  background: rgba(245, 158, 11, 0.32);
}
.sat-map-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 1055 / 720;
  max-height: 68vh;
  border-radius: 12px;
  overflow: hidden;
  border: 1.5px solid rgba(251, 191, 36, 0.35);
  background: #182820;
  cursor: crosshair;
}
#sat-fullmap-canvas {
  width: 100%;
  height: 100%;
  display: block;
}
.sat-map-pins-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.sat-pin-chip {
  appearance: none;
  border: 1px solid rgba(251, 191, 36, 0.3);
  background: rgba(255, 255, 255, 0.06);
  color: #fef3c7;
  font-size: 11px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.sat-pin-chip:hover {
  background: rgba(251, 191, 36, 0.22);
  border-color: #fbbf24;
  color: #ffffff;
}
/* Mahayana Main Hall Part-by-Part Assembly HUD & Blueprint Modal */
.hall-assembly-box {
  background: rgba(12, 15, 12, 0.76);
  border: 1px solid rgba(251, 191, 36, 0.28);
  border-radius: 10px;
  padding: 8px 9px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.hall-stage-pill {
  appearance: none;
  border: 1px solid rgba(251, 191, 36, 0.22);
  background: rgba(255, 255, 255, 0.05);
  color: #e2e8f0;
  font-size: 10.2px;
  font-weight: 600;
  padding: 4.5px 2px;
  border-radius: 6px;
  cursor: pointer;
  text-align: center;
  transition: all 0.14s ease;
  white-space: nowrap;
}
.hall-stage-pill:hover {
  border-color: #fbbf24;
  background: rgba(251, 191, 36, 0.18);
  color: #ffffff;
}
.hall-stage-pill.active {
  border-color: #fbbf24;
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.34), rgba(180, 83, 9, 0.42));
  color: #fef08a;
  box-shadow: 0 0 8px rgba(245, 158, 11, 0.28);
}
.hall-cam-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
}
@media (max-width: 768px) {
  .hud-panel {
    top: 10px;
    left: 10px;
    right: 10px;
    width: calc(100vw - 20px);
    padding: 10px 11px;
    max-height: 74dvh;
    overflow-y: auto;
  }
  .hud-title {
    font-size: 13.5px;
    gap: 6px;
  }
  .hud-collapse-btn {
    font-size: 10.5px;
    padding: 4px 8px;
  }
  .hud-desc {
    display: none;
  }
  .incense-prompt {
    bottom: calc(176px + env(safe-area-inset-bottom, 0px));
    max-width: calc(100vw - 24px);
    font-size: 11.8px;
    padding: 8px 13px;
    border-radius: 14px;
  }
  .joystick-zone {
    left: 14px;
    bottom: calc(18px + env(safe-area-inset-bottom, 0px));
    width: 104px;
    height: 104px;
  }
  .joystick-knob {
    width: 42px;
    height: 42px;
  }
  .fp-action-pad {
    right: 12px;
    bottom: calc(18px + env(safe-area-inset-bottom, 0px));
    gap: 7px;
  }
  .fp-action-row {
    gap: 6px;
  }
  .mob-action-btn {
    padding: 8px 11px;
    font-size: 11.2px;
    white-space: nowrap;
  }
  .mob-action-btn.primary-bow {
    padding: 10px 15px;
    font-size: 12px;
  }
  .bottom-hint-pill {
    bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    font-size: 10.5px;
    padding: 5px 12px;
    max-width: calc(100vw - 20px);
    overflow: hidden;
    text-overflow: ellipsis;
  }
  body.fp-active .bottom-hint-pill {
    display: none;
  }
  #hud-panel:not(.collapsed) ~ #fp-mobile-controls {
    opacity: 0;
    pointer-events: none;
  }
}
