:root { color-scheme: dark; }
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: #101216;
  color: #e8eaed;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
}

/* Общий каркас: фиксированная высота экрана, чат скроллится внутри */
.app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ---------- Сцена ---------- */

.scene-wrap {
  position: sticky; /* сцена всегда остаётся сверху */
  top: 0;
  z-index: 5;
  flex: none;
  background: #101216;
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
  border-bottom: 1px solid #1e2128;
}
#stage {
  position: relative;
  width: min(100%, 420px, 60dvh);
  aspect-ratio: 1;
  margin: 0 auto;
  border-radius: 16px;
  overflow: hidden;
  background: #000;
  box-shadow: 0 8px 32px rgba(0, 0, 0, .6);
}
#stage video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
}
#stage video.active { opacity: 1; }
#stage-hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #6b7078;
  font-size: 14px;
  padding: 0 16px;
  text-align: center;
}
#latency {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 2;
  background: rgba(0, 0, 0, .65);
  padding: 4px 10px;
  border-radius: 8px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
#latency b { color: #5dd39e; font-weight: 600; }

/* ---------- Чат ---------- */

.chat-col {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.chat-head {
  flex: none;
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 12px 16px 4px;
}
.brand {
  font-weight: 700;
  letter-spacing: .12em;
  font-size: 14px;
  color: #5dd39e;
}
.sub { font-size: 12px; color: #6b7078; }
#chat {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px 14px;
  -webkit-overflow-scrolling: touch;
}
.msg {
  max-width: 84%;
  padding: 10px 14px;
  border-radius: 16px;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg.user {
  align-self: flex-end;
  background: rgba(93, 211, 158, .14);
  border: 1px solid rgba(93, 211, 158, .4);
  border-bottom-right-radius: 6px;
}
.msg.bot {
  align-self: flex-start;
  background: #1e2128;
  border: 1px solid #34383f;
  border-bottom-left-radius: 6px;
}
.msg.typing { display: flex; gap: 5px; padding: 13px 16px; }
.msg.typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #5dd39e;
  animation: blink 1.2s infinite;
}
.msg.typing span:nth-child(2) { animation-delay: .2s; }
.msg.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink {
  0%, 70%, 100% { opacity: .25; }
  35% { opacity: 1; }
}

/* ---------- Поле ввода ---------- */

#composer {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: #101216;
  border-top: 1px solid #1e2128;
}
#text {
  flex: 1;
  min-width: 0;
  background: #1e2128;
  color: #e8eaed;
  border: 1px solid #34383f;
  border-radius: 14px;
  padding: 14px 16px;
  font-size: 16px; /* 16px — чтобы iOS не приближал поле при фокусе */
  font-family: inherit;
  outline: none;
}
#text:focus { border-color: #5dd39e; }
#text::placeholder { color: #6b7078; }
.icon-btn {
  flex: none;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #1e2128;
  border: 1px solid #34383f;
  color: #e8eaed;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
}
.icon-btn:active { background: #2d313a; }
#sendBtn { border-color: #5dd39e; color: #5dd39e; }
#sendBtn:disabled { opacity: .45; cursor: default; }
#stopBtn { border-color: #d97b6c; color: #d97b6c; }
/* запись голоса: пульсация вокруг кнопки микрофона */
#micBtn.rec {
  border-color: #d97b6c;
  color: #d97b6c;
  animation: rec-pulse 1.4s ease-out infinite;
}
@keyframes rec-pulse {
  0% { box-shadow: 0 0 0 0 rgba(217, 123, 108, .5); }
  100% { box-shadow: 0 0 0 10px rgba(217, 123, 108, 0); }
}
/* промежуточный текст распознавания речи */
#text.interim { color: #6b7078; font-style: italic; }
svg { display: block; }

/* ---------- Две колонки от 900px ---------- */

@media (min-width: 900px) {
  .app {
    flex-direction: row;
  }
  .scene-wrap {
    flex: 1;
    position: static;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    border-bottom: none;
  }
  #stage { width: min(100%, 640px, calc(100dvh - 96px)); }
  .chat-col {
    flex: none;
    width: min(480px, 42vw);
    border-left: 1px solid #1e2128;
    background: #14171c;
  }
  .chat-head { padding: 16px 18px 6px; }
  #chat { padding: 12px 16px 16px; }
  #composer {
    background: transparent;
    padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
  }
}
