:root {
  --bg: #1a0b2e;
  --red: #e63946;
  --gold: #ffd60a;
  --blue: #118ab2;
  --purple: #9b5de5;
  --white: #fff;
  --shadow: rgba(0,0,0,0.45);
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--white);
  overflow-x: hidden;
}

.night-sky {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(circle at 20% 20%, rgba(155,93,229,0.35) 0%, transparent 45%),
    radial-gradient(circle at 80% 30%, rgba(17,138,178,0.35) 0%, transparent 45%),
    linear-gradient(180deg, #1a0b2e 0%, #2d1b4e 100%);
}

.stars {
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(2px 2px at 10% 15%, white, transparent),
    radial-gradient(2px 2px at 20% 80%, white, transparent),
    radial-gradient(2px 2px at 50% 30%, white, transparent),
    radial-gradient(2px 2px at 70% 70%, white, transparent),
    radial-gradient(2px 2px at 90% 10%, white, transparent),
    radial-gradient(1px 1px at 15% 55%, white, transparent),
    radial-gradient(1px 1px at 85% 45%, white, transparent);
  animation: twinkle 4s ease-in-out infinite alternate;
}

@keyframes twinkle {
  from { opacity: 0.5; }
  to { opacity: 1; }
}

.top-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  background: rgba(0,0,0,0.25);
  border-bottom: 3px dashed var(--gold);
  gap: 0.75rem;
}

.logo {
  margin: 0;
  font-size: clamp(1rem, 3.5vw, 1.7rem);
  color: var(--gold);
  text-shadow: 2px 2px 0 var(--red), -1px -1px 0 var(--blue);
  animation: popIn 0.8s ease;
}
.star { display: inline-block; animation: spinStar 4s linear infinite; }

@keyframes spinStar {
  0% { transform: rotate(0deg) scale(1); }
  50% { transform: rotate(180deg) scale(1.08); }
  100% { transform: rotate(360deg) scale(1); }
}

@keyframes pulseMic {
  0% { box-shadow: 0 0 0 0 rgba(230,57,70,0.5); }
  70% { box-shadow: 0 0 0 12px rgba(230,57,70,0); }
  100% { box-shadow: 0 0 0 0 rgba(230,57,70,0); }
}

.host-badge {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: linear-gradient(135deg, var(--gold), #ffb703);
  color: #1a0b2e;
  padding: 0.35rem 0.8rem;
  border-radius: 999px;
  font-weight: 800;
  font-size: 0.85rem;
  box-shadow: 0 3px 10px rgba(0,0,0,0.35);
  animation: popIn 0.7s ease;
}
.host-emoji { font-size: 1.1rem; }

.lang-switch {
  display: flex;
  gap: 0.5rem;
}
.lang-switch button {
  background: var(--purple);
  color: var(--white);
  border: 2px solid var(--gold);
  border-radius: 999px;
  padding: 0.35rem 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.2s, background 0.2s;
}
.lang-switch button:hover { transform: scale(1.08); background: var(--blue); }
.lang-switch button.active { background: var(--red); box-shadow: 0 0 12px var(--gold); }

.controls-hint {
  max-width: 1100px;
  margin: 0.8rem auto 0;
  padding: 0 1rem;
  font-size: 1rem;
  color: var(--gold);
  text-align: center;
  font-weight: 700;
}

.stage {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1rem 1.5rem 1.5rem;
}

.ring {
  background: linear-gradient(180deg, rgba(230,57,70,0.9) 0%, rgba(189,16,38,0.95) 100%);
  border: 6px dashed var(--gold);
  border-radius: 40px 40px 20px 20px;
  padding: 1rem;
  box-shadow: 0 20px 60px var(--shadow);
  position: relative;
}
.ring::before,
.ring::after {
  content: "";
  position: absolute;
  top: -20px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: inset -4px -4px 0 rgba(0,0,0,0.2);
}
.ring::before { left: 30px; }
.ring::after { right: 30px; }

.arena {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 10;
  min-height: 320px;
  border-radius: 20px;
  overflow: hidden;
  background: radial-gradient(circle at center, #3a1c35 0%, #1a0b2e 80%);
  border: 3px solid var(--gold);
  touch-action: none;
}

.floor {
  position: absolute;
  inset: 8%;
  border-radius: 50%;
  background: conic-gradient(
    var(--red) 0deg 36deg,
    var(--gold) 36deg 72deg,
    var(--blue) 72deg 108deg,
    var(--purple) 108deg 144deg,
    var(--red) 144deg 180deg,
    var(--gold) 180deg 216deg,
    var(--blue) 216deg 252deg,
    var(--purple) 252deg 288deg,
    var(--red) 288deg 324deg,
    var(--gold) 324deg 360deg
  );
  opacity: 0.95;
  box-shadow: inset 0 0 60px rgba(0,0,0,0.4);
}
.ring-center {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 26%;
  height: 26%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #fff 0%, #ddd 40%, #999 100%);
  box-shadow: 0 0 20px rgba(0,0,0,0.35);
}

/* NPCs */
.npc {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  transition: transform 0.2s;
  outline: none;
  user-select: none;
}
.npc:hover, .npc:focus { transform: scale(1.12); }
.npc.nearby .npc-tag { background: var(--gold); color: #1a0b2e; }
.npc.nearby { filter: drop-shadow(0 0 12px var(--gold)); }

.npc .avatar {
  font-size: clamp(2.2rem, 6vw, 3.5rem);
  line-height: 1;
}
.npc-tag {
  margin-top: 0.25rem;
  background: rgba(0,0,0,0.55);
  color: var(--white);
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: clamp(0.7rem, 2vw, 0.9rem);
  font-weight: 700;
  white-space: nowrap;
  transition: background 0.2s, color 0.2s;
}

.clown-avatar { animation: gentleWobble 3.5s ease-in-out infinite; }
.acrobat-avatar { animation: gentleSwing 4s ease-in-out infinite alternate; }
.magician-avatar { animation: gentleFloat 4.2s ease-in-out infinite; }
.tamer-avatar { animation: gentleNod 3.8s ease-in-out infinite; }

@keyframes gentleWobble {
  0%, 100% { transform: rotate(-2deg); }
  50% { transform: rotate(2deg); }
}
@keyframes gentleSwing {
  from { transform: rotate(-5deg); }
  to { transform: rotate(5deg); }
}
@keyframes gentleFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}
@keyframes gentleNod {
  0%, 100% { transform: rotate(-2deg); }
  50% { transform: rotate(2deg); }
}

/* Jugador */
.player {
  position: absolute;
  left: 50%;
  top: 50%;
  width: clamp(40px, 8vw, 70px);
  height: clamp(40px, 8vw, 70px);
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 10;
  transition: left 0.28s ease-out, top 0.28s ease-out;
  pointer-events: none;
}
.player-avatar {
  font-size: clamp(1.8rem, 5vw, 3rem);
  line-height: 1;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.45));
  animation: popIn 0.4s ease;
}
.player-label {
  margin-top: 0.1rem;
  background: var(--blue);
  color: var(--white);
  font-size: clamp(0.6rem, 1.7vw, 0.8rem);
  font-weight: 800;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
}

.dialogue-bubble {
  position: absolute;
  background: var(--white);
  color: #1a0b2e;
  padding: 0.6rem 1rem;
  border-radius: 18px;
  font-size: clamp(0.75rem, 2.2vw, 1rem);
  font-weight: 700;
  max-width: 40%;
  text-align: center;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s, transform 0.3s;
  z-index: 20;
  transform: translate(-50%, -10px);
}
.dialogue-bubble.show {
  opacity: 1;
  transform: translate(-50%, -20px);
}

.voice-panel {
  max-width: 700px;
  margin: 1rem auto;
  background: rgba(0,0,0,0.3);
  border: 2px solid var(--blue);
  border-radius: 24px;
  padding: 1rem 1.5rem;
  text-align: center;
}

.music-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px dashed rgba(255,255,255,0.25);
}
.music-btn {
  background: linear-gradient(135deg, var(--gold), #ffb703);
  color: #1a0b2e;
  border: none;
  border-radius: 999px;
  padding: 0.6rem 1.2rem;
  font-weight: 800;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  box-shadow: 0 6px 16px rgba(0,0,0,0.3);
  transition: transform 0.2s;
}
.music-btn:hover { transform: scale(1.05); }
.music-volume {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  font-size: 0.85rem;
}
.music-volume input { accent-color: var(--gold); }
.music-credit {
  width: 100%;
  font-size: 0.75rem;
  color: rgba(255,255,255,0.55);
  font-style: italic;
}

.mic-area { display: flex; flex-direction: column; align-items: center; gap: 0.6rem; }
.mic-btn {
  background: linear-gradient(135deg, var(--blue), var(--purple));
  border: none;
  border-radius: 999px;
  padding: 0.85rem 1.4rem;
  color: var(--white);
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  box-shadow: 0 8px 20px rgba(0,0,0,0.35);
  transition: transform 0.2s, box-shadow 0.2s;
}
.mic-btn:hover { transform: scale(1.05); }
.mic-btn.listening {
  animation: pulseMic 1.6s infinite;
  background: linear-gradient(135deg, var(--red), var(--gold));
}

.speech-output {
  min-height: 2rem;
  color: var(--gold);
  font-weight: 600;
}

.controls {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}
.controls label { display: flex; flex-direction: column; align-items: center; gap: 0.3rem; font-size: 0.9rem; }
.controls input[type=range] { accent-color: var(--gold); }

.reply-bubble {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  max-width: 90%;
  padding: 1rem 1.5rem;
  background: var(--white);
  color: #1a0b2e;
  border-radius: 24px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s, transform 0.35s;
  z-index: 100;
  text-align: center;
  font-weight: 700;
}
.reply-bubble.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.history-panel {
  max-width: 700px;
  margin: 1rem auto 1.5rem;
  background: rgba(0,0,0,0.35);
  border: 2px solid var(--gold);
  border-radius: 20px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.35);
  overflow: hidden;
}
.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.7rem 1rem;
  background: rgba(255,214,10,0.12);
  border-bottom: 1px dashed var(--gold);
}
.history-header h3 {
  margin: 0;
  font-size: 1rem;
  color: var(--gold);
}
.clear-history {
  background: transparent;
  border: 2px solid var(--red);
  color: var(--red);
  border-radius: 999px;
  padding: 0.25rem 0.7rem;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.clear-history:hover { background: var(--red); color: var(--white); }
.history-list {
  max-height: 220px;
  overflow-y: auto;
  padding: 0.8rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.history-empty {
  margin: 0;
  color: rgba(255,255,255,0.55);
  font-style: italic;
  text-align: center;
}
.history-entry {
  display: flex;
  gap: 0.6rem;
  align-items: flex-start;
  font-size: 0.9rem;
  line-height: 1.35;
  animation: popIn 0.3s ease;
}
.history-entry .speaker {
  flex-shrink: 0;
  min-width: 4.5rem;
  font-weight: 800;
  color: var(--gold);
}
.history-entry.user .speaker { color: var(--blue); }
.history-entry.host .speaker { color: var(--purple); }
.history-entry .message { color: var(--white); }

.credits {
  text-align: center;
  padding: 0 1rem 2rem;
  color: rgba(255,255,255,0.75);
  font-size: 0.9rem;
}

.credits-card {
  display: inline-block;
  background: linear-gradient(135deg, rgba(0,0,0,0.35), rgba(0,0,0,0.55));
  border: 2px solid var(--gold);
  border-radius: 20px;
  padding: 1.2rem 1.8rem;
  margin-bottom: 1rem;
  box-shadow: 0 10px 30px rgba(0,0,0,0.35);
  backdrop-filter: blur(4px);
}
.credits-card h3 {
  margin: 0 0 0.8rem;
  color: var(--gold);
  font-size: 1.1rem;
  text-shadow: 1px 1px 0 var(--red);
}
.credits-list {
  display: grid;
  gap: 0.6rem;
  text-align: left;
  margin: 0;
}
.credits-list > div {
  display: flex;
  justify-content: space-between;
  gap: 1.5rem;
  border-bottom: 1px dashed rgba(255,255,255,0.2);
  padding-bottom: 0.35rem;
}
.credits-list dt {
  color: rgba(255,255,255,0.75);
  font-weight: 600;
}
.credits-list dd {
  margin: 0;
  color: var(--white);
  font-weight: 800;
}
.credits-list dd:last-child {
  color: var(--gold);
}

.popIn { animation: popIn 0.5s ease; }
@keyframes popIn {
  from { opacity: 0; transform: scale(0.8); }
  to { opacity: 1; transform: scale(1); }
}

@media (max-width: 640px) {
  .top-bar { justify-content: center; text-align: center; }
  .arena { aspect-ratio: 4 / 5; }
  .npc .avatar { font-size: 2rem; }
  .player-avatar { font-size: 1.8rem; }
}
