/* Model-page "Gallery" section (includes/model-gallery.php): build photos
   grouped by van — model + chassis header per group (each header collapses /
   reopens its grid), a van-selector dropdown in the head toolbar, and tiles
   that launch the shared fullscreen viewer
   (service-detail-gallery.css / .js) — plus the model-page flavor of that
   viewer (immersive near-black backdrop, no thumb strip, "current / total"
   counter; see the --models section below). The section title reuses
   .models-intro__heading from models-bg.css, so its rod dividers match the
   "Choose Your Build" heading exactly. */

/* On :root (not .s-model-gallery) because the fullscreen viewer is re-parented
   to <body> on init and still needs the token. */
:root {
    --mg-tile-radius: 22px; /* matches .model-gallery__group's shell radius */
}

.s-model-gallery {
    max-width: 90rem; /* match .s-compare so both headings' rods span alike */
    margin: 0 auto;
    padding: 0 1.25rem 4.5rem;

    /* Local dark palette — same recipe as the compare table's shell. */
    --mg-panel: #0e0f11;
    --mg-tile: #0a0b0d;
    --mg-line: rgba(255, 255, 255, 0.09);
    --mg-line-soft: rgba(255, 255, 255, 0.05);
    --mg-text: rgba(255, 255, 255, 0.85);
    --mg-text-dim: rgba(255, 255, 255, 0.6);

    /* Steel accent — the section's only accent color (deliberately not the
       brand red), shared by the chassis label, chip surfaces, and icon. */
    --mg-accent: #9db2c7;
    --mg-chip-line: rgba(157, 178, 199, 0.28);
    --mg-chip-bg: rgba(157, 178, 199, 0.1);
}

/* Detail pages: the gallery rides inside its own dark band section
   (`$galleryWrap` in model-gallery.php). The band supplies the vertical
   padding — mirroring the nested compare table's treatment — and hugs the
   section above it (the Options list's bottom padding already separates
   them). */
.s-options.dark-bg.s-options--gallery {
    padding-top: 0;
}

.s-options.dark-bg .s-model-gallery {
    padding-top: 0;
    padding-bottom: 0;
}

.model-gallery__head {
    text-align: center; /* keeps the rod-divider heading centered */
    margin-bottom: 1.4rem;
}

/* Toolbar row under the heading: intro copy anchored left, van selector on
   the right — replaces the old centered intro + wrapping pill wall. */
.model-gallery__toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 1rem 2rem;
    margin-top: 1.1rem;
    text-align: left;
}

/* Shared recipe with .compare-intro (models-compare.css) — keep the two in
   sync: fluid size (compact on phones, up to 1rem on wide screens), the
   same 50rem measure, orphan-avoiding wrap. */
.model-gallery__intro {
    flex: 1 1 30rem;
    max-width: min(50rem, 100%);
    margin: 0;
    color: var(--c3);
    line-height: 1.55;
    font-size: clamp(0.84rem, 0.79rem + 0.3vw, 1rem);
    text-wrap: pretty;
}

/* ---- van selector ----
   One compact control however many builds a family has (the pill row
   wrapped into a wall of buttons). Ghost-glass shell on the cta.css tokens;
   the native dropdown list gets a dark surface via the <option> rule. */
.model-gallery__select-wrap {
    position: relative;
    flex: 0 0 auto;
}

.model-gallery__select {
    appearance: none;
    -webkit-appearance: none;
    min-height: var(--tv-cta-height, 2.69rem);
    margin: 0;
    padding: 0.5rem 2.6rem 0.5rem 1.1rem;
    border: 1px solid var(--tv-cta-ghost-border, rgba(255, 255, 255, 0.14));
    border-radius: var(--tv-cta-radius, 30px);
    background: var(--tv-cta-ghost-bg, rgba(255, 255, 255, 0.04));
    box-shadow: var(--tv-cta-ghost-shadow, none);
    color: rgba(255, 255, 255, 0.92);
    font: inherit;
    font-size: 0.92rem;
    font-weight: 500;
    letter-spacing: 0.018em;
    line-height: 1.05;
    cursor: pointer;
    -webkit-backdrop-filter: var(--tv-cta-ghost-blur, none);
    backdrop-filter: var(--tv-cta-ghost-blur, none);
    transition:
        border-color 0.14s ease,
        background 0.14s ease,
        color 0.14s ease;
}

.model-gallery__select:hover {
    border-color: var(--tv-cta-ghost-border-hover, rgba(255, 255, 255, 0.3));
    background: var(--tv-cta-ghost-bg-hover, rgba(255, 255, 255, 0.075));
    color: #fff;
}

.model-gallery__select:focus-visible {
    outline: 2px solid rgba(255, 255, 255, 0.28);
    outline-offset: 3px;
}

/* The UA-rendered dropdown list — keep it legible on the dark theme. */
.model-gallery__select option {
    background: #101218;
    color: #fff;
}

/* Chevron on the shell (the native indicator is reset away above). */
.model-gallery__select-wrap::after {
    content: "";
    position: absolute;
    top: 50%;
    right: 1.15rem;
    width: 0.42rem;
    height: 0.42rem;
    border-right: 2px solid rgba(255, 255, 255, 0.65);
    border-bottom: 2px solid rgba(255, 255, 255, 0.65);
    transform: translateY(-70%) rotate(45deg);
    pointer-events: none;
}

/* ---- one group per van ---- */
.model-gallery__group {
    background: var(--mg-panel);
    border: 1px solid var(--mg-line-soft);
    border-radius: 22px;
    padding: clamp(0.9rem, 1.6vw, 1.4rem);
    margin-top: 1rem;
}

.model-gallery__group[hidden] {
    display: none !important;
}

.model-gallery__group-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem 1rem;
    padding-bottom: 0.85rem;
    border-bottom: 1px solid var(--mg-line-soft);
    margin-bottom: 0.9rem;
}

/* Model label as images — the family wordmark + length badge, the same
   pairing as the lineup cards. The h3's font-size is the em box the marks
   scale from; per-family heights/nudges mirror .option-title-logo--* in
   models-bg.css so the pairing matches the cards above. */
.model-gallery__group-model {
    margin: 0;
    display: flex;
    align-items: center;
    font-size: 1.15rem;
    line-height: 1;
    color: #fff;
}

.model-gallery__group-wordmark,
.model-gallery__group-num {
    display: block;
    width: auto;
    position: relative;
}

.model-gallery__group-wordmark--classic {
    height: 0.75em;
}

.model-gallery__group-wordmark--kronos {
    height: 0.8em;
}

.model-gallery__group-wordmark--ultra {
    height: 1.05em;
    top: 0.1em;
}

.model-gallery__group-wordmark--metis {
    height: 1.05em;
    bottom: 0.1em;
}

.model-gallery__group-num {
    height: 0.8em;
    margin-left: 0.3em;
}

/* Text fallback for groups without a wordmark (e.g. custom builds). */
.model-gallery__group-model--text {
    font-size: 1.02rem;
    font-weight: 600;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

/* Chassis subtext as a tracked micro-label in the steel accent — reads as
   a spec tag under the wordmark rather than a dim sentence. The owner /
   build designation joins it as quiet text ("… · Rausch build" /
   "… · Build 2") so the count chip is the row's only pill. */
.model-gallery__group-chassis {
    margin: 0.4rem 0 0;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.11em;
    text-transform: uppercase;
    color: var(--mg-accent);
}

.model-gallery__group-dot {
    color: rgba(255, 255, 255, 0.75);
    font-weight: 700;
}

.model-gallery__group-designation {
    color: rgba(255, 255, 255, 0.66);
}

.model-gallery__group-flags {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Photo-count chip — the row's only pill: camera icon + bold count on the
   steel glass recipe (the word "photos" lives on sr-only). */
.model-gallery__group-count {
    display: inline-flex;
    align-items: center;
    gap: 0.45em;
    border: 1px solid var(--mg-chip-line);
    border-radius: 2rem;
    background: var(--mg-chip-bg);
    color: var(--mg-text);
    white-space: nowrap;
    padding: 0.34rem 0.85rem;
    font-size: 0.92rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.model-gallery__group-count i {
    font-size: 0.85em;
    color: var(--mg-accent);
}

/* Variant cluster divider (family pages only) — a slim tracked label with
   hairline rules that separates the 144 builds from the 170 builds, etc. */
.model-gallery__cluster {
    display: flex;
    align-items: center;
    gap: 1.1rem;
    margin: 2.4rem 0 0.35rem;
    font-size: 0.74rem;
    font-weight: 700;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--mg-text-dim);
}

.model-gallery__cluster::before,
.model-gallery__cluster::after {
    content: "";
    height: 1px;
    flex: 1;
    background: var(--mg-line-soft);
}

.model-gallery__head + .model-gallery__cluster {
    margin-top: 0.6rem;
}

.model-gallery__cluster[hidden] {
    display: none;
}

/* ---- collapsible groups ----
   The whole group header is the toggle (models-gallery.js adds the button
   role + aria-expanded; a no-JS page just shows every grid open). Collapsing
   animates the body wrapper's row track 1fr→0fr so the grid slides fully
   shut; the chevron mirrors the compare table's category rows. */
.model-gallery__group {
    transition:
        border-color 0.2s ease,
        background-color 0.2s ease;
}

.model-gallery__group-head {
    cursor: pointer;
    user-select: none;
    transition:
        margin-bottom 0.45s cubic-bezier(0.22, 1, 0.36, 1),
        padding-bottom 0.45s cubic-bezier(0.22, 1, 0.36, 1),
        border-color 0.3s ease;
}

.model-gallery__group-head:focus-visible {
    outline: 2px solid rgba(255, 255, 255, 0.35);
    outline-offset: 4px;
    border-radius: 6px;
}

/* Expand / shrink glyph: a plus while collapsed that morphs into a minus
   once the group opens (the vertical bar rotates into the horizontal one).
   Revealed on header hover / focus only on pointer devices — opacity keeps
   its space reserved so nothing shifts. */
.model-gallery__group-toggle {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.1rem;
    height: 1.1rem;
    color: #fff;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.model-gallery__group-toggle::before,
.model-gallery__group-toggle::after {
    content: "";
    position: absolute;
    inset: 0;
    margin: auto;
    border-radius: 1px;
    background: currentColor;
    transition: transform 0.3s ease;
}

/* Horizontal bar — both states. */
.model-gallery__group-toggle::before {
    width: 0.66rem;
    height: 2px;
}

/* Vertical bar — open state lays it onto the horizontal (minus). */
.model-gallery__group-toggle::after {
    width: 2px;
    height: 0.66rem;
    transform: rotate(90deg);
}

.model-gallery__group-head:hover .model-gallery__group-toggle,
.model-gallery__group-head:focus-visible .model-gallery__group-toggle {
    opacity: 1;
}

/* Touch has no hover: the chevron's hover-reveal never fires there, leaving
   collapsed groups with no visible "this expands" cue — keep it dimmed-visible
   (the hover/focus rules above still bring it to full strength). */
@media (hover: none), (max-width: 1024px) {
    .model-gallery__group-toggle { opacity: 0.55; }
}

.model-gallery__group.is-collapsed .model-gallery__group-toggle::after {
    transform: rotate(0deg);     /* collapsed: the upright bar completes the plus */
}

/* Body wrapper: a single-row grid whose track animates shut. min-height: 0
   + overflow: hidden on the child grid let the track actually reach 0. */
.model-gallery__body {
    display: grid;
    grid-template-rows: 1fr;
    transition: grid-template-rows 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}

.model-gallery__body > .model-gallery__grid {
    min-height: 0;
    overflow: hidden;
    visibility: visible;
    transition: visibility 0s;
}

.model-gallery__group.is-collapsed .model-gallery__body {
    grid-template-rows: 0fr;
}

/* Once shut, drop the grid out of the focus / a11y tree; the delay holds
   until the height transition lands so nothing pops. */
.model-gallery__group.is-collapsed .model-gallery__body > .model-gallery__grid {
    visibility: hidden;
    transition: visibility 0s 0.45s;
}

/* Collapsed panel = just the header: retire its divider + gap while shut,
   and give the slimmed panel a minimal hover lift (border + wash) so it
   still reads as clickable. */
.model-gallery__group.is-collapsed .model-gallery__group-head {
    border-bottom-color: transparent;
    margin-bottom: 0;
    padding-bottom: 0;
}

.model-gallery__group.is-collapsed:hover,
.model-gallery__group.is-collapsed:focus-within {
    border-color: rgba(255, 255, 255, 0.22);
    background: #111216;
}

/* ---- photo wall ----
   Uniform auto-fill grid as the base; capable browsers get the mosaic grid
   in the @supports block further down (after the tile rules, so its
   overrides win the cascade). */
.model-gallery__grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(15rem, 100%), 1fr));
    gap: var(--mg-gap, 0.55rem);
}

.model-gallery__tile,
.model-gallery__more {
    /* Same global-button reset as the pills (docs/gotchas.md). */
    appearance: none;
    -webkit-appearance: none;
    display: block;
    width: 100%;
    margin: 0;
    padding: 0;
    font: inherit;
    text-transform: none;
    color: #fff;
    background: var(--mg-tile);
    border: 1px solid var(--mg-line-soft);
    border-radius: var(--mg-tile-radius);
    overflow: hidden;
    position: relative;
    aspect-ratio: 4 / 3;
    cursor: zoom-in;
    transition: border-color 0.2s ease;
}

/* The display: block above beats the UA's [hidden] rule, so hidden collapsed
   tiles — and the "+N photos" expander once it's spent — need the guard. */
.model-gallery__tile[hidden],
.model-gallery__more[hidden] {
    display: none !important;
}

/* ---- mosaic grid ----
   Four fixed tracks whose row height derives from the track width via
   container-query units (each 1×1 cell stays 4:3), so the span classes the
   component assigns per photo count (see tv_model_gallery_spans() in
   model-gallery.php) always compose complete, symmetric rectangles: every
   collapsed 11+ group is the same 3-row block (2×2 hero + 7 tiles + the
   expander). Browsers without container queries stay on the uniform
   auto-fill grid above — the span classes simply never activate. */
@supports (width: 1cqi) {
    .model-gallery__group {
        container-type: inline-size;
    }

    .model-gallery__grid {
        --mg-gap: 0.55rem;
        grid-template-columns: repeat(4, 1fr);
        /* One unit row = a 4:3 cell: track width × 3/4. 100cqi is the group's
           content-box width — exactly the grid's own width. */
        grid-auto-rows: calc((100cqi - 3 * var(--mg-gap)) / 4 * 0.75);
        grid-auto-flow: dense;
    }

    .model-gallery__tile,
    .model-gallery__more {
        aspect-ratio: auto; /* the grid rows own the height here */
        height: 100%;
    }

    .model-gallery__tile--w2 {
        grid-column: span 2;
    }

    .model-gallery__tile--big {
        grid-column: span 2;
        grid-row: span 2;
    }

    /* Right-anchored hero — the mirrored repetitions' 2×2 (explicit tracks
       3–4; the grid's dense flow backfills the singles to its left). */
    .model-gallery__tile--big-r {
        grid-column: 3 / span 2;
        grid-row: span 2;
    }

    .model-gallery__tile--wide {
        grid-column: span 4;
        grid-row: span 2;
    }
}

/* ---- fullscreen viewer, model-page flavor ----
   .service-detail-gallery-modal--models (set in model-gallery.php) — the
   modifier must ride on the modal itself because service-detail-gallery.js
   re-parents it to <body> on init, so section-scoped selectors can't reach
   it. Immersive minimal pass on the shared viewer: near-black backdrop,
   quiet glass controls, no thumb strip (the models modal markup omits it —
   the JS no-ops without the container), the freed height handed to the
   photo, and a "current / total" counter beside the caption as the only
   wayfinding. Service-page galleries are untouched. */
.service-detail-gallery-modal--models {
    /* Bottom UI = the caption bar only. All three tokens re-declared
       together: the :root bottom-ui-space calc resolves against :root's
       values at computed-value time, so overriding the parts alone wouldn't
       reach it here. thumbs-space doubles as the caption's offset from the
       bottom edge (the base __meta rule positions with it). These also
       outrank the :root breakpoint re-declarations in
       service-detail-gallery.css at every width. */
    --gallery-modal-thumbs-space: 1.1rem;
    --gallery-modal-meta-space: 4.6rem;
    --gallery-modal-bottom-ui-space: calc(
        var(--gallery-modal-meta-space) + var(--gallery-modal-thumbs-space)
    );
}

/* Near-opaque black — the page never reads through, the photo owns the room. */
.service-detail-gallery-modal--models .service-detail-gallery-modal__backdrop {
    background: rgba(5, 6, 9, 0.97);
}

/* Every render swaps in a fresh <img>, so the fade replays per photo. */
.service-detail-gallery-modal--models .service-detail-gallery-modal__stage img {
    animation: mg-viewer-fade 0.28s ease both;
}

@keyframes mg-viewer-fade {
    from {
        opacity: 0;
    }
}

/* Quiet glass controls: hairline border, whisper surface, brighten on use.
   Sizes stay with the base sheet — its breakpoint steps keep the arrows
   inside the dialog's 64/46/40px gutter tracks. */
.service-detail-gallery-modal--models .service-detail-gallery-modal__nav,
.service-detail-gallery-modal--models .service-detail-gallery-modal__close {
    border-color: rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.05);
    color: rgba(255, 255, 255, 0.9);
    transition:
        background-color 0.18s ease,
        border-color 0.18s ease,
        color 0.18s ease;
}

.service-detail-gallery-modal--models .service-detail-gallery-modal__nav:hover,
.service-detail-gallery-modal--models .service-detail-gallery-modal__nav:focus-visible,
.service-detail-gallery-modal--models .service-detail-gallery-modal__close:hover,
.service-detail-gallery-modal--models .service-detail-gallery-modal__close:focus-visible {
    border-color: rgba(255, 255, 255, 0.3);
    background: rgba(255, 255, 255, 0.13);
    color: #fff;
}

/* Brand mark recedes while viewing; full strength when sought out. */
.service-detail-gallery-modal--models .service-detail-gallery-modal__logo {
    opacity: 0.7;
    transition: opacity 0.18s ease;
}

.service-detail-gallery-modal--models .service-detail-gallery-modal__logo:hover,
.service-detail-gallery-modal--models .service-detail-gallery-modal__logo:focus-visible {
    opacity: 1;
}

/* Caption bar: "Model · Chassis" + counter on one line, photo description
   beneath. */
.service-detail-gallery-modal--models .service-detail-gallery-modal__meta {
    gap: 0.4rem;
    padding: 0.25rem 1rem;
}

.service-detail-gallery-modal--models .service-detail-gallery-modal__meta-row {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 0.65rem;
}

.service-detail-gallery-modal--models .service-detail-gallery-modal__label {
    font-size: 0.88rem;
    letter-spacing: 0.14em;
}

.service-detail-gallery-modal--models .service-detail-gallery-modal__count {
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    color: rgba(255, 255, 255, 0.55);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.service-detail-gallery-modal--models .service-detail-gallery-modal__alt {
    color: rgba(255, 255, 255, 0.62);
    font-size: 0.84rem;
}

@media (max-width: 620px) {
    .service-detail-gallery-modal--models {
        --gallery-modal-thumbs-space: 0.9rem;
        --gallery-modal-meta-space: 4rem;
    }

    .service-detail-gallery-modal--models .service-detail-gallery-modal__label {
        font-size: 0.8rem;
    }

    .service-detail-gallery-modal--models .service-detail-gallery-modal__count,
    .service-detail-gallery-modal--models .service-detail-gallery-modal__alt {
        font-size: 0.76rem;
    }
}

.model-gallery__tile img,
.model-gallery__more img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.35s ease;
}

.model-gallery__tile:hover,
.model-gallery__more:hover,
.s-model-gallery .model-gallery__tile:hover,
.s-model-gallery .model-gallery__more:hover {
    /* The doubled selectors' (0,3,0) outranks the detail pages'
       `.b-model button:hover { background-color: var(--c1) }` (0,2,1) —
       the tiles and the "+N photos" expander are <button>s, and without
       this they hover brand-red there (docs/gotchas.md button trap).
       Same surface as the family pages: dark tile, brighter hairline. */
    background: var(--mg-tile);
    border-color: rgba(255, 255, 255, 0.3);
}

.model-gallery__tile:hover img,
.model-gallery__more:hover img {
    transform: scale(1.05);
}

/* (Pills get their focus ring from .tv-cta--ghost:focus-visible in cta.css.) */
.model-gallery__tile:focus-visible,
.model-gallery__more:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

/* "+N photos" expander — a tile-sized cell previewing the first hidden photo. */
.model-gallery__more {
    cursor: pointer;
}

.model-gallery__more img {
    opacity: 0.45;
}

.model-gallery__more-label {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    background: rgba(0, 0, 0, 0.45);
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: 0.06em;
}

.model-gallery__more:hover .model-gallery__more-label {
    background: rgba(0, 0, 0, 0.3);
}

/* ---- tablet ----
   The 4-track mosaic stays through tablet widths (it only hands over to the
   2-track phone grid at 640px below) — an iPad-portrait wall stays as
   photo-dense as desktop. Only the chrome adapts here: tighter section
   gutters, stacked toolbar, baseline-aligned group heads. */
@media (max-width: 768px) {
    .s-model-gallery {
        padding: 0 0.75rem 3.5rem;
    }

    /* The flags cluster (camera count + chevron) sits absolutely in the
       top-right corner, out of the text flow entirely — it can never be
       pushed down or wrapped by the label. The label block owns the full
       row, and its chassis / designation line never wraps: it ellipsizes
       at the header's edge instead. */
    .model-gallery__group-head {
        position: relative;
    }

    .model-gallery__group-id {
        flex: 1 1 auto;
        min-width: 0;
    }

    .model-gallery__group-flags {
        position: absolute;
        top: 0;
        right: 0;
        /* Stacked: the count chip on top, the collapse chevron beneath it,
           both flush with the right edge. */
        flex-direction: column;
        align-items: flex-end;
        gap: 0.35rem;
    }

    .model-gallery__group-chassis {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Breathing room between the band's top edge and the wordmark row —
       also drops the wordmark toward the count chip's vertical centre.
       (The absolute flags stay pinned to the very corner.) */
    .model-gallery__group-model {
        margin-top: 0.4rem;
    }

    /* Toolbar stacks: intro above, the van selector full-width below it. */
    .model-gallery__toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    /* The intro's 30rem flex-basis is a WIDTH in the row layout, but once the
       toolbar goes column the main axis flips and it becomes a 30rem-tall
       paragraph — a giant blank gap above the selector. Size by content here. */
    .model-gallery__intro {
        flex: 0 0 auto;
    }

    .model-gallery__select {
        width: 100%;
    }
}

/* ---- phone ---- */
@media (max-width: 640px) {
    /* Full-bleed photo bands — the same edge-to-edge treatment as the compare
       panel: 100vw with a 50% − 50vw margin lands each group on the viewport
       edge whatever padding the page wrapper adds; corners square off, side
       borders drop, and the shell padding tightens so the photos own the
       screen width. */
    .model-gallery__group {
        width: 100vw;
        margin-left: calc(50% - 50vw);
        padding: 0.6rem;
        border-left: 0;
        border-right: 0;
        border-radius: 0;
    }

    /* The header text keeps a hair more inset than the tiles so wordmarks and
       the count chip don't ride the screen edge. */
    .model-gallery__group-head {
        padding-inline: 0.35rem;
    }

    /* Chunky 22px corners read oversized on ~170px tiles. */
    .model-gallery__tile,
    .model-gallery__more {
        border-radius: 14px;
    }

    /* Fallback (no container queries): smaller minimum so two columns fit. */
    .model-gallery__grid {
        grid-template-columns: repeat(auto-fill, minmax(min(9.25rem, 100%), 1fr));
        gap: var(--mg-gap, 0.45rem);
    }

    /* Two-track mosaic: the feature band pieces span both tracks (full-width
       bands) and the recipe guarantees an even number of leftover singles,
       so the rectangle still closes. --big/--wide keep their double row from
       the desktop rules. */
    @supports (width: 1cqi) {
        .model-gallery__grid {
            --mg-gap: 0.45rem;
            grid-template-columns: repeat(2, 1fr);
            grid-auto-rows: calc((100cqi - var(--mg-gap)) / 2 * 0.75);
        }

        /* --big-r especially: track 3 doesn't exist here, so it must drop
           its explicit placement and flow like a plain full-width hero. */
        .model-gallery__tile--w2,
        .model-gallery__tile--big,
        .model-gallery__tile--big-r,
        .model-gallery__tile--wide {
            grid-column: span 2;
        }
    }

    /* Tighter vertical rhythm between the variant clusters and their bands. */
    .model-gallery__cluster {
        margin: 1.6rem 0 0.3rem;
        gap: 0.8rem;
    }

    .model-gallery__group-count {
        padding: 0.3rem 0.75rem;
        font-size: 0.85rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .model-gallery__select,
    .model-gallery__group,
    .model-gallery__group-head,
    .model-gallery__group-toggle,
    .model-gallery__group-toggle::before,
    .model-gallery__group-toggle::after,
    .model-gallery__body,
    .model-gallery__body > .model-gallery__grid,
    .model-gallery__tile,
    .model-gallery__more,
    .model-gallery__tile img,
    .model-gallery__more img,
    .service-detail-gallery-modal--models .service-detail-gallery-modal__nav,
    .service-detail-gallery-modal--models .service-detail-gallery-modal__close,
    .service-detail-gallery-modal--models .service-detail-gallery-modal__logo {
        transition: none;
    }

    .model-gallery__tile:hover img,
    .model-gallery__more:hover img {
        transform: none;
    }

    .service-detail-gallery-modal--models .service-detail-gallery-modal__stage img {
        animation: none;
    }
}
