:root {
  --bg: #0a0e1a;
  --bg-2: #131a2e;
  --card: #1a2238;
  --border: #2a3354;
  --text: #e8ecf5;
  --muted: #8b94b0;
  --accent: #7dd3fc;
  --accent-2: #f0a8ff;
  --user: #4f46e5;
  --ai: #1f2942;
  --danger: #ff6b6b;
  --ok: #4ade80;
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif; }
body { min-height: 100vh; }

.app {
  max-width: 900px;
  margin: 0 auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
}
.topbar h1 {
  margin: 0;
  font-size: 18px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.topbar a {
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  padding: 6px 10px;
  border-radius: 8px;
}
.topbar a:hover { background: var(--bg-2); color: var(--text); }
.topbar .spacer { flex: 1; }

.hub-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin-top: 12px;
}
.hub-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-decoration: none;
  color: var(--text);
  transition: transform 0.15s, border-color 0.15s;
  display: block;
}
.hub-card:hover { transform: translateY(-2px); border-color: var(--accent); }
.hub-card .ico { font-size: 32px; margin-bottom: 10px; }
.hub-card h3 { margin: 0 0 6px; font-size: 16px; }
.hub-card p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.5; }

.chat-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.chat-toolbar {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
  align-items: center;
  flex-wrap: wrap;
}
.chat-toolbar select, .chat-toolbar button {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
  cursor: pointer;
}
.chat-toolbar .label { color: var(--muted); font-size: 12px; }
.chat-toolbar .auto { margin-left: auto; display: flex; align-items: center; gap: 6px; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 300px;
  max-height: calc(100vh - 280px);
}
.msg { max-width: 85%; padding: 10px 14px; border-radius: 14px; line-height: 1.5; font-size: 14px; white-space: pre-wrap; word-wrap: break-word; }
.msg.user { background: var(--user); color: white; align-self: flex-end; border-bottom-right-radius: 4px; }
.msg.ai { background: var(--ai); align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.system { background: transparent; color: var(--muted); font-size: 12px; align-self: center; text-align: center; }
.msg img { max-width: 100%; border-radius: 8px; margin-top: 8px; display: block; }
.msg video { max-width: 100%; border-radius: 8px; margin-top: 8px; display: block; }
.msg .badge { display: inline-block; font-size: 10px; background: var(--bg); padding: 2px 6px; border-radius: 4px; margin-bottom: 4px; color: var(--accent); }

.composer {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border);
  background: var(--bg-2);
}
.composer textarea {
  flex: 1;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 14px;
  resize: none;
  min-height: 42px;
  max-height: 140px;
  outline: none;
}
.composer textarea:focus { border-color: var(--accent); }
.composer button {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #0a0e1a;
  border: 0;
  border-radius: 10px;
  padding: 0 18px;
  font-weight: 600;
  cursor: pointer;
  font-size: 14px;
}
.composer button:disabled { opacity: 0.5; cursor: not-allowed; }
.composer label.file-btn {
  background: var(--card);
  border: 1px solid var(--border);
  padding: 0 14px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  cursor: pointer;
  font-size: 18px;
}
.composer label.file-btn:hover { border-color: var(--accent); }
.composer input[type=file] { display: none; }
.attach-preview {
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  background: var(--bg-2);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--muted);
}
.attach-preview img { width: 40px; height: 40px; object-fit: cover; border-radius: 6px; }
.attach-preview button { background: transparent; color: var(--danger); border: 0; cursor: pointer; font-size: 16px; }

.typing { display: inline-flex; gap: 4px; align-items: center; }
.typing span { width: 6px; height: 6px; background: var(--muted); border-radius: 50%; animation: blink 1.4s infinite; }
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.3; } 40% { opacity: 1; } }

/* Voice mode */
.voice-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 20px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.avatar-wrap {
  position: relative;
  width: 280px;
  height: 280px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.avatar-glow {
  position: absolute;
  inset: -20px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(125,211,252,0.4), transparent 70%);
  filter: blur(20px);
  animation: pulse 3s ease-in-out infinite;
}
.avatar-glow.speaking { animation: pulse 0.6s ease-in-out infinite; background: radial-gradient(circle, rgba(240,168,255,0.6), transparent 70%); }
.avatar-glow.listening { background: radial-gradient(circle, rgba(74,222,128,0.5), transparent 70%); }
@keyframes pulse { 0%, 100% { transform: scale(1); opacity: 0.6; } 50% { transform: scale(1.1); opacity: 1; } }
.avatar-img {
  position: relative;
  width: 280px;
  height: 280px;
  object-fit: contain;
  animation: breathe 4s ease-in-out infinite;
  z-index: 1;
}
@keyframes breathe { 0%, 100% { transform: translateY(0) scale(1); } 50% { transform: translateY(-4px) scale(1.02); } }
.voice-status {
  font-size: 14px;
  color: var(--muted);
  min-height: 22px;
  text-align: center;
  max-width: 500px;
}
.voice-status strong { color: var(--accent); }
.voice-controls { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.btn-mic {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #0a0e1a;
  border: 0;
  border-radius: 50%;
  width: 72px;
  height: 72px;
  font-size: 28px;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(125,211,252,0.4);
  transition: transform 0.15s;
}
.btn-mic.recording { background: linear-gradient(135deg, #ff6b6b, #ff8e8e); animation: pulse 1s infinite; }
.btn-mic:hover { transform: scale(1.05); }
.btn-secondary {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 18px;
  cursor: pointer;
  font-size: 14px;
}

.gen-form { padding: 16px; }
.gen-form textarea {
  width: 100%;
  background: var(--bg-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  font-family: inherit;
  font-size: 14px;
  min-height: 100px;
  resize: vertical;
  outline: none;
  margin-bottom: 12px;
}
.gen-form textarea:focus { border-color: var(--accent); }
.gen-form button {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #0a0e1a;
  border: 0;
  border-radius: 10px;
  padding: 12px 24px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  font-size: 15px;
}
.gen-form button:disabled { opacity: 0.5; cursor: wait; }
.gen-result { padding: 16px; }
.gen-result img, .gen-result video { width: 100%; border-radius: 10px; }
.gen-result .error { color: var(--danger); background: rgba(255,107,107,0.1); padding: 12px; border-radius: 8px; font-size: 13px; }

.file-upload-box {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 30px;
  text-align: center;
  cursor: pointer;
  margin-bottom: 12px;
  transition: border-color 0.15s;
}
.file-upload-box:hover { border-color: var(--accent); }
.file-upload-box.has-file { border-style: solid; border-color: var(--accent); }
.file-upload-box img { max-height: 200px; margin: 0 auto; display: block; border-radius: 6px; }

@media (max-width: 600px) {
  .app { padding: 8px; }
  .messages { max-height: calc(100vh - 260px); }
  .avatar-wrap, .avatar-img { width: 220px; height: 220px; }
}
