:root {
  --bg: #0b0e14;
  --panel: #11161f;
  --panel-2: #161d29;
  --line: #242d3d;
  --text: #e6eaf2;
  --muted: #8b94a7;
  --accent: #e8a93c;
  --accent-2: #4f8cff;
  --user: #1e2a44;
  --bot: #141a26;
  --error: #ff5c5c;
  --ok: #3ecf6e;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

body { display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 34px; height: 34px;
  border-radius: 9px;
  background: linear-gradient(135deg, #1a2333, #0e141f);
  border: 1px solid var(--line);
  font-family: ui-monospace, monospace;
  font-weight: 700;
  color: var(--accent);
}
.brand strong { display: block; font-size: 15px; line-height: 1.15; }
.brand small { color: var(--muted); font-size: 11px; }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--muted);
  padding: 5px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-2);
}
.status-pill i {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--muted);
}
.status-pill[data-state="online"] i { background: var(--ok); }
.status-pill[data-state="online"] { color: var(--ok); }
.status-pill[data-state="error"] i { background: var(--error); }
.status-pill[data-state="error"] { color: var(--error); }
.status-pill[data-state="busy"] i {
  background: var(--accent);
  animation: pulse 0.9s ease-in-out infinite;
}

.arena-link {
  color: var(--accent);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 12px;
  background: var(--panel-2);
}
.arena-link:hover { border-color: var(--accent); }

@keyframes pulse {
  50% { opacity: 0.25; }
}

.app {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 26px 16px;
  overflow: auto;
}

.connect-panel {
  width: 100%;
  max-width: 460px;
  margin: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
}

.connect-panel h1 { margin: 0 0 6px; font-size: 19px; }
.lead { margin: 0 0 18px; color: var(--muted); font-size: 13.5px; line-height: 1.5; }

.field { display: block; margin-bottom: 14px; }
.field span {
  display: block;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 5px;
}
.field input {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--text);
  font-size: 14px;
  padding: 10px 12px;
  outline: none;
}
.field input:focus { border-color: var(--accent-2); }

.form-error { min-height: 16px; margin: 0 0 10px; color: var(--error); font-size: 12.5px; }

.row { display: flex; gap: 10px; }

button {
  font: inherit;
  cursor: pointer;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  padding: 9px 16px;
  font-size: 14px;
}
button.primary { background: var(--accent); color: #14100a; border-color: var(--accent); font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }
button.primary:disabled { opacity: 0.55; cursor: default; }
button.ghost:hover { background: var(--line); }

.meta {
  margin: 18px 0 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.meta div {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 10px 12px;
}
.meta dt { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 3px; }
.meta dd { margin: 0; font-size: 13px; word-break: break-all; }

.chat {
  width: 100%;
  max-width: 860px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 420px;
}

.messages {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  padding: 4px 2px 8px;
}

.msg {
  display: flex;
  gap: 10px;
  max-width: 92%;
}
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg .avatar {
  flex: none;
  width: 28px; height: 28px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--muted);
}
.msg.user .avatar { background: var(--user); color: var(--accent-2); border-color: transparent; }
.msg .bubble {
  background: var(--bot);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 13px;
  font-size: 14px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg.user .bubble { background: var(--user); border-color: transparent; }
.msg .bubble .model-tag {
  display: block;
  font-size: 10.5px;
  color: var(--muted);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.msg .bubble code {
  background: #0a0e16;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 5px;
  font-size: 12.5px;
}
.msg .bubble pre {
  background: #0a0e16;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  overflow: auto;
  font-size: 12.5px;
  line-height: 1.45;
}
.msg .bubble pre code { border: 0; padding: 0; background: none; }

.msg.thinking .bubble::after {
  content: "";
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent);
  margin-left: 6px;
  animation: pulse 0.9s ease-in-out infinite;
}

.composer {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
}
.composer textarea {
  flex: 1;
  resize: none;
  background: transparent;
  border: 0;
  outline: 0;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  line-height: 1.5;
  max-height: 180px;
  padding: 6px 4px;
}
.composer .send {
  width: 38px; height: 38px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: var(--accent);
  color: #14100a;
  border: 0;
  font-size: 17px;
  font-weight: 700;
}
.composer .send:disabled { opacity: 0.5; cursor: default; }

.composer-note { min-height: 14px; color: var(--muted); font-size: 11.5px; padding: 0 4px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  background: #221a12;
  color: var(--accent);
  border: 1px solid #3a2f1c;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 13px;
  z-index: 50;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

@media (max-width: 560px) {
  .app { padding: 16px 12px; }
  .msg { max-width: 100%; }
  .meta { grid-template-columns: 1fr; }
}
