* { box-sizing: border-box; }
:root {
  --bg: #f7f3ec;
  --panel: #fffdf9;
  --line: #ece3d6;
  --ink: #2f2a26;
  --muted: #9b8873;
  --brand: #d97b52;
  --user: #5b8fa8;
}

html, body { height: 100%; }

body {
  margin: 0;
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

/* ---------- 主容器：移动端占满视口 ---------- */

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 640px;
  margin: 0 auto;
  background: var(--panel);
  overflow: hidden;
}

/* ---------- 顶栏 ---------- */

.chat-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  flex: none;
}

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

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #c3b7a6;
  flex: none;
  transition: background 0.25s ease, box-shadow 0.25s ease;
}
.dot[data-state="listening"] { background: #4f8a6b; box-shadow: 0 0 0 4px rgba(79, 138, 107, 0.15); }
.dot[data-state="thinking"]  { background: #d9a53f; box-shadow: 0 0 0 4px rgba(217, 165, 63, 0.15); }
.dot[data-state="speaking"]  { background: var(--brand); box-shadow: 0 0 0 4px rgba(217, 123, 82, 0.18); }

.chat-head .title { font-size: 16px; font-weight: 600; }
.chat-head .sub {
  font-size: 12px;
  color: var(--muted);
  margin-left: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-head .ghost {
  flex: none;
  border: 1px solid var(--line);
  background: #fff;
  color: #8a6f56;
  border-radius: 999px;
  padding: 5px 14px;
  font-size: 13px;
  cursor: pointer;
  text-decoration: none;
  display: flex;
  align-items: center;
}
.chat-head .ghost:active { background: #faf4ea; }
.chat-head .sub + .ghost { margin-left: auto; }
.chat-head .ghost.icon { padding: 7px; }
.chat-head .ghost + .ghost { margin-left: 6px; }

/* ---------- 消息区 ---------- */

.messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.bubble {
  max-width: 84%;
  padding: 11px 15px;
  border-radius: 16px;
  line-height: 1.68;
  font-size: 16px;
  white-space: pre-wrap;
  word-break: break-word;
}

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

/* 声纹识别出的说话人，打在气泡里 */
.who {
  display: block;
  font-size: 11px;
  opacity: 0.72;
  margin-bottom: 2px;
  letter-spacing: 0.5px;
}

.bubble.teacher {
  align-self: flex-start;
  background: #f3ede4;
  color: #332c25;
  border-bottom-left-radius: 5px;
}

.bubble.system {
  align-self: center;
  background: none;
  color: var(--muted);
  font-size: 13px;
  padding: 2px;
}

/* ---------- 底部 ---------- */

.composer {
  flex: none;
  padding: 12px 16px calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: center;
  background: var(--panel);
}

.mic {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  border: none;
  border-radius: 999px;
  padding: 13px 26px;
  font-size: 16px;
  font-weight: 500;
  color: #fff;
  background: var(--brand);
  cursor: pointer;
  transition: transform 0.1s ease, background 0.2s ease;
}
.mic:active { transform: scale(0.98); }
.mic.on { background: #4f8a6b; }

/* ---------- 语音模式 ---------- */

.voice-mode {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: radial-gradient(circle at 50% 30%, #ffffff 0%, #f4f2fb 55%, #eaedf8 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.voice-mode[hidden] { display: none; }

.orb-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

#orb { width: min(320px, 62vw); height: min(320px, 62vw); }

.voice-status {
  min-height: 22px;
  font-size: 15px;
  color: #5b6a8a;
  letter-spacing: 1px;
}

.subtitle {
  position: absolute;
  bottom: 128px;
  left: 50%;
  transform: translateX(-50%);
  max-width: 80%;
  padding: 11px 18px;
  background: rgba(38, 44, 66, 0.72);
  color: #fff;
  border-radius: 14px;
  font-size: 16px;
  line-height: 1.65;
  word-break: break-word;
}
.subtitle:empty { display: none; }
.subtitle[data-role="user"] { background: rgba(91, 143, 168, 0.88); }

.vclose {
  position: absolute;
  top: calc(14px + env(safe-area-inset-top));
  left: 14px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.75);
  color: #3c4560;
  cursor: pointer;
}

.voice-bar {
  position: absolute;
  bottom: calc(40px + env(safe-area-inset-bottom));
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  gap: 28px;
}

.vbtn {
  width: 66px;
  height: 66px;
  border-radius: 50%;
  border: 1px solid #d9dcea;
  background: #fff;
  color: #3c4560;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  transition: transform 0.1s ease;
}
.vbtn:active { transform: scale(0.94); }
.vbtn.muted { background: #f3d9ce; color: #9a5433; border-color: #e6bda9; }

/* ---------- 声纹管理页 ---------- */

.admin-body { gap: 14px; }

.engine {
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 13px;
}
.engine.ok { background: #eaf4ee; color: #3f7a56; }
.engine.bad { background: #fbeae6; color: #a2543a; }

.card {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  background: #fff;
}

.card-title { font-size: 14px; font-weight: 600; margin-bottom: 10px; color: #6d6154; }

.row { display: flex; gap: 8px; margin-bottom: 8px; }

.card input, .card select {
  flex: 1;
  min-width: 0;
  border: 1px solid #e2d6c4;
  border-radius: 9px;
  padding: 9px 11px;
  font-size: 15px;
  font-family: inherit;
  background: #fffdf9;
  color: var(--ink);
}
.card input:focus, .card select:focus { outline: 2px solid #e8c9a8; outline-offset: -1px; }

button.primary {
  width: 100%;
  border: none;
  border-radius: 999px;
  padding: 10px;
  font-size: 15px;
  color: #fff;
  background: var(--brand);
  cursor: pointer;
}
button.primary:active { transform: scale(0.98); }
button.primary:disabled { background: #d6cdbf; cursor: default; }

button.primary.big {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px;
  font-size: 16px;
  font-weight: 500;
}

/* ---------- 引导弹窗 ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: var(--panel);
  display: flex;
  flex-direction: column;
}
.modal[hidden] { display: none; }

.modal-head {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  border-bottom: 1px solid var(--line);
}
.mclose {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  background: #f4efe6;
  color: #6d6154;
  cursor: pointer;
  flex: none;
}
.mtitle { font-size: 16px; font-weight: 600; }
.mstep { margin-left: auto; font-size: 12px; color: var(--muted); }

.modal-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 16px calc(20px + env(safe-area-inset-bottom));
}
.modal-body[hidden] { display: none; }

.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 13px;
  color: #6d6154;
  margin-bottom: 6px;
}
.field label .opt { color: #ab9c88; font-size: 12px; }
.field input {
  width: 100%;
  border: 1px solid #e2d6c4;
  border-radius: 10px;
  padding: 11px 12px;
  font-size: 16px;
  font-family: inherit;
  background: #fffdf9;
  color: var(--ink);
}
.field input:focus { outline: 2px solid #e8c9a8; outline-offset: -1px; }

.segmented {
  display: flex;
  gap: 6px;
  background: #f4efe6;
  padding: 3px;
  border-radius: 10px;
}
.seg {
  flex: 1;
  border: none;
  background: none;
  padding: 9px 0;
  font-size: 14px;
  font-family: inherit;
  color: #7a6a58;
  border-radius: 8px;
  cursor: pointer;
}
.seg.on { background: #fff; color: var(--ink); font-weight: 500; box-shadow: 0 1px 3px rgba(90, 70, 50, 0.08); }

.lead { font-size: 13px; color: #7a6a58; margin: 0 0 12px; line-height: 1.6; }

.clip {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  margin-bottom: 10px;
  background: #fff;
  transition: border-color 0.2s ease, background 0.2s ease;
}
.clip.recording { border-color: var(--user); background: #f4f9fb; }
.clip.done { border-color: #bfd9c9; }

.clip-no { font-size: 12px; color: var(--muted); margin-bottom: 6px; }

.clip-text {
  font-size: 19px;
  line-height: 1.6;
  color: #332c25;
  margin-bottom: 10px;
  letter-spacing: 0.5px;
}

.wave { width: 100%; height: 48px; display: block; margin-bottom: 10px; }

.recbtn, .rebtn {
  width: 100%;
  border: 1px solid var(--user);
  background: #fff;
  color: #3d7288;
  border-radius: 999px;
  padding: 10px;
  font-size: 15px;
  font-family: inherit;
  cursor: pointer;
}
.recbtn:active, .rebtn:active { transform: scale(0.98); }
.rebtn { border-color: #e2d6c4; color: #7a6a58; }

.hintline {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  margin: 10px 0 0;
  min-height: 18px;
}

.person {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
  border-top: 1px solid #f2ece2;
}
.person:first-child { border-top: none; }

.pinfo { flex: 1; min-width: 0; }
.pname { font-size: 15px; font-weight: 600; }
.pmeta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.tag {
  font-size: 11px;
  font-weight: 400;
  padding: 1px 7px;
  border-radius: 999px;
  background: #eef2f6;
  color: #5b6a8a;
}

.pact { display: flex; gap: 6px; flex: none; }
.pact .btn {
  border: 1px solid #e2d6c4;
  background: #fff;
  color: #6d5f4e;
  border-radius: 8px;
  padding: 6px 11px;
  font-size: 13px;
  cursor: pointer;
}
.pact .btn:active { background: #faf4ea; }
.pact .btn.danger { color: #a2543a; border-color: #e6c9bd; }

/* 识别测试 */
.probe {
  margin-top: 18px;
  padding: 14px;
  border: 1px solid #ece3d6;
  border-radius: 14px;
  background: #fffdf8;
}
.probe .ptitle { font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.probe .lead { font-size: 13px; color: #7a6a58; line-height: 1.6; margin-bottom: 10px; }
.probe canvas.wave { width: 100%; height: 48px; display: block; margin-bottom: 10px; }
.probe button.primary { border-radius: 10px; padding: 11px; }

.probe-out { margin-top: 10px; }
.prow { display: flex; align-items: center; gap: 8px; margin: 5px 0; }
.prow .pn { font-size: 13px; width: 68px; flex: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prow .pbar { flex: 1; height: 8px; background: #f0e9dd; border-radius: 999px; overflow: hidden; }
.prow .pbar i { display: block; height: 100%; background: #cfc3ae; border-radius: 999px; }
.prow.hit .pbar i { background: #5b8fa8; }
.prow .pv { font-size: 12px; width: 42px; text-align: right; color: var(--muted); flex: none; }
.prow.hit .pn, .prow.hit .pv { color: #3f6f88; font-weight: 600; }
.pverdict { font-size: 13px; margin-top: 8px; color: #3f7a56; }
.pverdict.bad { color: #a2543a; }

.tune { margin-top: 12px; border-top: 1px dashed #e6dccb; padding-top: 10px; }
.tstat { font-size: 12.5px; color: #7a6a58; line-height: 1.6; }
.tact { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.tact .btn {
  border: 1px solid #e2d6c4;
  background: #fff;
  color: #6d5f4e;
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 13px;
  cursor: pointer;
}
.tact .btn:active { background: #faf4ea; }
#applyBtn { background: #5b8fa8; border-color: #5b8fa8; color: #fff; }

.probe select {
  width: 100%;
  border: 1px solid #e2d6c4;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 15px;
  background: #fff;
  color: #3b332a;
}

.empty { font-size: 14px; color: var(--muted); padding: 6px 0; }
.progress { font-size: 13px; color: #7a6a58; min-height: 20px; margin-top: 8px; }

.tips { font-size: 13px; color: #7a6a58; line-height: 1.75; padding: 0 2px; }
.tips p { margin: 2px 0; }
.tips .warn { color: #a2543a; }

/* ---------- 平板/桌面：居中卡片 ---------- */

@media (min-width: 700px) {
  body {
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .app {
    height: min(760px, 94vh);
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(90, 70, 50, 0.12);
  }
  .voice-mode { border-radius: 0; }
}
