/* The scan (src/scan.mjs): the full-bleed background of the first screen and of every page's head. On the site's own
   tokens: it follows the page's theme (Daylight on the marketing pages, Workspace on the tools). A sweep is ten wake
   durations; lines draw over a draw duration; everything else is the measuring plane's own linear pace.
   The plane runs on its own (two compositor transforms); on a scroll stage, scroll.js takes it over (.is-scrubbed,
   --sweep from 0 to 1) and every line and figure follows the plane's position instead of the clock. */
.ei-scan {
  --scan-dur: calc(var(--dur-wake) * 10);
  --photo-opacity: 1;
  --zoom: 1.12; --shift-x: 7%; --shift-y: 1%;
  position: absolute; inset: 0; overflow: hidden; background: var(--surface-000);
  container-type: size; pointer-events: none; user-select: none;
}
[data-theme="dark"] .ei-scan { --photo-opacity: .92; }
/* A 16:9 stage that covers its host, like object-fit: cover, composed per page. */
.ei-scan__stage {
  position: absolute; left: 50%; top: 50%;
  translate: calc(-50% + var(--shift-x)) calc(-50% + var(--shift-y)); scale: var(--zoom);
  width: max(100cqw, calc(100cqh * 16 / 9)); height: max(100cqh, calc(100cqw * 9 / 16));
}
@container (max-aspect-ratio: 1/1) {
  .ei-scan__stage { --zoom: .66; --shift-x: 1%; --shift-x2: 1%; --shift-y: 24%; }
}
.ei-scan__ground { position: absolute; left: -100%; top: -100%; width: 300%; height: 300%; display: block; }
.ei-scan__photo, .ei-scan__water { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
/* The picture fades into the ground at its edges; the villa and its pool stay whole. */
.ei-scan__photo, .ei-scan__pool {
  -webkit-mask-image: radial-gradient(ellipse 62% 70% at 55% 50%, #000 52%, rgb(0 0 0 / .7) 75%, transparent 100%);
          mask-image: radial-gradient(ellipse 62% 70% at 55% 50%, #000 52%, rgb(0 0 0 / .7) 75%, transparent 100%);
}
.ei-scan__photo { object-fit: cover; opacity: var(--photo-opacity); }
/* The band: a window onto the model, a soft trailing edge and a crisp leading one. */
.ei-scan__band { position: absolute; top: 0; bottom: 0; left: 0; width: 30%; animation: ei-scan-band var(--scan-dur) linear infinite; will-change: transform; }
.ei-scan__window {
  position: absolute; inset: 0; overflow: hidden;
  -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 24%, #000 calc(100% - var(--space-6)), transparent 100%);
          mask-image: linear-gradient(90deg, transparent 0, #000 24%, #000 calc(100% - var(--space-6)), transparent 100%);
}
.ei-scan__model { position: absolute; top: 0; left: 0; height: 100%; width: 1000%; background: var(--surface-000); animation: ei-scan-model var(--scan-dur) linear infinite; will-change: transform; }
.ei-scan__model > svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
@keyframes ei-scan-band { from { transform: translateX(-100%); } to { transform: translateX(333.3333%); } }
@keyframes ei-scan-model { from { transform: translateX(-23.3333%); } to { transform: translateX(-66.6667%); } }
.ei-scan__plane { position: absolute; top: 0; bottom: 0; right: 0; width: var(--stroke-hair); background: var(--ink); opacity: .45; }

/* Lines draw and figures appear as the plane passes them: each carries its moment in the sweep as --at. */
.ei-scan .draw { stroke-dasharray: 1; stroke-dashoffset: 1; animation: ei-draw var(--scan-dur) linear infinite; animation-delay: calc(var(--scan-dur) * var(--at, 0)); }
@keyframes ei-draw { 0% { stroke-dashoffset: 1; } 5% { stroke-dashoffset: 0; } 100% { stroke-dashoffset: 0; } }
.ei-scan .reveal, .ei-scan .reveal-g { opacity: 0; animation: ei-reveal var(--scan-dur) linear infinite; animation-delay: calc(var(--scan-dur) * var(--at, 0)); }
@keyframes ei-reveal { 0%, 2.5% { opacity: 0; } 5%, 100% { opacity: 1; } }
/* The datum lands once each time the plane reaches it. */
.ei-scan .datum .pulse { animation: ei-pulse var(--scan-dur) var(--ease-instrument) infinite; animation-delay: calc(var(--scan-dur) * var(--at, 0)); transform-box: fill-box; transform-origin: center; }
@keyframes ei-pulse { 0%, 3% { transform: scale(1.6); opacity: 0; } 5% { transform: scale(1); opacity: 1; } 100% { transform: scale(1); opacity: 1; } }

/* The drawing. */
.ei-scan .grid path { stroke: var(--line); stroke-width: 1; fill: none; vector-effect: non-scaling-stroke; opacity: .7; }
.ei-scan .kerb path { stroke: var(--line-strong); stroke-width: 1; fill: none; vector-effect: non-scaling-stroke; opacity: .6; }
.ei-scan .parcel path { stroke: var(--line-strong); stroke-width: 1; fill: none; stroke-dasharray: 14 6 2 6; vector-effect: non-scaling-stroke; }
.ei-scan .u-grid { stroke: var(--line); stroke-width: 1; opacity: .7; }
.ei-scan .u-kerb { stroke: var(--line-strong); stroke-width: 1; opacity: .6; }
.ei-scan .u-parcel { stroke: var(--line-strong); stroke-width: 1; stroke-dasharray: 14 6 2 6; }
.ei-scan .arch-p { stroke: var(--ink-muted); stroke-width: 1; fill: none; vector-effect: non-scaling-stroke; stroke-linecap: round; }
.ei-scan .struct-p { stroke: var(--ink); stroke-width: 1.5; fill: none; vector-effect: non-scaling-stroke; stroke-linecap: round; }
.ei-scan .mep path { stroke-width: 1.75; fill: none; vector-effect: non-scaling-stroke; stroke-linecap: round; stroke-linejoin: round; }
.ei-scan .mep--water { stroke: var(--ice-ink); }
.ei-scan .mep--power { stroke: var(--nerve); }
.ei-scan .datum circle { fill: none; stroke: var(--laser); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.ei-scan .datum path { stroke: var(--laser); stroke-width: 1.5; fill: none; vector-effect: non-scaling-stroke; }
.ei-scan .datum .leader { stroke-width: 1; opacity: .8; }
.ei-scan .datum .dot { fill: var(--laser); stroke: none; }
.ei-scan .fig { font: 500 13px/1 var(--font-mono); fill: var(--ink-muted); font-variant-numeric: tabular-nums; }
.ei-scan .datum-id { fill: var(--laser-ink); }
.ei-scan .coord { font-size: 11px; }
.ei-scan .dims .dim, .ei-scan .levels .dim { stroke: var(--ink-muted); stroke-width: 1; fill: none; vector-effect: non-scaling-stroke; }
.ei-scan .levels .dim { fill: var(--ink-muted); }

/* The pool: water that keeps moving, with the sun on it. The light is the caustic texture used as a mask over a
   plain light layer (so it is decoration, never the page's largest picture), laid on the ground as the iso picture
   lies (the 30° set square's matrix), clipped to the pool the picture shows. --u is one of the picture's pixels on
   the stage. Each layer slides by exactly one tile of its own (its period along the ground), so the loop has no seam;
   the glints flare and go, each on its own period. */
.ei-scan__w1 { stop-color: var(--ice); }
.ei-scan__w2 { stop-color: var(--ice-ink); }
.ei-scan__water-tint { opacity: .5; }
.ei-scan__light {
  --u: calc(max(100cqw, 100cqh * 16 / 9) / 1920);
  position: absolute; left: 40.2552%; top: 68.9815%; width: 14.7083%; height: 15.0926%; overflow: hidden;
  clip-path: polygon(33.75% 0, 100% 66.26%, 66.25% 100%, 0 33.74%); opacity: var(--water, 1); pointer-events: none;
}
.ei-scan__caustic {
  --tile: calc(158.72 * var(--u)); --iso: matrix(0.866, 0.5, -0.866, 0.5, 0, 0);
  position: absolute; left: -100%; top: -250%; width: 320%; height: 500%; transform-origin: 0 0;
  background: var(--surface-100); mix-blend-mode: screen; opacity: .55;
  -webkit-mask: url(/assets/img/scan/caustic.png) 0 0 / var(--tile) var(--tile) repeat;
          mask: url(/assets/img/scan/caustic.png) 0 0 / var(--tile) var(--tile) repeat;
  transform: var(--iso);
  animation: ei-caustic calc(var(--dur-wake) * 6) linear infinite;
}
.ei-scan__caustic--2 { --tile: calc(117.76 * var(--u)); opacity: .35; transform: var(--iso) rotate(90deg); animation: ei-caustic-2 calc(var(--dur-wake) * 9.5) linear infinite; }
@keyframes ei-caustic { from { transform: translate(calc(-137.45 * var(--u)), calc(-79.36 * var(--u))) var(--iso); } to { transform: var(--iso); } }
@keyframes ei-caustic-2 { from { transform: var(--iso) rotate(90deg); } to { transform: translate(calc(101.98 * var(--u)), calc(58.88 * var(--u))) var(--iso) rotate(90deg); } }
.ei-spark { fill: var(--surface-100); transform: scale(0); transform-box: fill-box; transform-origin: center; animation: ei-twinkle calc(var(--dur-wake) * var(--t, 1.6)) var(--ease-draw) calc(var(--dur-wake) * var(--d, 0)) infinite; }
@keyframes ei-twinkle { 0%, 100% { transform: scale(0); opacity: 0; } 10% { opacity: 1; } 20% { transform: scale(var(--s, 1.6)) rotate(12deg); opacity: 1; } 32% { transform: scale(0); opacity: 0; } }

/* Compositions for the pages' heads (src/layout.mjs pageHead; the zooms are also in src/scan.mjs ZOOM, for the
   picture's sizes): where the villa sits, and what the drawing stresses on each page. */
.ei-scan[data-frame="method"] { --zoom: 1.5; --shift-x: 17%; --shift-y: 12%; }
.ei-scan[data-frame="method"] .struct-p { stroke-width: 2.5; }
.ei-scan[data-frame="method"] .arch-p { opacity: .55; }
.ei-scan[data-frame="work"] { --zoom: 1; --shift-x: 15%; --shift-y: 3%; }
.ei-scan[data-frame="work"] .parcel path, .ei-scan[data-frame="work"] .u-parcel { stroke: var(--ink); stroke-width: 2; }
.ei-scan[data-frame="tools"] { --zoom: 1.25; --shift-x: 13%; --shift-y: 4%; --mep: .7; }
.ei-scan[data-frame="standards"] { --zoom: 1.4; --shift-x: 6%; --shift-y: 8%; }
.ei-scan[data-frame="standards"] .fig { font-size: 17px; }
.ei-scan[data-frame="standards"] .coord { font-size: 13px; }
.ei-scan[data-frame="contact"] { --zoom: 1.2; --shift-x: 13%; --shift-y: 10%; }
.ei-scan[data-frame="contact"] .datum circle, .ei-scan[data-frame="contact"] .datum path { stroke-width: 2.5; }
.ei-scan[data-frame="glossary"] { --zoom: 1.1; --shift-x: 13%; --shift-y: 12%; }
[dir="rtl"] .ei-scan[data-frame="method"] { --shift-x: -21%; }
[dir="rtl"] .ei-scan[data-frame="work"] { --shift-x: -19%; }
[dir="rtl"] .ei-scan[data-frame="tools"] { --shift-x: -17%; }
[dir="rtl"] .ei-scan[data-frame="standards"] { --shift-x: -12%; }
[dir="rtl"] :is(.ei-scan[data-frame="contact"], .ei-scan[data-frame="glossary"]) { --shift-x: -17%; }
@container (max-aspect-ratio: 1/1) {
  .ei-scan:not([data-frame="home"]) .ei-scan__stage { --zoom: .58; --shift-x: -2%; --shift-y: -14%; }
}

/* Off screen or in a hidden tab, nothing moves (scan.js sets .is-paused). */
.ei-scan.is-paused, .ei-scan.is-paused * { animation-play-state: paused !important; }

/* Taken over by the scroll (the home page's first scene, assets/js/pages/home.js): the plane stands where the scroll
   puts it (--sweep, 0 to 1), and everything it has passed is the model. The band, 130% of the stage with the plane as
   its right edge, slides in from the left while the drawing inside it slides back by as much, so the drawing stays
   put: two transforms. A line is drawn and a figure shown once the plane has passed it. Before the scroll takes over,
   the band on its own clock fades (--band-o), so the hand-over never jumps. */
.ei-scan__band { opacity: var(--band-o, 1); }
.ei-scan.is-scrubbed .ei-scan__band { animation: none; width: 130%; transform: translateX(calc((var(--sweep, 0) - 1) * 100%)); }
.ei-scan.is-scrubbed .ei-scan__window {
  -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - var(--space-6)), transparent);
          mask-image: linear-gradient(90deg, #000 calc(100% - var(--space-6)), transparent);
}
.ei-scan.is-scrubbed .ei-scan__model { animation: none; width: 230.7692%; transform: translateX(calc(-33.3333% + (1 - var(--sweep, 0)) * 43.3333%)); }
.ei-scan.is-scrubbed .draw { animation: none; stroke-dashoffset: calc(1 - clamp(0, (var(--sweep, 0) - var(--at, 0)) * 20, 1)); }
.ei-scan.is-scrubbed .reveal, .ei-scan.is-scrubbed .reveal-g { animation: none; opacity: clamp(0, (var(--sweep, 0) - var(--at, 0)) * 40 - 1, 1); }
.ei-scan.is-scrubbed .datum .pulse { animation: none; }
/* The water goes with the picture (--water). Drawn as water (assets/js/scan-water.js) where WebGL is there: a canvas
   over the pool's opening, under the picture's own mask; the CSS light and glints are then put away. */
.ei-scan__water { opacity: var(--water, 1); }
.ei-scan__pool { position: absolute; inset: 0; pointer-events: none; opacity: calc(var(--photo-opacity) * var(--water, 1)); }
.ei-scan__pool canvas { position: absolute; display: block; }
.ei-scan.has-water .ei-scan__light, .ei-scan.has-water .ei-scan__sparks, .ei-scan.has-water .ei-scan__water-tint { display: none; }
/* The storeys lift apart (--explode, 0 to 1). In a parallel view a rise in the model is a rise on the screen, so a
   vertical shift is an exact explode: the upper floor rises by --lift, the roof by twice it, and the levels ride with
   their storeys. What no longer holds while they are apart (the overall dimensions, the datum, the runs that cross the
   floors) steps aside until they settle. */
.ei-scan [data-storey="1"] { transform: translateY(calc(var(--explode, 0) * -1 * var(--lift, 0px))); }
.ei-scan [data-storey="2"] { transform: translateY(calc(var(--explode, 0) * -2 * var(--lift, 0px))); }
.ei-scan__ann, .ei-scan__runs { opacity: calc(1 - var(--explode, 0)); }
/* The services stay as the architecture steps back (--mep, 0 to 1). */
.ei-scan .arch-p { opacity: calc(1 - var(--mep, 0) * .7); }
.ei-scan .struct-p { opacity: calc(1 - var(--mep, 0) * .55); }
.ei-scan .mep path { stroke-width: calc(1.75px + var(--mep, 0) * 1.25px); }

/* Still (reduced motion, ?p, ?freeze): the plane rests through the building, the model on its left awake, the water
   still. */
html.is-still .ei-scan__band { animation: none; width: 56%; transform: none; }
html.is-still .ei-scan__model { animation: none; width: 535.7143%; transform: translateX(-33.3333%); }
html.is-still .ei-scan .draw, html.is-still .ei-scan .reveal, html.is-still .ei-scan .reveal-g, html.is-still .ei-scan .datum .pulse, html.is-still .ei-spark { animation: none; }
html.is-still .ei-scan .draw { stroke-dashoffset: 0; }
html.is-still .ei-scan .reveal, html.is-still .ei-scan .reveal-g { opacity: 1; }
html.is-still .ei-scan__caustic, html.is-still .ei-scan__sparks { display: none; }
@media (prefers-reduced-motion: reduce) {
  .ei-scan__band, .ei-scan__model, .ei-scan .draw, .ei-scan .reveal, .ei-scan .reveal-g, .ei-spark, .ei-scan__caustic { animation: none; }
}
