/*
 * Group B uplift (docs/design/uplift-b.md): the SEO pages, the partnership
 * and Site Insight. Linked once per page from site/snippets/uplift/b/
 * (ub_css()), never in the head. Looks in the templates layer, movement in
 * the motion layer under the shared keys (diagrams, timeline), only under
 * "screen and (prefers-reduced-motion: no-preference)". Hidden start
 * states need html.js-motion and a revealing ancestor, so without JS,
 * with reduced motion, ?fx=off and in print everything shows complete.
 */

@layer templates {
  .ub-cols-3,
  .ub-cols-4 {
    gap: var(--space-3);
  }

  @media (min-width: 40rem) {
    .ub-cols-4 {
      grid-template-columns: repeat(2, minmax(0, 1fr));
    }
  }

  @media (min-width: 48rem) {
    .ub-cols-3 {
      grid-template-columns: repeat(3, minmax(0, 1fr));
    }
  }

  @media (min-width: 75rem) {
    .ub-cols-4 {
      grid-template-columns: repeat(4, minmax(0, 1fr));
    }
  }

  /* ---------- Graphics (shared diagram classes, blocks.css) ---------- */

  .ub-query {
    font-size: 16px;
  }

  .ub-hl {
    fill: var(--accent);
  }

  .ub-pulse,
  .ub-tick {
    fill: none;
    stroke: var(--color-ink);
    stroke-width: 1.5;
    stroke-linecap: round;
  }

  .ub-pulse {
    opacity: 0.4;
  }

  .ub-glyph {
    display: block;
    width: auto;
    height: 8rem;
    margin-inline: auto;
  }

  /* ---------- Who it is for ---------- */

  .ub-fit__panel {
    max-width: 64rem;
    gap: 0;
    margin: 0 auto;
    padding: 0;
    border: var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-hard);
    list-style: none;
  }

  .ub-fit__half {
    padding: var(--space-5) var(--space-4);
    background: var(--accent-pale);
  }

  .ub-fit__half--not {
    border-top: var(--border);
    background: var(--color-white);
  }

  .ub-fit__mark,
  .ub-do__mark {
    display: grid;
    place-items: center;
    width: 2.75rem;
    height: 2.75rem;
    border: var(--border);
    border-radius: 50%;
    background: var(--accent);
  }

  .ub-fit__half--not .ub-fit__mark {
    background: var(--color-white);
  }

  .ub-fit__title {
    margin-block: var(--space-3) var(--space-2);
    font-size: var(--step-2);
    font-weight: var(--weight-heading);
  }

  :is(.ub-fit__text, .ub-tier__text, .ub-do__text, .ub-yr__text, .ub-ways__text, .ub-callout__text, .ub-bp__text) > * + * {
    margin-top: var(--space-2);
  }

  @media (min-width: 48rem) {
    .ub-fit__panel {
      grid-template-columns: 1fr 1fr;
    }

    .ub-fit__half {
      padding: var(--space-5);
    }

    .ub-fit__half--not {
      border-top: 0;
      border-left: var(--border);
    }
  }

  /* Site Insight: the large quote and the cards under it read as one mint band */
  .ub-page .block-testimonials + .block-testimonials {
    padding-block-start: 0;
  }

  /* The Search funnel (owner, 2026-11-27, A10): a framed photo band keeps the same space
     above and below as any section, so it never sits flush against the section before it.
     It still opens with no line (the photo does the separating). */
  .ub-page--search .section--flush.block-photos {
    padding-block: var(--section-pad-top) var(--section-pad-bottom);
  }

  /* ---------- SEO: the four tiers ---------- */

  .ub-tiers__intro {
    font-size: var(--step-0);
  }

  .ub-tiers__list,
  .ub-routes__list,
  .ub-steps__list,
  .ub-do__list,
  .ub-yr__list,
  .ub-ways__list,
  .ub-bp__steps,
  .ub-tier__features {
    margin: 0;
    padding: 0;
    list-style: none;
  }

  .ub-tier {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    padding: 0 var(--space-4) var(--space-4);
    border: var(--border);
    border-radius: var(--radius-sm);
    background: var(--color-paper);
    scroll-margin-top: calc(var(--header-height) + var(--space-3));
  }

  .ub-tier:target {
    box-shadow: var(--shadow-hard);
  }

  .ub-tier__plant {
    margin-inline: calc(-1 * var(--space-4));
    margin-bottom: var(--space-2);
    padding-top: var(--space-3);
    border-bottom: var(--border);
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    background: var(--accent-pale);
  }

  .ub-tier__name {
    font-size: var(--step-4);
    font-weight: var(--weight-display);
    line-height: 1;
  }

  .ub-tier__line {
    margin: 0;
    font-weight: 600;
  }

  .ub-tier__features {
    margin-top: auto;
    padding-top: var(--space-3);
    border-top: var(--border);
    font-size: 0.9375rem;
  }

  .ub-tier__features li {
    padding-left: 1.5rem;
    background: linear-gradient(var(--accent), var(--accent)) 0 0.45em / 0.75rem 0.75rem no-repeat;
  }

  .ub-tier__features li + li {
    margin-top: var(--space-1);
  }

  /* Design review 2026-10-22: the four tiers stay two by two on desktop, so
     the cards are wide rather than long, and each card's parts share rows
     with its neighbour (subgrid): the plants, names, lines, texts and the
     "included" lists with their divider start at the same height, and the
     lists sit at the top of their row */
  @media (min-width: 75rem) {
    .ub-tiers__list.ub-cols-4 {
      grid-template-columns: repeat(2, minmax(0, 1fr));
    }
  }

  @supports (grid-template-rows: subgrid) {
    .ub-tier {
      display: grid;
      grid-row: span 6;
      grid-template-rows: subgrid;
      row-gap: var(--space-2);
    }

    .ub-tier__plant {
      grid-row: 1;
    }

    .ub-tier__label {
      grid-row: 2;
    }

    .ub-tier__name {
      grid-row: 3;
    }

    .ub-tier__line {
      grid-row: 4;
    }

    .ub-tier__text {
      grid-row: 5;
    }

    .ub-tier__features {
      grid-row: 6;
      margin-top: 0;
    }
  }

  /* ---------- SEO: the three SEO pages ---------- */

  .ub-routes__lead {
    max-width: 54rem;
    margin: 0 auto var(--space-6);
    text-align: center;
  }

  .ub-routes__lead a {
    background: linear-gradient(var(--accent), var(--accent)) 0 92% / 100% 0.28em no-repeat;
  }

  .ub-routes__card,
  .ub-do--checks .ub-do__item,
  .ub-ways__card {
    position: relative;
    padding: var(--space-4);
    border: var(--border);
    border-radius: var(--radius-sm);
    background: var(--color-white);
  }

  .ub-routes__media {
    margin-bottom: var(--space-3);
    padding: var(--space-2);
    border-radius: var(--radius-sm);
    background: var(--accent-pale);
  }

  .ub-routes__media .diagram {
    height: 11rem;
  }

  @media (max-width: 47.99rem) {
    .ub-routes__card {
      display: grid;
      grid-template-columns: 6.5rem 1fr;
      gap: var(--space-3);
      align-items: center;
      padding: var(--space-3);
    }

    .ub-routes__media {
      margin: 0;
      padding: 0.25rem;
    }

    .ub-routes__media .diagram {
      height: 4.5rem;
    }
  }

  /* Each card is one link: the shared button (link variant, its own arrow,
     underline and arrow nudge on hover and focus) whose ::after covers the
     card, like the study cards; the ring goes around the whole card */
  .ub-routes__title {
    font-size: inherit;
    line-height: 1;
  }

  .ub-routes__link {
    justify-content: flex-start;
    text-align: start;
  }

  .ub-routes__arrow {
    display: inline-flex;
    align-items: center;
  }

  .ub-routes__link::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 1;
    border-radius: var(--radius-sm);
  }

  .ub-routes__link:focus-visible {
    outline: none;
  }

  .ub-routes__card:has(.ub-routes__link:focus-visible) {
    outline: 3px solid var(--focus-ring);
    outline-offset: 3px;
  }

  .ub-routes__card:is(:hover, :focus-within) {
    box-shadow: var(--shadow-hard);
  }

  /* ---------- How it works ---------- */

  .ub-steps__item {
    position: relative;
    padding-top: var(--space-3);
  }

  .ub-steps__item::before {
    content: "";
    position: absolute;
    inset: 0 0 auto;
    height: 1px;
    background: currentColor;
    transform-origin: left;
  }

  .ub-steps__num {
    margin: 0 0 var(--space-2);
    font-family: var(--font-heading);
    font-size: var(--step-6);
    font-weight: var(--weight-display);
    line-height: 1;
  }

  .section--ink .ub-steps__num {
    color: var(--accent-on-ink, var(--accent));
  }

  .ub-steps__title,
  .ub-do__title,
  .ub-yr__title,
  .ub-bp__title {
    margin-bottom: var(--space-1);
    font-size: var(--step-1);
    font-weight: var(--weight-heading-sm);
  }

  @media (min-width: 40rem) {
    .ub-steps__list {
      grid-template-columns: repeat(2, minmax(0, 1fr));
    }
  }

  @media (min-width: 64rem) {
    .ub-steps__list:has(> :nth-child(4)) {
      grid-template-columns: repeat(4, minmax(0, 1fr));
    }
  }

  /* ---------- Proof ---------- */

  .ub-fig {
    display: inline-block;
    font-weight: var(--weight-strong);
  }

  /* ---------- Notes and callouts ---------- */

  .ub-note__text,
  .ub-ways__note {
    max-width: var(--measure);
    margin-inline: auto;
    text-align: center;
  }

  .ub-ways__note {
    margin-top: var(--space-5);
  }

  .ub-callout__card {
    display: grid;
    gap: var(--space-4);
    max-width: 64rem;
    margin-inline: auto;
    padding: var(--space-5) var(--space-4);
    border: var(--border);
    border-radius: var(--radius-lg);
    background: var(--accent-pale);
  }

  .ub-callout__title,
  .ub-problem__title,
  .ub-bp__heading,
  .ub-invest__title {
    margin: 0 0 var(--space-3);
    font-size: var(--step-4);
    font-weight: var(--weight-display);
    line-height: var(--leading-heading);
  }

  .ub-callout__media {
    width: 100%;
    max-width: 20rem;
    margin-inline: auto;
  }

  @media (min-width: 60rem) {
    .ub-callout__card {
      padding: var(--space-6);
    }

    .ub-callout__card--media {
      grid-template-columns: 3fr 2fr;
      align-items: center;
    }
  }

  /* ---------- The problem ---------- */

  .ub-problem__grid {
    display: grid;
    gap: var(--space-4);
  }

  .ub-problem__title {
    font-size: var(--step-5);
    line-height: var(--leading-tight);
  }

  .ub-problem--sticky .ub-problem__title::after {
    content: "";
    display: block;
    width: 4rem;
    height: 0.5rem;
    margin-top: var(--space-4);
    border: var(--border);
    border-radius: var(--radius-pill);
    background: var(--accent);
  }

  .ub-problem--sticky .ub-problem__body {
    max-width: var(--measure);
  }

  /* a table inside the body (Technical SEO, 2026-11-27) scrolls in its own frame, never the page */
  .ub-problem__body {
    min-width: 0;
  }

  .ub-problem--ink .ub-problem__title,
  .ub-problem--pull .ub-problem__title {
    max-width: 48rem;
    margin-inline: auto;
    text-align: center;
  }

  .ub-problem--pull .ub-problem__body {
    max-width: var(--measure);
    margin-inline: auto;
  }

  .ub-problem__last {
    max-width: 46rem;
    margin: var(--space-4) auto 0;
    padding-top: var(--space-5);
    border-top: var(--border);
    font-family: var(--font-heading);
    font-size: var(--step-4);
    font-weight: var(--weight-display);
    line-height: var(--leading-heading);
    text-align: center;
  }

  @media (min-width: 60rem) {
    .ub-problem--sticky .ub-problem__grid {
      grid-template-columns: 5fr 7fr;
      gap: var(--space-6);
      align-items: start;
    }

    .ub-problem--sticky .ub-problem__title {
      position: sticky;
      top: calc(var(--header-height) + var(--space-4));
    }

    .ub-problem--ink .ub-problem__body {
      columns: 3 16rem;
      column-gap: var(--space-5);
    }

    /* pretty: no paragraph ends on a lone word (design review 2026-10-22) */
    .ub-problem--ink .ub-problem__body > * {
      break-inside: avoid;
      text-wrap: pretty;
    }
  }

  /* ---------- What we do: three looks ---------- */

  .ub-do__item {
    display: grid;
    gap: var(--space-2);
    align-content: start;
  }

  .ub-do--numbers .ub-do__item {
    grid-template-columns: auto 1fr;
    column-gap: var(--space-3);
    padding-top: var(--space-3);
    border-top: var(--border);
  }

  .ub-do--numbers .ub-do__item > :not(.ub-do__mark) {
    grid-column: 2;
  }

  .ub-do--numbers .ub-do__mark {
    grid-row: span 2;
    width: auto;
    height: auto;
    border: 0;
    background: none;
    font-family: var(--font-heading);
    font-size: var(--step-5);
    font-weight: var(--weight-display);
    line-height: 1;
  }

  .ub-do--bubbles .ub-do__item {
    padding: var(--space-4);
    border: var(--border);
    border-radius: var(--radius-lg) var(--radius-lg) var(--radius-lg) 0.25rem;
    background: var(--accent-pale);
  }

  .ub-do--bubbles .ub-do__mark {
    background: var(--color-white);
  }

  /* ---------- Plan rail (the three search plans; --stops set inline) ---------- */

  .ub-rail__track {
    position: relative;
    display: grid;
    grid-template-columns: repeat(var(--stops, 3), 1fr);
    max-width: 48rem;
    margin: 0 auto var(--space-5);
  }

  .ub-rail__track::before,
  .ub-rail__fill {
    content: "";
    position: absolute;
    top: 1.125rem;
    right: calc(50% / var(--stops, 3));
    left: calc(50% / var(--stops, 3));
    height: 1px;
    background: var(--color-ink);
  }

  .ub-rail__fill {
    top: calc(1.125rem - 3px);
    left: calc((var(--from) + 0.5) * 100% / var(--stops, 3));
    height: 7px;
    border: var(--border);
    border-radius: var(--radius-pill);
    background: var(--accent);
    transform-origin: left;
  }

  .ub-rail__stop {
    position: relative;
    display: grid;
    justify-items: center;
    gap: var(--space-1);
  }

  .ub-rail__dot {
    width: 2.25rem;
    height: 2.25rem;
    border: var(--border);
    border-radius: 50%;
    background: var(--color-white);
  }

  .is-on > .ub-rail__dot {
    background: var(--accent);
  }

  .ub-rail__name {
    font-family: var(--font-heading);
    font-size: var(--step-1);
    font-weight: var(--weight-heading-sm);
  }

  .ub-rail__text {
    max-width: var(--measure);
    margin-inline: auto;
  }

  /* ---------- Partnership: the year ---------- */

  .ub-year {
    display: grid;
    gap: var(--space-2);
    max-width: 60rem;
    margin: 0 auto var(--space-6);
  }

  .ub-year__row {
    display: grid;
    grid-template-columns: 6rem 1fr;
    gap: var(--space-2);
    align-items: center;
  }

  .ub-year__name {
    font-size: var(--step--1);
    font-weight: 600;
  }

  .ub-year__ticks {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    font-size: var(--step--1);
    text-align: center;
  }

  .ub-year__track {
    position: relative;
    height: 2rem;
    border: var(--border);
    border-radius: var(--radius-pill);
    background: repeating-linear-gradient(90deg, transparent 0 calc(100% / 12 - 1px), color-mix(in srgb, var(--color-ink) 18%, transparent) 0 calc(100% / 12));
  }

  .ub-year__bar {
    position: absolute;
    inset: 4px;
    border: var(--border);
    border-radius: var(--radius-pill);
    transform-origin: left;
  }

  .ub-k0 {
    background: var(--color-brand);
  }

  .ub-k1 {
    background: var(--color-accent-2);
  }

  .ub-k2 {
    background: var(--color-butter);
  }

  .ub-k3 {
    background: var(--color-ink);
  }

  .ub-yr__key {
    display: inline-block;
    width: 0.875rem;
    height: 0.875rem;
    margin-right: 0.5rem;
    border: var(--border);
    border-radius: 50%;
  }

  @media (min-width: 48rem) {
    .ub-year__row {
      grid-template-columns: 8rem 1fr;
    }
  }

  /* ---------- Partnership: two ways in ---------- */

  .ub-ways__bar {
    display: block;
    width: 100%;
    max-width: 280px;
    height: auto;
    margin-bottom: var(--space-3);
  }

  .ub-ways__bar rect {
    stroke: var(--color-ink);
  }

  .ub-ways__year {
    fill: var(--accent);
  }

  .ub-ways__build {
    fill: var(--color-butter);
  }

  .ub-ways__title {
    margin-bottom: var(--space-2);
    font-size: var(--step-2);
    font-weight: var(--weight-heading);
  }

  /* ---------- Site Insight ---------- */

  .ub-bp__grid {
    display: grid;
    gap: var(--space-5);
  }

  .ub-bp__step {
    padding-block: var(--space-4);
    border-top: var(--border);
  }

  .ub-bp__label {
    margin-bottom: var(--space-2);
  }

  .ub-bp__media {
    width: 100%;
    max-width: 24rem;
    margin-inline: auto;
  }

  .ub-report {
    display: block;
    width: 100%;
    height: auto;
  }

  .ub-invest {
    text-align: center;
  }

  .ub-invest__fee {
    margin: 0 0 var(--space-3);
    color: var(--accent-on-ink, var(--accent));
    font-family: var(--font-heading);
    font-size: calc(var(--step-6) * 1.8);
    font-weight: var(--weight-display);
    line-height: 1;
  }

  .ub-invest__text {
    max-width: 46rem;
    margin-inline: auto;
  }

  @media (min-width: 60rem) {
    .ub-bp__grid {
      grid-template-columns: 7fr 5fr;
      gap: var(--space-6);
      align-items: start;
    }

    .ub-bp__steps {
      gap: 0;
    }
  }

  @media (min-width: 60rem) and (min-height: 50rem) {
    .ub-bp__media {
      position: sticky;
      top: calc(var(--header-height) + var(--space-4));
    }

    .ub-bp__step {
      min-height: 28vh;
    }
  }
}

@layer motion {
  @media screen and (prefers-reduced-motion: no-preference) {
    /* fx:diagrams (uplift-b) ---- The page graphics play on load like the tier
       diagram, element by element (--d on each element); the pins drop, the
       bubbles rise, the highlighter sweeps, the pin rings twice. The tier card
       plants grow as their card reveals; the Site Insight report fills in part
       by part as its step reveals (from 60rem). */
    html[data-fx~="diagrams"] .ub-pin {
      transform-box: fill-box;
      transform-origin: 50% 100%;
      animation: ub-drop 700ms var(--ease-pop) both;
    }

    html[data-fx~="diagrams"] .ub-pop {
      animation: ub-rise 600ms var(--ease-out) both;
    }

    html[data-fx~="diagrams"] .ub-hl {
      transform-box: fill-box;
      transform-origin: left;
      animation: ub-sweep 600ms var(--ease-out) both;
    }

    html[data-fx~="diagrams"] .ub-pulse {
      transform-box: fill-box;
      transform-origin: center;
      animation: ub-ring 1400ms var(--ease-out) 1.7s 2 both;
    }

    html[data-fx~="diagrams"] .ub-g [style] {
      animation-delay: var(--d);
    }

    html[data-fx~="diagrams"] .diagram:is(.ub-mini, .ub-glyph, .ub-report) * {
      animation: none;
    }

    html[data-fx~="diagrams"] .ub-tier__plant svg {
      transform-origin: 50% 100%;
      transition: transform 800ms var(--ease-pop) 250ms;
    }

    html.js-motion[data-fx~="diagrams"] [data-reveal]:not(.is-in) .ub-tier__plant svg {
      transform: scale(0.3);
    }

    @media (min-width: 60rem) {
      html[data-fx~="diagrams"] .ub-r {
        transition: opacity 500ms var(--ease-out), transform 700ms var(--ease-pop);
      }

      html.js-motion[data-fx~="diagrams"] .ub-bp:has(.ub-bp__step:nth-child(1)[data-reveal]:not(.is-in)) .ub-r1,
      html.js-motion[data-fx~="diagrams"] .ub-bp:has(.ub-bp__step:nth-child(2)[data-reveal]:not(.is-in)) .ub-r2,
      html.js-motion[data-fx~="diagrams"] .ub-bp:has(.ub-bp__step:nth-child(3)[data-reveal]:not(.is-in)) .ub-r3 {
        opacity: 0;
        transform: translateY(18px);
      }
    }

    @keyframes ub-drop {
      from {
        opacity: 0;
        transform: translateY(-40px);
      }
    }

    @keyframes ub-rise {
      from {
        opacity: 0;
        transform: translateY(12px);
      }
    }

    @keyframes ub-sweep {
      from {
        transform: scaleX(0);
      }
    }

    @keyframes ub-ring {
      from {
        opacity: 0.8;
        transform: scale(1);
      }

      to {
        opacity: 0;
        transform: scale(2.4);
      }
    }
    /* /fx:diagrams */

    /* fx:timeline (uplift-b) ---- Lines that fill: the step rules draw, the tier
       rail fills from the first tier that includes the service, and the
       partnership year's lanes fill across the twelve months (with the scroll
       where scroll-driven animations exist, else once the chart reveals). */
    html[data-fx~="timeline"] :is(.ub-rail__fill, .ub-year__bar),
    html[data-fx~="timeline"] .ub-steps__item::before {
      transition: transform 1100ms var(--ease-out) 200ms;
    }

    html.js-motion[data-fx~="timeline"] [data-reveal]:not(.is-in) :is(.ub-rail__fill, .ub-year__bar),
    html.js-motion[data-fx~="timeline"] .ub-steps__item[data-reveal]:not(.is-in)::before {
      transform: scaleX(0);
    }

    .ub-year__row:nth-child(3) .ub-year__bar {
      transition-delay: 350ms;
    }

    .ub-year__row:nth-child(4) .ub-year__bar {
      transition-delay: 500ms;
    }

    .ub-year__row:nth-child(5) .ub-year__bar {
      transition-delay: 650ms;
    }

    @supports (animation-timeline: view()) {
      html.js-motion[data-fx~="timeline"] .ub-year__bar {
        animation: ub-sweep linear both;
        animation-timeline: view();
        animation-range: entry 60% cover 50%;
      }

      html.js-motion[data-fx~="timeline"] .ub-year__row:nth-child(n + 4) .ub-year__bar {
        animation-range: entry 80% cover 58%;
      }
    }
    /* /fx:timeline */

    .ub-routes__card {
      transition: translate 200ms var(--ease-out);
    }

    .ub-routes__card:focus-within {
      translate: 0 -4px;
    }

    @media (hover: hover) {
      .ub-routes__card:hover {
        translate: 0 -4px;
      }
    }
  }
}
