:root {
  --bg: #f5f6f8;
  --bg-panel: #ffffff;
  --bg-card: #fafbfc;
  --border: #e3e6ea;
  --text: #23272e;
  --text-dim: #7a828e;
  --a: #2f6fed;
  --a-bg: #eef4ff;
  --b: #e07b2a;
  --b-bg: #fdf2e7;
  --j: #7c3aed;
  --j-bg: #f4efff;
  --danger: #dc3c36;
  --radius: 10px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.6;
}

/* ---------- Header ---------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel);
  position: sticky;
  top: 0;
  z-index: 10;
}
.logo { display: flex; align-items: center; gap: 8px; }
.logo-badge { font-size: 20px; }
.logo h1 { font-size: 17px; font-weight: 700; }
.logo .sub { color: var(--text-dim); font-weight: 400; font-size: 13px; }

/* ---------- Layout ---------- */
.app-main {
  max-width: 980px;
  margin: 0 auto;
  padding: 16px 16px 50px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 12px;
}
.panel-head h2 { font-size: 15px; }
.hint { color: var(--text-dim); font-size: 12px; }
.sync-state { color: var(--text-dim); font-size: 11px; margin-left: 4px; }
.sync-state.synced { color: #2e9e5b; }
.sync-state.failed { color: var(--danger); }
.sync-state.syncing { color: var(--text-dim); }

/* ---------- Buttons ---------- */
.btn {
  border: 1px solid var(--border);
  background: var(--bg-panel);
  color: var(--text);
  padding: 7px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  transition: all .15s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn:hover:not(:disabled) { border-color: #c6ccd4; background: #f0f2f5; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--a); border-color: var(--a); color: #fff; font-weight: 600; }
.btn-primary:hover:not(:disabled) { background: #275fd4; border-color: #275fd4; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-ghost { background: transparent; }

/* ---------- Config ---------- */
.config-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.player-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.card-a { border-top: 3px solid var(--a); }
.card-b { border-top: 3px solid var(--b); }
.card-j { border-top: 3px solid var(--j); grid-column: 1 / -1; }
.player-card h3 { font-size: 14px; margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.player-card h3 .hint { font-size: 11px; font-weight: 400; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot-a { background: var(--a); }
.dot-b { background: var(--b); }
.dot-j { background: var(--j); }
.judge-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }

label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-dim); margin-bottom: 10px; }
input, textarea {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 13px;
  font-family: inherit;
  resize: vertical;
}
input:focus, textarea:focus { outline: 1px solid var(--a); }

.debate-config { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 12px; }
.debate-config h3 { font-size: 13px; color: var(--text-dim); margin-bottom: 10px; }
.config-row { display: flex; gap: 12px; flex-wrap: wrap; }
.config-row label { flex: 0 0 auto; min-width: 110px; }
.config-row label.grow { flex: 1 1 200px; }
.config-row label.wide { flex: 1 1 100%; }

/* ---------- Quick bar (首页快捷设置) ---------- */
.quick-bar { display: flex; flex-direction: column; gap: 8px; }
.quick-row { display: flex; gap: 12px; flex-wrap: wrap; }
.quick-row label { flex: 1 1 200px; }
.quick-row label.wide { flex: 1 1 100%; }
.quick-bar .hint { font-size: 12px; color: var(--text-dim); }
.quick-bar .hint a { color: var(--a); }

/* ---------- Stage ---------- */
.stage-panel { padding: 0; overflow: hidden; }
.stage-status {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
}
.status-idle::before { content: "·"; margin-right: 4px; }
.status-idle a { color: var(--a); }
.status-thinking::before {
  content: "";
  width: 12px; height: 12px;
  border: 2px solid var(--border);
  border-top-color: var(--text);
  border-radius: 50%;
  display: inline-block;
  animation: spin .8s linear infinite;
}
.status-paused::before {
  content: "⏸";
  margin-right: 4px;
  font-size: 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Resume bar ---------- */
.resume-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-color: #f0c36d;
  background: #fffaf0;
}
.resume-info { flex: 1; color: #8a6d1a; font-size: 13px; }

/* ---------- History ---------- */
.history-list { display: flex; flex-direction: column; gap: 8px; max-height: 62vh; overflow-y: auto; }
.history-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  cursor: pointer;
  transition: border-color .15s;
}
.history-item:hover { border-color: var(--a); }
.history-item-head { display: flex; align-items: center; gap: 10px; }
.history-item-topic { font-weight: 600; flex: 1; }
.history-item-judge { font-size: 12px; color: var(--a); }
.history-item-status { font-size: 12px; color: var(--text-dim); border: 1px solid var(--border); border-radius: 10px; padding: 1px 8px; }
.history-item-sub { font-size: 12px; color: var(--text-dim); margin-top: 4px; }

.chat {
  padding: 16px;
  max-height: 62vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: auto;
}

/* ---------- Bubbles ---------- */
.msg { display: flex; flex-direction: column; max-width: 86%; }
.msg .meta { display: flex; align-items: baseline; gap: 8px; margin-bottom: 4px; font-size: 12px; }
.msg .name { font-weight: 700; }
.msg .round-tag { color: var(--text-dim); font-size: 11px; }
.msg .token-tag { color: var(--text-dim); font-size: 11px; background: rgba(0,0,0,.05); border-radius: 4px; padding: 1px 5px; }
.msg-speak-btn {
  margin-left: auto;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 13px;
  padding: 2px 6px;
  border-radius: 6px;
  color: var(--text-dim);
  line-height: 1;
}
.msg-speak-btn:hover { background: rgba(0,0,0,.06); color: var(--text); }
.msg.speaking .msg-speak-btn { color: var(--a); background: rgba(47,111,237,.1); }
.msg .bubble {
  padding: 10px 14px;
  border-radius: var(--radius);
  word-break: break-word;
  border: 1px solid var(--border);
}
.msg.system .bubble {
  background: var(--bg-card);
  color: var(--text-dim);
  border-color: var(--border);
  font-style: italic;
  font-size: 12px;
}
.msg.a { align-self: flex-start; }
.msg.a .bubble { background: var(--a-bg); border-color: #cfe0ff; }
.msg.a .name { color: var(--a); }
.msg.b { align-self: flex-end; }
.msg.b .bubble { background: var(--b-bg); border-color: #fbe0c2; }
.msg.b .name { color: var(--b); }
.msg.me { align-self: center; }
.msg.me .bubble { background: var(--bg-card); border: 1px dashed var(--border); }
.msg.me .name { color: var(--text-dim); }

.msg.speaking .bubble {
  box-shadow: 0 0 0 2px var(--a), 0 2px 10px rgba(0,0,0,.15);
  transform: scale(1.015);
}
.msg.speaking .name::after {
  content: " 🔊";
  font-size: 12px;
}

.msg .bubble.streaming::after {
  content: "▍";
  color: var(--text-dim);
  animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.placeholder-msg {
  color: var(--text-dim);
  text-align: center;
  padding: 40px 0;
  font-size: 13px;
}

/* ---------- Markdown inside bubbles ---------- */
.bubble > :first-child { margin-top: 0; }
.bubble > :last-child { margin-bottom: 0; }
.bubble p { margin: 4px 0; }
.bubble h1, .bubble h2, .bubble h3, .bubble h4, .bubble h5, .bubble h6 {
  margin: 10px 0 6px;
  line-height: 1.35;
}
.bubble h1 { font-size: 17px; }
.bubble h2 { font-size: 16px; }
.bubble h3 { font-size: 15px; }
.bubble h4, .bubble h5, .bubble h6 { font-size: 14px; }
.bubble ul, .bubble ol { margin: 6px 0; padding-left: 22px; }
.bubble li { margin: 2px 0; }
.bubble blockquote {
  margin: 6px 0;
  padding: 2px 12px;
  border-left: 3px solid var(--border);
  color: var(--text-dim);
}
.bubble code {
  font-family: Consolas, Monaco, "Courier New", monospace;
  font-size: 12px;
  background: rgba(0, 0, 0, .06);
  border-radius: 4px;
  padding: 1px 5px;
}
.bubble pre {
  margin: 8px 0;
  background: rgba(0, 0, 0, .06);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  overflow-x: auto;
}
.bubble pre code { background: none; padding: 0; font-size: 12px; }
.bubble hr { border: none; border-top: 1px solid var(--border); margin: 10px 0; }
.bubble a { color: var(--a); }

/* ---------- Controls ---------- */
.controls {
  display: flex;
  gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
  align-items: center;
}
.rate-label {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
}
.rate-label select {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  color: var(--text);
  font-size: 13px;
}

/* ---------- AI Judge ---------- */
.msg.judge { align-self: flex-start; max-width: 100%; }
.msg.judge .bubble { background: var(--j-bg); border-color: #ddd0f9; }
.msg.judge .name { color: var(--j); }
.judge-chat { max-height: 40vh; }
.judge-result {
  margin: 0 16px 16px;
  padding: 12px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--j);
  background: var(--j-bg);
  font-size: 14px;
  font-weight: 600;
  color: var(--j);
}
.judge-result .verdict-side { color: var(--text); }
.judge-result.j-a { border-color: var(--a); color: var(--a); }
.judge-result.j-b { border-color: var(--b); color: var(--b); }
.judge-result.j-draw { border-color: var(--text-dim); color: var(--text-dim); }
.judge-result .judge-note { display: block; margin-top: 6px; font-size: 12px; font-weight: 400; color: var(--text-dim); }
.judge-result .judge-raw {
  display: block;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--j);
  font-size: 13px;
  font-weight: 400;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---------- Misc ---------- */
.hidden { display: none !important; }
.toast {
  position: fixed;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  background: #333;
  color: #fff;
  font-size: 13px;
  padding: 10px 18px;
  border-radius: 8px;
  z-index: 100;
  max-width: 86vw;
  box-shadow: 0 4px 16px rgba(0,0,0,.25);
}
.toast.show { animation: toastIn .2s ease; }
@keyframes toastIn { from { opacity: 0; transform: translateX(-50%) translateY(-6px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }
.app-footer {
  text-align: center;
  color: var(--text-dim);
  font-size: 12px;
  padding: 20px 0 30px;
}

/* ---------- 补充想法继续讨论 ---------- */
.continue-zone {
  margin-top: 14px;
  padding: 14px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.continue-head { display: flex; align-items: baseline; gap: 8px; }
.continue-title { font-weight: 700; }
.continue-zone textarea {
  width: 100%;
  box-sizing: border-box;
  resize: vertical;
}
.continue-zone .controls { justify-content: flex-end; }

/* ---------- 底部固定 Token 栏 ---------- */
.token-bar {
  display: inline-block;
  margin-right: 10px;
  font-weight: 600;
  color: var(--text);
  background: rgba(47,111,237,.08);
  border: 1px solid #cfe0ff;
  border-radius: 999px;
  padding: 2px 12px;
  cursor: help;
}

/* ---------- Responsive ---------- */
@media (max-width: 720px) {
  .config-grid { grid-template-columns: 1fr; }
  .judge-grid { grid-template-columns: 1fr; }
  .msg { max-width: 94%; }
  .app-header { padding: 8px 12px; }
  .logo h1 { font-size: 15px; }
  .logo .sub { display: none; }
  .app-main { padding: 10px 10px 40px; gap: 10px; }
  .panel { padding: 12px; }
  .controls { padding: 10px; gap: 8px; }
  .btn { flex: 1 1 auto; padding: 8px 10px; }
  .config-row label { min-width: 100%; }
  .config-row label.grow { flex: 1 1 100%; }
}

@media (max-width: 480px) {
  .chat { padding: 12px; gap: 10px; }
  .msg { max-width: 100%; }
  .resume-bar { flex-wrap: wrap; padding: 10px 12px; gap: 8px; }
  .resume-bar .btn { flex: 1 1 100%; }
  .history-item-head { flex-wrap: wrap; gap: 6px; }
  .stage-status { padding: 8px 12px; font-size: 12px; }
  .panel-head h2 { font-size: 14px; }
  .panel-head { flex-wrap: wrap; gap: 8px; }
  input, textarea { padding: 10px 12px; font-size: 16px; }
  .btn { padding: 10px 12px; font-size: 14px; min-height: 42px; }
  .app-header .btn { flex: 0 0 auto; min-height: 36px; padding: 6px 10px; }
  .player-card { padding: 12px 10px; }
  label { margin-bottom: 12px; }
  .logo-badge { font-size: 18px; }
}
