You should review the Adding stylesheets (CSS) and Javascript (JS) to a Drupal module and Drupal theme docs. Unfortunately, there's information in one that's not in the other, but I believe all of the information pertaining to defining a library, i.e. creating a libraries.yml file, applies to both modules and themes.
Looking at mytheme.libraries.yml, I see 'base', 'component', 'layout',
'theme', and so on. Do these designations represent/do anything in
practice?
Yes, they do stuff. Primarily, they change the order that the files are loaded (lower weights are loaded first). It's also a good way to organize your CSS (these keys only apply to CSS, not JS) conceptually so as to make it easier to find, debug, and fix any issues or make changes.
From the docs:
[base, layout, component, state, theme keys] indicate the style type the CSS file belongs to.
You can set CSS weights with 5 different levels of styling:
- base: CSS reset/normalize plus HTML element styling. Key assigns a weight of
CSS_BASE = -200
- layout: macro arrangement of a web page, including any grid systems. Key assigns a weight of
CSS_LAYOUT = -100
- component: discrete, reusable UI elements. Key assigns a weight of
CSS_COMPONENT = 0
- state: styles that deal with client-side changes to components. Key assigns a weight of
CSS_STATE = 100
- theme: purely visual styling (“look-and-feel”) for a component. Key assigns a weight of
CSS_THEME = 200
This is defined by the SMACSS standard. So here if you specify theme
it means that the CSS file contains theme related styling which is
pure look and feel. More info here. You cannot use other keys as these
will cause strict warnings.
These keys do not provide any conditional loading of the files. They're all always loaded when the library is included, the keys only change the order in which the individual files are loaded. (If you're using aggregation, they will all be in the one file, but the order will be preserved.) To conditionally load files, you'll need to create separate libraries (you can define multiple libraries in the same libraries.yml file) and then attach the individual libraries only when you need them.
There are a number of ways to attach a library to a page, see the Attaching a Library to Page(s) section of the module and theme docs noted above.