/* Reset Everything */
* {
  box-sizing: border-box;
  user-select: none; /* Stop text highlighting on touch */
  -webkit-user-select: none;
}

/* 1vh fallback until player_main sets --player-vh from inner/visual viewport (fixes mobile rotation) */
:root {
  --player-vh: 1vh;
}

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) ---
   Keep z-index low: measure/sticky HUD uses 30000+ so WebKit mobile does not composite
   the full-screen touch layer above fixed overlays. */
#touch-ui-container {
  position: fixed; /* Stronger than absolute */
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 2; /* Above canvas (1); below all player HUD (see #measure-ui, #sticky-note-popup) */
  pointer-events: none; /* Let clicks pass through empty areas */
}

/* Full-screen look + tap zone (was right half only; left half had no touch handlers, so sticky notes / tap-to-interact failed there) */
#touch-look-zone {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  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: 25000;
  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: 40010;
  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: 40000;
  background: rgba(30, 30, 30, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  min-width: 180px;
  min-height: 0;
  /* --player-vh last so JS (visualViewport / innerHeight) wins over vh/dvh after mobile rotation */
  max-height: calc(100vh - 100px);
  max-height: calc(100dvh - 100px);
  max-height: calc(100 * var(--player-vh) - 100px);
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  overscroll-behavior-y: contain;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

/* Mobile / touch: force dropdown to stay within viewport and scroll (iOS needs explicit scroll + bounded height) */
@media (max-width: 1024px), (pointer: coarse) {
  #hamburger-menu {
    max-height: min(70vh, calc(100 * var(--player-vh) - 80px)) !important;
    max-height: min(70dvh, calc(100 * var(--player-vh) - 80px)) !important;
    overflow-y: scroll !important;
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
  }
}

/* Ensure scrollable menu on very short viewports */
@media (max-height: 500px), (max-width: 480px) {
  #hamburger-menu {
    max-height: min(55vh, calc(100 * var(--player-vh) - 120px)) !important;
    max-height: min(55dvh, calc(100 * var(--player-vh) - 120px)) !important;
    top: 55px;
    right: 10px;
  }
}

#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 (inline SVG — same pattern as other menu icons; no PNG fetch) */
.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='none' stroke='white' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 18v-6a9 9 0 0 1 18 0v6'/%3E%3Cpath d='M21 19a2 2 0 0 1-2 2h-1a2 2 0 0 1-2-2v-3a2 2 0 0 1 2-2h3zM3 19a2 2 0 0 0 2 2h1a2 2 0 0 0 2-2v-3a2 2 0 0 0-2-2H3z'/%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;
}

.menu-icon-fullscreen {
  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='M7 14H5v5h5v-2H7v-3zm-2-4h2V7h3V5H5v5zm12 7h-3v2h5v-5h-2v3zM14 5v2h3v3h2V5h-5z'/%3E%3C/svg%3E") center/contain no-repeat;
}

/* Sticky note icon for Add Sticky Note */
.menu-icon-note {
  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 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-5 14H7v-2h7v2zm3-4H7v-2h10v2zm0-4H7V7h10v2z'/%3E%3C/svg%3E") center/contain no-repeat;
}

/* Tape measure — side view (housing + blade + ticks) */
.menu-icon-ruler {
  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='none' stroke='white' stroke-width='1.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='1.5' y='8' width='8' height='8' rx='1.5'/%3E%3Cpath d='M9.5 10.5h13M9.5 12.5h13M9.5 14.5h11'/%3E%3Cline x1='12' y1='7' x2='12' y2='8.2'/%3E%3Cline x1='15' y1='7' x2='15' y2='8.2'/%3E%3Cline x1='18' y1='7' x2='18' y2='8.2'/%3E%3Cline x1='21' y1='7' x2='21' y2='8.2'/%3E%3Cpath d='M3 8c0-2 2-3 3.5-2.5'/%3E%3C/svg%3E") center/contain no-repeat;
}

/* Info circle — About link */
.menu-icon-info {
  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='none' stroke='white' stroke-width='1.5'%3E%3Ccircle cx='12' cy='12' r='8.5'/%3E%3Ccircle cx='12' cy='8' r='1.1' fill='white' stroke='none'/%3E%3Cline x1='12' y1='11.2' x2='12' y2='17' stroke-linecap='round'/%3E%3C/svg%3E") center/contain no-repeat;
}

/* Share/link icon for Copy Share Link */
.menu-icon-share {
  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='M18 16.08c-.76 0-1.44.3-1.96.77L8.91 12.7c.05-.23.09-.46.09-.7s-.04-.47-.09-.7l7.05-4.11c.54.5 1.25.81 2.04.81 1.66 0 3-1.34 3-3s-1.34-3-3-3-3 1.34-3 3c0 .24.04.47.09.7L8.04 9.81C7.5 9.31 6.79 9 6 9c-1.66 0-3 1.34-3 3s1.34 3 3 3c.79 0 1.5-.31 2.04-.81l7.12 4.16c-.05.21-.08.43-.08.65 0 1.61 1.31 2.92 2.92 2.92 1.61 0 2.92-1.31 2.92-2.92s-1.31-2.92-2.92-2.92z'/%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: 45000;
  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: #333;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  color: white;
  font-size: 14px;
}

/* Native dropdown options often use a light background; ensure text is dark and visible */
.setting-row select option {
  background: #fff;
  color: #222;
}

.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: 46000;
  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;
}

.instructions-modal .instructions-section-title {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.55);
  text-align: left;
}

.instructions-modal .instructions-section-title + .controls-grid {
  margin-bottom: 18px;
}

.help-shortcuts {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin: 8px 0 16px;
}

.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;
}

/* Teleport hint (touch) — GPS-style destination marker asset */
.control-icon-crosshair {
  display: inline-block;
  width: 24px;
  height: 24px;
  min-width: 24px;
  background: url("./assets/teleport_icon_v1.png") 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;
}

/* --- STICKY NOTE TOOL UI (same band as measure) --- */
#sticky-note-ui {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 30000;
  pointer-events: none;
}

#sticky-note-ui.hidden {
  display: none;
}

#sticky-note-controls {
  pointer-events: auto;
}

#sticky-note-controls {
  position: fixed;
  bottom: max(30px, calc(env(safe-area-inset-bottom, 0px) + 16px));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  padding: 10px 16px;
  background: rgba(30, 30, 30, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
  max-width: calc(100vw - 24px);
}

/* Notes directory panel */
#sticky-notes-directory-overlay.overlay {
  z-index: 45120;
}

.sticky-notes-directory-content {
  max-width: 420px;
  width: 92%;
}

.sticky-notes-list-scroll {
  max-height: min(60vh, 440px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.sticky-notes-list-body {
  list-style: none;
  margin: 0;
  padding: 0;
}

button.sticky-notes-list-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  margin: 0 0 8px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 6px;
  color: #fff;
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
  transition: background 0.2s, border-color 0.2s;
}

button.sticky-notes-list-item:hover {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.22);
}

.sticky-notes-list-item-title {
  font-weight: 600;
  word-break: break-word;
}

.sticky-notes-list-item-meta {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.45);
  margin-top: 4px;
}

.sticky-notes-list-empty {
  text-align: center;
  color: rgba(255, 255, 255, 0.5);
  padding: 16px 8px;
  font-size: 14px;
}

/* --- MEASURE MODE UI --- */
/* High z-index band: must paint above #touch-ui-container on mobile WebKit */
#measure-ui {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 30000;
  pointer-events: none;
}

#measure-ui.hidden {
  display: none;
}

#measure-controls,
#measure-context-menu {
  pointer-events: auto;
}

/* First-time measure guidance when there are no points yet */
#measure-onboarding-hint {
  position: fixed;
  top: 26%;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 14px;
  text-align: center;
  pointer-events: none;
  max-width: min(520px, calc(100vw - 28px));
}

#measure-onboarding-hint.hidden {
  display: none;
}

/* Measure controls (bottom center) */
#measure-controls {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  padding: 10px 16px;
  background: rgba(30, 30, 30, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.measure-btn {
  padding: 10px 18px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 6px;
  color: white;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}

.measure-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.4);
}

.measure-exit {
  background: rgba(180, 60, 60, 0.4);
  border-color: rgba(255, 100, 100, 0.5);
}

.measure-exit:hover {
  background: rgba(180, 60, 60, 0.6);
  border-color: rgba(255, 100, 100, 0.7);
}

.measure-hint {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.6);
  align-self: center;
  margin-left: 8px;
}

/* Sticky Note Modal - same HUD band as measure / sticky popup */
#sticky-note-modal.overlay {
  z-index: 45100;
}

/* Sticky Note Modal */
.sticky-note-modal-content {
  max-width: 400px;
}

.sticky-note-modal-content textarea {
  width: 100%;
  padding: 12px;
  margin: 12px 0;
  background: #333;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  color: white;
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
  min-height: 80px;
  box-sizing: border-box;
}

.sticky-note-char-count {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.5);
  margin-bottom: 12px;
}

.sticky-note-modal-buttons {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* Sticky Note View Popup — full-screen layer so backdrop receives touch (above #touch-ui-container) */
#sticky-note-popup {
  position: fixed;
  inset: 0;
  z-index: 30000;
  pointer-events: auto;
}

#sticky-note-popup.hidden {
  display: none;
  pointer-events: none;
}

.sticky-note-popup-backdrop {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 0;
  border: none;
  background: rgba(0, 0, 0, 0.45);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.sticky-note-popup-content {
  position: absolute;
  left: 50%;
  bottom: max(100px, calc(env(safe-area-inset-bottom, 0px) + 88px));
  transform: translateX(-50%);
  z-index: 1;
  width: min(360px, calc(100vw - 32px));
  background: rgba(30, 30, 30, 0.95);
  border: 1px solid rgba(255, 200, 100, 0.5);
  border-radius: 8px;
  padding: 16px 20px;
  min-width: 220px;
  max-width: 360px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
  pointer-events: auto;
}

#sticky-note-popup-text {
  color: #fdc;
  font-size: 14px;
  line-height: 1.5;
  margin-bottom: 12px;
  white-space: pre-wrap;
  word-break: break-word;
}

.sticky-note-popup-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

/* Context menu for point actions */
#measure-context-menu {
  position: fixed;
  background: rgba(30, 30, 30, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  min-width: 160px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
  z-index: 30001;
}

#measure-context-menu.hidden {
  display: none;
}

.measure-context-item {
  display: block;
  width: 100%;
  padding: 12px 18px;
  background: none;
  border: none;
  color: white;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  transition: background 0.2s;
}

.measure-context-item:hover {
  background: rgba(255, 255, 255, 0.15);
}

.measure-context-item + .measure-context-item {
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.measure-context-item:first-child {
  border-radius: 8px 8px 0 0;
}

.measure-context-item:last-child {
  border-radius: 0 0 8px 8px;
}

/* Measure label container */
#measure-label-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 30000;
}

/* Measurement labels (HTML overlays) */
.measure-label {
  position: fixed;
  padding: 4px 8px;
  background: rgba(0, 0, 0, 0.75);
  border: 1px solid rgba(0, 200, 255, 0.6);
  border-radius: 4px;
  color: #7df;
  font-size: 12px;
  font-family: monospace;
  white-space: nowrap;
  pointer-events: none;
  z-index: 30001;
  transform: translate(-50%, -50%);
}
