/* ── Reset & tokens ───────────────────────────────────────────────────── */

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

:root {
  --bg:            #f2f2f7;
  --surface:       #ffffff;
  --primary:       #007aff;
  --danger:        #ff3b30;
  --success:       #34c759;
  --text:          #1d1d1f;
  --text-muted:    #6e6e73;
  --border:        rgba(0,0,0,0.10);
  --bubble-user:   #007aff;
  --bubble-agent:  #e5e5ea;
  --text-user:     #ffffff;
  --text-agent:    #1d1d1f;
  --radius-bubble: 18px;
  --shadow:        0 8px 32px rgba(0,0,0,0.10);
}

/* ── Layout ───────────────────────────────────────────────────────────── */

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.app {
  width: 100%;
  max-width: 480px;
  height: 100dvh;
  max-height: 820px;
  background: var(--surface);
  border-radius: 28px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Header ───────────────────────────────────────────────────────────── */

.header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.header-icon { font-size: 26px; }

.header h1 {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.3px;
}

.header-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 1px;
}

/* ── Selector screen ─────────────────────────────────────────────────── */

.selector {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 32px 20px;
}

.selector-label {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.2px;
}

.selector-cards {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: center;
}

.card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 148px;
  padding: 24px 16px 20px;
  background: var(--bg);
  border: 2px solid transparent;
  border-radius: 20px;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.12s, box-shadow 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.card:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0,122,255,0.15);
}

.card:active { transform: translateY(0); }

.card-icon  { font-size: 36px; line-height: 1; }
.card-name  { font-size: 14px; font-weight: 600; color: var(--text); }
.card-desc  { font-size: 12px; color: var(--text-muted); text-align: center; }

/* ── Voice picker ────────────────────────────────────────────────────── */

.voice-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  max-width: 320px;
  padding: 0 4px;
}

.voice-icon {
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.voice-select {
  flex: 1;
  padding: 8px 12px;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236e6e73' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.voice-select:focus {
  border-color: rgba(0,122,255,0.4);
  box-shadow: 0 0 0 3px rgba(0,122,255,0.08);
}

/* ── Chat thread ──────────────────────────────────────────────────────── */

.chat {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scroll-behavior: smooth;
}

.chat::-webkit-scrollbar { width: 4px; }
.chat::-webkit-scrollbar-track { background: transparent; }
.chat::-webkit-scrollbar-thumb { background: #c7c7cc; border-radius: 2px; }

.message {
  display: flex;
  max-width: 80%;
}

.message.user      { align-self: flex-end; }
.message.assistant { align-self: flex-start; }

.bubble {
  padding: 10px 14px;
  border-radius: var(--radius-bubble);
  font-size: 15px;
  line-height: 1.5;
}

.message.user .bubble {
  background: var(--bubble-user);
  color: var(--text-user);
  border-bottom-right-radius: 4px;
}

.message.assistant .bubble {
  background: var(--bubble-agent);
  color: var(--text-agent);
  border-bottom-left-radius: 4px;
}

/* Typing indicator */
.typing {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 12px 16px;
  background: var(--bubble-agent);
  border-radius: var(--radius-bubble);
  border-bottom-left-radius: 4px;
  width: fit-content;
}

.typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: bounce 1.3s ease-in-out infinite;
}
.typing span:nth-child(2) { animation-delay: 0.18s; }
.typing span:nth-child(3) { animation-delay: 0.36s; }

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0);    opacity: 0.5; }
  30%            { transform: translateY(-6px); opacity: 1;   }
}

/* Success banner */
.done-banner {
  align-self: center;
  background: var(--success);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  padding: 10px 20px;
  border-radius: 20px;
  margin: 4px 0;
}

/* ── Footer / input bar ───────────────────────────────────────────────── */

.footer {
  border-top: 1px solid var(--border);
  padding: 10px 14px calc(14px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}

.status {
  font-size: 12px;
  color: var(--text-muted);
  min-height: 16px;
  text-align: center;
  transition: color 0.2s;
}

.status.error { color: var(--danger); }
.status:empty { display: none; }

.input-bar {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 22px;
  padding: 8px 8px 8px 14px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.input-bar:focus-within {
  border-color: rgba(0,122,255,0.4);
  box-shadow: 0 0 0 3px rgba(0,122,255,0.08);
}

/* Recording state: red tint */
.input-bar.recording {
  border-color: rgba(255,59,48,0.5);
  box-shadow: 0 0 0 3px rgba(255,59,48,0.08);
}

.text-input {
  flex: 1;
  border: none;
  background: transparent;
  resize: none;
  font-family: inherit;
  font-size: 15px;
  color: var(--text);
  line-height: 1.5;
  max-height: 120px;
  outline: none;
  padding: 0;
}

.text-input::placeholder { color: var(--text-muted); }
.text-input:disabled { opacity: 0.5; }

.input-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

/* ── Mic button (small) ───────────────────────────────────────────────── */

.mic-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: transparent;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.mic-btn:hover:not(:disabled) {
  background: rgba(0,0,0,0.06);
  color: var(--primary);
}

.mic-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.mic-btn[data-state="recording"] {
  color: var(--danger);
  animation: mic-pulse 1.4s ease-in-out infinite;
}

@keyframes mic-pulse {
  0%, 100% { transform: scale(1); }
  50%       { transform: scale(1.15); }
}

.mic-icon {
  width: 18px;
  height: 18px;
  fill: currentColor;
  pointer-events: none;
  position: relative;
  z-index: 1;
}

.mic-ring {
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  border: 2px solid var(--danger);
  opacity: 0;
  pointer-events: none;
}

.mic-btn[data-state="recording"] .mic-ring {
  animation: ring-pulse 1s ease-out infinite;
}

@keyframes ring-pulse {
  0%   { transform: scale(1);    opacity: 0.6; }
  100% { transform: scale(1.7);  opacity: 0;   }
}

/* ── Send button ──────────────────────────────────────────────────────── */

.send-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--primary);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.send-btn svg { width: 15px; height: 15px; }

.send-btn:hover:not(:disabled) { background: #0063d1; }
.send-btn:active:not(:disabled) { transform: scale(0.92); }

.send-btn:disabled {
  background: #c7c7cc;
  cursor: not-allowed;
}

/* ── Responsive: full-screen on small devices ─────────────────────────── */

@media (max-width: 520px) {
  .app { border-radius: 0; max-height: 100dvh; }
}
