:root {
  color-scheme: light;
  --color-primary: #9a4c32;
  --color-primary-strong: #7b3826;
  --color-secondary: #486b58;
  --color-accent: #b8753f;
  --color-background: #f6efe4;
  --color-surface: rgba(255, 253, 248, 0.96);
  --color-surface-raised: #fffaf2;
  --color-foreground: #2f2621;
  --color-muted: #75675f;
  --color-border: rgba(94, 73, 60, 0.16);
  --color-danger: #a33a3a;
  --color-success: #49735c;
  --shadow-card: 0 24px 70px rgba(89, 62, 43, 0.14);
  font-family: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  min-height: 100%;
  background: var(--color-background);
}

body {
  min-height: 100dvh;
  margin: 0;
  color: var(--color-foreground);
  background:
    radial-gradient(circle at 50% 4%, rgba(214, 174, 135, 0.3), transparent 30rem),
    linear-gradient(160deg, #fbf6ed, var(--color-background));
}

button,
input {
  font: inherit;
}

button {
  touch-action: manipulation;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid var(--color-secondary);
  outline-offset: 3px;
}

.page-shell {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
}

.call-card {
  width: min(100%, 480px);
  min-height: calc(100dvh - 32px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--color-border);
  border-radius: 28px;
  background: var(--color-surface);
  box-shadow: var(--shadow-card);
}

.topbar {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  font-weight: 600;
}

.brand-mark {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(154, 76, 50, 0.4);
  border-radius: 10px;
  color: #fffaf2;
  background: var(--color-primary);
  font-family: "STKaiti", "KaiTi", serif;
}

.status-badge {
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  color: var(--color-muted);
  background: rgba(117, 103, 95, 0.06);
  font-size: 12px;
  font-weight: 600;
}

.status-badge[data-state="listening"] {
  border-color: rgba(73, 115, 92, 0.34);
  color: #315a45;
  background: rgba(73, 115, 92, 0.09);
}

.status-badge[data-state="thinking"],
.status-badge[data-state="speaking"] {
  border-color: rgba(154, 76, 50, 0.32);
  color: var(--color-primary-strong);
  background: rgba(154, 76, 50, 0.08);
}

.teacher-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 24px 20px;
  text-align: center;
}

.avatar-wrap {
  position: relative;
  width: 136px;
  height: 136px;
  margin: 4px 0 20px;
}

.avatar-halo {
  position: absolute;
  inset: -12px;
  border: 1px solid rgba(184, 117, 63, 0.28);
  border-radius: 46px;
  background: radial-gradient(circle, rgba(214, 174, 135, 0.26), transparent 68%);
  opacity: 0.7;
}

.teacher-avatar {
  position: relative;
  width: 136px;
  height: 136px;
  display: block;
  border-radius: 40px;
  box-shadow: 0 14px 38px rgba(122, 79, 48, 0.18);
}

.teacher-stage h1 {
  margin: 0;
  font-family: "STKaiti", "KaiTi", serif;
  font-size: clamp(30px, 8vw, 38px);
  font-weight: 600;
  letter-spacing: 0.02em;
}

.status-text {
  min-height: 24px;
  margin: 8px 0 6px;
  color: var(--color-muted);
  font-size: 15px;
  line-height: 1.6;
}

.call-timer {
  color: #67574e;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.12em;
}

.voice-wave {
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  margin-top: 8px;
}

.voice-wave span {
  width: 4px;
  height: 7px;
  border-radius: 999px;
  background: linear-gradient(180deg, var(--color-accent), var(--color-primary));
  opacity: 0.35;
  transform-origin: center;
}

.voice-wave[data-active="true"] span {
  opacity: 1;
  animation: voice-pulse 0.9s ease-in-out infinite;
}

.voice-wave[data-active="true"] span:nth-child(2),
.voice-wave[data-active="true"] span:nth-child(4) {
  animation-delay: 0.14s;
}

.voice-wave[data-active="true"] span:nth-child(3) {
  animation-delay: 0.28s;
}

@keyframes voice-pulse {
  0%, 100% { transform: scaleY(1); }
  50% { transform: scaleY(3.4); }
}

.auto-service-note {
  margin: 0 28px 14px;
  color: var(--color-muted);
  font-size: 13px;
  line-height: 1.6;
  text-align: center;
}

.live-panel {
  min-height: 196px;
  flex: 1;
  margin: 0 16px;
  padding: 18px;
  overflow: hidden;
  border: 1px solid var(--color-border);
  border-radius: 20px;
  background: var(--color-surface-raised);
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-heading h2 {
  margin: 0;
  font-size: 15px;
}

.panel-heading span {
  color: var(--color-muted);
  font-size: 12px;
}

.live-text {
  min-height: 48px;
  margin: 14px 0 0;
  color: var(--color-foreground);
  font-size: 17px;
  line-height: 1.65;
}

.emotion-hint {
  width: fit-content;
  margin: 8px 0 0;
  padding: 5px 10px;
  border: 1px solid rgba(72, 107, 88, 0.2);
  border-radius: 999px;
  color: #3d604d;
  background: rgba(72, 107, 88, 0.07);
  font-size: 12px;
  line-height: 1.4;
}

.messages {
  max-height: 220px;
  margin-top: 14px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.message {
  display: grid;
  gap: 4px;
  margin-top: 10px;
  padding: 12px 14px;
  border: 1px solid var(--color-border);
  border-radius: 16px;
  background: #fffdf9;
}

.message.user {
  margin-left: 28px;
  background: #f2e4d7;
}

.message.assistant {
  margin-right: 18px;
}

.message-role {
  color: var(--color-muted);
  font-size: 12px;
  font-weight: 600;
}

.message-content {
  margin: 0;
  color: var(--color-foreground);
  font-size: 15px;
  line-height: 1.65;
}

.message.user .message-role {
  color: #6c5141;
}

.message.assistant .message-role {
  color: var(--color-primary);
}

.text-form {
  min-height: 52px;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 14px 16px 0;
  padding: 4px 5px 4px 16px;
  border: 1px solid var(--color-border);
  border-radius: 18px;
  background: #fffdf9;
}

.text-form:focus-within {
  border-color: rgba(72, 107, 88, 0.62);
}

.text-form input {
  min-width: 0;
  flex: 1;
  border: 0;
  outline: 0;
  color: var(--color-foreground);
  background: transparent;
  font-size: 16px;
}

.text-form input::placeholder {
  color: #94857c;
}

.icon-button {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border: 0;
  border-radius: 14px;
  cursor: pointer;
}

.icon-button svg,
.control-button svg,
.start-button svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

.send-button {
  color: #fff;
  background: var(--color-primary);
  transition: background 180ms ease, opacity 180ms ease;
}

.send-button:hover {
  background: var(--color-primary-strong);
}

.send-button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.controls {
  min-height: 92px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 14px 16px;
}

.start-button {
  min-width: 190px;
  min-height: 54px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 0;
  border-radius: 18px;
  color: #fff;
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-strong));
  box-shadow: 0 14px 30px rgba(123, 56, 38, 0.2);
  cursor: pointer;
  font-size: 16px;
  font-weight: 700;
  transition: transform 180ms ease, box-shadow 180ms ease;
}

.start-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 18px 38px rgba(123, 56, 38, 0.28);
}

.start-button:active,
.control-button:active,
.icon-button:active {
  transform: scale(0.97);
}

.control-button {
  min-width: 96px;
  min-height: 54px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--color-border);
  border-radius: 18px;
  color: var(--color-foreground);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: background 180ms ease, transform 180ms ease;
}

.control-button.secondary {
  background: #fffaf2;
}

.control-button.danger {
  border-color: rgba(163, 58, 58, 0.32);
  background: rgba(163, 58, 58, 0.08);
}

.support-note {
  margin: 0;
  padding: 0 22px 20px;
  color: #8d7f76;
  font-size: 12px;
  line-height: 1.6;
  text-align: center;
}

.error-notice {
  margin: 0 16px 18px;
  padding: 12px 14px;
  border: 1px solid rgba(163, 58, 58, 0.32);
  border-radius: 14px;
  color: #7b2929;
  background: rgba(163, 58, 58, 0.08);
  font-size: 14px;
  line-height: 1.5;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

[hidden] {
  display: none !important;
}

@media (min-width: 640px) {
  .call-card {
    min-height: min(820px, calc(100dvh - 48px));
  }
}

@media (max-height: 760px) {
  .avatar-wrap,
  .teacher-avatar {
    width: 104px;
    height: 104px;
  }

  .avatar-halo {
    border-radius: 38px;
  }

  .teacher-stage {
    padding-top: 0;
    padding-bottom: 10px;
  }

  .live-panel {
    min-height: 164px;
  }
}

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