:root {
  --bg: #0f1115;
  --panel: #1a1d24;
  --panel-2: #232733;
  --accent: #5fb3ff;
  --accent-2: #82e9d4;
  --text: #e3e6eb;
  --muted: #7a8290;
  --border: #2a2f3a;
  --danger: #ff7676;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
        "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
}
button, select, textarea, input {
  font: inherit; color: inherit;
}

.app {
  display: grid;
  grid-template-rows: 48px 1fr;
  height: 100vh;
}

/* ------------ Top bar ------------ */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 600; letter-spacing: 0.3px; }
.brand .tag {
  margin-left: 8px;
  padding: 2px 8px;
  font-size: 11px;
  background: rgba(95, 179, 255, 0.15);
  color: var(--accent);
  border-radius: 10px;
  font-weight: 500;
}
.ctrl { display: flex; gap: 8px; align-items: center; }

.btn {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: background .12s;
}
.btn:hover:not(:disabled) { background: #2c3140; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #0a1827; border-color: var(--accent); font-weight: 600; }
.btn-primary:hover:not(:disabled) { background: #82c4ff; }
.btn.ghost { background: transparent; }
.btn.link { text-decoration: none; }
.select {
  background: var(--panel-2);
  border: 1px solid var(--border);
  padding: 5px 8px;
  border-radius: 6px;
  min-width: 200px;
}

/* ------------ Main layout ------------ */
.layout {
  display: grid;
  grid-template-columns: 380px 1fr 340px;
  min-height: 0;
}
.panel {
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.panel:last-child { border-right: none; border-left: 1px solid var(--border); }
.panel-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--panel);
  font-size: 13px;
}
.panel-header.collapsible { cursor: pointer; user-select: none; }
.arrow { font-size: 10px; color: var(--muted); transition: transform .15s; }
.arrow.collapsed { transform: rotate(-90deg); }

/* ------------ Chat ------------ */
.panel-chat .messages {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}
.msg {
  margin-bottom: 8px;
  padding: 10px 12px;
  border-radius: 8px;
  word-wrap: break-word;
}
.msg-user {
  background: rgba(95, 179, 255, 0.12);
  border-left: 2px solid var(--accent);
}
.msg-assistant {
  background: rgba(130, 233, 212, 0.08);
  border-left: 2px solid var(--accent-2);
}
.msg-thought {
  font-size: 12px;
  color: var(--muted);
  background: var(--panel-2);
  border-left: 2px solid var(--muted);
  padding: 6px 10px;
  margin-bottom: 4px;
}
.msg-thought .stage {
  display: inline-block;
  padding: 1px 6px;
  margin-right: 6px;
  background: rgba(255,255,255,0.04);
  border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  color: var(--accent);
}
.msg pre {
  background: rgba(0, 0, 0, 0.3);
  padding: 8px;
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  margin-top: 6px;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
}
.input-bar {
  display: flex;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--border);
  background: rgba(0,0,0,0.15);
}
.input-bar textarea {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  resize: none;
  outline: none;
}
.input-bar textarea:focus { border-color: var(--accent); }

/* ------------ Viewer ------------ */
.panel-viewer .panel-header .legend {
  font-weight: 400; font-size: 11px; color: var(--muted);
}
.legend .swatch {
  display: inline-block;
  width: 10px; height: 10px;
  margin: 0 4px 0 12px;
  border-radius: 2px;
  vertical-align: -1px;
}
.viewer { flex: 1; background: #14171e; position: relative; min-height: 0; }
.viewer canvas { display: block; }
.metrics {
  padding: 8px 16px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  background: var(--panel);
}
.metrics .item b { color: var(--text); }

/* ------------ Config / Renders ------------ */
.config-body { padding: 10px; }
.config-body.collapsed { display: none; }
#configEditor {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  outline: none;
  resize: vertical;
}
.config-actions { display: flex; gap: 8px; margin-top: 8px; }
.renders {
  padding: 10px;
  overflow-y: auto;
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  align-content: start;
}
.renders .render-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.renders .render-card img { width: 100%; display: block; }
.renders .render-card .cap {
  padding: 4px 6px;
  font-size: 10px;
  color: var(--muted);
  text-align: center;
}
.renders .render-card.full { grid-column: span 2; }

/* ------------ Scrollbar ------------ */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #2e3340; border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }
