* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #0a0a0a;
  --surface: #141414;
  --border: #2a2a2a;
  --text: #e0e0e0;
  --text-dim: #888;
  --accent: #4a9eff;
  --accent-glow: rgba(74, 158, 255, 0.3);
  --green: #4ade80;
  --yellow: #facc15;
  --red: #ef4444;
  --user-bubble: #1a2a3a;
  --bot-bubble: #1a1a2a;
  --system-bubble: #1a1a1a;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* --- Header --- */
#header {
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  flex-shrink: 0;
}

#header h1 { font-size: 18px; font-weight: 600; letter-spacing: 0.5px; }

#status {
  font-size: 12px;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 6px;
}

/* --- Status Dot --- */
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: background 0.3s;
  flex-shrink: 0;
}

.status-dot.ready { background: var(--text-dim); }
.status-dot.listening { background: var(--green); animation: pulse 1.5s ease-in-out infinite; }
.status-dot.thinking { background: var(--yellow); animation: pulse 1s ease-in-out infinite; }
.status-dot.speaking { background: var(--accent); animation: pulse 0.6s ease-in-out infinite; }
.status-dot.disconnected { background: var(--red); }

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.85); }
}

/* --- Chat --- */
#chat {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
}

.msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.5;
  word-wrap: break-word;
  animation: fadeIn 0.2s ease-out;
}

.msg.user {
  align-self: flex-end;
  background: var(--user-bubble);
  border-bottom-right-radius: 4px;
}

.msg.bot {
  align-self: flex-start;
  background: var(--bot-bubble);
  border-bottom-left-radius: 4px;
}

.msg.system {
  align-self: center;
  background: var(--system-bubble);
  color: var(--text-dim);
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 8px;
  max-width: 90%;
}

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

/* --- Controls --- */
#controls {
  padding: 10px 16px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--surface);
  flex-shrink: 0;
}

#visualizer {
  height: 40px;
  background: var(--bg);
  border-radius: 8px;
  overflow: hidden;
}

#visualizer canvas { width: 100%; height: 100%; display: block; }

#input-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

#text-input {
  flex: 1;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
}

#text-input:focus { border-color: var(--accent); }

#mic-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  background: transparent;
  color: var(--accent);
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

#mic-btn:active {
  transform: scale(0.95);
}

#mic-btn.active {
  background: var(--accent);
  color: var(--bg);
  box-shadow: 0 0 20px var(--accent-glow);
  animation: micPulse 2s ease-in-out infinite;
}

@keyframes micPulse {
  0%, 100% { box-shadow: 0 0 20px var(--accent-glow); }
  50% { box-shadow: 0 0 30px var(--accent-glow), 0 0 60px rgba(74, 158, 255, 0.15); }
}

#send-btn {
  padding: 10px 16px;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: 20px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

#send-btn:active {
  opacity: 0.8;
}

/* --- Mobile --- */
@media (max-width: 600px) {
  #mic-btn {
    width: 56px;
    height: 56px;
    font-size: 24px;
  }

  .msg {
    max-width: 90%;
    font-size: 16px;
  }

  #text-input {
    font-size: 16px; /* Prevents zoom on iOS */
  }
}

/* --- Scrollbar --- */
#chat::-webkit-scrollbar { width: 4px; }
#chat::-webkit-scrollbar-track { background: transparent; }
#chat::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
