:root {
  --bg: #0b141a;
  --panel: #111b21;
  --panel-2: #202c33;
  --bubble: #005c4b;
  --text: #e9edef;
  --muted: #8696a0;
  --green: #25d366;
  --green-dark: #1da851;
  --radius-card: 22px;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

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

html, body { height: 100%; }

body {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(120% 60% at 50% -10%, rgba(37, 211, 102, 0.18), transparent 60%),
    radial-gradient(80% 50% at 100% 110%, rgba(0, 92, 75, 0.35), transparent 70%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
}

.card {
  width: 100%;
  max-width: 400px;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius-card);
  overflow: hidden;
  box-shadow: 0 30px 80px -20px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(37, 211, 102, 0.05);
  animation: rise 0.6s var(--ease-out) both;
}

/* ---------- шапка чата ---------- */
.chat-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  background: var(--panel-2);
}

.avatar {
  width: 52px;
  height: 52px;
  flex: none;
  border-radius: 50%;
  display: grid;
  place-items: center;
  overflow: hidden;
  font-weight: 700;
  font-size: 20px;
  color: #fff;
  background: linear-gradient(135deg, var(--green), var(--bubble));
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }

.name { font-weight: 600; font-size: 16px; line-height: 1.3; }

.status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 0 rgba(37, 211, 102, 0.6);
  animation: ping 2s infinite;
}

/* ---------- сообщения ---------- */
.chat-body {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  padding: 22px 18px 8px;
  min-height: 150px;
  background:
    radial-gradient(circle at 1px 1px, rgba(255, 255, 255, 0.035) 1px, transparent 0) 0 0 / 18px 18px;
}

.bubble {
  max-width: 88%;
  padding: 9px 12px;
  font-size: 15px;
  line-height: 1.4;
  background: var(--panel-2);
  border-radius: 4px 12px 12px 12px;
  opacity: 0;
  animation: pop 0.45s var(--ease-out) forwards;
}
.bubble:empty { display: none; }
#greeting { animation-delay: 0.25s; }
#bubble { animation-delay: 0.7s; border-radius: 12px; }

.typing {
  display: inline-flex;
  gap: 4px;
  padding: 11px 13px;
  background: var(--panel-2);
  border-radius: 12px;
  opacity: 0;
  animation: pop 0.4s var(--ease-out) 1.2s forwards;
}
.typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: blink 1.2s infinite;
}
.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }

/* ---------- авторедирект ---------- */
.redirect { padding: 6px 18px 0; text-align: center; }
.redirect p { font-size: 15px; font-weight: 600; }
.redirect .hint { margin-top: 10px; font-size: 13px; font-weight: 400; color: var(--muted); }

.bar {
  height: 4px;
  margin-top: 10px;
  border-radius: 4px;
  overflow: hidden;
  background: var(--panel-2);
}
.bar-fill {
  height: 100%;
  background: var(--green);
  transform: scaleX(0);
  transform-origin: left;
  transition-property: transform;
  transition-timing-function: linear;
}
.bar-fill.is-running { transform: scaleX(1); }

/* ---------- кнопка ---------- */
.cta {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 16px 18px 20px;
  padding: 17px 20px;
  border-radius: 14px;
  font-size: 17px;
  font-weight: 700;
  color: #06290f;
  text-decoration: none;
  background: var(--green);
  box-shadow: 0 10px 30px -8px rgba(37, 211, 102, 0.65);
  transition: transform 0.15s var(--ease-out), background-color 0.15s, box-shadow 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.cta svg { width: 24px; height: 24px; flex: none; }
.cta::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: 0 0 0 0 rgba(37, 211, 102, 0.55);
  animation: ring 2.2s 1.6s infinite;
  pointer-events: none;
}
.cta:hover { background: #2fe072; transform: translateY(-1px); }
.cta:active { background: var(--green-dark); transform: scale(0.98); }
.cta:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }
.cta[hidden] { display: none; }

.is-auto .cta { margin-top: 14px; }

.is-error .bubble { background: #5c1f1f; }

/* ---------- анимации ---------- */
@keyframes rise { from { opacity: 0; transform: translateY(16px) scale(0.98); } }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(0.96); } to { opacity: 1; transform: none; } }
@keyframes blink { 0%, 80%, 100% { opacity: 0.3; } 40% { opacity: 1; } }
@keyframes ping { 70% { box-shadow: 0 0 0 7px rgba(37, 211, 102, 0); } 100% { box-shadow: 0 0 0 0 rgba(37, 211, 102, 0); } }
@keyframes ring { 70% { box-shadow: 0 0 0 12px rgba(37, 211, 102, 0); } 100% { box-shadow: 0 0 0 0 rgba(37, 211, 102, 0); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .bubble, .typing { opacity: 1; }
}
