:root {
  color-scheme: light;
  --bg: #edf6fb;
  --panel: rgba(255, 255, 255, 0.92);
  --ink: #172638;
  --muted: #63798c;
  --line: #d8e7f1;
  --accent: #3d8fce;
  --accent-strong: #1f6fa8;
  --shadow: 0 16px 40px rgba(42, 78, 110, 0.16);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background:
    radial-gradient(circle at 50% 0%, rgba(214, 238, 255, 0.9), transparent 34%),
    linear-gradient(180deg, #f8fcff 0%, var(--bg) 56%, #f6f8fa 100%);
  color: var(--ink);
  overflow-x: hidden;
}

button,
input {
  font: inherit;
}

.app-shell {
  width: 100%;
  max-width: 430px;
  min-height: 100vh;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 12px max(14px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-rows: minmax(330px, 48vh) auto auto auto;
  gap: 10px;
}

.stage {
  position: relative;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 0 0 22px 22px;
  background:
    radial-gradient(circle at 28% 20%, rgba(255, 255, 255, 0.78), transparent 30%),
    radial-gradient(circle at 80% 18%, rgba(80, 150, 205, 0.18), transparent 34%),
    linear-gradient(180deg, #dcecf8 0%, #eef8ff 54%, #f3dfc2 100%);
  box-shadow: var(--shadow);
}

.stage::before,
.stage::after {
  content: "";
  position: absolute;
  pointer-events: none;
}

.stage::before {
  left: 24px;
  top: 28px;
  width: 124px;
  height: 124px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 247, 218, 0.86), transparent 68%);
  filter: blur(2px);
}

.stage::after {
  left: 24px;
  right: 24px;
  bottom: 20px;
  height: 74px;
  border-radius: 18px;
  background: rgba(126, 82, 46, 0.18);
}

.status-pill {
  position: absolute;
  z-index: 3;
  top: 10px;
  left: 10px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.86);
  color: #215a82;
  font-size: 13px;
  font-weight: 800;
  box-shadow: 0 8px 22px rgba(29, 60, 87, 0.12);
}

.enroll-link {
  position: absolute;
  z-index: 3;
  top: 10px;
  right: 10px;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.86);
  color: #215a82;
  font-size: 13px;
  font-weight: 850;
  text-decoration: none;
  box-shadow: 0 8px 22px rgba(29, 60, 87, 0.12);
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #2aa66a;
  box-shadow: 0 0 0 4px rgba(42, 166, 106, 0.16);
}

.cat-avatar {
  position: relative;
  z-index: 2;
  width: min(88vw, 360px);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  filter: drop-shadow(0 22px 24px rgba(24, 52, 78, 0.24));
  animation: idleBreath 4.8s ease-in-out infinite;
}

#characterCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

.cat-avatar.state-speaking {
  animation: speakingBob 0.38s ease-in-out infinite;
}

.cat-avatar.state-thinking {
  animation: thinkingSway 1.6s ease-in-out infinite;
}

.cat-avatar.state-happy {
  animation: happyHop 0.52s ease-out 2;
}

.chat-form button,
.voice-button {
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.answer-card {
  min-height: 118px;
  padding: 14px 16px 16px;
  border: 1px solid rgba(41, 78, 112, 0.12);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.identity-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 10px;
  border: 1px solid rgba(41, 78, 112, 0.12);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.identity-main {
  display: grid;
  gap: 2px;
}

.identity-main span,
.identity-hint {
  color: var(--muted);
  font-size: 12px;
}

.identity-main strong {
  color: var(--accent-strong);
  font-size: 16px;
}

#cameraButton {
  min-height: 42px;
  padding: 0 14px;
  border: 0;
  border-radius: 8px;
  color: #fff;
  background: var(--accent);
  font-weight: 850;
}

#identityVideo {
  width: 1px;
  height: 1px;
  opacity: 0;
  position: absolute;
  pointer-events: none;
}

.identity-hint,
.manual-identity {
  grid-column: 1 / -1;
}

.manual-identity {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.manual-identity[hidden] {
  display: none;
}

.manual-identity button {
  min-height: 38px;
  border: 0;
  border-radius: 8px;
  color: #215a82;
  background: #e8f4ff;
  border: 1px solid rgba(64, 132, 188, 0.16);
  font-weight: 800;
}

.answer-title {
  margin-bottom: 8px;
  color: var(--accent-strong);
  font-size: 14px;
  font-weight: 850;
}

#answerText {
  margin: 0;
  font-size: 16px;
  line-height: 1.58;
  white-space: pre-line;
}

.chat-form {
  display: grid;
  grid-template-columns: 1fr 72px;
  gap: 8px;
  align-items: center;
  height: 50px;
}

.chat-form input {
  min-width: 0;
  height: 50px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

.chat-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(61, 143, 206, 0.16);
}

.chat-form button,
.voice-button {
  color: #fff;
  background: var(--accent);
  font-weight: 850;
}

.chat-form button {
  width: 72px;
  height: 50px;
  display: grid;
  place-items: center;
}

.voice-button {
  width: 100%;
  min-height: 58px;
  background: #3c7fae;
  box-shadow: 0 12px 22px rgba(44, 95, 132, 0.2);
}

.voice-button.is-recording {
  background: #d9534f;
}

@keyframes idleBreath {
  0%,
  100% {
    transform: translateY(0) scale(1);
  }
  50% {
    transform: translateY(-4px) scale(1.01);
  }
}

@keyframes speakingBob {
  0%,
  100% {
    transform: translateY(0) scale(1.006);
  }
  50% {
    transform: translateY(-3px) scale(1.018);
  }
}

@keyframes thinkingSway {
  0%,
  100% {
    transform: rotate(-1deg) translateY(-2px);
  }
  50% {
    transform: rotate(1.4deg) translateY(-5px);
  }
}

@keyframes happyHop {
  0% {
    transform: translateY(0) scale(1);
  }
  45% {
    transform: translateY(-18px) scale(1.03);
  }
  100% {
    transform: translateY(0) scale(1);
  }
}

@media (max-height: 700px) {
  .app-shell {
    grid-template-rows: minmax(280px, 42vh) auto auto auto;
  }

  .cat-avatar {
    width: min(78vw, 312px);
  }

  .answer-card {
    min-height: 96px;
  }
}
