:root {
  --bg: #0a0a0f;
  --surface: #13131a;
  --surface2: #1a1a24;
  --surface3: #222230;
  --border: #2a2a3a;
  --text: #e0e0e8;
  --text2: #8888a0;
  --text3: #555568;
  --accent: #6366f1;
  --accent2: #818cf8;
  --green: #34d399;
  --red: #f87171;
  --amber: #fbbf24;
  --blue: #60a5fa;
  --radius: 6px;
  --sidebar-width: 280px;
  --props-width: 260px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
#editor-header {
  height: 40px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  flex-shrink: 0;
  z-index: 20;
}

#editor-header .title {
  font-size: 13px;
  font-weight: 600;
}

#editor-header .title span { color: var(--text2); font-weight: 400; }

#editor-header .actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

/* Layout */
#editor-body {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* Sidebar */
#sidebar {
  width: var(--sidebar-width);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
  transition: transform 0.2s, width 0.2s;
}

#sidebar.collapsed { width: 0; transform: translateX(calc(-1 * var(--sidebar-width))); border: none; }

/* Sidebar toggle */
#sidebar-toggle {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 15;
  width: 28px;
  height: 28px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text2);
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

#sidebar-toggle:hover { border-color: var(--accent); color: var(--accent2); }

.sidebar-section {
  border-bottom: 1px solid var(--border);
}

.sidebar-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text2);
  cursor: pointer;
  user-select: none;
}

.sidebar-section-header:hover { color: var(--text); }

.sidebar-section-body {
  padding: 0 8px 8px 8px;
  overflow-y: auto;
  max-height: 40vh;
}

/* Asset tree */
.asset-tree-item {
  padding: 4px 8px;
  font-size: 12px;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.asset-tree-item:hover { background: var(--surface2); }
.asset-tree-item.expandable { font-weight: 600; color: var(--text); }
.asset-tree-item .icon { color: var(--text2); font-size: 10px; width: 12px; text-align: center; }
.asset-tree-item.child { padding-left: 24px; color: var(--text2); }
.asset-tree-item.child:hover { color: var(--text); }

.asset-tree-item .badge {
  font-size: 9px;
  padding: 1px 5px;
  border-radius: 3px;
  margin-left: auto;
  flex-shrink: 0;
}

.badge-completed { background: #0d2818; color: var(--green); }
.badge-running { background: #0d1628; color: var(--blue); }

/* Scene hierarchy */
.scene-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  font-size: 12px;
  border-radius: 4px;
  cursor: pointer;
}

.scene-item:hover { background: var(--surface2); }
.scene-item.selected { background: var(--accent); color: #fff; }

.scene-item .vis-toggle {
  width: 14px;
  height: 14px;
  border: 1px solid var(--border);
  border-radius: 3px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  flex-shrink: 0;
  background: var(--surface2);
}

.scene-item .vis-toggle.visible { background: var(--accent); border-color: var(--accent); color: #fff; }
.scene-item .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scene-item .remove { color: var(--text3); cursor: pointer; font-size: 14px; padding: 0 2px; }
.scene-item .remove:hover { color: var(--red); }

/* Compositions */
.comp-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  font-size: 12px;
  border-radius: 4px;
  cursor: pointer;
}

.comp-item:hover { background: var(--surface2); }
.comp-item.active { background: var(--surface3); color: var(--accent2); }
.comp-item .name { flex: 1; }
.comp-item .meta { color: var(--text3); font-size: 10px; }

/* Viewport */
#viewport {
  flex: 1;
  position: relative;
  overflow: hidden;
}

#viewport canvas {
  width: 100%;
  height: 100%;
  display: block;
}

#viewport-overlay {
  position: absolute;
  bottom: 12px;
  left: 12px;
  font-size: 11px;
  color: var(--text2);
  pointer-events: none;
}

/* Transform mode toolbar */
#transform-toolbar {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 2px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 3px;
  z-index: 10;
}

.tf-btn {
  padding: 5px 12px;
  font-size: 11px;
  border: none;
  background: transparent;
  color: var(--text2);
  cursor: pointer;
  border-radius: 4px;
}

.tf-btn:hover { color: var(--text); background: var(--surface2); }
.tf-btn.active { color: #fff; background: var(--accent); }

/* Properties panel */
#properties {
  width: var(--props-width);
  background: var(--surface);
  border-left: 1px solid var(--border);
  flex-shrink: 0;
  overflow-y: auto;
  display: none;
}

#properties.open { display: block; }

.prop-group {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.prop-group-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text2);
  margin-bottom: 8px;
}

.prop-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 5px;
}

.prop-row label {
  font-size: 11px;
  color: var(--text2);
  width: 14px;
  text-align: center;
  flex-shrink: 0;
}

.prop-row input[type="number"] {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 6px;
  color: var(--text);
  font-size: 11px;
  width: 0;
}

.prop-row input:focus { outline: none; border-color: var(--accent); }

.prop-row input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  background: var(--surface2);
  height: 4px;
  border-radius: 2px;
  outline: none;
}

.prop-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 12px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 11px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.btn:hover { border-color: var(--accent); color: var(--accent2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent2); border-color: var(--accent2); }
.btn-danger { border-color: var(--red); color: var(--red); }
.btn-danger:hover { background: var(--red); color: #fff; }
.btn-sm { padding: 3px 8px; font-size: 10px; }

/* Toast */
.toast {
  position: fixed;
  bottom: 16px;
  right: 16px;
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.3s;
  z-index: 1000;
}

.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { border-color: var(--red); color: var(--red); }
.toast.success { border-color: var(--green); color: var(--green); }

/* Loading state */
.loading-spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

/* Crop box overlay */
#crop-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
  z-index: 5;
}

.crop-controls {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  pointer-events: auto;
}

/* Mobile / narrow screens */
@media (max-width: 768px) {
  :root {
    --sidebar-width: 260px;
    --props-width: 220px;
  }

  #sidebar {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 12;
    box-shadow: 4px 0 20px rgba(0,0,0,0.5);
  }

  #sidebar.collapsed { transform: translateX(-100%); }

  #properties {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 12;
    box-shadow: -4px 0 20px rgba(0,0,0,0.5);
  }

  #transform-toolbar {
    top: 8px;
    left: auto;
    right: 8px;
    transform: none;
  }

  #sidebar-toggle { display: flex; }
}

@media (min-width: 769px) {
  #sidebar-toggle { display: none; }
  #sidebar.collapsed { width: 0; transform: translateX(calc(-1 * var(--sidebar-width))); }
}
