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

:root {
  --bg: #0e1116;
  --panel: #171c24;
  --line: #262d38;
  --text: #e6e9ef;
  --muted: #8a93a2;
  --accent: #4c8dff;
  --user: #223047;
  --agent: #1b2530;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  height: 100dvh; /* exclui a barra do browser no telemóvel */
}

.app {
  max-width: 720px;
  margin: 0 auto;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 16px;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.top h1 { font-size: 20px; letter-spacing: .5px; }

.controls { display: flex; align-items: center; gap: 10px; }

select, .ghost {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
  cursor: pointer;
}

.switch { display: flex; align-items: center; gap: 5px; font-size: 13px; color: var(--muted); }

/* ---- Avatar ------------------------------------------------------------- */
.avatar {
  position: relative;
  width: 132px;
  height: 132px;
  align-self: center;
  margin: 14px 0 6px;
  flex: none;
}

.avatar-ring {
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 2px solid var(--line);
  transition: border-color .3s ease, box-shadow .3s ease;
}

.avatar-face {
  position: relative;
  width: 100%;
  height: 100%;
  display: block;
  animation: breathe 4s ease-in-out infinite;
}

.face-bg { fill: var(--panel); stroke: var(--line); stroke-width: 2; }
.eye { fill: var(--text); }
.mouth-smile { fill: none; stroke: var(--text); stroke-width: 3.5; stroke-linecap: round; }
.mouth-open { fill: var(--text); opacity: 0; transform-origin: 60px 82px; }

.eyes {
  transform-origin: 60px 54px;
  animation: blink 5s infinite;
}

@keyframes breathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.03); } }
@keyframes blink { 0%, 92%, 100% { transform: scaleY(1); } 96% { transform: scaleY(.1); } }
@keyframes talk { from { transform: scaleY(.35); } to { transform: scaleY(1.1); } }
@keyframes think-eyes { 0%, 100% { transform: translate(-2px, -4px); } 50% { transform: translate(3px, -4px); } }
@keyframes ring-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(76, 141, 255, .45); }
  70%  { box-shadow: 0 0 0 15px rgba(76, 141, 255, 0); }
  100% { box-shadow: 0 0 0 0 rgba(76, 141, 255, 0); }
}

.avatar[data-state="listening"] .avatar-ring {
  border-color: var(--accent);
  animation: ring-pulse 1.4s infinite;
}
.avatar[data-state="thinking"] .avatar-ring { border-color: #ffcf6b; }
.avatar[data-state="speaking"] .avatar-ring { border-color: #5ad19b; }

.avatar[data-state="thinking"] .eyes { animation: think-eyes 1.6s ease-in-out infinite; }

.avatar[data-state="speaking"] .avatar-face { animation: none; }
.avatar[data-state="speaking"] .mouth-smile { opacity: 0; }
.avatar[data-state="speaking"] .mouth-open {
  opacity: 1;
  animation: talk .26s ease-in-out infinite alternate;
}

@media (max-height: 640px) {
  .avatar { width: 96px; height: 96px; margin: 8px 0 4px; }
}
@media (prefers-reduced-motion: reduce) {
  .avatar-face, .eyes, .avatar-ring,
  .avatar[data-state="speaking"] .mouth-open { animation: none !important; }
}

.log {
  flex: 1;
  overflow-y: auto;
  padding: 16px 4px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 14px;
  line-height: 1.45;
  font-size: 15px;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.msg.user { align-self: flex-end; background: var(--user); border-bottom-right-radius: 4px; }
.msg.agent { align-self: flex-start; background: var(--agent); border-bottom-left-radius: 4px; }
.msg.error { align-self: center; background: #3a1d1d; color: #ffb4b4; font-size: 13px; }

.status {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  min-height: 18px;
  padding: 6px 0;
}
.status.listening { color: var(--accent); }
.status.thinking { color: #ffcf6b; }

.mic {
  align-self: center;
  width: 76px;
  height: 76px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  margin: 10px 0 calc(64px + env(safe-area-inset-bottom));
  transition: transform .1s ease, background .2s ease;
}
.mic:active { transform: scale(.94); }
.mic.on { background: #e2483d; animation: pulse 1.4s infinite; }
.mic:disabled { background: var(--line); cursor: not-allowed; }

@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(226, 72, 61, .5); }
  70%  { box-shadow: 0 0 0 18px rgba(226, 72, 61, 0); }
  100% { box-shadow: 0 0 0 0 rgba(226, 72, 61, 0); }
}
