:root {
  --bg: #0b1220;
  --bg2: #101a2e;
  --bubble-pet: #1c2b45;
  --bubble-me: #2f6fed;
  --text: #e8eefc;
  --dim: #8aa0c2;
  --accent: #4d8dff;
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
  overscroll-behavior: none;
}
#app { display: flex; flex-direction: column; height: 100dvh; }

/* 顶栏 */
#topbar {
  display: flex; align-items: center; gap: 10px;
  padding: calc(env(safe-area-inset-top) + 10px) 14px 10px;
  background: linear-gradient(180deg, var(--bg2), var(--bg));
  border-bottom: 1px solid #1d2a42;
}
#avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #4d8dff, #1a3a75);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
}
#titles { flex: 1; min-width: 0; }
#botname { font-weight: 700; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#status { font-size: 12px; color: var(--dim); display: flex; align-items: center; gap: 5px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #666; display: inline-block; }
.dot.on { background: #37d67a; box-shadow: 0 0 6px #37d67a; }
.dot.off { background: #e05555; }
#installbtn {
  background: #1c2b45; color: var(--text); border: none; border-radius: 10px;
  padding: 8px 10px; font-size: 16px;
}
#apkbtn {
  background: var(--accent); color: #fff; text-decoration: none;
  border-radius: 10px; padding: 8px 10px; font-size: 12px; font-weight: 600;
  white-space: nowrap;
}

/* 聊天区 */
#chat { flex: 1; overflow-y: auto; padding: 14px 12px 6px; scroll-behavior: smooth; }
#msgs { display: flex; flex-direction: column; gap: 10px; max-width: 760px; margin: 0 auto; width: 100%; }
.msg { display: flex; flex-direction: column; max-width: 82%; }
.msg.pet { align-self: flex-start; align-items: flex-start; }
.msg.me { align-self: flex-end; align-items: flex-end; }
.bubble {
  padding: 9px 13px; border-radius: 16px; font-size: 15px; line-height: 1.55;
  word-break: break-word; white-space: pre-wrap;
  box-shadow: 0 1px 4px rgba(0,0,0,.25);
}
.pet .bubble { background: var(--bubble-pet); border-bottom-left-radius: 5px; }
.me .bubble { background: var(--bubble-me); border-bottom-right-radius: 5px; }
.bubble img {
  max-width: 220px; max-height: 220px; border-radius: 10px; display: block; margin: 4px 0;
  cursor: pointer;
}
.meta { font-size: 10.5px; color: var(--dim); margin-top: 3px; padding: 0 4px; }
.meta .failed { color: #e05555; }
.meta .recalled { color: var(--dim); }
.sysline { align-self: center; font-size: 11px; color: var(--dim); background: #16233a; padding: 4px 12px; border-radius: 10px; }

/* 输入区 */
#inputbar {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 10px calc(env(safe-area-inset-bottom) + 10px);
  background: var(--bg2); border-top: 1px solid #1d2a42;
}
#input {
  flex: 1; resize: none; border: none; outline: none;
  background: #17233a; color: var(--text);
  border-radius: 14px; padding: 11px 14px; font-size: 15px;
  max-height: 120px; line-height: 1.4;
}
#sendbtn, #attachbtn {
  border: none; border-radius: 12px; font-size: 17px;
  padding: 10px 13px; background: var(--accent); color: white;
}
#attachbtn { background: #1c2b45; }
#sendbtn:active, #attachbtn:active { transform: scale(.94); }

/* token 弹层 */
#tokenbox {
  position: fixed; inset: 0; background: rgba(4,8,18,.82);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
#tokenbox .card {
  background: var(--bg2); border: 1px solid #24354f; border-radius: 16px;
  padding: 24px; width: min(86vw, 340px); text-align: center;
}
#tokenbox h2 { margin-bottom: 10px; }
#tokenbox p { color: var(--dim); font-size: 13px; margin-bottom: 14px; }
#tokeninput {
  width: 100%; padding: 11px; border-radius: 10px; border: 1px solid #2c405f;
  background: #0e1830; color: var(--text); margin-bottom: 12px; font-size: 14px;
}
#tokenok {
  width: 100%; padding: 11px; border: none; border-radius: 10px;
  background: var(--accent); color: #fff; font-size: 15px; font-weight: 600;
}

/* toast */
#toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom) + 90px);
  background: #e05555; color: #fff; padding: 10px 18px; border-radius: 12px;
  font-size: 13px; z-index: 60; max-width: 82vw; text-align: center;
}
[hidden] { display: none !important; }
