/* Shared part "life" (every page; js/sections/_shared/life.js). The day passing in the nav, and the small loops any
   section can ask for with data-idle. Transform and opacity only. Paper loops step on twos (12 updates a second) and
   run only while their element is on screen (.is-seen, set by life.js). Reduced motion: none of it. */

/* ---------- the day passing: a paper sun rolls along the nav's cut edge, and the moon takes over at night */
.nv__sky { position: absolute; z-index: 3; left: 50%; bottom: -11px; width: var(--wrap); height: 22px; translate: -50% 0; pointer-events: none;
  opacity: 0; transition: opacity var(--m-small, 400ms) var(--m-settle, ease); }
.nv__sky.is-live.is-on { opacity: 1; }
.nv.is-open .nv__sky { opacity: 0; }
.nv__sun, .nv__moon { position: absolute; left: 0; top: 0; width: 22px; height: 22px; will-change: transform, opacity; }
.nv__sun img, .nv__moon img { display: block; width: 100%; height: 100%; }
.nv__moon { opacity: 0; }
@media (max-width: 639.98px) {
  .nv__sky { bottom: -10px; height: 20px; }
  .nv__sun, .nv__moon { width: 20px; height: 20px; }
}
@media (prefers-reduced-motion: reduce) { .nv__sky { display: none; } }
html.rm .nv__sky { display: none; }
@media (forced-colors: active) { .nv__sky { display: none; } }

/* ---------- a character drawn as its parts (body, eye whites, pupils), for googly eyes (data-eyes, life.js) */
.char { position: relative; display: block; pointer-events: none; }
.char__part { position: absolute; display: block; max-width: none; height: auto; } /* width comes from its inline style */
.char__part:first-child { position: relative; }
.start__sun { width: 100%; transform-origin: 50% 50%; }

/* ---------- buttons that life.js made magnetic: the light layer needs a positioned box */
.btn.life-mag { position: relative; }

/* ---------- idle loops (data-idle="bob | sway | breathe | drift | spin | twinkle | float").
   Each keeps the element's own resting translate, rotate or scale through --idle-tx / --idle-ty, --idle-r and
   --idle-s, so a centred or tilted piece keeps its place. Stepped: n steps per keyframe segment, about 83 ms each. */
@media (prefers-reduced-motion: no-preference) {
  html.js:not(.rm) [data-idle] { animation-play-state: paused; animation-iteration-count: infinite; animation-fill-mode: both; }
  html.js:not(.rm) [data-idle].is-seen { animation-play-state: running; }
  html.js:not(.rm) [data-idle="bob"] { animation-name: life-bob; animation-duration: var(--idle-dur, 3.8s); animation-timing-function: steps(6, end); }
  html.js:not(.rm) [data-idle="float"] { animation-name: life-float; animation-duration: var(--idle-dur, 5.6s); animation-timing-function: steps(8, end); }
  html.js:not(.rm) [data-idle="sway"] { animation-name: life-sway; animation-duration: var(--idle-dur, 4.8s); animation-timing-function: steps(7, end); }
  html.js:not(.rm) [data-idle="breathe"] { animation-name: life-breathe; animation-duration: var(--idle-dur, 4.2s); animation-timing-function: steps(6, end); }
  html.js:not(.rm) [data-idle="drift"] { animation-name: life-drift; animation-duration: var(--idle-dur, 16s); animation-timing-function: steps(48, end); }
  html.js:not(.rm) [data-idle="spin"] { animation-name: life-spin; animation-duration: var(--idle-dur, 80s); animation-timing-function: steps(960, end); }
  html.js:not(.rm) [data-idle="twinkle"] { animation-name: life-twinkle; animation-duration: var(--idle-dur, 3.4s); animation-timing-function: steps(1, end); }
}
/* a soft bob, about 6 px (a cosine sampled in eight segments) */
@keyframes life-bob {
  0%, 100% { translate: var(--idle-tx, 0px) var(--idle-ty, 0px); }
  12.5%, 87.5% { translate: var(--idle-tx, 0px) calc(var(--idle-ty, 0px) - var(--idle-a, 6px) * .146); }
  25%, 75% { translate: var(--idle-tx, 0px) calc(var(--idle-ty, 0px) - var(--idle-a, 6px) * .5); }
  37.5%, 62.5% { translate: var(--idle-tx, 0px) calc(var(--idle-ty, 0px) - var(--idle-a, 6px) * .854); }
  50% { translate: var(--idle-tx, 0px) calc(var(--idle-ty, 0px) - var(--idle-a, 6px)); }
}
/* a slow float: up and a little sideways, like paper on a thread */
@keyframes life-float {
  0%, 100% { translate: var(--idle-tx, 0px) var(--idle-ty, 0px); rotate: var(--idle-r, 0deg); }
  25% { translate: calc(var(--idle-tx, 0px) + 2px) calc(var(--idle-ty, 0px) - var(--idle-a, 8px) * .6); rotate: calc(var(--idle-r, 0deg) + 1.2deg); }
  50% { translate: var(--idle-tx, 0px) calc(var(--idle-ty, 0px) - var(--idle-a, 8px)); rotate: var(--idle-r, 0deg); }
  75% { translate: calc(var(--idle-tx, 0px) - 2px) calc(var(--idle-ty, 0px) - var(--idle-a, 8px) * .6); rotate: calc(var(--idle-r, 0deg) - 1.2deg); }
}
/* a sway about the element's own transform-origin (set it in the section: the base of a character) */
@keyframes life-sway {
  0%, 100% { rotate: var(--idle-r, 0deg); }
  25% { rotate: calc(var(--idle-r, 0deg) + var(--idle-a, 2.4deg)); }
  75% { rotate: calc(var(--idle-r, 0deg) - var(--idle-a, 2.4deg)); }
}
@keyframes life-breathe {
  0%, 100% { scale: var(--idle-s, 1); }
  50% { scale: calc(var(--idle-s, 1) * (1 + var(--idle-a, .03))); }
}
/* clouds: a long drift sideways and back */
@keyframes life-drift {
  0%, 100% { translate: var(--idle-tx, 0px) var(--idle-ty, 0px); }
  50% { translate: calc(var(--idle-tx, 0px) + var(--idle-a, 22px)) var(--idle-ty, 0px); }
}
@keyframes life-spin { from { rotate: var(--idle-r, 0deg); } to { rotate: calc(var(--idle-r, 0deg) + 360deg); } }
/* a star: rests, then two quick flickers */
@keyframes life-twinkle {
  0%, 70%, 100% { scale: 1; opacity: 1; }
  74% { scale: 1.28; opacity: 1; }
  78% { scale: .86; opacity: .7; }
  82% { scale: 1.14; opacity: 1; }
  86% { scale: 1; }
}
@media (prefers-reduced-motion: reduce) { [data-idle] { animation: none !important; } }
