/* ============================================================
   JARVIS v4.0 — Iron Man MCU HUD Stylesheet
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700;900&family=Share+Tech+Mono&family=Rajdhani:wght@500;600;700&display=swap');

:root {
  --cyan:       #00d4ff;
  --cyan-dim:   #00aacc;
  --cyan-glow:  rgba(0, 212, 255, 0.2);
  --red:        #ff2d2d;
  --red-dim:    #aa1111;
  --gold:       #f5a623;
  --bg:         #020810;
  --bg-panel:   rgba(0, 20, 40, 0.88);
  --text:       #ffffff;
  --text-dim:   #7ab8d4;
  --border:     rgba(0, 212, 255, 0.35);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Share Tech Mono', monospace;
  min-height: 100vh;
  overflow: hidden;
  position: relative;
}

/* Scan line overlay */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 0, 0, 0.15) 2px,
    rgba(0, 0, 0, 0.15) 4px
  );
  pointer-events: none;
  z-index: 1000;
}

/* Radial background glow */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse at 50% 50%, rgba(0, 60, 100, 0.4) 0%, transparent 70%);
  pointer-events: none;
}

/* ── Canvas (arc reactor) ───────────────────────────────── */
#reactor-canvas {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  opacity: 0.72;
  pointer-events: none;
  z-index: 0;
}

/* ── HUD corner brackets ────────────────────────────────── */
.hud-corner {
  position: fixed;
  width: 60px;
  height: 60px;
  z-index: 10;
  opacity: 0.7;
}
.hud-corner::before,
.hud-corner::after {
  content: '';
  position: absolute;
  background: var(--cyan);
}
.hud-corner::before { width: 100%; height: 2px; }
.hud-corner::after  { width: 2px; height: 100%; }

.hud-corner.tl { top: 16px; left: 16px; }
.hud-corner.tr { top: 16px; right: 16px; transform: scaleX(-1); }
.hud-corner.bl { bottom: 16px; left: 16px; transform: scaleY(-1); }
.hud-corner.br { bottom: 16px; right: 16px; transform: scale(-1); }

/* ── Top status bar ─────────────────────────────────────── */
#top-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 80px;
  background: linear-gradient(180deg, rgba(0,212,255,0.08) 0%, transparent 100%);
  border-bottom: 1px solid var(--border);
  z-index: 20;
}

.top-bar-title {
  font-family: 'Orbitron', sans-serif;
  font-weight: 900;
  font-size: 14px;
  letter-spacing: 6px;
  color: var(--cyan);
  text-shadow: 0 0 20px var(--cyan);
}

.top-bar-stats {
  display: flex;
  gap: 32px;
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 2px;
}

.stat-item span { color: var(--cyan); margin-left: 6px; }

/* ── Bottom status bar ──────────────────────────────────── */
#bottom-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 80px;
  background: linear-gradient(0deg, rgba(0,212,255,0.08) 0%, transparent 100%);
  border-top: 1px solid var(--border);
  z-index: 20;
  font-size: 10px;
  color: var(--text-dim);
  letter-spacing: 2px;
}

.status-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 6px var(--cyan);
  margin-right: 8px;
  animation: pulse-dot 2s infinite;
}
.status-dot.offline { background: var(--red); box-shadow: 0 0 6px var(--red); }

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

/* ── Side panels ────────────────────────────────────────── */
.side-panel {
  position: fixed;
  top: 80px;
  bottom: 60px;
  width: 220px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px;
}
.side-panel.left  { left: 0; }
.side-panel.right { right: 0; }

.panel-block {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  padding: 12px;
  position: relative;
}
.panel-block::before {
  content: attr(data-label);
  position: absolute;
  top: -8px;
  left: 10px;
  background: var(--bg);
  padding: 0 6px;
  font-size: 9px;
  letter-spacing: 3px;
  color: var(--cyan-dim);
}

.panel-block h3 {
  font-family: 'Orbitron', sans-serif;
  font-size: 9px;
  letter-spacing: 3px;
  color: var(--cyan-dim);
  margin-bottom: 10px;
  text-transform: uppercase;
}

.bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 10px;
  color: var(--text-dim);
}
.bar-row span:first-child { width: 30px; }
.bar-track {
  flex: 1;
  height: 3px;
  background: rgba(0,212,255,0.1);
  border: 1px solid var(--border);
}
.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--cyan-dim), var(--cyan));
  box-shadow: 0 0 4px var(--cyan);
  transition: width 1s ease;
}
.bar-fill.hot { background: linear-gradient(90deg, var(--red-dim), var(--red)); box-shadow: 0 0 4px var(--red); }

.phase-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 10px;
  margin-bottom: 6px;
  color: var(--text-dim);
}
.phase-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  border: 1px solid var(--text-dim);
  flex-shrink: 0;
}
.phase-dot.active { background: var(--cyan); border-color: var(--cyan); box-shadow: 0 0 6px var(--cyan); }
.phase-dot.done   { background: var(--gold); border-color: var(--gold); }

/* ── Main chat area ─────────────────────────────────────── */
#main {
  position: fixed;
  top: 48px;
  bottom: 40px;
  left: 220px;
  right: 220px;
  display: flex;
  flex-direction: column;
  z-index: 10;
  padding: 16px;
}

#chat-window {
  flex: 1;
  overflow-y: auto;
  padding: 12px 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scrollbar-width: thin;
  scrollbar-color: var(--cyan-dim) transparent;
}
#chat-window::-webkit-scrollbar { width: 4px; }
#chat-window::-webkit-scrollbar-thumb { background: var(--cyan-dim); }

/* Message bubbles */
.message {
  max-width: 85%;
  animation: msg-in 0.3s ease;
}
@keyframes msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.message.user  { align-self: flex-end; }
.message.jarvis { align-self: flex-start; }
.message.system { align-self: center; max-width: 100%; }

.message-label {
  font-size: 9px;
  letter-spacing: 3px;
  margin-bottom: 4px;
  color: var(--text-dim);
}
.message.user .message-label  { text-align: right; color: var(--gold); }
.message.jarvis .message-label { color: var(--cyan-dim); }

.message-body {
  padding: 12px 16px;
  border: 1px solid;
  line-height: 1.7;
  font-size: 15px;
  font-family: 'Rajdhani', sans-serif;
  font-weight: 600;
  position: relative;
}
.message.user .message-body {
  border-color: rgba(245,166,35,0.5);
  background: rgba(245,166,35,0.08);
  color: #ffd080;
}
.message.jarvis .message-body {
  border-color: var(--border);
  background: var(--bg-panel);
  color: #ffffff;
  text-shadow: 0 0 8px rgba(0, 212, 255, 0.15);
}
.message.system .message-body {
  border-color: rgba(0,212,255,0.2);
  background: rgba(0,212,255,0.05);
  color: var(--cyan-dim);
  font-size: 11px;
  letter-spacing: 1px;
  text-align: center;
}

/* Thinking indicator */
#thinking {
  align-self: flex-start;
  display: none;
  padding: 10px 16px;
  border: 1px solid var(--border);
  background: var(--bg-panel);
  color: var(--cyan-dim);
  font-size: 11px;
  letter-spacing: 2px;
}
#thinking.visible { display: flex; gap: 6px; align-items: center; }

.think-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--cyan);
  animation: think-bounce 1.2s infinite;
}
.think-dot:nth-child(2) { animation-delay: 0.2s; }
.think-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes think-bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40%           { transform: scale(1);   opacity: 1; }
}

/* ── Input area ─────────────────────────────────────────── */
#input-area {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 12px 0 0;
  border-top: 1px solid var(--border);
}

#msg-input {
  flex: 1;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: 'Share Tech Mono', monospace;
  font-size: 13px;
  padding: 12px 16px;
  outline: none;
  transition: border-color 0.2s;
  letter-spacing: 0.5px;
}
#msg-input:focus { border-color: var(--cyan); box-shadow: 0 0 12px var(--cyan-glow); }
#msg-input::placeholder { color: var(--text-dim); letter-spacing: 1px; }

.hud-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--cyan);
  font-family: 'Orbitron', sans-serif;
  font-size: 10px;
  letter-spacing: 2px;
  padding: 12px 18px;
  cursor: pointer;
  transition: all 0.2s;
  text-transform: uppercase;
}
.hud-btn:hover {
  background: var(--cyan-glow);
  border-color: var(--cyan);
  box-shadow: 0 0 12px var(--cyan-glow);
}
.hud-btn:active { transform: scale(0.97); }

.hud-btn.voice {
  border-color: var(--cyan-dim);
  color: var(--cyan);
  opacity: 1;
  cursor: pointer;
  font-size: 16px;
  padding: 12px 14px;
  transition: all 0.2s;
  position: relative;
}
.hud-btn.voice:hover {
  background: var(--cyan-glow);
  border-color: var(--cyan);
  box-shadow: 0 0 16px var(--cyan-glow);
}

/* Recording state — red pulsing glow */
.hud-btn.voice.recording {
  border-color: var(--red);
  color: var(--red);
  box-shadow: 0 0 16px rgba(255,45,45,0.6), 0 0 32px rgba(255,45,45,0.2);
  animation: voice-recording-pulse 1s infinite;
  cursor: pointer;
}
@keyframes voice-recording-pulse {
  0%, 100% { box-shadow: 0 0 10px rgba(255,45,45,0.5), 0 0 20px rgba(255,45,45,0.2); }
  50%       { box-shadow: 0 0 22px rgba(255,45,45,0.9), 0 0 44px rgba(255,45,45,0.4); }
}

/* Transcribing state — cyan spinner */
.hud-btn.voice.transcribing {
  border-color: var(--cyan);
  color: var(--cyan);
  box-shadow: 0 0 12px var(--cyan-glow);
  animation: voice-transcribing-spin 1.2s linear infinite;
  cursor: not-allowed;
}
@keyframes voice-transcribing-spin {
  0%   { box-shadow: 0 0 12px var(--cyan-glow), 2px 0 8px var(--cyan-glow); }
  25%  { box-shadow: 0 0 12px var(--cyan-glow), 0 2px 8px var(--cyan-glow); }
  50%  { box-shadow: 0 0 12px var(--cyan-glow), -2px 0 8px var(--cyan-glow); }
  75%  { box-shadow: 0 0 12px var(--cyan-glow), 0 -2px 8px var(--cyan-glow); }
  100% { box-shadow: 0 0 12px var(--cyan-glow), 2px 0 8px var(--cyan-glow); }
}

/* Speaking state — gold pulse */
.hud-btn.voice.speaking {
  border-color: var(--gold);
  color: var(--gold);
  box-shadow: 0 0 14px rgba(245,166,35,0.5), 0 0 28px rgba(245,166,35,0.2);
  animation: voice-speaking-pulse 1.8s ease-in-out infinite;
  cursor: not-allowed;
}
@keyframes voice-speaking-pulse {
  0%, 100% { box-shadow: 0 0 10px rgba(245,166,35,0.4), 0 0 20px rgba(245,166,35,0.15); }
  50%       { box-shadow: 0 0 20px rgba(245,166,35,0.7), 0 0 40px rgba(245,166,35,0.3); }
}

/* ── Voice status bar ───────────────────────────────────── */
#voice-status {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 6px 14px;
  border: 1px solid var(--border);
  background: var(--bg-panel);
  font-size: 10px;
  letter-spacing: 2px;
  color: var(--cyan-dim);
  margin-bottom: 8px;
  position: relative;
}
#voice-status.visible { display: flex; }

#voice-status.state-recording {
  border-color: rgba(255,45,45,0.5);
  color: var(--red);
}
#voice-status.state-transcribing {
  border-color: var(--border);
  color: var(--cyan-dim);
}
#voice-status.state-speaking {
  border-color: rgba(245,166,35,0.4);
  color: var(--gold);
}

.voice-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 6px currentColor;
  flex-shrink: 0;
}
.voice-status-dot.blinking { animation: voice-dot-blink 0.8s infinite; }
@keyframes voice-dot-blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.1; }
}

/* ── Waveform visualizer ────────────────────────────────── */
#waveform-canvas {
  display: none;
  height: 28px;
  flex: 1;
  opacity: 0.85;
}
#voice-status.state-recording #waveform-canvas { display: block; }

/* ── Mic permission error toast ─────────────────────────── */
#mic-error {
  display: none;
  position: fixed;
  bottom: 56px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255,45,45,0.12);
  border: 1px solid var(--red);
  color: var(--red);
  padding: 10px 24px;
  font-size: 11px;
  letter-spacing: 2px;
  z-index: 50;
  animation: msg-in 0.3s ease;
}
#mic-error.visible { display: block; }


/* ── Always-on listening toggle ─────────────────────────── */
.hud-btn.always-on {
  border-color: var(--cyan-dim);
  color: var(--text-dim);
  font-size: 9px;
  letter-spacing: 1.5px;
  padding: 12px 10px;
  white-space: nowrap;
  min-width: 90px;
  transition: all 0.25s;
}
.hud-btn.always-on:hover {
  background: var(--cyan-glow);
  border-color: var(--cyan);
  color: var(--cyan);
  box-shadow: 0 0 12px var(--cyan-glow);
}

/* Passive mode — cyan idle */
.hud-btn.always-on.passive {
  border-color: var(--cyan);
  color: var(--cyan);
  box-shadow: 0 0 8px var(--cyan-glow);
  animation: passive-breathe 3s ease-in-out infinite;
}
@keyframes passive-breathe {
  0%, 100% { box-shadow: 0 0 6px var(--cyan-glow); }
  50%       { box-shadow: 0 0 16px rgba(0, 212, 255, 0.4); }
}

/* Wake detected — gold burst */
.hud-btn.always-on.wake-detected {
  border-color: var(--gold);
  color: var(--gold);
  box-shadow: 0 0 18px rgba(245,166,35,0.6), 0 0 36px rgba(245,166,35,0.25);
  animation: wake-detected-flash 0.4s ease-in-out 3;
}
@keyframes wake-detected-flash {
  0%, 100% { box-shadow: 0 0 10px rgba(245,166,35,0.4); }
  50%       { box-shadow: 0 0 28px rgba(245,166,35,0.9), 0 0 56px rgba(245,166,35,0.4); }
}

/* Active query capture — bright cyan */
.hud-btn.always-on.active-query {
  border-color: #00ffff;
  color: #00ffff;
  box-shadow: 0 0 20px rgba(0, 255, 255, 0.7), 0 0 40px rgba(0, 255, 255, 0.3);
  animation: active-query-pulse 0.7s ease-in-out infinite;
}
@keyframes active-query-pulse {
  0%, 100% { box-shadow: 0 0 14px rgba(0, 255, 255, 0.5), 0 0 28px rgba(0, 255, 255, 0.2); }
  50%       { box-shadow: 0 0 28px rgba(0, 255, 255, 1.0), 0 0 56px rgba(0, 255, 255, 0.5); }
}

/* ── Wake word voice status extensions ──────────────────── */
#voice-status.state-passive {
  border-color: var(--cyan-dim);
  color: var(--cyan-dim);
}
#voice-status.state-wake-detected {
  border-color: rgba(245,166,35,0.6);
  color: var(--gold);
}
#voice-status.state-active-query {
  border-color: rgba(0, 255, 255, 0.7);
  color: #00ffff;
}

/* ── Wake confirmation toast ─────────────────────────────── */
#wake-toast {
  display: none;
  position: fixed;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(245,166,35,0.12);
  border: 1px solid var(--gold);
  color: var(--gold);
  padding: 8px 28px;
  font-family: 'Orbitron', sans-serif;
  font-size: 11px;
  letter-spacing: 3px;
  z-index: 50;
  animation: msg-in 0.25s ease;
}
#wake-toast.visible { display: block; }

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 1100px) {
  .side-panel { display: none; }
  #main { left: 16px; right: 16px; }
}
