/* ===========================================
   LIVING DRAGON — cutout rig, laser, intro
   Geometry (layer files, pivots, eye box): css/dragon-rig.css,
   generated by tools/dragon/cut.py
   =========================================== */

/* Anchored by the feet: rescaling the rig in tools/dragon/cut.py keeps it on the ground */
.dragon {
  position: absolute;
  bottom: 21px;
  z-index: 2;
  transition: left 1s ease-out;
}

.dragon-rig {
  position: relative;
  width: var(--rig-w);
  height: var(--rig-h);
  filter: drop-shadow(0 0 8px var(--dragon-color)) drop-shadow(0 0 18px rgba(0, 240, 255, 0.45));
}

.dragon-rig .part,
.dragon-rig .head-aim,
.dragon-rig .head-idle,
.dragon-rig .glow {
  position: absolute;
  inset: 0;
}

.dragon-rig .part,
.dragon-rig .glow {
  background-size: 100% 100%;
  background-repeat: no-repeat;
}

/* Idle: breathing body, head riding on it, tail and hand on their own beat */
.dragon-rig .part.body { animation: dragon-breathe 3.2s ease-in-out infinite; }
.dragon-rig .head-idle { animation: dragon-head-idle 3.2s ease-in-out infinite; }
.dragon-rig .part.hand { animation: dragon-hand 3.2s ease-in-out infinite; }
.dragon-rig .part.tail { animation: dragon-tail 2.6s ease-in-out infinite; }

@keyframes dragon-breathe {
  0%, 100% { transform: scaleY(1); }
  50% { transform: scaleY(1.025); }
}

/* Lift follows the chest rise of dragon-breathe at the neck (~1.4% of the rig) */
@keyframes dragon-head-idle {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-1.4%) rotate(-4deg); }
}

@keyframes dragon-hand {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-1%) rotate(-6deg); }
}

@keyframes dragon-tail {
  0%, 100% { transform: rotate(-7deg); }
  50% { transform: rotate(7deg); }
}

/* Light wave along spikes and neon lines, tail -> head. All glow layers share
   the rig canvas, so one mask position keeps the wave continuous across parts */
.dragon-rig .glow {
  mix-blend-mode: screen;
  filter: brightness(2.2) drop-shadow(0 0 4px rgba(255, 255, 255, 0.8));
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 50%, transparent);
  mask-image: linear-gradient(90deg, transparent, #000 50%, transparent);
  -webkit-mask-size: 35% 100%;
  mask-size: 35% 100%;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  animation: dragon-neon-wave 3.6s linear infinite;
}

@keyframes dragon-neon-wave {
  0% { -webkit-mask-position: -60% 0; mask-position: -60% 0; }
  100% { -webkit-mask-position: 160% 0; mask-position: 160% 0; }
}

/* Eye: pulsing glow and a blink every few seconds */
.dragon-rig .eye { position: absolute; }

.dragon-rig .eye::before {
  content: '';
  position: absolute;
  inset: -40%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.9) 0 15%, rgba(255, 42, 109, 0.8) 35%, transparent 70%);
  mix-blend-mode: screen;
  animation: dragon-eye-glow 1.6s ease-in-out infinite;
}

.dragon-rig .eyelid {
  position: absolute;
  inset: 0;
  border-radius: 40%;
  transform: scaleY(0);
  transform-origin: 50% 0;
  animation: dragon-blink 4.3s infinite;
}

@keyframes dragon-eye-glow {
  0%, 100% { opacity: 0.55; transform: scale(0.9); }
  50% { opacity: 1; transform: scale(1.1); }
}

@keyframes dragon-blink {
  0%, 93%, 100% { transform: scaleY(0); }
  96% { transform: scaleY(1); }
}

/* Danger zone stops at the dragon's eye; never wider than the track */
.danger-zone { max-width: 100%; }

/* Laser: aim the head, open the jaw, flare the eye, hold the idle pose */
.dragon-rig .head-aim {
  transform: rotate(var(--aim, 0deg));
  transition: transform 0.35s cubic-bezier(0.3, 1.4, 0.5, 1);
}

.dragon-rig .part.jaw { transition: transform 0.12s ease-out; }
.dragon-rig.is-aiming .part.jaw { transform: rotate(5deg); }
.dragon-rig.is-firing .part.jaw { transform: rotate(16deg); }

.dragon-rig.is-aiming .head-idle,
.dragon-rig.is-firing .head-idle { animation-play-state: paused; }

.dragon-rig.is-aiming .eye::before,
.dragon-rig.is-firing .eye::before {
  animation: none;
  opacity: 1;
  transform: scale(1.8);
}

.dragon-rig.is-aiming .eyelid,
.dragon-rig.is-firing .eyelid { animation: none; }

.dragon-laser {
  position: absolute;
  height: 6px;
  margin-top: -3px;
  border-radius: 3px;
  transform-origin: 0 50%;
  background: linear-gradient(180deg, transparent, var(--neon-pink) 20%, #fff 42%, #fff 58%, var(--neon-pink) 80%, transparent);
  box-shadow: 0 0 10px var(--neon-pink), 0 0 22px #ff0044;
  mix-blend-mode: screen;
  pointer-events: none;
  z-index: 7;
}

.dragon-spark {
  position: absolute;
  width: 4px;
  height: 4px;
  margin: -2px 0 0 -2px;
  background: #fff;
  box-shadow: 0 0 6px var(--neon-pink), 0 0 10px var(--neon-pink);
  pointer-events: none;
  z-index: 8;
}

/* Hit lands on the img, so it never fights the avatar's own state animations */
.student-marker .avatar img.hit { animation: avatar-hit 0.45s ease-out; }

@keyframes avatar-hit {
  0% { filter: brightness(3) saturate(0); transform: translateX(0); }
  20% { transform: translateX(-4px); }
  40% { filter: brightness(2); transform: translateX(4px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(2px); }
  100% { filter: none; transform: translateX(0); }
}

/* Intro replay: everyone runs from the start line to today's positions.
   --intro-ms / --intro-stagger come from INTRO_* in js/dashboard.js */
.progress-track.intro .dragon,
.progress-track.intro .student-marker {
  transition: left var(--intro-ms, 2s) cubic-bezier(0.25, 0.8, 0.3, 1);
}

.progress-track.intro .student-marker {
  transition-delay: calc(var(--i, 0) * var(--intro-stagger, 80ms));
}

.progress-track.intro .danger-zone,
.progress-track.intro .safe-zone {
  transition: width var(--intro-ms, 2s) cubic-bezier(0.25, 0.8, 0.3, 1);
}

.progress-track .student-marker.running .avatar {
  animation: avatar-run 0.3s ease-in-out infinite;
}

@keyframes avatar-run {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

/* Heavy stomping walk while the dragon runs in */
.dragon-rig.is-walking { animation: dragon-stomp 0.42s ease-in-out infinite; }
.dragon-rig.is-walking .head-idle { animation-duration: 0.84s; }

@keyframes dragon-stomp {
  0%, 50%, 100% { transform: translateY(0) rotate(0deg); }
  25% { transform: translateY(-5%) rotate(-1.5deg); }
  75% { transform: translateY(-5%) rotate(1.5deg); }
}

@media (prefers-reduced-motion: reduce) {
  .dragon-rig,
  .dragon-rig *,
  .dragon-rig .eye::before,
  .progress-track .student-marker.running .avatar {
    animation: none !important;
    transition: none !important;
  }
}
