/* Reset Everything */
* {
  box-sizing: border-box;
  user-select: none; /* Stop text highlighting on touch */
  -webkit-user-select: none;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background-color: #000;
  font-family: sans-serif;
}

/* --- LAYER 1: The 3D World --- */
#canvas-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1; /* Base Layer */
}

canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

/* --- LAYER 2: The Touch Controls (D-Pad) --- */
#touch-ui-container {
  position: fixed; /* Stronger than absolute */
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 10; /* Above Canvas */
  pointer-events: none; /* Let clicks pass through empty areas */
}

/* Look Zone (Right Half) */
#touch-look-zone {
  position: absolute;
  top: 0;
  right: 0;
  width: 50%;
  height: 100%;
  pointer-events: auto; /* Catch touches here */
  touch-action: none;
}

/* D-Pad (Bottom Left) */
#d-pad {
  position: absolute;
  bottom: 30px; /* Lift it up slightly */
  left: 30px;
  width: 160px;
  height: 160px;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr;
  gap: 5px; /* Spacing between buttons */
  pointer-events: auto; /* Catch touches here */
  touch-action: none;
}

.d-btn {
  background: rgba(255, 255, 255, 0.15);
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 10px;
  color: white;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 24px;
  cursor: pointer;
}

.d-btn:active {
  background: rgba(255, 255, 255, 0.5);
}

/* Grid Layout */
#d-up {
  grid-column: 2;
  grid-row: 1;
}
#d-left {
  grid-column: 1;
  grid-row: 2;
}
#d-right {
  grid-column: 3;
  grid-row: 2;
}
#d-down {
  grid-column: 2;
  grid-row: 3;
}

/* --- LAYER 3: The Instructions Modal --- */
#touch-instructions {
  position: fixed; /* Stronger than absolute */
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.85);
  z-index: 10001; /* Topmost Layer */

  display: flex;
  justify-content: center;
  align-items: center;

  transition: opacity 0.3s ease;
}

#touch-instructions.hidden {
  opacity: 0;
  pointer-events: none; /* Stop blocking clicks when hidden */
}

.modal-content {
  background: #222;
  padding: 30px;
  border-radius: 12px;
  text-align: center;
  color: white;
  border: 1px solid #444;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.modal-content button {
  background: #007aff;
  color: white;
  border: none;
  padding: 12px 24px;
  border-radius: 6px;
  font-size: 16px;
  margin-top: 15px;
  cursor: pointer;
}

/* --- LAYER 4: Developer Panel --- */
#dev-panel-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.6);
  color: #0f0;
  border: 1px solid #0f0;
  padding: 5px 10px;
  cursor: pointer;
  font-family: monospace;
  font-weight: bold;
  display: none; /* Hidden by default */
}

#dev-panel {
  position: absolute;
  top: 50px;
  right: 10px;
  width: 250px;
  background: rgba(0, 0, 0, 0.85);
  color: #eee;
  padding: 15px;
  border-radius: 8px;
  border: 1px solid #444;
  font-family: monospace;
  font-size: 12px;
  z-index: 1000;
  display: none; /* Hidden by default */
}

#dev-panel h3 {
  margin-top: 0;
  color: #0f0;
  border-bottom: 1px solid #444;
  padding-bottom: 5px;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 5px;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
  cursor: pointer;
}

.toggle-row input {
  margin-right: 10px;
}

.section-divider {
  border-top: 1px solid #444;
  margin: 10px 0;
}

#player-branding {
  position: absolute;
  bottom: 20px;
  right: 20px;
  z-index: 50; /* Above the canvas (z-index 1), below the Dev Panel (z-index 1000) */
  opacity: 0.8;
  pointer-events: auto; /* Make clickable */
  user-select: none;
  text-decoration: none;
  cursor: pointer;
  transition: opacity 0.2s;
}

#player-branding:hover {
  opacity: 1;
}

#player-branding img {
  width: 150px; /* Adjust this to change the size */
  height: auto; /* Maintains aspect ratio */
  display: block;
}

/* --- LOADING SCREEN STYLES --- */
#loading-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: #1a1a1a; /* Dark background matching your editor theme */
  z-index: 99999; /* On top of everything */
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  transition: opacity 0.8s ease-out; /* Smooth fade away */
}

/* The Logo */
#loading-logo {
  width: 200px; /* Bigger than the corner logo */
  height: auto;
  margin-bottom: 20px;
}

/* The Pulsing Text */
#loading-text {
  color: #ffffff;
  font-family: sans-serif;
  font-size: 1.2rem;
  font-weight: 300;
  letter-spacing: 2px;
  opacity: 0.5;
  animation: pulse 1.5s infinite ease-in-out;
}

/* Pulse Animation Keyframes */
@keyframes pulse {
  0% {
    opacity: 0.3;
  }
  50% {
    opacity: 1;
  }
  100% {
    opacity: 0.3;
  }
}

/* Utility class to hide it */
.fade-out {
  opacity: 0;
  pointer-events: none; /* Let clicks pass through while fading */
}

/* --- ROTATION TRANSITION OVERLAY (prevents black flash) --- */
#rotation-transition {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
  z-index: 9999;
  display: flex;
  justify-content: center;
  align-items: center;
  opacity: 1;
  transition: opacity 0.4s ease-out;
  pointer-events: none;
}

#rotation-transition.hidden {
  opacity: 0;
}

#rotation-transition::after {
  content: "Adjusting view...";
  color: rgba(255, 255, 255, 0.7);
  font-size: 14px;
  font-family: sans-serif;
}

/* --- ROTATE WARNING MODAL --- */
#rotate-warning {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: #000; /* Solid black to hide the game */
  z-index: 10000; /* Must be on top of EVERYTHING */

  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
}

#rotate-warning.hidden {
  display: none;
}

.rotate-content {
  text-align: center;
  color: white;
}

.rotate-icon {
  font-size: 80px;
  margin-bottom: 20px;
  animation: spin-icon 2s infinite ease-in-out;
}

@keyframes spin-icon {
  0% {
    transform: rotate(0deg);
  }
  25% {
    transform: rotate(-90deg);
  }
  100% {
    transform: rotate(-90deg);
  }
}

/* --- HELP BUTTON (Upper Left) --- */
#help-btn {
  position: fixed;
  top: 15px;
  left: 15px;
  z-index: 500;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.6);
  border: 2px solid rgba(255, 255, 255, 0.3);
  color: white;
  font-size: 20px;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, border-color 0.2s;
}

#help-btn:hover {
  background: rgba(0, 0, 0, 0.8);
  border-color: rgba(255, 255, 255, 0.6);
}

/* --- HAMBURGER BUTTON (Upper Right) --- */
#hamburger-btn {
  position: fixed;
  top: 15px;
  right: 15px;
  z-index: 500;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.6);
  border: 2px solid rgba(255, 255, 255, 0.3);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 8px;
  transition: background 0.2s, border-color 0.2s;
}

#hamburger-btn:hover {
  background: rgba(0, 0, 0, 0.8);
  border-color: rgba(255, 255, 255, 0.6);
}

#hamburger-btn span {
  display: block;
  width: 20px;
  height: 2px;
  background: white;
  border-radius: 1px;
}

/* --- HAMBURGER MENU DROPDOWN --- */
#hamburger-menu {
  position: fixed;
  top: 65px;
  right: 15px;
  z-index: 500;
  background: rgba(30, 30, 30, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  min-width: 180px;
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

#hamburger-menu.hidden {
  display: none;
}

#hamburger-menu button.hidden {
  display: none;
}

#hamburger-menu button,
#hamburger-menu a {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 14px 18px;
  background: none;
  border: none;
  color: white;
  font-size: 14px;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.2s;
}

/* Map pin icon - language-agnostic, used for POI */
.menu-icon-pin {
  display: inline-block;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M12 2C8.13 2 5 5.13 5 9c0 5.25 7 13 7 13s7-7.75 7-13c0-3.87-3.13-7-7-7zm0 9.5c-1.38 0-2.5-1.12-2.5-2.5s1.12-2.5 2.5-2.5 2.5 1.12 2.5 2.5-1.12 2.5-2.5 2.5z'/%3E%3C/svg%3E") center/contain no-repeat;
}

.poi-item .menu-icon-pin {
  width: 16px;
  height: 16px;
  opacity: 0.9;
}

.overlay-header h2 .menu-icon-pin,
.overlay-header h2 .menu-icon-gear,
.overlay-header h2 .menu-icon-plus {
  margin-right: 6px;
  vertical-align: middle;
}

/* Gear/cog icon for Settings */
.menu-icon-gear {
  display: inline-block;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M19.14 12.94c.04-.31.06-.63.06-.94 0-.31-.02-.63-.06-.94l2.03-1.58c.18-.14.23-.41.12-.61l-1.92-3.32c-.12-.22-.37-.29-.59-.22l-2.39.96c-.5-.38-1.03-.7-1.62-.94l-.36-2.54c-.04-.24-.24-.41-.48-.41h-3.84c-.24 0-.43.17-.47.41l-.36 2.54c-.59.24-1.13.57-1.62.94l-2.39-.96c-.22-.08-.47 0-.59.22L2.74 8.87c-.12.21-.08.47.12.61l2.03 1.58c-.04.31-.06.63-.06.94s.02.63.06.94l-2.03 1.58c-.18.14-.23.41-.12.61l1.92 3.32c.12.22.37.29.59.22l2.39-.96c.5.38 1.03.7 1.62.94l.36 2.54c.05.24.24.41.48.41h3.84c.24 0 .44-.17.47-.41l.36-2.54c.59-.24 1.13-.56 1.62-.94l2.39.96c.22.08.47 0 .59-.22l1.92-3.32c.12-.22.07-.47-.12-.61l-2.01-1.58zM12 15.6c-1.98 0-3.6-1.62-3.6-3.6s1.62-3.6 3.6-3.6 3.6 1.62 3.6 3.6-1.62 3.6-3.6 3.6z'/%3E%3C/svg%3E") center/contain no-repeat;
}

/* VR headset icon for Enter VR */
.menu-icon-headset {
  display: inline-block;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M20.5 11.19c0-1.43-1.14-2.59-2.5-2.59-.72 0-1.37.29-1.85.76V11.2c0-.55-.45-1-1-1h-1V7.5C14.65 5.57 12.78 4 10.5 4S6.35 5.57 6.35 7.5V10.2h-1c-.55 0-1 .45-1 1v1.26c-.5-.48-1.14-.77-1.85-.77-1.36 0-2.5 1.16-2.5 2.59 0 1.19.86 2.18 2 2.43V20c0 .55.45 1 1 1h3v-4h4v4h3c.55 0 1-.45 1-1v-6.38c1.14-.25 2-1.24 2-2.43zM7.35 7.5c0-1.73 1.41-3.14 3.15-3.14s3.15 1.41 3.15 3.14v2.7H7.35V7.5zm11 6.81c0 .55-.45 1-1 1h-2v2h-2v-2h-2c-.55 0-1-.45-1-1v-3.16c.48.29 1.04.46 1.65.46 1.36 0 2.5-1.16 2.5-2.59 0-.55-.18-1.06-.49-1.5.31-.44.49-.95.49-1.5v.19z'/%3E%3C/svg%3E") center/contain no-repeat;
}

/* Plus icon for Add Model */
.menu-icon-plus {
  display: inline-block;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z'/%3E%3C/svg%3E") center/contain no-repeat;
}

#hamburger-menu button:hover,
#hamburger-menu a:hover {
  background: rgba(255, 255, 255, 0.1);
}

#hamburger-menu .menu-divider {
  height: 1px;
  background: rgba(255, 255, 255, 0.15);
  margin: 5px 0;
}

/* --- OVERLAY BASE STYLES --- */
.overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.85);
  z-index: 600;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: opacity 0.3s ease;
}

.overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.overlay-content {
  background: #1e1e1e;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  padding: 25px;
  max-width: 400px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  color: white;
}

.overlay-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 15px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
}

.overlay-header h2 {
  margin: 0;
  font-size: 18px;
}

.overlay-close {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.6);
  font-size: 28px;
  cursor: pointer;
  line-height: 1;
  padding: 0;
  width: 30px;
  height: 30px;
}

.overlay-close:hover {
  color: white;
}

/* --- POI LIST --- */
#poi-list-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.poi-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  padding: 12px 15px;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}

.poi-item:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.25);
}

.poi-empty {
  color: rgba(255, 255, 255, 0.5);
  text-align: center;
  padding: 20px;
}

/* --- SETTINGS OVERLAY --- */
.settings-group {
  margin-bottom: 20px;
}

.settings-group label {
  display: block;
  font-size: 14px;
  color: rgba(255, 255, 255, 0.8);
  margin-bottom: 8px;
}

.setting-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.setting-row input[type="range"] {
  flex: 1;
  accent-color: #007aff;
}

.setting-row span {
  min-width: 110px;
  text-align: right;
  font-size: 14px;
  color: rgba(255, 255, 255, 0.6);
  white-space: nowrap;
}

.setting-row select {
  flex: 1;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  color: white;
  font-size: 14px;
}

.setting-row select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Settings Footer */
.settings-footer {
  margin-top: 20px;
  padding-top: 15px;
  border-top: 1px solid rgba(255, 255, 255, 0.15);
  text-align: center;
}

.reset-btn {
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.2);
  padding: 10px 20px;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.reset-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  color: white;
}

/* --- INSTRUCTIONS MODALS --- */
.instructions-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.9);
  z-index: 700;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: opacity 0.3s ease;
}

.instructions-modal.hidden {
  opacity: 0;
  pointer-events: none;
}

.instructions-modal .modal-content {
  background: #222;
  padding: 30px;
  border-radius: 12px;
  text-align: center;
  color: white;
  border: 1px solid #444;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
  max-width: 400px;
  width: 90%;
}

.instructions-modal h2 {
  margin-top: 0;
  margin-bottom: 20px;
}

.controls-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 25px;
  text-align: left;
}

.control-item {
  display: flex;
  align-items: center;
  gap: 10px;
}

.control-item .key {
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 4px;
  padding: 6px 10px;
  font-size: 12px;
  min-width: 60px;
  text-align: center;
  font-family: monospace;
}

.control-item .icon {
  font-size: 16px;
  min-width: 60px;
  text-align: center;
}

/* Crosshair/target icon for Teleport instruction */
.control-icon-crosshair {
  display: inline-block;
  width: 24px;
  height: 24px;
  min-width: 24px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8zm-1-13h2v4h-2zm0 6h2v4h-2zm5-7v2h-4V6zm-6 0V4h4v2zm7 7h2v2h-2zm-14 0h2v2H4zm11 5v2h-2v-2zm-6 0v2H7v-2zm7-7h-2V4h2v2z'/%3E%3C/svg%3E") center/contain no-repeat;
}

.modal-close-btn {
  background: #007aff;
  color: white;
  border: none;
  padding: 12px 30px;
  border-radius: 6px;
  font-size: 16px;
  cursor: pointer;
  transition: background 0.2s;
}

.modal-close-btn:hover {
  background: #0056b3;
}
