/* Ivy — the website assistant (assets/js/ivy/, shown on /tools/ivy).
   Uses the site's tokens from styles.css so it follows light/dark theme. */

.ivy-panel {
  --ivy-glow: #6cf2b6;
  --ivy-stage-top: #13402c;
  --ivy-stage-bottom: #0b1f17;
  --ivy-radius: 22px;
  font-family: var(--font-sans, system-ui, sans-serif);
}

/* ── Panel ──────────────────────────────────────────────────────────── */

.ivy-panel {
  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 950;
  width: min(400px, calc(100vw - 32px));
  height: min(680px, calc(100vh - 32px));
  height: min(680px, calc(100dvh - 32px));
  display: flex;
  flex-direction: column;
  border-radius: var(--ivy-radius);
  background: var(--bg-card, #fff);
  color: var(--text, #0b1f17);
  box-shadow: 0 24px 60px rgba(11, 31, 23, 0.28), 0 6px 18px rgba(11, 31, 23, 0.16), 0 0 0 1px var(--color-line, #d8e2db);
  overflow: hidden;
  opacity: 0;
  transform: translateY(16px) scale(0.98);
  transform-origin: bottom right;
  transition: opacity 240ms ease, transform 300ms cubic-bezier(0.22, 0.61, 0.36, 1);
}
.ivy-panel[hidden] { display: none; }
.ivy-panel [hidden] { display: none !important; }   /* buttons set display, which would override [hidden] */
.ivy-panel--open { opacity: 1; transform: none; }

.ivy-stage {
  position: relative;
  flex: none;
  height: clamp(190px, 38%, 270px);
  background:
    radial-gradient(120% 90% at 50% 18%, rgba(108, 242, 182, 0.16), transparent 60%),
    linear-gradient(180deg, var(--ivy-stage-top), var(--ivy-stage-bottom));
  color: #eaf3ed;
  overflow: hidden;
}
.ivy-stage::after {          /* faint greenhouse-glass grid */
  content: "";
  position: absolute;
  inset: 0;
  background-image: linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px), linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px);
  background-size: 28px 28px;
  mask-image: linear-gradient(180deg, transparent, #000 30%, #000 70%, transparent);
  pointer-events: none;
}
.ivy-canvas { position: absolute; inset: 0; z-index: 1; }
.ivy-canvas canvas { display: block; width: 100% !important; height: 100% !important; }
.ivy-loading {
  position: absolute;
  left: 0;
  right: 0;
  top: 45%;
  z-index: 2;
  margin: 0;
  text-align: center;
  font-size: 0.85rem;
  color: rgba(234, 243, 237, 0.85);
}
.ivy-flat { position: absolute; left: 50%; bottom: 0; height: 92%; transform: translateX(-50%); }
.ivy-flat__eyes { transform-origin: center; transform-box: fill-box; animation: ivy-blink 5s infinite; }
.ivy-canvas[data-state="thinking"] .ivy-flat__mouth { animation: ivy-pulse 0.9s ease-in-out infinite; }

.ivy-stage__top {
  position: absolute;
  inset: 0 0 auto;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 14px 12px 0 18px;
}
.ivy-id__name {
  margin: 0;
  font: 600 1.35rem/1.1 var(--font-display, Georgia, serif);
  color: #fff;
}
.ivy-id__role { margin: 2px 0 0; font-size: 0.78rem; color: rgba(234, 243, 237, 0.7); }
.ivy-actions { display: flex; gap: 2px; }

.ivy-icon-btn {
  width: 38px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  cursor: pointer;
  transition: background 140ms, color 140ms;
}
.ivy-stage .ivy-icon-btn { color: rgba(234, 243, 237, 0.85); }
.ivy-stage .ivy-icon-btn:hover { background: rgba(255, 255, 255, 0.1); color: #fff; }
.ivy-icon-btn:focus-visible, .ivy-send:focus-visible, .ivy-chip:focus-visible { outline: 3px solid var(--color-sprout, #3fb37f); outline-offset: 1px; }
.ivy-icon-btn[aria-pressed="false"][data-act="voice"] { color: rgba(234, 243, 237, 0.5); }

.ivy-status {
  position: absolute;
  left: 18px;
  bottom: 12px;
  z-index: 2;
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 11px 5px 9px;
  border-radius: 999px;
  background: rgba(11, 31, 23, 0.55);
  backdrop-filter: blur(6px);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: #eaf3ed;            /* the site colours <p> dark in light theme */
}
.ivy-status__dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ivy-glow); box-shadow: 0 0 10px var(--ivy-glow); }
.ivy-panel[data-state="thinking"] .ivy-status__dot,
.ivy-panel[data-state="listening"] .ivy-status__dot { animation: ivy-pulse 0.9s ease-in-out infinite; }
.ivy-panel[data-state="listening"] .ivy-status__dot { background: #ff8a65; box-shadow: 0 0 10px #ff8a65; }

/* ── Conversation ───────────────────────────────────────────────────── */

.ivy-log {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}
.ivy-log:focus-visible { outline: 2px solid var(--color-sprout, #3fb37f); outline-offset: -2px; }
.ivy-msg { display: flex; }
.ivy-msg--user { justify-content: flex-end; }
.ivy-msg__bubble {
  max-width: 86%;
  padding: 10px 13px;
  border-radius: 16px;
  font-size: 0.94rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}
.ivy-msg--ivy .ivy-msg__bubble { background: var(--color-mist, #e6efe9); border-bottom-left-radius: 5px; }
.ivy-msg--user .ivy-msg__bubble { background: var(--color-emerald, #0e5c3a); color: #fff; border-bottom-right-radius: 5px; }
.ivy-msg__bubble a { color: var(--color-emerald, #0e5c3a); font-weight: 600; text-underline-offset: 2px; }
[data-theme="dark"] .ivy-msg__bubble a { color: var(--ivy-glow); }
.ivy-link { white-space: nowrap; }

.ivy-typing { display: inline-flex; gap: 4px; padding: 4px 2px; }
.ivy-typing i { width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: 0.35; animation: ivy-dots 1.1s infinite; }
.ivy-typing i:nth-child(2) { animation-delay: 0.15s; }
.ivy-typing i:nth-child(3) { animation-delay: 0.3s; }

.ivy-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 14px 10px; }
.ivy-chips[hidden] { display: none; }
.ivy-chip {
  border: 1px solid var(--color-line, #d8e2db);
  border-radius: 999px;
  padding: 7px 12px;
  background: transparent;
  color: var(--text, #0b1f17);
  font: 500 0.82rem/1.2 var(--font-sans, system-ui, sans-serif);
  cursor: pointer;
  transition: background 140ms, border-color 140ms;
}
.ivy-chip:hover { background: var(--color-mist, #e6efe9); border-color: var(--color-sprout, #3fb37f); }

.ivy-form {
  flex: none;
  display: flex;
  align-items: flex-end;
  gap: 4px;
  margin: 0 12px;
  padding: 6px 6px 6px 14px;
  border: 1px solid var(--color-line, #d8e2db);
  border-radius: 18px;
  background: var(--bg-page, #f7f4ee);
  transition: border-color 140ms, box-shadow 140ms;
}
.ivy-form:focus-within { border-color: var(--color-sprout, #3fb37f); box-shadow: 0 0 0 3px rgba(63, 179, 127, 0.18); }
.ivy-input {
  flex: 1;
  min-width: 0;
  max-height: 120px;
  margin: 0;
  padding: 9px 0;
  border: 0;
  background: transparent;
  color: var(--text, #0b1f17);
  font: 400 16px/1.4 var(--font-sans, system-ui, sans-serif); /* 16px stops iOS zooming in */
  resize: none;
  outline: none;
  overflow-y: hidden;
}
.ivy-input::placeholder { color: var(--text-muted, #5b6b62); }
.ivy-form .ivy-icon-btn { color: var(--text-muted, #5b6b62); }
.ivy-form .ivy-icon-btn:hover { background: var(--color-mist, #e6efe9); color: var(--text, #0b1f17); }
.ivy-mic.is-live { background: #ffe3da; color: #b3261e; animation: ivy-ring 1.4s infinite; }
.ivy-send {
  width: 38px;
  height: 38px;
  flex: none;
  display: inline-grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: var(--color-emerald, #0e5c3a);
  color: #fff;
  cursor: pointer;
  transition: background 140ms, transform 140ms;
}
.ivy-send:hover { background: var(--color-emerald-2, #0a4a2f); }
.ivy-send svg { width: 17px; height: 17px; }
.ivy-form.is-busy .ivy-send { opacity: 0.5; pointer-events: none; }

.ivy-note { flex: none; margin: 8px 16px 12px; font-size: 0.72rem; line-height: 1.35; color: var(--text-muted, #5b6b62); text-align: center; }
.ivy-note a { color: inherit; }
.ivy-sr { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); border: 0; }

/* Phones: a full-screen sheet. */
@media (max-width: 520px) {
  .ivy-panel {
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    border-radius: 0;
    transform: translateY(24px);
  }
  .ivy-panel.ivy-panel--open { transform: none; }
  .ivy-stage { height: 34%; }
  .ivy-is-open body { overflow: hidden; }
}

/* Inline: part of a page (/tools/ivy) rather than floating in the corner. */
.ivy-panel.ivy-panel--inline {
  position: relative;
  inset: auto;
  z-index: auto;
  width: 100%;
  height: min(720px, 82vh);
  height: min(720px, 82dvh);
  border-radius: var(--ivy-radius);
  opacity: 1;
  transform: none;
  box-shadow: var(--shadow-lg, 0 18px 40px rgba(11, 31, 23, 0.12)), 0 0 0 1px var(--color-line, #d8e2db);
}
.ivy-panel--inline .ivy-stage { height: clamp(220px, 46%, 360px); }

@media (prefers-reduced-motion: reduce) {
  .ivy-panel { transition: none; }
  .ivy-flat__eyes { animation: none; }
  .ivy-log { scroll-behavior: auto; }
}

@media print { .ivy-panel { display: none !important; } }

@keyframes ivy-blink { 0%, 92%, 100% { transform: scaleY(1); } 95% { transform: scaleY(0.1); } }
@keyframes ivy-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
@keyframes ivy-dots { 0%, 60%, 100% { opacity: 0.25; transform: translateY(0); } 30% { opacity: 0.8; transform: translateY(-3px); } }
@keyframes ivy-ring { 0% { box-shadow: 0 0 0 0 rgba(179, 38, 30, 0.35); } 100% { box-shadow: 0 0 0 10px rgba(179, 38, 30, 0); } }
