diff --git a/core/includes/common.inc b/core/includes/common.inc
index 20d24a7..8719660 100644
--- a/core/includes/common.inc
+++ b/core/includes/common.inc
@@ -5450,8 +5450,23 @@ function drupal_render(&$elements) {
     $elements['#children'] = $elements['#markup'] . $elements['#children'];
   }
 
+  // Add any JavaScript state information associated with the element.
+  if (!empty($elements['#states'])) {
+    drupal_process_states($elements);
+  }
+
+  // Add additional libraries, CSS, JavaScript an other custom
+  // attached data associated with this element.
+  if (!empty($elements['#attached'])) {
+    drupal_process_attached($elements);
+  }
+
   // Let the theme functions in #theme_wrappers add markup around the rendered
   // children.
+  // #states and #attached have to be processed before #theme_wrappers, because
+  // the #type 'page' render array from drupal_render_page() would render the
+  // $page and wrap it into the html.tpl.php template without the attached
+  // assets otherwise.
   if (isset($elements['#theme_wrappers'])) {
     foreach ($elements['#theme_wrappers'] as $theme_wrapper) {
       $elements['#children'] = theme($theme_wrapper, $elements);
@@ -5467,17 +5482,6 @@ function drupal_render(&$elements) {
     }
   }
 
-  // Add any JavaScript state information associated with the element.
-  if (!empty($elements['#states'])) {
-    drupal_process_states($elements);
-  }
-
-  // Add additional libraries, CSS, JavaScript an other custom
-  // attached data associated with this element.
-  if (!empty($elements['#attached'])) {
-    drupal_process_attached($elements);
-  }
-
   $prefix = isset($elements['#prefix']) ? $elements['#prefix'] : '';
   $suffix = isset($elements['#suffix']) ? $elements['#suffix'] : '';
   $output = $prefix . $elements['#children'] . $suffix;
diff --git a/core/modules/dblog/dblog.module b/core/modules/dblog/dblog.module
index 89efb57..a0afcd4 100644
--- a/core/modules/dblog/dblog.module
+++ b/core/modules/dblog/dblog.module
@@ -86,12 +86,11 @@ function dblog_menu() {
 }
 
 /**
- * Implements hook_init().
+ * Implements hook_page_build().
  */
-function dblog_init() {
+function dblog_page_build(&$page) {
   if (arg(0) == 'admin' && arg(1) == 'reports') {
-    // Add the CSS for this module
-    drupal_add_css(drupal_get_path('module', 'dblog') . '/dblog.css');
+    $page['#attached']['css'][] = drupal_get_path('module', 'dblog') . '/dblog.css';
   }
 }
 
diff --git a/core/modules/system/system.module b/core/modules/system/system.module
index c3df4c1..ad3366b 100644
--- a/core/modules/system/system.module
+++ b/core/modules/system/system.module
@@ -2313,15 +2313,6 @@ function system_filetransfer_info() {
  * Implements hook_init().
  */
 function system_init() {
-  $path = drupal_get_path('module', 'system');
-  // Add the CSS for this module. These aren't in system.info, because they
-  // need to be in the CSS_SYSTEM group rather than the CSS_DEFAULT group.
-  drupal_add_css($path . '/system.base.css', array('group' => CSS_SYSTEM, 'every_page' => TRUE));
-  if (path_is_admin(current_path())) {
-    drupal_add_css($path . '/system.admin.css', array('group' => CSS_SYSTEM));
-  }
-  drupal_add_css($path . '/system.theme.css', array('group' => CSS_SYSTEM, 'every_page' => TRUE));
-
   // Ignore slave database servers for this request.
   //
   // In Drupal's distributed database structure, new data is written to the master
@@ -2343,9 +2334,22 @@ function system_init() {
       unset($_SESSION['ignore_slave_server']);
     }
   }
+}
+
+/**
+ * Implements hook_page_build().
+ */
+function system_page_build(&$page) {
+  $path = drupal_get_path('module', 'system');
+  // Use the CSS_SYSTEM group to load these early.
+  $page['#attached']['css'][$path . '/system.base.css'] = array('group' => CSS_SYSTEM, 'every_page' => TRUE);
+  if (path_is_admin(current_path())) {
+    $page['#attached']['css'][$path . '/system.admin.css'] = array('group' => CSS_SYSTEM);
+  }
+  $page['#attached']['css'][$path . '/system.theme.css'] = array('group' => CSS_SYSTEM, 'every_page' => TRUE);
 
   // Add CSS/JS files from module .info files.
-  system_add_module_assets();
+  system_add_module_assets($page);
 }
 
 /**
@@ -2371,17 +2375,17 @@ function system_get_localized_date_format($languages) {
 /**
  * Adds CSS and JavaScript files declared in module .info files.
  */
-function system_add_module_assets() {
+function system_add_module_assets(&$page) {
   foreach (system_get_module_info('stylesheets') as $module => $value) {
     foreach ($value as $media => $stylesheets) {
       foreach ($stylesheets as $stylesheet) {
-        drupal_add_css($stylesheet, array('every_page' => TRUE, 'media' => $media));
+        $page['#attached']['css'][$stylesheet] = array('every_page' => TRUE, 'media' => $media);
       }
     }
   }
   foreach (system_get_module_info('scripts') as $module => $scripts) {
     foreach ($scripts as $script) {
-      drupal_add_js($script, array('every_page' => TRUE));
+      $page['#attached']['js'][$script] = array('every_page' => TRUE);
     }
   }
 }
