@font-face {
  font-family: PuHuiTi;
  src: url('./assets/puhuiti-medium.woff2') format('woff2');
  font-weight: 500;
  font-display: swap;
}

@font-face {
  font-family: PuHuiTi;
  src: url('./assets/puhuiti-regular.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: PuHuiTi;
  src: url('./assets/puhuiti-bold.woff2') format('woff2');
  font-weight: 700;
  font-display: swap;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: #e1f1fb; color: #303334; font-family: PuHuiTi, "PingFang SC", "Microsoft YaHei", sans-serif; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; padding: 0; background: none; }
button:focus-visible { outline: 2px solid #0673d3; outline-offset: 2px; }
img { display: block; max-width: 100%; }
h1, h2, p { margin: 0; }

.app {
  display: flex;
  flex-direction: column;
  width: min(100%, 500px, 64dvh);
  height: 100dvh;
  margin-inline: auto;
  overflow: hidden;
  container-type: inline-size;
  background: #c4e6fe url('./assets/background.png') center top / 100% 100% no-repeat;
}

.app > * {
  --u: calc(100cqw / 1220);
  --controls-height: calc(124 * var(--u));
  --side: calc(74 * var(--u));
  min-width: 0;
}

.fixed-top {
  flex: none;
  position: relative;
  z-index: 1;
  padding-top: max(16px, env(safe-area-inset-top));
}

.scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
  padding-bottom: calc(50 * var(--u));
}

.app[data-recording] .scroll {
  padding-bottom: calc(92 * var(--u));
  scroll-padding-bottom: calc(92 * var(--u));
}

.heading {
  margin-inline: calc(72 * var(--u));
  display: flex;
  align-items: center;
  gap: calc(22 * var(--u));
}

.heading img { width: calc(74 * var(--u)); }
.heading h1 {
  font-size: calc(71 * var(--u));
  font-weight: 500;
  line-height: calc(74 * var(--u));
  letter-spacing: calc(2 * var(--u));
  color: #0079ec;
  background: linear-gradient(100deg, #0065ff, #05bacb);
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.intro { position: relative; height: calc(500 * var(--u)); }
.avatar {
  position: absolute;
  z-index: 1;
  top: calc(44 * var(--u));
  left: calc(12 * var(--u));
  width: calc(495 * var(--u));
  aspect-ratio: 495 / 520;
  -webkit-tap-highlight-color: transparent;
}
.avatar video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.avatar:has(video:not([hidden])) img { visibility: hidden; }
.avatar[data-action="clicked"]:not(:has(video:not([hidden]))) { animation: avatar-greet .55s ease-out; }
@keyframes avatar-greet { 50% { transform: translateY(-5px); } }

.welcome {
  position: absolute;
  top: calc(139 * var(--u));
  left: calc(367 * var(--u));
  width: calc(750 * var(--u));
  height: calc(283 * var(--u));
  padding: calc(58 * var(--u)) calc(53 * var(--u)) 0 calc(57 * var(--u));
  background: url('./assets/welcome.png') center / 100% 100% no-repeat;
}
.welcome h2 {
  color: #319cf4;
  background: linear-gradient(90deg, #478eff, #12c6df);
  background-clip: text;
  -webkit-text-fill-color: transparent;
  width: max-content;
  font-weight: 700;
  font-size: calc(44 * var(--u));
  line-height: calc(57 * var(--u));
}
.welcome p { font-size: calc(35 * var(--u)); line-height: calc(54 * var(--u)); width: calc(650 * var(--u)); }

.topics {
  position: relative;
  z-index: 2;
  width: calc(1115 * var(--u));
  height: calc(627 * var(--u));
  margin-inline: auto;
  background: url('./assets/topics-panel.png') center / 100% 100% no-repeat;
  padding: calc(56 * var(--u)) calc(50 * var(--u)) 0;
}
.topic-heading { display: flex; align-items: center; gap: calc(25 * var(--u)); }
.topic-heading h2 { font-size: calc(35 * var(--u)); line-height: calc(48 * var(--u)); }
.topic-heading span {
  background: url('./assets/voice-tip.png') center / 100% 100% no-repeat;
  width: calc(384 * var(--u));
  line-height: calc(35 * var(--u));
  text-align: center;
  font-size: calc(25 * var(--u));
  color: #daf6ff;
}
.topic-list { display: grid; grid-template-columns: repeat(4, calc(226 * var(--u))); justify-content: space-between; margin-top: calc(28 * var(--u)); }
.topic-list a { border-radius: calc(8 * var(--u)); }
.topic-list a:focus-visible { outline: 2px solid #0673d3; outline-offset: 2px; }
.topic-list img { width: 100%; aspect-ratio: 226 / 129; }

.questions {
  display: grid;
  align-content: center;
  width: calc(1046 * var(--u));
  height: calc(308 * var(--u));
  margin-top: calc(16 * var(--u));
  margin-left: calc(-18 * var(--u));
  padding-inline: calc(60 * var(--u));
  background: url('./assets/questions-panel.png') center / 100% 100% no-repeat;
}
.questions button {
  text-align: start;
  font-size: calc(36 * var(--u));
  line-height: 1.3;
  min-height: calc(74 * var(--u));
}
.questions button:enabled:hover { color: #0878ce; }
.questions button:disabled { opacity: .65; cursor: default; }

.chat {
  display: flex;
  flex-direction: column;
  gap: calc(59 * var(--u));
  margin-top: calc(59 * var(--u));
}
.bubble {
  align-self: flex-end;
  background: url('./assets/question-bubble.png') center / 100% 100% no-repeat;
  margin-inline: var(--side) calc(75 * var(--u));
  padding: calc(8 * var(--u)) calc(42 * var(--u));
  font-size: calc(40 * var(--u));
  line-height: calc(62 * var(--u));
  color: white;
  overflow-wrap: anywhere;
}
.answer {
  width: calc(1115 * var(--u));
  margin-inline: auto;
  padding: calc(54 * var(--u)) calc(71 * var(--u)) calc(47 * var(--u));
  border-image: url('./assets/answer-panel.png') 42 fill / calc(42 * var(--u)) stretch;
}
.answer-text { font-size: calc(40 * var(--u)); line-height: calc(60 * var(--u)); letter-spacing: calc(0.7 * var(--u)); overflow-wrap: anywhere; }
.answer-text p + p { margin-top: calc(13 * var(--u)); }
.answer-text.streaming-text { white-space: pre-wrap; }
.speaker { display: grid; place-items: center; width: calc(50 * var(--u)); height: calc(56 * var(--u)); margin-top: calc(34 * var(--u)); }
.speaker img { width: calc(44 * var(--u)); }
.speaker[aria-pressed="true"] { opacity: .55; }
.answer.error { color: #754120; }

.app[data-recording] .current-question { display: none; }
.app[data-recording] .chat:has(> .current-question:first-child) { margin-top: calc(37 * var(--u)); }
.recording-bubble {
  background-image: url('./assets/record-bubble.png');
  min-width: calc(326 * var(--u));
  text-align: center;
}

.controls {
  flex: none;
  position: relative;
  margin-inline: calc(75 * var(--u));
  margin-bottom: max(12px, env(safe-area-inset-bottom));
}
.chat-unavailable {
  display: grid;
  place-items: center;
  min-height: max(44px, var(--controls-height));
  border-radius: 999px;
  background: #effaff;
  color: #516973;
  font-size: 14px;
}
.voice {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  height: var(--controls-height);
  color: #6a828b;
  font-size: calc(42 * var(--u));
  border-radius: 999px;
  touch-action: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
.voice::before {
  content: "";
  position: absolute;
  inset: calc(-22 * var(--u));
  background: url('./assets/voice-button.png') center / 100% 100% no-repeat;
  pointer-events: none;
}
.voice-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.app[data-recording] .voice::before { inset: 0; background-image: url('./assets/record-button.png'); border-radius: inherit; }
.app[data-recording] .voice-label { display: none; }
.waveform {
  display: flex;
  justify-content: space-between;
  position: relative;
  width: calc(582 * var(--u));
  height: calc(69 * var(--u));
  pointer-events: none;
}
.waveform span {
  width: calc(5 * var(--u));
  height: 100%;
  border-radius: 999px;
  background: white;
  transform: scaleY(.16);
}
.record-tip, .voice-status { position: absolute; bottom: calc(100% + 10 * var(--u)); width: 100%; text-align: center; }
.record-tip { bottom: calc(100% + 30 * var(--u)); font-size: calc(42 * var(--u)); color: #795340; }
.record-tip img { width: calc(386 * var(--u)); margin-inline: auto; }
.voice-status { background: #effaffed; border-radius: 12px; font-size: 13px; padding: 6px 10px; }
.voice-status:empty { display: none; }
.app[data-recording="cancel"] .voice::before { filter: grayscale(.8); }

.question-form {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: max(44px, var(--controls-height));
  padding: 3px;
  border: 1px solid #fff;
  border-radius: 999px;
  background: #effaff;
}
.question-form input {
  flex: 1;
  min-width: 0;
  min-height: 36px;
  padding: 0 12px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 16px;
}
.question-form button {
  flex-shrink: 0;
  min-width: 56px;
  min-height: 36px;
  padding-inline: 12px;
  border-radius: 999px;
  background: #0873c7;
  color: white;
  font-size: 14px;
}

@media (prefers-reduced-motion: reduce) {
  .avatar[data-action="clicked"] { animation: none !important; }
}
