/* ==========================================================================
   Trading page
   ========================================================================== */

/* --------------------------------------------------------------------------
   Hero: diagonal split
   Text on the left; on the right a photo whose left edge is cut at 75°.
   On smaller screens the photo sits below the text with a gently slanted
   top edge.
   -------------------------------------------------------------------------- */

.trade-hero {
  position: relative;
  isolation: isolate;
  padding-top: calc(var(--header-height) + var(--space-8));

  @media (width >= 64rem) {
    display: grid;
    align-items: center;
    min-height: clamp(38rem, 100svh, 52rem);
    padding-block: var(--header-height) 0;
  }
}

.trade-hero__content {
  display: grid;
  justify-items: start;
  gap: var(--space-5);
  max-width: 36rem;

  @media (width >= 64rem) {
    /* Stay clear of the photo, which starts at the middle of the screen */
    max-width: min(38rem, 46vw - var(--gutter));
    padding-block: var(--space-8);
  }
}

/* Sized so each sentence stays on one line beside the photo on desktop */
.trade-hero__title {
  font-size: clamp(2.25rem, 1.25rem + 2.2vw, 3.25rem);
}

/* Each line sits in its own mask so it can slide up into view */
.trade-hero__line,
.trade-cta__line {
  display: block;
  overflow: clip;
  padding-bottom: 0.08em;
  margin-bottom: -0.08em;
}

.trade-hero__line-inner,
.trade-cta__line-inner {
  display: block;
}

.trade-hero__note {
  max-width: 32rem;
  color: var(--ink-500);
}

.trade-hero__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-top: var(--space-2);
}

/* ---- Photo with the diagonal cut ---- */

.trade-hero__media {
  position: relative;
  z-index: -1;
  aspect-ratio: 4 / 3;
  margin-top: var(--space-8);

  @media (width >= 40rem) {
    aspect-ratio: 16 / 9;
  }

  @media (width >= 64rem) {
    position: absolute;
    inset: var(--header-height) 0 0 auto;
    width: 50%;
    aspect-ratio: auto;
    margin-top: 0;
    /* Lets the photo size its cut from this box's height (cqh) */
    container-type: size;
  }
}

.trade-hero__photo {
  position: absolute;
  inset: 0;
  clip-path: polygon(0 14%, 100% 0, 100% 100%, 0 100%);

  /* A 75° edge: the top corner sits height ÷ tan(75°) in from the bottom one */
  @media (width >= 64rem) {
    clip-path: polygon(calc(100cqh / tan(75deg)) 0, 100% 0, 100% 100%, 0 100%);
  }

  img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;

    /* The near-square desktop frame keeps the container's right door in view;
       its left door falls behind the diagonal cut anyway */
    @media (width >= 64rem) {
      object-position: 85% 50%;
    }
  }
}

/* --------------------------------------------------------------------------
   Capabilities: sticky photo beside a scrolling list
   Desktop: the photo frame stays in view while the list scrolls; the item in
   the middle of the screen is active and the others dim (trading.js adds
   .is-interactive). The frame repeats the hero's 75° cut, mirrored.
   Mobile: a plain list where every item shows its own photo.
   -------------------------------------------------------------------------- */

.capabilities__title {
  max-width: 36rem;
  margin-bottom: var(--space-8);
}

.capabilities__body {
  /* Height of the sticky photo frame */
  --frame-h: min(68svh, 38rem);

  @media (width >= 64rem) {
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-items: start;
    gap: clamp(var(--space-7), 6vw, var(--space-10));
  }
}

/* ---- Sticky photo frame (desktop only) ---- */

.capabilities__media {
  display: none;

  @media (width >= 64rem) {
    position: sticky;
    /* Centred in the space below the header */
    top: calc(var(--header-height) + (100svh - var(--header-height) - var(--frame-h)) / 2);
    display: block;
    height: var(--frame-h);
    /* Lets the frame size its cut from this box's height (cqh) */
    container-type: size;
  }
}

.capabilities__frame {
  position: absolute;
  inset: 0;
  background: var(--surface-alt);
  /* The right edge leans at 75°, parallel to the hero's cut */
  clip-path: polygon(0 0, 100% 0, calc(100% - 100cqh / tan(75deg)) 100%, 0 100%);

  img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  /* Only the first photo shows until trading.js takes over */
  img:not(:first-child) {
    visibility: hidden;
  }
}

/* ---- The list ---- */

.capabilities__list-wrap {
  position: relative;

  @media (width >= 64rem) {
    padding-left: var(--space-7);
  }
}

/* Thin track beside the list; its green fill follows the scroll (trading.js) */
.capabilities__progress {
  display: none;

  @media (width >= 64rem) {
    position: absolute;
    inset-block: 0;
    left: 0;
    display: block;
    width: 2px;
    background: var(--line);

    span {
      display: block;
      height: 100%;
      background: var(--brand-green);
      transform-origin: top;
    }
  }
}

.capabilities__list {
  display: grid;
  gap: var(--space-9);

  @media (width >= 64rem) {
    gap: 0;
  }
}

.capability {
  @media (width >= 64rem) {
    /* Tall enough that each item holds the middle of the screen for a while */
    display: grid;
    align-content: center;
    min-height: 60svh;
  }
}

/* Dim every item except the active one (desktop, once trading.js runs) */
.capabilities.is-interactive .capability {
  opacity: 0.3;
  transition: opacity 0.5s var(--ease-out);

  &.is-active {
    opacity: 1;
  }
}

/* Each item's own photo, with a slanted top edge (mobile only) */
.capability__photo {
  aspect-ratio: 4 / 3;
  margin-bottom: var(--space-5);
  clip-path: polygon(0 10%, 100% 0, 100% 100%, 0 100%);
  background: var(--surface-alt);

  @media (width >= 40rem) {
    aspect-ratio: 16 / 9;
  }

  @media (width >= 64rem) {
    display: none;
  }

  img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }
}

.capability__title {
  margin-bottom: var(--space-3);
}

.capability__text {
  max-width: 32rem;
  color: var(--ink-700);
}

.capability__tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-5);

  li {
    padding: 0.35em 0.9em;
    border: 1px solid var(--line);
    border-radius: var(--radius-pill);
    font-size: var(--fs-xs);
    font-weight: 500;
    color: var(--ink-700);
  }
}

/* --------------------------------------------------------------------------
   Product categories: bento grid of photo tiles, then a call to action
   Desktop: two rows of mixed widths (5/4/3 and 3/4/5 of 12 columns).
   Tablet: three per row. Phone: two per row, square.
   -------------------------------------------------------------------------- */

.categories__head {
  display: grid;
  gap: var(--space-4);
  margin-bottom: var(--space-8);

  @media (width >= 64rem) {
    grid-template-columns: 7fr 5fr;
    align-items: end;
    gap: var(--space-9);
  }
}

.categories__title {
  max-width: 40rem;
}

.categories__intro {
  max-width: 30rem;
  color: var(--ink-700);
}

.categories__grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-2);

  @media (width >= 40rem) {
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-3);
  }

  @media (width >= 64rem) {
    grid-template-columns: repeat(12, 1fr);
    grid-auto-rows: clamp(16rem, 26vw, 22rem);
  }
}

.category {
  position: relative;
  overflow: clip;
  aspect-ratio: 1;
  background: var(--surface-alt);

  @media (width >= 40rem) {
    aspect-ratio: 4 / 5;
  }

  @media (width >= 64rem) {
    aspect-ratio: auto;
  }

  img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  /* Dark fade at the bottom so the white name stays readable */
  &::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(to top, rgb(11 31 23 / 0.85), rgb(11 31 23 / 0.35) 45%, rgb(11 31 23 / 0) 75%);
    transition: opacity var(--duration-base) ease;
    opacity: 0.9;
  }

  &:hover::after {
    opacity: 1;
  }
}

/* Mixed widths on desktop */
@media (width >= 64rem) {
  .category--lifestyle,
  .category--retail {
    grid-column: span 5;
  }

  .category--electronics,
  .category--textiles {
    grid-column: span 4;
  }

  .category--industrial,
  .category--construction {
    grid-column: span 3;
  }
}

.category__name {
  position: absolute;
  inset: auto var(--space-4) var(--space-4);
  z-index: 1;
  max-width: 16rem;
  font-size: var(--fs-base);
  color: var(--surface);

  @media (width >= 40rem) {
    inset: auto var(--space-5) var(--space-5);
    font-size: var(--fs-md);
  }
}

/* ---- Closing row: a thin rule, the question, and the button ---- */

.categories__cta {
  display: grid;
  justify-items: start;
  gap: var(--space-5);
  margin-top: var(--space-7);
  padding-top: var(--space-6);
  border-top: 1px solid var(--line);

  @media (width >= 48rem) {
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: var(--space-7);
  }
}

.categories__cta-text {
  max-width: 40rem;
  color: var(--ink-700);

  strong {
    display: block;
    margin-bottom: var(--space-1);
    font-family: var(--font-display);
    font-size: var(--fs-lg);
    font-weight: 600;
    color: var(--ink-900);
  }
}

/* --------------------------------------------------------------------------
   Sourcing markets: accurate map of south-east China beside the city list
   Desktop: text on the left, map on the right. Mobile: heading, map, list.
   Hovering (or tapping) a city lights it up on the map and in the list.
   -------------------------------------------------------------------------- */

.markets__inner {
  display: grid;
  grid-template-areas:
    "head"
    "map"
    "list"
    "note";
  gap: var(--space-6);

  @media (width >= 64rem) {
    grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
    grid-template-rows: auto auto 1fr;
    grid-template-areas:
      "head head"
      "list map"
      "note map";
    column-gap: clamp(var(--space-7), 6vw, var(--space-10));
    row-gap: var(--space-6);
  }
}

.markets__head {
  grid-area: head;
  display: grid;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}

.markets__title {
  max-width: 44rem;
}

.markets__intro {
  max-width: 30rem;
  color: var(--ink-700);
}

/* ---- The list ---- */

.markets__list {
  grid-area: list;
  border-bottom: 1px solid var(--line);
}

.market {
  padding-block: var(--space-4);
  border-top: 1px solid var(--line);
}

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

.market__name {
  font-size: var(--fs-lg);
  transition: color var(--duration-fast) ease;

  .market.is-active & {
    color: var(--brand-green);
  }
}

.market__coords {
  font-size: var(--fs-xs);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  color: var(--ink-500);
  white-space: nowrap;
}

.market__text {
  margin-top: var(--space-1);
  color: var(--ink-700);
}

.markets__note {
  grid-area: note;
  max-width: 30rem;
  font-size: var(--fs-sm);
  color: var(--ink-500);
}

/* ---- The map ---- */

.markets__map {
  grid-area: map;
  position: relative;
  overflow: clip;
  /* Same proportions as the generated map */
  aspect-ratio: 560 / 480;
  /* Sea: a pale tint of the brand blue */
  background: color-mix(in srgb, var(--brand-blue) 7%, var(--surface));

  @media (width >= 64rem) {
    align-self: center;
  }
}

.markets__svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.markets__grid {
  fill: none;
  stroke: color-mix(in srgb, var(--brand-blue) 14%, var(--surface));
  stroke-width: 1;
}

.markets__grid-labels {
  font: 500 10px var(--font-body);
  letter-spacing: 0.04em;
  fill: #7f9bb0;

  /* Too small to read on phones */
  @media (width < 40rem) {
    display: none;
  }
}

.markets__land {
  fill: var(--surface-alt);
}

.markets__coast {
  fill: none;
  stroke: #9fb0a7;
  stroke-width: 1;
  stroke-linejoin: round;
}

.markets__sea {
  position: absolute;
  left: var(--x);
  top: var(--y);
  translate: -50% -50%;
  font-size: var(--fs-xs);
  font-weight: 500;
  letter-spacing: var(--tracking-label);
  line-height: 1.4;
  text-transform: uppercase;
  color: #7f9bb0;
  white-space: nowrap;
}

.markets__sea--east {
  left: auto;
  right: 4%;
  /* Between the 28°N and 26°N grid lines, clear of their labels */
  top: 37.5%;
  translate: 0 -50%;
  text-align: right;
}

/* Pin: a green dot with a white ring; the active one grows and pulses */
.markets__pin {
  position: absolute;
  left: var(--x);
  top: var(--y);
  z-index: 1;
  cursor: pointer;

  &::before,
  &::after {
    content: "";
    position: absolute;
    width: 0.8rem;
    height: 0.8rem;
    translate: -50% -50%;
    border-radius: 50%;
  }

  &::before {
    background: var(--brand-green);
    box-shadow: 0 0 0 3px var(--surface), 0 2px 8px rgb(15 26 23 / 0.25);
    transition: scale var(--duration-fast) var(--ease-out);
  }

  &::after {
    border: 2px solid var(--brand-green);
    opacity: 0;
  }

  &.is-active::before {
    scale: 1.35;
  }

  @media (prefers-reduced-motion: no-preference) {
    &.is-active::after {
      animation: markets-ripple 1.6s ease-out infinite;
    }
  }
}

@keyframes markets-ripple {
  from {
    scale: 1;
    opacity: 0.7;
  }

  to {
    scale: 3.2;
    opacity: 0;
  }
}

.markets__pin-label {
  position: absolute;
  top: 0;
  left: 0.95rem;
  translate: 0 -50%;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--ink-900);
  white-space: nowrap;
  transition: color var(--duration-fast) ease;

  .markets__pin--left & {
    left: auto;
    right: 0.95rem;
  }

  .markets__pin.is-active & {
    color: var(--brand-green);
  }
}

/* Map parts start hidden until the entrance animation runs (trading.js) */
@media (prefers-reduced-motion: no-preference) {
  .js .markets__map [data-map-reveal] {
    visibility: hidden;
  }
}

/* --------------------------------------------------------------------------
   Our process: rising steps
   Each step stands taller (desktop, tablet) or wider (phone) than the one
   before, set by --rise (0 to 3), and its tint deepens a little each time.
   -------------------------------------------------------------------------- */

.process__title {
  max-width: 36rem;
  margin-bottom: var(--space-8);
}

.process__steps {
  display: grid;
  gap: var(--space-3);

  @media (width >= 40rem) {
    grid-template-columns: repeat(2, 1fr);
    align-items: end;
    gap: var(--space-4) var(--space-3);
  }

  @media (width >= 64rem) {
    grid-template-columns: repeat(4, 1fr);
    /* The shared baseline every step stands on */
    border-bottom: 1px solid #c3ccc7;
  }
}

.step {
  display: flex;
  flex-direction: column;
  padding: var(--space-5);
  background: color-mix(in srgb, var(--brand-green) calc(4% + var(--rise) * 3%), var(--surface));

  /* Phone: bars that grow wider */
  width: calc(76% + var(--rise) * 8%);

  @media (width >= 40rem) {
    /* Tablet and desktop: panels that grow taller */
    width: auto;
    /* A minimum, so a panel never clips its text */
    min-height: calc(17rem + var(--rise) * 2.5rem);
  }

  @media (width >= 64rem) {
    min-height: calc(21.5rem + var(--rise) * 3.5rem);
    padding: var(--space-6) var(--space-5);
  }
}

.step__icon {
  flex-shrink: 0;
  width: 2rem;
  height: 2rem;
  margin-bottom: var(--space-5);
  color: var(--brand-green);
}

.step__title {
  margin-bottom: var(--space-2);
  font-size: var(--fs-lg);
}

.step__text {
  color: var(--ink-700);
}

/* --------------------------------------------------------------------------
   Trading CTA: the hero's mirror image, closing the page
   Desktop: photo on the left, its right edge cut at 75°; text on the right.
   Mobile: text first, then the photo with a gently slanted top edge.
   (The title lines share the hero's mask styles above.)
   -------------------------------------------------------------------------- */

.trade-cta {
  position: relative;
  isolation: isolate;
  padding-top: var(--section-y);

  @media (width >= 64rem) {
    display: grid;
    align-items: center;
    min-height: clamp(32rem, 64svh, 40rem);
    padding-top: 0;
  }
}

.trade-cta__content {
  display: grid;
  justify-items: start;
  gap: var(--space-5);
  max-width: 36rem;

  @media (width >= 64rem) {
    /* Sit in the right half, clear of the photo */
    max-width: min(36rem, 44vw - var(--gutter));
    margin-left: auto;
    padding-block: var(--space-8);
  }
}

.trade-cta__title {
  font-size: var(--fs-2xl);
  /* Even line lengths, whatever the width; the whole title rises as one block */
  text-wrap: balance;
}

.trade-cta__text {
  max-width: 32rem;
}

.trade-cta__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-4) var(--space-6);
  margin-top: var(--space-2);
}

/* ---- Photo ---- */

.trade-cta__media {
  position: relative;
  z-index: -1;
  aspect-ratio: 4 / 3;
  margin-top: var(--space-8);

  @media (width >= 40rem) {
    aspect-ratio: 16 / 9;
  }

  @media (width >= 64rem) {
    position: absolute;
    inset: 0 auto 0 0;
    width: 50%;
    aspect-ratio: auto;
    margin-top: 0;
    /* Lets the photo size its cut from this box's height (cqh) */
    container-type: size;
  }
}

.trade-cta__photo {
  position: absolute;
  inset: 0;
  /* Mirror of the hero's phone shape */
  clip-path: polygon(0 0, 100% 14%, 100% 100%, 0 100%);

  /* Mirror of the hero's 75° edge, on the right */
  @media (width >= 64rem) {
    clip-path: polygon(0 0, calc(100% - 100cqh / tan(75deg)) 0, 100% 100%, 0 100%);
  }

  img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
  }
}

/* Start hidden until the entrance animation runs (trading.js) */
@media (prefers-reduced-motion: no-preference) {
  .js [data-cta-reveal] {
    visibility: hidden;
  }
}
