@layer components {
  .talk-mode {
    display: grid;
    grid-template-columns: minmax(var(--space-0), var(--track-fill));
    grid-template-rows: minmax(var(--space-0), var(--track-fill)) auto;
    grid-template-areas:
      "caption"
      "footer";
    gap: var(--space-4);
    block-size: var(--size-fill);
    max-inline-size: var(--measure);
    margin-inline: auto;
    padding-block: var(--space-5);
    padding-inline: var(--gutter-fluid);
  }

  .talk-mode > .conversation-activity {
    display: none;
  }

  .talk-mode:has(.talk-mode__panel:not([hidden]), .talk-mode__notice:not(:empty), .resume) {
    grid-template-areas:
      "footer"
      "footer";
  }

  .talk-mode:has(.talk-mode__panel:not([hidden]), .talk-mode__notice:not(:empty), .resume) > .conversation-caption {
    display: none;
  }

  .sheet__body:has(.talk-mode) .participant--guide .participant__avatar::before {
    border: var(--border-width-strong) solid transparent;
    scale: var(--participant-halo-scale);
  }

  .sheet__body:has(.talk-mode .conversation-activity--thinking) .participant--guide .participant__avatar::before {
    border-color: var(--color-guide-halo);
    border-block-start-color: var(--color-guide);
    animation: talk-mode-spin var(--dur-thinking) linear infinite;
  }

  .sheet__body:has(.talk-mode .conversation-activity--speaking:not(.conversation-activity--participant)) .participant--guide .participant__avatar::before {
    scale: none;
    animation: speaking-ring var(--dur-speaking) var(--ease-calm) infinite;
  }

  .sheet__body:has(.talk-mode--hold-to-talk[data-microphone="live"] .conversation-activity--idle) .participant--guide .participant__avatar::before {
    border-color: var(--color-guide-halo);
    animation: talk-mode-pulse var(--dur-slow) var(--ease-spring-soft) infinite alternate;
  }

  .sheet__body:has(.talk-mode--open-line[data-microphone="live"] .conversation-activity--idle) .participant--guide .participant__avatar::before {
    border-color: var(--color-guide-halo);
    animation: talk-mode-ripple var(--dur-breath) var(--ease-calm) infinite;
  }

  .sheet__body:has(.talk-mode--push-to-talk[data-microphone="live"] .conversation-activity--idle) .participant--guide .avatar {
    animation: talk-mode-breathe var(--dur-breath) var(--ease-breath) infinite alternate;
  }

  @keyframes talk-mode-ripple {
    to {
      scale: var(--participant-ripple-scale);
      opacity: var(--participant-ripple-fade);
    }
  }

  @keyframes talk-mode-spin {
    to { rotate: var(--participant-spin); }
  }

  @keyframes talk-mode-pulse {
    to { transform: scale(var(--participant-pulse-scale)); }
  }

  @keyframes talk-mode-breathe {
    to { transform: scale(var(--participant-breathe-scale)); }
  }

  .talk-device {
    display: none;
    position: absolute;
    inset-block-start: var(--talk-device-dot-inset);
    inset-inline-end: var(--talk-device-dot-inset);
    inline-size: var(--talk-device-dot-size);
    block-size: var(--talk-device-dot-size);
    border-radius: var(--radius-pill);
    background-color: var(--color-guide);
  }

  .sheet:has(.talk-mode[data-ai-lilt-speaking="true"]:is([data-microphone="live"], [data-microphone="muted"], [data-microphone="ready"])) .talk-device {
    display: block;
  }

  .talk-device__word {
    position: absolute;
    inline-size: var(--border-width);
    block-size: var(--border-width);
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  .talk-mode__panel {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-5);
    max-inline-size: var(--measure-tight);
    margin-inline: auto;
    margin-block-end: var(--space-6);
    text-align: center;
    text-wrap: balance;
  }

  .talk-mode__panel[data-reason="asking"] {
    animation: entrance var(--dur-slow) var(--ease-spring-soft) var(--dur-slow) backwards;
  }

  .talk-mode__panel-why {
    font: var(--type-title-2);
    letter-spacing: var(--tracking-display);
    color: var(--color-ink-display);
  }

  .talk-mode__panel-guide {
    font: var(--type-body-sm);
    color: var(--color-ink-muted);
  }

  .talk-mode__panel-guide[data-platform] {
    display: none;
  }

  .talk-mode[data-platform="ios"] .talk-mode__panel-guide[data-platform="ios"],
  .talk-mode[data-platform="android"] .talk-mode__panel-guide[data-platform="android"],
  .talk-mode[data-platform="other"] .talk-mode__panel-guide[data-platform="other"] {
    display: block;
  }

  .talk-mode > .conversation-caption {
    grid-area: caption;
    align-self: safe center;
    text-align: start;
  }

  .talk-mode__footer {
    grid-area: footer;
    align-self: end;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-self: stretch;
  }

  .talk-mode__footer .turn-failure {
    margin-block-end: var(--space-6);
  }

  .talk-mode > .conversation-caption {
    transition: opacity var(--dur-base) var(--ease-calm);
  }

  .talk-mode:has(.conversation-activity--thinking, .conversation-activity--participant) > .conversation-caption {
    opacity: var(--opacity-none);
  }

  .talk-mode__footer .prompts {
    align-self: stretch;
    justify-content: safe center;
    margin-block-end: var(--space-6);
  }

  .talk-mode__actions {
    display: grid;
    grid-template-columns: minmax(var(--space-0), 1fr) auto minmax(var(--space-0), 1fr);
    align-items: center;
    gap: var(--space-5);
    inline-size: var(--size-fill);
  }

  .talk-mode__actions > .talk-way {
    justify-self: end;
  }

  .talk-mode__microphone-button {
    transition: background-color var(--dur-fast) var(--ease-calm), box-shadow var(--dur-fast) var(--ease-calm), transform var(--dur-fast) var(--ease-spring);
  }

  .talk-mode[data-ai-lilt-microphone="live"] .talk-mode__microphone-button:not(:disabled) {
    border-color: transparent;
    background-color: var(--color-accent);
    color: var(--color-ink-on-accent);
    box-shadow: var(--elev-2);
  }

  .talk-mode:is([data-microphone="connecting"], [data-microphone="asking"]) .talk-mode__microphone-button {
    outline: var(--border-width-strong) solid var(--color-accent);
    outline-offset: var(--space-2);
    animation: talk-mode-waiting var(--dur-breath) var(--ease-breath) infinite alternate;
  }

  @keyframes talk-mode-waiting {
    to { outline-color: transparent; }
  }

  .talk-mode__microphone-button > :is(.icon--arrow-up, .icon--microphone-slash),
  .talk-mode--push-to-talk[data-microphone="live"] .talk-mode__microphone-button > .icon--microphone,
  .talk-mode__microphone-button:disabled > :is(.icon--microphone, .icon--arrow-up) {
    display: none;
  }

  .talk-mode--push-to-talk[data-microphone="live"] .talk-mode__microphone-button:not(:disabled) > .icon--arrow-up,
  .talk-mode__microphone-button:disabled > .icon--microphone-slash {
    display: inline-block;
  }

  @media (any-hover: hover) {
    .talk-mode[data-ai-lilt-microphone="live"] .talk-mode__microphone-button:hover:where(:not(:disabled)) {
      background-color: var(--color-accent-hover);
    }
  }

  .talk-way__button {
    font: var(--type-label);
  }

  .talk-way__button > .icon {
    --icon-size: var(--space-6);
  }

  .talk-mode__hint {
    margin-block-start: var(--space-4);
    font: var(--type-caption);
    color: var(--color-ink-faint);
    text-align: center;
    text-wrap: balance;
  }

  .talk-mode__footer:has(.talk-mode__panel:not([hidden])) .talk-mode__hint {
    display: none;
  }

  .talk-mode--hold-to-talk .talk-mode__actions .button--large {
    touch-action: none;
  }
}
