/* ── 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-center {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
}
.header-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.header-sep-pipe {
  color: var(--text-faint);
  font-size: 13px;
}
.header-role {
  font-size: 13px;
  font-weight: 400;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

.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;
}

.badge-version {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-muted);
  letter-spacing: 0.02em;
  font-family: "SFMono-Regular", Consolas, monospace;
}

.badge-version:empty {
  display: none;
}

/* ── 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;
}

.app.conversation-enabled.hide-transcript .main {
  grid-template-columns: 1fr 360px;
}

.app.conversation-enabled.hide-transcript .convo-panel {
  display: flex;
}

@media (max-width: 768px) {
  /* ── Single-column base ── */
  .main {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
  }

  /* Override desktop hide-transcript grid adjustments */
  .app.conversation-enabled.hide-transcript .main {
    grid-template-columns: 1fr;
  }

  /* ── Header: strip non-essential elements ── */
  .header { padding: 0 16px; }
  .header-sep-pipe,
  .header-role { display: none; }

  /* ── Voice mode: avatar full-screen, no chat panel ── */
  .app.voice-mode .convo-panel,
  .app.conversation-enabled.hide-transcript.voice-mode .convo-panel {
    display: none;
  }

  /* ── Text mode: conversation only, avatar hidden ── */
  .app.text-mode .avatar-panel { display: none; }

  .app.text-mode .convo-panel {
    border-left: none;
    border-top: none;
    height: 100%;
  }

  /* Hide lang indicator to maximise vertical space */
  .app.text-mode .convo-footer { display: none; }

  /* Ensure chat panel is visible even with hide-transcript */
  .app.conversation-enabled.hide-transcript.text-mode .convo-panel {
    display: flex;
  }

  /* No manual resize on mobile textarea */
  .app.text-mode .chat-input { resize: none; }
}

/* ── Text mode desktop: hide avatar, convo takes full width ── */
.app.text-mode .avatar-panel { display: none; }
.app.text-mode .main { grid-template-columns: 1fr; }

/* ── Debug panel (dev only) ───────────────────────────────── */
.app.debug-panel-active .main {
  grid-template-columns: 1fr 360px 280px;
}

.debug-panel {
  display: flex;
  flex-direction: column;
  background: #070712;
  border-left: 1px solid #7c3aed44;
  overflow: hidden;
  font-family: 'JetBrains Mono', 'Cascadia Code', 'Fira Code', ui-monospace, monospace;
}

.debug-panel[hidden] {
  display: none;
}

.dbg-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid #1a1a30;
  flex-shrink: 0;
  background: #0a0a1a;
}

.dbg-title {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: #7c3aed;
  text-transform: uppercase;
}

.dbg-status {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text-faint);
  letter-spacing: 0.03em;
}
.dbg-status.ready    { color: #a78bfa; background: #7c3aed22; }
.dbg-status.listening { color: #34d399; background: #10b98122; }
.dbg-status.thinking  { color: #fcd34d; background: #f59e0b22; }
.dbg-status.speaking  { color: #60a5fa; background: #3b82f622; }
.dbg-status.error     { color: #f87171; background: #ef444422; }

.dbg-body {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.dbg-section {
  padding: 10px 14px;
  border-bottom: 1px solid #0f0f22;
  flex-shrink: 0;
}

.dbg-events-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-bottom: 0;
}

.dbg-section-label {
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: #6b6b90;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.dbg-flags { display: flex; flex-direction: column; gap: 5px; }

.dbg-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.dbg-key   { font-size: 10px; color: #a0a0c0; }
.dbg-bool.on  { font-size: 11px; color: #34d399; }
.dbg-bool.off { font-size: 11px; color: #3a3a58; }
.dbg-val      { font-size: 10px; color: #67e8f9; }
.dbg-val-str  { font-size: 10px; color: #fcd34d; }

.dbg-events {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 4px 14px 10px;
}
.dbg-events::-webkit-scrollbar { width: 3px; }
.dbg-events::-webkit-scrollbar-track { background: transparent; }
.dbg-events::-webkit-scrollbar-thumb { background: #1c1c3a; border-radius: 2px; }

.dbg-event { display: flex; align-items: baseline; gap: 8px; }

.dbg-event-time {
  font-size: 9px;
  color: #5a5a80;
  flex-shrink: 0;
  width: 86px;
}

.dbg-event-type          { font-size: 10px; color: #c0c0e0; }
.dbg-event-type.ev-session      { color: #c4b5fd; }
.dbg-event-type.ev-speech       { color: #fcd34d; }
.dbg-event-type.ev-response-key { color: #93c5fd; }
.dbg-event-type.ev-response     { color: #6080b0; }
.dbg-event-type.ev-conversation { color: #6ee7b7; }
.dbg-event-type.ev-error        { color: #fca5a5; }

/* ── Avatar panel ─────────────────────────────────────────── */
.avatar-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding-bottom: 28px;
  background: #000000;
  overflow: hidden;
}

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

.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: 12px;
  margin-top: 8px;
}

.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;
}

/* ── Mode switch buttons ──────────────────────────────────── */
.mode-switch-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  flex-shrink: 0;
}

.mode-switch-btn:hover {
  background: var(--primary-dim);
  border-color: var(--primary);
  color: #a78bfa;
}

/* Voice→Text button lives in mic-wrap (below avatar) */
#switch-to-text-btn {
  margin-top: 4px;
}

/* Text→Voice button lives inside chat-form (left of input) */
.mode-switch-voice {
  background: var(--surface-2);
}

.chat-form {
  display: none;
  gap: 10px;
  padding: 12px;
  border-top: 1px solid var(--border);
  background: #0a0a19;
  flex-shrink: 0;
}

.app.text-mode .chat-form {
  display: flex;
}

.chat-input {
  min-height: 42px;
  max-height: 120px;
  flex: 1;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  line-height: 1.4;
  padding: 10px 12px;
  outline: none;
}

.chat-input:focus {
  border-color: #7c3aedaa;
  box-shadow: 0 0 0 2px #7c3aed22;
}

.chat-send-btn {
  width: 44px;
  min-height: 42px;
  border: 1px solid #22d3ee66;
  border-radius: 8px;
  background: #0e7490;
  color: #ecfeff;
  font-size: 18px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}

.chat-send-btn:hover { background: #0891b2; border-color: #67e8f9; }

.chat-send-btn:disabled,
.chat-input:disabled {
  cursor: default;
  opacity: 0.55;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ── 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;
}

/* ── About ───────────────────────────────────────────────── */
.about-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.about-btn:hover,
.about-btn:focus-visible {
  background: var(--primary-dim);
  border-color: var(--primary);
  color: var(--text);
}

.about-dialog {
  position: fixed;
  inset: 0;
  margin: auto;
  width: min(420px, calc(100vw - 48px));
  height: fit-content;
  max-height: calc(100vh - 48px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
}

.about-dialog::backdrop {
  background: rgba(2, 6, 23, 0.72);
}

.about-content {
  position: relative;
  padding: 32px 28px 28px;
  text-align: center;
}

.about-close {
  position: absolute;
  top: 12px;
  right: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.about-close:hover,
.about-close:focus-visible {
  background: var(--surface-2);
  color: var(--text);
}

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

.about-content h2 {
  margin-bottom: 8px;
  color: var(--text);
  font-size: 22px;
  font-weight: 600;
}

.about-row {
  color: var(--text-muted);
  font-size: 13px;
  font-family: "SFMono-Regular", Consolas, monospace;
}

.about-models {
  margin: 20px 0 0;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 14px;
  text-align: left;
}

.about-models[hidden] {
  display: none;
}

.about-models dt {
  color: var(--text-faint);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.about-models dd {
  margin: 0;
  color: var(--text);
  font-size: 13px;
  font-family: "SFMono-Regular", Consolas, monospace;
  word-break: break-all;
}
