/* TOQUIA Cinematic — Scene 06 · Toki. Charcoal room, emerald key light, gold rim light.
   Toki is a stack of 512×512 layers (see js/toki-rig.mjs). All motion is transform/opacity on
   composited layers; the idle loop only runs while the scene is on screen. */

.toki-stage {
  aspect-ratio: 1 / 1;
  max-height: min(70vh, 640px);
  margin-inline: auto;
  perspective: 1200px;
  --tk-line: rgba(79,174,138,.85);
  --tk-gold: var(--tq-gold);
  --tk-visor: #0b0d0c;
}
.tk-light { position: absolute; inset: -12%; pointer-events: none; }
.tk-light i { position: absolute; border-radius: 50%; }
.tk-key  { inset: 14% 12% 18%; background: radial-gradient(circle at 50% 45%, rgba(20,92,70,.75), rgba(20,92,70,.18) 45%, transparent 68%); }
.tk-rim  { width: 46%; aspect-ratio: 1; right: 6%; top: 4%; background: radial-gradient(circle, rgba(197,164,109,.28), transparent 65%); }
.tk-floor { left: 24%; right: 24%; bottom: 13%; height: 7%; background: radial-gradient(ellipse at 50% 50%, rgba(79,174,138,.35), rgba(0,0,0,.4) 55%, transparent 72%); }

.tk-rig { position: absolute; inset: 4% 6% 8%; transform-style: preserve-3d; }
.tk-layer { position: absolute; inset: 0; }
.tk-layer svg, .tk-layer img { width: 100%; height: 100%; display: block; }
.tk-layer[hidden] { display: none; }
.tk-group { transform-style: preserve-3d; }
.tk-defs { position: absolute; width: 0; height: 0; overflow: hidden; }

/* Eyes on the visor */
.tk-eyes path { fill: #4CF87A; stroke: none; }
.tk-eyes .tk-e-happy, .tk-eyes .tk-e-closed { display: none; }
[data-expression="happy"] .tk-e-open, [data-expression="closed"] .tk-e-open { display: none; }
[data-expression="happy"] .tk-e-happy { display: inline; }
[data-expression="closed"] .tk-e-closed { display: inline; }
[data-expression="look-left"] .tk-eye { transform: translateX(-18.2px); }
[data-expression="look-right"] .tk-eye { transform: translateX(17.3px); }
.tk-eye { transition: transform .35s var(--ease-out); }
/* Soft glow behind the eyes: a static blurred copy (the filter itself is never animated) */
.tk-eyes svg { overflow: visible; }
.tk-eyes .tk-glow { filter: blur(3px); opacity: .35; }


/* Approved clips: presentation (canvas) and idle loop (video, or WebGL canvas for the stacked
   fallback). Same box as the rig; only one source is visible at a time (js/toki-clips.mjs). */
.tk-clip, .tk-loop, .tk-loop-gl, .tk-static {
  position: absolute; left: 6%; top: 4%; width: 88%; height: 88%;
  pointer-events: none;
}
.tk-clip, .tk-loop-gl { visibility: hidden; }
.tk-loop { opacity: 0; object-fit: contain; background: transparent; }
.tk-clip.is-shown, .tk-loop-gl.is-shown { visibility: visible; }
.tk-loop.is-shown { opacity: 1; }
.tk-rig.is-hidden { visibility: hidden; }

/* ── Idle life (only while on screen, never with reduced motion) ── */
.tk-rig.is-awake [data-layer="torso"],
.tk-rig.is-awake [data-layer="head-group"] { animation: tk-breathe 3.6s var(--ease-in-out) infinite; }
.tk-rig.is-awake [data-layer="head-group"] { animation-delay: -.25s; }
.tk-rig.is-awake [data-layer="cape"] { animation: tk-cape 3.6s var(--ease-in-out) infinite; }
@keyframes tk-breathe { 50% { translate: 0 -1.2%; } }
@keyframes tk-cape { 50% { rotate: 1.6deg; scale: 1.015 1; } }

/* With the clips ready the layers hold still, so the handover to the clip matches exactly. */
.tk-rig.has-clips [data-layer] { animation: none; }

@media (prefers-reduced-motion: reduce) {
  .tk-rig.is-awake [data-layer] { animation: none !important; }
}
@media (max-width: 959px) {
  .toki-stage { max-height: none; width: min(100%, 440px); }
}
