:root {
  --bg: #070a0e;
  --bg-2: #0b1219;
  --line: rgba(126, 168, 190, 0.14);
  --line-soft: rgba(126, 168, 190, 0.07);
  --text: #dfe9f0;
  --muted: #7e93a4;
  --accent: #63e6c8;
  --user-1: #16505e;
  --user-2: #0f3c48;
  --her: #0c141c;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(58% 36% at 50% -8%, rgba(99, 230, 200, 0.07), transparent 72%),
    radial-gradient(42% 30% at 88% 108%, rgba(64, 122, 168, 0.06), transparent 72%);
}

/* ---------- 顶栏 ---------- */

#bar {
  position: relative;
  z-index: 5;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 13px) max(16px, calc((100% - 720px) / 2)) 12px;
  background: rgba(7, 10, 14, 0.82);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line-soft);
}

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

.orb {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: 0 0 auto;
  background: radial-gradient(circle at 35% 30%, #d7fff5, #4fd8bb 60%, #1d7f6d 100%);
  box-shadow: 0 0 10px rgba(79, 216, 187, 0.55);
  animation: breathe 4.2s ease-in-out infinite;
}

@keyframes breathe {
  0%, 100% { opacity: 0.75; box-shadow: 0 0 8px rgba(79, 216, 187, 0.4); }
  50% { opacity: 1; box-shadow: 0 0 14px rgba(79, 216, 187, 0.7); }
}

#name {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.16em;
}

.pill {
  font-size: 11px;
  padding: 2px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(126, 168, 190, 0.05);
  color: var(--muted);
  white-space: nowrap;
}

.tools {
  display: flex;
  align-items: center;
}

#offline {
  position: relative;
  z-index: 4;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 7px 16px;
  font-size: 12px;
  color: #e8b57e;
  background: rgba(230, 161, 92, 0.08);
  border-bottom: 1px solid rgba(230, 161, 92, 0.16);
}

#offline.hidden {
  display: none;
}

#offline button {
  background: none;
  border: 1px solid rgba(230, 161, 92, 0.35);
  border-radius: 999px;
  color: #e8b57e;
  font: inherit;
  font-size: 11px;
  padding: 2px 10px;
  cursor: pointer;
}

#menu {
  background: none;
  border: 0;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  padding: 4px 8px;
  cursor: pointer;
  border-radius: 8px;
}

#menu:hover {
  color: var(--text);
  background: rgba(126, 168, 190, 0.07);
}

/* ---------- 对话 ---------- */

#chat {
  position: relative;
  z-index: 1;
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 14px max(14px, calc((100% - 720px) / 2)) 10px;
  display: flex;
  flex-direction: column;
  gap: 0;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}

#chat::before {
  content: "";
  margin-top: auto;
}

#chat.is-empty::before {
  display: none;
}

.empty {
  margin: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  animation: fade 0.6s ease-out;
}

.empty .mark {
  font-size: 21px;
  letter-spacing: 0.18em;
  color: #c9dde9;
  padding-left: 0.18em;
}

.empty .sub {
  font-size: 12px;
  letter-spacing: 0.08em;
  opacity: 0.65;
}

@keyframes fade {
  from { opacity: 0; transform: translateY(4px); }
}

.msg {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: min(82%, 560px);
  margin: 5px 0;
  animation: rise 0.18s ease-out;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(5px); }
}

.msg.user {
  align-self: flex-end;
  justify-content: flex-end;
}

.msg.assistant {
  align-self: flex-start;
}

.avatar {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  margin-bottom: 3px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #d7fff5, #4fd8bb 58%, #1a6f60 100%);
  box-shadow: 0 0 12px rgba(79, 216, 187, 0.32);
}

.msg.assistant + .msg.assistant .avatar {
  visibility: hidden;
}

.body {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.msg.user .body {
  align-items: flex-end;
}

.msg.assistant .body {
  align-items: flex-start;
}

.bubble {
  padding: 10px 14px;
  border-radius: 18px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 15.5px;
  line-height: 1.62;
}

.user .bubble {
  background: linear-gradient(180deg, var(--user-1), var(--user-2));
  color: #eafcff;
  border-bottom-right-radius: 6px;
  box-shadow: 0 2px 10px rgba(15, 60, 72, 0.35);
}

.assistant .bubble {
  background: var(--her);
  border: 1px solid rgba(126, 168, 190, 0.12);
  border-bottom-left-radius: 6px;
}

.assistant.proactive .bubble {
  border-color: rgba(99, 230, 200, 0.22);
  background: linear-gradient(180deg, rgba(99, 230, 200, 0.045), var(--her));
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 10.5px;
  letter-spacing: 0.12em;
  color: var(--muted);
  margin: 0 6px 5px;
}

.tag::before {
  content: "";
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.75;
}

.bubble.error {
  color: #fca5a5;
  border-color: rgba(127, 29, 29, 0.6);
}

.sep {
  align-self: center;
  color: rgba(126, 168, 190, 0.55);
  font-size: 10.5px;
  letter-spacing: 0.1em;
  margin: 16px 0 8px;
}

.sep.time {
  margin: 10px 0 4px;
  font-size: 10px;
  opacity: 0.75;
}

.dots {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 2px;
}

.dots i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--muted);
  animation: dot 1.3s ease-in-out infinite;
}

.dots i:nth-child(2) { animation-delay: 0.16s; }
.dots i:nth-child(3) { animation-delay: 0.32s; }

@keyframes dot {
  0%, 70%, 100% { opacity: 0.25; transform: translateY(0); }
  35% { opacity: 1; transform: translateY(-2px); }
}

/* ---------- 输入 ---------- */

#composer {
  position: relative;
  z-index: 2;
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px max(12px, calc((100% - 720px) / 2)) calc(env(safe-area-inset-bottom) + 12px);
  background: linear-gradient(180deg, rgba(7, 10, 14, 0), var(--bg) 38%);
}

#input {
  flex: 1;
  resize: none;
  max-height: 140px;
  padding: 11px 15px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--text);
  font: inherit;
  line-height: 1.5;
  outline: none;
  transition: border-color 0.18s, box-shadow 0.18s;
}

#input::placeholder {
  color: rgba(126, 168, 190, 0.55);
}

#input:focus {
  border-color: rgba(99, 230, 200, 0.32);
  box-shadow: 0 0 0 4px rgba(99, 230, 200, 0.055);
}

#send {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border-radius: 50%;
  border: 0;
  background: linear-gradient(160deg, #82f2d9, #3fc9ae);
  color: #04211c;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(63, 201, 174, 0.22);
  transition: opacity 0.15s, transform 0.1s;
}

#send:active {
  transform: scale(0.95);
}

#send:disabled {
  opacity: 0.35;
  box-shadow: none;
}

/* ---------- 抽屉 ---------- */

#scrim {
  position: fixed;
  inset: 0;
  z-index: 9;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
  animation: fade 0.16s ease-out;
}

#scrim.hidden,
#sheet.hidden {
  display: none;
}

#sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  max-width: 520px;
  margin: 0 auto;
  background: #0a1118;
  border: 1px solid var(--line-soft);
  border-bottom: 0;
  border-radius: 20px 20px 0 0;
  padding: 8px 14px calc(env(safe-area-inset-bottom) + 16px);
  animation: up 0.2s ease-out;
}

@keyframes up {
  from { transform: translateY(16px); opacity: 0.4; }
}

.grip {
  width: 36px;
  height: 4px;
  border-radius: 999px;
  background: rgba(126, 168, 190, 0.22);
  margin: 2px auto 12px;
}

.state {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 2px 8px 12px;
  border-bottom: 1px solid var(--line-soft);
  margin-bottom: 6px;
}

.state .row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 6px 0;
  font-size: 13px;
  color: var(--muted);
}

.state .row b {
  font-weight: 500;
  color: var(--text);
}

.acts {
  display: flex;
  flex-direction: column;
}

.acts button {
  background: none;
  border: 0;
  color: var(--text);
  font: inherit;
  font-size: 15px;
  text-align: left;
  padding: 13px 10px;
  border-radius: 12px;
  cursor: pointer;
}

.acts button:hover {
  background: rgba(126, 168, 190, 0.06);
}

.acts button[data-act="close"] {
  color: var(--muted);
}

/* ---------- 登录 ---------- */

.login-body {
  display: grid;
  place-items: center;
  padding: 24px;
}

#login {
  position: relative;
  z-index: 1;
  width: min(340px, 100%);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#login h1 {
  margin: 0 0 2px;
  font-size: 30px;
  font-weight: 600;
  letter-spacing: 0.34em;
}

#login .hint {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.02em;
}

#login input {
  padding: 12px 15px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--text);
  font: inherit;
  outline: none;
  transition: border-color 0.18s, box-shadow 0.18s;
}

#login input:focus {
  border-color: rgba(99, 230, 200, 0.32);
  box-shadow: 0 0 0 4px rgba(99, 230, 200, 0.055);
}

#login button {
  margin-top: 4px;
  padding: 12px 15px;
  border-radius: 14px;
  border: 0;
  background: linear-gradient(160deg, #82f2d9, #3fc9ae);
  color: #04211c;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.err {
  color: #fca5a5;
  font-size: 13px;
  margin: 0;
}

:focus-visible {
  outline: 2px solid rgba(99, 230, 200, 0.5);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- 图片与表情包 ---------- */

#attach {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  margin-bottom: 2px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

#attach:hover {
  color: var(--text);
  border-color: rgba(99, 230, 200, 0.3);
}

#pending {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 max(12px, calc((100% - 720px) / 2)) 6px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--bg-2);
}

#pending.hidden {
  display: none;
}

#pending img {
  width: 46px;
  height: 46px;
  object-fit: cover;
  border-radius: 10px;
}

#pendingText {
  flex: 1;
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--muted);
}

#pendingClear {
  padding: 4px 8px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.photo {
  display: block;
  max-width: min(240px, 62vw);
  max-height: 320px;
  border-radius: 14px;
  border: 1px solid var(--line);
  cursor: zoom-in;
}

.cap {
  margin-top: 5px;
  font-size: 12px;
  color: var(--muted);
}

.msg.user .cap {
  text-align: right;
}

.is-sticker .bubble {
  display: none;
}

.sticker-img {
  display: block;
  width: 132px;
  height: auto;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

#lightbox {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(0, 0, 0, 0.92);
  animation: fade 0.15s ease-out;
}

#lightbox.hidden {
  display: none;
}

#lightbox img {
  max-width: 94vw;
  max-height: 88vh;
  border-radius: 8px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 88px);
  z-index: 30;
  transform: translateX(-50%);
  padding: 9px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(20, 26, 32, 0.95);
  color: var(--text);
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  animation: rise 0.18s ease-out;
}
