/* ═══════════════════════════════════════════════════════════════
   Siyada Voice Agent — Design System
   Dark neon theme with audio-reactive voice UI
   ═══════════════════════════════════════════════════════════════ */

/* ── CSS Variables ──────────────────────────────────────────── */
:root {
  --bg-primary: #040609;
  --bg-card: #0a0f1a;
  --bg-overlay: rgba(4, 6, 9, 0.85);
  --border: rgba(255, 255, 255, 0.06);

  --emerald: #10b981;
  --emerald-glow: rgba(16, 185, 129, 0.4);
  --cyan: #06b6d4;
  --cyan-glow: rgba(6, 182, 212, 0.4);
  --purple: #a855f7;
  --purple-glow: rgba(168, 85, 247, 0.4);
  --amber: #f59e0b;
  --red: #ef4444;

  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --font-body: 'Outfit', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --radius: 12px;
  --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Reset & Base ───────────────────────────────────────────── */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--font-body);
  background: var(--bg-primary);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

::selection {
  background: var(--emerald);
  color: var(--bg-primary);
}

/* ── Scrollbar ──────────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

/* ── Grain Overlay ──────────────────────────────────────────── */
.grain {
  position: fixed;
  inset: 0;
  z-index: 9999;
  pointer-events: none;
  opacity: 0.03;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ── Canvas (Background) ────────────────────────────────────── */
#scene-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
}

/* ── UI Overlay ─────────────────────────────────────────────── */
.ui-overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  pointer-events: none;
}

.ui-overlay > * {
  pointer-events: auto;
}

/* ── Top Bar ────────────────────────────────────────────────── */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  backdrop-filter: blur(12px);
  background: rgba(4, 6, 9, 0.5);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.brand-siyada { color: var(--emerald); }
.brand-x { color: var(--cyan); font-weight: 400; }

.connection-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background var(--transition);
}

.status-dot[data-status="connecting"] {
  background: var(--amber);
  animation: pulse-dot 1s ease-in-out infinite;
}

.status-dot[data-status="connected"] {
  background: var(--emerald);
  box-shadow: 0 0 8px var(--emerald-glow);
}

.status-dot[data-status="error"] {
  background: var(--red);
}

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

/* ── Center Section (Voice Button) ──────────────────────────── */
.center-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  pointer-events: none;
}

.agent-name {
  font-size: 42px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: 0.04em;
  text-shadow: 0 0 30px var(--emerald-glow);
  opacity: 0.9;
}

.voice-btn-wrapper {
  position: relative;
  pointer-events: auto;
}

/* Pulse ring behind button */
.voice-btn-wrapper::before {
  content: '';
  position: absolute;
  inset: -12px;
  border-radius: 50%;
  border: 2px solid var(--emerald);
  opacity: 0;
  transition: opacity var(--transition);
}

.voice-btn-wrapper[data-state="idle"]::before {
  opacity: 0;
}

.voice-btn-wrapper[data-state="connecting"]::before {
  opacity: 0.4;
  border-color: var(--amber);
  animation: ring-pulse 1.5s ease-in-out infinite;
}

.voice-btn-wrapper[data-state="connected"]::before {
  opacity: 0.5;
  border-color: var(--emerald);
  animation: ring-pulse 2s ease-in-out infinite;
}

.voice-btn-wrapper[data-state="speaking"]::before {
  opacity: 0.7;
  border-color: var(--emerald);
  animation: ring-pulse-fast 0.8s ease-in-out infinite;
}

.voice-btn-wrapper[data-state="listening"]::before {
  opacity: 0.5;
  border-color: var(--cyan);
  animation: ring-pulse 1.5s ease-in-out infinite;
}

@keyframes ring-pulse {
  0%, 100% { transform: scale(1); opacity: 0.5; }
  50% { transform: scale(1.15); opacity: 0.1; }
}

@keyframes ring-pulse-fast {
  0%, 100% { transform: scale(1); opacity: 0.7; }
  50% { transform: scale(1.25); opacity: 0.15; }
}

.voice-btn {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: 2px solid var(--emerald);
  background: rgba(16, 185, 129, 0.08);
  color: var(--emerald);
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 1;
}

.voice-btn:hover {
  background: rgba(16, 185, 129, 0.15);
  box-shadow: 0 0 30px var(--emerald-glow);
  transform: scale(1.05);
}

.voice-btn:active {
  transform: scale(0.95);
}

.voice-btn svg {
  width: 32px;
  height: 32px;
  fill: currentColor;
  transition: all var(--transition);
}

/* Button state colors */
.voice-btn[data-state="connecting"] {
  border-color: var(--amber);
  color: var(--amber);
  background: rgba(245, 158, 11, 0.08);
  animation: btn-connecting 1.5s ease-in-out infinite;
}

@keyframes btn-connecting {
  0%, 100% { box-shadow: 0 0 10px rgba(245, 158, 11, 0.2); }
  50% { box-shadow: 0 0 25px rgba(245, 158, 11, 0.4); }
}

.voice-btn[data-state="connected"],
.voice-btn[data-state="speaking"],
.voice-btn[data-state="listening"] {
  border-color: var(--emerald);
  color: var(--emerald);
  background: rgba(16, 185, 129, 0.12);
  box-shadow: 0 0 20px var(--emerald-glow);
}

.voice-btn[data-state="speaking"] {
  animation: btn-speaking 0.6s ease-in-out infinite;
}

@keyframes btn-speaking {
  0%, 100% { box-shadow: 0 0 20px var(--emerald-glow); }
  50% { box-shadow: 0 0 40px var(--emerald-glow); }
}

.voice-label {
  font-size: 13px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  letter-spacing: 0.05em;
  transition: color var(--transition);
}

.voice-label[data-state="connecting"] { color: var(--amber); }
.voice-label[data-state="connected"],
.voice-label[data-state="listening"] { color: var(--cyan); }
.voice-label[data-state="speaking"] { color: var(--emerald); }

/* ── Transcript Area ────────────────────────────────────────── */
.transcript-area {
  max-height: 30vh;
  overflow-y: auto;
  padding: 16px 24px 24px;
  backdrop-filter: blur(12px);
  background: rgba(4, 6, 9, 0.6);
  border-top: 1px solid var(--border);
}

.transcript-inner {
  max-width: 600px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.transcript-msg {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  animation: msg-in 0.3s ease-out;
}

@keyframes msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg-source {
  font-size: 10px;
  font-family: var(--font-mono);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  min-width: 44px;
  padding-top: 3px;
  flex-shrink: 0;
}

.msg-source[data-source="ai"] { color: var(--emerald); }
.msg-source[data-source="user"] { color: var(--cyan); }

.msg-text {
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-secondary);
  direction: rtl;
  text-align: right;
  unicode-bidi: plaintext;
}

.transcript-empty {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  padding: 12px 0;
  font-family: var(--font-mono);
}

/* ── Error Banner ───────────────────────────────────────────── */
.error-banner {
  position: fixed;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: var(--red);
  padding: 10px 20px;
  border-radius: var(--radius);
  font-size: 13px;
  font-family: var(--font-mono);
  backdrop-filter: blur(12px);
  animation: msg-in 0.3s ease-out;
  display: none;
}

.error-banner.visible {
  display: block;
}


/* ── Email Gate ─────────────────────────────────────────────── */
.gate {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
  transition: opacity 0.5s ease;
}

.gate.fade-out {
  opacity: 0;
  pointer-events: none;
}

.gate.hidden {
  display: none;
}

.gate-card {
  width: 100%;
  max-width: 380px;
  padding: 40px 32px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  text-align: center;
}

.gate-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 6px;
}

.gate-brand-siyada { color: var(--emerald); }
.gate-brand-tech { color: var(--cyan); font-weight: 400; }

.gate-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 28px;
}

.gate-desc {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 20px;
  line-height: 1.5;
}

.gate-desc strong {
  color: var(--emerald);
  word-break: break-all;
}

.gate-step.hidden {
  display: none;
}

.gate-input {
  display: block;
  width: 100%;
  padding: 12px 16px;
  margin-bottom: 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 14px;
  outline: none;
  transition: border-color var(--transition);
}

.gate-input:focus {
  border-color: var(--emerald);
}

.gate-input::placeholder {
  color: var(--text-muted);
}

.gate-code-input {
  font-family: var(--font-mono);
  font-size: 24px;
  font-weight: 600;
  text-align: center;
  letter-spacing: 0.3em;
  padding: 16px;
}

.gate-error {
  font-size: 12px;
  color: var(--red);
  min-height: 18px;
  margin-bottom: 8px;
  font-family: var(--font-mono);
}

.gate-btn {
  width: 100%;
  padding: 12px;
  background: var(--emerald);
  color: var(--bg-primary);
  border: none;
  border-radius: 8px;
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.gate-btn:hover:not(:disabled) {
  background: #0ea472;
  box-shadow: 0 0 20px var(--emerald-glow);
}

.gate-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.gate-btn-loader {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(4, 6, 9, 0.3);
  border-top-color: var(--bg-primary);
  border-radius: 50%;
  animation: gate-spin 0.6s linear infinite;
}

.gate-btn-loader.hidden {
  display: none;
}

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

.gate-back {
  margin-top: 16px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 12px;
  font-family: var(--font-mono);
  cursor: pointer;
  transition: color var(--transition);
}

.gate-back:hover {
  color: var(--cyan);
}

.gate-footer {
  margin-top: 24px;
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 768px) {
  .top-bar {
    padding: 12px 16px;
  }

  .brand {
    font-size: 11px;
  }

  .agent-name {
    font-size: 32px;
  }

  .voice-btn {
    width: 70px;
    height: 70px;
  }

  .voice-btn svg {
    width: 28px;
    height: 28px;
  }

  .transcript-area {
    max-height: 25vh;
    padding: 12px 16px 20px;
  }

  .msg-text {
    font-size: 13px;
  }
}

@media (max-width: 480px) {
  .agent-name {
    font-size: 26px;
  }

  .voice-btn {
    width: 64px;
    height: 64px;
  }

  .voice-btn svg {
    width: 24px;
    height: 24px;
  }

  .connection-status span:not(.status-dot) {
    display: none;
  }
}
