/* How we work: from the first message to launch (src/partials/process.html).
   Four stages on one rail. Each stage has a numbered node on the rail, a stage
   card with a small wordless scene, its title and its text.

   The rail: every step draws its own stretch, from its node to the next one, and
   fills it from --enter (site.js scroll effects on each step). The stretches
   follow each other, so the accent runs along the rail as the section moves up
   the screen, with a soft point of light riding the front. Without motion (no
   --enter) every stretch is full.

   The scenes: every element's plain style is the FINISHED scene. The loops run
   only while a step has .is-playing (site.js: in view, or under the mouse) and
   only where motion is allowed, so reduced motion and no JavaScript both show
   the finished scenes. */

.process {
  --rail-glow: rgb(59 125 154 / 0.42);
  --stack-shadow: rgb(36 93 118 / 0.24);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) .process { --rail-glow: rgb(167 216 239 / 0.5); --stack-shadow: rgb(0 0 0 / 0.55); }
}
:root[data-theme='dark'] .process { --rail-glow: rgb(167 216 239 / 0.5); --stack-shadow: rgb(0 0 0 / 0.55); }

/* -------------------------------------------------------------- the journey */

.process__steps {
  --node: 40px;
  --col-gap: clamp(20px, 2.4vw, 32px);
  --row-gap: clamp(40px, 5vw, 56px);
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--row-gap) var(--col-gap);
}
.process__step {
  /* Where on the way up this step's stretch of rail fills (fractions of --enter). */
  --rail-from: calc(0.2 + var(--i, 0) * 0.1);
  --rail-span: 0.1;
  --fill: clamp(0, calc((var(--enter, 1) - var(--rail-from)) / var(--rail-span)), 1);
  --lit: clamp(0, calc(var(--fill) * 40), 1);
  position: relative; display: flex; flex-direction: column; min-width: 0;
}

/* The node: the step's number on the rail. It lights up as the fill leaves it. */
.process__num {
  position: relative; z-index: 1; display: grid; place-items: center; flex: none;
  width: var(--node); height: var(--node); border-radius: 50%;
  border: 1px solid var(--line-strong); background: var(--surface);
  font-size: 0.8125rem; font-weight: 650; letter-spacing: 0.02em; font-variant-numeric: tabular-nums;
  color: color-mix(in srgb, var(--accent) calc(var(--lit) * 100%), var(--text-2));
}
.process__num::before {
  content: ''; position: absolute; inset: -1px; border-radius: inherit;
  border: 1.5px solid var(--accent);
  box-shadow: 0 0 0 5px var(--accent-soft), 0 0 22px -2px var(--rail-glow);
  opacity: var(--lit);
}

/* The rail: from this node to the next one (across the gap). */
.process__line {
  position: absolute; z-index: 0; top: calc(var(--node) / 2 - 1px); left: calc(var(--node) / 2);
  width: calc(100% + var(--col-gap)); height: 2px; border-radius: 2px;
  background: var(--line-strong);
}
.process__line i {
  position: absolute; inset: 0; border-radius: inherit; background: var(--accent);
  transform-origin: 0 50%;
  transform: scaleX(var(--fill));
}
/* The point of light on the fill front, only while the stretch is filling. */
.process__line::after {
  content: ''; position: absolute; top: 50%; left: calc(var(--fill) * 100%);
  width: 20px; height: 20px; margin: -10px 0 0 -10px; border-radius: 50%;
  background: radial-gradient(circle, var(--accent) 0 2.5px, var(--rail-glow) 3.5px, transparent 70%);
  opacity: clamp(0, calc(min(var(--fill), 1 - var(--fill)) * 14), 1);
  pointer-events: none;
}

/* The stage card: a small surface for the scene. */
.process__card {
  position: relative; display: grid; place-items: center; overflow: hidden;
  height: clamp(200px, 8vw + 132px, 236px); margin-top: 22px;
  border: 1px solid var(--card-border); border-radius: 20px;
  background: radial-gradient(var(--card-dot) 1px, transparent 1.4px) center / 14px 14px, var(--card-bg);
  box-shadow: var(--card-shadow);
  transition: transform 320ms var(--ease), box-shadow 320ms var(--ease), border-color 320ms var(--ease);
}
@media (hover: hover) {
  .process__step:hover .process__card { transform: translateY(-2px); border-color: var(--accent-line); box-shadow: var(--card-shadow), var(--shadow-m); }
}
.process__title { margin-top: 22px; font-size: clamp(1.1875rem, 1.1rem + 0.3vw, 1.3125rem); font-weight: 630; line-height: 1.25; letter-spacing: -0.018em; text-wrap: balance; }
.process__text { margin-top: 8px; font-size: 1rem; line-height: 1.55; color: var(--text-2); text-wrap: pretty; }
.process__cta { margin-top: clamp(40px, 5vw, 64px); }

/* Four columns: the last stretch runs to the end of its column and fades out. */
@media (min-width: 1024px) {
  .process__step:last-child .process__line {
    width: calc(100% - var(--node) / 2);
    -webkit-mask-image: linear-gradient(90deg, #000 55%, transparent); mask-image: linear-gradient(90deg, #000 55%, transparent);
  }
}
/* Two columns: one rail per row. */
@media (min-width: 600px) and (max-width: 1023px) {
  .process__steps { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .process__step:nth-child(odd) { --rail-from: 0.2; }
  .process__step:nth-child(even) { --rail-from: 0.3; }
  .process__step:nth-child(even) .process__line {
    width: calc(100% - var(--node) / 2);
    -webkit-mask-image: linear-gradient(90deg, #000 55%, transparent); mask-image: linear-gradient(90deg, #000 55%, transparent);
  }
}
/* Phones: one vertical rail on the left. Each stretch runs down to the next node
   and fills as its own step comes up the screen. */
@media (max-width: 599px) {
  .process__steps { --node: 34px; grid-template-columns: minmax(0, 1fr); row-gap: var(--row-gap); }
  .process__step {
    --rail-from: 0.4; --rail-span: 0.6;
    display: grid; grid-template-columns: var(--node) minmax(0, 1fr); column-gap: 14px; align-content: start;
  }
  .process__num { grid-column: 1; grid-row: 1; }
  .process__card, .process__title, .process__text { grid-column: 2; }
  .process__card { margin-top: 0; height: 200px; }
  .process__title { margin-top: 18px; }
  .process__line { top: calc(var(--node) / 2); left: calc(var(--node) / 2 - 1px); width: 2px; height: calc(100% + var(--row-gap)); }
  .process__line i { transform-origin: 50% 0; transform: scaleY(var(--fill)); }
  .process__line::after { top: calc(var(--fill) * 100%); left: 50%; }
  .process__step:last-child .process__line {
    height: calc(100% - var(--node) / 2);
    -webkit-mask-image: linear-gradient(180deg, #000 45%, transparent); mask-image: linear-gradient(180deg, #000 45%, transparent);
  }
}

/* ------------------------------------------------------------- the scenes */

.pv { position: relative; width: min(176px, calc(100% - 28px)); }

/* 01 Tell us your idea: a message is typed, sent and ticked, and a reply is on its way. */
.pv-chat { display: flex; flex-direction: column; gap: 12px; }
.pv-chat__thread { display: flex; flex-direction: column; gap: 7px; }
.pv-chat__msg {
  align-self: flex-end; display: flex; flex-direction: column; gap: 5px; padding: 9px 11px;
  border-radius: 14px 14px 4px 14px; background: var(--accent); box-shadow: var(--shadow-s);
  transform-origin: 100% 100%;
}
.pv-chat__msg i { display: block; height: 5px; border-radius: 3px; background: var(--btn-fg); opacity: 0.62; }
.pv-chat__msg--1 { width: 80%; }
.pv-chat__msg--1 i:last-child { width: 62%; }
.pv-chat__msg--2 { width: 56%; flex-direction: row; align-items: center; gap: 6px; }
.pv-chat__msg--2 i { flex: 1; }
.pv-chat__check { width: 12px; height: 12px; flex: none; fill: none; stroke: var(--btn-fg); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 1; stroke-dashoffset: 0; }
.pv-chat__typing {
  align-self: flex-start; display: flex; gap: 4px; padding: 9px 11px;
  border: 1px solid var(--line); border-radius: 14px 14px 14px 4px; background: var(--surface);
  transform-origin: 0 100%;
}
.pv-chat__typing i { width: 5px; height: 5px; border-radius: 50%; background: var(--text-2); opacity: 0.7; }
.pv-chat__composer {
  display: flex; align-items: center; gap: 8px; height: 32px; padding: 0 4px 0 12px;
  border: 1px solid var(--line-strong); border-radius: 999px; background: var(--surface);
}
.pv-chat__draft { flex: 1; height: 5px; border-radius: 3px; background: var(--text-2); opacity: 0.4; transform-origin: 0 50%; transform: scaleX(0); }
.pv-chat__send { display: grid; place-items: center; flex: none; width: 24px; height: 24px; border-radius: 50%; background: var(--accent); }
.pv-chat__send svg { width: 12px; height: 12px; fill: none; stroke: var(--btn-fg); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* 02 We shape it with you: loose, dashed blocks snap into one aligned layout. */
.pv-wire__frame {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); grid-template-rows: 5px 12px minmax(0, 1fr) 30px; gap: 6px;
  height: 128px; padding: 9px 10px 10px;
  border: 1px solid var(--line-strong); border-radius: 12px; background: var(--surface); box-shadow: var(--shadow-s);
}
.pv-wire__chrome { grid-column: 1 / -1; display: flex; gap: 3px; }
.pv-wire__chrome i { width: 5px; height: 5px; border-radius: 50%; background: var(--line-strong); }
.pv-wire__block {
  --dx: 0px; --dy: 0px; --r: 0deg; --d: 0s;
  --wire-fill: color-mix(in srgb, var(--accent) 14%, var(--surface));
  position: relative; border: 1.2px dashed var(--accent-line); border-radius: 5px;
}
.pv-wire__block::before { content: ''; position: absolute; inset: -1.2px; border-radius: inherit; background: var(--wire-fill); }
.pv-wire__block--nav { grid-column: 1 / -1; --wire-fill: color-mix(in srgb, var(--text) 12%, var(--surface)); --dx: -7px; --dy: -5px; --r: -3deg; }
.pv-wire__block--hero { grid-column: 1 / span 2; --wire-fill: color-mix(in srgb, var(--accent) 32%, var(--surface)); --dx: 9px; --dy: 7px; --r: 3deg; --d: 0.08s; }
.pv-wire__block--side { --dx: 11px; --dy: -9px; --r: 7deg; --d: 0.16s; }
.pv-wire__block--a { --dx: -9px; --dy: 9px; --r: -6deg; --d: 0.24s; }
.pv-wire__block--b { --dx: 5px; --dy: 11px; --r: 5deg; --d: 0.32s; }
.pv-wire__block--c { --dx: 10px; --dy: 5px; --r: -7deg; --d: 0.4s; }
.pv-wire__pointer {
  position: absolute; right: 22%; bottom: 14%; width: 16px; height: 16px;
  fill: var(--text); stroke: var(--surface); stroke-width: 1.2; stroke-linejoin: round;
  filter: drop-shadow(0 2px 3px rgb(24 27 32 / 0.25));
}

/* 03 We build it: five thin layers stack up, foundation first. */
.pv-stack { display: grid; place-items: center; height: 168px; }
.pv-stack__scene {
  position: relative; width: 88px; height: 88px;
  transform: translateY(26px) rotateX(58deg) rotateZ(-45deg); transform-style: preserve-3d;
}
.pv-stack__slab {
  position: absolute; inset: 0; border-radius: 12px;
  transform: translateZ(calc(var(--n) * 13px)); transform-style: preserve-3d;
}
.pv-stack__slab::before, .pv-stack__slab::after { content: ''; position: absolute; inset: 0; border-radius: inherit; }
.pv-stack__slab::before { background: var(--side); transform: translateZ(-5px); }
.pv-stack__slab::after { background: linear-gradient(135deg, rgb(255 255 255 / 0.3), transparent 60%), var(--top); box-shadow: inset 0 0 0 1px rgb(255 255 255 / 0.22); }
.pv-stack__slab--cloud { --top: var(--layer-cloud); --side: var(--layer-cloud-side); }
.pv-stack__slab--data { --top: var(--layer-data); --side: var(--layer-data-side); }
.pv-stack__slab--api { --top: var(--layer-api); --side: var(--layer-api-side); }
.pv-stack__slab--ui { --top: var(--layer-ui); --side: var(--layer-ui-side); }
.pv-stack__slab--brand { --top: var(--layer-brand); --side: var(--layer-brand-side); }
.pv-stack__shadow {
  position: absolute; left: 50%; top: 50%; width: 132px; height: 40px; border-radius: 50%;
  background: radial-gradient(closest-side, var(--stack-shadow), transparent);
  transform: translate(-50%, calc(-50% + 30px));
}

/* 04 Launch and care: a live status card, with uptime bars and a heartbeat. */
.pv-status {
  display: flex; flex-direction: column; gap: 12px; padding: 13px 13px 10px;
  border: 1px solid var(--line-strong); border-radius: 14px; background: var(--surface); box-shadow: var(--shadow-s);
}
.pv-status__head { display: flex; align-items: center; gap: 8px; }
.pv-status__dot { position: relative; flex: none; width: 9px; height: 9px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 18%, transparent); }
.pv-status__dot::after { content: ''; position: absolute; inset: -1px; border-radius: 50%; border: 1.5px solid var(--ok); opacity: 0; }
.pv-status__head i { display: block; width: 46%; height: 5px; border-radius: 3px; background: var(--line-strong); }
.pv-status__head b { margin-left: auto; width: 30px; height: 12px; border-radius: 999px; background: color-mix(in srgb, var(--ok) 22%, transparent); }
.pv-status__bars { display: flex; align-items: flex-end; gap: 3px; height: 30px; }
.pv-status__bars i { flex: 1; height: 100%; border-radius: 2px; background: var(--ok); transform-origin: 50% 100%; }
.pv-status__beat { width: 100%; height: auto; aspect-ratio: 160 / 36; overflow: visible; }
.pv-status__track { fill: none; stroke: var(--line-strong); stroke-width: 1; }
.pv-status__pulse { fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 1; stroke-dashoffset: 0; }

/* ------------------------------------------------------------ the loops */

@media (prefers-reduced-motion: no-preference) {
  .process__step.is-playing .pv-chat__msg--1 { animation: pv-chat-msg1 3.6s var(--ease) infinite both; }
  .process__step.is-playing .pv-chat__draft { animation: pv-chat-draft 3.6s var(--ease-io) infinite both; }
  .process__step.is-playing .pv-chat__send { animation: pv-chat-send 3.6s var(--ease) infinite both; }
  .process__step.is-playing .pv-chat__msg--2 { animation: pv-chat-msg2 3.6s var(--ease) infinite both; }
  .process__step.is-playing .pv-chat__check { animation: pv-chat-check 3.6s var(--ease) infinite both; }
  .process__step.is-playing .pv-chat__typing { animation: pv-chat-typing 3.6s var(--ease) infinite both; }
  .process__step.is-playing .pv-chat__typing i { animation: pv-dot 1.2s var(--ease-io) infinite both; }
  .process__step.is-playing .pv-chat__typing i:nth-child(2) { animation-delay: 0.15s; }
  .process__step.is-playing .pv-chat__typing i:nth-child(3) { animation-delay: 0.3s; }

  .process__step.is-playing .pv-wire__block { animation: pv-wire-snap 3.4s var(--ease) var(--d) infinite both; }
  .process__step.is-playing .pv-wire__block::before { animation: pv-wire-fill 3.4s var(--ease) var(--d) infinite both; }
  .process__step.is-playing .pv-wire__pointer { animation: pv-wire-pointer 3.4s var(--ease-io) infinite both; }

  .process__step.is-playing .pv-stack__slab--cloud { animation: pv-slab-0 3.8s linear infinite both; }
  .process__step.is-playing .pv-stack__slab--data { animation: pv-slab-1 3.8s linear infinite both; }
  .process__step.is-playing .pv-stack__slab--api { animation: pv-slab-2 3.8s linear infinite both; }
  .process__step.is-playing .pv-stack__slab--ui { animation: pv-slab-3 3.8s linear infinite both; }
  .process__step.is-playing .pv-stack__slab--brand { animation: pv-slab-4 3.8s linear infinite both; }

  .process__step.is-playing .pv-status__dot::after { animation: pv-ping 1.6s var(--ease) infinite both; }
  .process__step.is-playing .pv-status__bars i { animation: pv-bar 3.2s var(--ease) calc(var(--k, 0) * 70ms) infinite both; }
  .process__step.is-playing .pv-status__pulse { animation: pv-beat 3.2s var(--ease-io) infinite both; }
}

@keyframes pv-chat-msg1 {
  0%, 6% { opacity: 0; transform: translateY(6px) scale(0.96); }
  14%, 92% { opacity: 1; transform: none; }
  100% { opacity: 0; transform: none; }
}
@keyframes pv-chat-draft {
  0%, 16% { transform: scaleX(0); }
  38%, 44% { transform: scaleX(1); }
  47%, 100% { transform: scaleX(0); }
}
@keyframes pv-chat-send {
  0%, 43% { transform: none; }
  46% { transform: scale(0.84); }
  52%, 100% { transform: none; }
}
@keyframes pv-chat-msg2 {
  0%, 46% { opacity: 0; transform: translateY(6px) scale(0.96); }
  54%, 92% { opacity: 1; transform: none; }
  100% { opacity: 0; transform: none; }
}
@keyframes pv-chat-check {
  0%, 56% { stroke-dashoffset: 1; }
  64%, 100% { stroke-dashoffset: 0; }
}
@keyframes pv-chat-typing {
  0%, 66% { opacity: 0; transform: translateY(4px) scale(0.96); }
  72%, 92% { opacity: 1; transform: none; }
  100% { opacity: 0; transform: none; }
}
@keyframes pv-dot {
  0%, 60%, 100% { opacity: 0.45; transform: none; }
  30% { opacity: 1; transform: translateY(-3px); }
}

@keyframes pv-wire-snap {
  0% { opacity: 0; transform: translate(var(--dx), var(--dy)) rotate(var(--r)) scale(0.94); }
  8%, 22% { opacity: 1; transform: translate(var(--dx), var(--dy)) rotate(var(--r)) scale(1); animation-timing-function: cubic-bezier(0.34, 1.5, 0.64, 1); }
  36%, 92% { opacity: 1; transform: none; }
  100% { opacity: 0; transform: none; }
}
@keyframes pv-wire-fill {
  0%, 34% { opacity: 0; }
  46%, 100% { opacity: 1; }
}
@keyframes pv-wire-pointer {
  0% { opacity: 0; transform: translate(26px, 22px); }
  10% { opacity: 1; transform: translate(26px, 22px); }
  30% { transform: translate(-58px, -40px) scale(1); }
  33% { transform: translate(-58px, -40px) scale(0.82); }
  37% { transform: translate(-58px, -40px) scale(1); }
  62% { transform: translate(-14px, 2px) scale(1); }
  74%, 92% { opacity: 1; transform: none; }
  100% { opacity: 0; transform: none; }
}

/* Each layer drops in from above the card (clipped by it), lands a touch low and
   settles; the five land one after another, hold together, then fade. */
@keyframes pv-slab-0 {
  0%, 4% { opacity: 1; transform: translateZ(calc(var(--n) * 13px + 220px)); animation-timing-function: cubic-bezier(0.5, 0, 0.75, 0); }
  14% { transform: translateZ(calc(var(--n) * 13px - 3px)); animation-timing-function: cubic-bezier(0.22, 1, 0.36, 1); }
  18%, 90% { opacity: 1; transform: translateZ(calc(var(--n) * 13px)); }
  97%, 100% { opacity: 0; transform: translateZ(calc(var(--n) * 13px)); }
}
@keyframes pv-slab-1 {
  0%, 15% { opacity: 1; transform: translateZ(calc(var(--n) * 13px + 220px)); animation-timing-function: cubic-bezier(0.5, 0, 0.75, 0); }
  25% { transform: translateZ(calc(var(--n) * 13px - 3px)); animation-timing-function: cubic-bezier(0.22, 1, 0.36, 1); }
  29%, 90% { opacity: 1; transform: translateZ(calc(var(--n) * 13px)); }
  97%, 100% { opacity: 0; transform: translateZ(calc(var(--n) * 13px)); }
}
@keyframes pv-slab-2 {
  0%, 26% { opacity: 1; transform: translateZ(calc(var(--n) * 13px + 220px)); animation-timing-function: cubic-bezier(0.5, 0, 0.75, 0); }
  36% { transform: translateZ(calc(var(--n) * 13px - 3px)); animation-timing-function: cubic-bezier(0.22, 1, 0.36, 1); }
  40%, 90% { opacity: 1; transform: translateZ(calc(var(--n) * 13px)); }
  97%, 100% { opacity: 0; transform: translateZ(calc(var(--n) * 13px)); }
}
@keyframes pv-slab-3 {
  0%, 37% { opacity: 1; transform: translateZ(calc(var(--n) * 13px + 220px)); animation-timing-function: cubic-bezier(0.5, 0, 0.75, 0); }
  47% { transform: translateZ(calc(var(--n) * 13px - 3px)); animation-timing-function: cubic-bezier(0.22, 1, 0.36, 1); }
  51%, 90% { opacity: 1; transform: translateZ(calc(var(--n) * 13px)); }
  97%, 100% { opacity: 0; transform: translateZ(calc(var(--n) * 13px)); }
}
@keyframes pv-slab-4 {
  0%, 48% { opacity: 1; transform: translateZ(calc(var(--n) * 13px + 220px)); animation-timing-function: cubic-bezier(0.5, 0, 0.75, 0); }
  58% { transform: translateZ(calc(var(--n) * 13px - 3px)); animation-timing-function: cubic-bezier(0.22, 1, 0.36, 1); }
  62%, 90% { opacity: 1; transform: translateZ(calc(var(--n) * 13px)); }
  97%, 100% { opacity: 0; transform: translateZ(calc(var(--n) * 13px)); }
}

@keyframes pv-ping {
  0% { opacity: 0.8; transform: scale(0.7); }
  100% { opacity: 0; transform: scale(2.4); }
}
@keyframes pv-bar {
  0% { opacity: 1; transform: none; }
  8% { opacity: 0.4; transform: scaleY(0.16); }
  24%, 100% { opacity: 1; transform: none; }
}
@keyframes pv-beat {
  0% { opacity: 1; stroke-dashoffset: 1; }
  56%, 86% { opacity: 1; stroke-dashoffset: 0; }
  100% { opacity: 0; stroke-dashoffset: 0; }
}

/* Forced colours: the rail stays as a plain line; the decorative scenes step aside. */
@media (forced-colors: active) {
  .process__line, .process__line i { background: CanvasText; }
  .process__line::after, .process__num::before { display: none; }
  .process__card { display: none; }
}
