/* Momo — portfolio assistant
   Uses the shared design tokens from variables.css so light/dark themes work
   automatically. */

.momo {
  --momo-surface: var(--background-secondary);
  --momo-panel-width: 380px;
  --momo-radius: 20px;

  position: fixed;
  right: 1.5rem;
  bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px));
  z-index: 1080;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.75rem;
  font-family: var(--font-body);
}

/* ------------------------------------------------------------------ mascot */

.momo-mascot {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
}

.momo-launcher-mascot .momo-mascot {
  animation: momo-float 4.5s ease-in-out infinite;
}

.momo-mascot .momo-eyes {
  animation: momo-blink 7s ease-in-out infinite;
  transform-origin: center 29.5px;
}

.momo-mascot .momo-glow,
.momo-mascot .momo-spark {
  animation: momo-pulse 3.5s ease-in-out infinite;
  transform-origin: center;
}

@keyframes momo-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4%); }
}

@keyframes momo-blink {
  0%, 92%, 100% { transform: scaleY(1); }
  95% { transform: scaleY(0.12); }
}

@keyframes momo-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

/* ---------------------------------------------------------------- launcher */

.momo-launcher {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 1.1rem 0.5rem 0.6rem;
  border: 1px solid var(--border-color);
  border-radius: 999px;
  background-color: var(--momo-surface);
  color: var(--text-primary);
  font-size: 0.95rem;
  font-weight: 600;
  box-shadow: 0 10px 30px var(--shadow-light);
  cursor: pointer;
  transition: transform 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease;
}

.momo-launcher:hover,
.momo-launcher:focus-visible {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: 0 18px 40px var(--shadow-medium);
}

.momo-launcher-mascot {
  display: block;
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
}

.momo[data-open="true"] .momo-launcher-label {
  display: none;
}

.momo[data-open="true"] .momo-launcher {
  padding: 0.5rem;
}

/* ---------------------------------------------------------- intro bubble */

.momo-intro {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  max-width: 15rem;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border-color);
  border-radius: 14px;
  background-color: var(--momo-surface);
  box-shadow: 0 10px 24px var(--shadow-light);
  animation: momo-fade-in 0.35s ease both;
}

.momo-intro p {
  margin: 0;
  font-size: 0.88rem;
  color: var(--text-primary);
}

.momo-intro-close {
  border: 0;
  background: none;
  color: var(--text-tertiary);
  font-size: 1rem;
  line-height: 1;
  padding: 0.1rem;
  cursor: pointer;
}

.momo-intro-close:hover {
  color: var(--accent);
}

/* ------------------------------------------------------------------- panel */

.momo-panel {
  display: flex;
  flex-direction: column;
  width: min(var(--momo-panel-width), calc(100vw - 3rem));
  max-height: min(560px, calc(100vh - 7rem));
  border: 1px solid var(--border-color);
  border-radius: var(--momo-radius);
  background-color: color-mix(in srgb, var(--momo-surface) 88%, transparent);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  box-shadow: 0 24px 60px var(--shadow-medium);
  overflow: hidden;
  animation: momo-panel-in 0.28s cubic-bezier(0.2, 0.8, 0.3, 1) both;
}

.momo-panel[hidden] {
  display: none;
}

@keyframes momo-panel-in {
  from { opacity: 0; transform: translateY(12px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes momo-fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ------------------------------------------------------------------ header */

.momo-header {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border-color);
}

.momo-header-mascot {
  display: block;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
}

.momo-header-text {
  display: flex;
  flex-direction: column;
  margin-right: auto;
  min-width: 0;
}

.momo-title {
  font-family: var(--font-heading);
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.momo-subtitle {
  font-size: 0.78rem;
  color: var(--text-tertiary);
}

.momo-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.momo-icon-btn:hover,
.momo-icon-btn:focus-visible {
  background-color: var(--background-tertiary);
  color: var(--accent);
}

/* ---------------------------------------------------------------- messages */

.momo-messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  scroll-behavior: smooth;
}

.momo-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  text-align: center;
  padding: 0.5rem 0.5rem 0.75rem;
}

.momo-welcome-mascot {
  display: block;
  width: 64px;
  height: 64px;
}

.momo-welcome-text {
  margin: 0;
  font-size: 0.92rem;
  color: var(--text-secondary);
}

.momo-message {
  max-width: 85%;
  padding: 0.6rem 0.85rem;
  border-radius: 16px;
  font-size: 0.92rem;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.momo-message--user {
  align-self: flex-end;
  background-color: var(--accent);
  color: var(--brand-dark-bg-primary);
  border-bottom-right-radius: 6px;
}

[data-theme="light"] .momo-message--user {
  color: #FFFFFF;
}

.momo-message--assistant {
  align-self: flex-start;
  background-color: var(--background-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  border-bottom-left-radius: 6px;
}

.momo-action-btn {
  align-self: flex-start;
  margin-top: -0.2rem;
  padding: 0.35rem 0.85rem;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: none;
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.momo-action-btn:hover,
.momo-action-btn:focus-visible {
  background-color: var(--accent);
  color: var(--background);
}

/* typing indicator */

.momo-typing {
  align-self: flex-start;
  display: inline-flex;
  gap: 0.28rem;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--border-color);
  border-radius: 16px;
  border-bottom-left-radius: 6px;
  background-color: var(--background-tertiary);
}

.momo-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--accent);
  animation: momo-typing 1.2s ease-in-out infinite;
}

.momo-typing span:nth-child(2) { animation-delay: 0.15s; }
.momo-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes momo-typing {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

/* ------------------------------------------------------------- suggestions */

.momo-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0 1rem 0.75rem;
}

.momo-suggestions[hidden] {
  display: none;
}

.momo-suggestion {
  padding: 0.35rem 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: 999px;
  background-color: transparent;
  color: var(--text-secondary);
  font-size: 0.8rem;
  cursor: pointer;
  transition: border-color 0.2s ease, color 0.2s ease;
}

.momo-suggestion:hover,
.momo-suggestion:focus-visible {
  border-color: var(--accent);
  color: var(--accent);
}

/* -------------------------------------------------------------- form/error */

.momo-error {
  margin: 0 1rem 0.6rem;
  padding: 0.55rem 0.75rem;
  border: 1px solid #e0708a;
  border-radius: 12px;
  background-color: rgba(224, 112, 138, 0.1);
  color: var(--text-primary);
  font-size: 0.83rem;
}

.momo-error[hidden] {
  display: none;
}

.momo-form {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border-color);
}

.momo-input {
  flex: 1 1 auto;
  max-height: 7rem;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border-color);
  border-radius: 14px;
  background-color: var(--background);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.92rem;
  line-height: 1.4;
  resize: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.momo-input::placeholder {
  color: var(--text-tertiary);
}

.momo-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}

.momo-send {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  border: 0;
  border-radius: 12px;
  background-color: var(--accent);
  color: var(--background);
  cursor: pointer;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.momo-send:hover:not(:disabled) {
  transform: translateY(-1px);
}

.momo-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.momo-privacy {
  margin: 0;
  padding: 0 1rem calc(0.85rem + env(safe-area-inset-bottom, 0px));
  font-size: 0.7rem;
  line-height: 1.4;
  color: var(--text-tertiary);
}

/* ------------------------------------------------------------------- focus */

.momo :focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ------------------------------------------------------------------ mobile */

@media (max-width: 575.98px) {
  .momo {
    right: 1rem;
    bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
  }

  .momo-launcher-label {
    display: none;
  }

  .momo-launcher {
    padding: 0.5rem;
  }

  .momo[data-open="true"] {
    inset: 0;
    right: 0;
    bottom: 0;
    gap: 0;
  }

  .momo[data-open="true"] .momo-launcher,
  .momo[data-open="true"] .momo-intro {
    display: none;
  }

  .momo-panel {
    width: 100%;
    height: 100%;
    max-height: none;
    border: 0;
    border-radius: 0;
  }

  /* Keeps the input reachable when the on-screen keyboard is open. */
  @supports (height: 100dvh) {
    .momo-panel {
      height: 100dvh;
    }
  }

  .momo-messages {
    overscroll-behavior: contain;
  }
}

/* --------------------------------------------------------- reduced motion */

@media (prefers-reduced-motion: reduce) {
  .momo *,
  .momo-mascot * {
    animation: none !important;
    transition: none !important;
  }

  .momo-messages {
    scroll-behavior: auto;
  }
}
