:root {
  --bg: #0b0d12;
  --panel: #141821;
  --line: rgba(255, 255, 255, 0.09);
  --text: #f2f4f8;
  --muted: #9aa3b2;
  --accent: #7c9cff;
  --accent-2: #9d7bff;
  --danger: #ff5d6c;
  --ok: #4ade80;
  --radius: 22px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background:
    radial-gradient(1100px 600px at 50% -10%, rgba(124, 156, 255, 0.16), transparent 60%),
    radial-gradient(800px 500px at 100% 100%, rgba(157, 123, 255, 0.10), transparent 60%),
    var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.app {
  min-height: 100dvh;
  max-width: 1040px;
  margin: 0 auto;
  padding: 18px clamp(14px, 3vw, 28px) calc(22px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.top { display: flex; align-items: center; justify-content: space-between; min-height: 32px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; letter-spacing: 0.01em; }
.dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 14px rgba(124, 156, 255, 0.8);
}
.timer {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  padding: 4px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.03);
  font-size: 14px;
}
.timer.low { color: var(--danger); border-color: rgba(255, 93, 108, 0.4); }

.stage { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.frame {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 2;
  max-height: 68dvh;
  border-radius: var(--radius);
  overflow: hidden;
  background: #10131a;
  border: 1px solid var(--line);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55);
}
.frame video, .poster {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; background-size: cover; background-position: center top;
}
.frame video { opacity: 0; transition: opacity 0.5s ease; }
.app[data-state="live"] .frame video { opacity: 1; }
.poster { transition: opacity 0.5s ease, filter 0.5s ease; }
.app[data-state="live"] .poster { opacity: 0; }
.app[data-state="idle"] .poster, .app[data-state="connecting"] .poster { filter: saturate(0.9) brightness(0.72); }
.veil {
  position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(180deg, rgba(11, 13, 18, 0.15) 0%, rgba(11, 13, 18, 0) 30%, rgba(11, 13, 18, 0.78) 100%);
  transition: opacity 0.5s ease;
}
.app[data-state="live"] .veil { opacity: 0.35; }

.badge {
  position: absolute; top: 14px; left: 14px;
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 12px 6px 10px;
  border-radius: 999px;
  background: rgba(11, 13, 18, 0.62);
  backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  font-size: 13.5px;
}
.pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.badge[data-kind="speaking"] .pulse { background: var(--accent); animation: pulse 1s ease-in-out infinite; }
.badge[data-kind="thinking"] .pulse { background: #fbbf24; animation: pulse 0.7s ease-in-out infinite; }
.badge[data-kind="muted"] .pulse { background: var(--danger); }
@keyframes pulse { 50% { transform: scale(1.7); opacity: 0.55; } }

.ai-mark {
  position: absolute; top: 14px; right: 14px;
  padding: 5px 10px; border-radius: 999px;
  font-size: 12px; color: var(--muted);
  background: rgba(11, 13, 18, 0.55); border: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.center {
  position: absolute; inset: auto 0 0 0;
  padding: clamp(18px, 4vw, 40px);
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 10px;
}
.app[data-state="live"] .center, .app[data-state="connecting"] .center { display: none; }
h1 { margin: 0; font-size: clamp(22px, 3.6vw, 34px); line-height: 1.15; letter-spacing: -0.01em; }
.center p { margin: 0; max-width: 520px; }
#sub { color: #d5dae4; }
.hint { color: var(--muted); font-size: 13.5px; }
.error {
  color: #ffd7db; background: rgba(255, 93, 108, 0.16); border: 1px solid rgba(255, 93, 108, 0.4);
  padding: 8px 14px; border-radius: 12px; font-size: 14.5px;
}
.code {
  width: min(260px, 100%); padding: 11px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: rgba(11, 13, 18, 0.7); color: var(--text);
  font: inherit; text-align: center; outline: none;
}
.code:focus { border-color: var(--accent); }

button { font: inherit; color: inherit; cursor: pointer; border: 0; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.primary {
  display: inline-flex; align-items: center; gap: 10px;
  margin-top: 6px; padding: 14px 26px;
  border-radius: 999px; font-weight: 600; font-size: 16.5px; color: #0b0d12;
  background: linear-gradient(135deg, #a9bcff, #c3adff);
  box-shadow: 0 10px 30px rgba(124, 156, 255, 0.35);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.primary:hover { transform: translateY(-1px); box-shadow: 0 14px 36px rgba(124, 156, 255, 0.45); }
.primary:active { transform: translateY(0); }
.primary:disabled { opacity: 0.6; cursor: default; transform: none; }

.spinner {
  position: absolute; left: 50%; top: 50%; width: 46px; height: 46px; margin: -23px 0 0 -23px;
  border-radius: 50%; border: 3px solid rgba(255, 255, 255, 0.18); border-top-color: #fff;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.controls { display: flex; align-items: center; gap: 12px; }
.round {
  width: 52px; height: 52px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--panel); border: 1px solid var(--line);
  transition: background 0.15s ease;
}
.round:hover { background: #1b2030; }
.round .mic-off { display: none; }
.round[aria-pressed="true"] { background: rgba(255, 93, 108, 0.18); border-color: rgba(255, 93, 108, 0.5); color: #ffb3ba; }
.round[aria-pressed="true"] .mic-on { display: none; }
.round[aria-pressed="true"] .mic-off { display: block; }
.end {
  height: 52px; padding: 0 26px; border-radius: 999px; font-weight: 600;
  background: #e23d4f; color: #fff;
  transition: filter 0.15s ease;
}
.end:hover { filter: brightness(1.08); }

.captions {
  flex: 1; min-height: 120px;
  background: rgba(20, 24, 33, 0.7);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px;
}
.log {
  max-height: 30dvh; overflow-y: auto; padding: 10px 12px;
  display: flex; flex-direction: column; gap: 8px;
  scrollbar-width: thin; scrollbar-color: #2a3040 transparent;
}
.msg { max-width: 82%; padding: 9px 13px; border-radius: 16px; font-size: 15px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.assistant { align-self: flex-start; background: #1c2130; border-bottom-left-radius: 6px; }
.msg.user { align-self: flex-end; background: linear-gradient(135deg, rgba(124, 156, 255, 0.28), rgba(157, 123, 255, 0.28)); border-bottom-right-radius: 6px; }
.msg.note { align-self: center; background: none; color: var(--muted); font-size: 13.5px; padding: 2px 8px; }

@media (max-width: 640px) {
  .frame { aspect-ratio: 4 / 5; max-height: 62dvh; }
  .msg { max-width: 92%; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* the emotion the avatar is showing right now */
.mood {
  position: absolute; top: 52px; left: 14px;
  padding: 5px 11px; border-radius: 999px;
  font-size: 13px;
  background: rgba(11, 13, 18, 0.55); border: 1px solid var(--line);
  backdrop-filter: blur(10px);
}
