/* Nutty: the talking squirrel in the corner. Self-contained; uses its own
   custom properties so it does not depend on the desktop theme. */
.nutty {
  --nutty-panel: #15171c;
  --nutty-panel-2: #1f232b;
  --nutty-text: #eef1f4;
  --nutty-muted: #9aa3ad;
  --nutty-accent: #c7f04b;
  position: fixed;
  right: 18px;
  bottom: 84px;
  z-index: 9000;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  font-family: inherit;
  pointer-events: none;
}

.nutty > * {
  pointer-events: auto;
}

.nutty[hidden] {
  display: none;
}

/* Character */
.nutty-critter {
  position: relative;
  width: 92px;
  height: 92px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.45)) drop-shadow(0 0 6px rgba(199, 240, 75, 0.25));
  animation: nutty-bob 3.2s ease-in-out infinite;
}

.nutty-critter:hover {
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.45)) drop-shadow(0 0 10px rgba(199, 240, 75, 0.45));
}

.nutty-critter:focus-visible {
  outline: 2px solid var(--nutty-accent);
  outline-offset: 4px;
  border-radius: 50%;
}

.nutty-critter svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.nutty-ring {
  transform-origin: 50px 54px;
  animation: nutty-spin 14s linear infinite;
}

.nutty.is-thinking .nutty-ring {
  animation-duration: 1.6s;
}

.nutty-tip {
  animation: nutty-glow 2.4s ease-in-out infinite;
}

.nutty-tip + .nutty-tip {
  animation-delay: 1.2s;
}

.nutty-eye {
  transform-origin: center;
  transform-box: fill-box;
  filter: drop-shadow(0 0 2px var(--nutty-accent));
  animation: nutty-blink 5s infinite;
}

.nutty.is-thinking .nutty-eye {
  animation: nutty-glow 0.8s ease-in-out infinite;
}

.nutty-scan {
  animation: nutty-scan 3.5s ease-in-out infinite;
}

.nutty-mouth rect {
  fill: var(--nutty-accent);
  opacity: 0.55;
  transform-origin: center;
  transform-box: fill-box;
  transform: scaleY(0.5);
}

.nutty.is-talking .nutty-mouth rect {
  opacity: 1;
  animation: nutty-eq 0.42s ease-in-out infinite alternate;
}

.nutty.is-talking .nutty-mouth rect:nth-child(2) { animation-delay: -0.12s; }
.nutty.is-talking .nutty-mouth rect:nth-child(3) { animation-delay: -0.3s; }
.nutty.is-talking .nutty-mouth rect:nth-child(4) { animation-delay: -0.06s; }
.nutty.is-talking .nutty-mouth rect:nth-child(5) { animation-delay: -0.22s; }

.nutty-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--nutty-accent);
  box-shadow: 0 0 0 3px rgba(199, 240, 75, 0.25);
  animation: nutty-pulse 1.8s ease-in-out infinite;
}

.nutty.is-open .nutty-badge {
  display: none;
}

/* Chatter bubble: short one-liners Nutty pops up now and then */
.nutty-hint {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  max-width: 240px;
  margin-right: 20px;
  padding: 9px 12px;
  border-radius: 14px 14px 4px 14px;
  background: var(--nutty-panel);
  color: var(--nutty-text);
  font-size: 13px;
  line-height: 1.35;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  animation: nutty-pop 0.25s ease-out;
}

.nutty-hint[hidden],
.nutty.is-open .nutty-hint {
  display: none;
}

.nutty-hint-action {
  padding: 3px 9px;
  border: 1px solid rgba(199, 240, 75, 0.45);
  border-radius: 999px;
  background: rgba(199, 240, 75, 0.12);
  color: var(--nutty-accent);
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.nutty-hint-action:hover,
.nutty-hint-action:focus-visible {
  background: rgba(199, 240, 75, 0.22);
}

.nutty-hint-action[hidden] {
  display: none;
}

/* Chat panel */
.nutty-panel {
  display: none;
  flex-direction: column;
  width: min(340px, calc(100vw - 32px));
  height: min(430px, calc(100vh - 220px));
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px 16px 4px 16px;
  background: var(--nutty-panel);
  color: var(--nutty-text);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
  overflow: hidden;
  animation: nutty-pop 0.2s ease-out;
}

.nutty.is-open .nutty-panel {
  display: flex;
}

.nutty-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--nutty-panel-2);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.nutty-head span {
  flex: 1;
}

.nutty-head small {
  color: var(--nutty-muted);
  font-weight: 400;
  letter-spacing: 0;
}

.nutty-icon-button {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--nutty-muted);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}

.nutty-icon-button:hover,
.nutty-icon-button:focus-visible {
  background: rgba(255, 255, 255, 0.08);
  color: var(--nutty-text);
}

.nutty-log {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  overflow-y: auto;
  font-size: 14px;
  line-height: 1.4;
}

.nutty-msg {
  max-width: 85%;
  padding: 8px 11px;
  border-radius: 14px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.nutty-msg.from-nutty {
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  background: var(--nutty-panel-2);
}

.nutty-msg.from-you {
  align-self: flex-end;
  border-bottom-right-radius: 4px;
  background: var(--nutty-accent);
  color: #15171c;
}

.nutty-msg.is-error {
  color: #ffb4a8;
}

.nutty-dots::after {
  content: "…";
  animation: nutty-dots 1s steps(3, end) infinite;
}

.nutty-form {
  display: flex;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.nutty-form input {
  flex: 1;
  min-width: 0;
  padding: 9px 11px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  background: #0f1115;
  color: var(--nutty-text);
  font: inherit;
  font-size: 14px;
}

.nutty-form input:focus {
  outline: none;
  border-color: var(--nutty-accent);
}

.nutty-form button {
  padding: 0 14px;
  border: 0;
  border-radius: 10px;
  background: var(--nutty-accent);
  color: #15171c;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.nutty-form button:disabled,
.nutty-form input:disabled {
  opacity: 0.5;
  cursor: default;
}

.nutty-note {
  padding: 0 12px 8px;
  color: var(--nutty-muted);
  font-size: 11px;
}

/* Small "bring Nutty back" tab after hiding */
.nutty-return {
  position: fixed;
  right: 0;
  bottom: 110px;
  z-index: 9000;
  padding: 6px 8px;
  border: 0;
  border-radius: 10px 0 0 10px;
  background: #15171c;
  color: #eef1f4;
  font-size: 18px;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
}

.nutty-return[hidden] {
  display: none;
}

@keyframes nutty-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

@keyframes nutty-spin {
  to { transform: rotate(360deg); }
}

@keyframes nutty-glow {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

@keyframes nutty-blink {
  0%, 94%, 100% { transform: scaleY(1); }
  96% { transform: scaleY(0.1); }
}

@keyframes nutty-scan {
  0% { transform: translateY(0); }
  50% { transform: translateY(16px); }
  100% { transform: translateY(0); }
}

@keyframes nutty-eq {
  from { transform: scaleY(0.4); }
  to { transform: scaleY(1.9); }
}

@keyframes nutty-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.2); }
}

@keyframes nutty-pop {
  from { opacity: 0; transform: translateY(6px) scale(0.97); }
  to { opacity: 1; transform: none; }
}

@keyframes nutty-dots {
  0% { content: "."; }
  33% { content: ".."; }
  66% { content: "..."; }
}

@media (max-width: 640px) {
  .nutty {
    right: 10px;
    bottom: 76px;
  }

  .nutty-critter {
    width: 68px;
    height: 68px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .nutty-critter,
  .nutty-ring,
  .nutty-tip,
  .nutty-eye,
  .nutty-scan,
  .nutty-badge,
  .nutty.is-talking .nutty-mouth rect,
  .nutty.is-thinking .nutty-eye,
  .nutty-hint {
    animation: none;
  }
}
