:root {
  --bg: #f5f4ef;
  --surface: #ffffff;
  --border: #e3e1d9;
  --text: #2d2a26;
  --muted: #8a867e;
  --user-bubble: #d9714e;
  --user-text: #ffffff;
  --bot-bubble: #ffffff;
  --accent: #d9714e;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.7rem 1.2rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 650; font-size: 1.05rem; }
.controls { display: flex; align-items: center; gap: 0.6rem; }

button {
  font: inherit;
  padding: 0.45rem 0.95rem;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--muted); }
button:disabled { opacity: 0.45; cursor: default; }
#connectBtn { background: var(--accent); border-color: var(--accent); color: #fff; }
#micBtn.muted, #voiceBtn.muted { background: #f3d9d1; }

.chip {
  font-size: 0.78rem;
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  text-transform: lowercase;
}
.chip.listening { background: #e7f2e7; color: #2f6b31; border-color: #cfe4cf; }
.chip.thinking  { background: #fdf3d7; color: #8a6d1a; border-color: #f0e2b6; }
.chip.speaking  { background: #fdeae2; color: #b04a26; border-color: #f5d5c8; }
.chip.off       { background: #eeede8; }

#layout {
  flex: 1;
  display: flex;
  min-height: 0; /* allow children to scroll instead of the page */
}
#chatCol {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
main {
  flex: 1;
  min-height: 0; /* required so the flex child scrolls internally */
  overflow-y: auto;
  padding: 1.2rem 0 1rem;
}
#messages {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 1rem;
}
#facePanel {
  width: 300px;
  flex-shrink: 0;
  border-left: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 2rem;
  gap: 0.8rem;
}
#facePanel[hidden] { display: none; }
.panelTitle { font-weight: 650; color: var(--text); }
.panelNote { font-size: 0.78rem; color: var(--muted); }
@media (max-width: 860px) {
  /* narrow screens: floating card instead of a column */
  #facePanel {
    position: fixed;
    top: 4.2rem;
    right: 0.8rem;
    width: auto;
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 0.6rem 0.8rem;
    box-shadow: 0 4px 14px rgba(0,0,0,0.08);
    z-index: 5;
  }
  #facePanel canvas { width: 130px; height: 130px; }
  .panelTitle { display: none; }
  .panelNote { display: none; }
}

.hint {
  text-align: center;
  color: var(--muted);
  font-size: 0.92rem;
  margin: 2.2rem 0;
}

.msg {
  display: flex;
  margin: 0.55rem 0;
}
.msg .bubble {
  max-width: 78%;
  padding: 0.65rem 0.95rem;
  border-radius: 16px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.msg.user { justify-content: flex-end; }
.msg.user .bubble {
  background: var(--user-bubble);
  color: var(--user-text);
  border-bottom-right-radius: 5px;
}
.msg.bot .bubble {
  background: var(--bot-bubble);
  border: 1px solid var(--border);
  border-bottom-left-radius: 5px;
}
.msg .bubble.interim { opacity: 0.55; font-style: italic; }
.msg .meta {
  font-size: 0.72rem;
  color: var(--muted);
  margin: 0.2rem 0.3rem 0;
  align-self: flex-end;
}
.msg.bot { flex-direction: column; align-items: flex-start; }
.msg.bot .meta { align-self: flex-start; }
.totals { font-size: 0.76rem; color: var(--muted); white-space: nowrap; }

footer {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 0.75rem 1rem calc(0.75rem + env(safe-area-inset-bottom));
}
.inputBar {
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  gap: 0.6rem;
  align-items: flex-end;
}
#input {
  flex: 1;
  font: inherit;
  resize: none;
  padding: 0.6rem 0.85rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  max-height: 8rem;
}
#input:focus { outline: 2px solid var(--accent); border-color: transparent; }
#sendBtn { background: var(--accent); border-color: var(--accent); color: #fff; }
