/* ==========================================================================
   Selam Éditions — pen drawings (see js/illustrations.js)
   Thin ink lines, traced when they scroll into view, then small loops that
   play only while the drawing is visible and motion is welcome.
   ========================================================================== */

.sempe {
  display: block;
  width: 100%;
  margin-inline: auto;
  color: var(--ink);
  pointer-events: none;
}

.sempe svg {
  width: 100%;
  height: auto;
  overflow: visible;
}

/* Space reserved for each drawing before the script traces it, so the page
   does not jump (same proportions as the viewBox of each scene). */
[data-sempe="walk"] { aspect-ratio: 640 / 260; }
[data-sempe="runner"] { aspect-ratio: 640 / 96; }
[data-sempe="ladder"] { aspect-ratio: 320 / 316; }
[data-sempe="mountains"] { aspect-ratio: 640 / 240; }
[data-sempe="kite"] { aspect-ratio: 320 / 260; }
[data-sempe="coffee"],
[data-sempe="lalibela"] { aspect-ratio: 320 / 230; }
[data-sempe="umbrella"],
[data-sempe="reader"] { aspect-ratio: 320 / 240; }
[data-sempe="lion"] { aspect-ratio: 200 / 150; }

.sempe svg {
  display: block;
}

/* Sizes */
.sempe--hero {
  max-width: 40rem;
  margin-block: var(--space-xs);
}

.sempe--vignette {
  max-width: 15rem;
  margin-bottom: var(--space-m);
}

.sempe--chapter {
  max-width: 17rem;
  margin-bottom: var(--space-m);
}

.sempe--wide {
  max-width: 34rem;
  margin-bottom: var(--space-m);
}

.sempe--strip {
  overflow: hidden;
  max-width: none;
  padding-inline: 0;
}

.sempe--tailpiece {
  max-width: 7rem;
  margin-top: var(--space-m);
}

/* Tab "Séries": the runner crosses the panel, between the text and
   "Tourner la page" */
.sempe--runner {
  max-width: 30rem;
  margin-top: clamp(1rem, 4vh, 2.5rem);
}

/* Pen — widths are in drawing units, so the line keeps the proportions of
   the drawing (no non-scaling-stroke: it would break the tracing effect). */
.sempe {
  --pen: 1.6;
  --pen-light: 1.2;
}

.sempe--hero,
.sempe--strip,
.sempe--wide {
  --pen: 2.1;
  --pen-light: 1.5;
}

.sempe--runner {
  --pen: 2.6;
  --pen-light: 1.8;
}

.sempe--tailpiece {
  --pen: 2.2;
  --pen-light: 1.6;
}

.sempe path,
.sempe circle {
  fill: none;
  stroke: currentColor;
  stroke-width: var(--pen);
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sempe .light {
  stroke: var(--faint);
  stroke-width: var(--pen-light);
}

/* The only touches of colour in the drawings, on the title page: the three
   colours of the Ethiopian flag — yellow sun, green acacia, red tukul roof. */
.sempe .sun {
  fill: #fedd00;
  stroke: var(--faint);           /* same thin grey line as the clouds */
  stroke-width: var(--pen-light);
}

.sempe .canopy-green {
  fill: #009a44;
}

/* The kite of the Articles chapter: the Ethiopian flag */
.sempe .flag-green { fill: #009a44; }
.sempe .flag-yellow { fill: #fedd00; }
.sempe .flag-red { fill: #ef3340; }


/* The Lion of Judah (colophon): white paper inside the lines, so the
   lines behind are hidden; a yellow crown; the pennant waves */
.sempe .paper-fill,
.sempe .lion-body,
.sempe .lion-mane {
  fill: var(--paper);
}

.sempe .crown {
  fill: #fedd00;
}

.sempe .flag-wave {
  transform-box: fill-box;
  transform-origin: center top;
}

.sempe .pennant {
  transform-box: fill-box;
  transform-origin: left center;
}

/* Thin black line (the leaves drawn on the green acacia) */
.sempe .thin {
  stroke-width: var(--pen-light);
}

.sempe .roof-red {
  fill: #ef3340;
}


/* Tracing: each stroke is revealed in turn (delays set by the script) */
.sempe [data-draw] {
  stroke-dasharray: var(--len) calc(var(--len) * 2);
  stroke-dashoffset: var(--len);
  transition: stroke-dashoffset 1.3s cubic-bezier(0.45, 0.05, 0.35, 1);
}

.sempe.is-drawn [data-draw] {
  stroke-dashoffset: 0;
}

.sempe .rain {
  stroke: var(--muted);
  stroke-width: var(--pen-light);
  stroke-dasharray: 5 9;
  opacity: 0;
  transition: opacity 600ms 1.6s;
}

.sempe.is-drawn .rain {
  opacity: 1;
}

/* Without motion, only the first leg position of the runner is shown */
.sempe .frame--b {
  opacity: 0;
}

.sempe .pour {
  stroke: var(--muted);
  stroke-width: var(--pen-light);
  stroke-dasharray: 4 2;
  opacity: 0;
  transition: opacity 600ms 1.8s;
}

.sempe.is-drawn .pour {
  opacity: 1;
}

.sempe .pour-pot {
  transform-box: view-box;
  transform-origin: 141px 172px; /* the pouring hand */
}

/* Reading progress under the running head, and the bird walking on it */
.progress-bird {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 26px;
  height: 18px;
  color: var(--ink);
  pointer-events: none;
}

.progress-bird svg {
  width: 26px;
  height: 18px;
  overflow: visible;
  transition: transform var(--duration) var(--ease);
}

.progress-bird path {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transform-box: fill-box;
  transform-origin: center bottom;
}

.progress-bird .pigeon-body {
  fill: var(--paper);
}

.progress-bird .pigeon-ink {
  fill: currentColor;
  stroke-width: 0.6;
}

.progress-bird .pigeon-line {
  stroke-width: 0.7;
}

.progress-bird .pigeon-eye {
  stroke-width: 1.4;
}

.progress-bird.is-flipped svg {
  transform: scaleX(-1);
}

/* --------------------------------------------------------------------------
   Loops — only while visible (.is-playing) and when motion is welcome
   -------------------------------------------------------------------------- */
.sempe .wing,
.sempe .wag,
.sempe .tail,
.sempe .tilt,
.sempe .hop,
.sempe .nod,
.sempe .page,
.sempe .twinkle {
  transform-box: fill-box;
  transform-origin: center;
}

.sempe .wag,
.sempe .tail {
  transform-origin: left bottom;
}


.sempe .tilt {
  transform-origin: left bottom;
}

.sempe .nod {
  transform-origin: center bottom;
}

.sempe .sway {
  transform-box: view-box;
  transform-origin: 78px 210px; /* the boy's hand */
}

.sempe .orbit {
  transform-box: view-box;
  transform-origin: 420px 70px;
}

.sempe .rock {
  transform-box: view-box;
  transform-origin: 100px 75px;
}

@media (prefers-reduced-motion: no-preference) {
  .sempe.is-playing .wing { animation: flap 0.5s ease-in-out infinite alternate; }
  .sempe.is-playing .wing--2 { animation-duration: 0.42s; animation-delay: -0.2s; }
  .sempe.is-playing .wing--3 { animation-duration: 0.58s; animation-delay: -0.35s; }
  .sempe.is-playing .wing--glide { animation: glide 2.4s ease-in-out infinite alternate; }

  .sempe.is-playing .flock { animation: fly 14s ease-in-out infinite alternate; }
  .sempe.is-playing .drift { animation: drift 11s ease-in-out infinite alternate; }
  .sempe.is-playing .drift--slow { animation-duration: 17s; animation-direction: alternate-reverse; }
  .sempe.is-playing .drift--short { animation: drift-short 6s ease-in-out infinite alternate; }

  .sempe.is-playing .bob { animation: bob 0.55s ease-in-out infinite alternate; }
  .sempe.is-playing .bob--slow { animation-duration: 1.6s; }
  .sempe.is-playing .wag { animation: wag 0.35s ease-in-out infinite alternate; }

  .sempe.is-playing .ride { animation: ride 16s linear infinite; }

  .sempe.is-playing .tilt { animation: tilt 5s ease-in-out infinite; }
  .sempe.is-playing .hop { animation: hop 3.2s ease-in-out infinite; }
  .sempe.is-playing .nod { animation: nod 4s ease-in-out infinite; }
  .sempe.is-playing .page { animation: page 5s ease-in-out infinite; }

  .sempe.is-playing .orbit { animation: orbit 26s linear infinite; }
  .sempe.is-playing .sway { animation: sway 4.5s ease-in-out infinite alternate; }
  .sempe.is-playing .tail { animation: tail 1.4s ease-in-out infinite alternate; }
  .sempe.is-playing .rock { animation: rock 7s ease-in-out infinite alternate; }
  .sempe.is-playing .pennant { animation: pennant 2.6s ease-in-out infinite alternate; }
  .sempe.is-playing .flag-wave { animation: flag-wave 1.8s ease-in-out infinite alternate; }
  .sempe.is-playing .twinkle { animation: twinkle 2.6s ease-in-out infinite; }
  .sempe.is-playing .twinkle--2 { animation-delay: -0.9s; }
  .sempe.is-playing .twinkle--3 { animation-delay: -1.7s; }
  .sempe.is-playing .steam { animation: steam 3.2s ease-in-out infinite; }
  .sempe.is-playing .rain { animation: rain 0.55s linear infinite; }

  /* The runner: two leg positions alternate */
  .sempe.is-playing .ride--run { animation-duration: 11s; }
  .sempe.is-playing .frame--a { animation: stride-a 0.36s steps(1) infinite; }
  .sempe.is-playing .frame--b { animation: stride-b 0.36s steps(1) infinite; }

  /* Coffee pouring from the jebena, incense rising */
  .sempe.is-playing .pour { animation: pour 0.8s linear infinite; }
  .sempe.is-playing .pour-pot { animation: pour-tilt 6s ease-in-out infinite; }
  .sempe.is-playing .steam--slow { animation-duration: 4.6s; }

  .progress-bird.is-hopping path { animation: perch-hop 0.22s ease-in-out infinite alternate; }
}

@keyframes flap {
  from { transform: scaleY(1); }
  to { transform: scaleY(-0.55); }
}

@keyframes glide {
  from { transform: scaleY(1) rotate(-4deg); }
  to { transform: scaleY(0.6) rotate(4deg); }
}

@keyframes fly {
  from { transform: translate(0, 0); }
  to { transform: translate(-46px, -14px); }
}

@keyframes drift {
  from { transform: translateX(-14px); }
  to { transform: translateX(14px); }
}

@keyframes drift-short {
  from { transform: translateX(-3px); }
  to { transform: translateX(3px); }
}

@keyframes bob {
  from { transform: translateY(0); }
  to { transform: translateY(-1.6px); }
}

@keyframes wag {
  from { transform: rotate(-14deg); }
  to { transform: rotate(16deg); }
}

@keyframes ride {
  from { transform: translateX(-80px); }
  to { transform: translateX(700px); }
}

@keyframes tilt {
  0%, 70%, 100% { transform: rotate(0); }
  80% { transform: rotate(-12deg); }
  90% { transform: rotate(-4deg); }
}

@keyframes hop {
  0%, 60%, 100% { transform: translate(0, 0); }
  66% { transform: translate(3px, -5px); }
  72% { transform: translate(6px, 0); }
  80% { transform: translate(6px, 0) scaleX(-1); }
  86% { transform: translate(3px, -5px) scaleX(-1); }
  92% { transform: translate(0, 0) scaleX(-1); }
}

@keyframes nod {
  0%, 100% { transform: rotate(0); }
  50% { transform: rotate(8deg); }
}

@keyframes page {
  0%, 82%, 100% { transform: scaleX(1); }
  88% { transform: scaleX(-1); }
  94% { transform: scaleX(1); }
}

@keyframes orbit {
  to { transform: rotate(360deg); }
}

@keyframes sway {
  from { transform: rotate(-3deg); }
  to { transform: rotate(4deg); }
}

@keyframes tail {
  from { transform: rotate(-10deg); }
  to { transform: rotate(18deg); }
}

@keyframes flag-wave {
  from { transform: skewY(-4deg) skewX(2deg); }
  to { transform: skewY(4deg) skewX(-3deg); }
}

@keyframes pennant {
  from { transform: skewY(-3deg) scaleX(1); }
  to { transform: skewY(4deg) scaleX(0.95); }
}

@keyframes rock {
  from { transform: rotate(-4deg); }
  to { transform: rotate(4deg); }
}

@keyframes twinkle {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.15; }
}

@keyframes steam {
  0% { opacity: 0; transform: translateY(4px); }
  40% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-8px); }
}

@keyframes rain {
  to { stroke-dashoffset: -14; }
}

@keyframes stride-a {
  0% { opacity: 1; }
  50% { opacity: 0; }
}

@keyframes stride-b {
  0% { opacity: 0; }
  50% { opacity: 1; }
}

@keyframes pour {
  to { stroke-dashoffset: -12; }
}

@keyframes pour-tilt {
  0%, 100% { transform: rotate(0); }
  50% { transform: rotate(-5deg); }
}

@keyframes perch-hop {
  from { transform: translateY(0); }
  to { transform: translateY(-3px); }
}

/* Never hide content on paper */
@media print {
  .js-reveal [data-reveal] {
    opacity: 1 !important;
    transform: none !important;
  }
}
