/* ==========================================================================
   PAGE · MEDLAB (medlab.html) — every rule scoped under .page-medlab
   The live app is sacred: everything here sits OUTSIDE the iframe, no rAF,
   no fx layers, no backdrop-filter. The only motion near the stage is the
   one-shot depth scan (CSS) and the engaged light (a CSS transition on focus).
     1. Stage & bar — edges, wordmark, input monitor, folded phones, no-JS
     2. Film furniture — grey map, depth scale and calipers around the frame
     3. Engaged — the furniture lights while the app has the keyboard
     4. Side panels — Controls strip (below aspect 2.1) · [datasheet | app | controls] (above)
     5. After the app — spec list + plate
     6. Limits — heading with figures, ruled list, note
     7. Next
   ========================================================================== */

@property --ml-p {
    syntax: '<number>';
    inherits: true;
    initial-value: 1.4;
}

@property --ml-hot {
    syntax: '<number>';
    inherits: true;
    initial-value: 0;
}

.page-medlab {
    --caliper-rgb: 255, 216, 74;   /* = --accent-2: the films' yellow caliper marks; marks only, never text */
}


/* ---------- 1. Stage & bar -----------------------------------------------------
   Below aspect 2.1 the stage shares the content column's edges (--wrap), so the
   title, the screen, the Controls strip, the sections and the footer all start
   on one line; above it the console sets the edges (section 4). */

.page-medlab .stage {
    --rail-w: clamp(7px, .55rem, 12px);       /* the depth scale's width */
    --rail-gap: clamp(5px, .45rem, 10px);     /* between the frame and its furniture */
    --cal: 11px;                              /* a caliper mark */
    padding-inline: max(var(--gutter), (100% - var(--wrap-max)) / 2);
}

.page-medlab .stage-bar {
    column-gap: var(--space-m);
}

/* the eyebrow breaks between its halves, never inside one */
.page-medlab .stage-bar .eyebrow > span {
    white-space: nowrap;
}

/* the arrow sits apart from the label (the link is an inline-flex row) */
.page-medlab .stage-skip {
    gap: .55em;
}

/* The wordmark: MedLab in Anybody, its "Lab" lit. Sized to stand where ID Engine's logo stands. */
.page-medlab .ml-wordmark {
    font-family: var(--font-display);
    font-size: clamp(1.5rem, 1.05rem + 1.7vmin, 2.75rem);
    font-weight: 300;
    font-stretch: 112%;
    line-height: .9;
    letter-spacing: -.015em;
    color: var(--plasma);
}

.page-medlab .ml-wordmark span {
    color: var(--accent);
}

/* Input monitor: an aria-hidden echo of the Controls legend, in the bar wherever the legend
   isn't already beside the app: compact from 73rem (56rem in landscape, below), labelled
   from 78rem. */
.page-medlab .ml-monitor {
    display: none;
    align-items: center;
    gap: .25rem;
    margin-inline: auto;
    padding: .4rem .5rem;
    border-radius: var(--r-sm);
    box-shadow: inset 0 0 0 1px var(--line);
    background: linear-gradient(180deg, rgba(var(--accent-rgb), .045), rgba(var(--accent-rgb), .01));
}

.page-medlab .ml-monitor-label {
    display: none;
    margin-right: .45rem;
    font-family: var(--font-mono);
    font-size: .625rem;
    font-weight: 500;
    letter-spacing: .2em;
    text-transform: uppercase;
    color: var(--text-3);
}

.page-medlab .ml-monitor-keys {
    display: inline-flex;
    gap: 3px;
    margin-inline: .25rem;
}

.page-medlab .ml-monitor kbd {
    min-width: 2em;
    height: 2em;
    padding: 0 .45em;
    font-size: .6875rem;
}

.page-medlab .ml-monitor .key--space { min-width: 4.25em; margin-left: .25rem; }
.page-medlab .ml-monitor .key--wide { min-width: 3.1em; }

.page-medlab .ml-monitor .key-mouse {
    width: 1rem;
    height: 1.5rem;
    border-radius: .55rem;
}

.page-medlab .ml-monitor .key-mouse::after {
    top: 18%;
    width: 2px;
    height: 5px;
    margin-left: -1px;
}

@container (min-width: 73rem) {
    .page-medlab .ml-monitor {
        display: inline-flex;
    }
}

/* 56–73rem (1000–1280px windows, landscape tablets): the Controls strip is below the fold,
   so the monitor is the only key feedback in view. It takes the skip link's room: the link
   becomes visible on focus (in its own place, the monitor stepping aside meanwhile) and
   "Open in new tab" reads "New tab". Not in portrait, where the strip shows under the stage. */
@media not (max-aspect-ratio: 4/5) {
    @container (56rem <= width < 73rem) {
        .page-medlab .ml-monitor {
            display: inline-flex;
        }

        .page-medlab .stage-bar:has(.stage-skip:focus) .ml-monitor {
            display: none;
        }

        .page-medlab :is(.stage-skip:not(:focus), .ml-label-long) {
            position: absolute;
            width: 1px;
            height: 1px;
            overflow: hidden;
            clip-path: inset(50%);
            white-space: nowrap;
        }

        .page-medlab .ml-label-key {
            display: inline-block;
        }

        .page-medlab .ml-label-key::first-letter {
            text-transform: uppercase;
        }
    }
}

@container (min-width: 78rem) {
    .page-medlab .ml-monitor {
        gap: .3rem;
        padding-inline: .8rem .55rem;
    }

    .page-medlab .ml-monitor-label {
        display: inline;
    }

    .page-medlab .ml-monitor .key--space { min-width: 5.5em; margin-left: .35rem; }
    .page-medlab .ml-monitor-keys { margin-inline: .35rem; }
}

/* Folded and small phones: title + LIVE on one line, both buttons on the next,
   "Open in new tab" shortened to "New tab" (its full name stays for screen readers) */
@media (max-width: 24rem) {
    .page-medlab .stage-bar {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: center;
        gap: .35rem .75rem;
    }

    .page-medlab :is(.stage-id, .stage-meta) {
        display: contents;
    }

    .page-medlab .stage-bar .eyebrow {
        grid-column: 1 / -1;
        letter-spacing: .14em;
    }

    .page-medlab .stage-title { grid-column: 1; }
    .page-medlab .live-status { grid-column: 2; grid-row: 2; }

    .page-medlab .stage-actions {
        grid-column: 1 / -1;
        flex-wrap: nowrap;
        margin-top: .5rem;
    }

    .page-medlab .stage-actions .btn {
        flex: 1 1 0;
        min-width: 0;
        min-height: 44px;
        padding-inline: .8em;
    }

    .page-medlab .stage-skip {
        grid-column: 1 / -1;
        justify-self: start;
    }

    .page-medlab .ml-label-long {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip-path: inset(50%);
        white-space: nowrap;
    }

    .page-medlab .ml-label-key {
        display: inline-block;
    }

    .page-medlab .ml-label-key::first-letter {
        text-transform: uppercase;
    }
}

/* Without JS nothing runs: no LIVE, no full screen, no key echo. The poster steps in front
   of the inert frame with an honest caption; "Open in new tab" stays as the action. */
html:not(.js) .page-medlab :is(.ml-monitor, [data-fullscreen], .live-status) {
    display: none;
}

html:not(.js) .page-medlab .app-frame {
    visibility: hidden;
}

html:not(.js) .page-medlab .stage-poster {
    z-index: 1;
}

.page-medlab .ml-nojs {
    position: absolute;
    inset: auto 0 0;
    z-index: 2;
    display: grid;
    grid-template-columns: minmax(0, 60ch);
    gap: .4rem;
    max-width: none;
    padding: clamp(2.5rem, 12%, 8rem) clamp(1rem, 4%, 3rem) clamp(1rem, 4%, 2.5rem);
    font-size: clamp(.9375rem, .85rem + .4vmin, 1.25rem);
    line-height: 1.5;
    color: var(--text);
    text-wrap: balance;
    background: linear-gradient(to top, rgba(3, 9, 7, .94), rgba(3, 9, 7, .72) 55%, transparent);
}

.page-medlab .ml-nojs-kicker {
    font-family: var(--font-mono);
    font-size: var(--t-mono);
    letter-spacing: .14em;
    text-transform: uppercase;
    color: var(--accent-text);
}


/* ---------- 2. Film furniture --------------------------------------------------
   Each frame of a printed ultrasound film carries a grey map (the ramp from white
   to black) on its left, a depth scale on its right and yellow caliper marks where
   a measurement was taken. The frame wears them on the outside, never over the
   app. On load a scan line runs down the depth scale once (1.6s), lighting its
   ticks as the beam would go deeper; the grey map fades up beside it and the two
   calipers land when it reaches the bottom. Then everything rests, dim.
   Layers on the scale: element = dim ticks · ::after = lit ticks (section 3) ·
   .ml-depth-run = the scan (lit ticks in a band trailing the front, and the line). */

.page-medlab .stage-screen {
    isolation: isolate;
}

.page-medlab :is(.ml-greymap, .ml-depth, .ml-caliper) {
    position: absolute;
    pointer-events: none;
}

/* depth scale: a baseline beside the frame, a short tick per twentieth of its height and
   a long one per quarter, closed at the bottom */
.page-medlab .ml-depth,
.page-medlab .ml-depth::after,
.page-medlab .ml-depth-run {
    background:
        linear-gradient(var(--tick), var(--tick)) 0 0 / 1px 100% no-repeat,
        linear-gradient(var(--tick), var(--tick)) 0 100% / 100% 1px no-repeat,
        linear-gradient(to bottom, var(--tick) 1px, transparent 1px) 0 0 / 50% calc(100% / 20) repeat-y,
        linear-gradient(to bottom, var(--tick) 1px, transparent 1px) 0 0 / 100% calc(100% / 4) repeat-y;
}

.page-medlab .ml-depth {
    --tick: rgba(var(--accent-rgb), .26);
    top: 0;
    bottom: 0;
    left: calc(100% + var(--rail-gap));
    width: var(--rail-w);
}

.page-medlab .ml-depth::after,
.page-medlab .ml-depth-run {
    content: "";
    position: absolute;
    inset: 0;
}

/* the scan: lit ticks in a band that trails the front by a third of the height */
.page-medlab .ml-depth-run {
    --tick: rgba(var(--accent-rgb), .95);
    -webkit-mask: linear-gradient(to bottom, transparent calc(var(--ml-p) * 100% - 34%), #000 calc(var(--ml-p) * 100%), transparent calc(var(--ml-p) * 100% + 1px));
    mask: linear-gradient(to bottom, transparent calc(var(--ml-p) * 100% - 34%), #000 calc(var(--ml-p) * 100%), transparent calc(var(--ml-p) * 100% + 1px));
}

/* the scan line itself, a little wider than the scale and glowing, at the front */
.page-medlab .ml-depth-run::before {
    content: "";
    position: absolute;
    inset: 0 -4px 0 calc(-1 * var(--rail-gap) + 1px);
    opacity: var(--ml-hot);
    background:
        linear-gradient(to bottom, transparent calc(var(--ml-p) * 100% - 1.5px), var(--plasma) calc(var(--ml-p) * 100% - 1.5px) calc(var(--ml-p) * 100% + .5px), transparent calc(var(--ml-p) * 100% + .5px)),
        linear-gradient(to bottom, transparent calc(var(--ml-p) * 100% - 14px), rgba(var(--accent-rgb), .45) calc(var(--ml-p) * 100%), transparent calc(var(--ml-p) * 100% + 6px));
    filter: drop-shadow(0 0 4px rgba(var(--accent-rgb), .9));
}

/* grey map: level with the frame's upper half, as on the films */
.page-medlab .ml-greymap {
    top: 20%;
    height: 34%;
    right: calc(100% + var(--rail-gap));
    width: max(4px, calc(var(--rail-w) * .55));
    border-radius: 1px;
    background: linear-gradient(to bottom, #F2F7FF, #EEF3EF 4%, #08100D);
    box-shadow: 0 0 0 1px var(--line-strong);
    opacity: .42;
    transition: opacity var(--dur-3) var(--ease-out);
}

/* calipers: the yellow "+" set at each end of a measurement, on two opposite corners */
.page-medlab .ml-caliper {
    --c: rgba(var(--caliper-rgb), .62);
    width: var(--cal);
    height: var(--cal);
    background:
        linear-gradient(var(--c), var(--c)) 50% 0 / 1.5px 100% no-repeat,
        linear-gradient(var(--c), var(--c)) 0 50% / 100% 1.5px no-repeat;
    transition: filter var(--dur-3) var(--ease-out);
}

/* outside the corner, but never past the gutter (12px on folded phones) */
.page-medlab .ml-caliper--a {
    left: calc(-1 * min(var(--cal) + var(--rail-gap) * .5, var(--gutter) - 1px));
    top: calc(-1 * (var(--cal) + var(--rail-gap) * .5));
}

.page-medlab .ml-caliper--b {
    right: calc(-1 * min(var(--cal) + var(--rail-gap) * .5, var(--gutter) - 1px));
    bottom: calc(-1 * (var(--cal) + var(--rail-gap) * .5));
}

/* the run: once, shortly after first paint */
:root:not(.motion-off) .page-medlab .ml-depth-run {
    animation: ml-scan 1.6s cubic-bezier(.45, 0, .3, 1) .45s backwards;
}

:root:not(.motion-off) .page-medlab .ml-greymap {
    animation: ml-greymap 1.2s var(--ease-out) .45s backwards;
}

:root:not(.motion-off) .page-medlab .ml-caliper {
    animation: ml-caliper .5s var(--ease-out) 1.85s backwards;
}

:root:not(.motion-off) .page-medlab .ml-caliper--b {
    animation-delay: 1.95s;
}

@keyframes ml-scan {
    0% { --ml-p: 0; --ml-hot: 0; }
    6% { --ml-hot: 1; }
    82% { --ml-hot: 1; }
    100% { --ml-p: 1.4; --ml-hot: 0; }
}

@keyframes ml-greymap {
    from { opacity: 0; clip-path: inset(0 0 100% 0); }
}

@keyframes ml-caliper {
    from { opacity: 0; scale: .2; }
}

/* the scale and the grey map need the gutter beside the frame: tablets and wider */
@media (max-width: 47.99rem) {
    .page-medlab :is(.ml-depth, .ml-greymap) {
        display: none;
    }
}

/* phone landscape: bar (40px) + stage fill the screen exactly; no room for furniture.
   The stage clears the whole header, including the no-JS link row (--header-offset). */
@media (orientation: landscape) and (max-height: 520px) {
    .page-medlab :is(.ml-depth, .ml-greymap, .ml-caliper) {
        display: none;
    }

    .page-medlab .stage {
        padding-top: var(--header-offset);
    }

    .page-medlab .stage-bar {
        column-gap: .75rem;
        padding-bottom: 0;
    }

    .page-medlab .ml-wordmark {
        font-size: 1.375rem;
    }
}


/* ---------- 3. Engaged --------------------------------------------------------
   While the app has the keyboard (or is full screen) the frame's ring lights in the
   accent (shared stage rule), the whole depth scale lights, the grey map comes up
   and the calipers glow. .is-engaged comes from the shared script: Chromium doesn't
   match :focus-within once focus is inside the iframe's own document. */

.page-medlab .ml-depth::after {
    --tick: rgba(var(--accent-rgb), .8);
    opacity: 0;
    transition: opacity var(--dur-3) var(--ease-out);
}

.page-medlab .stage-screen:is(:focus-within, .is-engaged) .ml-depth::after,
.page-medlab .stage-screen:has(.app-frame:fullscreen) .ml-depth::after {
    opacity: 1;
}

.page-medlab .stage-screen:is(:focus-within, .is-engaged) .ml-greymap,
.page-medlab .stage-screen:has(.app-frame:fullscreen) .ml-greymap {
    opacity: .85;
}

.page-medlab .stage-screen:is(:focus-within, .is-engaged) .ml-caliper,
.page-medlab .stage-screen:has(.app-frame:fullscreen) .ml-caliper {
    --c: rgb(var(--caliper-rgb));
    filter: drop-shadow(0 0 4px rgba(var(--caliper-rgb), .85));
}

/* a soft echo-green bloom around the frame while engaged, behind the opaque frame */
.page-medlab .stage-screen::before {
    content: "";
    position: absolute;
    inset: -1px;
    z-index: -1;
    border-radius: calc(var(--r-sm) + 1px);
    pointer-events: none;
    opacity: 0;
    box-shadow:
        0 -14px 80px -24px rgba(var(--accent-rgb), .5),
        0 26px 110px -30px rgba(var(--accent-rgb), .4);
    transition: opacity var(--dur-3) var(--ease-out);
}

.page-medlab .stage-screen:is(:focus-within, .is-engaged)::before,
.page-medlab .stage-screen:has(.app-frame:fullscreen)::before {
    opacity: 1;
}


/* ---------- 4. Side panels ---------------------------------------------------
   Below aspect 2.1 the Controls panel runs as a full-width console strip under
   the stage and the datasheet steps aside (the spec list below tells the same
   story). Above 2.1 both flank the app, as tall as the stage. */

.page-medlab .ml-side--datasheet {
    display: none;
}

@media (min-width: 768px) {
    .page-medlab .stage {
        grid-template-areas: "bar bar" "screen screen" "end end";
    }
}

.page-medlab .ml-side-title {
    font-size: clamp(1.25rem, 1rem + 1vmin, 1.75rem);
    font-weight: 400;
}

.page-medlab .ml-controls-head {
    display: grid;
    gap: .35rem;
}

.page-medlab .ml-hint {
    max-width: 46ch;
    font-size: var(--t-small);
    line-height: 1.6;
    color: var(--text-2);
}

.page-medlab .ml-hint kbd {
    font-size: .6875rem;
    height: 1.9em;
    min-width: 1.9em;
    margin-inline: .15em;
}

/* which mouse button: the left half lit for Rotate, the right half for Pan */
.page-medlab :is(.ml-mouse-left, .ml-mouse-right) {
    --btn-tint: rgba(var(--accent-rgb), .24);
    background:
        linear-gradient(var(--line-strong), var(--line-strong)) 50% 0 / 1px 42% no-repeat,
        linear-gradient(var(--line-strong), var(--line-strong)) 0 42% / 100% 1px no-repeat,
        linear-gradient(var(--btn-tint), var(--btn-tint)) var(--btn-x, 0) 0 / 50% 42% no-repeat,
        linear-gradient(to bottom, rgba(255, 255, 255, .06), transparent 60%),
        var(--laminate);
}

.page-medlab .ml-mouse-right {
    --btn-x: 100%;
}

/* console strip (default, below aspect 2.1): a ruled panel under the screen */
.page-medlab .ml-side--controls {
    margin-top: var(--space-m);
    padding-block: var(--space-l);
    border-block: 1px solid var(--line);
}

.page-medlab .ml-controls {
    display: grid;
    grid-template-areas: "head" "legend" "hint";
    gap: var(--space-m) var(--space-l);
    align-items: center;
}

.page-medlab .ml-controls-head { grid-area: head; }
.page-medlab .ml-legend { grid-area: legend; }
.page-medlab .ml-hint { grid-area: hint; }

.page-medlab .ml-legend {
    gap: var(--space-m) clamp(1.25rem, 3cqi, 2.75rem);
}

/* phones: the eight key groups form a tidy matrix — 4 × 2, or 2 × 4 on the narrowest */
@container (width < 46rem) {
    .page-medlab .ml-legend {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        align-items: end;
        gap: var(--space-l) var(--space-s);
    }

    .page-medlab .ml-legend .key--space {
        min-width: 5.5em;
    }
}

@container (24rem <= width < 46rem) {
    .page-medlab .ml-legend {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}

/* tablet-wide strip: title and hint side by side, the keys spread across below */
@container (min-width: 46rem) {
    .page-medlab .ml-controls {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        grid-template-areas: "head hint" "legend legend";
        gap: var(--space-l);
    }

    .page-medlab .ml-hint {
        justify-self: end;
    }

    .page-medlab .ml-legend {
        justify-content: space-between;
    }
}

/* desktop strip: one line — title | keys | hint */
@container (min-width: 84rem) {
    .page-medlab .ml-controls {
        grid-template-columns: minmax(9rem, auto) minmax(0, 1fr) minmax(14rem, 24rem);
        grid-template-areas: "head legend hint";
    }

    .page-medlab .ml-hint {
        justify-self: start;
    }

    .page-medlab .ml-legend {
        justify-content: center;
    }
}

/* Above aspect 2.1: [datasheet | app | controls] as one console. The app takes up to
   2.4 × its height first; the sides get at least 17–24rem (more on taller ultrawides)
   and at most 33.5rem (the pinout stays one column); on 32:9 the console centres and
   the bar spans exactly its three columns. The panels are size containers: rows spread
   over the full height of the column and the type follows its height (cqh). */
@media (min-aspect-ratio: 21/10) and (min-height: 520.02px) {
    .page-medlab .stage {
        --ml-side: clamp(clamp(17rem, 12vw, 24rem), (100% - var(--stage-h) * 2.4 - 2 * var(--stage-gap)) / 2, 33.5rem);
        grid-template-columns: var(--ml-side) minmax(0, calc(var(--stage-h) * 2.4)) var(--ml-side);
        grid-template-areas: "bar bar bar" "start screen end";
        justify-content: center;
        padding-inline: var(--gutter);
    }

    .page-medlab .ml-monitor {
        display: none;
    }

    /* the calipers sit in the middle of the gap between the frame and the panels */
    .page-medlab .ml-caliper--a {
        left: calc(-1 * (var(--stage-gap) + var(--cal)) / 2);
    }

    .page-medlab .ml-caliper--b {
        right: calc(-1 * (var(--stage-gap) + var(--cal)) / 2);
    }

    .page-medlab .ml-side {
        --ml-gap: clamp(.5rem, 2cqh, 1.5rem);   /* cqh: resolved in the children, against this column */
        display: flex;
        flex-direction: column;
        gap: var(--space-m);
        height: var(--stage-h);
        margin: 0;
        padding: .25rem 0 0;
        border: 0;
        container-type: size;
    }

    .page-medlab .ml-side-title {
        font-size: clamp(1.25rem, .55rem + 1.5cqh, 2.25rem);
    }

    .page-medlab .ml-side > * {
        gap: var(--ml-gap);
    }

    .page-medlab .ml-side-foot {
        margin-top: auto;
        padding-top: var(--ml-gap);
        border-top: 1px solid var(--line);
    }

    .page-medlab .ml-side-foot .chip {
        white-space: normal;
        border-radius: var(--r-xs);
        line-height: 1.5;
    }

    /* datasheet: a tall package, its seven pins spread down the column */
    .page-medlab .ml-side--datasheet .datasheet {
        display: flex;
        flex: 1 1 auto;
        flex-direction: column;
        min-height: 0;
    }

    .page-medlab .ml-side--datasheet .datasheet-head {
        gap: .35rem;
        margin-bottom: 0;
    }

    .page-medlab .ml-side--datasheet .pinout {
        flex: 1 1 auto;
        grid-template-rows: repeat(7, auto);
    }

    .page-medlab .ml-side--datasheet .pinout::before {
        grid-row: 1 / -1;
    }

    .page-medlab .ml-side--datasheet .pin {
        padding-block: .3rem;
    }

    .page-medlab .ml-side--datasheet .pin-name {
        font-size: clamp(.875rem, .35rem + 1.2cqh, 1.25rem);
    }

    .page-medlab .ml-side--datasheet .pin-num {
        font-size: clamp(var(--t-mono), .3rem + .45cqh, .8125rem);
    }

    /* controls: the legend becomes a ruled list — caption left, caps right — whose rows
       share the column's height down to the hint */
    .page-medlab .ml-controls {
        display: flex;
        flex: 1 1 auto;
        flex-direction: column;
        align-items: stretch;
        min-height: 0;
    }

    .page-medlab .ml-legend {
        flex: 1 1 auto;
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: repeat(8, auto);
        justify-content: normal;
        align-items: stretch;
        gap: 0;
        border-top: 1px solid var(--line);
    }

    .page-medlab .ml-legend .key-group {
        grid-template-columns: minmax(0, 1fr) auto;
        align-content: center;
        align-items: center;
        justify-items: end;
        gap: 1rem;
        padding-block: .15rem;
        border-bottom: 1px solid var(--line);
    }

    .page-medlab .ml-legend .key-group:last-child {
        border-bottom: 0;
    }

    .page-medlab .ml-legend .key-caption {
        order: -1;
        justify-self: start;
        font-size: clamp(.72rem, .25rem + .8cqh, .9375rem);
    }

    .page-medlab .ml-legend kbd {
        font-size: clamp(.8125rem, .3rem + 1.2cqh, 1.2rem);
    }

    .page-medlab .ml-legend .key-mouse {
        width: clamp(1.6rem, .85rem + 1.4cqh, 2.3rem);
        height: clamp(2.35rem, 1.2rem + 2.1cqh, 3.4rem);
        border-radius: 999px;
    }

    .page-medlab .ml-legend .key--space {
        min-width: 7em;
    }

    .page-medlab .ml-hint {
        max-width: none;
        font-size: clamp(.8125rem, .5rem + .6cqh, 1.0625rem);
        line-height: 1.55;
    }

    /* the sections below share the console's outer edges: its width (= the bar's) is published
       on <main> by js/page-medlab.js; without JS, the console's usual gutter-to-gutter width */
    .page-medlab :is(.ml-after, .ml-limits) > .wrap {
        width: var(--ml-console, calc(100% - 2 * var(--gutter)));
    }
}

/* super-ultrawide (32:9): the centred console lights the wall around it — a static, faint
   spill of echo green that fades out into the margins, so they read as room, not dead bands */
@media (min-aspect-ratio: 3/1) and (min-height: 520.02px) {
    .page-medlab .stage {
        position: relative;
        isolation: isolate;
    }

    .page-medlab .stage::before {
        content: "";
        position: absolute;
        inset: 0;
        z-index: -1;
        pointer-events: none;
        background: radial-gradient(ellipse 58% 80% at 50% 58%, rgba(var(--accent-rgb), .06), transparent 72%);
    }
}


/* ---------- 5. After the app: spec list + plate ---------------------------- */

.page-medlab .ml-after {
    isolation: isolate;
    padding-bottom: calc(var(--section) * .5);
}

/* a pool of echo green behind the heading (static; fades out before every edge) */
.page-medlab .ml-after::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    background: radial-gradient(ellipse min(70rem, 70%) min(40rem, 45%) at 22% 30%, rgba(var(--accent-rgb), .06), transparent 70%);
}

/* heading · plate · spec list. Narrow: one column, the plate between the lede and the list.
   From 64rem: the plate rides beside the heading and the list (sticky). From 160rem (the
   21:9 / 32:9 console width): three columns side by side, all in one view. */
.page-medlab .ml-specs {
    display: grid;
    grid-template-areas: "head" "plate" "list";
    gap: var(--space-xl) clamp(2rem, 5cqi, 6rem);
    align-items: start;
}

.page-medlab .ml-specs > * {
    min-width: 0;
}

.page-medlab .ml-specs-head { grid-area: head; margin-bottom: 0; }
.page-medlab .ml-plate { grid-area: plate; }
.page-medlab .ml-spec-list { grid-area: list; }

/* fills its column, but never taller than the screen can show */
.page-medlab .ml-plate {
    --plate-ratio: 16 / 9;
    --plate-focus: 62% 50%;
    width: auto;
    max-width: min(100%, (100svh - var(--header-offset) - 6rem) * 16 / 9);
}

/* phones on their side: the plate (capped by the short screen) sits beside the heading,
   the list runs full width below */
@media (max-height: 600px) {
    @container (36rem <= width < 64rem) {
        .page-medlab .ml-specs {
            grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr);
            grid-template-areas: "head plate" "list list";
        }
    }
}

@container (min-width: 64rem) {
    .page-medlab .ml-specs {
        grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr);
        grid-template-areas: "head plate" "list plate";
        row-gap: clamp(2rem, 1.5rem + 3vmin, 5rem);
    }

    .page-medlab .ml-plate {
        position: sticky;
        top: calc(var(--header-offset) + var(--space-l));
    }
}

@container (min-width: 160rem) {
    .page-medlab .ml-specs {
        grid-template-columns: minmax(0, .8fr) minmax(0, 66rem) minmax(0, 1.2fr);
        grid-template-areas: "head list plate";
    }
}


/* ---------- 6. Limits ----------------------------------------------------------
   What the films can't tell: the heading and its three figures, then a ruled list
   whose marks are caliper crosses, then the note. Side by side from 64rem. */

.page-medlab .ml-limits {
    padding-top: 0;
}

.page-medlab .ml-limits-grid {
    display: grid;
    gap: var(--space-xl) clamp(2rem, 5cqi, 6rem);
    align-items: start;
    padding-top: calc(var(--section) * .6);
    border-top: 1px solid var(--line);
}

.page-medlab .ml-limits-head {
    margin-bottom: 0;
}

.page-medlab .ml-stats {
    grid-template-columns: repeat(3, minmax(0, max-content));
    gap: var(--space-l) clamp(1.75rem, 6cqi, 3.5rem);
    margin-top: var(--space-m);
}

@container (min-width: 64rem) {
    .page-medlab .ml-limits-grid {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr);
    }
}

.page-medlab .ml-limit-list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.page-medlab .ml-limit-list > li {
    display: grid;
    grid-template-columns: 1.25rem minmax(0, 1fr);
    gap: 1rem;
    align-items: start;
    padding-block: 1.1rem;
    border-top: 1px solid var(--line);
}

.page-medlab .ml-limit-list > li:last-child {
    border-bottom: 1px solid var(--line);
}

.page-medlab .ml-limit-list p {
    color: var(--text-2);
}

.page-medlab .ml-limit-mark {
    --c: rgba(var(--caliper-rgb), .75);
    width: var(--cal, 11px);
    height: var(--cal, 11px);
    margin-top: .4em;
    background:
        linear-gradient(var(--c), var(--c)) 50% 0 / 1.5px 100% no-repeat,
        linear-gradient(var(--c), var(--c)) 0 50% / 100% 1.5px no-repeat;
}

.page-medlab .ml-note {
    margin-top: var(--space-xl);
}


/* ---------- 7. Next ----------------------------------------------------------- */

.page-medlab .ml-next {
    display: flex;
    margin-top: var(--section);
    padding-top: var(--space-l);
    border-top: 1px solid var(--line);
}

@media (min-width: 768px) {
    .page-medlab .ml-next {
        justify-content: flex-end;
    }
}


/* ---------- Modes ----------------------------------------------------------- */

@media (forced-colors: active) {
    .page-medlab .ml-depth-run,
    .page-medlab .stage-screen::before,
    .page-medlab .ml-after::before,
    .page-medlab .stage::before {
        display: none;
    }

    .page-medlab .ml-depth,
    .page-medlab .ml-depth::after {
        --tick: CanvasText;
    }

    .page-medlab :is(.ml-caliper, .ml-limit-mark) {
        --c: CanvasText;
        filter: none;
    }

    .page-medlab .ml-greymap {
        forced-color-adjust: none;
    }

    .page-medlab .ml-wordmark span {
        color: inherit;
    }

    .page-medlab .stage-screen:is(:focus-within, .is-engaged) .stage-frame {
        outline: 2px solid Highlight;
    }

    /* keycaps are drawn with box-shadows, which forced colours remove */
    .page-medlab :is(kbd, .key-mouse) {
        border: 1px solid CanvasText;
    }

    .page-medlab .ml-nojs {
        background: Canvas;
    }
}

@media (prefers-contrast: more) {
    .page-medlab .stage-screen::before,
    .page-medlab .ml-after::before {
        display: none;
    }

    .page-medlab .ml-depth {
        --tick: rgba(var(--accent-rgb), .5);
    }
}
