:root {
  --bg: #0d1117;
  --bg-2: #161b22;
  --bg-3: #1c2330;
  --panel: #11161f;
  --line: #232b38;
  --line-2: #2d3748;
  --text: #e6edf3;
  --muted: #8b97a7;
  --muted-2: #6b7686;
  --accent: #f0a500;
  --accent-2: #ffc94d;
  --blue: #4493f8;
  --green: #3fb950;
  --red: #f85149;
  --amber: #d29922;
  --radius: 14px;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

body {
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(240, 165, 0, 0.06), transparent),
    radial-gradient(900px 500px at 0% 0%, rgba(68, 147, 248, 0.05), transparent),
    var(--bg);
  min-height: 100vh;
}

/* ── topbar ── */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 28px;
  background: rgba(13, 17, 23, 0.82);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.brand-mark {
  font-size: 24px; width: 40px; height: 40px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), #b87900);
  color: #1a1205; border-radius: 11px; font-weight: 800;
  box-shadow: 0 4px 14px rgba(240, 165, 0, 0.3);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-size: 17px; letter-spacing: 0.2px; }
.brand-text span { font-size: 12px; color: var(--muted); }
.topnav { display: flex; align-items: center; gap: 6px; }
.nav-link {
  background: none; border: none; color: var(--muted);
  font: inherit; padding: 8px 14px; border-radius: 9px; cursor: pointer;
  transition: all 0.15s;
}
.nav-link:hover { color: var(--text); background: var(--bg-2); }
.nav-link.active { color: var(--accent-2); background: rgba(240, 165, 0, 0.1); }
.nav-link.ghost { border: 1px solid var(--line-2); }

main { max-width: 1080px; margin: 0 auto; padding: 32px 28px 80px; }

/* ── hero / build view ── */
.hero { text-align: center; margin: 24px 0 40px; }
.hero h1 { font-size: 34px; margin: 0 0 10px; letter-spacing: -0.5px; }
.hero h1 .hl { color: var(--accent-2); }
.hero p { color: var(--muted); max-width: 620px; margin: 0 auto; font-size: 16px; }

.section-label {
  display: flex; align-items: center; gap: 10px;
  font-size: 13px; text-transform: uppercase; letter-spacing: 1.2px;
  color: var(--muted-2); margin: 36px 0 16px; font-weight: 600;
}
.section-label .step {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent); color: #1a1205; display: grid; place-items: center;
  font-size: 12px; font-weight: 700;
}

/* ── template gallery ── */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.tmpl-card {
  text-align: left; cursor: pointer;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px; transition: all 0.18s;
  position: relative; overflow: hidden;
}
.tmpl-card:hover { border-color: var(--line-2); transform: translateY(-2px); }
.tmpl-card.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), 0 8px 24px rgba(240,165,0,.12); }
.tmpl-card .flag { position: absolute; top: 14px; right: 14px; font-size: 11px;
  background: rgba(240,165,0,.14); color: var(--accent-2); padding: 3px 8px; border-radius: 20px; }
.tmpl-card h3 { margin: 0 0 6px; font-size: 17px; }
.tmpl-card .desc { color: var(--muted); font-size: 13.5px; min-height: 40px; }
.tmpl-card .flow { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 12px; }
.chip {
  font-size: 11.5px; padding: 3px 9px; border-radius: 20px;
  background: var(--bg-3); color: var(--muted); border: 1px solid var(--line);
}
.chip.arrow { background: none; border: none; color: var(--muted-2); padding: 3px 1px; }
.tmpl-card .meta { display: flex; gap: 14px; margin-top: 12px; font-size: 12px; color: var(--muted-2); }

/* ── question + run controls ── */
.ask-panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px;
}
.ask-panel textarea {
  width: 100%; min-height: 90px; resize: vertical;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line-2); border-radius: 10px;
  padding: 14px; font: inherit; line-height: 1.5;
}
.ask-panel textarea:focus { outline: none; border-color: var(--accent); }
.examples { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.example-pill {
  font-size: 12.5px; padding: 5px 11px; border-radius: 20px; cursor: pointer;
  background: var(--bg-3); color: var(--muted); border: 1px solid var(--line);
}
.example-pill:hover { color: var(--text); border-color: var(--line-2); }

.run-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; margin-top: 18px; flex-wrap: wrap;
}
.tier-toggle { display: inline-flex; background: var(--bg); border: 1px solid var(--line-2); border-radius: 10px; padding: 3px; }
.tier-toggle button {
  background: none; border: none; color: var(--muted); font: inherit;
  padding: 7px 14px; border-radius: 8px; cursor: pointer; font-size: 13.5px;
}
.tier-toggle button.active { background: var(--accent); color: #1a1205; font-weight: 600; }
.tier-toggle button .sub { display: block; font-size: 10.5px; opacity: 0.8; font-weight: 400; }

.btn {
  font: inherit; cursor: pointer; border-radius: 10px; padding: 11px 20px;
  border: 1px solid var(--line-2); background: var(--bg-3); color: var(--text);
  transition: all 0.15s; font-weight: 500;
}
.btn:hover { border-color: var(--muted-2); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary {
  background: linear-gradient(135deg, var(--accent), #cf8c00); color: #1a1205;
  border: none; font-weight: 700; box-shadow: 0 4px 16px rgba(240,165,0,.25);
}
.btn.primary:hover:not(:disabled) { filter: brightness(1.07); }
.btn.ghost { background: none; }
.btn.lg { padding: 13px 26px; font-size: 15px; }
.icon-btn { background: none; border: none; color: var(--muted); font-size: 18px; cursor: pointer; }

.hint { font-size: 12.5px; color: var(--muted-2); }
.hint.warn { color: var(--amber); }

/* ── run / live view ── */
.run-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; flex-wrap: wrap; }
.run-head .topic { font-size: 21px; margin: 0 0 6px; max-width: 720px; }
.run-head .sub { color: var(--muted); font-size: 13.5px; }
.council-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 20px 0; }
.agent-chip {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 24px;
  padding: 6px 14px 6px 6px; font-size: 13px;
}
.agent-avatar {
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  font-size: 12px; font-weight: 700; color: #0d1117;
}
.agent-chip .role { color: var(--muted-2); font-size: 11px; }

.progress-track { height: 6px; background: var(--bg-3); border-radius: 4px; overflow: hidden; margin: 8px 0 20px; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); width: 0%; transition: width 0.5s ease; }

.event-log {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; max-height: 360px; overflow-y: auto; font-family: var(--mono); font-size: 13px;
}
.event-line { display: flex; gap: 12px; padding: 4px 0; color: var(--muted); animation: fade 0.4s; }
.event-line .ts { color: var(--muted-2); min-width: 46px; }
.event-line.latest { color: var(--text); }
.event-line .dot { color: var(--accent); }
@keyframes fade { from { opacity: 0; transform: translateX(-4px); } to { opacity: 1; } }

.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--line-2);
  border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite; vertical-align: -3px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── decision / result ── */
.verdict-card {
  background: linear-gradient(135deg, var(--bg-2), var(--panel));
  border: 1px solid var(--line); border-left: 4px solid var(--accent);
  border-radius: var(--radius); padding: 24px; margin-bottom: 22px;
}
.verdict-card .label { font-size: 12px; text-transform: uppercase; letter-spacing: 1.4px; color: var(--muted-2); }
.verdict-card .verdict { font-size: 22px; font-weight: 700; margin: 6px 0 16px; }
.stats { display: flex; flex-wrap: wrap; gap: 22px; }
.stat .k { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted-2); }
.stat .v { font-size: 20px; font-weight: 700; }
.conf-meter { width: 120px; height: 7px; background: var(--bg-3); border-radius: 4px; overflow: hidden; margin-top: 8px; }
.conf-fill { height: 100%; background: linear-gradient(90deg, var(--green), var(--accent-2)); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 20px; flex-wrap: wrap; }
.tab {
  background: none; border: none; color: var(--muted); font: inherit;
  padding: 11px 16px; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent-2); border-bottom-color: var(--accent); }
.tab .count { font-size: 11px; background: var(--bg-3); padding: 1px 7px; border-radius: 10px; margin-left: 6px; }

.markdown { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px 28px; }
.markdown h1 { font-size: 24px; margin: 0 0 16px; }
.markdown h2 { font-size: 17px; margin: 24px 0 10px; color: var(--accent-2); border-bottom: 1px solid var(--line); padding-bottom: 6px; }
.markdown h3 { font-size: 15px; margin: 18px 0 8px; }
.markdown ul { padding-left: 20px; }
.markdown li { margin: 6px 0; }
.markdown p { margin: 10px 0; }
.markdown code { background: var(--bg-3); padding: 1px 6px; border-radius: 5px; font-family: var(--mono); font-size: 13px; }
.markdown strong { color: var(--text); }
.cite { color: var(--blue); font-size: 12.5px; }

/* dissent / questions lists */
.list-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 20px; }
.list-item { padding: 14px 0; border-bottom: 1px solid var(--line); display: flex; gap: 12px; }
.list-item:last-child { border-bottom: none; }
.list-item .marker { color: var(--accent); flex-shrink: 0; }
.empty-state { text-align: center; color: var(--muted-2); padding: 48px 20px; }
.empty-state .big { font-size: 32px; margin-bottom: 10px; }

/* transcript */
.round-block { margin-bottom: 24px; }
.round-title { display: flex; align-items: center; gap: 10px; font-size: 14px; font-weight: 600; margin-bottom: 12px; color: var(--accent-2); }
.round-title .badge { font-size: 11px; background: var(--bg-3); color: var(--muted); padding: 2px 8px; border-radius: 6px; font-weight: 400; }
.turn {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px 16px; margin-bottom: 10px;
}
.turn-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.turn-head .name { font-weight: 600; }
.turn-head .model { font-size: 11.5px; color: var(--muted-2); font-family: var(--mono); }
.turn-body { color: var(--muted); font-size: 14px; white-space: pre-wrap; }
.turn.error { border-color: var(--red); }
.turn.error .turn-body { color: var(--red); }

/* details / raw */
.kv-grid { display: grid; grid-template-columns: 180px 1fr; gap: 8px 16px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.kv-grid .k { color: var(--muted-2); }
.kv-grid .v { font-family: var(--mono); font-size: 13px; }
pre.raw { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; overflow-x: auto; font-family: var(--mono); font-size: 12.5px; color: var(--muted); max-height: 520px; }

/* history */
.history-table { display: flex; flex-direction: column; gap: 8px; }
.history-row {
  display: grid; grid-template-columns: 1fr auto auto auto; gap: 16px; align-items: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px 18px; cursor: pointer; transition: all 0.15s;
}
.history-row:hover { border-color: var(--line-2); }
.history-row .topic { font-weight: 500; }
.history-row .sub { font-size: 12.5px; color: var(--muted-2); }
.badge-status { font-size: 11.5px; padding: 3px 10px; border-radius: 20px; }
.badge-status.completed { background: rgba(63,185,80,.14); color: var(--green); }
.badge-status.running { background: rgba(68,147,248,.14); color: var(--blue); }
.badge-status.failed { background: rgba(248,81,73,.14); color: var(--red); }

/* diagnostics */
.diag { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.diag:last-child { border: none; }
.diag .lvl { font-size: 11px; padding: 2px 8px; border-radius: 6px; height: fit-content; flex-shrink: 0; }
.diag .lvl.error { background: rgba(248,81,73,.16); color: var(--red); }
.diag .lvl.warning { background: rgba(210,153,34,.16); color: var(--amber); }
.diag .lvl.tip { background: rgba(68,147,248,.14); color: var(--blue); }

/* modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal-backdrop[hidden] { display: none; }
.modal { background: var(--bg-2); border: 1px solid var(--line-2); border-radius: var(--radius); padding: 24px; max-width: 480px; width: 100%; box-shadow: var(--shadow); }
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.modal-head h2 { margin: 0; font-size: 18px; }
.key-fields { display: flex; flex-direction: column; gap: 12px; margin: 18px 0; max-height: 50vh; overflow-y: auto; }
.key-field label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }
.key-field input { width: 100%; background: var(--bg); border: 1px solid var(--line-2); border-radius: 8px; padding: 9px 12px; color: var(--text); font-family: var(--mono); font-size: 13px; }
.key-field input:focus { outline: none; border-color: var(--accent); }
.key-field .present { color: var(--green); font-size: 11px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

.muted { color: var(--muted); }
.row { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.spaced { margin-top: 20px; }

/* toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--bg-3); border: 1px solid var(--line-2); color: var(--text);
  padding: 12px 20px; border-radius: 10px; box-shadow: var(--shadow); z-index: 60; font-size: 14px;
}
.toast.error { border-color: var(--red); }

/* editor */
.editor-grid { display: flex; flex-direction: column; gap: 14px; }
.edit-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.edit-card .eh { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.edit-card input[type=text], .edit-card textarea, .edit-card select {
  background: var(--bg); border: 1px solid var(--line-2); border-radius: 8px;
  padding: 8px 10px; color: var(--text); font: inherit; font-size: 13.5px; width: 100%;
}
.edit-card textarea { resize: vertical; min-height: 54px; }
.field { margin-bottom: 10px; }
.field label { display: block; font-size: 11.5px; color: var(--muted-2); margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.5px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

@media (max-width: 720px) {
  .field-row { grid-template-columns: 1fr; }
  .history-row { grid-template-columns: 1fr; gap: 6px; }
  main { padding: 24px 16px 60px; }
}
