:root {
  --bg: #05070d;
  --bg-soft: #0a0f19;
  --line: rgba(90, 160, 210, .16);
  --cyan: #35e0ff;
  --cyan-dim: #1e93a8;
  --violet: #8b7bff;
  --amber: #ffb86b;
  --green: #4dffa8;
  --text: #dce9f5;
  --muted: #7d93a8;
  --glass: rgba(12, 20, 32, .62);
  --radius: 18px;
  --font: "Rajdhani", "Chakra Petch", "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: "JetBrains Mono", "SFMono-Regular", ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  letter-spacing: .01em;
}

/* ---------- fondo ---------- */
.bg-grid {
  position: fixed;
  inset: -20%;
  background-image:
    linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 64px 64px;
  transform: perspective(700px) rotateX(58deg) translateY(18%);
  opacity: .5;
  mask-image: radial-gradient(ellipse at 50% 42%, #000 5%, transparent 72%);
  pointer-events: none;
  animation: drift 32s linear infinite;
}

@keyframes drift {
  to { background-position: 0 640px, 640px 0; }
}

.bg-glow {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(620px 420px at 26% 32%, rgba(53, 224, 255, .11), transparent 70%),
    radial-gradient(520px 420px at 78% 74%, rgba(139, 123, 255, .12), transparent 72%),
    radial-gradient(900px 600px at 50% 120%, rgba(30, 147, 168, .10), transparent 70%);
  pointer-events: none;
}

/* ---------- barra superior ---------- */
.topbar {
  position: relative;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 26px 8px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--cyan);
}

.brand-mark { display: grid; place-items: center; filter: drop-shadow(0 0 10px rgba(53,224,255,.55)); }

.brand-text {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: .34em;
  color: #eaf7ff;
  text-transform: uppercase;
  display: flex;
  flex-direction: column;
  line-height: 1;
}

.brand-text em {
  font-style: normal;
  font-size: 9.5px;
  letter-spacing: .42em;
  color: var(--muted);
  margin-top: 5px;
}

.status-wrap { display: flex; align-items: center; gap: 18px; }

.status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 11px;
  border: 1px solid rgba(77, 255, 168, .28);
  border-radius: 999px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .18em;
  color: var(--green);
  background: rgba(77, 255, 168, .07);
  transition: all .25s ease;
}

.status i {
  width: 6px; height: 6px; border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 8px currentColor;
  animation: blink 2.4s ease-in-out infinite;
}

.status[data-state="listening"] { color: var(--green); border-color: rgba(77,255,168,.55); }
.status[data-state="thinking"] { color: var(--cyan); border-color: rgba(53,224,255,.5); background: rgba(53,224,255,.08); }
.status[data-state="speaking"] { color: var(--violet); border-color: rgba(139,123,255,.5); background: rgba(139,123,255,.09); }
.status[data-state="error"] { color: #ff7d7d; border-color: rgba(255,125,125,.5); background: rgba(255,125,125,.08); }

@keyframes blink { 50% { opacity: .25; } }

.clock {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  letter-spacing: .14em;
}

/* ---------- escenario ---------- */
.stage {
  position: relative;
  z-index: 2;
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(340px, 1fr) minmax(380px, 1.05fr);
  gap: 26px;
  padding: 6px 26px 18px;
}

/* ---------- nucleo ---------- */
.core-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 0;
}

.core {
  position: relative;
  width: min(46vh, 380px);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
}

.ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1px solid rgba(53, 224, 255, .22);
  mask-image: conic-gradient(from 0deg, #000 0 24%, transparent 24% 100%);
  animation: spin 9s linear infinite;
}

.ring-2 { inset: 9%; border-color: rgba(139, 123, 255, .28); animation-duration: 13s; animation-direction: reverse; }
.ring-3 { inset: 19%; border-color: rgba(53, 224, 255, .16); animation-duration: 21s; }

.ring-ticks {
  position: absolute;
  inset: -2%;
  border-radius: 50%;
  background: repeating-conic-gradient(from 0deg, rgba(53,224,255,.5) 0deg .6deg, transparent .6deg 6deg);
  mask-image: radial-gradient(circle, transparent 66%, #000 68%, #000 70%, transparent 72%);
  opacity: .55;
  animation: spin 60s linear infinite;
}

.core[data-state="thinking"] .ring { animation-duration: 2.4s; }
.core[data-state="thinking"] .ring-2 { animation-duration: 3.1s; }
.core[data-state="listening"] .ring { border-color: rgba(77, 255, 168, .5); }
.core[data-state="speaking"] .ring { border-color: rgba(139, 123, 255, .45); }

@keyframes spin { to { transform: rotate(360deg); } }

#wave {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.orb {
  position: relative;
  width: 44%;
  aspect-ratio: 1;
  border-radius: 50%;
  background:
    radial-gradient(circle at 34% 28%, rgba(255,255,255,.95), rgba(53,224,255,.75) 26%, rgba(43,120,190,.55) 55%, rgba(20,30,60,.9) 78%);
  box-shadow:
    0 0 34px rgba(53, 224, 255, .5),
    0 0 90px rgba(53, 224, 255, .22),
    inset 0 0 34px rgba(10, 30, 60, .8);
  animation: breathe 5.2s ease-in-out infinite;
  transition: box-shadow .4s ease, transform .4s ease;
}

.orb-inner {
  position: absolute;
  inset: 26%;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 34%, #fff, rgba(139, 123, 255, .5) 60%, transparent 72%);
  filter: blur(7px);
  opacity: .8;
}

.core[data-state="listening"] .orb { box-shadow: 0 0 42px rgba(77,255,168,.6), 0 0 110px rgba(77,255,168,.25), inset 0 0 30px rgba(6,40,26,.7); }
.core[data-state="thinking"] .orb { animation: breathe 1.2s ease-in-out infinite; }
.core[data-state="speaking"] .orb { box-shadow: 0 0 46px rgba(139,123,255,.65), 0 0 120px rgba(139,123,255,.3), inset 0 0 30px rgba(24,18,60,.75); animation: breathe 2.2s ease-in-out infinite; }

@keyframes breathe {
  50% { transform: scale(1.045); filter: brightness(1.12); }
}

.telemetry {
  display: flex;
  gap: 10px;
  width: min(100%, 430px);
  justify-content: center;
}

.telemetry div {
  flex: 1;
  border: 1px solid rgba(90, 160, 210, .14);
  background: var(--glass);
  border-radius: 12px;
  padding: 8px 10px;
  backdrop-filter: blur(8px);
  min-width: 0;
}

.telemetry span {
  display: block;
  font-family: var(--mono);
  font-size: 8.5px;
  letter-spacing: .2em;
  color: var(--muted);
}

.telemetry b {
  display: block;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--cyan);
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hint {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--muted);
  text-align: center;
  max-width: 34ch;
  line-height: 1.45;
}

/* ---------- consola ---------- */
.console {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border: 1px solid rgba(90, 160, 210, .16);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(14, 23, 37, .82), rgba(7, 11, 19, .9));
  backdrop-filter: blur(14px);
  box-shadow: 0 24px 60px rgba(0, 0, 0, .45), inset 0 1px 0 rgba(255, 255, 255, .04);
  overflow: hidden;
}

.console-head {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(90, 160, 210, .12);
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: .22em;
  color: var(--muted);
}

.console-head .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 8px var(--cyan);
}

.ghost {
  margin-left: auto;
  background: none;
  border: 1px solid rgba(90, 160, 210, .2);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: .16em;
  padding: 4px 9px;
  border-radius: 7px;
  cursor: pointer;
  transition: .2s;
  text-transform: uppercase;
}

.ghost:hover { color: var(--cyan); border-color: rgba(53, 224, 255, .45); }

.log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 18px 18px 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scrollbar-width: thin;
  scrollbar-color: rgba(53, 224, 255, .25) transparent;
}

.log::-webkit-scrollbar { width: 6px; }
.log::-webkit-scrollbar-thumb { background: rgba(53, 224, 255, .22); border-radius: 3px; }

.msg { display: flex; gap: 10px; animation: rise .35s ease both; }

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
}

.msg .tag {
  flex: 0 0 auto;
  font-family: var(--mono);
  font-size: 8.5px;
  letter-spacing: .16em;
  color: var(--muted);
  padding-top: 6px;
  width: 46px;
  text-align: right;
}

.msg-body {
  border-radius: 14px;
  padding: 10px 14px;
  line-height: 1.55;
  font-size: 15px;
  max-width: 62ch;
}

.msg.jarvis .msg-body {
  background: linear-gradient(180deg, rgba(53, 224, 255, .09), rgba(53, 224, 255, .03));
  border: 1px solid rgba(53, 224, 255, .18);
  color: #e6f6ff;
}

.msg.user { flex-direction: row-reverse; }

.msg.user .msg-body {
  background: linear-gradient(180deg, rgba(139, 123, 255, .16), rgba(139, 123, 255, .07));
  border: 1px solid rgba(139, 123, 255, .26);
}

.msg.user .tag { text-align: left; }

.msg-body p { margin: 0; white-space: pre-wrap; }
.msg-body p + p { margin-top: 8px; }

.msg-body.streaming::after {
  content: "";
  display: inline-block;
  width: 8px;
  height: 15px;
  margin-left: 3px;
  vertical-align: -2px;
  background: var(--cyan);
  animation: caret .9s steps(1) infinite;
}

@keyframes caret { 50% { opacity: 0; } }

.thinking-dots { display: inline-flex; gap: 5px; padding: 3px 0; }
.thinking-dots i {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--cyan);
  opacity: .35;
  animation: dot 1.3s ease-in-out infinite;
}
.thinking-dots i:nth-child(2) { animation-delay: .18s; }
.thinking-dots i:nth-child(3) { animation-delay: .36s; }

@keyframes dot { 50% { opacity: 1; transform: translateY(-3px); } }

.chips {
  display: flex;
  gap: 8px;
  padding: 10px 16px 14px;
  overflow-x: auto;
  scrollbar-width: none;
}

.chips::-webkit-scrollbar { display: none; }

.chips button {
  white-space: nowrap;
  font-family: var(--font);
  font-size: 12.5px;
  color: #b9d6e8;
  background: rgba(53, 224, 255, .05);
  border: 1px solid rgba(53, 224, 255, .18);
  border-radius: 999px;
  padding: 7px 13px;
  cursor: pointer;
  transition: .2s;
}

.chips button:hover {
  color: #eaf9ff;
  border-color: rgba(53, 224, 255, .5);
  background: rgba(53, 224, 255, .12);
  box-shadow: 0 0 18px rgba(53, 224, 255, .18);
}

/* ---------- compositor ---------- */
.composer {
  position: relative;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 26px 20px;
}

.mic, .send, .stop {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 50%;
  cursor: pointer;
  transition: .2s;
}

.mic {
  width: 50px;
  height: 50px;
  border: 1px solid rgba(53, 224, 255, .3);
  background: rgba(53, 224, 255, .07);
  color: var(--cyan);
}

.mic:hover { border-color: rgba(53, 224, 255, .7); box-shadow: 0 0 22px rgba(53, 224, 255, .3); }

.mic.active {
  color: #04120c;
  background: var(--green);
  border-color: var(--green);
  box-shadow: 0 0 26px rgba(77, 255, 168, .6);
  animation: pulse 1.4s ease-in-out infinite;
}

.mic[disabled] { opacity: .32; cursor: not-allowed; }

@keyframes pulse {
  50% { box-shadow: 0 0 6px rgba(77, 255, 168, .35); }
}

.input-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 5px 5px 18px;
  border: 1px solid rgba(90, 160, 210, .22);
  border-radius: 999px;
  background: var(--glass);
  backdrop-filter: blur(12px);
  transition: border-color .2s, box-shadow .2s;
}

.input-wrap:focus-within {
  border-color: rgba(53, 224, 255, .55);
  box-shadow: 0 0 0 3px rgba(53, 224, 255, .08), 0 0 26px rgba(53, 224, 255, .12);
}

#input {
  flex: 1;
  min-width: 0;
  background: none;
  border: 0;
  outline: none;
  color: var(--text);
  font-family: var(--font);
  font-size: 15.5px;
  letter-spacing: .01em;
  padding: 11px 0;
}

#input::placeholder { color: #5e7488; }

.send {
  width: 40px;
  height: 40px;
  border: 0;
  color: #04121a;
  background: linear-gradient(180deg, #7ff0ff, var(--cyan));
  box-shadow: 0 6px 18px rgba(53, 224, 255, .3);
}

.send:hover { filter: brightness(1.08); }
.send[disabled] { opacity: .4; cursor: not-allowed; box-shadow: none; }

.stop {
  width: auto;
  height: 44px;
  padding: 0 16px;
  border-radius: 999px;
  border: 1px solid rgba(255, 125, 125, .4);
  background: rgba(255, 125, 125, .1);
  color: #ff9d9d;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .18em;
  text-transform: uppercase;
}

/* ---------- adaptacion ---------- */
@media (max-width: 940px) {
  body { overflow: auto; }
  .stage {
    grid-template-columns: 1fr;
    gap: 14px;
    padding-bottom: 8px;
  }
  .core { width: min(46vh, 260px); }
  .console { min-height: 340px; }
  .hint { max-width: 30ch; }
  .topbar { padding: 12px 16px 4px; }
  .composer { padding: 8px 14px 16px; }
  .clock { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .bg-grid, .ring, .ring-ticks, .orb { animation: none !important; }
}

/* sin contexto seguro (HTTP): el microfono del navegador no esta disponible */
.mic-blocked-note {
  display: inline-block;
  margin-top: 4px;
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: .12em;
  color: var(--amber);
}
