:root {
    /* Branding & Accents */
    --oct-primary: #2463eb;
    --oct-primary-hover: #1d4ed8;
    --oct-header-bg: var(--oct-primary);
    --oct-header-fg: #ffffff;

    /* 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) */
    --oct-border: light-dark(#e1e4e8, #30363d);
    --oct-bg-subtle: light-dark(#f0f1f3, #22272e);
    --oct-bg-card: light-dark(#f6f8fa, #161b22);
    --oct-radius: 0.3em;
}

/* Page layout */
body { max-width: none; margin: 0; padding: 0; }
.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 > details { min-width: 0; border-bottom: 1px solid var(--oct-border); padding-bottom: 0.75rem; }
.page-layout > details > summary { font-weight: 600; padding: 0.35rem 0; }
.page-layout > details > nav { margin-top: 0.5rem; }
.page-layout summary { cursor: pointer; }
.custom-layout { max-width: none; padding: 0; }
main :is(h1,h2,h3,h4,h5,h6)[id] { scroll-margin-top: 7rem; }

/* 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 { min-width: 0; overflow-wrap: anywhere; font-size: 1.25rem; font-weight: 600; }
.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: #ffffff20; }
.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-toc { font-size: 0.85rem; line-height: 1.4; }
.site-nav ul, .page-toc :is(ul, ol) { list-style: none; margin: 0; padding-left: 1rem; }
.site-nav > nav > ul, .page-toc > nav > :is(ul, ol) { padding-left: 0; }
.site-nav a, .page-toc 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-toc a:hover { background: var(--oct-bg-subtle); }
.site-nav a[aria-current], .page-toc 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, listing filters, and footer */
.page-markdown { display: block; width: fit-content; margin: 0 0 1rem; font-size: 0.85rem; text-align: left; }
.categories-nav ul { display: flex; flex-wrap: wrap; gap: 0.5rem; list-style: none; padding: 0; }
.categories-nav a { display: block; padding: 0.25rem 0.5rem; border-radius: var(--oct-radius); text-decoration: none; }
.categories-nav a[aria-current] { background: var(--oct-bg-subtle); font-weight: 600; }
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; }

/* 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 { 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: 2px solid var(--oct-primary); outline-offset: -2px; }
.panel-tabset > .tab-panel > .tab-title { display: none; }

/* Listings */
.listing-table table { width: 100%; 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%; height: 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: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-toc { grid-column: 3; }
    .page-layout:not(.custom-layout) > details {
        grid-row: 1; position: sticky; top: 5rem; align-self: start;
        max-height: calc(100dvh - 6rem); overflow: auto; border-bottom: 0;
    }
}

@media (any-pointer: coarse) {
    .site-nav a, .site-nav summary, .page-toc a, .page-toc 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; }
}
