/* 证明自动机 —— 深色学术风 */
:root {
  --bg: #0d0f13;
  --bg-glow: #151922;
  --card: #141820;
  --card-hi: #181d27;
  --line: #242a36;
  --line-soft: #1a1f29;
  --text: #e8eaee;
  --text-dim: #9ba3b0;
  --text-faint: #69717e;
  --gold: #d6a756;
  --gold-dim: rgba(214, 167, 86, 0.14);
  --gold-line: rgba(214, 167, 86, 0.32);
  --green: #6ecf9a;
  --red: #e06c6c;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background:
    radial-gradient(1200px 520px at 50% -220px, var(--bg-glow) 0%, transparent 70%),
    var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.72;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* ---------------- 顶栏 ---------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line-soft);
  background: rgba(13, 15, 19, 0.82);
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--gold-line);
  border-radius: 9px;
  color: var(--gold);
  font-family: "Cambria Math", "STIX Two Math", "Segoe UI Symbol", serif;
  font-size: 20px;
  line-height: 1;
  background: var(--gold-dim);
  flex: none;
}

.brand-text h1 {
  margin: 0;
  font-size: 15.5px;
  font-weight: 650;
  letter-spacing: 0.06em;
}

.brand-text p {
  margin: 1px 0 0;
  font-size: 11.5px;
  color: var(--text-faint);
  letter-spacing: 0.04em;
}

.top-actions {
  display: flex;
  gap: 8px;
  flex: none;
}

button.ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text-dim);
  font-family: inherit;
  font-size: 12.5px;
  padding: 6px 13px;
  border-radius: 8px;
  cursor: pointer;
  transition: border-color .18s, color .18s, background .18s;
}
button.ghost:hover {
  border-color: var(--gold-line);
  color: var(--gold);
  background: var(--gold-dim);
}

/* ---------------- 消息流 ---------------- */
.stream {
  flex: 1;
  width: 100%;
  max-width: 860px;
  margin: 0 auto;
  padding: 30px 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 15px;
}

/* 开场语 */
.welcome {
  padding: 26px 26px 24px;
  position: relative;
  overflow: hidden;
}
.welcome::after {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold-line), transparent);
}
.kicker {
  margin: 0 0 12px;
  font-size: 10.5px;
  letter-spacing: 0.22em;
  color: var(--gold);
  text-transform: uppercase;
}
.welcome h2 {
  margin: 0 0 10px;
  font-size: 22px;
  font-weight: 650;
  letter-spacing: 0.02em;
}
.welcome .lead {
  margin: 0 0 8px;
  font-size: 15.5px;
  color: var(--text);
}
.welcome .body-text {
  margin: 0;
  color: var(--text-dim);
}
.starters {
  display: grid;
  gap: 8px;
  margin: 20px 0 18px;
}
.starter {
  display: grid;
  grid-template-columns: 132px 1fr;
  gap: 12px;
  align-items: baseline;
  padding: 9px 13px;
  border: 1px solid var(--line-soft);
  border-left: 2px solid var(--gold-line);
  border-radius: 9px;
  background: var(--card-hi);
  font-size: 13.5px;
}
.starter-k { color: var(--text); font-weight: 600; }
.starter-v { color: var(--text-dim); }
.welcome .note {
  margin: 0;
  padding-top: 16px;
  border-top: 1px dashed var(--line);
  font-size: 12.5px;
  color: var(--text-faint);
  line-height: 1.85;
}

/* 消息 */
.msg {
  display: flex;
  flex-direction: column;
  gap: 8px;
  animation: fade .28s ease both;
}
@keyframes fade {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: none; }
}

.msg-user { align-items: flex-end; }
.msg-user .bubble {
  max-width: 84%;
  padding: 10px 15px;
  border-radius: 13px 13px 3px 13px;
  background: var(--gold-dim);
  border: 1px solid var(--gold-line);
  white-space: pre-wrap;
  word-break: break-word;
}

.msg-assistant { align-items: stretch; }
.msg-assistant .who {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11.5px;
  letter-spacing: 0.1em;
  color: var(--text-faint);
}
.msg-assistant .who .dot {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 8px var(--gold);
}
.msg-assistant .body {
  padding-left: 14px;
  border-left: 2px solid var(--line);
  word-break: break-word;
}
.msg-assistant .body.streaming {
  border-left-color: var(--gold-line);
}

/* Markdown */
.body p { margin: 0 0 11px; }
.body p:last-child { margin-bottom: 0; }
.body h1, .body h2, .body h3 {
  margin: 20px 0 9px;
  font-weight: 650;
  line-height: 1.45;
}
.body h1 { font-size: 18px; }
.body h2 { font-size: 16.5px; }
.body h3 { font-size: 15px; }
.body ul, .body ol { margin: 0 0 11px; padding-left: 22px; }
.body li { margin: 3px 0; }
.body strong { color: #fff; font-weight: 620; }
.body em { color: var(--text-dim); }
.body code {
  font-family: var(--mono);
  font-size: 0.9em;
  padding: 1.5px 5px;
  border-radius: 5px;
  background: #1d222c;
  border: 1px solid var(--line-soft);
  color: #d9c3a0;
}
.body pre {
  margin: 0 0 12px;
  padding: 13px 15px;
  border-radius: 10px;
  background: #10141b;
  border: 1px solid var(--line);
  overflow-x: auto;
}
.body pre code {
  padding: 0;
  border: 0;
  background: transparent;
  color: #cfd6e2;
  font-size: 12.8px;
  line-height: 1.65;
}
.body blockquote {
  margin: 0 0 12px;
  padding: 4px 0 4px 14px;
  border-left: 2px solid var(--gold-line);
  color: var(--text-dim);
}
.body hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 18px 0;
}

/* 公式 */
.katex { font-size: 1.02em; }
.katex-display {
  margin: 13px 0 !important;
  padding: 6px 0;
  overflow-x: auto;
  overflow-y: hidden;
}

/* 工具卡片 */
.tool-card {
  margin: 6px 0 10px;
  padding: 8px 12px;
  border: 1px solid var(--line-soft);
  border-radius: 9px;
  background: #10141b;
  font-size: 12px;
  font-family: var(--mono);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: baseline;
  color: var(--text-dim);
}
.tool-card .tool-tag {
  color: var(--gold);
  letter-spacing: 0.05em;
  flex: none;
}
.tool-card .tool-name {
  color: #cfd6e2;
  flex: none;
}
.tool-card .tool-args {
  color: var(--text-faint);
  word-break: break-all;
  flex: 1 1 200px;
  min-width: 0;
}
.tool-card .tool-out {
  flex: 1 1 100%;
  color: var(--green);
  word-break: break-all;
  white-space: pre-wrap;
}
.tool-card.is-error .tool-out { color: var(--red); }
.tool-card .spinner {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  border: 1.5px solid var(--gold);
  border-top-color: transparent;
  animation: spin .7s linear infinite;
  margin-left: 2px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* 评分卡 */
.scorecard {
  margin-top: 4px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: linear-gradient(180deg, var(--card-hi), var(--card));
  max-width: 520px;
}
.score-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 11px;
  font-size: 12px;
  letter-spacing: 0.12em;
  color: var(--text-dim);
}
.score-head .badge {
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--gold);
  border: 1px solid var(--gold-line);
  border-radius: 20px;
  padding: 1px 8px;
}
.score-row {
  display: grid;
  grid-template-columns: 88px 1fr 20px;
  gap: 10px;
  align-items: center;
  margin: 7px 0;
  font-size: 12.5px;
}
.score-row .label { color: var(--text-dim); }
.score-row .bar {
  height: 5px;
  border-radius: 3px;
  background: #1c212b;
  overflow: hidden;
}
.score-row .bar i {
  display: block;
  height: 100%;
  border-radius: 3px;
  background: linear-gradient(90deg, #a97f38, var(--gold));
  transition: width .5s cubic-bezier(.2,.7,.3,1);
}
.score-row .num {
  text-align: right;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--gold);
}
.score-note {
  margin: 10px 0 0;
  padding-top: 9px;
  border-top: 1px dashed var(--line);
  font-size: 12.5px;
  color: var(--text-dim);
  line-height: 1.6;
}
.score-note strong,
.score-note b {
  color: var(--text);
  font-weight: 600;
}

/* 提示条 */
.notice {
  font-size: 12px;
  color: var(--text-faint);
  padding: 5px 11px;
  border: 1px dashed var(--line);
  border-radius: 7px;
  align-self: flex-start;
}

.err {
  color: var(--red);
  font-size: 13px;
  padding: 9px 13px;
  border: 1px solid rgba(224,108,108,.3);
  background: rgba(224,108,108,.07);
  border-radius: 9px;
}

/* 输入区 */
.composer {
  position: sticky;
  bottom: 0;
  padding: 12px 22px calc(14px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, transparent, var(--bg) 42%);
}
.composer-box {
  max-width: 816px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 9px;
  padding: 9px 9px 9px 15px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  transition: border-color .2s, box-shadow .2s;
}
.composer-box:focus-within {
  border-color: var(--gold-line);
  box-shadow: 0 0 0 3px var(--gold-dim);
}
#input {
  flex: 1;
  resize: none;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  line-height: 1.6;
  max-height: 220px;
  padding: 5px 0;
}
#input::placeholder { color: var(--text-faint); }
button.send {
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--gold-line);
  background: var(--gold-dim);
  color: var(--gold);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background .18s, opacity .18s;
}
button.send:hover:not(:disabled) { background: rgba(214,167,86,.24); }
button.send:disabled { opacity: .38; cursor: not-allowed; }
.composer-hint {
  max-width: 816px;
  margin: 7px auto 0;
  font-size: 11px;
  color: var(--text-faint);
  text-align: center;
  letter-spacing: 0.02em;
}
.composer-hint code {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--text-dim);
}

/* 角色设定模态框 */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(6, 8, 11, 0.72);
  backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
  padding: 24px;
}
.modal[hidden] { display: none; }
.modal-panel {
  position: relative;
  width: min(660px, 100%);
  max-height: 86vh;
  overflow-y: auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px 30px 30px;
  box-shadow: 0 24px 70px rgba(0,0,0,.55);
}
.modal-close {
  position: absolute;
  top: 14px;
  right: 16px;
  width: 30px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--text-dim);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
}
.modal-close:hover { color: var(--gold); border-color: var(--gold-line); }

.role-content { font-size: 13.8px; }
.role-title {
  margin: 0 0 4px;
  font-size: 21px;
  font-weight: 650;
  letter-spacing: 0.03em;
}
.role-sub {
  margin: 0 0 20px;
  font-size: 12px;
  color: var(--gold);
  letter-spacing: 0.14em;
}
.role-block { margin: 0 0 19px; }
.role-block h3 {
  margin: 0 0 7px;
  font-size: 11px;
  letter-spacing: 0.18em;
  color: var(--text-faint);
  font-weight: 600;
  text-transform: uppercase;
}
.role-block p { margin: 0; color: var(--text); line-height: 1.78; }
.role-block ol, .role-block ul { margin: 0; padding-left: 20px; color: var(--text); }
.role-block li { margin: 5px 0; line-height: 1.72; }
.role-block li b { color: var(--gold); font-weight: 600; }
.role-quote {
  margin: 0;
  padding: 13px 16px;
  border-radius: 10px;
  background: var(--card-hi);
  border: 1px solid var(--line-soft);
  border-left: 2px solid var(--gold);
  white-space: pre-wrap;
  font-size: 13px;
  line-height: 1.85;
  color: var(--text-dim);
}
.loading { color: var(--text-faint); font-size: 13px; }

@media (max-width: 620px) {
  .topbar { padding: 11px 14px; }
  .brand-text p { display: none; }
  .stream { padding: 20px 14px 14px; }
  .welcome { padding: 20px 18px; }
  .welcome h2 { font-size: 19px; }
  .starter { grid-template-columns: 1fr; gap: 2px; }
  .composer { padding: 10px 14px calc(12px + env(safe-area-inset-bottom)); }
  .modal-panel { padding: 24px 20px; }
  .msg-user .bubble { max-width: 100%; }
}
