.hero {
    --hero-fallback: linear-gradient(180deg, #2a6fc4 0%, #9fcbec 42%, #cfe6f5 52%, #2d8fa0 53%, #0b4f73 66%, #38c6bd 74%, #ead7b0 78%, #e2cba0 100%);
    position: relative;
    isolation: isolate;
    display: flex;
    overflow: hidden;
    height: min(var(--hero-height), 85vh);
    min-height: 240px;
    background: #0b2a44 var(--hero-fallback);
    color: #fff;
}

.hero-canvas {
    position: absolute;
    inset: 0;
    z-index: -2;
    display: block;
    width: 100%;
    height: 100%;
    opacity: 0;
    transition: opacity 1400ms ease;
}

.hero.hero-ready .hero-canvas {
    opacity: 1;
}

.hero::before {
    position: absolute;
    inset: 0;
    z-index: -1;
    background: linear-gradient(90deg, rgb(3 14 28 / 52%) 0%, rgb(3 14 28 / 28%) 38%, rgb(3 14 28 / 0%) 66%);
    content: "";
    pointer-events: none;
}

.hero-full.hero-align-left::before {
    background: linear-gradient(90deg, rgb(3 14 28 / 52%) var(--page-inset), rgb(3 14 28 / 28%) calc(var(--page-inset) + 30rem), rgb(3 14 28 / 0%) calc(var(--page-inset) + 52rem));
}

.hero.hero-align-center::before {
    background: radial-gradient(ellipse 55% 60% at 50% 48%, rgb(3 14 28 / 42%) 0%, rgb(3 14 28 / 0%) 100%);
}

.hero-full::after {
    position: absolute;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: -1;
    height: 72px;
    background: linear-gradient(180deg, transparent, var(--page-background));
    content: "";
    pointer-events: none;
}

/* A full-width hero reaches up behind the header bars; while it is under them, the bars are transparent. */
.hero-full {
    --hero-overlap: calc(var(--site-header-height) + var(--top-navigation-height));
    height: calc(min(var(--hero-height), 85vh) + var(--hero-overlap));
    margin-top: calc(0px - var(--hero-overlap));
}

.top-navigation.is-empty ~ .hero-full {
    --hero-overlap: var(--site-header-height);
}

.hero-full .hero-content {
    padding-top: calc(2.5rem + var(--hero-overlap));
}

:root.is-over-hero:not(:has(.site-layout.sidebar-open)) body::before,
:root.is-over-hero:not(:has(.site-layout.sidebar-open)) .site-header,
:root.is-over-hero:not(:has(.site-layout.sidebar-open)) .top-navigation {
    background: transparent;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    box-shadow: none;
}

:root.is-over-hero:has(.hero-full[data-hero-scene="beach"]):not(:has(.site-layout.sidebar-open)) .site-header,
:root.is-over-hero:has(.hero-full[data-hero-scene="beach"]):not(:has(.site-layout.sidebar-open)) .top-navigation {
    --text-primary: #fff;
    --text-secondary: rgb(255 255 255 / 80%);
    --link: #fff;
    --border: rgb(255 255 255 / 30%);
    --surface-current: rgb(255 255 255 / 12%);
}

/* A soft shade behind both bars keeps their text readable on a light scene. It fades out without an edge, so it
   never reads as a second horizon, and it stays at the top while the hero scrolls under it. It lies below both bars
   (z-index 18 and 20) and above the hero. */
body::after {
    position: fixed;
    top: 0;
    right: 0;
    left: 0;
    z-index: 17;
    height: calc(var(--site-header-height) + var(--top-navigation-height) + 4rem);
    background: linear-gradient(180deg, rgb(3 14 28 / 38%) 0%, rgb(3 14 28 / 22%) 45%, rgb(3 14 28 / 8%) 75%, rgb(3 14 28 / 0%) 100%);
    content: "";
    opacity: 0;
    pointer-events: none;
    transition: opacity 300ms ease;
}

body:has(.top-navigation.is-empty)::after {
    height: calc(var(--site-header-height) + 4rem);
}

:root.is-over-hero:has(.hero-full[data-hero-scene="beach"]):not(:has(.site-layout.sidebar-open)) body::after {
    opacity: 1;
}

/* The hero content fades out right at the lower edge of the bars, so it is never drawn under them. --hero-cut is the
   part of the content that lies under the bars: the bars' height plus how far the hero has scrolled up. */
@property --hero-cut {
    syntax: "<length>";
    inherits: false;
    initial-value: 0px;
}

.hero-full .hero-content {
    -webkit-mask-image: linear-gradient(180deg, transparent var(--hero-cut), #000 calc(var(--hero-cut) + 2.5rem));
    mask-image: linear-gradient(180deg, transparent var(--hero-cut), #000 calc(var(--hero-cut) + 2.5rem));
}

/* A scroll-driven animation moves the cut in the same frame as the scroll; other browsers get it from the scroll script. */
@keyframes hero-cut {
    from {
        --hero-cut: var(--hero-overlap);
    }

    to {
        --hero-cut: calc(min(var(--hero-height), 85vh) + 2 * var(--hero-overlap));
    }
}

/* The timeline follows the hero in the page; the content's own view() would follow the hero, which clips its overflow. */
@supports (animation-timeline: view()) {
    .hero-full {
        view-timeline-name: --hero-view;
    }

    .hero-full .hero-content {
        animation: hero-cut linear both;
        animation-timeline: --hero-view;
        animation-range: exit-crossing 0% exit-crossing 100%;
    }
}

.site-header {
    transition: box-shadow 160ms ease, background-color 300ms ease;
}

.top-navigation {
    transition: transform 220ms cubic-bezier(0.2, 0.7, 0.2, 1), box-shadow 160ms ease, background-color 300ms ease;
}

/* Only a beach under the transparent header needs the light-on-dark logo outside the normal theme. */
:root.is-over-hero:has(.hero-full[data-hero-scene="beach"]):not(:has(.site-layout.sidebar-open)) .site-brand-logo-light {
    filter: opacity(0);
}

:root.is-over-hero:has(.hero-full[data-hero-scene="beach"]):not(:has(.site-layout.sidebar-open)) .site-brand-logo-dark {
    filter: none;
}

/* While the bars switch between transparent and solid, their text, icons, borders, and logo fade together with the
   background. Otherwise the colors would switch at once and show dark text on the scene or light text on a half
   solid bar. Hover transitions keep their own timing at other times. */
:root.is-hero-switching .site-header *,
:root.is-hero-switching .top-navigation * {
    transition: color 300ms ease, background-color 300ms ease, border-color 300ms ease, filter 300ms ease, opacity 140ms ease, transform 140ms ease, visibility 140ms ease;
}

:root.is-hero-settling body::before,
:root.is-hero-settling .site-header,
:root.is-hero-settling .site-header *,
:root.is-hero-settling .top-navigation,
:root.is-hero-settling .top-navigation *,
:root.is-hero-settling body::after {
    transition: none;
}

.hero-content {
    display: flex;
    flex-direction: column;
    justify-content: center;
    width: min(38rem, 100%);
    padding: 2.5rem clamp(1.25rem, 6vw, 5.5rem) 4rem;
    text-shadow: 0 1px 18px rgb(0 18 40 / 45%);
}

/* A full-width hero lines its text up with the logo of the centered page instead of the window edge. */
.hero-full.hero-align-left .hero-content {
    width: 100%;
    padding-inline: calc(var(--page-inset) + 1.5rem);
}

.hero-full.hero-align-left .hero-content > * {
    max-width: 40rem;
}

.hero-align-center .hero-content {
    align-items: center;
    width: min(46rem, 100%);
    margin: 0 auto;
    text-align: center;
}

.hero .hero-title {
    margin: 0 0 0.85rem;
    font-size: clamp(2.2rem, 4.8vw, 3.75rem);
    font-weight: 700;
    letter-spacing: -0.025em;
    line-height: 1.04;
    text-wrap: balance;
}

.hero .hero-text {
    margin: 0 0 1.75rem;
    font-size: clamp(1.05rem, 1.7vw, 1.3rem);
    line-height: 1.45;
    opacity: 0.94;
    text-wrap: pretty;
}

.hero-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.hero-align-center .hero-actions {
    justify-content: center;
}

.hero .hero-button {
    display: inline-flex;
    align-items: center;
    min-height: 2.6rem;
    padding: 0.5rem 1.3rem;
    border: 1.5px solid rgb(255 255 255 / 72%);
    border-radius: 999px;
    background: rgb(255 255 255 / 10%);
    color: #fff;
    font-size: 0.98rem;
    font-weight: 600;
    text-decoration: none;
    text-shadow: none;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    transition: background-color 160ms ease, border-color 160ms ease, transform 160ms ease;
}

.hero .hero-button:hover {
    border-color: #fff;
    background: rgb(255 255 255 / 22%);
    text-decoration: none;
    transform: translateY(-1px);
}

.hero .hero-button-primary {
    border-color: #fff;
    background: #fff;
    color: #0b2a44;
}

.hero .hero-button-primary:hover {
    background: rgb(255 255 255 / 88%);
}

.hero .hero-button:focus-visible {
    outline: 2px solid var(--link);
    outline-offset: 3px;
}

.hero-inline {
    margin: 0 0 2rem;
    border-radius: 14px;
}

.markdown-content > .hero-inline:first-child {
    margin-top: 0.5rem;
}

:root[data-theme="dark"] .hero {
    --hero-fallback: linear-gradient(180deg, #02050f 0%, #0b1730 40%, #1b2d52 52%, #0f4c5a 53%, #03101f 70%, #2a3a48 76%, #45434f 100%);
}

@media (prefers-color-scheme: dark) {
    :root[data-theme="auto"] .hero {
        --hero-fallback: linear-gradient(180deg, #02050f 0%, #0b1730 40%, #1b2d52 52%, #0f4c5a 53%, #03101f 70%, #2a3a48 76%, #45434f 100%);
    }
}

@media (max-width: 1220px) {
    .hero-full {
        --hero-overlap: var(--site-header-height);
    }

    body::after {
        height: calc(var(--site-header-height) + 4rem);
    }
}

@media (max-width: 760px) {
    .hero::before,
    .hero-full.hero-align-left::before {
        background: linear-gradient(180deg, rgb(3 14 28 / 18%) 0%, rgb(3 14 28 / 48%) 100%);
    }

    .hero-content {
        justify-content: flex-end;
        padding-bottom: 3.5rem;
    }
}

    .hero:not([data-hero-scene="beach"]) {
        background: var(--page-background);
        color: var(--text-primary);
    }

    .hero:not([data-hero-scene="beach"])::before {
        background: linear-gradient(90deg, var(--page-background), color-mix(in srgb, var(--page-background) 85%, transparent) 35%, transparent);
    }

    .hero.hero-align-center:not([data-hero-scene="beach"])::before {
        background: radial-gradient(ellipse at center, var(--page-background), transparent 85%);
    }

    .hero:not([data-hero-scene="beach"]) .hero-content {
        text-shadow: none;
    }

    .hero:not([data-hero-scene="beach"]) .hero-button {
        border-color: var(--border);
        background: var(--page-background);
        color: var(--text-primary);
    }

    .hero:not([data-hero-scene="beach"]) .hero-button:hover {
        border-color: var(--link);
        background: var(--surface-current);
    }

    .hero:not([data-hero-scene="beach"]) .hero-button-primary {
        border-color: var(--text-primary);
        background: var(--text-primary);
        color: var(--page-background);
    }

    .hero:not([data-hero-scene="beach"]) .hero-button-primary:hover {
        border-color: var(--text-primary);
        background: color-mix(in srgb, var(--text-primary) 90%, var(--page-background));
        color: var(--page-background);
    }

    .hero[data-hero-scene="beach"] {
        --link: #fff;
    }

    .hero-error {
        max-height: 7rem;
        overflow: auto;
        margin: 0 0 1rem;
        padding: 0.6rem 0.8rem;
        border-radius: 6px;
        background: var(--page-background);
        color: var(--text-primary);
        font: 0.8rem/1.4 ui-monospace, monospace;
        white-space: pre-wrap;
    }

    .hero-full + .hero-error {
        width: min(60rem, calc(100% - 2rem));
        margin: 1rem auto;
    }

    .hero-error[hidden],
    .hero-playground [hidden],
    .hero-playground-return[hidden] {
        display: none;
    }

    .hero-playground {
        display: grid;
        gap: 1rem;
        min-width: 0;
        margin: 0 0 2rem;
        padding: 1.25rem;
        border: 1px solid var(--border);
        border-radius: 14px;
        background: var(--surface-current);
        color: var(--text-primary);
    }

    .hero-playground-preview {
        scroll-margin-top: calc(var(--site-header-height) + var(--top-navigation-height) + 1rem);
    }

    .hero-playground-toolbar {
        position: sticky;
        top: calc(var(--site-header-height) + var(--top-navigation-height) + 0.5rem);
        z-index: 5;
        display: flex;
        flex-wrap: wrap;
        gap: 0.75rem;
        align-items: center;
        justify-content: space-between;
        padding-block: 0.5rem;
        background: var(--surface-current);
    }

    .hero-full + .hero-playground {
        width: min(60rem, calc(100% - 2rem));
        margin: 1.5rem auto;
    }

    .hero-playground fieldset {
        min-width: 0;
        margin: 0;
        padding: 0;
        border: 0;
    }

    .hero-playground legend {
        margin-bottom: 0.75rem;
        font-weight: 600;
    }

    .hero-controls {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(min(100%, 9rem), 1fr));
        gap: 1rem;
        align-items: start;
    }

    .hero-content-controls {
        margin-bottom: 1rem;
        grid-template-columns: repeat(auto-fit, minmax(min(100%, 16rem), 1fr));
    }

    .hero-color-controls {
        align-items: end;
        grid-template-columns: auto auto;
        justify-content: start;
    }

    .hero-playground label {
        display: grid;
        gap: 0.35rem;
        min-width: 0;
        font-size: 0.9rem;
    }

    .hero-playground :is(button, select, textarea, input),
    .hero-playground-return {
        box-sizing: border-box;
        min-width: 0;
        max-width: 100%;
        min-height: 2.5rem;
        border: 1px solid var(--border);
        border-radius: 6px;
        background: var(--page-background);
        color: var(--text-primary);
        font: inherit;
    }

    .hero-playground :is(button, select),
    .hero-playground-return {
        padding: 0.45rem 0.75rem;
        cursor: pointer;
    }

    .hero-playground button:hover,
    .hero-playground-return:hover {
        border-color: var(--link);
    }

    .hero-playground button:disabled {
        opacity: 0.55;
        cursor: not-allowed;
    }

    .hero-playground :is(button, select, textarea, input, summary):focus-visible,
    .hero-playground-return:focus-visible {
        outline: 2px solid var(--link);
        outline-offset: 3px;
    }

    .hero-playground textarea {
        width: 100%;
        padding: 0.75rem;
        font: 0.8rem/1.5 ui-monospace, monospace;
        resize: vertical;
        tab-size: 2;
    }

    .hero-playground input[type="range"] {
        width: 100%;
        accent-color: var(--link);
    }

    .hero-playground input[type="text"] {
        width: 100%;
        padding: 0.45rem 0.75rem;
    }

    .hero-playground select {
        width: 100%;
    }

    .hero-playground button.hero-copy {
        border-color: var(--text-primary);
        background: var(--text-primary);
        color: var(--page-background);
    }

    .hero-playground-return {
        position: absolute;
        right: 1rem;
        bottom: 1rem;
        z-index: 2;
    }

    .hero-control-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
        align-items: center;
    }

    .hero-playground-status:empty {
        display: none;
    }

    .hero-playground p {
        margin: 0;
        font-size: 0.85rem;
    }

    .hero-playground details {
        margin: 0;
        border: 0;
        border-radius: 0;
        background: none;
    }

    .hero-playground details > summary {
        display: list-item;
        min-height: 2rem;
        padding: 0.2rem 0;
        border-radius: 6px;
        list-style: disclosure-closed inside;
        cursor: pointer;
        font-weight: 600;
    }

    .hero-playground details[open] > summary {
        border-bottom: 0;
        border-radius: 6px;
        list-style-type: disclosure-open;
    }

    .hero-playground details > summary::-webkit-details-marker {
        display: initial;
    }

    .hero-playground details > summary::after {
        content: none;
    }

    .hero-playground details > summary:focus-visible {
        outline: 2px solid var(--link);
        outline-offset: 3px;
    }

    .hero-playground details > :not(summary) {
        margin-inline: 0;
    }

    .hero-playground details > :last-child:not(summary) {
        margin-bottom: 0;
    }

    .hero-playground details[open] > :not(summary) {
        margin-top: 0.75rem;
    }

    .hero-playground :is(input, select, textarea, summary) {
        scroll-margin-top: calc(var(--site-header-height) + var(--top-navigation-height) + 8rem);
    }

    @media (max-width: 480px) {
        .hero-playground {
            padding: 0.75rem;
        }

        .hero-playground .hero-control-actions {
            gap: 0.35rem;
        }

        .hero-playground-toolbar button {
            padding-inline: 0.5rem;
            font-size: 0.85rem;
        }
    }

    @media (prefers-reduced-motion: reduce) {
        .hero-canvas,
        .hero .hero-button {
            transition: none;
        }

        .hero .hero-button:hover {
            transform: none;
        }
    }

    @media print {
        .hero,
        .hero-playground {
            display: none;
        }
    }
