:root {
  --bg-color: #07070a;
  --panel-bg: rgba(18, 18, 26, 0.75);
  --panel-border: rgba(255, 255, 255, 0.08);
  --panel-border-hover: rgba(255, 255, 255, 0.16);
  --text-main: #f4f4f5;
  --text-muted: #a1a1aa;
  --text-sub: #71717a;

  /* State Colors */
  --color-idle: #f59e0b;
  --glow-idle: rgba(245, 158, 11, 0.45);
  --color-listening: #10b981;
  --glow-listening: rgba(16, 185, 129, 0.65);
  --color-thinking: #8b5cf6;
  --glow-thinking: rgba(139, 92, 246, 0.65);
  --color-speaking: #f97316;
  --glow-speaking: rgba(249, 115, 22, 0.75);
  --color-error: #ef4444;
  --glow-error: rgba(239, 68, 68, 0.65);

  --current-color: var(--color-idle);
  --current-glow: var(--glow-idle);

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-color);
  color: var(--text-main);
  min-height: 100vh;
  width: 100vw;
  overflow-x: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
}

/* Background grid & glowing gradients */
.app-background {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    radial-gradient(circle at 50% 35%, var(--current-glow) 0%, transparent 60%),
    radial-gradient(ellipse 60% 30% at 50% 0%, rgba(139, 92, 246, 0.08), transparent 70%),
    linear-gradient(rgba(255, 255, 255, 0.02) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.02) 1px, transparent 1px);
  background-size: 100% 100%, 100% 100%, 48px 48px, 48px 48px;
  transition: background-image 0.8s cubic-bezier(0.16, 1, 0.3, 1);
}

.noise-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%noiseFilter)'/%3E%3C/svg%3E");
}

/* Main Layout */
.app-container {
  position: relative;
  z-index: 10;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 1.25rem 1.5rem;
  gap: 1.25rem;
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.25rem;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 1rem;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.5);
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.brand-badge {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.live-beacon {
  position: relative;
  display: flex;
  width: 10px;
  height: 10px;
}

.beacon-ping {
  position: absolute;
  inset: 0;
  border-radius: 9999px;
  background-color: var(--current-color);
  opacity: 0.75;
  animation: ping 2s cubic-bezier(0, 0, 0.2, 1) infinite;
}

.beacon-dot {
  position: relative;
  display: inline-flex;
  border-radius: 9999px;
  width: 10px;
  height: 10px;
  background-color: var(--current-color);
  box-shadow: 0 0 10px var(--current-color);
  transition: background-color 0.4s ease, box-shadow 0.4s ease;
}

@keyframes ping {
  75%, 100% {
    transform: scale(2.2);
    opacity: 0;
  }
}

.brand-title {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #ffffff 40%, #a1a1aa 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.endpoint-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  padding: 0.25rem 0.65rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 9999px;
  color: #d4d4d8;
}

.endpoint-badge .edge-icon {
  color: #f59e0b;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

/* Persona Selector */
.persona-picker-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.persona-select {
  appearance: none;
  background: rgba(24, 24, 32, 0.85);
  border: 1px solid var(--panel-border);
  color: var(--text-main);
  font-size: 0.82rem;
  font-weight: 500;
  padding: 0.45rem 2rem 0.45rem 0.85rem;
  border-radius: 0.6rem;
  cursor: pointer;
  outline: none;
  transition: border-color 0.2s, background-color 0.2s;
}

.persona-select:hover {
  border-color: var(--panel-border-hover);
  background: rgba(30, 30, 40, 0.9);
}

.persona-chevron {
  position: absolute;
  right: 0.65rem;
  pointer-events: none;
  color: var(--text-muted);
  width: 14px;
  height: 14px;
}

.stats-pill {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  padding: 0.4rem 0.7rem;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--panel-border);
  border-radius: 0.5rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.stats-pill strong {
  color: #fff;
  font-weight: 600;
}

/* Main Content Grid */
.main-stage {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 1.25rem;
  flex: 1;
  min-height: 520px;
}

@media (max-width: 960px) {
  .main-stage {
    grid-template-columns: 1fr;
  }
}

/* Left / Orb Stage */
.orb-stage-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 1.25rem;
  padding: 2rem 1.5rem 1.5rem;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  position: relative;
  overflow: hidden;
  box-shadow: 0 20px 50px -20px rgba(0, 0, 0, 0.7);
}

.orb-status-banner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  z-index: 2;
  text-align: center;
}

.state-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 0.35rem 0.85rem;
  border-radius: 9999px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--panel-border);
  color: var(--current-color);
  box-shadow: 0 0 16px -4px var(--current-glow);
  transition: all 0.3s ease;
}

.state-helper-text {
  font-size: 0.85rem;
  color: var(--text-muted);
  min-height: 1.25rem;
}

/* Interactive Aura Orb Container */
.orb-viewport {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 380px;
  height: 340px;
  margin: 1.5rem 0;
  cursor: pointer;
}

.orb-ambient-glow {
  position: absolute;
  width: 280px;
  height: 280px;
  border-radius: 50%;
  background: var(--current-glow);
  filter: blur(60px);
  opacity: 0.75;
  transition: background 0.6s ease, transform 0.2s ease-out;
  pointer-events: none;
}

.orb-acoustic-ring {
  position: absolute;
  width: 240px;
  height: 240px;
  border-radius: 50%;
  border: 1.5px solid var(--current-color);
  opacity: 0;
  pointer-events: none;
  transform: scale(0.9);
}

.orb-viewport.state-listening .orb-acoustic-ring {
  animation: acoustic-ripple 2.2s cubic-bezier(0.2, 0.8, 0.2, 1) infinite;
}

.orb-viewport.state-speaking .orb-acoustic-ring {
  animation: acoustic-ripple 1.4s cubic-bezier(0.1, 0.7, 0.1, 1) infinite;
}

@keyframes acoustic-ripple {
  0% {
    transform: scale(0.9);
    opacity: 0.8;
  }
  100% {
    transform: scale(1.65);
    opacity: 0;
  }
}

.orb-canvas {
  position: relative;
  z-index: 2;
  width: 280px;
  height: 280px;
  border-radius: 50%;
  box-shadow:
    inset 0 0 40px rgba(255, 255, 255, 0.2),
    0 0 50px -10px var(--current-glow);
  transition: box-shadow 0.5s ease;
}

.orb-center-overlay {
  position: absolute;
  z-index: 3;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #fff;
}

.orb-center-icon {
  width: 48px;
  height: 48px;
  opacity: 0.85;
  filter: drop-shadow(0 2px 8px rgba(0,0,0,0.6));
  transition: transform 0.3s ease, opacity 0.3s ease;
}

/* Floating Subtitle / Interim Speech Bubble */
.live-subtitle-container {
  width: 100%;
  min-height: 48px;
  max-width: 540px;
  background: rgba(14, 14, 20, 0.65);
  border: 1px dashed var(--panel-border);
  border-radius: 0.85rem;
  padding: 0.75rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 0.92rem;
  color: #e4e4e7;
  backdrop-filter: blur(12px);
  transition: all 0.2s ease;
}

.live-subtitle-container.active {
  border-style: solid;
  border-color: var(--panel-border-hover);
  background: rgba(20, 20, 28, 0.8);
}

.typing-cursor {
  display: inline-block;
  width: 2px;
  height: 1.1em;
  background: var(--current-color);
  margin-left: 4px;
  vertical-align: middle;
  animation: blink 1s step-end infinite;
}

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

/* Controls Dock (Bottom Bar) */
.controls-dock {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--panel-border);
  z-index: 2;
}

.control-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-main);
  border-radius: 9999px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  outline: none;
  transition: all 0.2s ease;
}

.control-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--panel-border-hover);
  transform: translateY(-1px);
}

.control-btn:active {
  transform: translateY(0);
}

.btn-icon-only {
  width: 48px;
  height: 48px;
  padding: 0;
  border-radius: 50%;
}

.btn-icon-only svg {
  width: 20px;
  height: 20px;
}

/* Mute Button Active state */
.control-btn.muted {
  background: rgba(239, 68, 68, 0.2);
  border-color: rgba(239, 68, 68, 0.4);
  color: #fca5a5;
}

/* Push to Talk Button */
.btn-ptt {
  padding: 0.75rem 1.25rem;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--panel-border);
  color: var(--text-main);
  border-radius: 9999px;
  font-size: 0.88rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  user-select: none;
  touch-action: none;
  transition: all 0.2s ease;
}

.btn-ptt:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: var(--panel-border-hover);
  box-shadow: 0 0 14px rgba(255, 255, 255, 0.1);
  transform: translateY(-1px);
}

.btn-ptt:active {
  transform: translateY(0);
}

.btn-ptt.recording {
  background: linear-gradient(135deg, #ef4444, #b91c1c);
  border-color: #f87171;
  color: #ffffff;
  box-shadow: 0 0 20px rgba(239, 68, 68, 0.65);
  animation: pttPulse 1.2s infinite alternate;
}

@keyframes pttPulse {
  from {
    box-shadow: 0 0 12px rgba(239, 68, 68, 0.5);
    transform: scale(1);
  }
  to {
    box-shadow: 0 0 24px rgba(239, 68, 68, 0.9);
    transform: scale(1.03);
  }
}

/* Call Button */
.btn-call {
  padding: 0.75rem 1.75rem;
  background: linear-gradient(135deg, #10b981, #059669);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 4px 20px -2px rgba(16, 185, 129, 0.45);
}

.btn-call:hover {
  background: linear-gradient(135deg, #34d399, #10b981);
  box-shadow: 0 6px 24px -2px rgba(16, 185, 129, 0.6);
}

.btn-call.in-call {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  box-shadow: 0 4px 20px -2px rgba(239, 68, 68, 0.45);
}

.btn-call.in-call:hover {
  background: linear-gradient(135deg, #f87171, #ef4444);
  box-shadow: 0 6px 24px -2px rgba(239, 68, 68, 0.6);
}

/* Right / Transcript Stage */
.transcript-stage-panel {
  display: flex;
  flex-direction: column;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 1.25rem;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: 0 20px 50px -20px rgba(0, 0, 0, 0.7);
  overflow: hidden;
  height: 100%;
}

.transcript-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.02);
}

.transcript-title-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.transcript-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-main);
}

.turn-count-badge {
  font-size: 0.7rem;
  font-family: var(--font-mono);
  background: rgba(255, 255, 255, 0.08);
  padding: 0.15rem 0.45rem;
  border-radius: 9999px;
  color: var(--text-muted);
}

.btn-clear-transcript {
  background: none;
  border: none;
  color: var(--text-sub);
  font-size: 0.75rem;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 0.4rem;
  transition: all 0.2s;
}

.btn-clear-transcript:hover {
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.05);
}

/* Transcript Feed */
.transcript-feed {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  scroll-behavior: smooth;
}

.transcript-feed::-webkit-scrollbar {
  width: 5px;
}
.transcript-feed::-webkit-scrollbar-track {
  background: transparent;
}
.transcript-feed::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 4px;
}

/* Message bubbles */
.message-bubble {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  max-width: 90%;
  animation: fadeInBubble 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.message-bubble.user {
  align-self: flex-end;
}

.message-bubble.assistant {
  align-self: flex-start;
}

.bubble-meta {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.7rem;
  color: var(--text-sub);
}

.message-bubble.user .bubble-meta {
  justify-content: flex-end;
}

.role-tag {
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.65rem;
  letter-spacing: 0.05em;
}

.message-bubble.user .role-tag {
  color: #38bdf8;
}

.message-bubble.assistant .role-tag {
  color: #a78bfa;
}

.bubble-content {
  padding: 0.75rem 0.95rem;
  border-radius: 0.85rem;
  font-size: 0.88rem;
  line-height: 1.45;
  word-break: break-word;
}

.message-bubble.user .bubble-content {
  background: linear-gradient(135deg, rgba(14, 116, 144, 0.5), rgba(3, 105, 161, 0.6));
  border: 1px solid rgba(56, 189, 248, 0.25);
  color: #ffffff;
  border-bottom-right-radius: 0.2rem;
}

.message-bubble.assistant .bubble-content {
  background: rgba(28, 28, 38, 0.85);
  border: 1px solid var(--panel-border);
  color: #f4f4f5;
  border-bottom-left-radius: 0.2rem;
}

.empty-transcript-state {
  margin: auto;
  text-align: center;
  color: var(--text-sub);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  padding: 2rem 1rem;
}

.empty-icon {
  width: 40px;
  height: 40px;
  opacity: 0.35;
}

/* Transcript Text Input Form */
.transcript-input-form {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.75rem 1rem;
  background: rgba(18, 18, 26, 0.85);
  border-top: 1px solid var(--panel-border);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  position: relative;
  z-index: 5;
}

.transcript-input-form input[type="text"] {
  flex: 1;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--panel-border);
  border-radius: 0.75rem;
  padding: 0.65rem 0.95rem;
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 0.88rem;
  outline: none;
  transition: all 0.2s ease;
}

.transcript-input-form input[type="text"]::placeholder {
  color: var(--text-sub);
}

.transcript-input-form input[type="text"]:focus {
  border-color: rgba(139, 92, 246, 0.6);
  background: rgba(255, 255, 255, 0.08);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.25);
}

.transcript-input-form button[type="submit"] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 0.75rem;
  border: none;
  background: linear-gradient(135deg, #8b5cf6, #6d28d9);
  color: #ffffff;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.2s ease;
  box-shadow: 0 4px 12px rgba(139, 92, 246, 0.35);
}

.transcript-input-form button[type="submit"]:hover {
  background: linear-gradient(135deg, #a78bfa, #8b5cf6);
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(139, 92, 246, 0.5);
}

.transcript-input-form button[type="submit"]:active {
  transform: translateY(0);
}

/* Audio Level Visualizer Footer */
.transcript-footer {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--panel-border);
  background: rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.audio-meters-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.72rem;
  color: var(--text-sub);
}

.meter-label {
  font-weight: 600;
  color: var(--text-sub);
}

.meter-val {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: #38bdf8;
  min-width: 48px;
  text-align: right;
}

.audio-meter-bar {
  flex: 1;
  height: 6px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 3px;
  overflow: hidden;
  position: relative;
}

.audio-meter-fill {
  height: 100%;
  width: 0%;
  background: var(--current-color);
  box-shadow: 0 0 8px var(--current-color);
  transition: width 0.05s ease-out;
}

.bargein-hint {
  font-size: 0.7rem;
  color: var(--text-sub);
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.bargein-hint svg {
  width: 12px;
  height: 12px;
  color: #f59e0b;
}

/* Modal / Toast Notifications */
.toast-notice {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: rgba(24, 24, 32, 0.95);
  border: 1px solid var(--panel-border);
  padding: 0.65rem 1.25rem;
  border-radius: 0.75rem;
  font-size: 0.85rem;
  color: #fff;
  box-shadow: 0 10px 30px rgba(0,0,0,0.6);
  z-index: 1000;
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.toast-notice.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  .beacon-ping,
  .orb-acoustic-ring,
  .typing-cursor {
    animation: none;
  }
}
