/* Phone composition: iPhone SE (375 CSS px wide) is the 1x reference.
   Width controls bounded spacing/art growth; height never enlarges type.
   Typography grows more gently than illustrations. No root scaling, CSS zoom
   or whole-page transform. UI-08 reuses this composition on portrait tablets
   with one bounded unit; landscape and desktop remain independent.

   Keep this after the section and desktop-scale styles. Match api.compactQuery
   in js/main.js. These are layout boundaries, not device detection. */
@media (max-width: 600px), (min-width: 601px) and (max-width: 1100px) and (max-aspect-ratio: 999/1000) {
    :root {
        --phone-unit: clamp(.853333px, calc(100vw / 375), 1.173333px);
        --text-body: clamp(1.0625rem, calc(.7019rem + 1.5385vw), 1.125rem);
        --phone-small: clamp(1rem, calc(.6394rem + 1.5385vw), 1.0625rem);
        --phone-heading: clamp(1.75rem, calc(30 * var(--phone-unit)), 2.125rem);
        --phone-subheading: clamp(1.125rem, calc(19 * var(--phone-unit)), 1.3125rem);
        --phone-hero: clamp(2rem, calc(34 * var(--phone-unit)), 2.375rem);
        --phone-problem-heading: clamp(1.5rem, calc(28 * var(--phone-unit)), 2rem);
        --phone-gap: calc(24 * var(--phone-unit));
        --phone-section: calc(48 * var(--phone-unit));
        --gut: max(1rem, calc(20 * var(--phone-unit)));
        --stage-pad: var(--phone-gap);
        --phone-title-inset: calc(var(--nav-h) + var(--phone-gap));
    }
    /* Sections reserve the navbar themselves, including native hash links. */
    html { scroll-padding-top: 0; }
    .band:not(.hero) { --section-lands-at-top: 1; }

    /* Reading roles, not a different size for each section. */
    .lede,
    .approach__head .note,
    .step p,
    .card__back p,
    .cases__detail p,
    .reason p { font-size: var(--text-body); line-height: 1.55; }

    .display,
    .approach__head h2,
    .services h2 { font-size: var(--phone-heading); }
    .display { text-wrap: balance; }

    .step h3,
    .card h3,
    .cases__item { font-size: var(--phone-subheading); }

    .btn { min-height: 44px; font-size: 1rem; }
    .nav__cta.btn { min-height: 44px; }
    .card__more { font-size: .875rem; min-height: 44px; }
    .cases__item button {
        min-height: 44px;
        /* UI-73: Chintzy labels can wrap to two lines. A body-text line
           height makes the original enclosing ring wider than the phone;
           use heading leading while retaining the type size and 44px hit. */
        line-height: 1.25;
        max-width: 100%;
    }
    .footer__links a { min-height: 44px; min-width: 44px; }
    .footer .nav__logo { min-height: 44px; }

    /* One title rail for pinned stories and ordinary sections. */
    .approach, .pilot, .services, .cases, .about, .final,
    .problem.is-still { padding-block: var(--phone-title-inset) var(--phone-section); }

    .cols, .approach__figure { gap: var(--phone-gap); }
    .cols { grid-template-columns: 1fr; }
    .approach__head, .services h2 { margin-bottom: var(--phone-gap); }
    .cases h2 { margin-bottom: var(--phone-gap); }
    h1 + p, h2 + p { margin-top: var(--phone-gap); }

    .hero {
        padding-block: calc(var(--nav-h) + var(--phone-gap)) var(--phone-gap);
    }
    .hero__card { padding: 0; width: 100%; }
    .hero__card h1 { font-size: var(--phone-hero); }
    .hero__card .lede { margin-block: 0; }

    /* Keep a real box for the lazy loader. Without animation (or if loading
       fails), the introduction and all four steps remain a normal list. */
    .approach__art { display: block; width: min(100%, calc(300 * var(--phone-unit))); }
    .approach { display: block; min-height: 0; }
    .approach__figure { display: grid; }
    .step { position: static; width: auto; text-align: left; }
    .approach.is-phone-story {
        height: 100svh;
        min-height: 0;
        padding-block: var(--phone-title-inset) var(--phone-gap);
    }
    .approach.is-phone-story > .wrap {
        height: 100%;
        display: grid;
        grid-template-rows: auto auto minmax(0, 1fr);
        gap: var(--phone-gap);
    }
    .approach.is-phone-story .approach__head,
    .approach.is-phone-story .approach__figure { display: contents; }
    .approach.is-phone-story h2 { grid-area: 1 / 1; }
    .approach.is-phone-story .approach__head .note,
    .approach.is-phone-story .approach__figure > .step {
        grid-area: 2 / 1;
        position: relative;
        inset: auto;
        margin: 0;
        align-self: start;
    }
    /* UI-02: spend 10 reference pixels of the reserved text/art gap. */
    .approach.is-phone-story .approach__art {
        grid-area: 3 / 1;
        min-height: 0;
        width: 100%;
        height: 100%;
        margin: calc(-10 * var(--phone-unit)) 0 0;
    }
    .approach.is-phone-story .approach__art .slot {
        width: 100%;
        height: 100%;
        max-height: none;
        aspect-ratio: auto;
    }

    /* Copy gets its actual height, artwork the remaining stage. Avoid the
       old percentage-height frame growing taller than the SE's viewport. */
    .problem:not(.is-still) { height: 100svh; min-height: 0; align-items: stretch; }
    .problem:not(.is-still) .problem__frame {
        width: 100%;
        aspect-ratio: auto;
        display: grid;
        gap: 0;
        height: auto;
        min-height: 0;
        grid-template-rows: auto minmax(0, 1fr);
    }
    .problem:not(.is-still) .problem__art {
        min-height: 0;
        position: relative;
        inset: auto;
        grid-area: 2 / 1;
        width: 100%;
        height: 100%;
        margin-inline: 0;
        overflow: hidden;
    }
    .problem:not(.is-still) .problem__copy {
        position: relative;
        grid-area: 1 / 1;
        top: auto;
        left: auto;
        width: auto;
        transform: none;
        align-self: end;
    }
    .problem__copy .display { font-size: var(--phone-problem-heading); }
    .problem__copy p, .problem__copy .note { max-width: none; }
    .problem__copy p, .problem__copy .lede { font-size: var(--phone-small); }
    .problem__copy .strong { font-size: var(--text-body); }
    .problem__copy > * { margin-bottom: 1rem; }
    .problem__copy > *:last-child { margin-bottom: 0; }

    /* Illustrations share the width multiplier and retain SVG proportions.
       Without animation, the original cards remain in normal flow. */
    .pilot__scan { width: min(100%, calc(240 * var(--phone-unit))); margin-top: 0; }
    .pilot__gets { margin-top: var(--phone-gap); }
    .pilot__gets h3 { font-size: var(--phone-small); margin-bottom: 1rem; }

    /* Assessment follows the same title/reading/art rails as Approach. The
       longest paragraph reserves the reading row; the CTA stays available.
       These rules only apply after the scene has successfully initialized. */
    .pilot.is-phone-story {
        height: 100svh;
        min-height: 0;
        padding-block: var(--phone-title-inset) var(--phone-gap);
    }
    .pilot.is-phone-story > .wrap {
        height: 100%;
        display: grid;
        grid-template-rows: auto auto minmax(0, 1fr) auto;
        gap: var(--phone-gap);
    }
    .pilot.is-phone-story .cols,
    .pilot.is-phone-story .cols > :first-child { display: contents; }
    .pilot.is-phone-story h2 { grid-area: 1 / 1; max-width: none; }
    .pilot.is-phone-story .lede,
    .pilot.is-phone-story .pilot__gets {
        grid-area: 2 / 1;
        align-self: start;
        margin: 0;
    }
    .pilot.is-phone-story .pilot__gets ul { display: grid; }
    .pilot.is-phone-story .pilot__gets li { grid-area: 1 / 1; margin: 0; }
    .pilot.is-phone-story .pilot__scan {
        grid-area: 3 / 1;
        min-height: 0;
        width: 100%;
        height: 100%;
        max-height: none;
        aspect-ratio: auto;
    }
    /* The new hand reaches beyond the route's centered viewBox. Keep the
       approved compact artwork cap inside the restored full-height row. */
    .pilot.is-phone-story .pilot__scan > svg { max-width: calc(240 * var(--phone-unit)); }
    /* UI-04: center the existing email CTA without moving its row. */
    .pilot.is-phone-story .btn { grid-area: 4 / 1; justify-self: center; }

    .services { display: block; min-height: 0; height: auto; overflow: visible; }
    .services__figure { overflow: visible; }
    .services__art { height: auto; width: auto; padding-bottom: 0; will-change: auto; }
    .services__art > .slot { display: none; }
    .card {
        position: static;
        width: auto;
        max-width: calc(300 * var(--phone-unit));
        margin: 0 auto var(--phone-section);
    }
    .card:last-child { margin-bottom: 0; }
    /* One service per screen, using the existing cards/paragraphs once. All
       cards share rows so the longest title and copy reserve their height. */
    .services.is-phone-story {
        height: 100svh;
        min-height: 0;
        padding-block: var(--phone-title-inset) var(--phone-gap);
    }
    .services.is-phone-story > .wrap {
        height: 100%;
        display: grid;
        grid-template-rows: auto auto auto minmax(0, 1fr);
        gap: var(--phone-gap);
    }
    .services.is-phone-story h2 { grid-area: 1 / 1; margin: 0; }
    .services.is-phone-story .services__figure,
    .services.is-phone-story .services__art,
    .services.is-phone-story .card__flip,
    .services.is-phone-story .card__front,
    .services.is-phone-story .card__back { display: contents; }
    .services.is-phone-story .card {
        grid-area: 2 / 1 / 5 / 2;
        display: grid;
        grid-template-rows: subgrid;
        max-width: none;
        margin: 0;
        min-height: 0;
    }
    .services.is-phone-story .card h3 { grid-area: 1 / 1; margin: 0; }
    .services.is-phone-story .card__back p { grid-area: 2 / 1; color: var(--ink); }
    .services.is-phone-story .card__more { display: none; }
    .services.is-phone-story .card__back { animation: none; }
    .services.is-phone-story .card__media {
        grid-area: 3 / 1;
        width: 100%;
        height: 100%;
        min-height: 0;
        max-height: none;
        aspect-ratio: auto;
        transition: none;
        background: none;
        align-items: start;
        margin-top: calc(-10 * var(--phone-unit)); /* UI-03: same lift as Approach */
    }
    .services.is-phone-story .card__media svg {
        width: auto;
        height: 100%;
        max-width: 100%;
        margin-inline: auto;
        background: var(--plate);
    }

    .about .slot { width: 100%; max-width: calc(320 * var(--phone-unit)); margin-inline: auto; }

    /* UI-34: compact About reuses one row for its paragraphs; the independent
       illustration stays in the remaining space. Wide About accumulates. */
    .about.is-phone-story,
    .final.is-phone-story {
        height: 100svh;
        min-height: 0;
        padding-block: var(--phone-title-inset) var(--phone-gap);
    }
    .about.is-phone-story > .wrap {
        height: 100%;
        display: grid;
        grid-template-rows: auto auto minmax(0, 1fr);
        gap: var(--phone-gap);
    }
    .about.is-phone-story .cols,
    .about.is-phone-story .cols > :first-child { display: contents; }
    .about.is-phone-story h2 { grid-area: 1 / 1; max-width: none; margin: 0; }
    .about.is-phone-story .lede,
    .about.is-phone-story .note { grid-area: 2 / 1; align-self: start; margin: 0; }
    .about.is-phone-story .slot {
        grid-area: 3 / 1;
        width: 100%;
        height: 100%;
        min-height: 0;
        max-width: none;
        aspect-ratio: auto;
        padding: .5rem;
    }
    .about.is-phone-story .slot svg { height: 100%; width: auto; max-width: 100%; }
    /* UI-07: keep main's centered, stacked paragraphs and CTA spacing.
       Hidden paragraphs retain their space so revealing them never jumps. */
    .final.is-phone-story,
    .final.is-compact-ending {
        height: auto;
        min-height: 100svh;
        display: flex;
        flex-direction: column;
    }
    /* UI-10: center the final action in the space BELOW the full copy stack. */
    .final.is-compact-ending { padding-bottom: max(var(--phone-gap), env(safe-area-inset-bottom)); }
    .final.is-compact-ending > .wrap { flex: 1; display: flex; flex-direction: column; }
    .final.is-compact-ending > .wrap > :is(h2, p) { flex: none; }
    .final.is-compact-ending > .wrap > p:last-of-type { margin-bottom: 0; }
    .final.is-compact-ending .btn { flex: none; align-self: center; margin-block: auto; }

    /* UI-14: the original footer closes the same stage, not a new screen.
       Keep real 44px targets and the header's exact wordmark. */
    .final.is-compact-ending > .footer {
        flex: none;
        padding: calc(8 * var(--phone-unit)) 0 0;
        border-top: 1px solid var(--rule);
        text-align: left;
    }
    .final.is-compact-ending .footer__inner { flex-direction: column; gap: 0; }
    .final.is-compact-ending .footer__inner > div {
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: .5rem;
    }
    .final.is-compact-ending .footer__meta {
        margin: 0;
        max-width: none;
        font-size: calc(14 * var(--phone-unit));
        line-height: 1.4;
        text-align: right;
    }
    .final.is-compact-ending .footer__links {
        width: 100%;
        justify-content: space-between;
        gap: 0;
    }
    .final.is-compact-ending .footer__links a {
        display: flex;
        align-items: center;
        padding-block: 0;
        font-size: calc(15 * var(--phone-unit));
        line-height: 1.4;
    }

    /* The longest reason reserves its own space; no fixed-height text box.
       The SVG fits the middle row without changing the animation itself. */
    .why:not(.is-static) .why__stage {
        height: 100svh;
        min-height: 0;
        display: grid;
        grid-template-rows: auto minmax(0, 1fr) auto;
        gap: var(--phone-gap);
        justify-items: center;
    }
    .why:not(.is-static) .why__art { width: 100%; height: 100%; }
    .why:not(.is-static) .why__art .slot { height: 100%; max-height: none; aspect-ratio: auto; }
    .why:not(.is-static) .why__reasons { display: grid; min-height: 0; }
    .why:not(.is-static) .reason { position: relative; inset: auto; grid-area: 1 / 1; }
    .reason__num { display: none; }
    .why.is-static .why__stage { padding-block: var(--phone-title-inset) var(--phone-section); }
}

/* Budget phone spacing against the short SE, without shrinking type/targets.
   Keep it stable as browser bars change height; taller phones put the extra
   room around the CTA. Enlarged text can still grow the section naturally. */
@media (max-width: 600px) {
    .final.is-compact-ending { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
    .final.is-compact-ending > .wrap > h2 { margin-bottom: 12px; }
    .final.is-compact-ending > .wrap > p { line-height: 1.5; margin-bottom: 8px; }
    .final.is-compact-ending > .wrap > p:last-of-type { margin-bottom: 0; }
    .final.is-compact-ending > .footer { padding-top: 0; }
}

/* UI-08 — portrait tablet = the SE composition, scaled against BOTH axes.
   The 2x ceiling keeps large tablets from producing oversized type. Keep
   rem/root and the restored navbar geometry unchanged; scale the content's
   reference dimensions through this one length unit instead. */
@media (min-width: 601px) and (max-width: 1100px) and (max-aspect-ratio: 999/1000) {
    :root {
        --phone-unit: clamp(1px, min(calc(100vw / 375), calc(100svh / 667)), 2px);
        --text-body: calc(17 * var(--phone-unit));
        --phone-small: calc(16 * var(--phone-unit));
        --phone-heading: calc(30 * var(--phone-unit));
        --phone-subheading: calc(19 * var(--phone-unit));
        --phone-hero: calc(34 * var(--phone-unit));
        --phone-problem-heading: calc(28 * var(--phone-unit));
    }
    main .btn {
        font-size: calc(16 * var(--phone-unit));
        padding: calc(13.6 * var(--phone-unit)) calc(25.6 * var(--phone-unit));
    }
    .step h3 { margin-bottom: calc(9.6 * var(--phone-unit)); }
    .pilot__gets h3 { margin-bottom: calc(16 * var(--phone-unit)); }
    .pilot__gets li { font-size: var(--text-body); }
    .problem__copy > * { margin-bottom: calc(16 * var(--phone-unit)); }
    .problem__copy > *:last-child { margin-bottom: 0; }
    .hero__art { width: min(100%, calc(340 * var(--phone-unit))); }
    .why__reasons { width: min(100%, calc(335 * var(--phone-unit))); }
    .final h2 { margin-bottom: calc(32 * var(--phone-unit)); }
    .final p { margin-bottom: calc(20 * var(--phone-unit)); }
    .final .btn { margin-top: calc(24 * var(--phone-unit)); }

    /* UI-12: the phone's original expanding answer follows its title on
       portrait tablets too, including widths above the old 900px cutoff. */
    .cases.is-accordion .cases__panel { display: none; }
    .cases.is-accordion .cases__drawer { height: 0; overflow: hidden; }
    .cases.is-accordion .cases__detail {
        grid-area: auto;
        margin-top: calc(var(--ring-drop, 1.8rem) + 5.6 * var(--phone-unit));
        border-top: 1px solid var(--rule);
        padding: calc(12 * var(--phone-unit)) 0 calc(8 * var(--phone-unit));
    }
    /* UI-11: centered labels in the existing narrow tablet drop-down. */
    .nav__links { text-align: center; }
}

/* UI-11: center the link group on the viewport, not the space left between
   unequal logo/CTA widths. Compact gaps/padding keep the full CTA label at
   tight tablet widths without wrapping links or colliding with either side. */
@media (min-width: 761px) and (max-width: 1100px) and (max-aspect-ratio: 999/1000) {
    .nav__inner { position: relative; gap: 1rem; }
    .nav__links {
        position: absolute;
        left: 50%;
        translate: -50%;
        margin: 0;
        gap: 1rem;
        font-size: 15px;
        line-height: 1.5;
        white-space: nowrap;
    }
    .nav__cta { margin-left: auto; white-space: nowrap; }
    .nav__cta.btn { padding-inline: 1rem; }
}
