/* =====================================================================
   perOS characters (design/characters-3d 01524ab; work 055, 059): tokens and motion for
   characters.js. A character is animal x role x state. This file is the ONLY place a character
   colour is written, and only inside the token block below (between ch-tokens and /ch-tokens):
   scripts/check_ui.py refuses a raw colour or a colour mix anywhere else in ui/characters/.
   A role sets three tokens, an animal says how it wears them, every shade is derived here.
   ===================================================================== */

/* ch-tokens */
/* ---------- 1. fixed tokens (same for every animal and role) ---------- */
.ch{
  --role:#8F8A9C; --pale:#EFEDF4; --item:#3A3142;           /* an unknown role: plain grey, no item */
  --iris:var(--amber,#F5B544);
  --ch-deep:#1F1638;                                           /* what shadows fall towards */
  --ch-ink:#1D1728; --ch-spec:#FFFFFF; --ch-shadow:#1F1638;
  --ch-beak:#F5A93B; --ch-gold:var(--amber,#F5B544);
  --ch-paper:#FFFFFF; --ch-paper-lo:#D9D5E6;
  --ch-lap:#ECE9F3; --ch-lap-lo:#A7A2B8; --ch-glow:#FFF1C2;
  --ch-owl:#9A6E4A; --ch-owl-pale:#FBF3E4;                     /* a brown owl with a white face */
  --ch-ant:#3A2D33; --ch-chitin:#2B1A22;                       /* a nearly black ant */
  --ch-sleep:var(--mute,#5C5A68);                                         /* the ant's own shell tone */
  --ch-ok:var(--ok,#17784F); --ch-bad:var(--critical-text,#C0302F); --ch-wait:var(--amber,#F5B544);
  --ch-acc:var(--role,#4F46E5); --ch-ring:var(--surf,#FFFFFF);

  /* ---------- 2. how an animal wears the role colour ---------- */
  --coat:var(--role);

  /* ---------- 3. derived shades: one light, top left ---------- */
  --c-hi:color-mix(in oklab,var(--coat),#fff 42%);
  --c-lo:color-mix(in oklab,var(--coat),var(--ch-deep) 30%);
  --c-lo2:color-mix(in oklab,var(--coat),var(--ch-deep) 54%);
  --p-hi:color-mix(in oklab,var(--pale),#fff 65%);
  --p-lo:color-mix(in oklab,var(--pale),var(--coat) 34%);
  --p-lo2:color-mix(in oklab,var(--pale),var(--coat) 58%);
  --r-hi:color-mix(in oklab,var(--role),#fff 38%);
  --r-lo:color-mix(in oklab,var(--role),var(--ch-deep) 34%);
  --i-hi:color-mix(in oklab,var(--item),#fff 36%);
  --i-lo:color-mix(in oklab,var(--item),var(--ch-deep) 36%);
  --iris-hi:color-mix(in oklab,var(--iris),#fff 48%);
  --iris-lo:color-mix(in oklab,var(--iris),var(--ch-deep) 42%);
  --k-hi:color-mix(in oklab,var(--ch-beak),#fff 40%);
  --k-lo:color-mix(in oklab,var(--ch-beak),#7A2E00 38%);
  --g-hi:color-mix(in oklab,var(--ch-gold),#fff 45%);
  --g-lo:color-mix(in oklab,var(--ch-gold),#7A2E00 34%);
  --edge:color-mix(in oklab,var(--coat),var(--ch-deep) 62%);
  --lid:var(--p-lo);
}

/* ---------- 4. roles: an accent and an item colour each, nothing else. Keyed on data-tint (the role, or look.accent) ---------- */
.ch[data-tint="assistant"]{--role:var(--owl-body,#5B54E0);--item:#3A3142}
.ch[data-tint="finance"]{--role:#3F9A6B;--item:#3F9A6B}
.ch[data-tint="email"]{--role:#3F4EA0;--item:#3F4EA0}
.ch[data-tint="documents"]{--role:#B8862E;--item:#3A3142}
.ch[data-tint="tasks"]{--role:#2F9296;--item:#F5B544}
.ch[data-tint="games"]{--role:#8C5FA0;--item:#5A3C8C}
.ch[data-tint="teaching"]{--role:#6E9E4F;--item:#2F2A3A}
.ch[data-tint="music"]{--role:#E0794A;--item:#2F2A3A}
.ch[data-tint="career"]{--role:#6A5ACD;--item:#4A4458}
.ch[data-tint="journal"]{--role:#2E9C8A;--item:#F3EFE6}
.ch[data-tint="office"]{--role:#D9534F;--item:#3A3142}
.ch[data-tint="health"]{--role:#38B2A0;--item:#F3EFE6}
.ch[data-tint="planner"]{--role:#F0A030;--item:#F5B544}
.ch[data-tint="study"]{--role:#7C6FD0;--item:#3A3142}
.ch[data-tint="tech-lead"]{--role:#6E7F9C;--item:#F5B544}
.ch[data-tint="architect"]{--role:#2F4F7F;--item:#2F2A3A}
.ch[data-tint="dev"]{--role:#3E7CC4;--item:#EE6C4D}
.ch[data-tint="designer"]{--role:#C76A8E;--item:#3A3142}
.ch[data-tint="qa"]{--role:#5FA05A;--item:#3A3142}
.ch[data-tint="ops"]{--role:#E08A2E;--item:#F5B544}
.ch[data-tint="lawyer"]{--role:#7A3B4E;--item:#F3EFE6}
.ch[data-tint="analyst"]{--role:#C99A2E;--item:#2F2A3A}
.ch[data-tint="intern"]{--role:#5BB7C8;--item:#EE6C4D}

/* ---------- 4b. animals keep their own colour; the role is worn (tie or badge, head item, tuft or antenna tips) ---------- */
.ch[data-animal="owl"]{--coat:var(--ch-owl);--pale:var(--ch-owl-pale)}
.ch[data-animal="ant"]{--coat:var(--ch-ant);--pale:#FFFFFF;--iris:color-mix(in oklab,var(--role) 45%,var(--ch-chitin));--lid:var(--coat);--c-hi:color-mix(in oklab,var(--coat),#fff 46%)}

/* ---------- 5. dark surfaces: a light edge instead of a dark one, a deeper floor shadow ---------- */
[data-theme="dark"] .ch{--edge:color-mix(in oklab,var(--coat),#fff 34%);--ch-shadow:#000000;--ch-lap:#4A465C;--ch-lap-lo:#2A2738}
[data-theme="dark"] .ch[data-animal="ant"]{--ch-ant:#6E6680}                     /* a mid grey-violet: the near-black shell reads on the dark page */
[data-theme="dark"] [data-theme="light"] .ch{--edge:color-mix(in oklab,var(--coat),var(--ch-deep) 62%);--ch-shadow:#1F1638;--ch-lap:#ECE9F3;--ch-lap-lo:#A7A2B8}
[data-theme="dark"] [data-theme="light"] .ch[data-animal="ant"]{--ch-ant:#3A2D33}
@media (prefers-color-scheme:dark){
  :root:where(:not([data-theme="light"])) .ch:where(:not([data-theme="light"] *)){--edge:color-mix(in oklab,var(--coat),#fff 34%);--ch-shadow:#000000;--ch-lap:#4A465C;--ch-lap-lo:#2A2738}
  :root:where(:not([data-theme="light"])) .ch[data-animal="ant"]:where(:not([data-theme="light"] *)){--ch-ant:#6E6680}
}
/* /ch-tokens */
/* Below this line: no colour value, only the tokens above. */

/* ---------- 6. motion. All of it stops under reduced motion and in .ch-still ---------- */
.ch{display:inline-block;vertical-align:middle;flex:none;overflow:visible}
.ch[data-lod="s"]{overflow:hidden;border-radius:50%;box-shadow:0 0 0 2px var(--ch-ring),0 0 0 3.5px var(--role)}   /* head only: a ring in the role's accent tells two heads apart */
.ch .ch-fig{transform-box:view-box;transform-origin:50% 90%;animation:ch-breathe 4.4s ease-in-out infinite}
.ch .ch-head{transform-box:view-box;transform-origin:50% 62%;animation:ch-sway 9s ease-in-out infinite}
.ch .ch-back{animation:ch-turn-back 9s ease-in-out infinite}
.ch .ch-face{animation:ch-turn-face 9s ease-in-out infinite}
.ch .ch-nose{animation:ch-turn-nose 9s ease-in-out infinite}
.ch .ch-eye{transform-box:fill-box;transform-origin:50% 55%;animation:ch-blink 5.2s infinite}
.ch .ch-feel{transform-box:fill-box;transform-origin:50% 100%;animation:ch-feel 6s ease-in-out infinite}
.ch .ch-feel.f2{animation-delay:-2.2s}

.ch[data-state="working"] .ch-head{animation:ch-nod 1.3s ease-in-out infinite}
.ch[data-state="working"] .ch-face,.ch[data-state="working"] .ch-nose,.ch[data-state="working"] .ch-back{animation:none}
.ch[data-state="working"] .ch-hand{transform-box:fill-box;animation:ch-type .36s steps(2) infinite}
.ch[data-state="working"] .ch-hand.h2{animation-delay:.18s}
.ch[data-state="working"] .ch-glow{animation:ch-glow 2s ease-in-out infinite}
.ch[data-state="working"] .ch-spin{transform-box:fill-box;transform-origin:center;animation:ch-spin 1.2s linear infinite}
.ch[data-state="working"] .ch-dot{transform-box:fill-box;transform-origin:center;animation:ch-spin 1.4s linear infinite}

.ch[data-state="waiting"] .ch-card{transform-box:fill-box;transform-origin:30% 100%;animation:ch-wave 2.8s ease-in-out infinite}
.ch[data-state="waiting"] .ch-face,.ch[data-state="waiting"] .ch-nose,.ch[data-state="waiting"] .ch-back,.ch[data-state="waiting"] .ch-head{animation:none}

.ch[data-state="listening"] .ch-head,.ch[data-state="listening"] .ch-face,.ch[data-state="listening"] .ch-nose,.ch[data-state="listening"] .ch-back{animation:none}
.ch[data-state="listening"] .ch-arc{animation:ch-arc 1.5s ease-in-out infinite}
.ch[data-state="listening"] .ch-arc.a2{animation-delay:.25s}
.ch[data-state="listening"] .ch-arc.a3{animation-delay:.5s}

/* done plays once and rests: a loop is only for something that is really running */
.ch[data-state="done"] .ch-fig{animation:ch-hop .7s ease-out 1}
.ch[data-state="done"] .ch-head,.ch[data-state="done"] .ch-face,.ch[data-state="done"] .ch-nose,.ch[data-state="done"] .ch-back,.ch[data-state="done"] .ch-eye{animation:none}
.ch[data-state="done"] .ch-badge{transform-box:fill-box;transform-origin:center;animation:ch-pop .5s ease-out 1}

/* the soft-smile idle blinks slowly */
.ch[data-face="smile"] .ch-eye{animation:ch-slowblink 6.4s infinite}
/* asleep: only a slower breath */
.ch[data-state="asleep"] *{animation:none}
.ch[data-state="asleep"] .ch-fig{animation:ch-breathe 7.5s ease-in-out infinite}

/* something wrong: nothing moves */
.ch[data-state="wrong"] *{animation:none}

@keyframes ch-breathe{50%{transform:scale(1.01,1.022)}}
@keyframes ch-sway{0%,58%,100%{transform:rotate(0)}68%,90%{transform:rotate(1.8deg)}}
@keyframes ch-turn-back{0%,58%,100%{transform:translateX(0)}68%,90%{transform:translateX(-.9px)}}
@keyframes ch-turn-face{0%,58%,100%{transform:translateX(0)}68%,90%{transform:translateX(1.3px)}}
@keyframes ch-turn-nose{0%,58%,100%{transform:translateX(0)}68%,90%{transform:translateX(2.2px)}}
@keyframes ch-blink{0%,93%,100%{transform:scaleY(1)}96%{transform:scaleY(.08)}}
@keyframes ch-slowblink{0%,86%,100%{transform:scaleY(1)}91%,95%{transform:scaleY(.08)}}
@keyframes ch-feel{0%,70%,100%{transform:rotate(0)}78%{transform:rotate(-6deg)}88%{transform:rotate(4deg)}}
@keyframes ch-nod{50%{transform:translateY(1.2px)}}
@keyframes ch-type{50%{transform:translateY(-1.8px)}}
@keyframes ch-glow{50%{opacity:.45}}
@keyframes ch-spin{to{transform:rotate(360deg)}}
@keyframes ch-wave{0%,55%,100%{transform:rotate(0)}68%{transform:rotate(-7deg)}82%{transform:rotate(4deg)}}
@keyframes ch-arc{0%,100%{opacity:.3}50%{opacity:1}}
@keyframes ch-hop{0%{transform:translateY(0)}35%{transform:translateY(-5px) scale(.99,1.02)}70%{transform:translateY(0) scale(1.015,.985)}100%{transform:none}}
@keyframes ch-pop{0%{transform:scale(.6)}60%{transform:scale(1.15)}100%{transform:scale(1)}}

@media (prefers-reduced-motion:reduce){.ch *{animation:none!important}}
:root[data-motion="reduce"] .ch *{animation:none!important}                 /* the same rule, for tests and a page's own switch */
.ch-still .ch *{animation:none!important}
.ch-paused .ch *{animation-play-state:paused!important}
