:root {
  color-scheme: light dark;
  --bg: #f4f1ea;
  --surface: #fffdf8;
  --border: #e3ddd0;
  --text: #1f2421;
  --muted: #6f746f;
  --assistant-bg: #dcefe1;
  --assistant-text: #173322;
  --caller-bg: #1d3557;
  --caller-text: #f1f5fb;
  --interim-border: #a7aca7;
  --tool-bg: #f0ece2;
  --green: #2f9e5b;
  --green-hover: #278550;
  --red: #c8443a;
  --red-hover: #ad3930;
  --idle: #a3a7a3;
  --font-title: "Bricolage Grotesque", ui-sans-serif, system-ui, sans-serif;
  --font-body: "Atkinson Hyperlegible", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121513;
    --surface: #1a1e1b;
    --border: #2c322d;
    --text: #e7ebe7;
    --muted: #949a94;
    --assistant-bg: #1f3a29;
    --assistant-text: #dbf0e1;
    --caller-bg: #3a5a8c;
    --caller-text: #f4f7fc;
    --interim-border: #5c625c;
    --tool-bg: #222723;
    --green: #3bb26a;
    --green-hover: #4cc27b;
    --red: #d9554a;
    --red-hover: #e5675c;
    --idle: #5c625c;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.45;
}

.phone {
  display: flex;
  flex-direction: column;
  max-width: 440px;
  height: 100dvh;
  margin: 0 auto;
  background: var(--surface);
  border-inline: 1px solid var(--border);
}

.header {
  padding: 18px 20px 12px;
  border-bottom: 1px solid var(--border);
}

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

h1 {
  flex: 1;
  margin: 0;
  font-family: var(--font-title);
  font-size: 1.3rem;
  font-weight: 700;
  line-height: 1.2;
}

.badge {
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--idle);
}

.dot.live {
  background: var(--green);
  box-shadow: 0 0 0 0 var(--green);
  animation: pulse 1.6s ease-out infinite;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--green) 60%, transparent); }
  100% { box-shadow: 0 0 0 8px transparent; }
}

.conversation {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.empty {
  margin: auto 8px;
  text-align: center;
  color: var(--muted);
}

.empty h2 {
  margin: 0 0 6px;
  color: var(--text);
  font-family: var(--font-title);
  font-size: 1.5rem;
}

.empty p {
  margin: 0;
}

.turn {
  display: flex;
  flex-direction: column;
  max-width: 85%;
  animation: appear 160ms ease-out;
}

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

.turn.assistant {
  align-self: flex-start;
}

.turn.caller {
  align-self: flex-end;
  align-items: flex-end;
}

.label {
  margin: 0 4px 4px;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.bubble {
  padding: 10px 14px;
  border-radius: 18px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.assistant .bubble {
  background: var(--assistant-bg);
  color: var(--assistant-text);
  border-bottom-left-radius: 6px;
}

.caller .bubble {
  background: var(--caller-bg);
  color: var(--caller-text);
  border-bottom-right-radius: 6px;
}

.caller.interim .bubble {
  background: transparent;
  color: var(--muted);
  border: 1.5px dashed var(--interim-border);
  font-style: italic;
}

.bubble .pending {
  opacity: 0.55;
}

.bubble .live-text {
  font-style: italic;
  opacity: 0.75;
}

.note {
  margin: 4px 6px 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.tool {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--tool-bg);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  animation: appear 160ms ease-out;
}

.tool summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  cursor: pointer;
  list-style: none;
}

.tool summary::-webkit-details-marker {
  display: none;
}

.tool summary::before {
  content: "▸";
  color: var(--muted);
  transition: transform 120ms ease;
}

.tool[open] summary::before {
  transform: rotate(90deg);
}

.tool-name {
  flex: 1;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pill {
  flex-shrink: 0;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--border);
  color: var(--muted);
  font-size: 0.72rem;
  white-space: nowrap;
}

.pill.ok {
  background: color-mix(in srgb, var(--green) 18%, transparent);
  color: var(--green);
}

.pill.failed {
  background: color-mix(in srgb, var(--red) 18%, transparent);
  color: var(--red);
}

.tool-body {
  padding: 0 12px 10px;
}

.tool-body h3 {
  margin: 8px 0 4px;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.tool-body pre {
  margin: 0;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--surface);
  overflow-x: auto;
  white-space: pre;
}

.footer {
  padding: 14px 20px 18px;
  border-top: 1px solid var(--border);
  text-align: center;
}

.call-button {
  width: 100%;
  padding: 14px 20px;
  border: 0;
  border-radius: 999px;
  background: var(--green);
  color: #fff;
  font-family: var(--font-body);
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 120ms ease;
}

.call-button:hover {
  background: var(--green-hover);
}

.call-button.end {
  background: var(--red);
}

.call-button.end:hover {
  background: var(--red-hover);
}

.call-button:disabled {
  opacity: 0.6;
  cursor: progress;
}

.call-button:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--text) 40%, transparent);
  outline-offset: 3px;
}

.hint {
  min-height: 1.3em;
  margin: 8px 0 0;
  color: var(--red);
  font-size: 0.85rem;
}

@media (max-width: 440px) {
  .phone {
    border-inline: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before {
    animation: none !important;
    transition: none !important;
  }
}
