/* The homepage as one scrolling page (html.hn-scroll, set by index.html; desktop only).
   The left column is a real page: the cover (wordmark and reading pane) and then each section in its own
   frame, all scrolling with the window. The plates column does not scroll: on the cover it sits where it
   always does; once the page moves it is pinned under the bar and shows the section being read, with the
   same switch as a click. The bar comes back off the cover, with the small name, the section's name after
   it, the console and the theme button. The footer stays at the foot of the window.
   main keeps the height of one screen and the left column runs on below it, so everything that sizes itself
   from main (the plates' art) is unchanged. */

@media (min-width: 881px) {
    html.hn-flow { overflow-y: auto; --hn-sec-gap: clamp(0.8rem, 2vh, 1.4rem); }
    html.hn-flow body { overflow: visible; }
    /* what's new still scrolls under the pointer, and hands the scroll on to the page at its ends */
    html.hn-flow .changelog-scroll { overscroll-behavior: auto; }
    html.hn-flow main { flex: none; height: calc(100vh - var(--hn-foot-h, 36px)); overflow: visible; }
    html.hn-flow footer { position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; background: var(--bg); }

    /* the left column: the cover, then the sections */
    html.hn-flow main > .hero { align-self: start; height: auto; min-height: 0; }
    html.hn-flow main > .hero > .hero-cols { flex: none; height: var(--hn-cover-h, 70vh); grid-template-columns: minmax(0, 1fr); }
    html.hn-flow body.mode-section .home-welcome { opacity: 1; visibility: visible; }
    html.hn-flow #stage { display: none; }
    html.hn-flow .hn-secs { display: flex; flex-direction: column; gap: var(--hn-sec-gap); padding-top: var(--hn-sec-gap);
        padding-bottom: calc(var(--hn-sec-gap) + var(--hn-foot-h, 36px)); }
    /* each frame is at least a screen tall: a short section (Practice) holds the plates for a while, and
       when it is brought to the top the next frame starts below the window, never across the reading line */
    .hn-sec { position: relative; border: 1px solid var(--line); background: var(--bg);
        min-height: calc(100vh - var(--hn-bar-h, 48px) - var(--hn-foot-h, 36px) - 2 * var(--hn-sec-gap));
        padding: clamp(1rem, 2.4vw, 1.8rem); scroll-margin-top: calc(var(--hn-bar-h, 40px) + var(--hn-sec-gap)); }
    .hn-sec .stage { position: static; inset: auto; display: block; opacity: 1; visibility: visible; transform: none; padding: 0; z-index: auto; }
    .hn-sec .stage-text { overflow: visible; padding-right: 0; }
    html.hn-flow .hn-sec .stage .filters { top: var(--hn-bar-h, 40px); z-index: 2; }
    .hn-sec .hn-more { display: none; }

    /* the plates: where they always are on the cover; pinned under the bar off it */
    html.hn-flow main > .tiles { align-self: start; height: var(--hn-tiles-h, 80vh); }
    html.hn-flow.hn-scrolled main > .tiles { position: fixed; z-index: 20; right: 0; top: var(--hn-bar-h, 40px);
        width: var(--hn-rail-w); height: calc(100vh - var(--hn-bar-h, 40px) - var(--hn-foot-h, 36px)); }

    /* the bar: the small name and the section being read, then the console and the theme button */
    html.hn-flow.hn-scrolled body > header { display: flex; position: fixed; left: 0; right: 0; top: 0; z-index: 40; background: var(--bg);
        animation: hn-bar-in 0.38s cubic-bezier(0.22, 1, 0.36, 1); }
    html.hn-flow.hn-scrolled body > header .id { display: inline; }
    html.hn-flow.hn-scrolled body > header .header-actions { margin-left: 0; }
    html.hn-flow.hn-scrolled body.console-modal .header-actions .console-launch { position: relative; inset: auto; top: auto; right: auto;
        margin: 0; height: 1.45rem; padding: 0 0.62rem; }
    html.hn-flow.hn-scrolled .header-actions .tog { height: 1.45rem; padding: 0 0.62rem; display: inline-flex; align-items: center; }
    html.hn-flow.hn-scrolled body.console-open .console-launch { opacity: 0; pointer-events: none; }
    .hn-crumb { color: var(--muted); }
    .hn-crumb b { color: var(--fg); font-weight: inherit; }

    /* how far down the page is, as a gold rule under the bar */
    .hn-progress { position: absolute; left: 0; bottom: -1px; height: 1px; width: 100%; background: var(--gold);
        transform-origin: 0 0; transform: scaleX(var(--hn-progress, 0)); pointer-events: none; }
}
/* carets that say the page goes on: at the foot of the cover (desktop) and of every section but the last,
   in room of their own; a faint gold glow, a slow bob */
.hn-caret { display: none; position: absolute; z-index: 4; left: 50%; bottom: 0.7rem; width: 2.2rem; height: 2.2rem; padding: 0.35rem;
    transform: translateX(-50%); border: 0; background: none; color: var(--gold); cursor: pointer;
    filter: drop-shadow(0 0 5px color-mix(in srgb, var(--gold) 60%, transparent)) drop-shadow(0 0 12px color-mix(in srgb, var(--gold) 25%, transparent));
    transition: opacity 0.35s ease; }
.light-mode .hn-caret { filter: drop-shadow(0 0 4px color-mix(in srgb, var(--gold) 45%, transparent)); }
.hn-caret svg { display: block; width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round;
    stroke-linejoin: round; animation: hn-caret-bob 1.9s ease-in-out infinite; }
.hn-caret:hover svg, .hn-caret:focus-visible svg { animation-play-state: paused; }
.hn-caret:focus-visible { outline: 1px solid var(--gold); outline-offset: 2px; border-radius: 3px; }
@keyframes hn-caret-bob { 0%, 100% { transform: translateY(0); opacity: 0.72; } 50% { transform: translateY(4px); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .hn-caret svg { animation: none; } }
@media (min-width: 881px) {
    html.hn-flow main > .hero > .hero-cols { position: relative; }
    html.hn-flow .hn-caret-cover { display: block; }
    html.hn-flow.hn-scrolled .hn-caret-cover { opacity: 0; pointer-events: none; }
    html.hn-flow .hn-caret-next { display: block; }
    html.hn-flow .hn-sec:has(> .hn-caret-next) { padding-bottom: calc(clamp(1rem, 2.4vw, 1.8rem) + 2.6rem); }
}
@media (max-width: 880px) {
    html.hn-mflow .hn-caret-next { display: block; bottom: 0.5rem; }
    html.hn-mflow .hn-sec:has(> .hn-caret-next) { padding-bottom: 3.4rem; }
}

/* the written-out sections exist only for the scrolling page (they are built on every width) */
.hn-secs { display: none; }
html:not(.hn-scrolled) .hn-progress { display: none; }

@keyframes hn-bar-in { from { opacity: 0; transform: translateY(-100%); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { html.hn-flow.hn-scrolled body > header { animation: none; } }

/* very wide windows (a large monitor): the page keeps --hn-max and stands in the middle, the plates beside
   the text as always; the bar and the footer line up with it. Narrower windows are filled as before. */
html.hn-scroll { --hn-max: 1800px; --hn-side-pad: max(var(--gutter), calc((100vw - var(--hn-max)) / 2 + var(--gutter))); }
@media (min-width: 1801px) {
    html.hn-scroll main { width: var(--hn-max); margin-left: auto; margin-right: auto; }
    html.hn-scroll body > header, html.hn-scroll footer { padding-left: var(--hn-side-pad); padding-right: var(--hn-side-pad); }
    html.hn-flow.hn-scrolled main > .tiles { right: calc((100vw - var(--hn-max)) / 2); }
}

/* ─── phones (html.hn-mflow): the bar stays at the top; the sections follow the four plates, each at least a
   screen tall and headed by its plate. The plate slides up under the bar and becomes its backdrop: the name,
   the console and theme buttons and the menu float over it on a soft fade, and the plate's own marker
   ("01 Profile") names the section below them. The next section's plate pushes it away. ─── */
@media (max-width: 880px) {
    html.hn-mflow { --hn-mbar-h: 55px; --hn-mplate-h: calc(var(--hn-mbar-h) + 4.5rem); }
    html.hn-mflow body > header { position: sticky; top: 0; z-index: 50; background: var(--bg);
        transition: background-color 0.25s ease, border-color 0.25s ease; }
    html.hn-mflow.hn-mscrolled body > header .id { display: inline; }
    html.hn-mflow .hn-crumb { display: none; }
    /* over a plate: the bar turns clear, and only its words and buttons carry a backing */
    html.hn-mflow.hn-mover body > header { border-bottom-color: transparent; background: transparent; }
    html.hn-mflow.hn-mover body > header .id { padding: 0.18rem 0.55rem; margin-left: -0.55rem; border-radius: 2px;
        background: color-mix(in srgb, var(--bg) 78%, transparent); }
    html.hn-mflow.hn-mover body > header .tog, html.hn-mflow.hn-mover body > header .burger,
    html.hn-mflow.hn-mover body > header .hn-mconsole { background: color-mix(in srgb, var(--bg) 78%, transparent); }
    html.hn-mflow .hn-secs { display: block; }
    html.hn-mflow .hn-sec { position: relative; border-top: 1px solid var(--line); padding: 0 var(--gutter) 2.4rem;
        min-height: 100svh; }
    html.hn-mflow .hn-sec .stage { position: static; inset: auto; display: block; opacity: 1; visibility: visible; transform: none;
        padding: 0; z-index: auto; background: none; border: 0; box-shadow: none; min-height: 0; }
    html.hn-mflow .hn-sec .stage-text { overflow: visible; padding-right: 0; }
    html.hn-mflow .hn-sec .stage-num { display: none; }
    html.hn-mflow .hn-sec .stage-title { margin-top: 0.2rem; }
    html.hn-mflow .hn-sec .stage .filters { top: var(--hn-mplate-h); z-index: 4; }
    html.hn-mflow .hn-sec .hn-more { display: none; }
    .hn-mplate { position: sticky; top: 0; z-index: 6; height: var(--hn-mplate-h); overflow: hidden;
        margin: 0 calc(-1 * var(--gutter)) 1.1rem; background: var(--bg); border-bottom: 1px solid var(--line); }
    .hn-mplate canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
    .hn-mplate-label { position: absolute; left: var(--gutter); bottom: 0.6rem; padding: 0.18rem 0.55rem; border-radius: 2px;
        background: color-mix(in srgb, var(--bg) 78%, transparent); font-family: var(--mono); font-size: 0.74rem;
        letter-spacing: 0.12em; text-transform: uppercase; color: var(--fg); }
    .hn-mplate-label b { color: var(--gold); font-weight: 500; margin-right: 0.35rem; }

    /* the console: a small button beside the theme button; the terminal stays folded until it is asked for */
    html.hn-mflow .console-toggle { display: none; }
    .hn-mconsole { display: inline-flex; align-items: center; justify-content: center; position: relative; height: 28px; padding: 0 0.55rem;
        border: 1px solid var(--line); border-radius: 2px; background: none; color: var(--gold); cursor: pointer;
        font-family: var(--mono); font-size: 0.72rem; letter-spacing: 0.04em; line-height: 1; }
    .hn-mconsole.on { border-color: var(--gold); }
    body.console-unread .hn-mconsole::after { content: ''; position: absolute; top: -3px; right: -3px; width: 6px; height: 6px;
        border-radius: 50%; background: var(--gold); }
}
.hn-mplate, .hn-mconsole { display: none; }
@media (max-width: 880px) { html.hn-mflow .hn-mplate { display: block; } html.hn-mflow .hn-mconsole { display: inline-flex; } }
