:root {
  --bg-primary: #0f0f14;
  --bg-secondary: #1a1a24;
  --bg-tertiary: #24243a;
  --text-primary: #f0f0f5;
  --text-secondary: #a0a0b8;
  --accent: #6c5ce7;
  --accent-hover: #7f6ff0;
  --border: #2a2a3e;
  --user-bubble: #2d2d5e;
  --assistant-bubble: #1e1e34;
  --radius: 12px;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
}

.app {
  max-width: 900px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

header {
  text-align: center;
  margin-bottom: 2rem;
}

header h1 {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

header .subtitle {
  color: var(--text-secondary);
  font-size: 0.95rem;
  margin-top: 0.25rem;
}

/* Avatar Picker */
.avatar-picker h2 {
  font-size: 1rem;
  color: var(--text-secondary);
  margin-bottom: 0.75rem;
  font-weight: 500;
}

.avatar-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.avatar-card {
  background: var(--bg-secondary);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.avatar-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.avatar-card.selected {
  border-color: var(--accent);
  background: var(--bg-tertiary);
}

.avatar-card .avatar-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 0.75rem;
  font-size: 1.25rem;
  font-weight: 700;
  color: white;
}

.avatar-card .avatar-name {
  font-weight: 600;
  font-size: 0.95rem;
}

/* Video Section */
.video-section {
  margin-bottom: 2rem;
}

.video-container {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: var(--bg-secondary);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}

#video-player {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: none;
}

#video-player.active {
  display: block;
}

.video-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  font-size: 0.9rem;
  padding: 1rem;
  text-align: center;
}

.loading-overlay {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(15, 15, 20, 0.85);
  gap: 1rem;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.loading-overlay.active {
  display: flex;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Chat Section */
.chat-section {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.chat-history {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  max-height: 300px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.chat-message {
  padding: 0.75rem 1rem;
  border-radius: 10px;
  max-width: 80%;
  font-size: 0.9rem;
  line-height: 1.5;
}

.chat-message.user {
  background: var(--user-bubble);
  align-self: flex-end;
}

.chat-message.assistant {
  background: var(--assistant-bubble);
  align-self: flex-start;
}

.chat-message .msg-role {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  margin-bottom: 0.25rem;
}

.chat-input {
  display: flex;
  gap: 0.75rem;
}

.chat-input input {
  flex: 1;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  font-size: 0.95rem;
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.2s;
}

.chat-input input:focus {
  border-color: var(--accent);
}

.chat-input button {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  padding: 0.75rem 1.5rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.chat-input button:hover {
  background: var(--accent-hover);
}

.chat-input button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Scrollbar */
.chat-history::-webkit-scrollbar {
  width: 6px;
}

.chat-history::-webkit-scrollbar-track {
  background: transparent;
}

.chat-history::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

/* Responsive */
@media (max-width: 600px) {
  .app {
    padding: 1rem;
  }

  .avatar-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
  }

  .avatar-card {
    padding: 0.75rem 0.5rem;
  }

  .chat-message {
    max-width: 90%;
  }
}
