/* Agent on fire: "Agent" in the headline burns inside its letters; the logo's robot stands to its right
   with a gas cylinder and a flamethrower aimed at the word. Page markup, one span per letter:
   <h1>Bring Your Own <span class="af-word"><span>A</span>...<span>t</span></span><span class="af-rig" aria-hidden="true"></span></h1>
   agent-fire.js puts agent-fire.svg into .af-rig, flickers the letters and pauses off-screen.
   How to change things: design/agent-fire.md. Everything tunable is in the first block. */

.hero h1 {
  /* ---- motion ---- */
  --af-anim: running;      /* running | paused. paused shows one still frame (reduced motion uses it too) */
  --af-speed: 1;           /* 2 = flames twice as fast, 0.5 = half as fast */

  /* ---- flame colours, from white-hot to the darkest tips; c2 to c5 are the logo's colours ---- */
  --af-c0: #fff3c8;        /* white-hot: jet core and the spot where the jet hits the word */
  --af-c1: #ffd36b;        /* yellow */
  --af-c2: #fcaa4b;        /* amber: bottom of the logo tile */
  --af-c3: #e8552e;        /* orange: top of the logo tile (the page's --signal) */
  --af-c4: #c8401c;        /* deep red (--signal-deep) */
  --af-c5: #a93514;        /* darkest flame tips (--signal-dark) */

  /* ---- the burning word ---- */
  --af-flame-h: 1;         /* how high the tongues reach inside the letters: 1 = to the x-height, 1.3 = higher */
  --af-glow: 0.5;          /* soft glow around the letters: 0 = none, 1 = strong */
  --af-rim: 0.009;         /* thin deep-red edge that keeps the letters crisp, em: 0 = none */

  /* ---- robot and jet (sizes in em of the headline: 1 = the font size) ---- */
  --af-robot-h: 0.9;       /* robot height, antenna tips to feet */
  --af-gap: 0.32;          /* space between the end of "Agent" and the nozzle; the jet crosses it */
  --af-reach: 0.12;        /* jet length beyond the gap: 0.12 ends it at the t's stem, between hook and crossbar */
  --af-jet-thick: 0.7;     /* jet thickness, 1 = as drawn; above ~0.8 it starts to cover the t's hook */
  --af-robot: #13151b;     /* robot and tank (the page's --ink) */
  --af-steel: #5a6070;     /* wand and hose */
  --af-band: var(--af-c3); /* stripes on the tank */

  /* ---- the two rows of flame tongues inside the word: flat SVG tiles; the grey sets how much they brighten
     the red underneath (lighter = more yellow). Keep both ends of a row at the same height so it tiles. ---- */
  --af-tongues-front: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 200 100' preserveAspectRatio='none'%3E%3Cpath fill='%23626262' d='M0 100V62C28.6 62 42.4 26 52 2C65.4 26.3 78 56 104 56C129.3 56 131.2 35.6 150 22C157.5 40 175 62 200 62V100Z'/%3E%3C/svg%3E");
  --af-tongues-back: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 300 100' preserveAspectRatio='none'%3E%3Cpath fill='%23474747' d='M0 100V54C22 54 23 21.6 40 0C46.3 22.5 62 50 84 50C108.2 50 118.8 32 128 20C139.6 30.8 152 44 176 44C203.5 44 218 20 226 4C244.3 26.5 263 54 300 54V100Z'/%3E%3C/svg%3E");

  /* computed, do not edit: the width the robot adds to the line, in em; the headline's font-size uses it */
  --af-w: calc(var(--af-gap) + var(--af-robot-h) * 1.3);
}
@media (prefers-reduced-motion: reduce) { .hero h1 { --af-anim: paused; } }
.hero h1.af-idle { --af-anim: paused; }   /* set by agent-fire.js while the headline is off-screen */

/* ---------- the burning word ---------- */
/* Per letter: two rows of flat grey tongues (color-dodge turns the red base into orange, amber, yellow),
   clipped to the glyph. Each letter has its own tongue sizes and drift (below), and agent-fire.js sends its
   tongues to random heights (--f1, --f2) over random times (--tt). Padding: room for glyph overhangs.
   Without background-clip: text or color-mix the word is solid deep red. */
.af-word { color: var(--af-c4); }
.af-word > * { padding: 0.12em 0.06em; margin: 0 -0.06em; }
@supports ((background-clip: text) or (-webkit-background-clip: text)) and (color: color-mix(in srgb, red 50%, blue)) {
  .af-word {
    -webkit-text-stroke: calc(var(--af-rim) * 1em) var(--af-c4);
    filter: drop-shadow(0 0 calc(var(--af-glow) * 0.12em) color-mix(in srgb, var(--af-c3) 45%, transparent));
  }
  .af-word > * {
    --W1: calc(var(--fw) * 1em); --W2: calc(var(--bw) * 1em);
    --H1: calc(0.46em * var(--fh) * var(--f1, 1) * var(--af-flame-h)); --H2: calc(0.7em * var(--bh) * var(--f2, 1) * var(--af-flame-h));
    color: transparent;
    /* layers, top first: the spot where the jet touches (only on the t), front tongues, back tongues, red base */
    background-image:
      var(--hot, none),
      var(--af-tongues-front),
      var(--af-tongues-back),
      linear-gradient(to top, color-mix(in srgb, var(--af-c3) 55%, var(--af-c4)) 0.3em, var(--af-c4) 0.7em, var(--af-c5) 1.05em);
    background-size: var(--hs, 0 0), var(--W1) var(--H1), var(--W2) var(--H2), 100% 100%;
    background-repeat: no-repeat, repeat-x, repeat-x, no-repeat;
    background-position: var(--hp, 0 0), left 0em bottom 0.3em, left 0em bottom 0.27em, 0 0;
    background-blend-mode: normal, color-dodge, color-dodge, normal;
    -webkit-background-clip: text;
    background-clip: text;
    transition: background-size var(--tt, 0.5s) ease-in-out;
    animation: af-drift calc(var(--td) / var(--af-speed)) linear calc(var(--dd) / var(--af-speed)) infinite var(--dir);
    animation-play-state: var(--af-anim);
  }
  /* per letter: tongue tile widths (em), height factors, drift loop time, its start offset and direction */
  .af-word > :nth-child(5n+1) { --fw: 0.58; --bw: 1.04; --fh: 1.08; --bh: 0.95; --td: 7.3s; --dd: -1.7s; --dir: normal; }
  .af-word > :nth-child(5n+2) { --fw: 0.71; --bw: 0.86; --fh: 0.9; --bh: 1.12; --td: 6.1s; --dd: -4.4s; --dir: reverse; }
  .af-word > :nth-child(5n+3) { --fw: 0.53; --bw: 1.13; --fh: 1.14; --bh: 0.88; --td: 9.7s; --dd: -2.2s; --dir: normal; }
  .af-word > :nth-child(5n+4) { --fw: 0.66; --bw: 0.93; --fh: 0.95; --bh: 1.05; --td: 8.3s; --dd: -6.1s; --dir: reverse; }
  .af-word > :nth-child(5n+5) { --fw: 0.62; --bw: 0.99; --fh: 1.03; --bh: 0.98; --td: 6.7s; --dd: -0.9s; --dir: normal; }
  /* the t: a small warm spot on the stem where the jet touches it (the letter keeps its shape) */
  .af-word > :last-child {
    --hot: radial-gradient(closest-side, color-mix(in srgb, var(--af-c1) 85%, transparent), transparent);
    --hs: 0.26em 0.24em; --hp: left 0.14em bottom 0.47em;
  }
  :lang(ru) .af-word > :last-child { --hp: left 0.15em bottom 0.53em; }
}
/* drift at uneven speed; per loop the rows move 2 and -3 whole tiles, so it never jumps */
@keyframes af-drift {
  0% { background-position: var(--hp,0 0), left calc(var(--W1)*0) bottom .3em, left calc(var(--W2)*0) bottom .27em, 0 0; }
  18% { background-position: var(--hp,0 0), left calc(var(--W1)*.3) bottom .3em, left calc(var(--W2)*-.7) bottom .27em, 0 0; }
  31% { background-position: var(--hp,0 0), left calc(var(--W1)*.42) bottom .3em, left calc(var(--W2)*-1.1) bottom .27em, 0 0; }
  52% { background-position: var(--hp,0 0), left calc(var(--W1)*1.15) bottom .3em, left calc(var(--W2)*-1.35) bottom .27em, 0 0; }
  67% { background-position: var(--hp,0 0), left calc(var(--W1)*1.3) bottom .3em, left calc(var(--W2)*-2.2) bottom .27em, 0 0; }
  84% { background-position: var(--hp,0 0), left calc(var(--W1)*1.75) bottom .3em, left calc(var(--W2)*-2.45) bottom .27em, 0 0; }
  100% { background-position: var(--hp,0 0), left calc(var(--W1)*2) bottom .3em, left calc(var(--W2)*-3) bottom .27em, 0 0; }
}

/* ---------- the robot and the jet (agent-fire.svg) ---------- */
/* zero height: the drawing stands on the baseline and never changes the height of the line */
.af-rig { position: relative; display: inline-block; height: 0; width: calc(var(--af-robot-h) * 1.3em); margin-left: calc(var(--af-gap) * 1em); }
.af-rig .af-svg { position: absolute; left: 0; bottom: 0; width: 100%; height: calc(var(--af-robot-h) * 1em); overflow: visible; opacity: 0; transition: opacity 0.4s ease-out; }
.af-ready .af-rig .af-svg { opacity: 1; }
@media (prefers-reduced-motion: reduce) { .af-rig .af-svg { transition: none; } }

.af-svg .af-ink { fill: var(--af-robot); }
.af-svg .af-ink-line { stroke: var(--af-robot); }
.af-svg .af-wand-tube { fill: var(--af-steel); }
.af-svg .af-hose { stroke: var(--af-steel); }
.af-svg .af-tank-band { fill: var(--af-band); }
.af-svg .af-s-c2 { stop-color: var(--af-c2); }
.af-svg .af-s-c3 { stop-color: var(--af-c3); }
.af-svg .af-s-c4 { stop-color: var(--af-c4); }
.af-svg .af-jet-mid { fill: var(--af-c2); }
.af-svg .af-jet-core, .af-svg .af-puff-2 { fill: var(--af-c0); }
.af-svg .af-nozzle-glow, .af-svg .af-visor-glow, .af-svg .af-puff { fill: var(--af-c1); }

/* the jet's length follows the gap: (gap + reach) em; it is drawn 40 units long, and 100 units = robot height */
.af-svg .af-jet-len { transform: scale(calc((var(--af-gap) + var(--af-reach)) * 2.5 / var(--af-robot-h)), var(--af-jet-thick)); }
.af-svg .af-jet-len, .af-svg .af-jet-outer, .af-svg .af-jet-mid, .af-svg .af-jet-core { transform-origin: 0 0; }
.af-svg .af-jet-outer { animation: af-flick-a calc(0.23s / var(--af-speed)) ease-in-out infinite alternate; }
.af-svg .af-jet-mid { animation: af-flick-b calc(0.16s / var(--af-speed)) ease-in-out infinite alternate; }
.af-svg .af-jet-core { animation: af-flick-c calc(0.11s / var(--af-speed)) ease-in-out infinite alternate; }
.af-svg .af-puff { transform-box: fill-box; transform-origin: 50% 50%; animation: af-puff calc(0.5s / var(--af-speed)) ease-in infinite; }
.af-svg .af-puff-2 { animation-delay: calc(-0.17s / var(--af-speed)); }
.af-svg .af-puff-3 { animation-delay: calc(-0.34s / var(--af-speed)); }
.af-svg .af-nozzle-glow { animation: af-pulse calc(0.19s / var(--af-speed)) ease-in-out infinite alternate; }
.af-svg .af-visor-glow { animation: af-visor calc(1.1s / var(--af-speed)) linear infinite; }
.af-svg .af-jet-outer, .af-svg .af-jet-mid, .af-svg .af-jet-core, .af-svg .af-puff,
.af-svg .af-nozzle-glow, .af-svg .af-visor-glow { animation-play-state: var(--af-anim); }

@keyframes af-flick-a { 0% { transform: scale(0.96, 0.9); } 60% { transform: scale(1.02, 1.08); } 100% { transform: scale(0.99, 0.97); } }
@keyframes af-flick-b { 0% { transform: scale(1.03, 0.88); } 100% { transform: scale(0.93, 1.1); } }
@keyframes af-flick-c { 0% { transform: scale(0.9, 1); } 100% { transform: scale(1.05, 0.85); } }
@keyframes af-puff { 0% { transform: translateX(0) scale(0.5); opacity: 1; } 70% { opacity: 0.85; } 100% { transform: translateX(-38px) scale(1.7); opacity: 0; } }
@keyframes af-pulse { from { opacity: 0.75; } to { opacity: 1; } }
@keyframes af-visor { 0%, 100% { opacity: 0.1; } 30% { opacity: 0.26; } 45% { opacity: 0.08; } 70% { opacity: 0.22; } }
