/* ============================================================
   AI 助理 · 右下角悬浮数字人对话 widget
   复用全站配色变量（--bg/--ink/--accent 等，定义在 style.css）
   ============================================================ */

.aiw {
  position: fixed;
  right: clamp(16px, 3vw, 28px);
  bottom: clamp(16px, 3vw, 28px);
  z-index: 9999;
  font-family: var(--sans);
}

/* —— 悬浮气泡 —— */
.aiw-bubble {
  position: relative;
  display: grid;
  place-items: center;
  width: 68px;
  height: 68px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: radial-gradient(120% 120% at 30% 25%, #14203c 0%, #0d0d0d 70%);
  color: var(--ink);
  cursor: pointer;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .5), 0 0 0 6px rgba(0, 85, 255, .06);
  transition: transform .25s var(--ease), box-shadow .25s var(--ease);
}
.aiw-bubble:hover { transform: translateY(-2px) scale(1.04); box-shadow: 0 12px 36px rgba(0,0,0,.55), 0 0 0 8px rgba(0,85,255,.12); }
.aiw-bubble-txt {
  font-family: var(--display);
  font-weight: 700;
  font-size: 11px;
  line-height: 1.28;
  text-align: center;
  letter-spacing: 0;
}
.aiw-bubble-dot {
  position: absolute;
  top: 6px; right: 6px;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: #22c55e;
  border: 2px solid #0d0d0d;
  box-shadow: 0 0 0 0 rgba(34,197,94,.6);
  animation: aiw-pulse 2.2s var(--ease) infinite;
}
@keyframes aiw-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(34,197,94,.55); }
  70%  { box-shadow: 0 0 0 10px rgba(34,197,94,0); }
  100% { box-shadow: 0 0 0 0 rgba(34,197,94,0); }
}

/* —— 展开面板 —— */
.aiw-panel {
  position: absolute;
  right: 0;
  bottom: 84px;
  width: min(92vw, 360px);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 24px 70px rgba(0, 0, 0, .6);
  transform: translateY(12px) scale(.96);
  transform-origin: bottom right;
  opacity: 0;
  pointer-events: none;
  transition: opacity .22s var(--ease), transform .22s var(--ease);
}

/* 状态切换：由容器 data-state 控制 */
.aiw[data-state="idle"]  .aiw-panel { }
.aiw[data-state="open"]  .aiw-panel,
.aiw[data-state="connecting"] .aiw-panel,
.aiw[data-state="live"]  .aiw-panel,
.aiw[data-state="ended"] .aiw-panel {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}
.aiw[data-state="idle"] .aiw-bubble { display: grid; }
.aiw:not([data-state="idle"]) .aiw-bubble { display: none; }

/* —— 头部 —— */
.aiw-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
.aiw-title {
  display: flex; align-items: center; gap: 7px;
  font-family: var(--display);
  font-weight: 700;
  font-size: 15px;
  color: var(--ink);
  flex: 1;
}
.aiw-live {
  width: 8px; height: 8px; border-radius: 50%;
  background: #666;
}
.aiw[data-state="live"] .aiw-live { background: #22c55e; box-shadow: 0 0 8px #22c55e; }
.aiw[data-state="connecting"] .aiw-live { background: #f59e0b; animation: aiw-blink 1s infinite; }
@keyframes aiw-blink { 50% { opacity: .3; } }
.aiw-timer {
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--dim);
  padding: 2px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
}
.aiw-close {
  width: 28px; height: 28px;
  display: grid; place-items: center;
  border: none; background: transparent;
  color: var(--body);
  font-size: 22px; line-height: 1;
  cursor: pointer; border-radius: 8px;
}
.aiw-close:hover { background: #1a1a1a; color: var(--ink); }

/* —— 视频舞台 —— */
.aiw-stage {
  position: relative;
  aspect-ratio: 3 / 4;
  background: #060606;
}
.aiw-video {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
  background: #060606;
}
.aiw-overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 16px; padding: 20px;
  text-align: center;
  background: radial-gradient(120% 90% at 50% 40%, #10162a 0%, #060606 75%);
}
.aiw[data-state="live"] .aiw-overlay { display: none; }
.aiw-status { color: var(--body); font-size: 14px; line-height: 1.5; }
.aiw-start {
  font-family: var(--display); font-weight: 700; font-size: 15px;
  color: #fff;
  background: var(--accent);
  border: none; border-radius: 12px;
  padding: 12px 26px;
  cursor: pointer;
  transition: background .2s var(--ease), transform .2s var(--ease);
}
.aiw-start:hover { background: var(--accent-soft); transform: translateY(-1px); }
.aiw-start:disabled { opacity: .5; cursor: default; transform: none; }
.aiw-spin {
  width: 34px; height: 34px;
  border: 3px solid #ffffff22;
  border-top-color: var(--accent-soft);
  border-radius: 50%;
  animation: aiw-rot .8s linear infinite;
}
@keyframes aiw-rot { to { transform: rotate(360deg); } }

/* 字幕 */
.aiw-caption {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  margin: 0;
  padding: 20px 14px 12px;
  font-size: 13px;
  line-height: 1.45;
  color: #fff;
  background: linear-gradient(to top, rgba(0,0,0,.78), transparent);
  min-height: 1.4em;
  opacity: 0;
  transition: opacity .2s var(--ease);
}
.aiw[data-state="live"] .aiw-caption.show { opacity: 1; }

/* —— 底部控制 —— */
.aiw-controls {
  display: flex;
  gap: 8px;
  padding: 12px 12px 10px;
  align-items: center;
}
.aiw[data-state="live"] .aiw-controls { display: flex; }
.aiw:not([data-state="live"]) .aiw-controls { display: none; }
.aiw-input {
  flex: 1;
  background: #060606;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 10px 14px;
  color: var(--ink);
  font-size: 14px;
  font-family: var(--sans);
  outline: none;
}
.aiw-input:focus { border-color: #2b3a5c; }
.aiw-input::placeholder { color: var(--dim); }
.aiw-mic, .aiw-send {
  border: 1px solid var(--line);
  background: #101010;
  color: var(--ink);
  border-radius: 999px;
  height: 40px;
  cursor: pointer;
  font-family: var(--sans);
  font-size: 14px;
}
.aiw-mic { width: 40px; font-size: 17px; }
.aiw-send { padding: 0 16px; }
.aiw-mic:hover, .aiw-send:hover { border-color: #2b3a5c; }
.aiw-mic.on { background: var(--accent); border-color: var(--accent); }

.aiw-foot {
  margin: 0;
  padding: 0 14px 12px;
  font-size: 11px;
  line-height: 1.4;
  color: var(--dim);
  text-align: center;
}

@media (max-width: 480px) {
  .aiw-panel { bottom: 80px; }
}

/* Framer-inspired widget skin：保留全部状态与交互，只换视觉。 */
.aiw {
  right: clamp(14px, 2vw, 24px);
  bottom: clamp(14px, 2vw, 24px);
}

.aiw-bubble {
  width: 64px;
  height: 64px;
  border-radius: 18px;
  border-color: rgba(255, 255, 255, .12);
  background:
    radial-gradient(80% 80% at 82% 18%, rgba(45, 111, 255, .22), transparent 72%),
    #111113;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .07), 0 18px 44px rgba(0, 0, 0, .5);
}

.aiw-bubble:hover {
  transform: translateY(-2px);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .09), 0 22px 50px rgba(0, 0, 0, .56);
}

.aiw-bubble-txt {
  display: block;
  width: 52px;
  height: 30px;
  font-size: 11px;
  line-height: 1.28;
  letter-spacing: 0;
}

.aiw-bubble-dot {
  top: 7px;
  right: 7px;
  width: 9px;
  height: 9px;
  border-color: #111113;
}

.aiw-panel {
  bottom: 76px;
  width: min(92vw, 380px);
  height: min(640px, calc(100dvh - 92px));
  display: flex;
  flex-direction: column;
  border-color: rgba(255, 255, 255, .11);
  border-radius: 16px;
  background: #0a0a0b;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .045), 0 30px 90px rgba(0, 0, 0, .68);
}

.aiw-head {
  min-height: 52px;
  padding: 12px 16px;
  border-color: rgba(255, 255, 255, .08);
}

.aiw-title { font-size: 14px; }

.aiw-close {
  border-radius: 7px;
  font-size: 20px;
}

.aiw-close:hover { background: #171719; }

.aiw-overlay {
  background:
    linear-gradient(rgba(255, 255, 255, .018) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, .018) 1px, transparent 1px),
    radial-gradient(80% 55% at 50% 35%, rgba(44, 105, 255, .15), transparent 76%),
    #070708;
  background-size: 28px 28px, 28px 28px, auto, auto;
}

.aiw-stage,
.aiw-chat {
  flex: 1 1 auto;
  min-height: 0;
}

.aiw-stage {
  aspect-ratio: auto;
}

.aiw-start {
  border-radius: 8px;
  padding: 11px 22px;
  background: #f5f5f5;
  color: #09090a;
  font-size: 14px;
}

.aiw-start:hover { background: #fff; }

.aiw-controls {
  padding: 12px;
  border-top: 1px solid rgba(255, 255, 255, .075);
}

.aiw-input {
  height: 40px;
  border-radius: 8px;
  background: #111113;
  border-color: rgba(255, 255, 255, .09);
}

.aiw-input:focus {
  border-color: rgba(84, 141, 255, .62);
  box-shadow: 0 0 0 3px rgba(41, 102, 236, .12);
}

.aiw-mic,
.aiw-send {
  border-radius: 8px;
  background: #141416;
  border-color: rgba(255, 255, 255, .09);
}

.aiw-mic.on { background: #286fff; }

.aiw-foot { padding-bottom: 13px; }

@media (max-width: 480px) {
  .aiw-bubble { width: 58px; height: 58px; border-radius: 16px; }
  .aiw-panel { bottom: 68px; border-radius: 14px; }
}

/* 悬浮入口固定保持圆形。 */
.aiw-bubble { border-radius: 50%; }

@media (max-width: 480px) {
  .aiw-bubble { border-radius: 50%; }
}

/* ============================================================
   视频 / 语音 双模式：开关 + 语音聊天区
   ============================================================ */

/* —— 模式开关 —— */
.aiw-modes {
  display: flex;
  gap: 4px;
  margin: 0 12px 10px;
  padding: 3px;
  background: #0a0a0b;
  border: 1px solid rgba(255, 255, 255, .08);
  border-radius: 10px;
}
.aiw-mode {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--body);
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 600;
  padding: 7px 0;
  border-radius: 8px;
  cursor: pointer;
  transition: background .18s var(--ease), color .18s var(--ease);
}
.aiw-mode[aria-selected="true"] { background: #f5f5f5; color: #09090a; }
.aiw-mode:not([aria-selected="true"]):hover { color: var(--ink); }

/* —— 模式切换：显隐 —— */
.aiw-chat { display: none; }
.aiw[data-mode="voice"] .aiw-stage { display: none; }
.aiw[data-mode="voice"] .aiw-chat { display: flex; }
.aiw[data-mode="voice"] .aiw-controls { display: flex; }
.aiw[data-mode="voice"] .aiw-mic { display: none; }

/* —— 语音模式：聊天区 —— */
.aiw-chat {
  flex-direction: column;
  gap: 10px;
  height: auto;
  overflow-y: auto;
  padding: 12px 12px 4px;
}
.aiw-msg { display: flex; align-items: flex-end; gap: 6px; }
.aiw-msg-me { justify-content: flex-end; }
.aiw-msg-b {
  max-width: 82%;
  padding: 9px 12px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}
.aiw-msg-bot .aiw-msg-b { background: #17171a; color: var(--ink); border-bottom-left-radius: 5px; }
.aiw-msg-me .aiw-msg-b { background: #286fff; color: #fff; border-bottom-right-radius: 5px; }
.aiw-play {
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 2px;
  opacity: .55;
  transition: opacity .15s var(--ease);
}
.aiw-play:hover { opacity: 1; }

/* 打字中动画 */
.aiw-typing { display: inline-flex; gap: 4px; align-items: center; }
.aiw-typing i {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--dim);
  animation: aiw-typing 1s var(--ease) infinite;
}
.aiw-typing i:nth-child(2) { animation-delay: .15s; }
.aiw-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes aiw-typing {
  0%, 60%, 100% { opacity: .3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

/* —— 站主总开关：模式下线 —— */
.aiw-mode[aria-disabled="true"] {
  opacity: .4;
  cursor: not-allowed;
}
.aiw-mode[aria-disabled="true"]::after {
  content: " · 下线";
  font-weight: 400;
  font-size: 11px;
}

/* ============================================================
   公开课分流：口令门、讲师引导、学员文字领取
   ============================================================ */
.aiw-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;
}

.aiw-gate {
  display: none;
  flex: 1;
  min-height: 360px;
  padding: 54px 28px 30px;
  background:
    radial-gradient(circle at 50% 15%, rgba(40, 111, 255, .18), transparent 34%),
    #0a0a0b;
}

.aiw[data-access="locked"] .aiw-gate { display: block; }
.aiw[data-access="locked"] .aiw-modes,
.aiw[data-access="locked"] .aiw-classroom-entry,
.aiw[data-access="locked"] .aiw-stage,
.aiw[data-access="locked"] .aiw-chat,
.aiw[data-access="locked"] .aiw-controls,
.aiw[data-access="locked"] .aiw-foot { display: none; }

.aiw-gate-kicker {
  margin: 0 0 12px;
  color: #75a2ff;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .08em;
}

.aiw-gate-title {
  margin: 0;
  color: var(--ink);
  font-family: var(--display);
  font-size: 27px;
  line-height: 1.2;
}

.aiw-gate-copy {
  margin: 12px 0 28px;
  color: var(--body);
  font-size: 14px;
}

.aiw-gate-form { display: flex; gap: 8px; }
.aiw-passcode {
  min-width: 0;
  flex: 1;
  padding: 13px 14px;
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 10px;
  outline: none;
  background: #111113;
  color: #fff;
  font: 700 19px/1 var(--sans);
  letter-spacing: .18em;
  text-align: center;
}
.aiw-passcode:focus { border-color: #4f86f7; box-shadow: 0 0 0 3px rgba(40, 111, 255, .13); }
.aiw-passcode.is-wrong { animation: aiw-shake .28s ease; border-color: #e35d6a; }
@keyframes aiw-shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }

.aiw-unlock {
  border: 0;
  border-radius: 10px;
  padding: 0 20px;
  background: #286fff;
  color: #fff;
  font: 700 14px/1 var(--sans);
  cursor: pointer;
}
.aiw-unlock:hover { background: #3d7dff; }
.aiw-gate-msg { min-height: 21px; margin: 12px 0 0; color: #ef8791; font-size: 13px; }
.aiw-gate-back {
  display: block;
  margin: 18px auto 0;
  border: 0;
  background: transparent;
  color: var(--dim);
  font: 500 12px/1.4 var(--sans);
  cursor: pointer;
}
.aiw-gate-back:hover { color: var(--ink); }
.aiw[data-flow="instructor"] .aiw-gate-back { display: none; }

/* 讲师优先使用视频 TA + 下方现场导航；视频关闭时退回语音。学员只使用确定性的文字按钮。 */
.aiw[data-flow="instructor"][data-access="granted"] .aiw-modes,
.aiw[data-flow="classroom"][data-access="granted"] .aiw-modes,
.aiw[data-flow="classroom"][data-access="granted"] .aiw-stage,
.aiw[data-flow="instructor"] .aiw-classroom-entry,
.aiw[data-flow="classroom"] .aiw-classroom-entry { display: none; }
.aiw[data-flow="instructor"][data-access="granted"] .aiw-chat,
.aiw[data-flow="classroom"][data-access="granted"] .aiw-chat { display: flex; flex: 1; min-height: 0; }
.aiw[data-flow="instructor"][data-access="granted"] .aiw-controls { display: flex; }
.aiw[data-flow="classroom"][data-access="granted"] .aiw-controls { display: none; }
.aiw[data-flow="instructor"][data-access="granted"][data-mode="video"] .aiw-stage {
  flex: 1.35 1 0;
  min-height: 220px;
}
.aiw[data-flow="instructor"][data-access="granted"][data-mode="video"] .aiw-chat {
  flex: .65 1 0;
  max-height: 220px;
  border-top: 1px solid rgba(255, 255, 255, .075);
}

.aiw-classroom-entry {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 12px 10px;
  padding: 11px 12px;
  border: 1px solid rgba(84, 141, 255, .25);
  border-radius: 11px;
  background: linear-gradient(110deg, rgba(40, 111, 255, .12), rgba(40, 111, 255, .035));
}
.aiw-classroom-entry > div { display: grid; flex: 1; min-width: 0; gap: 2px; }
.aiw-classroom-entry b { color: #e7eeff; font-size: 12px; }
.aiw-classroom-entry span { color: var(--dim); font-size: 11px; line-height: 1.35; }
.aiw-claim-entry {
  flex: 0 0 auto;
  padding: 8px 10px;
  border: 1px solid rgba(97, 146, 247, .42);
  border-radius: 8px;
  background: rgba(40, 111, 255, .13);
  color: #dbe7ff;
  font: 700 12px/1 var(--sans);
  cursor: pointer;
}
.aiw-claim-entry:hover { background: rgba(40, 111, 255, .22); border-color: #6192f7; }

.aiw-actions {
  display: grid;
  gap: 7px;
  margin: 2px 0 6px;
  padding-left: 0;
}
.aiw-action {
  width: fit-content;
  max-width: 92%;
  padding: 9px 12px;
  border: 1px solid rgba(84, 141, 255, .42);
  border-radius: 10px;
  background: rgba(40, 111, 255, .09);
  color: #dce8ff;
  font: 600 13px/1.35 var(--sans);
  text-align: left;
  cursor: pointer;
}
.aiw-action:hover { border-color: #6192f7; background: rgba(40, 111, 255, .16); }
.aiw-action:disabled { opacity: .45; cursor: default; }

.aiw-role-tag {
  margin-left: 4px;
  padding: 3px 7px;
  border: 1px solid rgba(84, 141, 255, .35);
  border-radius: 999px;
  color: #91b2f8;
  font-size: 10px;
  font-weight: 700;
}

.instructor-toast {
  position: fixed;
  top: 76px;
  left: 50%;
  z-index: 10000;
  transform: translateX(-50%);
  margin: 0;
  padding: 10px 15px;
  border: 1px solid rgba(97, 146, 247, .5);
  border-radius: 999px;
  background: rgba(9, 9, 11, .94);
  color: #e8efff;
  box-shadow: 0 12px 36px rgba(0, 0, 0, .45);
  font: 600 13px/1.2 var(--sans);
}

@media (max-width: 480px) {
  .aiw-gate { min-height: 330px; padding: 44px 20px 24px; }
  .aiw-gate-title { font-size: 24px; }
}
