:root {
  --bg: #0b0d12;
  --bg2: #12151d;
  --panel: #171b25;
  --line: #262b38;
  --text: #e8eaf0;
  --muted: #8b92a5;
  --accent: #e8945a;
  --accent2: #6ea8fe;
  --ok: #4cc38a;
  --warn: #f2c14e;
  --bad: #ff6b6b;
  --user: #243044;
  --bot: #1a1f2b;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overscroll-behavior: none; }
body { padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); }
.hidden { display: none !important; }

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

#top { display: flex; align-items: center; gap: 10px; padding: 8px 12px; min-height: 44px; }
#status { flex: 1; display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; transition: background .2s; }
#dot.idle { background: var(--ok); }
#dot.listening { background: var(--ok); box-shadow: 0 0 0 4px rgba(76,195,138,.25); }
#dot.thinking, #dot.working { background: var(--warn); animation: pulse 1s infinite; }
#dot.speaking { background: var(--accent2); animation: pulse .6s infinite; }
#dot.confirm { background: var(--bad); animation: pulse .8s infinite; }
#dot.off { background: #555; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }
#awake { font-size: 18px; }

#stage { position: relative; flex: 0 0 42%; min-height: 220px; overflow: hidden;
  background: radial-gradient(120% 90% at 50% 20%, #1c2233 0%, #0b0d12 70%); }
#avatar-3d, #avatar-2d { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#loading { position: absolute; left: 16px; right: 16px; bottom: 14px; color: var(--muted); font-size: 13px; text-align: center; }
#loading .bar { height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; margin-bottom: 6px; }
#loading .bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
#thinking-tag { position: absolute; left: 12px; bottom: 10px; max-width: 70%; font-size: 12px; color: var(--muted);
  background: rgba(11,13,18,.7); padding: 4px 8px; border-radius: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

#pip { position: absolute; top: 8px; right: 8px; width: 34%; max-width: 180px; aspect-ratio: 3/4;
  border-radius: 12px; overflow: hidden; border: 1px solid var(--line); background: #000; }
#pip video { width: 100%; height: 100%; object-fit: cover; }
#pip .mini { position: absolute; bottom: 6px; width: 30px; height: 30px; border-radius: 50%; border: 0;
  background: rgba(0,0,0,.55); color: #fff; font-size: 15px; }
#btn-flip { left: 6px; }
#btn-observe { right: 6px; }
#btn-observe.on { background: var(--accent); }

#chat { flex: 1; overflow-y: auto; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; scroll-behavior: smooth; }
.msg { max-width: 88%; padding: 8px 12px; border-radius: 14px; white-space: pre-wrap; word-break: break-word; font-size: 15px; }
.msg.user { align-self: flex-end; background: var(--user); border-bottom-right-radius: 4px; }
.msg.user.ignored { opacity: .45; font-style: italic; font-size: 13px; }
.msg.bot { align-self: flex-start; background: var(--bot); border-bottom-left-radius: 4px; border: 1px solid var(--line); }
.msg.bot .tool { display: block; font-size: 12px; color: var(--muted); font-family: ui-monospace, monospace; margin: 2px 0; }
.msg.bot .err { color: var(--bad); }
.msg.bot .cursor::after { content: "▍"; color: var(--accent); animation: pulse .8s infinite; }
.msg.bot pre { background: #0d1017; padding: 8px; border-radius: 8px; overflow-x: auto; font-size: 13px; margin: 4px 0; }
.msg.bot code { background: #0d1017; padding: 1px 4px; border-radius: 4px; font-size: 13px; }
.msg.sys { align-self: center; color: var(--muted); font-size: 12px; background: transparent; }
.msg .thumbs { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.msg .thumbs img { max-width: 140px; max-height: 140px; border-radius: 8px; }
.msg .thumbs .doc { font-size: 12px; background: rgba(255,255,255,.08); padding: 4px 8px; border-radius: 8px; }
.msg.obs { border-color: var(--accent2); }
.msg.confirm { align-self: stretch; max-width: 100%; background: #2a1d1d; border: 1px solid var(--bad); border-radius: 12px; }
.msg.confirm .t { font-weight: 600; margin-bottom: 4px; }
.msg.confirm .d { font-family: ui-monospace, monospace; font-size: 13px; color: #ffd0d0; white-space: pre-wrap; word-break: break-all; max-height: 120px; overflow: auto; }
.msg.confirm .b { display: flex; gap: 8px; margin-top: 8px; }
.msg.confirm button { flex: 1; padding: 10px; border-radius: 10px; border: 0; font-size: 15px; font-weight: 600; }
.msg.confirm .yes { background: var(--ok); color: #062; }
.msg.confirm .no { background: #444; color: #fff; }
.msg.confirm.answered { opacity: .6; }
.msg.confirm.answered .b { display: none; }
.msg.confirm .res { font-size: 13px; margin-top: 6px; color: var(--muted); }

#composer { padding: 6px 10px 10px; border-top: 1px solid var(--line); background: var(--bg2); }
#composer .row { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
#composer .row .spacer { flex: 1; }
#input { display: block; width: 100%; resize: none; max-height: 120px; overflow-y: hidden; padding: 10px 14px; border-radius: 18px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text); font: inherit; outline: none; }
button.icon { width: 42px; height: 42px; border-radius: 50%; border: 0; background: var(--panel); color: var(--text);
  font-size: 19px; flex: none; display: inline-flex; align-items: center; justify-content: center; }
button.icon:active { transform: scale(.94); }
button.icon.mic.on { background: var(--ok); color: #041; }
button.icon.mic.speaking { background: var(--accent2); }
#btn-cam.on { background: var(--accent); color: #200; }
#btn-send { background: var(--accent); color: #200; }
#chips { display: flex; gap: 6px; flex-wrap: wrap; }
#chips .chip { display: inline-flex; align-items: center; gap: 6px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 4px 8px; font-size: 12px; margin-bottom: 6px; max-width: 100%; }
#chips .chip img { width: 28px; height: 28px; object-fit: cover; border-radius: 6px; }
#chips .chip b { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 140px; }
#chips .chip .x { cursor: pointer; color: var(--muted); padding: 0 2px; }

.sheet { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: flex-end; z-index: 20; }
.sheet-body { width: 100%; max-width: 720px; margin: 0 auto; background: var(--bg2); border-radius: 18px 18px 0 0; padding: 16px 16px 24px;
  max-height: 88dvh; overflow-y: auto; }
.sheet h2 { margin: 0 0 12px; font-size: 18px; }
.sheet label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.sheet label.check { flex-direction: row; align-items: center; gap: 10px; color: var(--text); font-size: 15px; }
.sheet select, .sheet input[type=text] { font: inherit; font-size: 15px; color: var(--text); background: var(--panel);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
.sheet input[type=checkbox] { width: 20px; height: 20px; }
.sheet .btns { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.sheet .btns button, #gate button { flex: 1; padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel);
  color: var(--text); font: inherit; font-size: 15px; }
button.primary { background: var(--accent) !important; color: #200 !important; border-color: transparent !important; font-weight: 600; }
.hint { color: var(--muted); font-size: 12px; margin: 12px 0 0; }

#gate { position: fixed; inset: 0; background: var(--bg); display: flex; align-items: center; justify-content: center; z-index: 30; padding: 24px; }
#gate div { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 10px; }
#gate input { font: inherit; padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); color: var(--text); }

@media (min-width: 720px) {
  #stage { flex-basis: 46%; }
}
@media (max-height: 560px) {
  #stage { flex-basis: 34%; min-height: 160px; }
}
