/* Homepage hero: files swarm the screen, RALPH appears and clears them, then the headline and button fade in.
   Markup: the [data-swarm-hero] block in index.html and mobile/index.html. Behaviour: swarm-hero.js.

   States (data-swarm on the block, set before first paint by a tiny inline script):
   - none / "still": the finished frame (mark, headline, button). No script, reduced motion, data saver, slow
     connection or a slow phone all end up here. Nothing moves and nothing is hidden.
   - "pending": script is about to start; the copy is held back. A CSS timer reveals it if the script never runs.
   - "playing": the swarm runs; the copy stays transparent but remains in the page for screen readers.
   - "done": the copy has faded in; the skip button has become a replay button.
   Linked after every other stylesheet on both the desktop page and /mobile/. */
.swarm-hero {
  --sh-ink: #16161a;
  --sh-navy: #173a65;
  --sh-blue: #2f6bdb;
  --sh-fw: clamp(90px, 8.6vw, 124px);          /* file width; height is 1.25x */
  position: relative;
  isolation: isolate;
  box-sizing: border-box;
  display: grid;
  place-items: center;
  width: 100%;
  min-height: clamp(540px, calc(100svh - 110px), 780px);
  padding: clamp(28px, 5vh, 56px) clamp(16px, 4vw, 48px);
  overflow: hidden;
  text-align: center;
}
.swarm-hero.surface { background: transparent; border-color: transparent; box-shadow: none; }
/* On the desktop page every section is one snap scene the height of the screen below the header
   (see scrollytelling.css). On /mobile/ the hero is nested inside the first card and flows normally. */
.page > .swarm-hero {
  height: var(--ralph-stage-height);
  min-height: var(--ralph-stage-height);
  max-height: var(--ralph-stage-height);
  margin: 0;
  border-radius: 0;
  overflow-x: clip;
  overflow-y: auto;
  scroll-snap-align: start;
}

/* ---------- Stage: files, halo ---------- */
.swarm-stage {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}
.swarm-halo {
  position: absolute;
  left: 50%; top: 50%;
  width: clamp(240px, 34vw, 420px);
  aspect-ratio: 1;
  margin: calc(clamp(240px, 34vw, 420px) / -2) 0 0 calc(clamp(240px, 34vw, 420px) / -2);
  border-radius: 50%;
  background: radial-gradient(circle, rgb(47 107 219 / .20) 0%, rgb(47 107 219 / .08) 45%, transparent 70%);
  opacity: 0;
}
.swarm-file {
  position: absolute;
  left: 50%; top: 50%;
  width: var(--sh-fw);
  height: calc(var(--sh-fw) * 1.25);
  opacity: 0;
  visibility: hidden;
  color: var(--sh-ink);
}
[data-swarm="playing"] .swarm-file { will-change: transform, opacity; }
[data-swarm="done"] .swarm-file, [data-swarm="still"] .swarm-file, .swarm-hero:not([data-swarm]) .swarm-file { display: none; }

/* The outline is the outer shape and the paper sits inside it, so the folded corner keeps an even line. */
.swarm-file-body, .swarm-file-paper {
  position: absolute;
  --fold: calc(var(--sh-fw) * .2);
  clip-path: polygon(0 0, calc(100% - var(--fold)) 0, 100% var(--fold), 100% 100%, 0 100%);
}
.swarm-file-body { inset: 0; background: var(--sh-ink); }
.swarm-file-paper {
  inset: 2px;
  background: #fff;
  display: flex;
  flex-direction: column;
  gap: calc(var(--sh-fw) * .07);
  padding: calc(var(--sh-fw) * .09);
  box-sizing: border-box;
  overflow: hidden;
}
.swarm-file--note .swarm-file-paper { background: #e6f0fd; justify-content: center; align-items: center; }
.swarm-file--sheet .swarm-file-paper { background: #f3faf6; }
.swarm-file-chip {
  align-self: flex-start;
  padding: 1px calc(var(--sh-fw) * .06);
  border-radius: 3px;
  background: var(--chip, var(--sh-blue));
  color: #fff;
  font: 700 calc(var(--sh-fw) * .1)/1.3 Inter, system-ui, sans-serif;
  letter-spacing: .04em;
}
.swarm-file--sheet { --chip: #4f9b72; }
.swarm-file--doc { --chip: var(--sh-blue); }
.swarm-file--pdf { --chip: #173a65; }
.swarm-file-lines {
  flex: 1 1 auto;
  min-height: 0;
  background:
    repeating-linear-gradient(to bottom, #b9c8de 0 2px, transparent 2px calc(var(--sh-fw) * .1));
  opacity: .8;
}
.swarm-file--sheet .swarm-file-lines {
  background:
    repeating-linear-gradient(to bottom, #9cc9b0 0 1.5px, transparent 1.5px calc(var(--sh-fw) * .13)),
    repeating-linear-gradient(to right, #9cc9b0 0 1.5px, transparent 1.5px calc(var(--sh-fw) * .26));
}
.swarm-file-label {
  display: block;
  font: 600 max(9px, calc(var(--sh-fw) * .115))/1.2 Inter, system-ui, sans-serif;
  color: var(--sh-ink);
  overflow-wrap: anywhere;
  text-align: left;
}
.swarm-file--note .swarm-file-label {
  font-size: max(9px, calc(var(--sh-fw) * .15));
  font-weight: 700;
  line-height: 1.18;
  text-align: center;
  color: var(--sh-navy);
}

/* ---------- Copy ---------- */
.swarm-copy {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 980px;
  margin-inline: auto;
}
.swarm-mark-slot {
  display: block;
  width: clamp(44px, 4.4vw, 58px);
  aspect-ratio: 430 / 530;
  margin: 0 auto clamp(16px, 2.6vh, 26px);
}
.swarm-mark {
  display: block;
  width: 100%;
  height: 100%;
  transform-origin: 50% 50%;
}
.swarm-hero .swarm-title {
  margin: 0;
  font-size: clamp(40px, 5.6vw, 80px);
  font-weight: 720; /* same as the other section headings */
  line-height: 1.12;
  letter-spacing: -0.03em;
  text-align: center;
  /* Gradient text is clipped to the box: give descenders (the g, p, y) room, and take it back from the margin. */
  padding-bottom: .16em;
  margin-bottom: -.16em;
  text-wrap: balance;
  color: var(--sh-navy);
  background: linear-gradient(100deg, #173a65 0%, #1f55a3 55%, #3a86d8 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.swarm-hero .swarm-copy .swarm-cta { display: flex; justify-content: center; margin: clamp(24px, 4vh, 40px) 0 0; }
.swarm-hero .swarm-copy .swarm-button {
  display: inline-flex;
  flex: 0 0 auto;
  width: auto;
  min-width: 0;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  padding: 12px 30px;
  border: 1px solid #173d78;
  border-radius: 999px;
  background: linear-gradient(110deg, #091f46 0%, #123f85 60%, #387ee5 100%);
  color: #fff;
  -webkit-text-fill-color: #fff;
  font: 700 15px/1 Inter, system-ui, sans-serif;
  text-decoration: none;
  white-space: nowrap;
  box-shadow: 0 8px 22px rgb(23 61 120 / .22);
}
.swarm-hero .swarm-copy .swarm-button:hover { background: linear-gradient(110deg, #12336b 0%, #2464c0 65%, #5698f3 100%); }
.swarm-hero .swarm-copy .swarm-button:focus-visible { outline: 3px solid #3e8bd6; outline-offset: 4px; }
.swarm-hero .swarm-copy .swarm-trust {
  order: 0;
  width: auto;
  max-width: 100%;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px clamp(14px, 2.6vw, 32px);
  margin: clamp(22px, 3.4vh, 34px) 0 0;
}
.swarm-hero .swarm-copy .swarm-trust span {
  display: inline-flex;
  justify-content: center;
  font-weight: 400;
  align-items: center;
  gap: 6px;
  font-size: clamp(12px, 1.05vw, 14px);
  line-height: 1.35;
  color: #3d5271;
}
.swarm-hero .swarm-copy .swarm-trust .swarm-ico { width: 16px; height: 16px; flex: 0 0 16px; color: var(--sh-blue); fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Control: skip while playing, replay when finished ---------- */
.swarm-control {
  position: absolute;
  z-index: 3;
  left: 50%;
  bottom: clamp(12px, 2.4vh, 24px);
  margin-left: -22px;
  display: inline-grid;
  place-items: center;
  width: 44px; height: 44px;
  padding: 0;
  border: 1px solid #cfe0f5;
  border-radius: 50%;
  background: #fff;
  color: var(--sh-navy);
  cursor: pointer;
}
.swarm-control:hover { background: #eaf1fd; }
.swarm-control:focus-visible { outline: 3px solid #3e8bd6; outline-offset: 3px; }
.swarm-control svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.swarm-control .swarm-icon-replay { display: none; }
.swarm-control[data-mode="replay"] .swarm-icon-skip { display: none; }
.swarm-control[data-mode="replay"] .swarm-icon-replay { display: block; }
.swarm-control[hidden] { display: none; }
.swarm-hero:not([data-swarm]) .swarm-control, [data-swarm="pending"] .swarm-control { display: none; }
/* On the still frame (reduced motion, data saver, slow phone) the control says what it does, so the animation is one clear tap away. */
.swarm-hero[data-swarm="still"] .swarm-control {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: auto; height: 40px; margin-left: 0; padding: 0 16px 0 12px;
  transform: translateX(-50%); border-radius: 999px;
  bottom: clamp(72px, 12vh, 110px);
  font: 600 14px/1 Inter, ui-sans-serif, system-ui, sans-serif; white-space: nowrap;
}
.swarm-hero[data-swarm="still"] .swarm-control::after { content: 'Play animation'; }

/* ---------- State: what the copy and mark do ---------- */
[data-swarm="pending"] .swarm-copy > *:not(.swarm-mark-slot),
[data-swarm="playing"] .swarm-copy > *:not(.swarm-mark-slot) { opacity: 0; }
[data-swarm="pending"] .swarm-copy .swarm-cta,
[data-swarm="playing"] .swarm-copy .swarm-cta { pointer-events: none; }
[data-swarm="pending"] .swarm-mark,
[data-swarm="playing"] .swarm-mark { opacity: 0; }
.swarm-hero:has(.swarm-copy:focus-within) .swarm-copy > * { opacity: 1; }

[data-swarm="done"] .swarm-copy > *:not(.swarm-mark-slot) {
  opacity: 1;
  transition: opacity .7s ease, translate .7s cubic-bezier(.2, .7, .2, 1);
}
[data-swarm="done"] .swarm-copy > .swarm-cta { transition-delay: .15s; }
[data-swarm="done"] .swarm-copy > .swarm-trust { transition-delay: .3s; }
[data-swarm="playing"] .swarm-copy > *:not(.swarm-mark-slot) { translate: 0 10px; }

/* If the script never runs, show the copy anyway. */
[data-swarm="pending"] .swarm-copy > *:not(.swarm-mark-slot) { animation: swarm-failsafe .5s ease 3s forwards; }
[data-swarm="pending"] .swarm-mark { animation: swarm-failsafe .5s ease 3s forwards; }
@keyframes swarm-failsafe { to { opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  /* The swarm is not shown, but a visible "Play animation" button lets the visitor choose to watch it. */
  .swarm-hero:not([data-user-play]) .swarm-stage { display: none !important; }
  .swarm-hero:not([data-user-play]) .swarm-copy > *, .swarm-hero:not([data-user-play]) .swarm-mark { opacity: 1 !important; translate: none !important; animation: none !important; transition: none !important; }
}

/* Reduce Motion gets the calm version: the same story told with fades only, so nothing slides in. */
.swarm-hero[data-calm] .swarm-copy > * { translate: none !important; }
.swarm-hero[data-calm] .swarm-file-body { transform: none; }

/* ---------- Phone ---------- */
@media (max-width: 750px), (pointer: coarse) and (max-height: 600px) {
  .swarm-hero {
    --sh-fw: 78px;
    min-height: clamp(460px, 70svh, 600px);
    padding: 28px 16px 40px;
  }
  .swarm-mark-slot { width: 44px; margin-bottom: 14px; }
  .swarm-hero .swarm-title { font-size: clamp(34px, 10.4vw, 46px); }
  .swarm-hero .swarm-copy .swarm-cta { margin-top: 24px; }
  .swarm-hero .swarm-copy .swarm-trust { gap: 8px 16px; margin: 22px 0 0; max-width: 340px; }
  .swarm-hero .swarm-copy .swarm-trust span { font-size: 12.5px; }
  .swarm-control { bottom: 10px; width: 40px; height: 40px; margin-left: -20px; }
}

/* The sketch reception scene's heading: smaller than the hero headline above it. The long selector and
   !important are needed to beat the legacy end-card rules in the desktop and phone stylesheets. */
html body main.page > :is(#intro, #top.ralph-landing-reception)[data-persistent-overlay] .ralph-reception-endcard .ralph-ending-wordmark[data-lede] {
  font-size: clamp(34px, min(4.6vw, 7.2vh), 76px) !important;
  font-weight: 720 !important; /* same as the other section headings */
  line-height: 1.2 !important;
  letter-spacing: -0.03em !important;
}
@media (max-width: 750px), (pointer: coarse) and (max-height: 600px) {
  html body main.page > :is(#intro, #top.ralph-landing-reception)[data-persistent-overlay] .ralph-reception-endcard .ralph-ending-wordmark[data-lede] {
    font-size: clamp(29px, 8.2vw, 33px) !important;
    font-weight: 720 !important;
    letter-spacing: -0.03em !important;
  }
}

/* Desktop: the sketch scene no longer carries a button or icon row, so the drawing may use that height. Same sizing
   formula as the shared hero rule in desktop-refresh.css, with the heading's real height. */
@media (min-width: 751px) and (not ((pointer: coarse) and (max-height: 600px))) {
  html body main.page > :is(#intro, #top.ralph-landing-reception)[data-persistent-overlay]:has(.ralph-ending-wordmark[data-lede]) {
    --hero-title: clamp(34px, min(4.6vw, 7.2vh), 76px);
    --hero-text-h: calc(var(--hero-title) * 2.5 + var(--hero-pad-top) + var(--hero-gap) + var(--hero-clear));
  }
}
