/* ═══════════════════════════════════════════════════════════════
   MAEL ROBLOX LAB — style.css
   PWA · Mobile-first · Dark UI · Three.js Viewport
   ═══════════════════════════════════════════════════════════════ */

/* ─── RESET & VARS ────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg0:    #0d0d1a;
  --bg1:    #13132b;
  --bg2:    #1a1a2e;
  --bg3:    #22224a;
  --bg4:    #2a2a5a;
  --border: #2e2e5e;
  --accent: #4f8ef7;
  --accent2:#7c3aed;
  --danger: #ef4444;
  --success:#22c55e;
  --warn:   #f59e0b;
  --text0:  #e2e8f0;
  --text1:  #94a3b8;
  --text2:  #64748b;
  --panel-w:220px;
  --toolbar-h:40px;
  --menu-h: 36px;
  --status-h:26px;
  --console-h:160px;
  --radius: 4px;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono: 'Consolas', 'Courier New', monospace;
  --trans: 0.15s ease;
}

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--bg0);
  color: var(--text0);
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  touch-action: none; /* prevent scroll on canvas */
}

/* ─── UTILS ───────────────────────────────────────────────────── */
.hidden { display: none !important; }
.ml-auto { margin-left: auto; }
button { cursor: pointer; border: none; background: none; color: inherit; font: inherit; }
input, select { color: inherit; font: inherit; background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius); }
select { cursor: pointer; }
label { color: var(--text1); }

/* ─── LOADING SCREEN ─────────────────────────────────────────── */
#loading-screen {
  position: fixed; inset: 0;
  z-index: 9999;
  background: var(--bg0);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 16px;
}
.loading-logo {
  display: flex; align-items: center; gap: 10px;
}
.logo-icon {
  font-size: 40px; color: var(--accent);
  animation: spin 3s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.logo-text { font-size: 22px; font-weight: 700; letter-spacing: 1px; }
.loading-bar-wrap {
  width: min(360px, 80vw); height: 4px;
  background: var(--bg3); border-radius: 2px; overflow: hidden;
}
.loading-bar {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  border-radius: 2px;
  transition: width 0.3s;
}
.loading-msg { color: var(--text1); font-size: 12px; }

/* ─── APP SHELL ──────────────────────────────────────────────── */
#app {
  display: flex; flex-direction: column;
  width: 100%; height: 100%;
}

/* ─── MENU BAR ───────────────────────────────────────────────── */
#menu-bar {
  height: var(--menu-h);
  background: var(--bg1);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  flex-shrink: 0;
  z-index: 100;
  gap: 4px;
  padding: 0 8px;
}
.menu-logo {
  font-size: 13px; font-weight: 700;
  color: var(--accent);
  margin-right: 8px;
  white-space: nowrap;
}
.menu-nav {
  display: flex; gap: 2px; flex-wrap: nowrap;
}
.menu-item {
  padding: 4px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 12px;
  white-space: nowrap;
  color: var(--text1);
  transition: background var(--trans), color var(--trans);
}
.menu-item:hover, .menu-item.active {
  background: var(--bg3); color: var(--text0);
}
.menu-actions { margin-left: auto; display: flex; gap: 4px; }
.btn-icon {
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius);
  font-size: 14px;
  transition: background var(--trans);
}
.btn-icon:hover { background: var(--bg3); }

/* ─── DROPDOWN ──────────────────────────────────────────────── */
#dropdown-overlay {
  position: fixed; inset: 0;
  z-index: 200;
  background: transparent;
}
#dropdown {
  position: fixed;
  z-index: 201;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-width: 160px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  padding: 4px 0;
}
.dd-item {
  padding: 6px 16px;
  font-size: 12px;
  color: var(--text1);
  cursor: pointer;
  display: flex; align-items: center; gap: 8px;
  transition: background var(--trans), color var(--trans);
}
.dd-item:hover { background: var(--bg3); color: var(--text0); }
.dd-sep { height: 1px; background: var(--border); margin: 4px 0; }
.dd-kbd {
  margin-left: auto;
  font-size: 10px;
  color: var(--text2);
  font-family: var(--font-mono);
}

/* ─── TOOLBAR ────────────────────────────────────────────────── */
#toolbar {
  height: var(--toolbar-h);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 8px; gap: 6px;
  flex-shrink: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
#toolbar::-webkit-scrollbar { display: none; }
.tool-group { display: flex; align-items: center; gap: 2px; }
.tool-sep {
  width: 1px; height: 24px;
  background: var(--border);
  flex-shrink: 0;
}
.tool-btn {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center;
  padding: 3px 8px;
  border-radius: var(--radius);
  font-size: 11px;
  gap: 1px;
  min-width: 42px;
  color: var(--text1);
  transition: background var(--trans), color var(--trans);
}
.tool-btn:hover { background: var(--bg3); color: var(--text0); }
.tool-btn.active { background: var(--accent); color: #fff; }
.tool-icon { font-size: 13px; line-height: 1; }
.tool-label { font-size: 9px; white-space: nowrap; }
.tool-btn-sm {
  width: 26px; height: 26px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--text1);
  transition: background var(--trans), color var(--trans);
}
.tool-btn-sm:hover { background: var(--bg3); color: var(--text0); }
.snap-label { font-size: 10px; color: var(--text2); white-space: nowrap; }
#snap-select, #quality-select, #settings-quality, #settings-fps {
  font-size: 11px; padding: 3px 4px;
  background: var(--bg3);
  border-color: var(--border);
  border-radius: var(--radius);
  height: 26px;
}

/* ─── MAIN LAYOUT ────────────────────────────────────────────── */
#main-layout {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

/* ─── PANELS (LEFT / RIGHT) ──────────────────────────────────── */
#panel-left, #panel-right {
  width: var(--panel-w);
  flex-shrink: 0;
  background: var(--bg1);
  display: flex; flex-direction: column;
  overflow: hidden;
  border-right: 1px solid var(--border);
}
#panel-right {
  border-right: none;
  border-left: 1px solid var(--border);
}
.panel-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.panel-tab {
  flex: 1; padding: 7px 4px;
  font-size: 11px;
  color: var(--text2);
  border-bottom: 2px solid transparent;
  transition: color var(--trans), border-color var(--trans);
}
.panel-tab:hover { color: var(--text1); }
.panel-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.panel-content {
  display: none; flex: 1;
  flex-direction: column; overflow: hidden;
}
.panel-content.active { display: flex; }
.panel-header {
  padding: 8px 10px;
  font-size: 11px; font-weight: 600;
  color: var(--text2); letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  text-transform: uppercase;
}
.panel-search {
  padding: 6px 8px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}
.panel-search input {
  width: 100%;
  padding: 4px 8px;
  font-size: 12px;
  background: var(--bg3);
  border-color: var(--border);
  border-radius: var(--radius);
}

/* ─── EXPLORER TREE ──────────────────────────────────────────── */
#explorer-tree {
  flex: 1; overflow-y: auto;
  list-style: none;
  padding: 4px 0;
  scrollbar-width: thin;
  scrollbar-color: var(--bg4) transparent;
}
.tree-item {
  display: flex; align-items: center;
  padding: 4px 8px; gap: 4px;
  cursor: pointer;
  font-size: 12px; color: var(--text1);
  border-radius: var(--radius);
  margin: 1px 4px;
  position: relative;
}
.tree-item:hover { background: var(--bg3); }
.tree-item.selected { background: var(--accent); color: #fff; }
.tree-item.selected .tree-icon { color: #fff; }
.tree-icon { font-size: 12px; color: var(--text2); flex-shrink: 0; }
.tree-indent { display: inline-block; }
.tree-toggle {
  font-size: 10px; cursor: pointer;
  color: var(--text2); flex-shrink: 0;
  width: 12px;
}
.tree-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.panel-actions {
  display: flex; gap: 4px; padding: 6px 8px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.btn-sm {
  padding: 4px 8px;
  font-size: 11px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text0);
  cursor: pointer;
  transition: background var(--trans);
}
.btn-sm:hover { background: var(--bg4); }
.btn-danger { border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; border-color: var(--border); }

/* ─── ASSETS ─────────────────────────────────────────────────── */
.asset-drop-zone {
  margin: 8px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 16px 8px;
  text-align: center;
  color: var(--text2);
  transition: border-color var(--trans);
  cursor: pointer;
}
.asset-drop-zone.drag-over { border-color: var(--accent); color: var(--accent); }
.drop-icon { font-size: 28px; margin-bottom: 6px; }
.asset-drop-zone p { font-size: 11px; margin-bottom: 8px; }
.btn-upload { cursor: pointer; }
.btn-upload input { display: none; }
.asset-list {
  flex: 1; overflow-y: auto;
  list-style: none;
  padding: 4px;
  scrollbar-width: thin;
  scrollbar-color: var(--bg4) transparent;
}
.asset-item {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 8px;
  border-radius: var(--radius);
  cursor: grab; font-size: 11px;
  color: var(--text1);
  transition: background var(--trans);
}
.asset-item:hover { background: var(--bg3); }

/* ─── LIBRARY ────────────────────────────────────────────────── */
.library-categories {
  display: flex; flex-wrap: wrap; gap: 4px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.lib-cat {
  padding: 3px 8px;
  font-size: 10px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 20px;
  cursor: pointer;
  color: var(--text1);
  transition: background var(--trans), color var(--trans);
}
.lib-cat.active, .lib-cat:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.library-items {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 4px; padding: 6px;
  overflow-y: auto; flex: 1;
  scrollbar-width: thin;
  scrollbar-color: var(--bg4) transparent;
}
.lib-item {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 6px;
  text-align: center;
  cursor: grab;
  font-size: 10px; color: var(--text1);
  transition: background var(--trans), border-color var(--trans);
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.lib-item:hover { background: var(--bg4); border-color: var(--accent); }
.lib-item-icon { font-size: 20px; }

/* ─── VIEWPORT ───────────────────────────────────────────────── */
#viewport-wrap {
  flex: 1; position: relative; overflow: hidden;
  background: #090916;
}
#viewport {
  display: block; width: 100%; height: 100%;
  outline: none;
  cursor: crosshair;
}

/* ─── HUD ────────────────────────────────────────────────────── */
#hud {
  position: absolute; top: 8px; left: 8px;
  display: flex; gap: 12px;
  background: rgba(0,0,0,0.45);
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11px; color: var(--text1);
  pointer-events: none;
  backdrop-filter: blur(4px);
}
#hud-fps { color: var(--success); font-weight: 700; }

/* ─── TERRAIN TOOLBAR ────────────────────────────────────────── */
#terrain-toolbar {
  position: absolute; bottom: 12px; left: 50%;
  transform: translateX(-50%);
  display: flex; align-items: center; gap: 6px;
  background: rgba(13,13,26,0.85);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  backdrop-filter: blur(4px);
}
.terr-btn {
  padding: 4px 10px;
  font-size: 11px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text1); cursor: pointer;
  transition: background var(--trans), color var(--trans);
}
.terr-btn.active, .terr-btn:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
#terrain-toolbar label {
  display: flex; align-items: center; gap: 4px;
  font-size: 10px;
}
#terrain-toolbar input[type=range] {
  width: 70px; background: transparent; border: none;
  accent-color: var(--accent);
}

/* ─── CONTEXT MENU ───────────────────────────────────────────── */
#context-menu {
  position: fixed; z-index: 500;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-width: 150px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  padding: 4px 0;
}
.ctx-item {
  padding: 6px 14px;
  font-size: 12px; color: var(--text1);
  cursor: pointer;
  transition: background var(--trans), color var(--trans);
}
.ctx-item:hover { background: var(--bg3); color: var(--text0); }
.ctx-sep { height: 1px; background: var(--border); margin: 3px 0; padding: 0; }

/* ─── INSPECTOR ──────────────────────────────────────────────── */
#panel-right {
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--bg4) transparent;
}
.inspector-empty {
  flex: 1; display: flex; align-items: center; justify-content: center;
  color: var(--text2); font-size: 12px; text-align: center; padding: 20px;
}
#inspector-content { padding-bottom: 16px; }
.insp-section {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
.insp-section-title {
  font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--text2); margin-bottom: 6px;
}
.insp-row {
  display: flex; align-items: center; gap: 6px;
  margin-bottom: 5px;
  min-height: 24px;
}
.insp-row label { min-width: 72px; font-size: 11px; }
.insp-input {
  flex: 1; padding: 3px 6px;
  font-size: 12px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text0);
}
.insp-input:focus { border-color: var(--accent); outline: none; }
.insp-select {
  flex: 1; padding: 3px 4px;
  font-size: 11px;
  background: var(--bg3);
  border-color: var(--border);
}
.vec3 {
  display: flex; gap: 3px; flex: 1;
}
.vec3 input {
  flex: 1; min-width: 0;
  padding: 3px 4px;
  font-size: 11px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text0);
  text-align: center;
}
.vec3 input:focus { border-color: var(--accent); outline: none; }
.insp-check { align-items: center; }
.insp-check input { width: 14px; height: 14px; accent-color: var(--accent); }
#insp-color { width: 36px; height: 24px; padding: 1px; border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer; }
#insp-transparency, #insp-reflectance { flex: 1; accent-color: var(--accent); }
#insp-transparency-val, #insp-reflectance-val { font-size: 10px; color: var(--text2); min-width: 24px; }
.insp-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ─── STATUS BAR ─────────────────────────────────────────────── */
#status-bar {
  height: var(--status-h);
  background: var(--bg1);
  border-top: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 10px; gap: 16px;
  flex-shrink: 0; font-size: 11px;
  color: var(--text2);
}
#console-toggle {
  cursor: pointer; color: var(--text2);
  transition: color var(--trans);
}
#console-toggle:hover { color: var(--text0); }
#status-msg { color: var(--text1); }
#status-tri { margin-left: auto; }

/* ─── CONSOLE ────────────────────────────────────────────────── */
#console-drawer {
  height: var(--console-h);
  background: var(--bg0);
  border-top: 1px solid var(--border);
  display: flex; flex-direction: column;
  flex-shrink: 0;
  font-family: var(--font-mono);
  font-size: 12px;
}
#console-log {
  flex: 1; overflow-y: auto; padding: 6px 10px;
  scrollbar-width: thin; scrollbar-color: var(--bg4) transparent;
}
.console-line { padding: 1px 0; }
.console-line.info { color: var(--text1); }
.console-line.warn { color: var(--warn); }
.console-line.error { color: var(--danger); }
.console-line.success { color: var(--success); }
.console-input-row {
  display: flex; gap: 4px;
  padding: 4px 8px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
#console-input {
  flex: 1; padding: 4px 8px;
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--bg1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text0);
}
#console-run {
  padding: 0 12px; background: var(--accent);
  border-radius: var(--radius); color: #fff;
  font-size: 12px; cursor: pointer;
}

/* ─── MODALS ─────────────────────────────────────────────────── */
.modal {
  position: fixed; inset: 0;
  z-index: 1000;
  background: rgba(0,0,0,0.65);
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(3px);
}
.modal-box {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  min-width: min(360px, 90vw);
  box-shadow: 0 16px 40px rgba(0,0,0,0.6);
  overflow: hidden;
}
.modal-title {
  padding: 12px 16px;
  font-weight: 700; font-size: 14px;
  border-bottom: 1px solid var(--border);
}
.modal-body {
  padding: 16px;
  display: flex; flex-direction: column; gap: 10px;
}
.modal-body label { display: flex; align-items: center; gap: 8px; font-size: 12px; cursor: pointer; }
.setting-row {
  display: flex; align-items: center;
  justify-content: space-between;
  font-size: 12px;
}
.setting-row input[type=checkbox] { accent-color: var(--accent); }
.modal-actions {
  display: flex; gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  justify-content: flex-end;
}

/* ─── TOAST ──────────────────────────────────────────────────── */
#toast {
  position: fixed; bottom: 48px; left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 8px 20px;
  font-size: 12px; color: var(--text0);
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  animation: fadeInUp 0.25s ease;
}
@keyframes fadeInUp {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ─── MOBILE CONTROLS ────────────────────────────────────────── */
#mobile-controls {
  position: absolute; bottom: 12px;
  left: 0; right: 0;
  display: flex; align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  pointer-events: none;
}
.joystick {
  width: 90px; height: 90px;
  background: rgba(255,255,255,0.08);
  border: 2px solid rgba(255,255,255,0.15);
  border-radius: 50%;
  position: relative;
  pointer-events: all;
  touch-action: none;
}
.joystick-knob {
  width: 36px; height: 36px;
  background: rgba(79,142,247,0.7);
  border-radius: 50%;
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%,-50%);
  box-shadow: 0 0 12px rgba(79,142,247,0.5);
  transition: transform 0.08s;
}
#mobile-btns {
  display: flex; flex-direction: column;
  gap: 8px; pointer-events: all;
}
.mob-btn {
  width: 42px; height: 42px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 50%;
  font-size: 16px; color: var(--text1);
  display: flex; align-items: center; justify-content: center;
}

/* ─── RESPONSIVE: TABLET / MOBILE ──────────────────────────────*/
@media (max-width: 900px) {
  :root { --panel-w: 180px; }
  .tool-label { display: none; }
  .tool-btn { min-width: 32px; padding: 4px; }
}

@media (max-width: 640px) {
  :root {
    --panel-w: 0px;
    --toolbar-h: 44px;
    --menu-h: 40px;
    font-size: 12px;
  }

  #panel-left, #panel-right { display: none; }

  /* Mobile: panels as bottom sheets via JS toggle */
  #panel-left.mobile-open, #panel-right.mobile-open {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: 50vh;
    z-index: 300;
    width: 100%;
    border-top: 1px solid var(--border);
    border-radius: 12px 12px 0 0;
  }

  .menu-nav { display: none; }

  #menu-bar { padding: 0 6px; }
  .menu-logo { font-size: 12px; }

  #toolbar { gap: 4px; padding: 0 6px; }

  #hud { font-size: 10px; gap: 8px; }

  #mobile-controls { display: flex !important; }
}

/* ─── SCROLLBARS ─────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg4); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* ─── SELECTION OUTLINE ──────────────────────────────────────── */
.selection-outline { outline: 2px solid var(--accent); }

/* ─── FOCUS VISIBLE ──────────────────────────────────────────── */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
