:root {
  color-scheme: dark;
  --page: #0b1119;
  --surface: #111b28;
  --surface-raised: #182536;
  --surface-soft: #202e40;
  --line: #27384b;
  --text: #eef3f8;
  --muted: #97a8bc;
  --muted-dim: #73859a;
  --teal: #25c3bd;
  --teal-deep: #116d73;
  --danger: #ffb2ad;
  --font: "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", sans-serif;
  font-family: var(--font);
  color: var(--text);
  background: var(--page);
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  scrollbar-color: #35485e transparent;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body { background: radial-gradient(ellipse at 50% -30%, #203247 0, var(--page) 62%); }
button, textarea { font: inherit; }
button { color: inherit; }
[hidden] { display: none !important; }

.app-shell {
  width: min(100%, 1100px);
  height: min(var(--visual-height, 100dvh), 1040px);
  min-height: 440px;
  margin: max(0px, calc((100dvh - 1040px) / 2)) auto 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: linear-gradient(145deg, #111b28 0%, #0f1925 52%, #101b29 100%);
  border: 1px solid #233347;
  border-radius: 22px;
  box-shadow: 0 28px 90px #02070d80, inset 0 1px #ffffff05;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.app-header {
  flex: 0 0 auto;
  min-height: 94px;
  padding: 17px 30px;
  display: flex;
  align-items: center;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  background: #182432a8;
}
.brand { display: flex; align-items: center; gap: 15px; min-width: 0; }
.bear-avatar { display: block; object-fit: contain; }
.brand-avatar { width: 58px; height: 58px; flex: 0 0 58px; border-radius: 50%; }
.brand-copy strong { display: block; font-size: 22px; line-height: 1.2; font-weight: 600; letter-spacing: .04em; }
.brand-copy small { display: block; margin-top: 5px; color: var(--muted); font-size: 13px; letter-spacing: .025em; }
.header-actions { display: flex; align-items: center; gap: 11px; margin-left: auto; }
.connection { display: inline-flex; align-items: center; gap: 8px; margin-right: 6px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.connection i { width: 8px; height: 8px; border-radius: 50%; background: #d7a35a; box-shadow: 0 0 12px #d7a35a55; }
.connection[data-state="ready"] i { background: var(--teal); box-shadow: 0 0 12px #25c3bd70; }
.connection[data-state="offline"] i { background: #e27676; box-shadow: 0 0 12px #e2767655; }
.icon-button, .share-button {
  height: 42px; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid #34485d; border-radius: 12px; background: #121d2a; color: #dce6f0;
  cursor: pointer; transition: border-color .18s, background .18s, transform .18s;
}
.icon-button:hover, .share-button:hover { background: #203044; border-color: #4d657e; transform: translateY(-1px); }
.icon-button { width: 42px; padding: 0; }
.icon-button svg, .share-button svg, .send-button svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.share-button { padding: 0 13px; font-size: 13px; }
.share-button svg { width: 17px; height: 17px; }

.chat-main { flex: 1 1 auto; min-height: 0; width: 100%; overflow-y: auto; overscroll-behavior: contain; padding: 26px clamp(20px, 6vw, 82px) 20px; scroll-behavior: smooth; }
.empty-state { min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 12px 0 34px; animation: fade-in .35s ease-out; }
.hero-avatar { width: 82px; height: 82px; margin-bottom: 20px; border-radius: 50%; }
.eyebrow { margin: 0 0 11px; color: #91a4b9; font-size: 11px; letter-spacing: .11em; }
h1 { margin: 0; color: #ecf2f8; font-size: clamp(27px, 4vw, 34px); font-weight: 500; letter-spacing: .045em; }
.intro { margin: 12px 0 26px; color: var(--muted); font-size: 14px; }
.suggestions { width: min(100%, 520px); display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.suggestion { min-height: 52px; padding: 10px 13px; display: flex; align-items: center; justify-content: space-between; gap: 10px; border: 1px solid #2c3d50; border-radius: 13px; background: #151f2c; color: #c8d5e3; text-align: left; cursor: pointer; font-size: 12px; line-height: 1.5; transition: background .18s, border-color .18s, transform .18s; }
.suggestion:hover { transform: translateY(-2px); border-color: #46717a; background: #192c37; }
.suggestion svg { flex: 0 0 14px; width: 14px; height: 14px; fill: none; stroke: #8295aa; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.messages { display: flex; flex-direction: column; gap: 21px; width: min(100%, 790px); margin: 4px auto; padding: 0 0 8px; }
.message { display: flex; align-items: flex-end; gap: 11px; max-width: 91%; animation: fade-in .2s ease-out; }
.message.user { align-self: flex-end; }
.message.assistant { align-self: flex-start; }
.message-avatar { width: 42px; height: 42px; flex: 0 0 42px; border-radius: 50%; }
.bubble { min-width: 58px; max-width: 100%; padding: 14px 18px; border: 1px solid #2b3c50; border-radius: 18px 18px 18px 5px; background: linear-gradient(145deg, #202e40, #1b293a); color: #e6edf5; font-size: 15px; line-height: 1.85; white-space: pre-wrap; overflow-wrap: anywhere; box-shadow: 0 5px 20px #02070b22; }
.user .bubble { border-color: #167a80; border-radius: 18px 18px 5px 18px; background: linear-gradient(145deg, #177980, #12666f); color: #f1ffff; }
.typing-bubble { display: inline-flex; align-items: center; gap: 5px; min-height: 44px; padding: 0 15px; border: 1px solid #2b3c50; border-radius: 16px 16px 16px 5px; background: #202e40; color: #a9b7c7; font-size: 12px; }
.typing-row { width: min(100%, 790px); margin: 0 auto 8px; display: flex; align-items: flex-end; gap: 11px; animation: fade-in .2s ease-out; }
.small-avatar { width: 42px; height: 42px; flex: 0 0 42px; border-radius: 50%; }
.typing-bubble i { width: 5px; height: 5px; border-radius: 50%; background: #65b9b7; animation: pulse 1.1s infinite ease-in-out; }
.typing-bubble i:nth-child(2) { animation-delay: .15s; }
.typing-bubble i:nth-child(3) { animation-delay: .3s; margin-right: 5px; }
.retry-row { width: min(100%, 790px); margin: 8px auto 4px; padding-left: 53px; display: flex; align-items: center; gap: 13px; color: var(--danger); font-size: 12px; }
.retry-row p { margin: 0; }
.retry-row button { padding: 7px 12px; border: 1px solid #68474a; border-radius: 9px; background: #36262d; color: #ffd7d3; cursor: pointer; }

.composer-dock { flex: 0 0 auto; padding: 14px clamp(18px, 6vw, 82px) max(14px, env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--line); background: #111b28eF; }
.composer { width: min(100%, 790px); min-height: 68px; margin: 0 auto; padding: 9px 10px 9px 20px; display: flex; align-items: center; gap: 12px; border: 1px solid #3b5069; border-radius: 999px; background: linear-gradient(145deg, #182535, #1a293a); box-shadow: inset 0 1px #ffffff05; transition: border-color .2s, box-shadow .2s; }
.composer:focus-within { border-color: #339b9d; box-shadow: 0 0 0 3px #25c3bd16, inset 0 1px #ffffff05; }
.composer textarea { flex: 1; width: 100%; min-width: 0; max-height: 144px; resize: none; overflow-y: auto; border: 0; outline: 0; background: transparent; color: var(--text); font-size: 15px; line-height: 1.6; padding: 8px 0; }
.composer textarea::placeholder { color: #8597ad; }
.send-button { width: 48px; height: 48px; flex: 0 0 48px; display: grid; place-items: center; border: 0; border-radius: 50%; background: linear-gradient(145deg, #2bcac4, #20aaa9); color: #efffff; cursor: pointer; box-shadow: 0 5px 15px #0a757566; transition: transform .18s, filter .18s; }
.send-button:hover:not(:disabled) { transform: scale(1.04); filter: brightness(1.08); }
.send-button:disabled { opacity: .42; cursor: default; box-shadow: none; }
.send-button svg { width: 22px; height: 22px; fill: currentColor; stroke-width: 1.1; }
.disclaimer { margin: 10px 0 0; color: #7e90a4; text-align: center; font-size: 11px; }
.disclaimer button { margin-left: 8px; padding: 2px 0; border: 0; background: none; color: #9bb2c8; text-decoration: underline; text-underline-offset: 2px; cursor: pointer; font-size: inherit; }
.icp-record { display: block; margin-top: 5px; color: #7e90a4; text-align: center; font-size: 10px; text-decoration: none; }
.icp-record:hover { text-decoration: underline; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.toast { position: fixed; z-index: 10; left: 50%; bottom: max(22px, env(safe-area-inset-bottom, 0px)); max-width: min(90vw, 480px); padding: 11px 16px; transform: translate(-50%, 10px); opacity: 0; pointer-events: none; border: 1px solid #33475b; border-radius: 12px; background: #1c2938; color: #edf4fa; box-shadow: 0 10px 35px #02070d8c; text-align: center; font-size: 13px; transition: opacity .2s, transform .2s; }
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.about-dialog { width: min(490px, calc(100% - 32px)); max-height: min(82vh, 680px); padding: 30px; border: 1px solid #35485d; border-radius: 20px; background: #14202e; color: var(--text); box-shadow: 0 25px 90px #0009; }
.about-dialog::backdrop { background: #04080dbb; backdrop-filter: blur(5px); }
.dialog-avatar { width: 62px; height: 62px; margin-bottom: 16px; border-radius: 50%; }
.about-dialog h2 { margin: 0 0 12px; font-size: 21px; font-weight: 500; }
.about-dialog p { color: #aab9c9; font-size: 13px; line-height: 1.9; }
.dialog-close { float: right; width: 34px; height: 34px; border: 1px solid #35485d; border-radius: 10px; background: #1b2a3b; color: #c9d4df; cursor: pointer; font-size: 22px; line-height: 1; }
.dialog-confirm { margin-top: 8px; padding: 10px 17px; border: 0; border-radius: 10px; background: #1c8589; color: white; cursor: pointer; }

@keyframes fade-in { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }
@keyframes pulse { 0%, 60%, 100% { opacity: .42; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }

@media (max-width: 700px) {
  .app-shell { width: 100%; height: var(--visual-height, 100dvh); min-height: 360px; margin: 0; border: 0; border-radius: 0; box-shadow: none; }
  .app-header { min-height: 72px; padding: 10px 15px; gap: 8px; }
  .brand { gap: 10px; }
  .brand-avatar { width: 44px; height: 44px; flex-basis: 44px; }
  .brand-copy strong { font-size: 17px; }
  .brand-copy small { margin-top: 2px; font-size: 11px; }
  .header-actions { gap: 8px; }
  .connection { width: 8px; height: 28px; margin: 0 2px; overflow: visible; }
  .connection span { position: absolute; width: 1px; height: 1px; clip: rect(0,0,0,0); overflow: hidden; }
  .icon-button { width: 38px; height: 38px; border-radius: 11px; }
  .share-button { width: 38px; height: 38px; padding: 0; border-radius: 11px; }
  .share-button span { position: absolute; width: 1px; height: 1px; clip: rect(0,0,0,0); overflow: hidden; }
  .chat-main { padding: 16px 15px 13px; }
  .empty-state { padding: 10px 0 24px; }
  .hero-avatar { width: 68px; height: 68px; margin-bottom: 15px; }
  .eyebrow { font-size: 10px; }
  h1 { font-size: 27px; }
  .intro { margin: 9px 0 20px; font-size: 13px; }
  .suggestions { max-width: 390px; grid-template-columns: 1fr; gap: 8px; }
  .suggestion { min-height: 47px; padding: 9px 13px; font-size: 12px; }
  .messages { gap: 15px; }
  .message { max-width: 96%; gap: 8px; }
  .message-avatar { width: 34px; height: 34px; flex-basis: 34px; }
  .typing-row { gap: 8px; }
  .small-avatar { width: 34px; height: 34px; flex-basis: 34px; }
  .bubble { padding: 11px 14px; font-size: 14px; line-height: 1.75; }
  .retry-row { padding-left: 42px; flex-wrap: wrap; }
  .composer-dock { padding: 10px 13px max(9px, env(safe-area-inset-bottom, 0px)); }
  .composer { min-height: 58px; padding: 6px 7px 6px 16px; gap: 8px; }
  .composer textarea { font-size: 16px; padding: 7px 0; }
  .send-button { width: 44px; height: 44px; flex-basis: 44px; }
  .disclaimer { margin-top: 7px; font-size: 10px; }
  .about-dialog { padding: 22px; }
}

@media (max-height: 560px) {
  .app-header { min-height: 62px; padding-block: 7px; }
  .brand-avatar { width: 42px; height: 42px; flex-basis: 42px; }
  .hero-avatar { width: 54px; height: 54px; margin: 0 0 8px; }
  .empty-state { padding: 4px 0 10px; }
  .intro { margin-bottom: 13px; }
  .suggestions { gap: 6px; }
  .suggestion { min-height: 40px; padding-block: 6px; }
  .composer-dock { padding-top: 7px; }
  .composer { min-height: 50px; }
  .send-button { width: 40px; height: 40px; flex-basis: 40px; }
  .disclaimer { margin-top: 4px; }
}

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