@layer app {
  :root {
      /* Branding & Accents */
      --oct-primary: var(--color-accent);
      --oct-primary-hover: var(--v1);
      --oct-header-bg: var(--oct-primary);
      --oct-header-fg: var(--color-on-accent);

      /* Layout dimensions */
      --oct-content-max: 46rem;
      --oct-nav-width: 15rem;
      --oct-toc-width: 15rem;
      --oct-gap: 2rem;
      --oct-card-img-width: 13.5rem;

      /* Neutrals & Borders (auto light/dark via AnswerUI) */
      --oct-border: var(--color-border);
      --oct-bg-subtle: var(--color-surface);
      --oct-bg-card: var(--color-surface);
      --oct-bg: var(--color-background);
      --oct-radius: var(--radius-1);
  }

  /* Page layout */
  body { background: var(--oct-bg); }
  main[prose] { --prose-measure: none; }
  main[prose] pre { font-size: 0.9em; line-height: 1.45; white-space: pre; overflow-wrap: normal; padding: var(--space-1) var(--space); }
  .page-layout {
      display: grid; grid-template-columns: minmax(0, 1fr); gap: 1.25rem;
      max-width: calc(var(--oct-nav-width) + var(--oct-content-max) + var(--oct-toc-width) + 2 * var(--oct-gap) + 3rem);
      margin: auto; padding: 1.5rem;
  }
  .page-layout > main { min-width: 0; overflow-wrap: anywhere; }
  .page-layout > :is(details, aside) { min-width: 0; border-bottom: 1px solid var(--oct-border); padding-bottom: 0.75rem; }
  :is(.page-layout, .page-side) > details > summary { font-weight: 600; padding: 0.35rem 0; }
  :is(.page-layout, .page-side) > details > nav { margin-top: 0.5rem; }
  .page-layout summary { cursor: pointer; }
  .custom-layout { max-width: none; padding: 0; }
  .full-layout { max-width: none; }
  main :is(h1,h2,h3,h4,h5,h6)[id] { scroll-margin-top: 7rem; }
  main :is(.column-body-outset, .column-page, .column-screen-inset-right) { max-width: 100%; overflow-x: auto; }
  .oct-video { display: block; width: 100%; aspect-ratio: 16 / 9; border: 0; margin: 1rem 0; }

  /* Site header */
  .site-header {
      position: sticky; top: 0; z-index: 100; box-sizing: border-box;
      display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem;
      padding: 0.55rem 1.5rem; background: var(--oct-header-bg); color: var(--oct-header-fg);
  }
  .site-header > :first-child { display: flex; align-items: center; gap: 0.5rem; min-width: 0; overflow-wrap: anywhere; font-size: 1.25rem; font-weight: 600; }
  .site-header .site-logo { height: 1.75rem; width: auto; display: block; }
  .site-header a { color: inherit; text-decoration: none; }
  .site-tools { margin-left: auto; min-width: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem; }
  .site-tools a { display: flex; padding: 0.5rem; }
  .site-tools svg, .site-tools img { width: 18px; height: 18px; }

  .header-nav { order: 3; flex-basis: 100%; min-width: 0; }
  .header-nav summary { cursor: pointer; }
  .header-nav > summary { padding: 0.35rem 0; font-weight: 600; }
  .header-nav > nav { max-height: calc(100dvh - 9rem); overflow: auto; }
  .header-nav ul { list-style: none; padding: 0; margin: 0; }
  .header-nav ul ul { padding-left: 1rem; }
  .header-nav a, .header-nav nav summary { display: block; padding: 0.5rem 0.75rem; overflow-wrap: anywhere; }
  .header-nav nav summary { display: list-item; }
  .header-nav a:hover, .header-nav nav summary:hover { background: var(--tint); }
  .header-nav a[aria-current] { font-weight: 600; text-decoration: underline; }

  @media (width > 72rem) {
      .header-nav { order: initial; flex-basis: auto; }
      .header-nav > summary { display: none; }
      .header-nav > nav { max-height: none; overflow: visible; }
      .header-nav > nav > ul { display: flex; flex-wrap: wrap; align-items: center; }
      .header-nav > nav > ul > li { position: relative; }
      .header-nav > nav > ul > li > details > ul {
          position: absolute; top: 100%; left: 0; min-width: 12rem; padding: 0.5rem;
          background: var(--oct-header-bg); border-radius: var(--oct-radius); box-shadow: 0 4px 12px #0003;
      }
  }

  /* Navigation */
  .site-nav { font-size: 0.9rem; }
  .page-side { font-size: 0.85rem; line-height: 1.4; }
  .site-nav ul, .page-side :is(ul, ol) { list-style: none; margin: 0; padding-left: 1rem; }
  .site-nav > nav > ul, .page-side > details > nav > :is(ul, ol) { padding-left: 0; }
  .site-nav a, .page-side a {
      display: block; padding: 0.35rem 0.5rem; color: inherit;
      text-decoration: none; overflow-wrap: anywhere;
  }
  .site-nav nav summary { padding: 0.35rem 0.5rem; overflow-wrap: anywhere; }
  :is(.site-nav, .header-nav) summary > a { display: inline-block; padding: 0; }
  .site-nav a:hover, .site-nav nav summary:hover, .page-side a:hover { background: var(--oct-bg-subtle); }
  .site-nav a[aria-current], .page-side a[aria-current] { font-weight: 600; color: var(--oct-primary); }
  .site-nav a[aria-current] { background: var(--oct-bg-subtle); border-radius: var(--oct-radius); }

  /* Page actions and footer */
  .page-side > details + .page-actions { border-top: 1px solid var(--oct-border); margin-top: 0.5rem; padding-top: 0.5rem; }
  footer.site { border-top: 1px solid var(--oct-border); padding: 1rem 1.5rem; opacity: 0.7; font-size: 0.9em; }

  /* Title block */
  .title-block { margin: 0 0 2rem; }
  .title-block h1 { margin: 0 0 0.35rem; font-size: 2.25rem; font-weight: 700; line-height: 1.2; }
  .title-block .description { margin: 0; font-size: 1.2rem; opacity: 0.7; font-weight: 300; line-height: 1.5; }
  .title-block .title-categories { display: flex; flex-wrap: wrap; gap: 0.35rem; margin: 0 0 0.75rem; }
  .title-block .title-category {
      font-size: 0.8rem; padding: 0.15em 0.55em; border-radius: var(--oct-radius);
      background: var(--oct-bg-subtle); border: 1px solid var(--oct-border); color: inherit; text-decoration: none;
  }
  .title-block a.title-category:hover { border-color: var(--oct-primary); color: var(--oct-primary); }
  .title-block .title-meta { display: flex; flex-wrap: wrap; gap: 0.5rem 3rem; margin: 1.25rem 0 0; }
  .title-block .title-meta dt { margin: 0; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; opacity: 0.6; }
  .title-block .title-meta dd { margin: 0.2rem 0 0; padding: 0; }

  /* Clickable header anchors */
  main[prose] :is(h1,h2,h3,h4)[id] > a.h-anchor { margin-left: .35em; font-size: .8em; font-weight: 400; text-decoration: none; opacity: 0; }
  main[prose] :is(h1,h2,h3,h4)[id]:hover > a.h-anchor { opacity: .5; }
  main[prose] :is(h1,h2,h3,h4)[id] > a.h-anchor:hover { opacity: 1; }

  /* Code copy button */
  .vm-code { position: relative; }
  .vm-copy {
      position: absolute; top: 0.4rem; right: 0.4rem; font: inherit; font-size: 0.75rem;
      padding: 0.15em 0.5em; cursor: pointer; opacity: 0; transition: opacity 0.1s;
      border: 1px solid var(--oct-border); border-radius: var(--oct-radius);
      background: var(--oct-bg-card); color: inherit;
  }
  .vm-code:hover .vm-copy { opacity: 1; }

  /* Folded code (`code-fold` cells): a details element with the summary as its label */
  details.code-fold { margin: 1em 0; border: 1px solid var(--oct-border); border-radius: var(--oct-radius); }
  details.code-fold > summary { cursor: pointer; padding: 0.3em 0.8em; font-size: 0.85rem; opacity: 0.7; }
  details.code-fold > summary:hover { opacity: 1; }
  details.code-fold[open] > summary { border-bottom: 1px solid var(--oct-border); }
  details.code-fold > .vm-code, details.code-fold > pre, details.code-fold > .vm-code > pre { margin: 0; }

  /* Tabsets */
  .panel-tabset { min-width: 0; }
  .panel-tabset > .tab-buttons {
      display: flex; overflow-x: auto; gap: 0.25rem;
      border-bottom: 1px solid var(--oct-border);
  }
  .panel-tabset > .tab-buttons > button {
      flex: none; margin: 0; padding: 0.5em 1em; font: inherit; cursor: pointer;
      color: inherit; background: transparent; border: 0; border-bottom: 2px solid transparent;
      border-radius: var(--oct-radius) var(--oct-radius) 0 0;
  }
  .panel-tabset > .tab-buttons > button:hover { background: var(--oct-bg-subtle); }
  .panel-tabset > .tab-buttons > button[aria-pressed="true"] {
      font-weight: 600; border-bottom-color: var(--oct-primary);
  }
  .panel-tabset > .tab-buttons > button:focus-visible { outline: var(--ring); outline-offset: -2px; }
  .panel-tabset > .tab-panel > .tab-title { display: none; }

  /* Margin notes (Quarto's `.column-margin`): an aside in the text, moved beside the block before it on wide screens */
  main .column-margin { margin: 1rem 0; padding-left: 0.75rem; border-left: 2px solid var(--oct-border); font-size: 0.85rem; line-height: 1.45; }
  main .column-margin > :first-child { margin-top: 0; }
  main .column-margin > :last-child { margin-bottom: 0; }

  /* Listings */
  .listing-table table { display: table; width: 100%; margin-inline: 0; border-collapse: collapse; }
  .listing-table th, .listing-table td { padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--oct-border); text-align: left; }

  .listing-card {
      display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: repeat(3, min-content) 1fr; column-gap: 1.5rem;
      padding: 1.5rem 0; border-bottom: 1px solid var(--oct-border);
  }
  .listing-card:has(> figure) { grid-template-columns: minmax(0, 1fr) var(--oct-card-img-width); }
  .listing-card:last-child { border-bottom: none; }
  .listing-card > :is(h2, p, figure) { grid-column: 1; margin: 0; }
  .listing-card > p { margin-top: 0.35rem; }
  .listing-card h2 { grid-row: 1; font-size: 1.3rem; line-height: 1.25; font-weight: 600; }
  .listing-card h2 a { color: inherit; text-decoration: none; }
  .listing-card h2 a:hover { color: var(--oct-primary); }
  .listing-card .listing-meta { grid-row: 2; font-size: 0.85em; opacity: 0.7; }
  .listing-card .listing-description { grid-row: 3; opacity: 0.8; font-size: 0.95rem; line-height: 1.5; }
  .listing-card .listing-categories { grid-row: 4; display: flex; gap: 0.35rem; flex-wrap: wrap; align-content: end; padding-top: 0.25rem; }
  .listing-card .listing-category {
      font-size: 0.75em; padding: 0.15em 0.55em; border-radius: var(--oct-radius);
      background: var(--oct-bg-subtle); border: 1px solid var(--oct-border);
      color: inherit; text-decoration: none; opacity: 0.85;
  }
  .listing-card .listing-category:hover { opacity: 1; border-color: var(--oct-primary); color: var(--oct-primary); }
  .listing-card > figure { grid-column: 2; grid-row: 1 / 5; width: var(--oct-card-img-width); height: 100%; min-height: 7rem; overflow: hidden; }
  .listing-card > figure img { width: 100%; object-fit: cover; display: block; }

  /* ==========================================================================
     4. Responsive Media Queries
     ========================================================================== */

  @media (width > 72rem) {
      .page-layout:not(.custom-layout) {
          grid-template-columns: var(--oct-nav-width) minmax(0, var(--oct-content-max)) var(--oct-toc-width);
          gap: var(--oct-gap);
      }
      .page-layout.full-layout { grid-template-columns: var(--oct-nav-width) minmax(0, 1fr) var(--oct-toc-width); }
      .page-layout:not(.custom-layout) > main { grid-column: 2; grid-row: 1; }
      .page-layout:not(.custom-layout) > .site-nav { grid-column: 1; }
      .page-layout:not(.custom-layout) > .page-side { grid-column: 3; z-index: 1; background: var(--oct-bg); }
      .page-layout:not(.custom-layout) > :is(details, aside) {
          grid-row: 1; position: sticky; top: 5rem; align-self: start;
          max-height: calc(100dvh - 6rem); overflow: auto; border-bottom: 0;
      }
      .page-layout:not(.custom-layout) > main :is(.column-body-outset, .column-page, .column-screen-inset-right) {
          max-width: none; width: calc(100% + var(--oct-toc-width) + var(--oct-gap));
      }
      /* Each group of margin notes sits in the right-hand column, level with the top of the block before it; the side panel covers them as they scroll past */
      .page-layout:not(.custom-layout) > main > .margin-group { position: relative; }
      .page-layout:not(.custom-layout) > main > .margin-group > .margin-notes {
          position: absolute; top: 0; left: calc(100% + var(--oct-gap)); width: var(--oct-toc-width);
      }
      .page-layout:not(.custom-layout) > main > .margin-group > .margin-notes > .column-margin { margin: 0 0 1rem; padding: 0; border: 0; }
  }

  @media (any-pointer: coarse) {
      .site-nav a, .site-nav summary, .page-side a, .page-side summary { min-height: 2.75rem; }
  }

  @media (max-width: 48rem) {
      .listing-card { display: flex; flex-direction: column; gap: 0.35rem; }
      .listing-card > p { margin: 0; }
      .listing-card > figure { width: 100%; height: 10rem; order: -1; }
  }
}
