:root {
  --purple: #603388;
  --purple-light: #7c4daa;
  --purple-dark: #4a2068;
  --purple-glow: rgba(96, 51, 136, 0.3);
  --gold: #D4AF37;
  --gold-light: #e8c84a;
  --bg-primary: #0f0f14;
  --bg-secondary: #16161e;
  --bg-tertiary: #1e1e2a;
  --bg-chat: #12121a;
  --text-primary: #f0f0f5;
  --text-secondary: #a0a0b8;
  --text-muted: #6a6a82;
  --border: #2a2a3a;
  --border-light: #3a3a4a;
  --user-bubble: #603388;
  --kyle-bubble: #1e1e2a;
  --success: #4ade80;
  --danger: #f87171;
  --nate-primary: #d97706;
  --nate-light: #f59e0b;
  --nate-dark: #92400e;
  --nate-glow: rgba(217, 119, 6, 0.3);
  --nate-bubble: #2a2218;
  --observer-bubble: #3d2a5c;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
}

/* Modal */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  z-index: 1000;
  justify-content: center;
  align-items: center;
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 90%;
  max-width: 480px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  font-size: 18px;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 24px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
  transition: all 0.2s;
}

.modal-close:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.modal-body {
  padding: 24px;
}

.setting-group {
  margin-bottom: 20px;
}

.setting-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.setting-group select,
.setting-group input {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  transition: all 0.2s;
}

.setting-group select:focus,
.setting-group input:focus {
  outline: none;
  border-color: var(--purple);
  box-shadow: 0 0 0 3px var(--purple-glow);
}

.btn-save {
  width: 100%;
  padding: 14px;
  background: var(--purple);
  border: none;
  border-radius: 10px;
  color: white;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-save:hover {
  background: var(--purple-light);
  transform: translateY(-1px);
}

/* App Layout */
.app-container {
  display: flex;
  height: 100vh;
}

/* Sidebar */
.sidebar {
  width: 280px;
  min-width: 280px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease;
}

.sidebar-header {
  padding: 28px 20px 20px;
  text-align: center;
  border-bottom: 1px solid var(--border);
}

.avatar-container {
  position: relative;
  display: inline-block;
  margin-bottom: 12px;
}

.avatar {
  width: 64px;
  height: 64px;
  background: linear-gradient(135deg, var(--purple), var(--purple-light));
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 700;
  color: white;
  box-shadow: 0 4px 20px var(--purple-glow);
}

.status-dot {
  position: absolute;
  bottom: 2px;
  right: 2px;
  width: 14px;
  height: 14px;
  background: var(--success);
  border-radius: 50%;
  border: 3px solid var(--bg-secondary);
}

.sidebar-header h1 {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 2px;
}

.subtitle {
  font-size: 13px;
  color: var(--gold);
  font-weight: 500;
}

.sidebar-nav {
  padding: 12px;
  flex-shrink: 0;
}

.nav-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: none;
  border: none;
  border-radius: 10px;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  text-align: left;
  font-family: inherit;
}

.nav-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.nav-btn.active {
  background: var(--purple-dark);
  color: white;
  box-shadow: 0 2px 12px var(--purple-glow);
}

.nav-icon {
  font-size: 18px;
}

.sidebar-stats {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  flex-grow: 1;
  overflow-y: auto;
}

.sidebar-stats h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.stat-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
}

.stat-label {
  font-size: 13px;
  color: var(--text-secondary);
}

.stat-value {
  font-size: 13px;
  font-weight: 600;
  color: var(--gold);
}

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.settings-btn,
.clear-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 16px;
  background: none;
  border: none;
  border-radius: 8px;
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

.settings-btn:hover,
.clear-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

/* Chat Area */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-chat);
  min-width: 0;
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  flex-shrink: 0;
}

.chat-header-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.hamburger {
  display: none;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 22px;
  cursor: pointer;
  padding: 4px;
}

.chat-avatar {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, var(--purple), var(--purple-light));
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  color: white;
}

.chat-header h2 {
  font-size: 16px;
  font-weight: 600;
}

.chat-status {
  font-size: 12px;
  color: var(--text-muted);
}

.badge {
  padding: 6px 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

.badge.connected {
  color: var(--success);
  border-color: rgba(74, 222, 128, 0.3);
}

/* Messages */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  scroll-behavior: smooth;
}

.messages-container::-webkit-scrollbar {
  width: 6px;
}

.messages-container::-webkit-scrollbar-track {
  background: transparent;
}

.messages-container::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.welcome-message {
  text-align: center;
  padding: 60px 20px;
  max-width: 600px;
  margin: 0 auto;
}

.welcome-avatar {
  width: 80px;
  height: 80px;
  background: linear-gradient(135deg, var(--purple), var(--purple-light));
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  font-weight: 700;
  color: white;
  margin: 0 auto 20px;
  box-shadow: 0 8px 30px var(--purple-glow);
}

.welcome-message h2 {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 12px;
}

.welcome-message p {
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.6;
  margin-bottom: 28px;
}

.action-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 0 auto 22px;
  max-width: 660px;
}

.action-card {
  min-height: 112px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  text-align: left;
  cursor: pointer;
  transition: border-color .2s ease, transform .2s ease, background .2s ease;
}

.action-card:hover,
.action-card:focus-visible {
  border-color: var(--purple-light);
  background: var(--bg-tertiary);
  transform: translateY(-2px);
}

.action-card strong,
.action-card span {
  display: block;
}

.action-card span {
  margin-top: 6px;
  color: var(--text-secondary);
  font-size: 12px;
  line-height: 1.45;
}

.sidebar-footer .disclaimer {
  line-height: 1.5;
}

.sidebar-footer .disclaimer a {
  color: var(--text-secondary);
}

@media (max-width: 640px) {
  .action-grid { grid-template-columns: 1fr; }
  .action-card { min-height: 78px; }
}

.quick-prompts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.quick-prompt {
  padding: 10px 16px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

.quick-prompt:hover {
  border-color: var(--purple);
  color: var(--text-primary);
  background: var(--purple-dark);
}

/* Message Bubbles */
.message {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.message.user {
  flex-direction: row-reverse;
}

.message-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
  align-self: flex-end;
}

.message.kyle .message-avatar {
  background: linear-gradient(135deg, var(--purple), var(--purple-light));
  color: white;
}

.message.user .message-avatar {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
}

.message-content {
  max-width: 70%;
  min-width: 80px;
}

.message-bubble {
  padding: 14px 18px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.6;
  word-wrap: break-word;
}

.message.kyle .message-bubble {
  background: var(--kyle-bubble);
  border: 1px solid var(--border);
  border-bottom-left-radius: 6px;
  color: var(--text-primary);
}

.message.user .message-bubble {
  background: var(--user-bubble);
  border-bottom-right-radius: 6px;
  color: white;
}

.message-time {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
  padding: 0 4px;
}

.message.user .message-time {
  text-align: right;
}

/* Typing indicator */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 14px 18px;
  background: var(--kyle-bubble);
  border: 1px solid var(--border);
  border-radius: 18px;
  border-bottom-left-radius: 6px;
  width: fit-content;
}

.typing-dot {
  width: 8px;
  height: 8px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typingBounce 1.4s infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* Input Area */
.input-area {
  padding: 16px 24px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
  flex-shrink: 0;
}

.input-container {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 8px 8px 8px 18px;
  transition: all 0.2s;
}

.input-container:focus-within {
  border-color: var(--purple);
  box-shadow: 0 0 0 3px var(--purple-glow);
}

#messageInput {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  resize: none;
  max-height: 120px;
  line-height: 1.5;
  padding: 6px 0;
}

#messageInput:focus {
  outline: none;
}

#messageInput::placeholder {
  color: var(--text-muted);
}

.send-btn {
  width: 40px;
  height: 40px;
  background: var(--purple);
  border: none;
  border-radius: 12px;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}

.send-btn:hover {
  background: var(--purple-light);
  transform: scale(1.05);
}

.send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.disclaimer {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 10px;
}

/* Responsive */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 100;
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .hamburger {
    display: block;
  }

  .message-content {
    max-width: 85%;
  }

  .quick-prompts {
    flex-direction: column;
  }

  .welcome-message {
    padding: 40px 10px;
  }
}

/* Error message */
.error-bubble {
  background: rgba(248, 113, 113, 0.1) !important;
  border-color: rgba(248, 113, 113, 0.3) !important;
  color: var(--danger) !important;
}

/* Markdown-like styling in messages */
.message-bubble strong {
  font-weight: 600;
}

.message-bubble em {
  font-style: italic;
  color: var(--text-secondary);
}

.message-bubble code {
  background: rgba(96, 51, 136, 0.2);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
  font-family: 'SF Mono', 'Fira Code', monospace;
}

.message-bubble p {
  margin-bottom: 8px;
}

.message-bubble p:last-child {
  margin-bottom: 0;
}

/* ============================================================
   DEBATE MODE STYLES — Nate & Kyle Conversation
   ============================================================ */

/* Nav divider */
.nav-divider {
  height: 1px;
  background: var(--border);
  margin: 8px 16px;
}

/* Debate mode nav button active state (amber) */
.nav-btn[data-mode="debate"].active {
  background: var(--nate-dark);
  box-shadow: 0 2px 12px var(--nate-glow);
}

/* Debate Controls Bar */
.debate-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 24px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.debate-controls-left {
  display: flex;
  gap: 8px;
}

.debate-ctrl-btn {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  font-family: inherit;
}

.debate-ctrl-btn:hover:not(:disabled) {
  background: var(--purple-dark);
  color: white;
  border-color: var(--purple);
}

.debate-ctrl-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.debate-ctrl-btn.active-ctrl {
  background: var(--purple);
  color: white;
  border-color: var(--purple-light);
}

.turn-counter {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
}

/* Debate input area */
.debate-input-container {
  border-color: var(--nate-dark);
}

.debate-input-container:focus-within {
  border-color: var(--nate-primary);
  box-shadow: 0 0 0 3px var(--nate-glow);
}

#debateInput {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  resize: none;
  max-height: 120px;
  line-height: 1.5;
  padding: 6px 0;
}

#debateInput:focus {
  outline: none;
}

#debateInput::placeholder {
  color: var(--text-muted);
}

.debate-send-btn {
  background: var(--nate-primary) !important;
}

.debate-send-btn:hover {
  background: var(--nate-light) !important;
}

/* Speaker Name Labels */
.speaker-name {
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 4px;
  padding: 0 4px;
}

.speaker-name.kyle-name {
  color: var(--purple-light);
}

.speaker-name.nate-name {
  color: var(--nate-light);
}

.speaker-name.observer-name {
  color: var(--text-muted);
  text-align: right;
}

/* Nate message bubbles */
.message.nate {
  flex-direction: row;
}

.message.nate .message-avatar {
  background: linear-gradient(135deg, var(--nate-primary), var(--nate-light));
  color: white;
}

.message.nate .message-bubble {
  background: var(--nate-bubble);
  border: 1px solid rgba(217, 119, 6, 0.2);
  border-bottom-left-radius: 6px;
  color: var(--text-primary);
}

/* Observer (user interjection) message bubbles */
.message.observer {
  flex-direction: row-reverse;
}

.message.observer .message-avatar {
  background: var(--observer-bubble);
  color: var(--text-secondary);
}

.message.observer .message-bubble {
  background: var(--observer-bubble);
  border: 1px solid rgba(96, 51, 136, 0.3);
  border-bottom-right-radius: 6px;
  color: var(--text-primary);
}

.message.observer .message-time {
  text-align: right;
}

/* System messages (topic seeds, status) */
.debate-system-msg {
  display: flex;
  justify-content: center;
  margin: 16px 0;
  animation: fadeIn 0.3s ease;
}

.debate-system-pill {
  padding: 8px 20px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
  text-align: center;
}

/* Debate Welcome Screen */
.debate-welcome {
  text-align: center;
  padding: 40px 20px;
  max-width: 600px;
  margin: 0 auto;
}

.debate-welcome-avatars {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 24px;
}

.debate-avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 700;
  color: white;
}

.debate-avatar.kyle-avatar {
  background: linear-gradient(135deg, var(--purple), var(--purple-light));
  box-shadow: 0 6px 24px var(--purple-glow);
}

.debate-avatar.nate-avatar {
  background: linear-gradient(135deg, var(--nate-primary), var(--nate-light));
  box-shadow: 0 6px 24px var(--nate-glow);
}

.debate-ampersand {
  font-size: 28px;
  font-weight: 300;
  color: var(--text-muted);
}

.debate-welcome h2 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 8px;
}

.debate-welcome p {
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.6;
  margin-bottom: 28px;
}

/* Topic Seed Grid */
.topic-seed-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  max-width: 480px;
  margin: 0 auto 20px;
}

.topic-seed-btn {
  padding: 14px 16px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
  text-align: left;
  line-height: 1.4;
}

.topic-seed-btn:hover {
  border-color: var(--nate-primary);
  color: var(--text-primary);
  background: rgba(217, 119, 6, 0.1);
}

/* Custom Topic Input */
.custom-topic-area {
  max-width: 480px;
  margin: 0 auto;
}

.custom-topic-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.custom-topic-row {
  display: flex;
  gap: 8px;
}

.custom-topic-input {
  flex: 1;
  padding: 12px 16px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  transition: all 0.2s;
}

.custom-topic-input:focus {
  outline: none;
  border-color: var(--nate-primary);
  box-shadow: 0 0 0 3px var(--nate-glow);
}

.custom-topic-input::placeholder {
  color: var(--text-muted);
}

.custom-topic-start {
  padding: 12px 20px;
  background: var(--nate-primary);
  border: none;
  border-radius: 10px;
  color: white;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
  white-space: nowrap;
}

.custom-topic-start:hover {
  background: var(--nate-light);
  transform: translateY(-1px);
}

/* Nate typing indicator */
.message.nate .typing-indicator {
  background: var(--nate-bubble);
  border-color: rgba(217, 119, 6, 0.2);
}

/* Chat header in debate mode */
.chat-avatar.debate-avatar-header {
  background: linear-gradient(135deg, var(--nate-primary), var(--purple-light));
}

/* Responsive for debate */
@media (max-width: 768px) {
  .topic-seed-grid {
    grid-template-columns: 1fr;
  }

  .debate-welcome {
    padding: 30px 10px;
  }

  .custom-topic-row {
    flex-direction: column;
  }
}
