/* The chalk sketches on a book's contents page: how they look, and how they move.

   Shared by all three books (site/angles, site/numbers, site/ratios) instead of
   being copied into each book's index.html. That duplication had already gone wrong:
   Ratios' sketches carried .cut and .hop classes for an animation that only existed
   in Angles' copy of this block, so the pie never swept and the dot never hopped —
   markup that named a motion nothing could hear.

   Each sketch is an inline SVG with viewBox 0 0 600 180, one per unit, drawn in that
   unit's colour. Keep the left ~200px light: the unit title sits over it on narrow
   screens. Classes a sketch can use:

     .d      a stroke that draws itself in when the unit scrolls into view.
             --k on the element orders the strokes.
     .t      text, or a filled shape, that fades in after its stroke.
     .a      chalk white rather than the unit colour.
     .faint  fainter still.
     .cell   a repeating tile that lights up in turn (.seen .unit-art .cell)
     .cut    a shape that wipes open   .shade   a shape that fills in
     .step   something that blinks      .hop     a dot riding an offset-path
     .pie    an arc that grows          .diag    a line that re-draws
     .root   something that pulses      .breathe something that squashes
     .ride   a dot running a path       .spin    something that turns
     .tilt   something that leans       .sweep   a ray that opens and closes
     .swap-a / .swap-b   two things that trade places
     .feed-in / .feed-out   things that arrive and leave
     .pulse  a line that brightens in turn with its neighbours (--j numbers the turn)

   Motion classes loop only after the sketch has finished drawing, so the eye gets
   the drawing first and the idle movement second.
*/

/* ---------- placement ---------- */
.unit-art { position: absolute; top: 20px; right: 28px; width: min(580px, 56%); height: auto;
  overflow: visible; pointer-events: none; opacity: .78;
  color: var(--c); fill: none; stroke: currentColor; stroke-width: 2.6;
  stroke-linecap: round; stroke-linejoin: round; }
.unit-art text { fill: currentColor; stroke: none; font-family: var(--book); font-style: italic; }
.unit-art .a { color: var(--chalk); opacity: .55; }
.unit-art .faint { opacity: .22; }

/* ---------- the drawing ---------- */
.unit-art .d { stroke-dasharray: 1 1; stroke-dashoffset: 1; }
.unit-art .t { opacity: 0; }
.seen .unit-art .d { animation: art-draw 1.1s cubic-bezier(.5, 0, .3, 1) forwards; animation-delay: calc(var(--k) * 55ms + 120ms); }
.seen .unit-art .t { animation: art-fade .6s ease-out forwards; animation-delay: calc(var(--k) * 55ms + 300ms); }
.seen .unit-art .a.t { animation-name: art-fade-a; }
@keyframes art-draw { to { stroke-dashoffset: 0; } }
@keyframes art-fade { to { opacity: 1; } }
@keyframes art-fade-a { to { opacity: .55; } }

/* ---------- what the chalk keeps doing once drawn ---------- */
.unit-art g { transform-box: fill-box; }
.seen .unit-art .swap-a { animation: swap-a 6s var(--ease) 2.4s infinite; }
.seen .unit-art .swap-b { animation: swap-b 6s var(--ease) 2.4s infinite; }
@keyframes swap-a { 0%, 30%, 100% { transform: none; } 45%, 80% { transform: translate(80px, 0); } 37% { transform: translate(40px, -30px); } 88% { transform: translate(40px, 30px); } }
@keyframes swap-b { 0%, 30%, 100% { transform: none; } 45%, 80% { transform: translate(-80px, 0); } 37% { transform: translate(-40px, 30px); } 88% { transform: translate(-40px, -30px); } }

.seen .unit-art .step { animation: art-fade .6s ease-out forwards, step 4s var(--ease) 2s infinite; animation-delay: calc(var(--k) * 55ms + 300ms), calc(var(--k) * 300ms + 2s); }
@keyframes step { 0%, 20%, 100% { fill-opacity: 1; } 10% { fill-opacity: .3; } }

.unit-art .hop, .unit-art .ride { offset-rotate: 0deg; }
.seen .unit-art .hop { animation: art-fade .4s ease-out 2s forwards, along 3.4s linear 2s infinite; }
.seen .unit-art .ride { animation: art-fade .4s ease-out 2s forwards, along 4s var(--ease) 2s infinite alternate; }
@keyframes along { from { offset-distance: 0%; } to { offset-distance: 100%; } }

.unit-art .pie { stroke-linecap: butt; stroke-dasharray: 0 100; }
.seen .unit-art .pie { animation: art-fade .4s ease-out 1.6s forwards, pie 5s var(--ease) 1.6s infinite; }
@keyframes pie { 0% { stroke-dasharray: 0 100; } 35%, 85% { stroke-dasharray: 25 100; } 100% { stroke-dasharray: 0 100; } }

.seen .unit-art .tilt { transform-box: view-box; transform-origin: 300px 72px; animation: tilt 4.8s ease-in-out 2s infinite; }
@keyframes tilt { 0%, 100% { transform: rotate(0); } 30% { transform: rotate(-4deg); } 60% { transform: rotate(2deg); } }

.seen .unit-art .spin { transform-box: view-box; transform-origin: 320px 95px; animation: spin 5s var(--ease) 2s infinite; }
@keyframes spin { from { transform: rotate(0); } 70%, to { transform: rotate(1530deg); } }

.seen .unit-art .feed-in { animation: feed-in 4s ease-in-out 2s infinite; }
.seen .unit-art .feed-out { opacity: 0; animation: feed-out 4s ease-in-out 2s infinite; }
@keyframes feed-in { 0% { transform: none; opacity: 1; } 40% { transform: translate(100px, 0); opacity: 0; } 41%, 100% { transform: none; opacity: 0; } 95% { opacity: 1; } }
@keyframes feed-out { 0%, 45% { transform: translate(-40px, 0); opacity: 0; } 70%, 90% { transform: none; opacity: 1; } 100% { opacity: 0; } }

.seen .unit-art .cell { animation: cell 5s ease-in-out infinite; animation-delay: calc(var(--j) * .5s + 2s); }
@keyframes cell { 0%, 100% { opacity: .25; } 15%, 60% { opacity: 1; } }

.seen .unit-art .cut { animation: cut 4s ease-in-out 2s infinite; }
.seen .unit-art .shade { animation: shade 1s ease-out 1.6s forwards; }
@keyframes cut { 0%, 100% { opacity: 0; } 30%, 70% { opacity: .5; } }
@keyframes shade { to { opacity: .14; } }

.seen .unit-art .diag { animation: art-draw 1.1s cubic-bezier(.5, 0, .3, 1) forwards, redraw 4s ease-in-out 2.5s infinite; }
@keyframes redraw { 0%, 15% { stroke-dashoffset: 1; } 50%, 100% { stroke-dashoffset: 0; } }

.seen .unit-art .root { animation: art-fade .4s ease-out 1.8s forwards, root 2.4s ease-in-out 2.2s infinite; }
@keyframes root { 0%, 100% { r: 7px; } 50% { r: 11px; } }

.seen .unit-art .breathe { transform-box: view-box; transform-origin: 380px 140px; animation: breathe 4s ease-in-out 2s infinite alternate; }
@keyframes breathe { from { transform: scaleY(1); } to { transform: scaleY(.35); } }

/* Unit 1's own motion: the ray opens from the horizontal up to meet the drawn arm, and closes again. */
.unit-art .sweep { transform-box: view-box; transform-origin: 244px 158px; }
.seen .unit-art .sweep { animation: art-draw .8s cubic-bezier(.5, 0, .3, 1) forwards, sweep-ray 4.6s var(--ease) 1.4s infinite;
  animation-delay: .6s, 1.4s; }
@keyframes sweep-ray { 0%, 100% { transform: rotate(-4deg); } 50% { transform: rotate(-45deg); } }

/* A shape that brightens in turn with its neighbours: the three angles of one
   unit, the two opposite angles at a crossing, the four divisors of twelve.
   The point is the turn -- one after the other -- not a single blink, so the
   stagger comes from --j (0, 1, 2, ...) and not from --k, which orders the
   drawing.

   The stroke brightens, not the whole shape: a chalk line that dims to nothing
   and comes back reads as a mistake, a line that loses its colour and gets it
   back reads as a lamp. */
.seen .unit-art .pulse { animation: art-draw 1.1s cubic-bezier(.5, 0, .3, 1) forwards, pulse 5.4s var(--ease) 2s infinite;
  animation-delay: calc(var(--k) * 55ms + 120ms), calc(var(--j, 0) * 1.2s + 2s); }
@keyframes pulse { 0%, 100% { stroke-opacity: 1; } 12% { stroke-opacity: .12; } 42% { stroke-opacity: 1; } }

/* ---------- the seam between one unit and the next ---------- */
/* A book of one unit reads as a list; a book of several needs to say "this is where
   the topic turns". The seam is that signal: a short chalk line drawn down the
   middle with an arrowhead, in the colour of the unit being entered. It draws in
   with the unit it belongs to, so scrolling on is what reveals it. */
.unit-seam { display: flex; justify-content: center; max-width: 1212px; margin: 0 auto; padding: 0 16px; }
.unit-seam svg { width: 46px; height: 62px; overflow: visible; color: var(--c);
  fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.unit-seam .d { stroke-dasharray: 1 1; stroke-dashoffset: 1; }
.unit-seam .t { opacity: 0; }
.seen .unit-seam .d { animation: art-draw 1s cubic-bezier(.5, 0, .3, 1) forwards; animation-delay: calc(var(--k) * 90ms); }
.seen .unit-seam .t { animation: art-fade .6s ease-out forwards; animation-delay: 620ms; }
/* Once drawn, a dot runs down the seam: the thread between the two units. */
.unit-seam .runner { r: 4; fill: currentColor; stroke: none; opacity: 0; }
.seen .unit-seam .runner { animation: seam-run 3.2s ease-in-out 1.4s infinite; }
@keyframes seam-run {
  0%   { opacity: 0; transform: translateY(-4px); }
  18%  { opacity: 1; }
  70%  { opacity: 1; }
  100% { opacity: 0; transform: translateY(44px); }
}

/* ---------- narrow screens and reduced motion ---------- */
@media (max-width: 560px) {
  .unit-art { width: calc(100% - 32px); right: 16px; opacity: .32; }
  .unit-seam svg { width: 34px; height: 46px; }
}
@media (prefers-reduced-motion: reduce) {
  .unit-art .d, .unit-seam .d { stroke-dashoffset: 0; }
  .unit-art .t, .unit-seam .t { opacity: 1; }
  .unit-art .a.t { opacity: .55; }
  .unit-art .shade { opacity: .14; }
  .unit-art .pie { stroke-dasharray: 25 100; }
  .unit-art .pulse { stroke-opacity: 1; }
  .unit-seam .runner { opacity: 0; }
}
