/* ============================================================
   AI 自动模式 - 样式（AI 自动模式 / 原始自动模式 / API Key / 聊天框）
   跟随游戏深浅色主题（body.darkmode）
   ============================================================ */

/* ---------- 模式选择弹窗 ---------- */
.ai-mode-pop {
  padding: 8px 4px 4px;
  text-align: center;
}
.ai-mode-title {
  font-size: 18px;
  font-weight: 700;
  margin: 4px 0 16px;
  color: #333;
}
body.darkmode .ai-mode-title { color: #eee; }
.ai-mode-sub {
  font-size: 13px;
  color: #888;
  margin: -10px 0 14px;
  line-height: 1.5;
}
body.darkmode .ai-mode-sub { color: #999; }
.ai-mode-btn {
  display: block;
  width: 100%;
  padding: 13px 16px;
  margin: 8px 0;
  border: 0;
  border-radius: 14px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  -webkit-appearance: none;
}
.ai-mode-ai {
  background: linear-gradient(135deg, #4f8cff, #7c5cff);
  color: #fff;
}
.ai-mode-orig {
  background: #f1f1f4;
  color: #333;
}
body.darkmode .ai-mode-orig { background: #2a2a2e; color: #eee; }
.ai-mode-btn:active { transform: scale(0.97); }

/* ---------- API Key 弹窗 ---------- */
.ai-key-pop {
  padding: 8px 4px 4px;
  text-align: center;
}
.ai-key-title {
  font-size: 18px;
  font-weight: 700;
  margin: 4px 0 14px;
  color: #333;
}
body.darkmode .ai-key-title { color: #eee; }
.ai-key-input {
  width: 100%;
  box-sizing: border-box;
  padding: 12px 14px;
  margin: 0 0 6px;
  border: 1px solid #dcdce0;
  border-radius: 12px;
  font-size: 14px;
  background: #fff;
  color: #333;
  outline: none;
}
body.darkmode .ai-key-input {
  border-color: #3a3a40;
  background: #222226;
  color: #eee;
}
.ai-key-hint {
  font-size: 12px;
  color: #999;
  margin: 4px 0 10px;
  text-align: left;
  line-height: 1.6;
}
body.darkmode .ai-key-hint { color: #777; }

/* ---------- 聊天面板 ---------- */
#ai-chat {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(560px, 100%);
  z-index: 990;
  display: none;
  flex-direction: column;
  background: rgba(250, 250, 252, 0.97);
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -6px 30px rgba(0, 0, 0, 0.18);
  overflow: hidden;
  font-family: inherit;
}
body.darkmode #ai-chat {
  background: rgba(24, 24, 28, 0.97);
}
#ai-chat.ai-open { display: flex; }
#ai-chat.ai-collapsed #ai-chat-msgs,
#ai-chat.ai-collapsed #ai-chat-inputrow { display: none; }

.ai-chat-head {
  display: flex;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}
body.darkmode .ai-chat-head { border-bottom-color: rgba(255, 255, 255, 0.08); }
.ai-chat-title {
  flex: 1;
  font-size: 15px;
  font-weight: 700;
  color: #333;
  display: flex;
  align-items: center;
  gap: 8px;
}
body.darkmode .ai-chat-title { color: #eee; }
.ai-chat-title .ai-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #34c759;
  display: inline-block;
}
.ai-chat-key {
  font-size: 12px;
  color: #4f8cff;
  padding: 4px 10px;
  border: 1px solid rgba(79, 140, 255, 0.4);
  border-radius: 10px;
  cursor: pointer;
  margin-right: 8px;
}
.ai-chat-close {
  font-size: 16px;
  color: #999;
  padding: 2px 6px;
  cursor: pointer;
}
.ai-chat-close:active { transform: scale(0.9); }

#ai-chat-msgs {
  max-height: 32vh;
  min-height: 90px;
  overflow-y: auto;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  -webkit-overflow-scrolling: touch;
}
.ai-msg {
  max-width: 86%;
  padding: 9px 12px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.55;
  word-break: break-word;
  white-space: pre-wrap;
}
.ai-msg-user {
  align-self: flex-end;
  background: #4f8cff;
  color: #fff;
  border-bottom-right-radius: 4px;
}
.ai-msg-ai {
  align-self: flex-start;
  background: #ececf1;
  color: #333;
  border-bottom-left-radius: 4px;
}
body.darkmode .ai-msg-ai { background: #2c2c32; color: #eee; }
.ai-msg-ai.ai-err { background: #ffe3e3; color: #b3261e; }
body.darkmode .ai-msg-ai.ai-err { background: #3a2226; color: #ff9b8f; }

#ai-chat-inputrow {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid rgba(0, 0, 0, 0.06);
}
body.darkmode #ai-chat-inputrow { border-top-color: rgba(255, 255, 255, 0.08); }
#ai-chat-input {
  flex: 1;
  min-width: 0;
  padding: 10px 14px;
  border: 1px solid #dcdce0;
  border-radius: 20px;
  font-size: 14px;
  background: #fff;
  color: #333;
  outline: none;
}
body.darkmode #ai-chat-input {
  border-color: #3a3a40;
  background: #222226;
  color: #eee;
}
#ai-chat-send {
  padding: 10px 18px;
  border: 0;
  border-radius: 20px;
  background: linear-gradient(135deg, #4f8cff, #7c5cff);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
#ai-chat-send:disabled { opacity: 0.5; }

/* ---------- 快捷按钮行 ---------- */
.ai-chat-quick {
  display: flex;
  gap: 8px;
  padding: 0 12px 8px;
}
.ai-chat-quick button {
  flex: 1;
  padding: 8px 0;
  border: 1px solid rgba(79, 140, 255, 0.35);
  border-radius: 14px;
  background: rgba(79, 140, 255, 0.08);
  color: #4f8cff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  -webkit-appearance: none;
}
body.darkmode .ai-chat-quick button {
  border-color: rgba(120, 160, 255, 0.4);
  background: rgba(90, 130, 255, 0.12);
  color: #7fa8ff;
}
.ai-chat-quick button:active { transform: scale(0.96); }

/* ---------- 设置弹窗里的 AI 密钥行 ---------- */
#param-aikey .ai-key-set {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 86px;
  margin-left: auto;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  background: #f1f1f4;
  color: #333;
}
body.darkmode #param-aikey .ai-key-set { background: #2a2a2e; color: #eee; }
#param-aikey .ai-key-set.ai-has {
  background: #e4f3e8;
  color: #1f7a3d;
}
body.darkmode #param-aikey .ai-key-set.ai-has { background: #1e3326; color: #5fd17f; }
