/* A dragon flies across the board every 5 moves the player makes (see dragon.js).
   Everything moves with transform/opacity only, so the flight stays smooth on the
   browser's compositor even while the computer opponent is thinking on the main
   thread. .dr-x and .dr-y are full-size layers, so their translate percentages
   are percentages of the board. Each wing is its own layer so it can flap there too. */
.dr-layer {
  --dw: clamp(150px, 46vw, 260px);   /* dragon width */
  position:absolute; inset:0; z-index:6; pointer-events:none; overflow:hidden; border-radius:6px;
}
.dr-x, .dr-y { position:absolute; inset:0 }
.dr-x { animation: dr-fly-x 3.2s cubic-bezier(.4,.05,.6,.95) forwards }
.dr-y { animation: dr-fly-y 3.2s ease-in-out forwards }

/* The dragon: body art from dragon-body.svg (200 x 120), wings from dragon-wing.svg. */
.dr {
  position:absolute; top:30%; left:102%;
  width:var(--dw); aspect-ratio: 200 / 120;
  filter: drop-shadow(0 8px 10px rgba(0,0,0,.4));
}
.dr img { position:absolute; display:block; user-select:none; -webkit-user-drag:none }
.dr-body { inset:0; width:100%; height:100% }
/* Shoulder at (80,52) of the body; the wing's own shoulder is at 8% / 90% of the wing. */
.dr-wing { left:35%; top:-27%; width:56%; height:78%; transform-origin:8% 90% }
.dr-wing.near { animation: dr-flap .55s ease-in-out infinite }
.dr-wing.far  { left:41%; top:-31%; width:50%; height:70%; filter:brightness(.5) saturate(.8); animation: dr-flap .55s ease-in-out -.08s infinite }

/* Fire from the mouth (the snout is at the left edge, 44% down): fireballs roll
   out of the jaws and billow larger as they burn out, over a hot core at the mouth. */
.dr-fire { position:absolute; right:95%; top:14%; width:70%; height:62% }
.dr-fire .puff {
  position:absolute; right:0; top:50%; width:34%; aspect-ratio:1; margin-top:-17%;
  border-radius:50%;
  background: radial-gradient(circle, #fffbe0 0 12%, #ffd34a 30%, #ff7a1a 52%, rgba(190,30,0,.55) 64%, rgba(120,0,0,0) 72%);
  filter: blur(1.2px);
  opacity:0;
  animation: dr-puff .62s linear infinite;
}
.dr-fire .puff:nth-child(2) { animation-delay:-.1s;  top:46% }
.dr-fire .puff:nth-child(3) { animation-delay:-.2s;  top:54% }
.dr-fire .puff:nth-child(4) { animation-delay:-.31s; top:48% }
.dr-fire .puff:nth-child(5) { animation-delay:-.41s; top:53% }
.dr-fire .puff:nth-child(6) { animation-delay:-.52s; top:47% }
.dr-fire .core {
  position:absolute; right:-2%; top:38%; width:30%; height:24%; border-radius:50%;
  background: radial-gradient(ellipse at 100% 50%, #ffffff, #fff1a8 35%, rgba(255,190,60,0) 75%);
  transform-origin:100% 50%;
  animation: dr-core .14s ease-in-out infinite alternate;
}

/* A soft shadow on the board, below the flight path. */
.dr-shadow {
  position:absolute; left:102%; top:74%;
  width:calc(var(--dw) * .7); height:7%; margin-left:calc(var(--dw) * .15);
  border-radius:50%;
  background: radial-gradient(ellipse, rgba(0,0,0,.38), rgba(0,0,0,0) 70%);
}

.dr-ember {
  position:absolute; width:8px; height:8px; border-radius:50%; opacity:0;
  background: radial-gradient(circle, #fff3b0, #ff9a2a 50%, rgba(255,80,0,0) 70%);
  animation: dr-ember 1.1s ease-out forwards;
}

.dr-msg {
  position:absolute; left:50%; bottom:6%;
  font:800 clamp(1.1rem, 4.6vw, 1.9rem)/1 "Bricolage Grotesque", system-ui, sans-serif;
  color:#fff; white-space:nowrap; padding:.45em .9em; border-radius:999px;
  background:rgba(120,20,10,.88);
  box-shadow: 0 0 0 3px #ffcf5a, 0 0 24px rgba(255,120,30,.8);
  opacity:0;
  animation: dr-pop 3.4s ease forwards;
}

/* From just off the right edge to fully off the left edge. */
@keyframes dr-fly-x { from { transform:translateX(0) } to { transform:translateX(-185%) } }
/* A swoop: dive, climb, glide out. */
@keyframes dr-fly-y {
  0%   { transform:translateY(-6%) }
  35%  { transform:translateY(-18%) }
  70%  { transform:translateY(6%) }
  100% { transform:translateY(-10%) }
}
/* Downstroke: the wing folds through flat to below the body, then sweeps back up. */
@keyframes dr-flap {
  0%   { transform: rotate(-8deg) scaleY(1) }
  45%  { transform: rotate(10deg) scaleY(-.55) }
  100% { transform: rotate(-8deg) scaleY(1) }
}
/* Each fireball leaves the mouth small and white-hot, then grows and fades. */
@keyframes dr-puff {
  0%   { transform: translateX(0) scale(.3); opacity:1 }
  60%  { opacity:.9 }
  100% { transform: translateX(-215%) scale(1.45); opacity:0 }
}
@keyframes dr-core { from { transform: scaleX(.8); opacity:.85 } to { transform: scaleX(1.15); opacity:1 } }
@keyframes dr-ember {
  0%   { opacity:0; transform:scale(.5) }
  20%  { opacity:1; transform:scale(1.4) }
  100% { opacity:0; transform:translateY(30px) scale(.3) }
}
@keyframes dr-pop {
  0%   { opacity:0; transform:translateX(-50%) scale(.6) }
  12%  { opacity:1; transform:translateX(-50%) scale(1.08) }
  20%  { opacity:1; transform:translateX(-50%) scale(1) }
  80%  { opacity:1; transform:translateX(-50%) scale(1) }
  100% { opacity:0; transform:translateX(-50%) scale(1) }
}

@media (prefers-reduced-motion: reduce) {
  .dr-x, .dr-y, .dr-wing.near, .dr-wing.far, .dr-fire .core { animation:none }
  .dr-fire .puff { display:none }
  .dr { left:50%; top:24%; transform:translateX(-50%); animation: dr-still 3s ease forwards }
  .dr-shadow, .dr-ember { display:none }
  @keyframes dr-still { 0%, 100% { opacity:0 } 15%, 80% { opacity:1 } }
}
