: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; }

button, input, textarea, select { font: inherit; color: inherit; }

/* ---------- topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  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; }
.topbar-center { display: flex; align-items: center; gap: 8px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }

.status-pill, .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, .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; }
.pill i { background: var(--accent-2); }
.pill { color: var(--text); }

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

/* ---------- layout ---------- */
.app {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 300px 1fr;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 0;
}

.lobby {
  grid-column: 1 / -1;
  grid-row: 1 / -1;
  max-width: 760px;
  margin: 0 auto;
  padding: 40px 24px;
  overflow: auto;
}
.lobby h1 { font-size: 26px; margin: 0 0 8px; }
.lobby .lead { color: var(--muted); line-height: 1.6; margin: 0 0 24px; }
.lobby code {
  background: var(--panel-2); border: 1px solid var(--line);
  padding: 1px 6px; border-radius: 6px; font-size: 13px;
}

.create-form { display: flex; gap: 10px; }
.create-form input {
  flex: 1;
  padding: 11px 13px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  outline: none;
}
.create-form input:focus { border-color: var(--accent); }
.form-error { color: var(--error); font-size: 13px; min-height: 18px; margin: 8px 0; }

.room-list { list-style: none; margin: 18px 0 0; padding: 0; display: grid; gap: 10px; }
.room-card {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
}
.room-card:hover { border-color: var(--accent); }
.room-card strong { display: block; }
.room-card .muted { font-size: 12px; }
.room-card .meta { text-align: right; font-size: 12px; color: var(--muted); }
.empty { color: var(--muted); font-size: 13px; }

/* ---------- room panels ---------- */
.room {
  grid-column: 1 / -1;
  grid-row: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 300px 1fr;
  min-width: 0;
}
.left {
  border-right: 1px solid var(--line);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.scroll { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; min-height: 0; }

.center {
  background: var(--bg);
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}
.tabs {
  display: flex; gap: 4px;
  padding: 8px 12px 0;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.tab {
  background: transparent; border: none;
  color: var(--muted);
  padding: 8px 14px;
  border-radius: 8px 8px 0 0;
  cursor: pointer;
  font-size: 13px;
}
.tab.is-active { color: var(--text); background: var(--bg); }
.tab-body { flex: 1; min-height: 0; display: flex; }
.tab-pane { display: none; flex: 1; min-height: 0; }
.tab-pane.is-active { display: flex; flex-direction: column; }

.manifest-toolbar, .files-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.btn-group { display: flex; gap: 8px; align-items: center; }
#manifest-input {
  flex: 1;
  margin: 12px;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  resize: none;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  line-height: 1.5;
  outline: none;
}
#manifest-input:focus { border-color: var(--accent); }
.manifest-actions { padding: 0 12px 12px; font-size: 12px; }

.files-split { display: flex; flex: 1; min-height: 0; }
.file-tree {
  list-style: none; margin: 0; padding: 10px;
  width: 46%; max-width: 420px;
  overflow-y: auto;
  border-right: 1px solid var(--line);
  font-family: ui-monospace, Menlo, monospace;
  font-size: 12.5px;
  display: flex; flex-direction: column; gap: 2px;
}
.file-tree li { padding: 4px 8px; border-radius: 6px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-tree li:hover { background: var(--panel-2); }
.file-tree li.is-active { background: var(--panel-2); color: var(--accent); }
.file-tree li.dir { color: var(--muted); cursor: default; }
.file-view {
  flex: 1; min-width: 0;
  margin: 0;
  padding: 14px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 12.5px;
  line-height: 1.55;
}

.activity-list { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.activity-item {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 12.5px;
}
.activity-item .who { font-weight: 600; color: var(--accent-2); margin-bottom: 4px; display: flex; justify-content: space-between; gap: 8px; }
.activity-item .who .muted { font-weight: 400; }
.activity-item pre { margin: 0; white-space: pre-wrap; word-break: break-word; font-family: ui-monospace, Menlo, monospace; }

/* ---------- chat ---------- */
.agent-chat {
  grid-column: 1 / -1;
  grid-row: 2;
  border-top: 1px solid var(--line);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  max-height: 46vh;
  min-height: 220px;
}
.agent-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.agent-messages {
  flex: 1; min-height: 0;
  overflow-y: auto;
  padding: 12px;
  display: flex; flex-direction: column; gap: 8px;
}
.composer {
  display: flex; gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid var(--line);
  background: var(--panel-2);
}
.composer input, .composer textarea {
  flex: 1;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  outline: none;
  resize: none;
}
.composer input:focus, .composer textarea:focus { border-color: var(--accent); }
.composer textarea { min-height: 42px; max-height: 140px; }
.send {
  width: 42px; height: 42px;
  border-radius: 10px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #141414;
  font-weight: 700;
  cursor: pointer;
  align-self: center;
}
.send:disabled { opacity: 0.45; cursor: default; }
.composer-note { padding: 4px 14px 8px; font-size: 12px; color: var(--muted); min-height: 18px; }

.msg { display: flex; gap: 10px; align-items: flex-start; }
.msg .avatar {
  width: 26px; height: 26px; flex: none;
  display: grid; place-items: center;
  border-radius: 8px;
  font-size: 10px; font-weight: 700;
  text-transform: uppercase;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--muted);
}
.msg.player .avatar { background: #2a2438; color: #c9a2ff; border-color: #4a3b6b; }
.msg.agent .avatar { background: #243828; color: #7fe0a0; border-color: #2f5a3c; }
.msg .bubble {
  background: var(--bot);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 9px 12px;
  font-size: 13.5px;
  line-height: 1.5;
  min-width: 0;
  max-width: 100%;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg .who { display: block; font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.msg .model-tag {
  display: inline-block;
  font-size: 10px;
  color: var(--accent);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 8px;
  margin: 0 0 6px;
}
.msg .cursor { color: var(--accent); animation: blink 0.8s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* ---------- selects & buttons ---------- */
.select {
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  max-width: 220px;
  outline: none;
}
button.primary {
  padding: 9px 16px;
  border-radius: 10px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #141414;
  font-weight: 600;
  cursor: pointer;
}
button.ghost {
  padding: 7px 13px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
}
button.ghost:hover { border-color: var(--accent); }
button.primary:disabled, button.ghost:disabled { opacity: 0.5; cursor: default; }

.muted { color: var(--muted); }

.toast {
  position: fixed;
  bottom: 24px; left: 50%;
  transform: translateX(-50%);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 13px;
  z-index: 50;
}

[hidden] { display: none !important; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) auto; }
  .room { grid-template-columns: 1fr; }
  .left { border-right: none; border-bottom: 1px solid var(--line); max-height: 38vh; }
}
