:root {
    /* Our custom aliases — built on top of Fluent design tokens with warm
       nougat fallbacks for the boot screen (before Fluent's JS fires).
       Fluent generates the brown primary-brand ramp from data-theme-color on
       <body>; we only need to set the pistachio-green slots ourselves. */
    --bg-accent: var(--colorBrandForeground1, #9b6238);
    --bg-green: #5f8f3c;
    --bg-link: var(--colorBrandForegroundLink, #5f8f3c);
    --bg-border: var(--colorNeutralStroke1, #e8dbc4);
    --bg-muted: var(--colorNeutralForeground3, #6e6253);
    --bg-fg: var(--colorNeutralForeground1, #2a2118);
    --bg-layer-1: var(--colorNeutralBackground1, #faf5ec);
    --bg-layer-3: #f2e6d2;
    --bg-max-width: 1100px;

    /* Fluent injects brand tokens as inline styles on :root via JS, which
       normally beats stylesheet rules. !important lets us permanently own
       the green slots (links, checkmarks, combobox focus) without touching
       the brown primary-brand ramp Fluent generates from data-theme-color.
       Light-mode values live here because Fluent *removes* data-theme in
       light mode, so body[data-theme="light"] never matches after boot. */
    --colorBrandForegroundLink: #5f8f3c !important;
    --colorBrandForegroundLinkHover: #4b702f !important;
    --colorBrandForegroundLinkPressed: #3d5c27 !important;
    --colorCompoundBrandForeground1: #5f8f3c !important;
    --colorCompoundBrandForeground1Hover: #4b702f !important;
    --colorCompoundBrandStroke: #5f8f3c !important;
    --colorCompoundBrandStrokeHover: #4b702f !important;
}

/* Dark mode: Fluent sets data-theme="dark" on body.
   Higher specificity than :root so these !important values win. */
body[data-theme="dark"] {
    --bg-green: #8fcb72;
    --bg-layer-3: #241e16;

    /* Green slots — dark-mode shades */
    --colorBrandForegroundLink: #8fcb72 !important;
    --colorBrandForegroundLinkHover: #a6d98a !important;
    --colorBrandForegroundLinkPressed: #7ab961 !important;
    --colorCompoundBrandForeground1: #8fcb72 !important;
    --colorCompoundBrandForeground1Hover: #a6d98a !important;
    --colorCompoundBrandStroke: #8fcb72 !important;
    --colorCompoundBrandStrokeHover: #a6d98a !important;

    /* Fluent's neutral scale is cool grey by default; warm it up. */
    --colorNeutralBackground1: #1b1712 !important;
    --colorNeutralBackground2: #201c14 !important;
    --colorNeutralBackground3: #261f16 !important;
    --colorNeutralBackground4: #2d2418 !important;
    --colorNeutralBackground5: #38291b !important;
    --colorNeutralBackground6: #43311f !important;
    --colorNeutralStroke1: #392f23 !important;
    --colorNeutralStroke2: #4a3c2a !important;
    --colorNeutralStroke3: #5c4c35 !important;
}

html, body {
    margin: 0;
    /* Fluent UI's auto-injected default-fuib.css pins body to
       height:100dvh; overflow:hidden. We accept that here — all scrolling
       (both axes) happens inside .bg-body-scroll so the header never moves. */
    height: 100dvh !important;
    overflow: hidden !important;
    font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, Helvetica, Arial, sans-serif;
    color: var(--bg-fg, #2a2118);
    background: var(--bg-layer-1, #fff);
}

/* Blazor mounts into #app — it must propagate the viewport height down to .bg-page. */
#app {
    height: 100%;
}

/* Full-viewport flex column: header is a fixed-size item, body-scroll fills the rest. */
.bg-page {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* Scrollable content area — handles both vertical and horizontal scroll
   independently of the header, so the header is never scrolled off-screen. */
.bg-body-scroll {
    flex: 1;
    min-height: 0; /* allow flex child to shrink below its content size */
    overflow-x: auto;
    overflow-y: auto;
}

a {
    color: var(--bg-link);
    text-decoration: none;
}

a:hover {
    text-decoration: none;
}

.bg-container {
    max-width: var(--bg-max-width);
    margin: 0 auto;
    padding: 0 1rem;
}

/* Header */
.bg-header {
    background: var(--bg-layer-3, #f2e6d2);
    border-bottom: 1px solid var(--bg-border);
}

.bg-header-inner {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    padding-top: .75rem;
    padding-bottom: .75rem;
    flex-wrap: wrap;
}

.bg-brand {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--bg-accent, #9b6238);
    text-decoration: none;
}

.bg-brand:hover {
    text-decoration: none;
}

.bg-nav {
    display: flex;
    gap: 1rem;
}

.bg-nav-link {
    font-weight: 600;
    color: var(--bg-fg, #2a2118);
    padding: .25rem 0;
    text-decoration: none;
}

.bg-nav-link:hover {
    text-decoration: none;
}

.bg-nav-link.active {
    border-bottom: 2px solid var(--bg-accent);
}

.bg-search {
    display: flex;
    flex: 1 1 320px;
    gap: .5rem;
}

.bg-search-input {
    flex: 1;
    padding: .4rem .6rem;
    border: 1px solid var(--bg-border);
    border-radius: 4px;
    font-size: .95rem;
}

/* Main */
.bg-main {
    padding-top: 1.5rem;
    padding-bottom: 3rem;
}

/* Filters */
.bg-filters {
    display: flex;
    gap: 1.5rem;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
}

.bg-filter {
    display: flex;
    flex-direction: column;
    gap: .25rem;
    font-size: .85rem;
    color: var(--bg-muted);
}

.bg-filter.bg-filter-inline {
    flex-direction: row;
    align-items: center;
    gap: .5rem;
}

/* Custom dropdown — replaces native <select> for full theming control. */
.bg-select-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
}

.bg-select {
    position: relative;
    z-index: 101;
}

.bg-select-trigger {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: .5rem;
    min-width: 12rem;
    padding: .35rem .5rem;
    border: 1px solid var(--bg-green);
    border-radius: 4px;
    background: var(--bg-layer-1);
    color: var(--bg-fg);
    font-size: inherit;
    cursor: pointer;
    text-align: left;
    width: 100%;
}

.bg-select-trigger:hover {
    border-color: var(--bg-accent);
}

.bg-select-trigger:focus-visible {
    outline: none;
    border-color: var(--bg-link);
    box-shadow: 0 0 0 2px rgba(95, 143, 60, 0.3);
}

.bg-select-chevron {
    font-size: .75rem;
    opacity: .6;
    flex-shrink: 0;
}

.bg-select-list {
    position: absolute;
    top: calc(100% + 2px);
    left: 0;
    min-width: 100%;
    background: var(--bg-layer-1);
    border: 1px solid var(--bg-border);
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0,0,0,.15);
    overflow: hidden;
}

.bg-select-option {
    display: block;
    width: 100%;
    padding: .4rem .6rem;
    border: none;
    background: none;
    color: var(--bg-fg);
    font-size: inherit;
    text-align: left;
    cursor: pointer;
    white-space: nowrap;
}

.bg-select-option:hover {
    background: var(--bg-layer-3);
}

.bg-select-option.selected {
    color: var(--bg-accent);
    font-weight: 600;
}

/* Native checkbox: accent-color makes the browser tint it with our green. */
.bg-filter input[type="checkbox"] {
    accent-color: var(--bg-green);
    width: 1rem;
    height: 1rem;
    cursor: pointer;
}

/* Search results */
.bg-result {
    display: flex;
    gap: 1rem;
    padding: 1rem;
    margin-bottom: 1rem;
}

.bg-result-icon img {
    width: 64px;
    height: 64px;
    object-fit: contain;
}

.bg-result-body {
    flex: 1;
    min-width: 0;
}

.bg-result-title {
    font-size: 1.4rem;
    font-weight: 600;
    overflow-wrap: anywhere;
}

.bg-result-authors {
    margin-left: .5rem;
    color: var(--bg-muted);
    font-size: .9rem;
}

.bg-result-info {
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    padding: 0;
    margin: .5rem 0;
    color: var(--bg-muted);
    font-size: .9rem;
}

.bg-tags {
    color: var(--bg-muted, #6e6253);
}

.bg-result-desc {
    color: var(--bg-fg, #2a2118);
}

.bg-pager {
    display: flex;
    gap: .5rem;
    justify-content: center;
    margin-top: 1.5rem;
}

.bg-center {
    display: flex;
    justify-content: center;
    padding: 3rem 0;
}

.bg-empty {
    text-align: center;
    padding: 2rem 0;
    color: var(--bg-muted);
}

/* Package details */
.bg-details {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: 2rem;
}

@media (max-width: 800px) {
    .bg-details {
        grid-template-columns: 1fr;
    }
}

.bg-details-head {
    display: flex;
    gap: 1rem;
    align-items: center;
    margin-bottom: 1rem;
}

.bg-details-head img {
    width: 72px;
    height: 72px;
    object-fit: contain;
}

.bg-details-title {
    font-size: 2rem;
    font-weight: 600;
    margin: 0;
    overflow-wrap: anywhere;
}

.bg-release-notes {
    border-top: 1px solid var(--bg-border);
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    overflow-wrap: anywhere;
}

.bg-release-notes h2 {
    font-size: 1.1rem;
    margin: 0 0 .5rem;
}

.bg-readme {
    border-top: 1px solid var(--bg-border);
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    overflow-wrap: anywhere;
    overflow-x: hidden;
}

.bg-readme img {
    max-width: 100%;
}

.bg-readme pre {
    overflow-x: auto;
    max-width: 100%;
}

.bg-readme table {
    display: block;
    overflow-x: auto;
    max-width: 100%;
}

.bg-sidebar h3 {
    font-size: 1rem;
    margin: 1.25rem 0 .5rem;
}

.bg-versions {
    width: 100%;
    border-collapse: collapse;
}

.bg-versions th,
.bg-versions td {
    text-align: left;
    padding: .35rem .5rem;
    border-bottom: 1px solid var(--bg-border);
    font-size: .9rem;
}

.bg-dep-group {
    margin-bottom: .75rem;
}

.bg-dep-group > .bg-dep-fw {
    font-weight: 600;
}

.bg-dep-list {
    list-style: none;
    padding-left: 1rem;
    margin: .25rem 0;
}

.bg-used-by {
    list-style: none;
    padding: 0;
}

/* Upload */
.bg-upload pre {
    background: var(--bg-layer-3, #f2e6d2);
    border: 1px solid var(--bg-border);
    border-radius: 4px;
    padding: .75rem 1rem;
    overflow-x: auto;
}

.bg-code {
    background: var(--bg-layer-3, #f2e6d2);
    padding: .1rem .35rem;
    border-radius: 3px;
    font-family: Consolas, "Courier New", monospace;
}

/* Theme toggle button in the header */
.bg-theme-toggle {
    margin-left: auto;
}

/* Boot loading screen — shown until the WASM app mounts into #app and
   replaces this markup. Adapted from the default Blazor template. */
.loading-progress {
    position: relative;
    display: block;
    width: 8rem;
    height: 8rem;
    margin: 20vh auto 1rem auto;
}

.loading-progress circle {
    fill: none;
    stroke: var(--bg-border, #e8dbc4);
    stroke-width: 0.6rem;
    transform-origin: 50% 50%;
    transform: rotate(-90deg);
}

.loading-progress circle:last-child {
    stroke: var(--bg-accent, #9b6238);
    stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
    transition: stroke-dasharray 0.05s ease-in-out;
}

.loading-progress-text {
    position: absolute;
    text-align: center;
    font-weight: bold;
    inset: calc(20vh + 3.25rem) 0 auto 0.2rem;
    color: var(--bg-muted, #6e6253);
}

.loading-progress-text:after {
    content: var(--blazor-load-percentage-text, "Loading");
}

/* Unhandled-error banner — hidden until Blazor flips it to display:block on a
   real error. Without this rule the div in index.html is shown permanently. */
#blazor-error-ui {
    color-scheme: light only;
    background: lightyellow;
    color: #1a1a1a;
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    box-sizing: border-box;
    z-index: 1000;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}
