/* ============================================================================
   JARVIS HUD — negro / rojo
   ========================================================================== */
:root {
  --bg: #07070a;
  --panel: rgba(18, 8, 10, 0.72);
  --panel-border: rgba(255, 40, 60, 0.35);
  --red: #ff2a3c;
  --red-dim: rgba(255, 42, 60, 0.35);
  --red-glow: rgba(255, 42, 60, 0.55);
  --text: #f3e9ea;
  --muted: #a88c90;
  --ok: #4cff9a;
  --font-hud: "Orbitron", "Segoe UI", system-ui, sans-serif;
  --font-mono: "Share Tech Mono", Consolas, "Courier New", monospace;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: radial-gradient(1200px 700px at 70% -10%, #2a0a10 0%, var(--bg) 55%);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 15px;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font-family: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.scanlines {
  pointer-events: none;
  position: fixed; inset: 0; z-index: 0;
  background: repeating-linear-gradient(0deg, rgba(255,255,255,0.025) 0 1px, transparent 1px 3px);
  mix-blend-mode: overlay;
}

/* ---------- Cabecera ---------- */
.hud-header {
  z-index: 2;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + var(--safe-top)) 16px 10px;
  border-bottom: 1px solid var(--panel-border);
  background: linear-gradient(180deg, rgba(20,6,8,0.9), rgba(10,5,6,0.6));
  backdrop-filter: blur(6px);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand h1 {
  margin: 0; font-family: var(--font-hud); font-size: 20px; letter-spacing: 3px;
  color: var(--red); text-shadow: 0 0 12px var(--red-glow);
  white-space: nowrap;
}
.brand-sub { font-size: 10px; letter-spacing: 2px; color: var(--muted); text-transform: uppercase; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-ring {
  width: 34px; height: 34px; border-radius: 50%; flex: 0 0 auto;
  border: 2px solid var(--red);
  box-shadow: 0 0 14px var(--red-glow), inset 0 0 10px var(--red-dim);
  position: relative;
}
.brand-ring::after {
  content: ""; position: absolute; inset: 9px; border-radius: 50%;
  background: var(--red); box-shadow: 0 0 12px var(--red);
  animation: pulse 2.2s ease-in-out infinite;
}
.header-right { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }
.status-pill {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px; border: 1px solid var(--panel-border); border-radius: 999px;
  font-family: var(--font-hud); font-size: 11px; letter-spacing: 2px;
  background: rgba(0,0,0,0.35);
}
.status-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status-pill[data-state="idle"] .dot { background: var(--muted); }
.status-pill[data-state="listening"] .dot { background: var(--ok); box-shadow: 0 0 10px var(--ok); animation: pulse 1s infinite; }
.status-pill[data-state="thinking"] .dot { background: #ffb020; box-shadow: 0 0 10px #ffb020; animation: pulse 0.6s infinite; }
.status-pill[data-state="speaking"] .dot { background: var(--red); box-shadow: 0 0 10px var(--red); animation: pulse 0.5s infinite; }
.status-pill[data-state="error"] .dot { background: var(--red); }
.clock { font-family: var(--font-hud); font-size: 14px; letter-spacing: 2px; color: var(--muted); }
.icon-btn {
  width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--panel-border);
  background: rgba(0,0,0,0.35); color: var(--red); font-size: 18px; line-height: 1;
}
.icon-btn:hover { background: var(--red-dim); }

/* ---------- Cuerpo ---------- */
.hud-main {
  z-index: 1; flex: 1; min-height: 0;
  display: grid; grid-template-columns: 300px 1fr; gap: 12px;
  padding: 12px 16px;
}
.panel {
  min-width: 0;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  backdrop-filter: blur(4px);
  border-radius: 10px;
  position: relative;
  min-height: 0;
}
.panel::before, .panel::after {
  content: ""; position: absolute; width: 14px; height: 14px; border-color: var(--red); border-style: solid;
}
.panel::before { top: 0; left: 0; border-width: 2px 0 0 2px; border-radius: 10px 0 0 0; }
.panel::after { bottom: 0; right: 0; border-width: 0 2px 2px 0; border-radius: 0 0 10px 0; }

.side { display: flex; flex-direction: column; gap: 12px; padding: 14px; overflow: hidden auto; scrollbar-width: thin; scrollbar-color: var(--red-dim) transparent; }
.log { scrollbar-width: thin; scrollbar-color: var(--red-dim) transparent; }
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background: var(--red-dim); border-radius: 3px; }
::-webkit-scrollbar-track { background: transparent; }

/* Reactor arc */
.radar-wrap { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.reactor {
  --rx: var(--red);
  width: 220px; height: 220px; position: relative;
  filter: drop-shadow(0 0 18px rgba(255,42,60,0.35));
  transition: filter .4s;
}
.reactor svg { width: 100%; height: 100%; display: block; overflow: visible; }
.rx-ring { fill: none; stroke: var(--rx); stroke-width: 2.2; }
.rx-ring.dim { stroke-width: 1; opacity: 0.45; }
.rx-tick { stroke: var(--rx); stroke-width: 1.2; opacity: 0.7; }
.rx-tick.big { stroke-width: 2; opacity: 1; }
.rx-coil { fill: rgba(255,42,60,0.16); stroke: var(--rx); stroke-width: 1.8; filter: url(#rxGlow); }
.rx-tri { fill: url(#rxCore); stroke: var(--rx); stroke-width: 3; stroke-linejoin: round; filter: url(#rxGlowBig); }
.rx-tri.inner { fill: #fff3f4; stroke: none; opacity: 0.9; filter: none; }
.rx-outer, .rx-coils, .rx-core { transform-box: fill-box; transform-origin: center; }
.rx-outer { animation: spin 40s linear infinite; }
.rx-coils { animation: spinBack 60s linear infinite; }
.rx-core { animation: corePulseSoft 2.6s ease-in-out infinite; }
.rx-halo { animation: pulse 2.6s ease-in-out infinite; }

.reactor[data-state="thinking"] .rx-outer { animation-duration: 4s; }
.reactor[data-state="thinking"] .rx-coils { animation-duration: 6s; }
.reactor[data-state="thinking"] .rx-core { animation-duration: 0.8s; }
.reactor[data-state="listening"] { --rx: var(--ok); filter: drop-shadow(0 0 18px rgba(76,255,154,0.35)); }
.reactor[data-state="listening"] .rx-coil { fill: rgba(76,255,154,0.16); }
.reactor[data-state="listening"] .rx-outer { animation-duration: 12s; }
.reactor[data-state="speaking"] .rx-core { animation: corePulseHard 0.32s ease-in-out infinite alternate; }
.reactor[data-state="speaking"] .rx-halo { animation-duration: 0.64s; }
.reactor[data-state="speaking"] { filter: drop-shadow(0 0 28px rgba(255,42,60,0.6)); }
.reactor[data-state="error"] { --rx: #ff6a00; }

.voice-viz { display: flex; gap: 3px; align-items: flex-end; height: 26px; }
.voice-viz i { width: 4px; height: 3px; background: var(--red); opacity: 0.35; border-radius: 2px; transition: height .12s; }
.voice-viz.active i { animation: viz 0.7s ease-in-out infinite; opacity: 1; }
.voice-viz i:nth-child(2n) { animation-delay: -0.2s; }
.voice-viz i:nth-child(3n) { animation-delay: -0.4s; }
.voice-viz i:nth-child(5n) { animation-delay: -0.55s; }

/* Sistema */
.sys { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.side > * { min-width: 0; max-width: 100%; }
.hud-main, .hud-header, .hud-footer { min-width: 0; max-width: 100vw; }
.sys-row { display: grid; grid-template-columns: 78px minmax(0, 1fr) 44px; align-items: center; gap: 8px; font-size: 11px; letter-spacing: 1px; color: var(--muted); }
.sys-row em { font-style: normal; text-align: right; color: var(--text); }
.bar { height: 6px; background: rgba(255,255,255,0.06); border: 1px solid var(--panel-border); border-radius: 3px; overflow: hidden; }
.bar b { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #7a0f1a, var(--red)); box-shadow: 0 0 8px var(--red-glow); transition: width .6s ease; }
.sys-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; font-size: 11px; border-top: 1px dashed var(--panel-border); padding-top: 10px; }
.sys-meta div { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.sys-meta span { color: var(--muted); letter-spacing: 1px; font-size: 9px; }
.sys-meta em { font-style: normal; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Registro */
.log-panel { display: flex; flex-direction: column; }
.panel-title {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; border-bottom: 1px solid var(--panel-border);
  font-family: var(--font-hud); font-size: 12px; letter-spacing: 3px; color: var(--red);
}
.mini-btn { background: none; border: 1px solid var(--panel-border); color: var(--muted); font-size: 10px; letter-spacing: 2px; padding: 4px 8px; border-radius: 4px; }
.mini-btn:hover { color: var(--text); border-color: var(--red); }
.log { flex: 1; overflow-y: auto; padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; scroll-behavior: smooth; }
.entry { display: grid; grid-template-columns: 58px 1fr; gap: 10px; animation: fadeIn .25s ease; }
.entry .who { font-size: 10px; letter-spacing: 2px; color: var(--muted); padding-top: 3px; }
.entry .body { white-space: pre-wrap; word-break: break-word; line-height: 1.45; }
.entry.user .who { color: #ffb0b8; }
.entry.jarvis .who { color: var(--red); }
.entry.system .who { color: var(--muted); }
.entry.system .body { color: var(--muted); font-size: 13px; }
.entry.error .body { color: #ff8a94; }
.entry .time { font-size: 10px; color: var(--muted); margin-top: 2px; }
.entry img.shot { max-width: 220px; border: 1px solid var(--panel-border); border-radius: 6px; display: block; margin-bottom: 6px; }
.entry.streaming .body::after { content: "▌"; color: var(--red); animation: pulse .8s infinite; }
.log-empty { color: var(--muted); text-align: center; padding: 30px 10px; font-size: 13px; line-height: 1.6; }

/* ---------- Barra inferior ---------- */
.hud-footer {
  z-index: 2; padding: 8px 16px calc(10px + var(--safe-bottom));
  border-top: 1px solid var(--panel-border);
  background: linear-gradient(0deg, rgba(20,6,8,0.95), rgba(10,5,6,0.7));
  backdrop-filter: blur(6px);
}
.attach { position: relative; display: inline-block; margin-bottom: 8px; }
.attach img { height: 64px; border-radius: 6px; border: 1px solid var(--red); display: block; }
.attach-x { position: absolute; top: -8px; right: -8px; width: 22px; height: 22px; border-radius: 50%; border: none; background: var(--red); color: #000; font-size: 12px; font-weight: bold; }
.input-row { display: flex; align-items: flex-end; gap: 8px; }
#input {
  flex: 1; min-height: 44px; max-height: 140px; resize: none;
  padding: 11px 14px; border-radius: 22px; border: 1px solid var(--panel-border);
  background: rgba(0,0,0,0.45); color: var(--text); outline: none; font-size: 15px; line-height: 1.4;
}
#input:focus { border-color: var(--red); box-shadow: 0 0 0 2px var(--red-dim); }
.round-btn {
  width: 44px; height: 44px; flex: 0 0 auto; border-radius: 50%;
  border: 1px solid var(--panel-border); background: rgba(0,0,0,0.45); color: var(--red);
  display: grid; place-items: center; transition: transform .1s, background .2s;
}
.round-btn svg { width: 22px; height: 22px; fill: currentColor; }
.round-btn:active { transform: scale(0.93); }
.round-btn.send { background: var(--red); color: #000; border-color: var(--red); box-shadow: 0 0 14px var(--red-glow); }
.round-btn.mic.on { background: var(--ok); color: #000; border-color: var(--ok); box-shadow: 0 0 16px var(--ok); animation: pulse 1s infinite; }
.round-btn.mic.armed { border-color: var(--ok); color: var(--ok); }
.round-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.footer-hint { font-size: 11px; color: var(--muted); margin-top: 6px; text-align: center; }

/* ---------- Modales ---------- */
.modal { position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,0.75); display: flex; align-items: center; justify-content: center; padding: 14px; backdrop-filter: blur(4px); }
.modal-box {
  width: min(560px, 100%); max-height: calc(100dvh - 28px); overflow: auto;
  background: #0d0709; border: 1px solid var(--red); border-radius: 12px;
  box-shadow: 0 0 40px rgba(255,42,60,0.25);
}
.modal-title { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-bottom: 1px solid var(--panel-border); font-family: var(--font-hud); letter-spacing: 3px; color: var(--red); font-size: 13px; }
.modal-actions { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 14px; justify-content: flex-end; }
.hud-btn {
  border: 1px solid var(--red); background: var(--red-dim); color: var(--text);
  padding: 10px 14px; border-radius: 6px; font-family: var(--font-hud); font-size: 11px; letter-spacing: 1.5px;
}
.hud-btn.strong { background: var(--red); color: #000; font-weight: 700; }
.hud-btn.ghost { background: transparent; border-color: var(--panel-border); color: var(--muted); }
.hud-btn:hover { filter: brightness(1.15); }

.cam-view { position: relative; background: #000; aspect-ratio: 4 / 3; }
.cam-view video { width: 100%; height: 100%; object-fit: cover; display: block; }
.cam-corner { position: absolute; width: 26px; height: 26px; border: 2px solid var(--red); }
.cam-corner.tl { top: 10px; left: 10px; border-right: 0; border-bottom: 0; }
.cam-corner.tr { top: 10px; right: 10px; border-left: 0; border-bottom: 0; }
.cam-corner.bl { bottom: 10px; left: 10px; border-right: 0; border-top: 0; }
.cam-corner.br { bottom: 10px; right: 10px; border-left: 0; border-top: 0; }

.settings-box { padding-bottom: 6px; }
.set-group { padding: 12px 14px; border-bottom: 1px dashed var(--panel-border); display: flex; flex-direction: column; gap: 10px; }
.set-group h3 { margin: 0 0 2px; font-family: var(--font-hud); font-size: 11px; letter-spacing: 2px; color: var(--red); }
.set-group label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--text); }
.set-group label.row { flex-direction: row; align-items: center; gap: 10px; }
.set-group small { color: var(--muted); font-size: 11px; }
.set-group input[type="text"], .set-group input[type="url"], .set-group input[type="password"], .set-group select {
  padding: 9px 10px; border-radius: 6px; border: 1px solid var(--panel-border); background: rgba(0,0,0,0.5); color: var(--text); font-size: 14px; outline: none;
}
.set-group input:focus, .set-group select:focus { border-color: var(--red); }
.set-group input[type="range"] { width: 100%; accent-color: var(--red); }
.set-group input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--red); }
.set-group output { color: var(--red); margin-left: 6px; }
.set-status { font-size: 12px; color: var(--muted); min-height: 16px; }
.set-status.ok { color: var(--ok); }
.set-status.bad { color: #ff8a94; }
.set-foot { padding: 8px 14px 10px; font-size: 11px; color: var(--muted); text-align: center; }
.settings-box:not(.show-direct) .direct-only { display: none; }
.settings-box.hide-browser .browser-only { display: none; }

.toast {
  position: fixed; left: 50%; bottom: calc(90px + var(--safe-bottom)); transform: translateX(-50%);
  z-index: 30; max-width: min(420px, 92vw);
  background: #14080b; border: 1px solid var(--red); color: var(--text); padding: 12px 14px; border-radius: 10px;
  font-size: 13px; line-height: 1.45; box-shadow: 0 0 24px rgba(255,42,60,0.3);
}
.toast button { margin-top: 8px; }

/* ---------- Animaciones ---------- */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
@keyframes blip { 0%, 15% { opacity: 1; transform: scale(1); } 60%, 100% { opacity: 0; transform: scale(0.4); } }
@keyframes spinBack { to { transform: rotate(-360deg); } }
@keyframes corePulseSoft { 0%, 100% { transform: scale(1); opacity: 1; } 50% { transform: scale(0.94); opacity: 0.85; } }
@keyframes corePulseHard { from { transform: scale(0.9); } to { transform: scale(1.15); } }
@keyframes viz { 0%, 100% { height: 4px; } 50% { height: 26px; } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------- Móvil ---------- */
@media (max-width: 760px) {
  body { font-size: 15px; }
  .hud-header { padding-left: 12px; padding-right: 12px; }
  .brand h1 { font-size: 16px; letter-spacing: 2px; }
  .brand-sub { display: none; }
  .clock { display: none; }
  .hud-main { grid-template-columns: 1fr; grid-template-rows: auto 1fr; gap: 8px; padding: 8px 10px; }
  .side { flex-direction: row; align-items: center; gap: 12px; padding: 10px; overflow: hidden; }
  .reactor { width: 100px; height: 100px; }
  .voice-viz { height: 18px; }
  .voice-viz i { width: 3px; }
  @keyframes viz { 0%, 100% { height: 3px; } 50% { height: 18px; } }
  .sys { flex: 1; gap: 5px; }
  .sys-row { grid-template-columns: 62px 1fr 38px; font-size: 9px; }
  .sys-row:nth-child(n+4) { display: none; }
  .sys-meta { display: none; }
  .hud-footer { padding-left: 10px; padding-right: 10px; }
  .footer-hint { display: none; }
  .entry { grid-template-columns: 1fr; gap: 2px; }
  .entry img.shot { max-width: 100%; }
}
@media (max-width: 400px) {
  .brand h1 { font-size: 14px; letter-spacing: 1px; }
  .status-pill { padding: 5px 9px; font-size: 10px; letter-spacing: 1px; }
}
@media (max-width: 360px) {
  .side { display: none; }
  .hud-main { grid-template-rows: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  .rx-outer, .rx-coils, .rx-core, .rx-halo, .brand-ring::after { animation: none; }
}
