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

:root {
  --bg-primary: #0a0e1a;
  --bg-secondary: #111827;
  --bg-card: #0f1419;
  --accent: #7F77DD;
  --accent-hover: #6b63c7;
  --text-primary: #f0f0f5;
  --text-secondary: #9ca3af;
  --border: rgba(127, 119, 221, 0.3);
  --border-subtle: rgba(127, 119, 221, 0.15);
  --success: #22c55e;
  --error: #ef4444;
}

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

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 2rem;
  border-bottom: 0.5px solid var(--border-subtle);
}

.logo {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.02em;
}

.btn-settings {
  background: transparent;
  border: 0.5px solid var(--border);
  color: var(--text-primary);
  padding: 0.5rem 1rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.875rem;
  transition: all 0.2s;
}

.btn-settings:hover {
  background: var(--border-subtle);
  border-color: var(--accent);
}

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 2rem;
}

.race-input {
  margin-bottom: 2rem;
}

#promptInput {
  width: 100%;
  background: var(--bg-secondary);
  border: 0.5px solid var(--border-subtle);
  border-radius: 8px;
  padding: 1rem;
  color: var(--text-primary);
  font-size: 1rem;
  resize: vertical;
  min-height: 100px;
  font-family: inherit;
}

#promptInput:focus {
  outline: none;
  border-color: var(--accent);
}

.race-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 1rem;
  flex-wrap: wrap;
  gap: 1rem;
}

.model-toggles {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.pill {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-secondary);
  border: 0.5px solid var(--border-subtle);
  color: var(--text-secondary);
  padding: 0.5rem 1rem;
  border-radius: 20px;
  cursor: pointer;
  font-size: 0.875rem;
  transition: all 0.2s;
}

.pill:hover {
  border-color: var(--border);
  color: var(--text-primary);
}

.pill.active {
  border-color: var(--accent);
  color: var(--text-primary);
  background: rgba(127, 119, 221, 0.1);
}

.pill.active .indicator {
  background: var(--accent);
}

.pill.disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-secondary);
  transition: background 0.2s;
}

.btn-race {
  background: var(--accent);
  border: none;
  color: white;
  padding: 0.75rem 2rem;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-race:hover {
  background: var(--accent-hover);
}

.btn-race:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.response-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  gap: 1.5rem;
}

.response-card {
  background: var(--bg-card);
  border: 0.5px solid var(--border-subtle);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.response-card.streaming {
  border-color: var(--accent);
  box-shadow: 0 0 20px rgba(127, 119, 221, 0.1);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem;
  border-bottom: 0.5px solid var(--border-subtle);
  background: var(--bg-secondary);
}

.model-name {
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--text-primary);
}

.card-meta {
  display: flex;
  gap: 1rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.card-body {
  padding: 1rem;
  flex: 1;
  overflow-y: auto;
  max-height: 500px;
}

.response-text {
  font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
  font-size: 0.875rem;
  line-height: 1.6;
  color: var(--text-primary);
  white-space: pre-wrap;
  word-break: break-word;
}

.card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem;
  border-top: 0.5px solid var(--border-subtle);
  background: var(--bg-secondary);
}

.metrics {
  display: flex;
  gap: 1rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.metric {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.metric-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.metric-value {
  color: var(--text-primary);
  font-weight: 500;
}

.btn-vote {
  background: transparent;
  border: 0.5px solid var(--border);
  color: var(--text-secondary);
  padding: 0.5rem 1rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.875rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: all 0.2s;
}

.btn-vote:hover {
  border-color: var(--accent);
  color: var(--text-primary);
}

.btn-vote.voted {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.card-error {
  color: var(--error);
  font-size: 0.875rem;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border-subtle);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

.streaming-indicator {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: var(--accent);
}

/* Modal */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10, 14, 26, 0.9);
  backdrop-filter: blur(4px);
  z-index: 100;
  justify-content: center;
  align-items: center;
  padding: 2rem;
}

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

.modal {
  background: var(--bg-secondary);
  border: 0.5px solid var(--border);
  border-radius: 12px;
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.5rem;
  border-bottom: 0.5px solid var(--border-subtle);
}

.modal-header h2 {
  font-size: 1.25rem;
  font-weight: 600;
}

.btn-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
}

.btn-close:hover {
  color: var(--text-primary);
}

.modal-body {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.key-input-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.key-input-group label {
  font-size: 0.875rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.key-input-group input {
  background: var(--bg-primary);
  border: 0.5px solid var(--border-subtle);
  border-radius: 6px;
  padding: 0.75rem;
  color: var(--text-primary);
  font-size: 0.875rem;
  font-family: monospace;
}

.key-input-group input:focus {
  outline: none;
  border-color: var(--accent);
}

.key-status {
  font-size: 0.75rem;
  min-height: 1rem;
}

.key-status.valid {
  color: var(--success);
}

.key-status.invalid {
  color: var(--error);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 1rem;
  padding: 1.5rem;
  border-top: 0.5px solid var(--border-subtle);
}

.btn-secondary {
  background: transparent;
  border: 0.5px solid var(--border);
  color: var(--text-primary);
  padding: 0.75rem 1.5rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.875rem;
  transition: all 0.2s;
}

.btn-secondary:hover {
  background: var(--border-subtle);
}

.btn-primary {
  background: var(--accent);
  border: none;
  color: white;
  padding: 0.75rem 1.5rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  transition: background 0.2s;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

@media (max-width: 768px) {
  .response-grid {
    grid-template-columns: 1fr;
  }
  
  .race-controls {
    flex-direction: column;
    align-items: stretch;
  }
  
  .container {
    padding: 1rem;
  }
  
  .topbar {
    padding: 1rem;
  }
}
