/* Algorimate — scroll 3D world (prototype, world.html only). Loaded after styles.css.
   Default = static layout (no JS, no WebGL, reduced motion). html.world-live = the camera flight. */

.world { position: relative; background: var(--paper); }
.world-stage { display: none; }
.world-steps { position: relative; z-index: 1; }
.world-step { position: relative; }

/* ---------- static layout ---------- */
.world-step--hero {
  min-height: calc(100svh - var(--header-h)); display: flex; align-items: center; justify-content: center; text-align: center;
  background: radial-gradient(120% 80% at 50% 110%, var(--hero-1) 0%, var(--ink) 55%, var(--hero-2) 100%); color: var(--hero-text);
}
.world-step--fold, .world-step--out { display: none; }

/* ---------- live: sticky canvas, copy scrolls over it ---------- */
html.world-live .world { background: var(--ink); }
html.world-live .world-stage {
  display: block; position: sticky; top: var(--header-h); z-index: 0;
  height: calc(100lvh - var(--header-h)); margin-bottom: calc(100svh - 100lvh);   /* down to the screen's foot when Safari's bar collapses; the flow keeps the svh height */
  overflow: hidden;   /* no background of its own: .world's ink shows through. iOS 27 Safari tinted its bars with this pinned element's background (a black bar down to the footer) */
}
.world-canvas { display: block; width: 100%; height: 100%; opacity: 0; transition: opacity 700ms ease; }
.world.is-ready .world-canvas { opacity: 1; }

/* the copy rides over the sticky stage: pull the steps up instead of letting the stage overhang the next section */
html.world-live .world-steps { margin-top: calc(-1 * (100svh - var(--header-h))); }
html.world-live .world-step--hero { background: transparent; height: calc(100svh - var(--header-h)); min-height: 0; position: sticky; top: var(--header-h); z-index: 2; }
html.world-live .world-pin { position: relative; }
/* short screens (iPhone Duo folded and open, small laptops' windows): the hero copy drops its phone padding and keeps
   room for the Scroll hint under it, so they never overlap */
@media (max-height: 640px) { html.world-live .hero-inner { padding-block: 0 88px; gap: clamp(16px, 3.5svh, 32px); } html.world-live .hero-scroll { bottom: 36px; } }   /* 36px: clear of the open Duo's rounded lower edge */
html.world-live .world-step--fold { display: block; height: 170svh; }

html.world-live .world-step--out { display: block; height: 60svh; }

/* ---------- client story: a film scrubbed by scroll (world.html) ---------- */
.story { position: relative; background: var(--ink); color: var(--on-dark); }
.story-stage { position: relative; overflow: hidden; }
.story-video { display: block; width: 100%; aspect-ratio: 16 / 9; object-fit: cover; background: var(--ink); }
.story-shade { display: none; }
.story-copy { display: grid; gap: 28px; padding-block: 40px 64px; }
.story-step h2 { color: var(--on-dark); font-size: clamp(30px, 4.6vw, 64px); max-width: 16ch; margin: 0 0 12px; text-wrap: balance; }
.story-step p { margin: 0; max-width: 46ch; color: var(--on-dark-2); }
html.story-live .story { height: 360svh; }
html.story-live .story-stage { position: sticky; top: var(--header-h); height: calc(100lvh - var(--header-h)); }   /* the film reaches the screen's foot under Safari's collapsed bar */
html.story-live .story-video { position: absolute; inset: 0; height: 100%; aspect-ratio: auto; }
.story-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }   /* the colour film, drawn over its video */
html.story-live .story-shade { display: block; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(180deg, rgba(17, 19, 24, 0) 38%, rgba(17, 19, 24, 0.74) 100%); }
html.story-live .story-copy { position: absolute; left: 0; right: 0; bottom: calc(clamp(40px, 9svh, 88px) + 100lvh - 100svh); height: 0; padding-block: 0; }
html.story-live .story-step { position: absolute; left: var(--gutter); right: var(--gutter); bottom: 0; opacity: 0; transform: translateY(18px);
  transition: opacity 500ms ease, transform 500ms var(--ease-out); }
html.story-live .story-step.is-on { opacity: 1; transform: none; }

@media (max-width: 760px) { #story-ceva .story-video { object-position: 38% 50%; } }

/* ---------- services: four cards, each with its plaster maquette moving with the scroll ---------- */
.svc-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
@media (max-width: 760px) { .svc-grid { grid-template-columns: 1fr; } }
.svc-card {
  display: grid; background: var(--paper-2); border: 1px solid var(--line-2); border-radius: var(--radius-card); overflow: hidden;
  cursor: pointer; color: var(--ink); transition: border-color 200ms ease, transform 200ms ease;
}
.svc-card:hover, .svc-card:focus-visible { border-color: var(--ink); transform: translateY(-4px); }
.svc-card:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }
.svc-media { position: relative; aspect-ratio: 1 / 1; background: #E4E4E0; overflow: hidden; }
.svc-body { display: grid; gap: 12px; padding: 26px 30px 30px; }
.svc-body h3 { font-size: clamp(22px, 2vw, 26px); letter-spacing: -0.02em; }
.svc-body p { margin: 0; color: var(--ink-2); }
@media (prefers-reduced-motion: reduce) { .svc-card, .svc-card:hover { transform: none; } }

/* the services title waits at the centre of the screen from the moment the camera enters the A (T 1.3, world.js
   reveals it during the dive), holds after the landing (T 2), then flies past the camera (services.js) while the
   first maquette flies in. Lengths follow the world steps (fold 170svh, out 60svh): the section starts where the
   scroll reaches T 1.3 and the title lets go 3 screens down, as its fly-past ends; the first card is centred
   at 4.25 screens. The #services anchor lands on the title fully revealed (T 1.85). */
/* the title grows past the screen in the dive: the pinned block clips it so the page never widens (phones would pan
   sideways). Never clip a block that contains a pinned element: WebKit (Safari, iOS and Mac) then shakes it while scrolling */
html.world-live .svc-intro > .container { overflow-x: clip; }
html.world-live .svc { position: relative; z-index: 2; margin-top: calc(-166.5svh + 0.65 * var(--header-h)); padding-top: 0; scroll-margin-top: calc(-52.25svh - 0.275 * var(--header-h)); }
html.world-live .svc-intro { height: calc(236.5svh - 0.65 * var(--header-h)); pointer-events: none; }
html.world-live .svc-intro > .container {
  position: sticky; top: var(--header-h); height: calc(100svh - var(--header-h));
  display: flex; align-items: center; justify-content: center; will-change: opacity, transform;
}
html.world-live .svc-intro .section-head { flex-direction: column; align-items: center; text-align: center; gap: 22px; border-top: 0; padding: 0; margin: 0; will-change: opacity, transform; }
html.world-live .svc-intro .section-head h2 { font-size: clamp(42px, 7.2vw, 104px); max-width: 12ch; margin-inline: auto; }
html.world-live .svc-intro .eyebrow, html.world-live .svc-intro .section-hint { color: inherit; opacity: 0.66; }

/* ---------- services, live: a showcase pinned under the header (services.js) ----------
   The four names form an index on one side, one window on the other. The current service turns to ink and unfolds its
   copy; in the window each maquette wipes up over the last one and its film follows the scroll. The window and the
   index swap sides at every service, so the left-right rhythm stays. The cards stay in the flow as the scroll track. */
.svc-stage { display: none; }
html.svc-live .svc-scroller { position: relative; }
html.svc-live .svc { padding-bottom: 0; }   /* the pinned showcase ends the section, the client logos follow at once */
html.svc-live .svc-stage {
  display: flex; align-items: center; position: sticky; top: var(--header-h); z-index: 0;
  height: calc(100svh - var(--header-h)); overflow: hidden; pointer-events: none;
}
/* the way out to the AI section (services.js): the stage holds on a short tail while the showcase leaves through
   its doors, and the AI section rides up over the stage so We deploy arrives centred as the stage lets go */
html.svc-live .svc-tail { height: 70svh; pointer-events: none; }
html.svc-live .ai { margin-top: calc(-1 * (100svh - var(--header-h))); }
html.svc-live .ai-head { opacity: 0; }
/* the title block takes the stage's place in the flow (it rides over the stage), the cards follow it */
html.svc-live .svc-intro { position: relative; z-index: 2; margin-top: calc(-1 * (100svh - var(--header-h))); }
html.svc-live .svc-grid { display: block; position: relative; z-index: 1; pointer-events: none; }
html.svc-live .svc-card { height: 110svh; background: transparent; border: 0; border-radius: 0; pointer-events: none; }
html.svc-live .svc-card > * { display: none; }   /* the film and the copy moved into the showcase */
html.svc-live .svc-card:hover, html.svc-live .svc-card:focus-visible { transform: none; outline: none; }

.svc-vitrine {
  width: 100%; display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); column-gap: clamp(16px, 2.4vw, 32px);
  align-items: center; visibility: hidden; will-change: opacity;
}
.svc-index { grid-column: 1 / span 5; grid-row: 1; position: relative; padding-left: 28px; display: grid; gap: 6px; pointer-events: auto;
  transition: transform 700ms var(--ease-out); }
.svc-index::before, .svc-fill { content: ""; position: absolute; left: 0; top: 6px; width: 1px; }
.svc-index::before { bottom: 6px; background: var(--line); }
.svc-fill { height: 0; background: var(--ink); }
.svc-index .svc-body { display: block; padding: 0; background: none; border: 0; }
.svc-index h3 { font-size: clamp(28px, 3.3vw, 48px); letter-spacing: -0.035em; line-height: 1.02; color: var(--on-dark-3); transition: color 450ms ease; }
.svc-index .is-on h3 { color: var(--ink); }
.svc-index h3[role="button"] { cursor: pointer; }
.svc-index .svc-body:not(.is-on) h3:hover { color: var(--muted); }
.svc-index .is-on h3[role="button"] { cursor: default; }
.svc-index h3:focus-visible { outline: 2px solid var(--ink); outline-offset: 4px; border-radius: 4px; }
.svc-more { display: grid; grid-template-rows: 0fr; transition: grid-template-rows 600ms var(--ease-out); }
.svc-index .is-on .svc-more { grid-template-rows: 1fr; }
.svc-more > div { overflow: hidden; visibility: hidden; transition: visibility 0s 600ms; }
.svc-index .is-on .svc-more > div { visibility: visible; transition-delay: 0s; }
.svc-more p { padding-block: 14px 18px; max-width: 38ch; opacity: 0; transition: opacity 400ms ease; }
.svc-index .is-on .svc-more p { opacity: 1; transition-delay: 200ms; }
.svc-window {
  grid-column: 7 / span 6; grid-row: 1; justify-self: center; position: relative; overflow: hidden; isolation: isolate;
  width: 100%; max-width: calc((100svh - var(--header-h)) * 0.82 * 0.8); aspect-ratio: 4 / 5;
  background: #E4E4E0; border-radius: var(--radius-card); transition: transform 700ms var(--ease-out);
}
.svc-window video {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; will-change: opacity, transform;
  opacity: 0; z-index: 0; transition: opacity 0s linear 900ms, transform 900ms var(--ease-out);
}
/* the new maquette fades in on top while the previous one stays under it, then goes; a time-based change, never half done */
.svc-window video.is-shown { opacity: 1; z-index: 2; transform: none; transition: opacity 900ms ease, transform 900ms var(--ease-out); }
/* a step forward: the old maquette rushes past the camera as the new one arrives (scales stay above 1, so the window
   edge never shows) */
.svc-window video.is-past { transform: scale(1.22); }
.svc-window video.is-next { transform: scale(1.06); }
@media (min-width: 761px) {
  .svc-vitrine.is-flip .svc-window { transform: translateX(var(--win-x, 0)); }
  .svc-vitrine.is-flip .svc-index { transform: translateX(var(--index-x, 0)); }
}
@media (max-width: 760px) {
  html.svc-live .svc-card { height: 120svh; }
  .svc-vitrine { grid-template-columns: minmax(0, 1fr); row-gap: 22px; align-content: center; }
  /* as on the web: the whole index with its rail under the window, the other services in grey; the window gives up
     the height the index needs */
  .svc-window { grid-column: 1; grid-row: 1; aspect-ratio: 1 / 1; max-width: min(100%, calc(100svh - var(--header-h) - 300px)); }
  .svc-index { grid-column: 1; grid-row: 2; padding-left: 18px; gap: 8px; }
  .svc-index h3 { font-size: clamp(21px, 6vw, 26px); }
  .svc-more p { padding-block: 8px 4px; font-size: 15px; line-height: 1.45; }
}

/* ---------- the AI we deploy (ai.js) ----------
   A: the headline names an assistant, and changes like a chat answering a prompt: the name is erased, dots think while
   a small status cycles (Searching, Reading, Weighing), then the next name streams in and its mark appears.
   C: a diagram pinned under the header and drawn by the scroll: the assistants, Algorimate, the company's systems. */
.ai { position: relative; z-index: 2; }
.ai-head { min-height: calc(100svh - var(--header-h)); }
.ai-head-in { min-height: calc(100svh - var(--header-h)); display: flex; flex-direction: column; justify-content: safe center; align-items: center; text-align: center; padding-block: 5svh; position: relative; }
/* live (ai.js): the headline holds still for a pause, then fades back while the diagram rides up */
html.ai-live .ai-head { height: calc(100svh - var(--header-h) + 110svh); }
html.ai-live .ai-head-in { position: sticky; top: var(--header-h); height: calc(100svh - var(--header-h)); min-height: 0; }
html.ai-live .ai-plug { margin-top: calc(-1 * (100svh - var(--header-h))); }
.ai-title { font-size: clamp(40px, min(7.2vw, 10.5svh), 120px); letter-spacing: -0.045em; line-height: 1; }   /* sized by the screen's height too, so the block fits one screen */
@media (max-height: 640px) {   /* short screens: the block still fits one screen under the header (safe centring above keeps it below the header if not) */
  .ai-title { font-size: clamp(30px, min(7.2vw, 8.5svh), 120px); }
  .ai-fde { font-size: 17px; margin-top: 2svh; } .ai-lead { font-size: 15px; margin-top: 2svh; } .ai-strip { margin-top: 3svh; }
}
.ai-title > span { display: block; }
.ai-slot { display: flex !important; justify-content: center; align-items: center; gap: 0.2em; margin-block: 0.06em; }
.ai-mark { width: 0.7em; height: 0.7em; position: relative; flex: none; }
.ai-mark img { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; transform: scale(0.5); transition: opacity 300ms ease, transform 600ms var(--ease-out); }
.ai-mark img.is-on { opacity: 1; transform: none; }
.ai-think { position: absolute; inset: 0; opacity: 0; transition: opacity 200ms ease; }
.ai-think.is-on { opacity: 1; }
.ai-think i { position: absolute; width: 0.13em; height: 0.13em; border-radius: 50%; background: var(--ink); animation: ai-pulse 900ms ease-in-out infinite; }
.ai-think i:nth-child(1) { left: 18%; top: 30%; }
.ai-think i:nth-child(2) { left: 60%; top: 22%; animation-delay: 150ms; }
.ai-think i:nth-child(3) { left: 30%; top: 64%; animation-delay: 300ms; }
@keyframes ai-pulse { 0%, 100% { transform: scale(0.55); opacity: 0.35; } 45% { transform: scale(1); opacity: 1; } }
.ai-name { display: block; text-align: left; white-space: nowrap; overflow: hidden; height: 1.12em; line-height: 1.12; transition: width 450ms var(--ease-out); }
.ai-caret { display: inline-block; width: 0.06em; height: 0.8em; margin-left: 0.04em; vertical-align: -0.04em; background: var(--ink); opacity: 0; }
.ai-caret.is-on { opacity: 1; animation: ai-blink 800ms steps(1) infinite; }
@keyframes ai-blink { 50% { opacity: 0; } }
.ai-neg { display: inline-block !important; background: var(--ink); color: var(--paper); border-radius: 0.14em; padding: 0.02em 0.22em 0.1em; margin-top: 0.08em; }
.ai-status { height: 30px; margin: 28px 0 0; display: flex; justify-content: center; align-items: center; gap: 10px; font-size: 18px; line-height: 1;
  opacity: 0; transform: translateY(6px); transition: opacity 300ms ease, transform 400ms var(--ease-out); }
.ai-status.is-on { opacity: 1; transform: none; }
.ai-dots { display: inline-flex; gap: 4px; }
.ai-dots i { width: 5px; height: 5px; border-radius: 50%; background: var(--ink); animation: ai-pulse 900ms ease-in-out infinite; }
.ai-dots i:nth-child(2) { animation-delay: 150ms; }
.ai-dots i:nth-child(3) { animation-delay: 300ms; }
/* the sweep is painted inside the letters (background-clip: text) and only within the word's box: the box is given
   room for descenders, or the bottom of the letters would be cut off */
.ai-word { display: inline-block; line-height: 1.3; padding-bottom: 0.08em; color: transparent; -webkit-background-clip: text; background-clip: text; background-size: 250% 100%;
  background-image: linear-gradient(90deg, var(--muted) 0 38%, var(--ink) 50%, var(--muted) 62% 100%); animation: ai-sweep 1.3s linear infinite; }
@keyframes ai-sweep { from { background-position: 100% 0; } to { background-position: 0 0; } }
/* how we deploy: on site, in the client's teams, for a scoped engagement */
.ai-fde { margin: clamp(16px, 3svh, 28px) auto 0; max-width: 44ch; font-family: var(--font-head); font-weight: 700; font-size: clamp(19px, 1.6vw, 23px); letter-spacing: -0.01em; line-height: 1.35; color: var(--ink); }
.ai-lead { margin: 22px auto 0; max-width: 46ch; color: var(--ink-2); font-size: 18px; }
.ai-strip { list-style: none; margin: clamp(20px, 4svh, 40px) 0 0; padding: 0; display: flex; flex-wrap: wrap; justify-content: center; gap: 12px 30px; }
.ai-strip li { display: inline-flex; align-items: center; gap: 9px; font-size: 15px; font-weight: 600; line-height: 1; color: var(--on-dark-3); transition: color 400ms ease; }
.ai-strip li.is-on { color: var(--ink); }
.ai-strip img { width: 18px; height: 18px; opacity: 0.35; filter: grayscale(1); transition: opacity 400ms ease, filter 400ms ease; }
.ai-strip li.is-on img { opacity: 1; filter: none; }   /* the current assistant shows its own colours */

.ai-plug-stage { display: grid; gap: 4svh; padding-block: 8svh; }
.ai-plug-title { text-align: center; font-size: clamp(32px, 4.6vw, 68px); letter-spacing: -0.04em; line-height: 1.02; }
.ai-map { width: 100%; max-height: 56svh; display: block; overflow: visible; }
.ai-map .line { fill: none; stroke: var(--ink); stroke-width: 1.4; }
.ai-map .ghost { fill: none; stroke: var(--line); stroke-width: 1.4; }
.ai-map .node circle { fill: var(--paper); stroke: var(--line); stroke-width: 1.4; transition: stroke 400ms ease; }
.ai-map .node.is-lit circle { stroke: var(--ink); }
.ai-map .node .mono { opacity: 0.45; transition: opacity 400ms ease; }
.ai-map .node .color { opacity: 0; transition: opacity 500ms ease; }
.ai-map .node.is-lit .mono { opacity: 0; }
.ai-map .node.is-lit .color { opacity: 1; }
.ai-map .node text { font: 600 15px var(--font-body); fill: var(--ink-2); text-anchor: middle; }
.ai-map .sys rect { fill: var(--paper); stroke: var(--line); stroke-width: 1.4; transition: stroke 400ms ease, fill 400ms ease; }
.ai-map .sys.is-lit rect { stroke: var(--ink); fill: var(--paper-2); }
.ai-map .sys text { font: 600 15px var(--font-body); fill: var(--ink); text-anchor: middle; dominant-baseline: central; }
.ai-map .hub circle { fill: var(--ink); }
.ai-map .dot { fill: var(--ink); }
.ai-steps { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: clamp(16px, 3vw, 48px); max-width: 980px; margin: 0 auto; width: 100%; }
.ai-steps h3 { font-size: 22px; letter-spacing: -0.02em; margin-bottom: 6px; }
.ai-steps p { margin: 0; font-size: 15px; color: var(--ink-2); }
html.ai-live .ai-plug { height: 300svh; }
html.ai-live .ai-plug-stage { position: sticky; top: var(--header-h); height: calc(100svh - var(--header-h)); grid-template-rows: auto minmax(0, 1fr) auto; gap: 3svh; padding-block: 4svh 9svh; }
/* pinned, the diagram takes exactly the height left between the title and the three steps (it scales, never overflows) */
html.ai-live .ai-map { height: 100%; max-height: none; min-height: 0; }
html.ai-live .ai-steps > div { opacity: 0.25; transition: opacity 500ms ease; }
html.ai-live .ai-steps > div.is-on { opacity: 1; }
@media (max-width: 760px) {
  .ai-map { max-height: 52svh; }
  .ai-map .node text, .ai-map .sys text { font-size: 17px; }
  .ai-steps { grid-template-columns: 1fr; gap: 6px; text-align: center; }
  .ai-steps p { display: none; }
  html.ai-live .ai-plug-stage { gap: 2svh; }
}

/* ---------- client logos, live: pinned like the hero copy, then the first film opens up (clients.js) ---------- */
html.clients-live .clients-pin { overflow-x: clip; }   /* the block and its logos slide in from the side: clipped by the pinned block itself, never by .clients (see .svc-intro) */
html.clients-live .clients-pin > * { transform: translateX(var(--clients-x, 0px)); }
html.clients-live .clients { height: 220svh; padding: 0; }
html.clients-live .clients-pin {
  position: sticky; top: var(--header-h); height: calc(100svh - var(--header-h));
  display: flex; flex-direction: column; justify-content: center; will-change: transform, opacity;
}
html.clients-live #story-cma { background: transparent; }
/* the first film rides up as the logos start to leave (clients.js fades them out from 72 % of the section), so the
   two cross instead of leaving an empty screen between them */
html.clients-live #story-cma { margin-top: -50svh; position: relative; z-index: 1; }

/* endless CSS animations pause while their section is away from the screen (js/loop.js sets .is-away) */
.is-away, .is-away * { animation-play-state: paused !important; }
