:root {
  color-scheme: light;
  font-family: "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
  --bg: #f7fbff;
  --surface: #ffffff;
  --ink: #17324d;
  --muted: #6f8498;
  --line: #dbe8f2;
  --blue: #2878b9;
  --blue-dark: #155889;
  --green: #2f8b6b;
  --green-soft: #e6f5ed;
  --yellow: #f4b942;
  --danger: #c85d48;
  --shadow: 0 14px 36px rgba(42, 86, 120, 0.12);
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--ink); }

body { min-height: 100dvh; }

button, input { font: inherit; letter-spacing: 0; }

button { cursor: pointer; }

.app-shell {
  min-height: 100dvh;
  max-width: 760px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 20px calc(230px + env(safe-area-inset-bottom));
}
.greeting { display: flex; align-items: baseline; gap: 2px; margin: 18px 0 14px; color: #17253d; font-size: 30px; line-height: 1.08; font-weight: 800; }
.greeting strong { min-width: 0; max-width: 70%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 0 12px;
}
.header-actions { display: flex; align-items: center; gap: 8px; }
.icon-button { width: 38px; height: 38px; padding: 0; border: 1px solid var(--line); border-radius: 50%; background: var(--surface); color: var(--blue-dark); font-size: 18px; }

.brand-kicker, .stage-eyebrow, .dialog-kicker {
  margin: 0 0 4px;
  color: var(--blue);
  font-size: 12px;
  font-weight: 700;
}

h1, h2, p { letter-spacing: 0; }

h1 { margin: 0; font-size: 22px; line-height: 1.25; }

.service-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
}

.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--yellow); }
.status-dot.ready { background: var(--green); }
.status-dot.error { background: var(--danger); }

.buddy-stage {
  display: grid;
  grid-template-columns: minmax(132px, 42%) 1fr;
  align-items: center;
  min-height: 232px;
  margin-top: 8px;
  padding: 18px 18px 18px 4px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: linear-gradient(90deg, #eef8ff 0%, #fff9e9 100%);
}

.character-wrap { position: relative; align-self: end; min-width: 0; }
.character-image { display: block; width: 100%; max-height: 214px; object-fit: contain; object-position: bottom; }

.sound-bars {
  position: absolute;
  left: 50%;
  bottom: 4px;
  display: flex;
  align-items: center;
  gap: 4px;
  height: 28px;
  padding: 5px 8px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.9);
  opacity: 0;
  transform: translateX(-50%);
  transition: opacity 160ms ease;
}

.sound-bars.active { opacity: 1; }
.sound-bars span { display: block; width: 3px; height: 8px; border-radius: 3px; background: var(--blue); }
.sound-bars.active span { animation: speaking 700ms ease-in-out infinite alternate; }
.sound-bars span:nth-child(2), .sound-bars span:nth-child(4) { animation-delay: 140ms; }
.sound-bars span:nth-child(3) { animation-delay: 280ms; }

@keyframes speaking { from { height: 7px; } to { height: 22px; } }

.stage-copy { min-width: 0; padding-left: 12px; }
.stage-copy h2 { margin: 0 0 9px; font-size: 25px; line-height: 1.22; }
.stage-copy p:last-child { margin: 0; color: var(--muted); font-size: 15px; line-height: 1.6; }

.conversation-section { padding: 22px 0; }
.section-heading { display: flex; align-items: center; justify-content: space-between; }
.section-heading h2 { margin: 0; font-size: 17px; }
.text-button { border: 0; background: transparent; color: var(--blue); font-size: 13px; }

.messages { display: flex; flex-direction: column; gap: 12px; margin-top: 14px; }
.message { max-width: 88%; padding: 13px 15px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.message-user { align-self: flex-end; background: #2f80ed; border-color: #2f80ed; color: #ffffff; }
.message-user .message-name { color: rgba(255,255,255,0.76); }
.message-name { display: block; margin-bottom: 5px; color: var(--muted); font-size: 11px; font-weight: 700; }
.message p { margin: 0; font-size: 16px; line-height: 1.55; overflow-wrap: anywhere; }
.speak-again { margin-top: 8px; padding: 0; border: 0; background: transparent; color: var(--blue); font-size: 12px; }
.support-card { display: grid; gap: 8px; margin-top: 12px; }
.support-box { padding: 10px 11px; border: 1px solid var(--line); border-radius: 7px; }
.support-box p { margin: 4px 0 0; font-size: 14px; line-height: 1.45; }
.support-label { display: block; font-size: 11px; font-weight: 800; }
.support-box.hint { background: #eef8ff; border-color: #cae8f8; color: #1f6fbd; }
.support-box.practice { background: #ffffff; border-color: #bddded; color: var(--ink); }
.support-box.correction { background: #f0fbef; border-color: #cbeecf; color: #247a39; }
.support-box.achievement { background: #fff7dc; border-color: #f5dfa3; color: #805a10; }
.support-actions { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 9px; }
.support-actions button { min-height: 30px; padding: 0 10px; border: 1px solid #bddded; border-radius: 15px; background: #ffffff; color: #1f6fbd; font-size: 11px; font-weight: 700; }
.support-actions button:disabled { opacity: 0.55; }

.composer {
  position: fixed;
  z-index: 10;
  left: 50%;
  bottom: 0;
  width: min(760px, 100%);
  padding: 10px 20px calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(247, 251, 255, 0.96);
  backdrop-filter: blur(16px);
  transform: translateX(-50%);
}

.mode-switch { display: grid; grid-template-columns: 1fr 1fr; width: 164px; margin: 0 auto 10px; padding: 3px; border: 1px solid var(--line); border-radius: 6px; background: #edf4f9; }
.mode-switch.three-modes { grid-template-columns: repeat(3, 1fr); width: min(300px, 100%); }
.mode-button { height: 31px; border: 0; border-radius: 4px; background: transparent; color: var(--muted); font-size: 13px; }
.mode-button.active { background: var(--surface); color: var(--ink); font-weight: 700; box-shadow: 0 2px 8px rgba(42, 86, 120, 0.1); }

.voice-panel { display: flex; justify-content: center; }
.talk-button { width: 100%; min-height: 70px; border: 0; border-radius: 8px; background: var(--blue-dark); color: white; box-shadow: var(--shadow); touch-action: none; user-select: none; }
.talk-button.recording { background: var(--danger); transform: scale(0.985); }
.talk-button.in-call { background: var(--danger); }
.ptt-button { background: var(--green); }
.talk-button:disabled { opacity: 0.5; cursor: not-allowed; }
.talk-button-main, .talk-button-sub { display: block; }
.talk-button-main { font-size: 18px; font-weight: 700; }
.talk-button-sub { margin-top: 4px; font-size: 12px; opacity: 0.76; }

.text-panel { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.text-panel input { min-width: 0; height: 52px; padding: 0 15px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); }
.text-panel button { min-width: 74px; border: 0; border-radius: 8px; background: var(--blue); color: white; font-weight: 700; }

.diagnostics { margin-top: 8px; color: var(--muted); font-size: 11px; }
.diagnostics summary { text-align: center; cursor: pointer; }
.diagnostics dl { display: grid; grid-template-columns: repeat(5, 1fr); gap: 5px; margin: 8px 0 0; }
.diagnostics dl div { min-width: 0; padding: 6px; border-radius: 4px; background: #edf4f9; text-align: center; }
.diagnostics dt { margin-bottom: 3px; }
.diagnostics dd { margin: 0; color: var(--ink); overflow-wrap: anywhere; }

.consent-dialog { width: min(420px, calc(100% - 36px)); padding: 0; border: 0; border-radius: 8px; box-shadow: 0 28px 80px rgba(23, 50, 77, 0.28); }
.consent-dialog::backdrop { background: rgba(12, 35, 57, 0.58); }
.consent-dialog form { padding: 24px; }
.consent-dialog h2 { margin: 0 0 12px; font-size: 23px; }
.consent-dialog p { color: var(--muted); font-size: 14px; line-height: 1.65; }
.consent-check { display: flex; align-items: flex-start; gap: 10px; margin: 18px 0; color: var(--ink); font-size: 14px; line-height: 1.5; }
.consent-check input { width: 18px; height: 18px; margin-top: 2px; }
.primary-button { width: 100%; min-height: 50px; border: 0; border-radius: 8px; background: var(--blue); color: white; font-weight: 700; }
.primary-button:disabled { opacity: 0.4; }
.field-label { display: grid; gap: 7px; margin: 14px 0; color: var(--ink); font-size: 13px; font-weight: 700; }
.profile-summary { margin: 14px 0 18px; padding: 11px 12px; border: 1px solid #cae8f8; border-radius: 7px; background: #eef8ff; color: #52647d; font-size: 12px; line-height: 1.55; }
.field-label input, .field-label select { width: 100%; min-height: 44px; padding: 0 12px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--ink); font: inherit; font-weight: 400; }
.dialog-actions { display: grid; grid-template-columns: 1fr 1.5fr; gap: 10px; margin-top: 20px; }
.dialog-actions .primary-button { min-height: 46px; }
.secondary-button { min-height: 46px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--muted); }

.toast { position: fixed; z-index: 30; left: 50%; top: calc(18px + env(safe-area-inset-top)); max-width: calc(100% - 40px); padding: 10px 14px; border-radius: 6px; background: var(--ink); color: white; font-size: 13px; opacity: 0; pointer-events: none; transform: translate(-50%, -10px); transition: 180ms ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.hidden { display: none !important; }
.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; }

@media (max-width: 460px) {
  .app-shell { padding-left: 14px; padding-right: 14px; }
  .topbar { align-items: flex-start; }
  .service-pill { max-width: 118px; }
  .greeting { margin-top: 14px; font-size: 28px; }
  .buddy-stage { grid-template-columns: 44% 1fr; min-height: 210px; padding-right: 12px; }
  .character-image { max-height: 198px; }
  .stage-copy h2 { font-size: 21px; }
  .diagnostics dl { grid-template-columns: repeat(3, 1fr); }
  .composer { padding-left: 14px; padding-right: 14px; }
}

@media (min-width: 900px) {
  body { background: #eaf3f8; }
  .app-shell { background: var(--bg); box-shadow: 0 0 50px rgba(23, 50, 77, 0.08); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
