:root {
  --bg: #eef1f8;
  --card: #ffffff;
  --accent: #3b5bdb;
  --accent-soft: #eef1ff;
  --text: #1f2430;
  --text-2: #5b6270;
  --line: #e3e7f0;
  --bubble-user: #3b5bdb;
  --bubble-user-text: #fff;
  --radius: 16px;
  --shadow: 0 6px 24px rgba(31, 43, 76, 0.08);
}

* { box-sizing: border-box; }

html {
  /* 防系统字体放大/横竖屏自动缩放网页文字（路线B：固定像素） */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

button, a { touch-action: manipulation; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  background: radial-gradient(1200px 600px at 50% -10%, #e2e9ff 0%, var(--bg) 55%);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.layout {
  max-width: 820px;
  /* 兼容不支持 dvh 的旧浏览器 */
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  /* 刘海屏/圆角屏安全区适配（viewport-fit=cover 生效时） */
  padding: calc(18px + env(safe-area-inset-top)) 16px
    calc(10px + env(safe-area-inset-bottom));
  gap: 14px;
}

/* ---- 名片条 ---- */
.profile {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 18px;
  box-shadow: var(--shadow);
  flex-wrap: wrap;
}

.avatar {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  font-size: 24px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, #4b6bfb, #7c5cff);
}

.profile-meta { min-width: 0; flex: 1 1 300px; }

.profile-meta h1 {
  margin: 0;
  font-size: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #34c77b;
  box-shadow: 0 0 0 3px rgba(52, 199, 123, 0.18);
  display: inline-block;
}

.subtitle {
  margin: 4px 0 8px;
  color: var(--text-2);
  font-size: 13.5px;
  line-height: 1.5;
}

.tags { display: flex; flex-wrap: wrap; gap: 6px; }

.tag {
  font-size: 12px;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 3px 10px;
}

.links {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

.links a {
  text-decoration: none;
  font-size: 13px;
  color: var(--text-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.links a:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
}

/* ---- 聊天区 ---- */
.chat {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 18px 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

.msg {
  max-width: 82%;
  display: flex;
  flex-direction: column;
  gap: 2px;
  animation: rise 0.2s ease;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.msg .who {
  font-size: 11.5px;
  color: var(--text-2);
  margin: 0 4px;
}

.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.assistant { align-self: flex-start; align-items: flex-start; }

.bubble {
  padding: 10px 14px;
  border-radius: 16px;
  line-height: 1.65;
  font-size: 14.5px;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.user .bubble {
  background: var(--bubble-user);
  color: var(--bubble-user-text);
  border-bottom-right-radius: 6px;
}

.assistant .bubble {
  background: #f2f4fa;
  border-bottom-left-radius: 6px;
}

/* 流式中的光标 */
.bubble.typing::after {
  content: "▍";
  color: var(--accent);
  animation: blink 0.9s steps(2) infinite;
}

@keyframes blink { 50% { opacity: 0; } }

/* 助手回答内的轻量排版 */
.bubble p { margin: 0 0 6px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 4px 0; padding-left: 20px; }
.bubble h1, .bubble h2, .bubble h3 {
  font-size: 15px;
  margin: 10px 0 4px;
}
.bubble code {
  background: rgba(59, 91, 219, 0.08);
  color: #2d4ad0;
  border-radius: 5px;
  padding: 1px 5px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 13px;
}
.bubble pre {
  background: #0f1420;
  color: #e6e9f2;
  padding: 10px 12px;
  border-radius: 10px;
  overflow-x: auto;
}
.bubble pre code { background: none; color: inherit; padding: 0; }
.bubble a { color: var(--accent); }

/* 错误提示条 */
.banner {
  align-self: center;
  background: #fdecec;
  color: #b4342c;
  border: 1px solid #f5c6c2;
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 13px;
  max-width: 90%;
  text-align: center;
  animation: rise 0.2s ease;
}

/* ---- 底部输入区 ---- */
.composer {
  border-top: 1px solid var(--line);
  /* 底部安全区：iPhone 底部横条不遮挡输入框 */
  padding: 10px 14px calc(12px + env(safe-area-inset-bottom));
}

.chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.chip {
  font-size: 13px;
  color: var(--text-2);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.chip:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
}

.input-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

#input {
  flex: 1;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 14px;
  font: inherit;
  /* ≥16px：避免 iOS 聚焦输入时整页自动放大 */
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: #fafbfe;
  outline: none;
  max-height: 140px;
  transition: border-color 0.15s ease, background 0.15s ease;
}

#input:focus {
  border-color: var(--accent);
  background: #fff;
}

.send-btn {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: opacity 0.15s ease, transform 0.1s ease;
  flex-shrink: 0;
}

.send-btn:hover:not(:disabled) { transform: translateY(-1px); }
.send-btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* ---- 页脚 ---- */
.foot {
  text-align: center;
  font-size: 12px;
  color: #9aa1af;
  padding-bottom: 2px;
}

/* ===== 桌面 / 手机 UI 显隐（默认桌面可见，手机隐藏） ===== */
.mobile-ui { display: none; }

/* =========================================================
   手机端专属界面（≤560px）：聊天 App 风
   ========================================================= */
@media (max-width: 560px) {
  .desktop-ui { display: none; }
  .mobile-ui { display: block; }

  /* 布局改为全屏，去掉卡片留白 */
  .layout {
    max-width: none;
    padding: 0;
    gap: 0;
  }

  /* ---- 顶部细条 ---- */
  .m-top {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
    background: rgba(255, 255, 255, 0.92);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--line);
    position: relative;
    z-index: 5;
  }

  .m-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    flex-shrink: 0;
    display: grid;
    place-items: center;
    font-size: 17px;
    font-weight: 700;
    color: #fff;
    background: linear-gradient(135deg, #4b6bfb, #7c5cff);
    border: none;
    padding: 0;
    cursor: pointer;
  }

  .m-top-info { flex: 1; min-width: 0; }

  .m-top-name {
    font-size: 16.5px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 7px;
    line-height: 1.3;
  }

  .m-top-sub {
    font-size: 12px;
    color: var(--text-2);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 1px;
  }

  .m-top-links { display: flex; gap: 6px; flex-shrink: 0; }
  .m-top-links a {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    font-size: 17px;
    text-decoration: none;
    background: var(--accent-soft);
    color: var(--text);
    border-radius: 50%;
  }

  /* ---- 聊天主体全屏化 ---- */
  .chat {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: transparent;
    border-radius: 0;
    box-shadow: none;
  }

  /* 消息背景淡色，气泡浮于其上，更像 IM */
  .messages {
    background:
      radial-gradient(600px 260px at 85% -10%, #dfe7ff 0%, transparent 60%),
      var(--bg);
    padding: 14px 12px 8px;
  }

  /* 自己发的消息也带一点渐变 */
  .user .bubble {
    background: linear-gradient(135deg, #4b6bfb, #5a7bff);
    color: #fff;
  }

  /* 底部输入区固定感（跟随聊天区底部） */
  .composer {
    background: rgba(255, 255, 255, 0.94);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--line);
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  }

  /* 推荐问题 chips 改横向滚动，不占多行 */
  .chips {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    margin-bottom: 8px;
  }
  .chips::-webkit-scrollbar { display: none; }
  .chip { flex: 0 0 auto; white-space: nowrap; }

  /* ---- 资料卡（底部抽屉） ---- */
  .m-mask {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 20, 32, 0.45);
    z-index: 40;
  }
  .m-mask.open { display: block; }

  .m-sheet {
    display: block;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 41;
    background: #fff;
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -10px 40px rgba(31, 43, 76, 0.18);
    padding: 8px 18px calc(18px + env(safe-area-inset-bottom));
    transform: translateY(105%);
    transition: transform 0.28s ease;
    max-height: 86dvh;
    overflow-y: auto;
  }
  .m-sheet.open { transform: translateY(0); }

  .m-sheet-close {
    float: right;
    width: 32px;
    height: 32px;
    border: none;
    background: #f0f2f8;
    color: var(--text-2);
    font-size: 14px;
    border-radius: 50%;
    cursor: pointer;
    margin-top: 2px;
  }

  .m-sheet-body { clear: both; text-align: center; }
  .m-sheet-avatar {
    width: 72px;
    height: 72px;
    margin: 6px auto 10px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-size: 30px;
    font-weight: 700;
    color: #fff;
    background: linear-gradient(135deg, #4b6bfb, #7c5cff);
  }
  .m-sheet-name {
    margin: 0;
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
  }
  .m-sheet-sub {
    margin: 8px 0 12px;
    color: var(--text-2);
    font-size: 13px;
    line-height: 1.6;
  }
  .m-sheet-tags { justify-content: center; margin-bottom: 16px; }

  .m-sheet-actions { display: flex; flex-direction: column; gap: 10px; }
  .m-action {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-decoration: none;
    padding: 13px;
    border-radius: 14px;
    font-size: 15px;
    font-weight: 600;
    background: var(--accent);
    color: #fff;
  }
  .m-action-gh {
    background: #f2f4fa;
    color: var(--text);
    border: 1px solid var(--line);
  }
  .m-sheet-note {
    margin: 16px 0 0;
    font-size: 11.5px;
    color: #9aa1af;
    line-height: 1.5;
  }

  .foot { display: none; }
}
