* { margin: 0; padding: 0; box-sizing: border-box; }
body { overflow: hidden; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background: #000; }
#canvas-container { position: fixed; inset: 0; z-index: 0; }

/* Mode badge */
#mode-badge {
  position: fixed; top: 12px; left: 16px; z-index: 10;
  color: rgba(255,255,255,0.75); font-size: 14px; font-weight: 700;
}
#mode-badge small { display: block; color: rgba(255,255,255,0.4); font-size: 11px; font-weight: 400; margin-top: 2px; }

/* Polygon Budget Warning */
.poly-warn {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%);
  z-index: 20; padding: 6px 16px; border-radius: 8px; font-size: 13px; font-weight: 600;
  pointer-events: none; white-space: nowrap; backdrop-filter: blur(8px);
  transition: background 0.3s, color 0.3s;
}
.poly-ok { background: rgba(40,80,40,0.75); color: #8f8; border: 1px solid rgba(100,255,100,0.2); }
.poly-caution { background: rgba(100,80,10,0.85); color: #ffd54f; border: 1px solid rgba(255,200,50,0.3); }
.poly-danger { background: rgba(120,20,20,0.9); color: #ff5252; border: 1px solid rgba(255,80,80,0.4); }

/* Chat Panel (desktop) */
#chat-panel {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  width: 520px; max-width: 94vw; z-index: 10; display: flex; flex-direction: column; gap: 8px;
}
#chat-output {
  background: rgba(15,15,25,0.85); backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.1); border-radius: 14px;
  padding: 16px; max-height: 260px; overflow-y: auto;
  color: #e0e0e0; font-size: 14px; line-height: 1.55;
  scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.15) transparent;
}
#chat-output::-webkit-scrollbar { width: 6px; }
#chat-output::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 3px; }
.msg { margin-bottom: 10px; animation: fadeIn .25s ease; }
.msg:last-child { margin-bottom: 0; }
.msg-user { color: #7eb8ff; }
.msg-user::before { content: 'You: '; font-weight: 600; }
.msg-bot { color: #b8ffb8; }
.msg-bot::before { content: 'AI: '; font-weight: 600; }
.msg-system { color: #ffd27e; font-style: italic; text-align: center; }
.msg-peer { color: #c4a8ff; }
@keyframes fadeIn { from{opacity:0;transform:translateY(6px)} to{opacity:1;transform:translateY(0)} }

#chat-input-row { display: flex; gap: 8px; }
#chat-input {
  flex: 1; padding: 12px 16px; border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.15);
  background: rgba(15,15,25,0.85); backdrop-filter: blur(12px);
  color: #fff; font-size: 14px; outline: none; transition: border-color .2s;
}
#chat-input:focus { border-color: rgba(120,180,255,0.5); }
#chat-input::placeholder { color: rgba(255,255,255,0.35); }
#send-btn {
  padding: 12px 20px; border-radius: 12px; border: none;
  background: linear-gradient(135deg,#4a7cff,#6a4cff);
  color: #fff; font-size: 14px; font-weight: 600; cursor: pointer;
  transition: opacity .2s; white-space: nowrap;
}
#send-btn:hover { opacity: 0.85; }
#send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Toolbar */
#toolbar {
  position: fixed; top: 12px; right: 16px; z-index: 10;
  display: flex; gap: 6px; flex-wrap: wrap; max-width: 520px; justify-content: flex-end;
}
.toolbar-btn {
  padding: 8px 12px; border-radius: 8px;
  background: rgba(15,15,25,0.85); backdrop-filter: blur(12px);
  color: #fff; font-size: 12px; font-weight: 600; cursor: pointer;
  border: 1px solid rgba(255,255,255,0.12); transition: background .2s;
}
.toolbar-btn:hover { background: rgba(60,60,100,0.85); }
.toolbar-btn.active { background: rgba(74,124,255,0.6); border-color: rgba(74,124,255,0.8); }

/* Transform mode buttons */
#transform-modes {
  position: fixed; top: 46px; left: 16px; z-index: 10; display: flex; gap: 4px;
}

/* Light properties */
#light-props {
  position: fixed; top: 54px; right: 16px; z-index: 10;
  background: rgba(15,15,25,0.92); backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.12); border-radius: 12px;
  padding: 14px; width: 210px; display: none;
  color: #e0e0e0; font-size: 13px;
}
#light-props .prop-row { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
#light-props label { flex-shrink: 0; width: 55px; }
#light-props input[type="range"] { flex: 1; }
#light-props input[type="color"] { width: 36px; height: 26px; border: none; cursor: pointer; background: none; padding: 0; }

/* API Key Panel */
#api-key-panel {
  position: fixed; top: 54px; right: 16px; z-index: 15;
  background: rgba(15,15,25,0.92); backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.12); border-radius: 12px;
  padding: 14px; width: 280px;
  color: #e0e0e0; font-size: 13px;
}
#api-key-input, #bot-name-input {
  width: 100%; padding: 8px 10px; border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.15);
  background: rgba(15,15,25,0.85); color: #fff; font-size: 13px; outline: none;
}
#api-key-input:focus, #bot-name-input:focus { border-color: rgba(120,180,255,0.5); }

/* Speech Bubble */
#speech-bubble {
  position: fixed; display: none; max-width: 320px; padding: 12px 16px;
  background: rgba(255,255,255,0.95); color: #222; border-radius: 14px;
  font-size: 13px; line-height: 1.5; box-shadow: 0 4px 20px rgba(0,0,0,0.25);
  z-index: 5; cursor: pointer; animation: bubbleIn .3s ease;
}
#speech-bubble::after {
  content: ''; position: absolute; bottom: -8px; left: 50%;
  transform: translateX(-50%);
  border-left: 8px solid transparent; border-right: 8px solid transparent;
  border-top: 8px solid rgba(255,255,255,0.95);
}
@keyframes bubbleIn { from{opacity:0;transform:scale(.9)} to{opacity:1;transform:scale(1)} }
.typing-indicator span {
  display: inline-block; width: 6px; height: 6px; margin: 0 2px;
  background: #666; border-radius: 50%; animation: bounce 1.2s infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: .2s; }
.typing-indicator span:nth-child(3) { animation-delay: .4s; }
@keyframes bounce { 0%,80%,100%{transform:translateY(0)} 40%{transform:translateY(-8px)} }

#file-input { display: none; }

/* Shortcuts */
#shortcuts-hint {
  position: fixed; bottom: 90px; left: 16px; z-index: 10;
  color: rgba(255,255,255,0.35); font-size: 11px; line-height: 1.6;
  pointer-events: none;
}

/* VR overlay (DOM overlay for Quest keyboard) */
#vr-overlay {
  display: none; position: fixed; bottom: 0; left: 0; width: 100%;
  z-index: 50; padding: 12px;
}
#vr-chat-container {
  max-width: 480px; margin: 0 auto;
  background: rgba(10,10,25,0.92); border-radius: 14px; padding: 12px;
  border: 1px solid rgba(74,124,255,0.35);
}
#vr-badge { color: #7eb8ff; font-size: 11px; font-weight: 600; margin-bottom: 6px; }
#vr-chat-output {
  max-height: 110px; overflow-y: auto;
  color: #e0e0e0; font-size: 13px; margin-bottom: 8px; line-height: 1.4;
  scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.15) transparent;
}
#vr-input-row { display: flex; gap: 6px; }
#vr-chat-input {
  flex: 1; padding: 10px 12px; border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.2);
  background: rgba(0,0,0,0.5); color: #fff; font-size: 14px; outline: none;
}
#vr-send-btn {
  padding: 10px 16px; border-radius: 10px; border: none;
  background: linear-gradient(135deg,#4a7cff,#6a4cff);
  color: #fff; font-weight: 600; cursor: pointer;
}

/* Asset Panel */
#asset-panel {
  position: fixed; top: 54px; left: 16px; z-index: 10;
  background: rgba(15,15,25,0.92); backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.12); border-radius: 12px;
  padding: 10px; width: 260px; max-height: 60vh; display: none;
  color: #e0e0e0; font-size: 12px;
  overflow-y: auto;
  scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.15) transparent;
}
#asset-panel::-webkit-scrollbar { width: 5px; }
#asset-panel::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 3px; }
#asset-panel .ap-header { font-weight: 700; margin-bottom: 8px; font-size: 13px; display: flex; justify-content: space-between; align-items: center; }
#asset-panel .ap-section { color: rgba(255,255,255,0.45); font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; margin: 8px 0 4px; }
.ap-item {
  display: flex; align-items: center; gap: 6px; padding: 5px 6px;
  border-radius: 6px; cursor: pointer; transition: background .15s; margin-bottom: 2px;
}
.ap-item:hover { background: rgba(255,255,255,0.08); }
.ap-item.selected { background: rgba(74,124,255,0.3); }
.ap-item .ap-icon { flex-shrink: 0; width: 18px; text-align: center; font-size: 13px; }
.ap-item .ap-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ap-item .ap-actions { display: flex; gap: 2px; }
.ap-item .ap-btn {
  background: rgba(255,255,255,0.1); border: none; color: #ccc; font-size: 11px;
  padding: 2px 6px; border-radius: 4px; cursor: pointer;
}
.ap-item .ap-btn:hover { background: rgba(255,255,255,0.2); }
.ap-empty { color: rgba(255,255,255,0.3); font-style: italic; text-align: center; padding: 12px; }

/* Dev Panel */
#dev-panel {
  position: fixed; top: 80px; left: 16px; z-index: 20;
  background: rgba(10,10,20,0.95); backdrop-filter: blur(14px);
  border: 1px solid rgba(255,100,100,0.25); border-radius: 12px;
  padding: 12px; width: 230px; max-height: 80vh;
  color: #e0e0e0; font-size: 12px;
  overflow-y: auto; display: none;
  scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.15) transparent;
}
#dev-panel::-webkit-scrollbar { width: 5px; }
#dev-panel::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 3px; }
.dev-header {
  display: flex; justify-content: space-between; align-items: center;
  font-weight: 700; font-size: 13px; margin-bottom: 10px;
  color: #ff9e9e;
}
.dev-close {
  background: none; border: none; color: rgba(255,255,255,0.4);
  font-size: 14px; cursor: pointer; padding: 0 2px; line-height: 1;
}
.dev-close:hover { color: #fff; }
.dev-section {
  color: rgba(255,160,100,0.7); font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.6px;
  margin: 10px 0 5px; border-top: 1px solid rgba(255,255,255,0.06); padding-top: 8px;
}
.dev-section:first-of-type { margin-top: 0; border-top: none; padding-top: 0; }
.dev-btn {
  display: block; width: 100%; padding: 7px 10px; margin-bottom: 4px;
  background: rgba(255,255,255,0.07); border: 1px solid rgba(255,255,255,0.1);
  border-radius: 7px; color: #e0e0e0; font-size: 12px; cursor: pointer;
  text-align: left; transition: background .15s;
}
.dev-btn:hover { background: rgba(255,255,255,0.14); }
.dev-btn.active { background: rgba(255,80,80,0.3); border-color: rgba(255,80,80,0.5); color: #ffaaaa; }
.dev-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 3px 2px; margin-bottom: 2px;
}
.dev-label { color: rgba(255,255,255,0.45); }
.dev-val { font-family: monospace; color: #b8ffb8; font-size: 11px; }
.dev-bones {
  font-family: monospace; font-size: 10px; color: rgba(180,220,255,0.8);
  line-height: 1.7; padding: 2px 0;
}
.dev-slider { flex: 1; accent-color: #7eb8ff; cursor: pointer; min-width: 0; }
.dev-select {
  width: 100%; padding: 5px 8px; border-radius: 6px; margin-bottom: 2px;
  background: rgba(255,255,255,0.07); border: 1px solid rgba(255,255,255,0.15);
  color: #e0e0e0; font-size: 12px; cursor: pointer;
}

/* Import Modal */
.modal {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
}
.modal.hidden { display: none; }
.modal-content {
  background: rgba(15,15,25,0.95); backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.12); border-radius: 14px;
  padding: 20px; width: 340px; color: #e0e0e0;
}
.modal-content h3 { margin: 0 0 14px; font-size: 16px; font-weight: 600; }
.modal-tabs { display: flex; gap: 4px; margin-bottom: 14px; }
.modal-tab {
  flex: 1; padding: 8px 12px; border: none; border-radius: 8px;
  background: rgba(255,255,255,0.08); color: rgba(255,255,255,0.6);
  font-size: 12px; font-weight: 600; cursor: pointer;
  transition: background .2s, color .2s;
}
.modal-tab:hover { background: rgba(255,255,255,0.12); }
.modal-tab.active { background: rgba(74,124,255,0.5); color: #fff; }
.tab-panel { min-height: 120px; }
.tab-panel.hidden { display: none; }
.primitive-grid {
  display: grid; grid-template-columns: repeat(5, 1fr);
  gap: 8px; margin-bottom: 14px;
}
.primitive-btn {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 10px 6px; border: 2px solid rgba(255,255,255,0.12);
  border-radius: 10px; background: rgba(255,255,255,0.05);
  color: #e0e0e0; cursor: pointer; transition: border-color .2s, background .2s;
}
.primitive-btn:hover { background: rgba(255,255,255,0.1); }
.primitive-btn.selected { border-color: #4a7cff; background: rgba(74,124,255,0.2); }
.primitive-icon { font-size: 22px; }
.primitive-label { font-size: 10px; font-weight: 600; }
.color-row { display: flex; align-items: center; gap: 10px; }
.color-row label { font-size: 12px; color: rgba(255,255,255,0.7); }
.color-row input[type="color"] {
  width: 50px; height: 30px; border: none; border-radius: 6px;
  cursor: pointer; background: none;
}
.upload-area {
  border: 2px dashed rgba(255,255,255,0.2); border-radius: 10px;
  padding: 24px 16px; text-align: center; cursor: pointer;
  transition: border-color .2s, background .2s;
}
.upload-area:hover { border-color: rgba(74,124,255,0.5); background: rgba(74,124,255,0.1); }
.upload-area p { margin: 0; font-size: 13px; color: rgba(255,255,255,0.7); }
.upload-hint { font-size: 11px !important; color: rgba(255,255,255,0.4) !important; margin-top: 4px !important; }
.modal-actions { display: flex; gap: 8px; margin-top: 16px; justify-content: flex-end; }
.modal-btn {
  padding: 8px 18px; border-radius: 8px; border: none;
  font-size: 12px; font-weight: 600; cursor: pointer; transition: opacity .2s;
}
.modal-btn.cancel { background: rgba(255,255,255,0.1); color: rgba(255,255,255,0.7); }
.modal-btn.cancel:hover { background: rgba(255,255,255,0.15); }
.modal-btn.primary { background: linear-gradient(135deg,#4a7cff,#6a4cff); color: #fff; }
.modal-btn.primary:hover { opacity: 0.85; }
