:root {
  color-scheme: light;
  --sky: #7ed4ff;
  --sky-deep: #47b8f2;
  --sky-pale: #dff5ff;
  --navy: #173b59;
  --navy-soft: #4b7390;
  --white: #fff;
  --yellow: #ffe276;
  --peach: #ffad91;
  --pink: #ff96be;
  --mint: #86e4cc;
  --lavender: #b6b8ff;
  --shadow: 0 12px 30px rgba(34, 116, 161, .18);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html, body { width: 100%; min-height: 100%; margin: 0; }
body {
  overflow: hidden;
  background: #bceaff;
  color: var(--navy);
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, canvas { -webkit-tap-highlight-color: transparent; }
button { font: inherit; }

.app {
  position: relative;
  width: min(100vw, 500px);
  height: 100vh;
  height: 100dvh;
  min-height: 650px;
  margin: 0 auto;
  overflow: hidden;
  isolation: isolate;
  background:
    radial-gradient(circle at 18% 16%, rgba(255,255,255,.55) 0 2px, transparent 3px),
    radial-gradient(circle at 82% 26%, rgba(255,255,255,.42) 0 2px, transparent 3px),
    linear-gradient(180deg, #bfeeff 0%, #8cddff 47%, #75cef8 100%);
  box-shadow: 0 0 50px rgba(40, 125, 170, .2);
}

.sky-shape { position: absolute; z-index: 0; border-radius: 50%; pointer-events: none; }
.sky-shape-one { width: 330px; height: 330px; top: -205px; right: -120px; background: rgba(255,255,255,.36); box-shadow: -90px 112px 0 -60px rgba(255,255,255,.2); }
.sky-shape-two { width: 260px; height: 110px; bottom: -65px; left: -80px; background: rgba(255,255,255,.25); transform: rotate(-10deg); }
.sparkles { position: absolute; z-index: 1; inset: 0; pointer-events: none; }
.sparkles i { position: absolute; width: 7px; height: 7px; border-radius: 50%; background: rgba(255,255,255,.8); box-shadow: 0 0 14px rgba(255,255,255,.9); animation: sparkle 2.6s ease-in-out infinite; }
.sparkles i:nth-child(1) { left: 8%; top: 27%; }
.sparkles i:nth-child(2) { right: 12%; top: 18%; animation-delay: -.7s; }
.sparkles i:nth-child(3) { left: 15%; top: 66%; width: 4px; height: 4px; animation-delay: -1.2s; }
.sparkles i:nth-child(4) { right: 8%; top: 71%; width: 5px; height: 5px; animation-delay: -.2s; }
.sparkles i:nth-child(5) { left: 8%; top: 47%; width: 3px; height: 3px; animation-delay: -1.7s; }
.sparkles i:nth-child(6) { right: 22%; top: 53%; width: 3px; height: 3px; animation-delay: -2.1s; }

.topbar { position: absolute; z-index: 12; top: 0; left: 0; width: 100%; display: flex; justify-content: space-between; align-items: center; padding: max(15px, env(safe-area-inset-top)) 18px 8px; }
.brand { display: flex; align-items: center; gap: 9px; }
.brand-mark { display: grid; place-items: center; width: 33px; height: 33px; border: 2px solid rgba(23,59,89,.72); border-radius: 11px 8px 12px 8px; font: 700 18px/1 serif; transform: rotate(-5deg); background: rgba(255,255,255,.35); }
.brand > span:last-child { display: grid; gap: 2px; }
.brand strong { font-size: 11px; letter-spacing: .09em; }
.brand small { color: rgba(23,59,89,.52); font-size: 6px; letter-spacing: .15em; }
.top-actions { display: flex; align-items: center; gap: 6px; }
.online { display: inline-flex; align-items: center; gap: 6px; padding: 7px 10px; border: 1px solid rgba(23,59,89,.12); border-radius: 999px; background: rgba(255,255,255,.48); color: var(--navy-soft); font-size: 9px; font-weight: 600; backdrop-filter: blur(8px); }
.online i { width: 6px; height: 6px; border-radius: 50%; background: #34ca8c; box-shadow: 0 0 0 3px rgba(52,202,140,.16); }
.sound-toggle { display: grid; place-items: center; width: 31px; height: 31px; padding: 0; border: 1px solid rgba(23,59,89,.12); border-radius: 50%; background: rgba(255,255,255,.62); color: var(--navy); box-shadow: 0 5px 14px rgba(34,116,161,.1); cursor: pointer; backdrop-filter: blur(8px); }
.sound-toggle span { font-size: 13px; line-height: 1; }
.sound-toggle[aria-pressed="true"] { color: rgba(23,59,89,.46); background: rgba(255,255,255,.4); }
.sound-toggle:focus-visible { outline: 2px solid #3180a9; outline-offset: 2px; }

.intro { position: absolute; z-index: 10; top: max(76px, calc(env(safe-area-inset-top) + 55px)); left: 0; width: 100%; padding: 0 22px; text-align: center; pointer-events: none; transition: opacity .35s ease, transform .35s ease; }
.intro p { margin: 0 0 5px; color: rgba(23,59,89,.6); font-size: 10px; font-weight: 700; letter-spacing: .16em; }
.intro h1 { margin: 0; font-size: clamp(29px, 8.2vw, 38px); line-height: 1.12; letter-spacing: -.03em; }
.intro h1 span { position: relative; display: inline-block; margin: 0 3px; color: #147caf; }
.intro h1 span::after { position: absolute; right: -11px; top: -8px; content: "✦"; color: #fff; font-size: 11px; text-shadow: 0 2px 8px rgba(38,128,177,.25); }
.intro small { display: inline-block; margin-top: 8px; color: var(--navy-soft); font-size: 10px; letter-spacing: .04em; }

.character-stage { position: absolute; z-index: 3; inset: 0; }
#character-canvas { position: absolute; z-index: 2; inset: 0; display: block; width: 100%; height: 100%; pointer-events: auto; touch-action: none; cursor: grab; }
#character-canvas.is-dragging { cursor: grabbing; }
#character-canvas:focus-visible { outline: 2px dashed rgba(23,124,175,.5); outline-offset: -7px; }
.interaction-effects { position: absolute; z-index: 8; inset: 0; overflow: hidden; pointer-events: none; }
.gesture-spark { position: absolute; display: grid; place-items: center; width: 25px; height: 25px; margin: -12px 0 0 -12px; border-radius: 50%; color: #fff; background: rgba(255,255,255,.78); box-shadow: 0 7px 18px rgba(39,121,163,.14); font-size: 13px; font-style: normal; font-weight: 800; opacity: 0; animation: gestureBurst .95s cubic-bezier(.16,.75,.28,1) forwards; animation-delay: var(--delay, 0ms); }
.gesture-spark.is-heart { color: #f36f9f; background: #fff0f6; }
.gesture-spark.is-note { color: #4bb9aa; background: #eafff9; }
.name-tag { position: absolute; z-index: 6; left: 50%; top: 70.5%; display: flex; align-items: center; gap: 5px; padding: 6px 10px 6px 7px; border-radius: 999px; background: rgba(255,255,255,.86); box-shadow: 0 8px 20px rgba(44,129,174,.15); transform: translateX(-50%); transition: opacity .3s ease, transform .4s ease; }
.name-tag span { padding: 4px 7px; border-radius: 999px; background: var(--yellow); color: #795d00; font-size: 8px; font-weight: 700; }
.name-tag strong { font-size: 11px; letter-spacing: .08em; }
.name-tag i { color: #ff9c47; font-style: normal; font-size: 10px; }

.question-field { position: absolute; z-index: 7; inset: 0 0 max(52px, env(safe-area-inset-bottom)); pointer-events: none; }
.question-bubble { position: absolute; width: 108px; min-height: 52px; padding: 6px 7px; display: flex; align-items: center; gap: 5px; border: 2px solid rgba(255,255,255,.78); border-radius: 15px; color: var(--navy); background: rgba(255,255,255,.92); box-shadow: 0 8px 20px rgba(34,116,161,.13); text-align: left; line-height: 1.24; cursor: pointer; pointer-events: auto; transform-origin: center; transition: opacity .28s ease, transform .32s cubic-bezier(.2,.8,.2,1), filter .25s ease; animation: floatBubble 3.2s ease-in-out infinite; }
.question-bubble::after { position: absolute; width: 9px; height: 9px; content: ""; background: inherit; transform: rotate(45deg); }
.question-bubble[data-side="left"]::after { right: -4px; top: 19px; }
.question-bubble[data-side="right"]::after { left: -4px; top: 19px; }
.question-bubble:hover, .question-bubble:focus-visible { filter: brightness(1.03); transform: translateY(-3px) scale(1.03); outline: none; }
.question-bubble:active { transform: scale(.97); }
.question-bubble .q-icon { flex: 0 0 auto; display: grid; place-items: center; width: 22px; height: 22px; border-radius: 8px; background: var(--bubble-accent); color: #fff; font-size: 11px; font-weight: 800; box-shadow: inset 0 -2px 0 rgba(23,59,89,.08); }
.question-bubble .q-copy { display: grid; gap: 1px; }
.question-bubble small { color: rgba(23,59,89,.48); font-size: 5.7px; font-weight: 700; letter-spacing: .055em; }
.question-bubble strong { font-size: 8.5px; font-weight: 700; }
.question-bubble:nth-child(1) { --bubble-accent: #ff9e7d; left: 9px; top: 21%; animation-delay: -.4s; }
.question-bubble:nth-child(2) { --bubble-accent: #6ecac1; right: 9px; top: 20%; animation-delay: -1.3s; }
.question-bubble:nth-child(3) { --bubble-accent: #8c9cff; left: 5px; top: 42%; width: 91px; animation-delay: -2.1s; }
.question-bubble:nth-child(4) { --bubble-accent: #f3b74f; right: 5px; top: 43%; width: 103px; animation-delay: -.8s; }
.question-bubble:nth-child(5) { --bubble-accent: #ec83b4; left: 9px; top: 68%; animation-delay: -1.7s; }
.question-bubble:nth-child(6) { --bubble-accent: #5faee9; right: 9px; top: 72%; animation-delay: -2.5s; }

.answer-bubble { position: absolute; z-index: 9; top: max(130px, calc(env(safe-area-inset-top) + 106px)); left: 50%; width: calc(100% - 54px); max-width: 336px; padding: 10px 12px 9px; border: 2px solid rgba(255,255,255,.88); border-radius: 18px 18px 18px 7px; background: rgba(255,255,255,.94); box-shadow: 0 14px 34px rgba(35,105,144,.18); opacity: 0; visibility: hidden; transform: translate(-50%, -10px) scale(.96); transition: opacity .32s ease, visibility .32s ease, transform .42s cubic-bezier(.2,.8,.2,1); }
.answer-bubble::after { position: absolute; left: 27px; bottom: -7px; width: 14px; height: 14px; content: ""; background: #fff; transform: rotate(45deg); border-radius: 0 0 3px 0; }
.answer-head { display: flex; align-items: center; gap: 7px; }
.avatar { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 10px; background: linear-gradient(145deg, #71d2c2, #3fb6aa); color: #fff; font-family: serif; font-size: 14px; font-weight: 700; box-shadow: inset 0 -3px 0 rgba(22,91,92,.12); }
.answer-head > div { display: grid; gap: 2px; }
.answer-head strong { font-size: 9.5px; }
.answer-head small { color: var(--navy-soft); font-size: 7px; }
.speaking-dot { display: flex; gap: 3px; align-items: center; margin-left: auto; padding: 5px 7px; border-radius: 999px; background: #eaf8ff; }
.speaking-dot b { width: 3px; height: 3px; border-radius: 50%; background: var(--sky-deep); animation: talkDot .9s ease-in-out infinite; }
.speaking-dot b:nth-child(2) { animation-delay: .15s; }
.speaking-dot b:nth-child(3) { animation-delay: .3s; }
.asked-question { display: inline-block; margin: 7px 0 5px; padding: 4px 7px; border-radius: 7px; background: #eaf8ff; color: #3f7998; font-size: 7px; font-weight: 700; }
.asked-question::before { content: "你问："; opacity: .65; }
.answer-text { min-height: 44px; margin: 0; color: var(--navy); font-size: 10.5px; font-weight: 600; line-height: 1.65; letter-spacing: .01em; }
.answer-text::after { display: inline-block; width: 2px; height: 11px; margin-left: 3px; content: ""; background: var(--sky-deep); vertical-align: -2px; animation: cursor .7s steps(1) infinite; }
.answer-bubble.is-complete .answer-text::after { display: none; }
.answer-progress { height: 2px; margin-top: 7px; overflow: hidden; border-radius: 999px; background: #e5f3fa; }
.answer-progress i { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #5ac7f7, #71d6c0); }
.answer-bubble button { display: block; min-height: 27px; margin: 7px 0 0 auto; padding: 0 10px; border: 0; border-radius: 999px; background: #e9f7ff; color: #3180a9; font-size: 8px; font-weight: 700; cursor: pointer; }
.answer-bubble button:focus-visible { outline: 2px solid #3180a9; outline-offset: 2px; }

.listening-pill { position: absolute; z-index: 8; left: 50%; bottom: max(82px, calc(env(safe-area-inset-bottom) + 68px)); display: flex; align-items: center; gap: 7px; padding: 8px 12px; border-radius: 999px; color: var(--navy-soft); background: rgba(255,255,255,.75); box-shadow: 0 8px 24px rgba(48,131,175,.14); font-size: 9px; opacity: 0; transform: translate(-50%, 10px); transition: opacity .3s ease, transform .3s ease; pointer-events: none; }
.listening-pill i { width: 7px; height: 7px; border-radius: 50%; background: #34ca8c; box-shadow: 0 0 0 4px rgba(52,202,140,.15); animation: pulse 1.1s ease-in-out infinite; }

.footer-bar { position: absolute; z-index: 10; bottom: 0; left: 0; width: 100%; min-height: 52px; padding: 12px 18px max(12px, env(safe-area-inset-bottom)); display: flex; justify-content: center; align-items: center; gap: 8px; color: rgba(23,59,89,.56); font-size: 8px; font-weight: 700; letter-spacing: .09em; background: linear-gradient(180deg, rgba(126,212,255,0), rgba(255,255,255,.32)); }
.footer-bar i { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; color: #fff; background: rgba(23,124,175,.68); font-size: 14px; font-style: normal; animation: tapHint 1.8s ease-in-out infinite; }

.app[data-mode="answering"] .intro { opacity: 0; transform: translateY(-10px); }
.app[data-mode="answering"] #character-canvas,
.app[data-mode="returning"] #character-canvas { pointer-events: none; }
.app[data-mode="answering"] .question-bubble { opacity: 0; transform: scale(.72); pointer-events: none; animation-play-state: paused; }
.app[data-mode="answering"] .answer-bubble { opacity: 1; visibility: visible; transform: translate(-50%, 0) scale(1); transition-delay: .16s; }
.app[data-mode="answering"] .name-tag { opacity: 0; transform: translate(-50%, 8px); }
.app[data-mode="answering"] .listening-pill { opacity: 1; transform: translate(-50%, 0); }
.app[data-mode="returning"] .answer-bubble { opacity: 0; visibility: hidden; transform: translate(-50%, -8px) scale(.97); }
.app[data-mode="returning"] .question-bubble { opacity: 0; transform: scale(.8); pointer-events: none; }

.loading { position: absolute; z-index: 40; inset: 0; display: grid; place-content: center; justify-items: center; gap: 10px; background: linear-gradient(160deg, #c8f1ff, #78d4ff); transition: opacity .45s ease, visibility .45s ease; }
.loading.is-done { opacity: 0; visibility: hidden; pointer-events: none; }
.loading-face { position: relative; width: 68px; height: 58px; border-radius: 47% 54% 46% 55%; background: #64cbbb; box-shadow: inset 0 -7px 0 rgba(31,120,113,.1), 0 15px 30px rgba(37,123,163,.18); animation: loadingBounce 1.2s ease-in-out infinite; }
.loading-face i { position: absolute; top: 19px; width: 8px; height: 11px; border-radius: 50%; background: #174950; }
.loading-face i:first-child { left: 18px; }
.loading-face i:nth-child(2) { right: 18px; }
.loading-face b { position: absolute; left: 50%; top: 36px; width: 15px; height: 7px; border-bottom: 3px solid #174950; border-radius: 50%; transform: translateX(-50%); }
.loading strong { font-size: 14px; letter-spacing: .12em; }
.loading small { color: var(--navy-soft); font-size: 9px; }
.error { position: absolute; z-index: 50; left: 50%; top: 50%; width: calc(100% - 48px); padding: 22px; border-radius: 20px; background: rgba(255,255,255,.95); box-shadow: var(--shadow); transform: translate(-50%,-50%); text-align: center; }
.error strong { color: #ef6f7f; }
.error p { margin: 8px 0 0; color: var(--navy-soft); font-size: 11px; line-height: 1.7; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }

@keyframes sparkle { 0%,100% { opacity: .3; transform: scale(.7); } 50% { opacity: 1; transform: scale(1.25); } }
@keyframes floatBubble { 0%,100% { margin-top: 0; } 50% { margin-top: -6px; } }
@keyframes talkDot { 0%,60%,100% { transform: translateY(0); opacity: .45; } 30% { transform: translateY(-3px); opacity: 1; } }
@keyframes cursor { 0%,49% { opacity: 1; } 50%,100% { opacity: 0; } }
@keyframes pulse { 0%,100% { transform: scale(.85); } 50% { transform: scale(1.25); } }
@keyframes tapHint { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }
@keyframes loadingBounce { 0%,100% { transform: translateY(0) rotate(-2deg); } 50% { transform: translateY(-9px) rotate(2deg); } }
@keyframes gestureBurst {
  0% { opacity: 0; transform: translate(0, 5px) scale(.35) rotate(-10deg); }
  20% { opacity: 1; }
  72% { opacity: 1; }
  100% { opacity: 0; transform: translate(var(--drift-x, 0), var(--drift-y, -58px)) scale(1.16) rotate(var(--turn, 12deg)); }
}

@media (min-width: 501px) {
  body { display: grid; place-items: center; background: linear-gradient(135deg, #e7f8ff, #aedfff); }
  .app { height: min(100dvh, 920px); border-radius: 26px; }
}
@media (max-height: 720px) {
  .intro { top: 65px; }
  .intro small { margin-top: 4px; }
  .name-tag { top: 70%; }
  .question-bubble { width: 102px; min-height: 48px; }
  .question-bubble:nth-child(3) { width: 88px; }
  .question-bubble:nth-child(4) { width: 98px; }
  .answer-bubble { top: 106px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
