/* 英语学习助手：右下角机器人与聊天窗 */
#enChatRobot {
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: calc(20px + env(safe-area-inset-bottom));
  z-index: 99980;
  width: 62px;
  height: 62px;
  padding: 0;
  border: 1px solid var(--glass-border);
  border-radius: 20px;
  background: linear-gradient(145deg, var(--surface-strong), var(--surface));
  color: var(--text-primary);
  box-shadow: var(--shadow-lg);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
  backdrop-filter: blur(18px) saturate(160%);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  animation: enChatFloat 3.2s ease-in-out infinite;
}
#enChatRobot:hover { border-color: var(--gold-border-strong); }
#enChatRobot:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
#enChatRobot .en-bot-head {
  position: absolute; left: 50%; top: 13px; width: 30px; height: 25px;
  transform: translateX(-50%); border-radius: 10px;
  background: linear-gradient(160deg, #d9b878, #9b7335);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.5);
}
#enChatRobot .en-bot-antenna {
  position: absolute; left: 50%; top: 7px; width: 2px; height: 8px;
  transform: translateX(-50%); background: var(--gold-text);
}
#enChatRobot .en-bot-antenna::after {
  content: ''; position: absolute; left: -3px; top: -4px; width: 8px; height: 8px;
  border-radius: 50%; background: var(--gold-text);
  box-shadow: 0 0 8px var(--gold-border-strong);
  animation: enChatPulse 1.6s ease-in-out infinite;
}
#enChatRobot .en-bot-eye {
  position: absolute; top: 22px; width: 5px; height: 5px; border-radius: 50%;
  background: #1c1c1e; animation: enChatBlink 4s infinite;
}
#enChatRobot .en-bot-eye.left { left: 20px; }
#enChatRobot .en-bot-eye.right { right: 20px; }
#enChatRobot .en-bot-body {
  position: absolute; left: 50%; bottom: 10px; width: 34px; height: 17px;
  transform: translateX(-50%); border-radius: 6px 6px 9px 9px;
  background: linear-gradient(180deg, var(--accent), var(--accent2));
  opacity: .9;
}

/* 机器人上方的提醒气泡：短句、两行以内，自动出现/消失 */
#enChatBubble {
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: calc(92px + env(safe-area-inset-bottom));
  z-index: 99979;
  box-sizing: border-box;
  max-width: 220px;
  padding: 9px 13px;
  border: 1px solid var(--glass-border);
  border-radius: 14px 14px 4px 14px;
  background: var(--surface-strong);
  color: var(--text-primary);
  font: 500 12.5px/1.55 var(--font-sans, -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif);
  text-align: left;
  box-shadow: var(--shadow-lg);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
  backdrop-filter: blur(18px) saturate(160%);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px) scale(.96);
  transform-origin: right bottom;
  transition: opacity .22s ease, transform .22s ease, visibility .22s ease;
  pointer-events: none;
}
#enChatBubble::after {
  content: '';
  position: absolute;
  right: 26px;
  bottom: -5px;
  width: 9px;
  height: 9px;
  background: var(--surface-strong);
  border-right: 1px solid var(--glass-border);
  border-bottom: 1px solid var(--glass-border);
  transform: rotate(45deg);
  border-bottom-right-radius: 2px;
}
#enChatBubble.show { opacity: 1; visibility: visible; transform: none; pointer-events: auto; }
#enChatBubble:hover { border-color: var(--gold-border-strong); }
#enChatBubble:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
#enChatBubble .en-chat-bubble-text { display: block; }
body.en-chat-open #enChatBubble { display: none; }

@keyframes enChatFloat { 0%,100%{transform:translateY(0)} 50%{transform:translateY(-6px)} }
@keyframes enChatBlink { 0%,46%,54%,100%{transform:scaleY(1)} 50%{transform:scaleY(.15)} }
@keyframes enChatPulse { 0%,100%{opacity:.6} 50%{opacity:1} }

#enChatMask {
  position: fixed; inset: 0; z-index: 99990;
  display: none; align-items: flex-end; justify-content: flex-end;
  padding: 16px; background: rgba(10, 14, 26, .18);
  -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
}
#enChatMask.show { display: flex; }
#enChatPanel {
  width: 380px; max-width: 100%; height: 620px; max-height: calc(100dvh - 120px);
  display: flex; flex-direction: column; overflow: hidden;
  border: 1px solid var(--glass-border); border-radius: 18px;
  background: var(--surface-strong); color: var(--text-primary);
  box-shadow: var(--shadow-lg); -webkit-backdrop-filter: blur(22px); backdrop-filter: blur(22px);
}
.en-chat-head { flex: none; display: flex; align-items: center; gap: 10px; padding: 13px 14px 11px; border-bottom: 1px solid var(--hairline); }
.en-chat-head-main { flex: 1; min-width: 0; }
.en-chat-title { font-size: 14px; font-weight: 750; }
.en-chat-status { margin-top: 2px; font-size: 11px; color: var(--text-muted); }
.en-chat-status.unlimited { color: var(--success-text); }
.en-chat-close { flex: none; width: 32px; height: 32px; border: 0; border-radius: 50%; background: var(--fill-1); color: var(--text-secondary); font-size: 16px; cursor: pointer; }
.en-chat-messages { flex: 1; min-height: 0; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; scroll-behavior: smooth; }
.en-chat-msg { max-width: 88%; padding: 9px 11px; border-radius: 13px; font-size: 12.5px; line-height: 1.72; white-space: pre-wrap; word-break: break-word; }
.en-chat-msg.user { align-self: flex-end; background: var(--accent-filled); color: #fff; border-bottom-right-radius: 4px; }
.en-chat-msg.assistant { align-self: flex-start; background: var(--fill-1); color: var(--text-primary); border-bottom-left-radius: 4px; }
.en-chat-msg.assistant .en-chat-p { margin: 0 0 7px; }
.en-chat-msg.assistant .en-chat-p:last-child { margin-bottom: 0; }
.en-chat-msg.assistant .en-chat-h { margin: 2px 0 6px; font-weight: 750; color: var(--text-primary); }
.en-chat-msg.assistant .en-chat-list { margin: 3px 0 7px; padding-left: 18px; }
.en-chat-msg.assistant .en-chat-list:last-child { margin-bottom: 0; }
.en-chat-msg.assistant .en-chat-list li { margin: 2px 0; padding-left: 1px; }
.en-chat-msg.assistant strong { font-weight: 750; color: var(--text-primary); }
.en-chat-msg.assistant em { font-style: italic; }
.en-chat-msg.assistant code { padding: 1px 5px; border-radius: 5px; background: var(--fill-2); color: var(--text-primary); font-family: var(--font-mono); font-size: 11.5px; }
.en-chat-msg.assistant .en-chat-code { margin: 5px 0 7px; padding: 8px 10px; overflow-x: auto; border-radius: 9px; background: var(--fill-2); white-space: pre-wrap; word-break: break-word; }
.en-chat-msg.assistant .en-chat-code code { padding: 0; background: transparent; font-size: 11px; line-height: 1.6; }
.en-chat-msg.error { align-self: stretch; max-width: 100%; color: var(--error-text); background: var(--error-soft); font-size: 11.5px; }
.en-chat-typing { align-self: flex-start; display: inline-flex; gap: 4px; padding: 11px 13px; border-radius: 13px; background: var(--fill-1); }
.en-chat-typing i { width: 5px; height: 5px; border-radius: 50%; background: var(--text-muted); animation: enChatTyping 1.2s infinite; }
.en-chat-typing i:nth-child(2) { animation-delay: .15s; }
.en-chat-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes enChatTyping { 0%,60%,100%{opacity:.3;transform:translateY(0)} 30%{opacity:1;transform:translateY(-2px)} }
.en-chat-suggestions { flex: none; display: flex; gap: 6px; overflow-x: auto; padding: 0 14px 10px; scrollbar-width: none; }
.en-chat-suggestions::-webkit-scrollbar { display: none; }
.en-chat-suggestion { flex: none; padding: 6px 9px; border: 1px solid var(--hairline); border-radius: 99px; background: var(--surface-solid); color: var(--text-secondary); font: inherit; font-size: 11px; cursor: pointer; }
.en-chat-suggestion:hover { border-color: var(--gold-border); color: var(--gold-text); }
.en-chat-lock { flex: none; margin: 0 14px 10px; padding: 10px 11px; border: 1px solid var(--gold-border); border-radius: 11px; background: var(--gold-bg); color: var(--gold-text); font-size: 11.5px; line-height: 1.6; }
.en-chat-lock[hidden] { display: none; }
.en-chat-lock button { display: block; width: 100%; height: 34px; margin-top: 7px; border: 0; border-radius: 8px; background: var(--accent-filled); color: #fff; font: inherit; font-size: 12px; font-weight: 700; cursor: pointer; }
.en-chat-form { flex: none; display: flex; gap: 7px; align-items: flex-end; padding: 10px 12px calc(11px + env(safe-area-inset-bottom)); border-top: 1px solid var(--hairline); }
#enChatInput { flex: 1; min-height: 38px; max-height: 100px; resize: none; padding: 9px 10px; border: 1px solid var(--hairline); border-radius: 10px; background: var(--input-bg); color: var(--text-primary); font: inherit; font-size: 13px; line-height: 1.5; outline: none; }
#enChatInput:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
#enChatSend { flex: none; height: 38px; padding: 0 13px; border: 0; border-radius: 10px; background: var(--accent-filled); color: #fff; font: inherit; font-size: 12px; font-weight: 700; cursor: pointer; }
#enChatSend:disabled { opacity: .45; cursor: not-allowed; }
.en-chat-foot { flex: none; padding: 0 12px 9px; color: var(--text-muted); font-size: 10.5px; text-align: center; }
body.en-chat-open { overflow: hidden; }
body.en-chat-open #enChatRobot { display: none; }

@media (max-width: 767px) {
  #enChatRobot { width: 54px; height: 54px; right: 14px; bottom: calc(72px + env(safe-area-inset-bottom)); border-radius: 17px; }
  #enChatRobot .en-bot-head { top: 11px; width: 27px; height: 23px; }
  #enChatRobot .en-bot-eye { top: 19px; }
  #enChatRobot .en-bot-eye.left { left: 17px; }
  #enChatRobot .en-bot-eye.right { right: 17px; }
  #enChatRobot .en-bot-body { bottom: 8px; width: 30px; height: 15px; }
  #enChatBubble { right: 14px; bottom: calc(136px + env(safe-area-inset-bottom)); max-width: 200px; padding: 8px 11px; font-size: 12px; }
  #enChatBubble::after { right: 22px; }
  #enChatMask { padding: 0; align-items: flex-end; }
  #enChatPanel { width: 100%; height: 90dvh; max-height: 90dvh; border-radius: 18px 18px 0 0; }
  .en-chat-msg { font-size: 13px; }
}
@media (prefers-reduced-motion: reduce) {
  #enChatRobot, #enChatRobot .en-bot-antenna::after, #enChatRobot .en-bot-eye { animation: none; }
  #enChatBubble { transition: none; }
}
