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

:root {
  --bg: #0e0e0f;
  --surface: #1a1a1e;
  --surface2: #242428;
  --border: #2e2e34;
  --accent: #9b6fff;
  --accent-dim: rgba(155, 111, 255, 0.15);
  --text: #f0f0f2;
  --text-muted: #8a8a96;
  --bubble-ai: #1e1e26;
  --bubble-user: #9b6fff;
  --bubble-user-text: #ffffff;
  --danger: #ff4f4f;
  --green: #3ddc84;
  --radius-bubble: 18px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

/* ── SCREENS ── */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.screen.active {
  opacity: 1;
  pointer-events: all;
}

/* ── CHAT HEADER ── */
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding-top: max(14px, env(safe-area-inset-top));
  flex-shrink: 0;
}

.avatar-wrap {
  position: relative;
  flex-shrink: 0;
}

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--accent-dim);
  display: block;
}

.status-dot {
  position: absolute;
  bottom: 1px;
  right: 1px;
  width: 11px;
  height: 11px;
  background: var(--green);
  border-radius: 50%;
  border: 2px solid var(--surface);
}

.header-info {
  flex: 1;
  min-width: 0;
}

.header-info h1 {
  font-size: 16px;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

.status-text {
  font-size: 12px;
  color: var(--green);
  margin-top: 1px;
}

.call-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--accent-dim);
  color: var(--accent);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  flex-shrink: 0;
}

.call-btn:hover {
  background: rgba(155, 111, 255, 0.28);
}

/* ── MESSAGES ── */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overscroll-behavior: contain;
}

.messages::-webkit-scrollbar {
  width: 0;
}

.msg {
  display: flex;
  flex-direction: column;
  max-width: 78%;
}

.msg.ai {
  align-self: flex-start;
  align-items: flex-start;
}

.msg.user {
  align-self: flex-end;
  align-items: flex-end;
}

.msg p {
  padding: 11px 15px;
  border-radius: var(--radius-bubble);
  font-size: 15px;
  line-height: 1.45;
  word-break: break-word;
}

.msg.ai p {
  background: var(--bubble-ai);
  color: var(--text);
  border-bottom-left-radius: 5px;
}

.msg.user p {
  background: var(--bubble-user);
  color: var(--bubble-user-text);
  border-bottom-right-radius: 5px;
}

.msg .time {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  padding: 0 4px;
}

/* typing indicator */
.msg.typing p {
  padding: 14px 18px;
}

.dots {
  display: flex;
  gap: 5px;
  align-items: center;
}

.dots span {
  width: 7px;
  height: 7px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: blink 1.2s infinite;
}

.dots span:nth-child(2) { animation-delay: 0.2s; }
.dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes blink {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1); }
}

/* ── PAYWALL BANNER ── */
.paywall-banner {
  background: linear-gradient(135deg, #1a1230 0%, #1e1428 100%);
  border-top: 1px solid var(--accent);
  padding: 16px 20px;
  text-align: center;
  flex-shrink: 0;
}

.paywall-banner p {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.unlock-btn {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  padding: 11px 24px;
  border-radius: 50px;
  text-decoration: none;
  letter-spacing: -0.01em;
  transition: opacity 0.2s;
}

.unlock-btn:hover {
  opacity: 0.85;
}

/* ── INPUT BAR ── */
.input-bar {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

#msgInput {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 10px 16px;
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.4;
  resize: none;
  outline: none;
  max-height: 120px;
  overflow-y: auto;
  transition: border-color 0.2s;
}

#msgInput:focus {
  border-color: var(--accent);
}

#msgInput::placeholder {
  color: var(--text-muted);
}

#sendBtn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.2s, transform 0.15s;
}

#sendBtn:hover { opacity: 0.85; }
#sendBtn:active { transform: scale(0.93); }

/* ── CALL SCREEN ── */
#screen-call {
  background: #0a0a12;
  align-items: center;
  justify-content: flex-start;
}

.call-bg {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 30%, rgba(155,111,255,0.18) 0%, transparent 70%);
  pointer-events: none;
}

.call-content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  padding-top: max(60px, env(safe-area-inset-top) + 40px);
  padding-bottom: max(40px, env(safe-area-inset-bottom) + 20px);
  flex: 1;
  justify-content: space-between;
}

.call-avatar-wrap {
  position: relative;
  width: 130px;
  height: 130px;
}

.call-avatar {
  width: 130px;
  height: 130px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--accent-dim);
  display: block;
  border: 3px solid rgba(155,111,255,0.4);
}

.call-pulse {
  position: absolute;
  inset: -8px;
  border-radius: 50%;
  border: 2px solid rgba(155,111,255,0.35);
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.4; transform: scale(1); }
  50% { opacity: 0.15; transform: scale(1.08); }
}

.call-name {
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-top: 24px;
}

.call-status {
  font-size: 15px;
  color: var(--text-muted);
  margin-top: 6px;
}

.call-timer {
  font-size: 14px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  margin-top: 4px;
  letter-spacing: 0.04em;
}

/* AI speaking bars */
.ai-speaking-indicator {
  display: flex;
  gap: 5px;
  align-items: flex-end;
  height: 36px;
  margin-top: 20px;
}

.ai-speaking-indicator span {
  width: 5px;
  background: var(--accent);
  border-radius: 3px;
  animation: sound-bar 1s ease-in-out infinite;
}

.ai-speaking-indicator span:nth-child(1) { height: 14px; animation-delay: 0s; }
.ai-speaking-indicator span:nth-child(2) { height: 26px; animation-delay: 0.1s; }
.ai-speaking-indicator span:nth-child(3) { height: 36px; animation-delay: 0.2s; }
.ai-speaking-indicator span:nth-child(4) { height: 26px; animation-delay: 0.3s; }
.ai-speaking-indicator span:nth-child(5) { height: 14px; animation-delay: 0.4s; }

@keyframes sound-bar {
  0%, 100% { transform: scaleY(0.4); opacity: 0.5; }
  50% { transform: scaleY(1); opacity: 1; }
}

/* Listening ring */
.listening-indicator {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-top: 20px;
}

.listen-ring {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 3px solid var(--accent);
  animation: listen-pulse 1s ease-in-out infinite;
}

.listening-indicator p {
  font-size: 14px;
  color: var(--accent);
  letter-spacing: 0.05em;
}

@keyframes listen-pulse {
  0%, 100% { transform: scale(1); opacity: 0.6; box-shadow: 0 0 0 0 rgba(155,111,255,0.4); }
  50% { transform: scale(1.1); opacity: 1; box-shadow: 0 0 0 12px rgba(155,111,255,0); }
}

/* Call controls */
.call-controls {
  display: flex;
  gap: 32px;
  align-items: center;
  margin-top: 40px;
}

.ctrl-btn {
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s, opacity 0.2s;
}

.ctrl-btn:active { transform: scale(0.9); }

.mute-btn, .speaker-btn {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--surface2);
  color: var(--text);
}

.mute-btn.muted, .speaker-btn.active {
  background: var(--accent-dim);
  color: var(--accent);
}

.end-btn {
  width: 70px;
  height: 70px;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
}

/* ── UTILITIES ── */
.hidden {
  display: none !important;
}
