:root {
  --bg: #0e1117;
  --panel: #161b22;
  --panel-2: #1c2230;
  --border: #2a3140;
  --text: #e6edf3;
  --muted: #8b97a7;
  --accent: #4f8cff;
  --good: #3fb950;
  --bad: #f85149;
  --warn: #d29922;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  display: flex;
  flex-direction: column;
}

h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 10px; }
h3 { font-size: 12px; color: var(--muted); margin: 0 0 8px; }

/* 頂部 */
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 18px; background: var(--panel); border-bottom: 1px solid var(--border);
}
.brand { font-size: 18px; font-weight: 700; white-space: nowrap; }
.brand small { color: var(--muted); font-weight: 400; font-size: 12px; margin-left: 6px; }
.launch { display: flex; flex: 1; gap: 8px; }
.launch input {
  flex: 1; padding: 9px 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text); font-size: 14px;
}
.launch input:focus { outline: none; border-color: var(--accent); }
.launch button {
  padding: 9px 18px; border: none; border-radius: 8px; cursor: pointer;
  background: var(--accent); color: white; font-weight: 600; font-size: 14px;
}
.launch button:disabled { opacity: .5; cursor: not-allowed; }
.phase { font-size: 13px; color: var(--accent); white-space: nowrap; min-width: 120px; text-align: right; }

/* 版面 */
.layout {
  flex: 1; display: grid;
  grid-template-columns: 240px 1fr 360px;
  gap: 12px; padding: 12px; overflow: hidden;
}
.experts, .discussion, .side { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 14px; overflow: hidden; display: flex; flex-direction: column; }
.side { gap: 14px; }

/* 專家卡 */
.expert {
  display: flex; align-items: center; gap: 10px;
  padding: 10px; border-radius: 10px; background: var(--panel-2);
  border: 1px solid var(--border); margin-bottom: 10px; transition: border-color .2s;
}
.expert.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.expert .av { font-size: 26px; }
.expert .meta { flex: 1; min-width: 0; }
.expert .nm { font-weight: 600; font-size: 14px; }
.expert .tt { font-size: 11px; color: var(--muted); }
.expert .dot { width: 9px; height: 9px; border-radius: 50%; background: #3a4150; }
.expert[data-status="thinking"] .dot { background: var(--warn); animation: pulse 1s infinite; }
.expert[data-status="working"] .dot { background: var(--accent); animation: pulse .6s infinite; }
.expert[data-status="idle"] .dot { background: var(--good); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

/* 討論串 */
.stream { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; padding-right: 6px; }
.placeholder { color: var(--muted); text-align: center; margin-top: 40px; }
.msg { display: flex; gap: 10px; }
.msg .av { font-size: 24px; flex-shrink: 0; }
.msg .body { background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px; max-width: 88%; }
.msg .who { font-size: 12px; color: var(--accent); font-weight: 600; margin-bottom: 3px; }
.msg .txt { font-size: 14px; line-height: 1.55; white-space: pre-wrap; word-break: break-word; }
.tool { font-size: 12.5px; color: var(--muted); display: flex; gap: 8px; align-items: center; padding-left: 34px; }
.tool .badge { background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px; padding: 1px 7px; }
.sys { text-align: center; font-size: 12px; color: var(--muted); border-top: 1px dashed var(--border); padding-top: 8px; }
.result.pass { color: var(--good); } .result.fail { color: var(--bad); }
.result { text-align: center; font-weight: 600; font-size: 13px; }
.result .log { text-align: left; font-weight: 400; margin-top: 6px; }
.result .log summary { cursor: pointer; color: var(--muted); font-size: 12px; }
.result .log pre { background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 8px; font-size: 11.5px; overflow: auto; max-height: 220px; color: #c9d1d9; }

/* 人類插話 */
.msg.human .body { background: #1d2a1d; border-color: #2f5132; }
.msg.human .who { color: var(--good); }

/* git commit chip */
.commit { display: flex; gap: 8px; align-items: center; font-size: 12px; color: var(--muted); padding-left: 34px; }
.commit .hash { background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px; padding: 1px 7px; color: var(--accent); font-family: monospace; }

/* Demo 區塊 */
.demo { border: 1px solid var(--border); border-radius: 10px; padding: 10px; background: var(--panel-2); }
.demo.pass { border-color: #2f5132; } .demo.fail { border-color: #5a2a2a; }
.demo .demohead { font-weight: 600; font-size: 13px; margin-bottom: 6px; }
.demo .demohead code { font-weight: 400; font-size: 11.5px; color: var(--muted); }
.demo pre { background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 8px; font-size: 11.5px; overflow: auto; max-height: 240px; margin: 0; color: #c9d1d9; }

/* 插話列 */
.interject { display: flex; gap: 8px; margin-top: 10px; }
.interject input { flex: 1; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text); font-size: 13px; }
.interject input:focus { outline: none; border-color: var(--accent); }
.interject input:disabled { opacity: .5; }
.interject button { padding: 8px 16px; border: none; border-radius: 8px; background: var(--good); color: white; font-weight: 600; cursor: pointer; }
.interject button:disabled { opacity: .4; cursor: not-allowed; }

/* topbar 次要按鈕 */
.launch button.ghost { background: transparent; border: 1px solid var(--border); color: var(--muted); }
#stopBtn.ghost:not(:disabled) { color: var(--bad); border-color: var(--bad); }
#historyBtn.ghost { color: var(--accent); border-color: var(--border); }

/* 歷史面板 */
.history-panel {
  position: fixed; top: 64px; right: 18px; width: 420px; max-height: 70vh;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0,0,0,.5); z-index: 50; display: flex; flex-direction: column;
}
.history-panel.hidden { display: none; }
.history-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.history-head h2 { margin: 0; }
.history-head button { padding: 4px 10px; border-radius: 6px; cursor: pointer; }
.history-list { list-style: none; margin: 0; padding: 8px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.history-list li { padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel-2); cursor: pointer; }
.history-list li:hover { border-color: var(--accent); }
.history-list li.muted { color: var(--muted); text-align: center; cursor: default; border-style: dashed; }
.history-list li.muted:hover { border-color: var(--border); }
.h-req { font-size: 13.5px; font-weight: 600; margin-bottom: 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.h-meta { display: flex; gap: 12px; font-size: 11.5px; color: var(--muted); }

/* 發佈到 GitHub */
.publish-cta { text-align: center; }
.publish-cta button { padding: 9px 18px; border: none; border-radius: 8px; cursor: pointer; background: var(--accent); color: white; font-weight: 600; font-size: 14px; }
.publish-cta button:disabled { opacity: .5; cursor: not-allowed; }
.publish { text-align: center; font-size: 13px; padding: 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel-2); }
.publish.ok { border-color: #2f5132; } .publish.fail { border-color: #5a2a2a; color: var(--bad); }
.publish code { background: var(--bg); border: 1px solid var(--border); border-radius: 5px; padding: 1px 6px; font-size: 12px; }
.publish a { color: var(--accent); }

/* 看板 */
.board { flex-shrink: 0; }
.columns { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.col { background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px; min-height: 90px; }
.col .cards { display: flex; flex-direction: column; gap: 5px; }
.card { background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 6px 7px; font-size: 11.5px; line-height: 1.35; }

/* 檔案 */
.files { flex: 1; overflow: hidden; display: flex; flex-direction: column; }
.filewrap { flex: 1; display: grid; grid-template-rows: auto 1fr; gap: 8px; overflow: hidden; }
.filelist { list-style: none; margin: 0; padding: 0; max-height: 110px; overflow-y: auto; display: flex; flex-direction: column; gap: 3px; }
.filelist li { font-size: 12.5px; padding: 4px 8px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px; cursor: pointer; }
.filelist li:hover { border-color: var(--accent); }
.fileview { flex: 1; overflow: auto; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 10px; font-size: 12px; color: #c9d1d9; margin: 0; }

/* 離線模式徽章 */
.badge-offline { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: #3a2d12; color: var(--warn); border: 1px solid #5a4a1f; white-space: nowrap; }
.badge-offline.hidden { display: none; }

/* Toast 通知 */
#toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 100; align-items: center; }
.toast { padding: 10px 16px; border-radius: 8px; font-size: 13px; color: var(--text); background: var(--panel-2); border: 1px solid var(--border); box-shadow: 0 6px 24px rgba(0,0,0,.45); animation: toastin .2s ease; }
.toast.err { border-color: var(--bad); color: #ffb4ae; }
.toast.ok { border-color: var(--good); }
@keyframes toastin { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; } }

/* 窄螢幕 / 手機版面 */
@media (max-width: 900px) {
  .topbar { flex-wrap: wrap; }
  .launch { order: 3; width: 100%; }
  .layout { grid-template-columns: 1fr; overflow: auto; }
  .experts, .discussion, .side { overflow: visible; }
  .stream { max-height: 50vh; }
  .history-panel { left: 12px; right: 12px; width: auto; }
}
