/* The home page's "every function" section (#functions, agent-showcase.js):
   function tabs, then a card that plays one agent's sample conversation
   around its orb, with the function's four agents underneath. */

.fn { margin-top: 32px; }

.fn-tabs {
  margin-top: 0;
  flex-wrap: nowrap;
  max-width: 100%;
  overflow-x: auto;
  scrollbar-width: none;
}
.fn-tabs::-webkit-scrollbar { display: none; }
.fn-tabs button { height: 40px; padding: 0 20px; font-size: 15px; flex: none; }

.fn-card {
  position: relative;
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background: var(--bg-subtle);
  overflow: hidden;
}

.fn-head {
  position: relative;
  z-index: 3;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 24px 24px 0 28px;
}
.fn-title { font-size: 16px; line-height: 24px; font-weight: 500; color: var(--ink); }
.fn-tagline { font-size: 14px; line-height: 20px; color: var(--ink-3); }
.fn-clone { flex: none; }

/* ---------------------------------------------------------------- stage */

.fn-stage {
  position: relative;
  height: 400px;
  margin-top: -24px;
}

.fn-orb {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 400px;
  height: 400px;
  margin: -212px 0 0 -200px;
  transition: opacity 320ms var(--ease-out), transform 420ms var(--ease-out);
}
.fn-orb canvas { display: block; width: 100%; height: 100%; }
/* Without WebGL the agent's icon stands in for the orb. */
.fn:not(.has-orb) .fn-orb { background: var(--orb); background-size: 300px; }

.fn-sound {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 2;
  width: 48px;
  height: 48px;
  margin: -36px 0 0 -24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: var(--radius-pill);
  background: rgba(10, 10, 10, 0.3);
  color: #fff;
  -webkit-backdrop-filter: blur(10px) saturate(1.3);
  backdrop-filter: blur(10px) saturate(1.3);
  cursor: pointer;
  transition: background-color var(--motion), transform 160ms var(--ease-out), opacity 240ms var(--ease-out);
}
.fn-sound:hover { background: rgba(10, 10, 10, 0.45); }
.fn-sound:active { transform: scale(0.94); }
.fn-sound:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }
.fn-sound-on { display: none; }
.fn.is-audible .fn-sound-on { display: block; }
.fn.is-audible .fn-sound-off { display: none; }
.fn:not(.is-ready) .fn-sound { opacity: 0; pointer-events: none; }

.fn-stage[data-kind="chat"] .fn-orb { opacity: 0; transform: scale(0.92); }
.fn-stage[data-kind="chat"] .fn-sound { display: none; }

/* The conversation: the newest message sits just below the middle, the older
   ones rise and fade under the top of the stage. */
.fn-thread-wrap {
  position: absolute;
  inset: 0;
  z-index: 1;
  overflow: hidden;
  pointer-events: none;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 30%, #000 100%);
  mask-image: linear-gradient(to bottom, transparent 0, #000 30%, #000 100%);
}
.fn-thread {
  width: min(600px, 92%);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: transform 460ms var(--ease-out);
}
.fn-stage[data-kind="chat"] .fn-thread { width: min(440px, 92%); }

.fn-bubble {
  max-width: 236px;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 20px;
  opacity: 0;
  transform: translateY(8px) scale(0.98);
  transition: opacity 260ms var(--ease-out), transform 320ms var(--ease-out);
}
.fn-bubble.is-in { opacity: 1; transform: none; }
.fn-bubble p { margin: 0; }

/* Voice: the agent's words in frosted glass on the left, the caller's on white
   to the right, each word appearing as it is spoken. */
.fn-bubble.fn-from-agent {
  align-self: flex-start;
  color: var(--ink-3);
  background: rgba(231, 231, 231, 0.7);
  -webkit-backdrop-filter: blur(12px) saturate(1.2);
  backdrop-filter: blur(12px) saturate(1.2);
}
.fn-bubble.fn-from-caller {
  align-self: flex-end;
  color: var(--ink);
  background: var(--bg);
  box-shadow: 0 0 0 0.5px rgba(10, 10, 10, 0.1), 0 2px 8px rgba(10, 10, 10, 0.05);
}
.fn-w { opacity: 0; transition: opacity 180ms ease; }
.fn-w.is-on { opacity: 1; }

/* Chat: messages arrive whole; the agent's on white, the customer's on grey. */
.fn-stage[data-kind="chat"] .fn-bubble { max-width: 300px; }
.fn-stage[data-kind="chat"] .fn-bubble.fn-from-agent {
  color: var(--ink);
  background: var(--bg);
  box-shadow: 0 0 0 0.5px rgba(10, 10, 10, 0.1), 0 2px 8px rgba(10, 10, 10, 0.05);
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}
.fn-stage[data-kind="chat"] .fn-bubble.fn-from-caller {
  color: var(--ink-2);
  background: var(--bg-muted);
  box-shadow: none;
}

.fn-typing { display: flex; gap: 4px; align-items: center; height: 36px; padding: 0 14px; }
.fn-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.35;
  animation: fn-dot 1.1s ease-in-out infinite;
}
.fn-typing span:nth-child(2) { animation-delay: 0.15s; }
.fn-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes fn-dot {
  0%, 60%, 100% { opacity: 0.25; transform: none; }
  30% { opacity: 0.7; transform: translateY(-2px); }
}

/* ---------------------------------------------------------------- agents */

.fn-agents {
  position: relative;
  z-index: 3;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  padding: 8px 20px 24px;
}
.fn-agent {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  padding: 8px;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  text-align: left;
  cursor: pointer;
  opacity: 0.45;
  transition: opacity 200ms ease, background-color var(--motion);
}
.fn-agent:hover { opacity: 0.8; }
.fn-agent[aria-pressed="true"] { opacity: 1; }
.fn-agent:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.fn-agent-orb {
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: 50%;
  background: var(--orb);
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
  filter: grayscale(1);
  transition: filter 300ms ease;
}
.fn-agent[aria-pressed="true"] .fn-agent-orb { filter: saturate(1.5); }
.fn-agent-text { display: flex; flex-direction: column; min-width: 0; }
.fn-agent-name { font-size: 15px; line-height: 20px; font-weight: 500; color: var(--ink); }
.fn-agent-role {
  font-size: 13px;
  line-height: 18px;
  color: var(--ink-3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------------------------------------------------------------- small screens */

@media (max-width: 899px) {
  .fn-agents {
    grid-template-columns: none;
    grid-auto-flow: column;
    grid-auto-columns: minmax(200px, 44%);
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
  }
  .fn-agents::-webkit-scrollbar { display: none; }
  .fn-agent { scroll-snap-align: center; }
}

@media (max-width: 639px) {
  .fn-head { padding: 20px 16px 0 20px; }
  .fn-stage { height: 380px; margin-top: -8px; }
  .fn-orb { width: 320px; height: 320px; margin: -230px 0 0 -160px; }
  .fn-sound { margin-top: -94px; }
  .fn-thread-wrap {
    -webkit-mask-image: linear-gradient(to bottom, transparent 0, transparent 34%, #000 62%, #000 100%);
    mask-image: linear-gradient(to bottom, transparent 0, transparent 34%, #000 62%, #000 100%);
  }
  .fn-stage[data-kind="chat"] .fn-thread-wrap {
    -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 30%, #000 100%);
    mask-image: linear-gradient(to bottom, transparent 0, #000 30%, #000 100%);
  }
  .fn-bubble { max-width: 68%; font-size: 13.5px; }
  .fn-stage[data-kind="chat"] .fn-bubble { max-width: 80%; }
  .fn-agents { grid-auto-columns: minmax(200px, 72%); padding: 4px 12px 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .fn-thread, .fn-bubble, .fn-w, .fn-orb { transition: none; }
  .fn-typing span { animation: none; }
}
