:root {
  color-scheme: dark;
  --bg: #070a12;
  --panel: rgba(16, 22, 38, 0.88);
  --panel-strong: #111827;
  --border: rgba(148, 163, 184, 0.18);
  --text: #e5eefc;
  --muted: #94a3b8;
  --accent: #8b5cf6;
  --accent-2: #22d3ee;
  --user: linear-gradient(135deg, #7c3aed, #2563eb);
  --assistant: rgba(30, 41, 59, 0.78);
  --danger: #fda4af;
  --shadow: 0 30px 90px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 12% 15%, rgba(124, 58, 237, 0.22), transparent 34%),
    radial-gradient(circle at 88% 8%, rgba(34, 211, 238, 0.16), transparent 30%),
    linear-gradient(145deg, #050711 0%, #0a1020 55%, #070a12 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.22;
  background-image:
    linear-gradient(rgba(255,255,255,0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.025) 1px, transparent 1px);
  background-size: 36px 36px;
  mask-image: linear-gradient(to bottom, black, transparent 85%);
}

button, textarea { font: inherit; }

.app-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px;
}

.chat-card {
  width: min(940px, 100%);
  height: min(820px, calc(100vh - 56px));
  min-height: 610px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 28px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(24px);
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.72);
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 15px;
  font-size: 22px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 10px 28px rgba(124, 58, 237, 0.3);
}

.chat-header h1 {
  margin: 0 0 4px;
  font-size: clamp(17px, 2vw, 21px);
  letter-spacing: 0.01em;
}

.chat-header p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 5px;
  border-radius: 999px;
  background: #34d399;
  box-shadow: 0 0 12px rgba(52, 211, 153, 0.8);
}

.messages {
  overflow-y: auto;
  padding: 28px 24px;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: rgba(148, 163, 184, 0.35) transparent;
}

.message {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 22px;
  animation: message-in 240ms ease-out both;
}

.user-message { justify-content: flex-end; }

.avatar {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 12px;
  color: #dbeafe;
  background: rgba(30, 41, 59, 0.95);
  font-size: 12px;
  font-weight: 800;
}

.user-message .avatar {
  background: linear-gradient(135deg, #6d28d9, #1d4ed8);
}

.bubble {
  max-width: min(720px, 78%);
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 7px 20px 20px 20px;
  background: var(--assistant);
  box-shadow: 0 12px 32px rgba(0,0,0,0.18);
}

.user-message .bubble {
  border-color: rgba(255,255,255,0.14);
  border-radius: 20px 7px 20px 20px;
  background: var(--user);
}

.bubble p {
  margin: 0;
  line-height: 1.72;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.error-message .bubble {
  border-color: rgba(251, 113, 133, 0.28);
  color: var(--danger);
}

.thinking-bubble { min-width: min(410px, 76vw); }

.thinking-title {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
}

.typing-dots {
  display: inline-flex;
  gap: 4px;
}

.typing-dots i {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--accent-2);
  animation: dot-bounce 1.05s infinite ease-in-out;
}

.typing-dots i:nth-child(2) { animation-delay: 0.14s; }
.typing-dots i:nth-child(3) { animation-delay: 0.28s; }

.thinking-track {
  height: 5px;
  margin: 14px 0 10px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.15);
}

.thinking-track span {
  display: block;
  width: 42%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, transparent, var(--accent-2), var(--accent), transparent);
  animation: track-slide 1.45s infinite ease-in-out;
}

.thinking-caption {
  color: var(--muted);
  font-size: 12px;
}

.thinking-avatar { animation: avatar-pulse 1.8s infinite ease-in-out; }

.composer {
  padding: 18px 20px 20px;
  border-top: 1px solid var(--border);
  background: rgba(8, 13, 25, 0.88);
}

textarea {
  width: 100%;
  min-height: 86px;
  max-height: 230px;
  resize: vertical;
  padding: 14px 15px;
  border: 1px solid rgba(148, 163, 184, 0.24);
  border-radius: 16px;
  outline: none;
  color: var(--text);
  background: rgba(15, 23, 42, 0.85);
  line-height: 1.6;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

textarea:focus {
  border-color: rgba(139, 92, 246, 0.78);
  box-shadow: 0 0 0 4px rgba(139, 92, 246, 0.12);
}

textarea:disabled { opacity: 0.7; cursor: wait; }

.composer-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding-top: 12px;
}

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

button {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  border: 0;
  border-radius: 12px;
  padding: 10px 16px;
  color: white;
  background: linear-gradient(135deg, var(--accent), #2563eb);
  cursor: pointer;
  font-weight: 750;
  box-shadow: 0 10px 26px rgba(79, 70, 229, 0.28);
  transition: transform 150ms ease, filter 150ms ease, opacity 150ms ease;
}

button:hover:not(:disabled) { transform: translateY(-1px); filter: brightness(1.08); }
button:active:not(:disabled) { transform: translateY(0); }
button:disabled { opacity: 0.55; cursor: wait; }

.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;
}

@keyframes message-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes dot-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.45; }
  30% { transform: translateY(-5px); opacity: 1; }
}

@keyframes track-slide {
  from { transform: translateX(-120%); }
  to { transform: translateX(340%); }
}

@keyframes avatar-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(34, 211, 238, 0); }
  50% { box-shadow: 0 0 0 7px rgba(34, 211, 238, 0.1); }
}

@media (max-width: 640px) {
  .app-shell { padding: 0; }
  .chat-card {
    min-height: 100vh;
    height: 100vh;
    border: 0;
    border-radius: 0;
  }
  .chat-header, .messages { padding-left: 16px; padding-right: 16px; }
  .composer { padding: 14px; }
  .bubble { max-width: 86%; }
  .hint { display: none; }
  .composer-footer { justify-content: flex-end; }
}

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