:root {
  --lefei-float-size: 56px;
  --lefei-float-right: 24px;
  --lefei-float-bottom: 24px;
  --lefei-float-gap: 12px;
}

.lefei-ai-chat {
  --lefei-ai-chat-green: #0d352e;
  --lefei-ai-chat-paper: #fbf6f1;
  --lefei-ai-chat-paper-2: #f2ebe3;
  --lefei-ai-chat-ink: #0d352e;
  --lefei-ai-chat-ink-soft: #587068;
  --lefei-ai-chat-yellow: #efb300;
  --lefei-ai-chat-white: #fffdf9;
  --lefei-ai-chat-radius: 22px;
  position: fixed;
  right: var(--lefei-float-right);
  bottom: calc(var(--lefei-float-bottom) + var(--lefei-float-size) + var(--lefei-float-gap));
  z-index: 9990;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
  color: var(--lefei-ai-chat-ink);
}

.lefei-ai-chat__launcher {
  width: var(--lefei-float-size);
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--lefei-ai-chat-yellow);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  border-radius: 22px;
}

.lefei-ai-chat__portrait {
  position: relative;
  overflow: hidden;
  box-sizing: border-box;
  width: var(--lefei-float-size);
  height: var(--lefei-float-size);
  flex: 0 0 auto;
  border: 2px solid var(--lefei-ai-chat-green);
  border-radius: 50%;
  background: var(--lefei-ai-chat-paper);
  box-shadow: 0 12px 28px rgba(13, 53, 46, 0.28);
}

.lefei-ai-chat__label {
  display: block;
  padding: 3px 11px;
  border-radius: 20px;
  background: var(--lefei-ai-chat-green);
  color: var(--lefei-ai-chat-yellow);
  box-shadow: 0 0 0 1px rgba(173, 197, 175, 0.4), 0 4px 10px rgba(13, 53, 46, 0.1);
  font-size: 12px;
  font-weight: 650;
  line-height: 18px;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.lefei-ai-chat__launcher:hover,
.lefei-ai-chat__launcher:focus-visible {
  filter: brightness(1.08);
  outline: none;
}

.lefei-ai-chat__launcher:focus-visible .lefei-ai-chat__portrait {
  box-shadow: 0 0 0 4px rgba(239, 179, 0, 0.22), 0 12px 28px rgba(13, 53, 46, 0.28);
}

.lefei-ai-chat__avatar {
  position: absolute;
  top: 0;
  left: 50%;
  display: block;
  width: 165%;
  max-width: none;
  height: auto;
  transform: translateX(-50%);
  pointer-events: none;
  user-select: none;
}

.lefei-ai-chat.is-open .lefei-ai-chat__launcher {
  display: none;
}

.lefei-ai-chat__panel {
  width: min(420px, calc(100vw - 32px));
  height: min(600px, calc(100vh - 140px));
  min-height: min(360px, calc(100vh - 140px));
  max-height: calc(100vh - 140px);
  display: none;
  flex-direction: column;
  overflow: hidden;
  border-radius: var(--lefei-ai-chat-radius);
  background: var(--lefei-ai-chat-paper);
  box-shadow: 0 28px 75px rgba(8, 37, 31, 0.18);
}

.lefei-ai-chat.is-open .lefei-ai-chat__panel {
  display: flex;
}

.lefei-ai-chat__header {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: var(--lefei-ai-chat-green);
  color: var(--lefei-ai-chat-white);
  cursor: grab;
  user-select: none;
  touch-action: none;
}

.lefei-ai-chat__identity {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.lefei-ai-chat__heading {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.lefei-ai-chat__subtitle {
  color: rgba(255, 253, 249, 0.72);
  font-size: 11px;
  line-height: 1.5;
}

.lefei-ai-chat__portrait--header {
  width: 40px;
  height: 40px;
  border: 1px solid rgba(255, 253, 249, 0.45);
  box-shadow: none;
}

.lefei-ai-chat__portrait--message {
  width: 32px;
  height: 32px;
  border: 1px solid rgba(13, 53, 46, 0.15);
  box-shadow: none;
}

.lefei-ai-chat.is-dragging .lefei-ai-chat__header {
  cursor: grabbing;
}

.lefei-ai-chat__title {
  margin: 0;
  font-family: inherit;
  font-size: 15px;
  font-weight: 650;
  line-height: 1.4;
  letter-spacing: 0.02em;
}

.lefei-ai-chat__close {
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  color: var(--lefei-ai-chat-yellow);
  background: transparent;
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
}

.lefei-ai-chat__close:hover,
.lefei-ai-chat__close:focus-visible {
  background: rgba(255, 253, 249, 0.1);
  outline: none;
}

.lefei-ai-chat__messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--lefei-ai-chat-paper);
}

.lefei-ai-chat__message {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  width: 100%;
}

.lefei-ai-chat__message--user {
  justify-content: flex-end;
}

.lefei-ai-chat__message--assistant .lefei-ai-chat__bubble {
  max-width: calc(100% - 40px);
}

.lefei-ai-chat__bubble {
  max-width: 88%;
  padding: 10px 12px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.lefei-ai-chat__bubble--user {
  color: var(--lefei-ai-chat-white);
  background: var(--lefei-ai-chat-green);
  border-bottom-right-radius: 6px;
}

.lefei-ai-chat__bubble--assistant {
  color: var(--lefei-ai-chat-ink);
  background: var(--lefei-ai-chat-paper-2);
  border-bottom-left-radius: 6px;
}

.lefei-ai-chat__bubble a {
  color: var(--lefei-ai-chat-green);
  font-weight: 650;
}

.lefei-ai-chat__form {
  display: flex;
  flex: 0 0 auto;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid rgba(13, 53, 46, 0.12);
  background: var(--lefei-ai-chat-white);
}

.lefei-ai-chat__input {
  flex: 1;
  min-height: 44px;
  max-height: 96px;
  resize: none;
  padding: 10px 12px;
  border: 1px solid rgba(13, 53, 46, 0.16);
  border-radius: 14px;
  background: var(--lefei-ai-chat-paper);
  color: var(--lefei-ai-chat-ink);
  font: inherit;
}

.lefei-ai-chat__input:focus {
  outline: 2px solid rgba(13, 53, 46, 0.28);
  outline-offset: 1px;
}

.lefei-ai-chat__send {
  flex: 0 0 auto;
  min-width: 72px;
  border: 0;
  border-radius: 14px;
  padding: 0 14px;
  background: var(--lefei-ai-chat-green);
  color: var(--lefei-ai-chat-yellow);
  font: inherit;
  font-weight: 650;
  cursor: pointer;
}

.lefei-ai-chat__send:hover,
.lefei-ai-chat__send:focus-visible {
  filter: brightness(1.08);
  outline: none;
}

.lefei-ai-chat__send:disabled,
.lefei-ai-chat__input:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* Keep every page's two floating actions on one shared grid. */
.back-top,
.st_button {
  position: fixed !important;
  right: var(--lefei-float-right) !important;
  bottom: var(--lefei-float-bottom) !important;
  z-index: 10000 !important;
  width: var(--lefei-float-size) !important;
  height: var(--lefei-float-size) !important;
  min-width: var(--lefei-float-size) !important;
  min-height: var(--lefei-float-size) !important;
  margin: 0 !important;
  padding: 0 !important;
  display: grid !important;
  place-items: center !important;
  box-sizing: border-box !important;
  border: 0 !important;
  border-radius: 50% !important;
  background: transparent !important;
  appearance: none;
  -webkit-appearance: none;
  color: transparent;
  line-height: 0;
  cursor: pointer;
  overflow: hidden;
  outline: none;
}

.back-top {
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px);
  transition: opacity .25s ease, visibility .25s ease, transform .25s ease;
}

.back-top.is-visible {
  opacity: 1;
  visibility: visible;
  transform: none;
}

.back-top:focus-visible,
.st_button:focus-visible {
  outline: 3px solid rgba(239, 179, 0, .78);
  outline-offset: 3px;
}

.st_button > .icon-embed-xxsmall {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
}

.back-top svg,
.st_button svg {
  width: var(--lefei-float-size) !important;
  height: var(--lefei-float-size) !important;
  display: block;
}

.lefei-mobile-tools-toggle {
  display: none;
}

@media (max-width: 900px) {
  :root {
    --lefei-float-right: 16px;
    --lefei-float-bottom: 16px;
  }

  .lefei-ai-chat {
    right: var(--lefei-float-right);
    bottom: calc(var(--lefei-float-bottom) + var(--lefei-float-size) + var(--lefei-float-gap));
  }
}

@media (max-width: 640px) {
  .lefei-tools-ready:not(.lefei-tools-open) .lefei-ai-chat,
  .lefei-tools-ready:not(.lefei-tools-open) .back-top,
  .lefei-tools-ready:not(.lefei-tools-open) .st_button {
    visibility: hidden !important;
    pointer-events: none;
  }

  .lefei-mobile-tools-toggle {
    position: fixed;
    right: 0;
    bottom: 16px;
    z-index: 10001;
    display: block;
    width: 28px;
    min-height: 52px;
    padding: 5px;
    border: 0;
    border-radius: 12px 0 0 12px;
    background: #0d352e;
    color: #efb300;
    font: 600 12px/1.3 Inter, "PingFang SC", "Microsoft YaHei", sans-serif;
    cursor: pointer;
  }

  .lefei-mobile-tools-toggle:focus-visible {
    outline: 3px solid #efb300;
    outline-offset: -3px;
  }

  .lefei-tools-open .lefei-mobile-tools-toggle {
    bottom: 176px;
  }

  .lefei-ai-chat.is-open ~ .lefei-mobile-tools-toggle {
    display: none;
  }

  .lefei-ai-chat__panel {
    width: calc(100vw - 24px);
    height: min(70vh, 560px);
    min-height: 0;
    max-height: calc(100vh - 112px);
  }

  .lefei-ai-chat__header {
    cursor: default;
    touch-action: auto;
  }
}
