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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0a0a0a;
  font-family: 'Segoe UI', Tahoma, sans-serif;
  color: #e8e0d5;
}

#canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* ========== Loading ========== */
#loading {
  position: fixed;
  inset: 0;
  background: #0f0f0f;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  transition: opacity 0.6s ease;
}

#loading.hidden {
  opacity: 0;
  pointer-events: none;
}

.loader-content {
  text-align: center;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 3px solid rgba(232, 224, 213, 0.15);
  border-top-color: #c4a77d;
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
  margin: 0 auto 20px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.progress-bar {
  width: 200px;
  height: 4px;
  background: rgba(255,255,255,0.1);
  border-radius: 2px;
  margin-top: 16px;
  overflow: hidden;
}

#progress {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #c4a77d, #e8d5b5);
  transition: width 0.3s ease;
}

/* ========== UI Overlay ========== */
#ui {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

#ui > * {
  pointer-events: auto;
}

#top-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  background: linear-gradient(to bottom, rgba(0,0,0,0.55), transparent);
  padding-top: env(safe-area-inset-top);
}

.icon-btn {
  width: 44px;
  height: 44px;
  border: none;
  background: rgba(255,255,255,0.08);
  color: #e8e0d5;
  font-size: 20px;
  border-radius: 12px;
  cursor: pointer;
  backdrop-filter: blur(8px);
}

.icon-btn:active {
  background: rgba(255,255,255,0.18);
}

#scene-name {
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0.5px;
  opacity: 0.9;
}

#crosshair {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 6px;
  height: 6px;
  margin: -3px 0 0 -3px;
  background: rgba(255,255,255,0.5);
  border-radius: 50%;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
}

#crosshair.visible {
  opacity: 1;
}

/* Bottom Controls */
#bottom-controls {
  position: absolute;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  padding-bottom: env(safe-area-inset-bottom);
}

.control-btn {
  padding: 12px 18px;
  border: none;
  background: rgba(20,20,20,0.65);
  color: #e8e0d5;
  font-size: 13px;
  border-radius: 24px;
  backdrop-filter: blur(10px);
  cursor: pointer;
  border: 1px solid rgba(255,255,255,0.08);
}

.control-btn.primary {
  background: rgba(196, 167, 125, 0.35);
  border-color: rgba(196, 167, 125, 0.4);
}

.control-btn:active {
  transform: scale(0.96);
}

/* Joystick */
#joystick-zone {
  position: absolute;
  bottom: 30px;
  left: 30px;
  width: 130px;
  height: 130px;
  pointer-events: auto;
}

#joystick-base {
  width: 100%;
  height: 100%;
  background: rgba(255,255,255,0.07);
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.12);
  position: relative;
  backdrop-filter: blur(6px);
}

#joystick-stick {
  width: 50px;
  height: 50px;
  background: rgba(196, 167, 125, 0.7);
  border-radius: 50%;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  transition: transform 0.05s;
}

/* ========== Panels ========== */
.panel {
  position: fixed;
  top: 0;
  right: 0;
  width: min(340px, 90vw);
  height: 100%;
  background: rgba(18, 16, 14, 0.92);
  backdrop-filter: blur(20px);
  z-index: 50;
  overflow-y: auto;
  padding: 20px;
  padding-top: calc(20px + env(safe-area-inset-top));
  transform: translateX(100%);
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  border-left: 1px solid rgba(255,255,255,0.06);
}

.panel:not(.hidden) {
  transform: translateX(0);
}

.panel.hidden {
  transform: translateX(100%);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.panel-header h2 {
  font-size: 18px;
  font-weight: 600;
  color: #c4a77d;
}

.close-btn {
  width: 36px;
  height: 36px;
  border: none;
  background: rgba(255,255,255,0.08);
  color: #e8e0d5;
  border-radius: 10px;
  font-size: 16px;
  cursor: pointer;
}

/* Scene List */
.scene-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.scene-btn {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 14px;
  color: #e8e0d5;
  font-size: 15px;
  cursor: pointer;
  text-align: right;
  transition: all 0.2s;
}

.scene-btn:active,
.scene-btn.active {
  background: rgba(196, 167, 125, 0.18);
  border-color: rgba(196, 167, 125, 0.35);
}

.scene-icon {
  font-size: 22px;
}

/* Settings */
.setting-group {
  margin-bottom: 22px;
}

.setting-group label {
  display: block;
  font-size: 13px;
  opacity: 0.75;
  margin-bottom: 8px;
}

.toggle-row {
  display: flex;
  gap: 8px;
}

.toggle {
  flex: 1;
  padding: 11px 8px;
  border: 1px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.04);
  color: #e8e0d5;
  border-radius: 10px;
  font-size: 13px;
  cursor: pointer;
}

.toggle.active {
  background: rgba(196, 167, 125, 0.25);
  border-color: rgba(196, 167, 125, 0.5);
  color: #f0e6d6;
}

input[type="range"] {
  width: 100%;
  height: 6px;
  -webkit-appearance: none;
  background: rgba(255,255,255,0.12);
  border-radius: 3px;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  background: #c4a77d;
  border-radius: 50%;
  cursor: pointer;
}

input[type="file"] {
  width: 100%;
  margin-bottom: 10px;
  font-size: 13px;
  color: #aaa;
}

.action-btn {
  width: 100%;
  padding: 12px;
  border: none;
  background: rgba(196, 167, 125, 0.3);
  color: #f0e6d6;
  border-radius: 12px;
  font-size: 14px;
  cursor: pointer;
}

.action-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Hide joystick on large screens if wanted */
@media (min-width: 768px) {
  #joystick-zone {
    opacity: 0.7;
  }
}
