:root {
  --bg: #0b0c10;
  --bg-elevated: #15171f;
  --bg-elevated-2: #1c1f2a;
  --text: #f4f4f7;
  --text-dim: #9498a8;
  --accent: #7c5cff;
  --accent-2: #9d85ff;
  --accent-glow: rgba(124, 92, 255, 0.45);
  --danger: #ff5470;
  --danger-bg: rgba(255, 84, 112, 0.12);
  --ok: #33d69f;
  --radius-lg: 28px;
  --radius-md: 16px;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  background: radial-gradient(circle at 50% 0%, #14151d 0%, var(--bg) 55%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 28px;
  padding: 24px 20px calc(24px + env(safe-area-inset-bottom));
  text-align: center;
}

.brand {
  position: absolute;
  top: max(20px, env(safe-area-inset-top));
  left: 0;
  right: 0;
  pointer-events: none;
}

.brand h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.35em;
  color: var(--text-dim);
}

/* Connection indicator */
.conn-indicator {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  right: 16px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--bg-elevated);
  border: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 11px;
  color: var(--text-dim);
  z-index: 20;
}

.conn-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
  flex-shrink: 0;
  transition: background 0.25s ease;
}

.conn-indicator.connected .conn-dot {
  background: var(--ok);
  box-shadow: 0 0 8px var(--ok);
}

.conn-indicator.connecting .conn-dot {
  background: #f5b942;
  box-shadow: 0 0 8px #f5b942;
  animation: blink 1s ease-in-out infinite;
}

.conn-indicator.disconnected .conn-dot {
  background: var(--danger);
  box-shadow: 0 0 8px var(--danger);
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* Error / status banner */
.banner {
  position: fixed;
  top: max(56px, calc(env(safe-area-inset-top) + 52px));
  left: 16px;
  right: 16px;
  max-width: 420px;
  margin: 0 auto;
  background: var(--danger-bg);
  border: 1px solid rgba(255, 84, 112, 0.35);
  color: #ffc2ce;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 13.5px;
  line-height: 1.4;
  z-index: 30;
  animation: slide-down 0.25s ease;
  text-align: left;
}

@keyframes slide-down {
  from { transform: translateY(-12px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* Mic stage */
.stage {
  position: relative;
  width: 220px;
  height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.rings {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ring {
  position: absolute;
  border-radius: 50%;
  border: 1.5px solid var(--accent);
  opacity: 0;
  width: 140px;
  height: 140px;
}

body.state-listening .ring {
  animation: pulse-ring 2.2s ease-out infinite;
}

body.state-listening .ring-2 { animation-delay: 0.5s; }
body.state-listening .ring-3 { animation-delay: 1s; }

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

body.state-thinking .rings,
body.state-transcribing .rings {
  animation: spin 1.6s linear infinite;
}

body.state-thinking .ring-1,
body.state-transcribing .ring-1 {
  opacity: 1;
  border-color: transparent;
  border-top-color: var(--accent);
  border-right-color: var(--accent);
  width: 168px;
  height: 168px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

body.state-speaking .ring {
  opacity: 0.5;
  width: 150px;
  height: 150px;
  animation: speak-pulse 1.1s ease-in-out infinite;
}
body.state-speaking .ring-2 { animation-delay: 0.2s; }
body.state-speaking .ring-3 { animation-delay: 0.4s; }

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

/* Mic button */
.mic-button {
  position: relative;
  width: 124px;
  height: 124px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  background: linear-gradient(160deg, var(--accent-2), var(--accent) 70%);
  box-shadow: 0 8px 30px var(--accent-glow), inset 0 1px 1px rgba(255, 255, 255, 0.25);
  transition: transform 0.15s ease, box-shadow 0.25s ease, filter 0.25s ease;
  z-index: 5;
  -webkit-tap-highlight-color: transparent;
}

.mic-button svg {
  width: 42px;
  height: 42px;
}

.mic-button:active {
  transform: scale(0.94);
}

body.state-listening .mic-button {
  background: linear-gradient(160deg, #ff7a90, var(--danger) 70%);
  box-shadow: 0 8px 30px rgba(255, 84, 112, 0.45), inset 0 1px 1px rgba(255, 255, 255, 0.25);
}

body.state-thinking .mic-button,
body.state-transcribing .mic-button,
body.state-speaking .mic-button {
  filter: brightness(0.75) saturate(0.8);
  cursor: default;
}

body.disconnected .mic-button {
  filter: grayscale(0.6) brightness(0.55);
  cursor: not-allowed;
}

.status-text {
  margin: 0;
  font-size: 16px;
  font-weight: 500;
  color: var(--text-dim);
  min-height: 22px;
  transition: color 0.2s ease;
}

body.state-listening .status-text { color: var(--danger); }
body.state-thinking .status-text,
body.state-transcribing .status-text,
body.state-speaking .status-text { color: var(--accent-2); }

/* Transcript */
.transcript {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bubble {
  border-radius: var(--radius-md);
  padding: 12px 16px;
  text-align: left;
  font-size: 14.5px;
  line-height: 1.45;
  background: var(--bg-elevated);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.bubble-label {
  display: block;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.bubble-user .bubble-label { color: var(--accent-2); }
.bubble-assistant {
  background: var(--bg-elevated-2);
}
.bubble-assistant .bubble-label { color: var(--ok); }

.bubble p {
  margin: 0;
  color: var(--text);
  white-space: pre-wrap;
}

@media (max-width: 380px) {
  .stage { width: 190px; height: 190px; }
  .mic-button { width: 108px; height: 108px; }
}
