:root {
  --bg: #1c1917;
  --surface: #292524;
  --border: #44403c;
  --text: #f5f5f4;
  --muted: #a8a29e;
  --accent: #d97706;
  --error: #f87171;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, system-ui, sans-serif;
}

[hidden] { display: none !important; }

button {
  font: inherit;
  border: 0;
  border-radius: 10px;
  padding: 0.6rem 1rem;
  background: var(--accent);
  color: #fff;
}
button:disabled { opacity: 0.5; }

/* Inputs must be at least 16px or iOS zooms the page on focus. */
input, textarea {
  font: inherit;
  font-size: 16px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.6rem 0.8rem;
}

#setup {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 1rem;
}
#token-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: min(100%, 22rem);
}
#token-form h1 { margin: 0; }
#token-form p { margin: 0; color: var(--muted); }

#chat {
  height: 100%;
  display: flex;
  flex-direction: column;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: calc(env(safe-area-inset-top, 0px) + 0.5rem) 1rem 0.5rem;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}
.header-actions { display: flex; gap: 1rem; }
header button {
  background: none;
  color: var(--muted);
  padding: 0.25rem 0;
  font-weight: 400;
  font-size: 0.9rem;
}

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.msg {
  max-width: 85%;
  padding: 0.5rem 0.8rem;
  border-radius: 14px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; }
.msg.agent { align-self: flex-start; background: var(--surface); }
.msg.tool {
  align-self: flex-start;
  background: none;
  color: var(--muted);
  font-size: 0.8rem;
  font-family: ui-monospace, Menlo, monospace;
  padding: 0 0.8rem;
}
.msg.denied { align-self: flex-start; background: none; color: var(--error); font-size: 0.8rem; padding: 0 0.8rem; }
.msg.error { align-self: center; background: none; color: var(--error); font-size: 0.9rem; }

#composer {
  display: flex;
  gap: 0.5rem;
  padding: 0.5rem 1rem calc(env(safe-area-inset-bottom, 0px) + 0.5rem);
  border-top: 1px solid var(--border);
}
#composer textarea {
  flex: 1;
  resize: none;
  max-height: 8rem;
}

/* Hold-to-talk: no text selection, callout or scrolling while held. */
#mic {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
#mic.recording {
  background: var(--error);
  border-color: var(--error);
  color: #fff;
}
