/* Mahalla — warm indigo night with a ceramic-blue accent, loosely after Uzbek
   suzani/ceramic palettes. One accent hue, one warm neutral, nothing else. */

:root {
  --ink: #0b1020;
  --ink-2: #121a33;
  --surface: rgba(255, 255, 255, 0.055);
  --surface-2: rgba(255, 255, 255, 0.09);
  --line: rgba(255, 255, 255, 0.11);
  --text: #eef1f8;
  --muted: #98a3c0;
  --accent: #4cc9d8;
  --accent-2: #7aa2ff;
  --warm: #e8b04b;
  --danger: #ff7a7a;
  --radius: 20px;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Inter, sans-serif;
}

* { box-sizing: border-box; }

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

body {
  display: flex;
  flex-direction: column;
  background: radial-gradient(1200px 700px at 50% -10%, #1b2547 0%, var(--ink) 55%, #070a15 100%);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Slow-breathing glow behind everything; pinned so it never affects layout. */
.aura {
  position: fixed;
  left: 50%;
  bottom: -22vmin;
  width: 90vmin;
  height: 90vmin;
  translate: -50% 0;
  background: radial-gradient(circle, rgba(76, 201, 216, 0.16), transparent 62%);
  filter: blur(28px);
  pointer-events: none;
  animation: breathe 9s ease-in-out infinite;
}

@keyframes breathe {
  0%, 100% { opacity: 0.55; scale: 1; }
  50%      { opacity: 0.9;  scale: 1.08; }
}

/* ── header ───────────────────────────────────────────────────────── */

.top {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px clamp(16px, 4vw, 34px);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 13px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: block;
  box-shadow: 0 0 0 1px rgba(76, 201, 216, 0.35), 0 0 20px rgba(76, 201, 216, 0.3);
}

.top h1 {
  margin: 0;
  font-size: 1.06rem;
  font-weight: 640;
  letter-spacing: 0.2px;
}

.tagline {
  margin: 0;
  font-size: 0.76rem;
  color: var(--muted);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.badge {
  padding: 5px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.72rem;
  white-space: nowrap;
}

.badge[data-engine="server"] { color: var(--accent); border-color: rgba(76, 201, 216, 0.4); }
.badge[data-engine="browser"] { color: var(--warm); border-color: rgba(232, 176, 75, 0.4); }
.badge[data-engine="none"] { color: var(--danger); border-color: rgba(255, 122, 122, 0.4); }

.ghost-btn {
  padding: 7px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.18s, border-color 0.18s;
}

.ghost-btn:hover { background: var(--surface-2); border-color: rgba(255, 255, 255, 0.22); }

/* ── transcript ───────────────────────────────────────────────────── */

.transcript {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.16) transparent;
  padding: 26px clamp(16px, 4vw, 34px) 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.transcript::-webkit-scrollbar { width: 8px; }
.transcript::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.16);
  border-radius: 99px;
}

/* An assistant turn is her avatar plus the bubble, so every answer is visibly
   attributed to her. User turns are a bare bubble on the other side. */
.turn {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  align-self: flex-start;
  max-width: min(720px, 88%);
  animation: rise 0.32s cubic-bezier(0.22, 1, 0.36, 1) both;
}

/* The halo owns the scale and the glow; the image inside stays untransformed. */
.avatar-halo {
  position: relative;
  flex: none;
  width: 48px;
  height: 48px;
  margin-top: 3px;
  /* Scaled rather than resized: growing the box would reflow the bubble and
     make the streaming text jump while she is mid-sentence. */
  transform-origin: center center;
  transition: transform 0.32s cubic-bezier(0.22, 1, 0.36, 1);
  will-change: transform;
}

.turn.speaking .avatar-halo {
  transform: scale(2.1);
  z-index: 2;
}

.turn .avatar {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  background: var(--ink-2);
  box-shadow: 0 0 0 1px var(--line);
  transition: box-shadow 0.3s;
}

/* Two layers behind her: a soft breathing bloom, and a ring that pulses out.
   Both sit under the image (z-index 1) so they read as light coming off her. */
.avatar-halo::before,
.avatar-halo::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
}

.avatar-halo::before {
  background: radial-gradient(circle, rgba(76, 201, 216, 0.6), rgba(76, 201, 216, 0) 70%);
  filter: blur(5px);
  transform: scale(1.45);
}

.avatar-halo::after {
  border: 2px solid rgba(76, 201, 216, 0.65);
}

.turn.speaking .avatar {
  box-shadow: 0 0 0 2px rgba(76, 201, 216, 0.8), 0 0 26px rgba(76, 201, 216, 0.55);
}

.turn.speaking .avatar-halo::before {
  opacity: 1;
  animation: halo-breathe 1.7s ease-in-out infinite;
}

.turn.speaking .avatar-halo::after {
  opacity: 1;
  animation: halo-ripple 1.9s cubic-bezier(0.16, 0.8, 0.4, 1) infinite;
}

@keyframes halo-breathe {
  0%, 100% { opacity: 0.5; transform: scale(1.36); }
  50%      { opacity: 1;   transform: scale(1.6); }
}

/* Ripple reach is bounded: .transcript scrolls, so anything wider than the
   left margin below gets clipped at the edge. */
@keyframes halo-ripple {
  0%        { opacity: 0.65; transform: scale(1); }
  75%, 100% { opacity: 0;    transform: scale(1.75); }
}

.turn .msg {
  align-self: auto;
  max-width: 100%;
  animation: none;
}

/* Room for the enlarged avatar and its glow to bloom without colliding. */
.turn.speaking { margin: 26px 0 26px 40px; }

.msg {
  max-width: min(680px, 82%);
  padding: 12px 17px;
  border-radius: var(--radius);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  animation: rise 0.32s cubic-bezier(0.22, 1, 0.36, 1) both;
}

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

.msg.user {
  align-self: flex-end;
  background: linear-gradient(140deg, rgba(122, 162, 255, 0.26), rgba(76, 201, 216, 0.2));
  border: 1px solid rgba(122, 162, 255, 0.3);
  border-bottom-right-radius: 7px;
}

.msg.assistant {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--line);
  border-bottom-left-radius: 7px;
}

.msg.assistant.speaking {
  border-color: rgba(76, 201, 216, 0.5);
  box-shadow: 0 0 0 1px rgba(76, 201, 216, 0.22), 0 0 34px rgba(76, 201, 216, 0.13);
}

/* Replay button under each assistant turn. */
.replay {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 9px;
  padding: 3px 10px 3px 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.72rem;
  cursor: pointer;
  transition: color 0.16s, border-color 0.16s;
}

.replay:hover { color: var(--accent); border-color: rgba(76, 201, 216, 0.45); }
.replay svg { width: 13px; height: 13px; fill: currentColor; }

/* Three-dot thinking indicator. */
.dots { display: inline-flex; gap: 5px; padding: 4px 2px; }
.dots i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  animation: blink 1.25s ease-in-out infinite;
}
.dots i:nth-child(2) { animation-delay: 0.18s; }
.dots i:nth-child(3) { animation-delay: 0.36s; }

@keyframes blink {
  0%, 80%, 100% { opacity: 0.28; transform: translateY(0); }
  40%           { opacity: 1;    transform: translateY(-3px); }
}

/* ── banner ───────────────────────────────────────────────────────── */

.banner {
  flex: none;
  margin: 0 clamp(16px, 4vw, 34px) 4px;
  padding: 12px 15px;
  border: 1px solid rgba(255, 122, 122, 0.38);
  border-radius: 14px;
  background: rgba(255, 122, 122, 0.1);
  color: #ffdada;
  font-size: 0.83rem;
  white-space: pre-wrap;
}

.banner code {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.32);
  font-size: 0.95em;
}

/* ── stage (status + orb + input) ─────────────────────────────────── */

.stage {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 6px clamp(16px, 4vw, 34px) max(18px, env(safe-area-inset-bottom));
}

.status {
  margin: 0;
  min-height: 1.3em;
  color: var(--muted);
  font-size: 0.84rem;
  text-align: center;
  transition: color 0.2s;
}

.status[data-state="listening"] { color: var(--accent); }
.status[data-state="speaking"]  { color: var(--accent-2); }
.status[data-state="error"]     { color: var(--danger); }

.orb-wrap {
  position: relative;
  width: 160px;
  height: 160px;
  display: grid;
  place-items: center;
}

/* Canvas is larger than the orb so the reactive ring has room to bloom. */
.viz {
  position: absolute;
  inset: -80px;
  width: 320px;
  height: 320px;
  pointer-events: none;
}

.orb {
  position: relative;
  width: 112px;
  height: 112px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(150deg, #5ad3e2, #4a7dff 78%);
  box-shadow: 0 14px 40px rgba(74, 125, 255, 0.4), inset 0 -6px 18px rgba(0, 0, 0, 0.22);
  color: #06101f;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform 0.2s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.2s, filter 0.2s;
}

.orb:hover { transform: scale(1.045); }
.orb:active { transform: scale(0.97); }

.orb:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 6px;
}

.orb[disabled] {
  filter: grayscale(0.55) brightness(0.7);
  cursor: not-allowed;
  transform: none;
}

.orb.recording {
  background: linear-gradient(150deg, #ff8e8e, #ff5f7a 78%);
  box-shadow: 0 14px 44px rgba(255, 95, 122, 0.45), inset 0 -6px 18px rgba(0, 0, 0, 0.22);
}

.orb-icon {
  position: absolute;
  width: 40px;
  height: 40px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: opacity 0.16s, transform 0.16s;
}

.stop-icon { fill: currentColor; stroke: none; }

.orb .stop-icon { opacity: 0; transform: scale(0.7); }
.orb.recording .mic-icon { opacity: 0; transform: scale(0.7); }
.orb.recording .stop-icon { opacity: 1; transform: none; }

/* ── text input ───────────────────────────────────────────────────── */

.text-form {
  display: flex;
  align-items: center;
  gap: 8px;
  width: min(560px, 100%);
  padding: 5px 5px 5px 17px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  transition: border-color 0.18s, background 0.18s;
}

.text-form:focus-within {
  border-color: rgba(76, 201, 216, 0.5);
  background: var(--surface-2);
}

#text-input {
  flex: 1;
  min-width: 0;
  border: none;
  background: none;
  color: var(--text);
  font: inherit;
  font-size: 0.92rem;
  padding: 9px 0;
}

#text-input:focus { outline: none; }
#text-input::placeholder { color: var(--muted); }

.send-btn {
  flex: none;
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.18s, color 0.18s;
}

.send-btn:hover { background: var(--accent); color: #06101f; }
.send-btn svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

@media (max-width: 520px) {
  .tagline { display: none; }
  .msg { max-width: 90%; }
  .orb-wrap { width: 132px; height: 132px; }
  .orb { width: 96px; height: 96px; }
}

@media (prefers-reduced-motion: reduce) {
  .aura { animation: none; }
  .msg, .turn { animation: none; }
  .dots i { animation: none; opacity: 0.6; }
  /* Keep a steady glow as the speaking cue; drop the growth and the pulsing. */
  .avatar-halo { transition: none; }
  .turn.speaking .avatar-halo { transform: none; }
  .turn.speaking .avatar-halo::before,
  .turn.speaking .avatar-halo::after { animation: none; }
  .turn.speaking { margin: 0; }
}
