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

html, body {
  overflow: hidden;
  position: fixed;
  width: 100%;
  height: 100%;
  touch-action: none;
  overscroll-behavior: none;
}

body {
  background: #0a0a0a;
  font-family: 'Share Tech Mono', monospace;
  cursor: crosshair;
  user-select: none;
  -webkit-user-select: none;
}

#scene-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 0;
}

#scene-container canvas {
  display: block;
  touch-action: none;
}

/* ====== Modal ====== */
.modal-overlay {
  position: fixed;
  top: 0; left: 0;
  width: 100vw; height: 100vh;
  background: rgba(0,0,0,0.88);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.5s ease;
  padding: 16px;
  padding: env(safe-area-inset-top, 16px) env(safe-area-inset-right, 16px) env(safe-area-inset-bottom, 16px) env(safe-area-inset-left, 16px);
}

.modal-overlay.hidden {
  display: none;
}

.modal-box {
  background: linear-gradient(135deg, #0d1117 0%, #161b22 100%);
  border: 2px solid #00d4ff;
  border-radius: 4px;
  padding: 30px 36px;
  max-width: 520px;
  width: 100%;
  text-align: center;
  box-shadow: 0 0 60px rgba(0, 212, 255, 0.15), inset 0 0 30px rgba(0, 212, 255, 0.03);
  max-height: 90vh;
  overflow-y: auto;
}

.modal-box h1 {
  font-family: 'Rajdhani', sans-serif;
  font-weight: 700;
  font-size: clamp(1.8rem, 6vw, 2.8rem);
  color: #ffffff;
  line-height: 1;
  margin-bottom: 5px;
  text-shadow: 0 0 20px rgba(0, 212, 255, 0.5);
  letter-spacing: 3px;
}

.modal-box .subtitle {
  font-size: clamp(1rem, 3.5vw, 1.4rem);
  color: #00d4ff;
  font-weight: 300;
  letter-spacing: 6px;
  text-transform: uppercase;
}

.tip-line {
  color: #6a737d;
  font-size: 0.72rem;
  margin: 12px 0 20px;
  font-style: italic;
}

.controls-ref {
  text-align: left;
  margin: 0 auto 20px;
  max-width: 300px;
}

.control-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 3px 0;
  color: #c9d1d9;
  font-size: 0.78rem;
}

.key {
  background: rgba(0, 212, 255, 0.12);
  border: 1px solid rgba(0, 212, 255, 0.3);
  color: #00d4ff;
  padding: 2px 8px;
  border-radius: 3px;
  font-size: 0.7rem;
  min-width: 50px;
  text-align: center;
  font-family: 'Share Tech Mono', monospace;
}

.gmod-btn {
  background: linear-gradient(180deg, #00d4ff 0%, #0099cc 100%);
  color: #0d1117;
  border: none;
  padding: 12px 40px;
  font-family: 'Rajdhani', sans-serif;
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: 3px;
  cursor: pointer;
  border-radius: 3px;
  transition: all 0.15s;
  text-transform: uppercase;
  min-height: 48px;
}

.gmod-btn:hover, .gmod-btn:active {
  background: linear-gradient(180deg, #33e0ff 0%, #00bbee 100%);
  box-shadow: 0 0 25px rgba(0, 212, 255, 0.4);
}

.gmod-btn.danger {
  background: linear-gradient(180deg, #ff4444 0%, #cc2222 100%);
  color: #fff;
  padding: 5px 12px;
  font-size: 0.65rem;
  letter-spacing: 2px;
  min-height: 32px;
}

.gmod-btn.danger:hover, .gmod-btn.danger:active {
  box-shadow: 0 0 25px rgba(255, 68, 68, 0.4);
}

/* ====== HUD ====== */
#hud {
  position: fixed;
  top: 0; left: 0;
  width: 100vw; height: 100vh;
  z-index: 100;
  pointer-events: none;
}

#hud button, #hud a, #hud .spawn-btn, #hud .spawn-drawer-btn,
#hud .m-tool-btn, #hud .m-action-btn, #hud #spawn-fab {
  pointer-events: auto;
}

.hud-panel {
  background: rgba(13, 17, 23, 0.82);
  border: 1px solid rgba(0, 212, 255, 0.25);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: #e6e6e6;
  padding: 8px 12px;
  border-radius: 3px;
}

/* Tool Display */
#tool-display {
  position: absolute;
  top: max(12px, env(safe-area-inset-top, 12px));
  left: max(12px, env(safe-area-inset-left, 12px));
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 120px;
}

#tool-icon {
  font-size: 1.3rem;
}

#tool-name {
  font-family: 'Rajdhani', sans-serif;
  font-weight: 700;
  font-size: 0.9rem;
  color: #00d4ff;
  letter-spacing: 2px;
}

/* Counters */
#counters {
  position: absolute;
  top: max(12px, env(safe-area-inset-top, 12px));
  right: max(12px, env(safe-area-inset-right, 12px));
  text-align: right;
  font-size: 0.72rem;
}

#prop-count {
  color: #00d4ff;
  font-weight: bold;
  margin-bottom: 2px;
}

#fps-counter {
  color: #6a737d;
  font-size: 0.62rem;
}

/* Crosshair */
#crosshair {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 24px; height: 24px;
}

.ch-h, .ch-v {
  position: absolute;
  background: rgba(0, 212, 255, 0.8);
}

.ch-h {
  width: 100%; height: 1px;
  top: 50%;
}

.ch-v {
  height: 100%; width: 1px;
  left: 50%;
}

.ch-dot {
  position: absolute;
  width: 3px; height: 3px;
  background: #00d4ff;
  border-radius: 50%;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 6px #00d4ff;
}

/* Grab Info */
#grab-info {
  position: absolute;
  bottom: 130px;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  font-size: 0.68rem;
  color: #00d4ff;
}

/* ====== Desktop Spawn Menu ====== */
#spawn-menu {
  position: absolute;
  bottom: max(12px, env(safe-area-inset-bottom, 12px));
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  transition: opacity 0.2s, transform 0.2s;
}

#spawn-menu.hidden {
  opacity: 0;
  transform: translateX(-50%) translateY(20px);
  pointer-events: none !important;
}

#spawn-menu.hidden * {
  pointer-events: none !important;
}

.spawn-title {
  font-size: 0.6rem;
  color: #6a737d;
  margin-bottom: 6px;
  letter-spacing: 2px;
}

#spawn-buttons {
  display: flex;
  gap: 5px;
  justify-content: center;
  flex-wrap: wrap;
}

.spawn-btn {
  background: rgba(0, 212, 255, 0.06);
  border: 1px solid rgba(0, 212, 255, 0.2);
  color: #c9d1d9;
  padding: 7px 10px;
  cursor: pointer;
  border-radius: 3px;
  transition: all 0.12s;
  min-width: 56px;
  font-family: 'Share Tech Mono', monospace;
}

.spawn-btn:hover, .spawn-btn:active {
  background: rgba(0, 212, 255, 0.15);
  border-color: #00d4ff;
  color: #ffffff;
  box-shadow: 0 0 12px rgba(0, 212, 255, 0.2);
}

.spawn-icon {
  font-size: 1.2rem;
  margin-bottom: 1px;
}

.spawn-label {
  font-size: 0.55rem;
  letter-spacing: 1px;
  text-transform: uppercase;
}

/* Desktop Tool Switcher */
#tool-switcher {
  position: absolute;
  top: 65px;
  left: max(12px, env(safe-area-inset-left, 12px));
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 6px;
}

.tool-btn {
  background: rgba(0, 212, 255, 0.04);
  border: 1px solid rgba(0, 212, 255, 0.15);
  color: #8b949e;
  padding: 5px 10px;
  cursor: pointer;
  border-radius: 2px;
  font-family: 'Share Tech Mono', monospace;
  font-size: 0.68rem;
  text-align: left;
  transition: all 0.12s;
}

.tool-btn span {
  color: rgba(0, 212, 255, 0.5);
  margin-right: 3px;
}

.tool-btn:hover, .tool-btn:active {
  background: rgba(0, 212, 255, 0.1);
  color: #c9d1d9;
}

.tool-btn.active {
  background: rgba(0, 212, 255, 0.15);
  border-color: #00d4ff;
  color: #00d4ff;
}

.tool-btn.active span {
  color: #00d4ff;
}

/* Footer */
#footer-link {
  position: absolute;
  bottom: max(4px, env(safe-area-inset-bottom, 4px));
  right: max(8px, env(safe-area-inset-right, 8px));
  pointer-events: auto;
}

#footer-link a {
  color: #30363d;
  font-size: 0.55rem;
  text-decoration: none;
  letter-spacing: 1px;
  transition: color 0.2s;
}

#footer-link a:hover, #footer-link a:active {
  color: #00d4ff;
}

/* ====== MOBILE CONTROLS ====== */

/* By default, mobile elements hidden */
.mobile-only {
  display: none !important;
}

.desktop-only {
  display: flex;
}

/* Landscape Hint */
#landscape-hint {
  display: none;
  position: fixed;
  bottom: max(60px, env(safe-area-inset-bottom, 60px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 500;
  pointer-events: none;
  animation: fadeInOut 4s ease forwards;
}

.landscape-hint-inner {
  background: rgba(13, 17, 23, 0.9);
  border: 1px solid rgba(0, 212, 255, 0.3);
  color: #00d4ff;
  font-size: 0.72rem;
  padding: 8px 16px;
  border-radius: 20px;
  white-space: nowrap;
}

/* ====== Mobile Media Query ====== */
body.is-touch .mobile-only {
  display: flex !important;
}

body.is-touch .desktop-only {
  display: none !important;
}

body.is-touch #crosshair {
  width: 30px;
  height: 30px;
}

body.is-touch .ch-dot {
  width: 5px;
  height: 5px;
  box-shadow: 0 0 10px #00d4ff, 0 0 20px rgba(0,212,255,0.3);
}

body.is-touch #tool-display {
  padding: 6px 10px;
}

body.is-touch #tool-icon {
  font-size: 1.1rem;
}

body.is-touch #tool-name {
  font-size: 0.75rem;
  letter-spacing: 1px;
}

body.is-touch #counters {
  font-size: 0.65rem;
  padding: 5px 8px;
}

body.is-touch #grab-info {
  bottom: 160px;
  font-size: 0.62rem;
}

body.is-touch {
  cursor: none;
}

/* Mobile Tool Strip */
#mobile-tool-strip {
  position: absolute;
  top: max(52px, calc(env(safe-area-inset-top, 12px) + 44px));
  left: max(12px, env(safe-area-inset-left, 12px));
  flex-direction: row;
  gap: 4px;
  z-index: 120;
}

.m-tool-btn {
  width: 44px;
  height: 44px;
  background: rgba(13, 17, 23, 0.85);
  border: 1px solid rgba(0, 212, 255, 0.2);
  border-radius: 4px;
  color: #8b949e;
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.12s;
}

.m-tool-btn.active {
  background: rgba(0, 212, 255, 0.18);
  border-color: #00d4ff;
  box-shadow: 0 0 10px rgba(0, 212, 255, 0.3);
}

/* Virtual Joystick */
#joystick-zone {
  position: absolute;
  bottom: max(24px, env(safe-area-inset-bottom, 24px));
  left: max(20px, env(safe-area-inset-left, 20px));
  width: 130px;
  height: 130px;
  z-index: 150;
  pointer-events: auto;
  align-items: center;
  justify-content: center;
}

#joystick-base {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: rgba(13, 17, 23, 0.5);
  border: 2px solid rgba(0, 212, 255, 0.3);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

#joystick-thumb {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 40%, rgba(0, 212, 255, 0.5), rgba(0, 212, 255, 0.15));
  border: 2px solid rgba(0, 212, 255, 0.6);
  position: absolute;
  transition: none;
  box-shadow: 0 0 12px rgba(0, 212, 255, 0.2);
}

/* Mobile Action Buttons */
#mobile-actions {
  position: absolute;
  bottom: max(24px, env(safe-area-inset-bottom, 24px));
  right: max(20px, env(safe-area-inset-right, 20px));
  flex-direction: column;
  gap: 8px;
  align-items: center;
  z-index: 150;
}

.m-action-btn {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: rgba(13, 17, 23, 0.85);
  border: 2px solid rgba(0, 212, 255, 0.3);
  color: #e6e6e6;
  font-size: 1.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.12s;
  box-shadow: 0 2px 10px rgba(0,0,0,0.4);
}

.m-action-btn.small {
  width: 44px;
  height: 44px;
  font-size: 1rem;
  border-color: rgba(0, 212, 255, 0.2);
}

.m-action-btn.primary {
  width: 68px;
  height: 68px;
  background: rgba(0, 212, 255, 0.15);
  border-color: #00d4ff;
  box-shadow: 0 0 18px rgba(0, 212, 255, 0.25), 0 2px 10px rgba(0,0,0,0.4);
  font-size: 1.6rem;
}

.m-action-btn:active {
  background: rgba(0, 212, 255, 0.3);
  transform: scale(0.92);
}

.m-action-btn.primary:active {
  background: rgba(0, 212, 255, 0.45);
  box-shadow: 0 0 30px rgba(0, 212, 255, 0.5);
}

/* Spawn FAB */
#spawn-fab {
  position: absolute;
  bottom: max(24px, env(safe-area-inset-bottom, 24px));
  left: 50%;
  transform: translateX(-50%);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, #00d4ff, #0099cc);
  border: none;
  color: #0d1117;
  font-size: 2rem;
  font-weight: 700;
  cursor: pointer;
  z-index: 160;
  box-shadow: 0 0 20px rgba(0, 212, 255, 0.35), 0 4px 12px rgba(0,0,0,0.5);
  transition: all 0.2s;
  line-height: 1;
}

#spawn-fab:active {
  transform: translateX(-50%) scale(0.9);
  box-shadow: 0 0 30px rgba(0, 212, 255, 0.6);
}

/* Spawn Drawer */
#spawn-drawer {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(13, 17, 23, 0.95);
  border-top: 2px solid rgba(0, 212, 255, 0.35);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: 12px 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom, 16px));
  z-index: 200;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
  pointer-events: auto;
  flex-direction: column;
  gap: 10px;
}

#spawn-drawer.open {
  transform: translateY(0);
}

.spawn-drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #00d4ff;
  font-family: 'Rajdhani', sans-serif;
  font-weight: 700;
  font-size: 0.85rem;
  letter-spacing: 2px;
}

.spawn-drawer-header button {
  background: none;
  border: 1px solid rgba(0, 212, 255, 0.3);
  color: #8b949e;
  width: 32px;
  height: 32px;
  border-radius: 4px;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

#spawn-drawer-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.spawn-drawer-btn {
  background: rgba(0, 212, 255, 0.06);
  border: 1px solid rgba(0, 212, 255, 0.2);
  color: #c9d1d9;
  padding: 12px 8px;
  cursor: pointer;
  border-radius: 6px;
  font-family: 'Share Tech Mono', monospace;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-height: 64px;
  justify-content: center;
  transition: all 0.12s;
}

.spawn-drawer-btn:active {
  background: rgba(0, 212, 255, 0.2);
  border-color: #00d4ff;
  box-shadow: 0 0 14px rgba(0, 212, 255, 0.25);
}

.sd-icon {
  font-size: 1.5rem;
}

.sd-label {
  font-size: 0.6rem;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #8b949e;
}

/* ====== Confirm Dialog ====== */
#confirm-dialog {
  position: fixed;
  top: 0; left: 0;
  width: 100vw; height: 100vh;
  background: rgba(0,0,0,0.7);
  z-index: 2000;
  display: none;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
}

#confirm-dialog.open {
  display: flex;
}

.confirm-box {
  background: linear-gradient(135deg, #0d1117 0%, #161b22 100%);
  border: 2px solid #ff4444;
  border-radius: 6px;
  padding: 24px 32px;
  text-align: center;
  max-width: 320px;
  width: 90%;
  box-shadow: 0 0 40px rgba(255, 68, 68, 0.2);
}

.confirm-box p {
  color: #e6e6e6;
  font-size: 0.9rem;
  margin-bottom: 20px;
  font-family: 'Rajdhani', sans-serif;
  font-weight: 500;
  letter-spacing: 1px;
}

.confirm-btns {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.confirm-btns button {
  padding: 10px 24px;
  border: none;
  border-radius: 3px;
  font-family: 'Rajdhani', sans-serif;
  font-weight: 700;
  font-size: 0.9rem;
  letter-spacing: 2px;
  cursor: pointer;
  min-height: 44px;
  min-width: 80px;
  transition: all 0.15s;
}

#confirm-yes {
  background: linear-gradient(180deg, #ff4444, #cc2222);
  color: #fff;
}

#confirm-no {
  background: rgba(0, 212, 255, 0.1);
  border: 1px solid rgba(0, 212, 255, 0.3);
  color: #c9d1d9;
}

/* ====== Animations ====== */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes fadeInOut {
  0% { opacity: 0; }
  15% { opacity: 1; }
  80% { opacity: 1; }
  100% { opacity: 0; }
}

@keyframes spawnPoof {
  0% { transform: scale(0); opacity: 1; }
  100% { transform: scale(2); opacity: 0; }
}

/* ====== Small screen adjustments ====== */
@media (max-width: 380px) {
  #tool-display {
    padding: 4px 8px;
    min-width: 80px;
  }
  #tool-name {
    font-size: 0.65rem;
  }
  #tool-icon {
    font-size: 1rem;
  }
  #joystick-base {
    width: 100px;
    height: 100px;
  }
  #joystick-thumb {
    width: 40px;
    height: 40px;
  }
  .m-action-btn {
    width: 52px;
    height: 52px;
  }
  .m-action-btn.primary {
    width: 58px;
    height: 58px;
  }
  .m-action-btn.small {
    width: 38px;
    height: 38px;
  }
  #spawn-fab {
    width: 48px;
    height: 48px;
    font-size: 1.6rem;
  }
}

@media (max-height: 500px) and (orientation: landscape) {
  #joystick-base {
    width: 90px;
    height: 90px;
  }
  #joystick-thumb {
    width: 36px;
    height: 36px;
  }
  .m-action-btn {
    width: 48px;
    height: 48px;
    font-size: 1.1rem;
  }
  .m-action-btn.primary {
    width: 56px;
    height: 56px;
    font-size: 1.3rem;
  }
  .m-action-btn.small {
    width: 36px;
    height: 36px;
    font-size: 0.85rem;
  }
  #mobile-actions {
    gap: 4px;
  }
  #spawn-fab {
    width: 44px;
    height: 44px;
    font-size: 1.5rem;
  }
  #grab-info {
    bottom: 100px !important;
  }
}