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

:root {
  --primary: #00d4ff;
  --secondary: #7b2ff7;
  --accent: #ff6b9d;
  --bg-dark: #0a0e27;
  --bg-card: rgba(255, 255, 255, 0.05);
  --border: rgba(255, 255, 255, 0.1);
  --text: #e8eaf0;
  --text-dim: #8892b0;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background:
    radial-gradient(circle at 20% 50%, rgba(123, 47, 247, 0.15), transparent 50%),
    radial-gradient(circle at 80% 80%, rgba(0, 212, 255, 0.15), transparent 50%),
    var(--bg-dark);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 20px;
  overflow-x: hidden;
}

.container {
  max-width: 900px;
  width: 100%;
}

/* Header */
header {
  text-align: center;
  margin-bottom: 25px;
}

h1 {
  font-size: 2.8rem;
  margin-bottom: 5px;
  background: linear-gradient(90deg, var(--primary), var(--secondary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 0 30px rgba(0, 212, 255, 0.3));
  font-weight: 800;
}

.subtitle {
  color: var(--text-dim);
  font-size: 1rem;
}

/* Status */
#status-container {
  background: var(--bg-card);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 15px;
}

#status {
  font-size: 0.95rem;
  margin-bottom: 10px;
  min-height: 24px;
  display: flex;
  align-items: center;
  gap: 8px;
}

#progress-bar-container {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 3px;
  overflow: hidden;
}

#progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary), var(--secondary));
  border-radius: 3px;
  transition: width 0.3s ease;
  box-shadow: 0 0 10px var(--primary);
}

#stats {
  margin-top: 10px;
  font-size: 0.8rem;
  color: var(--text-dim);
  display: none;
}

#stats.show { display: block; }

/* Selector */
.model-selector {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 15px;
  flex-wrap: wrap;
  background: var(--bg-card);
  padding: 15px;
  border-radius: 16px;
  border: 1px solid var(--border);
}

.model-selector label {
  font-weight: 600;
  font-size: 0.95rem;
}

.model-selector select {
  flex: 1;
  min-width: 250px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.3);
  color: var(--text);
  font-size: 0.9rem;
  cursor: pointer;
  transition: border-color 0.3s;
}

.model-selector select:hover {
  border-color: var(--primary);
}

.model-selector select option,
.model-selector select optgroup {
  background: var(--bg-dark);
  color: var(--text);
}

/* Advanced settings */
.advanced {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 12px 16px;
  margin-bottom: 15px;
}

.advanced summary {
  cursor: pointer;
  font-weight: 600;
  padding: 5px 0;
  user-select: none;
}

.advanced summary:hover {
  color: var(--primary);
}

.settings {
  margin-top: 15px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.setting label {
  display: block;
  font-size: 0.9rem;
  margin-bottom: 5px;
  color: var(--text-dim);
}

.setting input[type="range"] {
  width: 100%;
  accent-color: var(--primary);
}

.setting textarea {
  width: 100%;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.3);
  color: var(--text);
  font-family: inherit;
  font-size: 0.85rem;
  resize: vertical;
}

/* Chat */
#chat-box {
  background: var(--bg-card);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  height: 450px;
  overflow-y: auto;
  margin-bottom: 15px;
  scroll-behavior: smooth;
}

.message {
  display: flex;
  gap: 12px;
  margin-bottom: 18px;
  animation: slideIn 0.4s ease;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateY(15px); }
  to { opacity: 1; transform: translateY(0); }
}

.avatar {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  flex-shrink: 0;
}

.message.user .avatar {
  background: linear-gradient(135deg, var(--primary), #0090ff);
  box-shadow: 0 4px 15px rgba(0, 212, 255, 0.3);
}

.message.assistant .avatar {
  background: linear-gradient(135deg, var(--secondary), var(--accent));
  box-shadow: 0 4px 15px rgba(123, 47, 247, 0.3);
}

.content-wrapper {
  flex: 1;
  min-width: 0;
}

.name {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-bottom: 4px;
  font-weight: 600;
}

.content {
  background: rgba(255, 255, 255, 0.03);
  padding: 12px 16px;
  border-radius: 12px;
  line-height: 1.6;
  word-wrap: break-word;
  white-space: pre-wrap;
  font-size: 0.95rem;
}

.message.user .content {
  background: rgba(0, 212, 255, 0.08);
  border-left: 3px solid var(--primary);
}

.message.assistant .content {
  background: rgba(123, 47, 247, 0.08);
  border-left: 3px solid var(--secondary);
}

/* Code blocks */
.content code {
  background: rgba(0, 0, 0, 0.4);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'Consolas', monospace;
  font-size: 0.9em;
  color: var(--primary);
}

/* Input */
.input-area {
  background: var(--bg-card);
  padding: 15px;
  border-radius: 16px;
  border: 1px solid var(--border);
  margin-bottom: 15px;
}

#user-input {
  width: 100%;
  padding: 12px 15px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.3);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  resize: vertical;
  margin-bottom: 10px;
  transition: all 0.3s;
  min-height: 60px;
}

#user-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0, 212, 255, 0.1);
}

#user-input:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.buttons {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

button {
  padding: 10px 18px;
  border: none;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s;
  font-family: inherit;
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

#load-btn {
  background: linear-gradient(135deg, var(--primary), #0090ff);
  color: white;
}

#load-btn:not(:disabled):hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 212, 255, 0.4);
}

#send-btn {
  background: linear-gradient(135deg, var(--secondary), var(--accent));
  color: white;
  flex: 1;
  min-width: 100px;
}

#send-btn:not(:disabled):hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(123, 47, 247, 0.4);
}

#stop-btn {
  background: linear-gradient(135deg, #ff4444, #ff6b6b);
  color: white;
}

#clear-btn {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border: 1px solid var(--border);
}

#clear-btn:hover {
  background: rgba(255, 255, 255, 0.15);
}

/* Footer info */
.info {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}

.info-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-dim);
}

/* Scrollbar */
#chat-box::-webkit-scrollbar { width: 8px; }
#chat-box::-webkit-scrollbar-track { background: transparent; }
#chat-box::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 4px;
}
#chat-box::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.25);
}

/* Typing indicator */
.typing-indicator {
  display: inline-flex;
  gap: 5px;
  padding: 8px 0;
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  background: var(--secondary);
  border-radius: 50%;
  animation: typing 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* Cursor blink */
.cursor {
  display: inline-block;
  width: 8px;
  height: 16px;
  background: var(--secondary);
  animation: blink 1s infinite;
  vertical-align: middle;
  margin-left: 2px;
}

@keyframes blink {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0; }
}

/* Responsive */
@media (max-width: 600px) {
  body { padding: 10px; }
  h1 { font-size: 2rem; }
  #chat-box { height: 380px; padding: 12px; }
  .avatar { width: 32px; height: 32px; font-size: 1.1rem; }
  .content { padding: 10px 12px; font-size: 0.9rem; }
  .model-selector select { min-width: 100%; }
}
