/* Popeye W1 — Mathreex branding (aligned with local/popeye) */
#popeye-root {
  --popeye-ink: #2b2d42;
  --popeye-black: #000000;
  --popeye-white: #ffffff;
  --popeye-accent: #ef233c;
  --popeye-user-bubble: #dce1e9;
  --popeye-composer: #f6ecee;
  --popeye-shadow: 0 14px 42px rgba(0, 0, 0, 0.28);
  font-family: "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
}

#popeye-root * {
  box-sizing: border-box;
}

.popeye-launcher {
  appearance: none;
  -webkit-appearance: none;
  position: fixed;
  bottom: max(1.5rem, env(safe-area-inset-bottom));
  right: max(1.5rem, env(safe-area-inset-right));
  width: 4rem;
  height: 4rem;
  min-width: 4rem;
  min-height: 4rem;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--popeye-black);
  box-shadow: var(--popeye-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  cursor: pointer;
  z-index: 99999;
  line-height: 0;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.popeye-launcher:hover,
.popeye-launcher:focus {
  transform: translateY(-2px) scale(1.03);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.36);
  outline: none;
  background: var(--popeye-black);
}

.popeye-launcher img {
  width: 72%;
  height: 72%;
  object-fit: contain;
  object-position: center center;
  /* Optical nudge: asset face sits slightly high/left in the circle. */
  transform: translate(1px, 2px);
}

.popeye-launcher.is-shaking {
  animation: popeye-shake 0.5s;
}

@keyframes popeye-shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-3px); }
  40%, 80% { transform: translateX(3px); }
}

.popeye-panel {
  position: fixed;
  bottom: max(1.5rem, env(safe-area-inset-bottom));
  right: max(1.5rem, env(safe-area-inset-right));
  width: min(23.75rem, calc(100vw - 2rem));
  height: min(35rem, calc(100vh - 3rem));
  background: var(--popeye-white);
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 10px;
  box-shadow: var(--popeye-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 99999;
}

.popeye-panel.is-minimized {
  height: auto;
}

.popeye-header {
  background: var(--popeye-black);
  color: var(--popeye-white);
  padding: 0.7rem 0.85rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.popeye-header-left {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
}

.popeye-avatar-wrap {
  position: relative;
  flex-shrink: 0;
}

.popeye-avatar {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 50%;
  background: var(--popeye-white);
  border: 0;
  padding: 2px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
}

.popeye-avatar img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center center;
}

.popeye-online {
  display: none;
}

.popeye-title {
  font-weight: 700;
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  line-height: 1.25;
}

.popeye-subtitle {
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  opacity: 0.85;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.popeye-header-actions {
  display: flex;
  gap: 0.25rem;
}

.popeye-icon-btn {
  background: transparent;
  border: 0;
  color: var(--popeye-white);
  width: 2rem;
  height: 2rem;
  border-radius: 0;
  cursor: pointer;
  font-size: 1.35rem;
  line-height: 1;
  opacity: 0.9;
}

.popeye-icon-btn:hover {
  opacity: 1;
  background: transparent;
}

.popeye-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.1rem 1rem 1.35rem;
  background: var(--popeye-white);
  display: flex;
  flex-direction: column;
  gap: 1.15rem;
}

.popeye-panel.is-minimized .popeye-messages,
.popeye-panel.is-minimized .popeye-composer {
  display: none;
}

.popeye-bubble {
  position: relative;
  max-width: 86%;
  padding: 0.8rem 0.9rem 0.95rem;
  border-radius: 0;
  font-size: 0.9rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  border: 0;
}

.popeye-bubble::after {
  content: "";
  position: absolute;
  bottom: -10px;
  width: 0;
  height: 0;
  border-style: solid;
}

.popeye-bubble.user {
  align-self: flex-end;
  background: var(--popeye-user-bubble);
  color: var(--popeye-ink);
}

.popeye-bubble.user::after {
  right: 0;
  border-width: 10px 12px 0 0;
  border-color: var(--popeye-user-bubble) transparent transparent transparent;
}

.popeye-bubble.popeye {
  align-self: flex-start;
  background: var(--popeye-accent);
  color: var(--popeye-white);
}

.popeye-bubble.popeye::after {
  left: 0;
  border-width: 10px 0 0 12px;
  border-color: var(--popeye-accent) transparent transparent transparent;
}

.popeye-bubble.popeye a {
  color: var(--popeye-white);
  text-decoration: underline;
  word-break: break-word;
}

.popeye-bubble.popeye a:hover {
  opacity: 0.9;
}

.popeye-bubble.popeye strong {
  font-weight: 700;
}

.popeye-typing {
  align-self: flex-start;
  color: rgba(43, 45, 66, 0.65);
  font-size: 0.85rem;
  font-style: italic;
  padding: 0.25rem 0.5rem;
}

.popeye-composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.55rem;
  padding: 0.85rem;
  border-top: 0;
  background: var(--popeye-composer);
}

.popeye-composer input,
#popeye-root .popeye-composer input[type="text"] {
  width: 100%;
  border: 1px solid rgba(43, 45, 66, 0.16);
  border-radius: 0;
  padding: 0.65rem 0.75rem;
  font-size: 0.9rem;
  /* Theme dark-mode rules often force white input text — keep this readable. */
  color: #2b2d42 !important;
  -webkit-text-fill-color: #2b2d42 !important;
  caret-color: #2b2d42 !important;
  background: #ffffff !important;
  background-color: #ffffff !important;
  outline: none;
}

.popeye-composer input::placeholder,
#popeye-root .popeye-composer input[type="text"]::placeholder {
  color: rgba(43, 45, 66, 0.55) !important;
  -webkit-text-fill-color: rgba(43, 45, 66, 0.55) !important;
  opacity: 1;
}

.popeye-composer input:focus,
#popeye-root .popeye-composer input[type="text"]:focus {
  outline: 2px solid rgba(239, 35, 60, 0.35);
  border-color: var(--popeye-accent);
  box-shadow: none;
  color: #2b2d42 !important;
  -webkit-text-fill-color: #2b2d42 !important;
  caret-color: #2b2d42 !important;
  background: #ffffff !important;
}

.popeye-composer input:-webkit-autofill,
.popeye-composer input:-webkit-autofill:focus {
  -webkit-text-fill-color: #2b2d42 !important;
  box-shadow: 0 0 0 1000px #ffffff inset !important;
}

.popeye-composer button {
  align-self: stretch;
  border: 0;
  border-radius: 0;
  background: var(--popeye-accent);
  color: var(--popeye-white);
  padding: 0 0.95rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  cursor: pointer;
}

.popeye-composer button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

@media (max-width: 480px) {
  .popeye-title {
    font-size: 0.7rem;
    letter-spacing: 0.04em;
  }

  .popeye-panel {
    width: calc(100vw - 1.5rem);
    height: min(72vh, 580px);
  }
}
