/* ZAITech Home: the contour field, the panel that carries the hero words and the pause control at the hero's lower corner. Loaded by index.html only, after site.css, whose tokens it uses. */

/* On Home the header lies over the top of the hero. On wide screens it is clear and the field shows through; once the menu wraps it keeps its solid ivory bar. */
.top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 3;
}

@media (min-width: 900px) {
  .top {
    background: none;
    border-bottom-color: transparent;
  }
}

/* The hero fills the first screen but for its last 104 px, where the heading of the next section shows, and the panel sits at its bottom. On a screen too short for that the hero keeps the whole screen. --floor is the least height the hero may have once it has given up those 104 px, and --next is what it gives up: 104 px where the screen is at least --floor and 104 px tall, nothing on a shorter one, and never a part, so the heading is shown whole or not at all. Below 900 px the floor is 800 px, which keeps the cloud that forms in place whole between the header and the panel. The top padding keeps the panel out from under the header on a short screen. */
.hero {
  --screen: 100vh;
  --floor: 800px;
  --next: clamp(0px, (var(--screen) - var(--floor) - 104px) * 1000, 104px);
  position: relative;
  display: flex;
  align-items: flex-end;
  min-height: calc(var(--screen) - var(--next));
  padding-top: 116px;
  overflow: hidden;
}

/* Where the browser knows the small viewport height, that is the height of a screen. */
@supports (height: 100svh) {
  .hero {
    --screen: 100svh;
  }
}

/* The section under the hero is ivory like the hero itself, so a hairline marks the edge where the field's lines are cut. Its heading stands 48 px under that edge, inside the strip of the first screen that the hero leaves free. */
.hero + .sec {
  padding-top: 48px;
  border-top: 1px solid var(--rule);
}

/* The field fills the hero and crops, never stretches. It hangs from the top edge: on a screen wider than the drawing the surplus is cut from the bottom, so the strip under the header's words is the same empty strip of the drawing at every width. On a taller screen the sides are cut evenly. */
.field {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: auto;
  min-height: 100%;
  aspect-ratio: 8 / 5;
}

/* Each line is one group holding two streaks; both share the group's speed (--d) and differ by half a cycle. */
.streaks use {
  fill: none;
  stroke: var(--ink);
  stroke-width: 1.2;
  opacity: 0.42;
  stroke-linecap: round;
  stroke-dasharray: 340 2200;
  stroke-dashoffset: 2540;
}

/* The one clay line carries one streak. */
.clay {
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.2;
  opacity: 0.85;
  stroke-linecap: round;
  stroke-dasharray: 480 2200;
  stroke-dashoffset: 2680;
}

/* A cloud is drawn by a streak (.form), then its outline (.shape) stays and glides. */
.cloud .shape {
  fill: none;
  stroke: var(--ink);
  stroke-width: 1.2;
  opacity: 0;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.cloud .form {
  fill: none;
  stroke: var(--ink);
  stroke-width: 1.2;
  opacity: 0.42;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* The fourth cloud forms in place, one puff after another. Unitless numbers throughout: mixed units made the browser drop the dash array. */
.snake .puff {
  fill: none;
  stroke: var(--ink);
  stroke-width: 1.2;
  opacity: 0;
  stroke-linecap: round;
  stroke-dasharray: var(--P) 1000;
  stroke-dashoffset: var(--P);
}

/* The panel: solid ivory, so no word sits on the field. Its clay rule stands on the same left edge as the wordmark and the sections below. */
.panel {
  position: relative;
  z-index: 2;
  max-width: 720px;
  margin: 0 var(--gutter) 72px max(var(--gutter), calc((100% - var(--max)) / 2));
  padding: 40px 44px 36px;
  border-left: 2px solid var(--accent);
  background: var(--bg);
}

/* Inside the panel the small line, the headline and the button have sizes of their own. The small line above the headline is in the label style and in muted ink, never clay: the clay on this screen is the rule and the button. It may run to two lines, so it keeps a line height. */
.panel .eyebrow {
  max-width: none;
  margin-top: -4px;
  margin-bottom: 18px;
  font-weight: 500;
  line-height: 1.7;
}

.panel h1 {
  font-size: clamp(40px, 4.6vw, 64px);
}

.panel h1 span {
  display: block;
}

.sub {
  max-width: 46ch;
  margin: 22px 0 30px;
  font-size: 19px;
  color: var(--muted);
}

.panel .btn {
  display: inline-block;
  min-height: 0;
  padding: 14px 22px;
  border: 0;
  border-radius: 0;
  font-size: 15px;
}

/* The pause control at the hero's lower corner: on a chip of solid ivory, so no word sits on the field. It stands on the right edge of the page's column and on the hero's bottom edge, beside or below the panel and never over its words. */
.hero .pause {
  position: absolute;
  right: max(var(--gutter), calc((100% - var(--max)) / 2));
  bottom: 0;
  z-index: 2;
  padding: 0 14px;
  background: var(--bg);
}

/* Wide screens. On a short one (a small laptop) the panel tightens by degrees so that its top edge stays under the cloud that forms in place. The lower edge of that cloud is 215 units down the drawing, which is 1440 by 900 and fills the hero by width or by height, whichever needs the larger scale: --cloud is that edge in px, worked out from the whole screen, so it is never too small. --room is what lies between that edge and the hero's bottom edge; the hero gives up its last 104 px only where 452 px of room are left afterwards, which keeps the headline at 52 px or more there. */
/* At full size the panel and its bottom margin take 600 px with the headline on three lines, and 10 px are kept clear. --give is how many px they give up: 0 on any screen tall enough, at most 140. The factors below share it out. Under 58 px the headline takes two lines, not three, which frees 67 px in one step; so from a give of 69 px (a headline of 55 px) the sum counts on two lines, where the factors add up to 1 (a px off the headline's size is 2.1 px off its two lines). */
@media (min-width: 900px) {
  .hero {
    padding-top: 96px;
    --cloud: max(14.93vw, 0.2389 * var(--screen));
    --floor: calc(452px + var(--cloud));
    --room: calc(var(--screen) - var(--next) - var(--cloud));
    --give: clamp(0px, min(610px - var(--room), max(69px, 543px - var(--room))), 140px);
  }
  .panel {
    margin-bottom: calc(72px - 0.34 * var(--give));
    padding-top: calc(40px - 0.115 * var(--give));
    padding-bottom: calc(36px - 0.085 * var(--give));
  }
  .panel .eyebrow {
    margin-bottom: calc(18px - 0.06 * var(--give));
  }
  .panel h1 {
    font-size: min(clamp(40px, 4.6vw, 64px), calc(64px - 0.13 * var(--give)));
  }
  .sub {
    margin: calc(22px - 0.06 * var(--give)) 0 calc(30px - 0.07 * var(--give));
  }
}

/* Phones: the panel takes the full width at the bottom of the screen, and each line carries one streak, not two. */
@media (max-width: 699.98px) {
  .panel {
    flex: 1 1 auto;
    max-width: none;
    margin: 0 var(--gutter) 40px;
    padding: 28px 24px;
  }
  /* Sized so that the headline takes three lines on a 360 px screen. */
  .panel h1 {
    font-size: clamp(30px, 9.4vw, 40px);
  }
  .streaks use.b {
    display: none;
  }
}

@media (max-width: 599.98px) {
  .sub {
    margin: 18px 0 26px;
    font-size: 17px;
  }
}

/* Under 425 px the five pages take two rows and the header is 144 px tall; the panel starts below it. */
@media (max-width: 424.98px) {
  .hero {
    padding-top: 160px;
  }
}

/* Under 342 px the address takes a row of its own as well, so that it stays clear of the curl that ends the name's line, and the header is 168 px tall. */
@media (max-width: 341.98px) {
  .hero {
    padding-top: 184px;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .streaks g { --d: 11s; --p: 0s; }
  .streaks g:nth-child(3n) { --d: 13.5s; }
  .streaks g:nth-child(5n) { --d: 9.5s; }
  .streaks g:nth-child(7n) { --d: 15s; }
  .streaks g:nth-child(4n+1) { --p: -2.4s; }
  .streaks g:nth-child(6n+2) { --p: -3.7s; }
  .streaks use { animation: run var(--d) linear infinite; animation-delay: var(--p); }
  .streaks use.b { animation-delay: calc(var(--p) - var(--d) / 2); }
  @keyframes run { from { stroke-dashoffset: 2540; } to { stroke-dashoffset: 0; } }

  .clay { animation: runclay 12s linear infinite; }
  @keyframes runclay { from { stroke-dashoffset: 2680; } to { stroke-dashoffset: 0; } }

  .cloud { animation: glide var(--T) linear infinite var(--D); }
  .cloud .form { animation: form var(--T) linear infinite var(--D); }
  .cloud .shape { animation: show var(--T) linear infinite var(--D); }
  @keyframes glide { 0%, 7% { transform: translate(var(--x), var(--y)); } 100% { transform: translate(calc(var(--x) + var(--dist)), var(--y)); } }
  @keyframes form { 0% { stroke-dashoffset: var(--o0); opacity: 0.42; } 7% { stroke-dashoffset: var(--o1); opacity: 0.42; } 7.01%, 100% { stroke-dashoffset: var(--o1); opacity: 0; } }
  @keyframes show { 0%, 6.99% { opacity: 0; } 7%, 100% { opacity: 0.42; } }
  .cloud.c1 { --T: 70s; --D: -12s; --x: 300px; --y: 170px; --dist: 1360px; }
  .cloud.c2 { --T: 85s; --D: -50s; --x: 560px; --y: 345px; --dist: 1100px; }
  .cloud.c3 { --T: 52s; --D: -28s; --x: 820px; --y: 640px; --dist: 860px; }

  /* One 20 s clock for the fourth cloud; each puff starts at its own point on it. */
  .snake .puff { animation: puff 20s linear infinite; }
  @keyframes puff { 0% { stroke-dashoffset: var(--P); opacity: 0.42; } 3.5% { stroke-dashoffset: 0; opacity: 0.42; } 30% { opacity: 0.42; } 52% { opacity: 0; } 99.9% { opacity: 0; stroke-dashoffset: 0; } 100% { stroke-dashoffset: var(--P); opacity: 0; } }

  /* The page-load arrival, in turn: the small line, the headline, the sentence, the button, then the first section. The keyframes are the ones site.css defines. */
  .panel .eyebrow,
  .panel h1,
  .sub,
  .panel .btn,
  .hero + .sec {
    animation: arrive 0.45s ease-out both;
  }
  .panel h1 { animation-delay: 0.09s; }
  .sub { animation-delay: 0.18s; }
  .panel .btn { animation-delay: 0.27s; }
  .hero + .sec { animation-delay: 0.36s; }

  /* Pause motion, as site.css sets it: with the box ticked every streak, the clay line and the clouds stop where they are. The lines that arrive when the page loads are left to finish arriving. */
  @supports selector(:has(*)) {
    body:has(#pause-motion:checked) .field * {
      animation-play-state: paused !important;
    }
    body:has(#pause-motion:checked) .panel .eyebrow,
    body:has(#pause-motion:checked) .panel h1,
    body:has(#pause-motion:checked) .sub,
    body:has(#pause-motion:checked) .panel .btn,
    body:has(#pause-motion:checked) .hero + .sec {
      animation-play-state: running !important;
    }
  }
}

/* Motion off: the streaks and the forming strokes go; three cloud outlines and the clay line stand still. */
@media (prefers-reduced-motion: reduce) {
  .streaks,
  .cloud .form,
  .snake {
    display: none;
  }
  .clay {
    stroke-dasharray: none;
    stroke-dashoffset: 0;
    opacity: 0.5;
  }
  .cloud .shape { opacity: 0.3; }
  .cloud.c1 { transform: translate(700px, 170px); }
  .cloud.c2 { transform: translate(900px, 345px); }
  .cloud.c3 { transform: translate(1100px, 640px); }
}

/* Motion off on a phone. The screen shows only the middle of the drawing (about 520 to 920 across), and only the part between the header and the panel, which has room for one outline. That outline and the clay line, with its curl, are set inside that part, so the still is whole and no end of a line shows beside the panel; the other two outlines are left out. */
@media (prefers-reduced-motion: reduce) and (max-width: 699.98px) {
  .clay { transform: translate(-330px, -215px); }
  .cloud.c1 { transform: translate(540px, 215px); }
  .cloud.c2, .cloud.c3 { display: none; }
}
