/* ── companion: carteiro ─────────────────────────────────────────── */

#companion {
  position: fixed;
  z-index: 9999;
  pointer-events: none;
  will-change: transform;
  filter: drop-shadow(0 2px 6px rgba(0,0,0,.45));
  transition: filter .3s;
}

/* ── character rig ──────────────────────────────────────────────── */

.cw {
  position: relative;
  width: 64px;
  height: 84px;
}

/* breathing / bounce keyframes applied to the whole rig */
#companion.state-idle .cw      { animation: cw-breathe 2.4s ease-in-out infinite; }
#companion.state-walking .cw   { animation: cw-walk-bounce .32s ease-in-out infinite; }
#companion.state-delivering .cw{ animation: cw-deliver-bounce .4s ease-in-out infinite; }
#companion.state-celebrating .cw{ animation: cw-celebrate .5s ease-in-out infinite; }

@keyframes cw-breathe {
  0%,100% { transform: translateY(0); }
  50%     { transform: translateY(-3px); }
}
@keyframes cw-walk-bounce {
  0%,100% { transform: translateY(0) rotate(-2deg); }
  50%     { transform: translateY(-5px) rotate(2deg); }
}
@keyframes cw-deliver-bounce {
  0%,100% { transform: translateY(0) scale(1); }
  50%     { transform: translateY(-7px) scale(1.05); }
}
@keyframes cw-celebrate {
  0%,100% { transform: translateY(0) rotate(0); }
  25%     { transform: translateY(-10px) rotate(-6deg); }
  75%     { transform: translateY(-10px) rotate(6deg); }
}

/* ── shadow on ground ──────────────────────────────────────────── */

.cw-shadow {
  position: absolute;
  bottom: -4px;
  left: 50%;
  width: 36px;
  height: 8px;
  background: radial-gradient(ellipse, rgba(0,0,0,.35) 0%, transparent 70%);
  transform: translateX(-50%);
  border-radius: 50%;
}

/* ── hat ────────────────────────────────────────────────────────── */

.cw-hat {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 44px;
  height: 16px;
  background: #1d4ed8;
  border-radius: 6px 6px 2px 2px;
  z-index: 3;
}
.cw-hat::before {
  content: "";
  position: absolute;
  bottom: -4px;
  left: -4px;
  right: -4px;
  height: 6px;
  background: #1e3a8a;
  border-radius: 2px;
}
.cw-hat-badge {
  position: absolute;
  top: 4px;
  left: 50%;
  transform: translateX(-50%);
  width: 8px;
  height: 8px;
  background: #fbbf24;
  border-radius: 50%;
  z-index: 4;
  box-shadow: 0 0 4px rgba(251,191,36,.6);
}

/* ── head ───────────────────────────────────────────────────────── */

.cw-head {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  width: 36px;
  height: 32px;
  background: #fcd9b6;
  border-radius: 10px;
  z-index: 2;
}

/* eyes */
.cw-eye {
  position: absolute;
  top: 10px;
  width: 5px;
  height: 6px;
  background: #1e293b;
  border-radius: 50%;
  transition: height .15s, top .15s;
}
.cw-eye.l { left: 8px; }
.cw-eye.r { right: 8px; }

/* blink */
#companion.state-idle .cw-eye {
  animation: cw-blink 4s ease-in-out infinite;
}
@keyframes cw-blink {
  0%,42%,46%,100% { height: 6px; top: 10px; }
  44%             { height: 1px; top: 13px; }
}

/* happy eyes (delivering / celebrating) */
#companion.state-delivering .cw-eye,
#companion.state-celebrating .cw-eye {
  height: 2px;
  top: 12px;
  border-radius: 2px 2px 0 0;
  animation: none;
}

/* mouth */
.cw-mouth {
  position: absolute;
  bottom: 6px;
  left: 50%;
  transform: translateX(-50%);
  width: 8px;
  height: 3px;
  border-bottom: 2px solid #c2856a;
  border-radius: 0 0 4px 4px;
  transition: all .2s;
}
#companion.state-delivering .cw-mouth,
#companion.state-celebrating .cw-mouth {
  width: 10px;
  height: 5px;
  border-bottom-width: 0;
  background: #c2856a;
  border-radius: 0 0 5px 5px;
}

/* cheeks */
.cw-cheek {
  position: absolute;
  bottom: 8px;
  width: 7px;
  height: 4px;
  background: rgba(255,140,140,.45);
  border-radius: 50%;
}
.cw-cheek.l { left: 2px; }
.cw-cheek.r { right: 2px; }

/* ── body ───────────────────────────────────────────────────────── */

.cw-body {
  position: absolute;
  top: 42px;
  left: 50%;
  transform: translateX(-50%);
  width: 30px;
  height: 24px;
  background: #2563eb;
  border-radius: 6px 6px 4px 4px;
  z-index: 1;
}
/* buttons */
.cw-body::before {
  content: "";
  position: absolute;
  top: 6px;
  left: 50%;
  transform: translateX(-50%);
  width: 4px;
  height: 4px;
  background: #fbbf24;
  border-radius: 50%;
  box-shadow: 0 7px 0 #fbbf24;
}

/* ── bag strap ──────────────────────────────────────────────────── */

.cw-strap {
  position: absolute;
  top: 42px;
  left: 12px;
  width: 40px;
  height: 3px;
  background: #92400e;
  transform: rotate(25deg);
  z-index: 2;
  border-radius: 1px;
}

/* ── arms ───────────────────────────────────────────────────────── */

.cw-arm {
  position: absolute;
  top: 44px;
  width: 8px;
  height: 18px;
  background: #2563eb;
  border-radius: 4px;
  z-index: 0;
  transform-origin: top center;
  transition: transform .2s;
}
.cw-arm.l {
  left: 10px;
  animation: cw-arm-swing-l .32s ease-in-out infinite;
}
.cw-arm.r {
  right: 10px;
  animation: cw-arm-swing-r .32s ease-in-out infinite;
}
/* hand */
.cw-arm::after {
  content: "";
  position: absolute;
  bottom: -2px;
  left: 50%;
  transform: translateX(-50%);
  width: 7px;
  height: 7px;
  background: #fcd9b6;
  border-radius: 50%;
}

#companion.state-idle .cw-arm { animation: none; }
#companion.state-idle .cw-arm.l { transform: rotate(5deg); }
#companion.state-idle .cw-arm.r { transform: rotate(-5deg); }

#companion.state-delivering .cw-arm.l,
#companion.state-celebrating .cw-arm.l {
  animation: none;
  transform: rotate(-45deg);
}
#companion.state-delivering .cw-arm.r,
#companion.state-celebrating .cw-arm.r {
  animation: none;
  transform: rotate(45deg);
}

@keyframes cw-arm-swing-l {
  0%,100% { transform: rotate(15deg); }
  50%     { transform: rotate(-15deg); }
}
@keyframes cw-arm-swing-r {
  0%,100% { transform: rotate(-15deg); }
  50%     { transform: rotate(15deg); }
}

/* ── legs ───────────────────────────────────────────────────────── */

.cw-leg {
  position: absolute;
  top: 64px;
  width: 10px;
  height: 14px;
  background: #1e3a8a;
  border-radius: 3px 3px 4px 4px;
  z-index: 0;
  transform-origin: top center;
}
/* shoe */
.cw-leg::after {
  content: "";
  position: absolute;
  bottom: -2px;
  left: -1px;
  width: 12px;
  height: 5px;
  background: #78350f;
  border-radius: 3px 6px 3px 3px;
}

.cw-leg.l { left: 19px; }
.cw-leg.r { right: 19px; }

#companion.state-idle .cw-leg { animation: none; }
#companion.state-walking .cw-leg.l { animation: cw-leg-l .32s ease-in-out infinite; }
#companion.state-walking .cw-leg.r { animation: cw-leg-r .32s ease-in-out infinite; }

#companion.state-delivering .cw-leg,
#companion.state-celebrating .cw-leg {
  animation: none;
  transform: rotate(0);
}

@keyframes cw-leg-l {
  0%,100% { transform: rotate(12deg); }
  50%     { transform: rotate(-12deg); }
}
@keyframes cw-leg-r {
  0%,100% { transform: rotate(-12deg); }
  50%     { transform: rotate(12deg); }
}

/* ── letter (carried) ──────────────────────────────────────────── */

.cw-letter {
  position: absolute;
  top: 32px;
  left: -6px;
  width: 18px;
  height: 13px;
  background: #fef3c7;
  border: 1px solid #d97706;
  border-radius: 2px;
  z-index: 5;
  opacity: 0;
  transform: scale(0);
  transition: opacity .25s, transform .25s cubic-bezier(.34,1.56,.64,1);
}
.cw-letter::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-top: 6px solid #d97706;
}
.cw-letter::after {
  content: "";
  position: absolute;
  top: 1px;
  left: 1px;
  width: 0;
  height: 0;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-top: 5px solid #fef3c7;
}

#companion.state-delivering .cw-letter,
#companion.state-celebrating .cw-letter {
  opacity: 1;
  transform: scale(1);
}

/* ── bag on back ────────────────────────────────────────────────── */

.cw-bag {
  position: absolute;
  top: 44px;
  right: 2px;
  width: 16px;
  height: 18px;
  background: #92400e;
  border-radius: 3px 6px 4px 4px;
  z-index: 0;
}
.cw-bag::before {
  content: "";
  position: absolute;
  top: -3px;
  left: 2px;
  width: 12px;
  height: 6px;
  border: 2px solid #78350f;
  border-bottom: none;
  border-radius: 6px 6px 0 0;
}

/* ── thought bubble ────────────────────────────────────────────── */

.cw-bubble {
  position: absolute;
  bottom: calc(100% + 12px);
  left: 50%;
  transform: translateX(-50%) scale(0);
  background: #1e293b;
  color: #e2e8f0;
  font-size: 10px;
  font-family: "SF Mono", "Cascadia Code", "Fira Code", monospace;
  padding: 5px 9px;
  border-radius: 8px;
  white-space: nowrap;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0;
  transition: transform .3s cubic-bezier(.34,1.56,.64,1), opacity .3s;
  pointer-events: none;
  border: 1px solid #334155;
  z-index: 10;
}
.cw-bubble::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid #1e293b;
}
.cw-bubble.show {
  opacity: 1;
  transform: translateX(-50%) scale(1);
}

/* ── delivery counter badge ────────────────────────────────────── */

.cw-badge {
  position: absolute;
  top: -8px;
  right: -12px;
  background: #ef4444;
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  font-family: "SF Mono", monospace;
  min-width: 18px;
  height: 18px;
  line-height: 18px;
  text-align: center;
  border-radius: 9px;
  padding: 0 4px;
  opacity: 0;
  transform: scale(0);
  transition: opacity .3s, transform .3s cubic-bezier(.34,1.56,.64,1);
  z-index: 10;
  box-shadow: 0 1px 4px rgba(239,68,68,.5);
}
.cw-badge.show {
  opacity: 1;
  transform: scale(1);
}

/* ── particles (envelope sparks) ───────────────────────────────── */

.cw-particle {
  position: fixed;
  width: 8px;
  height: 6px;
  background: #fef3c7;
  border: 1px solid #d97706;
  border-radius: 1px;
  pointer-events: none;
  z-index: 9998;
  animation: cw-particle-fly .7s ease-out forwards;
}
@keyframes cw-particle-fly {
  0%   { opacity: 1; transform: translate(0,0) rotate(0) scale(1); }
  100% { opacity: 0; transform: translate(var(--dx), var(--dy)) rotate(var(--rot)) scale(.3); }
}

/* ── sparkle (celebration) ─────────────────────────────────────── */

.cw-sparkle {
  position: fixed;
  width: 4px;
  height: 4px;
  background: #fbbf24;
  border-radius: 50%;
  pointer-events: none;
  z-index: 9998;
  animation: cw-sparkle-pop .6s ease-out forwards;
  box-shadow: 0 0 6px #fbbf24;
}
@keyframes cw-sparkle-pop {
  0%   { opacity: 1; transform: translate(0,0) scale(1); }
  100% { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(0); }
}

/* ── reduced motion ────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  .cw, .cw-arm, .cw-leg, .cw-eye { animation: none !important; }
  #companion { transition: transform .05s linear !important; }
}
