/* OYI Live — Telegram WebApp styling.
   Colours come from Telegram theme params when available, with a dark fallback. */

:root {
  --bg: var(--tg-theme-bg-color, #0b0e13);
  --bg-2: var(--tg-theme-secondary-bg-color, #141922);
  --card: var(--tg-theme-section-bg-color, #141922);
  --text: var(--tg-theme-text-color, #eef2f9);
  --hint: var(--tg-theme-hint-color, #8a97ab);
  --accent: var(--tg-theme-button-color, #2f7bff);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, #4fc3ff);
  --border: color-mix(in srgb, var(--hint) 22%, transparent);
  --danger: #ff4d5e;
  --ok: #2fd07a;
  --warn: #ffb020;

  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.28);

  --font: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  overscroll-behavior: none;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
  position: relative;
}

/* ------------------------------------------------------------------ topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px 12px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar__brand { display: flex; align-items: center; gap: 12px; min-width: 0; }

.avatar {
  width: 42px; height: 42px;
  border-radius: 14px;
  display: grid; place-items: center;
  font-weight: 800; font-size: 15px; letter-spacing: 0.5px;
  color: #04121a;
  background: linear-gradient(140deg, #4fc3ff, #7c5cff 55%, #2fd07a);
  box-shadow: 0 6px 18px rgba(79, 195, 255, 0.28);
  flex: none;
}

.topbar__meta { min-width: 0; }

.topbar__title {
  font-size: 17px; font-weight: 800; letter-spacing: -0.2px;
  display: flex; align-items: center; gap: 7px;
}

.live-tag {
  font-size: 9px; font-weight: 800; letter-spacing: 1.4px;
  padding: 2px 7px; border-radius: 999px;
  color: var(--ok);
  background: color-mix(in srgb, var(--ok) 16%, transparent);
  border: 1px solid color-mix(in srgb, var(--ok) 45%, transparent);
}

.topbar__sub {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--hint); font-weight: 600;
  margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.conn-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--hint); flex: none;
  transition: background 0.25s ease, box-shadow 0.25s ease;
}
.conn-dot.is-online { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.conn-dot.is-connecting { background: var(--warn); box-shadow: 0 0 8px var(--warn); animation: blink 1s infinite; }
.conn-dot.is-offline { background: var(--danger); box-shadow: 0 0 8px var(--danger); }

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

.topbar__actions { display: flex; gap: 8px; flex: none; }

.icon-btn {
  width: 38px; height: 38px; border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-2);
  color: var(--text);
  display: grid; place-items: center;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.2s ease;
}
.icon-btn svg { width: 19px; height: 19px; }
.icon-btn:active { transform: scale(0.92); }
.icon-btn.is-off { color: var(--hint); opacity: 0.6; }

/* -------------------------------------------------------------------- feed */
.feed {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

.msg {
  max-width: 86%;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 14.5px;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
  animation: rise 180ms ease-out;
}
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.msg.user {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 70%, #7c5cff));
  color: var(--accent-text);
  border-bottom-right-radius: 6px;
}

.msg.bot {
  align-self: flex-start;
  background: var(--card);
  border: 1px solid var(--border);
  border-bottom-left-radius: 6px;
}

.msg.bot.is-streaming::after {
  content: '';
  display: inline-block;
  width: 7px; height: 7px;
  margin-left: 4px;
  border-radius: 50%;
  background: var(--link);
  animation: blink 0.9s infinite;
  vertical-align: middle;
}

.msg.system {
  align-self: center;
  max-width: 96%;
  text-align: center;
  font-size: 12.5px;
  color: var(--hint);
  background: color-mix(in srgb, var(--bg-2) 70%, transparent);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
}

.msg.error {
  align-self: center;
  max-width: 96%;
  font-size: 13px;
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent);
  border-radius: var(--radius-sm);
}

/* backchannel / filler chips */
.chip {
  align-self: flex-start;
  font-size: 12px;
  font-style: italic;
  color: var(--link);
  background: color-mix(in srgb, var(--link) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--link) 34%, transparent);
  padding: 4px 11px;
  border-radius: 999px;
  animation: rise 160ms ease-out;
}
.chip.filler { color: var(--warn); background: color-mix(in srgb, var(--warn) 12%, transparent); border-color: color-mix(in srgb, var(--warn) 36%, transparent); }

/* tool activity */
.tool {
  align-self: flex-start;
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 12px; font-weight: 600;
  color: var(--hint);
  background: color-mix(in srgb, var(--bg-2) 80%, transparent);
  border: 1px solid var(--border);
  padding: 5px 11px;
  border-radius: 999px;
}
.tool.is-running { color: var(--link); border-color: color-mix(in srgb, var(--link) 34%, transparent); }
.tool__dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.tool.is-running .tool__dot { animation: blink 1s infinite; }

/* ---------------------------------------------------------------- activity */
.activity {
  display: flex; align-items: center; gap: 9px;
  margin: 0 16px 4px;
  padding: 8px 13px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--bg-2) 85%, transparent);
  border: 1px solid var(--border);
  font-size: 12.5px; font-weight: 600; color: var(--hint);
  animation: rise 160ms ease-out;
}
.activity__spinner {
  width: 13px; height: 13px; flex: none;
  border-radius: 50%;
  border: 2px solid color-mix(in srgb, var(--link) 30%, transparent);
  border-top-color: var(--link);
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.activity__timer { margin-left: auto; font-family: var(--mono); font-size: 11px; color: var(--hint); }

/* ---------------------------------------------------------------- composer */
.composer {
  padding: 10px 16px calc(env(safe-area-inset-bottom, 0px) + 12px);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
}

.voice-strip {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 12px;
  margin-bottom: 10px;
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--link) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--link) 30%, transparent);
}

.wave { display: flex; align-items: center; gap: 3px; height: 24px; }
.wave span {
  width: 3.5px; border-radius: 3px;
  background: var(--link);
  height: calc(6px + var(--level, 0) * 20px);
  transition: height 90ms linear;
  animation: waveIdle 1.4s ease-in-out infinite;
}
.wave span:nth-child(1) { animation-delay: 0s; }
.wave span:nth-child(2) { animation-delay: 0.15s; }
.wave span:nth-child(3) { animation-delay: 0.3s; }
.wave span:nth-child(4) { animation-delay: 0.45s; }
.wave span:nth-child(5) { animation-delay: 0.6s; }
@keyframes waveIdle { 0%,100% { opacity: 0.65; } 50% { opacity: 1; } }

.voice-state { font-size: 13px; font-weight: 700; color: var(--link); flex: 1; }
.voice-state[data-state="speaking"] { color: var(--ok); }
.voice-state[data-state="thinking"] { color: var(--warn); }

.voice-stop {
  border: 1px solid color-mix(in srgb, var(--danger) 45%, transparent);
  background: color-mix(in srgb, var(--danger) 14%, transparent);
  color: var(--danger);
  font-weight: 700; font-size: 12.5px;
  padding: 6px 14px; border-radius: 999px;
  cursor: pointer;
}

.composer__row { display: flex; align-items: center; gap: 9px; }

.mic-btn {
  width: 46px; height: 46px; flex: none;
  border-radius: 50%;
  border: none;
  background: linear-gradient(140deg, #4fc3ff, #2f7bff);
  color: #fff;
  display: grid; place-items: center;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(47, 123, 255, 0.38);
  transition: transform 0.15s ease, background 0.25s ease, box-shadow 0.25s ease;
}
.mic-btn svg { width: 21px; height: 21px; }
.mic-btn:active { transform: scale(0.92); }
.mic-btn.is-active {
  background: linear-gradient(140deg, #ff5f6d, #ff2d55);
  box-shadow: 0 0 0 0 rgba(255, 45, 85, 0.5);
  animation: micPulse 1.6s infinite;
}
@keyframes micPulse {
  0% { box-shadow: 0 0 0 0 rgba(255, 45, 85, 0.5); }
  70% { box-shadow: 0 0 0 14px rgba(255, 45, 85, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 45, 85, 0); }
}

.field {
  flex: 1; display: flex; align-items: center; gap: 6px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 5px 5px 16px;
}
.field input {
  flex: 1; min-width: 0;
  border: none; outline: none; background: transparent;
  color: var(--text); font-family: var(--font); font-size: 15px;
  padding: 8px 0;
}
.field input::placeholder { color: var(--hint); }

.send-btn {
  width: 38px; height: 38px; flex: none;
  border: none; border-radius: 50%;
  background: var(--accent); color: var(--accent-text);
  display: grid; place-items: center; cursor: pointer;
  transition: transform 0.15s ease, opacity 0.2s ease;
}
.send-btn svg { width: 18px; height: 18px; }
.send-btn:active { transform: scale(0.9); }
.send-btn:disabled { opacity: 0.4; }

/* ------------------------------------------------------------------- sheet */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
  animation: fade 160ms ease-out;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  max-width: 720px; margin: 0 auto;
  background: var(--bg-2);
  border-radius: 22px 22px 0 0;
  border-top: 1px solid var(--border);
  padding: 10px 20px calc(env(safe-area-inset-bottom, 0px) + 24px);
  box-shadow: var(--shadow);
  animation: sheetUp 220ms cubic-bezier(0.2, 0.9, 0.3, 1);
}
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: none; } }

.sheet__grab { width: 40px; height: 4px; border-radius: 99px; background: var(--border); margin: 2px auto 14px; }
.sheet__title { font-size: 15px; font-weight: 800; margin-bottom: 16px; }

.setting { margin-bottom: 16px; }
.setting__label { font-size: 12.5px; font-weight: 700; color: var(--hint); margin-bottom: 8px; }

.segmented { display: flex; background: var(--bg); border: 1px solid var(--border); border-radius: 12px; padding: 3px; }
.segment {
  flex: 1; border: none; background: transparent; color: var(--hint);
  font-family: var(--font); font-size: 13px; font-weight: 700;
  padding: 9px; border-radius: 9px; cursor: pointer; transition: all 0.2s ease;
}
.segment.is-active { background: var(--accent); color: var(--accent-text); }

.select {
  width: 100%; padding: 11px 12px; border-radius: 12px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border);
  font-family: var(--font); font-size: 14px; font-weight: 600; outline: none;
}

.toggle {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px 0; font-size: 14px; font-weight: 600;
  border-bottom: 1px solid var(--border); cursor: pointer;
}
.toggle input { display: none; }
.toggle__track {
  width: 46px; height: 27px; flex: none; border-radius: 999px;
  background: color-mix(in srgb, var(--hint) 35%, transparent);
  position: relative; transition: background 0.2s ease;
}
.toggle__thumb {
  position: absolute; top: 3px; left: 3px;
  width: 21px; height: 21px; border-radius: 50%;
  background: #fff; transition: transform 0.2s ease;
}
.toggle input:checked + .toggle__track { background: var(--accent); }
.toggle input:checked + .toggle__track .toggle__thumb { transform: translateX(19px); }

.ghost-btn {
  width: 100%; margin-top: 16px; padding: 13px;
  border-radius: 12px; border: 1px solid var(--border);
  background: transparent; color: var(--danger);
  font-family: var(--font); font-size: 14px; font-weight: 700; cursor: pointer;
}

.engine-info {
  margin-top: 14px; font-family: var(--mono); font-size: 11px;
  color: var(--hint); line-height: 1.7; text-align: center;
}

/* ------------------------------------------------------------------- toast */
.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom, 0px) + 96px);
  transform: translateX(-50%); z-index: 60;
  background: var(--bg-2); color: var(--text);
  border: 1px solid var(--border);
  padding: 10px 16px; border-radius: 999px;
  font-size: 13px; font-weight: 600;
  box-shadow: var(--shadow);
  animation: rise 160ms ease-out;
}
