/* NeuroSoul G1 评委演示 · 样式
   只用 flex / grid / 自定义属性，不依赖任何构建工具与新语法。
   Safari 不支持动画时自动退化为静态，不影响对话。 */

:root {
  --bg: #0d1117;
  --bg-soft: #161b22;
  --panel: #161b22;
  --line: #30363d;
  --text: #e6edf3;
  --text-dim: #8b949e;
  --accent: #58a6ff;
  --accent-2: #7ee787;
  --warn: #d29922;
  --bad: #f85149;
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Noto Sans SC", "Source Han Sans SC", sans-serif;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f8fa;
    --bg-soft: #ffffff;
    --panel: #ffffff;
    --line: #d0d7de;
    --text: #1f2328;
    --text-dim: #59636e;
    --accent: #0969da;
    --accent-2: #1a7f37;
    --warn: #9a6700;
    --bad: #cf222e;
  }
}

* { box-sizing: border-box; }

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

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3 { margin: 0; font-weight: 600; }
h2 { font-size: 15px; }
h3 { font-size: 13px; color: var(--text-dim); font-weight: 600; letter-spacing: .02em; }
p { margin: 0; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.tiny { font-size: 12px; color: var(--text-dim); font-weight: 400; }

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-soft);
  position: sticky;
  top: 0;
  z-index: 10;
}

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

.logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px; height: 30px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  flex: 0 0 auto;
}

.brand-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.brand-text strong { font-size: 15px; white-space: nowrap; }
.brand-text .sub { font-size: 11px; color: var(--text-dim); white-space: nowrap; }

.ver {
  font-size: 11px;
  color: var(--text-dim);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 8px;
}

.status { display: flex; flex-wrap: wrap; gap: 6px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  padding: 3px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text-dim);
  background: transparent;
  white-space: nowrap;
}

.chip .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-dim); flex: 0 0 auto;
}

.chip[data-state="ok"] { color: var(--accent-2); border-color: rgba(126, 231, 135, .45); }
.chip[data-state="ok"] .dot { background: var(--accent-2); }
.chip[data-state="warn"] { color: var(--warn); }
.chip[data-state="warn"] .dot { background: var(--warn); }
.chip[data-state="bad"] { color: var(--bad); }
.chip[data-state="bad"] .dot { background: var(--bad); }

/* ---------- 主布局 ---------- */
.layout {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 14px;
  padding: 14px 16px;
  min-height: 0;
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
}

.panel {
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  min-height: 0;
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}

/* ---------- 对话 ---------- */
.bubbles {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 220px;
  -webkit-overflow-scrolling: touch;
}

.bubble {
  max-width: min(85%, 640px);
  padding: 9px 13px;
  border-radius: 14px;
  word-break: break-word;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  border: 1px solid transparent;
}

.bubble.sys {
  max-width: 100%;
  background: transparent;
  border-color: var(--line);
  color: var(--text-dim);
  font-size: 13px;
}

.bubble.user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 5px;
}

.bubble.bot {
  align-self: flex-start;
  background: var(--bg);
  border-color: var(--line);
  border-bottom-left-radius: 5px;
}

.bubble .meta {
  display: block;
  margin-top: 5px;
  font-size: 11px;
  opacity: .75;
}

.bubble.pending { opacity: .6; }

.composer {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  flex: 0 0 auto;
}

textarea#input {
  flex: 1 1 auto;
  min-height: 40px;
  max-height: 120px;
  resize: none;
  padding: 9px 11px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  line-height: 1.45;
}

textarea#input:focus,
input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

button {
  font: inherit;
  cursor: pointer;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  padding: 9px 14px;
}

button:disabled { opacity: .5; cursor: not-allowed; }

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

button.wide { width: 100%; margin-top: 10px; }

.linkbtn {
  border: 0;
  background: transparent;
  color: var(--text-dim);
  font-size: 12px;
  padding: 2px 4px;
  text-decoration: underline;
}

.hint {
  margin: 0;
  padding: 6px 14px 10px;
  font-size: 12px;
  color: var(--warn);
  border-top: 1px dashed var(--line);
}

.hint .act {
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
  border: 0;
  background: none;
  padding: 0 4px;
  font: inherit;
}

/* ---------- 参数面板 ---------- */
.params-panel { overflow-y: auto; }

.param-block {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.param-block:last-child { border-bottom: 0; }

.vec { display: flex; flex-direction: column; gap: 6px; }

.vec-row {
  display: grid;
  grid-template-columns: 54px 1fr 58px;
  gap: 8px;
  align-items: center;
  font-size: 12px;
}

.vec-row .name { color: var(--text-dim); }

.vec-bar {
  position: relative;
  height: 8px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
}

.vec-fill {
  position: absolute;
  top: 0; bottom: 0;
  left: 50%;
  width: 0%;
  background: var(--accent);
  transform: translateX(-50%);
  transition: width .35s ease, left .35s ease;
}

.vec-fill.neg { background: var(--bad); }

.vec-row b { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

.spark-wrap { display: flex; flex-direction: column; gap: 4px; }

.spark {
  width: 100%;
  height: 48px;
  display: block;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.spark polyline {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}

.spark line.mid { stroke: var(--line); stroke-width: 1; }

.kv { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; }
.kv.tight { gap: 4px 10px; }
.kv > div { display: flex; justify-content: space-between; gap: 6px; font-size: 12px; }
.kv span { color: var(--text-dim); }
.kv b { font-variant-numeric: tabular-nums; font-weight: 600; }

.gate {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
}

.gate-badge {
  font-size: 12px;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--text-dim);
  white-space: nowrap;
}

.gate[data-state="pass"] .gate-badge { color: var(--accent-2); border-color: currentColor; }
.gate[data-state="block"] .gate-badge { color: var(--bad); border-color: currentColor; }
.gate[data-state="sanitized"] .gate-badge { color: var(--warn); border-color: currentColor; }

.gate-meta { display: flex; flex-direction: column; min-width: 0; font-size: 12px; }

.memlist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }

.memlist li {
  font-size: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  background: var(--bg);
  word-break: break-word;
}

.memlist li.empty { color: var(--text-dim); border-style: dashed; }
.memlist .m-top { display: flex; justify-content: space-between; gap: 8px; color: var(--text-dim); }
.memlist .m-sum { display: block; margin-top: 2px; }

/* 参数变化高亮：不支持动画也能看见（直接变成强调色） */
.flash { animation: flash .9s ease-out 1; }
@keyframes flash {
  0% { background-color: rgba(88, 166, 255, .28); }
  100% { background-color: transparent; }
}

/* ---------- 演练 ---------- */
.presets {
  border-top: 1px solid var(--line);
  background: var(--bg-soft);
  padding: 10px 16px 14px;
  flex: 0 0 auto;
}

.presets-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 8px;
  max-width: 1400px;
  margin-left: auto;
  margin-right: auto;
}

.preset-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  max-width: 1400px;
  margin: 0 auto;
}

.preset {
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 9px 11px;
  background: var(--panel);
  border-radius: 10px;
  min-height: 62px;
}

.preset strong { font-size: 13px; }
.preset span { font-size: 11px; color: var(--text-dim); line-height: 1.35; }
.preset[aria-busy="true"] { border-color: var(--accent); }

/* ---------- 弹窗 ---------- */
.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(2, 6, 12, .62);
  z-index: 50;
}

.modal[hidden] { display: none; }

.modal-card {
  width: 100%;
  max-width: 420px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.modal-card input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

.err { color: var(--bad); font-size: 12px; }

/* ---------- 响应式 ---------- */
@media (max-width: 1000px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(320px, 1fr) auto;
  }
  .params-panel { max-height: none; }
  .preset-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 600px) {
  body { font-size: 14px; }
  .topbar { padding: 8px 10px; }
  .layout { padding: 10px; gap: 10px; }
  .bubble { max-width: 92%; }
  .preset-row { grid-template-columns: 1fr; }
  .presets { padding: 8px 10px 12px; }
  .status { width: 100%; }
  .kv { grid-template-columns: 1fr; }
}

/* 减少动效偏好 / 不支持动画 → 静态 */
@media (prefers-reduced-motion: reduce) {
  .vec-fill { transition: none; }
  .flash { animation: none; }
}
