:root {
  --blue: #5ac2fe;
  --purple: #bc5bf5;
  --orange: #fda565;
  --ink: #292733;
  --muted: #777382;
  --paper: #f7f4ef;
  --card: rgba(255, 255, 255, 0.84);
  --line: rgba(52, 46, 68, 0.09);
  --shadow: 0 28px 80px rgba(77, 65, 96, 0.16);
  --title-size: clamp(30px, 2.4vw, 36px);
  --body-size: 15px;
  --control-size: 14px;
  --viewport-height: 100dvh;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body { min-height: 100vh; margin: 0; background: radial-gradient(circle at 50% -20%, #fff 0, var(--paper) 56%); }
body.support-open { overflow: hidden; }
button, textarea { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

.ambient { position: fixed; width: 38vw; height: 38vw; border-radius: 999px; filter: blur(90px); opacity: .16; pointer-events: none; }
.ambient-blue { background: var(--blue); left: -16vw; top: 18vh; }
.ambient-orange { background: var(--orange); right: -18vw; bottom: -12vw; }

.topbar { width: min(1180px, calc(100% - 40px)); margin: 0 auto; min-height: 84px; padding-top: env(safe-area-inset-top); display: flex; align-items: center; justify-content: space-between; position: relative; z-index: 2; }
.brand { display: inline-flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.brand img { width: 44px; height: 44px; object-fit: cover; border-radius: 12px; }
.brand span { display: grid; gap: 2px; }
.brand strong { font-size: 17px; letter-spacing: .04em; }
.brand small { font-size: 11px; color: var(--muted); letter-spacing: .08em; }
.status { display: inline-flex; align-items: center; gap: 8px; padding: 9px 13px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font-size: 12px; background: rgba(255,255,255,.58); backdrop-filter: blur(12px); }
.status i { width: 7px; height: 7px; border-radius: 50%; background: #63c995; box-shadow: 0 0 0 4px rgba(99,201,149,.14); }

.layout { width: min(1180px, calc(100% - 40px)); height: calc(var(--viewport-height) - 104px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); min-height: 0; margin: 0 auto calc(20px + env(safe-area-inset-bottom)); display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(420px, 1fr); gap: clamp(24px, 3vw, 48px); align-items: center; position: relative; z-index: 1; }
.intro { min-width: 0; display: grid; grid-template-columns: minmax(150px, .48fr) minmax(0, 1fr); gap: clamp(16px, 2vw, 30px); align-items: center; }
.intro-copy { min-width: 0; }
.character-wrap { min-height: 0; grid-row: span 2; display: flex; align-items: center; justify-content: center; }
.character { display: block; width: min(100%, 330px); height: auto; aspect-ratio: 1; object-fit: cover; border-radius: 28px; box-shadow: 0 24px 48px rgba(47,38,58,.13); }
.eyebrow { color: #8c839b !important; font-size: 11px !important; font-weight: 700; letter-spacing: .18em; margin: 0 0 15px !important; }
.intro h1 { margin: 0; max-width: 520px; font-size: var(--title-size); line-height: 1.22; letter-spacing: -.035em; font-weight: 650; text-wrap: balance; overflow-wrap: anywhere; }
.intro h1 span { display: block; }
.intro h1 .title-mobile { display: none; }
.intro-copy > p { max-width: 510px; margin: 22px 0 0; color: var(--muted); font-size: var(--body-size); line-height: 1.75; }
.suggestions { grid-column: 2; display: flex; flex-wrap: wrap; gap: 8px; margin: 0; }
.suggestions button { border: 1px solid rgba(188,91,245,.17); background: rgba(255,255,255,.72); color: #6e647b; border-radius: 999px; padding: 9px 13px; font-size: var(--control-size); cursor: pointer; transition: .2s ease; }
.suggestions button:hover { transform: translateY(-2px); border-color: rgba(188,91,245,.42); color: var(--ink); }

.chat-card { min-width: 0; height: min(800px, 100%); min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr) auto auto; background: var(--card); border: 1px solid rgba(255,255,255,.9); border-radius: 28px; box-shadow: var(--shadow); backdrop-filter: blur(24px); overflow: hidden; }
.chat-head { display: flex; align-items: center; gap: 12px; padding: 20px 22px; border-bottom: 1px solid var(--line); }
.avatar { width: 42px; height: 42px; border-radius: 14px; flex: none; overflow: hidden; border: 1px solid rgba(188,91,245,.13); }
.avatar img { display: block; width: 100%; height: 100%; object-fit: cover; }
.chat-head > div:nth-child(2) { display: grid; gap: 3px; }
.chat-head strong { font-size: 14px; }
.chat-head span { color: var(--muted); font-size: 11px; }
.human-button { margin-left: auto; min-height: 40px; padding: 0 14px; border: 1px solid rgba(188,91,245,.28); border-radius: 12px; background: #faf5ff; color: #75538d; font-size: 13px; font-weight: 650; white-space: nowrap; cursor: pointer; }
.human-button:hover, .human-button.active { border-color: rgba(188,91,245,.55); background: #f4e8ff; }
.human-button:focus-visible, .back-to-chat:focus-visible, .save-qr-button:focus-visible, .icon-button:focus-visible, .suggestions button:focus-visible { outline: 3px solid var(--blue); outline-offset: 3px; }
.icon-button { flex: none; border: 0; background: transparent; color: #9a94a2; width: 40px; height: 40px; border-radius: 50%; cursor: pointer; font-size: 22px; transition: .2s; }
.icon-button:hover { background: rgba(188,91,245,.08); color: var(--purple); }

.messages { min-height: 0; overflow-y: auto; padding: 24px 20px; scroll-behavior: smooth; }
.human-panel { position: fixed; inset: 0; width: min(420px, calc(100% - 32px)); max-width: none; max-height: calc(var(--viewport-height) - 32px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); margin: auto; padding: 28px; overflow: auto; border: 1px solid rgba(255,255,255,.9); border-radius: 26px; background: #fffdfa; color: var(--ink); box-shadow: 0 24px 100px rgba(41,39,51,.25); }
.human-panel::backdrop { background: rgba(34,29,44,.36); backdrop-filter: blur(7px); }
.human-panel-inner { width: 100%; display: grid; justify-items: center; gap: 14px; text-align: center; }
.human-kicker { margin: 0 0 8px; color: #8664a3; font-size: 11px; font-weight: 700; letter-spacing: .16em; }
.human-panel h2 { margin: 0; font-size: clamp(24px, 2.2vw, 30px); line-height: 1.3; font-weight: 650; }
.human-description { margin: 10px auto 0; max-width: 340px; color: var(--muted); font-size: 14px; line-height: 1.65; }
.human-qr-frame { width: min(100%, 252px); aspect-ratio: 1; margin: 0 auto; }
.human-qr-frame svg { display: block; width: 100%; height: 100%; border-radius: 20px; }
.human-qr-hint { margin: 0; max-width: 280px; color: var(--muted); font-size: 12px; line-height: 1.5; }
.human-actions { display: flex; justify-content: center; flex-wrap: wrap; gap: 10px; margin: 0; }
.save-qr-button, .back-to-chat { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; padding: 0 17px; border-radius: 12px; font-size: 13px; font-weight: 650; text-decoration: none; cursor: pointer; }
.save-qr-button { border: 1px solid var(--ink); background: var(--ink); color: #fff; }
.back-to-chat { border: 1px solid var(--line); background: #fff; color: var(--ink); }
.message { display: flex; margin: 0 0 16px; animation: message-in .28s ease both; }
.message.user { justify-content: flex-end; }
.bubble { max-width: 86%; padding: 13px 16px; border-radius: 19px 19px 19px 6px; font-size: 14px; line-height: 1.65; white-space: pre-wrap; overflow-wrap: anywhere; background: #f0edf3; }
.user .bubble { color: #fff; border-radius: 19px 19px 6px 19px; background: linear-gradient(135deg, var(--purple), #8c73f6 58%, var(--blue)); box-shadow: 0 10px 22px rgba(158,91,245,.18); }
.bubble.thinking { display: flex; gap: 5px; width: 58px; }
.bubble.thinking i { width: 6px; height: 6px; border-radius: 50%; background: #9991a4; animation: dots 1.1s infinite; }
.bubble.thinking i:nth-child(2) { animation-delay: .16s; }
.bubble.thinking i:nth-child(3) { animation-delay: .32s; }

.composer { margin: 0 16px; padding: 12px; border: 1px solid rgba(77,66,90,.12); background: rgba(255,255,255,.82); border-radius: 20px; transition: .2s; }
.composer:focus-within { border-color: rgba(188,91,245,.38); box-shadow: 0 0 0 4px rgba(188,91,245,.08); }
.composer textarea { display: block; width: 100%; max-height: 128px; resize: none; border: 0; outline: 0; background: transparent; color: var(--ink); padding: 2px 3px 10px; font-size: 16px; line-height: 1.55; }
.composer textarea::placeholder { color: #aaa4b0; }
.composer-actions { display: flex; align-items: center; gap: 8px; }
.voice-button, .send-button { border: 0; border-radius: 12px; min-height: 40px; cursor: pointer; transition: .2s ease; }
.voice-button { display: inline-flex; align-items: center; gap: 7px; padding: 0 12px; color: #746d7d; background: #f3f0f5; }
.voice-button:hover { color: var(--purple); }
.voice-button.listening { color: #fff; background: #ee6f84; animation: pulse 1.3s infinite; }
.mic-icon { width: 11px; height: 16px; border: 2px solid currentColor; border-radius: 8px; position: relative; }
.mic-icon::after { content: ""; position: absolute; left: 50%; transform: translateX(-50%); bottom: -6px; width: 15px; height: 8px; border: 2px solid currentColor; border-top: 0; border-radius: 0 0 9px 9px; }
.voice-label { font-size: 12px; }
.voice-status { flex: 1; min-width: 0; color: #9a94a2; font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.send-button { padding: 0 15px; color: #fff; background: var(--ink); font-size: 13px; }
.send-button span { margin-left: 6px; font-size: 16px; }
.send-button:hover { transform: translateY(-1px); background: #17151e; }
.send-button:disabled, .voice-button:disabled { cursor: not-allowed; opacity: .5; transform: none; }
.privacy { margin: 10px 20px 16px; color: #9a95a0; font-size: 10px; line-height: 1.45; text-align: center; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@keyframes message-in { from { transform: translateY(7px); opacity: 0; } }
@keyframes dots { 0%,60%,100% { transform: translateY(0); opacity: .35; } 30% { transform: translateY(-4px); opacity: 1; } }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(238,111,132,.15); } }

@media (max-width: 1100px) {
  :root { --title-size: clamp(28px, 3.6vw, 36px); }
  .layout { width: min(850px, calc(100% - 40px)); grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); gap: 20px; align-items: stretch; }
  .intro { grid-template-columns: minmax(120px, 180px) minmax(0, 1fr); gap: 16px 24px; }
  .character { width: min(180px, 100%); }
  .chat-card { height: 100%; }
}

@media (max-width: 640px) {
  :root { --title-size: clamp(23px, 5.9vw, 28px); --body-size: 13px; --control-size: 12px; }
  .topbar, .layout { width: min(100% - 24px, 560px); }
  .topbar { min-height: calc(64px + env(safe-area-inset-top)); }
  .status { padding: 8px 10px; font-size: 10px; }
  .brand small { display: none; }
  .layout { height: calc(var(--viewport-height) - 76px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); gap: 14px; margin-bottom: calc(12px + env(safe-area-inset-bottom)); }
  .intro { grid-template-columns: 76px minmax(0, 1fr); gap: 12px; align-items: center; }
  .intro h1 .title-full { display: none; }
  .intro h1 .title-mobile { display: block; }
  .character-wrap { grid-row: auto; }
  .character { width: 100%; border-radius: 16px; }
  .intro-copy > p:not(.eyebrow) { display: none; }
  .eyebrow { margin-bottom: 8px !important; }
  .suggestions { grid-column: 1 / -1; gap: 6px; }
  .suggestions button { font-size: 12px; padding: 8px 10px; }
  .chat-card { height: 100%; border-radius: 23px; }
  .chat-head { padding: 12px; gap: 8px; }
  .human-button { padding-inline: 11px; font-size: 12px; }
  .human-panel { padding: 22px 18px; }
  .human-qr-frame { width: min(100%, 232px); }
  .messages { padding: 20px 14px; }
  .bubble { max-width: 91%; }
  .privacy { margin-inline: 14px; }
}

@media (max-width: 375px) {
  :root { --title-size: 23px; }
  .intro { grid-template-columns: 64px minmax(0, 1fr); gap: 10px; }
  .eyebrow { font-size: 9px !important; }
  .chat-head > div:nth-child(2) span { display: none; }
  .human-qr-frame { width: min(100%, 210px); }
  .suggestions button { padding: 8px; font-size: 11px; }
  .composer { margin-inline: 10px; padding: 10px; }
}

@media (orientation: landscape) and (max-width: 1100px) {
  .layout { width: min(1180px, calc(100% - 32px)); grid-template-columns: minmax(190px, .7fr) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); gap: 22px; align-items: center; }
  .intro { grid-template-columns: 1fr; gap: 16px; }
  .character-wrap { grid-row: auto; justify-content: flex-start; }
  .character { width: 130px; }
  .intro h1 { font-size: 28px; }
  .intro h1 .title-full { display: none; }
  .intro h1 .title-mobile { display: block; }
  .intro-copy > p:not(.eyebrow) { display: none; }
  .suggestions { grid-column: 1; }
}

@media (orientation: landscape) and (max-height: 540px) {
  .topbar { min-height: calc(50px + env(safe-area-inset-top)); }
  .topbar, .layout { width: calc(100% - 24px - env(safe-area-inset-left) - env(safe-area-inset-right)); }
  .brand img { width: 32px; height: 32px; border-radius: 9px; }
  .brand small { display: none; }
  .layout { height: calc(var(--viewport-height) - 62px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); grid-template-columns: minmax(170px, .55fr) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); gap: 16px; margin-bottom: calc(12px + env(safe-area-inset-bottom)); }
  .intro { grid-template-columns: 1fr; gap: 10px; }
  .character-wrap { grid-row: auto; justify-content: flex-start; }
  .character { width: 64px; border-radius: 13px; }
  .intro h1 { font-size: 22px; }
  .intro h1 .title-full { display: none; }
  .intro h1 .title-mobile { display: block; }
  .eyebrow, .intro-copy > p { display: none; }
  .suggestions { grid-column: 1; gap: 6px; }
  .suggestions button { padding: 7px 9px; font-size: 11px; }
  .chat-head { padding: 8px 12px; gap: 8px; }
  .avatar { width: 34px; height: 34px; border-radius: 11px; }
  .chat-head > div:nth-child(2) span { display: none; }
  .messages { padding: 12px; }
  .bubble { padding: 10px 12px; font-size: 13px; }
  .composer { padding: 8px 10px; margin-inline: 10px; border-radius: 15px; }
  .composer textarea { max-height: 66px; padding-bottom: 5px; }
  .privacy { margin: 5px 12px 7px; font-size: 9px; }
  .human-panel { width: min(640px, calc(100% - 32px)); padding: 22px; }
  .human-panel-inner { grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: 12px 24px; align-items: center; }
  .human-heading { grid-column: 2; grid-row: 1; }
  .human-qr-frame { grid-column: 1; grid-row: 1 / 4; width: min(100%, 240px, calc(var(--viewport-height) - 90px)); }
  .human-qr-hint { grid-column: 2; }
  .human-actions { grid-column: 2; gap: 8px; }
  .save-qr-button, .back-to-chat { padding-inline: 12px; }
}

@media (orientation: portrait) and (max-height: 680px) {
  .human-panel { padding-block: 18px; }
  .human-panel-inner { gap: 10px; }
  .human-qr-frame { width: min(100%, 210px); }
}

.keyboard-open .topbar, .keyboard-open .intro { display: none; }
.keyboard-open .layout { height: calc(var(--viewport-height) - 12px); margin-block: 6px; grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
.keyboard-open .chat-card { height: 100%; }

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