/* Styles for the model page only. */

/* The film or photo fills the width, with the text on top. */
.model-hero {
    --color-text: var(--color-hero-text);
    --color-bg: var(--color-footer-bg);
    --color-focus: var(--color-footer-focus);

    position: relative;
    isolation: isolate;
    display: flex;
    align-items: flex-end;
    min-height: max(480px, 68svh);
    background: var(--color-footer-bg);
    color: var(--color-hero-text);
}

.model-hero::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: -1;
    background: var(--hero-scrim-foot);
}

.model-hero__media {
    position: absolute;
    inset: 0;
    z-index: -2;
    overflow: hidden;
    container-type: size;
}

.model-hero__media img,
.model-hero__media video {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Stays hidden until it plays, so the photo never gives way to a black box. */
.model-hero__media video,
.model-hero__media iframe {
    opacity: 0;
    transition: opacity 0.7s ease;
}

.model-hero.is-live video,
.model-hero.is-live iframe {
    opacity: 1;
}

/* Covers the box at 16:9. The extra 35% crops the black bars in wide films and
   YouTube's title, and a bigger player gets a sharper picture than a zoom. */
.model-hero__media iframe {
    position: absolute;
    top: 50%;
    left: 50%;
    width: calc(max(100cqw, 177.78cqh) * 1.35);
    aspect-ratio: 16 / 9;
    border: 0;
    pointer-events: none;
    transform: translate(-50%, -50%);
}

.model-hero__inner {
    display: grid;
    justify-items: start;
    gap: var(--space-3);
    padding-block: var(--space-8) var(--space-6);
    text-shadow: var(--hero-text-shadow);
}

.model-hero h1,
.model-hero h2 {
    color: inherit;
}

.model-hero h1 {
    font-size: clamp(2.2rem, 4.6vw, 4rem);
    line-height: 1;
}

/* Lighter than the model name, or as light when the title itself is light. */
.model-hero h1 span {
    font-weight: min(500, var(--heading-1-weight));
    opacity: 0.75;
}

.model-hero__buy {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: var(--space-4) var(--space-6);
    width: 100%;
    max-width: 820px;
    margin-top: var(--space-3);
    padding-top: var(--space-4);
    border-top: 1px solid var(--color-hero-line);
}

.model-hero .model-price__label {
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.2em;
    text-transform: uppercase;
}

.model-hero .model-price__amount {
    font-size: clamp(2rem, 1.6rem + 1vw, 2.6rem);
}

.model-hero .btn {
    text-shadow: none;
}

.model-hero__toggle {
    top: var(--space-4);
    bottom: auto;
}

.model-strip {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr));
    border-bottom: 1px solid var(--color-border);
    background: var(--color-surface);
}

.model-strip__item {
    display: grid;
    gap: 2px;
    padding: var(--space-4) var(--page-gutter);
    border-inline-end: 1px solid var(--color-border);
    color: var(--color-text);
    font-size: var(--text-sm);
    text-decoration: none;
}

.model-strip__item span {
    color: var(--color-text-muted);
}

.model-layout {
    display: grid;
    gap: var(--space-6);
    padding-block: var(--space-6) var(--space-8);
}

.model-main {
    display: grid;
    gap: var(--space-8);
    min-width: 0;
}

/* Keeps a heading clear of the sticky header and section bar. */
.model-section,
.buy-card__stock,
.model-note {
    scroll-margin-top: calc(var(--header-height) + 64px);
}

.model-price {
    display: grid;
    justify-items: start;
    gap: 2px;
}

.model-price__label,
.model-price__note,
.model-price__was {
    font-size: var(--text-sm);
}

.model-price__amount {
    font-family: var(--font-heading);
    font-size: var(--text-2xl);
    font-weight: var(--heading-weight);
    line-height: 1.1;
}

.model-price__otr {
    color: inherit;
    font-size: var(--text-sm);
}

.model-price__was {
    text-decoration: line-through;
}

.model-price__finance {
    color: inherit;
    font-size: var(--text-sm);
}

.model-feature {
    display: grid;
    align-items: center;
    gap: var(--space-5);
    margin-top: var(--space-6);
}

.model-feature img {
    width: 100%;
    aspect-ratio: 4 / 3;
    object-fit: cover;
    border-radius: var(--radius-card);
}

.model-feature__text {
    display: grid;
    gap: var(--space-3);
}

.model-feature h3 {
    font-size: clamp(1.4rem, 2.2vw, 2rem);
}

/* Grows with the screen, so narrow columns aren't a few words a line. */
.model-feature p {
    font-size: clamp(1.125rem, 0.6rem + 0.77vw, 1.52rem);
    line-height: 1.7;
}

.model-gallery {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-3);
}

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

.model-gallery img {
    width: 100%;
    aspect-ratio: 3 / 2;
    object-fit: cover;
    border-radius: var(--radius-card);
    background: var(--color-media);
}

.model-colours {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 200px), 1fr));
    gap: var(--space-4);
}

.model-colour {
    display: grid;
    gap: var(--space-1);
}

.model-colour__photo {
    display: block;
    background: var(--color-media);
}

.model-colour__photo img {
    width: 100%;
    aspect-ratio: 3 / 2;
    object-fit: contain;
}

/* Each video takes the whole width until two big ones fit side by side. */
.model-videos {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 480px), 1fr));
    gap: var(--space-4);
}

/* The still, the play button and the title share one cell. */
.model-video {
    position: relative;
    display: grid;
    place-items: center;
    overflow: hidden;
    border-radius: var(--radius-card);
    background: #000000;
}

.model-video > * {
    grid-area: 1 / 1;
}

/* The zoom on hover lifts the still, so these sit above it. */
.model-video__caption,
.model-video .play {
    z-index: 1;
}

/* A single video on a very wide screen still fits on it. */
.model-video img {
    width: 100%;
    max-height: 80svh;
    aspect-ratio: 16 / 9;
    object-fit: cover;
}

/* The whole card opens the video. */
.model-video .play::after {
    content: "";
    position: absolute;
    inset: 0;
}

.model-video:hover .play {
    background: var(--color-primary-hover);
}

.model-video:has(.play:focus-visible) {
    outline: 3px solid var(--color-focus);
    outline-offset: 2px;
}

.model-video .play:focus-visible {
    outline: none;
}

/* The still is a photo in both modes, so the title stays white on a shade. */
.model-video__caption {
    align-self: end;
    justify-self: stretch;
    padding: var(--space-7) var(--space-5) var(--space-4);
    background: linear-gradient(to bottom, transparent, rgb(0 0 0 / 0.6) 45%, rgb(0 0 0 / 0.85));
    color: #FFFFFF;
    text-shadow: var(--hero-text-shadow);
    font-family: var(--font-heading);
    font-size: var(--text-lg);
    font-weight: var(--heading-weight);
    line-height: 1.3;
}

.model-about p {
    margin-bottom: var(--space-3);
}

/* The description holds several paragraphs, so this clamps by height. */
.model-about.is-clamped {
    display: block;
    max-height: 13em;
}

.model-specs__title {
    margin-block: var(--space-5) var(--space-3);
}

.model-specs {
    display: grid;
    margin: 0;
}

.model-specs div {
    display: flex;
    justify-content: space-between;
    gap: var(--space-5);
    padding-block: var(--space-2);
    border-bottom: 1px solid var(--color-border);
    font-size: var(--text-sm);
}

.model-specs dt {
    color: var(--color-text-muted);
}

.model-specs dd {
    margin: 0;
    font-weight: 600;
    text-align: end;
}

.model-notes {
    display: grid;
    gap: var(--space-4);
}

.model-note {
    display: grid;
    gap: var(--space-1);
    padding: var(--space-4);
    border-inline-start: 3px solid var(--color-primary);
    background: var(--color-surface);
    font-size: var(--text-sm);
}

.calculator {
    display: grid;
    gap: var(--space-4);
    padding: var(--space-5);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-card);
    background: var(--color-surface);
}

.calculator__head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
}

.calculator__label {
    color: var(--color-text-muted);
    font-size: var(--text-sm);
    font-weight: 600;
}

/* Even-width digits, so the figure doesn't shake as it counts to a new payment (model.js). */
.calculator__amount {
    font-family: var(--font-heading);
    font-size: var(--text-3xl);
    font-weight: var(--heading-weight);
    font-variant-numeric: tabular-nums;
    line-height: 1.1;
}

.calculator__amount small {
    font-size: var(--text-md);
}

.has-error .calculator__amount {
    opacity: 0.35;
}

.calculator__error {
    color: var(--color-danger);
    font-size: var(--text-sm);
    font-weight: 600;
}

.calculator__title {
    font-family: var(--font-heading);
    font-size: var(--text-lg);
    font-weight: var(--heading-weight);
    text-transform: var(--heading-transform);
}

.calculator__terms {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
    gap: var(--space-2);
}

.calculator__term {
    display: grid;
    justify-items: center;
    gap: 2px;
    padding: var(--space-3) var(--space-2);
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-field);
    background: transparent;
    color: var(--color-text);
    font: inherit;
    font-size: var(--text-sm);
    cursor: pointer;
}

.calculator__term.is-active {
    border-color: var(--color-primary);
    background: var(--color-primary);
    color: var(--color-on-primary);
}

.calculator__deposit {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-4);
}

/*
 * The deposit slider: a thick track, filled up to the handle (model.js gives --fill, from
 * 0 to 1), and a big handle, round or square as the brand's play button is. The input
 * is taller than the track, so it is easy to catch on a phone.
 */
.calculator input[type="range"] {
    --track: 10px;
    --thumb: 28px;
    width: 100%;
    height: 36px;
    margin: 0;
    background: transparent;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
}

.calculator input[type="range"]::-webkit-slider-runnable-track {
    height: var(--track);
    border-radius: var(--radius-badge);
    background: linear-gradient(to right, var(--color-primary) calc(var(--thumb) / 2 + (100% - var(--thumb)) * var(--fill, 0)), var(--color-border) 0);
}

.calculator input[type="range"]::-moz-range-track {
    height: var(--track);
    border-radius: var(--radius-badge);
    background: var(--color-border);
}

.calculator input[type="range"]::-moz-range-progress {
    height: var(--track);
    border-radius: var(--radius-badge);
    background: var(--color-primary);
}

.calculator input[type="range"]::-webkit-slider-thumb {
    box-sizing: border-box;
    width: var(--thumb);
    height: var(--thumb);
    margin-top: calc((var(--track) - var(--thumb)) / 2);
    border: 4px solid var(--color-surface);
    border-radius: var(--radius-play);
    background: var(--color-primary);
    box-shadow: 0 1px 6px rgb(0 0 0 / 0.35);
    -webkit-appearance: none;
    appearance: none;
    transition: transform 0.15s ease;
}

.calculator input[type="range"]::-moz-range-thumb {
    box-sizing: border-box;
    width: var(--thumb);
    height: var(--thumb);
    border: 4px solid var(--color-surface);
    border-radius: var(--radius-play);
    background: var(--color-primary);
    box-shadow: 0 1px 6px rgb(0 0 0 / 0.35);
    transition: transform 0.15s ease;
}

.calculator input[type="range"]:active::-webkit-slider-thumb {
    transform: scale(1.12);
}

.calculator input[type="range"]:active::-moz-range-thumb {
    transform: scale(1.12);
}

.calculator__terms-text {
    color: var(--color-text-muted);
    font-size: var(--text-sm);
}

.finance-boxes {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr));
    gap: var(--space-4);
    margin-top: var(--space-5);
}

.finance-box {
    display: grid;
    align-content: start;
    justify-items: start;
    gap: var(--space-2);
    padding: var(--space-5);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-card);
    background: var(--color-surface);
}

.finance-box__amount {
    font-family: var(--font-heading);
    font-size: var(--text-2xl);
    font-weight: var(--heading-weight);
}

.finance-box__amount small {
    font-size: var(--text-sm);
}

.finance-box__facts {
    width: 100%;
    margin: 0 0 var(--space-2);
}

.finance-box__facts div {
    display: flex;
    justify-content: space-between;
    gap: var(--space-4);
    padding-block: var(--space-1);
    border-bottom: 1px solid var(--color-border);
    font-size: var(--text-sm);
}

.finance-box__facts dd {
    margin: 0;
    font-weight: 600;
}

.buy-card {
    display: grid;
    gap: var(--space-4);
    padding: var(--space-5);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-card);
    background: var(--color-surface);
}

.buy-card__actions {
    display: grid;
    gap: var(--space-2);
}

.buy-card__stock {
    padding-top: var(--space-4);
    border-top: 1px solid var(--color-border);
}

.buy-card__link {
    font-size: var(--text-sm);
}

.model-dock {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 90;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-2) var(--page-gutter);
    border-top: 1px solid var(--color-border);
    background: var(--color-surface);
    transform: translateY(100%);
    visibility: hidden;
}

.model-dock.is-on {
    transform: none;
    visibility: visible;
}

.model-dock__label {
    display: block;
    color: var(--color-text-muted);
    font-size: 0.75rem;
}

.model-dock .button-row {
    flex-wrap: nowrap;
    gap: var(--space-2);
}

.dialog-actions {
    margin-top: var(--space-4);
}

/* Used bike page: the same layout, with the dealer's own photos and films. */

/* A dealer's photo is smaller than a studio shot, so the hero is shorter. */
.model-hero--used {
    min-height: max(420px, 56svh);
}

/* The text fills most of this shorter hero, so the shade covers it all, even
   on a bright showroom photo. The old used page darkened its photo too. */
.model-hero.model-hero--used::after {
    background: linear-gradient(to bottom, rgb(0 0 0 / 0.6), rgb(0 0 0 / 0.75) 50%, rgb(0 0 0 / 0.92));
}

/* Short facts, so two fit side by side on a phone. */
.model-strip--facts {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 140px), 1fr));
}

/* Phone films are often upright, so the whole frame shows on black. */
.model-video--file video {
    width: 100%;
    max-height: 80svh;
    aspect-ratio: 16 / 9;
    background: #000000;
}

.buy-card__dealer {
    display: grid;
    gap: var(--space-1);
    padding-top: var(--space-4);
    border-top: 1px solid var(--color-border);
    font-size: var(--text-sm);
}

.used-dealer {
    display: grid;
    justify-items: start;
    gap: var(--space-4);
}

.used-dealer .dealer-card {
    width: min(100%, 420px);
}

.used-dealer__more {
    font-weight: 600;
}

@media (min-width: 992px) {
    .model-hero::after {
        background: var(--hero-scrim-corner);
    }
}

@media (min-width: 700px) {
    .model-feature {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: var(--space-6);
    }

    .model-feature--flipped img {
        order: 2;
    }

    .model-gallery {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}

@media (min-width: 1100px) {
    .model-layout {
        grid-template-columns: minmax(0, 1fr) 400px;
        gap: var(--space-7);
    }

    /* Follows the reader, and scrolls itself when stock results make it tall. */
    .buy-card {
        position: sticky;
        top: calc(var(--header-height) + 64px);
        max-height: calc(100vh - var(--header-height) - 80px);
        overflow-y: auto;
    }
}

@media (prefers-reduced-motion: no-preference) {
    .model-video img {
        transition: transform 0.3s;
    }

    .model-video:hover img {
        transform: scale(1.03);
    }
}
