:root {
  --bg: #0f1115;
  --bg-soft: #171a21;
  --panel: #1c2029;
  --border: #272c38;
  --text: #e6e8ee;
  --text-dim: #9aa3b2;
  --accent: #4f8cff;
  --accent-2: #2dd4a7;
  --user-bubble: #2b5fd6;
  --assistant-bubble: #1f242f;
  --kaoyan: #4f8cff;
  --baoyan: #2dd4a7;
  --unknown: #6b7280;
  --chat: #b07bd6;
}

* {
  box-sizing: border-box;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 820px;
  margin: 0 auto;
  background: var(--bg);
}

/* 顶栏 */
#topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand .logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #0f1115;
  font-weight: 800;
  font-size: 13px;
}

.brand .title {
  font-weight: 600;
  letter-spacing: 0.3px;
}

.mode-badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  border: 1px solid transparent;
  transition: all 0.25s ease;
}

.mode-kaoyan {
  color: var(--kaoyan);
  background: rgba(79, 140, 255, 0.12);
  border-color: rgba(79, 140, 255, 0.4);
}

.mode-baoyan {
  color: var(--baoyan);
  background: rgba(45, 212, 167, 0.12);
  border-color: rgba(45, 212, 167, 0.4);
}

.mode-unknown {
  color: var(--unknown);
  background: rgba(107, 114, 128, 0.14);
  border-color: rgba(107, 114, 128, 0.35);
}

.mode-chat {
  color: var(--chat);
  background: rgba(176, 123, 214, 0.14);
  border-color: rgba(176, 123, 214, 0.4);
}

/* 聊天区 */
#chat {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 18px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.msg {
  display: flex;
  width: 100%;
}

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

.msg.assistant {
  justify-content: flex-start;
}

.bubble {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: 14px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 15px;
  line-height: 1.62;
}

.msg.user .bubble {
  background: var(--user-bubble);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.msg.assistant .bubble {
  background: var(--assistant-bubble);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.bubble.typing::after {
  content: "▍";
  display: inline-block;
  margin-left: 1px;
  color: var(--accent);
  animation: blink 1s steps(2, start) infinite;
}

@keyframes blink {
  to {
    visibility: hidden;
  }
}

/* 输入区 */
#composer {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
  background: var(--bg-soft);
  border-top: 1px solid var(--border);
}

#input {
  flex: 1 1 auto;
  resize: none;
  max-height: 140px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  line-height: 1.5;
  outline: none;
}

#input:focus {
  border-color: var(--accent);
}

#input::placeholder {
  color: var(--text-dim);
}

#send {
  flex: 0 0 auto;
  height: 42px;
  padding: 0 20px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #0f1115;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  transition: opacity 0.2s ease, transform 0.05s ease;
}

#send:hover:not(:disabled) {
  opacity: 0.92;
}

#send:active:not(:disabled) {
  transform: translateY(1px);
}

#send:disabled {
  opacity: 0.5;
  cursor: default;
}

/* 滚动条 */
#chat::-webkit-scrollbar {
  width: 8px;
}

#chat::-webkit-scrollbar-thumb {
  background: #2a3040;
  border-radius: 8px;
}

#chat::-webkit-scrollbar-track {
  background: transparent;
}

@media (max-width: 640px) {
  .bubble {
    max-width: 86%;
  }
  .brand .title {
    font-size: 14px;
  }
}
