:root {
  --bg-start: #020817;
  --bg-end: #020817;
  --flame-deep: #1f0a0a;
  --flame-outer: #7f1d1d;
  --flame-mid: #fb923c;
  --flame-inner: #fff7ed;
  --flame-size: 56px;
  --spirit-size: 86%;
}

/* Base layout */

body {
  margin: 0;
  height: 100vh;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  color: #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: radial-gradient(circle at top, var(--bg-start), var(--bg-end));
  background-attachment: fixed;
  transition: background 1.2s ease, filter 1.2s ease;
}

/* Mood backgrounds */

body.mood-calm {
  background: radial-gradient(circle at top, #020817, #020817);
  filter: saturate(1);
}

body.mood-reflective {
  background: radial-gradient(circle at top, #020817, #111827);
  filter: saturate(0.9);
}

body.mood-alert {
  background: radial-gradient(circle at top, #160b0b, #020817);
  filter: saturate(1.1);
}

.ember-wrapper {
  position: relative;
  text-align: center;
  z-index: 1;
}

/* Hide main interface until welcome dismissed */

#ember-interface {
  display: none;
}

/* BACKGROUND FLOATING EMBERS */

#particles {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 0;
}

#particles::before,
#particles::after {
  content: "";
  position: absolute;
  width: 3px;
  height: 3px;
  border-radius: 999px;
  background: radial-gradient(circle, rgba(249, 115, 22, 0.9), transparent);
  opacity: 0.8;
  animation: bgSparks 18s linear infinite;
}

#particles::before {
  left: 15%;
  bottom: -40px;
  box-shadow:
    0 40px 0 rgba(249, 115, 22, 0.18),
    18px 110px 0 rgba(248, 250, 252, 0.12),
    -22px 190px 0 rgba(249, 115, 22, 0.16),
    30px 270px 0 rgba(248, 250, 252, 0.08),
    -10px 350px 0 rgba(249, 115, 22, 0.14);
}

#particles::after {
  left: 80%;
  bottom: -40px;
  animation-duration: 22s;
  box-shadow:
    0 60px 0 rgba(248, 250, 252, 0.12),
    -24px 140px 0 rgba(249, 115, 22, 0.18),
    26px 220px 0 rgba(248, 250, 252, 0.1),
    -12px 300px 0 rgba(248, 250, 252, 0.14),
    8px 380px 0 rgba(248, 250, 252, 0.08);
}

@keyframes bgSparks {
  0% {
    transform: translateY(0);
    opacity: 0;
  }
  12% {
    opacity: 0.9;
  }
  80% {
    opacity: 0.8;
  }
  100% {
    transform: translateY(-420px);
    opacity: 0;
  }
}

/* WELCOME SCREEN */

#welcome-screen {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at top, rgba(120, 53, 220, 0.12), transparent),
    radial-gradient(circle at bottom, rgba(15, 23, 42, 0.96), #020817);
  backdrop-filter: blur(14px);
  transition: opacity 0.8s ease, visibility 0.8s ease;
}

#welcome-screen.hidden {
  opacity: 0;
  visibility: hidden;
}

.welcome-inner {
  max-width: 640px;
  padding: 3rem 3.5rem;
  border-radius: 32px;
  background: radial-gradient(circle at top left, rgba(148, 163, 253, 0.06), transparent)
    ,rgba(2, 6, 23, 0.96);
  box-shadow:
    0 18px 90px rgba(15, 23, 42, 0.9),
    0 0 40px rgba(79, 70, 229, 0.18);
  border: 1px solid rgba(148, 163, 253, 0.18);
  text-align: left;
  position: relative;
  overflow: hidden;
}

.welcome-inner::before {
  content: "";
  position: absolute;
  inset: -30%;
  background:
    radial-gradient(circle at 0 0, rgba(56, 189, 248, 0.06), transparent),
    radial-gradient(circle at 100% 0, rgba(79, 70, 229, 0.08), transparent);
  opacity: 0.8;
  mix-blend-mode: screen;
  pointer-events: none;
}

.welcome-inner h1 {
  font-size: 2.4rem;
  margin: 0 0 0.6rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #e5e7eb;
}

.welcome-subtitle {
  font-size: 1rem;
  margin: 0 0 1.4rem;
  color: #9ca3af;
}

.welcome-body {
  font-size: 0.95rem;
  margin: 0 0 0.8rem;
  color: #cbd5f5;
}

/* Username input on welcome screen */
.username-input-wrapper {
  margin-top: 1.5rem;
  text-align: left;
}

.username-label {
  display: block;
  font-size: 0.85rem;
  color: #9ca3af;
  margin-bottom: 0.4rem;
}

.username-input {
  width: 100%;
  padding: 0.65rem 1rem;
  border-radius: 8px;
  border: 1px solid rgba(148, 163, 253, 0.2);
  background: rgba(15, 23, 42, 0.6);
  color: #e2e8f0;
  font-size: 0.95rem;
  font-family: inherit;
  transition: all 0.3s ease;
}

.username-input:focus {
  outline: none;
  border-color: rgba(249, 115, 22, 0.5);
  box-shadow: 0 0 12px rgba(249, 115, 22, 0.2);
}

.username-input::placeholder {
  color: #64748b;
}

#enterEmberBtn {
  margin-top: 1.6rem;
  padding: 0.7rem 1.9rem;
  border-radius: 999px;
  border: none;
  background: linear-gradient(to right, #4f46e5, #f97316);
  color: #f9fafb;
  font-size: 0.95rem;
  cursor: pointer;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  box-shadow:
    0 10px 40px rgba(15, 23, 42, 0.9),
    0 0 24px rgba(249, 115, 22, 0.6);
  transition: all 0.3s ease;
}

#enterEmberBtn:hover {
  transform: translateY(-2px);
  box-shadow:
    0 16px 50px rgba(15, 23, 42, 0.95),
    0 0 32px rgba(249, 115, 22, 0.9);
}

/* FLAME CLUSTER (removed):
   The original ember flame artwork (primary flames, sparks, and secondary flames)
   has been intentionally removed in favor of the central spirit video + clones.
   Keep a compact container for layout and simple state hooks so JS can still
   toggle `.listening` and `.responding` on `#ember` without reintroducing the
   legacy flame visuals.
*/

.flame-cluster {
  display: none; /* legacy container hidden in new layout */
}

/* Minimal ember container used as an anchor for the spirit visuals (background) */
#ember {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(58vmin, 560px);
  height: min(58vmin, 560px);
  z-index: 0;
  transition: transform 0.45s ease, box-shadow 0.45s ease;
  background: transparent;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none; /* keep it in the background */
}

/* Simple state styles used by JS (keeps visual feedback but no flame art) */
#ember.listening {
  box-shadow: 0 18px 60px rgba(79, 70, 229, 0.08), 0 0 120px rgba(249, 115, 22, 0.06);
}

#ember.responding {
  box-shadow: 0 22px 90px rgba(79, 70, 229, 0.1), 0 0 200px rgba(249, 115, 22, 0.08);
}

/* Text + button */

/* Status text for feedback messages */
#status {
  margin-top: 1rem;
  font-size: 0.9rem;
  color: #94a3b8;
  text-align: center;
  min-height: 1.5em;
  transition: color 0.3s ease;
}

.status-text {
  position: relative;
  z-index: 4;
}

/* Warning note in welcome screen */
.welcome-note {
  margin-top: 1.2rem;
  padding: 0.8rem 1rem;
  background: rgba(251, 191, 36, 0.1);
  border: 1px solid rgba(251, 191, 36, 0.3);
  border-radius: 8px;
  font-size: 0.85rem;
  color: #fbbf24;
}

.warning-icon {
  margin-right: 0.4rem;
}

#micBtn {
  background: transparent;
  border: 1px solid #475569;
  color: #e2e8f0;
  padding: 0.5rem 1.4rem;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.95rem;
  transition: all 0.3s ease;
  position: relative;
  z-index: 2;
}

#micBtn:hover:not(:disabled) {
  box-shadow: 0 0 14px rgba(148, 163, 253, 0.35);
}

#micBtn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  box-shadow: none;
}

#micBtn.recording {
  background: rgba(239, 68, 68, 0.15);
  border-color: #ef4444;
  color: #fca5a5;
  box-shadow: 0 0 20px rgba(239, 68, 68, 0.5);
  animation: pulse-red 1.2s ease-in-out infinite;
}

@keyframes pulse-red {
  0%, 100% {
    box-shadow: 0 0 20px rgba(239, 68, 68, 0.5);
  }
  50% {
    box-shadow: 0 0 30px rgba(239, 68, 68, 0.8);
  }
}

/* Voice controls dropdown */
.voice-controls {
  margin-bottom: 1.2rem;
  text-align: center;
  position: relative;
  z-index: 2;
}

.voice-controls label {
  display: inline-block;
  margin-right: 0.6rem;
  color: #cbd5f5;
  font-size: 0.9rem;
}

#voiceSelect {
  background: rgba(51, 65, 85, 0.6);
  border: 1px solid #475569;
  color: #e2e8f0;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.3s ease;
}

#voiceSelect:hover {
  box-shadow: 0 0 10px rgba(148, 163, 253, 0.25);
  border-color: #64748b;
}

#voiceSelect:focus {
  outline: none;
  box-shadow: 0 0 12px rgba(148, 163, 253, 0.4);
  border-color: #94a3b8;
}

#reply {
  margin-top: 1.4rem;
  max-width: 680px;
  font-size: 1rem;
  color: #e6eef8;
  line-height: 1.5;
  position: relative;
  z-index: 4;
  white-space: pre-wrap;
  transform: translateY(110px);
}

/* Aligned transcript display with per-word timing */
#alignedTranscript {
  margin-top: 1.4rem;
  max-width: 680px;
  font-size: 1rem;
  color: #cbd5e1;
  line-height: 1.6;
  position: relative;
  z-index: 4;
  word-wrap: break-word;
  display: none; /* Only show when tokens are available */
  transform: translateY(110px);
}

.token {
  display: inline;
  position: relative;
  padding: 0.1em 0.05em;
  border-radius: 4px;
  transition: all 0.05s ease;
  color: #cbd5e1;
}

.token.active-token {
  color: #fef08a;
  background: rgba(251, 191, 36, 0.15);
  font-weight: 600;
  box-shadow: 
    0 0 12px rgba(251, 191, 36, 0.4),
    inset 0 0 8px rgba(251, 191, 36, 0.1);
  text-shadow: 0 0 8px rgba(251, 191, 36, 0.3);
}

/* Reduced motion: simplify token highlighting */
@media (prefers-reduced-motion: reduce) {
  .token {
    transition: none;
  }
}

/* ------------------ Spirit video + clones (new) ------------------ */

/* Per-state tuning */
#ember {
  --flame-orbit-speed: 12s;
  --flame-scale: 0.85;
}

#ember.listening {
  --flame-orbit-speed: 8s;
  --flame-scale: 1.1;
}

#ember.responding {
  --flame-orbit-speed: 5s;
  --flame-scale: 1.3;
}

.spirit-wrapper {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 0;
  pointer-events: none;
}

.spirit-video {
  width: 84%;
  height: 84%;
  object-fit: cover;
  border-radius: 22% 18% 22% 18% / 60% 60% 40% 40%;
  position: relative;
  z-index: 0;
  box-shadow: none;
  transform-origin: center;
  animation: spiritBreathe 4.2s ease-in-out infinite;
  filter: saturate(1.06) contrast(1.02);
}

.spirit-video.speaking {
  transform: scale(1.025);
  filter: saturate(1.18) contrast(1.05) drop-shadow(0 10px 40px rgba(249,115,22,0.14));
}

.spirit-glow {
  position: absolute;
  z-index: 0;
  width: 220%;
  height: 220%;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: none;
  filter: none;
  mix-blend-mode: screen;
  pointer-events: none;
}

/* Orbiting flames container */
.orbiting-flames-container {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1; /* behind UI but above background particles */
}

/* Orbiting flame video element */
.orbiting-flame {
  position: fixed;
  width: var(--flame-size);
  height: var(--flame-size);
  object-fit: cover;
  border-radius: 50%;
  filter: saturate(1.1) brightness(1.06);
  box-shadow: none;
  pointer-events: none;
  z-index: 1;
}

/* Reply particle burst */
.reply-burst-container {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
}

.reply-burst-particle {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: radial-gradient(circle at 30% 25%, #fff9f0, #ffb86b 45%, #ff6b6b 100%);
  box-shadow: 0 8px 30px rgba(79,70,229,0.12), 0 0 28px rgba(249,115,22,0.12);
  transform: translate(-50%, -50%) scale(0.9);
  opacity: 0.98;
  animation: burstOut 700ms cubic-bezier(.2,.8,.2,1) forwards;
}

@keyframes burstOut {
  0% { transform: translate(-50%, -50%) scale(0.8); opacity: 0.98; }
  60% { opacity: 1; }
  100% { transform: translate(var(--tx), var(--ty)) scale(var(--s, 0.9)); opacity: 0; }
}

/* Reduced motion: simplify/disable heavy animation */
@media (prefers-reduced-motion: reduce) {
  .reply-burst-particle { animation: none !important; opacity: 0.0 !important; }
}

@keyframes spiritBreathe {
  0% { transform: scale(0.995); filter: saturate(1.03); }
  50% { transform: scale(1.02); filter: saturate(1.08); }
  100% { transform: scale(0.995); filter: saturate(1.03); }
}

/* Small responsive tweak */
@media (max-width: 520px) {
  .spirit-video { width: 92%; height: 92%; }
  .spirit-glow { width: 260%; height: 260%; filter: blur(30px); }
}

/* UI overlay and bottom controls */
.ui-overlay {
  position: relative;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.controls-bottom {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 18px;
  z-index: 6;
  pointer-events: none;
}

.controls-bottom .voice-controls {
  position: fixed;
  right: 18px;
  bottom: 18px;
  pointer-events: auto;
  z-index: 7;
}

.controls-bottom #micBtn {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  pointer-events: auto;
  z-index: 7;
}


