/*
 * Codi · estilos del componente
 * Cambia los tokens --codi-* para ajustar tamaño, colores y posición.
 */
.codi {
  --codi-size: 76px;
  --codi-ring: #f1bd19;        /* primary-500 */
  --codi-bg: #070707;          /* surface-dark */
  --codi-eye: #fef8e8;         /* primary-50 */
  --codi-accent: #f6d365;      /* primary-300 */
  --codi-bubble-bg: #fef8e8;
  --codi-bubble-fg: #111111;
  --codi-right: 20px;
  --codi-bottom: 20px;
  --codi-font: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;

  position: fixed;
  right: calc(var(--codi-right) + env(safe-area-inset-right, 0px));
  bottom: calc(var(--codi-bottom) + env(safe-area-inset-bottom, 0px));
  z-index: 50;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  pointer-events: none;
  transition: right .35s ease, bottom .35s ease;
}
.codi > * { pointer-events: auto; }

.codi__avatar {
  width: var(--codi-size);
  height: var(--codi-size);
  flex: none;
  padding: 0;
  border-radius: 50%;
  border: 2px solid var(--codi-ring);
  background: var(--codi-bg);
  box-shadow: 0 0 0 6px rgba(241, 189, 25, .08), 0 10px 30px rgba(0, 0, 0, .45);
  cursor: pointer;
  animation: codi-float 3.4s ease-in-out infinite;
  transition: width .4s ease, height .4s ease, box-shadow .3s ease;
}
.codi__avatar:hover { box-shadow: 0 0 0 8px rgba(241, 189, 25, .14), 0 10px 30px rgba(0, 0, 0, .45); }
.codi__avatar:focus-visible { outline: 2px solid var(--codi-accent); outline-offset: 4px; }
.codi__avatar svg { width: 100%; height: 100%; display: block; overflow: visible; }
.codi__braces { fill: none; stroke: var(--codi-ring); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }

.codi--dormido .codi__avatar { animation-duration: 6s; box-shadow: 0 0 0 4px rgba(241, 189, 25, .04), 0 10px 30px rgba(0, 0, 0, .45); }

.codi__bubble {
  max-width: min(240px, 58vw);
  background: var(--codi-bubble-bg);
  color: var(--codi-bubble-fg);
  font: 500 13px/1.45 var(--codi-font);
  padding: 9px 13px;
  border-radius: 14px 14px 4px 14px;
  margin-bottom: calc(var(--codi-size) * .35);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .35);
  transform-origin: 100% 100%;
  overflow-wrap: anywhere;
}
.codi__bubble--in { animation: codi-pop .22s cubic-bezier(.3, 1.4, .5, 1); }
.codi--talking .codi__text::after { content: "▍"; color: #ab8612; margin-left: 1px; }

/* Modo escenario: Codi grande al centro, ideal para grabar para redes */
.codi[data-mode="stage"] {
  --codi-size: min(52vw, 46vh, 300px);
  inset: 0;
  right: 0; bottom: 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 34px;
  background: radial-gradient(circle at 50% 44%, #1c1503 0%, #070707 62%);
  z-index: 80;
}
.codi[data-mode="stage"] .codi__avatar { border-width: 4px; box-shadow: 0 0 0 18px rgba(241, 189, 25, .06), 0 0 120px rgba(241, 189, 25, .16); }
.codi[data-mode="stage"] .codi__bubble {
  order: 2; margin: 0; max-width: min(86vw, 520px);
  font-size: clamp(16px, 2.6vw, 22px); text-align: center;
  border-radius: 18px; padding: 14px 20px; transform-origin: 50% 0;
}

/* Animaciones del cuerpo */
.codi--hop { animation: codi-hop .45s cubic-bezier(.3, 1.5, .5, 1) !important; }
.codi--shake { animation: codi-shake .12s linear 3 !important; }

/* Animaciones internas de cada expresión (clases usadas en expressions.js) */
.codi .codi-z { animation: codi-z 1.8s ease-out infinite; transform-box: fill-box; }
.codi .codi-dot { animation: codi-dot .9s ease-in-out infinite; transform-box: fill-box; }
.codi .codi-heart { animation: codi-heart 1s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
.codi .codi-spark { animation: codi-spark 1.6s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
.codi .codi-caret { animation: codi-caret 1s steps(1) infinite; }
.codi .codi-glitch { animation: codi-glitch .5s steps(2) infinite; }
.codi .codi-sweat { animation: codi-sweat 1.6s ease-in infinite; transform-box: fill-box; }

@keyframes codi-float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
@keyframes codi-pop { from { transform: scale(.7); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes codi-hop { 0% { transform: translateY(0); } 40% { transform: translateY(-14px) scale(1.04); } 100% { transform: translateY(0); } }
@keyframes codi-shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
@keyframes codi-z { 0% { opacity: 0; transform: translate(0, 2px); } 40% { opacity: 1; } 100% { opacity: 0; transform: translate(3px, -5px); } }
@keyframes codi-dot { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }
@keyframes codi-heart { 50% { transform: scale(1.18); } }
@keyframes codi-spark { 0%, 100% { transform: scale(1) rotate(0); } 50% { transform: scale(1.25) rotate(45deg); } }
@keyframes codi-caret { 50% { opacity: 0; } }
@keyframes codi-glitch { 0% { transform: translate(-1.4px, .6px); } 50% { transform: translate(1.6px, -.8px); } 100% { transform: translate(-.6px, 0); } }
@keyframes codi-sweat { 0% { transform: translateY(-1px); opacity: 0; } 30% { opacity: 1; } 100% { transform: translateY(5px); opacity: 0; } }

@media (max-width: 640px) {
  .codi { --codi-size: 64px; --codi-right: 14px; --codi-bottom: 14px; }
  .codi__bubble { font-size: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .codi__avatar, .codi .codi-z, .codi .codi-dot, .codi .codi-heart, .codi .codi-spark,
  .codi .codi-caret, .codi .codi-glitch, .codi .codi-sweat, .codi--hop, .codi--shake { animation: none !important; }
}
