:root {
  --bg-start: #0f172a;
  --bg-end: #1d4ed8;
  --panel: rgba(15, 23, 42, 0.72);
  --panel-border: rgba(255, 255, 255, 0.12);
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #60a5fa;
  --accent-strong: #38bdf8;
  --success: #22c55e;
  --shadow: 0 20px 60px rgba(2, 6, 23, 0.35);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top, rgba(96, 165, 250, 0.25), transparent 35%),
    linear-gradient(135deg, var(--bg-start), var(--bg-end));
}

button,
textarea {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(320px, 460px) 1fr;
  gap: 24px;
  padding: 24px;
  transition: background 280ms ease;
}

.hero-panel,
.chat-panel {
  border: 1px solid var(--panel-border);
  background: var(--panel);
  backdrop-filter: blur(18px);
  border-radius: 28px;
  box-shadow: var(--shadow);
}

.hero-panel {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.status-bar,
.mood-grid,
.quick-actions,
.composer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.status-pill,
.mood-card,
.quick-chip,
.toggle-voice,
#sendButton,
.upload-button,
.secondary-button {
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border-radius: 999px;
  padding: 10px 14px;
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease;
}

button:disabled {
  opacity: 0.56;
  cursor: not-allowed;
  transform: none !important;
}

.status-pill.online {
  border-color: rgba(34, 197, 94, 0.4);
  color: #bbf7d0;
}

.status-pill.offline {
  border-color: rgba(248, 113, 113, 0.35);
  color: #fecaca;
}

.status-pill.listening {
  border-color: rgba(96, 165, 250, 0.55);
  color: #bfdbfe;
}

.mood-card:hover,
.quick-chip:hover,
.toggle-voice:hover,
#sendButton:hover,
.upload-button:hover,
.secondary-button:hover {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.14);
}

.mood-card.active {
  background: rgba(96, 165, 250, 0.28);
  border-color: rgba(96, 165, 250, 0.56);
}

.hidden {
  display: none !important;
}

.upload-panel {
  padding: 16px 18px;
  border-radius: 22px;
  background: rgba(15, 23, 42, 0.42);
  border: 1px solid rgba(255, 255, 255, 0.08);
  display: grid;
  gap: 12px;
}

.upload-title {
  margin: 0 0 6px;
  font-weight: 700;
}

.upload-tip {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.upload-actions,
.image-link-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.tuning-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.tuning-item {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
}

.tuning-item span {
  color: var(--text);
}

.tuning-item input[type="range"] {
  width: 100%;
  accent-color: #60a5fa;
}

.upload-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.image-link-row input {
  flex: 1;
  min-width: 220px;
  padding: 12px 14px;
  color: var(--text);
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(15, 23, 42, 0.66);
  outline: none;
}

.image-link-row input:focus {
  border-color: rgba(96, 165, 250, 0.55);
  box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.15);
}

.avatar-stage {
  position: relative;
  min-height: 420px;
  border-radius: 24px;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: linear-gradient(180deg, rgba(148, 163, 184, 0.08), rgba(15, 23, 42, 0.28));
}

.halo {
  position: absolute;
  width: 280px;
  height: 280px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(96, 165, 250, 0.35), transparent 65%);
  filter: blur(12px);
  animation: pulse 4s ease-in-out infinite;
}

.avatar {
  position: relative;
  width: 240px;
  height: 360px;
  display: flex;
  flex-direction: column;
  align-items: center;
  transform-origin: center bottom;
  animation: float 4.5s ease-in-out infinite;
}

.portrait-avatar {
  position: relative;
  width: 250px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  z-index: 1;
  animation: float 4.5s ease-in-out infinite;
}

.portrait-frame {
  --rig-top: 34%;
  width: 250px;
  height: 330px;
  padding: 8px;
  border-radius: 34px;
  position: relative;
  background: linear-gradient(180deg, rgba(96, 165, 250, 0.55), rgba(15, 23, 42, 0.72));
  box-shadow: 0 18px 38px rgba(2, 6, 23, 0.35);
}

.portrait-frame img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  border-radius: 28px;
  transition: transform 220ms ease, filter 220ms ease, box-shadow 220ms ease;
}

.portrait-rig-wrap {
  position: absolute;
  left: 50%;
  top: var(--rig-top);
  width: 48%;
  height: 34%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  filter: drop-shadow(0 2px 4px rgba(15, 23, 42, 0.28));
}

.portrait-rig {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.rig-brow,
.rig-mouth {
  fill: none;
  stroke: rgba(52, 35, 32, 0.95);
  stroke-width: 3.2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: d 200ms ease, opacity 200ms ease;
}

.rig-eye {
  fill: rgba(255, 255, 255, 0.94);
  transition: all 200ms ease;
}

.rig-pupil {
  fill: #1e293b;
  transition: all 200ms ease;
}

.rig-blush {
  fill: rgba(248, 113, 113, 0.24);
  opacity: 0.18;
  transition: opacity 200ms ease, transform 200ms ease;
}

.rig-tear {
  fill: rgba(125, 211, 252, 0.85);
  opacity: 0;
  transition: opacity 200ms ease;
}

.portrait-icons {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.portrait-icon {
  position: absolute;
  font-weight: 700;
  font-size: 28px;
  opacity: 0;
  transform: scale(0.8);
  transition: opacity 200ms ease, transform 200ms ease;
  text-shadow: 0 4px 14px rgba(15, 23, 42, 0.35);
}

.portrait-icon.sparkle-left {
  top: 18px;
  left: 16px;
  color: #fde68a;
}

.portrait-icon.sparkle-right {
  top: 42px;
  right: 18px;
  color: #fef08a;
}

.portrait-icon.question {
  top: 22px;
  right: 16px;
  color: #a5f3fc;
}

.portrait-icon.exclaim {
  top: 16px;
  right: 18px;
  color: #fef3c7;
}

.portrait-icon.anger {
  top: 12px;
  left: 18px;
  color: #fda4af;
}

.portrait-badge {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 16px;
  border-radius: 18px;
  background: rgba(15, 23, 42, 0.58);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.portrait-badge span {
  font-size: 13px;
  color: var(--muted);
}

.hair {
  position: absolute;
  top: 22px;
  width: 170px;
  height: 140px;
  background: linear-gradient(180deg, #1e293b, #0f172a);
  border-radius: 45% 45% 42% 42%;
}

.face {
  position: relative;
  margin-top: 52px;
  width: 160px;
  height: 190px;
  background: linear-gradient(180deg, #fde7d8, #f6cfb8);
  border-radius: 42% 42% 46% 46%;
  box-shadow: inset 0 -10px 20px rgba(215, 152, 120, 0.18);
}

.brow,
.eye,
.mouth,
.blush {
  position: absolute;
}

.brow {
  top: 60px;
  width: 34px;
  height: 8px;
  border-radius: 10px;
  background: #5b4437;
  transition: transform 220ms ease;
}

.brow-left { left: 34px; }
.brow-right { right: 34px; }

.eye {
  top: 82px;
  width: 28px;
  height: 18px;
  background: white;
  border-radius: 50px;
  overflow: hidden;
  animation: blink 5.8s infinite;
}

.eye-left { left: 38px; }
.eye-right { right: 38px; }

.pupil {
  position: absolute;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #1e293b;
  top: 3px;
  left: 8px;
}

.blush {
  top: 120px;
  width: 24px;
  height: 12px;
  border-radius: 50%;
  background: rgba(248, 113, 113, 0.18);
}

.blush-left { left: 18px; }
.blush-right { right: 18px; }

.mouth {
  left: 50%;
  bottom: 42px;
  width: 44px;
  height: 16px;
  transform: translateX(-50%);
  border-bottom: 5px solid #9f4d5d;
  border-radius: 0 0 40px 40px;
  transition: all 180ms ease;
}

.body {
  position: relative;
  margin-top: -10px;
  width: 200px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.neck {
  width: 26px;
  height: 24px;
  background: #f4ceb6;
  border-radius: 10px;
}

.torso {
  width: 180px;
  height: 130px;
  background: linear-gradient(180deg, #2563eb, #1e40af);
  border-radius: 28px 28px 18px 18px;
  box-shadow: inset 0 8px 16px rgba(255, 255, 255, 0.12);
}

.insight-panel {
  padding: 18px;
  border-radius: 22px;
  background: rgba(15, 23, 42, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.session-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.llm-panel {
  padding: 18px;
  border-radius: 22px;
  background: rgba(15, 23, 42, 0.42);
  border: 1px solid rgba(255, 255, 255, 0.08);
  display: grid;
  gap: 14px;
}

.llm-panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.llm-panel-header h3 {
  margin: 6px 0 0;
}

.llm-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.llm-field {
  display: grid;
  gap: 8px;
}

.llm-span-2 {
  grid-column: span 2;
}

.llm-field span,
.llm-tip {
  color: var(--muted);
}

.llm-field input {
  width: 100%;
  padding: 12px 14px;
  color: var(--text);
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(15, 23, 42, 0.66);
  outline: none;
}

.llm-field input:focus {
  border-color: rgba(96, 165, 250, 0.55);
  box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.15);
}

.llm-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.llm-tip {
  margin: 0;
  font-size: 13px;
  line-height: 1.6;
}

.insight-panel h3,
.panel-header h1 {
  margin: 0 0 10px;
}

.insight-panel ul {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  display: grid;
  gap: 8px;
}

.chat-panel {
  padding: 28px;
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 48px);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: flex-start;
}

.eyebrow {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 12px;
  color: var(--accent-strong);
}

.subtext,
.hint {
  color: var(--muted);
}

.chat-log {
  flex: 1;
  margin: 22px 0;
  padding: 8px 4px 8px 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.message {
  max-width: 76%;
  padding: 14px 16px;
  border-radius: 18px;
  line-height: 1.65;
  animation: slideIn 220ms ease;
}

.message.user {
  align-self: flex-end;
  background: linear-gradient(135deg, rgba(96, 165, 250, 0.3), rgba(14, 165, 233, 0.18));
}

.message.bot {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.08);
}

.meta {
  margin-top: 8px;
  display: block;
  font-size: 12px;
  color: var(--muted);
}

.composer {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px;
  border-radius: 22px;
  background: rgba(15, 23, 42, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.composer textarea {
  width: 100%;
  resize: none;
  padding: 16px;
  color: var(--text);
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(15, 23, 42, 0.66);
  outline: none;
}

.composer textarea:focus {
  border-color: rgba(96, 165, 250, 0.55);
  box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.15);
}

#sendButton {
  padding-inline: 20px;
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.5), rgba(14, 165, 233, 0.3));
}

.app-shell[data-emotion="happy"] {
  --bg-start: #172554;
  --bg-end: #f59e0b;
}

.app-shell[data-emotion="sad"] {
  --bg-start: #0f172a;
  --bg-end: #334155;
}

.app-shell[data-emotion="angry"] {
  --bg-start: #3f0d12;
  --bg-end: #7f1d1d;
}

.app-shell[data-emotion="surprised"] {
  --bg-start: #1e1b4b;
  --bg-end: #7c3aed;
}

.app-shell[data-emotion="confused"] {
  --bg-start: #1f2937;
  --bg-end: #0f766e;
}

.avatar[data-emotion="happy"] .mouth {
  height: 20px;
  border-bottom-width: 6px;
  border-radius: 0 0 50px 50px;
}

.avatar[data-emotion="happy"] .brow-left,
.avatar[data-emotion="happy"] .brow-right {
  transform: translateY(3px) rotate(8deg);
}

.avatar[data-emotion="sad"] .mouth {
  bottom: 36px;
  border-bottom: none;
  border-top: 5px solid #9f4d5d;
  border-radius: 30px 30px 0 0;
}

.avatar[data-emotion="sad"] .brow-left { transform: rotate(-12deg); }
.avatar[data-emotion="sad"] .brow-right { transform: rotate(12deg); }

.avatar[data-emotion="angry"] .brow-left { transform: rotate(18deg) translateY(2px); }
.avatar[data-emotion="angry"] .brow-right { transform: rotate(-18deg) translateY(2px); }

.avatar[data-emotion="angry"] .mouth {
  width: 38px;
  border-bottom-width: 7px;
}

.avatar[data-emotion="surprised"] .mouth {
  width: 24px;
  height: 28px;
  border: 4px solid #9f4d5d;
  border-radius: 50%;
  background: rgba(159, 77, 93, 0.08);
}

.avatar[data-emotion="surprised"] .eye {
  height: 24px;
}

.avatar[data-emotion="confused"] .brow-left { transform: rotate(14deg); }
.avatar[data-emotion="confused"] .brow-right { transform: rotate(-6deg) translateY(-3px); }

.avatar[data-speaking="true"] .mouth {
  animation: speaking 240ms ease-in-out infinite alternate;
}

.portrait-avatar[data-speaking="true"] .portrait-frame img {
  animation: portraitSpeaking 240ms ease-in-out infinite alternate;
}

.portrait-avatar[data-speaking="true"] .rig-mouth {
  animation: rigMouthTalk 240ms ease-in-out infinite alternate;
  transform-box: fill-box;
  transform-origin: center;
}

.portrait-avatar[data-emotion="happy"] .portrait-frame img {
  filter: saturate(1.16) brightness(1.04);
}

.portrait-avatar[data-emotion="sad"] .portrait-frame img {
  filter: saturate(0.82) brightness(0.92);
}

.portrait-avatar[data-emotion="angry"] .portrait-frame img {
  filter: saturate(1.08) contrast(1.08);
}

.portrait-avatar[data-emotion="surprised"] .portrait-frame img {
  filter: brightness(1.08) contrast(1.05);
}

.portrait-avatar[data-emotion="confused"] .portrait-frame img {
  filter: saturate(0.9) hue-rotate(-10deg);
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

@keyframes pulse {
  0%, 100% { transform: scale(0.96); opacity: 0.7; }
  50% { transform: scale(1.06); opacity: 1; }
}

@keyframes blink {
  0%, 45%, 48%, 100% { transform: scaleY(1); }
  46%, 47% { transform: scaleY(0.1); }
}

@keyframes speaking {
  from { transform: translateX(-50%) scaleY(0.85); }
  to { transform: translateX(-50%) scaleY(1.25); }
}

@keyframes portraitSpeaking {
  from { transform: scale(0.995); }
  to { transform: scale(1.02); }
}

@keyframes rigMouthTalk {
  from { transform: scaleY(0.9); }
  to { transform: scaleY(1.18); }
}

@keyframes slideIn {
  from { transform: translateY(8px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .chat-panel {
    min-height: auto;
  }
}

@media (max-width: 640px) {
  .app-shell {
    padding: 14px;
    gap: 14px;
  }

  .hero-panel,
  .chat-panel {
    border-radius: 22px;
  }

  .panel-header {
    flex-direction: column;
  }

  .session-actions {
    flex-direction: column;
  }

  .llm-panel-header {
    flex-direction: column;
  }

  .message {
    max-width: 92%;
  }

  .image-link-row input {
    min-width: 100%;
  }

  .tuning-grid {
    grid-template-columns: 1fr;
  }

  .llm-grid {
    grid-template-columns: 1fr;
  }

  .llm-span-2 {
    grid-column: auto;
  }
}