:root {
  --hemi-blue: #1432f5;
  --hemi-blue-soft: #eef1ff;
  --hemi-ink: #1b2a41;
  --hemi-muted: #6b7688;
  --hemi-line: #dce4f0;
  --hemi-panel: rgba(255, 255, 255, .96);
  --hemi-shadow: 0 18px 54px rgba(22, 38, 66, .18);
  --hemi-alert: #e5a127;
  --hemi-good: #2ba471;
}

.hemi-companion {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 2147482000;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--hemi-ink);
  transition: transform .18s ease, opacity .18s ease;
}

.hemi-companion * {
  box-sizing: border-box;
}

.hemi-orb {
  width: 92px;
  height: 92px;
  padding: 0;
  border: 0;
  border-radius: 30px;
  background: transparent;
  box-shadow: none;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}

.hemi-companion[data-mode="minimized"] .hemi-orb,
.hemi-companion[data-mode="snoozed"] .hemi-orb,
.hemi-companion[data-mode="hidden"] .hemi-orb {
  opacity: 0;
  transform: translateY(8px) scale(.82);
  pointer-events: none;
}

.hemi-orb:hover {
  transform: translateY(-1.5px);
  border-color: transparent;
  box-shadow: none;
}

.hemi-orb:active {
  transform: translateY(0) scale(.98);
}

.hemi-orb-inner {
  width: 88px;
  height: 88px;
  position: relative;
  display: grid;
  place-items: center;
}

.hemi-sprite {
  width: 92px;
  height: 92px;
  display: block;
  overflow: hidden;
  filter: drop-shadow(0 12px 18px rgba(27, 42, 65, .18));
  user-select: none;
  transform-origin: 50% 82%;
  will-change: transform;
}

.hemi-sprite-strip {
  width: 800%;
  height: 100%;
  max-width: none;
  display: block;
  object-fit: fill;
  transform: translateX(0);
  animation: hemi-sprite-play var(--hemi-duration, 2.4s) steps(7, end) infinite;
  will-change: transform;
  -webkit-user-drag: none;
}

/* alert plays continuously so Hemi doesn't freeze */

/* peek state: no orb bounce — sprite animation is enough */

.hemi-status-dot {
  position: absolute;
  right: 8px;
  top: 12px;
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--hemi-blue);
  border: 2px solid #fff;
  box-shadow: 0 0 0 4px rgba(20, 50, 245, .13);
}

.hemi-companion[data-state="alert"] .hemi-status-dot {
  background: var(--hemi-alert);
  box-shadow: 0 0 0 4px rgba(229, 161, 39, .14);
  /* no pulse — status dot is static to avoid distraction */
}

.hemi-companion[data-state="done"] .hemi-status-dot {
  background: var(--hemi-good);
  box-shadow: 0 0 0 4px rgba(43, 164, 113, .14);
}

.hemi-panel {
  position: absolute;
  right: 0;
  bottom: 102px;
  width: min(372px, calc(100vw - 32px));
  border: 1px solid var(--hemi-line);
  border-radius: 18px;
  background: var(--hemi-panel);
  box-shadow: var(--hemi-shadow);
  overflow: hidden;
  opacity: 0;
  transform: translateY(10px) scale(.98);
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
  backdrop-filter: blur(18px);
  display: flex;
  flex-direction: column;
}
.hemi-resize-handle {
  flex: 0 0 6px;
  cursor: ns-resize;
  border-radius: 18px 18px 0 0;
}
.hemi-resize-handle:hover,
.hemi-resize-handle.dragging {
  background: rgba(99,126,234,.18);
}

.hemi-companion.is-open .hemi-panel {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.hemi-companion[data-mode="minimized"] .hemi-panel,
.hemi-companion[data-mode="snoozed"] .hemi-panel,
.hemi-companion[data-mode="hidden"] .hemi-panel {
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px) scale(.98);
}

.hemi-panel-head {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 14px 14px 12px;
  border-bottom: 1px solid var(--hemi-line);
}

.hemi-mini {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: transparent;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}

.hemi-mini .hemi-sprite {
  width: 46px;
  height: 46px;
  filter: drop-shadow(0 5px 9px rgba(27, 42, 65, .13));
}

.hemi-title-wrap {
  min-width: 0;
  flex: 1;
}

.hemi-icon-btn {
  appearance: none;
  width: 30px;
  height: 30px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--hemi-muted);
  cursor: pointer;
  font-size: 17px;
  line-height: 1;
}

.hemi-icon-btn:hover {
  background: #f3f6fb;
  color: var(--hemi-ink);
}

.hemi-title {
  font-size: 14px;
  font-weight: 750;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hemi-subtitle {
  margin-top: 2px;
  color: var(--hemi-muted);
  font-size: 12px;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hemi-close {
  appearance: none;
  width: 30px;
  height: 30px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--hemi-muted);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}

.hemi-close:hover {
  background: #f3f6fb;
  color: var(--hemi-ink);
}

.hemi-panel-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 14px 14px 0;
  position: relative;
}

.hemi-panel-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--hemi-muted);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  display: grid;
  place-items: center;
}

.hemi-panel-close:hover {
  background: #f3f6fb;
  color: var(--hemi-ink);
}

.hemi-summary {
  margin: 0;
  color: #314158;
  font-size: 13px;
  line-height: 1.65;
}

.hemi-toast {
  display: none;
  margin: 0 0 12px;
  border: 1px solid rgba(20,50,245,.22);
  border-radius: 12px;
  background: #f7faff;
  padding: 10px 11px;
  color: #2b3e5c;
  font-size: 12.5px;
  line-height: 1.55;
}

.hemi-toast.is-visible {
  display: block;
}

.hemi-findings {
  display: grid;
  gap: 8px;
  margin: 13px 0 0;
  padding: 0;
  list-style: none;
}

.hemi-findings li {
  position: relative;
  padding: 9px 10px 9px 29px;
  border: 1px solid #edf1f7;
  border-radius: 12px;
  background: #fff;
  color: #4a5870;
  font-size: 12.5px;
  line-height: 1.45;
}

.hemi-findings li::before {
  content: "";
  position: absolute;
  left: 11px;
  top: 14px;
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--hemi-blue);
  opacity: .72;
}

.hemi-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.hemi-action {
  appearance: none;
  border: 1px solid rgba(20,50,245,.28);
  border-radius: 10px;
  background: #fff;
  color: var(--hemi-blue);
  cursor: pointer;
  min-height: 34px;
  padding: 0 11px;
  font-size: 12.5px;
  font-weight: 700;
}

.hemi-action:hover {
  background: var(--hemi-blue-soft);
}

.hemi-wake-tab {
  position: absolute;
  right: 0;
  bottom: 5px;
  min-width: 48px;
  height: 34px;
  border: 1px solid rgba(20, 50, 245, .22);
  border-radius: 999px;
  background: rgba(255,255,255,.94);
  box-shadow: 0 10px 28px rgba(31, 56, 96, .16);
  color: var(--hemi-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: center;
  padding: 0 10px;
  opacity: 0;
  transform: translateY(8px) scale(.92);
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease, border-color .18s ease;
}

.hemi-wake-tab:hover {
  border-color: rgba(20, 50, 245, .48);
  transform: translateY(0) scale(1);
}

.hemi-wake-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--hemi-blue);
  box-shadow: 0 0 0 4px rgba(20, 50, 245, .12);
}

.hemi-wake-text {
  font-size: 11px;
  font-weight: 750;
  letter-spacing: .01em;
}

.hemi-companion[data-mode="minimized"] .hemi-wake-tab,
.hemi-companion[data-mode="snoozed"] .hemi-wake-tab,
.hemi-companion[data-mode="hidden"] .hemi-wake-tab {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.hemi-companion[data-mode="snoozed"] .hemi-wake-dot {
  background: #9aa8ba;
  box-shadow: 0 0 0 4px rgba(154, 168, 186, .13);
}

.hemi-companion[data-mode="hidden"] .hemi-wake-tab {
  min-width: 32px;
  width: 32px;
  padding: 0;
}

.hemi-companion[data-mode="hidden"] .hemi-wake-text {
  display: none;
}

@keyframes hemi-sprite-play {
  to { transform: translateX(-87.5%); }
}

@keyframes hemi-peek-nudge {
  0%, 100% { transform: translateY(3px); }
  50% { transform: translateY(-1px); }
}

@keyframes hemi-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.18); opacity: .82; }
}

@media (prefers-reduced-motion: reduce) {
  .hemi-sprite-strip,
  .hemi-orb-inner,
  .hemi-status-dot {
    animation: none !important;
  }
  .hemi-panel,
  .hemi-orb,
  .hemi-companion,
  .hemi-wake-tab {
    transition: none;
  }
}

@media (max-width: 640px) {
  .hemi-companion {
    right: 14px;
    bottom: 14px;
  }
  .hemi-orb {
    width: 78px;
    height: 78px;
    border-radius: 24px;
  }
  .hemi-orb-inner {
    width: 74px;
    height: 74px;
  }
  .hemi-sprite {
    width: 78px;
    height: 78px;
  }
  .hemi-panel {
    bottom: 88px;
  }
}

/* ── Topbar layout ──────────────────────────────────────────────────── */
.hemi-companion[data-layout="topbar"] {
  position: relative;
  right: auto;
  bottom: auto;
  z-index: auto;
  display: inline-flex;
  align-items: center;
  transition: none;
}

.hemi-topbar-btn {
  position: relative;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--hemi-line);
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition: border-color .15s, background .15s;
}

.hemi-topbar-btn:hover {
  border-color: var(--hemi-blue);
  background: var(--hemi-blue-soft);
}

.hemi-companion[data-layout="topbar"][data-state="alert"] .hemi-topbar-btn {
  border-color: var(--hemi-alert);
  background: rgba(229, 161, 39, .08);
}

.hemi-companion[data-layout="topbar"] .hemi-sprite {
  width: 28px;
  height: 28px;
  filter: drop-shadow(0 1px 3px rgba(27, 42, 65, .14));
}

.hemi-companion[data-layout="topbar"] .hemi-status-dot {
  right: -3px;
  top: -3px;
  width: 8px;
  height: 8px;
  border-width: 1.5px;
}

.hemi-topbar-x {
  position: absolute;
  top: -5px;
  right: -5px;
  width: 15px;
  height: 15px;
  border-radius: 999px;
  border: 1px solid var(--hemi-line);
  background: #fff;
  color: var(--hemi-muted);
  font-size: 10px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  display: grid;
  place-items: center;
  padding: 0;
  transition: opacity .15s;
  pointer-events: none;
  box-shadow: 0 1px 4px rgba(0,0,0,.1);
}

.hemi-topbar-btn:hover .hemi-topbar-x {
  opacity: 1;
  pointer-events: auto;
}

/* ── Bubble ─────────────────────────────────────────────────────────── */
.hemi-bubble {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: min(300px, calc(100vw - 40px));
  background: var(--hemi-panel);
  border: 1px solid var(--hemi-line);
  border-radius: 14px;
  box-shadow: var(--hemi-shadow);
  backdrop-filter: blur(18px);
  opacity: 0;
  transform: translateY(-6px) scale(.97);
  pointer-events: none;
  transition: opacity .16s ease, transform .16s ease;
  z-index: 500;
}

.hemi-bubble::before {
  content: '';
  position: absolute;
  top: -5px;
  right: 13px;
  width: 9px;
  height: 9px;
  background: var(--hemi-panel);
  border-top: 1px solid var(--hemi-line);
  border-left: 1px solid var(--hemi-line);
  transform: rotate(45deg);
  border-radius: 1px;
}

.hemi-companion[data-layout="topbar"].is-open .hemi-bubble {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.hemi-bubble-body {
  padding: 12px 14px;
}

.hemi-bubble-body .hemi-summary {
  margin: 0;
  font-size: 13px;
  line-height: 1.6;
  color: #314158;
}

.hemi-bubble-body .hemi-findings {
  margin-top: 10px;
}

.hemi-bubble-body .hemi-actions {
  margin-top: 10px;
}

.hemi-bubble-body .hemi-toast {
  margin-bottom: 10px;
}

/* hidden/snoozed/minimized → hide the whole topbar element (but NOT the ctrl button) */
.hemi-companion[data-layout="topbar"]:not(.hemi-ctrl)[data-mode="hidden"],
.hemi-companion[data-layout="topbar"]:not(.hemi-ctrl)[data-mode="snoozed"],
.hemi-companion[data-layout="topbar"]:not(.hemi-ctrl)[data-mode="minimized"] {
  display: none;
}

/* Control button: always visible so user can wake Hemi; dim when sleeping */
.hemi-companion.hemi-ctrl[data-mode="hidden"],
.hemi-companion.hemi-ctrl[data-mode="snoozed"],
.hemi-companion.hemi-ctrl[data-mode="minimized"] {
  opacity: 0.4;
}

/* Control button: always neutral — no state-based color/animation */
.hemi-companion.hemi-ctrl .hemi-topbar-btn {
  border-color: var(--hemi-line) !important;
  background: #fff !important;
}
.hemi-companion.hemi-ctrl .hemi-topbar-btn:hover {
  border-color: #c5cfe0 !important;
  background: #f5f7fa !important;
}

.hemi-ctrl-icon {
  width: 24px;
  height: 24px;
  object-fit: contain;
  border-radius: 4px;
  display: block;
}

/* ── Chat input ──────────────────────────────────────────────────────── */
.hemi-history {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-bottom: 10px;
  scroll-behavior: smooth;
  scrollbar-gutter: stable;
  padding-right: 2px;
}

.hemi-msg {
  max-width: 88%;
  font-size: 13px;
  line-height: 1.55;
  padding: 8px 11px;
  border-radius: 12px;
  word-break: break-word;
}

.hemi-msg--hemi {
  align-self: flex-start;
  background: #f0f3ff;
  color: #2b3e5c;
  border-bottom-left-radius: 4px;
}

.hemi-msg--user {
  align-self: flex-end;
  background: var(--hemi-blue);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.hemi-name-tag {
  color: #c05e00;
  border-radius: 3px;
  padding: 0 2px;
  cursor: pointer;
  text-decoration: underline dotted rgba(224,112,0,.5);
  transition: background .15s;
}
.hemi-name-tag:hover { background: rgba(224,112,0,.12); }


.hemi-msg-ctx {
  align-self: center;
  font-size: 11px;
  color: var(--hemi-muted);
  padding: 2px 0;
  opacity: 0.7;
}

.hemi-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 4px 0 6px 0;
}

.hemi-chip {
  border: 1px solid var(--hemi-blue);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 12px;
  cursor: pointer;
  background: transparent;
  color: var(--hemi-blue);
  transition: background .15s, color .15s;
  font-family: inherit;
}

.hemi-chip:hover {
  background: var(--hemi-blue);
  color: #fff;
}

.hemi-chat {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 10px 0 14px;
  border-top: 1px solid var(--hemi-line);
}

.hemi-chat-input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--hemi-line);
  border-radius: 10px;
  padding: 7px 10px;
  font-size: 12.5px;
  font-family: inherit;
  outline: none;
  background: #fff;
  color: var(--hemi-ink);
  height: 34px;
}

.hemi-chat-input:focus {
  border-color: var(--hemi-blue);
}

.hemi-chat-input:disabled {
  opacity: 0.5;
}

.hemi-chat-send {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border: none;
  border-radius: 9px;
  background: var(--hemi-blue);
  color: #fff;
  font-size: 15px;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: opacity .15s;
}

.hemi-chat-send:hover { opacity: 0.82; }

.hemi-mic-btn {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border: 1px solid var(--hemi-line);
  border-radius: 9px;
  background: transparent;
  color: var(--hemi-ink);
  font-size: 15px;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background .15s, border-color .15s;
}
.hemi-mic-btn:hover { border-color: var(--hemi-blue); }
.hemi-mic-btn.recording {
  background: #e03535;
  border-color: #e03535;
  color: #fff;
  animation: hemiMicPulse 1.2s infinite;
}
@keyframes hemiMicPulse {
  0%   { box-shadow: 0 0 0 0 rgba(224,53,53,.5); }
  70%  { box-shadow: 0 0 0 8px rgba(224,53,53,0); }
  100% { box-shadow: 0 0 0 0 rgba(224,53,53,0); }
}

/* ── Action Cards ── */
.hemi-action-card {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  margin: 4px 0;
  background: var(--hemi-blue-soft);
  border: 1px solid rgba(20,50,245,.15);
  border-radius: 10px;
  font-size: 12.5px;
}
.hemi-action-card-label {
  flex: 1;
  color: var(--hemi-ink);
  line-height: 1.4;
}
.hemi-action-exec-btn {
  flex-shrink: 0;
  padding: 4px 14px;
  background: #e07000;
  color: #fff;
  border: none;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s, opacity .15s;
  white-space: nowrap;
  letter-spacing: .2px;
}
.hemi-action-exec-btn:hover:not(:disabled) { background: #c05e00; }
.hemi-action-exec-btn:disabled { opacity: .6; cursor: default; }
.hemi-action-exec-btn.hemi-action-exec-done {
  background: #18a058;
  pointer-events: none;
}

/* ── 手机端悬浮态：头像居中放大，不再贴右下角 ── */
@media (max-width: 700px) {
  .hemi-companion:not(.hemi-ctrl) {
    right: auto !important;
    left: 50% !important;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 14px) !important;
    transform: translateX(-50%) !important;
  }
  .hemi-orb { width: 164px !important; height: 164px !important; }
  .hemi-orb-inner { width: 156px !important; height: 156px !important; }
  .hemi-sprite { width: 160px !important; height: 160px !important; }
  .hemi-panel {
    right: auto !important;
    left: 50% !important;
    /* 头像放大到 164px 后，面板底部原来的 88px 偏移不够，会跟头像视觉重叠、
       盖住底部输入框——挪到头像顶部之上再留一点间隙 */
    bottom: calc(env(safe-area-inset-bottom, 0px) + 14px + 164px - 40px) !important;
    /* 面板原来没有任何高度上限，聊天记录越多面板就一直往上长，长到能顶到屏幕最上面，
       输入框也跟着看不见。加个上限，且必须留出到顶部的余量——绝不能贴到顶。
       历史消息区（.hemi-history）本来就是 overflow-y:auto，只是外层一直没有真正的
       高度天花板让它触发滚动，这里给了天花板之后它会自己滚动，不用再改内部结构。 */
    max-height: calc(100vh - env(safe-area-inset-bottom, 0px) - env(safe-area-inset-top, 0px) - 14px - 164px - 12px - 72px) !important;
    transform: translateX(-50%) translateY(10px) scale(.98) !important;
  }
  .hemi-companion:not(.hemi-ctrl).is-open .hemi-panel {
    transform: translateX(-50%) translateY(0) scale(1) !important;
  }

  /* 深色悬浮面板，不是桌面那套浅色卡片 */
  .hemi-panel {
    background: #101012 !important;
    border-color: rgba(255,255,255,.12) !important;
    box-shadow: 0 20px 40px -12px rgba(0,0,0,.5) !important;
  }
  .hemi-msg--hemi { background: rgba(255,255,255,.08) !important; color: rgba(255,255,255,.9) !important; }
  .hemi-msg-ctx { color: rgba(255,255,255,.4) !important; }
  .hemi-chat { border-top-color: rgba(255,255,255,.12) !important; }
  .hemi-chat-input {
    background: rgba(255,255,255,.08) !important;
    color: #fff !important;
    border-color: rgba(255,255,255,.16) !important;
  }
  .hemi-chat-input::placeholder { color: rgba(255,255,255,.35) !important; }
  .hemi-mic-btn { border-color: rgba(255,255,255,.2) !important; color: #fff !important; }
}
