/* ── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0a0a0f;
  --surface:   #13131a;
  --border:    #1e1e2e;
  --text:      #e2e2f0;
  --muted:     #6b6b8a;
  --accent:    #7c6af7;
  --accent-glow: rgba(124, 106, 247, 0.35);
  --danger:    #f77c6a;
  --success:   #6af7b0;
  --radius:    12px;
  --safe-top:  env(safe-area-inset-top, 0px);
  --safe-bot:  env(safe-area-inset-bottom, 0px);
}

/* ── Login screen ────────────────────────────────────────────────────────── */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: var(--bg);
}
.login-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}
.login-box h2 {
  color: var(--text);
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}
.login-box input {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 1rem;
  padding: 0.75rem 1rem;
  width: 240px;
  text-align: center;
}
.login-box input:focus {
  outline: none;
  border-color: var(--accent);
}
.login-box button {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  padding: 0.6rem 2rem;
  cursor: pointer;
  transition: opacity 0.2s;
}
.login-box button:active { opacity: 0.7; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

/* ── Layout ───────────────────────────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bot);
}

header {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: relative;  /* anchor new-chat-btn absolute positioning */
}

.header-spacer { width: 32px; }  /* mirror of new-chat-btn to keep status centered */

#new-chat-btn {
  position: absolute;
  right: 16px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
  -webkit-user-select: none;
  user-select: none;
}
#new-chat-btn:hover  { color: var(--text); border-color: var(--accent); }
#new-chat-btn:active { background: var(--surface); }
#new-chat-btn.flash  { color: var(--success); border-color: var(--success); }

#chat-panel {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  -webkit-overflow-scrolling: touch;
}

footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 24px 16px;
  flex-shrink: 0;
  border-top: 1px solid var(--border);
}

/* ── Status chip ─────────────────────────────────────────────────────────── */
.status {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 4px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  transition: all 0.2s;
}
.status-transcribing { color: var(--accent); border-color: var(--accent); }
.status-thinking     { color: #f7c26a;       border-color: #f7c26a; }
.status-speaking     { color: var(--success); border-color: var(--success); }
.status-error        { color: var(--danger);  border-color: var(--danger); }
.status-listening    { color: #6af7d0;       border-color: #6af7d0; animation: pulse-border 1.5s ease-in-out infinite; }

@keyframes pulse-border {
  0%, 100% { border-color: #6af7d0; opacity: 1; }
  50%       { border-color: #6af7d0; opacity: 0.5; }
}

/* ── Chat bubbles ────────────────────────────────────────────────────────── */
.bubble {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: var(--radius);
  line-height: 1.45;
  font-size: 15px;
  word-break: break-word;
  animation: bubble-in 0.15s ease-out;
}
.bubble-user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.bubble-assistant {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.bubble-error {
  align-self: center;
  background: transparent;
  border: 1px solid var(--danger);
  color: var(--danger);
  font-size: 13px;
}

@keyframes bubble-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.chat-sep {
  align-self: center;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.05em;
  padding: 4px 0;
  opacity: 0.6;
}

/* ── PTT button ──────────────────────────────────────────────────────────── */
#ptt-btn {
  position: relative;
  width: 100px;
  height: 100px;
  border-radius: 50%;
  border: none;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  outline: none;
  transition: transform 0.1s, background 0.15s;
  -webkit-user-select: none;
  user-select: none;
  box-shadow: 0 0 0 2px var(--border);
}

.ptt-ring {
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  opacity: 0;
  transition: opacity 0.15s;
  pointer-events: none;
}

.ptt-icon  { font-size: 28px; line-height: 1; pointer-events: none; }
.ptt-label { font-size: 11px; color: var(--muted); pointer-events: none; }

#ptt-btn.active {
  background: var(--accent);
  transform: scale(1.06);
  box-shadow: 0 0 24px var(--accent-glow);
}
#ptt-btn.active .ptt-ring  { opacity: 1; animation: ring-pulse 1s ease-in-out infinite; }
#ptt-btn.active .ptt-label { color: rgba(255,255,255,0.8); }

@keyframes ring-pulse {
  0%, 100% { transform: scale(1);    opacity: 1; }
  50%       { transform: scale(1.12); opacity: 0.5; }
}

/* PTT button — busy state (response in progress, not recording) */
#ptt-btn.busy {
  box-shadow: 0 0 0 2px var(--accent);
}
#ptt-btn.busy .ptt-ring {
  opacity: 0.3;
  animation: ring-pulse 2.4s ease-in-out infinite;
}
#ptt-btn.busy .ptt-label { color: var(--accent); }

/* PTT button — ready-flash (response fully complete, audio drained) */
#ptt-btn.ready-flash {
  background: rgba(106, 247, 176, 0.12);
  box-shadow: 0 0 18px rgba(106, 247, 176, 0.3);
}
@keyframes ready-flash {
  from { box-shadow: 0 0 20px rgba(106, 247, 176, 0.5); }
  to   { box-shadow: 0 0 0 rgba(106, 247, 176, 0); }
}

/* ── Waveform visual ─────────────────────────────────────────────────────── */
#waveform {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  height: 20px;
  pointer-events: none;
}

.wave-bar {
  width: 4px;
  min-height: 3px;
  height: 15%;
  border-radius: 2px;
  background: var(--muted);
  transition: height 0.1s ease-out;
}

#ptt-btn.active .wave-bar {
  background: rgba(255, 255, 255, 0.7);
}