.frog-face {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: pixelated;
}

.frog {
  position: fixed;
  z-index: 40;
  right: calc(var(--gutter) + var(--safe-right));
  bottom: calc(var(--bottom-bar-height, 0px) + var(--space-3) + var(--safe-bottom));
  display: grid;
  place-items: center;
  width: var(--button-height);
  height: var(--button-height);
  padding: 10px 9px 11px;
  border: 1px solid var(--glass-edge);
  border-radius: var(--radius-pill);
  background: var(--glass-strong);
  backdrop-filter: var(--blur);
  box-shadow: var(--shadow-glass);
  cursor: pointer;
  transition: transform 160ms var(--spring), bottom var(--motion-screen) var(--ease-out);
  -webkit-tap-highlight-color: transparent;
}

.frog[hidden] {
  display: none;
}

.frog:active {
  transform: scale(0.92);
}

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

.sheet-overlay:not([hidden]) ~ .frog {
  display: none;
}

.frog-dot {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 12px;
  height: 12px;
  border: 2px solid var(--bg);
  border-radius: 999px;
  background: var(--danger);
  transform: scale(0);
  transition: transform 220ms var(--spring);
}

.frog[data-fresh] .frog-dot {
  transform: scale(1);
}

.frog[data-fresh] .frog-face {
  animation: frog-hop 1.6s var(--ease) 2;
}

@keyframes frog-hop {
  0%,
  60%,
  100% {
    transform: translateY(0);
  }

  70% {
    transform: translateY(-4px);
  }

  80% {
    transform: translateY(0);
  }

  88% {
    transform: translateY(-2px);
  }
}

.chat {
  position: fixed;
  inset: 0;
  z-index: 45;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: var(--scrim);
  animation: scrim-in var(--motion-fast) var(--ease);
}

.chat[hidden] {
  display: none;
}

.chat[data-leaving] {
  opacity: 0;
  transition: opacity var(--motion-fast) var(--ease);
}

.chat-panel {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 720px;
  height: min(88dvh, 760px);
  border: 1px solid var(--glass-edge);
  border-bottom: 0;
  border-radius: var(--radius-sheet) var(--radius-sheet) 0 0;
  background: var(--glass-strong);
  backdrop-filter: var(--blur);
  box-shadow: var(--shadow-sheet);
  animation: sheet-in var(--motion-sheet) var(--spring);
  overflow: hidden;
}

.chat-head {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-2) var(--space-2) var(--gutter);
  border-bottom: 1px solid var(--line);
}

.chat-face {
  width: 28px;
  flex: none;
}

.chat-title {
  flex: 1;
  margin: 0;
  font-size: 17px;
  font-weight: 700;
}

.chat-close {
  display: grid;
  place-items: center;
  width: var(--hit);
  height: var(--hit);
  border: 0;
  background: none;
  color: var(--hint);
  cursor: pointer;
}

.chat-clear {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  min-height: var(--hit);
  padding: 0 var(--space-2);
  border: 0;
  background: none;
  color: var(--hint);
  font: inherit;
  font-size: var(--control-font);
  white-space: nowrap;
  cursor: pointer;
}

@media (width < 440px) {
  .chat-clear {
    justify-content: center;
    min-width: var(--hit);
  }

  .chat-clear-text {
    display: none;
  }
}

.chat-clear:disabled {
  opacity: 0.4;
  cursor: default;
}

.chat-hint {
  margin: var(--space-4) var(--gutter) 0;
  font-size: 14px;
  line-height: 1.4;
  color: var(--hint);
}

.chat-log {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: var(--space-2);
  margin: 0;
  padding: var(--space-3) var(--gutter);
  overflow-y: auto;
  overscroll-behavior: contain;
  list-style: none;
}

.chat-message {
  max-width: 85%;
  padding: 9px 14px;
  border-radius: 18px;
  font-size: 15px;
  position: relative;
  line-height: 1.4;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.chat-message-user {
  align-self: flex-end;
  border-bottom-right-radius: 6px;
  background: var(--accent-fill);
  color: var(--accent-ink);
}

.chat-message-assistant {
  align-self: flex-start;
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
  background: var(--plate);
  color: var(--ink);
}

.chat-message a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.chat-message-assistant a {
  color: var(--accent);
}

.chat-message[data-status='streaming']:not([data-waiting])::after {
  content: '▍';
  margin-left: 1px;
  color: var(--accent);
  animation: chat-caret 1s steps(1) infinite;
}

.chat-thinking {
  color: var(--hint);
}

.chat-thinking::after {
  content: '';
  display: inline-block;
  width: 1.2em;
  text-align: left;
  animation: chat-dots 1.2s steps(4) infinite;
}

.chat-error {
  display: block;
  margin-top: 2px;
  font-size: 13px;
  color: var(--danger);
}

.chat-message[data-status='failed'] .chat-error:first-child {
  margin-top: 0;
}

@keyframes chat-caret {
  50% {
    opacity: 0;
  }
}

@keyframes chat-dots {
  0% {
    content: '';
  }

  25% {
    content: '.';
  }

  50% {
    content: '..';
  }

  75% {
    content: '...';
  }
}

.chat-compose {
  display: flex;
  align-items: flex-end;
  gap: var(--space-2);
  margin: 0;
  padding: var(--space-2) var(--space-2) calc(var(--space-2) + var(--safe-bottom)) var(--gutter);
  border-top: 1px solid var(--line);
}

.chat-field {
  resize: none;
  font-size: 16px;
}

.chat-compose:not([data-ready]) .chat-send {
  opacity: 0.35;
  pointer-events: none;
}

@media (width >= 900px) {
  .chat {
    align-items: flex-end;
    justify-content: flex-end;
    padding: var(--space-6);
    background: var(--scrim-light);
  }

  .chat-panel {
    max-width: 420px;
    height: min(80vh, 680px);
    border-bottom: 1px solid var(--glass-edge);
    border-radius: var(--radius-sheet);
  }
}

@media (prefers-reduced-motion: reduce) {
  .frog[data-fresh] .frog-face,
  .chat-thinking::after,
  .chat-message::after {
    animation: none;
  }
}

.chat-title-box {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
}

.chat-typing {
  font-size: 13px;
  color: var(--accent);
}

.chat-message-user::after {
  content: '\2713';
  margin-left: 6px;
  font-size: 11px;
  opacity: 0.75;
}

.chat-message-user:not([data-status='queued'])::after {
  content: '\2713\2713';
}

.chat-message[data-reactions] {
  margin-bottom: 12px;
}

.chat-message[data-reactions]::before {
  content: attr(data-reactions);
  position: absolute;
  bottom: -14px;
  right: 10px;
  padding: 0 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--plate);
  font-size: 13px;
  line-height: 20px;
}

.chat-message-user[data-reactions]::before {
  right: auto;
  left: 10px;
}

.chat-quote {
  display: block;
  margin-bottom: 4px;
  padding-left: 8px;
  border-left: 3px solid currentcolor;
  font-size: 13px;
  opacity: 0.8;
}

.chat-split {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 0;
  border: 0;
  background: none;
}

.chat-part {
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  border-bottom-left-radius: 6px;
  background: var(--plate);
}

.chat-sticker {
  padding: 0;
  border: 0;
  background: none;
  font-size: 56px;
  line-height: 1.1;
}

.chat-sticker-media {
  display: block;
  width: 160px;
  height: 160px;
  object-fit: contain;
}

.chat-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 8px;
  white-space: normal;
}

.chat-quote-bar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-2) 0 var(--gutter);
  font-size: 13px;
  color: var(--hint);
}

.chat-quote-text {
  flex: 1;
  min-width: 0;
  padding-left: 8px;
  border-left: 3px solid var(--accent);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-stickers {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: var(--space-2) var(--space-2) 0 var(--gutter);
  font-size: 22px;
}

.chat-tool {
  display: grid;
  place-items: center;
  min-width: var(--hit);
  min-height: var(--hit);
}

.chat-topic {
  align-self: center;
  padding: 2px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12px;
  color: var(--hint);
}

.chat-artifact {
  display: block;
  width: 100%;
  min-width: 240px;
  height: 260px;
  margin-top: 6px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
}
