* { box-sizing: border-box; }
body { margin: 0; font-family: var(--font); background: var(--bg); color: var(--text); }
h1, h2, h3, h4 { font-weight: 600; }

/* ---------- 顶栏 + 图标按钮 ---------- */
.topbar { display: flex; align-items: center; gap: 12px; padding: 12px 18px; background: var(--card); border-bottom: 1px solid var(--border); }
.topbar h1 { font-size: 16px; margin: 0; flex: 1; }
.top-actions { display: flex; gap: 8px; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border: none; border-radius: 10px;
  background: var(--primary-soft); color: var(--primary); cursor: pointer;
}
.icon-btn:hover { background: #d7e6fb; }
.icon-btn.sm { width: 30px; height: 30px; border-radius: 8px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: none; background: var(--primary); color: #fff; padding: 8px 14px; border-radius: 10px; font-size: 14px; cursor: pointer; }
.btn .ic { flex: 0 0 auto; }
.btn.ghost { background: var(--primary-soft); color: var(--primary); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- 布局 ---------- */
.layout { display: grid; grid-template-columns: 1fr 320px; gap: 16px; padding: 16px; max-width: 1100px; margin: 0 auto; }
@media (max-width: 820px) { .layout { grid-template-columns: 1fr; } }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.chat-card { display: flex; flex-direction: column; }

/* ---------- 场景卡（背景图 + 渐变遮罩 + 标题 + 描述） ---------- */
.sceneWrap {
  position: relative; min-height: 150px; padding: 18px; border-radius: 12px;
  background: linear-gradient(135deg, #1a73e8 0%, #4f8df9 100%);
  background-size: cover; background-position: center; background-repeat: no-repeat;
  color: #fff; margin-bottom: 12px; overflow: hidden;
}
.sceneWrap::before {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(to bottom, rgba(0,0,0,.45) 0%, rgba(0,0,0,.12) 42%, rgba(0,0,0,.55) 100%);
}
.sceneWrap > * { position: relative; z-index: 1; }
.scenarioTitleTag { display: inline-block; color: #fff; font-weight: 700; font-size: 18px; text-shadow: 0 1px 3px rgba(0,0,0,.6); }
.sceneDesc { margin: 8px 0 0; line-height: 1.65; font-size: 14px; text-shadow: 0 1px 2px rgba(0,0,0,.5); }

/* ---------- 当前任务条 ---------- */
.taskBar { background: var(--primary-soft); border: 1px solid #d7e6fb; border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; }
.taskBar-head { display: flex; align-items: center; gap: 6px; }
.taskBar-label { font-weight: 700; color: var(--primary); font-size: 13px; }
.taskBar-idx { font-size: 12px; color: var(--muted); }
.taskBar-toggle { margin-left: auto; border: none; background: none; color: var(--primary); font-size: 12px; cursor: pointer; }
.taskBar-text { margin-top: 4px; font-size: 14px; color: #234; font-weight: 600; }

/* ---------- 气泡 ---------- */
.chat { min-height: 320px; max-height: 56vh; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; padding-right: 4px; }
.row { display: flex; gap: 8px; align-items: center; }
.row.user { flex-direction: row-reverse; }
.bubble { max-width: 78%; padding: 10px 14px; border-radius: 14px; line-height: 1.55; font-size: 15px; white-space: pre-wrap; }
.row.ai .bubble { background: var(--bubble-ai); border-top-left-radius: 4px; }
.row.user .bubble { background: var(--bubble-user); border-top-right-radius: 4px; }
.row.sys .bubble { background: #fff4e5; color: #8a5a00; font-size: 13px; align-self: center; }
.row.warn .bubble { background: #fdecea; color: #b71c1c; font-size: 13px; align-self: center; border-left: 4px solid var(--danger); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
/* 现场状况：特殊楷体 + 琥珀色框（与蓝色“当前任务”提示区分） */
.row.scene { justify-content: center; }
.row.scene .bubble { width: 100%; max-width: 100%; background: linear-gradient(135deg, #fff8e6 0%, #fdecbf 100%); border: 1px solid #ecd9a0; border-left: 4px solid #e0a020; border-radius: 12px; color: #5c4410; font-family: "Kaiti SC", "STKaiti", "楷体", "KaiTi", "Noto Serif SC", serif; font-size: 14.5px; line-height: 1.7; box-shadow: 0 1px 6px rgba(224,160,32,.12); white-space: nowrap; overflow-x: auto; }
.row.scene .bubble::-webkit-scrollbar { height: 5px; }
.row.scene .bubble::-webkit-scrollbar-thumb { background: #e0c98a; border-radius: 3px; }
.bubble-head { font-size: 12px; font-weight: 700; color: #a86a00; margin-bottom: 5px; letter-spacing: .5px; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); display: flex; align-items: center; justify-content: center; font-weight: 700; flex: 0 0 auto; object-fit: cover; background-size: cover; background-position: center; background-repeat: no-repeat; }
.avatar.has-img { color: transparent; }
.avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.name { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.msg-col { display: flex; flex-direction: column; max-width: 78%; min-width: 0; }
.msg-col .bubble { max-width: 100%; }
.row.user .msg-col { align-items: flex-end; }
.speak-btn { margin-top: 4px; font-size: 12px; padding: 2px 8px; border: 1px solid var(--border); background: #fff; border-radius: 8px; cursor: pointer; color: var(--primary); }

/* ---------- 输入区（微信式：默认语音，可切文字） ---------- */
.composer { display: flex; gap: 6px; margin-top: 12px; align-items: flex-end; }
.composer textarea { flex: 1; resize: none; height: 52px; line-height: 24px; overflow: hidden; border: 1px solid var(--border); border-radius: 12px; padding: 14px 14px; font-family: var(--font); font-size: 15px; transition: border-color .15s, box-shadow .15s; }
.composer textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.mode-toggle { flex: 0 0 auto; width: 44px; height: 52px; display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--border); background: #fff; border-radius: 12px; color: var(--primary); cursor: pointer; transition: background .15s, border-color .15s; }
.mode-toggle:hover { background: var(--primary-soft); }
.composer-main { flex: 1; min-width: 0; position: relative; }
.composer .btn { height: 52px; }
.hold-btn { width: 100%; height: 52px; display: none; align-items: center; justify-content: center; gap: 8px; border: 1px solid #c5d9f8; background: var(--primary-soft); border-radius: 12px; font-size: 15px; color: var(--primary); cursor: pointer; touch-action: manipulation; user-select: none; -webkit-user-select: none; transition: background .15s, border-color .15s; }
.hold-btn .rec-dot { display: none; width: 9px; height: 9px; border-radius: 50%; background: currentColor; flex: 0 0 auto; }
.hold-btn.listening { background: #d93025; border-color: #d93025; color: #fff; }
.hold-btn.listening .rec-dot { display: inline-block; animation: voicePulse 1.1s ease-in-out infinite; }
#composer[data-mode="voice"] .hold-btn { display: inline-flex; }
#composer[data-mode="voice"] #userInput { display: none; }
#composer[data-mode="voice"] #btnSend { display: none; }
#composer[data-mode="text"] #userInput { display: block; }
@keyframes voicePulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .35; transform: scale(.65); } }
.hint { background: var(--primary-soft); border-left: 4px solid var(--primary); padding: 10px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 12px; color: #234; }
.note { font-size: 12px; color: var(--muted); line-height: 1.5; }

/* ---------- 状态栏 ---------- */
.status h3 { margin: 0 0 10px; font-size: 14px; }
.metric { margin-bottom: 12px; }
.metric label { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; }
.bar { height: 8px; border-radius: 6px; background: var(--border); overflow: hidden; margin-top: 4px; }
.bar > span { display: block; height: 100%; }
.bar.tension > span { background: var(--danger); }
.bar.trust > span { background: var(--success); }
.chars { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 12px; padding: 4px 10px; border-radius: 20px; background: var(--bg); border: 1px solid var(--border); }
.chip.s-活跃 { color: var(--success); border-color: var(--success); }
.chip.s-沉默 { color: var(--muted); }
.chip.s-退场, .chip.s-绝望退场 { color: var(--danger); border-color: var(--danger); }
.chip.s-爆发 { color: var(--warn); border-color: var(--warn); }

/* ---------- 任务列表 ---------- */
.tasks { list-style: none; padding: 0; margin: 6px 0 0; font-size: 13px; }
.tasks li { padding: 3px 0; }
.tasks li.done { color: var(--muted); text-decoration: line-through; }
.tasks li.cur { color: var(--primary); font-weight: 700; }

/* ---------- 弹层 ---------- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal .box { background: #fff; border-radius: 14px; padding: 22px; width: 380px; max-width: 92vw; max-height: 88vh; overflow: auto; }
.modal .box.wide { width: 680px; }
.box-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.box-head-actions { display: flex; gap: 6px; align-items: center; }
.modal-actions { display: flex; gap: 8px; margin-top: 6px; }
.modal input { width: 100%; padding: 10px; border: 1px solid var(--border); border-radius: 8px; margin: 8px 0 14px; }

/* ---------- 记录面板 ---------- */
.trace { font-size: 12px; max-height: 60vh; overflow-y: auto; margin-top: 4px; }
.trace .rec { border-bottom: 1px dashed var(--border); padding: 8px 0; }
.trace .rec-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.trace .tag { font-weight: 700; padding: 1px 8px; border-radius: 10px; font-size: 11px; color: #fff; }
.tag.director { background: var(--primary); }
.tag.actor { background: var(--success); }
.tag.task { background: var(--warn); }
.tag.gatekeeper { background: #8e44ad; }
.tag.evaluator { background: #16a085; }
.trace .type-name { font-weight: 600; color: var(--text); }
.trace .ok { color: var(--success); font-weight: 700; }
.trace .bad { color: var(--danger); font-weight: 700; }
.trace .meta { color: var(--muted); margin-left: auto; }
.trace .err { color: var(--danger); margin-top: 2px; }
.trace details { margin-top: 6px; }
.trace summary { cursor: pointer; color: var(--primary); font-size: 11px; }
.trace pre { background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 8px; max-height: 180px; overflow: auto; white-space: pre-wrap; word-break: break-word; margin: 4px 0 0; font-size: 11px; }

/* ---------- 评价报告 ---------- */
.report .total { font-size: 15px; font-weight: 700; margin: 4px 0 10px; }
.report .score { margin-bottom: 8px; }
.report .score .lbl { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 3px; }
.report .bar { height: 8px; }
.report .bar > span { background: var(--primary); display: block; height: 100%; }
.report h4 { margin: 12px 0 4px; font-size: 14px; }
.report ul { margin: 4px 0; padding-left: 18px; }
.report ul li { margin: 2px 0; }

/* ---------- 设置弹层表单 ---------- */
.settings-body { display: flex; flex-direction: column; gap: 16px; }
.settings-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 14px; border-top: 1px solid var(--border); padding-top: 12px; }
.set-section { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.set-section > h4 { margin: 0 0 10px; font-size: 13px; color: var(--primary); }
.set-row { display: flex; gap: 10px; align-items: center; margin-bottom: 8px; }
.set-row label { width: 96px; flex: 0 0 auto; font-size: 13px; color: var(--muted); }
.set-row input, .set-row textarea, .set-row select {
  flex: 1; padding: 7px 9px; border: 1px solid var(--border); border-radius: 8px; font-family: var(--font); font-size: 13px; width: 100%;
}
.set-row textarea { resize: vertical; min-height: 56px; }
.set-row .ctrl { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.set-row .ctrl textarea { width: 100%; }
.mini-note { font-size: 11px; color: var(--muted); margin-top: 4px; line-height: 1.4; }
.set-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.role-card { border: 1px dashed var(--border); border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; }
.role-card .role-title { font-weight: 700; font-size: 13px; margin-bottom: 6px; }
.prompt-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.prompt-tabs button { border: 1px solid var(--border); background: #fff; border-radius: 8px; padding: 4px 10px; font-size: 12px; cursor: pointer; color: var(--muted); }
.prompt-tabs button.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.prompt-pane textarea { width: 100%; min-height: 180px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; padding: 10px; border: 1px solid var(--border); border-radius: 8px; resize: vertical; }

/* ---------- 设置：角色卡 / 头像 / 折叠 ---------- */
.role-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.role-head .set-row { flex: 1; margin: 0; }
.role-del { flex: 0 0 auto; }
.file-in { flex: 1; font-size: 12px; }
.avatar-prev { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; border: 1px solid var(--border); flex: 0 0 auto; }
.avatar-prev.placeholder { display: inline-flex; align-items: center; justify-content: center; background: var(--primary-soft); color: var(--primary); font-size: 11px; }
.student-card { border-style: solid; border-color: #c5d9f8; background: #f7fbff; }
.role-badge { font-weight: 700; color: #fff; background: var(--primary); border-radius: 6px; padding: 1px 8px; font-size: 12px; }
.task-card { border: 1px dashed var(--border); border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; background: #fbfcfe; }
.task-card .set-row:last-child { margin-bottom: 0; }
.tasks-editor label { align-self: flex-start; padding-top: 4px; }
.tasks-editor .ctrl { gap: 4px; }
.task-del { align-self: flex-start; }
.row-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
#addRole { margin-top: 6px; }
.sec-head { cursor: pointer; user-select: none; display: flex; align-items: center; justify-content: space-between; }
.sec-toggle { color: var(--muted); font-size: 12px; transition: transform .15s; }
.set-section.collapsed .sec-body { display: none; }
.set-section.collapsed .sec-toggle { transform: rotate(-90deg); }

/* ---------- 状态栏：Key 提示 ---------- */
.key-tip { background: #fff4e5; color: #8a5a00; border: 1px solid #ffd8a8; border-radius: 8px; padding: 8px 10px; font-size: 12px; margin-bottom: 12px; line-height: 1.5; }
