/* ─── MATI — mascota IA flotante ────────────────────────── */
#mati-root {
  position: fixed;
  bottom: 24px;
  left: 24px;
  z-index: 500;
  width: 100px;
  height: 118px;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-drag: none;
}
#mati-root:active { cursor: grabbing; }
/* on juego.html, visibility during actual gameplay is toggled from JS (see
   initJuegoVisibility in mascot.js) instead of a CSS class — #game-stage's
   .overlay-open is only ever toggled true/false by specific game events
   (quiz, game over, start()), never set at the very first page load, so a
   pure-CSS :has() check on that class misread "haven't pressed start yet"
   as "actively playing" and hid Mati before the intro screen even showed */
#mati-root canvas {
  display: block;
  filter: drop-shadow(0 4px 12px rgba(56, 189, 248, 0.35));
  pointer-events: none;
}
@media (max-width: 560px) {
  #mati-root { width: 76px; height: 90px; bottom: 16px; left: 16px; }
  #mati-root canvas { transform: scale(.76); transform-origin: bottom left; }
}

/* ground shadow used by the "hole" entrance */
#mati-root::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: -6px;
  width: 60%;
  height: 10px;
  background: radial-gradient(ellipse at center, rgba(0,0,0,.45), transparent 70%);
  transform: translateX(-50%) scale(0);
  transform-origin: center;
  pointer-events: none;
}

/* parachute canopy used by the "parachute" entrance */
#mati-root::before {
  content: '';
  position: absolute;
  left: 50%;
  top: -46px;
  width: 70px;
  height: 40px;
  background: linear-gradient(180deg, var(--cyan), var(--violet));
  clip-path: ellipse(50% 100% at 50% 100%);
  transform: translateX(-50%);
  opacity: 0;
  pointer-events: none;
}

@keyframes mati-enter-hole {
  0%   { transform: scale(0) translateY(30px); }
  60%  { transform: scale(1.15) translateY(-6px); }
  100% { transform: scale(1) translateY(0); }
}
#mati-root.enter-hole { animation: mati-enter-hole .6s cubic-bezier(.34,1.56,.64,1) both; }
#mati-root.enter-hole::after { animation: mati-hole-shadow .6s ease-out both; }
@keyframes mati-hole-shadow {
  0%   { transform: translateX(-50%) scale(0); }
  100% { transform: translateX(-50%) scale(1); }
}

@keyframes mati-enter-corner {
  0%   { transform: translate(-140vw, -140vh) rotate(-25deg); }
  100% { transform: translate(0, 0) rotate(0deg); }
}
#mati-root.enter-corner { animation: mati-enter-corner .7s cubic-bezier(.34,1.56,.64,1) both; }

@keyframes mati-enter-parachute {
  0%   { transform: translateY(-320px) rotate(0deg); }
  25%  { transform: translateY(-220px) rotate(-8deg); }
  50%  { transform: translateY(-120px) rotate(8deg); }
  75%  { transform: translateY(-40px) rotate(-4deg); }
  100% { transform: translateY(0) rotate(0deg); }
}
#mati-root.enter-parachute { animation: mati-enter-parachute 1.6s ease-in both; }
#mati-root.enter-parachute::before { animation: mati-canopy 1.6s ease-in both; }
@keyframes mati-canopy {
  0%   { opacity: 1; }
  90%  { opacity: 1; }
  100% { opacity: 0; }
}

#mati-root.dragging { transition: none !important; animation: none !important; }

/* ─── jump hop (triggered on interaction) — the sprite itself already
   swaps to the real jump pose via the canvas engine, this just arcs the
   whole widget up so it reads as an actual hop, not a pose swap in place */
@keyframes mati-jump {
  0%   { transform: translateY(0); }
  40%  { transform: translateY(-30px); }
  100% { transform: translateY(0); }
}
#mati-root.mati-jump { animation: mati-jump .55s cubic-bezier(.34,1.56,.64,1) both; }

/* ─── speech bubble (intro + grumbles) ──────────────────── */
/* fixed to the viewport (not a child of #mati-root) with a z-index above
   the chat panel (501) — otherwise the panel visually covers the bubble
   whenever positionPanelNear puts it over Mati's current spot */
.mati-bubble {
  position: fixed;
  z-index: 600;
  min-width: 180px;
  max-width: 260px;
  background: rgba(15, 23, 42, .95);
  border: 1px solid var(--border-h);
  color: var(--text);
  font-family: var(--sans);
  font-size: .88rem;
  line-height: 1.4;
  padding: 10px 14px;
  border-radius: 14px;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
  cursor: pointer;
  animation: mati-bubble-in .25s ease-out both;
}
.mati-bubble::after {
  content: '';
  position: absolute;
  top: 100%;
  border: 7px solid transparent;
  border-top-color: rgba(15, 23, 42, .95);
}
/* tail points down at wherever Mati actually is — JS picks whichever side
   has room (see positionBubble in mascot.js) and toggles these */
.mati-bubble.tail-right::after { right: 20px; }
.mati-bubble.tail-left::after { left: 20px; }
@keyframes mati-bubble-in {
  0%   { opacity: 0; transform: translateY(6px) scale(.9); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

/* ─── chat panel ─────────────────────────────────────────── */
#mati-panel {
  /* left/top set at runtime in JS (positionPanelNear), always right next to
     wherever Mati currently is, including mid-drag */
  position: fixed;
  z-index: 501;
  width: min(320px, calc(100vw - 24px));
  max-height: 420px;
  display: none;
  flex-direction: column;
  background: rgba(3, 7, 18, .96);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 12px 32px rgba(0,0,0,.5);
  overflow: hidden;
}
#mati-panel.open { display: flex; }

#mati-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: linear-gradient(135deg, var(--cyan), var(--violet));
  font-family: var(--mono);
  font-size: .8rem;
  color: #05131f;
  font-weight: 700;
}
#mati-panel-close {
  background: none;
  border: none;
  color: #05131f;
  font-size: 1rem;
  cursor: pointer;
  line-height: 1;
}

#mati-panel-log {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: .86rem;
}
.mati-msg {
  padding: 8px 12px;
  border-radius: 12px;
  max-width: 85%;
  line-height: 1.4;
}
.mati-msg.mati   { align-self: flex-start; background: rgba(56,189,248,.14); color: var(--text); }
.mati-msg.user   { align-self: flex-end; background: rgba(139,92,246,.22); color: var(--text); }
.mati-msg.typing { opacity: .6; font-style: italic; }

#mati-panel-form {
  display: flex;
  gap: 6px;
  padding: 10px;
  border-top: 1px solid var(--border);
}
#mati-panel-input {
  flex: 1;
  background: rgba(255,255,255,.05);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  padding: 8px 10px;
  font-family: var(--sans);
  font-size: .85rem;
}
#mati-panel-input:focus { outline: none; border-color: var(--border-h); }
#mati-panel-send {
  background: linear-gradient(135deg, var(--cyan), var(--violet));
  border: none;
  border-radius: 10px;
  padding: 0 14px;
  color: #05131f;
  font-weight: 700;
  cursor: pointer;
}

@media (prefers-reduced-motion: reduce) {
  #mati-root, #mati-root::before, #mati-root::after, .mati-bubble { animation: none !important; }
}
