/*
 * Home "About RIVERO" (#about, FEATURES.aboutScroll). Needs tokens.css,
 * site.css and home.css first. Markup: organisms/home/about.mjs.
 *
 * The copy is a zigzag route timeline: a thin line down the center of the
 * column (svg.about-route) that about.js draws with the scroll, a dot per
 * beat on it, and each beat's sentence under a large outline number on one
 * side of the line with a small snapshot on the other. Odd beats put the text
 * on the left (.is-l), even ones on the right (.is-r); under 768px the line
 * runs down the left and every beat stacks, the photo first.
 *
 * Default (no JS, reduced motion): the photo, then the finished route — the
 * whole line drawn, every dot filled, every photo in place, the numbers in
 * outline. html.rv-about (motion allowed, set in <head>), from 768px up: the
 * photo fills the screen and stays pinned while the route rides over it; then
 * the photo shrinks into a framed picture and Leadership rises over it.
 * about.js publishes the state: --route (how much of the line is drawn),
 * --beat-k, --frame, --exit; .has-beat on the section; .is-on, .is-past and
 * .is-reached on the beats. Only transform, opacity, clip-path and the line's
 * stroke-dashoffset move. The logo hand-off to Leadership (about.js) brings
 * its own element and leaves nothing behind.
 */

/* Static: photo, then the route. The section is left out of home.css's
   padding rule, since pinned it runs edge to edge, so it carries its own. */
.about-xp {
  --about-blue: var(--rv-blue, #235cf2);
  --about-bg: var(--tone-alt);
  --about-gap: clamp(48px, 7vw, 96px);
  --about-beat-gap: clamp(56px, 10svh, 112px);
  --about-n: clamp(48px, 5vw, 84px);
  padding-block: var(--section-pad);
}
.about-stage {
  display: grid;
}
.about-still {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: var(--card-radius);
}
.about-veil {
  display: none;
}
.about-flow {
  display: grid;
  gap: var(--space-5);
  margin-top: clamp(40px, 6vw, 88px);
}
.about-title {
  margin: 0;
  max-width: 17ch;
  font-size: var(--display-md);
}

/* The route's own box: the line is centered on it, and each beat is a row
   of it. */
.about-text {
  position: relative;
  display: grid;
  gap: var(--about-beat-gap);
  width: 100%;
  max-width: 1080px;
  margin-inline: auto;
}
.about-text p {
  display: grid;
  gap: var(--about-beat-gap);
  margin: 0;
  color: var(--ink-muted);
}

/* The line: a faint track and, over it, the blue line that is drawn by its
   dash offset (pathLength 1). about.js sets --route-top and --route-h so it
   runs from the first dot to the last, and --route (0 to 1). Without them it
   is the whole box, fully drawn. 2px wide in a 2-unit box: only its length is
   stretched. */
.about-route {
  position: absolute;
  z-index: 0;
  top: var(--route-top, 0);
  left: 50%;
  width: 2px;
  height: var(--route-h, 100%);
  margin-left: -1px;
  overflow: visible;
  pointer-events: none;
}
.about-track,
.about-line {
  fill: none;
  stroke-width: 2;
}
.about-track {
  stroke: color-mix(in srgb, currentColor 22%, transparent);
}
.about-line {
  stroke: var(--about-blue);
  stroke-dasharray: 1;
  stroke-dashoffset: calc(1 - var(--route, 1));
}

/* One beat. */
.about-beat {
  position: relative;
  z-index: 1;
}
.about-copy {
  display: block;
}
.about-s {
  display: block;
  font-size: clamp(20px, 1.9vw, 27px);
  line-height: 1.35;
  text-wrap: pretty;
}

/* The dot on the line: a ring that is filled blue (::after, scaled in) once
   its beat is reached, with a halo (::before) while it is the one on show.
   Fill and halo are transform and opacity, not color changes. */
.about-dot {
  position: absolute;
  z-index: 2;
  width: 16px;
  height: 16px;
  margin: -8px 0 0 -8px;
  box-sizing: border-box;
  border: 2px solid color-mix(in srgb, currentColor 45%, transparent);
  border-radius: 50%;
  background: var(--about-bg);
}
.about-dot::before,
.about-dot::after {
  content: '';
  position: absolute;
  border-radius: 50%;
}
.about-dot::after {
  inset: -2px;
  background: var(--about-blue);
}
.about-dot::before {
  inset: -9px;
  border: 1.5px solid var(--about-blue);
  opacity: 0;
  transform: scale(0.5);
}

/* The large outline number, over the sentence. Two layers of the same
   figure: the outline, and the white one over it whose opacity is the fill. */
.about-n {
  position: relative;
  display: block;
  margin-bottom: var(--space-3);
  font-family: var(--font-display);
  font-size: var(--about-n);
  font-weight: 500;
  line-height: 1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.about-n::before,
.about-n::after {
  content: attr(data-n);
  content: attr(data-n) / '';
}
.about-n::before {
  /* The fill goes, the color stays: the stroke is mixed from currentColor. */
  -webkit-text-fill-color: transparent;
  -webkit-text-stroke: 1px color-mix(in srgb, currentColor 55%, transparent);
}
.about-n::after {
  position: absolute;
  inset: 0;
  color: #fff;
  opacity: 0;
}

/* The snapshot: 4:3, at most 300px wide, a thin border and a soft shadow. */
.about-pic {
  position: relative;
  display: block;
  width: min(100%, 300px);
  aspect-ratio: 4 / 3;
  overflow: clip;
  border: 1px solid color-mix(in srgb, currentColor 22%, transparent);
  border-radius: 12px;
  box-shadow: 0 14px 32px -12px rgba(0, 0, 0, 0.55);
}
.about-pic img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  /* One treatment for all six: the files are already colour-matched. */
  filter: none;
}
/* Beat 01: the full RIVERO logo with its tagline, unmodified, centered on a
   clean light card the size of the photo frames. The card is light in both
   themes (the logo is ink and blue on transparent), so it never follows the
   page's ink. */
.about-pic--mark {
  display: grid;
  place-items: center;
  background: #f6f7f9;
  border-color: rgba(11, 13, 18, 0.1);
}
.about-pic--mark img {
  width: 82%;
  height: auto;
  object-fit: contain;
}

/* Beats 04 and 05: the unit's product card, on the same light card and in
   the same frame as the others — its logo top-left, and under it a mini
   browser window (traffic lights, rounded, a soft shadow) whose screenshot
   pans slowly (below). */
.about-pic--card {
  display: flex;
  flex-direction: column;
  gap: 6%;
  padding: 6.5% 7% 7%;
  background: #f6f7f9;
  border-color: rgba(11, 13, 18, 0.1);
  color: #0b0d12;
}
.about-pic--card .about-card-logo {
  flex: none;
  width: 44%;
  height: auto;
  object-fit: contain;
}
.about-browser {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  overflow: clip;
  border-radius: 8px;
  background: #ffffff;
  box-shadow:
    0 0 0 1px rgba(11, 13, 18, 0.08),
    0 12px 26px -12px rgba(11, 13, 18, 0.4);
}
.about-browser-bar {
  display: flex;
  flex: none;
  gap: 4px;
  padding: 6px 8px;
  background: #eceef2;
}
.about-browser-bar i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #ff5f57;
}
.about-browser-bar i:nth-child(2) {
  background: #febc2e;
}
.about-browser-bar i:nth-child(3) {
  background: #28c840;
}
.about-browser-view {
  position: relative;
  display: block;
  flex: 1;
  min-height: 0;
  overflow: clip;
}
.about-browser-view img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: left top;
  transform-origin: left top;
}
/* The store's "Live" chip, floating over its window. */
.about-live {
  position: absolute;
  z-index: 1;
  top: 8px;
  right: 8px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px 4px 7px;
  border-radius: 999px;
  background: #ffffff;
  color: #0b0d12;
  font: 600 11px / 1 var(--font-body);
  box-shadow:
    0 0 0 1px rgba(11, 13, 18, 0.06),
    0 8px 18px -8px rgba(11, 13, 18, 0.45);
}
.about-live::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--rv-orange);
}
@media (prefers-reduced-motion: no-preference) {
  .about-browser-view img {
    animation: about-pan 22s ease-in-out infinite;
  }
  .about-live {
    animation: about-bob 4.5s ease-in-out infinite;
  }
}
/* A slow push in and across the product, and back: only transform moves. */
@keyframes about-pan {
  0%,
  100% {
    transform: none;
  }
  50% {
    transform: scale(1.18) translate(-8%, -6%);
  }
}
@keyframes about-bob {
  0%,
  100% {
    translate: 0 0;
  }
  50% {
    translate: 0 -3px;
  }
}

/* A sentence's words, each in a mask of its own to rise out of. */
.about-w {
  display: inline-block;
  overflow: clip;
  vertical-align: top;
}
.about-wi {
  display: inline-block;
}

/*
 * What moves waits for about.js (.is-timed). The beat on show is lit and the
 * rest stepped back; its words rise out of their masks one by one, its number
 * fills white and its dot fills blue; the line draws with the scroll; a photo
 * is placed once, when its beat first reaches the middle of the screen
 * (.is-reached): from a slight turn, 16px low and clear, to straight, in
 * 600ms. The photo behind zooms in and darkens a step per beat (--beat-k).
 * .is-still is the first frame, which lands without playing anything.
 */
.is-timed .about-line {
  stroke-dashoffset: calc(1 - var(--route, 0));
}
.is-timed .about-copy {
  opacity: 0.34;
  transition: opacity var(--dur-slow) var(--ease);
}
.is-timed .about-beat.is-on .about-copy {
  opacity: 1;
}
.is-timed .about-n::after {
  transition: opacity var(--dur-slow) var(--ease);
}
.is-timed .about-beat.is-on .about-n::after {
  opacity: 1;
}
.is-timed .about-dot::after {
  transform: scale(0);
  transition: transform var(--dur-slow) var(--ease-spring, var(--ease));
}
.is-timed .about-beat:is(.is-on, .is-past) .about-dot::after {
  transform: none;
}
.is-timed .about-dot::before {
  transition:
    opacity var(--dur-slow) var(--ease),
    transform var(--dur-slow) var(--ease);
}
.is-timed .about-beat.is-on .about-dot::before {
  opacity: 1;
  transform: none;
}
.is-timed .about-wi {
  transform: translateY(110%);
  transition: transform var(--dur-slow) var(--ease);
}
.is-timed .about-beat:is(.is-on, .is-past) .about-wi {
  transform: none;
  transition-duration: var(--dur-reveal);
  transition-delay: calc(min(var(--i), 24) * 28ms);
}
.is-timed .about-pic {
  opacity: 0;
  transform: rotate(-4deg) translateY(16px);
}
.is-timed .about-beat.is-reached .about-pic {
  opacity: 1;
  transform: none;
  transition:
    opacity 600ms var(--ease),
    transform 600ms var(--ease);
}
.about-shade {
  position: absolute;
  inset: 0;
  background: #070707;
  opacity: calc(var(--beat-k, 0) * 0.045);
}
.is-timed .about-shade {
  transition: opacity var(--dur-media) var(--ease);
}
.is-timed .about-still {
  transform: scale(calc(1 + 0.02 * var(--beat-k, 0)));
  transition: transform 2400ms var(--ease);
}
.is-still,
.is-still *,
.is-still *::after,
.is-still *::before {
  transition: none !important;
}

/*
 * From 768px up, the zigzag. Each beat is two columns either side of the line,
 * a gap wide at the middle (--about-gap): odd beats (.is-l) have the text on
 * the left, hugging the line, and the photo on the right; even ones (.is-r)
 * the other way round. The dot is at the beat's middle, so the beat is
 * "reached" when that point is at the middle of the screen.
 */
@media (min-width: 768px) {
  .about-flow {
    grid-template-columns: minmax(0, 1fr);
  }
  .about-beat {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    column-gap: var(--about-gap);
    align-items: center;
  }
  .about-dot {
    top: 50%;
    left: 50%;
  }
  .about-copy,
  .about-pic {
    grid-row: 1;
  }
  .about-beat.is-l .about-copy {
    grid-column: 1;
    text-align: right;
  }
  .about-beat.is-l .about-pic {
    grid-column: 2;
    justify-self: start;
  }
  .about-beat.is-r .about-copy {
    grid-column: 2;
    text-align: left;
  }
  .about-beat.is-r .about-pic {
    grid-column: 1;
    justify-self: end;
  }
}

/*
 * Pinned, from 768px up. The copy takes the stage's height back (negative
 * margin), so it starts at the top of the section and rides over the photo
 * for as long as the section lasts: the title, then the route. The stage
 * keeps its own height in the flow; with the height given back as a negative
 * margin on the stage instead, its margin box is empty, so the sticky range
 * never ends with the section and the photo stayed pinned over Leadership.
 * This way the section carries it away, and --exit (about.js) scales and
 * fades it out as Leadership arrives. Over the last screen of scroll (--frame)
 * the copy fades while the full-bleed photo is clipped down into a framed
 * picture sitting on the section's own color.
 */
@media (min-width: 768px) {
  .rv-about .about-xp {
    --frame: 0;
    --exit: 0;
    --about-bg: #0b0b0b;
    padding-block: 0;
  }
  .rv-about .about-stage {
    position: sticky;
    top: 0;
    z-index: 0;
    display: block;
    height: 100svh;
    overflow: clip;
    /* The fade itself is on the section (.has-exit, below); the picture
       only settles back as it goes. */
    scale: calc(1 - 0.07 * var(--exit));
    clip-path: inset(
      calc(var(--frame) * 13svh) calc(var(--frame) * 15vw)
        calc(var(--frame) * 11svh) round calc(var(--frame) * var(--card-radius))
    );
  }
  /* Full bleed while pinned; the framed picture gets its corners from the
     stage's clip above. The per-beat zoom is its transform (above); this
     scale is the framing's, which settles it back as the picture is framed. */
  .rv-about .about-still {
    width: 100%;
    height: 100%;
    aspect-ratio: auto;
    border-radius: 0;
    scale: calc(1.06 - 0.06 * var(--frame));
  }
  /* Darkest under the copy, and deep enough elsewhere that the snapshots
     read as lit photos over it rather than more of the same wall. */
  .rv-about .about-veil {
    display: block;
    position: absolute;
    inset: 0;
    background: linear-gradient(
      100deg,
      rgba(7, 7, 7, 0.88) 0%,
      rgba(7, 7, 7, 0.76) 46%,
      rgba(7, 7, 7, 0.62) 100%
    );
    /* Nothing left to keep legible once the copy has gone: the framed
       picture is a photograph again, not a backdrop. */
    opacity: calc(1 - 0.75 * var(--frame));
  }
  .rv-about .about-flow {
    position: relative;
    z-index: 1;
    margin-top: -100svh;
    padding-block: 34svh 0;
    color: #fff;
    row-gap: clamp(28px, 4vw, 48px);
    /* Twice the speed of the framing: the copy is gone well before the
       picture has finished shrinking. */
    opacity: clamp(0, calc(1 - 2 * var(--frame)), 1);
  }
  /* The scroll the framing gets, after the last line: just enough for the
     framing (40% of a screen, about.js) to finish while the stage is still
     pinned. */
  .rv-about .about-flow::after {
    content: '';
    grid-column: 1;
    grid-row: 4;
    height: 100svh;
  }
  /* Leadership sits under the section's last stretch: pulled up by 45svh +
     160px (the 160px being the last beat's half photo and the row gap), it
     is hidden by the section while the frame plays, and is what the
     section's fade (--exit, the last quarter of a screen) uncovers, its
     title about a fifth of the way down when the fade ends. */
  .rv-about .about-xp + .leadership {
    margin-top: calc(-1 * (45svh + 160px));
  }
  .rv-about .about-flow .eyebrow {
    color: rgba(255, 255, 255, 0.72);
  }
  .rv-about .about-title {
    max-width: 11ch;
    font-size: clamp(42px, 7vw, 108px);
    line-height: 0.95;
  }
  .rv-about .about-text {
    grid-column: 1;
    grid-row: 3;
    margin-top: clamp(24px, 6svh, 72px);
  }
  .rv-about .about-text p {
    color: rgba(255, 255, 255, 0.86);
  }
}

/*
 * Phone and small tablet, whatever the motion setting: the dark section of
 * the desktop, the photo held behind the copy under the same veil. The route
 * runs down the left with its dots, and every beat stacks beside it: the
 * photo, full width but never taller than 30% of the screen (it crops to
 * it), then the number and the sentence. The dot sits at the top of its
 * beat, so a beat is reached when its photo is at the middle of the screen.
 * lvh, not svh: the photo has to reach the bottom with Safari's bars gone.
 */
@media (max-width: 767px) {
  .about-xp {
    --about-beat-gap: clamp(48px, 9svh, 72px);
    --about-n: 30px;
    --about-bg: #0b0b0b;
    padding-block: 0;
  }
  .about-stage {
    position: sticky;
    top: 0;
    z-index: 0;
    display: block;
    height: 100vh;
    height: 100lvh;
    overflow: clip;
    background: #070707;
  }
  .about-still {
    height: 100%;
    aspect-ratio: auto;
    border-radius: 0;
  }
  .about-veil {
    display: block;
    position: absolute;
    inset: 0;
    background: linear-gradient(
      100deg,
      rgba(7, 7, 7, 0.88) 0%,
      rgba(7, 7, 7, 0.76) 46%,
      rgba(7, 7, 7, 0.62) 100%
    );
  }
  /* A block, not a grid, so nothing in it is placed by rows. */
  .about-flow {
    position: relative;
    z-index: 1;
    display: block;
    margin-top: -100vh;
    margin-top: -100lvh;
    padding-block: 24svh var(--section-pad);
    color: #fff;
  }
  .about-flow > * + * {
    margin-top: var(--space-5);
  }
  .about-flow .eyebrow {
    color: rgba(255, 255, 255, 0.72);
  }
  .about-title {
    max-width: 11ch;
    font-size: clamp(40px, 11vw, 64px);
    line-height: 0.95;
  }
  .about-flow > .about-text {
    margin-top: var(--space-7);
  }
  .about-text p {
    color: rgba(255, 255, 255, 0.86);
  }
  .about-route {
    left: 9px;
  }
  .about-beat {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    padding-left: 36px;
  }
  .about-dot {
    top: 18px;
    left: 10px;
  }
  .about-pic {
    order: -1;
    width: 100%;
    max-height: 30vh;
    max-height: 30svh;
  }
  .about-copy {
    text-align: left;
  }
  .about-s {
    font-size: 19px;
  }
}

/*
 * Phone, motion allowed (html.rv-about): the desktop's ending, so the last
 * beat's photo is read whole before anything covers it. After the last line
 * the stage stays pinned for one more screen (the flow's ::after, as on
 * desktop), over which about.js's --frame clips the full-bleed photo down
 * into a framed picture and fades the copy at twice that speed; then --exit
 * settles the picture back and fades the section while Leadership, pulled up
 * by the same 45svh + 160px as on desktop, rises over it. Without this the
 * pull was 50svh over a flow that ended with the last line, so Leadership's
 * opaque top edge slid over beat 06 (its team photo) while it was still on
 * screen. Reduced motion keeps the plain crossfade (below).
 */
@media (max-width: 767px) {
  .rv-about .about-xp {
    --frame: 0;
    --exit: 0;
  }
  .rv-about .about-stage {
    scale: calc(1 - 0.07 * var(--exit));
    clip-path: inset(
      calc(var(--frame) * 13svh) calc(var(--frame) * 15vw)
        calc(var(--frame) * 11svh) round calc(var(--frame) * var(--card-radius))
    );
  }
  .rv-about .about-still {
    scale: calc(1.06 - 0.06 * var(--frame));
  }
  .rv-about .about-veil {
    opacity: calc(1 - 0.75 * var(--frame));
  }
  .rv-about .about-flow {
    padding-bottom: 0;
    opacity: clamp(0, calc(1 - 2 * var(--frame)), 1);
  }
  /* The scroll the framing and the fade read, after the last line. */
  .rv-about .about-flow::after {
    content: '';
    display: block;
    height: 100svh;
  }
}

/*
 * The hand-off to Leadership, at every width (about.js adds .has-exit and
 * publishes --exit, 0 to 1 over the last quarter of a screen of the section):
 * the section is above Leadership and fades out with scroll, so Leadership is
 * revealed under it, not cut in over it. No visibility or display change, only
 * opacity (under reduced motion that is all there is: a crossfade). Leadership's
 * own curtain (clip-path, site.css) is off, or its edge would show through the
 * fade. Without the script none of this applies and the sections just meet.
 */
.about-xp.has-exit {
  z-index: 1;
  opacity: calc(1 - var(--exit, 0));
}
/* Faded out (about.js: --exit has reached 1), the section still lies over
   Leadership's top, so it lets the pointer through to the portraits. */
.about-xp.has-exit.is-out {
  pointer-events: none;
}
.about-xp.has-exit + .leadership[data-rise] {
  animation: none;
  clip-path: none;
  transition: none;
}
/* The dark section is pinned on a phone with no frame to play, so the pull
   is shorter: Leadership's top edge is half a screen up when the fade starts. */
@media (max-width: 767px) {
  .about-xp.has-exit + .leadership {
    margin-top: -50svh;
  }
  /* The copy goes at twice the speed, so the last beat is not read through
     Leadership's title. (With motion the framing above does this instead.) */
  html:not(.rv-about) .about-xp.has-exit .about-flow {
    opacity: clamp(0, calc(1 - 2 * var(--exit, 0)), 1);
  }
  .rv-about .about-xp.has-exit + .leadership {
    margin-top: calc(-1 * (45svh + 160px));
  }
}

/*
 * The hand-off's symbol (about.js makes it and removes it after): the
 * official RIVERO PNG, untouched, parked at the first portrait. Everything it
 * does is a Web Animation on transform and opacity.
 */
.about-handoff {
  position: absolute;
  z-index: 3;
  top: 0;
  left: 0;
  display: block;
  height: auto;
  transform-origin: 50% 100%;
  pointer-events: none;
}
/* The header pill is away on the way down; the flight calls it back until
   the lockup has pulsed, then it goes back to doing as it did. */
.rv-hdr.is-away.is-handoff .rv-hdr-bubble {
  transform: none;
}
