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

:root {
  --bg:           #06060f;
  --surface:      #0d0d20;
  --surface-2:    #12122a;
  --border:       #1c1c3a;
  --primary:      #7c3aed;
  --primary-dim:  #7c3aed44;
  --cyan:         #06b6d4;
  --green:        #10b981;
  --amber:        #f59e0b;
  --text:         #f1f5f9;
  --text-muted:   #8b8baa;
  --text-faint:   #3d3d60;
  --user-bg:      #1e2f5e;
  --asst-bg:      #13132b;
  --radius:       12px;
  --radius-lg:    20px;
  font-family: Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

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

/* ── Overlay ──────────────────────────────────────────────── */
.overlay {
  position: fixed; inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse 80% 70% at 50% 40%, #110d2e 0%, var(--bg) 100%);
  z-index: 100;
  transition: opacity 0.5s, visibility 0.5s;
}

.overlay.fade-out {
  opacity: 0;
  visibility: hidden;
}

.overlay-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 48px 40px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  max-width: 380px;
  width: 90%;
  box-shadow: 0 0 80px #7c3aed22;
}

.overlay-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.overlay-avatar-preview {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #7c3aed 0%, #06b6d4 60%, transparent 100%);
  opacity: 0.9;
  animation: orbPulse 3s ease-in-out infinite;
  box-shadow: 0 0 40px #7c3aed55;
}

@keyframes orbPulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 40px #7c3aed55; }
  50% { transform: scale(1.04); box-shadow: 0 0 60px #7c3aed88; }
}

.overlay-title {
  font-size: 26px;
  font-weight: 600;
  color: var(--text);
  text-align: center;
  line-height: 1.2;
}

.overlay-subtitle {
  font-size: 14px;
  color: var(--text-muted);
  text-align: center;
}

/* ── Loading steps ────────────────────────────────────────── */
.loading-steps {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  margin-top: 8px;
}

.load-step {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  transition: color 0.3s;
}

.step-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  flex-shrink: 0;
  position: relative;
  transition: background 0.3s, border 0.3s;
}

/* pending */
.load-step[data-state="pending"] .step-dot {
  border: 1.5px solid var(--text-faint);
}
.load-step[data-state="pending"] .step-label { color: var(--text-faint); }

/* active — spinning ring */
.load-step[data-state="active"] .step-dot {
  border: 2px solid transparent;
  border-top-color: var(--primary);
  border-right-color: var(--primary);
  animation: stepSpin 0.8s linear infinite;
}
.load-step[data-state="active"] .step-label { color: var(--text-muted); }

/* done — filled with checkmark */
.load-step[data-state="done"] .step-dot {
  background: var(--green);
  border: none;
}
.load-step[data-state="done"] .step-dot::after {
  content: '';
  display: block;
  position: absolute;
  top: 4px; left: 5px;
  width: 6px; height: 4px;
  border-left: 2px solid #fff;
  border-bottom: 2px solid #fff;
  transform: rotate(-45deg);
}
.load-step[data-state="done"] .step-label { color: var(--text); }

/* error */
.load-step[data-state="error"] .step-dot {
  background: #ef4444;
  border: none;
}
.load-step[data-state="error"] .step-dot::after {
  content: '×';
  display: block;
  position: absolute;
  inset: 0;
  text-align: center;
  line-height: 18px;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
}
.load-step[data-state="error"] .step-label { color: #fca5a5; }

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

.overlay-error {
  font-size: 12px;
  color: #fca5a5;
  text-align: center;
  min-height: 18px;
  line-height: 1.4;
}

.logo-diamond { color: var(--primary); font-size: 18px; }

/* ── Main app ─────────────────────────────────────────────── */
.app {
  display: grid;
  grid-template-rows: 52px 1fr;
  height: 100vh;
  transition: opacity 0.5s;
}

/* ── Header ───────────────────────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 500;
}

.logo-name { color: var(--text); font-weight: 600; letter-spacing: 0.05em; }
.header-sep { color: var(--text-faint); }
.header-product { color: var(--text-muted); }

.badge-ai {
  font-size: 11px;
  font-weight: 500;
  padding: 3px 10px;
  background: var(--primary-dim);
  color: #a78bfa;
  border: 1px solid #7c3aed44;
  border-radius: 20px;
  letter-spacing: 0.04em;
}

/* ── Main layout ──────────────────────────────────────────── */
.main {
  display: grid;
  grid-template-columns: 1fr 360px;
  overflow: hidden;
}

.app.hide-transcript .main {
  grid-template-columns: 1fr;
}

.app.hide-transcript .convo-panel {
  display: none;
}

@media (max-width: 768px) {
  .main {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
  }
}

/* ── Avatar panel ─────────────────────────────────────────── */
.avatar-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding-bottom: 28px;
  background: radial-gradient(ellipse 70% 60% at 50% 45%, #110d2e 0%, var(--bg) 100%);
  overflow: hidden;
}

.avatar-canvas-wrap {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.avatar-canvas-wrap canvas {
  display: block;
  /* Three.js controls width/height — do not override */
}

.avatar-identity {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  margin-bottom: 16px;
}

.avatar-name {
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
  text-shadow: 0 2px 20px rgba(0,0,0,0.8);
}

.avatar-role {
  font-size: 12px;
  color: var(--text-muted);
  letter-spacing: 0.04em;
}

/* ── Status + waveform ────────────────────────────────────── */
.mic-wrap {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.mic-canvas {
  display: block;
  opacity: 0.7;
}

.status-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 16px;
  background: rgba(13, 13, 32, 0.85);
  border: 1px solid var(--border);
  border-radius: 20px;
  backdrop-filter: blur(10px);
  font-size: 13px;
  color: var(--text-muted);
  min-width: 140px;
  justify-content: center;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-faint);
  transition: background 0.3s, box-shadow 0.3s;
  flex-shrink: 0;
}

.status-dot.listening {
  background: var(--green);
  box-shadow: 0 0 8px var(--green);
  animation: dotPulse 1s ease-in-out infinite;
}

.status-dot.thinking {
  background: var(--amber);
  box-shadow: 0 0 8px var(--amber);
  animation: dotPulse 0.6s ease-in-out infinite;
}

.status-dot.speaking {
  background: var(--cyan);
  box-shadow: 0 0 8px var(--cyan);
  animation: dotPulse 0.4s ease-in-out infinite;
}

.status-dot.ready {
  background: var(--primary);
  box-shadow: 0 0 6px var(--primary);
}

.status-dot.error { background: #ef4444; }

@keyframes dotPulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.4); opacity: 0.7; }
}

/* ── Conversation panel ───────────────────────────────────── */
.convo-panel {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-left: 1px solid var(--border);
  overflow: hidden;
}

.convo-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.convo-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.btn-clear {
  background: none;
  border: none;
  color: var(--text-faint);
  font-size: 16px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
}

.btn-clear:hover { color: var(--text-muted); background: var(--surface-2); }

/* ── Transcript ───────────────────────────────────────────── */
.transcript {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

.transcript::-webkit-scrollbar { width: 4px; }
.transcript::-webkit-scrollbar-track { background: transparent; }
.transcript::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.transcript-placeholder {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  color: var(--text-faint);
  text-align: center;
  padding: 40px 20px;
}

.message {
  display: flex;
  flex-direction: column;
  gap: 4px;
  animation: msgIn 0.2s ease-out;
}

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

.message-role {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.message.user .message-role  { color: #60a5fa; text-align: right; }
.message.assistant .message-role { color: #a78bfa; }

.message-bubble {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  max-width: 100%;
  word-break: break-word;
}

.message.user {
  align-items: flex-end;
}

.message.user .message-bubble {
  background: var(--user-bg);
  border-bottom-right-radius: 4px;
  border: 1px solid #1e3a7055;
}

.message.assistant .message-bubble {
  background: var(--asst-bg);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--border);
}

/* ── Footer ───────────────────────────────────────────────── */
.convo-footer {
  padding: 10px 20px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  min-height: 38px;
  display: flex;
  align-items: center;
}

.lang-tag {
  font-size: 11px;
  color: var(--text-faint);
  letter-spacing: 0.04em;
}

/* ── Error toast ──────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: #1f1f1f;
  border: 1px solid #ef4444;
  color: #fca5a5;
  padding: 12px 24px;
  border-radius: var(--radius);
  font-size: 13px;
  z-index: 200;
  transition: transform 0.3s;
  text-align: center;
}

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

/* ── End screen ───────────────────────────────────────────── */
.end-screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(ellipse 80% 70% at 50% 40%, #111827 0%, #020617 100%);
  z-index: 80;
}

.end-screen[hidden] {
  display: none;
}

.end-content {
  width: min(560px, 100%);
  text-align: center;
}

.end-logo {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 24px;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.10em;
}

.end-content h2 {
  margin-bottom: 16px;
  color: var(--text);
  font-size: 30px;
  font-weight: 600;
  line-height: 1.2;
}

.end-content p {
  color: var(--text-muted);
  font-size: 17px;
  line-height: 1.7;
}

.end-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  margin-top: 28px;
  padding: 0 18px;
  border: 1px solid #38bdf855;
  border-radius: 8px;
  background: #0f172a;
  color: #bae6fd;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.end-link:hover {
  background: #082f49;
  border-color: #38bdf8;
  color: #f0f9ff;
}
