/* Jarvis web client — dark, sci-fi minimal. Mobile-first. */

:root {
  --bg: #04070d;
  --bg-2: #0a1220;
  --panel: rgba(13, 22, 38, 0.72);
  --line: rgba(80, 170, 230, 0.14);
  --cyan: #3fd8ff;
  --cyan-soft: rgba(63, 216, 255, 0.55);
  --cyan-faint: rgba(63, 216, 255, 0.12);
  --text: #dce9f4;
  --muted: #6f8598;
  --danger: #ff5470;
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

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

html, body { height: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.hidden { display: none !important; }

/* ---------- ambient background ---------- */
#aurora {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(60% 45% at 50% -8%, rgba(38, 120, 180, 0.22), transparent 70%),
    radial-gradient(45% 35% at 85% 105%, rgba(30, 90, 150, 0.16), transparent 70%),
    radial-gradient(35% 30% at 8% 90%, rgba(63, 216, 255, 0.07), transparent 70%),
    var(--bg);
}

/* ---------- screens ---------- */
.screen {
  position: fixed;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

/* ---------- setup ---------- */
#setup { align-items: center; justify-content: center; padding: 24px; }

.setup-card {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 14px;
  padding: 36px 28px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 22px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
}

.setup-card .logo { color: var(--cyan); filter: drop-shadow(0 0 14px rgba(63, 216, 255, 0.45)); }

.ring-spin {
  transform-origin: 60px 60px;
  stroke-dasharray: 42 197;
  animation: spin 6s linear infinite;
}

.setup-card h1 {
  font-size: 26px;
  font-weight: 600;
  letter-spacing: 0.42em;
  text-indent: 0.42em;
}

.setup-card .sub { color: var(--muted); font-size: 14px; }

#setup-form { width: 100%; display: flex; flex-direction: column; gap: 12px; margin-top: 6px; }

#token-input {
  width: 100%;
  padding: 13px 16px;
  font-size: 16px;
  font-family: var(--font);
  color: var(--text);
  background: rgba(4, 10, 18, 0.8);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: none;
  text-align: center;
  letter-spacing: 0.06em;
  transition: border-color 0.2s, box-shadow 0.2s;
}

#token-input:focus {
  border-color: var(--cyan-soft);
  box-shadow: 0 0 0 3px var(--cyan-faint);
}

#connect-btn {
  padding: 13px 16px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-family: var(--font);
  color: #04121a;
  background: linear-gradient(180deg, #5fe2ff, #2bb8e0);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  box-shadow: 0 6px 24px rgba(63, 216, 255, 0.28);
  transition: transform 0.12s, opacity 0.2s;
}

#connect-btn:active { transform: scale(0.97); }
#connect-btn:disabled { opacity: 0.55; cursor: default; }

.setup-msg { min-height: 1.2em; font-size: 13px; color: var(--muted); }

.ghost {
  background: none;
  border: 1px solid var(--line);
  color: var(--muted);
  font-family: var(--font);
  font-size: 13px;
  padding: 8px 18px;
  border-radius: 999px;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}

.ghost:hover { color: var(--text); border-color: var(--cyan-soft); }

/* ---------- header ---------- */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  border-bottom: 1px solid var(--line);
  background: rgba(4, 7, 13, 0.6);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.35em;
}

.brand .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 10px var(--cyan);
  animation: breathe 3.2s ease-in-out infinite;
}

.actions { display: flex; align-items: center; gap: 8px; }

.actions button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  font-family: var(--font);
  font-size: 12px;
  color: var(--muted);
  background: rgba(13, 22, 38, 0.55);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s, background 0.2s, box-shadow 0.2s;
}

.actions button:hover { color: var(--text); border-color: var(--cyan-soft); }

#handsfree-btn.active {
  color: var(--cyan);
  border-color: var(--cyan-soft);
  background: var(--cyan-faint);
  box-shadow: 0 0 14px rgba(63, 216, 255, 0.22);
}

@media (max-width: 420px) {
  #handsfree-btn span { display: none; }
}

/* ---------- transcript ---------- */
#transcript {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 18px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

#empty-hint {
  margin: auto;
  text-align: center;
  color: var(--text);
  font-size: 17px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  opacity: 0.85;
}

#empty-hint .dim { color: var(--muted); font-size: 13px; }

.msg { display: flex; flex-direction: column; gap: 4px; max-width: 86%; }
.msg.you { align-self: flex-end; align-items: flex-end; }
.msg.jarvis { align-self: flex-start; align-items: flex-start; }

.msg .meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0 4px;
}

.msg.jarvis .meta { color: var(--cyan-soft); }

.msg .chip {
  font-size: 9.5px;
  letter-spacing: 0.08em;
  padding: 2px 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(13, 22, 38, 0.6);
}

.msg .bubble {
  padding: 11px 14px;
  font-size: 15px;
  line-height: 1.45;
  border-radius: 16px;
  white-space: pre-wrap;
  word-break: break-word;
  animation: rise 0.25s ease-out;
}

.msg.you .bubble {
  background: linear-gradient(180deg, rgba(46, 84, 120, 0.55), rgba(34, 62, 92, 0.55));
  border: 1px solid rgba(120, 190, 240, 0.18);
  border-bottom-right-radius: 5px;
}

.msg.jarvis .bubble {
  background: var(--panel);
  border: 1px solid var(--line);
  border-bottom-left-radius: 5px;
  box-shadow: 0 0 24px rgba(63, 216, 255, 0.05);
}

/* ---------- mic zone ---------- */
.mic-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 10px 16px 16px;
}

#status {
  font-size: 12px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--muted);
  min-height: 1.2em;
  transition: color 0.25s;
}

body[data-state="listening"] #status { color: var(--cyan); text-shadow: 0 0 12px rgba(63, 216, 255, 0.5); }
body[data-state="speaking"] #status { color: var(--cyan-soft); }

#mic-btn {
  position: relative;
  width: 92px;
  height: 92px;
  border-radius: 50%;
  border: 1px solid rgba(120, 200, 250, 0.28);
  background: radial-gradient(circle at 50% 34%, rgba(40, 80, 118, 0.75), rgba(8, 16, 28, 0.95) 72%);
  color: #bfe4f5;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow:
    0 10px 34px rgba(0, 0, 0, 0.55),
    0 0 calc(14px + 46px * var(--level, 0)) rgba(63, 216, 255, calc(0.12 + 0.5 * var(--level, 0)));
  transition: transform 0.15s, color 0.25s, border-color 0.25s;
}

#mic-btn:active { transform: scale(0.94); }

#mic-btn .halo {
  position: absolute;
  inset: -1px;
  border-radius: 50%;
  pointer-events: none;
}

/* listening: pulsing rings + cyan mic */
body[data-state="listening"] #mic-btn {
  color: var(--cyan);
  border-color: var(--cyan-soft);
}

body[data-state="listening"] #mic-btn .halo::before,
body[data-state="listening"] #mic-btn .halo::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1.5px solid var(--cyan-soft);
  animation: pulse 1.9s ease-out infinite;
}

body[data-state="listening"] #mic-btn .halo::after { animation-delay: 0.95s; }

/* thinking: spinning arc, dimmed mic */
body[data-state="thinking"] #mic-btn { color: rgba(191, 228, 245, 0.35); cursor: default; }

body[data-state="thinking"] #mic-btn .halo::before {
  content: "";
  position: absolute;
  inset: -7px;
  border-radius: 50%;
  border: 2px solid transparent;
  border-top-color: var(--cyan);
  border-right-color: rgba(63, 216, 255, 0.25);
  animation: spin 0.9s linear infinite;
}

/* speaking: hide mic, show bars */
#mic-btn .bars { display: none; align-items: center; gap: 5px; height: 34px; }

#mic-btn .bars i {
  width: 4.5px;
  height: 10px;
  border-radius: 3px;
  background: var(--cyan);
  box-shadow: 0 0 8px rgba(63, 216, 255, 0.6);
  animation: eq 1s ease-in-out infinite;
}

#mic-btn .bars i:nth-child(1) { animation-delay: 0s; }
#mic-btn .bars i:nth-child(2) { animation-delay: 0.18s; }
#mic-btn .bars i:nth-child(3) { animation-delay: 0.34s; }
#mic-btn .bars i:nth-child(4) { animation-delay: 0.12s; }
#mic-btn .bars i:nth-child(5) { animation-delay: 0.26s; }

body[data-state="speaking"] #mic-btn { border-color: var(--cyan-soft); }
body[data-state="speaking"] #mic-btn .icon-mic { display: none; }
body[data-state="speaking"] #mic-btn .bars { display: flex; }

/* ---------- text input ---------- */
#text-form {
  display: flex;
  gap: 10px;
  padding: 0 16px calc(14px + env(safe-area-inset-bottom));
}

#text-input {
  flex: 1;
  min-width: 0;
  padding: 12px 16px;
  font-size: 16px;
  font-family: var(--font);
  color: var(--text);
  background: rgba(10, 18, 32, 0.85);
  border: 1px solid var(--line);
  border-radius: 999px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

#text-input:focus {
  border-color: var(--cyan-soft);
  box-shadow: 0 0 0 3px var(--cyan-faint);
}

#text-input::placeholder { color: rgba(111, 133, 152, 0.7); }

#send-btn {
  flex: 0 0 auto;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(13, 22, 38, 0.8);
  color: var(--cyan);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.12s;
}

#send-btn:hover { border-color: var(--cyan-soft); box-shadow: 0 0 14px rgba(63, 216, 255, 0.2); }
#send-btn:active { transform: scale(0.93); }

/* ---------- toasts ---------- */
#toasts {
  position: fixed;
  left: 50%;
  bottom: calc(160px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  width: max-content;
  max-width: 88vw;
}

.toast {
  padding: 10px 18px;
  font-size: 13px;
  color: var(--text);
  background: rgba(16, 26, 44, 0.92);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.3s, transform 0.3s;
  max-width: 88vw;
  text-align: center;
}

.toast.show { opacity: 1; transform: translateY(0); }

/* ---------- desktop ---------- */
@media (min-width: 760px) {
  #app {
    max-width: 720px;
    left: 50%;
    transform: translateX(-50%);
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
    background: rgba(4, 7, 13, 0.35);
  }
  #mic-btn { width: 104px; height: 104px; }
}

/* ---------- animations ---------- */
@keyframes pulse {
  0%   { transform: scale(1); opacity: 0.9; }
  100% { transform: scale(1.65); opacity: 0; }
}

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

@keyframes eq {
  0%, 100% { height: 8px; }
  50%      { height: 30px; }
}

@keyframes breathe {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.35; }
}

@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}
