:root {
  --bg: #0d0f14; --panel: #161a22; --panel2: #1e2330; --line: #2a3040;
  --text: #e8eaf0; --muted: #8b93a7; --accent: #5b8cff; --accent2: #7c5cff;
  --ok: #3ccf91; --warn: #f5b041; --err: #ff6b6b;
  --me: #2b4a9e; --radius: 18px;
  --safe-b: env(safe-area-inset-bottom); --safe-t: env(safe-area-inset-top);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif; }
body { overscroll-behavior: none; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round; }
.muted { color: var(--muted); } .small { font-size: 13px; } .err { color: var(--err); min-height: 1.4em; }

/* Gate */
.gate { height: 100dvh; display: grid; place-items: center; padding: 24px; }
.gate-card { text-align: center; max-width: 340px; width: 100%; }
.gate-logo { width: 88px; height: 88px; border-radius: 22px; }
.gate h1 { margin: 14px 0 4px; font-size: 28px; }
.btn-primary { margin-top: 22px; width: 100%; padding: 15px; border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent2)); font-weight: 600; }
.btn-primary:disabled { opacity: .5; }

/* App layout */
.app { height: 100dvh; display: flex; flex-direction: column; }
.top { position: relative; z-index: 30; display: flex; align-items: center; justify-content: space-between;
  padding: calc(var(--safe-t) + 10px) 16px 10px; border-bottom: 1px solid var(--line);
  background: rgba(13,15,20,.92); backdrop-filter: blur(12px); }
.who { display: flex; align-items: center; gap: 8px; min-width: 0; }
.who .small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); flex: none; }
.dot.busy { background: var(--warn); animation: pulse 1s infinite; }
.top-actions { display: flex; align-items: center; gap: 6px; }
.btn-talk { display: flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 999px;
  background: linear-gradient(135deg, var(--accent), var(--accent2)); font-weight: 600; font-size: 15px; }
.btn-talk svg { width: 18px; height: 18px; }
.icon-btn { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; flex: none; }
.icon-btn:active { background: var(--panel2); }
.menu { position: absolute; right: 12px; top: calc(100% + 4px); background: var(--panel2);
  border: 1px solid var(--line); border-radius: 14px; overflow: hidden; z-index: 40; min-width: 240px;
  box-shadow: 0 10px 30px rgba(0,0,0,.5); }
.menu button { display: block; width: 100%; text-align: left; padding: 13px 16px; }
.menu button + button { border-top: 1px solid var(--line); }

/* Messages */
.msgs { position: relative; z-index: 1; flex: 1; overflow-y: auto; padding: 14px 12px 8px; display: flex; flex-direction: column; gap: 10px;
  -webkit-overflow-scrolling: touch; }
.msg { max-width: 88%; padding: 10px 14px; border-radius: var(--radius); word-wrap: break-word;
  overflow-wrap: anywhere; }
.msg.me { align-self: flex-end; background: var(--me); border-bottom-right-radius: 6px; }
.msg.bot { align-self: flex-start; background: var(--panel); border-bottom-left-radius: 6px; }
.msg.note { align-self: flex-start; background: none; color: var(--muted); font-size: 14px; padding: 2px 6px; }
.msg.error { align-self: center; color: var(--err); font-size: 14px; }
.msg .tag { font-size: 12px; color: var(--muted); display: block; margin-bottom: 2px; }
.msg p { margin: 0 0 .5em; } .msg p:last-child { margin-bottom: 0; }
.msg ul, .msg ol { margin: .3em 0 .5em; padding-left: 1.3em; }
.msg h1, .msg h2, .msg h3, .msg h4 { margin: .5em 0 .3em; font-size: 1.05em; }
.msg a { color: #9db8ff; }
.msg code { background: rgba(255,255,255,.08); padding: 1px 5px; border-radius: 5px; font-size: .9em; }
.msg pre { background: #0a0c10; padding: 10px; border-radius: 10px; overflow-x: auto; font-size: 13px; }
.msg pre code { background: none; padding: 0; }
.msg img { display: block; max-width: 100%; border-radius: 12px; margin: 6px 0; background: #fff; }
.msg .tbl { overflow-x: auto; } .msg table { border-collapse: collapse; font-size: 14px; }
.msg th, .msg td { border: 1px solid var(--line); padding: 4px 8px; text-align: left; }
.typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.typing i { width: 7px; height: 7px; background: var(--muted); border-radius: 50%; animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }

/* Composer */
.composer { border-top: 1px solid var(--line); padding: 8px 10px calc(var(--safe-b) + 8px); background: var(--bg); }
.composer .row { display: flex; align-items: flex-end; gap: 6px; }
#input { flex: 1; resize: none; max-height: 140px; padding: 10px 14px; border-radius: 20px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text); font: inherit; outline: none; }
#input:focus { border-color: var(--accent); }
.send { width: 40px; height: 40px; border-radius: 50%; background: var(--accent); display: grid; place-items: center; flex: none; }
.send:disabled { opacity: .4; }
#btn-mic.rec { background: var(--err); color: #fff; animation: pulse 1s infinite; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips:not(:empty) { margin-bottom: 8px; }
.chip { background: var(--panel2); border-radius: 999px; padding: 4px 10px; font-size: 13px; }
.chip button { margin-left: 6px; color: var(--muted); }

/* Voice overlay */
.voice { position: fixed; inset: 0; z-index: 20; background: radial-gradient(circle at 50% 40%, #1b2140, var(--bg) 70%);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px;
  padding: calc(var(--safe-t) + 20px) 24px calc(var(--safe-b) + 24px); }
.voice-top { position: absolute; top: calc(var(--safe-t) + 22px); font-weight: 600; color: var(--muted); }
.orb { width: 190px; height: 190px; border-radius: 50%; position: relative;
  background: radial-gradient(circle at 35% 30%, #8fb0ff, var(--accent) 45%, var(--accent2));
  box-shadow: 0 0 60px rgba(91,140,255,.45); transition: transform .12s ease; }
.orb span { position: absolute; inset: -14px; border-radius: 50%; border: 2px solid rgba(124,92,255,.5); opacity: 0; }
.voice[data-state="listening"] .orb span { animation: ring 1.6s infinite; }
.voice[data-state="thinking"] .orb { animation: breathe 1.4s ease-in-out infinite; filter: saturate(.6); }
.voice[data-state="speaking"] .orb { box-shadow: 0 0 90px rgba(124,92,255,.7); }
.voice[data-state="idle"] .orb { filter: grayscale(.7); opacity: .7; }
.voice-text { max-width: 520px; text-align: center; margin: 0; min-height: 1.4em; font-size: 17px; }
.voice-text.dim { color: var(--muted); font-size: 15px; max-height: 30vh; overflow-y: auto; }
.btn-end { margin-top: 10px; padding: 13px 40px; border-radius: 999px; background: var(--err); font-weight: 600; }

@keyframes pulse { 50% { opacity: .55; } }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
@keyframes ring { 0% { transform: scale(.92); opacity: .9; } 100% { transform: scale(1.25); opacity: 0; } }
@keyframes breathe { 50% { transform: scale(.94); } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
