/* ==========================================================================
   Responsive — mobile-first, min-width queries only.

   Tier            Range           Query                     Driven by
   Mobile          < 768px         (base styles)             single column, off-canvas nav
   Tablet          768 – 1023px    @media (min-width: 48em)  2–3 column grids, side-by-side header/footer
   Desktop         1024 – 1439px   @media (min-width: 64em)  inline nav, split layouts, 6-up service row
   Large desktop   ≥ 1440px        @media (min-width: 90em)  the design artboard: all tokens at maximum,
                                                             content fixed at 1280px, extra width → margins

   Fluid tokens (clamp) scale type, gutters and section padding between
   375px and 1440px, so these queries only change layout.
   Keep breakpoint values in sync with css/variables.css and js/navigation.js.
   ========================================================================== */

/* ==========================================================================
   Tablet — 768px+
   ========================================================================== */
@media (min-width: 48em) {
  /* Grids */
  .grid--2,
  .grid--3,
  .grid--4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .grid--5 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .grid--6 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  /* Section header: action aligns right of the title */
  .section-header:not(.section-header--center) {
    flex-direction: row;
    align-items: flex-end;
    justify-content: space-between;
    gap: var(--space-6);
  }

  .section-header__action {
    flex-shrink: 0;
  }

  /* CTA block: content left, button right. When the actions (e.g. a button plus a text link)
     cannot sit beside at least 16rem of content, they wrap below it instead of being clipped. */
  .cta-block__inner {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-6) var(--space-8);
  }

  .cta-block__content {
    flex: 1 1 16rem;
  }

  /* Connection map: areas on a ring around the centre, joined by spokes */
  .connection-map {
    position: relative;
    display: block;
    width: 100%;
    max-width: 32rem;
    aspect-ratio: 1;
    margin-inline: auto;
    container-type: inline-size;
  }

  .connection-map::before {
    content: "";
    position: absolute;
    inset: 13%;
    border: var(--border-width) dashed var(--color-border-control);
    border-radius: 50%;
  }

  .connection-map__center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
  }

  .connection-map__areas {
    position: absolute;
    inset: 0;
    display: block;
  }

  .connection-map__area {
    --angle: calc(360deg / var(--count) * var(--i) - 90deg);
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
  }

  .connection-map__area::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: var(--ring-radius, 37cqi);
    height: var(--border-width-thick);
    background: linear-gradient(90deg, transparent 20%, var(--accent));
    opacity: 0.55;
    transform-origin: 0 50%;
    transform: rotate(var(--angle));
  }

  .connection-map__area > span {
    position: absolute;
    top: 0;
    left: 0;
    transform: rotate(var(--angle)) translateX(var(--ring-radius, 37cqi)) rotate(calc(var(--angle) * -1)) translate(-50%, -50%);
  }

  /* Connection map mesh: a hub at the centre joins every area; spokes run the full way to it */

  /* Ring radius: the default 37% of the map, reduced only when the widest side label (up to ~13rem,
     sitting 0.866 × radius sideways at 30° from vertical) would otherwise reach the map's edge.
     Keeps every label inside the diagram with a margin at any column width. */
  .connection-map--mesh {
    --ring-radius: min(37cqi, calc((50cqi - 7.5rem) / 0.866));
  }

  /* Fit: long labels wrap (max 9rem wide), so the ring only needs room for ~4.5rem either side */
  .connection-map--fit {
    --ring-radius: min(37cqi, calc((50cqi - 5rem) / var(--ring-spread, 0.866)));
  }

  .connection-map--fit .connection-map__area > span {
    width: max-content;
    max-width: 9rem;
    white-space: normal;
    text-align: center;
    line-height: var(--line-height-snug);
  }

  .connection-map--mesh::before,
  .connection-map--fit::before {
    inset: calc(50% - var(--ring-radius));
  }

  /* Legal pages: contact details as label | value rows */
  .legal-details__row {
    grid-template-columns: 13rem minmax(0, 1fr);
  }

  /* Form grid: paired fields side by side; .form-grid__full spans both columns */
  .form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .form-grid__full {
    grid-column: 1 / -1;
  }

  .form-panel {
    padding: var(--space-8) var(--space-7);
  }

  /* Perspective panels (three): two side by side, the combined one full width below */
  .perspectives--three {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .perspectives--three .perspectives__panel--featured {
    grid-column: 1 / -1;
  }

  /* Outcome modules: two per row; an odd last tile spans the row */
  .outcome-list--modules {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .outcome-list--modules .outcome:last-child:nth-child(odd) {
    grid-column: 1 / -1;
  }

  /* Outcome list: title and text side by side in each row */
  .outcome-list--list .outcome {
    display: grid;
    grid-template-columns: 12rem minmax(0, 1fr);
    column-gap: var(--space-5);
    align-items: baseline;
  }
  .connection-map--mesh .connection-map__hub {
    position: absolute;
    top: 50%;
    left: 50%;
    z-index: 1;
    display: block;
    width: 1.25rem;
    height: 1.25rem;
    background-color: var(--color-primary);
    border-radius: 50%;
    box-shadow: 0 0 0 var(--space-2) color-mix(in srgb, var(--color-accent-violet) 18%, transparent);
    transform: translate(-50%, -50%);
  }

  .connection-map--mesh .connection-map__area::before {
    background: linear-gradient(90deg, color-mix(in srgb, var(--accent) 35%, transparent), var(--accent));
  }

  /* Outcome cycle: 2 × 2, read clockwise (1 → 2 ↓ 3 ← 4 ↑ back to 1) */
  .outcome-list--cycle .outcome:nth-child(3) { grid-row: 2; grid-column: 2; }
  .outcome-list--cycle .outcome:nth-child(4) { grid-row: 2; grid-column: 1; }

  .outcome-list--cycle .outcome:nth-child(1)::after {
    content: "→" / "";
    top: 50%;
    left: calc(100% + var(--grid-gap) / 2);
  }

  .outcome-list--cycle .outcome:nth-child(3)::after {
    content: "←" / "";
    top: 50%;
    left: calc(var(--grid-gap) / -2);
  }

  .outcome-list--cycle .outcome:nth-child(4)::after {
    content: "↑" / "";
    top: calc(var(--grid-gap) / -2);
    left: 50%;
    transform: translate(-50%, -50%);
  }

  /* Scope grid: two tiles per row */
  .scope-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  /* Stats side by side */
  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  /* Footer: three link columns; bottom bar on one line */
  .site-footer__nav {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .site-footer__bottom {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2) var(--space-6);
  }
}

/* ==========================================================================
   Desktop — 1024px+
   ========================================================================== */
@media (min-width: 64em) {
  /* Two-statement hero title: one statement per line in the split hero column */
  .hero__title--statements {
    font-size: calc(var(--font-size-h1) * 0.94);
  }

  :root {
    --logo-height: var(--logo-height-lg);
    --header-height: var(--header-height-lg);
  }

  /* Grids reach their full column counts */
  .grid--3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

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

  /* 5-up rows need ≥ 1440px to stay readable; 3-up until then */
  .grid--5 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

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

  /* Two-column split; --split-ratio sets the first column's share */
  .split {
    grid-template-columns: minmax(0, var(--split-ratio, 1fr)) minmax(0, 1fr);
    gap: var(--split-gap, var(--space-9));
  }

  .split--reverse > :first-child {
    order: 2;
  }

  /* ---------- Header: inline navigation bar ----------------------------- */
  .nav-toggle {
    display: none;
  }

  .no-js .site-header__inner {
    flex-wrap: nowrap;
    padding-block: 0;
  }

  .site-nav,
  .site-nav.is-open,
  .no-js .site-nav {
    position: static;
    flex: 1;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-5);
    width: auto;
    padding: 0;
    background: none;
    overflow: visible;
    visibility: visible;
    opacity: 1;
    transform: none;
    transition: none;
  }

  .site-nav__list {
    flex-direction: row;
    align-items: center;
    gap: var(--nav-item-gap);
    margin-inline: auto;
  }

  .site-nav__item {
    position: relative;
    border: 0;
  }

  .site-nav__row {
    gap: 0;
  }

  .site-nav__link {
    padding: var(--space-2) 0;
    font-size: var(--font-size-nav);
    font-weight: var(--font-weight-medium);
    line-height: var(--line-height-none);
    white-space: nowrap;
  }

  /* Current page/section: blue underline under the label, as in the reference */
  .site-nav__link[aria-current] {
    color: var(--color-text-primary);
  }

  .site-nav__link::after {
    content: "";
    position: absolute;
    inset: auto 0 calc(var(--space-1) * -1);
    height: var(--border-width-thick);
    background-color: var(--color-secondary);
    border-radius: var(--radius-pill);
    transform: scaleX(0);
    transition: transform var(--transition-duration) var(--transition-easing);
  }

  .site-nav__link[aria-current]::after {
    transform: scaleX(1);
  }

  /* Compact chevron button: 24px target (WCAG 2.2 minimum) */
  .site-nav__toggle {
    width: 1.5rem;
    height: 1.5rem;
    border-radius: var(--radius-sm);
  }

  .site-nav__chevron {
    width: 0.375rem;
    height: 0.375rem;
    border-width: 1.5px;
  }

  /* Dropdown panel */
  .site-nav__menu {
    position: absolute;
    top: 100%;
    left: calc(var(--space-3) * -1);
    z-index: var(--z-overlay);
    display: block;
    width: max-content;
    min-width: 15rem;
    max-width: 20rem;
    margin: var(--space-4) 0 0;
    padding: var(--space-2);
    background-color: var(--color-background);
    border: var(--border-width) solid var(--color-border-strong);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-md);
    visibility: hidden;
    opacity: 0;
    transform: translateY(-0.25rem);
    transition:
      opacity var(--transition-duration-fast) var(--transition-easing),
      transform var(--transition-duration-fast) var(--transition-easing),
      visibility 0s linear var(--transition-duration-fast);
  }

  /* Invisible bridge over the gap so the pointer can travel into the menu */
  .site-nav__menu::before {
    content: "";
    position: absolute;
    inset: calc(var(--space-4) * -1 - var(--border-width)) 0 auto;
    height: var(--space-4);
  }

  .site-nav__item.is-open > .site-nav__menu,
  .no-js .site-nav__item:hover > .site-nav__menu,
  .no-js .site-nav__item:focus-within > .site-nav__menu {
    visibility: visible;
    opacity: 1;
    transform: none;
    transition-delay: 0s;
  }

  .site-nav__menu-link {
    padding: var(--space-3);
    font-size: var(--font-size-small);
    color: var(--color-text-primary);
    border-radius: var(--radius-sm);
  }

  .site-nav__menu-link:hover {
    background-color: var(--color-background-alt);
  }

  .site-nav__menu-link[aria-current="page"] {
    background-color: var(--color-background-alt);
  }

  .no-js .site-nav__toggle {
    display: inline-flex;
  }

  /* CTA: compact header size, right-aligned */
  .site-nav__cta {
    width: auto;
    flex-shrink: 0;
    min-height: var(--button-height-sm);
    padding-inline: var(--button-padding-x-sm);
  }

  /* ---------- Hero: media fills the right side and fades into the page -- */
  .hero {
    display: flex;
    align-items: center;
    min-height: clamp(30rem, 36vw, 32.5rem); /* reference hero band: ≈ 520px at 1440 */
  }

  .hero__inner {
    padding-block: var(--space-9);
  }

  .hero__content {
    max-width: 37rem;
  }

  /* The image starts at 42% of the width, or just before the end of the text column if that is
     further right (laptop widths, ~1024–1250 px), so the intro text never runs into the image.
     Text column end = container offset + container padding + .hero__content max-width (37rem);
     the 1.5rem overlap only reaches the near-white start of the fade. */
  .hero__media {
    position: absolute;
    inset: 0 0 0 max(42%, calc(max(0px, (100vw - var(--container-max) - 2 * var(--container-padding)) / 2) + var(--container-padding) + 37rem - 1.5rem));
    aspect-ratio: auto;
    max-height: none;
  }

  .hero__media::after {
    background: linear-gradient(90deg, var(--color-background) 0%, color-mix(in srgb, var(--color-background) 60%, transparent) 9%, transparent 30%);
  }

  /* ---------- Page hero: text and contained image side by side -------- */
  .hero--page {
    display: block;
    min-height: 0;
  }

  .hero--page .hero__grid {
    grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
    gap: var(--space-9);
  }

  /* ---------- Service families: one row per family --------------------- */
  .family {
    grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr) minmax(0, 0.9fr);
    column-gap: var(--space-9);
    align-items: start;
    padding: var(--space-8) var(--space-7) var(--space-8) var(--space-8);
  }

  /* ---------- Scope grid: four tiles per row ---------------------------- */
  .scope-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  /* ---------- Process chevrons: one arrow row ---------------------------- */
  .chevrons {
    grid-template-columns: repeat(var(--count), minmax(0, 1fr));
    gap: var(--space-2);
  }

  .chevron__head {
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    gap: 0;
    min-height: 4.75rem;
    padding-inline: var(--space-7) var(--space-6);
    border-radius: 0;
    clip-path: polygon(0 0, calc(100% - 1rem) 0, 100% 50%, calc(100% - 1rem) 100%, 0 100%, 1rem 50%);
  }

  .chevron:first-child .chevron__head {
    padding-inline-start: var(--space-5);
    clip-path: polygon(0 0, calc(100% - 1rem) 0, 100% 50%, calc(100% - 1rem) 100%, 0 100%);
  }

  .chevron__title {
    font-size: var(--font-size-body);
  }

  .chevron__text {
    padding-inline: var(--space-2) var(--space-4);
  }

  /* ---------- Architecture view: considerations around the system ------- */
  .arch {
    grid-template-columns: minmax(0, 1fr) var(--arch-column) minmax(0, 1fr);
    gap: 0 var(--space-8);
  }

  .arch__layers {
    grid-column: 2;
    grid-row: 1;
  }

  /* Layers only (no considerations): a single column */
  .arch--simple {
    grid-template-columns: minmax(0, 1fr);
  }

  .arch--simple .arch__layers {
    grid-column: 1;
  }

  /* The support wrapper steps aside so its list can share the diagram's row */
  .arch__support {
    display: contents;
  }

  .arch__support-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .arch__considerations {
    grid-column: 1 / -1;
    grid-row: 1;
    display: grid;
    grid-template-columns: minmax(0, 1fr) var(--arch-column) minmax(0, 1fr);
    grid-template-rows: repeat(4, auto);
    align-content: space-evenly;
    gap: var(--space-4) var(--space-8);
    pointer-events: none;
  }

  .arch__consideration { pointer-events: auto; }
  .arch__consideration:nth-child(-n + 4) { grid-column: 1; justify-self: end; }
  .arch__consideration:nth-child(n + 5) { grid-column: 3; justify-self: start; }
  .arch__consideration:is(:nth-child(1), :nth-child(5)) { grid-row: 1; }
  .arch__consideration:is(:nth-child(2), :nth-child(6)) { grid-row: 2; }
  .arch__consideration:is(:nth-child(3), :nth-child(7)) { grid-row: 3; }
  .arch__consideration:nth-child(4) { grid-row: 4; }

  /* Dashed link from each consideration to the system boundary */
  .arch__consideration::after {
    content: "";
    position: absolute;
    top: 50%;
    width: var(--space-8);
    border-block-start: var(--border-width) dashed var(--arch-line);
  }

  .arch__consideration:nth-child(-n + 4)::after { left: 100%; }
  .arch__consideration:nth-child(n + 5)::after { right: 100%; }

  /* ---------- Transition path: one row, arrows between stages ----------- */
  .transition {
    grid-template-columns: repeat(var(--count), minmax(0, 1fr));
  }

  .transition__stage:not(:last-child)::after {
    content: "→" / "";
    top: 50%;
    left: 100%;
    width: var(--space-7);
    line-height: 1;
    text-align: center;
    transform: translateY(-50%);
  }

  /* ---------- Step axis: nodes on a horizontal axis, details alternate -- */
  .axis {
    grid-template-columns: repeat(var(--count), minmax(0, 1fr));
    gap: 0 var(--space-5);
  }

  .axis::before {
    inset-block: 50% auto;
    inset-inline: 0;
    width: auto;
    height: 2px;
    transform: translateY(-50%);
  }

  .axis__step {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 1fr auto 1fr;
    row-gap: var(--space-4);
    justify-items: center;
    text-align: center;
  }

  .axis__node { grid-row: 2; }

  .axis__step:nth-child(odd) .axis__body {
    grid-row: 1;
    align-self: end;
  }

  .axis__step:nth-child(even) .axis__body {
    grid-row: 3;
    align-self: start;
    padding-block-start: 0;
  }

  /* ---------- Perspective panels ------------------------------------------ */
  /* Two panels with the centre label between them, joined by short lines */
  .perspectives--two {
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: stretch;
    column-gap: var(--space-7);
  }

  .perspectives--two .perspectives__center {
    align-self: center;
  }

  .perspectives--two .perspectives__center > span::before,
  .perspectives--two .perspectives__center > span::after {
    content: "";
    position: absolute;
    top: 50%;
    width: var(--space-7);
    border-block-start: var(--border-width-thick) dashed var(--color-border-inverse);
  }

  .perspectives--two .perspectives__center > span::before { right: 100%; }
  .perspectives--two .perspectives__center > span::after { left: 100%; }

  /* Three panels: the featured (combined) panel in the visual centre, joined to both sides */
  .perspectives--three {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    column-gap: var(--space-7);
  }

  .perspectives--three .perspectives__panel--featured {
    position: relative;
    grid-column: 2;
    grid-row: 1;
  }

  .perspectives--three .perspectives__panel--featured::before,
  .perspectives--three .perspectives__panel--featured::after {
    content: "";
    position: absolute;
    top: 50%;
    width: var(--space-7);
    border-block-start: var(--border-width-thick) dashed var(--color-border-control);
  }

  .perspectives--three .perspectives__panel--featured::before { right: 100%; }
  .perspectives--three .perspectives__panel--featured::after { left: 100%; }

  /* ---------- Outcome modules: 2 wide tiles, then 3 (five items) --------- */
  .outcome-list--modules {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  .outcome-list--modules .outcome:nth-child(-n + 2) { grid-column: span 3; }
  .outcome-list--modules .outcome:nth-child(n + 3) { grid-column: span 2; }
  .outcome-list--modules .outcome:last-child:nth-child(odd) { grid-column: span 2; }

  /* ---------- Equation: inputs in one row, "+" between them -------------- */
  .equation__inputs {
    flex-direction: row;
    width: 100%;
    max-width: 56rem;
  }

  .equation__input {
    flex: 1 1 0;
    min-width: 13rem;
  }

  .equation__input + .equation__input::before {
    bottom: auto;
    top: 50%;
    left: auto;
    right: 100%;
    width: var(--space-6);
    line-height: 1;
    text-align: center;
    transform: translateY(-50%);
  }

  /* ---------- Steps: horizontal flow with connectors -------------------- */
  .steps {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: var(--space-6);
  }

  .step {
    grid-template-columns: minmax(0, 1fr);
    row-gap: var(--space-3);
  }

  .step__marker {
    grid-row: auto;
    margin-block-end: var(--space-2);
  }

  .step__title {
    align-self: start;
  }

  .step:not(:last-child)::before {
    inset: calc(var(--step-marker) / 2 - 1px) calc(var(--space-6) * -1 + var(--space-2)) auto calc(var(--step-marker) + var(--space-2));
    border-inline-start: 0;
    border-block-start: var(--border-width-thick) solid var(--color-border-strong);
  }


  /* ---------- Legal pages: sticky contents beside the reading column ---- */
  .legal-layout {
    grid-template-columns: 16rem minmax(0, var(--container-narrow));
    gap: var(--space-10);
    align-items: start;
  }

  .legal-layout__aside {
    position: sticky;
    top: calc(var(--header-height) + var(--space-6));
  }

  /* Long contents lists scroll inside the box on short screens */
  .legal-toc {
    max-height: calc(100vh - var(--header-height) - var(--space-6) * 2);
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  /* ---------- Footer: brand column + three link columns ----------------- */
  .site-footer__main {
    grid-template-columns: minmax(15rem, 1.2fr) minmax(0, 3fr);
    column-gap: var(--space-9);
  }
}

/* ==========================================================================
   Large desktop — 1440px+ (the design artboard)
   ========================================================================== */
@media (min-width: 90em) {
  .grid--5 {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
}
