Customization: Themes, Layouts, and Templates
Themes inherit from a parent theme declared in theme.xml, with registration.php registering the theme and composer.json for distribution. Static files live under web/; layout XML under Magento_Theme/layout/; templates under Magento_Module/templates/. The fallback chain runs from your theme to its parent, then to the module's own view files, so a template override placed in the correct module directory of your theme wins over the module default.
Layout XML uses handles: default, cms_index_index, and route-based handles like catalog_product_view. Handles are processed in order, with more specific handles overriding earlier ones. Key nodes are <block> (with class, name, template, before/after), <referenceBlock> and <referenceContainer> for modifying existing structures, and <arguments> for injecting data. setChild and getChildHtml connect blocks in templates. A common trap: <referenceBlock> fails if the referenced block name does not exist in the merged layout; use <referenceContainer> for containers.
UI Components (uiComponent XML in view/adminhtml/ui_component/) power grids and forms; they are configured declaratively and rendered by Knockout templates. Do not confuse UI component XML with layout XML - they are separate systems.
Template files are .phtml and should escape output with $block->escapeHtml(), escapeUrl(), and escapeJs(). Block caching uses cacheable="true" plus a cache lifetime and cache key.
Worked rule of thumb: To add a block to the product page, create catalog_product_view.xml in your theme's Magento_Catalog/layout/, use <referenceContainer name="content"> and <block ... template="Vendor_Module::product/extra.phtml"/>, then create the template under Magento_Catalog/templates/product/. If the block does not render, check the container name and whether the parent block calls getChildHtml.